mm: introduce clear_highpage_kasan_tagged
authorAndrey Konovalov <andreyknvl@google.com>
Thu, 9 Jun 2022 18:18:46 +0000 (20:18 +0200)
committerakpm <akpm@linux-foundation.org>
Mon, 4 Jul 2022 01:08:39 +0000 (18:08 -0700)
Add a clear_highpage_kasan_tagged() helper that does clear_highpage() on a
page potentially tagged by KASAN.

This helper is used by the following patch.

Link: https://lkml.kernel.org/r/4471979b46b2c487787ddcd08b9dc5fedd1b6ffd.1654798516.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/highmem.h
mm/page_alloc.c

index fee9835e37931b4db3f67803809b5a79b955ad42..22379a63e293fbd0542607bc2af2d81bdb933d5d 100644 (file)
@@ -243,6 +243,16 @@ static inline void clear_highpage(struct page *page)
        kunmap_local(kaddr);
 }
 
+static inline void clear_highpage_kasan_tagged(struct page *page)
+{
+       u8 tag;
+
+       tag = page_kasan_tag(page);
+       page_kasan_tag_reset(page);
+       clear_highpage(page);
+       page_kasan_tag_set(page, tag);
+}
+
 #ifndef __HAVE_ARCH_TAG_CLEAR_HIGHPAGE
 
 static inline void tag_clear_highpage(struct page *page)
index 9234863f2488ef2581741cafe31b43ebc5d18034..248469134962c320b42ad6ae3e492d7e92f433b2 100644 (file)
@@ -1302,12 +1302,8 @@ static void kernel_init_pages(struct page *page, int numpages)
 
        /* s390's use of memset() could override KASAN redzones. */
        kasan_disable_current();
-       for (i = 0; i < numpages; i++) {
-               u8 tag = page_kasan_tag(page + i);
-               page_kasan_tag_reset(page + i);
-               clear_highpage(page + i);
-               page_kasan_tag_set(page + i, tag);
-       }
+       for (i = 0; i < numpages; i++)
+               clear_highpage_kasan_tagged(page + i);
        kasan_enable_current();
 }