From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796137701; b=38/qiTSn+waNNsndy1NBzrf+mAw/8jhY4MnuRWUajEnSF9ozk3YdC8rerkDQh9//tg/J Fj5Bxw5LQf0WEkJH70gqeinBB0u5WpN/zuvkR+wdqMm/CY/MdDjRX5fzmlsdp9wDKh2hm m9GtJm4F1ddCil4hkdWQXb43TniiTgaDEDthbmBE1T8x4lLD44SnxePnNxkEu89OaQ9y+ RT/EsVwU1QOhIEziywJSCguw+shUoW3BJRT74wvycPS1Y2rSIU8cjJZ4Ekv8rSFRlIlxK ztjr+0+jVACY1Wg8o3aEtDr1lIECkkENyKMjetCXCsvd/XCA8OqrTJL4KpyJ2c4Ui5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137701; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=FtHYFvsapbXbfOOVZLqdRnYECVT15ALx8DYlKccyNlk=; b=3N9H68GVNV9JvNIAXh5w909dyNW31BPNT+zIg1RsMiecsFl/O0vfqky0TIxorFicj0vL qH1Wpw1ursAEDCgREgJghrp0XMLkVL/vPOVbUmT8OojWJhFF/vB0x4Fqsvog4xKOZbtys H6TCrALDC92MuoXlcxq2RAvOkRPkV5D5fLefPmTkXLKpT59/aqtouNJ+8kwguaTOh2Zxn D2riBZof36YrPwy5yy3lKkfF0siqWBVtnpjMxLpIy2zrnqb6AAswMzc9EjH+eSqpmosyf Rz9V88aVrX40HN+bts5tyj6J5ynImTm0HSrObEB5cl8nWmP0XeujAT77Celyq2qJS2Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=es7Q78yr; arc=none smtp.remote-ip=209.85.210.197 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C35FE60A262F for ; Tue, 1 Dec 2026 15:08:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C35FE60A262F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=es7Q78yr Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-8b930598cf0so22866927b3a.1 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=vger.kernel.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=es7Q78yrhJgg+/3sjvIAhwlT7BS0NOnlA2zDnB7OVo06BM97KkFoVRkdbTbr+s8w1S qRu9BEketZjboHYCywPEgfZCNujj79+Hi8ZSCqMd/EBR8lguK+0Q4MqoBR3DN7kak3yX f3agMFUBltfWWgEZcj+/ILGmW/NXP02QLNwcd66IVJy5fwo0A+0x2h85no+UDorI6MLu 8mYddHkgQ7AIvuHjTf4kmYv/AjbP1KiabGUHysGN378gFLBVc6KsR7E2E7IATQP9oltn SSGiftgKOc2E8d88m3mzV+FfICVfXBa8z6OzEOG7Jt4cf6sQWjAK+pKVqnfQVZYFMv/C yfww== 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=T+AUfzCIRw1H34gRXT2oGZhlzge/XMHxCrxMPiVRSrcM6hcY/PkZT2rnOW+nw/YyyK oUzqw9kgumSlct2wXXlJt2fTHTaEQEs+0qu5CGgZX1zMXS981dvufkIXxKVpgMk+kEVR C+dKw59C0yQUGdfwJlQUDkeE6M5kEZMWjEhGScZqHh3CcYXlXiG1AQgan0oZDPu9Eddr tBAJLHYUvPyvHCgOY3tr5hqo24+R0GDRI3gMtDME8sHpKH4NS7EPzK6zAYEP+24oNMWx kV5NiFjLhuG6CLetvICzHJlUqE3iVZ/c7V3JYuJuAV1aWJ6Rc0s/u5qM7aDlaUmJwycw hgaA== X-Forwarded-Encrypted: i=1; AL+hErGpjNvAZKDtMPyycE7IxlzkZzmoSo6K8ZOhX2aDZOduemMIKuT/aHSeOXMACIrcysWSZeAgoNGWFkBoYtI=@vger.kernel.org X-Gm-Message-State: APuU4Z/i61zKGm+8EQj5blw6fJx4M8/NVh4Uqr7USI1vPZVwuOm3c6lx PGxEQi6D/smj9YTcE5Jq6AyHtjgAUb8KfV7VK6tqGhikQawDBJixEbrSgDMufaqYHWBufr7Bxe0 OM2BE3Gw4pMeLWI6d6kpFNg== 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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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" 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