Skip to contentSkip to conversation

mm/slab: mark alloc tags empty for sheafs allocated with __GFP_NO_OBJ_EXT

PATCH Superseded Suren Baghdasaryan 2 participants 5 messages Feb 24

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/slab: mark alloc tags empty for sheafs allocated with __GFP_NO_OBJ_EXT

alloc_empty_sheaf() allocates sheafs from SLAB_KMALLOC caches using __GFP_NO_OBJ_EXT to avoid recursion, however it does not mark their allocation tags empty before freeing, which results in a warning when CONFIG_MEM_ALLOC_PROFILING_DEBUG is set. Fix this by marking allocation tags for such allocations as empty.

---
 mm/slab.h |  4 ++--
 mm/slub.c | 17 ++++++++++-------
 2 files changed, 12 insertions(+), 9 deletions(-)
mm/slab.h +2 -2
index 71c7261bf822..f6ef862b60ef 100644
@@ -290,14 +290,14 @@ static inline void *nearest_obj(struct kmem_cache *cache,
 
 /* Determine object index from a given position */
 static inline unsigned int __obj_to_index(const struct kmem_cache *cache,
-					  void *addr, void *obj)
+					  void *addr, const void *obj)
 {
 	return reciprocal_divide(kasan_reset_tag(obj) - addr,
 				 cache->reciprocal_size);
 }
 
 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
-					const struct slab *slab, void *obj)
+					const struct slab *slab, const void *obj)
 {
 	if (is_kfence_address(obj))
 		return 0;
mm/slub.c +10 -7
index 862642c165ed..3ddbe654cd56 100644
@@ -2041,18 +2041,18 @@ static inline void dec_slabs_node(struct kmem_cache *s, int node,
 
 #ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG
 
-static inline void mark_objexts_empty(struct slabobj_ext *obj_exts)
+static inline void mark_objexts_empty(const void *obj)
 {
-	struct slab *obj_exts_slab;
+	struct slab *obj_slab;
 	unsigned long slab_exts;
 
-	obj_exts_slab = virt_to_slab(obj_exts);
-	slab_exts = slab_obj_exts(obj_exts_slab);
+	obj_slab = virt_to_slab(obj);
+	slab_exts = slab_obj_exts(obj_slab);
 	if (slab_exts) {
 		get_slab_obj_exts(slab_exts);
-		unsigned int offs = obj_to_index(obj_exts_slab->slab_cache,
-						 obj_exts_slab, obj_exts);
-		struct slabobj_ext *ext = slab_obj_ext(obj_exts_slab,
+		unsigned int offs = obj_to_index(obj_slab->slab_cache,
+						 obj_slab, obj);
+		struct slabobj_ext *ext = slab_obj_ext(obj_slab,
 						       slab_exts, offs);
 
 		if (unlikely(is_codetag_empty(&ext->ref))) {
@@ -2783,6 +2783,9 @@ static inline struct slab_sheaf *alloc_empty_sheaf(struct kmem_cache *s,
 
 static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)
 {
+	if (s->flags & SLAB_KMALLOC)
+		mark_objexts_empty(sheaf);
+
 	kfree(sheaf);
 
 	stat(s, SHEAF_FREE);

base-commit: 7dff99b354601dd01829e1511711846e04340a69

Signature · 1 line
2.53.0.371.g1d285c8824-goog
#1 lore raw
kernel test robot noticed the following build errors:

Hi Suren,

kernel test robot noticed the following build errors:

[auto build test ERROR on 7dff99b354601dd01829e1511711846e04340a69]

url:    https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/mm-slab-mark-alloc-tags-empty-for-sheafs-allocated-with-__GFP_NO_OBJ_EXT/20260225-005422
base:   7dff99b354601dd01829e1511711846e04340a69
patch link:    https://lore.kernel.org/r/20260224165250.1322946-1-surenb%40google.com
patch subject: [PATCH 1/1] mm/slab: mark alloc tags empty for sheafs allocated with __GFP_NO_OBJ_EXT
config: nios2-allnoconfig (https://download.01.org/0day-ci/archive/20260225/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260225/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

mm/slub.c: In function 'free_empty_sheaf':

>> mm/slub.c:2787:17: error: implicit declaration of function 'mark_objexts_empty' [-Werror=implicit-function-declaration]
    2787 |                 mark_objexts_empty(sheaf);
         |                 ^~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/mark_objexts_empty +2787 mm/slub.c

2783
2784 static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)
2785 {
2786 if (s->flags & SLAB_KMALLOC)

> 2787			mark_objexts_empty(sheaf);

2788
2789 kfree(sheaf);
2790
2791 stat(s, SHEAF_FREE);
2792 }
2793

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Suren Baghdasaryan
kernel test robot noticed the following build errors:

Hi Suren,

kernel test robot noticed the following build errors:

[auto build test ERROR on 7dff99b354601dd01829e1511711846e04340a69]

url:    https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/mm-slab-mark-alloc-tags-empty-for-sheafs-allocated-with-__GFP_NO_OBJ_EXT/20260225-005422
base:   7dff99b354601dd01829e1511711846e04340a69
patch link:    https://lore.kernel.org/r/20260224165250.1322946-1-surenb%40google.com
patch subject: [PATCH 1/1] mm/slab: mark alloc tags empty for sheafs allocated with __GFP_NO_OBJ_EXT
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20260225/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260225/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> mm/slub.c:2787:3: error: call to undeclared function 'mark_objexts_empty'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    2787 |                 mark_objexts_empty(sheaf);
         |                 ^

1 error generated.

vim +/mark_objexts_empty +2787 mm/slub.c

2783
2784 static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)
2785 {
2786 if (s->flags & SLAB_KMALLOC)

> 2787			mark_objexts_empty(sheaf);

2788
2789 kfree(sheaf);
2790
2791 stat(s, SHEAF_FREE);
2792 }
2793

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
Quoted 20 lines · kernel test robot

Hi Suren,

kernel test robot noticed the following build errors:

[auto build test ERROR on 7dff99b354601dd01829e1511711846e04340a69]

url:    https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/mm-slab-mark-alloc-tags-empty-for-sheafs-allocated-with-__GFP_NO_OBJ_EXT/20260225-005422
base:   7dff99b354601dd01829e1511711846e04340a69
patch link:    https://lore.kernel.org/r/20260224165250.1322946-1-surenb%40google.com
patch subject: [PATCH 1/1] mm/slab: mark alloc tags empty for sheafs allocated with __GFP_NO_OBJ_EXT
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20260225/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260225/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 6 lines

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

mm/slub.c:2787:3: error: call to undeclared function 'mark_objexts_empty'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

    2787 |                 mark_objexts_empty(sheaf);
         |                 ^

1 error generated.

Thanks! In a hurry to post the fix I forgot to update the mark_objexts_empty() definition for !CONFIG_MEM_ALLOC_PROFILING_DEBUG. I'll post a fixed version shortly.

Quoted 19 lines

vim +/mark_objexts_empty +2787 mm/slub.c

2783
2784 static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf) 2785 {
2786 if (s->flags & SLAB_KMALLOC)

Quoted 1 line

2787 mark_objexts_empty(sheaf);

2788
2789 kfree(sheaf);
2790
2791 stat(s, SHEAF_FREE);
2792 }
2793

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#4 lore raw
Quoted 24 lines · Suren Baghdasaryan
Quoted 22 lines · kernel test robot

Hi Suren,

kernel test robot noticed the following build errors:

[auto build test ERROR on 7dff99b354601dd01829e1511711846e04340a69]

url:    https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/mm-slab-mark-alloc-tags-empty-for-sheafs-allocated-with-__GFP_NO_OBJ_EXT/20260225-005422
base:   7dff99b354601dd01829e1511711846e04340a69
patch link:    https://lore.kernel.org/r/20260224165250.1322946-1-surenb%40google.com
patch subject: [PATCH 1/1] mm/slab: mark alloc tags empty for sheafs allocated with __GFP_NO_OBJ_EXT
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20260225/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260225/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

mm/slub.c:2787:3: error: call to undeclared function 'mark_objexts_empty'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

    2787 |                 mark_objexts_empty(sheaf);
         |                 ^

1 error generated.

Thanks! In a hurry to post the fix I forgot to update the mark_objexts_empty() definition for !CONFIG_MEM_ALLOC_PROFILING_DEBUG. I'll post a fixed version shortly.

Fixed version is posted at
https://lore.kernel.org/all/[email protected]/

Quoted 20 lines
Quoted 20 lines

vim +/mark_objexts_empty +2787 mm/slub.c

2783
2784 static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf) 2785 {
2786 if (s->flags & SLAB_KMALLOC)

Quoted 1 line

2787 mark_objexts_empty(sheaf);

2788
2789 kfree(sheaf);
2790
2791 stat(s, SHEAF_FREE);
2792 }
2793

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki