From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78A1B606A337 for ; Tue, 1 Dec 2026 17:05:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=lnbFrDCW; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=avWqZlZF 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-Unsubscribe-Post:List-Owner; bh=FtHYFvsapbXbfOOVZLqdRnYECVT15ALx8DYlKccyNlk=; b=lnbFrDCWb0Je9uxTpe791UJB2v R2QHpYCVnJlbNVSk3oJXzI3w2H/MVB67Agj4duM3ZiFpt9Urns7H/9AYcus6djTI3ydO+AbQD6uDx xMhnp/S8UpsfLwqZEXJPtLxzADTEk5X7xBg2WMUmL//EAdsWhEV+D+YlsK8NiiaGKtRJ/A30Sgie+ jBAw5GvtWnKI38OgmofqtxJf1qBMQV+i8syTbxGSfpDbUKZed2Nsg6R1d2wJFFAw+qcxnFhrOKuU1 tyIZO5pAlFOLDcrq+hyGiAH86IE6eowvBc93qrIyMdhFi6FkgKdmsSXIGgz+4KlvEjdLo2xnkVYdd dtIXKsuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYPTF-00000008UaV-1rRH; Tue, 01 Dec 2026 15:08:41 +0000 Received: from mail-pf1-x446.google.com ([2607:f8b0:4864:20::446]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYPSx-00000008UAU-2FYE for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 15:08:31 +0000 Received: by mail-pf1-x446.google.com with SMTP id d2e1a72fcca58-8b8cef34b43so13134385b3a.2 for ; Tue, 01 Dec 2026 07:08:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796137700; x=1796742500; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FtHYFvsapbXbfOOVZLqdRnYECVT15ALx8DYlKccyNlk=; b=avWqZlZFejuC/iLxBgMKvakc7ff8FkQjdWF981Eh9pRaDyhWnLepWRObVFLdZegUjq Vr/ypLdMUrMgSot75ZAUFxDu8F8PO2ck3SFs9kmktgnPEtZvMCy8as44W3z9mPv6TcI7 hQBfka2q6zYoByF3HSrrQXlzwA8T4ohKRdE/VGmpwdWpewmp7T+9sy9chpVwmX0Vg2es D3hqxxUPr1vcnO2eTQ9q1nLJ1/QLXmuU9V9uWUURc/rIX9d9Ar9UgNn3Gnx+YKYziUlB mhx7he6h5RUj42vYS1P+Zp5zYO0BYGFh+1y51eKzMF3PCvN4eNTg1KryoNT1LIW33WHh 9gFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137700; x=1796742500; h=content-type: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:content-type; bh=FtHYFvsapbXbfOOVZLqdRnYECVT15ALx8DYlKccyNlk=; b=xQHNEne5UgxKUANT89o+J99wW405PdgWu0pwYMIH+O4N1zj2/vqKnTiOgAo2aBaLME CmoZRPrMCOFoZ1TcxCzhA2hQHS6Bz0FtmI8gAhdtv2G5K8DZa61l4T/vrCIaSUMPWCom XUIbKkQ5Q4nWKHY8ejWm5mlIHDR2ZwWlwm6n77T6xDhyfRE2Y6/+c7xZLv4hxd3K1dF+ TlZjLGdoTaJSXLYhMAeJGrBW2pjvnbtcTiYL3X4UNM8NAjKfnosX5GcaUl/pf2sv+RAv FApKkgq9ttS68EeROYEFuA7nLjgb0rT/Sg8wPl/jr1/FGIy9L9cjcbl9HZrLFGah36SO h8Kg== X-Forwarded-Encrypted: i=1; AL+hErEUfQUzd3/10B9O6kzWo4Y9MFuLWAFnPkVx0q1Hvw8vTfOypXdEhFYDaJHrycFbl3N9cpPPmC9ffwdtJnvtxVob@lists.infradead.org X-Gm-Message-State: APuU4Z9juZ3W2W9xCNnN8o+F3CYXWd1U1mJqWKW8vFMDlylVugcA3VDg kLPlaHuEd0A1IT5zGt2sZeDikLWHx+CxJt/KgeOkyvbjLBDTWAn0boEXpzGf0MLIL+aG+79Wr2J Nz9ymjr+4wNZfrgigwp1jUw== X-Received: from pfbmy11-n2.prod.google.com ([2002:a05:6a00:6d4b:20b0:8be:87fe:7950]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1ac9:b0:899:74d0:8a58 with SMTP id d2e1a72fcca58-8c87d11f274mr37073702b3a.55.1796137699457; Tue, 01 Dec 2026 07:08:19 -0800 (PST) Date: Tue, 1 Dec 2026 15:07:56 +0000 In-Reply-To: <20261201150801.2239894-1-jthoughton@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261201150801.2239894-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261201150801.2239894-15-jthoughton@google.com> Subject: [RFC PATCH v4 14/18] hugetlb_vmemmap: Use vmemmap_update_pmd for replacing in-use PMDs From: James Houghton To: Will Deacon , Catalin Marinas , Muchun Song , Oscar Salvador , Andrew Morton Cc: Kefeng Wang , Nikos Nikoleris , Linu Cherian , Mark Rutland , David Hildenbrand , Ryan Roberts , Nanyong Sun , Yu Zhao , Frank van der Linden , David Rientjes , James Houghton , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_070823_623060_0EE38919 X-CRM114-Status: GOOD ( 19.63 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 This routine is to be used for updating in-use, leaf-level PMDs in the vmemmap without introducing a window where vmemmap accesses might fault. Because vmemmap_update_pmd() can fail, the split_page() call needs to be moved to after the PMD update. Because both split_page() and the PMD update are done under the page table lock, this rearrangement is safe. Only leaf-level PMD to non-leaf PMD (mapping the same physical pages) is the only transition that needs to be supported. Collapsing a non-leaf PMD to a leaf-level PMD is not used by HVO, so vmemmap_update_pmd() need not support it. This patch allows arm64's implementation to replaced with one that does not require BBML3. Signed-off-by: James Houghton --- arch/arm64/include/asm/pgalloc.h | 9 +++++++++ include/linux/pgalloc.h | 23 +++++++++++++++++++++++ mm/hugetlb_vmemmap.c | 21 ++++++++++++++------- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h index 1b4509d3382c..421e07545cfd 100644 --- a/arch/arm64/include/asm/pgalloc.h +++ b/arch/arm64/include/asm/pgalloc.h @@ -121,4 +121,13 @@ pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep) PMD_TYPE_TABLE | PMD_TABLE_AF | PMD_TABLE_PXN); } +#define vmemmap_update_pmd vmemmap_update_pmd +static inline int vmemmap_update_pmd(unsigned long addr, pmd_t *pmdp, + pte_t *pgtable) +{ + /* BBLM3 is required. Its presence has been checked. */ + pmd_populate_kernel(&init_mm, pmdp, pgtable); + return 0; +} + #endif diff --git a/include/linux/pgalloc.h b/include/linux/pgalloc.h index 9174fa59bbc5..37f930bec1dc 100644 --- a/include/linux/pgalloc.h +++ b/include/linux/pgalloc.h @@ -26,4 +26,27 @@ arch_sync_kernel_mappings(addr, addr); \ } while (0) +#ifndef vmemmap_update_pmd +/* + * vmemmap_update_pmd - Populate a PMD that is in use by the vmemmap. + * @addr: Base address of the remapped PMD. + * @pmdp: Page table pointer to be overwritten. + * @pgtable: Pointer to the page table that the new PMD will point to. + * + * This function is only to be used to update PMDs that map the vmemmap to + * point to a page of already-populated PTEs that map the same pages. + * + * Implementations of this function must ensure that, while the update is taking + * place, CPUs will not fault on the remapped virtual address range. + * Architectures on which pmd_populate_kernel() does not guarantee this must + * override this function. + */ +static inline int vmemmap_update_pmd(unsigned long addr, pmd_t *pmdp, + pte_t *pgtable) +{ + pmd_populate_kernel(&init_mm, pmdp, pgtable); + return 0; +} +#endif + #endif /* _LINUX_PGALLOC_H */ diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 0f424093581c..99b40d4540e2 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -82,6 +82,7 @@ static int vmemmap_split_pmd(pmd_t *pmd, struct page *head, unsigned long start, struct vmemmap_remap_walk *walk) { pmd_t __pmd; + int ret; int i; unsigned long addr = start; pte_t *pgtable; @@ -101,8 +102,15 @@ static int vmemmap_split_pmd(pmd_t *pmd, struct page *head, unsigned long start, set_pte_at(&init_mm, addr, pte, entry); } + ret = 0; spin_lock(&init_mm.page_table_lock); if (likely(pmd_leaf(*pmd))) { + /* Make pte visible before pmd. See comment in pmd_install(). */ + smp_wmb(); + ret = vmemmap_update_pmd(start, pmd, pgtable); + if (ret) + goto free; + /* * Higher order allocations from buddy allocator must be able to * be treated as independent small pages (as they can be freed @@ -111,9 +119,6 @@ static int vmemmap_split_pmd(pmd_t *pmd, struct page *head, unsigned long start, if (!PageReserved(head)) split_page(head, get_order(PMD_SIZE)); - /* Make pte visible before pmd. See comment in pmd_install(). */ - smp_wmb(); - pmd_populate_kernel(&init_mm, pmd, pgtable); /* * Modern MMUs allow overlapping TLB entries with different mapping * granularities only if they map the same physical address. So @@ -121,12 +126,14 @@ static int vmemmap_split_pmd(pmd_t *pmd, struct page *head, unsigned long start, */ if (walk->remap_pte || !(walk->flags & VMEMMAP_DEFER_TLB_FLUSH)) flush_tlb_kernel_range(start, start + PMD_SIZE); - } else { - pte_free_kernel(&init_mm, pgtable); + goto out; } - spin_unlock(&init_mm.page_table_lock); - return 0; +free: + pte_free_kernel(&init_mm, pgtable); +out: + spin_unlock(&init_mm.page_table_lock); + return ret; } static int vmemmap_pmd_entry(pmd_t *pmd, unsigned long addr, -- 2.56.1.839.g22a8290db9-goog