Re: [PATCH] f2fs: fix 32-bit linking

From: Arnd Bergmann
Date: Mon Jul 01 2019 - 10:58:42 EST


On Fri, Jun 28, 2019 at 7:58 PM Russell King - ARM Linux admin
<linux@xxxxxxxxxxxxxxx> wrote:
>
> On Fri, Jun 28, 2019 at 04:46:14PM +0200, Arnd Bergmann wrote:
> > On Fri, Jun 28, 2019 at 3:17 PM Christoph Hellwig <hch@xxxxxxxxxxxxx> wrote:
> > >
> > > On Fri, Jun 28, 2019 at 03:09:47PM +0200, Arnd Bergmann wrote:
> > > > I came across this on arm-nommu (which disables
> > > > CONFIG_CPU_SPECTRE) during randconfig testing.
> > > >
> > > > I don't see an easy way to add this in there, short of rewriting the
> > > > whole __get_user_err() function. Any suggestions?
> > >
> > > Can't we just fall back to using copy_from_user with a little wrapper
> > > that switches based on sizeof()?
> >
> > I came up with something now. It's not pretty, but seems to satisfy the
> > compiler. Not a proper patch yet, but let me know if you find a bug.
>
> Have you checked what the behaviour is when "ptr" is a pointer to a
> pointer? I think you'll end up with a compiler warning for every
> case, complaining about casting an unsigned long long to a pointer.

I have built lots of kernels using this patch as a test, though my autobuilder
is currently configured to use clang-8, and other compilers or versions
might show more warnings.

> > uaccess_restore(__ua_flags); \
> > - (x) = (__typeof__(*(ptr)))__gu_val; \
> > + (x) = __builtin_choose_expr(sizeof(*(ptr)) == 8, \
> > + (__typeof__(*(ptr)))__gu_val8, \
> > + (__typeof__(*(ptr)))__gu_val); \
> > } while (0)

The __builtin_choose_expr() here is supposed to take care of the case
of a pointer type, gcc and clang should both ignore the non-taken
branch and only produce warnings for the case they actually use.

Arnd