[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210112220634.GA1377517@ubuntu-m3-large-x86>
Date: Tue, 12 Jan 2021 15:06:34 -0700
From: Nathan Chancellor <natechancellor@...il.com>
To: Nick Desaulniers <ndesaulniers@...gle.com>
Cc: Kees Cook <keescook@...omium.org>,
Andrew Morton <akpm@...ux-foundation.org>,
LKML <linux-kernel@...r.kernel.org>,
clang-built-linux <clang-built-linux@...glegroups.com>
Subject: Re: [PATCH] ubsan: Implement __ubsan_handle_alignment_assumption
On Tue, Jan 12, 2021 at 01:53:30PM -0800, Nick Desaulniers wrote:
> On Tue, Jan 12, 2021 at 1:37 PM Nathan Chancellor
> <natechancellor@...il.com> wrote:
> >
> > > if real_ptr is an unsigned long, do we want to use `__ffs(real_ptr) +
> > > 1` here rather than ffs which takes an int? It seems the kernel is
> > > missing a definition of ffsl. :(
> >
> > Why the + 1? I think if we use __ffs (which it seems like we should), I
> > think that needs to become
>
> This came up recently in an internal code review; ffs and __ffs differ
> in output by one. See also the definition of ffs for alpha in
> arch/alpha/include/asm/bitops.h.
Interesting, thanks for bringing it up! Looks like ffs returns 1-32 and
__ffs returns 0-31. I think that we want __ffs here because we are
shifting (1UL << 32 overflows on 32-bit architectures) and the code in
LLVM appears to agree. LeastSignificantSetBitIndex evaluates to
__builtin_ctzl, which is the asm-generic implementation of __ffs.
Cheers,
NAthan
Powered by blists - more mailing lists