mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Nick Desaulniers <ndesaulniers@google.com>, pbonzini@redhat.com
Cc: Matthias Kaehlcke <mka@chromium.org>,
	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 v2] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask()
Date: Mon, 25 Jun 2018 10:05:52 -0700	[thread overview]
Message-ID: <ca7719d7e917623bcd0bfd508add4d1f43c42d53.camel@perches.com> (raw)
In-Reply-To: <CAKwvOdmmv9EtPB-jhwVruLASFve5d4h0+wx-6iY=ve=T9hbNdg@mail.gmail.com>

On Mon, 2018-06-25 at 12:47 -0400, Nick Desaulniers wrote:
> On Mon, Jun 25, 2018 at 12:05 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
> > 
> > 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.
> 
> Here's an actual bug this warning caught applied to drivers/input/:
> 
> dae1a432ab1f ("Input: mousedev - fix implicit conversion warning"):
> https://patchwork.kernel.org/patch/9753771/

What bug is that?

$ cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

int main(int argc, char **argv)
{
	static const signed char a[3] = {0x60, 3, 200};
	static const unsigned char b[3] = {0x60, 3, 200};

	printf("a and b are %s\n",
	       memcmp(a, b, 3) == 0 ? "identical" : "different");
}
$ gcc test.c
$ ./a.out
a and b are identical


  parent reply	other threads:[~2018-06-25 17:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-19 19:25 Matthias Kaehlcke
2018-06-25 16:02 ` David Laight
2018-06-25 16:05 ` Paolo Bonzini
2018-06-25 16:47   ` Nick Desaulniers
2018-06-25 17:01     ` Paolo Bonzini
2018-06-25 17:05     ` Joe Perches [this message]
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=ca7719d7e917623bcd0bfd508add4d1f43c42d53.camel@perches.com \
    --to=joe@perches.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mka@chromium.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

all inboxes | Powered by JetHome®