diff mbox series

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

Message ID 20240313125711.20651-5-piliu@redhat.com (mailing list archive)
State New, archived
Headers show
Series arm64: mm: Use __create_pgd_mapping_locked() in | expand

Commit Message

Pingfan Liu March 13, 2024, 12:57 p.m. UTC
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@redhat.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
To: linux-arm-kernel@lists.infradead.org
---
 arch/arm64/mm/mmu_head.c | 42 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
diff mbox series

Patch

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,