KVM: s390: Add new reset vcpu API
Subsystems (5)
Janosch Frank
maintainerv10 cover KVM: s390: Add new reset vcpu API
Let's implement the remaining resets, namely the normal and clear reset to improve architectural compliance.
While we're at it, let's also start testing the new API. Those tests are not yet complete, but will be extended in the future.
v10:
* Cleared up the test patch and added strerror information
* Removed capability checks from irq test
* Fixed clobber patch
Christian Borntraeger (1):
KVM: s390: do not clobber registers during guest reset/store status
Janosch Frank (4):
KVM: s390: Cleanup initial cpu reset
KVM: s390: Add new reset vcpu API
selftests: KVM: Add fpu and one reg set/get library functions
selftests: KVM: s390x: Add reset tests
Pierre Morel (1):
selftests: KVM: testing the local IRQs resets
Documentation/virt/kvm/api.txt | 43 ++++ arch/s390/include/asm/kvm_host.h | 5 + arch/s390/kvm/kvm-s390.c | 92 +++++--- include/uapi/linux/kvm.h | 5 + tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/include/kvm_util.h | 6 + tools/testing/selftests/kvm/lib/kvm_util.c | 36 ++++ tools/testing/selftests/kvm/s390x/resets.c | 197 ++++++++++++++++++ 8 files changed, 351 insertions(+), 34 deletions(-) create mode 100644 tools/testing/selftests/kvm/s390x/resets.c
Signature · 1 line
2.20.1
Janosch Frank
maintainerPATCH v10 1/6 KVM: s390: do not clobber registers during guest reset/store status
From: Christian Borntraeger <[email protected]>
The initial CPU reset clobbers the userspace fpc and the store status ioctl clobbers the guest acrs + fpr. As these calls are only done via ioctl (and not via vcpu_run), no CPU context is loaded, so we can (and must) act directly on the sync regs, not on the thread context.
--- arch/s390/kvm/kvm-s390.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/s390/kvm/kvm-s390.c +2 -4
@@ -2860,9 +2860,7 @@ static void kvm_s390_vcpu_initial_reset(struct kvm_vcpu *vcpu) vcpu->arch.sie_block->gcr[14 ] =CR14_UNUSED_32 |CR14_UNUSED_33 |CR14_EXTERNAL_DAMAGE_SUBMASK ; -/* make sure the new fpc will be lazily loaded */ -save_fpu_regs (); - current->thread.fpu.fpc =0 ; + vcpu->run->s.regs.fpc =0 ; vcpu->arch.sie_block->gbea =1 ; vcpu->arch.sie_block->pp =0 ; vcpu->arch.sie_block->fpf &= ~FPF_BPBC ;
@@ -4351,7 +4349,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,switch (ioctl) {case KVM_S390_STORE_STATUS : idx =srcu_read_lock (&vcpu->kvm->srcu); - r =kvm_s390_vcpu_store_status (vcpu, arg); + r =kvm_s390_store_status_unloaded (vcpu, arg);srcu_read_unlock (&vcpu->kvm->srcu, idx);break ;case KVM_S390_SET_INITIAL_PSW : {
Signature · 1 line
2.20.1
Christian Borntraeger
AppliedRe: [PATCH v10 1/6] KVM: s390: do not clobber registers during guest reset/store status
Quoted 7 lines · Janosch Frank
From: Christian Borntraeger <[email protected]>
The initial CPU reset clobbers the userspace fpc and the store status ioctl clobbers the guest acrs + fpr. As these calls are only done via ioctl (and not via
vcpu_run), no CPU context is loaded, so we can (and must) act directly on the sync regs, not on the thread context.
Quoted 7 lines
Fixes e1788bb995be ("KVM: s390: handle floating point registers in the run ioctl not in vcpu_put/load")Fixes 31d8b8d41a7e ("KVM: s390: handle access registers in the run ioctl not in vcpu_put/load")Signed-off-by Christian Borntraeger <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Signed-off-by Janosch Frank <[email protected]>
Thanks applied.
Quoted 29 lines
--- arch/s390/kvm/kvm-s390.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)arch/s390/kvm/kvm-s390.c +2
-4@@ -2860,9 +2860,7 @@ static void kvm_s390_vcpu_initial_reset(struct kvm_vcpu *vcpu) vcpu->arch.sie_block->gcr[14 ] =CR14_UNUSED_32 |CR14_UNUSED_33 |CR14_EXTERNAL_DAMAGE_SUBMASK ; -/* make sure the new fpc will be lazily loaded */ -save_fpu_regs (); - current->thread.fpu.fpc =0 ; + vcpu->run->s.regs.fpc =0 ; vcpu->arch.sie_block->gbea =1 ; vcpu->arch.sie_block->pp =0 ; vcpu->arch.sie_block->fpf &= ~FPF_BPBC ;@@ -4351,7 +4349,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,switch (ioctl) {case KVM_S390_STORE_STATUS : idx =srcu_read_lock (&vcpu->kvm->srcu); - r =kvm_s390_vcpu_store_status (vcpu, arg); + r =kvm_s390_store_status_unloaded (vcpu, arg);srcu_read_unlock (&vcpu->kvm->srcu, idx);break ;case KVM_S390_SET_INITIAL_PSW : {
Janosch Frank
maintainerPATCH v10 2/6 KVM: s390: Cleanup initial cpu reset
In reply to Janosch FrankThe code seems to be quite old and uses lots of unneeded spaces for alignment, which doesn't really help with readability.
Let's:
* Get rid of the extra spaces
* Remove the ULs as they are not needed on 0s
* Define constants for the CR 0 and 14 initial values
* Use the sizeof of the gcr array to memset it to 0
--- arch/s390/include/asm/kvm_host.h | 5 +++++ arch/s390/kvm/kvm-s390.c | 18 +++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-)
arch/s390/include/asm/kvm_host.h +5 -0
@@ -122,6 +122,11 @@ struct mcck_volatile_info {__u32 reserved; }; +#define CR0_INITIAL_MASK (CR0_UNUSED_56 | CR0_INTERRUPT_KEY_SUBMASK | \ + CR0_MEASUREMENT_ALERT_SUBMASK) +#define CR14_INITIAL_MASK (CR14_UNUSED_32 | CR14_UNUSED_33 | \ + CR14_EXTERNAL_DAMAGE_SUBMASK) +#define CPUSTAT_STOPPED 0x80000000#define CPUSTAT_WAIT 0x10000000#define CPUSTAT_ECALL_PEND 0x08000000
arch/s390/kvm/kvm-s390.c +7 -11
@@ -2847,19 +2847,15 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)static void kvm_s390_vcpu_initial_reset (struct kvm_vcpu *vcpu) {/* this equals initial cpu reset in pop, but we don't switch to ESA */ - vcpu->arch.sie_block->gpsw.mask =0UL ; - vcpu->arch.sie_block->gpsw.addr =0UL ; + vcpu->arch.sie_block->gpsw.mask =0 ; + vcpu->arch.sie_block->gpsw.addr =0 ;kvm_s390_set_prefix (vcpu,0 );kvm_s390_set_cpu_timer (vcpu,0 ); - vcpu->arch.sie_block->ckc =0UL ; - vcpu->arch.sie_block->todpr =0 ; -memset (vcpu->arch.sie_block->gcr,0 ,16 *sizeof (__u64)); - vcpu->arch.sie_block->gcr[0 ] =CR0_UNUSED_56 | -CR0_INTERRUPT_KEY_SUBMASK | -CR0_MEASUREMENT_ALERT_SUBMASK ; - vcpu->arch.sie_block->gcr[14 ] =CR14_UNUSED_32 | -CR14_UNUSED_33 | -CR14_EXTERNAL_DAMAGE_SUBMASK ; + vcpu->arch.sie_block->ckc =0 ; + vcpu->arch.sie_block->todpr =0 ; +memset (vcpu->arch.sie_block->gcr,0 ,sizeof (vcpu->arch.sie_block->gcr)); + vcpu->arch.sie_block->gcr[0 ] =CR0_INITIAL_MASK ; + vcpu->arch.sie_block->gcr[14 ] =CR14_INITIAL_MASK ; vcpu->run->s.regs.fpc =0 ; vcpu->arch.sie_block->gbea =1 ; vcpu->arch.sie_block->pp =0 ;
Signature · 1 line
2.20.1
Christian Borntraeger
AppliedRe: [PATCH v10 2/6] KVM: s390: Cleanup initial cpu reset
Quoted 9 lines · Janosch Frank
The code seems to be quite old and uses lots of unneeded spaces for alignment, which doesn't really help with readability.
Let's:
* Get rid of the extra spaces
* Remove the ULs as they are not needed on 0s
* Define constants for the CR 0 and 14 initial values
* Use the sizeof of the gcr array to memset it to 0
Quoted 4 lines
Signed-off-by Janosch Frank <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Thomas Huth <[email protected]>
applied.
Quoted 53 lines
--- arch/s390/include/asm/kvm_host.h | 5 +++++ arch/s390/kvm/kvm-s390.c | 18 +++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-)arch/s390/include/asm/kvm_host.h +5
-0@@ -122,6 +122,11 @@ struct mcck_volatile_info {__u32 reserved; }; +#define CR0_INITIAL_MASK (CR0_UNUSED_56 | CR0_INTERRUPT_KEY_SUBMASK | \ + CR0_MEASUREMENT_ALERT_SUBMASK) +#define CR14_INITIAL_MASK (CR14_UNUSED_32 | CR14_UNUSED_33 | \ + CR14_EXTERNAL_DAMAGE_SUBMASK) +#define CPUSTAT_STOPPED 0x80000000#define CPUSTAT_WAIT 0x10000000#define CPUSTAT_ECALL_PEND 0x08000000arch/s390/kvm/kvm-s390.c +7
-11@@ -2847,19 +2847,15 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)static void kvm_s390_vcpu_initial_reset (struct kvm_vcpu *vcpu) {/* this equals initial cpu reset in pop, but we don't switch to ESA */ - vcpu->arch.sie_block->gpsw.mask =0UL ; - vcpu->arch.sie_block->gpsw.addr =0UL ; + vcpu->arch.sie_block->gpsw.mask =0 ; + vcpu->arch.sie_block->gpsw.addr =0 ;kvm_s390_set_prefix (vcpu,0 );kvm_s390_set_cpu_timer (vcpu,0 ); - vcpu->arch.sie_block->ckc =0UL ; - vcpu->arch.sie_block->todpr =0 ; -memset (vcpu->arch.sie_block->gcr,0 ,16 *sizeof (__u64)); - vcpu->arch.sie_block->gcr[0 ] =CR0_UNUSED_56 | -CR0_INTERRUPT_KEY_SUBMASK | -CR0_MEASUREMENT_ALERT_SUBMASK ; - vcpu->arch.sie_block->gcr[14 ] =CR14_UNUSED_32 | -CR14_UNUSED_33 | -CR14_EXTERNAL_DAMAGE_SUBMASK ; + vcpu->arch.sie_block->ckc =0 ; + vcpu->arch.sie_block->todpr =0 ; +memset (vcpu->arch.sie_block->gcr,0 ,sizeof (vcpu->arch.sie_block->gcr)); + vcpu->arch.sie_block->gcr[0 ] =CR0_INITIAL_MASK ; + vcpu->arch.sie_block->gcr[14 ] =CR14_INITIAL_MASK ; vcpu->run->s.regs.fpc =0 ; vcpu->arch.sie_block->gbea =1 ; vcpu->arch.sie_block->pp =0 ;
Janosch Frank
maintainerPATCH v10 3/6 KVM: s390: Add new reset vcpu API
In reply to Janosch FrankThe architecture states that we need to reset local IRQs for all CPU resets. Because the old reset interface did not support the normal CPU reset we never did that on a normal reset.
Let's implement an interface for the missing normal and clear resets and reset all local IRQs, registers and control structures as stated in the architecture.
Userspace might already reset the registers via the vcpu run struct, but as we need the interface for the interrupt clearing part anyway, we implement the resets fully and don't rely on userspace to reset the rest.
--- Documentation/virt/kvm/api.txt | 43 +++++++++++++++++ arch/s390/kvm/kvm-s390.c | 84 +++++++++++++++++++++++----------- include/uapi/linux/kvm.h | 5 ++ 3 files changed, 105 insertions(+), 27 deletions(-)
Documentation/virt/kvm/api.txt +43 -0
@@ -4168,6 +4168,42 @@ This ioctl issues an ultravisor call to terminate the secure guest, unpins the VPA pages and releases all the device pages that are used to track the secure pages by hypervisor. +4.122 KVM_S390_NORMAL_RESET + +Capability: KVM_CAP_S390_VCPU_RESETS +Architectures: s390 +Type: vcpu ioctl +Parameters: none +Returns: 0 + +This ioctl resets VCPU registers and control structures according to +the cpu reset definition in the POP (Principles Of Operation). + +4.123 KVM_S390_INITIAL_RESET + +Capability: none +Architectures: s390 +Type: vcpu ioctl +Parameters: none +Returns: 0 + +This ioctl resets VCPU registers and control structures according to +the initial cpu reset definition in the POP. However, the cpu is not +put into ESA mode. This reset is a superset of the normal reset. + +4.124 KVM_S390_CLEAR_RESET + +Capability: KVM_CAP_S390_VCPU_RESETS +Architectures: s390 +Type: vcpu ioctl +Parameters: none +Returns: 0 + +This ioctl resets VCPU registers and control structures according to +the clear cpu reset definition in the POP. However, the cpu is not put +into ESA mode. This reset is a superset of the initial reset. + + 5. The kvm_run structure ------------------------
@@ -5396,3 +5432,10 @@ handling by KVM (as some KVM hypercall may be mistakenly treated as TLB flush hypercalls by Hyper-V) so userspace should disable KVM identification in CPUID and only exposes Hyper-V identification. In this case, guest thinks it's running on Hyper-V and only use Hyper-V hypercalls. + +8.22 KVM_CAP_S390_VCPU_RESETS + +Architectures: s390 + +This capability indicates that the KVM_S390_NORMAL_RESET and +KVM_S390_CLEAR_RESET ioctls are available.
arch/s390/kvm/kvm-s390.c +57 -27
110 lines not on this page · raw message
include/uapi/linux/kvm.h +5 -0
@@ -1009,6 +1009,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_PPC_GUEST_DEBUG_SSTEP 176#define KVM_CAP_ARM_NISV_TO_USER 177#define KVM_CAP_ARM_INJECT_EXT_DABT 178 +#define KVM_CAP_S390_VCPU_RESETS 179#ifdef KVM_CAP_IRQ_ROUTING
@@ -1473,6 +1474,10 @@ struct kvm_enc_region {/* Available with KVM_CAP_ARM_SVE */ #define KVM_ARM_VCPU_FINALIZE _IOW(KVMIO, 0xc2, int) +/* Available with KVM_CAP_S390_VCPU_RESETS */ +#define KVM_S390_NORMAL_RESET _IO(KVMIO, 0xc3) +#define KVM_S390_CLEAR_RESET _IO(KVMIO, 0xc4) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
Signature · 1 line
2.20.1
Quoted 13 lines · Janosch Frank
The architecture states that we need to reset local IRQs for all CPU resets. Because the old reset interface did not support the normal CPU reset we never did that on a normal reset.
Let's implement an interface for the missing normal and clear resets and reset all local IRQs, registers and control structures as stated in the architecture.
Userspace might already reset the registers via the vcpu run struct, but as we need the interface for the interrupt clearing part anyway, we implement the resets fully and don't rely on userspace to reset the rest.
Quoted 8 lines
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Christian Borntraeger <[email protected]>--- Documentation/virt/kvm/api.txt | 43 +++++++++++++++++ arch/s390/kvm/kvm-s390.c | 84 +++++++++++++++++++++++----------- include/uapi/linux/kvm.h | 5 ++ 3 files changed, 105 insertions(+), 27 deletions(-)
Christian Borntraeger
AppliedQuoted 8 lines · Janosch Frank
The architecture states that we need to reset local IRQs for all CPU resets. Because the old reset interface did not support the normal CPU reset we never did that on a normal reset.
Let's implement an interface for the missing normal and clear resets and reset all local IRQs, registers and control structures as stated in the architecture.
Quoted 8 lines
Userspace might already reset the registers via the vcpu run struct, but as we need the interface for the interrupt clearing part anyway, we implement the resets fully and don't rely on userspace to reset the rest.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Christian Borntraeger <[email protected]>
thanks applied.
Janosch Frank
maintainerPATCH v10 4/6 selftests: KVM: Add fpu and one reg set/get library functions
In reply to Janosch FrankAdd library access to more registers.
--- .../testing/selftests/kvm/include/kvm_util.h | 6 ++++ tools/testing/selftests/kvm/lib/kvm_util.c | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+)
tools/testing/selftests/kvm/include/kvm_util.h +6 -0
@@ -125,6 +125,12 @@ void vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs);int _vcpu_sregs_set (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_sregs *sregs); +void vcpu_fpu_get (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_fpu *fpu); +void vcpu_fpu_set (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_fpu *fpu); +void vcpu_get_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg); +void vcpu_set_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg);#ifdef __KVM_HAVE_VCPU_EVENTSvoid vcpu_events_get (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_vcpu_events *events);
tools/testing/selftests/kvm/lib/kvm_util.c +36 -0
@@ -1373,6 +1373,42 @@ int _vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs)return ioctl (vcpu->fd,KVM_SET_SREGS , sregs); } +void vcpu_fpu_get (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_fpu *fpu) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_GET_FPU , fpu); +TEST_ASSERT (ret ==0 ,"KVM_GET_FPU failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_fpu_set (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_fpu *fpu) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_SET_FPU , fpu); +TEST_ASSERT (ret ==0 ,"KVM_SET_FPU failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_get_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_GET_ONE_REG , reg); +TEST_ASSERT (ret ==0 ,"KVM_GET_ONE_REG failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_set_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_SET_ONE_REG , reg); +TEST_ASSERT (ret ==0 ,"KVM_SET_ONE_REG failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} +/* * VCPU Ioctl *
Signature · 1 line
2.20.1
Re: [PATCH v10 4/6] selftests: KVM: Add fpu and one reg set/get library functions
Paolo,
are you ok with me taking this patch for my s390 pull request to you? Ideally still for 5.6?
Quoted 75 lines · Janosch Frank
Add library access to more registers.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>--- .../testing/selftests/kvm/include/kvm_util.h | 6 ++++ tools/testing/selftests/kvm/lib/kvm_util.c | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+)tools/testing/selftests/kvm/include/kvm_util.h +6
-0@@ -125,6 +125,12 @@ void vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs);int _vcpu_sregs_set (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_sregs *sregs); +void vcpu_fpu_get (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_fpu *fpu); +void vcpu_fpu_set (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_fpu *fpu); +void vcpu_get_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg); +void vcpu_set_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg);#ifdef __KVM_HAVE_VCPU_EVENTSvoid vcpu_events_get (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_vcpu_events *events);tools/testing/selftests/kvm/lib/kvm_util.c +36
-0@@ -1373,6 +1373,42 @@ int _vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs)return ioctl (vcpu->fd,KVM_SET_SREGS , sregs); } +void vcpu_fpu_get (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_fpu *fpu) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_GET_FPU , fpu); +TEST_ASSERT (ret ==0 ,"KVM_GET_FPU failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_fpu_set (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_fpu *fpu) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_SET_FPU , fpu); +TEST_ASSERT (ret ==0 ,"KVM_SET_FPU failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_get_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_GET_ONE_REG , reg); +TEST_ASSERT (ret ==0 ,"KVM_GET_ONE_REG failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_set_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_SET_ONE_REG , reg); +TEST_ASSERT (ret ==0 ,"KVM_SET_ONE_REG failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} +/* * VCPU Ioctl *
Paolo Bonzini
maintainerRe: [PATCH v10 4/6] selftests: KVM: Add fpu and one reg set/get library functions
Quoted 4 lines · Christian Borntraeger
Paolo,
are you ok with me taking this patch for my s390 pull request to you? Ideally still for 5.6?
Yes to both questions, of course.
Paolo
Quoted 77 lines · Janosch Frank
Quoted 75 lines
Add library access to more registers.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>--- .../testing/selftests/kvm/include/kvm_util.h | 6 ++++ tools/testing/selftests/kvm/lib/kvm_util.c | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+)tools/testing/selftests/kvm/include/kvm_util.h +6
-0@@ -125,6 +125,12 @@ void vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs);int _vcpu_sregs_set (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_sregs *sregs); +void vcpu_fpu_get (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_fpu *fpu); +void vcpu_fpu_set (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_fpu *fpu); +void vcpu_get_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg); +void vcpu_set_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg);#ifdef __KVM_HAVE_VCPU_EVENTSvoid vcpu_events_get (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_vcpu_events *events);tools/testing/selftests/kvm/lib/kvm_util.c +36
-0@@ -1373,6 +1373,42 @@ int _vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs)return ioctl (vcpu->fd,KVM_SET_SREGS , sregs); } +void vcpu_fpu_get (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_fpu *fpu) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_GET_FPU , fpu); +TEST_ASSERT (ret ==0 ,"KVM_GET_FPU failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_fpu_set (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_fpu *fpu) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_SET_FPU , fpu); +TEST_ASSERT (ret ==0 ,"KVM_SET_FPU failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_get_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_GET_ONE_REG , reg); +TEST_ASSERT (ret ==0 ,"KVM_GET_ONE_REG failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_set_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_SET_ONE_REG , reg); +TEST_ASSERT (ret ==0 ,"KVM_SET_ONE_REG failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} +/* * VCPU Ioctl *
Christian Borntraeger
AppliedRe: [PATCH v10 4/6] selftests: KVM: Add fpu and one reg set/get library functions
In reply to Janosch FrankQuoted 5 lines · Janosch Frank
Add library access to more registers.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>
thanks applied (assuming Paolos agreement)
Quoted 70 lines
--- .../testing/selftests/kvm/include/kvm_util.h | 6 ++++ tools/testing/selftests/kvm/lib/kvm_util.c | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+)tools/testing/selftests/kvm/include/kvm_util.h +6
-0@@ -125,6 +125,12 @@ void vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs);int _vcpu_sregs_set (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_sregs *sregs); +void vcpu_fpu_get (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_fpu *fpu); +void vcpu_fpu_set (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_fpu *fpu); +void vcpu_get_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg); +void vcpu_set_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg);#ifdef __KVM_HAVE_VCPU_EVENTSvoid vcpu_events_get (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_vcpu_events *events);tools/testing/selftests/kvm/lib/kvm_util.c +36
-0@@ -1373,6 +1373,42 @@ int _vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_sregs *sregs)return ioctl (vcpu->fd,KVM_SET_SREGS , sregs); } +void vcpu_fpu_get (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_fpu *fpu) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_GET_FPU , fpu); +TEST_ASSERT (ret ==0 ,"KVM_GET_FPU failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_fpu_set (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_fpu *fpu) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_SET_FPU , fpu); +TEST_ASSERT (ret ==0 ,"KVM_SET_FPU failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_get_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_GET_ONE_REG , reg); +TEST_ASSERT (ret ==0 ,"KVM_GET_ONE_REG failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} + +void vcpu_set_reg (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_one_reg *reg) +{ +int ret; + + ret =_vcpu_ioctl (vm, vcpuid,KVM_SET_ONE_REG , reg); +TEST_ASSERT (ret ==0 ,"KVM_SET_ONE_REG failed, rc: %i errno: %i (%s)" , + ret, errno,strerror (errno)); +} +/* * VCPU Ioctl *
Janosch Frank
maintainerPATCH v10 5/6 selftests: KVM: s390x: Add reset tests
In reply to Janosch FrankTest if the registers end up having the correct values after a normal, initial and clear reset.
--- tools/testing/selftests/kvm/Makefile | 1 + tools/testing/selftests/kvm/s390x/resets.c | 155 +++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 tools/testing/selftests/kvm/s390x/resets.c
tools/testing/selftests/kvm/Makefile +1 -0
@@ -36,6 +36,7 @@ TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus TEST_GEN_PROGS_s390x = s390x/memop TEST_GEN_PROGS_s390x += s390x/sync_regs_test +TEST_GEN_PROGS_s390x += s390x/resets TEST_GEN_PROGS_s390x += dirty_log_test TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
tools/testing/selftests/kvm/s390x/resets.c new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.20.1
Christian Borntraeger
AppliedRe: [PATCH v10 5/6] selftests: KVM: s390x: Add reset tests
Quoted 6 lines · Janosch Frank
Test if the registers end up having the correct values after a normal, initial and clear reset.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>
thanks applied.
Janosch Frank
maintainerPATCH v10 6/6 selftests: KVM: testing the local IRQs resets
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
Local IRQs are reset by a normal cpu reset. The initial cpu reset and the clear cpu reset, as superset of the normal reset, both clear the IRQs too.
Let's inject an interrupt to a vCPU before calling a reset and see if it is gone after the reset.
We choose to inject only an emergency interrupt at this point and can extend the test to other types of IRQs later.
--- tools/testing/selftests/kvm/s390x/resets.c | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+)
tools/testing/selftests/kvm/s390x/resets.c +42 -0
@@ -14,6 +14,9 @@#include "kvm_util.h" #define VCPU_ID 3 +#define LOCAL_IRQS 32 + +struct kvm_s390_irq buf[VCPU_ID +LOCAL_IRQS ];struct kvm_vm *vm;struct kvm_run *run;
@@ -53,6 +56,23 @@ static void test_one_reg(uint64_t id, uint64_t value)TEST_ASSERT (eval_reg == value,"value == %s" , value); } +static void assert_noirq (void ) +{ +struct kvm_s390_irq_state irq_state; +int irqs; + + irq_state.len =sizeof (buf); + irq_state.buf = (unsigned long )buf; + irqs =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_GET_IRQ_STATE , &irq_state); +/* +* irqs contains the number of retrieved interrupts. Any interrupt +* (notably, the emergency call interrupt we have injected) should +* be cleared by the resets, so this should be 0. +*/ +TEST_ASSERT (irqs >=0 ,"Could not fetch IRQs: errno %d\n" , errno); +TEST_ASSERT (!irqs,"IRQ pending" ); +} +static void assert_clear (void ) {struct kvm_sregs sregs;
@@ -94,6 +114,22 @@ static void assert_initial(void)static void assert_normal (void ) {test_one_reg (KVM_REG_S390_PFTOKEN ,KVM_S390_PFAULT_TOKEN_INVALID ); +assert_noirq (); +} + +static void inject_irq (int cpu_id) +{ +struct kvm_s390_irq_state irq_state; +struct kvm_s390_irq *irq = &buf[0 ]; +int irqs; + +/* Inject IRQ */ + irq_state.len =sizeof (struct kvm_s390_irq ); + irq_state.buf = (unsigned long )buf; + irq->type =KVM_S390_INT_EMERGENCY ; + irq->u.emerg.code = cpu_id; + irqs =_vcpu_ioctl (vm, cpu_id,KVM_S390_SET_IRQ_STATE , &irq_state); +TEST_ASSERT (irqs >=0 ,"Error injecting EMERGENCY IRQ errno %d\n" , errno); }static void test_normal (void )
@@ -106,6 +142,8 @@ static void test_normal(void)vcpu_run (vm,VCPU_ID ); +inject_irq (VCPU_ID ); +vcpu_ioctl (vm,VCPU_ID ,KVM_S390_NORMAL_RESET ,0 );assert_normal ();kvm_vm_free (vm);
@@ -120,6 +158,8 @@ static void test_initial(void)vcpu_run (vm,VCPU_ID ); +inject_irq (VCPU_ID ); +vcpu_ioctl (vm,VCPU_ID ,KVM_S390_INITIAL_RESET ,0 );assert_normal ();assert_initial ();
@@ -135,6 +175,8 @@ static void test_clear(void)vcpu_run (vm,VCPU_ID ); +inject_irq (VCPU_ID ); +vcpu_ioctl (vm,VCPU_ID ,KVM_S390_CLEAR_RESET ,0 );assert_normal ();assert_initial ();
Signature · 1 line
2.20.1
Re: [PATCH v10 6/6] selftests: KVM: testing the local IRQs resets
Quoted 6 lines · On Fri, 31 Jan 2020 05:02:05 -0500 Janosch Frank <[email protected]> wrote:
From: Pierre Morel <[email protected]>
Local IRQs are reset by a normal cpu reset. The initial cpu reset and the clear cpu reset, as superset of the normal reset, both clear the IRQs too.
Quoted 8 lines
Let's inject an interrupt to a vCPU before calling a reset and see if it is gone after the reset.
We choose to inject only an emergency interrupt at this point and can extend the test to other types of IRQs later.
Signed-off-by Pierre Morel <[email protected]>Signed-off-by Janosch Frank <[email protected]>[minor fixups]
I usually keep a blank between the email address and any annotations (not sure if that might trip some scripts).
Quoted 3 lines
--- tools/testing/selftests/kvm/s390x/resets.c | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+)
Re: [PATCH v10 6/6] selftests: KVM: testing the local IRQs resets
In reply to Janosch FrankQuoted 9 lines · Janosch Frank
From: Pierre Morel <[email protected]>
Local IRQs are reset by a normal cpu reset. The initial cpu reset and the clear cpu reset, as superset of the normal reset, both clear the IRQs too.
Let's inject an interrupt to a vCPU before calling a reset and see if it is gone after the reset.
Quoted 8 lines
We choose to inject only an emergency interrupt at this point and can extend the test to other types of IRQs later.
Signed-off-by Pierre Morel <[email protected]>Signed-off-by Janosch Frank <[email protected]>[minor fixups]--- tools/testing/selftests/kvm/s390x/resets.c | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+)
Christian Borntraeger
AppliedRe: [PATCH v10 6/6] selftests: KVM: testing the local IRQs resets
In reply to Janosch FrankQuoted 6 lines · Janosch Frank
From: Pierre Morel <[email protected]>
Local IRQs are reset by a normal cpu reset. The initial cpu reset and the clear cpu reset, as superset of the normal reset, both clear the IRQs too.
Quoted 8 lines
Let's inject an interrupt to a vCPU before calling a reset and see if it is gone after the reset.
We choose to inject only an emergency interrupt at this point and can extend the test to other types of IRQs later.
Signed-off-by Pierre Morel <[email protected]>Signed-off-by Janosch Frank <[email protected]>[minor fixups]
thanks applied.