Commit 8cee5816 authored by Andrew Jones's avatar Andrew Jones Committed by Paolo Bonzini

kvm: selftests: aarch64: dirty_log_test: support greater than 40-bit IPAs

When KVM has KVM_CAP_ARM_VM_IPA_SIZE we can test with > 40-bit IPAs by
using the 'type' field of KVM_CREATE_VM.
Signed-off-by: default avatarAndrew Jones <drjones@redhat.com>
Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
parent cdbd2428
...@@ -216,12 +216,14 @@ static void vm_dirty_log_verify(unsigned long *bmap) ...@@ -216,12 +216,14 @@ static void vm_dirty_log_verify(unsigned long *bmap)
} }
static struct kvm_vm *create_vm(enum vm_guest_mode mode, uint32_t vcpuid, static struct kvm_vm *create_vm(enum vm_guest_mode mode, uint32_t vcpuid,
uint64_t extra_mem_pages, void *guest_code) uint64_t extra_mem_pages, void *guest_code,
unsigned long type)
{ {
struct kvm_vm *vm; struct kvm_vm *vm;
uint64_t extra_pg_pages = extra_mem_pages / 512 * 2; uint64_t extra_pg_pages = extra_mem_pages / 512 * 2;
vm = vm_create(mode, DEFAULT_GUEST_PHY_PAGES + extra_pg_pages, O_RDWR); vm = _vm_create(mode, DEFAULT_GUEST_PHY_PAGES + extra_pg_pages,
O_RDWR, type);
kvm_vm_elf_load(vm, program_invocation_name, 0, 0); kvm_vm_elf_load(vm, program_invocation_name, 0, 0);
#ifdef __x86_64__ #ifdef __x86_64__
vm_create_irqchip(vm); vm_create_irqchip(vm);
...@@ -238,6 +240,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations, ...@@ -238,6 +240,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
struct kvm_vm *vm; struct kvm_vm *vm;
uint64_t max_gfn; uint64_t max_gfn;
unsigned long *bmap; unsigned long *bmap;
unsigned long type = 0;
switch (mode) { switch (mode) {
case VM_MODE_P52V48_4K: case VM_MODE_P52V48_4K:
...@@ -248,6 +251,14 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations, ...@@ -248,6 +251,14 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
guest_pa_bits = 52; guest_pa_bits = 52;
guest_page_shift = 16; guest_page_shift = 16;
break; break;
case VM_MODE_P48V48_4K:
guest_pa_bits = 48;
guest_page_shift = 12;
break;
case VM_MODE_P48V48_64K:
guest_pa_bits = 48;
guest_page_shift = 16;
break;
case VM_MODE_P40V48_4K: case VM_MODE_P40V48_4K:
guest_pa_bits = 40; guest_pa_bits = 40;
guest_page_shift = 12; guest_page_shift = 12;
...@@ -270,6 +281,10 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations, ...@@ -270,6 +281,10 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
* bits we can change to 39. * bits we can change to 39.
*/ */
guest_pa_bits = 39; guest_pa_bits = 39;
#endif
#ifdef __aarch64__
if (guest_pa_bits != 40)
type = KVM_VM_TYPE_ARM_IPA_SIZE(guest_pa_bits);
#endif #endif
max_gfn = (1ul << (guest_pa_bits - guest_page_shift)) - 1; max_gfn = (1ul << (guest_pa_bits - guest_page_shift)) - 1;
guest_page_size = (1ul << guest_page_shift); guest_page_size = (1ul << guest_page_shift);
...@@ -291,7 +306,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations, ...@@ -291,7 +306,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
bmap = bitmap_alloc(host_num_pages); bmap = bitmap_alloc(host_num_pages);
host_bmap_track = bitmap_alloc(host_num_pages); host_bmap_track = bitmap_alloc(host_num_pages);
vm = create_vm(mode, VCPU_ID, guest_num_pages, guest_code); vm = create_vm(mode, VCPU_ID, guest_num_pages, guest_code, type);
#ifdef USE_CLEAR_DIRTY_LOG #ifdef USE_CLEAR_DIRTY_LOG
struct kvm_enable_cap cap = {}; struct kvm_enable_cap cap = {};
...@@ -408,7 +423,7 @@ int main(int argc, char *argv[]) ...@@ -408,7 +423,7 @@ int main(int argc, char *argv[])
unsigned long interval = TEST_HOST_LOOP_INTERVAL; unsigned long interval = TEST_HOST_LOOP_INTERVAL;
bool mode_selected = false; bool mode_selected = false;
uint64_t phys_offset = 0; uint64_t phys_offset = 0;
unsigned int mode; unsigned int mode, host_ipa_limit;
int opt, i; int opt, i;
#ifdef USE_CLEAR_DIRTY_LOG #ifdef USE_CLEAR_DIRTY_LOG
...@@ -424,6 +439,14 @@ int main(int argc, char *argv[]) ...@@ -424,6 +439,14 @@ int main(int argc, char *argv[])
#ifdef __aarch64__ #ifdef __aarch64__
vm_guest_mode_params_init(VM_MODE_P40V48_4K, true, true); vm_guest_mode_params_init(VM_MODE_P40V48_4K, true, true);
vm_guest_mode_params_init(VM_MODE_P40V48_64K, true, true); vm_guest_mode_params_init(VM_MODE_P40V48_64K, true, true);
host_ipa_limit = kvm_check_cap(KVM_CAP_ARM_VM_IPA_SIZE);
if (host_ipa_limit >= 52)
vm_guest_mode_params_init(VM_MODE_P52V48_64K, true, true);
if (host_ipa_limit >= 48) {
vm_guest_mode_params_init(VM_MODE_P48V48_4K, true, true);
vm_guest_mode_params_init(VM_MODE_P48V48_64K, true, true);
}
#endif #endif
while ((opt = getopt(argc, argv, "hi:I:p:m:")) != -1) { while ((opt = getopt(argc, argv, "hi:I:p:m:")) != -1) {
......
...@@ -56,6 +56,8 @@ int kvm_check_cap(long cap); ...@@ -56,6 +56,8 @@ int kvm_check_cap(long cap);
int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap); int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap);
struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm); struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm);
struct kvm_vm *_vm_create(enum vm_guest_mode mode, uint64_t phy_pages,
int perm, unsigned long type);
void kvm_vm_free(struct kvm_vm *vmp); void kvm_vm_free(struct kvm_vm *vmp);
void kvm_vm_restart(struct kvm_vm *vmp, int perm); void kvm_vm_restart(struct kvm_vm *vmp, int perm);
void kvm_vm_release(struct kvm_vm *vmp); void kvm_vm_release(struct kvm_vm *vmp);
......
...@@ -85,13 +85,13 @@ int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap) ...@@ -85,13 +85,13 @@ int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap)
return ret; return ret;
} }
static void vm_open(struct kvm_vm *vm, int perm) static void vm_open(struct kvm_vm *vm, int perm, unsigned long type)
{ {
vm->kvm_fd = open(KVM_DEV_PATH, perm); vm->kvm_fd = open(KVM_DEV_PATH, perm);
if (vm->kvm_fd < 0) if (vm->kvm_fd < 0)
exit(KSFT_SKIP); exit(KSFT_SKIP);
vm->fd = ioctl(vm->kvm_fd, KVM_CREATE_VM, NULL); vm->fd = ioctl(vm->kvm_fd, KVM_CREATE_VM, type);
TEST_ASSERT(vm->fd >= 0, "KVM_CREATE_VM ioctl failed, " TEST_ASSERT(vm->fd >= 0, "KVM_CREATE_VM ioctl failed, "
"rc: %i errno: %i", vm->fd, errno); "rc: %i errno: %i", vm->fd, errno);
} }
...@@ -126,7 +126,8 @@ _Static_assert(sizeof(vm_guest_mode_string)/sizeof(char *) == NUM_VM_MODES, ...@@ -126,7 +126,8 @@ _Static_assert(sizeof(vm_guest_mode_string)/sizeof(char *) == NUM_VM_MODES,
* descriptor to control the created VM is created with the permissions * descriptor to control the created VM is created with the permissions
* given by perm (e.g. O_RDWR). * given by perm (e.g. O_RDWR).
*/ */
struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) struct kvm_vm *_vm_create(enum vm_guest_mode mode, uint64_t phy_pages,
int perm, unsigned long type)
{ {
struct kvm_vm *vm; struct kvm_vm *vm;
int kvm_fd; int kvm_fd;
...@@ -135,7 +136,8 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) ...@@ -135,7 +136,8 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
TEST_ASSERT(vm != NULL, "Insufficient Memory"); TEST_ASSERT(vm != NULL, "Insufficient Memory");
vm->mode = mode; vm->mode = mode;
vm_open(vm, perm); vm->type = type;
vm_open(vm, perm, type);
/* Setup mode specific traits. */ /* Setup mode specific traits. */
switch (vm->mode) { switch (vm->mode) {
...@@ -205,6 +207,11 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) ...@@ -205,6 +207,11 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
return vm; return vm;
} }
struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
{
return _vm_create(mode, phy_pages, perm, 0);
}
/* /*
* VM Restart * VM Restart
* *
...@@ -222,7 +229,7 @@ void kvm_vm_restart(struct kvm_vm *vmp, int perm) ...@@ -222,7 +229,7 @@ void kvm_vm_restart(struct kvm_vm *vmp, int perm)
{ {
struct userspace_mem_region *region; struct userspace_mem_region *region;
vm_open(vmp, perm); vm_open(vmp, perm, vmp->type);
if (vmp->has_irqchip) if (vmp->has_irqchip)
vm_create_irqchip(vmp); vm_create_irqchip(vmp);
......
...@@ -44,6 +44,7 @@ struct vcpu { ...@@ -44,6 +44,7 @@ struct vcpu {
struct kvm_vm { struct kvm_vm {
int mode; int mode;
unsigned long type;
int kvm_fd; int kvm_fd;
int fd; int fd;
unsigned int pgtable_levels; unsigned int pgtable_levels;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment