From: Alexander Potapenko <glider@google.com>
To: andrey.konovalov@linux.dev
Cc: Marco Elver <elver@google.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Peter Collingbourne <pcc@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
Andrey Ryabinin <aryabinin@virtuozzo.com>,
kasan-dev@googlegroups.com,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Will Deacon <will@kernel.org>,
linux-arm-kernel@lists.infradead.org,
Evgenii Stepanov <eugenis@google.com>,
linux-kernel@vger.kernel.org,
Andrey Konovalov <andreyknvl@google.com>
Subject: Re: [PATCH 03/31] kasan, page_alloc: merge kasan_free_pages into free_pages_prepare
Date: Thu, 2 Dec 2021 16:32:12 +0100 [thread overview]
Message-ID: <CAG_fn=V2PmihoVkyaNLJ2LMf4N1YsDJN1ZFbdsYecZdNHMdSpw@mail.gmail.com> (raw)
In-Reply-To: <64f8b74a4766f886a6df77438e7e098205fd0863.1638308023.git.andreyknvl@google.com>
On Tue, Nov 30, 2021 at 10:40 PM <andrey.konovalov@linux.dev> wrote:
>
> From: Andrey Konovalov <andreyknvl@google.com>
>
> Currently, the code responsible for initializing and poisoning memory
> in free_pages_prepare() is scattered across two locations:
> kasan_free_pages() for HW_TAGS KASAN and free_pages_prepare() itself.
> This is confusing.
>
> This and a few following patches combine the code from these two
> locations. Along the way, these patches also simplify the performed
> checks to make them easier to follow.
>
> This patch replaces the only caller of kasan_free_pages() with its
> implementation.
>
> As kasan_has_integrated_init() is only true when CONFIG_KASAN_HW_TAGS
> is enabled, moving the code does no functional changes.
>
> This patch is not useful by itself but makes the simplifications in
> the following patches easier to follow.
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
> ---
> include/linux/kasan.h | 8 --------
> mm/kasan/common.c | 2 +-
> mm/kasan/hw_tags.c | 11 -----------
> mm/page_alloc.c | 6 ++++--
> 4 files changed, 5 insertions(+), 22 deletions(-)
>
> diff --git a/include/linux/kasan.h b/include/linux/kasan.h
> index d8783b682669..89a43d8ae4fe 100644
> --- a/include/linux/kasan.h
> +++ b/include/linux/kasan.h
> @@ -95,7 +95,6 @@ static inline bool kasan_hw_tags_enabled(void)
> }
>
> void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags);
> -void kasan_free_pages(struct page *page, unsigned int order);
>
> #else /* CONFIG_KASAN_HW_TAGS */
>
> @@ -116,13 +115,6 @@ static __always_inline void kasan_alloc_pages(struct page *page,
> BUILD_BUG();
> }
>
> -static __always_inline void kasan_free_pages(struct page *page,
> - unsigned int order)
> -{
> - /* Only available for integrated init. */
> - BUILD_BUG();
> -}
> -
> #endif /* CONFIG_KASAN_HW_TAGS */
>
> static inline bool kasan_has_integrated_init(void)
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index 8428da2aaf17..66078cc1b4f0 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -387,7 +387,7 @@ static inline bool ____kasan_kfree_large(void *ptr, unsigned long ip)
> }
>
> /*
> - * The object will be poisoned by kasan_free_pages() or
> + * The object will be poisoned by kasan_poison_pages() or
> * kasan_slab_free_mempool().
> */
>
> diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c
> index 7355cb534e4f..0b8225add2e4 100644
> --- a/mm/kasan/hw_tags.c
> +++ b/mm/kasan/hw_tags.c
> @@ -213,17 +213,6 @@ void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags)
> }
> }
>
> -void kasan_free_pages(struct page *page, unsigned int order)
> -{
> - /*
> - * This condition should match the one in free_pages_prepare() in
> - * page_alloc.c.
> - */
> - bool init = want_init_on_free();
> -
> - kasan_poison_pages(page, order, init);
> -}
> -
> #if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
>
> void kasan_enable_tagging_sync(void)
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 3589333b5b77..3f3ea41f8c64 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1353,15 +1353,17 @@ static __always_inline bool free_pages_prepare(struct page *page,
>
> /*
> * As memory initialization might be integrated into KASAN,
> - * kasan_free_pages and kernel_init_free_pages must be
> + * KASAN poisoning and memory initialization code must be
> * kept together to avoid discrepancies in behavior.
> *
> * With hardware tag-based KASAN, memory tags must be set before the
> * page becomes unavailable via debug_pagealloc or arch_free_page.
> */
> if (kasan_has_integrated_init()) {
> + bool init = want_init_on_free();
> +
> if (!skip_kasan_poison)
> - kasan_free_pages(page, order);
> + kasan_poison_pages(page, order, init);
> } else {
> bool init = want_init_on_free();
>
> --
> 2.25.1
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/64f8b74a4766f886a6df77438e7e098205fd0863.1638308023.git.andreyknvl%40google.com.
--
Alexander Potapenko
Software Engineer
Google Germany GmbH
Erika-Mann-Straße, 33
80636 München
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
next prev parent reply other threads:[~2021-12-02 15:33 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-30 21:39 [PATCH 00/31] kasan, vmalloc, arm64: add vmalloc tagging support for SW/HW_TAGS andrey.konovalov
2021-11-30 21:39 ` [PATCH 01/31] kasan, page_alloc: deduplicate should_skip_kasan_poison andrey.konovalov
2021-11-30 21:39 ` [PATCH 02/31] kasan, page_alloc: move tag_clear_highpage out of kernel_init_free_pages andrey.konovalov
2021-12-02 15:24 ` Alexander Potapenko
2021-11-30 21:39 ` [PATCH 03/31] kasan, page_alloc: merge kasan_free_pages into free_pages_prepare andrey.konovalov
2021-12-02 15:32 ` Alexander Potapenko [this message]
2021-11-30 21:39 ` [PATCH 04/31] kasan, page_alloc: simplify kasan_poison_pages call site andrey.konovalov
2021-12-01 14:09 ` Marco Elver
2021-12-06 21:07 ` Andrey Konovalov
2021-11-30 21:39 ` [PATCH 05/31] kasan, page_alloc: init memory of skipped pages on free andrey.konovalov
2021-11-30 21:41 ` [PATCH 06/31] mm: clarify __GFP_ZEROTAGS comment andrey.konovalov
2021-11-30 21:41 ` [PATCH 07/31] kasan: only apply __GFP_ZEROTAGS when memory is zeroed andrey.konovalov
2021-12-02 15:40 ` Alexander Potapenko
2021-11-30 21:41 ` [PATCH 08/31] kasan, page_alloc: refactor init checks in post_alloc_hook andrey.konovalov
2021-12-02 16:13 ` Alexander Potapenko
2021-12-06 21:09 ` Andrey Konovalov
2021-12-16 10:59 ` Alexander Potapenko
2021-11-30 21:42 ` [PATCH 09/31] kasan, page_alloc: merge kasan_alloc_pages into post_alloc_hook andrey.konovalov
2021-11-30 21:52 ` [PATCH 10/31] kasan, page_alloc: combine tag_clear_highpage calls in post_alloc_hook andrey.konovalov
2021-11-30 22:05 ` [PATCH 11/31] kasan, page_alloc: move SetPageSkipKASanPoison " andrey.konovalov
2021-11-30 22:05 ` [PATCH 12/31] kasan, page_alloc: move kernel_init_free_pages " andrey.konovalov
2021-11-30 22:05 ` [PATCH 13/31] kasan, page_alloc: simplify kasan_unpoison_pages call site andrey.konovalov
2021-11-30 22:06 ` [PATCH 14/31] kasan: clean up metadata byte definitions andrey.konovalov
2021-11-30 22:06 ` [PATCH 15/31] kasan: define KASAN_VMALLOC_INVALID for SW_TAGS andrey.konovalov
2021-11-30 22:06 ` [PATCH 16/31] kasan, x86, arm64, s390: rename functions for modules shadow andrey.konovalov
2021-11-30 22:06 ` [PATCH 17/31] kasan, vmalloc: drop outdated VM_KASAN comment andrey.konovalov
2021-11-30 22:07 ` [PATCH 18/31] kasan: reorder vmalloc hooks andrey.konovalov
2021-11-30 22:07 ` [PATCH 19/31] kasan: add wrappers for " andrey.konovalov
2021-11-30 22:07 ` [PATCH 20/31] kasan, vmalloc: reset tags in vmalloc functions andrey.konovalov
2021-12-02 14:17 ` Marco Elver
2021-12-06 21:08 ` Andrey Konovalov
2021-11-30 22:07 ` [PATCH 21/31] kasan, fork: don't tag stacks allocated with vmalloc andrey.konovalov
2021-12-02 14:27 ` Marco Elver
2021-12-06 21:08 ` Andrey Konovalov
2021-11-30 22:07 ` [PATCH 22/31] kasan, vmalloc: add vmalloc support to SW_TAGS andrey.konovalov
2021-11-30 22:07 ` [PATCH 23/31] kasan, arm64: allow KASAN_VMALLOC with SW_TAGS andrey.konovalov
2021-12-03 12:37 ` Marco Elver
2021-12-06 21:10 ` Andrey Konovalov
2021-11-30 22:07 ` [PATCH 24/31] kasan, vmalloc, arm64: mark vmalloc mappings as pgprot_tagged andrey.konovalov
2021-12-03 12:42 ` Marco Elver
2021-12-06 21:12 ` Andrey Konovalov
2021-11-30 22:08 ` [PATCH 25/31] kasan, vmalloc: don't unpoison VM_ALLOC pages before mapping andrey.konovalov
2021-11-30 22:08 ` [PATCH 26/31] kasan, page_alloc: allow skipping unpoisoning for HW_TAGS andrey.konovalov
2021-11-30 22:08 ` [PATCH 27/31] kasan, vmalloc: add vmalloc support to HW_TAGS andrey.konovalov
2021-12-03 12:41 ` Marco Elver
2021-12-06 21:12 ` Andrey Konovalov
2021-11-30 22:08 ` [PATCH 28/31] kasan: add kasan.vmalloc command line flag andrey.konovalov
2021-12-03 12:09 ` Marco Elver
2021-12-06 21:09 ` Andrey Konovalov
2021-11-30 22:08 ` [PATCH 29/31] kasan, arm64: allow KASAN_VMALLOC with HW_TAGS andrey.konovalov
2021-12-01 11:35 ` Marco Elver
2021-12-06 21:10 ` Andrey Konovalov
2021-12-03 12:40 ` Marco Elver
2021-12-06 21:10 ` Andrey Konovalov
2021-11-30 22:08 ` [PATCH 30/31] kasan: documentation updates andrey.konovalov
2021-11-30 22:08 ` [PATCH 31/31] kasan: improve vmalloc tests andrey.konovalov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAG_fn=V2PmihoVkyaNLJ2LMf4N1YsDJN1ZFbdsYecZdNHMdSpw@mail.gmail.com' \
--to=glider@google.com \
--cc=akpm@linux-foundation.org \
--cc=andrey.konovalov@linux.dev \
--cc=andreyknvl@gmail.com \
--cc=andreyknvl@google.com \
--cc=aryabinin@virtuozzo.com \
--cc=catalin.marinas@arm.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=eugenis@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pcc@google.com \
--cc=vincenzo.frascino@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).