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: 13150980 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6733AC677F1 for ; Fri, 24 Feb 2023 06:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=NYNxJM9DFGf2AukG3l850LNAu9tZI7w1DzL5PZUxAuE=; b=eiF DaB1ST6bj5R0Qez6Jp8Zd1P5UfAu0/HXaPDFGN459caKFCzkcwgKnzlIjvNr+OfTAKyPxIieL4Zxz 7aJoRkVa2DlXnDHGhqiBz6ApmW81sP/xoO+nCX9I7sL1FrYQmQnROoGdk1RGw1e4wwNI12IAIQXKk 1zCn1+IifzImPnI5sW4x+Ihitc/vr4p+MhWepen6bfrwR2esiRsbst6UxE5vDDWoPipoV2OaRaX6j LpXFA9avnSQrSg5LVneilvuU7t6DQyCLXQQsBFkvb1+HOxZiq1zI/UXvBcedpbUfwwcP2aniI/0V5 8sYdEo8P8oR752ODasyPVIBetyiY+qw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pVRvl-001MZY-5V; Fri, 24 Feb 2023 06:51:45 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pVRvi-001MYb-51 for linux-arm-kernel@lists.infradead.org; Fri, 24 Feb 2023 06:51:43 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-538116920c3so120310447b3.15 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=6u6hbR0K/e5jqkP3tqDsEbeUgBuksGyoZ0/1bwl39eQy2sAAva9VA6y8HI2UsvQUuk 81ORr3N/4tbEqvmPxyzp+FTV2RYlGWb20NnSHkQqi7I9QEmigOfnV4XO+cfdI+o9Nc9I ON+azrPN1w6z1H4XNYAQ0Vao4fzRzkoYS5M6D3QJu+IjW+jKFrTMvlfGgrvTDZT3nx1p OMclnlDRQAZj5++10uE82UBGYXHDUjZjz4lKqO5ij1uLgHW+ceUve5U5AT5ftuQffSvC m7GYorLxVoI0a8DMwvnASWLDNY2px9iPB5FytgSJmavLGGVVbhISEhgQaQccnWBEKt27 eHeg== X-Gm-Message-State: AO0yUKX0vc5p18F8Pyis0aBayyqR5dt9vc4jMTSDUzqgQjZ9FWz0SpYB oJsm+uMBQE3Vms7jMU46uTADSyo= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230223_225142_218905_13B4A5DF X-CRM114-Status: GOOD ( 18.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);