Re: [PATCH 04/18] arm: implement nospec_ptr()

From: Hanjun Guo
Date: Wed Jan 10 2018 - 02:40:50 EST


On 2018/1/10 10:04, Laura Abbott wrote:
> On 01/05/2018 05:10 PM, Dan Williams wrote:
>> From: Mark Rutland <mark.rutland@xxxxxxx>
>>
>> This patch implements nospec_ptr() for arm, following the recommended
>> architectural sequences for the arm and thumb instruction sets.
>>
> Fedora picked up the series and it fails on arm:
>
> In file included from ./include/linux/compiler.h:242:0,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./include/uapi/linux/swab.h:6,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./include/linux/swab.h:5,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./arch/arm/include/asm/opcodes.h:89,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./arch/arm/include/asm/bug.h:7,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./include/linux/bug.h:5,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./include/linux/mmdebug.h:5,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./include/linux/gfp.h:5,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./include/linux/slab.h:15,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from kernel/fork.c:14:
> ./include/linux/fdtable.h: In function '__fcheck_files':
> ./arch/arm/include/asm/barrier.h:112:41: error: expected declaration specifiers or '...' before numeric constant
> Â __load_no_speculate(&__np_ptr, lo, hi, 0, __np_ptr);Â \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
> ./arch/arm/include/asm/barrier.h:68:32: note: in definition of macro '__load_no_speculate_n'
> ÂÂ (typeof(*ptr)(unsigned long)(failval));Â \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^~~~~~~
> ./arch/arm/include/asm/barrier.h:112:2: note: in expansion of macro '__load_no_speculate'
> Â __load_no_speculate(&__np_ptr, lo, hi, 0, __np_ptr);Â \
> Â ^~~~~~~~~~~~~~~~~~~
> ./include/asm-generic/barrier.h:122:2: note: in expansion of macro 'nospec_ptr'
> Â nospec_ptr(__arr + __idx, __arr, __arr + __sz);ÂÂ \
> Â ^~~~~~~~~~
> ./include/linux/fdtable.h:86:13: note: in expansion of macro 'nospec_array_ptr'
> Â if ((fdp = nospec_array_ptr(fdt->fd, fd, fdt->max_fds)))
> ÂÂÂÂÂÂÂÂÂÂÂÂ ^~~~~~~~~~~~~~~~
> ./arch/arm/include/asm/barrier.h:112:41: error: expected declaration specifiers or '...' before numeric constant
> Â __load_no_speculate(&__np_ptr, lo, hi, 0, __np_ptr);Â \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
> ./arch/arm/include/asm/barrier.h:68:32: note: in definition of macro '__load_no_speculate_n'
> ÂÂ (typeof(*ptr)(unsigned long)(failval));Â \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^~~~~~~
> ./arch/arm/include/asm/barrier.h:112:2: note: in expansion of macro '__load_no_speculate'
> Â __load_no_speculate(&__np_ptr, lo, hi, 0, __np_ptr);Â \
> Â ^~~~~~~~~~~~~~~~~~~
> ./include/asm-generic/barrier.h:122:2: note: in expansion of macro 'nospec_ptr'
> Â nospec_ptr(__arr + __idx, __arr, __arr + __sz);ÂÂ \
> Â ^~~~~~~~~~
> ./include/linux/fdtable.h:86:13: note: in expansion of macro 'nospec_array_ptr'
> Â if ((fdp = nospec_array_ptr(fdt->fd, fd, fdt->max_fds)))
> ÂÂÂÂÂÂÂÂÂÂÂÂ ^~~~~~~~~~~~~~~~
> ./arch/arm/include/asm/barrier.h:112:41: error: expected declaration specifiers or '...' before numeric constant
> Â __load_no_speculate(&__np_ptr, lo, hi, 0, __np_ptr);Â \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
> ./arch/arm/include/asm/barrier.h:68:32: note: in definition of macro '__load_no_speculate_n'
> ÂÂ (typeof(*ptr)(unsigned long)(failval));Â \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^~~~~~~
> ./arch/arm/include/asm/barrier.h:112:2: note: in expansion of macro '__load_no_speculate'
> Â __load_no_speculate(&__np_ptr, lo, hi, 0, __np_ptr);Â \
> Â ^~~~~~~~~~~~~~~~~~~
> ./include/asm-generic/barrier.h:122:2: note: in expansion of macro 'nospec_ptr'
> Â nospec_ptr(__arr + __idx, __arr, __arr + __sz);ÂÂ \
> Â ^~~~~~~~~~
> ./include/linux/fdtable.h:86:13: note: in expansion of macro 'nospec_array_ptr'
> Â if ((fdp = nospec_array_ptr(fdt->fd, fd, fdt->max_fds)))
>
> I can't puzzle out what exactly is the problem here, except that it really
> does not seem to like that failval. Does the arm compiler not like doing
> the typeof with the __arr + __idx?

>> +#define __load_no_speculate_n(ptr, lo, hi, failval, cmpptr, sz)ÂÂÂ \
>> +({ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂ typeof(*ptr) __nln_val;ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂ typeof(*ptr) __failval =ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂ (typeof(*ptr)(unsigned long)(failval));ÂÂÂÂÂÂÂ \

Just typo,

- (typeof(*ptr)(unsigned long)(failval)); \
+ (typeof(*ptr))(unsigned long)(failval); \

Please try it.

Thanks
Hanjun