path: root/mm/kasan
diff options
authorAndrey Konovalov <>2020-12-22 12:03:31 -0800
committerLinus Torvalds <>2020-12-22 12:55:09 -0800
commite86f8b09f215e3755cd2d56930487dec2de02433 (patch)
tree173bea4212fa9992e00bcf5e5ff178ecae402ed3 /mm/kasan
parent97593cad003c668e2532cb2939a24a031f8de52d (diff)
kasan, mm: allow cache merging with no metadata
The reason cache merging is disabled with KASAN is because KASAN puts its metadata right after the allocated object. When the merged caches have slightly different sizes, the metadata ends up in different places, which KASAN doesn't support. It might be possible to adjust the metadata allocation algorithm and make it friendly to the cache merging code. Instead this change takes a simpler approach and allows merging caches when no metadata is present. Which is the case for hardware tag-based KASAN with kasan.mode=prod. Link: Link: Co-developed-by: Vincenzo Frascino <> Signed-off-by: Vincenzo Frascino <> Signed-off-by: Andrey Konovalov <> Reviewed-by: Dmitry Vyukov <> Reviewed-by: Marco Elver <> Tested-by: Vincenzo Frascino <> Cc: Alexander Potapenko <> Cc: Andrey Ryabinin <> Cc: Branislav Rankov <> Cc: Catalin Marinas <> Cc: Evgenii Stepanov <> Cc: Kevin Brodsky <> Cc: Vasily Gorbik <> Cc: Will Deacon <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'mm/kasan')
1 files changed, 11 insertions, 0 deletions
diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index 0cd583d2fe1c..b25167664ead 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -86,6 +86,17 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark)
+ * Only allow cache merging when stack collection is disabled and no metadata
+ * is present.
+ */
+slab_flags_t __kasan_never_merge(void)
+ if (kasan_stack_collection_enabled())
+ return SLAB_KASAN;
+ return 0;
void __kasan_alloc_pages(struct page *page, unsigned int order)
u8 tag;