kasan, page_alloc: move SetPageSkipKASanPoison in post_alloc_hook
authorAndrey Konovalov <andreyknvl@google.com>
Fri, 25 Mar 2022 01:10:37 +0000 (18:10 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 25 Mar 2022 02:06:46 +0000 (19:06 -0700)
Pull the SetPageSkipKASanPoison() call in post_alloc_hook() out of the big
if clause for better code readability.  This also allows for more
simplifications in the following patches.

Also turn the kasan_has_integrated_init() check into the proper
kasan_hw_tags_enabled() one.  These checks evaluate to the same value, but
logically skipping kasan poisoning has nothing to do with integrated init.

Link: https://lkml.kernel.org/r/7214c1698b754ccfaa44a792113c95cc1f807c48.1643047180.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Acked-by: Marco Elver <elver@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Collingbourne <pcc@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/page_alloc.c

index 9d14ec37fd12af01e13fa88162ad2e23095aa2b2..7a5040d8e48eb81443d862f0450c87a44d036f09 100644 (file)
@@ -2383,9 +2383,6 @@ inline void post_alloc_hook(struct page *page, unsigned int order,
                init = false;
        }
        if (kasan_has_integrated_init()) {
-               if (gfp_flags & __GFP_SKIP_KASAN_POISON)
-                       SetPageSkipKASanPoison(page);
-
                if (!init_tags)
                        kasan_unpoison_pages(page, order, init);
        } else {
@@ -2394,6 +2391,9 @@ inline void post_alloc_hook(struct page *page, unsigned int order,
                if (init)
                        kernel_init_free_pages(page, 1 << order);
        }
+       /* Propagate __GFP_SKIP_KASAN_POISON to page flags. */
+       if (kasan_hw_tags_enabled() && (gfp_flags & __GFP_SKIP_KASAN_POISON))
+               SetPageSkipKASanPoison(page);
 
        set_page_owner(page, order, gfp_flags);
        page_table_check_alloc(page, order);