From patchwork Tue Feb 8 05:46:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12738203 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 4E539C433F5 for ; Tue, 8 Feb 2022 05:48:14 +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:MIME-Version:Message-Id:Date:Subject:Cc :To:From: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=AcmVB3Y5ppsBwnKJyWc8j0uYqKkkpFHjTX3KfWahANE=; b=J/uIYOve1Qlsd+ knBdUSOf9ciNDOsAxjU6ik9OMZKOwyDSJPqc2D7Z9lmWcE1Hz9WNiS7XsZJ4RsvVx/d4w0l71JP5F Jwf167Ehna9RhiAGI5zh2ln5ad477e72+Z7Wn16EJ26sR3//TaKvEpwIbMnjHEmv1PvH2O6orC6uM vnaA2SK/ImdG51UiYzufuI6E8+IVVQKm6jGV25uPxSlkDFDlwLmWBXanVhqriZ+iZ9S7R/oQZvrgP FDsg2wwRDuY+wFvk/IB6ynFQEs9hAT7qP0OnIe76XYBe5W8/fqpAqOrzutXi7X4jbzarM2pIXj31y s2RqbN/1sPenquVY6J2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHJLA-00CXmo-1N; Tue, 08 Feb 2022 05:47:00 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHJL6-00CXlr-2Q for linux-arm-kernel@lists.infradead.org; Tue, 08 Feb 2022 05:46:57 +0000 Received: by mail-pf1-x430.google.com with SMTP id e6so17016536pfc.7 for ; Mon, 07 Feb 2022 21:46:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZWLmgm9buCbXqY23s5VhjmfJZhCL4RghEpABSyXi0/w=; b=0HYhkWbJnwjpTlx6yPo8iGOzEbRV18XhnOFuEUyVggVDiXTNWhIYIA/aPOw0uT/L09 yYlF5uQgKM92dhsGYUFEULlf710NYp+6d5gV72NVyUEGVTIeAnH/far1EjAK173nhvMA GjeUDLqL5ol5Xc/S8j13re2FPQ9DbSQqW4hnoMvWW0ONXTDzniTB/sZvR27PUX0rMR31 2IaLUB3SKzesIpY3I5KoXVmMF8mTMmaVUWVDnPWX1VyYk6Y9IovfyCE5NfGDDwrp7+vU YDwbvjgGwRCxwOisVBbjwLb+EY70DD8YjVX2AO/x2nJabwLLDDkrf3fSuV6Gb6SzM5iE q6uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZWLmgm9buCbXqY23s5VhjmfJZhCL4RghEpABSyXi0/w=; b=LgbAo289RW8MQ2IXyOzRAQ/yy9GGLNKlhn9exAUt+xXDyxMeTVOREK6Qpi64Ln/y/i R9fGNJf0IsblChMJtRLrsBoUpzPESTvcW1BKG4ik26g1cSIfTdnYS/n/aiWPqdDh83DR bM2uRxv0rOuQpN2gRZIGQELbNJwngUw+vt/+vlU30nV5AlvtC26B+UcV9BFEaJTco8gO LNZJgktHNEjDOH9Fz2aXDrMaJFD8Gu/3Zx3EyoltE/zP2RT0gHj0LhmkdJUk7DdPDV3c EnX+gbR15rYPCgePYseiH4vsbJD0rVENihynvqzlUMWouupqPQGgCRXzUM5eDLOO61Jn lw4Q== X-Gm-Message-State: AOAM532G8TTgypjnQephY10fEKZgz1BtcqLSWwCt/k9l/dq7cRZtUHkf 20zIMNF8fj9U2vdYNq9LWnT6zg== X-Google-Smtp-Source: ABdhPJwaR77nsHjzpwtt7ubQtGVX/NP0wNsgi1dJyCP5hRbqwsfRyYHkv7pveQ5ABAYLcpJ/rdv9DQ== X-Received: by 2002:a63:df46:: with SMTP id h6mr2348666pgj.26.1644299214205; Mon, 07 Feb 2022 21:46:54 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id 20sm1160680pjf.15.2022.02.07.21.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 21:46:53 -0800 (PST) From: Muchun Song To: will@kernel.org, akpm@linux-foundation.org, david@redhat.com, bodeddub@amazon.com, osalvador@suse.de, mike.kravetz@oracle.com, rientjes@google.com, mark.rutland@arm.com, catalin.marinas@arm.com, james.morse@arm.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v2 1/2] arm64: avoid flushing icache multiple times on contiguous HugeTLB Date: Tue, 8 Feb 2022 13:46:31 +0800 Message-Id: <20220208054632.66534-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220207_214656_194689_F613372B X-CRM114-Status: GOOD ( 12.72 ) 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 When a contiguous HugeTLB page is mapped, set_pte_at() will be called CONT_PTES/CONT_PMDS times. Therefore, __sync_icache_dcache() will flush cache multiple times if the page is executable (to ensure the I-D cache coherency). However, the first flushing cache already covers subsequent cache flush operations. So only flusing cache for the head page if it is a HugeTLB page to avoid redundant cache flushing. In the next patch, it is also depends on this change since the tail vmemmap pages of HugeTLB is mapped with read-only meanning only head page struct can be modified. Signed-off-by: Muchun Song --- arch/arm64/mm/flush.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/mm/flush.c b/arch/arm64/mm/flush.c index 2aaf950b906c..a06c6ac770d4 100644 --- a/arch/arm64/mm/flush.c +++ b/arch/arm64/mm/flush.c @@ -52,6 +52,13 @@ void __sync_icache_dcache(pte_t pte) { struct page *page = pte_page(pte); + /* + * HugeTLB pages are always fully mapped, so only setting head page's + * PG_dcache_clean flag is enough. + */ + if (PageHuge(page)) + page = compound_head(page); + if (!test_bit(PG_dcache_clean, &page->flags)) { sync_icache_aliases((unsigned long)page_address(page), (unsigned long)page_address(page) +