]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
arm64: mm: Preserve existing table mappings when mapping DRAM
authorArd Biesheuvel <ardb@kernel.org>
Fri, 29 May 2026 15:01:55 +0000 (17:01 +0200)
committerWill Deacon <will@kernel.org>
Tue, 2 Jun 2026 15:29:15 +0000 (16:29 +0100)
Instead of blindly overwriting an existing table entry when mapping DRAM
regions, take care not to replace a pre-existing table entry with a
block entry. This permits the logic of mapping the kernel's linear alias
to be simplified in a subsequent patch.

Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/mm/mmu.c

index 3b302a0e8f34535faa5f321d5453183a3227e2b7..1db44adc87170f45cf4f483bbe936ebf390c4b36 100644 (file)
@@ -256,7 +256,8 @@ static int init_pmd(pmd_t *pmdp, unsigned long addr, unsigned long end,
 
                /* try section mapping first */
                if (((addr | next | phys) & ~PMD_MASK) == 0 &&
-                   (flags & NO_BLOCK_MAPPINGS) == 0) {
+                   (flags & NO_BLOCK_MAPPINGS) == 0 &&
+                   !pmd_table(old_pmd)) {
                        WARN_ON(!pmd_set_huge(pmdp, phys, prot));
 
                        /*
@@ -379,7 +380,8 @@ static int alloc_init_pud(p4d_t *p4dp, unsigned long addr, unsigned long end,
                 */
                if (pud_sect_supported() &&
                   ((addr | next | phys) & ~PUD_MASK) == 0 &&
-                   (flags & NO_BLOCK_MAPPINGS) == 0) {
+                   (flags & NO_BLOCK_MAPPINGS) == 0 &&
+                   !pud_table(old_pud)) {
                        WARN_ON(!pud_set_huge(pudp, phys, prot));
 
                        /*