Re: [PATCH] locking/atomics: don't alias ____ptr

From: Andrey Ryabinin
Date: Wed Jun 28 2017 - 09:58:44 EST




On 06/28/2017 04:20 PM, Thomas Gleixner wrote:
> On Wed, 28 Jun 2017, Sebastian Andrzej Siewior wrote:
>> On 2017-06-28 14:15:18 [+0300], Andrey Ryabinin wrote:
>>> The main problem here is that arch_cmpxchg64_local() calls cmpxhg_local() instead of using arch_cmpxchg_local().
>>>
>>> So, the patch bellow should fix the problem, also this will fix double instrumentation of cmpcxchg64[_local]().
>>> But I haven't tested this patch yet.
>>
>> tested, works. Next step?
>
> Check all other implementations in every architecture whether there is a
> similar problem .....
>

This and similar problems could have been caught by -Wshadow warning:

In file included from ../arch/x86/include/asm/atomic.h:282:0,
from ../include/linux/atomic.h:4,
from ../include/linux/jump_label.h:183,
from ../arch/x86/include/asm/string_64.h:5,
from ../arch/x86/include/asm/string.h:4,
from ../include/linux/string.h:18,
from ../include/linux/bitmap.h:8,
from ../drivers/iommu/intel-iommu.c:24:
../include/asm-generic/atomic-instrumented.h:376:18: warning: declaration of â____ptrâ shadows a previous local [-Wshadow]
__typeof__(ptr) ____ptr = (ptr); \
^
../arch/x86/include/asm/cmpxchg_64.h:18:2: note: in expansion of macro âcmpxchg_localâ
cmpxchg_local((ptr), (o), (n)); \
^
../include/asm-generic/atomic-instrumented.h:392:2: note: in expansion of macro âarch_cmpxchg64_localâ
arch_cmpxchg64_local(____ptr, (old), (new)); \
^
../drivers/iommu/intel-iommu.c:2290:9: note: in expansion of macro âcmpxchg64_localâ
tmp = cmpxchg64_local(&pte->val, 0ULL, pteval);
^
../include/asm-generic/atomic-instrumented.h:390:18: note: shadowed declaration is here
__typeof__(ptr) ____ptr = (ptr); \
^
../drivers/iommu/intel-iommu.c:2290:9: note: in expansion of macro âcmpxchg64_localâ
tmp = cmpxchg64_local(&pte->val, 0ULL, pteval);
^


But for some reason we use -Wshadow only on W=2 level.