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 3B3EEC64ED6 for ; Tue, 28 Feb 2023 06:33:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEC676B0078; Tue, 28 Feb 2023 01:33:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B9C7D6B007B; Tue, 28 Feb 2023 01:33:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8C4F6B007D; Tue, 28 Feb 2023 01:33:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9AA566B0078 for ; Tue, 28 Feb 2023 01:33:21 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 72E3E1A05AD for ; Tue, 28 Feb 2023 06:33:21 +0000 (UTC) X-FDA: 80515733802.17.334E17C Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by imf18.hostedemail.com (Postfix) with ESMTP id 9D1E11C000C for ; Tue, 28 Feb 2023 06:33:19 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hpEGmJ1V; spf=pass (imf18.hostedemail.com: domain of pcc@google.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=pcc@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677565999; 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=bUIZxkEW9znfcwTzBX3QFKfrO4/r5gi0IWGewBBrVw0=; b=pXd9rXU7yhqMb6y5+7SOadtK61EMJMU27oCI0/qztH1G3ZxiAqbyxdjkR7+Rmfvp/AuLLa +xzO7FjhRUMRIEijbKseHb4dZxGj7FVyOHYuqtxLAaxqfasSJAtOg9e3Wbq1aUhIHaaGg1 caqeli64eFLh8YYZJJBgmaHINAiTVvw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hpEGmJ1V; spf=pass (imf18.hostedemail.com: domain of pcc@google.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=pcc@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677565999; a=rsa-sha256; cv=none; b=Xm5WoWoVBJASONy1iFDcB3GiSNv7qkki58hVnfJWhhEeVYsIDP88h6cExS92yQyqOjzFDA 7RE19bnYg4MUs3pZeR0NfLgAKFA8Uljo4LvH6qSQ3eqnu/AN5RfipsxEZhsHrTd8tuaYbn YW+Xw8Gkc7I2iIts8b9EjRKuoAjnlpc= Received: by mail-wr1-f47.google.com with SMTP id bt28so8548176wrb.8 for ; Mon, 27 Feb 2023 22:33:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677565998; 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=bUIZxkEW9znfcwTzBX3QFKfrO4/r5gi0IWGewBBrVw0=; b=hpEGmJ1VRAoVgBvkLxEdOhVpwuMPAY99+INa9DnofHimHk5+gMDB1xqRGXn+GI1LUM 6hsosFw/tADCki03WFhHlzdK//SQoA6GUCPEnKx4B74tBwJ+XiT19FCOlpJvyF8oK/+K 4SntLliiYle8+6777xcKqWMIdd5pIFQi5N4Ssw5ZSBVEsCPI3kxeahEaK2sBF0qrkLHb qZYHY4di+BMbxifU9upchRjdySdTPZFmfWQ/SzZlYYhofzksoOUui3sMuic6LdAtM/uI nGGPKgFrkZrxaU6zxoChQi0agUw2nyRdINqgXeprgpaebWWAFVF51U+OmF5Bldy9Q+L5 TvpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677565998; 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=bUIZxkEW9znfcwTzBX3QFKfrO4/r5gi0IWGewBBrVw0=; b=Bpn7LIqiZiQ0UKskXNGwuys+eWU5uWA8B8SVQE1V08Ues+y7CqTRNpH2SgbJTzMQHg Rr/euYxdL02z5b+ShDU2yLpNPlXNZ1MpXsJYYj6l4IOVB0IkzmkvWWVu9eWCSEoG/dJ2 G8YsVcJDTsB8gMbKinFsDryF9SKzT/1f3bWcSfhVvaEjxIC0zUBNywiGEoYK97RPSNIY QAL30leiD4xfS8SZpM4RLG+IZCJHujUzyrCCQtCNx8WP4D50UtNDuUKZhv5srtS0FYiA q2/+iruj0x9kHbfw9wf1uTO7U4qd8MNXIndZJn1XgWGElMMWvcZzkzeJA5xA+xlf0w6C s6kg== X-Gm-Message-State: AO0yUKU/eNTINjnO6vHFZjvJnEBw5GpDx/Y9mAQUm5KTBeZvjfM3fU8a yPpfLBQvO+SsScGXCkelrMTfsWtWcvQCoH1C5dV8/w== X-Google-Smtp-Source: AK7set+146C9X/Hnww/n3dj0cL2N4sjHrgeUzZucSWq/azRblhlfMj6WO+9pQ7DD54/k8aI1rFla7uO/5f8Jdh7Y3qU= X-Received: by 2002:a5d:4d03:0:b0:2c5:3fcb:682b with SMTP id z3-20020a5d4d03000000b002c53fcb682bmr285444wrt.2.1677565997813; Mon, 27 Feb 2023 22:33:17 -0800 (PST) MIME-Version: 1.0 References: <20230224065128.505605-1-pcc@google.com> In-Reply-To: From: Peter Collingbourne Date: Mon, 27 Feb 2023 22:33:05 -0800 Message-ID: Subject: Re: [PATCH] kasan: remove PG_skip_kasan_poison flag To: Andrey Konovalov 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: rspam07 X-Rspamd-Queue-Id: 9D1E11C000C X-Rspam-User: X-Stat-Signature: it7wzxeeg8eqka9wwu94ooot3fbyenob X-HE-Tag: 1677565999-175870 X-HE-Meta: U2FsdGVkX1/fQyPRAAHQHjbrJK2cFmUyh1hUf9Xo0YllkY/95l2LbAYDiLhriIUb3z9U6XaNsLhtXwvUWOctC19TOOjKvqi9g/wYYkX6YGFoWLZSgt0yWIZTjLvlVMsB7Yj66KVetACxHNVjAzvGir1PLborecribMJuE8G1y/pQcOxJv9vLsVseQXl/inCfnQFk6xUHUEOT9IspskEB/AL0BA7CB/8LZFfJi4MLoVpO8R2jD3Qrj+JbuyLSsG1lImVMvcpAKD2YF9fk0c8sCK+0TVmAeCl3/QPL79Hf4IL6JOt1xrZ6L6wiOBhCJ5+MlqweokUHFw44Yrt/X1RbAr8N4u5RpK4DmtsToFcWSmGSuaH6PWRlRTyHIVXcfr3AS4K043HM28XF34ctIXUVnbZk1mmdYDcPcLlEys7JdsRTsMKQyxBlgfpw9sY38xpsNWO3sCFMw6YeyOLs4yFT6QYc44tyoaY/s4Lf/GneM8ZV9xKIL7tahkWlZNhVyZLnIzSEqeI+0cCVcA9GN60GPeRFbSGlD+c9KkWTih6PV+NcmYeUk2mFEMs5IE1pyAQgUsSOPtAbyZVFwyCnFQ4o1a+Uq6jYwdyarOWOCYkf+D+uSE/YnbwX/9iRiaxZzVbYacwKsRJ4wnhugHEw7ZD7IafsHrOtiWBzapAZcdJpl/GV2ztE7KhMnifYgFEUUJdQ37ZFVUmFzJWSLRIbn1vqA4a0JW9Zbge+YT75o8j9AOBsshdBmXpcRHlyTJ7aX+aD3tDPZcdvX8npp5zt7oQgdbSck5AqwCDNn/wKZu3i3RTAhvayNVX2o1Jq7N1leuxEWP9CvkIB5DAfjxmoQFk6CI4VRnekdMqzFtqa3IWyd8j2oN9BEFoznqNb6scvtPfojyqxBXlbzRhQVTyZS4IaHRxX+tPjfi8qdu0qZ50SR58FuM03Az9Sm4plVdDAJ8giP0kfzEb3Pd7M5zgHkUQ GTj2D3pp AzrMIrcUHCKx0jR4aP+ahZ6Kb+Fii34v32ZhDwFxqX+ciH14jz+c5n73hUSOg1Op6P188YwBmnCwp8EFiMIO3SRKBBTU1IyP+RISGfRKJem7uxv+feV+mmzos2Rtol1yxVmDBwF+RTRISU1GUFH8J3hwVqbrC7gPUcMSST4h6ptodIaGKybtMb0ic7cZ5LMSAVMEmCEIIFt98MzxUCt3DUznxw19+u6yiVXfqmrvL1juOHkv8jQB/Fb90F6TCQV2MjKN0hmi7M9nfUwdEfU4WyXCdN5Tg/x76GNeFQSrWWCDolGNXA63ZI/stUM0DcV4DFOTupdHtxBVxh16j//7ZbEfleLIDp5wl8DkRzp0tg2MZfvulBKodgHxtIxmvDfroDtClfojAKlhrOV01rj9ngx2TBiOnLGctpK6daKDUXzFOtxQBETZBCgYZeUywqRJNUsYsml2rRGe63N1sL/6tztmQEqVdK7Cw6/oYqXjqrO4LGc2VW2qmyckMvDegnyA1IkoyEOMcWBRHaCMCBFJ4mmRMBA== 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 Sun, Feb 26, 2023 at 4:20=E2=80=AFPM Andrey Konovalov wrote: > > On Fri, Feb 24, 2023 at 7:51 AM Peter Collingbourne wrot= e: > > > > 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 pointles= s > > to poison pages which have kasantag=3D0, because any pages with this ta= g > > would have been pointed to by pointers with match-all tags, so poisonin= g > > 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. > > This seems reasonable. > > > Signed-off-by: Peter Collingbourne > > Link: https://linux-review.googlesource.com/id/I57f825f2eaeaf7e8389d6cf= 4597c8a5821359838 > > --- > > I sent this independently of > > https://lore.kernel.org/all/20230224061550.177541-1-pcc@google.com/ > > because I initially thought that the patches were independent. > > But moments after sending it, I realized that this patch depends on > > that one, because without that patch, this patch will end up disabling > > page poisoning altogether! But it's too late to turn them into a series > > now; I'll do that for v2. > > > > include/linux/page-flags.h | 9 --------- > > include/trace/events/mmflags.h | 9 +-------- > > mm/page_alloc.c | 28 ++++++++-------------------- > > 3 files changed, 9 insertions(+), 37 deletions(-) > > > > 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 Budd= y > > * 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/mmfl= ags.h > > index 9db52bc4ce19..c448694fc7e9 100644 > > --- a/include/trace/events/mmflags.h > > +++ b/include/trace/events/mmflags.h > > @@ -96,12 +96,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, strin= g} > > -#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 +124,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/page_alloc.c b/mm/page_alloc.c > > index 7136c36c5d01..2509b8bde8d5 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -1380,7 +1380,7 @@ static inline bool should_skip_kasan_poison(struc= t page *page, fpi_t fpi_flags) > > return deferred_pages_enabled() || > > (!IS_ENABLED(CONFIG_KASAN_GENERIC) && > > (fpi_flags & FPI_SKIP_KASAN_POISON)) || > > - PageSkipKASanPoison(page); > > + page_kasan_tag(page) =3D=3D 0xff; > > Please also update the comment above should_skip_kasan_poison. Done in v2. > I think we can drop #3 and #4 from that comment and instead add a more > generic #3: "Page tags have not been assigned, as unpoisoning has been > skipped". I realized that the page tag will also be unassigned when the page is first being initialized, so I decided to be more explicit in the comment here about the circumstances where this will happen. I also took the opportunity to remove the FPI_SKIP_KASAN_POISON flag, since I realized that it is now also redundant with the page tag. > > } > > > > static void kernel_init_pages(struct page *page, int numpages) > > @@ -2511,22 +2511,13 @@ inline void post_alloc_hook(struct page *page, = unsigned int order, > > /* Take note that memory was initialized by the loop ab= ove. */ > > init =3D false; > > } > > - if (!should_skip_kasan_unpoison(gfp_flags)) { > > - /* Try unpoisoning (or setting tags) and initializing m= emory. */ > > - if (kasan_unpoison_pages(page, order, init)) { > > - /* Take note that memory was initialized by KAS= AN. */ > > - 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 fro= m being > > - * (un)poisoned due to sampling. Make KASAN ski= p > > - * poisoning when the allocation is freed. > > - */ > > - SetPageSkipKASanPoison(page); > > - } > > + 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; > > + /* Take note that memory tags were set by KASAN. */ > > + reset_tags =3D false; > > } > > /* > > * If memory tags have not been set by KASAN, reset the page ta= gs to > > @@ -2539,9 +2530,6 @@ inline void post_alloc_hook(struct page *page, un= signed int order, > > /* 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_PO= ISON)) > > - SetPageSkipKASanPoison(page); > > With this removed, __GFP_SKIP_KASAN_POISON is no longer used and can > be removed too. Done in v2. Since the remaining flag will skip both poisoning and unpoisoning, I decided to rename it to GFP_SKIP_KASAN. Peter