linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function
@ 2022-11-23 12:31 Feng Tang
  2022-11-23 12:31 ` [PATCH v2 -next 2/2] mm/kasan: simplify and refine kasan_cache code Feng Tang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Feng Tang @ 2022-11-23 12:31 UTC (permalink / raw)
  To: Andrew Morton, Vlastimil Babka, Christoph Lameter, Pekka Enberg,
	David Rientjes, Joonsoo Kim, Roman Gushchin, Hyeonggon Yoo,
	Andrey Konovalov, Dmitry Vyukov, Andrey Ryabinin,
	Alexander Potapenko, Vincenzo Frascino
  Cc: linux-mm, kasan-dev, linux-kernel, Feng Tang

commit 6edf2576a6cc ("mm/slub: enable debugging memory wasting of
kmalloc") introduces 'SLAB_KMALLOC' bit specifying whether a
kmem_cache is a kmalloc cache for slab/slub (slob doesn't have
dedicated kmalloc caches).

Add a helper inline function for other components like kasan to
simplify code.

Signed-off-by: Feng Tang <feng.tang@intel.com>
---
changlog:
  
  since v1:
  * don't use macro for the helper (Andrew Morton)
  * place the inline function in mm/slb.h to solve data structure
    definition issue (Vlastimil Babka)

 mm/slab.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mm/slab.h b/mm/slab.h
index e3b3231af742..0d72fd62751a 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -325,6 +325,14 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size,
 }
 #endif
 
+static inline bool is_kmalloc_cache(struct kmem_cache *s)
+{
+#ifndef CONFIG_SLOB
+	return (s->flags & SLAB_KMALLOC);
+#else
+	return false;
+#endif
+}
 
 /* Legal flag mask for kmem_cache_create(), for various configurations */
 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | \
-- 
2.34.1



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

* [PATCH v2 -next 2/2] mm/kasan: simplify and refine kasan_cache code
  2022-11-23 12:31 [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function Feng Tang
@ 2022-11-23 12:31 ` Feng Tang
  2022-11-23 13:08   ` Andrey Konovalov
  2022-11-23 17:03 ` [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function Vlastimil Babka
  2022-11-24 10:57 ` Hyeonggon Yoo
  2 siblings, 1 reply; 6+ messages in thread
From: Feng Tang @ 2022-11-23 12:31 UTC (permalink / raw)
  To: Andrew Morton, Vlastimil Babka, Christoph Lameter, Pekka Enberg,
	David Rientjes, Joonsoo Kim, Roman Gushchin, Hyeonggon Yoo,
	Andrey Konovalov, Dmitry Vyukov, Andrey Ryabinin,
	Alexander Potapenko, Vincenzo Frascino
  Cc: linux-mm, kasan-dev, linux-kernel, Feng Tang

struct 'kasan_cache' has a member 'is_kmalloc' indicating whether
its host kmem_cache is a kmalloc cache. With newly introduced
is_kmalloc_cache() helper, 'is_kmalloc' and its related function can
be replaced and removed.

Also 'kasan_cache' is only needed by KASAN generic mode, and not by
SW/HW tag modes, so refine its protection macro accordingly, suggested
by Andrey Konoval.

Signed-off-by: Feng Tang <feng.tang@intel.com>
---
Changlog:

  Since v1
  * Use CONFIG_KASAN_GENERIC instead of CONFIG_KASAN for 'kasan_cache',
    as suggested by Andrey Konovalov

 include/linux/kasan.h    | 22 +++++-----------------
 include/linux/slab_def.h |  2 +-
 include/linux/slub_def.h |  2 +-
 mm/kasan/common.c        |  9 ++-------
 mm/slab_common.c         |  1 -
 5 files changed, 9 insertions(+), 27 deletions(-)

diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index dff604912687..0ff382f79f80 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -96,15 +96,6 @@ static inline bool kasan_has_integrated_init(void)
 }
 
 #ifdef CONFIG_KASAN
-
-struct kasan_cache {
-#ifdef CONFIG_KASAN_GENERIC
-	int alloc_meta_offset;
-	int free_meta_offset;
-#endif
-	bool is_kmalloc;
-};
-
 void __kasan_unpoison_range(const void *addr, size_t size);
 static __always_inline void kasan_unpoison_range(const void *addr, size_t size)
 {
@@ -129,13 +120,6 @@ static __always_inline bool kasan_unpoison_pages(struct page *page,
 	return false;
 }
 
-void __kasan_cache_create_kmalloc(struct kmem_cache *cache);
-static __always_inline void kasan_cache_create_kmalloc(struct kmem_cache *cache)
-{
-	if (kasan_enabled())
-		__kasan_cache_create_kmalloc(cache);
-}
-
 void __kasan_poison_slab(struct slab *slab);
 static __always_inline void kasan_poison_slab(struct slab *slab)
 {
@@ -252,7 +236,6 @@ static inline void kasan_poison_pages(struct page *page, unsigned int order,
 				      bool init) {}
 static inline bool kasan_unpoison_pages(struct page *page, unsigned int order,
 					bool init) { return false; }
-static inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) {}
 static inline void kasan_poison_slab(struct slab *slab) {}
 static inline void kasan_unpoison_object_data(struct kmem_cache *cache,
 					void *object) {}
@@ -303,6 +286,11 @@ static inline void kasan_unpoison_task_stack(struct task_struct *task) {}
 
 #ifdef CONFIG_KASAN_GENERIC
 
+struct kasan_cache {
+	int alloc_meta_offset;
+	int free_meta_offset;
+};
+
 size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object);
 slab_flags_t kasan_never_merge(void);
 void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
index f0ffad6a3365..39f7f1f95de2 100644
--- a/include/linux/slab_def.h
+++ b/include/linux/slab_def.h
@@ -72,7 +72,7 @@ struct kmem_cache {
 	int obj_offset;
 #endif /* CONFIG_DEBUG_SLAB */
 
-#ifdef CONFIG_KASAN
+#ifdef CONFIG_KASAN_GENERIC
 	struct kasan_cache kasan_info;
 #endif
 
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index f9c68a9dac04..4e7cdada4bbb 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -132,7 +132,7 @@ struct kmem_cache {
 	unsigned int *random_seq;
 #endif
 
-#ifdef CONFIG_KASAN
+#ifdef CONFIG_KASAN_GENERIC
 	struct kasan_cache kasan_info;
 #endif
 
diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index 1f30080a7a4c..6e265beefc27 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -122,11 +122,6 @@ void __kasan_poison_pages(struct page *page, unsigned int order, bool init)
 			     KASAN_PAGE_FREE, init);
 }
 
-void __kasan_cache_create_kmalloc(struct kmem_cache *cache)
-{
-	cache->kasan_info.is_kmalloc = true;
-}
-
 void __kasan_poison_slab(struct slab *slab)
 {
 	struct page *page = slab_page(slab);
@@ -326,7 +321,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache,
 	kasan_unpoison(tagged_object, cache->object_size, init);
 
 	/* Save alloc info (if possible) for non-kmalloc() allocations. */
-	if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc)
+	if (kasan_stack_collection_enabled() && !is_kmalloc_cache(cache))
 		kasan_save_alloc_info(cache, tagged_object, flags);
 
 	return tagged_object;
@@ -372,7 +367,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache,
 	 * Save alloc info (if possible) for kmalloc() allocations.
 	 * This also rewrites the alloc info when called from kasan_krealloc().
 	 */
-	if (kasan_stack_collection_enabled() && cache->kasan_info.is_kmalloc)
+	if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache))
 		kasan_save_alloc_info(cache, (void *)object, flags);
 
 	/* Keep the tag that was set by kasan_slab_alloc(). */
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 8276022f0da4..a5480d67f391 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -663,7 +663,6 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name,
 
 	create_boot_cache(s, name, size, flags | SLAB_KMALLOC, useroffset,
 								usersize);
-	kasan_cache_create_kmalloc(s);
 	list_add(&s->list, &slab_caches);
 	s->refcount = 1;
 	return s;
-- 
2.34.1



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

* Re: [PATCH v2 -next 2/2] mm/kasan: simplify and refine kasan_cache code
  2022-11-23 12:31 ` [PATCH v2 -next 2/2] mm/kasan: simplify and refine kasan_cache code Feng Tang
@ 2022-11-23 13:08   ` Andrey Konovalov
  0 siblings, 0 replies; 6+ messages in thread
From: Andrey Konovalov @ 2022-11-23 13:08 UTC (permalink / raw)
  To: Feng Tang
  Cc: Andrew Morton, Vlastimil Babka, Christoph Lameter, Pekka Enberg,
	David Rientjes, Joonsoo Kim, Roman Gushchin, Hyeonggon Yoo,
	Dmitry Vyukov, Andrey Ryabinin, Alexander Potapenko,
	Vincenzo Frascino, linux-mm, kasan-dev, linux-kernel

On Wed, Nov 23, 2022 at 1:35 PM Feng Tang <feng.tang@intel.com> wrote:
>
> struct 'kasan_cache' has a member 'is_kmalloc' indicating whether
> its host kmem_cache is a kmalloc cache. With newly introduced
> is_kmalloc_cache() helper, 'is_kmalloc' and its related function can
> be replaced and removed.
>
> Also 'kasan_cache' is only needed by KASAN generic mode, and not by
> SW/HW tag modes, so refine its protection macro accordingly, suggested
> by Andrey Konoval.
>
> Signed-off-by: Feng Tang <feng.tang@intel.com>
> ---
> Changlog:
>
>   Since v1
>   * Use CONFIG_KASAN_GENERIC instead of CONFIG_KASAN for 'kasan_cache',
>     as suggested by Andrey Konovalov
>
>  include/linux/kasan.h    | 22 +++++-----------------
>  include/linux/slab_def.h |  2 +-
>  include/linux/slub_def.h |  2 +-
>  mm/kasan/common.c        |  9 ++-------
>  mm/slab_common.c         |  1 -
>  5 files changed, 9 insertions(+), 27 deletions(-)
>
> diff --git a/include/linux/kasan.h b/include/linux/kasan.h
> index dff604912687..0ff382f79f80 100644
> --- a/include/linux/kasan.h
> +++ b/include/linux/kasan.h
> @@ -96,15 +96,6 @@ static inline bool kasan_has_integrated_init(void)
>  }
>
>  #ifdef CONFIG_KASAN
> -
> -struct kasan_cache {
> -#ifdef CONFIG_KASAN_GENERIC
> -       int alloc_meta_offset;
> -       int free_meta_offset;
> -#endif
> -       bool is_kmalloc;
> -};
> -
>  void __kasan_unpoison_range(const void *addr, size_t size);
>  static __always_inline void kasan_unpoison_range(const void *addr, size_t size)
>  {
> @@ -129,13 +120,6 @@ static __always_inline bool kasan_unpoison_pages(struct page *page,
>         return false;
>  }
>
> -void __kasan_cache_create_kmalloc(struct kmem_cache *cache);
> -static __always_inline void kasan_cache_create_kmalloc(struct kmem_cache *cache)
> -{
> -       if (kasan_enabled())
> -               __kasan_cache_create_kmalloc(cache);
> -}
> -
>  void __kasan_poison_slab(struct slab *slab);
>  static __always_inline void kasan_poison_slab(struct slab *slab)
>  {
> @@ -252,7 +236,6 @@ static inline void kasan_poison_pages(struct page *page, unsigned int order,
>                                       bool init) {}
>  static inline bool kasan_unpoison_pages(struct page *page, unsigned int order,
>                                         bool init) { return false; }
> -static inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) {}
>  static inline void kasan_poison_slab(struct slab *slab) {}
>  static inline void kasan_unpoison_object_data(struct kmem_cache *cache,
>                                         void *object) {}
> @@ -303,6 +286,11 @@ static inline void kasan_unpoison_task_stack(struct task_struct *task) {}
>
>  #ifdef CONFIG_KASAN_GENERIC
>
> +struct kasan_cache {
> +       int alloc_meta_offset;
> +       int free_meta_offset;
> +};
> +
>  size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object);
>  slab_flags_t kasan_never_merge(void);
>  void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
> diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
> index f0ffad6a3365..39f7f1f95de2 100644
> --- a/include/linux/slab_def.h
> +++ b/include/linux/slab_def.h
> @@ -72,7 +72,7 @@ struct kmem_cache {
>         int obj_offset;
>  #endif /* CONFIG_DEBUG_SLAB */
>
> -#ifdef CONFIG_KASAN
> +#ifdef CONFIG_KASAN_GENERIC
>         struct kasan_cache kasan_info;
>  #endif
>
> diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
> index f9c68a9dac04..4e7cdada4bbb 100644
> --- a/include/linux/slub_def.h
> +++ b/include/linux/slub_def.h
> @@ -132,7 +132,7 @@ struct kmem_cache {
>         unsigned int *random_seq;
>  #endif
>
> -#ifdef CONFIG_KASAN
> +#ifdef CONFIG_KASAN_GENERIC
>         struct kasan_cache kasan_info;
>  #endif
>
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index 1f30080a7a4c..6e265beefc27 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -122,11 +122,6 @@ void __kasan_poison_pages(struct page *page, unsigned int order, bool init)
>                              KASAN_PAGE_FREE, init);
>  }
>
> -void __kasan_cache_create_kmalloc(struct kmem_cache *cache)
> -{
> -       cache->kasan_info.is_kmalloc = true;
> -}
> -
>  void __kasan_poison_slab(struct slab *slab)
>  {
>         struct page *page = slab_page(slab);
> @@ -326,7 +321,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache,
>         kasan_unpoison(tagged_object, cache->object_size, init);
>
>         /* Save alloc info (if possible) for non-kmalloc() allocations. */
> -       if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc)
> +       if (kasan_stack_collection_enabled() && !is_kmalloc_cache(cache))
>                 kasan_save_alloc_info(cache, tagged_object, flags);
>
>         return tagged_object;
> @@ -372,7 +367,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache,
>          * Save alloc info (if possible) for kmalloc() allocations.
>          * This also rewrites the alloc info when called from kasan_krealloc().
>          */
> -       if (kasan_stack_collection_enabled() && cache->kasan_info.is_kmalloc)
> +       if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache))
>                 kasan_save_alloc_info(cache, (void *)object, flags);
>
>         /* Keep the tag that was set by kasan_slab_alloc(). */
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 8276022f0da4..a5480d67f391 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -663,7 +663,6 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name,
>
>         create_boot_cache(s, name, size, flags | SLAB_KMALLOC, useroffset,
>                                                                 usersize);
> -       kasan_cache_create_kmalloc(s);
>         list_add(&s->list, &slab_caches);
>         s->refcount = 1;
>         return s;
> --
> 2.34.1
>

Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>

Thanks!


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

* Re: [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function
  2022-11-23 12:31 [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function Feng Tang
  2022-11-23 12:31 ` [PATCH v2 -next 2/2] mm/kasan: simplify and refine kasan_cache code Feng Tang
@ 2022-11-23 17:03 ` Vlastimil Babka
  2022-11-24  1:21   ` Feng Tang
  2022-11-24 10:57 ` Hyeonggon Yoo
  2 siblings, 1 reply; 6+ messages in thread
From: Vlastimil Babka @ 2022-11-23 17:03 UTC (permalink / raw)
  To: Feng Tang, Andrew Morton, Christoph Lameter, Pekka Enberg,
	David Rientjes, Joonsoo Kim, Roman Gushchin, Hyeonggon Yoo,
	Andrey Konovalov, Dmitry Vyukov, Andrey Ryabinin,
	Alexander Potapenko, Vincenzo Frascino
  Cc: linux-mm, kasan-dev, linux-kernel

Subject should say mm/slab

On 11/23/22 13:31, Feng Tang wrote:
> commit 6edf2576a6cc ("mm/slub: enable debugging memory wasting of
> kmalloc") introduces 'SLAB_KMALLOC' bit specifying whether a
> kmem_cache is a kmalloc cache for slab/slub (slob doesn't have
> dedicated kmalloc caches).
> 
> Add a helper inline function for other components like kasan to
> simplify code.
> 
> Signed-off-by: Feng Tang <feng.tang@intel.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

Patch 2 seems to depend on patches in Andrew's tree so it's simpler if he
takes both of these too.

Thanks,
Vlastimil

> ---
> changlog:
>   
>   since v1:
>   * don't use macro for the helper (Andrew Morton)
>   * place the inline function in mm/slb.h to solve data structure
>     definition issue (Vlastimil Babka)
> 
>  mm/slab.h | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/mm/slab.h b/mm/slab.h
> index e3b3231af742..0d72fd62751a 100644
> --- a/mm/slab.h
> +++ b/mm/slab.h
> @@ -325,6 +325,14 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size,
>  }
>  #endif
>  
> +static inline bool is_kmalloc_cache(struct kmem_cache *s)
> +{
> +#ifndef CONFIG_SLOB
> +	return (s->flags & SLAB_KMALLOC);
> +#else
> +	return false;
> +#endif
> +}
>  
>  /* Legal flag mask for kmem_cache_create(), for various configurations */
>  #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | \



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

* Re: [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function
  2022-11-23 17:03 ` [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function Vlastimil Babka
@ 2022-11-24  1:21   ` Feng Tang
  0 siblings, 0 replies; 6+ messages in thread
From: Feng Tang @ 2022-11-24  1:21 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Andrew Morton, Christoph Lameter, Pekka Enberg, David Rientjes,
	Joonsoo Kim, Roman Gushchin, Hyeonggon Yoo, Andrey Konovalov,
	Dmitry Vyukov, Andrey Ryabinin, Alexander Potapenko,
	Vincenzo Frascino, linux-mm, kasan-dev, linux-kernel

On Wed, Nov 23, 2022 at 06:03:26PM +0100, Vlastimil Babka wrote:
> Subject should say mm/slab

My bad, thanks for catching this.

> On 11/23/22 13:31, Feng Tang wrote:
> > commit 6edf2576a6cc ("mm/slub: enable debugging memory wasting of
> > kmalloc") introduces 'SLAB_KMALLOC' bit specifying whether a
> > kmem_cache is a kmalloc cache for slab/slub (slob doesn't have
> > dedicated kmalloc caches).
> > 
> > Add a helper inline function for other components like kasan to
> > simplify code.
> > 
> > Signed-off-by: Feng Tang <feng.tang@intel.com>
> 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!

> Patch 2 seems to depend on patches in Andrew's tree so it's simpler if he
> takes both of these too.

Yes, patch 2/2 change many places of kasan code.

Hi Andrew,

Could you consider taking these 2 patches to your tree? If you think
it's too close to the merge windown, I can respin after 6.2. thanks!

- Feng

> Thanks,
> Vlastimil
> 
> > ---
> > changlog:
> >   
> >   since v1:
> >   * don't use macro for the helper (Andrew Morton)
> >   * place the inline function in mm/slb.h to solve data structure
> >     definition issue (Vlastimil Babka)
> > 
> >  mm/slab.h | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/mm/slab.h b/mm/slab.h
> > index e3b3231af742..0d72fd62751a 100644
> > --- a/mm/slab.h
> > +++ b/mm/slab.h
> > @@ -325,6 +325,14 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size,
> >  }
> >  #endif
> >  
> > +static inline bool is_kmalloc_cache(struct kmem_cache *s)
> > +{
> > +#ifndef CONFIG_SLOB
> > +	return (s->flags & SLAB_KMALLOC);
> > +#else
> > +	return false;
> > +#endif
> > +}
> >  
> >  /* Legal flag mask for kmem_cache_create(), for various configurations */
> >  #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | \
> 


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

* Re: [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function
  2022-11-23 12:31 [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function Feng Tang
  2022-11-23 12:31 ` [PATCH v2 -next 2/2] mm/kasan: simplify and refine kasan_cache code Feng Tang
  2022-11-23 17:03 ` [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function Vlastimil Babka
@ 2022-11-24 10:57 ` Hyeonggon Yoo
  2 siblings, 0 replies; 6+ messages in thread
From: Hyeonggon Yoo @ 2022-11-24 10:57 UTC (permalink / raw)
  To: Feng Tang
  Cc: Andrew Morton, Vlastimil Babka, Christoph Lameter, Pekka Enberg,
	David Rientjes, Joonsoo Kim, Roman Gushchin, Andrey Konovalov,
	Dmitry Vyukov, Andrey Ryabinin, Alexander Potapenko,
	Vincenzo Frascino, linux-mm, kasan-dev, linux-kernel

On Wed, Nov 23, 2022 at 08:31:58PM +0800, Feng Tang wrote:
> commit 6edf2576a6cc ("mm/slub: enable debugging memory wasting of
> kmalloc") introduces 'SLAB_KMALLOC' bit specifying whether a
> kmem_cache is a kmalloc cache for slab/slub (slob doesn't have
> dedicated kmalloc caches).
> 
> Add a helper inline function for other components like kasan to
> simplify code.
> 
> Signed-off-by: Feng Tang <feng.tang@intel.com>
> ---
> changlog:
>   
>   since v1:
>   * don't use macro for the helper (Andrew Morton)
>   * place the inline function in mm/slb.h to solve data structure
>     definition issue (Vlastimil Babka)
> 
>  mm/slab.h | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/mm/slab.h b/mm/slab.h
> index e3b3231af742..0d72fd62751a 100644
> --- a/mm/slab.h
> +++ b/mm/slab.h
> @@ -325,6 +325,14 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size,
>  }
>  #endif
>  
> +static inline bool is_kmalloc_cache(struct kmem_cache *s)
> +{
> +#ifndef CONFIG_SLOB
> +	return (s->flags & SLAB_KMALLOC);
> +#else
> +	return false;
> +#endif
> +}
>  
>  /* Legal flag mask for kmem_cache_create(), for various configurations */
>  #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | \
> -- 
> 2.34.1

With Vlastimil's comment:

Acked-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>

-- 
Thanks,
Hyeonggon


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

end of thread, other threads:[~2022-11-24 10:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-23 12:31 [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function Feng Tang
2022-11-23 12:31 ` [PATCH v2 -next 2/2] mm/kasan: simplify and refine kasan_cache code Feng Tang
2022-11-23 13:08   ` Andrey Konovalov
2022-11-23 17:03 ` [PATCH v2 -next 1/2] mm/slb: add is_kmalloc_cache() helper function Vlastimil Babka
2022-11-24  1:21   ` Feng Tang
2022-11-24 10:57 ` Hyeonggon Yoo

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