KVM: selftests: Fixups for overhaul
Sean Christopherson
reviewercover KVM: selftests: Fixups for overhaul
Fixups for the overhaul, all of which come from Drew's code review. The first three should all squash cleanly, but the kvm_check_cap() patch will not due to crossing the TEST_REQUIRE() boundary.
Sean Christopherson (4):
KVM: selftests: Add a missing apostrophe in comment to show ownership
KVM: selftests: Call a dummy helper in VM/vCPU ioctls() to enforce
type
KVM: selftests: Drop a duplicate TEST_ASSERT() in
vm_nr_pages_required()
KVM: selftests: Use kvm_has_cap(), not kvm_check_cap(), where possible
.../testing/selftests/kvm/aarch64/psci_test.c | 2 +- .../selftests/kvm/include/kvm_util_base.h | 57 ++++++++++--------- tools/testing/selftests/kvm/lib/kvm_util.c | 6 +- .../selftests/kvm/lib/x86_64/processor.c | 4 +- .../selftests/kvm/s390x/sync_regs_test.c | 2 +- .../kvm/x86_64/pmu_event_filter_test.c | 2 +- .../selftests/kvm/x86_64/sev_migrate_tests.c | 6 +- tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +- .../testing/selftests/kvm/x86_64/state_test.c | 2 +- 9 files changed, 42 insertions(+), 41 deletions(-)
base-commit: 8baacf67c76c560fed954ac972b63e6e59a6fba0
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Sean Christopherson
reviewerPATCH 1/4 KVM: selftests: Add a missing apostrophe in comment to show ownership
Add an apostrophe in a comment about it being the caller's, not callers, responsibility to free an object.
--- tools/testing/selftests/kvm/lib/kvm_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/lib/kvm_util.c +1 -1
@@ -1434,7 +1434,7 @@ void vcpu_run_complete_io(struct kvm_vcpu *vcpu)/* * Get the list of guest registers which are supported for * KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls. Returns a kvm_reg_list pointer, -* it is the callers responsibility to free the list. +* it is the caller's responsibility to free the list. */ struct kvm_reg_list *vcpu_get_reg_list (struct kvm_vcpu *vcpu) {
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Re: [PATCH 1/4] KVM: selftests: Add a missing apostrophe in comment to show ownership
Quoted 16 lines · Sean Christopherson
Add an apostrophe in a comment about it being the caller's, not callers, responsibility to free an object.
Reported-by Andrew Jones <[email protected]>Fixes 768e9a61856b ("KVM: selftests: Purge vm+vcpu_id == vcpu silliness")Signed-off-by Sean Christopherson <[email protected]>--- tools/testing/selftests/kvm/lib/kvm_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/kvm/lib/kvm_util.c +0
-0
tools/testing/selftests/kvm/lib/kvm_util.c void vcpu_run_complete_io(struct kvm_vcpu *vcpu) · line 1438
Quoted 6 lines
tools/testing/selftests/kvm/lib/kvm_util.c +1
-1@@ -1434,7 +1434,7 @@ void vcpu_run_complete_io(struct kvm_vcpu *vcpu)/* * Get the list of guest registers which are supported for * KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls. Returns a kvm_reg_list pointer, -* it is the callers responsibility to free the list. +* it is the caller's responsibility to free the list. */
Shouldn't that be callers'? Or are you assuming there is only ever going to be one caller?
Sean Christopherson
reviewerRe: [PATCH 1/4] KVM: selftests: Add a missing apostrophe in comment to show ownership
Quoted 12 lines · Jim Mattson
Quoted 11 lines · Sean Christopherson
Add an apostrophe in a comment about it being the caller's, not callers, responsibility to free an object.
Reported-by Andrew Jones <[email protected]>Fixes 768e9a61856b ("KVM: selftests: Purge vm+vcpu_id == vcpu silliness")Signed-off-by Sean Christopherson <[email protected]>--- tools/testing/selftests/kvm/lib/kvm_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
tools/testing/selftests/kvm/lib/kvm_util.c void vcpu_run_complete_io(struct kvm_vcpu *vcpu) · line 1438
Quoted 11 lines
tools/testing/selftests/kvm/lib/kvm_util.c +1
-1@@ -1434,7 +1434,7 @@ void vcpu_run_complete_io(struct kvm_vcpu *vcpu)/* * Get the list of guest registers which are supported for * KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls. Returns a kvm_reg_list pointer, -* it is the callers responsibility to free the list. +* it is the caller's responsibility to free the list. */ Shouldn't that be callers'? Or are you assuming there is only ever going to be one caller?
No? Regardless of the number of users of the function, for any given invocation and allocation, there is exactly one caller.
Re: [PATCH 1/4] KVM: selftests: Add a missing apostrophe in comment to show ownership
Quoted 28 lines · Sean Christopherson
Quoted 12 lines · Jim Mattson
Quoted 11 lines · Sean Christopherson
Add an apostrophe in a comment about it being the caller's, not callers, responsibility to free an object.
Reported-by Andrew Jones <[email protected]>Fixes 768e9a61856b ("KVM: selftests: Purge vm+vcpu_id == vcpu silliness")Signed-off-by Sean Christopherson <[email protected]>--- tools/testing/selftests/kvm/lib/kvm_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
tools/testing/selftests/kvm/lib/kvm_util.c void vcpu_run_complete_io(struct kvm_vcpu *vcpu) · line 1438
Quoted 11 lines
tools/testing/selftests/kvm/lib/kvm_util.c +1
-1@@ -1434,7 +1434,7 @@ void vcpu_run_complete_io(struct kvm_vcpu *vcpu)/* * Get the list of guest registers which are supported for * KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls. Returns a kvm_reg_list pointer, -* it is the callers responsibility to free the list. +* it is the caller's responsibility to free the list. */ Shouldn't that be callers'? Or are you assuming there is only ever going to be one caller?
Quoted 2 lines
No? Regardless of the number of users of the function, for any given invocation and allocation, there is exactly one caller.
Statically, there may be multiple callers, and each is responsible for freeing the list, right?
Sean Christopherson
reviewerPATCH 2/4 KVM: selftests: Call a dummy helper in VM/vCPU ioctls() to enforce type
In reply to Sean ChristophersonReplace the goofy static_assert on the size of the @vm/@vcpu parameters with a call to a dummy helper, i.e. let the compiler naturally complain about an incompatible type instead of homebrewing a poor replacement.
--- .../selftests/kvm/include/kvm_util_base.h | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-)
tools/testing/selftests/kvm/include/kvm_util_base.h +31 -26
@@ -186,50 +186,55 @@ static inline bool kvm_has_cap(long cap)ioctl (fd, cmd, arg); \ }) -#define __kvm_ioctl (kvm_fd, cmd, arg) \ +#define __kvm_ioctl (kvm_fd, cmd, arg) \ kvm_do_ioctl(kvm_fd, cmd, arg) -#define _kvm_ioctl (kvm_fd, cmd, name, arg) \ -({ \ - int ret = __kvm_ioctl(kvm_fd, cmd, arg); \ - \ - TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ +#define _kvm_ioctl (kvm_fd, cmd, name, arg) \ +({ \ + int ret = __kvm_ioctl(kvm_fd, cmd, arg); \ + \ + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ })#define kvm_ioctl (kvm_fd, cmd, arg) \ _kvm_ioctl(kvm_fd, cmd, #cmd, arg) -#define __vm_ioctl (vm, cmd, arg) \ -({ \ - static_assert(sizeof(*(vm)) == sizeof(struct kvm_vm), ""); \ - kvm_do_ioctl((vm)->fd, cmd, arg); \ +static __always_inline void static_assert_is_vm(struct kvm_vm *vm) { } + +#define __vm_ioctl (vm, cmd, arg) \ +({ \ + static_assert_is_vm(vm); \ + kvm_do_ioctl((vm)->fd, cmd, arg); \ }) -#define _vm_ioctl (vm, cmd, name, arg) \ -({ \ - int ret = __vm_ioctl(vm, cmd, arg); \ - \ - TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ +#define _vm_ioctl (vm, cmd, name, arg) \ +({ \ + int ret = __vm_ioctl(vm, cmd, arg); \ + \ + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ }) -#define vm_ioctl (vm, cmd, arg) \ +#define vm_ioctl (vm, cmd, arg) \ _vm_ioctl(vm, cmd, #cmd, arg) -#define __vcpu_ioctl (vcpu, cmd, arg) \ -({ \ - static_assert(sizeof(*(vcpu)) == sizeof(struct kvm_vcpu), ""); \ - kvm_do_ioctl((vcpu)->fd, cmd, arg); \ + +static __always_inline void static_assert_is_vcpu(struct kvm_vcpu *vcpu) { } + +#define __vcpu_ioctl (vcpu, cmd, arg) \ +({ \ + static_assert_is_vcpu(vcpu); \ + kvm_do_ioctl((vcpu)->fd, cmd, arg); \ }) -#define _vcpu_ioctl (vcpu, cmd, name, arg) \ -({ \ - int ret = __vcpu_ioctl(vcpu, cmd, arg); \ - \ - TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ +#define _vcpu_ioctl (vcpu, cmd, name, arg) \ +({ \ + int ret = __vcpu_ioctl(vcpu, cmd, arg); \ + \ + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ }) -#define vcpu_ioctl (vcpu, cmd, arg) \ +#define vcpu_ioctl (vcpu, cmd, arg) \ _vcpu_ioctl(vcpu, cmd, #cmd, arg)/*
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Sean Christopherson
reviewerPATCH 3/4 KVM: selftests: Drop a duplicate TEST_ASSERT() in vm_nr_pages_required()
In reply to Sean ChristophersonRemove a duplicate TEST_ASSERT() on the number of runnable vCPUs in vm_nr_pages_required() that snuck in during a rebase gone bad.
--- tools/testing/selftests/kvm/lib/kvm_util.c | 4 ---- 1 file changed, 4 deletions(-)
tools/testing/selftests/kvm/lib/kvm_util.c +0 -4
@@ -284,10 +284,6 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mode mode,*/ nr_pages += (nr_pages + extra_mem_pages) /PTES_PER_MIN_PAGE *2 ; -TEST_ASSERT (nr_runnable_vcpus <=kvm_check_cap (KVM_CAP_MAX_VCPUS ), -"Host doesn't support %d vCPUs, max-vcpus = %d" , - nr_runnable_vcpus,kvm_check_cap (KVM_CAP_MAX_VCPUS )); -return vm_adjust_num_guest_pages (mode, nr_pages); }
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Sean Christopherson
reviewerPATCH 4/4 KVM: selftests: Use kvm_has_cap(), not kvm_check_cap(), where possible
In reply to Sean ChristophersonReplace calls to kvm_check_cap() that treat its return as a boolean with calls to kvm_has_cap(). Several instances of kvm_check_cap() were missed when kvm_has_cap() was introduced.
--- tools/testing/selftests/kvm/aarch64/psci_test.c | 2 +- tools/testing/selftests/kvm/lib/x86_64/processor.c | 4 ++-- tools/testing/selftests/kvm/s390x/sync_regs_test.c | 2 +- tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c | 2 +- tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c | 6 +++--- tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +- tools/testing/selftests/kvm/x86_64/state_test.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)
tools/testing/selftests/kvm/aarch64/psci_test.c +1 -1
@@ -192,7 +192,7 @@ static void host_test_system_suspend(void)int main (void ) { -TEST_REQUIRE (kvm_check_cap (KVM_CAP_ARM_SYSTEM_SUSPEND )); +TEST_REQUIRE (kvm_has_cap (KVM_CAP_ARM_SYSTEM_SUSPEND ));host_test_cpu_on ();host_test_system_suspend ();
tools/testing/selftests/kvm/lib/x86_64/processor.c +2 -2
@@ -991,7 +991,7 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vcpu *vcpu)vcpu_regs_get (vcpu, &state->regs);vcpu_save_xsave_state (vcpu, state); -if (kvm_check_cap (KVM_CAP_XCRS )) +if (kvm_has_cap (KVM_CAP_XCRS ))vcpu_xcrs_get (vcpu, &state->xcrs);vcpu_sregs_get (vcpu, &state->sregs);
@@ -1022,7 +1022,7 @@ void vcpu_load_state(struct kvm_vcpu *vcpu, struct kvm_x86_state *state)vcpu_sregs_set (vcpu, &state->sregs);vcpu_msrs_set (vcpu, &state->msrs); -if (kvm_check_cap (KVM_CAP_XCRS )) +if (kvm_has_cap (KVM_CAP_XCRS ))vcpu_xcrs_set (vcpu, &state->xcrs);vcpu_xsave_set (vcpu, state->xsave);
tools/testing/selftests/kvm/s390x/sync_regs_test.c +1 -1
@@ -229,7 +229,7 @@ int main(int argc, char *argv[])struct kvm_vm *vm;int idx; -TEST_REQUIRE (kvm_check_cap (KVM_CAP_SYNC_REGS )); +TEST_REQUIRE (kvm_has_cap (KVM_CAP_SYNC_REGS ));/* Tell stdout not to buffer its content */ setbuf (stdout,NULL );
tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +1 -1
@@ -450,7 +450,7 @@ int main(int argc, char *argv[])/* Tell stdout not to buffer its content */ setbuf (stdout,NULL ); -TEST_REQUIRE (kvm_check_cap (KVM_CAP_PMU_EVENT_FILTER )); +TEST_REQUIRE (kvm_has_cap (KVM_CAP_PMU_EVENT_FILTER ));TEST_REQUIRE (use_intel_pmu () ||use_amd_pmu ()); guest_code =use_intel_pmu () ? intel_guest_code : amd_guest_code;
tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c +3 -3
@@ -411,16 +411,16 @@ int main(int argc, char *argv[]) have_sev_es = !!(cpuid->eax &X86_FEATURE_SEV_ES ); -if (kvm_check_cap (KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM )) { +if (kvm_has_cap (KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM )) {test_sev_migrate_from (/* es= */ false);if (have_sev_es)test_sev_migrate_from (/* es= */ true);test_sev_migrate_locking ();test_sev_migrate_parameters (); -if (kvm_check_cap (KVM_CAP_VM_COPY_ENC_CONTEXT_FROM )) +if (kvm_has_cap (KVM_CAP_VM_COPY_ENC_CONTEXT_FROM ))test_sev_move_copy (); } -if (kvm_check_cap (KVM_CAP_VM_COPY_ENC_CONTEXT_FROM )) { +if (kvm_has_cap (KVM_CAP_VM_COPY_ENC_CONTEXT_FROM )) {test_sev_mirror (/* es= */ false);if (have_sev_es)test_sev_mirror (/* es= */ true);
tools/testing/selftests/kvm/x86_64/smm_test.c +1 -1
@@ -153,7 +153,7 @@ int main(int argc, char *argv[])vcpu_set_msr (vcpu,MSR_IA32_SMBASE ,SMRAM_GPA ); -if (kvm_check_cap (KVM_CAP_NESTED_STATE )) { +if (kvm_has_cap (KVM_CAP_NESTED_STATE )) {if (nested_svm_supported ())vcpu_alloc_svm (vm, &nested_gva);else if (nested_vmx_supported ())
tools/testing/selftests/kvm/x86_64/state_test.c +1 -1
@@ -169,7 +169,7 @@ int main(int argc, char *argv[])vcpu_regs_get (vcpu, ®s1); -if (kvm_check_cap (KVM_CAP_NESTED_STATE )) { +if (kvm_has_cap (KVM_CAP_NESTED_STATE )) {if (nested_svm_supported ())vcpu_alloc_svm (vm, &nested_gva);else if (nested_vmx_supported ())
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Quoted 24 lines · Sean Christopherson
Fixups for the overhaul, all of which come from Drew's code review. The first three should all squash cleanly, but the
kvm_check_cap()patch will not due to crossing theTEST_REQUIRE()boundary.Sean Christopherson (4):
KVM: selftests: Add a missing apostrophe in comment to show ownership
KVM: selftests: Call a dummy helper in VM/vCPUioctls()to enforce
type
KVM: selftests: Drop a duplicateTEST_ASSERT()in
vm_nr_pages_required()
KVM: selftests: Usekvm_has_cap(), notkvm_check_cap(), where possible.../testing/selftests/kvm/aarch64/psci_test.c | 2 +- .../selftests/kvm/include/kvm_util_base.h | 57 ++++++++++--------- tools/testing/selftests/kvm/lib/kvm_util.c | 6 +- .../selftests/kvm/lib/x86_64/processor.c | 4 +- .../selftests/kvm/s390x/sync_regs_test.c | 2 +- .../kvm/x86_64/pmu_event_filter_test.c | 2 +- .../selftests/kvm/x86_64/sev_migrate_tests.c | 6 +- tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +- .../testing/selftests/kvm/x86_64/state_test.c | 2 +- 9 files changed, 42 insertions(+), 41 deletions(-)
Quoted 4 lines
base-commit:
8baacf67c76c560fed954ac972b63e6e59a6fba0Signature · 1 line
2.36.1.476.g0c4daa206d-goog
All these patches look good to me. For the series
There's still one more comment I made on the overhaul though, which is that the expressions using i and j in kvm_binary_stats_test.c for the vcpus and vcpu_stat_test indices have i and j swapped.
Thanks,
drew
Quoted 30 lines · Andrew Jones
Quoted 24 lines · Sean Christopherson
Fixups for the overhaul, all of which come from Drew's code review. The first three should all squash cleanly, but the
kvm_check_cap()patch will not due to crossing theTEST_REQUIRE()boundary.Sean Christopherson (4):
KVM: selftests: Add a missing apostrophe in comment to show ownership
KVM: selftests: Call a dummy helper in VM/vCPUioctls()to enforce
type
KVM: selftests: Drop a duplicateTEST_ASSERT()in
vm_nr_pages_required()
KVM: selftests: Usekvm_has_cap(), notkvm_check_cap(), where possible.../testing/selftests/kvm/aarch64/psci_test.c | 2 +- .../selftests/kvm/include/kvm_util_base.h | 57 ++++++++++--------- tools/testing/selftests/kvm/lib/kvm_util.c | 6 +- .../selftests/kvm/lib/x86_64/processor.c | 4 +- .../selftests/kvm/s390x/sync_regs_test.c | 2 +- .../kvm/x86_64/pmu_event_filter_test.c | 2 +- .../selftests/kvm/x86_64/sev_migrate_tests.c | 6 +- tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +- .../testing/selftests/kvm/x86_64/state_test.c | 2 +- 9 files changed, 42 insertions(+), 41 deletions(-)Quoted 4 lines
base-commit:
8baacf67c76c560fed954ac972b63e6e59a6fba0Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Quoted 8 lines
All these patches look good to me. For the series
Reviewed-by Andrew Jones <[email protected]>There's still one more comment I made on the overhaul though, which is that the expressions using i and j in
kvm_binary_stats_test.cfor the vcpus andvcpu_stat_testindices have i and j swapped.
I'll just go ahead and send that i,j patch myself now.
Thanks,
drew
Paolo Bonzini
maintainerQueued, thanks; also queued the i/j fixup at "KVM: selftests: kvm_binary_stats_test:
Fix index expressions".
Paolo