Skip to contentSkip to conversation

slub: fix check_bytes() for slub debugging

PATCH In review Akinobu Mita 4 participants 10 messages Aug 7, 2011 – Aug 9, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slub: fix check_bytes() for slub debugging

The check_bytes() function is used by slub debugging. It returns a pointer to the first unmatching byte for a character in the given memory area.

If the character for matching byte is greater than 0x80, check_bytes() doesn't work. Becuase 64-bit pattern is generated as below.

	value64 = value | value << 8 | value << 16 | value << 24;
	value64 = value64 | value64 << 32;

The integer promotions are performed and sign-extended as the type of value is u8. The upper 32 bits of value64 is 0xffffffff in the first line, and the second line has no effect.

This fixes the 64-bit pattern generation.

Cc Christoph Lameter <[email protected]>
Cc Pekka Enberg <[email protected]>
Cc Matt Mackall <[email protected]>
---
 mm/slub.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/slub.c +1 -1
index eb5a8f9..5695f92 100644
@@ -701,7 +701,7 @@ static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes)
 		return check_bytes8(start, value, bytes);
 
 	value64 = value | value << 8 | value << 16 | value << 24;
-	value64 = value64 | value64 << 32;
+	value64 = (value64 & 0xffffffff) | value64 << 32;
 	prefix = 8 - ((unsigned long)start) % 8;
 
 	if (prefix) {
Signature · 8 lines
1.7.4.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Akinobu Mita

The check_bytes() function is used by slub debugging. It returns a pointer to the first unmatching byte for a character in the given memory area.

If the character for matching byte is greater than 0x80, check_bytes() doesn't work. Becuase 64-bit pattern is generated as below.

Quoted 8 lines
	value64 = value | value << 8 | value << 16 | value << 24;
	value64 = value64 | value64 << 32;

The integer promotions are performed and sign-extended as the type of value is u8. The upper 32 bits of value64 is 0xffffffff in the first line, and the second line has no effect.

This fixes the 64-bit pattern generation.

Thank you. I'm a bit ashamed about this bug... I introduced this bug, so:

I tested your patch to check if performance improvements of commit c4089f98e943ff445665dea49c190657b34ccffe come from this bug or not. And forunately they aren't - performance is exactly the same.

How did you find it?

Marcin

#2 lore raw

2011/8/9 Marcin Slusarz <[email protected]>:

Quoted 3 lines

I tested your patch to check if performance improvements of commit c4089f98e943ff445665dea49c190657b34ccffe come from this bug or not. And forunately they aren't - performance is exactly the same.

That's good to know.

Quoted 1 line

How did you find it?

When I tried to reuse it in mm/debug-pagealloc.c, I realized that check_bytes() didn't work with 0xaa.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
In reply to Akinobu Mita

Le dimanche 07 aoA>>t 2011 A 18:30 +0900, Akinobu Mita a A(C)crit :

Quoted 29 lines

The check_bytes() function is used by slub debugging. It returns a pointer to the first unmatching byte for a character in the given memory area.

If the character for matching byte is greater than 0x80, check_bytes() doesn't work. Becuase 64-bit pattern is generated as below.

	value64 = value | value << 8 | value << 16 | value << 24;
	value64 = value64 | value64 << 32;

The integer promotions are performed and sign-extended as the type of value is u8. The upper 32 bits of value64 is 0xffffffff in the first line, and the second line has no effect.

This fixes the 64-bit pattern generation.

Cc Christoph Lameter <[email protected]>
Cc Pekka Enberg <[email protected]>
Cc Matt Mackall <[email protected]>
---
 mm/slub.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/slub.c +0 -0
index eb5a8f9..5695f92 100644

mm/slub.c static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes) · line 707

Quoted 8 lines
mm/slub.c +1 -1
@@ -701,7 +701,7 @@ static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes)
 		return check_bytes8(start, value, bytes);
 
 	value64 = value | value << 8 | value << 16 | value << 24;
-	value64 = value64 | value64 << 32;
+	value64 = (value64 & 0xffffffff) | value64 << 32;
 	prefix = 8 - ((unsigned long)start) % 8;
 
 	if (prefix) {

Still buggy I am afraid. Could we use the following ?

	value64 = value;
	value64 |= value64 << 8;
	value64 |= value64 << 16;
	value64 |= value64 << 32;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Le mardi 09 aoA>>t 2011 A 05:10 +0200, Eric Dumazet a A(C)crit :

Quoted 42 lines

Le dimanche 07 aoA>>t 2011 A 18:30 +0900, Akinobu Mita a A(C)crit :

Quoted 29 lines

The check_bytes() function is used by slub debugging. It returns a pointer to the first unmatching byte for a character in the given memory area.

If the character for matching byte is greater than 0x80, check_bytes() doesn't work. Becuase 64-bit pattern is generated as below.

	value64 = value | value << 8 | value << 16 | value << 24;
	value64 = value64 | value64 << 32;

The integer promotions are performed and sign-extended as the type of value is u8. The upper 32 bits of value64 is 0xffffffff in the first line, and the second line has no effect.

This fixes the 64-bit pattern generation.

Cc Christoph Lameter <[email protected]>
Cc Pekka Enberg <[email protected]>
Cc Matt Mackall <[email protected]>
---
 mm/slub.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/slub.c +0 -0
index eb5a8f9..5695f92 100644

mm/slub.c static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes) · line 707

Quoted 8 lines
mm/slub.c +1 -1
@@ -701,7 +701,7 @@ static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes)
 		return check_bytes8(start, value, bytes);
 
 	value64 = value | value << 8 | value << 16 | value << 24;
-	value64 = value64 | value64 << 32;
+	value64 = (value64 & 0xffffffff) | value64 << 32;
 	prefix = 8 - ((unsigned long)start) % 8;
 
 	if (prefix) {

Still buggy I am afraid. Could we use the following ?

Quoted 6 lines
	value64 = value;
	value64 |= value64 << 8;
	value64 |= value64 << 16;
	value64 |= value64 << 32;

Well, 'buggy' was not well chosen.

Another possibility would be to use a multiply if arch has a fast multiplier...

	value64 = value;
#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
	value64 *= 0x0101010101010101;
#elif defined(ARCH_HAS_FAST_MULTIPLIER)
	value64 *= 0x01010101;
	value64 |= value64 << 32;
#else
	value64 |= value64 << 8;
	value64 |= value64 << 16;
	value64 |= value64 << 32;

#endif

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

2011/8/9 Eric Dumazet <[email protected]>:

Quoted 37 lines
Quoted 17 lines

mm/slub.c static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes) · line 707

Quoted 13 lines
mm/slub.c +1 -1
index eb5a8f9..5695f92 100644
@@ -701,7 +701,7 @@ static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes)
             return check_bytes8(start, value, bytes);
 
     value64 = value | value << 8 | value << 16 | value << 24;
-   value64 = value64 | value64 << 32;
+   value64 = (value64 & 0xffffffff) | value64 << 32;
     prefix = 8 - ((unsigned long)start) % 8;
 
     if (prefix) {

Still buggy I am afraid. Could we use the following ?

Quoted 6 lines

      value64 = value;

      value64 |= value64 << 8;
      value64 |= value64 << 16;
      value64 |= value64 << 32;

Well, 'buggy' was not well chosen.

Another possibility would be to use a multiply if arch has a fast multiplier...

       value64 = value;
#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 value64 *= 0x0101010101010101;
#elif defined(ARCH_HAS_FAST_MULTIPLIER)
       value64 *= 0x01010101;
       value64 |= value64 << 32;
#else

Quoted 4 lines
       value64 |= value64 << 8;
       value64 |= value64 << 16;
       value64 |= value64 << 32;

#endif

I don't really care about which one should be used. So tell me if I need to resend it with this improvement.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
Quoted 44 lines · Akinobu Mita

2011/8/9 Eric Dumazet <[email protected]>:

Quoted 37 lines
Quoted 17 lines

mm/slub.c static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes) · line 707

Quoted 13 lines
mm/slub.c +1 -1
index eb5a8f9..5695f92 100644
@@ -701,7 +701,7 @@ static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes)
             return check_bytes8(start, value, bytes);
 
     value64 = value | value << 8 | value << 16 | value << 24;
-   value64 = value64 | value64 << 32;
+   value64 = (value64 & 0xffffffff) | value64 << 32;
     prefix = 8 - ((unsigned long)start) % 8;
 
     if (prefix) {

Still buggy I am afraid. Could we use the following ?

Quoted 6 lines

      value64 = value;

      value64 |= value64 << 8;
      value64 |= value64 << 16;
      value64 |= value64 << 32;

Well, 'buggy' was not well chosen.

Another possibility would be to use a multiply if arch has a fast multiplier...

       value64 = value;
#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 value64 *= 0x0101010101010101;
#elif defined(ARCH_HAS_FAST_MULTIPLIER)
       value64 *= 0x01010101;
       value64 |= value64 << 32;
#else

Quoted 4 lines
       value64 |= value64 << 8;
       value64 |= value64 << 16;
       value64 |= value64 << 32;

#endif

Quoted 2 lines

I don't really care about which one should be used.  So tell me if I need to resend it with this improvement.

I'm confused. What was wrong with your original patch?

Pekka

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw

Le mardi 09 aoA>>t 2011 A 12:43 +0300, Pekka Enberg a A(C)crit :

Quoted 2 lines

I'm confused. What was wrong with your original patch?

Patch is good. Some future improvements will follow.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
In reply to Akinobu Mita
Quoted 44 lines · Akinobu Mita

2011/8/9 Eric Dumazet <[email protected]>:

Quoted 40 lines
Quoted 17 lines

mm/slub.c static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes) · line 707

Quoted 13 lines
mm/slub.c +1 -1
index eb5a8f9..5695f92 100644
@@ -701,7 +701,7 @@ static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes)
            return check_bytes8(start, value, bytes);
 
    value64 = value | value << 8 | value << 16 | value << 24;
-   value64 = value64 | value64 << 32;
+   value64 = (value64 & 0xffffffff) | value64 << 32;
    prefix = 8 - ((unsigned long)start) % 8;
 
    if (prefix) {

Still buggy I am afraid. Could we use the following ?

Quoted 6 lines
      value64 = value;
      value64 |= value64 << 8;
      value64 |= value64 << 16;
      value64 |= value64 << 32;

Well, 'buggy' was not well chosen.

Another possibility would be to use a multiply if arch has a fast multiplier...

       value64 = value;
#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
       value64 *= 0x0101010101010101;
#elif defined(ARCH_HAS_FAST_MULTIPLIER)
       value64 *= 0x01010101;
       value64 |= value64 << 32;
#else
       value64 |= value64 << 8;
       value64 |= value64 << 16;
       value64 |= value64 << 32;
Quoted 1 line

#endif

Quoted 2 lines

I don't really care about which one should be used. So tell me if I need to resend it with this improvement.

It would be nice to fix all bugs while we review this code.

Lets push your patch and I'll submit a patch for next kernel.

For example, following code is suboptimal :

        prefix = 8 - ((unsigned long)start) % 8;

        if (prefix) {
                u8 *r = check_bytes8(start, value, prefix);
                if (r)
                        return r;
                start += prefix;
                bytes -= prefix;
        }

Since we always have prefix = 8 if 'start' is longword aligned, so we call check_bytes8() at least once with 8 bytes to compare...

Also, 32bit arches should be taken into account properly.

Oh well...

#9 lore raw
Quoted 65 lines · Eric Dumazet

Le mardi 09 aoA>>t 2011 A 18:38 +0900, Akinobu Mita a A(C)crit :

Quoted 44 lines

2011/8/9 Eric Dumazet <[email protected]>:

Quoted 40 lines
Quoted 17 lines

mm/slub.c static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes) · line 707

Quoted 13 lines
mm/slub.c +1 -1
index eb5a8f9..5695f92 100644
@@ -701,7 +701,7 @@ static u8 *check_bytes(u8 *start, u8 value, unsigned int bytes)
            return check_bytes8(start, value, bytes);
 
    value64 = value | value << 8 | value << 16 | value << 24;
-   value64 = value64 | value64 << 32;
+   value64 = (value64 & 0xffffffff) | value64 << 32;
    prefix = 8 - ((unsigned long)start) % 8;
 
    if (prefix) {

Still buggy I am afraid. Could we use the following ?

Quoted 6 lines
      value64 = value;
      value64 |= value64 << 8;
      value64 |= value64 << 16;
      value64 |= value64 << 32;

Well, 'buggy' was not well chosen.

Another possibility would be to use a multiply if arch has a fast multiplier...

       value64 = value;
#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
       value64 *= 0x0101010101010101;
#elif defined(ARCH_HAS_FAST_MULTIPLIER)
       value64 *= 0x01010101;
       value64 |= value64 << 32;
#else
       value64 |= value64 << 8;
       value64 |= value64 << 16;
       value64 |= value64 << 32;
Quoted 1 line

#endif

Quoted 2 lines

I don't really care about which one should be used. So tell me if I need to resend it with this improvement.

It would be nice to fix all bugs while we review this code.

Lets push your patch and I'll submit a patch for next kernel.

For example, following code is suboptimal :

        prefix = 8 - ((unsigned long)start) % 8;

        if (prefix) {
                u8 *r = check_bytes8(start, value, prefix);
                if (r)
                        return r;
                start += prefix;
                bytes -= prefix;
        }
Quoted 2 lines

Since we always have prefix = 8 if 'start' is longword aligned, so we call check_bytes8() at least once with 8 bytes to compare...

Yeah.

Quoted 1 line

Also, 32bit arches should be taken into account properly.

At least on x86_32 reading 8 bytes is faster than 4 (I benchmarked it - IIRC reading 8 bytes speeds up by a factor of ~5 and reading 4 only by ~3.5)

Marcin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>