It's always a bug to call remap_range with an unaligned address and it's
the responsibility of the callers (whether it's an ELF parser or code
walking reserved memory entries) to ensure that this doesn't happen.

We enforce this on ARM32, but don't yet on ARM64, so have it follow
suit and have both do the enforcement directly after pr_debug_remap():
That way, a developer enabling debug ouptut can easily see what was
last attempted before the BUG().

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 arch/arm/cpu/mmu_32.c | 6 +++---
 arch/arm/cpu/mmu_64.c | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/mmu_32.c b/arch/arm/cpu/mmu_32.c
index 912d14e8cf82..62e6e785f07c 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -350,14 +350,14 @@ static void __arch_remap_range(void *_virt_addr, 
phys_addr_t phys_addr, size_t s
        u32 pte_flags, pmd_flags;
        uint32_t *ttb = get_ttb();
 
-       BUG_ON(!IS_ALIGNED(virt_addr, PAGE_SIZE));
-       BUG_ON(!IS_ALIGNED(phys_addr, PAGE_SIZE));
-
        pte_flags = get_pte_flags(map_type);
        pmd_flags = pte_flags_to_pmd(pte_flags);
 
        pr_debug_remap(virt_addr, phys_addr, size, map_type);
 
+       BUG_ON(!IS_ALIGNED(virt_addr, PAGE_SIZE));
+       BUG_ON(!IS_ALIGNED(phys_addr, PAGE_SIZE));
+
        size = PAGE_ALIGN(size);
        if (!size)
                return;
diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
index 56c6a21f2b2a..8bbaf04e7fad 100644
--- a/arch/arm/cpu/mmu_64.c
+++ b/arch/arm/cpu/mmu_64.c
@@ -214,6 +214,9 @@ static int __arch_remap_range(uint64_t virt, uint64_t phys, 
uint64_t size,
 
        pr_debug_remap(addr, phys, size, map_type);
 
+       BUG_ON(!IS_ALIGNED(virt, PAGE_SIZE));
+       BUG_ON(!IS_ALIGNED(phys, PAGE_SIZE));
+
        attr &= ~PTE_TYPE_MASK;
 
        size = PAGE_ALIGN(size);
-- 
2.47.3


Reply via email to