From: Paolo Bonzini <pbonzini@redhat.com>
To: David Hildenbrand <david@redhat.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: jmattson@google.com
Subject: Re: [PATCH] KVM: MMU: speedup update_permission_bitmask
Date: Tue, 12 Sep 2017 10:20:27 +0200 [thread overview]
Message-ID: <6889a355-02ff-d473-681d-5632cf572e44@redhat.com> (raw)
In-Reply-To: <e4b5df86-31ae-2f4e-0666-393753e256df@redhat.com>
On 29/08/2017 18:46, David Hildenbrand wrote:
>> +#define BYTE_MASK(access) \
>> + ((1 & (access) ? 2 : 0) | \
>> + (2 & (access) ? 4 : 0) | \
>> + (3 & (access) ? 8 : 0) | \
>> + (4 & (access) ? 16 : 0) | \
>> + (5 & (access) ? 32 : 0) | \
>> + (6 & (access) ? 64 : 0) | \
>> + (7 & (access) ? 128 : 0))
>> +
> Hmm, I wonder if
>
> #define BYTE_MASK(access) \
> ((1 & (access) ? (1 << 1) : 0) | \
> (2 & (access) ? (1 << 2) : 0) | \
> ...
>
> would be easier to get
>
Yeah, you have a point. Another way to write it is:
(1 & (access) ? 0xAA : 0) | \
(2 & (access) ? 0xCC : 0) | \
(4 & (access) ? 0xF0 : 0)
but I think yours is the best.
>>
>> +
>> + const u8 x = BYTE_MASK(ACC_EXEC_MASK);
>> + const u8 w = BYTE_MASK(ACC_WRITE_MASK);
>> + const u8 u = BYTE_MASK(ACC_USER_MASK);
>> +
>> + bool cr4_smep = kvm_read_cr4_bits(vcpu, X86_CR4_SMEP) != 0;
>> + bool cr4_smap = kvm_read_cr4_bits(vcpu, X86_CR4_SMAP) != 0;
>> + bool cr0_wp = is_write_protection(vcpu);
>
> all three can be turned const. (and I'd drop the empty lines in between ..)
I am using const to identify a compile-time constant here, so more like
"static const" (but I was not sure if C optimizes away static const, so
I just used "const"). This explains also the empty line!
Paolo
prev parent reply other threads:[~2017-09-12 8:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-24 15:56 Paolo Bonzini
2017-08-28 19:42 ` Jim Mattson
2017-09-12 16:48 ` Peter Feiner
2017-09-12 19:55 ` Paolo Bonzini
2017-09-12 20:06 ` Peter Feiner
2017-08-29 16:46 ` David Hildenbrand
2017-09-12 8:20 ` Paolo Bonzini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6889a355-02ff-d473-681d-5632cf572e44@redhat.com \
--to=pbonzini@redhat.com \
--cc=david@redhat.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®