From: Matthias Kaehlcke <mka@chromium.org>
To: Joe Perches <joe@perches.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
pbonzini@redhat.com, rkrcmar@redhat.com,
Thomas Gleixner <tglx@linutronix.de>,
hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask()
Date: Fri, 15 Jun 2018 11:29:45 -0700 [thread overview]
Message-ID: <20180615182945.GN88063@google.com> (raw)
In-Reply-To: <d4f32707a89030733217b23b557b38504f0d83ca.camel@perches.com>
On Fri, Jun 15, 2018 at 11:18:12AM -0700, Joe Perches wrote:
> On Fri, 2018-06-15 at 11:04 -0700, Nick Desaulniers wrote:
> > On Fri, Jun 15, 2018 at 10:47 AM Matthias Kaehlcke <mka@chromium.org> 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 are assigned to
> > > u8 variables. Cast the negated values 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)
>
> Perhaps it's better to turn off the warning.
> There are more of these in the kernel too.
>
> At least:
> drivers/regulator/max8660.c: u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? ~1 : ~4;
> drivers/regulator/max8660.c: u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? ~2 : ~4;
> fs/ext4/resize.c: __u16 uninit_mask = (flexbg_size > 1) ? ~EXT4_BG_BLOCK_UNINIT : ~0;
In my experience neither clang nor gcc should promote these values to
int, since the MSB/sign bit is not set.
In any case I think it it preferable to fix the code over disabling
the warning, unless the warning is bogus or there are just too many
occurrences.
next prev parent reply other threads:[~2018-06-15 18:29 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-15 17:47 [PATCH] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask() Matthias Kaehlcke
2018-06-15 18:04 ` Nick Desaulniers
2018-06-15 18:18 ` Joe Perches
2018-06-15 18:29 ` Matthias Kaehlcke [this message]
2018-06-15 18:40 ` Joe Perches
2018-06-15 18:45 ` Nick Desaulniers
2018-06-19 15:19 ` Paolo Bonzini
2018-06-19 17:08 ` Nick Desaulniers
2018-06-19 17:13 ` Paolo Bonzini
2018-06-19 18:38 ` Matthias Kaehlcke
2018-06-19 17:23 ` Joe Perches
2018-06-19 17:35 ` Paolo Bonzini
2018-06-19 18:07 ` Joe Perches
2018-06-19 18:36 ` Matthias Kaehlcke
2018-06-19 19:11 ` Joe Perches
2018-06-19 21:10 ` Matthias Kaehlcke
2018-06-19 21:55 ` Joe Perches
2018-06-19 23:45 ` Matthias Kaehlcke
2018-06-20 0:18 ` Joe Perches
2018-06-20 1:36 ` Matthias Kaehlcke
2018-06-20 8:02 ` Paolo Bonzini
2018-06-20 23:00 ` Matthias Kaehlcke
2018-06-16 3:39 ` kbuild test robot
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=20180615182945.GN88063@google.com \
--to=mka@chromium.org \
--cc=hpa@zytor.com \
--cc=joe@perches.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ndesaulniers@google.com \
--cc=pbonzini@redhat.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