[PATCH] arm64: mm: fix VA-range sanity check

Russell King (Oracle) linux at armlinux.org.uk
Thu Jun 15 04:23:07 PDT 2023


On Thu, Jun 15, 2023 at 11:26:28AM +0100, Mark Rutland wrote:
> Both create_mapping_noalloc() and update_mapping_prot() sanity-check the
> 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:
> 
>   c1cc1552616d0f35 ("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:
> 
>   14c127c957c1c607 ("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:
> 
>   77ad4ce69321abbe ("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 at arm.com>
> Cc: Catalin Marinas <catalin.marinas at arm.com>
> Cc: Russell King <linux at armlinux.org.uk>
> Cc: Steve Capper <steve.capper at arm.com>
> Cc: Will Deacon <will at kernel.org>

This simplifies the second of the kernel text replication patches!

Reviewed-by: Russell King (Oracle) <rmk+kernel at armlinux.org.uk>

Thanks!

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!



More information about the linux-arm-kernel mailing list