selftests: kvm: Check whether SIDA memop fails for normal guests
PATCH 1/1 selftests: kvm: Check whether SIDA memop fails for normal guests
Commit 2c212e1baedc ("KVM: s390: Return error on SIDA memop on normal guest") fixed the behavior of the SIDA memops for normal guests. It would be nice to have a way to test whether the current kernel has the fix applied or not. Thus add a check to the KVM selftests for these two memops.
--- tools/testing/selftests/kvm/s390x/memop.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
tools/testing/selftests/kvm/s390x/memop.c +15 -0
@@ -160,6 +160,21 @@ int main(int argc, char *argv[]) run->psw_mask &= ~(3UL << (63 -17 ));/* Disable AR mode */ vcpu_run (vm,VCPU_ID );/* Run to sync new state */ +/* Check that the SIDA calls are rejected for non-protected guests */ + ksmo.gaddr =0 ; + ksmo.flags =0 ; + ksmo.size =8 ; + ksmo.op =KVM_S390_MEMOP_SIDA_READ ; + ksmo.buf = (uintptr_t )mem1; + ksmo.sida_offset =0x1c0 ; + rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_READ in non-protected mode" ); + ksmo.op =KVM_S390_MEMOP_SIDA_WRITE ; + rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_WRITE in non-protected mode" ); +kvm_vm_free (vm);return 0 ;
Signature · 1 line
2.27.0
Quoted 7 lines · On Tue, 15 Feb 2022 08:48:24 +0100 Thomas Huth <[email protected]> wrote:
Commit
2c212e1baedc("KVM: s390: Return error on SIDA memop on normal guest") fixed the behavior of the SIDA memops for normal guests. It would be nice to have a way to test whether the current kernel has the fix applied or not. Thus add a check to the KVM selftests for these two memops.Signed-off-by Thomas Huth <[email protected]>
looks rather straightforward
Quoted 30 lines
--- tools/testing/selftests/kvm/s390x/memop.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)tools/testing/selftests/kvm/s390x/memop.c +15
-0@@ -160,6 +160,21 @@ int main(int argc, char *argv[]) run->psw_mask &= ~(3UL << (63 -17 ));/* Disable AR mode */ vcpu_run (vm,VCPU_ID );/* Run to sync new state */ +/* Check that the SIDA calls are rejected for non-protected guests */ + ksmo.gaddr =0 ; + ksmo.flags =0 ; + ksmo.size =8 ; + ksmo.op =KVM_S390_MEMOP_SIDA_READ ; + ksmo.buf = (uintptr_t )mem1; + ksmo.sida_offset =0x1c0 ; + rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_READ in non-protected mode" ); + ksmo.op =KVM_S390_MEMOP_SIDA_WRITE ; + rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_WRITE in non-protected mode" ); +kvm_vm_free (vm);return 0 ;
Quoted 16 lines · Thomas Huth
Commit
2c212e1baedc("KVM: s390: Return error on SIDA memop on normal guest") fixed the behavior of the SIDA memops for normal guests. It would be nice to have a way to test whether the current kernel has the fix applied or not. Thus add a check to the KVM selftests for these two memops.Signed-off-by Thomas Huth <[email protected]>--- tools/testing/selftests/kvm/s390x/memop.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)tools/testing/selftests/kvm/s390x/memop.c +0
-0
tools/testing/selftests/kvm/s390x/memop.c int main(int argc, char *argv[]) · line 169
Quoted 10 lines
tools/testing/selftests/kvm/s390x/memop.c +7
-0@@ -160,6 +160,21 @@ int main(int argc, char *argv[]) run->psw_mask &= ~(3UL << (63 -17 ));/* Disable AR mode */ vcpu_run (vm,VCPU_ID );/* Run to sync new state */ +/* Check that the SIDA calls are rejected for non-protected guests */ + ksmo.gaddr =0 ; + ksmo.flags =0 ; + ksmo.size =8 ; + ksmo.op =KVM_S390_MEMOP_SIDA_READ ; + ksmo.buf = (uintptr_t )mem1; + ksmo.sida_offset =0x1c0 ;
What is the rational for that constant?
Any would do, as long as size + offset < PAGE_SIZE, correct?
Quoted 11 lines
tools/testing/selftests/kvm/s390x/memop.c +8
-0+ rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_READ in non-protected mode" ); + ksmo.op =KVM_S390_MEMOP_SIDA_WRITE ; + rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_WRITE in non-protected mode" ); +kvm_vm_free (vm);return 0 ;
Quoted 20 lines · Janis Schoetterl-Glausch
Quoted 19 lines · Thomas Huth
Commit
2c212e1baedc("KVM: s390: Return error on SIDA memop on normal guest") fixed the behavior of the SIDA memops for normal guests. It would be nice to have a way to test whether the current kernel has the fix applied or not. Thus add a check to the KVM selftests for these two memops.Signed-off-by Thomas Huth <[email protected]>--- tools/testing/selftests/kvm/s390x/memop.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)tools/testing/selftests/kvm/s390x/memop.c +0
-0@@ -160,6 +160,21 @@ int main(int argc, char *argv[]) run->psw_mask &= ~(3UL << (63 -17 ));/* Disable AR mode */ vcpu_run (vm,VCPU_ID );/* Run to sync new state */
Quoted 10 lines
tools/testing/selftests/kvm/s390x/memop.c int main(int argc, char *argv[]) · line 169
Quoted 7 lines
tools/testing/selftests/kvm/s390x/memop.c +7
-0+/* Check that the SIDA calls are rejected for non-protected guests */ + ksmo.gaddr =0 ; + ksmo.flags =0 ; + ksmo.size =8 ; + ksmo.op =KVM_S390_MEMOP_SIDA_READ ; + ksmo.buf = (uintptr_t )mem1; + ksmo.sida_offset =0x1c0 ;What is the rational for that constant?
Any would do, as long as size + offset <PAGE_SIZE, correct?
Right, it's rather a random value.
Thomas
Janis Schoetterl-Glausch
Reviewed-byQuoted 32 lines · Thomas Huth
Quoted 20 lines · Janis Schoetterl-Glausch
Quoted 19 lines · Thomas Huth
Commit
2c212e1baedc("KVM: s390: Return error on SIDA memop on normal guest") fixed the behavior of the SIDA memops for normal guests. It would be nice to have a way to test whether the current kernel has the fix applied or not. Thus add a check to the KVM selftests for these two memops.Signed-off-by Thomas Huth <[email protected]>---
tools/testing/selftests/kvm/s390x/memop.c| 15 +++++++++++++++1 file changed, 15 insertions(+)tools/testing/selftests/kvm/s390x/memop.c +0
-0@@ -160,6 +160,21 @@ int main(int argc, char *argv[])
run->psw_mask&= ~(3UL << (63 - 17)); /* Disable AR mode */vcpu_run(vm, VCPU_ID); /* Run to sync new state */Quoted 10 lines
Quoted 7 lines
+ /* Check that the SIDA calls are rejected for non-protected guests */ + ksmo.gaddr = 0;
+ ksmo.flags = 0;
+ ksmo.size = 8;
+ ksmo.op =KVM_S390_MEMOP_SIDA_READ;
+ ksmo.buf = (uintptr_t)mem1;
+ ksmo.sida_offset =0x1c0;What is the rational for that constant?
Any would do, as long as size + offset <PAGE_SIZE, correct?
Quoted 1 line
Right, it's rather a random value.
Ah, ok.
Quoted 3 lines
Thomas
Christian Borntraeger
AppliedAm 15.02.22 um 08:48 schrieb Thomas Huth:
Quoted 7 lines
Commit
2c212e1baedc("KVM: s390: Return error on SIDA memop on normal guest") fixed the behavior of the SIDA memops for normal guests. It would be nice to have a way to test whether the current kernel has the fix applied or not. Thus add a check to the KVM selftests for these two memops.Signed-off-by Thomas Huth <[email protected]>
Thanks, applied.
Quoted 30 lines
--- tools/testing/selftests/kvm/s390x/memop.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)tools/testing/selftests/kvm/s390x/memop.c +15
-0@@ -160,6 +160,21 @@ int main(int argc, char *argv[]) run->psw_mask &= ~(3UL << (63 -17 ));/* Disable AR mode */ vcpu_run (vm,VCPU_ID );/* Run to sync new state */ +/* Check that the SIDA calls are rejected for non-protected guests */ + ksmo.gaddr =0 ; + ksmo.flags =0 ; + ksmo.size =8 ; + ksmo.op =KVM_S390_MEMOP_SIDA_READ ; + ksmo.buf = (uintptr_t )mem1; + ksmo.sida_offset =0x1c0 ; + rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_READ in non-protected mode" ); + ksmo.op =KVM_S390_MEMOP_SIDA_WRITE ; + rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_WRITE in non-protected mode" ); +kvm_vm_free (vm);return 0 ;
Quoted 19 lines · Thomas Huth
Commit
2c212e1baedc("KVM: s390: Return error on SIDA memop on normal guest") fixed the behavior of the SIDA memops for normal guests. It would be nice to have a way to test whether the current kernel has the fix applied or not. Thus add a check to the KVM selftests for these two memops.Signed-off-by Thomas Huth <[email protected]>--- tools/testing/selftests/kvm/s390x/memop.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)tools/testing/selftests/kvm/s390x/memop.c +0
-0@@ -160,6 +160,21 @@ int main(int argc, char *argv[]) run->psw_mask &= ~(3UL << (63 -17 ));/* Disable AR mode */ vcpu_run (vm,VCPU_ID );/* Run to sync new state */
tools/testing/selftests/kvm/s390x/memop.c int main(int argc, char *argv[]) · line 172
Quoted 10 lines
tools/testing/selftests/kvm/s390x/memop.c +10
-0+/* Check that the SIDA calls are rejected for non-protected guests */ + ksmo.gaddr =0 ; + ksmo.flags =0 ; + ksmo.size =8 ; + ksmo.op =KVM_S390_MEMOP_SIDA_READ ; + ksmo.buf = (uintptr_t )mem1; + ksmo.sida_offset =0x1c0 ; + rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_READ in non-protected mode" );
Printing what passed would be a good addition to understand the tests that get run and expected to pass.
tools/testing/selftests/kvm/s390x/memop.c int main(int argc, char *argv[]) · line 177
Quoted 5 lines
tools/testing/selftests/kvm/s390x/memop.c +5
-0+ ksmo.op =KVM_S390_MEMOP_SIDA_WRITE ; + rv =_vcpu_ioctl (vm,VCPU_ID ,KVM_S390_MEM_OP , &ksmo); +TEST_ASSERT (rv ==-1 && errno ==EINVAL , +"ioctl does not reject SIDA_WRITE in non-protected mode" ); +
Same here.
tools/testing/selftests/kvm/s390x/memop.c int main(int argc, char *argv[]) · line 180
Quoted 4 lines
tools/testing/selftests/kvm/s390x/memop.c +0
-0kvm_vm_free (vm);return 0 ;
Something to consider in a follow-on patch and future changes to these tests.
thanks,
-- Shuah
Quoted 24 lines · Shuah Khan
Quoted 23 lines · Thomas Huth
Commit
2c212e1baedc("KVM: s390: Return error on SIDA memop on normal guest") fixed the behavior of the SIDA memops for normal guests. It would be nice to have a way to test whether the current kernel has the fix applied or not. Thus add a check to the KVM selftests for these two memops.Signed-off-by Thomas Huth <[email protected]>---
tools/testing/selftests/kvm/s390x/memop.c| 15 +++++++++++++++1 file changed, 15 insertions(+)tools/testing/selftests/kvm/s390x/memop.c +0
-0@@ -160,6 +160,21 @@ int main(int argc, char *argv[])
run->psw_mask&= ~(3UL << (63 - 17)); /* Disable AR mode */vcpu_run(vm, VCPU_ID); /* Run to sync new state */ + /* Check that the SIDA calls are rejected for non-protected guests */ + ksmo.gaddr = 0;
+ ksmo.flags = 0;
+ ksmo.size = 8;
+ ksmo.op =KVM_S390_MEMOP_SIDA_READ;
Quoted 8 lines
Quoted 5 lines
+ ksmo.buf = (uintptr_t)mem1;
+ ksmo.sida_offset =0x1c0;
+ rv =_vcpu_ioctl(vm, VCPU_ID, KVM_S390_MEM_OP, &ksmo); + TEST_ASSERT(rv == -1 && errno == EINVAL,
+ "ioctl does not rejectSIDA_READin non-protected mode");Printing what passed would be a good addition to understand the tests that get run and expected to pass.
Yes, I agree ... I'll add that for a follow-up patch to my TODO list.
Quoted 8 lines
Quoted 5 lines
+ ksmo.op =
KVM_S390_MEMOP_SIDA_WRITE;
+ rv =_vcpu_ioctl(vm, VCPU_ID, KVM_S390_MEM_OP, &ksmo); + TEST_ASSERT(rv == -1 && errno == EINVAL,
+ "ioctl does not rejectSIDA_WRITEin non-protected mode"); +Same here.
Quoted 7 lines
Quoted 3 lines
kvm_vm_free(vm);
return 0;Something to consider in a follow-on patch and future changes to these tests.
Reviewed-by Shuah Khan <[email protected]>
Thanks!
Thomas