From patchwork Thu Dec 14 07:39:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nanyong Sun X-Patchwork-Id: 13492437 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 83838C4332F for ; Thu, 14 Dec 2023 06:41:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B419E8D0098; Thu, 14 Dec 2023 01:41:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AEFA18D009C; Thu, 14 Dec 2023 01:41:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DDF98D0098; Thu, 14 Dec 2023 01:41:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 887DC8D009C for ; Thu, 14 Dec 2023 01:41:55 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 616D1C0183 for ; Thu, 14 Dec 2023 06:41:55 +0000 (UTC) X-FDA: 81564478590.03.213E73F Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf11.hostedemail.com (Postfix) with ESMTP id D816F4000B for ; Thu, 14 Dec 2023 06:41:52 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of sunnanyong@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=sunnanyong@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702536113; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OgJlxUQDILr7vk9eqhUikkWa51wWaYZkIB9AjYwmae4=; b=lWceXRmGTz7UZtXAyo3v7QqiT7ZtxJO39VSqwQG16Z64R63ZrVELYLfvmZkNs0k8F/Z6Ei XjYob2ZPtD2Co7MhpuP0EjsPiatA817rZniC5KhblBoWnhgmh1y0QNIeRlPmrMA+9x0vFX Ppr2UR6BRdQDprJcd7Ntf5v2pXLHFH8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of sunnanyong@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=sunnanyong@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702536113; a=rsa-sha256; cv=none; b=WwQmfuXzf6klRtnH2gThwb7c1YrDx+i295wbcbdEdZOtxfpfeYCQ5JVwkeVQOrWS816qr+ gDDvlZ8cWOmGx1MqIEkqjXvHtcN0gyd3IQ8aRImtL/j/P+TpY5Fn6voxylE59qCssU1fPY 1kJLgKxBnO/MyoywfQqp4x2RNgp0oBI= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4SrN5g0gYQz29fy0; Thu, 14 Dec 2023 14:40:39 +0800 (CST) Received: from kwepemm000003.china.huawei.com (unknown [7.193.23.66]) by mail.maildlp.com (Postfix) with ESMTPS id 5007C1A0190; Thu, 14 Dec 2023 14:41:47 +0800 (CST) Received: from huawei.com (10.175.113.32) by kwepemm000003.china.huawei.com (7.193.23.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 14 Dec 2023 14:41:46 +0800 From: Nanyong Sun To: , , , , , CC: , , , , , Subject: [PATCH 1/3] mm: HVO: introduce helper function to update and flush pgtable Date: Thu, 14 Dec 2023 15:39:10 +0800 Message-ID: <20231214073912.1938330-2-sunnanyong@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231214073912.1938330-1-sunnanyong@huawei.com> References: <20231214073912.1938330-1-sunnanyong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm000003.china.huawei.com (7.193.23.66) X-Rspamd-Queue-Id: D816F4000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 1rpgxtawgybt7uxs5aq1y6atpdr5dy1a X-HE-Tag: 1702536112-120567 X-HE-Meta: U2FsdGVkX19EjqGkxwgXn24fWDWgJXKFUZ/YptMP6tiJC5GJGZ8uRx+21acSgQnML9zkP+l0IqzQd/FgCC/q6HY8rCI2oIOo6Yst4HBXGurO3jUyX7dn1HOF1ScmyeMQ/cbUrpUxAouSMoy52TALnWmpHhECNl3d9DrhvSV5yW0tXKNdzucN1lgwrpS4khMLnQPYeKb1ohcjYs7tlLvbWQDtnfy2H7VF4MACt9UyBX/ZYUJEeOXaAeful2UPLsBNZyEsJTplIFRJDNlRy5QI4ly5BZ8lvO2W9yuQ7TpO8aFOorT6ksahsiftPlh41kNa/EboX2inHHLuFAfZVN5ORdqrbn6osewdKPqmHnv+45dLf8TaRRd8dPP58fhb1oBp8QJX0xuwSeFqQflp7dH9/veRZvEpMdArEVUPqkkgqYNxKGnepoJlVNupxyX7Px1M20kDyw4wzoz4+sN5h4TzVHkIQq0GsaArPN+6uFvDHyOTypk1pho2I6BZts77CPEQ93Gglr8LnGW8SoA8U54K/Im8wSk09S72DWt+4Q1dp1syXwTMJ35eCpWaK4ZHA35tjbU5YGpI1f9emU963RMSfiC2w3EWeYoN4Re1hsAVceyKJ7bJsoTAfHixBiNC3mmxr93tP6DQ2MPzE1az/L7p204Q1mKj+XVIHzFKk3q/yEnKS0ouoqdyFZQdkxjkQQZZAVQt9lDGIs461iuOvUoTp+BD1XLU66puilfReVg2Kma/dR2H1BRSTR9KwNKt/dbwBhcP2oQozbme8n6S0gBkVVHuFvSTjgRt7IWNuzpoZ8JKsFtBGAz0eCXN3/kcw6y2SEVkRsYmMDcvJR6ohIaMoVQXt831pgwL3qj6nfi5h2BDmQr7dvZdxJeId8cf2ebr8L6fRg9GdW15BJrir353vhkVw6FD5mSPIyw5Dove0dEQVXdAMdlVf9ZwLPJL7GusR1UcHCe+gk7TDBJou7K Md1F0OVq tXIXSrV9vyuWS3po3Q+YSLdGxU4Qrn9jUosCSfSm4GR0pHctGp0yBnNkg57Dsrtfq3wCxVGW9Pho92Lu/EOmePYaof9MccVKoNi8rS5BcMcXE0XZFKkXZJtRbA5Ad/itLoLyoVEbIfSltbPSrJozDGgB35g== 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: List-Subscribe: List-Unsubscribe: Add pmd/pte update and tlb flush helper function to update page table. This refactoring patch is designed to facilitate each architecture to implement its own special logic in preparation for the arm64 architecture to follow the necessary break-before-make sequence when updating page tables. Signed-off-by: Nanyong Sun Reviewed-by: Muchun Song --- mm/hugetlb_vmemmap.c | 55 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 87818ee7f01d..49e8b351def3 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -45,6 +45,37 @@ struct vmemmap_remap_walk { unsigned long flags; }; +#ifndef vmemmap_update_pmd +static inline void vmemmap_update_pmd(unsigned long start, + pmd_t *pmd, pte_t *pgtable) +{ + pmd_populate_kernel(&init_mm, pmd, pgtable); +} +#endif + +#ifndef vmemmap_update_pte +static inline void vmemmap_update_pte(unsigned long addr, + pte_t *pte, pte_t entry) +{ + set_pte_at(&init_mm, addr, pte, entry); +} +#endif + +#ifndef flush_tlb_vmemmap_all +static inline void flush_tlb_vmemmap_all(void) +{ + flush_tlb_all(); +} +#endif + +#ifndef flush_tlb_vmemmap_range +static inline void flush_tlb_vmemmap_range(unsigned long start, + unsigned long end) +{ + flush_tlb_kernel_range(start, end); +} +#endif + static int split_vmemmap_huge_pmd(pmd_t *pmd, unsigned long start, bool flush) { pmd_t __pmd; @@ -87,9 +118,9 @@ static int split_vmemmap_huge_pmd(pmd_t *pmd, unsigned long start, bool flush) /* Make pte visible before pmd. See comment in pmd_install(). */ smp_wmb(); - pmd_populate_kernel(&init_mm, pmd, pgtable); + vmemmap_update_pmd(start, pmd, pgtable); if (flush) - flush_tlb_kernel_range(start, start + PMD_SIZE); + flush_tlb_vmemmap_range(start, start + PMD_SIZE); } else { pte_free_kernel(&init_mm, pgtable); } @@ -217,7 +248,7 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, } while (pgd++, addr = next, addr != end); if (walk->remap_pte && !(walk->flags & VMEMMAP_REMAP_NO_TLB_FLUSH)) - flush_tlb_kernel_range(start, end); + flush_tlb_vmemmap_range(start, end); return 0; } @@ -263,15 +294,15 @@ static void vmemmap_remap_pte(pte_t *pte, unsigned long addr, /* * Makes sure that preceding stores to the page contents from - * vmemmap_remap_free() become visible before the set_pte_at() - * write. + * vmemmap_remap_free() become visible before the + * vmemmap_update_pte() write. */ smp_wmb(); } entry = mk_pte(walk->reuse_page, pgprot); list_add(&page->lru, walk->vmemmap_pages); - set_pte_at(&init_mm, addr, pte, entry); + vmemmap_update_pte(addr, pte, entry); } /* @@ -310,10 +341,10 @@ static void vmemmap_restore_pte(pte_t *pte, unsigned long addr, /* * Makes sure that preceding stores to the page contents become visible - * before the set_pte_at() write. + * before the vmemmap_update_pte() write. */ smp_wmb(); - set_pte_at(&init_mm, addr, pte, mk_pte(page, pgprot)); + vmemmap_update_pte(addr, pte, mk_pte(page, pgprot)); } /** @@ -576,7 +607,7 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h, } if (restored) - flush_tlb_all(); + flush_tlb_vmemmap_all(); if (!ret) ret = restored; return ret; @@ -744,7 +775,7 @@ void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_l break; } - flush_tlb_all(); + flush_tlb_vmemmap_all(); list_for_each_entry(folio, folio_list, lru) { int ret = __hugetlb_vmemmap_optimize_folio(h, folio, @@ -760,7 +791,7 @@ void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_l * allowing more vmemmap remaps to occur. */ if (ret == -ENOMEM && !list_empty(&vmemmap_pages)) { - flush_tlb_all(); + flush_tlb_vmemmap_all(); free_vmemmap_page_list(&vmemmap_pages); INIT_LIST_HEAD(&vmemmap_pages); __hugetlb_vmemmap_optimize_folio(h, folio, @@ -769,7 +800,7 @@ void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_l } } - flush_tlb_all(); + flush_tlb_vmemmap_all(); free_vmemmap_page_list(&vmemmap_pages); }