From patchwork Fri Feb 24 06:51:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13150978 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 BD8C8C677F1 for ; Fri, 24 Feb 2023 06:51:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E67446B0072; Fri, 24 Feb 2023 01:51:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E173A6B0073; Fri, 24 Feb 2023 01:51:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDE766B0074; Fri, 24 Feb 2023 01:51:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BF9846B0072 for ; Fri, 24 Feb 2023 01:51:41 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8A824161599 for ; Fri, 24 Feb 2023 06:51:41 +0000 (UTC) X-FDA: 80501264802.25.385EA2A Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf07.hostedemail.com (Postfix) with ESMTP id E60734000C for ; Fri, 24 Feb 2023 06:51:39 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=R0D2B1ci; spf=pass (imf07.hostedemail.com: domain of 3el74YwMKCD8qddhpphmf.dpnmjovy-nnlwbdl.psh@flex--pcc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3el74YwMKCD8qddhpphmf.dpnmjovy-nnlwbdl.psh@flex--pcc.bounces.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=1677221499; 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:in-reply-to: references:dkim-signature; bh=/4/Nn6TgzmPpFqf86zsQoyjbMesN0EC9v3sEz2T6CKI=; b=ijF2ri4woxc2I0d2/nuQKIXUu+eBATscbKNebo7JlnP06hZH0OCNI6gWI0yw/2CU4Qqw1t vViwzz8j+N1HWocJpgPtif2alqYo3hIz5FsiGLUVeWazrd0kn2WLx/C17jObnZlmxtrHb9 ERRHEElZWEQ5mJ6PfFBqryDi4ADNkfE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=R0D2B1ci; spf=pass (imf07.hostedemail.com: domain of 3el74YwMKCD8qddhpphmf.dpnmjovy-nnlwbdl.psh@flex--pcc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3el74YwMKCD8qddhpphmf.dpnmjovy-nnlwbdl.psh@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677221499; a=rsa-sha256; cv=none; b=5ms5Ayic+NGk8KQ4+a2vhVnSrJUWEbcLQhE7i6/l8LsPOwP+2uljoRZGo/Ma/JuwaepbT2 x1NHhNI4jVIGPRBVv9vtpFZXHxADSfK+H5ep0PmRZgnD2zCnIegwPLRaGJYLDj1ArZJvse 78MuPwYZyc//CtleLJQzaDYxvgMqtYQ= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-536c8bcae3bso163676907b3.2 for ; Thu, 23 Feb 2023 22:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=/4/Nn6TgzmPpFqf86zsQoyjbMesN0EC9v3sEz2T6CKI=; b=R0D2B1ci8CyEN930PpdHSdJcaK0nCqnnziNL0VLzI7Ls9Nke2xop9g29CS62bM4LCq H4REtFcQDJ5uir4Gp+TZw2/JQrPFWfCTa0Y1azE9Y2uaG2JQIoNnMZNfgZtiyBEHv3s4 fHxFA1gf2z77p6w3Cg8EuxPJ1fD3fHhIL2YYZZgVIymMULm4ZvRAs9QLXfvpWEAd2X0Q nJSYRtLggr5GpFuTkOPYCW6Fi5msZe9GMzzr45EIJOx7r0Dt/IJ1tBbirPgrhtRlMyKU ojCoXkKu2Cch5olEStl2BA/LxQdaJxFpe2qhjybo/kcZNpBWrLN14WnKd4WRrM8+wYz+ 6lfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/4/Nn6TgzmPpFqf86zsQoyjbMesN0EC9v3sEz2T6CKI=; b=xVIBpFuJM285C2Z1k68XcAHhYnteYfzZSR976UFHYD4CBAXTb6C4v4yjog2cb14dJS tTssPNz+pGcThYFggZeJxB64Lxk0yQ/GYDqndOWIvID1yu46ZA5CaCPDWv2m14TOB+ur VPqpDt3yv4xg7lJqLm1pR9qwrpYB3AywjuQhpFcV6mse7cINrBHKHyIrHgVoNwQ/MuUx tx35oBvUCP0qdcvm1Vh1VR9fWbrnPwusIGoHr1/EtgZ/XkB3VY1T2r34NQ7BxIgWBnZy sRYFj6d81IRrQj/3MejwLy3QPLQuO1TwrLzsCXkFMjjc8cTE3UUwxP+Lf5QJTH/ln/9T GcaA== X-Gm-Message-State: AO0yUKU+QJ2rSOTQ98n7lCSTM19gU+gyZhqlVzs/mjfbilXWNEfQA4wS WANre6G2ZXtRXi+OWc3S4GJz0Qw= X-Google-Smtp-Source: AK7set9idJpRb8Wy4fLmxo55dzUaLLjpYXeB0N4b+xk/yB2gmZsENBDNRvyPgjmTxLzYPct9OFMiRyw= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:d302:b63f:24c7:8a65]) (user=pcc job=sendgmr) by 2002:a81:7146:0:b0:52e:c8c9:221a with SMTP id m67-20020a817146000000b0052ec8c9221amr1364413ywc.519.1677221498805; Thu, 23 Feb 2023 22:51:38 -0800 (PST) Date: Thu, 23 Feb 2023 22:51:28 -0800 Message-Id: <20230224065128.505605-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Subject: [PATCH] kasan: remove PG_skip_kasan_poison flag From: Peter Collingbourne To: catalin.marinas@arm.com, andreyknvl@gmail.com Cc: Peter Collingbourne , 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 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 1esoh75ewmpnp5fahwbpkndx3kzybtpm X-Rspamd-Queue-Id: E60734000C X-HE-Tag: 1677221499-315518 X-HE-Meta: U2FsdGVkX19z+dGLw69Y5gfosFhHBPvoVaAGGP3FULYaWC6W9Icg6QK/llz5R9GderC68bvSD8hnKvEmuXgGonoOdU6c6e4byPkSBf2u22Rtmyct/8SqiAvs99MmFnwZB00IGtbmrrvvaBKXYdpHSz/S/RQW8XJnPkKL0lbCOto2IoNX826/E0fgeoGb9i1qwdnRBcsRrM3hUhx0aWLwxDM/NuMwngsgblp/oHV2+yYNEqkyMn6G3PhZo5dxbxNBxbvuyGj8p0RIRQ8lIo49uvUEiXSuYo/21VgXUD7vZ8epiWIyd3vXK/CCuPSnOvjyw6nUdpL3Eu9zVFdKxpT0F+ovZ4todAgLbuhTE0gEuO6z5/3wkPoXkBBKBr7lPHJx6ZXJG+LD25jn65Ua/E4vQrrT5cPiAauXpx6O3U5NqlyC7dCBU2CQTWKZpDPP38HwfZgEBJ8/+1TExEmmP59SSVU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WyA6tCgM59MNEL1+bPNvzIpfCl204GuE205TgefswQhNLIg6LJGMtlDUAluSlnbTTjs90lbffjId2dRT4iE4FCScLln6GuiUYZ0erFwq7eL55RSlY5R7om1WyJsbNJ2U2mvtf9pNkROgBsSp4DGpGDqzAqgbXS4JoJH62klI0/J5pYmZixk3AHdmcIx/fGHowykj8q7N/8jwrL/Eh5U4wIwpKFRtIFubLFjmEOSBRtqrrsoWFS28JRXfX3c4yKl6Q4LIl7vEbJHCzo2DYzh+Fd/BzO8BbSAVHfiWPjCJRN1DHA== 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: 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=0, 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. Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I57f825f2eaeaf7e8389d6cf4597c8a5821359838 --- 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 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/mmflags.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, 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 +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(struct 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) == 0xff; } 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 above. */ init = false; } - if (!should_skip_kasan_unpoison(gfp_flags)) { - /* Try unpoisoning (or setting tags) and initializing memory. */ - if (kasan_unpoison_pages(page, order, init)) { - /* Take note that memory was initialized by KASAN. */ - if (kasan_has_integrated_init()) - init = false; - /* Take note that memory tags were set by KASAN. */ - reset_tags = 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 (!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 = false; + /* Take note that memory tags were set by KASAN. */ + reset_tags = false; } /* * If memory tags have not been set by KASAN, reset the page tags to @@ -2539,9 +2530,6 @@ inline void post_alloc_hook(struct page *page, unsigned 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_POISON)) - SetPageSkipKASanPoison(page); set_page_owner(page, order, gfp_flags); page_table_check_alloc(page, order);