lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOdm4eS19-D3pEkKsyZw7VjJP9Jeh5gMZaszwgjrJe63yUg@mail.gmail.com>
Date:   Thu, 13 Feb 2020 14:43:21 -0800
From:   Nick Desaulniers <ndesaulniers@...gle.com>
To:     Michel Dänzer <michel@...nzer.net>
Cc:     Nathan Chancellor <natechancellor@...il.com>,
        intel-gfx@...ts.freedesktop.org,
        LKML <linux-kernel@...r.kernel.org>,
        clang-built-linux <clang-built-linux@...glegroups.com>,
        dri-devel <dri-devel@...ts.freedesktop.org>,
        Rodrigo Vivi <rodrigo.vivi@...el.com>
Subject: Re: [PATCH v2] drm/i915: Disable -Wtautological-constant-out-of-range-compare

On Wed, Feb 12, 2020 at 9:17 AM Michel Dänzer <michel@...nzer.net> wrote:
>
> On 2020-02-12 6:07 p.m., Nathan Chancellor wrote:
> > On Wed, Feb 12, 2020 at 09:52:52AM +0100, Michel Dänzer wrote:
> >> On 2020-02-11 9:39 p.m., Nathan Chancellor wrote:
> >>> On Tue, Feb 11, 2020 at 10:41:48AM +0100, Michel Dänzer wrote:
> >>>> On 2020-02-11 7:13 a.m., Nathan Chancellor wrote:
> >>>>> A recent commit in clang added -Wtautological-compare to -Wall, which is
> >>>>> enabled for i915 so we see the following warning:
> >>>>>
> >>>>> ../drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c:1485:22: warning:
> >>>>> result of comparison of constant 576460752303423487 with expression of
> >>>>> type 'unsigned int' is always false
> >>>>> [-Wtautological-constant-out-of-range-compare]
> >>>>>         if (unlikely(remain > N_RELOC(ULONG_MAX)))
> >>>>>             ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
> >>>>>
> >>>>> This warning only happens on x86_64 but that check is relevant for
> >>>>> 32-bit x86 so we cannot remove it.
> >>>>
> >>>> That's suprising. AFAICT N_RELOC(ULONG_MAX) works out to the same value
> >>>> in both cases, and remain is a 32-bit value in both cases. How can it be
> >>>> larger than N_RELOC(ULONG_MAX) on 32-bit (but not on 64-bit)?
> >>>>
> >>>
> >>> Hi Michel,
> >>>
> >>> Can't this condition be true when UINT_MAX == ULONG_MAX?
> >>
> >> Oh, right, I think I was wrongly thinking long had 64 bits even on 32-bit.
> >>
> >>
> >> Anyway, this suggests a possible better solution:
> >>
> >> #if UINT_MAX == ULONG_MAX
> >>      if (unlikely(remain > N_RELOC(ULONG_MAX)))
> >>              return -EINVAL;
> >> #endif
> >>
> >>
> >> Or if that can't be used for some reason, something like
> >>
> >>      if (unlikely((unsigned long)remain > N_RELOC(ULONG_MAX)))
> >>              return -EINVAL;
> >>
> >> should silence the warning.
> >
> > I do like this one better than the former.
>
> FWIW, one downside of this one compared to all alternatives (presumably)
> is that it might end up generating actual code even on 64-bit, which
> always ends up skipping the return.

The warning is pointing out that the conditional is always false,
which is correct on 64b.  The check is only active for 32b.
https://godbolt.org/z/oQrgT_
The cast silences the warning for 64b.  (Note that GCC and Clang also
generate precisely the same instruction sequences in my example, just
GCC doesn't warn on such tautologies).
-- 
Thanks,
~Nick Desaulniers

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ