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: 13168729 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 63231C6FD1F for ; Fri, 10 Mar 2023 04:31:08 +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:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=YKtPW15DvWCG6c13l2fWUqoW+sYUH8mW9U+qxmZewzI=; b=JIy2f8HmSPymNunOPpt3cyArrw g4MKepejSWdAAFZbLtAfnh5aOa/klA9XIUjKBXAVRiLij/5+21tauLCtg7G4BrdO3Hplzv3praR8/ nYJ4snVVOmOz5WwkUdt+q83LJMBb+/ZqHow/oGzi/G3XlKLY2erxzkd+Lia56IYsIzqIRMhYnfp7K m3DruE2vdnRnRhrj5eZAj+FELiWTCLev2OoKjj88j+6ir1KLQP+ooEy4RqHddasGEidftaAIW4WcO SFxJkaA84WM1+NEsP9G7rnnaF+LaCIYuMPLB8GwSqWilmXjtuZ6Ptu/R8g2XDzMnEutKA4LJ3Y3Fp N1efQQHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1paUOP-00CzjM-UG; Fri, 10 Mar 2023 04:30:10 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1paUOH-00Czge-7X for linux-arm-kernel@lists.infradead.org; Fri, 10 Mar 2023 04:30:02 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id k6-20020a25e806000000b00a623fca0d0aso4632968ybd.16 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=YwVpskBSFoYsyA6I8ZN0f2f8W+6AvV7yXl1IFzlquPeg+2d/kS09vhHQ997b+7hwIt /KdKA2ossonob/ZV3oXHwgi/OqiMP0hOzxPdZwdcTZytscRn/ygtrZTZZ0sH/lMLLKg7 TJPusDKz2wrgI8AjipO5+az5HeN4WjdDVGA6Yh9A7vYerct0I3qpEjr9eXBGj22oQV0d VChZLx3XflQd9VbqdVguOHAnyVCy81mCev254nzV7tdGi4fUdtVWHi9M/zgKdqwM12q6 l6Rf84mBb2gyWuXXP8AeonvY1XANqx2EVIL9iSdhiKdHvM8zE7Q8Peco5PdCLDS986f1 6CTA== X-Gm-Message-State: AO0yUKVFFGWeoBbVkmq1VDL/tCyISFycmtBPTxZDFqHapCn8EB+uXWBI oW7Xi499AJ+rMJn04Glx+h2PdI0= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230309_203001_289669_ABEC35A3 X-CRM114-Status: GOOD ( 15.21 ) 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 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. */