KVM: arm64: selftests: Align VA space allocator with TTBR0
An interesting feature of the Arm architecture is that the stage-1 MMU supports two distinct VA regions, controlled by TTBR{0,1}_EL1. As KVM selftests on arm64 only uses TTBR0_EL1, the VA space is constrained to [0, 2^(va_bits-1)). This is different from other architectures that allow for addressing low and high regions of the VA space from a single page table. KVM selftests' VA space allocator presumes the valid address range is split between low and high memory based the MSB, which of course is a poor match for arm64's TTBR0 region. Allow architectures to override the default VA space layout. Make use of the override to align vpages_valid with the behavior of TTBR0 on arm64. Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Message-Id: <20221207214809.489070-4-oliver.upton@linux.dev> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
eb5618911a
commit
e8b9a055fa
|
@ -408,6 +408,7 @@ void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags);
|
|||
void vm_mem_region_move(struct kvm_vm *vm, uint32_t slot, uint64_t new_gpa);
|
||||
void vm_mem_region_delete(struct kvm_vm *vm, uint32_t slot);
|
||||
struct kvm_vcpu *__vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id);
|
||||
void vm_populate_vaddr_bitmap(struct kvm_vm *vm);
|
||||
vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min);
|
||||
vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min);
|
||||
vm_vaddr_t __vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
|
||||
|
|
|
@ -541,3 +541,13 @@ void kvm_selftest_arch_init(void)
|
|||
*/
|
||||
guest_modes_append_default();
|
||||
}
|
||||
|
||||
void vm_vaddr_populate_bitmap(struct kvm_vm *vm)
|
||||
{
|
||||
/*
|
||||
* arm64 selftests use only TTBR0_EL1, meaning that the valid VA space
|
||||
* is [0, 2^(64 - TCR_EL1.T0SZ)).
|
||||
*/
|
||||
sparsebit_set_num(vm->vpages_valid, 0,
|
||||
(1ULL << vm->va_bits) >> vm->page_shift);
|
||||
}
|
||||
|
|
|
@ -186,6 +186,15 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = {
|
|||
_Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
|
||||
"Missing new mode params?");
|
||||
|
||||
__weak void vm_vaddr_populate_bitmap(struct kvm_vm *vm)
|
||||
{
|
||||
sparsebit_set_num(vm->vpages_valid,
|
||||
0, (1ULL << (vm->va_bits - 1)) >> vm->page_shift);
|
||||
sparsebit_set_num(vm->vpages_valid,
|
||||
(~((1ULL << (vm->va_bits - 1)) - 1)) >> vm->page_shift,
|
||||
(1ULL << (vm->va_bits - 1)) >> vm->page_shift);
|
||||
}
|
||||
|
||||
struct kvm_vm *____vm_create(enum vm_guest_mode mode)
|
||||
{
|
||||
struct kvm_vm *vm;
|
||||
|
@ -274,11 +283,7 @@ struct kvm_vm *____vm_create(enum vm_guest_mode mode)
|
|||
|
||||
/* Limit to VA-bit canonical virtual addresses. */
|
||||
vm->vpages_valid = sparsebit_alloc();
|
||||
sparsebit_set_num(vm->vpages_valid,
|
||||
0, (1ULL << (vm->va_bits - 1)) >> vm->page_shift);
|
||||
sparsebit_set_num(vm->vpages_valid,
|
||||
(~((1ULL << (vm->va_bits - 1)) - 1)) >> vm->page_shift,
|
||||
(1ULL << (vm->va_bits - 1)) >> vm->page_shift);
|
||||
vm_vaddr_populate_bitmap(vm);
|
||||
|
||||
/* Limit physical addresses to PA-bits. */
|
||||
vm->max_gfn = vm_compute_max_gfn(vm);
|
||||
|
|
Loading…
Reference in New Issue