Skip to content

Commit 96d8dbb

Browse files
committed
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: Xiongwei Song <[email protected]> Reviewed-by: Chengming Zhou <[email protected]> Reviewed-by: Andrey Konovalov <[email protected]> Tested-by: David Rientjes <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent cc61eb8 commit 96d8dbb

File tree

3 files changed

+7
-23
lines changed

3 files changed

+7
-23
lines changed

include/linux/kasan.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ struct kasan_cache {
429429
};
430430

431431
size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object);
432-
slab_flags_t kasan_never_merge(void);
433432
void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
434433
slab_flags_t *flags);
435434

@@ -446,11 +445,6 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache,
446445
{
447446
return 0;
448447
}
449-
/* And thus nothing prevents cache merging. */
450-
static inline slab_flags_t kasan_never_merge(void)
451-
{
452-
return 0;
453-
}
454448
/* And no cache-related metadata initialization is required. */
455449
static inline void kasan_cache_create(struct kmem_cache *cache,
456450
unsigned int *size,

mm/kasan/generic.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,6 @@ DEFINE_ASAN_SET_SHADOW(f3);
334334
DEFINE_ASAN_SET_SHADOW(f5);
335335
DEFINE_ASAN_SET_SHADOW(f8);
336336

337-
/* Only allow cache merging when no per-object metadata is present. */
338-
slab_flags_t kasan_never_merge(void)
339-
{
340-
if (!kasan_requires_meta())
341-
return 0;
342-
return SLAB_KASAN;
343-
}
344-
345337
/*
346338
* Adaptive redzone policy taken from the userspace AddressSanitizer runtime.
347339
* For larger allocations larger redzones are used.
@@ -370,15 +362,13 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
370362
return;
371363

372364
/*
373-
* SLAB_KASAN is used to mark caches that are sanitized by KASAN
374-
* and that thus have per-object metadata.
375-
* Currently this flag is used in two places:
376-
* 1. In slab_ksize() to account for per-object metadata when
377-
* calculating the size of the accessible memory within the object.
378-
* 2. In slab_common.c via kasan_never_merge() to prevent merging of
379-
* caches with per-object metadata.
365+
* SLAB_KASAN is used to mark caches that are sanitized by KASAN and
366+
* that thus have per-object metadata. Currently, this flag is used in
367+
* slab_ksize() to account for per-object metadata when calculating the
368+
* size of the accessible memory within the object. Additionally, we use
369+
* SLAB_NO_MERGE to prevent merging of caches with per-object metadata.
380370
*/
381-
*flags |= SLAB_KASAN;
371+
*flags |= SLAB_KASAN | SLAB_NO_MERGE;
382372

383373
ok_size = *size;
384374

mm/slab_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work,
5050
*/
5151
#define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \
5252
SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \
53-
SLAB_FAILSLAB | SLAB_NO_MERGE | kasan_never_merge())
53+
SLAB_FAILSLAB | SLAB_NO_MERGE)
5454

5555
#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \
5656
SLAB_CACHE_DMA32 | SLAB_ACCOUNT)

0 commit comments

Comments
 (0)