slab: fix and cleanup of slub_debug
Subsystems (2)
cover slab: fix and cleanup of slub_debug
Hello,
This series includes minor fix and cleanup of slub_debug, please see the commits for details.
---
Chengming Zhou (3):
slab: check the return value of check_bytes_and_report()
slab: don't put freepointer outside of object if only orig_size
slab: delete useless RED_INACTIVE and RED_ACTIVE
include/linux/poison.h | 7 ++----- mm/slub.c | 11 ++++++----- tools/include/linux/poison.h | 7 ++----- 3 files changed, 10 insertions(+), 15 deletions(-)
---
base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0
change-id: 20240528-b4-slab-debug-1d8179fc996a
Best regards,
Signature · 1 line
Chengming Zhou <[email protected]>
PATCH 1/3 slab: check the return value of check_bytes_and_report()
All check_bytes_and_report() callers have checked its return value except for this one. We should also check its return value here obviously, so fix it.
--- mm/slub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/slub.c +3 -2
@@ -1324,9 +1324,10 @@ static int check_object(struct kmem_cache *s, struct slab *slab, } }else {if ((s->flags &SLAB_POISON ) && s->object_size < s->inuse) { -check_bytes_and_report (s, slab, p,"Alignment padding" , +if (!check_bytes_and_report (s, slab, p,"Alignment padding" , endobject,POISON_INUSE , - s->inuse - s->object_size); + s->inuse - s->object_size)) +return 0 ; } }
Signature · 1 line
2.45.1
Christoph Lameter (Ampere)
reviewerRe: [PATCH 1/3] slab: check the return value of check_bytes_and_report()
Quoted 6 lines · Chengming Zhou
mm/slub.c +0
-0@@ -1324,9 +1324,10 @@ static int check_object(struct kmem_cache *s, struct slab *slab, }
mm/slub.c static int check_object(struct kmem_cache *s, struct slab *slab, · line 1332
Quoted 10 lines
mm/slub.c +3
-2}else {if ((s->flags &SLAB_POISON ) && s->object_size < s->inuse) { -check_bytes_and_report (s, slab, p,"Alignment padding" , +if (!check_bytes_and_report (s, slab, p,"Alignment padding" , endobject,POISON_INUSE , - s->inuse - s->object_size); + s->inuse - s->object_size)) +return 0 ; } }
This change means we will then skip the rest of the checks in check_object() such as the poison check.
Re: [PATCH 1/3] slab: check the return value of check_bytes_and_report()
Quoted 12 lines · Christoph Lameter (Ampere)
Quoted 10 lines · Chengming Zhou
mm/slub.c +1
-1@@ -1324,9 +1324,10 @@ static int check_object(struct kmem_cache *s, struct slab *slab, } } else { if ((s->flags & SLAB_POISON) && s->object_size < s->inuse) { - check_bytes_and_report(s, slab, p, "Alignment padding", + if (!check_bytes_and_report(s, slab, p, "Alignment padding",
Quoted 8 lines
mm/slub.c static int check_object(struct kmem_cache *s, struct slab *slab, · line 1332
Quoted 6 lines
mm/slub.c +2
-1endobject, POISON_INUSE, - s->inuse - s->object_size); + s->inuse - s->object_size)) + return 0; } }This change means we will then skip the rest of the checks in
check_object()such as the poison check.
Yeah, only when this padding checking failed.
Now, we always abort checking and return 0 when the first checking error happens, such as redzones checking above.
Thanks.
Re: [PATCH 1/3] slab: check the return value of check_bytes_and_report()
Quoted 22 lines · Chengming Zhou
Quoted 12 lines · Christoph Lameter (Ampere)
Quoted 10 lines · Chengming Zhou
mm/slub.c +1
-1@@ -1324,9 +1324,10 @@ static int check_object(struct kmem_cache *s, struct slab *slab, } } else { if ((s->flags & SLAB_POISON) && s->object_size < s->inuse) { - check_bytes_and_report(s, slab, p, "Alignment padding", + if (!check_bytes_and_report(s, slab, p, "Alignment padding",Quoted 8 lines
mm/slub.c static int check_object(struct kmem_cache *s, struct slab *slab, · line 1332
Quoted 6 lines
mm/slub.c +2
-1endobject, POISON_INUSE, - s->inuse - s->object_size); + s->inuse - s->object_size)) + return 0; } }This change means we will then skip the rest of the checks in
check_object()such as the poison check.
Quoted 4 lines
Yeah, only when this padding checking failed.
Now, we always abort checking and return 0 when the first checking error happens, such as redzones checking above.
Yes your patch will make it consistent. But IMHO it would be better to do all the checks without skipping, report their specific error findings in check_bytes_and_report() but not print_trailer(). Once all checks were done, if any found an error, print the trailer once from check_object(). Thoughts?
Quoted 1 line
Thanks.
Re: [PATCH 1/3] slab: check the return value of check_bytes_and_report()
Quoted 25 lines · Vlastimil Babka
Quoted 24 lines · Chengming Zhou
Quoted 12 lines · Christoph Lameter (Ampere)
Quoted 10 lines · Chengming Zhou
mm/slub.c +1
-1@@ -1324,9 +1324,10 @@ static int check_object(struct kmem_cache *s, struct slab *slab, } } else { if ((s->flags & SLAB_POISON) && s->object_size < s->inuse) { - check_bytes_and_report(s, slab, p, "Alignment padding", + if (!check_bytes_and_report(s, slab, p, "Alignment padding",Quoted 8 lines
mm/slub.c static int check_object(struct kmem_cache *s, struct slab *slab, · line 1332
Quoted 6 lines
mm/slub.c +2
-1endobject, POISON_INUSE, - s->inuse - s->object_size); + s->inuse - s->object_size)) + return 0; } }This change means we will then skip the rest of the checks in
check_object()such as the poison check.Yeah, only when this padding checking failed.
Quoted 7 lines
Quoted 2 lines
Now, we always abort checking and return 0 when the first checking error happens, such as redzones checking above.
Yes your patch will make it consistent. But IMHO it would be better to do all the checks without skipping, report their specific error findings in
check_bytes_and_report()but notprint_trailer(). Once all checks were done, if any found an error, print the trailer once fromcheck_object(). Thoughts?
Ok, it's feasible, will change to this.
Quoted 3 lines
Quoted 2 lines
Thanks.
PATCH 2/3 slab: don't put freepointer outside of object if only orig_size
In reply to Chengming ZhouThe commit 946fa0dbf2d8 ("mm/slub: extend redzone check to extra allocated kmalloc space than requested") will extend right redzone when allocating for orig_size < object_size. So we can't overlay the freepointer in the object space in this case.
But the code looks like it forgot to check SLAB_RED_ZONE, since there won't be extended right redzone if only orig_size enabled.
--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c +1 -1
@@ -5150,7 +5150,7 @@ static int calculate_sizes(struct kmem_cache *s)*/ s->inuse = size; -if (slub_debug_orig_size (s) || +if (((flags &SLAB_RED_ZONE ) &&slub_debug_orig_size (s)) || (flags & (SLAB_TYPESAFE_BY_RCU |SLAB_POISON )) || ((flags &SLAB_RED_ZONE ) && s->object_size <sizeof (void *)) || s->ctor) {
Signature · 1 line
2.45.1
Re: [PATCH 2/3] slab: don't put freepointer outside of object if only orig_size
Quoted 7 lines · Chengming Zhou
The commit
946fa0dbf2d8("mm/slub: extend redzone check to extra allocated kmalloc space than requested") will extend right redzone when allocating fororig_size<object_size. So we can't overlay the freepointer in the object space in this case.But the code looks like it forgot to check
SLAB_RED_ZONE, since there won't be extended right redzone if onlyorig_sizeenabled.
Look good to me. Thanks!
Quoted 23 lines
Signed-off-by Chengming Zhou <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +1
-1@@ -5150,7 +5150,7 @@ static int calculate_sizes(struct kmem_cache *s)*/ s->inuse = size; -if (slub_debug_orig_size (s) || +if (((flags &SLAB_RED_ZONE ) &&slub_debug_orig_size (s)) || (flags & (SLAB_TYPESAFE_BY_RCU |SLAB_POISON )) || ((flags &SLAB_RED_ZONE ) && s->object_size <sizeof (void *)) || s->ctor) {Signature · 2 lines
-- 2.45.1
Re: [PATCH 2/3] slab: don't put freepointer outside of object if only orig_size
In reply to Chengming ZhouQuoted 9 lines · Chengming Zhou
The commit
946fa0dbf2d8("mm/slub: extend redzone check to extra allocated kmalloc space than requested") will extend right redzone when allocating fororig_size<object_size. So we can't overlay the freepointer in the object space in this case.But the code looks like it forgot to check
SLAB_RED_ZONE, since there won't be extended right redzone if onlyorig_sizeenabled.Signed-off-by Chengming Zhou <[email protected]>
Seems OK.
Quoted 9 lines
--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0
mm/slub.c static int calculate_sizes(struct kmem_cache *s) · line 5155
Quoted 7 lines
mm/slub.c +1
-1@@ -5150,7 +5150,7 @@ static int calculate_sizes(struct kmem_cache *s)*/ s->inuse = size; - if (slub_debug_orig_size(s) || + if (((flags & SLAB_RED_ZONE) && slub_debug_orig_size(s)) || (flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON)) || ((flags & SLAB_RED_ZONE) && s->object_size < sizeof(void *)) ||
Should we consolidate the two cases with flags & SLAB_RED_ZONE?
Also below this is a comment that could also mention the slub_debug_orig_size().
Quoted 2 lines
mm/slub.c +0
-0s->ctor) {
Re: [PATCH 2/3] slab: don't put freepointer outside of object if only orig_size
Quoted 25 lines · Vlastimil Babka
Quoted 9 lines · Chengming Zhou
The commit
946fa0dbf2d8("mm/slub: extend redzone check to extra allocated kmalloc space than requested") will extend right redzone when allocating fororig_size<object_size. So we can't overlay the freepointer in the object space in this case.But the code looks like it forgot to check
SLAB_RED_ZONE, since there won't be extended right redzone if onlyorig_sizeenabled.Signed-off-by Chengming Zhou <[email protected]>Seems OK.
Quoted 12 lines
--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0@@ -5150,7 +5150,7 @@ static int calculate_sizes(struct kmem_cache *s)*/ s->inuse = size;
Quoted 6 lines
mm/slub.c static int calculate_sizes(struct kmem_cache *s) · line 5155
Quoted 4 lines
mm/slub.c +1
-1- if (slub_debug_orig_size(s) || + if (((flags & SLAB_RED_ZONE) && slub_debug_orig_size(s)) || (flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON)) || ((flags & SLAB_RED_ZONE) && s->object_size < sizeof(void *)) ||Should we consolidate the two cases with flags &
SLAB_RED_ZONE?
Yes, we can.
Quoted 2 lines
Also below this is a comment that could also mention the
slub_debug_orig_size().
Ok, will add.
Thanks.
Quoted 4 lines
Quoted 3 lines
mm/slub.c +0
-0s->ctor) {
PATCH 3/3 slab: delete useless RED_INACTIVE and RED_ACTIVE
In reply to Chengming ZhouThese seem useless since we use the SLUB_RED_INACTIVE and SLUB_RED_ACTIVE, so just delete them, no functional change.
--- include/linux/poison.h | 7 ++----- mm/slub.c | 4 ++-- tools/include/linux/poison.h | 7 ++----- 3 files changed, 6 insertions(+), 12 deletions(-)
include/linux/poison.h +2 -5
@@ -38,11 +38,8 @@* Magic nums for obj red zoning. * Placed in the first word before and the first word after an obj. */ -#define RED_INACTIVE 0x09F911029D74E35BULL/* when obj is inactive */ -#define RED_ACTIVE 0xD84156C5635688C0ULL/* when obj is active */ - -#define SLUB_RED_INACTIVE 0xbb -#define SLUB_RED_ACTIVE 0xcc +#define SLUB_RED_INACTIVE 0xbb/* when obj is inactive */ +#define SLUB_RED_ACTIVE 0xcc/* when obj is active */ /* ...and for poisoning */ #define POISON_INUSE 0x5a/* for use-uninitialised poisoning */
mm/slub.c +2 -2
@@ -1216,8 +1216,8 @@ static int check_bytes_and_report(struct kmem_cache *s, struct slab *slab,* Padding is extended by another word if Redzoning is enabled and * object_size == inuse. * -* We fill with 0xbb (RED_INACTIVE) for inactive objects and with -* 0xcc (RED_ACTIVE) for objects in use. +* We fill with 0xbb (SLUB_RED_INACTIVE) for inactive objects and with +* 0xcc (SLUB_RED_ACTIVE) for objects in use. * * object + s->inuse * Meta data starts here.
tools/include/linux/poison.h +2 -5
@@ -47,11 +47,8 @@* Magic nums for obj red zoning. * Placed in the first word before and the first word after an obj. */ -#define RED_INACTIVE 0x09F911029D74E35BULL/* when obj is inactive */ -#define RED_ACTIVE 0xD84156C5635688C0ULL/* when obj is active */ - -#define SLUB_RED_INACTIVE 0xbb -#define SLUB_RED_ACTIVE 0xcc +#define SLUB_RED_INACTIVE 0xbb/* when obj is inactive */ +#define SLUB_RED_ACTIVE 0xcc/* when obj is active */ /* ...and for poisoning */ #define POISON_INUSE 0x5a/* for use-uninitialised poisoning */
Signature · 1 line
2.45.1
Re: [PATCH 3/3] slab: delete useless RED_INACTIVE and RED_ACTIVE
Quoted 4 lines · Chengming Zhou
These seem useless since we use the
SLUB_RED_INACTIVEandSLUB_RED_ACTIVE, so just delete them, no functional change.Signed-off-by Chengming Zhou <[email protected]>
Hm right, only SLAB was using those. Thanks.