riscv: Avoid passing invalid addresses to pmap_fault()
authorMark Johnston <markj@FreeBSD.org>
Thu, 28 Jul 2022 13:38:52 +0000 (09:38 -0400)
committerMark Johnston <markj@FreeBSD.org>
Thu, 28 Jul 2022 18:33:39 +0000 (14:33 -0400)
commit828ea49debe34fddf63cb648b9e57871a34158b6
tree1c7424fb83d5b9389e87578af2559ccd1ae362db
parent0c8ff61ee113b7c09c21565c20ff6c7eb728a554
riscv: Avoid passing invalid addresses to pmap_fault()

After the addition of SV48 support, VIRT_IS_VALID() did not exclude
addresses that are in the SV39 address space hole but not in the SV48
address space hole.  This can result in mishandling of accesses to that
range when in SV39 mode.

Fix the problem by modifying VIRT_IS_VALID() to use the runtime address
space bounds.  Then, if the address is invalid, and pcb_onfault is set,
give vm_fault_trap() a chance to veto the access instead of panicking.

PR: 265439
Reviewed by: jhb
Reported and tested by: Robert Morris <rtm@lcs.mit.edu>
Fixes: 31218f3209ac ("riscv: Add support for enabling SV48 mode")
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35952
sys/riscv/include/pmap.h
sys/riscv/include/vmparam.h
sys/riscv/riscv/pmap.c
sys/riscv/riscv/trap.c