Skip to content

Commit 80c2b6d

Browse files
committed
KVM: selftests: Add KVM_{G,S}ET_ONE_REG coverage to MSRs test
When KVM_{G,S}ET_ONE_REG are supported, verify that MSRs can be accessed via ONE_REG and through the dedicated MSR ioctls. For simplicity, run the test twice, e.g. instead of trying to get MSR values into the exact right state when switching write methods. Reviewed-by: Chao Gao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent a8b9cca commit 80c2b6d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tools/testing/selftests/kvm/x86/msrs_test.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ static void guest_main(void)
200200
}
201201
}
202202

203+
static bool has_one_reg;
204+
static bool use_one_reg;
205+
203206
static void host_test_msr(struct kvm_vcpu *vcpu, u64 guest_val)
204207
{
205208
u64 reset_val = msrs[idx].reset_val;
@@ -213,11 +216,21 @@ static void host_test_msr(struct kvm_vcpu *vcpu, u64 guest_val)
213216
TEST_ASSERT(val == guest_val, "Wanted 0x%lx from get_msr(0x%x), got 0x%lx",
214217
guest_val, msr, val);
215218

216-
vcpu_set_msr(vcpu, msr, reset_val);
219+
if (use_one_reg)
220+
vcpu_set_reg(vcpu, KVM_X86_REG_MSR(msr), reset_val);
221+
else
222+
vcpu_set_msr(vcpu, msr, reset_val);
217223

218224
val = vcpu_get_msr(vcpu, msr);
219225
TEST_ASSERT(val == reset_val, "Wanted 0x%lx from get_msr(0x%x), got 0x%lx",
220226
reset_val, msr, val);
227+
228+
if (!has_one_reg)
229+
return;
230+
231+
val = vcpu_get_reg(vcpu, KVM_X86_REG_MSR(msr));
232+
TEST_ASSERT(val == reset_val, "Wanted 0x%lx from get_reg(0x%x), got 0x%lx",
233+
reset_val, msr, val);
221234
}
222235

223236
static void do_vcpu_run(struct kvm_vcpu *vcpu)
@@ -357,5 +370,12 @@ static void test_msrs(void)
357370

358371
int main(void)
359372
{
373+
has_one_reg = kvm_has_cap(KVM_CAP_ONE_REG);
374+
360375
test_msrs();
376+
377+
if (has_one_reg) {
378+
use_one_reg = true;
379+
test_msrs();
380+
}
361381
}

0 commit comments

Comments
 (0)