Commit 96d8dbb6 authored by Vlastimil Babka's avatar Vlastimil Babka

mm, slab, kasan: replace kasan_never_merge() with SLAB_NO_MERGE

The SLAB_KASAN flag prevents merging of caches in some configurations,
which is handled in a rather complicated way via kasan_never_merge().
Since we now have a generic SLAB_NO_MERGE flag, we can instead use it
for KASAN caches in addition to SLAB_KASAN in those configurations,
and simplify the SLAB_NEVER_MERGE handling.
Tested-by: default avatarXiongwei Song <xiongwei.song@windriver.com>
Reviewed-by: default avatarChengming Zhou <chengming.zhou@linux.dev>
Reviewed-by: default avatarAndrey Konovalov <andreyknvl@gmail.com>
Tested-by: default avatarDavid Rientjes <rientjes@google.com>
Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
parent cc61eb85
...@@ -429,7 +429,6 @@ struct kasan_cache { ...@@ -429,7 +429,6 @@ struct kasan_cache {
}; };
size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object); 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, void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
slab_flags_t *flags); slab_flags_t *flags);
...@@ -446,11 +445,6 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache, ...@@ -446,11 +445,6 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache,
{ {
return 0; return 0;
} }
/* And thus nothing prevents cache merging. */
static inline slab_flags_t kasan_never_merge(void)
{
return 0;
}
/* And no cache-related metadata initialization is required. */ /* And no cache-related metadata initialization is required. */
static inline void kasan_cache_create(struct kmem_cache *cache, static inline void kasan_cache_create(struct kmem_cache *cache,
unsigned int *size, unsigned int *size,
......
...@@ -334,14 +334,6 @@ DEFINE_ASAN_SET_SHADOW(f3); ...@@ -334,14 +334,6 @@ DEFINE_ASAN_SET_SHADOW(f3);
DEFINE_ASAN_SET_SHADOW(f5); DEFINE_ASAN_SET_SHADOW(f5);
DEFINE_ASAN_SET_SHADOW(f8); DEFINE_ASAN_SET_SHADOW(f8);
/* Only allow cache merging when no per-object metadata is present. */
slab_flags_t kasan_never_merge(void)
{
if (!kasan_requires_meta())
return 0;
return SLAB_KASAN;
}
/* /*
* Adaptive redzone policy taken from the userspace AddressSanitizer runtime. * Adaptive redzone policy taken from the userspace AddressSanitizer runtime.
* For larger allocations larger redzones are used. * For larger allocations larger redzones are used.
...@@ -370,15 +362,13 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, ...@@ -370,15 +362,13 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
return; return;
/* /*
* SLAB_KASAN is used to mark caches that are sanitized by KASAN * SLAB_KASAN is used to mark caches that are sanitized by KASAN and
* and that thus have per-object metadata. * that thus have per-object metadata. Currently, this flag is used in
* Currently this flag is used in two places: * slab_ksize() to account for per-object metadata when calculating the
* 1. In slab_ksize() to account for per-object metadata when * size of the accessible memory within the object. Additionally, we use
* calculating the size of the accessible memory within the object. * SLAB_NO_MERGE to prevent merging of caches with per-object metadata.
* 2. In slab_common.c via kasan_never_merge() to prevent merging of
* caches with per-object metadata.
*/ */
*flags |= SLAB_KASAN; *flags |= SLAB_KASAN | SLAB_NO_MERGE;
ok_size = *size; ok_size = *size;
......
...@@ -50,7 +50,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work, ...@@ -50,7 +50,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work,
*/ */
#define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \
SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \ SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \
SLAB_FAILSLAB | SLAB_NO_MERGE | kasan_never_merge()) SLAB_FAILSLAB | SLAB_NO_MERGE)
#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \
SLAB_CACHE_DMA32 | SLAB_ACCOUNT) SLAB_CACHE_DMA32 | SLAB_ACCOUNT)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment