From nobody Wed Apr 1 11:13:52 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A8F6377034 for ; Mon, 30 Mar 2026 16:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774887445; cv=none; b=LOaZcyIL2FDZo94nNwgksl2se0eB2Qrrd2CeP8b1FxSDmqFEQNjMxL6qEhYXSCjR0YRkCzIUS9UnGbQpzNRmwUGXED4V4IctNV7KVk94OxUdYWNWLNuvUeuMJGai/35HNOyuCAH/3vfOPHwODMjfJnQvlcLGy0ppYwxwDLVHlfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774887445; c=relaxed/simple; bh=+3ztKn8+vWKCZnOUAI7aUx3xPekEk67SRoVhvi8keJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sxOlr20TXMj8ZepkXfjArk19HTp7SaL/Gj6ENZ5CNtmouUpvzmiJwuDkvXP1+LTS6BTdvyLOsnDidvzJjlCJrVjB+kLULLsmOqFTU9kLE9S6R8uAEipvHWrcCCtagYgBI5MI9bXYFvjqReeq/Wbo1FN5+rREG85wHTKpFh2+yU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=enmQqJNv; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="enmQqJNv" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9C7CC2403; Mon, 30 Mar 2026 09:17:16 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 16E673F7D8; Mon, 30 Mar 2026 09:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1774887442; bh=+3ztKn8+vWKCZnOUAI7aUx3xPekEk67SRoVhvi8keJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=enmQqJNvDTlUKQZU6bTl+9V9fEoxuFHh4uX/kt/i5ys3TRGLf0xp7g/YDZcgtWJ3F lkyqWZOKTXe91pot2KSqSUUYfgdxnxZw80re9a2655bgLVItfoSKCu7OcIgAdi8FGD XhOiumC2o9B8AF5t5GNICg9JrdGqaL+BJgh6k2mU= From: Ryan Roberts To: Catalin Marinas , Will Deacon , "David Hildenbrand (Arm)" , Dev Jain , Yang Shi , Suzuki K Poulose , Jinjiang Tu , Kevin Brodsky Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] arm64: mm: Remove pmd_sect() and pud_sect() Date: Mon, 30 Mar 2026 17:17:04 +0100 Message-ID: <20260330161705.3349825-4-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260330161705.3349825-1-ryan.roberts@arm.com> References: <20260330161705.3349825-1-ryan.roberts@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The semantics of pXd_leaf() are very similar to pXd_sect(). The only difference is that pXd_sect() only considers it a section if PTE_VALID is set, whereas pXd_leaf() permits both "valid" and "present-invalid" types. Using pXd_sect() has caused issues now that large leaf entries can be present-invalid since commit a166563e7ec37 ("arm64: mm: support large block mapping when rodata=3Dfull"), so let's just remove the API and standardize on pXd_leaf(). There are a few callsites of the form pXd_leaf(READ_ONCE(*pXdp)). This was previously fine for the pXd_sect() macro because it only evaluated its argument once. But pXd_leaf() evaluates its argument multiple times. So let's avoid unintended side effects by reimplementing pXd_leaf() as an inline function. Signed-off-by: Ryan Roberts --- arch/arm64/include/asm/pgtable.h | 19 ++++++++++++------- arch/arm64/mm/mmu.c | 18 +++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index dd062179b9b66..5bc42b85acfc0 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -784,9 +784,13 @@ extern pgprot_t phys_mem_access_prot(struct file *file= , unsigned long pfn, =20 #define pmd_table(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) =3D=3D \ PMD_TYPE_TABLE) -#define pmd_sect(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) =3D=3D \ - PMD_TYPE_SECT) -#define pmd_leaf(pmd) (pmd_present(pmd) && !pmd_table(pmd)) + +#define pmd_leaf pmd_leaf +static inline bool pmd_leaf(pmd_t pmd) +{ + return pmd_present(pmd) && !pmd_table(pmd); +} + #define pmd_bad(pmd) (!pmd_table(pmd)) =20 #define pmd_leaf_size(pmd) (pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE) @@ -804,11 +808,8 @@ static inline int pmd_trans_huge(pmd_t pmd) #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 #if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3 -static inline bool pud_sect(pud_t pud) { return false; } static inline bool pud_table(pud_t pud) { return true; } #else -#define pud_sect(pud) ((pud_val(pud) & PUD_TYPE_MASK) =3D=3D \ - PUD_TYPE_SECT) #define pud_table(pud) ((pud_val(pud) & PUD_TYPE_MASK) =3D=3D \ PUD_TYPE_TABLE) #endif @@ -878,7 +879,11 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) PUD_TYPE_TABLE) #define pud_present(pud) pte_present(pud_pte(pud)) #ifndef __PAGETABLE_PMD_FOLDED -#define pud_leaf(pud) (pud_present(pud) && !pud_table(pud)) +#define pud_leaf pud_leaf +static inline bool pud_leaf(pud_t pud) +{ + return pud_present(pud) && !pud_table(pud); +} #else #define pud_leaf(pud) false #endif diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 1575680675d8d..dcee56bb622ad 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -204,7 +204,7 @@ static int alloc_init_cont_pte(pmd_t *pmdp, unsigned lo= ng addr, pmd_t pmd =3D READ_ONCE(*pmdp); pte_t *ptep; =20 - BUG_ON(pmd_sect(pmd)); + BUG_ON(pmd_leaf(pmd)); if (pmd_none(pmd)) { pmdval_t pmdval =3D PMD_TYPE_TABLE | PMD_TABLE_UXN | PMD_TABLE_AF; phys_addr_t pte_phys; @@ -303,7 +303,7 @@ static int alloc_init_cont_pmd(pud_t *pudp, unsigned lo= ng addr, /* * Check for initial section mappings in the pgd/pud. */ - BUG_ON(pud_sect(pud)); + BUG_ON(pud_leaf(pud)); if (pud_none(pud)) { pudval_t pudval =3D PUD_TYPE_TABLE | PUD_TABLE_UXN | PUD_TABLE_AF; phys_addr_t pmd_phys; @@ -1503,7 +1503,7 @@ static void unmap_hotplug_pmd_range(pud_t *pudp, unsi= gned long addr, continue; =20 WARN_ON(!pmd_present(pmd)); - if (pmd_sect(pmd)) { + if (pmd_leaf(pmd)) { pmd_clear(pmdp); =20 /* @@ -1536,7 +1536,7 @@ static void unmap_hotplug_pud_range(p4d_t *p4dp, unsi= gned long addr, continue; =20 WARN_ON(!pud_present(pud)); - if (pud_sect(pud)) { + if (pud_leaf(pud)) { pud_clear(pudp); =20 /* @@ -1650,7 +1650,7 @@ static void free_empty_pmd_table(pud_t *pudp, unsigne= d long addr, if (pmd_none(pmd)) continue; =20 - WARN_ON(!pmd_present(pmd) || !pmd_table(pmd) || pmd_sect(pmd)); + WARN_ON(!pmd_present(pmd) || !pmd_table(pmd)); free_empty_pte_table(pmdp, addr, next, floor, ceiling); } while (addr =3D next, addr < end); =20 @@ -1690,7 +1690,7 @@ static void free_empty_pud_table(p4d_t *p4dp, unsigne= d long addr, if (pud_none(pud)) continue; =20 - WARN_ON(!pud_present(pud) || !pud_table(pud) || pud_sect(pud)); + WARN_ON(!pud_present(pud) || !pud_table(pud)); free_empty_pmd_table(pudp, addr, next, floor, ceiling); } while (addr =3D next, addr < end); =20 @@ -1786,7 +1786,7 @@ int __meminit vmemmap_check_pmd(pmd_t *pmdp, int node, { vmemmap_verify((pte_t *)pmdp, node, addr, next); =20 - return pmd_sect(READ_ONCE(*pmdp)); + return pmd_leaf(READ_ONCE(*pmdp)); } =20 int __meminit vmemmap_populate(unsigned long start, unsigned long end, int= node, @@ -1850,7 +1850,7 @@ void p4d_clear_huge(p4d_t *p4dp) =20 int pud_clear_huge(pud_t *pudp) { - if (!pud_sect(READ_ONCE(*pudp))) + if (!pud_leaf(READ_ONCE(*pudp))) return 0; pud_clear(pudp); return 1; @@ -1858,7 +1858,7 @@ int pud_clear_huge(pud_t *pudp) =20 int pmd_clear_huge(pmd_t *pmdp) { - if (!pmd_sect(READ_ONCE(*pmdp))) + if (!pmd_leaf(READ_ONCE(*pmdp))) return 0; pmd_clear(pmdp); return 1; --=20 2.43.0