Message ID | 20240401152032.4284-3-manali.shukla@amd.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add a test case for KVM_X86_DISABLE_EXIT | expand |
On Mon, Apr 01, 2024, Manali Shukla wrote: > Currently, all the VMs are created with in-kernel APIC support in KVM > selftests because KVM_CREATE_IRQCHIP ioctl is called by default from > kvm_arch_vm_post_create(). > > Carve out space in the @shape passed to the various VM creation helpers to > allow using the shape to control creation of a VM without in-kernel APIC > support or with in-kernel APIC support. > > This is a preparatory patch to create a vm without in-kernel APIC support for > the KVM_X86_DISABLE_EXITS_HLT test. Ugh, when I suggested creating a VM without an in-kernel APIC as away to easily test that HLT doesn't exit, I wasn't thinking about the side effects of creating a runnable VM without an in-kernel APIC. The other downside is that practically no one uses a userspace local APIC these days, i.e. the selftest isn't a great representation of real world setups. Given that KVM already provides vcpu->stat.halt_exits, using a stats FD for verifying exiting behavior is probably a better option. The other check that could be added would be to verify that mp_state is always RUNNABLE (which is a bug/gap in KVM as migrating a vCPU that was halted in the guest won't resume in a halted state on the target).
Hi Sean, On 4/1/2024 10:45 PM, Sean Christopherson wrote: > On Mon, Apr 01, 2024, Manali Shukla wrote: >> Currently, all the VMs are created with in-kernel APIC support in KVM >> selftests because KVM_CREATE_IRQCHIP ioctl is called by default from >> kvm_arch_vm_post_create(). >> >> Carve out space in the @shape passed to the various VM creation helpers to >> allow using the shape to control creation of a VM without in-kernel APIC >> support or with in-kernel APIC support. >> >> This is a preparatory patch to create a vm without in-kernel APIC support for >> the KVM_X86_DISABLE_EXITS_HLT test. > > Ugh, when I suggested creating a VM without an in-kernel APIC as away to easily > test that HLT doesn't exit, I wasn't thinking about the side effects of creating > a runnable VM without an in-kernel APIC. The other downside is that practically > no one uses a userspace local APIC these days, i.e. the selftest isn't a great > representation of real world setups. > > Given that KVM already provides vcpu->stat.halt_exits, using a stats FD for > verifying exiting behavior is probably a better option. The other check that > could be added would be to verify that mp_state is always RUNNABLE (which is a > bug/gap in KVM as migrating a vCPU that was halted in the guest won't resume in > a halted state on the target). Sure. I will work on it. - Manali
diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 4a40b332115d..c94cfbdf0150 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -130,6 +130,7 @@ struct kvm_vm { * memslot. */ uint32_t memslots[NR_MEM_REGIONS]; + uint8_t flags; }; struct vcpu_reg_sublist { @@ -197,11 +198,14 @@ enum vm_guest_mode { NUM_VM_MODES, }; +#define NO_IRQCHIP 0x01 + struct vm_shape { uint32_t type; uint8_t mode; uint8_t subtype; - uint16_t padding; + uint8_t flags; + uint8_t padding; }; kvm_static_assert(sizeof(struct vm_shape) == sizeof(uint64_t)); @@ -218,6 +222,17 @@ kvm_static_assert(sizeof(struct vm_shape) == sizeof(uint64_t)); shape; \ }) +#define VM_SHAPE_FLAGS(__FLAGS) \ +({ \ + struct vm_shape shape = { \ + .mode = VM_MODE_DEFAULT, \ + .type = VM_TYPE_DEFAULT, \ + .flags = __FLAGS \ + }; \ + \ + shape; \ +}) + #if defined(__aarch64__) extern enum vm_guest_mode vm_mode_default; diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index adc51b0712ca..86546f603959 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -226,6 +226,7 @@ struct kvm_vm *____vm_create(struct vm_shape shape) vm->mode = shape.mode; vm->type = shape.type; vm->subtype = shape.subtype; + vm->flags = shape.flags; vm->pa_bits = vm_guest_mode_params[vm->mode].pa_bits; vm->va_bits = vm_guest_mode_params[vm->mode].va_bits; diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 49288fe10cd3..e5ca92feae67 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -574,7 +574,9 @@ static void vcpu_setup(struct kvm_vm *vm, struct kvm_vcpu *vcpu) void kvm_arch_vm_post_create(struct kvm_vm *vm) { - vm_create_irqchip(vm); + if (!(vm->flags & NO_IRQCHIP)) + vm_create_irqchip(vm); + sync_global_to_guest(vm, host_cpu_is_intel); sync_global_to_guest(vm, host_cpu_is_amd);
Currently, all the VMs are created with in-kernel APIC support in KVM selftests because KVM_CREATE_IRQCHIP ioctl is called by default from kvm_arch_vm_post_create(). Carve out space in the @shape passed to the various VM creation helpers to allow using the shape to control creation of a VM without in-kernel APIC support or with in-kernel APIC support. This is a preparatory patch to create a vm without in-kernel APIC support for the KVM_X86_DISABLE_EXITS_HLT test. Suggested-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Manali Shukla <manali.shukla@amd.com> --- .../selftests/kvm/include/kvm_util_base.h | 17 ++++++++++++++++- tools/testing/selftests/kvm/lib/kvm_util.c | 1 + .../selftests/kvm/lib/x86_64/processor.c | 4 +++- 3 files changed, 20 insertions(+), 2 deletions(-)