From patchwork Fri Mar 10 04:29:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13168727 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 D62BAC6FA99 for ; Fri, 10 Mar 2023 04:30:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C1856B0074; Thu, 9 Mar 2023 23:30:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 56C166B0075; Thu, 9 Mar 2023 23:30:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4344B6B0078; Thu, 9 Mar 2023 23:30:03 -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 3389B6B0074 for ; Thu, 9 Mar 2023 23:30:03 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id ED9C41A1492 for ; Fri, 10 Mar 2023 04:30:02 +0000 (UTC) X-FDA: 80551711044.07.F8BDE77 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf05.hostedemail.com (Postfix) with ESMTP id 2B19E10000A for ; Fri, 10 Mar 2023 04:29:59 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=IUwzYC9Q; spf=pass (imf05.hostedemail.com: domain of 3R7IKZAMKCPwtggksskpi.gsqpmry1-qqozego.svk@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3R7IKZAMKCPwtggksskpi.gsqpmry1-qqozego.svk@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=1678422600; 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:in-reply-to:references:references:dkim-signature; bh=QkRgpCrNH+soo+fiEkY3prqCJENxuAn2pQWgX5GFHYo=; b=e4ANEAARNCWfJyftwxu18jpxze20JVCYO312rpZW4Ej2q1uTvrPZzJ8/H0eHoYDL+WozZW VErujdiamLAYCstQ5oI5wNk0mGyZoMJXndJe7GsyU0hBrioSEDEdBKM46gO0dzrmCZiNLd 0JEbZJo1cm0vVhAxLSchFdRFUCKyULs= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=IUwzYC9Q; spf=pass (imf05.hostedemail.com: domain of 3R7IKZAMKCPwtggksskpi.gsqpmry1-qqozego.svk@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3R7IKZAMKCPwtggksskpi.gsqpmry1-qqozego.svk@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678422600; a=rsa-sha256; cv=none; b=N03pyavrQUhcLfGGkUH4gV0tV2J2BeFm45sOd8v1zkxtZfuyGT3veewE93FgzaG9f+3gxN xA7KU6LleSrd4Qz92i3RVbHGVf2xhhceIPPsrEdn6oWZV1qcdsxvXADu7YXg/fE9pYiWzw k9suaOQcDuPkJavITIXBYj0+Fc4EHWA= Received: by mail-yb1-f202.google.com with SMTP id 204-20020a2514d5000000b00a3637aea9e1so4660243ybu.17 for ; Thu, 09 Mar 2023 20:29:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678422599; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QkRgpCrNH+soo+fiEkY3prqCJENxuAn2pQWgX5GFHYo=; b=IUwzYC9QwdzKEGQekhpa3YY0njrREkSmoVgmtl99u7nOXC6fV8I6Qj8xuVm2JdNjLn ubRsEea2cY/79WDUcqLNBHNxYbZC0yowAuL8uRs9dKMJlfl6FryHgcWIuU1DGLMuyXBt PEjg/9aOEgNcJYJvM7lq/BUNAYKdWmpfQbreuO0+RIIH2FkduGalkt7xW4w8KqiPD21w 548hOgBBPCkxL0InIdqn8serccLJf2BAmAuuJF5wGZH6yih+2Uf1yosBEuzcLLl+tdHt jMdq1pIgADFODU1v+bGWjfsUjbguZJAQaVh0EbM8oOlgQP5bG02Ujj2O//AQw742BkZw avyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678422599; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QkRgpCrNH+soo+fiEkY3prqCJENxuAn2pQWgX5GFHYo=; b=14Nd/v/1Uk01P2pwYjZwk07cVsf7oeGm8nRDY0EAH9sV0L/p/TENoqTfoGQA6PVv/9 cuB8sVHU3VUm72Wgf9zPr5Gn6RHDYM8p1lbQbTeTAMY6lXtMIsE6f91buHK8z6o7ukG6 xkI4wHtplxB5T9vx1jzoGAo3C8Js7H0Ngv2hOidexqBV7ZP1VilC5u/pJOIFDoJvgirN q9G8edtW0cfuFSuvLBWMlv7LLPUVRUhljw0xb+G85MNC+hgeqd7/5CvKxK5eSuzNq/PK 4TjTr1xE6bt/GRsmFtD4Aieq7YDMJ3s+3tWYUQxTDZ8MQt9U214zkVmZH9AHSjOPOBIm AE2Q== X-Gm-Message-State: AO0yUKV6RXphRK9Slg35Ar2Xec+fWgf9y6CkgaMntQipmpyeADZ/+HSg P+tmPeSM5BEInK82QX5FlVeBPGE= X-Google-Smtp-Source: AK7set/EOxMMKghq1Vn5wpYfyDCvnNJSf9PCauOlQqG2n14zxfpAuyizvUnSCrDxjZGqveuY2rprJzc= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:4760:7b08:a3d0:bc10]) (user=pcc job=sendgmr) by 2002:a81:b289:0:b0:53c:7095:595a with SMTP id q131-20020a81b289000000b0053c7095595amr15950888ywh.7.1678422599352; Thu, 09 Mar 2023 20:29:59 -0800 (PST) Date: Thu, 9 Mar 2023 20:29:13 -0800 In-Reply-To: <20230310042914.3805818-1-pcc@google.com> Message-Id: <20230310042914.3805818-2-pcc@google.com> Mime-Version: 1.0 References: <20230310042914.3805818-1-pcc@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Subject: [PATCH v4 1/2] Revert "kasan: drop skip_kasan_poison variable in free_pages_prepare" 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, stable@vger.kernel.org X-Rspamd-Queue-Id: 2B19E10000A X-Stat-Signature: goqbohnfh79yuyamhxoehmrse49pjz5u X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678422599-766214 X-HE-Meta: U2FsdGVkX1/1c/bMxnIbTHX+HEq7PggA9i0fJ8dxxIks8vhvQ4qpnQg06gpBn6ITdeEIFb0RjmT/ueUfvNDWmhbwWuP1PLh15sOmeA+gMPr96NsUUZYNsV+KmdtDHDvdzkAdWCigulfPf8o89q9lAIYRhSy9pOC0PIBi3iNm23jhtCdmaGNAMmkXx+nKyixDwXS+/lzJTLElMUC8wu8Iapi6/V993qF3ygasa8YbU/9/BOw62/gwXkdxJPMTYmbVP2nhYTbcmahtueCoaQG0FwqeWCelRq/PPEXapCjpyU5z0mD78JAGK05d7QJbzPhSE+o4DVyb9xGOnSQG38dkK3AMNVOTi2bHI8WvyAjI3hPRamQ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MpRLDrY8Xfqna3stm2RkJD6IvbfyVEyxlZ3DeEju1pTbEqla46FhUcJwlyU7kPpCeKkMACvyloVhzLmO4sAxExMzwlYdPJM3MK7JBE/yEFikh//0sB3dg/5oh4tprUArE4Rj0npgJaV7qxyHuwRAblb61jQzYGMm7P2LILSApnjsUdQXnzRT13NxBy4Jzrv3spIxt5E0FG4wd2hNSYSuhjJ+2EUZIpEOgbHondwc/taeFR54Was5gJ/cc3C/M/RtntsURqxxbjLSnw9AYnayqzBP3rNFhcE0jfw+48/dFu7UnSZgBPnGSTJu4N6Q59B7pv2C2IB3dqCDdE1lgQIE8QSLlMpkc2gtPBVf5cMUyZUjhUCaSfecVYYmNxORMQJ7et5muJViBiHMyAQOsSFpaJG/Tj1i5Cp8P6PmEsZ0a8R3QfCQ8= 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: This reverts commit 487a32ec24be819e747af8c2ab0d5c515508086a. The should_skip_kasan_poison() function reads the PG_skip_kasan_poison flag from page->flags. However, this line of code in free_pages_prepare(): page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; clears most of page->flags, including PG_skip_kasan_poison, before calling should_skip_kasan_poison(), which meant that it would never return true as a result of the page flag being set. Therefore, fix the code to call should_skip_kasan_poison() before clearing the flags, as we were doing before the reverted patch. This fixes a measurable performance regression introduced in the reverted commit, where munmap() takes longer than intended if HW tags KASAN is supported and enabled at runtime. Without this patch, we see a single-digit percentage performance regression in a particular mmap()-heavy benchmark when enabling HW tags KASAN, and with the patch, there is no statistically significant performance impact when enabling HW tags KASAN. Signed-off-by: Peter Collingbourne Fixes: 487a32ec24be ("kasan: drop skip_kasan_poison variable in free_pages_prepare") Cc: # 6.1 Link: https://linux-review.googlesource.com/id/Ic4f13affeebd20548758438bb9ed9ca40e312b79 Reviewed-by: Andrey Konovalov --- mm/page_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 1c54790c2d17..c58ebf21ce63 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1413,6 +1413,7 @@ static __always_inline bool free_pages_prepare(struct page *page, unsigned int order, fpi_t fpi_flags) { int bad = 0; + bool skip_kasan_poison = should_skip_kasan_poison(page, fpi_flags); bool init = want_init_on_free(); VM_BUG_ON_PAGE(PageTail(page), page); @@ -1489,7 +1490,7 @@ static __always_inline bool free_pages_prepare(struct page *page, * With hardware tag-based KASAN, memory tags must be set before the * page becomes unavailable via debug_pagealloc or arch_free_page. */ - if (!should_skip_kasan_poison(page, fpi_flags)) { + if (!skip_kasan_poison) { kasan_poison_pages(page, order, init); /* Memory is already initialized if KASAN did it internally. */