diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2011-02-14 12:35:22 -0500 |
---|---|---|
committer | Pekka Enberg <penberg@kernel.org> | 2011-02-23 04:59:30 -0500 |
commit | b3d41885d9cd0d9db31c8f49e362bae02c96fa3f (patch) | |
tree | ab8f134456c9ae06ee0532a8ff0b7296e4d51c16 /mm | |
parent | 63310467a3d1ed6a0460ec1f4268126cd1ceec2e (diff) |
slub: fix kmemcheck calls to match ksize() hints
Recent use of ksize() in network stack (commit ca44ac38 : net: don't
reallocate skb->head unless the current one hasn't the needed extra size
or is shared) triggers kmemcheck warnings, because ksize() can return
more space than kmemcheck is aware of.
Pekka Enberg noticed SLAB+kmemcheck is doing the right thing, while SLUB
+kmemcheck doesnt.
Bugzilla reference #27212
Reported-by: Christian Casteyde <casteyde.christian@free.fr>
Suggested-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Christoph Lameter <cl@linux.com>
CC: Changli Gao <xiaosuo@gmail.com>
CC: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/slub.c | 49 |
1 files changed, 26 insertions, 23 deletions
@@ -797,10 +797,34 @@ static inline int slab_pre_alloc_hook(struct kmem_cache *s, gfp_t flags) | |||
797 | return should_failslab(s->objsize, flags, s->flags); | 797 | return should_failslab(s->objsize, flags, s->flags); |
798 | } | 798 | } |
799 | 799 | ||
800 | static inline size_t slab_ksize(const struct kmem_cache *s) | ||
801 | { | ||
802 | #ifdef CONFIG_SLUB_DEBUG | ||
803 | /* | ||
804 | * Debugging requires use of the padding between object | ||
805 | * and whatever may come after it. | ||
806 | */ | ||
807 | if (s->flags & (SLAB_RED_ZONE | SLAB_POISON)) | ||
808 | return s->objsize; | ||
809 | |||
810 | #endif | ||
811 | /* | ||
812 | * If we have the need to store the freelist pointer | ||
813 | * back there or track user information then we can | ||
814 | * only use the space before that information. | ||
815 | */ | ||
816 | if (s->flags & (SLAB_DESTROY_BY_RCU | SLAB_STORE_USER)) | ||
817 | return s->inuse; | ||
818 | /* | ||
819 | * Else we can use all the padding etc for the allocation | ||
820 | */ | ||
821 | return s->size; | ||
822 | } | ||
823 | |||
800 | static inline void slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags, void *object) | 824 | static inline void slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags, void *object) |
801 | { | 825 | { |
802 | flags &= gfp_allowed_mask; | 826 | flags &= gfp_allowed_mask; |
803 | kmemcheck_slab_alloc(s, flags, object, s->objsize); | 827 | kmemcheck_slab_alloc(s, flags, object, slab_ksize(s)); |
804 | kmemleak_alloc_recursive(object, s->objsize, 1, s->flags, flags); | 828 | kmemleak_alloc_recursive(object, s->objsize, 1, s->flags, flags); |
805 | } | 829 | } |
806 | 830 | ||
@@ -2690,7 +2714,6 @@ EXPORT_SYMBOL(__kmalloc_node); | |||
2690 | size_t ksize(const void *object) | 2714 | size_t ksize(const void *object) |
2691 | { | 2715 | { |
2692 | struct page *page; | 2716 | struct page *page; |
2693 | struct kmem_cache *s; | ||
2694 | 2717 | ||
2695 | if (unlikely(object == ZERO_SIZE_PTR)) | 2718 | if (unlikely(object == ZERO_SIZE_PTR)) |
2696 | return 0; | 2719 | return 0; |
@@ -2701,28 +2724,8 @@ size_t ksize(const void *object) | |||
2701 | WARN_ON(!PageCompound(page)); | 2724 | WARN_ON(!PageCompound(page)); |
2702 | return PAGE_SIZE << compound_order(page); | 2725 | return PAGE_SIZE << compound_order(page); |
2703 | } | 2726 | } |
2704 | s = page->slab; | ||
2705 | 2727 | ||
2706 | #ifdef CONFIG_SLUB_DEBUG | 2728 | return slab_ksize(page->slab); |
2707 | /* | ||
2708 | * Debugging requires use of the padding between object | ||
2709 | * and whatever may come after it. | ||
2710 | */ | ||
2711 | if (s->flags & (SLAB_RED_ZONE | SLAB_POISON)) | ||
2712 | return s->objsize; | ||
2713 | |||
2714 | #endif | ||
2715 | /* | ||
2716 | * If we have the need to store the freelist pointer | ||
2717 | * back there or track user information then we can | ||
2718 | * only use the space before that information. | ||
2719 | */ | ||
2720 | if (s->flags & (SLAB_DESTROY_BY_RCU | SLAB_STORE_USER)) | ||
2721 | return s->inuse; | ||
2722 | /* | ||
2723 | * Else we can use all the padding etc for the allocation | ||
2724 | */ | ||
2725 | return s->size; | ||
2726 | } | 2729 | } |
2727 | EXPORT_SYMBOL(ksize); | 2730 | EXPORT_SYMBOL(ksize); |
2728 | 2731 | ||