From: Paolo Bonzini <pbonzini@redhat.com>
To: "Matthias Kaehlcke" <mka@chromium.org>,
"Radim Krčmář" <rkrcmar@redhat.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"H . Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Nick Desaulniers <ndesaulniers@google.com>,
Joe Perches <joe@perches.com>
Subject: Re: [PATCH v2] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask()
Date: Mon, 25 Jun 2018 18:05:01 +0200 [thread overview]
Message-ID: <4dd99306-4fea-24b2-4bea-5b7927ea5e79@redhat.com> (raw)
In-Reply-To: <20180619192504.180479-1-mka@chromium.org>
On 19/06/2018 21:25, Matthias Kaehlcke wrote:
> update_permission_bitmask() negates u8 bitmask values and assigns them
> to variables of type u8. Since the MSB is set in the bitmask values the
> compiler expands the negated values to int, which then is assigned to
> an u8 variable. Cast the negated value back to u8.
>
> This fixes several warnings like this when building with clang:
>
> arch/x86/kvm/mmu.c:4266:39: error: implicit conversion from 'int' to 'u8'
> (aka 'unsigned char') changes value from -205 to 51 [-Werror,
> -Wconstant-conversion]
> u8 wf = (pfec & PFERR_WRITE_MASK) ? ~w : 0;
> ~~ ^~
>
> (gcc also raises a warning (see https://godbolt.org/g/6JWfWk), however it
> doesn't seem to be universally enabled)
>
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
> Changes in v2:
> - negate the bitmask at initialization and rename variables to not_X
The patch is not that bad, but I'd like to get confirmation that other
maintainers are applying fixes like this. Honestly I'm not really
impressed by most new clang warnings, these days.
Paolo
> arch/x86/kvm/mmu.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index d634f0332c0f..ad0a8c35f27b 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -4258,8 +4258,9 @@ static void update_permission_bitmask(struct kvm_vcpu *vcpu,
> {
> unsigned byte;
>
> - const u8 x = BYTE_MASK(ACC_EXEC_MASK);
> - const u8 w = BYTE_MASK(ACC_WRITE_MASK);
> + const u8 not_x = (u8)~BYTE_MASK(ACC_EXEC_MASK);
> + const u8 not_w = (u8)~BYTE_MASK(ACC_WRITE_MASK);
> + const u8 not_u = (u8)~BYTE_MASK(ACC_USER_MASK);
> const u8 u = BYTE_MASK(ACC_USER_MASK);
>
> bool cr4_smep = kvm_read_cr4_bits(vcpu, X86_CR4_SMEP) != 0;
> @@ -4275,11 +4276,11 @@ static void update_permission_bitmask(struct kvm_vcpu *vcpu,
> */
>
> /* Faults from writes to non-writable pages */
> - u8 wf = (pfec & PFERR_WRITE_MASK) ? ~w : 0;
> + u8 wf = (pfec & PFERR_WRITE_MASK) ? not_w : 0;
> /* Faults from user mode accesses to supervisor pages */
> - u8 uf = (pfec & PFERR_USER_MASK) ? ~u : 0;
> + u8 uf = (pfec & PFERR_USER_MASK) ? not_u : 0;
> /* Faults from fetches of non-executable pages*/
> - u8 ff = (pfec & PFERR_FETCH_MASK) ? ~x : 0;
> + u8 ff = (pfec & PFERR_FETCH_MASK) ? not_x : 0;
> /* Faults from kernel mode fetches of user pages */
> u8 smepf = 0;
> /* Faults from kernel mode accesses of user pages */
>
next prev parent reply other threads:[~2018-06-25 16:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-19 19:25 [PATCH v2] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask() Matthias Kaehlcke
2018-06-25 16:02 ` David Laight
2018-06-25 16:05 ` Paolo Bonzini [this message]
2018-06-25 16:47 ` Nick Desaulniers
2018-06-25 17:01 ` Paolo Bonzini
2018-06-25 17:05 ` Joe Perches
2018-06-25 17:12 ` Nick Desaulniers
2018-06-25 17:34 ` Joe Perches
2018-06-25 17:35 ` Matthias Kaehlcke
2018-06-25 17:50 ` Joe Perches
2018-06-25 19:05 ` Nick Desaulniers
2018-06-26 9:08 ` Paolo Bonzini
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=4dd99306-4fea-24b2-4bea-5b7927ea5e79@redhat.com \
--to=pbonzini@redhat.com \
--cc=hpa@zytor.com \
--cc=joe@perches.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mka@chromium.org \
--cc=ndesaulniers@google.com \
--cc=rkrcmar@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@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