linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* + fls-change-parameter-to-unsigned-int.patch added to -mm tree
@ 2018-11-05 23:33 akpm
  2018-11-06 15:14 ` Alexey Dobriyan
  0 siblings, 1 reply; 7+ messages in thread
From: akpm @ 2018-11-05 23:33 UTC (permalink / raw)
  To: mm-commits, tglx, linux-arch, willy


The patch titled
     Subject: fls: change parameter to unsigned int
has been added to the -mm tree.  Its filename is
     fls-change-parameter-to-unsigned-int.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/fls-change-parameter-to-unsigned-int.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/fls-change-parameter-to-unsigned-int.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Matthew Wilcox <willy@infradead.org>
Subject: fls: change parameter to unsigned int

When testing in userspace, UBSAN pointed out that shifting into the sign
bit is undefined behaviour.  It doesn't really make sense to ask for the
highest set bit of a negative value, so just turn the argument type into
an unsigned int.

Some architectures (eg ppc) already had it declared as an unsigned int, so
I don't expect too many problems.

Link: http://lkml.kernel.org/r/20181105221117.31828-1-willy@infradead.org
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 arch/alpha/include/asm/bitops.h          |    4 ++--
 arch/arc/include/asm/bitops.h            |    4 ++--
 arch/c6x/include/asm/bitops.h            |    2 +-
 arch/csky/include/asm/bitops.h           |    2 +-
 arch/hexagon/include/asm/bitops.h        |    2 +-
 arch/ia64/include/asm/bitops.h           |    3 +--
 arch/m68k/include/asm/bitops.h           |    2 +-
 arch/mips/include/asm/bitops.h           |    2 +-
 arch/openrisc/include/asm/bitops/fls.h   |    2 +-
 arch/parisc/include/asm/bitops.h         |    2 +-
 arch/s390/include/asm/bitops.h           |    4 ++--
 arch/unicore32/include/asm/bitops.h      |    2 +-
 arch/x86/include/asm/bitops.h            |    2 +-
 include/asm-generic/bitops/builtin-fls.h |    2 +-
 include/asm-generic/bitops/fls.h         |    2 +-
 tools/include/asm-generic/bitops/fls.h   |    2 +-
 16 files changed, 19 insertions(+), 20 deletions(-)

--- a/arch/alpha/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/alpha/include/asm/bitops.h
@@ -391,9 +391,9 @@ static inline unsigned long __fls(unsign
 	return fls64(x) - 1;
 }
 
-static inline int fls(int x)
+static inline int fls(unsigned int x)
 {
-	return fls64((unsigned int) x);
+	return fls64(x);
 }
 
 /*
--- a/arch/arc/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/arc/include/asm/bitops.h
@@ -278,7 +278,7 @@ static inline __attribute__ ((const)) in
 	return res;
 }
 
-static inline int constant_fls(int x)
+static inline int constant_fls(unsigned int x)
 {
 	int r = 32;
 
@@ -312,7 +312,7 @@ static inline int constant_fls(int x)
  * @result: [1-32]
  * fls(1) = 1, fls(0x80000000) = 32, fls(0) = 0
  */
-static inline __attribute__ ((const)) int fls(unsigned long x)
+static inline __attribute__ ((const)) int fls(unsigned int x)
 {
 	if (__builtin_constant_p(x))
 	       return constant_fls(x);
--- a/arch/c6x/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/c6x/include/asm/bitops.h
@@ -54,7 +54,7 @@ static inline unsigned long __ffs(unsign
  * This is defined the same way as ffs.
  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  */
-static inline int fls(int x)
+static inline int fls(unsigned int x)
 {
 	if (!x)
 		return 0;
--- a/arch/csky/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/csky/include/asm/bitops.h
@@ -40,7 +40,7 @@ static __always_inline unsigned long __f
 /*
  * asm-generic/bitops/fls.h
  */
-static __always_inline int fls(int x)
+static __always_inline int fls(unsigned int x)
 {
 	asm volatile(
 		"ff1 %0\n"
--- a/arch/hexagon/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/hexagon/include/asm/bitops.h
@@ -211,7 +211,7 @@ static inline long ffz(int x)
  * This is defined the same way as ffs.
  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  */
-static inline int fls(int x)
+static inline int fls(unsigned int x)
 {
 	int r;
 
--- a/arch/ia64/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/ia64/include/asm/bitops.h
@@ -388,8 +388,7 @@ ia64_fls (unsigned long x)
  * Find the last (most significant) bit set.  Returns 0 for x==0 and
  * bits are numbered from 1..32 (e.g., fls(9) == 4).
  */
-static inline int
-fls (int t)
+static inline int fls(unsigned int t)
 {
 	unsigned long x = t & 0xffffffffu;
 
--- a/arch/m68k/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/m68k/include/asm/bitops.h
@@ -502,7 +502,7 @@ static inline unsigned long __ffs(unsign
 /*
  *	fls: find last bit set.
  */
-static inline int fls(int x)
+static inline int fls(unsigned int x)
 {
 	int cnt;
 
--- a/arch/mips/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/mips/include/asm/bitops.h
@@ -541,7 +541,7 @@ static inline unsigned long __ffs(unsign
  * This is defined the same way as ffs.
  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  */
-static inline int fls(int x)
+static inline int fls(unsigned int x)
 {
 	int r;
 
--- a/arch/openrisc/include/asm/bitops/fls.h~fls-change-parameter-to-unsigned-int
+++ a/arch/openrisc/include/asm/bitops/fls.h
@@ -15,7 +15,7 @@
 
 #ifdef CONFIG_OPENRISC_HAVE_INST_FL1
 
-static inline int fls(int x)
+static inline int fls(unsigned int x)
 {
 	int ret;
 
--- a/arch/parisc/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/parisc/include/asm/bitops.h
@@ -188,7 +188,7 @@ static __inline__ int ffs(int x)
  * fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  */
 
-static __inline__ int fls(int x)
+static __inline__ int fls(unsigned int x)
 {
 	int ret;
 	if (!x)
--- a/arch/s390/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/s390/include/asm/bitops.h
@@ -397,9 +397,9 @@ static inline int fls64(unsigned long wo
  * This is defined the same way as ffs.
  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  */
-static inline int fls(int word)
+static inline int fls(unsigned int word)
 {
-	return fls64((unsigned int)word);
+	return fls64(word);
 }
 
 #else /* CONFIG_HAVE_MARCH_Z9_109_FEATURES */
--- a/arch/unicore32/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/unicore32/include/asm/bitops.h
@@ -22,7 +22,7 @@
  * the cntlz instruction for much better code efficiency.
  */
 
-static inline int fls(int x)
+static inline int fls(unsigned int x)
 {
 	int ret;
 
--- a/arch/x86/include/asm/bitops.h~fls-change-parameter-to-unsigned-int
+++ a/arch/x86/include/asm/bitops.h
@@ -448,7 +448,7 @@ static __always_inline int ffs(int x)
  * set bit if value is nonzero. The last (most significant) bit is
  * at position 32.
  */
-static __always_inline int fls(int x)
+static __always_inline int fls(unsigned int x)
 {
 	int r;
 
--- a/include/asm-generic/bitops/builtin-fls.h~fls-change-parameter-to-unsigned-int
+++ a/include/asm-generic/bitops/builtin-fls.h
@@ -9,7 +9,7 @@
  * This is defined the same way as ffs.
  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  */
-static __always_inline int fls(int x)
+static __always_inline int fls(unsigned int x)
 {
 	return x ? sizeof(x) * 8 - __builtin_clz(x) : 0;
 }
--- a/include/asm-generic/bitops/fls.h~fls-change-parameter-to-unsigned-int
+++ a/include/asm-generic/bitops/fls.h
@@ -10,7 +10,7 @@
  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  */
 
-static __always_inline int fls(int x)
+static __always_inline int fls(unsigned int x)
 {
 	int r = 32;
 
--- a/tools/include/asm-generic/bitops/fls.h~fls-change-parameter-to-unsigned-int
+++ a/tools/include/asm-generic/bitops/fls.h
@@ -10,7 +10,7 @@
  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  */
 
-static __always_inline int fls(int x)
+static __always_inline int fls(unsigned int x)
 {
 	int r = 32;
 
_

Patches currently in -mm which might be from willy@infradead.org are

fls-change-parameter-to-unsigned-int.patch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + fls-change-parameter-to-unsigned-int.patch added to -mm tree
  2018-11-05 23:33 + fls-change-parameter-to-unsigned-int.patch added to -mm tree akpm
@ 2018-11-06 15:14 ` Alexey Dobriyan
  2018-11-06 15:14   ` Alexey Dobriyan
  2018-11-06 15:44   ` Matthew Wilcox
  0 siblings, 2 replies; 7+ messages in thread
From: Alexey Dobriyan @ 2018-11-06 15:14 UTC (permalink / raw)
  To: willy; +Cc: linux-kernel, tglx, linux-arch

On Mon, Nov 05, 2018 at 03:33:01PM -0800, akpm@linux-foundation.org wrote:

> -static inline int fls(int x)
> +static inline int fls(unsigned int x)
>  {
> -	return fls64((unsigned int) x);
> +	return fls64(x);
>  }

Should it return "unsigned"? Logically it should.
I remember doing this and there was some code size increase :-(

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + fls-change-parameter-to-unsigned-int.patch added to -mm tree
  2018-11-06 15:14 ` Alexey Dobriyan
@ 2018-11-06 15:14   ` Alexey Dobriyan
  2018-11-06 15:44   ` Matthew Wilcox
  1 sibling, 0 replies; 7+ messages in thread
From: Alexey Dobriyan @ 2018-11-06 15:14 UTC (permalink / raw)
  To: willy; +Cc: linux-kernel, tglx, linux-arch

On Mon, Nov 05, 2018 at 03:33:01PM -0800, akpm@linux-foundation.org wrote:

> -static inline int fls(int x)
> +static inline int fls(unsigned int x)
>  {
> -	return fls64((unsigned int) x);
> +	return fls64(x);
>  }

Should it return "unsigned"? Logically it should.
I remember doing this and there was some code size increase :-(

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + fls-change-parameter-to-unsigned-int.patch added to -mm tree
  2018-11-06 15:14 ` Alexey Dobriyan
  2018-11-06 15:14   ` Alexey Dobriyan
@ 2018-11-06 15:44   ` Matthew Wilcox
  2018-11-06 15:44     ` Matthew Wilcox
  2018-11-06 17:01     ` Alexey Dobriyan
  1 sibling, 2 replies; 7+ messages in thread
From: Matthew Wilcox @ 2018-11-06 15:44 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel, tglx, linux-arch

On Tue, Nov 06, 2018 at 06:14:44PM +0300, Alexey Dobriyan wrote:
> On Mon, Nov 05, 2018 at 03:33:01PM -0800, akpm@linux-foundation.org wrote:
> 
> > -static inline int fls(int x)
> > +static inline int fls(unsigned int x)
> >  {
> > -	return fls64((unsigned int) x);
> > +	return fls64(x);
> >  }
> 
> Should it return "unsigned"? Logically it should.
> I remember doing this and there was some code size increase :-(

Yes, it returns a number in the range [0-32], so it can absolutely
be unsigned.  I'm kind of surprised it made any difference.

When you say "doing this", what did you try?  unsigned fls(unsigned),
int fls(unsigned) or unsigned fls(int) ?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + fls-change-parameter-to-unsigned-int.patch added to -mm tree
  2018-11-06 15:44   ` Matthew Wilcox
@ 2018-11-06 15:44     ` Matthew Wilcox
  2018-11-06 17:01     ` Alexey Dobriyan
  1 sibling, 0 replies; 7+ messages in thread
From: Matthew Wilcox @ 2018-11-06 15:44 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel, tglx, linux-arch

On Tue, Nov 06, 2018 at 06:14:44PM +0300, Alexey Dobriyan wrote:
> On Mon, Nov 05, 2018 at 03:33:01PM -0800, akpm@linux-foundation.org wrote:
> 
> > -static inline int fls(int x)
> > +static inline int fls(unsigned int x)
> >  {
> > -	return fls64((unsigned int) x);
> > +	return fls64(x);
> >  }
> 
> Should it return "unsigned"? Logically it should.
> I remember doing this and there was some code size increase :-(

Yes, it returns a number in the range [0-32], so it can absolutely
be unsigned.  I'm kind of surprised it made any difference.

When you say "doing this", what did you try?  unsigned fls(unsigned),
int fls(unsigned) or unsigned fls(int) ?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + fls-change-parameter-to-unsigned-int.patch added to -mm tree
  2018-11-06 15:44   ` Matthew Wilcox
  2018-11-06 15:44     ` Matthew Wilcox
@ 2018-11-06 17:01     ` Alexey Dobriyan
  2018-11-06 17:01       ` Alexey Dobriyan
  1 sibling, 1 reply; 7+ messages in thread
From: Alexey Dobriyan @ 2018-11-06 17:01 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: linux-kernel, tglx, linux-arch

On Tue, Nov 06, 2018 at 07:44:37AM -0800, Matthew Wilcox wrote:
> On Tue, Nov 06, 2018 at 06:14:44PM +0300, Alexey Dobriyan wrote:
> > On Mon, Nov 05, 2018 at 03:33:01PM -0800, akpm@linux-foundation.org wrote:
> > 
> > > -static inline int fls(int x)
> > > +static inline int fls(unsigned int x)
> > >  {
> > > -	return fls64((unsigned int) x);
> > > +	return fls64(x);
> > >  }
> > 
> > Should it return "unsigned"? Logically it should.
> > I remember doing this and there was some code size increase :-(
> 
> Yes, it returns a number in the range [0-32], so it can absolutely
> be unsigned.  I'm kind of surprised it made any difference.
> 
> When you say "doing this", what did you try?  unsigned fls(unsigned),
> int fls(unsigned) or unsigned fls(int) ?

I did "unsigned fls()" with and without

	if (rv > 32)
		__builtin_unreachable();

but I didn't send anything because there was something erratic with code
generation.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: + fls-change-parameter-to-unsigned-int.patch added to -mm tree
  2018-11-06 17:01     ` Alexey Dobriyan
@ 2018-11-06 17:01       ` Alexey Dobriyan
  0 siblings, 0 replies; 7+ messages in thread
From: Alexey Dobriyan @ 2018-11-06 17:01 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: linux-kernel, tglx, linux-arch

On Tue, Nov 06, 2018 at 07:44:37AM -0800, Matthew Wilcox wrote:
> On Tue, Nov 06, 2018 at 06:14:44PM +0300, Alexey Dobriyan wrote:
> > On Mon, Nov 05, 2018 at 03:33:01PM -0800, akpm@linux-foundation.org wrote:
> > 
> > > -static inline int fls(int x)
> > > +static inline int fls(unsigned int x)
> > >  {
> > > -	return fls64((unsigned int) x);
> > > +	return fls64(x);
> > >  }
> > 
> > Should it return "unsigned"? Logically it should.
> > I remember doing this and there was some code size increase :-(
> 
> Yes, it returns a number in the range [0-32], so it can absolutely
> be unsigned.  I'm kind of surprised it made any difference.
> 
> When you say "doing this", what did you try?  unsigned fls(unsigned),
> int fls(unsigned) or unsigned fls(int) ?

I did "unsigned fls()" with and without

	if (rv > 32)
		__builtin_unreachable();

but I didn't send anything because there was something erratic with code
generation.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-11-07  2:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-05 23:33 + fls-change-parameter-to-unsigned-int.patch added to -mm tree akpm
2018-11-06 15:14 ` Alexey Dobriyan
2018-11-06 15:14   ` Alexey Dobriyan
2018-11-06 15:44   ` Matthew Wilcox
2018-11-06 15:44     ` Matthew Wilcox
2018-11-06 17:01     ` Alexey Dobriyan
2018-11-06 17:01       ` Alexey Dobriyan

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).