linux-stable/arch/arm64/mm
Mark Rutland b03c7fcc5e arm64: mm: fix VA-range sanity check
[ Upstream commit ab9b400809 ]

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:

  c1cc155261 ("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:

  14c127c957 ("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:

  77ad4ce693 ("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>
2023-07-27 08:56:47 +02:00
..
Makefile arm64: mm: move fixmap code to its own file 2023-04-11 18:55:28 +01:00
cache.S efi: arm64: enter with MMU and caches enabled 2023-01-24 11:51:08 +00:00
context.c arm64/sysreg: Standardise naming of ID_AA64MMFR0_EL1.ASIDBits 2022-09-09 10:59:02 +01:00
copypage.c arm64: Also reset KASAN tag if page is not PG_mte_tagged 2023-05-16 14:58:54 +01:00
dma-mapping.c Revert "Revert "arm64: dma: Drop cache invalidation from arch_dma_prep_coherent()"" 2023-03-30 16:23:03 +01:00
extable.c arm64: extable: cleanup redundant extable type EX_TYPE_FIXUP 2022-06-28 12:11:47 +01:00
fault.c kasan: use internal prototypes matching gcc-13 builtins 2023-07-23 13:53:54 +02:00
fixmap.c arm64: mm: always map fixmap at page granularity 2023-04-11 18:55:28 +01:00
flush.c mm: hugetlb_vmemmap: delete hugetlb_optimize_vmemmap_enabled() 2022-08-08 18:06:42 -07:00
hugetlbpage.c arm64: errata: Workaround possible Cortex-A715 [ESR|FAR]_ELx corruption 2023-01-06 17:14:55 +00:00
init.c arm64: kdump: defer the crashkernel reservation for platforms with no DMA memory zones 2023-04-11 19:24:46 +01:00
ioremap.c arm64: mm: Convert to GENERIC_IOREMAP 2022-06-27 12:22:31 +01:00
kasan_init.c arm64: mm: provide idmap pointer to cpu_replace_ttbr1() 2022-06-24 17:18:10 +01:00
mmap.c arm64/mm: move protection_map[] inside the platform 2022-07-17 17:14:37 -07:00
mmu.c arm64: mm: fix VA-range sanity check 2023-07-27 08:56:47 +02:00
mteswap.c arm64: mte: Lock a page for MTE tag initialisation 2022-11-29 09:26:07 +00:00
pageattr.c mm,kfence: decouple kfence from page granularity mapping judgement 2023-03-27 16:15:20 +01:00
pgd.c mm: consolidate pgtable_cache_init() and pgd_cache_init() 2019-09-24 15:54:09 -07:00
physaddr.c arm64: Do not pass tagged addresses to __is_lm_address() 2021-02-02 17:44:47 +00:00
proc.S arm64: kernel: remove SHF_WRITE|SHF_EXECINSTR from .idmap.text 2023-05-02 12:42:22 +01:00
ptdump.c arm64: add FIXADDR_TOT_{START,SIZE} 2023-04-11 18:55:28 +01:00
ptdump_debugfs.c arm64: Add __init section marker to some functions 2021-04-08 17:45:10 +01:00
trans_pgd-asm.S arm64: kexec: configure EL2 vectors for kexec 2021-10-01 13:31:00 +01:00
trans_pgd.c arm64: mm: avoid writable executable mappings in kexec/hibernate code 2022-05-17 09:32:45 +01:00