aarch64,hyp: Move PPTR_BASE down to 0x8000000000

On aarch64 in EL2, there aren't any addresses after 2^48 and so the
any kernel device untypeds that have very large physical addresses could
potentially move into an invalid address range when translated to a
Kernel window PPTR address when being stored in a cap slot. The kernel
in EL2 doesn't need to share its address space with user level and so we
can make the kernel window start low enough that we can't get overflows.
We start from the second entry in the top level page table so that we
don't conflict with any setup code running in the lowest 512GiB of
virtual addresses.

Signed-off-by: Kent McLeod <kent@kry10.com>
This commit is contained in:
Kent McLeod 2021-09-24 16:47:37 +10:00 committed by Kent McLeod
parent 45dc26ded9
commit a94d90598f
2 changed files with 22 additions and 3 deletions

View file

@ -173,14 +173,14 @@
/* The base address in virtual memory to use for the 1:1 physical memory
* mapping */
#ifdef CONFIG_ARM_HYPERVISOR_SUPPORT
#define PPTR_BASE UL_CONST(0x0000ff8000000000)
#define PPTR_BASE UL_CONST(0x0000008000000000)
#else
#define PPTR_BASE UL_CONST(0xffffff8000000000)
#endif
/* Top of the physical memory window */
#ifdef CONFIG_ARM_HYPERVISOR_SUPPORT
#define PPTR_TOP UL_CONST(0x0000ffffc0000000)
#define PPTR_TOP UL_CONST(0x000000ffc0000000)
#else
#define PPTR_TOP UL_CONST(0xffffffffc0000000)
#endif
@ -194,7 +194,7 @@
/* This is a page table mapping at the end of the virtual address space
* to map objects with 4KiB pages rather than 4MiB large pages. */
#ifdef CONFIG_ARM_HYPERVISOR_SUPPORT
#define KERNEL_PT_BASE UL_CONST(0x0000ffffffe00000)
#define KERNEL_PT_BASE UL_CONST(0x000000ffffe00000)
#else
#define KERNEL_PT_BASE UL_CONST(0xffffffffffe00000)
#endif
@ -206,3 +206,17 @@
/* The log buffer is placed before the device region */
#define KS_LOG_PPTR (KDEV_BASE - UL_CONST(0x200000))
/* All PPTR addresses must be canonical to be able to be stored in caps or objects.
Check that all UTs that are created will have valid address in the PPTR space.
For non-hyp, PPTR_BASE is in the top part of the address space and device untyped
addresses are allowed to be large enough to overflow and be in the bottom half of
the address space. However, when the kernel is in EL2 it is not possible to safely
overflow without going into address ranges that are non-canonical. These static
asserts check that the kernel config won't lead to UTs being created that aren't
representable. */
#ifndef __ASSEMBLER__
compile_assert(ut_max_less_than_cannonical, CONFIG_PADDR_USER_DEVICE_TOP <= BIT(47));
#ifdef CONFIG_ARM_HYPERVISOR_SUPPORT
compile_assert(ut_max_is_cannonical, (PPTR_BASE + CONFIG_PADDR_USER_DEVICE_TOP) <= BIT(48));
#endif
#endif

View file

@ -240,8 +240,13 @@ BOOT_CODE void map_kernel_window(void)
pptr_t vaddr;
word_t idx;
#ifdef CONFIG_ARM_HYPERVISOR_SUPPORT
/* verify that the kernel window as at the second entry of the PGD */
assert(GET_PGD_INDEX(PPTR_BASE) == 1);
#else
/* verify that the kernel window as at the last entry of the PGD */
assert(GET_PGD_INDEX(PPTR_BASE) == BIT(PGD_INDEX_BITS) - 1);
#endif
assert(IS_ALIGNED(PPTR_BASE, seL4_LargePageBits));
/* verify that the kernel device window is 1gb aligned and 1gb in size */
assert(GET_PUD_INDEX(PPTR_TOP) == BIT(PUD_INDEX_BITS) - 1);