From patchwork Tue Aug 6 02:21:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13754348 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 6BE10C3DA7F for ; Tue, 6 Aug 2024 02:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Dz9+L9Nas5YdR+3aU4+X/tR5OCfJ0AKY3iAQMLv0S5k=; b=h8is+p2+mtnI1YKP27lv9g0Lbh FuVrKQzlbxXh+iSd4RkGphilUHfoZ4sVaNDzj7seGMYEluwc5SyIlLoewgNfhvnNr0Dq/rduxyV4a l2zylWlCJJtwqU1aclpvvSbHrU5oa8jdP9EGGMgHdV4VFnuelWdV1KK5occqSwr1Sa1p93Hid6G3O 9fhxtRtaJdDvNs/rcBJRaBU67YwfHHH7zRZ93aXOZvS5Ewxv0SXW1NLbt+KkAE6xNjG6RP3NP33R2 aVu2NPKamhCFluNUB/gIUalOPJmGkY4oynTueCrF1QBrtWOB1Wn+OUKxpphIlVqS/cMWyWKZLHuUE 0Gutbhig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb9rD-00000000GTc-0SQn; Tue, 06 Aug 2024 02:23:27 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb9pI-00000000Frl-0LFH for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 02:21:29 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-690404fd34eso534347b3.1 for ; Mon, 05 Aug 2024 19:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722910887; x=1723515687; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Dz9+L9Nas5YdR+3aU4+X/tR5OCfJ0AKY3iAQMLv0S5k=; b=Gq+2RmgMtvlGQbsq8iUoOYnmxg4t4svvO/dIqo7ZRZ8uv7ncXj8uaqnFA8tes38r5v BvxQche43tUzoTK1p3bZxVbqKpwJ9SVdRyJyMTSFslMIt7JKFVVVoY9dK4zCpIKYoATw LYwpZH5KPEvMU/zeOcDnHyuxrcTQF6CzPsKNOw8nb9A+rEclR7q62nhV8Y+7OufugEoe ihbWPCGJw67I9W7sMjVfuI2ZEHGYgvHEG18ZMmVOiRN/+wGAJjRKtXIxdtGgNe1f0eEn VrqCUGmyv86aSVztMGImSotWVkzCMalEYfRa28zoT+rL6y+JbkfRdDP0nCvjCVteyFqM 7giA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722910887; x=1723515687; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Dz9+L9Nas5YdR+3aU4+X/tR5OCfJ0AKY3iAQMLv0S5k=; b=Nfmd8jKvxR+OKK/cASanSAIU+a1GNA/UnhbkD6UhK77ar5Wssto3bGR2GiaIygbXpX f4NHrqORLJHyTieNGbVjKJ+QHsxY+3kVNvLxetWACkAY5ebkubt5X2Scz2/HPcH8a3Li YNLPUtjW2I3glM96lGeykDV2q6DDOSvUvd3tGaDLbQeRDxYoxSTOzkxCyimZ/aFhCQhk 1HD+4eclvTL1zVrC6CKnOHMHb7OpwMaQuU+FcjAtoDMp0OFi8btz31d0DUtKI9UW9t/G 20BlW/pMD2vYQygktt5IibZT4EMOmtav8XwUa469S+JRuxZrzYCdLq0wD1cJCUBxx+Js e6bA== X-Forwarded-Encrypted: i=1; AJvYcCUxMBadRcMMuQZ9hjMyvGAq6ndt4q5+QzX4gRAchdKkV87qONk0CyJ5mkaM54AeqUUL/NrS2s4L1xT486TeJiy/KfHhBBdp8Vl6TFORDHyghpfMtak= X-Gm-Message-State: AOJu0Yzi76DWn9fHzX1mBlCt6dj+o8XN9G3Kch6QVTOWwoBdpoyrcjJ2 nJ6vHPlevowk3bB2779pHVC3z+7rs20g4PvBsW1qPQR9R64F20EngcnbF02iHks2IvZ66ZPU7PR 20g== X-Google-Smtp-Source: AGHT+IE5Ot4MCUehL2BALtzt0Nbbacrl8HCjMPwdvfemN8nL8qevC8oWRD8zmA2efNk4jGDFZ//D943lM9s= X-Received: from yuzhao2.bld.corp.google.com ([2a00:79e0:2e28:6:261c:802b:6b55:e09c]) (user=yuzhao job=sendgmr) by 2002:a05:690c:113:b0:648:3f93:61f2 with SMTP id 00721157ae682-689641a414emr5295867b3.6.1722910886865; Mon, 05 Aug 2024 19:21:26 -0700 (PDT) Date: Mon, 5 Aug 2024 20:21:13 -0600 In-Reply-To: <20240806022114.3320543-1-yuzhao@google.com> Mime-Version: 1.0 References: <20240806022114.3320543-1-yuzhao@google.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog Message-ID: <20240806022114.3320543-4-yuzhao@google.com> Subject: [RFC PATCH 3/4] arm64: pause remote CPUs to update vmemmap From: Yu Zhao To: Catalin Marinas , Will Deacon Cc: Andrew Morton , David Rientjes , Douglas Anderson , Frank van der Linden , Mark Rutland , Muchun Song , Nanyong Sun , Yang Shi , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240805_192128_232114_1A9155D3 X-CRM114-Status: GOOD ( 12.79 ) 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 Pause remote CPUs so that the local CPU can follow the proper BBM sequence to safely update the vmemmap mapping `struct page` areas. While updating the vmemmap, it is guaranteed that neither the local CPU nor the remote ones will access the `struct page` area being updated, and therefore they will not trigger kernel PFs. Signed-off-by: Yu Zhao --- arch/arm64/include/asm/pgalloc.h | 55 ++++++++++++++++++++++++++++++++ mm/hugetlb_vmemmap.c | 14 ++++++++ 2 files changed, 69 insertions(+) diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h index 8ff5f2a2579e..1af1aa34a351 100644 --- a/arch/arm64/include/asm/pgalloc.h +++ b/arch/arm64/include/asm/pgalloc.h @@ -12,6 +12,7 @@ #include #include #include +#include #define __HAVE_ARCH_PGD_FREE #define __HAVE_ARCH_PUD_FREE @@ -137,4 +138,58 @@ pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep) __pmd_populate(pmdp, page_to_phys(ptep), PMD_TYPE_TABLE | PMD_TABLE_PXN); } +#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP + +#define vmemmap_update_lock vmemmap_update_lock +static inline void vmemmap_update_lock(void) +{ + cpus_read_lock(); +} + +#define vmemmap_update_unlock vmemmap_update_unlock +static inline void vmemmap_update_unlock(void) +{ + cpus_read_unlock(); +} + +#define vmemmap_update_pte vmemmap_update_pte +static inline void vmemmap_update_pte(unsigned long addr, pte_t *ptep, pte_t pte) +{ + preempt_disable(); + pause_remote_cpus(); + + pte_clear(&init_mm, addr, ptep); + flush_tlb_kernel_range(addr, addr + PAGE_SIZE); + set_pte_at(&init_mm, addr, ptep, pte); + + resume_remote_cpus(); + preempt_enable(); +} + +#define vmemmap_update_pmd vmemmap_update_pmd +static inline void vmemmap_update_pmd(unsigned long addr, pmd_t *pmdp, pte_t *ptep) +{ + preempt_disable(); + pause_remote_cpus(); + + pmd_clear(pmdp); + flush_tlb_kernel_range(addr, addr + PMD_SIZE); + pmd_populate_kernel(&init_mm, pmdp, ptep); + + resume_remote_cpus(); + preempt_enable(); +} + +#define vmemmap_flush_tlb_all vmemmap_flush_tlb_all +static inline void vmemmap_flush_tlb_all(void) +{ +} + +#define vmemmap_flush_tlb_range vmemmap_flush_tlb_range +static inline void vmemmap_flush_tlb_range(unsigned long start, unsigned long end) +{ +} + +#endif /* CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP */ + #endif diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 2dd92e58f304..893c73493d9c 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -46,6 +46,18 @@ struct vmemmap_remap_walk { unsigned long flags; }; +#ifndef vmemmap_update_lock +static void vmemmap_update_lock(void) +{ +} +#endif + +#ifndef vmemmap_update_unlock +static void vmemmap_update_unlock(void) +{ +} +#endif + #ifndef vmemmap_update_pmd static inline void vmemmap_update_pmd(unsigned long addr, pmd_t *pmdp, pte_t *ptep) @@ -194,10 +206,12 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, VM_BUG_ON(!PAGE_ALIGNED(start | end)); + vmemmap_update_lock(); mmap_read_lock(&init_mm); ret = walk_page_range_novma(&init_mm, start, end, &vmemmap_remap_ops, NULL, walk); mmap_read_unlock(&init_mm); + vmemmap_update_unlock(); if (ret) return ret;