[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160316081444.GB31133@gmail.com>
Date: Wed, 16 Mar 2016 09:14:44 +0100
From: Ingo Molnar <mingo@...nel.org>
To: Frederic Weisbecker <fweisbec@...il.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH v2] atomic: Fix bugs in 'fetch_or()' and rename it to
'xchg_or()'
* Frederic Weisbecker <fweisbec@...il.com> wrote:
> > diff --git a/include/linux/atomic.h b/include/linux/atomic.h
> > index 6c502cb13c95..7bc5297bcca8 100644
> > --- a/include/linux/atomic.h
> > +++ b/include/linux/atomic.h
> > @@ -549,22 +549,28 @@ static inline int atomic_dec_if_positive(atomic_t *v)
> > #endif
> >
> > /**
> > - * fetch_or - perform *ptr |= mask and return old value of *ptr
> > - * @ptr: pointer to value
> > + * xchg_or - perform *ptr |= mask atomically and return old value of *ptr
> > + * @ptr: pointer to value (cmpxchg() compatible integer pointer type)
> > * @mask: mask to OR on the value
> > *
> > - * cmpxchg based fetch_or, macro so it works for different integer types
> > + * cmpxchg() based, it's a macro so it works for different integer types.
> > */
> > -#ifndef fetch_or
> > -#define fetch_or(ptr, mask) \
> > -({ typeof(*(ptr)) __old, __val = *(ptr); \
> > +#ifndef xchg_or
> > +# define xchg_or(ptr, mask) \
> > +({ \
> > + typeof(ptr) _ptr = (ptr); \
>
> Can we add a comment above to prevent from future mistakes with cmpxchg
> variables aliasing?
>
> I'm suprised that GCC doesn't warn about that actually.
Yeah, so in the perf tooling build we do have -Wshadow to catch such mishaps,
but not in the main kernel build.
... and yes, if I add it via the patch below the bug gets warned about:
include/linux/atomic.h:561:15: note: shadowed declaration is here
typeof(ptr) __ptr = (ptr); \
^
kernel/sched/core.c:332:11: note: in expansion of macro ‘xchg_or’
return !(xchg_or(&ti->flags, _TIF_NEED_RESCHED) & _TIF_POLLING_NRFLA
... but I also get a ton of other warnings, just when building a single
kernel/sched/core.o file:
./arch/x86/include/asm/bitops.h:396:28: warning: declaration of ‘ffs’ shadows a built-in function [-Wshadow]
./arch/x86/include/asm/bitops.h:396:28: warning: declaration of ‘ffs’ shadows a built-in function [-Wshadow]
include/linux/jiffies.h:422:60: warning: declaration of ‘jiffies’ shadows a global declaration [-Wshadow]
./arch/x86/include/asm/io_apic.h:187:54: warning: declaration of ‘apic’ shadows a global declaration [-Wshadow]
./arch/x86/include/asm/bitops.h:396:28: warning: declaration of ‘ffs’ shadows a built-in function [-Wshadow]
include/linux/jiffies.h:422:60: warning: declaration of ‘jiffies’ shadows a global declaration [-Wshadow]
./arch/x86/include/asm/io_apic.h:187:54: warning: declaration of ‘apic’ shadows a global declaration [-Wshadow]
include/linux/kernel.h:750:12: warning: declaration of ‘_min1’ shadows a previous local [-Wshadow]
include/linux/kernel.h:750:12: warning: declaration of ‘_min1’ shadows a previous local [-Wshadow]
include/linux/kernel.h:751:12: warning: declaration of ‘_min2’ shadows a previous local [-Wshadow]
kernel/sched/sched.h:308:43: warning: declaration of ‘down’ shadows a global declaration [-Wshadow]
kernel/sched/sched.h:308:60: warning: declaration of ‘up’ shadows a global declaration [-Wshadow]
kernel/sched/auto_group.h:44:55: warning: declaration of ‘init_task’ shadows a global declaration [-Wshadow]
kernel/sched/core.c:635:20: warning: declaration of ‘down’ shadows a global declaration [-Wshadow]
kernel/sched/core.c:635:37: warning: declaration of ‘up’ shadows a global declaration [-Wshadow]
and yes, I'd say most of these are signatures of sloppy macros and sloppy variable
names - but it would be a ton of work to eliminate these warnings.
Thanks,
Ingo
==============>
Makefile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Makefile b/Makefile
index 7b3ecdcdc6c1..14b0ce82f2b0 100644
--- a/Makefile
+++ b/Makefile
@@ -776,6 +776,9 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=date-time)
# use the deterministic mode of AR if available
KBUILD_ARFLAGS := $(call ar-option,D)
+# enforce correct pointer usage
+KBUILD_CFLAGS += $(call cc-option,-Wshadow)
+
# check for 'asm goto'
ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC)), y)
KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
Powered by blists - more mailing lists