From patchwork Thu Feb 16 06:47:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13142669 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 1356EC61DA4 for ; Thu, 16 Feb 2023 06:48:46 +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=2ZQ6omEpPqiSlHwMKLP6Ahgs6C2E6htZL6r8tgDJLBM=; b=sIN jFDiNRGzIJ8jiNVScj+Zb/LF0Q6DPG0DbVVMCXP587YVm7BCch5vf9e9Hos8MBQSNctUVa9pPfswB GRl9imkpS5F28+WO+xScTevlLdt/DSz2DAPrx4Swk2Dzdq7CW5P8Ertw4MOMqE8ivLmEm4lQM6ks8 LnAGqDjzj0ivfLT0AA33I8FQ34WINpmRKCITvHEDreS6MpSHl88hfGlC+KUGEp6ca9ZSh8PKTxwqR 64NuxxmdKJR4WFRg+kv3B+cn7IzhCDcxCsgb7b48h9UPyjTpobjQd3nl8PbNicf5m4kZJp1kXfWVN qEcjeI6FY1sfgu34rH7S+Qph7qYEp7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSY3V-008jP4-8u; Thu, 16 Feb 2023 06:47:45 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSY3R-008jNJ-Ib for linux-arm-kernel@lists.infradead.org; Thu, 16 Feb 2023 06:47:43 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-52ec2c6b694so10248797b3.19 for ; Wed, 15 Feb 2023 22:47: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=U1KTvO9eh7af24NgSabBS4dGCCNbjIjt0zmjrEHKiTs=; b=OHpT13/ShK01bHTTiGQpOkxVzV8pA3jZiyFv/AU7X6UIDvLl5ByZWPtKuDj3X+EE+S RzFRVyIIjuvXN6u1ZFToZAhJW7XXC2WXjq2RwiiMJXPsBZs8orU7PqhCoR1oUDNRykJ+ nOKa8JSENsgplBgLDfCa2eMMx5J+hvXBV+mhZC3EDxr7H/sT6+8xYWkCDrx5oNsMsn2g i0BfVkorO2EeIY2ab/d0ZuS3jXQMXsEoux6miWDJeducQUhtFKts/moIZlqF4EBrWcDT DWXosukzjzzgFqODPgTWiLOmJ/Joc9nHPD4osSLqhWsGv8A/ui34v1LAteypKVjRfRvA niOw== 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=U1KTvO9eh7af24NgSabBS4dGCCNbjIjt0zmjrEHKiTs=; b=y+BC8YFIYEI1Omn891T4XzVSq0hjOBB3HsRjP0Z39JyhbUyj+sbYTCvU4IxGQ+o/Xy JvpIrtA1wEobfoKn2raYyRRxKFXXCARVBzOC6POJPqWerenizbgCJMIvVDgtgLv9Ufo8 XnCgioWR6VgkNpXqFEvBS/ShizPmTulP9Un/2PNpzJdvmizeDlz8dW4PHWQMQEs/Sti6 jzeCdasSBEXekfB08wamg8/od1GzXYwDyb9Gn/s4P7mRR3fgNmuHsacvgXS2ZGf5LqX1 RjAb0zm6arbVs2KrJhvUU/cfMp0HqK2xEL0LWszpu1zYRpVueoKt/j1jVtTnDKcVOcvq sTiA== X-Gm-Message-State: AO0yUKVWfCN1dxIY3KO6xOpuJB22aK0FDKKHlaH/5LAA6k1ZmS20ntBA gaOcUG9hlLBa80nubLH7g3LVdaY= X-Google-Smtp-Source: AK7set8IHohEy2xJNi2KgXsl8cXGjRbX0js9EYeWNv5hFjkZjqSfCNnZOGUUuUVDJoFYdw0moydtUWU= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:9dcb:3224:f941:1aad]) (user=pcc job=sendgmr) by 2002:a05:6902:13c6:b0:8da:3163:224 with SMTP id y6-20020a05690213c600b008da31630224mr9ybu.0.1676530057864; Wed, 15 Feb 2023 22:47:37 -0800 (PST) Date: Wed, 15 Feb 2023 22:47:26 -0800 Message-Id: <20230216064726.2724268-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Subject: [PATCH] kasan: call clear_page with a match-all tag instead of changing page tag 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-20230215_224741_647246_D9F5E4A9 X-CRM114-Status: GOOD ( 12.28 ) 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 Instead of changing the page's tag solely in order to obtain a pointer with a match-all tag and then changing it back again, just convert the pointer that we get from kmap_atomic() into one with a match-all tag before passing it to clear_page(). On a certain microarchitecture, this has been observed to cause a measurable improvement in microbenchmark performance, presumably as a result of being able to avoid the atomic operations on the page tag. Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I0249822cc29097ca7a04ad48e8eb14871f80e711 --- include/linux/highmem.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 44242268f53b..bbfa546dd602 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -245,12 +245,10 @@ static inline void clear_highpage(struct page *page) static inline void clear_highpage_kasan_tagged(struct page *page) { - u8 tag; + void *kaddr = kmap_atomic(page); - tag = page_kasan_tag(page); - page_kasan_tag_reset(page); - clear_highpage(page); - page_kasan_tag_set(page, tag); + clear_page(kasan_reset_tag(kaddr)); + kunmap_atomic(kaddr); } #ifndef __HAVE_ARCH_TAG_CLEAR_HIGHPAGE