From patchwork Wed Mar 2 08:46:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12765644 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 18BF3C433F5 for ; Wed, 2 Mar 2022 08:46:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B49C38D0002; Wed, 2 Mar 2022 03:46:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B21E38D0001; Wed, 2 Mar 2022 03:46:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A11688D0002; Wed, 2 Mar 2022 03:46:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id 9446F8D0001 for ; Wed, 2 Mar 2022 03:46:56 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 45CD1978FF for ; Wed, 2 Mar 2022 08:46:56 +0000 (UTC) X-FDA: 79198816032.29.8295ACB Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf04.hostedemail.com (Postfix) with ESMTP id 31C2A40006 for ; Wed, 2 Mar 2022 08:46:55 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id z16so1321621pfh.3 for ; Wed, 02 Mar 2022 00: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=QeneTRGP9wfQ25M47Q+R8Wl68p5vbBqnFJgw6WQkaxsfswBfxD1OITyA/HIqzBVEo2 AZnzxKeNl71ZMwKvldPBo/wm56YZT2vbzLAEyG8hvJerHG+nXA3Zw60rCyyOd0IpAdop J5DaQ73SFL4Scu7mhuf9krPmf8PFtNI7oPVChKCk6vmzr9midVGbN6LbpOIaShuS9YYg bGP22tPqpAGxGlbbLkhLm4bbuSykKGe4jJAwXg0fUSGEYcyZYd6ndab19DhXAeVFaVkB jcJ8izz4tngPcWkiO8vQR5PPQLzHKWKeHu0zP523nhOOPDxxIA4DenbBNVzA1yYmCiMi gIaQ== 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=6fuU8kPe31AuVR/vKp8yEqwh4w/OUbxyhxT97s3dJBYRCIGbqWgjIlBOJ5hGJnH7R8 uT6M4Ug1lRRWmzrPQEz3+Cn51a64Qoag1w+AT9q7F432RoQOW7V09poXxQDXTxNU66Gv fh0Xg8RmDQwp3WVzSLex0EW66aK2J8cdXOZ7IYiUFEmnFJbIxNhsigyR6tMz5bjbHGvc diMNM/JxMn9yfyHFqAYQrdOBpbsPn6DXA2PpQQHFFW6eIaP74QK73WDYJtGe4TrXPQf+ 5tLTojKpcAeeP+eK1Vp2hHwXTyn/useYC4hL93s5EZB7/s+pT8DxGVapU1dyYUB41Gd4 Du8g== X-Gm-Message-State: AOAM530/TQgIwgEdM6nwxoH/BleaoNN0VF20ORkUC24FZBGIrsRmD1hr yq+uiyYfNxkNJXQBL8odUqgA+Q== X-Google-Smtp-Source: ABdhPJxKaSrM6iBBGkvbdb2L3RZylc2pqe5tLOOKYk/MoVAf2KGjquxtsY4qytU/fXNy/oElueVSrg== X-Received: by 2002:a63:4386:0:b0:378:b62e:28b3 with SMTP id q128-20020a634386000000b00378b62e28b3mr11156359pga.442.1646210813974; Wed, 02 Mar 2022 00:46:53 -0800 (PST) Received: from FVFYT0MHHV2J.bytedance.net ([61.120.150.70]) by smtp.gmail.com with ESMTPSA id s10-20020a63214a000000b003652f4ee81fsm14828816pgm.69.2022.03.02.00.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 00: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, song.bao.hua@hisilicon.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, smuchun@gmail.com, Muchun Song Subject: [PATCH v2 RESEND 1/2] arm64: avoid flushing icache multiple times on contiguous HugeTLB Date: Wed, 2 Mar 2022 16:46:23 +0800 Message-Id: <20220302084624.33340-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 31C2A40006 X-Stat-Signature: upk9nqhescxfdjd9gipq5maateec7p1j Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=QeneTRGP; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-HE-Tag: 1646210815-145958 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: 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 Reviewed-by: Catalin Marinas --- 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) +