From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CDC4C64EC7 for ; Tue, 28 Feb 2023 20:48:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C73036B0078; Tue, 28 Feb 2023 15:48:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C492C6B007B; Tue, 28 Feb 2023 15:48:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEAF26B007D; Tue, 28 Feb 2023 15:48:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9BDC96B0078 for ; Tue, 28 Feb 2023 15:48:23 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4DC65120C3F for ; Tue, 28 Feb 2023 20:48:23 +0000 (UTC) X-FDA: 80517888486.27.3AD1AD5 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf29.hostedemail.com (Postfix) with ESMTP id 593D312001A for ; Tue, 28 Feb 2023 20:48:21 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AvBFEisD; spf=pass (imf29.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677617301; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QjEipJ5COAgM/CUAr8aRHqd6+hTCueASmrwYUwgRgIw=; b=t90PdKc5C4Jyu5n0+JszIsCQ0pS1iZuVPe4j9udB9gyMnR4A9E/1sBGNH+Py0U6b66qX1q LUoCr1q+pZqi7yRSzAZWdFFQoYRj0hRh8jRxa/UIBhQXCJ15CdtURHaB03SeEDNvn18Gyz 5lKjyLWvsJPT/KPJ1bXsOaVwn/gKTJk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AvBFEisD; spf=pass (imf29.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677617301; a=rsa-sha256; cv=none; b=cfyZLbObFkjb9Z1qIYHdKxItDqwRSSl/tgqL2emMhY5q7H6x3FR8U0/wmut6w8jo/8Er9m aJiEhmqAfzpgWsNaO6Zv65HsRGE1cnNSqMpkBk3XV7oHOBowCSZ7O5Q5ySub2wvjNCecSi v9PJC89wdNS6iz1P0XH8EYRfbv8VLOM= Received: by mail-pg1-f182.google.com with SMTP id z10so6461675pgr.8 for ; Tue, 28 Feb 2023 12:48:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677617300; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QjEipJ5COAgM/CUAr8aRHqd6+hTCueASmrwYUwgRgIw=; b=AvBFEisDTdMwTDwqSAAgc0FZYu42ZDgm92BJxwrkxgxP56uInsoY+e9PMNQow6Z94F enx1z4bjrUJHUtkvvkeBSF3qKRmOLbkcsEhPr73AvDBBJb+W1N6EuwaDXPD9H+CPD1aw 7g3tk2qzmVIEgfvaLmpO8WTIukLGMxB3gzUWPiNOyinC3K/gZVBVu8/abpA4czOgTlwl tnutKscFE+CPNO1PP/rChyymdKANUmp2gQice9xHb5+dvQy7ff6mM7iSV4B9zk6R6lSh BXyZdJJK1pymZeOUyEV5eGgvSkRtaIqlRl9xx+sON2wmXoCloUpuMPtyL+SiMEuI7l0X 5dNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677617300; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QjEipJ5COAgM/CUAr8aRHqd6+hTCueASmrwYUwgRgIw=; b=Ysr1JM3jLLQpqFhb+Tpe+NIL71Ex4PlcrPgD9zFg+eKyC7aTdDBD2mWljaeiqFelZt hFIOiyYd96jcHWcVx3+JupcIiLoF6+d0JW+9zEwxaayDlyiQo8lbSpSF0Ek1Bx/Gk3lc pEFdmbKTHP1oFD2EUA1yOK1T5SDR6dkJPIHehpxUj4cHCd7CeAlbELwIYPuYA3Vm/lhu 3iflEf2KeTcXgLVeFmtRPiAbHIquZSqNfxWfbQ/383sBpjsNLIXogSeR52K9m+p9QjWN 1BduF6OodiP+/md76HyMFRYnXG645dRygWZB2y0atA8pocI5laXF/pC+yhw8Ip6mFU4d iypw== X-Gm-Message-State: AO0yUKUyANC+cgAM/ItxXr/KF4t5zeg10DUKf+wMtH3a5Z/a+1+pSCcT fgQgHXzRQcujG7/k1j/5aw/XNfbewbpOUoFQcrQ= X-Google-Smtp-Source: AK7set8DG7c0N+BDSNYTgbQrxPtLdJpfPYCvjaHj46YmCKPSJqjF6cEKdQw/JUZ2zLj6Gtjnq3YZdCq6nLbuk6VQK3w= X-Received: by 2002:a63:7d59:0:b0:502:e6c0:88a4 with SMTP id m25-20020a637d59000000b00502e6c088a4mr1324263pgn.5.1677617299741; Tue, 28 Feb 2023 12:48:19 -0800 (PST) MIME-Version: 1.0 References: <20230228063240.3613139-1-pcc@google.com> <20230228063240.3613139-3-pcc@google.com> In-Reply-To: <20230228063240.3613139-3-pcc@google.com> From: Andrey Konovalov Date: Tue, 28 Feb 2023 21:48:08 +0100 Message-ID: Subject: Re: [PATCH v2 2/2] kasan: remove PG_skip_kasan_poison flag To: Peter Collingbourne Cc: catalin.marinas@arm.com, linux-mm@kvack.org, kasan-dev@googlegroups.com, ryabinin.a.a@gmail.com, linux-arm-kernel@lists.infradead.org, vincenzo.frascino@arm.com, will@kernel.org, eugenis@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 593D312001A X-Stat-Signature: utuifgqkkqcs7rfcdjq6joont9i1sh9h X-Rspam-User: X-HE-Tag: 1677617301-373466 X-HE-Meta: U2FsdGVkX18prIT4sKE/uTST5D3ID7rvG3+7vQxfyCBPLiCKV0K9mqd1daqEiXt5RyO6OPZkNdmgIg6znarLdGb241ZxZeM8+noFi/wYDNm8cJz5JqqtFkd2lSvhVGqkoVNWT5ek+iEhLhS0FI9vSYdcPn23RZiv4CzZMU4BZkywUsJ2MLfbOCp1hOF0tWei1YBKMT+0JC+7+VD7AJJ7u87+6mpacc8/UNGWxh7lyU+8vJZyrm87108mY9JnNes1WNWXCfPhsyejF7HRLGMe5Tetfj6TKpNw7Phc6RPZovvNDstlianhehTBjB/osC071C7biTEZWyCJKWNMPYvtUOa9EbNFsEhlcK4oljU8uhSzWnZ9SBrfxvuFwyGSJCjAM9sqGWYreW/izJZhGqbzMFa/TF6GIE/hivIJHNySfg9nojM/wrjOPIkG8BgudZtCvdIPgsn0QuYIn9ufmYjefccqhnUtoYouHEP482jylTfR9ZiBvV/WIKCVeasw+zUaAXBny2IX67kYZQTqGArC6b5YdWkBIus5PoNox7pFVKp9rj/1Er2t93FalBGgPCBLKXrHO/OTo5NwW3phWjKUhNh6j2smAtoZ3H9i0n8w4QDNpLKuAOVcfJPsVKmaiA3JURbx1lCFV52vWxEgxNmTclKi6mASzsV/33ne67T055nNaXX9iXCr5xERJtjYRRe5AQx7IHk5WHNqTsoURnUEEinR32/HfyrtXdCsqtR6XXElfyOok1upcM00AwtQ/DW6iTRJzGdHsZ+/G4ATzMZEV4/L4iyPii2csK9nXbGri6gtVC3EflJkTnse+8/YElu0xLEJo9EicF9iU1HJdoAMWFuYKEGZblnO74OU4pHZKJ2O9GbVoF38b0o7u6+gQdglN83B6d7ZRP2mwuPpLkhM3HHYrwcPYmNAcyfRxw0eoSXcuBcuV7yehQN0u9Et7jVRdGr6ql7XZkYQX03de8A VoNIj78I /ewjkte/3tn6PBfh8TPXuOnSRungA3SehvPUtddziBtZqsZgzBQJE9e1zPy72udsljsnCGf+lSTzx9Up950f431P3kVmyYntLZIiBPDp1NMzRiQDh9F0RVElsNciZdc/J8ZB4Dp/Zds045SnvuqJGswZMlr+iFKJjej/CFX+eaq7CtlDZ4ms7E3RhG+qOp29RJ22FPcO0hY+Vgcgr2c5Ex/DZRiSsDlTiO801OPwCFChB2dTP7kfg4bxqrj/eTzELD1dNoy4/1LRobhufJGbTZqgT676/JvT1AMZFxno0Z3TsPZdG2Gtnd8DD/qI76ZV2pUuwM7IDi5UbgcbNz+xAY2tCmUf/I9Q4e5Zr9GN4JDsGoVlbxA243HrvVKzVbLVZ58Xk8jjEMppu7UWeGikXyy+X0oo58fzmkaReb8tHaq4wCJuFgQf0xtIEDyLkHj5/kZSzRBycp5WAytP531DSe7CFCOqTPe7Nk4x78SZbzVxEcTHBh3v69WJDKsz7V0BpaOor+AUPmrxUWm7KyIcaSO7968EheH4bnQ8jA6ImqU34HBmkA2KcSlLjAnHlNAii6Di3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Feb 28, 2023 at 7:32=E2=80=AFAM Peter Collingbourne wrote: > > Code inspection reveals that PG_skip_kasan_poison is redundant with > kasantag, because the former is intended to be set iff the latter is > the match-all tag. It can also be observed that it's basically pointless > to poison pages which have kasantag=3D0, because any pages with this tag > would have been pointed to by pointers with match-all tags, so poisoning > the pages would have little to no effect in terms of bug detection. > Therefore, change the condition in should_skip_kasan_poison() to check > kasantag instead, and remove PG_skip_kasan_poison and associated flags. > > Signed-off-by: Peter Collingbourne > Link: https://linux-review.googlesource.com/id/I57f825f2eaeaf7e8389d6cf45= 97c8a5821359838 > --- > v2: > - also remove GFP_SKIP_KASAN_POISON and FPI_SKIP_KASAN_POISON > - rename GFP_SKIP_KASAN_UNPOISON to GFP_SKIP_KASAN > - update comments > - simplify control flow by removing reset_tags > > include/linux/gfp_types.h | 28 +++++------- > include/linux/page-flags.h | 9 ---- > include/trace/events/mmflags.h | 12 +----- > mm/kasan/hw_tags.c | 2 +- > mm/page_alloc.c | 79 +++++++++++++--------------------- > mm/vmalloc.c | 2 +- > 6 files changed, 44 insertions(+), 88 deletions(-) > > diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h > index 5088637fe5c2..9bd45cdd19ac 100644 > --- a/include/linux/gfp_types.h > +++ b/include/linux/gfp_types.h > @@ -47,16 +47,14 @@ typedef unsigned int __bitwise gfp_t; > #define ___GFP_ACCOUNT 0x400000u > #define ___GFP_ZEROTAGS 0x800000u > #ifdef CONFIG_KASAN_HW_TAGS > -#define ___GFP_SKIP_ZERO 0x1000000u > -#define ___GFP_SKIP_KASAN_UNPOISON 0x2000000u > -#define ___GFP_SKIP_KASAN_POISON 0x4000000u > +#define ___GFP_SKIP_ZERO 0x1000000u > +#define ___GFP_SKIP_KASAN 0x2000000u > #else > -#define ___GFP_SKIP_ZERO 0 > -#define ___GFP_SKIP_KASAN_UNPOISON 0 > -#define ___GFP_SKIP_KASAN_POISON 0 > +#define ___GFP_SKIP_ZERO 0 > +#define ___GFP_SKIP_KASAN 0 > #endif > #ifdef CONFIG_LOCKDEP > -#define ___GFP_NOLOCKDEP 0x8000000u > +#define ___GFP_NOLOCKDEP 0x4000000u > #else > #define ___GFP_NOLOCKDEP 0 > #endif > @@ -234,25 +232,22 @@ typedef unsigned int __bitwise gfp_t; > * memory tags at the same time as zeroing memory has minimal additional > * performace impact. > * > - * %__GFP_SKIP_KASAN_UNPOISON makes KASAN skip unpoisoning on page alloc= ation. > - * Only effective in HW_TAGS mode. > - * > - * %__GFP_SKIP_KASAN_POISON makes KASAN skip poisoning on page deallocat= ion. > - * Typically, used for userspace pages. Only effective in HW_TAGS mode. > + * %__GFP_SKIP_KASAN makes KASAN skip unpoisoning on page allocation and > + * poisoning on page deallocation. Typically used for userspace and vmal= loc > + * pages. Only effective in HW_TAGS mode. This is not entirely correct: for vmalloc pages, this flag doesn't result in poisoning being skipped, as the memory is unpoisoned and page tags are assigned by kasan_unpoison_vmalloc. How about something like this: %__GFP_SKIP_KASAN makes KASAN skip unpoisoning on page allocation. Used for userspace and vmalloc pages; the latter are unpoisoned by kasan_unpoison_vmalloc instead. For userspace pages, results in poisoning being skipped as well, see should_skip_kasan_poison for details. Only effective in HW_TAGS mode. > */ > #define __GFP_NOWARN ((__force gfp_t)___GFP_NOWARN) > #define __GFP_COMP ((__force gfp_t)___GFP_COMP) > #define __GFP_ZERO ((__force gfp_t)___GFP_ZERO) > #define __GFP_ZEROTAGS ((__force gfp_t)___GFP_ZEROTAGS) > #define __GFP_SKIP_ZERO ((__force gfp_t)___GFP_SKIP_ZERO) > -#define __GFP_SKIP_KASAN_UNPOISON ((__force gfp_t)___GFP_SKIP_KASAN_UNPO= ISON) > -#define __GFP_SKIP_KASAN_POISON ((__force gfp_t)___GFP_SKIP_KASAN_POIS= ON) > +#define __GFP_SKIP_KASAN ((__force gfp_t)___GFP_SKIP_KASAN) > > /* Disable lockdep for GFP context tracking */ > #define __GFP_NOLOCKDEP ((__force gfp_t)___GFP_NOLOCKDEP) > > /* Room for N __GFP_FOO bits */ > -#define __GFP_BITS_SHIFT (27 + IS_ENABLED(CONFIG_LOCKDEP)) > +#define __GFP_BITS_SHIFT (26 + IS_ENABLED(CONFIG_LOCKDEP)) > #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) > > /** > @@ -335,8 +330,7 @@ typedef unsigned int __bitwise gfp_t; > #define GFP_DMA __GFP_DMA > #define GFP_DMA32 __GFP_DMA32 > #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) > -#define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE | \ > - __GFP_SKIP_KASAN_POISON | __GFP_SKIP_KASAN_UNPOI= SON) > +#define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE | __GFP_SKI= P_KASAN) > #define GFP_TRANSHUGE_LIGHT ((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ > __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAI= M) > #define GFP_TRANSHUGE (GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM) > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > index a7e3a3405520..74f81a52e7e1 100644 > --- a/include/linux/page-flags.h > +++ b/include/linux/page-flags.h > @@ -135,9 +135,6 @@ enum pageflags { > #ifdef CONFIG_ARCH_USES_PG_ARCH_X > PG_arch_2, > PG_arch_3, > -#endif > -#ifdef CONFIG_KASAN_HW_TAGS > - PG_skip_kasan_poison, > #endif > __NR_PAGEFLAGS, > > @@ -594,12 +591,6 @@ TESTCLEARFLAG(Young, young, PF_ANY) > PAGEFLAG(Idle, idle, PF_ANY) > #endif > > -#ifdef CONFIG_KASAN_HW_TAGS > -PAGEFLAG(SkipKASanPoison, skip_kasan_poison, PF_HEAD) > -#else > -PAGEFLAG_FALSE(SkipKASanPoison, skip_kasan_poison) > -#endif > - > /* > * PageReported() is used to track reported free pages within the Buddy > * allocator. We can use the non-atomic version of the test and set > diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflag= s.h > index 9db52bc4ce19..232bc8efc98e 100644 > --- a/include/trace/events/mmflags.h > +++ b/include/trace/events/mmflags.h > @@ -55,8 +55,7 @@ > #ifdef CONFIG_KASAN_HW_TAGS > #define __def_gfpflag_names_kasan , \ > gfpflag_string(__GFP_SKIP_ZERO), \ > - gfpflag_string(__GFP_SKIP_KASAN_POISON), \ > - gfpflag_string(__GFP_SKIP_KASAN_UNPOISON) > + gfpflag_string(__GFP_SKIP_KASAN) > #else > #define __def_gfpflag_names_kasan > #endif > @@ -96,12 +95,6 @@ > #define IF_HAVE_PG_ARCH_X(flag,string) > #endif > > -#ifdef CONFIG_KASAN_HW_TAGS > -#define IF_HAVE_PG_SKIP_KASAN_POISON(flag,string) ,{1UL << flag, string} > -#else > -#define IF_HAVE_PG_SKIP_KASAN_POISON(flag,string) > -#endif > - > #define __def_pageflag_names \ > {1UL << PG_locked, "locked" }, \ > {1UL << PG_waiters, "waiters" }, \ > @@ -130,8 +123,7 @@ IF_HAVE_PG_HWPOISON(PG_hwpoison, "hwpoison" )= \ > IF_HAVE_PG_IDLE(PG_young, "young" ) \ > IF_HAVE_PG_IDLE(PG_idle, "idle" ) \ > IF_HAVE_PG_ARCH_X(PG_arch_2, "arch_2" ) \ > -IF_HAVE_PG_ARCH_X(PG_arch_3, "arch_3" ) \ > -IF_HAVE_PG_SKIP_KASAN_POISON(PG_skip_kasan_poison, "skip_kasan_poison") > +IF_HAVE_PG_ARCH_X(PG_arch_3, "arch_3" ) > > #define show_page_flags(flags) \ > (flags) ? __print_flags(flags, "|", \ > diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c > index d1bcb0205327..bb4f56e5bdec 100644 > --- a/mm/kasan/hw_tags.c > +++ b/mm/kasan/hw_tags.c > @@ -318,7 +318,7 @@ void *__kasan_unpoison_vmalloc(const void *start, uns= igned long size, > * Thus, for VM_ALLOC mappings, hardware tag-based KASAN only tag= s > * the first virtual mapping, which is created by vmalloc(). > * Tagging the page_alloc memory backing that vmalloc() allocatio= n is > - * skipped, see ___GFP_SKIP_KASAN_UNPOISON. > + * skipped, see ___GFP_SKIP_KASAN. > * > * For non-VM_ALLOC allocations, page_alloc memory is tagged as u= sual. > */ > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 7136c36c5d01..960e0edd413d 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -112,17 +112,6 @@ typedef int __bitwise fpi_t; > */ > #define FPI_TO_TAIL ((__force fpi_t)BIT(1)) > > -/* > - * Don't poison memory with KASAN (only for the tag-based modes). > - * During boot, all non-reserved memblock memory is exposed to page_allo= c. > - * Poisoning all that memory lengthens boot time, especially on systems = with > - * large amount of RAM. This flag is used to skip that poisoning. > - * This is only done for the tag-based KASAN modes, as those are able to > - * detect memory corruptions with the memory tags assigned by default. > - * All memory allocated normally after boot gets poisoned as usual. > - */ > -#define FPI_SKIP_KASAN_POISON ((__force fpi_t)BIT(2)) > - > /* prevent >1 _updater_ of zone percpu pageset ->high and ->batch fields= */ > static DEFINE_MUTEX(pcp_batch_high_lock); > #define MIN_PERCPU_PAGELIST_HIGH_FRACTION (8) > @@ -1355,13 +1344,19 @@ static int free_tail_pages_check(struct page *hea= d_page, struct page *page) > /* > * Skip KASAN memory poisoning when either: > * > - * 1. Deferred memory initialization has not yet completed, > - * see the explanation below. > - * 2. Skipping poisoning is requested via FPI_SKIP_KASAN_POISON, > - * see the comment next to it. > - * 3. Skipping poisoning is requested via __GFP_SKIP_KASAN_POISON, > + * 1. For generic KASAN: deferred memory initialization has not yet comp= leted. > + * Tag-based KASAN modes skip pages freed via deferred memory initial= ization > + * using page tags instead (see below). > + * 2. For tag-based KASAN: the page has a match-all KASAN tag, indicatin= g For tag-based KASAN modes: ... > + * that error detection is disabled for accesses via the page address= . > + * > + * Pages will have match-all tags in the following circumstances: > + * > + * 1. Skipping poisoning is requested via __GFP_SKIP_KASAN, > * see the comment next to it. According to the vmalloc thing I mentioned above, let's reword this to: The allocation was not unpoisoned due to __GFP_SKIP_KASAN, with the exception of pages unpoisoned by kasan_unpoison_vmalloc. > - * 4. The allocation is excluded from being checked due to sampling, > + * 2. Pages are being initialized for the first time, including during d= eferred > + * memory init; see the call to page_kasan_tag_reset in __init_single= _page. Let's put this item first in the list. > + * 3. The allocation is excluded from being checked due to sampling, "is" -> "was" possibly sounds better with "was" in #1. > * see the call to kasan_unpoison_pages. > * > * Poisoning pages during deferred memory init will greatly lengthen the > @@ -1377,10 +1372,10 @@ static int free_tail_pages_check(struct page *hea= d_page, struct page *page) > */ > static inline bool should_skip_kasan_poison(struct page *page, fpi_t fpi= _flags) > { > - return deferred_pages_enabled() || > - (!IS_ENABLED(CONFIG_KASAN_GENERIC) && > - (fpi_flags & FPI_SKIP_KASAN_POISON)) || > - PageSkipKASanPoison(page); > + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) > + return deferred_pages_enabled(); > + > + return page_kasan_tag(page) =3D=3D 0xff; > } > > static void kernel_init_pages(struct page *page, int numpages) > @@ -1754,7 +1749,7 @@ void __free_pages_core(struct page *page, unsigned = int order) > * Bypass PCP and place fresh pages right to the tail, primarily > * relevant for memory onlining. > */ > - __free_pages_ok(page, order, FPI_TO_TAIL | FPI_SKIP_KASAN_POISON)= ; > + __free_pages_ok(page, order, FPI_TO_TAIL); > } > > #ifdef CONFIG_NUMA > @@ -2456,9 +2451,9 @@ static inline bool should_skip_kasan_unpoison(gfp_t= flags) > > /* > * With hardware tag-based KASAN enabled, skip if this has been > - * requested via __GFP_SKIP_KASAN_UNPOISON. > + * requested via __GFP_SKIP_KASAN. > */ > - return flags & __GFP_SKIP_KASAN_UNPOISON; > + return flags & __GFP_SKIP_KASAN; > } > > static inline bool should_skip_init(gfp_t flags) > @@ -2477,7 +2472,6 @@ inline void post_alloc_hook(struct page *page, unsi= gned int order, > bool init =3D !want_init_on_free() && want_init_on_alloc(gfp_flag= s) && > !should_skip_init(gfp_flags); > bool zero_tags =3D init && (gfp_flags & __GFP_ZEROTAGS); > - bool reset_tags =3D true; > int i; > > set_page_private(page, 0); > @@ -2511,37 +2505,22 @@ inline void post_alloc_hook(struct page *page, un= signed int order, > /* Take note that memory was initialized by the loop abov= e. */ > init =3D false; > } > - if (!should_skip_kasan_unpoison(gfp_flags)) { > - /* Try unpoisoning (or setting tags) and initializing mem= ory. */ > - if (kasan_unpoison_pages(page, order, init)) { > - /* Take note that memory was initialized by KASAN= . */ > - if (kasan_has_integrated_init()) > - init =3D false; > - /* Take note that memory tags were set by KASAN. = */ > - reset_tags =3D false; > - } else { > - /* > - * KASAN decided to exclude this allocation from = being > - * (un)poisoned due to sampling. Make KASAN skip > - * poisoning when the allocation is freed. > - */ > - SetPageSkipKASanPoison(page); > - } > - } > - /* > - * If memory tags have not been set by KASAN, reset the page tags= to > - * ensure page_address() dereferencing does not fault. > - */ > - if (reset_tags) { > + if (!should_skip_kasan_unpoison(gfp_flags) && > + kasan_unpoison_pages(page, order, init)) { > + /* Take note that memory was initialized by KASAN. */ > + if (kasan_has_integrated_init()) > + init =3D false; > + } else { > + /* > + * If memory tags have not been set by KASAN, reset the p= age > + * tags to ensure page_address() dereferencing does not f= ault. > + */ > for (i =3D 0; i !=3D 1 << order; ++i) > page_kasan_tag_reset(page + i); > } > /* If memory is still not initialized, initialize it now. */ > if (init) > kernel_init_pages(page, 1 << order); > - /* Propagate __GFP_SKIP_KASAN_POISON to page flags. */ > - if (kasan_hw_tags_enabled() && (gfp_flags & __GFP_SKIP_KASAN_POIS= ON)) > - SetPageSkipKASanPoison(page); > > set_page_owner(page, order, gfp_flags); > page_table_check_alloc(page, order); > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index ef910bf349e1..b0c84847e9b6 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -3170,7 +3170,7 @@ void *__vmalloc_node_range(unsigned long size, unsi= gned long align, > * pages backing VM_ALLOC mapping. Memory is inst= ead > * poisoned and zeroed by kasan_unpoison_vmalloc(= ). > */ > - gfp_mask |=3D __GFP_SKIP_KASAN_UNPOISON | __GFP_S= KIP_ZERO; > + gfp_mask |=3D __GFP_SKIP_KASAN | __GFP_SKIP_ZERO; > } > > /* Take note that the mapping is PAGE_KERNEL. */ > -- > 2.39.2.722.g9855ee24e9-goog >