* [PATCH] arch/powerpc: use BUILD_BUG() when detect unfit {cmp}xchg, size
@ 2016-02-23 8:45 Pan Xinhui
2016-02-23 9:15 ` Boqun Feng
0 siblings, 1 reply; 3+ messages in thread
From: Pan Xinhui @ 2016-02-23 8:45 UTC (permalink / raw)
To: linuxppc-dev, open list
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Boqun Feng, 'Peter Zijlstra (Intel)", Paul E. McKenney,
Thomas Gleixner
From: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
__xchg_called_with_bad_pointer() can't tell us what codes use {cmp}xchg
in incorrect way. And no error will be reported until the link stage.
To fix such kinds of issues in a easy way, we use BUILD_BUG() here.
Signed-off-by: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
---
arch/powerpc/include/asm/cmpxchg.h | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/arch/powerpc/include/asm/cmpxchg.h b/arch/powerpc/include/asm/cmpxchg.h
index d1a8d93..20c0a30 100644
--- a/arch/powerpc/include/asm/cmpxchg.h
+++ b/arch/powerpc/include/asm/cmpxchg.h
@@ -5,6 +5,7 @@
#include <linux/compiler.h>
#include <asm/synch.h>
#include <asm/asm-compat.h>
+#include <linux/bug.h>
/*
* Atomic exchange
@@ -92,12 +93,6 @@ __xchg_u64_local(volatile void *p, unsigned long val)
}
#endif
-/*
- * This function doesn't exist, so you'll get a linker error
- * if something tries to do an invalid xchg().
- */
-extern void __xchg_called_with_bad_pointer(void);
-
static __always_inline unsigned long
__xchg(volatile void *ptr, unsigned long x, unsigned int size)
{
@@ -109,7 +104,7 @@ __xchg(volatile void *ptr, unsigned long x, unsigned int size)
return __xchg_u64(ptr, x);
#endif
}
- __xchg_called_with_bad_pointer();
+ BUILD_BUG();
return x;
}
@@ -124,7 +119,7 @@ __xchg_local(volatile void *ptr, unsigned long x, unsigned int size)
return __xchg_u64_local(ptr, x);
#endif
}
- __xchg_called_with_bad_pointer();
+ BUILD_BUG();
return x;
}
#define xchg(ptr,x) \
@@ -235,10 +230,6 @@ __cmpxchg_u64_local(volatile unsigned long *p, unsigned long old,
}
#endif
-/* This function doesn't exist, so you'll get a linker error
- if something tries to do an invalid cmpxchg(). */
-extern void __cmpxchg_called_with_bad_pointer(void);
-
static __always_inline unsigned long
__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
unsigned int size)
@@ -251,7 +242,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
return __cmpxchg_u64(ptr, old, new);
#endif
}
- __cmpxchg_called_with_bad_pointer();
+ BUILD_BUG();
return old;
}
@@ -267,7 +258,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
return __cmpxchg_u64_local(ptr, old, new);
#endif
}
- __cmpxchg_called_with_bad_pointer();
+ BUILD_BUG();
return old;
}
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] arch/powerpc: use BUILD_BUG() when detect unfit {cmp}xchg, size
2016-02-23 8:45 [PATCH] arch/powerpc: use BUILD_BUG() when detect unfit {cmp}xchg, size Pan Xinhui
@ 2016-02-23 9:15 ` Boqun Feng
2016-02-23 10:39 ` Michael Ellerman
0 siblings, 1 reply; 3+ messages in thread
From: Boqun Feng @ 2016-02-23 9:15 UTC (permalink / raw)
To: Pan Xinhui
Cc: linuxppc-dev, open list, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, 'Peter Zijlstra (Intel)",
Paul E. McKenney, Thomas Gleixner
[-- Attachment #1: Type: text/plain, Size: 2959 bytes --]
On Tue, Feb 23, 2016 at 04:45:16PM +0800, Pan Xinhui wrote:
> From: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
>
> __xchg_called_with_bad_pointer() can't tell us what codes use {cmp}xchg
> in incorrect way. And no error will be reported until the link stage.
> To fix such kinds of issues in a easy way, we use BUILD_BUG() here.
>
> Signed-off-by: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
> ---
> arch/powerpc/include/asm/cmpxchg.h | 19 +++++--------------
> 1 file changed, 5 insertions(+), 14 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/cmpxchg.h b/arch/powerpc/include/asm/cmpxchg.h
> index d1a8d93..20c0a30 100644
> --- a/arch/powerpc/include/asm/cmpxchg.h
> +++ b/arch/powerpc/include/asm/cmpxchg.h
> @@ -5,6 +5,7 @@
> #include <linux/compiler.h>
> #include <asm/synch.h>
> #include <asm/asm-compat.h>
> +#include <linux/bug.h>
>
> /*
> * Atomic exchange
> @@ -92,12 +93,6 @@ __xchg_u64_local(volatile void *p, unsigned long val)
> }
> #endif
>
> -/*
> - * This function doesn't exist, so you'll get a linker error
> - * if something tries to do an invalid xchg().
> - */
> -extern void __xchg_called_with_bad_pointer(void);
> -
> static __always_inline unsigned long
> __xchg(volatile void *ptr, unsigned long x, unsigned int size)
> {
> @@ -109,7 +104,7 @@ __xchg(volatile void *ptr, unsigned long x, unsigned int size)
> return __xchg_u64(ptr, x);
> #endif
> }
> - __xchg_called_with_bad_pointer();
> + BUILD_BUG();
Maybe we can use BUILD_BUG_ON_MSG(1, "Unsupported size for xchg"), which
could provide more information.
With or without this verbosity:
Acked-by: Boqun Feng <boqun.feng@gmail.com>
Regards,
Boqun
> return x;
> }
>
> @@ -124,7 +119,7 @@ __xchg_local(volatile void *ptr, unsigned long x, unsigned int size)
> return __xchg_u64_local(ptr, x);
> #endif
> }
> - __xchg_called_with_bad_pointer();
> + BUILD_BUG();
> return x;
> }
> #define xchg(ptr,x) \
> @@ -235,10 +230,6 @@ __cmpxchg_u64_local(volatile unsigned long *p, unsigned long old,
> }
> #endif
>
> -/* This function doesn't exist, so you'll get a linker error
> - if something tries to do an invalid cmpxchg(). */
> -extern void __cmpxchg_called_with_bad_pointer(void);
> -
> static __always_inline unsigned long
> __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
> unsigned int size)
> @@ -251,7 +242,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
> return __cmpxchg_u64(ptr, old, new);
> #endif
> }
> - __cmpxchg_called_with_bad_pointer();
> + BUILD_BUG();
> return old;
> }
>
> @@ -267,7 +258,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
> return __cmpxchg_u64_local(ptr, old, new);
> #endif
> }
> - __cmpxchg_called_with_bad_pointer();
> + BUILD_BUG();
> return old;
> }
>
> --
> 2.5.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] arch/powerpc: use BUILD_BUG() when detect unfit {cmp}xchg, size
2016-02-23 9:15 ` Boqun Feng
@ 2016-02-23 10:39 ` Michael Ellerman
0 siblings, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2016-02-23 10:39 UTC (permalink / raw)
To: Boqun Feng, Pan Xinhui
Cc: linuxppc-dev, open list, Benjamin Herrenschmidt, Paul Mackerras,
'Peter Zijlstra (Intel)", Paul E. McKenney,
Thomas Gleixner
On Tue, 2016-02-23 at 17:15 +0800, Boqun Feng wrote:
> On Tue, Feb 23, 2016 at 04:45:16PM +0800, Pan Xinhui wrote:
> > From: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
> >
> > diff --git a/arch/powerpc/include/asm/cmpxchg.h b/arch/powerpc/include/asm/cmpxchg.h
> > index d1a8d93..20c0a30 100644
> > --- a/arch/powerpc/include/asm/cmpxchg.h
> > +++ b/arch/powerpc/include/asm/cmpxchg.h
> > @@ -92,12 +93,6 @@ __xchg_u64_local(volatile void *p, unsigned long val)
> > }
> > #endif
> >
> > -/*
> > - * This function doesn't exist, so you'll get a linker error
> > - * if something tries to do an invalid xchg().
> > - */
> > -extern void __xchg_called_with_bad_pointer(void);
> > -
> > static __always_inline unsigned long
> > __xchg(volatile void *ptr, unsigned long x, unsigned int size)
> > {
> > @@ -109,7 +104,7 @@ __xchg(volatile void *ptr, unsigned long x, unsigned int size)
> > return __xchg_u64(ptr, x);
> > #endif
> > }
> > - __xchg_called_with_bad_pointer();
> > + BUILD_BUG();
>
> Maybe we can use BUILD_BUG_ON_MSG(1, "Unsupported size for xchg"), which
> could provide more information.
Yes I would prefer there was a message. Please send a v2.
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-23 10:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-23 8:45 [PATCH] arch/powerpc: use BUILD_BUG() when detect unfit {cmp}xchg, size Pan Xinhui
2016-02-23 9:15 ` Boqun Feng
2016-02-23 10:39 ` Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).