Commit e5b77cde authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Convert sync_regs_test away from VCPU_ID

Convert sync_regs_test to use vm_create_with_vcpus() and pass around a
'struct kvm_vcpu' object instead of passing around vCPU IDs.  Note, this
is a "functional" change in the sense that the test now creates a vCPU
with vcpu_id==0 instead of vcpu_id==5.  The non-zero VCPU_ID was 100%
arbitrary and added little to no validation coverage.  If testing
non-zero vCPU IDs is desirable for generic tests, that can be done in the
future by tweaking the VM creation helpers.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent ebca1b80
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
#include "diag318_test_handler.h" #include "diag318_test_handler.h"
#include "kselftest.h" #include "kselftest.h"
#define VCPU_ID 5
static void guest_code(void) static void guest_code(void)
{ {
/* /*
...@@ -75,55 +73,58 @@ static void compare_sregs(struct kvm_sregs *left, struct kvm_sync_regs *right) ...@@ -75,55 +73,58 @@ static void compare_sregs(struct kvm_sregs *left, struct kvm_sync_regs *right)
#define TEST_SYNC_FIELDS (KVM_SYNC_GPRS|KVM_SYNC_ACRS|KVM_SYNC_CRS|KVM_SYNC_DIAG318) #define TEST_SYNC_FIELDS (KVM_SYNC_GPRS|KVM_SYNC_ACRS|KVM_SYNC_CRS|KVM_SYNC_DIAG318)
#define INVALID_SYNC_FIELD 0x80000000 #define INVALID_SYNC_FIELD 0x80000000
void test_read_invalid(struct kvm_vm *vm, struct kvm_run *run) void test_read_invalid(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
int rv; int rv;
/* Request reading invalid register set from VCPU. */ /* Request reading invalid register set from VCPU. */
run->kvm_valid_regs = INVALID_SYNC_FIELD; run->kvm_valid_regs = INVALID_SYNC_FIELD;
rv = _vcpu_run(vm, VCPU_ID); rv = _vcpu_run(vcpu->vm, vcpu->id);
TEST_ASSERT(rv < 0 && errno == EINVAL, TEST_ASSERT(rv < 0 && errno == EINVAL,
"Invalid kvm_valid_regs did not cause expected KVM_RUN error: %d\n", "Invalid kvm_valid_regs did not cause expected KVM_RUN error: %d\n",
rv); rv);
vcpu_state(vm, VCPU_ID)->kvm_valid_regs = 0; run->kvm_valid_regs = 0;
run->kvm_valid_regs = INVALID_SYNC_FIELD | TEST_SYNC_FIELDS; run->kvm_valid_regs = INVALID_SYNC_FIELD | TEST_SYNC_FIELDS;
rv = _vcpu_run(vm, VCPU_ID); rv = _vcpu_run(vcpu->vm, vcpu->id);
TEST_ASSERT(rv < 0 && errno == EINVAL, TEST_ASSERT(rv < 0 && errno == EINVAL,
"Invalid kvm_valid_regs did not cause expected KVM_RUN error: %d\n", "Invalid kvm_valid_regs did not cause expected KVM_RUN error: %d\n",
rv); rv);
vcpu_state(vm, VCPU_ID)->kvm_valid_regs = 0; run->kvm_valid_regs = 0;
} }
void test_set_invalid(struct kvm_vm *vm, struct kvm_run *run) void test_set_invalid(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
int rv; int rv;
/* Request setting invalid register set into VCPU. */ /* Request setting invalid register set into VCPU. */
run->kvm_dirty_regs = INVALID_SYNC_FIELD; run->kvm_dirty_regs = INVALID_SYNC_FIELD;
rv = _vcpu_run(vm, VCPU_ID); rv = _vcpu_run(vcpu->vm, vcpu->id);
TEST_ASSERT(rv < 0 && errno == EINVAL, TEST_ASSERT(rv < 0 && errno == EINVAL,
"Invalid kvm_dirty_regs did not cause expected KVM_RUN error: %d\n", "Invalid kvm_dirty_regs did not cause expected KVM_RUN error: %d\n",
rv); rv);
vcpu_state(vm, VCPU_ID)->kvm_dirty_regs = 0; run->kvm_dirty_regs = 0;
run->kvm_dirty_regs = INVALID_SYNC_FIELD | TEST_SYNC_FIELDS; run->kvm_dirty_regs = INVALID_SYNC_FIELD | TEST_SYNC_FIELDS;
rv = _vcpu_run(vm, VCPU_ID); rv = _vcpu_run(vcpu->vm, vcpu->id);
TEST_ASSERT(rv < 0 && errno == EINVAL, TEST_ASSERT(rv < 0 && errno == EINVAL,
"Invalid kvm_dirty_regs did not cause expected KVM_RUN error: %d\n", "Invalid kvm_dirty_regs did not cause expected KVM_RUN error: %d\n",
rv); rv);
vcpu_state(vm, VCPU_ID)->kvm_dirty_regs = 0; run->kvm_dirty_regs = 0;
} }
void test_req_and_verify_all_valid_regs(struct kvm_vm *vm, struct kvm_run *run) void test_req_and_verify_all_valid_regs(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
struct kvm_sregs sregs; struct kvm_sregs sregs;
struct kvm_regs regs; struct kvm_regs regs;
int rv; int rv;
/* Request and verify all valid register sets. */ /* Request and verify all valid register sets. */
run->kvm_valid_regs = TEST_SYNC_FIELDS; run->kvm_valid_regs = TEST_SYNC_FIELDS;
rv = _vcpu_run(vm, VCPU_ID); rv = _vcpu_run(vcpu->vm, vcpu->id);
TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv); TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv);
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC,
"Unexpected exit reason: %u (%s)\n", "Unexpected exit reason: %u (%s)\n",
...@@ -136,15 +137,16 @@ void test_req_and_verify_all_valid_regs(struct kvm_vm *vm, struct kvm_run *run) ...@@ -136,15 +137,16 @@ void test_req_and_verify_all_valid_regs(struct kvm_vm *vm, struct kvm_run *run)
run->s390_sieic.icptcode, run->s390_sieic.ipa, run->s390_sieic.icptcode, run->s390_sieic.ipa,
run->s390_sieic.ipb); run->s390_sieic.ipb);
vcpu_regs_get(vm, VCPU_ID, &regs); vcpu_regs_get(vcpu->vm, vcpu->id, &regs);
compare_regs(&regs, &run->s.regs); compare_regs(&regs, &run->s.regs);
vcpu_sregs_get(vm, VCPU_ID, &sregs); vcpu_sregs_get(vcpu->vm, vcpu->id, &sregs);
compare_sregs(&sregs, &run->s.regs); compare_sregs(&sregs, &run->s.regs);
} }
void test_set_and_verify_various_reg_values(struct kvm_vm *vm, struct kvm_run *run) void test_set_and_verify_various_reg_values(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
struct kvm_sregs sregs; struct kvm_sregs sregs;
struct kvm_regs regs; struct kvm_regs regs;
int rv; int rv;
...@@ -161,7 +163,7 @@ void test_set_and_verify_various_reg_values(struct kvm_vm *vm, struct kvm_run *r ...@@ -161,7 +163,7 @@ void test_set_and_verify_various_reg_values(struct kvm_vm *vm, struct kvm_run *r
run->kvm_dirty_regs |= KVM_SYNC_DIAG318; run->kvm_dirty_regs |= KVM_SYNC_DIAG318;
} }
rv = _vcpu_run(vm, VCPU_ID); rv = _vcpu_run(vcpu->vm, vcpu->id);
TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv); TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv);
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC,
"Unexpected exit reason: %u (%s)\n", "Unexpected exit reason: %u (%s)\n",
...@@ -177,15 +179,16 @@ void test_set_and_verify_various_reg_values(struct kvm_vm *vm, struct kvm_run *r ...@@ -177,15 +179,16 @@ void test_set_and_verify_various_reg_values(struct kvm_vm *vm, struct kvm_run *r
"diag318 sync regs value incorrect 0x%llx.", "diag318 sync regs value incorrect 0x%llx.",
run->s.regs.diag318); run->s.regs.diag318);
vcpu_regs_get(vm, VCPU_ID, &regs); vcpu_regs_get(vcpu->vm, vcpu->id, &regs);
compare_regs(&regs, &run->s.regs); compare_regs(&regs, &run->s.regs);
vcpu_sregs_get(vm, VCPU_ID, &sregs); vcpu_sregs_get(vcpu->vm, vcpu->id, &sregs);
compare_sregs(&sregs, &run->s.regs); compare_sregs(&sregs, &run->s.regs);
} }
void test_clear_kvm_dirty_regs_bits(struct kvm_vm *vm, struct kvm_run *run) void test_clear_kvm_dirty_regs_bits(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
int rv; int rv;
/* Clear kvm_dirty_regs bits, verify new s.regs values are /* Clear kvm_dirty_regs bits, verify new s.regs values are
...@@ -195,7 +198,7 @@ void test_clear_kvm_dirty_regs_bits(struct kvm_vm *vm, struct kvm_run *run) ...@@ -195,7 +198,7 @@ void test_clear_kvm_dirty_regs_bits(struct kvm_vm *vm, struct kvm_run *run)
run->kvm_dirty_regs = 0; run->kvm_dirty_regs = 0;
run->s.regs.gprs[11] = 0xDEADBEEF; run->s.regs.gprs[11] = 0xDEADBEEF;
run->s.regs.diag318 = 0x4B1D; run->s.regs.diag318 = 0x4B1D;
rv = _vcpu_run(vm, VCPU_ID); rv = _vcpu_run(vcpu->vm, vcpu->id);
TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv); TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv);
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC,
"Unexpected exit reason: %u (%s)\n", "Unexpected exit reason: %u (%s)\n",
...@@ -211,7 +214,7 @@ void test_clear_kvm_dirty_regs_bits(struct kvm_vm *vm, struct kvm_run *run) ...@@ -211,7 +214,7 @@ void test_clear_kvm_dirty_regs_bits(struct kvm_vm *vm, struct kvm_run *run)
struct testdef { struct testdef {
const char *name; const char *name;
void (*test)(struct kvm_vm *vm, struct kvm_run *run); void (*test)(struct kvm_vcpu *vcpu);
} testlist[] = { } testlist[] = {
{ "read invalid", test_read_invalid }, { "read invalid", test_read_invalid },
{ "set invalid", test_set_invalid }, { "set invalid", test_set_invalid },
...@@ -222,8 +225,8 @@ struct testdef { ...@@ -222,8 +225,8 @@ struct testdef {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
static struct kvm_run *run; struct kvm_vcpu *vcpu;
static struct kvm_vm *vm; struct kvm_vm *vm;
int idx; int idx;
/* Tell stdout not to buffer its content */ /* Tell stdout not to buffer its content */
...@@ -237,12 +240,10 @@ int main(int argc, char *argv[]) ...@@ -237,12 +240,10 @@ int main(int argc, char *argv[])
ksft_set_plan(ARRAY_SIZE(testlist)); ksft_set_plan(ARRAY_SIZE(testlist));
/* Create VM */ /* Create VM */
vm = vm_create_default(VCPU_ID, 0, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
run = vcpu_state(vm, VCPU_ID);
for (idx = 0; idx < ARRAY_SIZE(testlist); idx++) { for (idx = 0; idx < ARRAY_SIZE(testlist); idx++) {
testlist[idx].test(vm, run); testlist[idx].test(vcpu);
ksft_test_result_pass("%s\n", testlist[idx].name); ksft_test_result_pass("%s\n", testlist[idx].name);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment