[PATCH 04/10] arm64: head: Enable __create_pgd_mapping() to handle pgtable's paddr

Pingfan Liu piliu at redhat.com
Wed Mar 13 05:57:02 PDT 2024


When mmu-off or identical mapping, both of the page table:
init_idmap_pg_dir and init_pg_dir can be accessed by physical address
(virtual address equals physical)

This patch introduces routines to avoid using fixmap to access page table.

Signed-off-by: Pingfan Liu <piliu at redhat.com>
Cc: Ard Biesheuvel <ardb at kernel.org>
Cc: Catalin Marinas <catalin.marinas at arm.com>
Cc: Will Deacon <will at kernel.org>
Cc: Mark Rutland <mark.rutland at arm.com>
To: linux-arm-kernel at lists.infradead.org
---
 arch/arm64/mm/mmu_head.c | 42 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/arch/arm64/mm/mmu_head.c b/arch/arm64/mm/mmu_head.c
index ccdd0f079c49..562d036dc30a 100644
--- a/arch/arm64/mm/mmu_head.c
+++ b/arch/arm64/mm/mmu_head.c
@@ -10,6 +10,48 @@
 #include <asm/pgalloc.h>
 
 #define INSTRUMENT_OPTION __noinstr_section(".init.text.noinstr")
+
+#undef pud_set_fixmap_offset
+#undef pud_clear_fixmap
+#undef pmd_set_fixmap_offset
+#undef pmd_clear_fixmap
+#undef pte_set_fixmap_offset
+#undef pte_clear_fixmap
+
+/* This group is used to access intermedia level in no mmu or identity map */
+#define pud_set_fixmap_offset(p4dp, addr)			\
+({								\
+	pud_t *pudp;						\
+	if (CONFIG_PGTABLE_LEVELS > 3)					\
+		pudp = (pud_t *)__p4d_to_phys(*p4dp) + pud_index(addr);	\
+	else								\
+		pudp = (pud_t *)p4dp;					\
+	pudp;							\
+})
+
+#define pud_clear_fixmap()
+
+#define pmd_set_fixmap_offset(pudp, addr)			\
+({								\
+	pmd_t *pmdp;						\
+	if (CONFIG_PGTABLE_LEVELS > 2)					\
+		pmdp = (pmd_t *)__pud_to_phys(*pudp) + pmd_index(addr);	\
+	else								\
+		pmdp = (pmd_t *)pudp;					\
+	pmdp;							\
+})
+
+#define pmd_clear_fixmap()
+
+#define pte_set_fixmap_offset(pmdp, addr)			\
+({								\
+	pte_t *ptep;						\
+	ptep = (pte_t *)__pmd_to_phys(*pmdp) + pte_index(addr);	\
+	ptep;							\
+})
+
+#define pte_clear_fixmap()
+
 #include "mmu_inc.c"
 
 void INSTRUMENT_OPTION mmu_head_create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys,
-- 
2.41.0




More information about the linux-arm-kernel mailing list