From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthias Kaehlcke Subject: Re: [PATCH] kvm: x86: mmu: Add cast to negated bitmasks in update_permission_bitmask() Date: Tue, 19 Jun 2018 14:10:19 -0700 Message-ID: <20180619211019.GE169030@google.com> References: <20180615182945.GN88063@google.com> <66b5e5c3ed82a5e1559419deb841c57bf0751fd3.camel@perches.com> <20180619183622.GB169030@google.com> <7547dfd4045a5acf23505887065bc228e65f2ff9.camel@perches.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: Paolo Bonzini , Nick Desaulniers , rkrcmar@redhat.com, Thomas Gleixner , hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org, LKML , Masahiro Yamada To: Joe Perches Return-path: Content-Disposition: inline In-Reply-To: <7547dfd4045a5acf23505887065bc228e65f2ff9.camel@perches.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Tue, Jun 19, 2018 at 12:11:27PM -0700, Joe Perches wrote: > On Tue, 2018-06-19 at 11:36 -0700, Matthias Kaehlcke wrote: > > On Tue, Jun 19, 2018 at 11:07:47AM -0700, Joe Perches wrote: > > > On Tue, 2018-06-19 at 19:35 +0200, Paolo Bonzini wrote: > > > > On 19/06/2018 19:23, Joe Perches wrote: > > > > > On Tue, 2018-06-19 at 10:08 -0700, Nick Desaulniers wrote: > > > > > > On Tue, Jun 19, 2018 at 8:19 AM Paolo Bonzini wrote: > > > > > > > > > > > > > > On 15/06/2018 20:45, Nick Desaulniers wrote: > > > > > > > > > > > > > > > > > > > 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. > > > > > > > > > > > > > > > > > > Maybe. > > > > > > > > > > > > > > > > Spurious warning today, actual bug tomorrow? I prefer to not to > > > > > > > > disable warnings wholesale. They don't need to find actual bugs to be > > > > > > > > useful. Flagging code that can be further specified does not hurt. > > > > > > > > Part of the effort to compile the kernel with different compilers is > > > > > > > > to add warning coverage, not remove it. That said, there may be > > > > > > > > warnings that are never useful (or at least due to some invariant that > > > > > > > > only affects the kernel). I cant think of any off the top of my head, > > > > > > > > but I'm also not sure this is one. > > > > > > > > > > > > > > This one really makes the code uglier though, so I'm not really inclined > > > > > > > to applying the patch. > > > > > > > > > > > > Note that of the three variables (w, u, x), only u is used later on. > > > > > > What about declaring them as negated with the cast, that way there's > > > > > > no cast in a ternary? > > > > > > > > > > It'd be simpler to cast in the BYTE_MASK macro itself > > > > > > > > I don't think that would work, as the ~ would be done on a zero-extended > > > > signed int. > > > > > > True, but the whole concept is dubious. > > > The implicit casts are all over the place, > > > not just in the file. > > > > Would that have been any different with the solution you proposed (if > > it worked)? > > > > Apparently both gcc and clang limit the warning to the potentially > > more problematic case where a value with sign bit is promoted. > > I think the warning is exactly equivalent to -Wsign-conversion > and we don't normally compile the kernel with that either. I disagree with "exactly equivalent". With -Wsign-conversion a warning is generated whenever a signed type is assigned to an unsigned variable or viceversa. -Wconstant-conversion is only issued when a *constant value* is assigned to an incompatible type. > Trying to allow a "make W=3" to be compiler warning message free > is also silly. > > I think it's better to make the warning emitted only at a W=3 > level instead. Another difference with -Wsign-conversion is that enabling it would probably result in thousands of warnings. Do you have evidence that there is a significant number of spurious -Wconstant-conversion warnings?