From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144937; b=etDRyQ8+t1NuAAwsXupVK+D+HucRyWOeFl1CPfI4zGf4K5YLu2dQ5luL08Dj1cm4pqdx /LkjOHPmPLVTAq5HXoLvag/EYpvKXMFvZf/nUBYnkCwPu/lFqDCBMZDJOFZ5dWBRqeAI3 DLQmqaF/4jvZvnHWkJ4xf4vlV7Ego8lwknKscGiJM8BwWokYPObWoe9cvkhOEkd9VwgX+ JJWzUGhIZtxBN4Tmm/KP0EX6iG3qBiUUDS4+XpNsG+dw1VOAha+yKn1867TfLP52B4NOa a0lY6j+YJQucuoE2rm4JvR1xyhDrcdSgVtxg81/A7AeIWYHA6dnH4Uj3TtdWhwORhbg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144937; h=DMARC-Filter:Received:Received:DKIM-Signature:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key; bh=cNQhPDzPapsEnKq6rFnOagU5cJC7hMWfAIdG8vpxijk=; b=F4s8i1KNaXsZCdgneTELM+tNeIhf4sLFHaltlAeojzwuVvbXpUOTYwEQdKGnk7KRf65a nV80Tv/dNlstYZ+GQLmA7AphmepeVitfodkXfjRLIC5QULnelQi4qWYt7DSaqqQcnAe78 sS0L8wGa7YR122CJ9EfvMjAcf4cG9EY9um3DIygIoIfIQwyBMxhvJDRRA2cgvKWK7O5m4 4hrZ1W/j42qt8ig1EFJVRHzJluqZZATdCBfO5C1lqYp0mp6q07LW2gdSoTq7oVrRuxXNk lKPfUnwO23mU2KQmkZPKOB+QCOwZ3pASHMBpw1nlfq4gf8X5w24aB1aXiG75c/Jbv+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=FNVqnFTm; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FAC1606A681; Tue, 1 Dec 2026 17:08:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1FAC1606A681 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.a=rsa-sha256 header.s=foss header.b=FNVqnFTm 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 EA8921A9A; Tue, 1 Dec 2026 09:08:53 -0800 (PST) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 52F403F7D8; Tue, 1 Dec 2026 09:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796144936; bh=zW+LVKPdjPec+zHWxvx5zqVGc3fw6w3hIxNw8wx0onk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FNVqnFTmYaSFcV46u963RRZnPJ3oeDfGiLZ/HOwDshAHpgkXA2rbOkQ9qnRZUSV67 IdHFNvlRnOxIYEMUDuF+Ciojx+70y9N3esit96ufRhxz9uBnonYfZZmkHXTKxHwBcB paVxWr/INton1rJJIjhC8nHTEf/iuZyJQISnp0Ec= From: Yeoreum Yun Date: Tue, 01 Dec 2026 17:07:16 +0000 Subject: [PATCH v4 14/20] x86/mm: Carve out the generic compile-time folded pgtable case in effective_prot() 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261201-dummy_ptxp3-v4-14-9dec1da6a49a@arm.com> References: <20261201-dummy_ptxp3-v4-0-9dec1da6a49a@arm.com> In-Reply-To: <20261201-dummy_ptxp3-v4-0-9dec1da6a49a@arm.com> To: Russell King , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Catalin Marinas , Will Deacon , Arnd Bergmann , Andrew Morton , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , David Hildenbrand , Michal Hocko , Lorenzo Stoakes , Tianrui Zhao , Bibo Mao , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonas Bonn , Stefan Kristiansson , Stafford Horne Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-openrisc@vger.kernel.org, Muhammad Usama Anjum , Yeoreum Yun X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4994; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=zW+LVKPdjPec+zHWxvx5zqVGc3fw6w3hIxNw8wx0onk=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBrDv7Anfxq4uYz3hQ06FSDV+umy86ECL86dH73v UM1sB8YgLOJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCaw7+wAAKCRBt1cPRWsUx MwxFC/9rKFWPaCxArcknS69d2nZ+ABSLg+E0OOLevE3lhrdA7g82T96qZCa64yyHFDKyaWRRLGq xm4Rptyljg5Ynu2CBLGDyxVNxmRw0LgiriCV7JmJgB5Ztxcv79iZNW1rI8zQDvnQE6bEmBBmLP8 f95iY1t9p0L1wUK5Xvi+S+F1ZDSpZg157ZA6KGRCBSr5G+BWX8w+apQvf1FrlaWJpM8QTS6AWmi 19K30zQSHyLiAHdmJ1nHnkT97iimgQWZsd1v8d2FHWoPi/v+7/Ch5AAb6Fey77FwL+a7KxZ5p+n HEg/UjON8DfXbiMSpJG3x4fbDMCjPwqXZA9nR60bXT4lElgcOVpECpOmAy9PkT0bGFYdw/v93HH kMqj2pfHH5gv3mAxdeiWNM0Fr7P07WK55bhehWDeNxq8ZK9IDAPSYPjlPmly8gpr7nhQhH3Mwuq bT4GRoKVuiUnZAY50j8OxW9HQ1UZHlNzJVIXkYzKEpF0J23CG3FHOKU9IChKB5LT+RWLE= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 The behaviour of pXdp_get() will change with generic compile-time folded page tables. To prepare for that, rework effective_prot() to ignore any folded page table entries, as it will unconditionally get called by ptdump core with pXd_val(pXdp_get()), and the value for folded entries really should be ignored. For this, introduce mm_first_pgtable_level() to identify the first real page-table level, move mm_pXd_folded() into !__ASSEMBLER__ and update effective_prot with higher_prot only when the current entry is not folded nor the first level. There should be no functional change. Link: [1] https://lore.kernel.org/all/0019d675-ce3d-4a5c-89ed-f126c45145c9@kernel.org/ Tested-by: Muhammad Usama Anjum Reviewed-by: David Hildenbrand (Arm) Acked-by: Dave Hansen Signed-off-by: Yeoreum Yun --- arch/x86/mm/dump_pagetables.c | 6 +++-- include/linux/pgtable.h | 61 ++++++++++++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index a18a61e732c3d..2acbe41eb58f2 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -38,6 +38,7 @@ struct pg_state { bool check_wx; unsigned long wx_pages; struct seq_file *seq; + struct mm_struct *mm; }; struct addr_marker { @@ -254,7 +255,7 @@ static void effective_prot(struct ptdump_state *pt_st, enum pgtable_level level, pgprotval_t prot = val & PTE_FLAGS_MASK; pgprotval_t effective; - if (level > PGTABLE_LEVEL_PGD) { + if (level > mm_first_pgtable_level(st->mm)) { pgprotval_t higher_prot = st->prot_levels[level - 1]; effective = (higher_prot & prot & (_PAGE_USER | _PAGE_RW)) | @@ -452,7 +453,8 @@ bool ptdump_walk_pgd_level_core(struct seq_file *m, .level = -1, .to_dmesg = dmesg, .check_wx = checkwx, - .seq = m + .seq = m, + .mm = mm, }; ptdump_walk_pgd(&st.ptdump, mm, pgd); diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index abe14728d280f..c64a7e8505b69 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -393,6 +393,22 @@ static inline void lazy_mmu_mode_pause(void) {} static inline void lazy_mmu_mode_resume(void) {} #endif +/* + * On some architectures it depends on the mm if the p4d/pud or pmd + * layer of the page table hierarchy is folded or not. + */ +#ifndef mm_p4d_folded +#define mm_p4d_folded(mm) __is_defined(__PAGETABLE_P4D_FOLDED) +#endif + +#ifndef mm_pud_folded +#define mm_pud_folded(mm) __is_defined(__PAGETABLE_PUD_FOLDED) +#endif + +#ifndef mm_pmd_folded +#define mm_pmd_folded(mm) __is_defined(__PAGETABLE_PMD_FOLDED) +#endif + #ifndef pte_batch_hint /** * pte_batch_hint - Number of pages that can be added to batch without scanning. @@ -2337,6 +2353,36 @@ static inline const char *pgtable_level_to_str(enum pgtable_level level) } } +#ifdef CONFIG_MMU +/** + * mm_first_pgtable_level - return the first non-folded page-table level + * @mm: The mm structure. + * + * With runtime- or compile-time folded page tables, page-table walkers + * effectively skip the folded top-level page tables, treating them as + * always-present entries pointing to the next lower-level page table. + * + * Return the first page-table level in @mm that is not folded. + * + * Return: the first non-folded page-table level. + */ +static inline enum pgtable_level mm_first_pgtable_level(struct mm_struct *mm) +{ + /* + * "PMD folded" actually means "PMD is folded into PUD", and + * pud_present() etc. are hard-coded to look like present page table + * levels, whereby pmd_present() etc. contain real logic. + */ + if (mm_pmd_folded(mm)) + return PGTABLE_LEVEL_PMD; + if (mm_pud_folded(mm)) + return PGTABLE_LEVEL_PUD; + if (mm_p4d_folded(mm)) + return PGTABLE_LEVEL_P4D; + return PGTABLE_LEVEL_PGD; +} +#endif /* CONFIG_MMU */ + void ptval_bytes_to_hex_str(char *buf, size_t buf_size, const void *entry, size_t entry_size); #define ptval_to_str(buf, val) \ @@ -2373,21 +2419,6 @@ void ptval_bytes_to_hex_str(char *buf, size_t buf_size, const void *entry, size_ #ifndef has_transparent_pud_hugepage #define has_transparent_pud_hugepage() IS_BUILTIN(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) #endif -/* - * On some architectures it depends on the mm if the p4d/pud or pmd - * layer of the page table hierarchy is folded or not. - */ -#ifndef mm_p4d_folded -#define mm_p4d_folded(mm) __is_defined(__PAGETABLE_P4D_FOLDED) -#endif - -#ifndef mm_pud_folded -#define mm_pud_folded(mm) __is_defined(__PAGETABLE_PUD_FOLDED) -#endif - -#ifndef mm_pmd_folded -#define mm_pmd_folded(mm) __is_defined(__PAGETABLE_PMD_FOLDED) -#endif #ifndef p4d_offset_lockless #define p4d_offset_lockless(pgdp, pgd, address) p4d_offset(&(pgd), address) -- 2.43.0