* [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init
@ 2019-05-27 14:31 Andrew Jones
2019-05-27 14:31 ` [PATCH v2 1/4] kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots Andrew Jones
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Andrew Jones @ 2019-05-27 14:31 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, rkrcmar, thuth, peterx
aarch64 vcpu setup requires a vcpu init step that takes a kvm_vcpu_init
struct. So far we've just hard coded that to be one that requests no
features and always uses KVM_ARM_TARGET_GENERIC_V8 for the target. We
should have used the preferred target from the beginning, so we do that
now, and we also provide an API to unit tests to select a target of their
choosing and/or cpu features.
Switching to the preferred target fixes running on platforms that don't
like KVM_ARM_TARGET_GENERIC_V8. The new API will be made use of with
some coming unit tests.
v2:
- rename vm_vcpu_add_memslots to vm_vcpu_add_with_memslots
Andrew Jones (4):
kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots
kvm: selftests: introduce vm_vcpu_add
kvm: selftests: introduce aarch64_vcpu_setup
kvm: selftests: introduce aarch64_vcpu_add_default
.../selftests/kvm/include/aarch64/processor.h | 4 +++
.../testing/selftests/kvm/include/kvm_util.h | 5 +--
.../selftests/kvm/lib/aarch64/processor.c | 33 +++++++++++++++----
tools/testing/selftests/kvm/lib/kvm_util.c | 29 +++++++++++++---
.../selftests/kvm/lib/x86_64/processor.c | 2 +-
.../testing/selftests/kvm/x86_64/evmcs_test.c | 2 +-
.../kvm/x86_64/kvm_create_max_vcpus.c | 2 +-
tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +-
.../testing/selftests/kvm/x86_64/state_test.c | 2 +-
9 files changed, 63 insertions(+), 18 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 1/4] kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots
2019-05-27 14:31 [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Andrew Jones
@ 2019-05-27 14:31 ` Andrew Jones
2019-05-28 2:14 ` Peter Xu
2019-05-27 14:31 ` [PATCH v2 2/4] kvm: selftests: introduce vm_vcpu_add Andrew Jones
` (4 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Andrew Jones @ 2019-05-27 14:31 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, rkrcmar, thuth, peterx
This frees up the name vm_vcpu_add for another use.
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
tools/testing/selftests/kvm/include/kvm_util.h | 4 ++--
tools/testing/selftests/kvm/lib/aarch64/processor.c | 2 +-
tools/testing/selftests/kvm/lib/kvm_util.c | 13 ++++++++-----
tools/testing/selftests/kvm/lib/x86_64/processor.c | 2 +-
tools/testing/selftests/kvm/x86_64/evmcs_test.c | 2 +-
.../selftests/kvm/x86_64/kvm_create_max_vcpus.c | 2 +-
tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +-
tools/testing/selftests/kvm/x86_64/state_test.c | 2 +-
8 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index a5a4b28f14d8..a82f877ea163 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -88,8 +88,8 @@ int _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl,
void *arg);
void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);
void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags);
-void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
- int gdt_memslot);
+void vm_vcpu_add_with_memslots(struct kvm_vm *vm, uint32_t vcpuid,
+ int pgd_memslot, int gdt_memslot);
vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
uint32_t data_memslot, uint32_t pgd_memslot);
void virt_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr,
diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
index 19e667911496..16cba9480ad6 100644
--- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
+++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
@@ -243,7 +243,7 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
uint64_t stack_vaddr = vm_vaddr_alloc(vm, stack_size,
DEFAULT_ARM64_GUEST_STACK_VADDR_MIN, 0, 0);
- vm_vcpu_add(vm, vcpuid, 0, 0);
+ vm_vcpu_add_with_memslots(vm, vcpuid, 0, 0);
set_reg(vm, vcpuid, ARM64_CORE_REG(sp_el1), stack_vaddr + stack_size);
set_reg(vm, vcpuid, ARM64_CORE_REG(regs.pc), (uint64_t)guest_code);
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 633b22df46a4..98d664825aa7 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -754,21 +754,24 @@ static int vcpu_mmap_sz(void)
}
/*
- * VM VCPU Add
+ * VM VCPU Add with provided memslots
*
* Input Args:
* vm - Virtual Machine
* vcpuid - VCPU ID
+ * pgd_memslot - Memory region slot for new virtual translation tables
+ * gdt_memslot - Memory region slot for data pages
*
* Output Args: None
*
* Return: None
*
- * Creates and adds to the VM specified by vm and virtual CPU with
- * the ID given by vcpuid.
+ * Adds a virtual CPU to the VM specified by vm with the ID given by vcpuid
+ * and then sets it up with vcpu_setup() using the provided memslots for the
+ * MMU setup.
*/
-void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
- int gdt_memslot)
+void vm_vcpu_add_with_memslots(struct kvm_vm *vm, uint32_t vcpuid,
+ int pgd_memslot, int gdt_memslot)
{
struct vcpu *vcpu;
diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index 21f3040d90cb..6d00c48c36a5 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -656,7 +656,7 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
DEFAULT_GUEST_STACK_VADDR_MIN, 0, 0);
/* Create VCPU */
- vm_vcpu_add(vm, vcpuid, 0, 0);
+ vm_vcpu_add_with_memslots(vm, vcpuid, 0, 0);
/* Setup guest general purpose registers */
vcpu_regs_get(vm, vcpuid, ®s);
diff --git a/tools/testing/selftests/kvm/x86_64/evmcs_test.c b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
index b38260e29775..9d99368ce3ad 100644
--- a/tools/testing/selftests/kvm/x86_64/evmcs_test.c
+++ b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
/* Restore state in a new VM. */
kvm_vm_restart(vm, O_RDWR);
- vm_vcpu_add(vm, VCPU_ID, 0, 0);
+ vm_vcpu_add_with_memslots(vm, VCPU_ID, 0, 0);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
vcpu_load_state(vm, VCPU_ID, state);
run = vcpu_state(vm, VCPU_ID);
diff --git a/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c b/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
index 50e92996f918..453871e92572 100644
--- a/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
+++ b/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
@@ -34,7 +34,7 @@ void test_vcpu_creation(int first_vcpu_id, int num_vcpus)
int vcpu_id = first_vcpu_id + i;
/* This asserts that the vCPU was created. */
- vm_vcpu_add(vm, vcpu_id, 0, 0);
+ vm_vcpu_add_with_memslots(vm, vcpu_id, 0, 0);
}
kvm_vm_free(vm);
diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/selftests/kvm/x86_64/smm_test.c
index 4daf520bada1..ea2dfd509e8d 100644
--- a/tools/testing/selftests/kvm/x86_64/smm_test.c
+++ b/tools/testing/selftests/kvm/x86_64/smm_test.c
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
state = vcpu_save_state(vm, VCPU_ID);
kvm_vm_release(vm);
kvm_vm_restart(vm, O_RDWR);
- vm_vcpu_add(vm, VCPU_ID, 0, 0);
+ vm_vcpu_add_with_memslots(vm, VCPU_ID, 0, 0);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
vcpu_load_state(vm, VCPU_ID, state);
run = vcpu_state(vm, VCPU_ID);
diff --git a/tools/testing/selftests/kvm/x86_64/state_test.c b/tools/testing/selftests/kvm/x86_64/state_test.c
index 2a4121f4de01..256d91599525 100644
--- a/tools/testing/selftests/kvm/x86_64/state_test.c
+++ b/tools/testing/selftests/kvm/x86_64/state_test.c
@@ -177,7 +177,7 @@ int main(int argc, char *argv[])
/* Restore state in a new VM. */
kvm_vm_restart(vm, O_RDWR);
- vm_vcpu_add(vm, VCPU_ID, 0, 0);
+ vm_vcpu_add_with_memslots(vm, VCPU_ID, 0, 0);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
vcpu_load_state(vm, VCPU_ID, state);
run = vcpu_state(vm, VCPU_ID);
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/4] kvm: selftests: introduce vm_vcpu_add
2019-05-27 14:31 [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Andrew Jones
2019-05-27 14:31 ` [PATCH v2 1/4] kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots Andrew Jones
@ 2019-05-27 14:31 ` Andrew Jones
2019-05-28 2:14 ` Peter Xu
2019-05-27 14:31 ` [PATCH v2 3/4] kvm: selftests: introduce aarch64_vcpu_setup Andrew Jones
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Andrew Jones @ 2019-05-27 14:31 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, rkrcmar, thuth, peterx
vm_vcpu_add() just adds a vcpu to the vm, but doesn't do any
additional vcpu setup.
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
.../testing/selftests/kvm/include/kvm_util.h | 1 +
tools/testing/selftests/kvm/lib/kvm_util.c | 34 ++++++++++++++-----
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index a82f877ea163..d16fdaad0511 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -88,6 +88,7 @@ int _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl,
void *arg);
void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);
void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags);
+void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid);
void vm_vcpu_add_with_memslots(struct kvm_vm *vm, uint32_t vcpuid,
int pgd_memslot, int gdt_memslot);
vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 98d664825aa7..0ac1ee93a519 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -754,24 +754,20 @@ static int vcpu_mmap_sz(void)
}
/*
- * VM VCPU Add with provided memslots
+ * VM VCPU Add
*
* Input Args:
* vm - Virtual Machine
* vcpuid - VCPU ID
- * pgd_memslot - Memory region slot for new virtual translation tables
- * gdt_memslot - Memory region slot for data pages
*
* Output Args: None
*
* Return: None
*
- * Adds a virtual CPU to the VM specified by vm with the ID given by vcpuid
- * and then sets it up with vcpu_setup() using the provided memslots for the
- * MMU setup.
+ * Adds a virtual CPU to the VM specified by vm with the ID given by vcpuid.
+ * No additional VCPU setup is done.
*/
-void vm_vcpu_add_with_memslots(struct kvm_vm *vm, uint32_t vcpuid,
- int pgd_memslot, int gdt_memslot)
+void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid)
{
struct vcpu *vcpu;
@@ -805,7 +801,29 @@ void vm_vcpu_add_with_memslots(struct kvm_vm *vm, uint32_t vcpuid,
vm->vcpu_head->prev = vcpu;
vcpu->next = vm->vcpu_head;
vm->vcpu_head = vcpu;
+}
+/*
+ * VM VCPU Add with provided memslots
+ *
+ * Input Args:
+ * vm - Virtual Machine
+ * vcpuid - VCPU ID
+ * pgd_memslot - Memory region slot for new virtual translation tables
+ * gdt_memslot - Memory region slot for data pages
+ *
+ * Output Args: None
+ *
+ * Return: None
+ *
+ * Adds a virtual CPU to the VM specified by vm with the ID given by vcpuid
+ * and then sets it up with vcpu_setup() using the provided memslots for the
+ * MMU setup.
+ */
+void vm_vcpu_add_with_memslots(struct kvm_vm *vm, uint32_t vcpuid,
+ int pgd_memslot, int gdt_memslot)
+{
+ vm_vcpu_add(vm, vcpuid);
vcpu_setup(vm, vcpuid, pgd_memslot, gdt_memslot);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 3/4] kvm: selftests: introduce aarch64_vcpu_setup
2019-05-27 14:31 [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Andrew Jones
2019-05-27 14:31 ` [PATCH v2 1/4] kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots Andrew Jones
2019-05-27 14:31 ` [PATCH v2 2/4] kvm: selftests: introduce vm_vcpu_add Andrew Jones
@ 2019-05-27 14:31 ` Andrew Jones
2019-05-27 14:31 ` [PATCH v2 4/4] kvm: selftests: introduce aarch64_vcpu_add_default Andrew Jones
` (2 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Andrew Jones @ 2019-05-27 14:31 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, rkrcmar, thuth, peterx
This allows aarch64 tests to run on more targets, such as the Arm
simulator that doesn't like KVM_ARM_TARGET_GENERIC_V8. And it also
allows aarch64 tests to provide vcpu features in struct kvm_vcpu_init.
Additionally it drops the unused memslot parameters.
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
.../selftests/kvm/include/aarch64/processor.h | 2 ++
.../selftests/kvm/lib/aarch64/processor.c | 22 ++++++++++++++-----
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h
index 9ef2ab1a0c08..37f8129e1ea9 100644
--- a/tools/testing/selftests/kvm/include/aarch64/processor.h
+++ b/tools/testing/selftests/kvm/include/aarch64/processor.h
@@ -52,4 +52,6 @@ static inline void set_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint
vcpu_ioctl(vm, vcpuid, KVM_SET_ONE_REG, ®);
}
+void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *init);
+
#endif /* SELFTEST_KVM_PROCESSOR_H */
diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
index 16cba9480ad6..285d86a2b6c3 100644
--- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
+++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
@@ -249,14 +249,21 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
set_reg(vm, vcpuid, ARM64_CORE_REG(regs.pc), (uint64_t)guest_code);
}
-void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
+void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *init)
{
- struct kvm_vcpu_init init;
+ struct kvm_vcpu_init default_init = { .target = -1, };
uint64_t sctlr_el1, tcr_el1;
- memset(&init, 0, sizeof(init));
- init.target = KVM_ARM_TARGET_GENERIC_V8;
- vcpu_ioctl(vm, vcpuid, KVM_ARM_VCPU_INIT, &init);
+ if (!init)
+ init = &default_init;
+
+ if (init->target == -1) {
+ struct kvm_vcpu_init preferred;
+ vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &preferred);
+ init->target = preferred.target;
+ }
+
+ vcpu_ioctl(vm, vcpuid, KVM_ARM_VCPU_INIT, init);
/*
* Enable FP/ASIMD to avoid trapping when accessing Q0-Q15
@@ -306,6 +313,11 @@ void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
set_reg(vm, vcpuid, ARM64_SYS_REG(TTBR0_EL1), vm->pgd);
}
+void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
+{
+ aarch64_vcpu_setup(vm, vcpuid, NULL);
+}
+
void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent)
{
uint64_t pstate, pc;
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 4/4] kvm: selftests: introduce aarch64_vcpu_add_default
2019-05-27 14:31 [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Andrew Jones
` (2 preceding siblings ...)
2019-05-27 14:31 ` [PATCH v2 3/4] kvm: selftests: introduce aarch64_vcpu_setup Andrew Jones
@ 2019-05-27 14:31 ` Andrew Jones
2019-06-04 17:16 ` [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Paolo Bonzini
2019-06-04 17:17 ` Paolo Bonzini
5 siblings, 0 replies; 12+ messages in thread
From: Andrew Jones @ 2019-05-27 14:31 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, rkrcmar, thuth, peterx
This is the same as vm_vcpu_add_default, but it also takes a
kvm_vcpu_init struct pointer.
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
.../testing/selftests/kvm/include/aarch64/processor.h | 2 ++
tools/testing/selftests/kvm/lib/aarch64/processor.c | 11 +++++++++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h
index 37f8129e1ea9..b7fa0c8551db 100644
--- a/tools/testing/selftests/kvm/include/aarch64/processor.h
+++ b/tools/testing/selftests/kvm/include/aarch64/processor.h
@@ -53,5 +53,7 @@ static inline void set_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint
}
void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *init);
+void aarch64_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_vcpu_init *init, void *guest_code);
#endif /* SELFTEST_KVM_PROCESSOR_H */
diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
index 285d86a2b6c3..284dfd63b65b 100644
--- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
+++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
@@ -235,7 +235,8 @@ struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages,
return vm;
}
-void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
+void aarch64_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid,
+ struct kvm_vcpu_init *init, void *guest_code)
{
size_t stack_size = vm->page_size == 4096 ?
DEFAULT_STACK_PGS * vm->page_size :
@@ -243,12 +244,18 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
uint64_t stack_vaddr = vm_vaddr_alloc(vm, stack_size,
DEFAULT_ARM64_GUEST_STACK_VADDR_MIN, 0, 0);
- vm_vcpu_add_with_memslots(vm, vcpuid, 0, 0);
+ vm_vcpu_add(vm, vcpuid);
+ aarch64_vcpu_setup(vm, vcpuid, init);
set_reg(vm, vcpuid, ARM64_CORE_REG(sp_el1), stack_vaddr + stack_size);
set_reg(vm, vcpuid, ARM64_CORE_REG(regs.pc), (uint64_t)guest_code);
}
+void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
+{
+ aarch64_vcpu_add_default(vm, vcpuid, NULL, guest_code);
+}
+
void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *init)
{
struct kvm_vcpu_init default_init = { .target = -1, };
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/4] kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots
2019-05-27 14:31 ` [PATCH v2 1/4] kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots Andrew Jones
@ 2019-05-28 2:14 ` Peter Xu
0 siblings, 0 replies; 12+ messages in thread
From: Peter Xu @ 2019-05-28 2:14 UTC (permalink / raw)
To: Andrew Jones; +Cc: kvm, pbonzini, rkrcmar, thuth
On Mon, May 27, 2019 at 04:31:38PM +0200, Andrew Jones wrote:
> This frees up the name vm_vcpu_add for another use.
>
> Signed-off-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 2/4] kvm: selftests: introduce vm_vcpu_add
2019-05-27 14:31 ` [PATCH v2 2/4] kvm: selftests: introduce vm_vcpu_add Andrew Jones
@ 2019-05-28 2:14 ` Peter Xu
0 siblings, 0 replies; 12+ messages in thread
From: Peter Xu @ 2019-05-28 2:14 UTC (permalink / raw)
To: Andrew Jones; +Cc: kvm, pbonzini, rkrcmar, thuth
On Mon, May 27, 2019 at 04:31:39PM +0200, Andrew Jones wrote:
> vm_vcpu_add() just adds a vcpu to the vm, but doesn't do any
> additional vcpu setup.
>
> Signed-off-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init
2019-05-27 14:31 [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Andrew Jones
` (3 preceding siblings ...)
2019-05-27 14:31 ` [PATCH v2 4/4] kvm: selftests: introduce aarch64_vcpu_add_default Andrew Jones
@ 2019-06-04 17:16 ` Paolo Bonzini
2019-06-05 7:26 ` Peter Xu
2019-06-04 17:17 ` Paolo Bonzini
5 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2019-06-04 17:16 UTC (permalink / raw)
To: Andrew Jones, kvm; +Cc: rkrcmar, thuth, peterx
On 27/05/19 16:31, Andrew Jones wrote:
> aarch64 vcpu setup requires a vcpu init step that takes a kvm_vcpu_init
> struct. So far we've just hard coded that to be one that requests no
> features and always uses KVM_ARM_TARGET_GENERIC_V8 for the target. We
> should have used the preferred target from the beginning, so we do that
> now, and we also provide an API to unit tests to select a target of their
> choosing and/or cpu features.
>
> Switching to the preferred target fixes running on platforms that don't
> like KVM_ARM_TARGET_GENERIC_V8. The new API will be made use of with
> some coming unit tests.
The following can replace patches 1 and 2 and simplify the API, so
that aarch64 and x86_64 are more similar:
---------------- 8< -------------------
From: Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH 1/1] kvm: selftests: hide vcpu_setup in x86_64 code
This removes the processor-dependent arguments from vm_vcpu_add.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
tools/testing/selftests/kvm/include/kvm_util.h | 3 +--
tools/testing/selftests/kvm/lib/aarch64/processor.c | 2 +-
tools/testing/selftests/kvm/lib/kvm_util.c | 9 +++------
tools/testing/selftests/kvm/lib/kvm_util_internal.h | 2 --
tools/testing/selftests/kvm/lib/x86_64/processor.c | 5 +++--
tools/testing/selftests/kvm/x86_64/evmcs_test.c | 2 +-
tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c | 2 +-
tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +-
tools/testing/selftests/kvm/x86_64/state_test.c | 2 +-
9 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index a5a4b28f14d8..55de43a7bd54 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -88,8 +88,7 @@ int _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl,
void *arg);
void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);
void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags);
-void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
- int gdt_memslot);
+void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid);
vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
uint32_t data_memslot, uint32_t pgd_memslot);
void virt_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr,
diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
index 19e667911496..16cba9480ad6 100644
--- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
+++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
@@ -243,7 +243,7 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
uint64_t stack_vaddr = vm_vaddr_alloc(vm, stack_size,
DEFAULT_ARM64_GUEST_STACK_VADDR_MIN, 0, 0);
- vm_vcpu_add(vm, vcpuid, 0, 0);
+ vm_vcpu_add(vm, vcpuid);
set_reg(vm, vcpuid, ARM64_CORE_REG(sp_el1), stack_vaddr + stack_size);
set_reg(vm, vcpuid, ARM64_CORE_REG(regs.pc), (uint64_t)guest_code);
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 633b22df46a4..6634adc4052d 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -764,11 +764,10 @@ static int vcpu_mmap_sz(void)
*
* Return: None
*
- * Creates and adds to the VM specified by vm and virtual CPU with
- * the ID given by vcpuid.
+ * Adds a virtual CPU to the VM specified by vm with the ID given by vcpuid.
+ * No additional VCPU setup is done.
*/
-void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
- int gdt_memslot)
+void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid)
{
struct vcpu *vcpu;
@@ -802,8 +801,6 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
vm->vcpu_head->prev = vcpu;
vcpu->next = vm->vcpu_head;
vm->vcpu_head = vcpu;
-
- vcpu_setup(vm, vcpuid, pgd_memslot, gdt_memslot);
}
/*
diff --git a/tools/testing/selftests/kvm/lib/kvm_util_internal.h b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
index 4595e42c6e29..6171c92561f4 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util_internal.h
+++ b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
@@ -65,8 +65,6 @@ struct kvm_vm {
};
struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid);
-void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot,
- int gdt_memslot);
void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent);
void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent);
diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index 21f3040d90cb..11f22c562380 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -610,7 +610,7 @@ static void kvm_setup_tss_64bit(struct kvm_vm *vm, struct kvm_segment *segp,
kvm_seg_fill_gdt_64bit(vm, segp);
}
-void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
+static void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
{
struct kvm_sregs sregs;
@@ -656,7 +656,8 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
DEFAULT_GUEST_STACK_VADDR_MIN, 0, 0);
/* Create VCPU */
- vm_vcpu_add(vm, vcpuid, 0, 0);
+ vm_vcpu_add(vm, vcpuid);
+ vcpu_setup(vm, vcpuid, 0, 0);
/* Setup guest general purpose registers */
vcpu_regs_get(vm, vcpuid, ®s);
diff --git a/tools/testing/selftests/kvm/x86_64/evmcs_test.c b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
index b38260e29775..dbf82658f2ef 100644
--- a/tools/testing/selftests/kvm/x86_64/evmcs_test.c
+++ b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
/* Restore state in a new VM. */
kvm_vm_restart(vm, O_RDWR);
- vm_vcpu_add(vm, VCPU_ID, 0, 0);
+ vm_vcpu_add(vm, VCPU_ID);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
vcpu_load_state(vm, VCPU_ID, state);
run = vcpu_state(vm, VCPU_ID);
diff --git a/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c b/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
index 50e92996f918..e5d980547896 100644
--- a/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
+++ b/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
@@ -34,7 +34,7 @@ void test_vcpu_creation(int first_vcpu_id, int num_vcpus)
int vcpu_id = first_vcpu_id + i;
/* This asserts that the vCPU was created. */
- vm_vcpu_add(vm, vcpu_id, 0, 0);
+ vm_vcpu_add(vm, vcpu_id);
}
kvm_vm_free(vm);
diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/selftests/kvm/x86_64/smm_test.c
index 4daf520bada1..8c063646f2a0 100644
--- a/tools/testing/selftests/kvm/x86_64/smm_test.c
+++ b/tools/testing/selftests/kvm/x86_64/smm_test.c
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
state = vcpu_save_state(vm, VCPU_ID);
kvm_vm_release(vm);
kvm_vm_restart(vm, O_RDWR);
- vm_vcpu_add(vm, VCPU_ID, 0, 0);
+ vm_vcpu_add(vm, VCPU_ID);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
vcpu_load_state(vm, VCPU_ID, state);
run = vcpu_state(vm, VCPU_ID);
diff --git a/tools/testing/selftests/kvm/x86_64/state_test.c b/tools/testing/selftests/kvm/x86_64/state_test.c
index 2a4121f4de01..13545df46d8b 100644
--- a/tools/testing/selftests/kvm/x86_64/state_test.c
+++ b/tools/testing/selftests/kvm/x86_64/state_test.c
@@ -177,7 +177,7 @@ int main(int argc, char *argv[])
/* Restore state in a new VM. */
kvm_vm_restart(vm, O_RDWR);
- vm_vcpu_add(vm, VCPU_ID, 0, 0);
+ vm_vcpu_add(vm, VCPU_ID);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
vcpu_load_state(vm, VCPU_ID, state);
run = vcpu_state(vm, VCPU_ID);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init
2019-05-27 14:31 [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Andrew Jones
` (4 preceding siblings ...)
2019-06-04 17:16 ` [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Paolo Bonzini
@ 2019-06-04 17:17 ` Paolo Bonzini
2019-06-27 12:36 ` Andrew Jones
5 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2019-06-04 17:17 UTC (permalink / raw)
To: Andrew Jones, kvm; +Cc: rkrcmar, thuth, peterx
On 27/05/19 16:31, Andrew Jones wrote:
> aarch64 vcpu setup requires a vcpu init step that takes a kvm_vcpu_init
> struct. So far we've just hard coded that to be one that requests no
> features and always uses KVM_ARM_TARGET_GENERIC_V8 for the target. We
> should have used the preferred target from the beginning, so we do that
> now, and we also provide an API to unit tests to select a target of their
> choosing and/or cpu features.
>
> Switching to the preferred target fixes running on platforms that don't
> like KVM_ARM_TARGET_GENERIC_V8. The new API will be made use of with
> some coming unit tests.
>
> v2:
> - rename vm_vcpu_add_memslots to vm_vcpu_add_with_memslots
>
> Andrew Jones (4):
> kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots
> kvm: selftests: introduce vm_vcpu_add
> kvm: selftests: introduce aarch64_vcpu_setup
> kvm: selftests: introduce aarch64_vcpu_add_default
>
> .../selftests/kvm/include/aarch64/processor.h | 4 +++
> .../testing/selftests/kvm/include/kvm_util.h | 5 +--
> .../selftests/kvm/lib/aarch64/processor.c | 33 +++++++++++++++----
> tools/testing/selftests/kvm/lib/kvm_util.c | 29 +++++++++++++---
> .../selftests/kvm/lib/x86_64/processor.c | 2 +-
> .../testing/selftests/kvm/x86_64/evmcs_test.c | 2 +-
> .../kvm/x86_64/kvm_create_max_vcpus.c | 2 +-
> tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +-
> .../testing/selftests/kvm/x86_64/state_test.c | 2 +-
> 9 files changed, 63 insertions(+), 18 deletions(-)
>
Queued with my replacement for patches 1 and 2 (but please do review it).
Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init
2019-06-04 17:16 ` [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Paolo Bonzini
@ 2019-06-05 7:26 ` Peter Xu
2019-06-05 12:15 ` Paolo Bonzini
0 siblings, 1 reply; 12+ messages in thread
From: Peter Xu @ 2019-06-05 7:26 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Andrew Jones, kvm, rkrcmar, thuth
On Tue, Jun 04, 2019 at 07:16:34PM +0200, Paolo Bonzini wrote:
> On 27/05/19 16:31, Andrew Jones wrote:
> > aarch64 vcpu setup requires a vcpu init step that takes a kvm_vcpu_init
> > struct. So far we've just hard coded that to be one that requests no
> > features and always uses KVM_ARM_TARGET_GENERIC_V8 for the target. We
> > should have used the preferred target from the beginning, so we do that
> > now, and we also provide an API to unit tests to select a target of their
> > choosing and/or cpu features.
> >
> > Switching to the preferred target fixes running on platforms that don't
> > like KVM_ARM_TARGET_GENERIC_V8. The new API will be made use of with
> > some coming unit tests.
>
> The following can replace patches 1 and 2 and simplify the API, so
> that aarch64 and x86_64 are more similar:
>
> ---------------- 8< -------------------
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 1/1] kvm: selftests: hide vcpu_setup in x86_64 code
>
> This removes the processor-dependent arguments from vm_vcpu_add.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> tools/testing/selftests/kvm/include/kvm_util.h | 3 +--
> tools/testing/selftests/kvm/lib/aarch64/processor.c | 2 +-
> tools/testing/selftests/kvm/lib/kvm_util.c | 9 +++------
> tools/testing/selftests/kvm/lib/kvm_util_internal.h | 2 --
> tools/testing/selftests/kvm/lib/x86_64/processor.c | 5 +++--
> tools/testing/selftests/kvm/x86_64/evmcs_test.c | 2 +-
> tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c | 2 +-
> tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +-
> tools/testing/selftests/kvm/x86_64/state_test.c | 2 +-
> 9 files changed, 12 insertions(+), 17 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
> index a5a4b28f14d8..55de43a7bd54 100644
> --- a/tools/testing/selftests/kvm/include/kvm_util.h
> +++ b/tools/testing/selftests/kvm/include/kvm_util.h
> @@ -88,8 +88,7 @@ int _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl,
> void *arg);
> void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);
> void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags);
> -void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
> - int gdt_memslot);
> +void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid);
> vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
> uint32_t data_memslot, uint32_t pgd_memslot);
> void virt_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr,
> diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> index 19e667911496..16cba9480ad6 100644
> --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> @@ -243,7 +243,7 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
> uint64_t stack_vaddr = vm_vaddr_alloc(vm, stack_size,
> DEFAULT_ARM64_GUEST_STACK_VADDR_MIN, 0, 0);
>
> - vm_vcpu_add(vm, vcpuid, 0, 0);
> + vm_vcpu_add(vm, vcpuid);
Do we need a vcpu_setup() here?
There're functional changes below too but they seem all good but I'm
not sure about this one. I noticed that in kvm/queue patch 4 added
this with the new function by Drew so at last it should be fine, but
it might affect bisection a bit on ARM.
>
> set_reg(vm, vcpuid, ARM64_CORE_REG(sp_el1), stack_vaddr + stack_size);
> set_reg(vm, vcpuid, ARM64_CORE_REG(regs.pc), (uint64_t)guest_code);
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 633b22df46a4..6634adc4052d 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -764,11 +764,10 @@ static int vcpu_mmap_sz(void)
> *
> * Return: None
> *
> - * Creates and adds to the VM specified by vm and virtual CPU with
> - * the ID given by vcpuid.
> + * Adds a virtual CPU to the VM specified by vm with the ID given by vcpuid.
> + * No additional VCPU setup is done.
> */
> -void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
> - int gdt_memslot)
> +void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid)
> {
> struct vcpu *vcpu;
>
> @@ -802,8 +801,6 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot,
> vm->vcpu_head->prev = vcpu;
> vcpu->next = vm->vcpu_head;
> vm->vcpu_head = vcpu;
> -
> - vcpu_setup(vm, vcpuid, pgd_memslot, gdt_memslot);
> }
>
> /*
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util_internal.h b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
> index 4595e42c6e29..6171c92561f4 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util_internal.h
> +++ b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
> @@ -65,8 +65,6 @@ struct kvm_vm {
> };
>
> struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid);
> -void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot,
> - int gdt_memslot);
> void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
> void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent);
> void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent);
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> index 21f3040d90cb..11f22c562380 100644
> --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> @@ -610,7 +610,7 @@ static void kvm_setup_tss_64bit(struct kvm_vm *vm, struct kvm_segment *segp,
> kvm_seg_fill_gdt_64bit(vm, segp);
> }
>
> -void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
> +static void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot)
> {
> struct kvm_sregs sregs;
>
> @@ -656,7 +656,8 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
> DEFAULT_GUEST_STACK_VADDR_MIN, 0, 0);
>
> /* Create VCPU */
> - vm_vcpu_add(vm, vcpuid, 0, 0);
> + vm_vcpu_add(vm, vcpuid);
> + vcpu_setup(vm, vcpuid, 0, 0);
>
> /* Setup guest general purpose registers */
> vcpu_regs_get(vm, vcpuid, ®s);
> diff --git a/tools/testing/selftests/kvm/x86_64/evmcs_test.c b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
> index b38260e29775..dbf82658f2ef 100644
> --- a/tools/testing/selftests/kvm/x86_64/evmcs_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
> @@ -144,7 +144,7 @@ int main(int argc, char *argv[])
>
> /* Restore state in a new VM. */
> kvm_vm_restart(vm, O_RDWR);
> - vm_vcpu_add(vm, VCPU_ID, 0, 0);
> + vm_vcpu_add(vm, VCPU_ID);
> vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
> vcpu_load_state(vm, VCPU_ID, state);
> run = vcpu_state(vm, VCPU_ID);
> diff --git a/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c b/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
> index 50e92996f918..e5d980547896 100644
> --- a/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
> +++ b/tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
> @@ -34,7 +34,7 @@ void test_vcpu_creation(int first_vcpu_id, int num_vcpus)
> int vcpu_id = first_vcpu_id + i;
>
> /* This asserts that the vCPU was created. */
> - vm_vcpu_add(vm, vcpu_id, 0, 0);
> + vm_vcpu_add(vm, vcpu_id);
> }
>
> kvm_vm_free(vm);
> diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/selftests/kvm/x86_64/smm_test.c
> index 4daf520bada1..8c063646f2a0 100644
> --- a/tools/testing/selftests/kvm/x86_64/smm_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/smm_test.c
> @@ -144,7 +144,7 @@ int main(int argc, char *argv[])
> state = vcpu_save_state(vm, VCPU_ID);
> kvm_vm_release(vm);
> kvm_vm_restart(vm, O_RDWR);
> - vm_vcpu_add(vm, VCPU_ID, 0, 0);
> + vm_vcpu_add(vm, VCPU_ID);
> vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
> vcpu_load_state(vm, VCPU_ID, state);
> run = vcpu_state(vm, VCPU_ID);
> diff --git a/tools/testing/selftests/kvm/x86_64/state_test.c b/tools/testing/selftests/kvm/x86_64/state_test.c
> index 2a4121f4de01..13545df46d8b 100644
> --- a/tools/testing/selftests/kvm/x86_64/state_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/state_test.c
> @@ -177,7 +177,7 @@ int main(int argc, char *argv[])
>
> /* Restore state in a new VM. */
> kvm_vm_restart(vm, O_RDWR);
> - vm_vcpu_add(vm, VCPU_ID, 0, 0);
> + vm_vcpu_add(vm, VCPU_ID);
> vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
> vcpu_load_state(vm, VCPU_ID, state);
> run = vcpu_state(vm, VCPU_ID);
> --
> 1.8.3.1
>
Regards,
--
Peter Xu
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init
2019-06-05 7:26 ` Peter Xu
@ 2019-06-05 12:15 ` Paolo Bonzini
0 siblings, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2019-06-05 12:15 UTC (permalink / raw)
To: Peter Xu; +Cc: Andrew Jones, kvm, rkrcmar, thuth
On 05/06/19 09:26, Peter Xu wrote:
> Do we need a vcpu_setup() here?
>
> There're functional changes below too but they seem all good but I'm
> not sure about this one. I noticed that in kvm/queue patch 4 added
> this with the new function by Drew so at last it should be fine, but
> it might affect bisection a bit on ARM.
Yes, I'll fix this and post a tested version.
Paolo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init
2019-06-04 17:17 ` Paolo Bonzini
@ 2019-06-27 12:36 ` Andrew Jones
0 siblings, 0 replies; 12+ messages in thread
From: Andrew Jones @ 2019-06-27 12:36 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm, rkrcmar, thuth, peterx
On Tue, Jun 04, 2019 at 07:17:23PM +0200, Paolo Bonzini wrote:
> On 27/05/19 16:31, Andrew Jones wrote:
> > aarch64 vcpu setup requires a vcpu init step that takes a kvm_vcpu_init
> > struct. So far we've just hard coded that to be one that requests no
> > features and always uses KVM_ARM_TARGET_GENERIC_V8 for the target. We
> > should have used the preferred target from the beginning, so we do that
> > now, and we also provide an API to unit tests to select a target of their
> > choosing and/or cpu features.
> >
> > Switching to the preferred target fixes running on platforms that don't
> > like KVM_ARM_TARGET_GENERIC_V8. The new API will be made use of with
> > some coming unit tests.
> >
> > v2:
> > - rename vm_vcpu_add_memslots to vm_vcpu_add_with_memslots
> >
> > Andrew Jones (4):
> > kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots
> > kvm: selftests: introduce vm_vcpu_add
> > kvm: selftests: introduce aarch64_vcpu_setup
> > kvm: selftests: introduce aarch64_vcpu_add_default
> >
> > .../selftests/kvm/include/aarch64/processor.h | 4 +++
> > .../testing/selftests/kvm/include/kvm_util.h | 5 +--
> > .../selftests/kvm/lib/aarch64/processor.c | 33 +++++++++++++++----
> > tools/testing/selftests/kvm/lib/kvm_util.c | 29 +++++++++++++---
> > .../selftests/kvm/lib/x86_64/processor.c | 2 +-
> > .../testing/selftests/kvm/x86_64/evmcs_test.c | 2 +-
> > .../kvm/x86_64/kvm_create_max_vcpus.c | 2 +-
> > tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +-
> > .../testing/selftests/kvm/x86_64/state_test.c | 2 +-
> > 9 files changed, 63 insertions(+), 18 deletions(-)
> >
>
> Queued with my replacement for patches 1 and 2 (but please do review it).
>
Sorry I forgot to follow up on this until now. I've reviewed tested the
commits on kvm/queue. LGTM.
Thanks,
drew
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2019-06-27 12:36 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-27 14:31 [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Andrew Jones
2019-05-27 14:31 ` [PATCH v2 1/4] kvm: selftests: rename vm_vcpu_add to vm_vcpu_add_with_memslots Andrew Jones
2019-05-28 2:14 ` Peter Xu
2019-05-27 14:31 ` [PATCH v2 2/4] kvm: selftests: introduce vm_vcpu_add Andrew Jones
2019-05-28 2:14 ` Peter Xu
2019-05-27 14:31 ` [PATCH v2 3/4] kvm: selftests: introduce aarch64_vcpu_setup Andrew Jones
2019-05-27 14:31 ` [PATCH v2 4/4] kvm: selftests: introduce aarch64_vcpu_add_default Andrew Jones
2019-06-04 17:16 ` [PATCH v2 0/4] kvm: selftests: aarch64: use struct kvm_vcpu_init Paolo Bonzini
2019-06-05 7:26 ` Peter Xu
2019-06-05 12:15 ` Paolo Bonzini
2019-06-04 17:17 ` Paolo Bonzini
2019-06-27 12:36 ` Andrew Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).