Skip to content

Commit 5cac5a4

Browse files
mrutland-armroxanan1996
authored andcommitted
arm64: mm: fix VA-range sanity check
BugLink: https://bugs.launchpad.net/bugs/2060142 [ Upstream commit ab9b400 ] Both create_mapping_noalloc() and update_mapping_prot() sanity-check their 'virt' parameter, but the check itself doesn't make much sense. The condition used today appears to be a historical accident. The sanity-check condition: if ((virt >= PAGE_END) && (virt < VMALLOC_START)) { [ ... warning here ... ] return; } ... can only be true for the KASAN shadow region or the module region, and there's no reason to exclude these specifically for creating and updateing mappings. When arm64 support was first upstreamed in commit: c1cc155 ("arm64: MMU initialisation") ... the condition was: if (virt < VMALLOC_START) { [ ... warning here ... ] return; } At the time, VMALLOC_START was the lowest kernel address, and this was checking whether 'virt' would be translated via TTBR1. Subsequently in commit: 14c127c ("arm64: mm: Flip kernel VA space") ... the condition was changed to: if ((virt >= VA_START) && (virt < VMALLOC_START)) { [ ... warning here ... ] return; } This appear to have been a thinko. The commit moved the linear map to the bottom of the kernel address space, with VMALLOC_START being at the halfway point. The old condition would warn for changes to the linear map below this, and at the time VA_START was the end of the linear map. Subsequently we cleaned up the naming of VA_START in commit: 77ad4ce ("arm64: memory: rename VA_START to PAGE_END") ... keeping the erroneous condition as: if ((virt >= PAGE_END) && (virt < VMALLOC_START)) { [ ... warning here ... ] return; } Correct the condition to check against the start of the TTBR1 address space, which is currently PAGE_OFFSET. This simplifies the logic, and more clearly matches the "outside kernel range" message in the warning. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Steve Capper <steve.capper@arm.com> Cc: Will Deacon <will@kernel.org> Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Link: https://lore.kernel.org/r/20230615102628.1052103-1-mark.rutland@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
1 parent 81e9263 commit 5cac5a4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/arm64/mm/mmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static phys_addr_t pgd_pgtable_alloc(int shift)
435435
static void __init create_mapping_noalloc(phys_addr_t phys, unsigned long virt,
436436
phys_addr_t size, pgprot_t prot)
437437
{
438-
if ((virt >= PAGE_END) && (virt < VMALLOC_START)) {
438+
if (virt < PAGE_OFFSET) {
439439
pr_warn("BUG: not creating mapping for %pa at 0x%016lx - outside kernel range\n",
440440
&phys, virt);
441441
return;
@@ -462,7 +462,7 @@ void __init create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
462462
static void update_mapping_prot(phys_addr_t phys, unsigned long virt,
463463
phys_addr_t size, pgprot_t prot)
464464
{
465-
if ((virt >= PAGE_END) && (virt < VMALLOC_START)) {
465+
if (virt < PAGE_OFFSET) {
466466
pr_warn("BUG: not updating mapping for %pa at 0x%016lx - outside kernel range\n",
467467
&phys, virt);
468468
return;

0 commit comments

Comments
 (0)