Skip to content

Commit b799e3e

Browse files
committed
KVM: selftests: Verify get/set PERF_CAPABILITIES w/o guest PDMC behavior
Add another testcase to x86's PMU capabilities test to verify that KVM's handling of userspace accesses to PERF_CAPABILITIES when the vCPU doesn't support the MSR (per the vCPU's CPUID). KVM's (newly established) ABI is that userspace MSR accesses are subject to architectural existence checks, but that if the MSR is advertised as supported _by KVM_, "bad" reads get '0' and writes of '0' are always allowed. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 1ded7a5 commit b799e3e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ KVM_ONE_VCPU_TEST(vmx_pmu_caps, lbr_perf_capabilities, guest_code)
207207
TEST_ASSERT(!r, "Writing LBR_TOS should fail after disabling vPMU");
208208
}
209209

210+
KVM_ONE_VCPU_TEST(vmx_pmu_caps, perf_capabilities_unsupported, guest_code)
211+
{
212+
uint64_t val;
213+
int i, r;
214+
215+
vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities);
216+
val = vcpu_get_msr(vcpu, MSR_IA32_PERF_CAPABILITIES);
217+
TEST_ASSERT_EQ(val, host_cap.capabilities);
218+
219+
vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_PDCM);
220+
221+
val = vcpu_get_msr(vcpu, MSR_IA32_PERF_CAPABILITIES);
222+
TEST_ASSERT_EQ(val, 0);
223+
224+
vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, 0);
225+
226+
for (i = 0; i < 64; i++) {
227+
r = _vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, BIT_ULL(i));
228+
TEST_ASSERT(!r, "Setting PERF_CAPABILITIES bit %d (= 0x%llx) should fail without PDCM",
229+
i, BIT_ULL(i));
230+
}
231+
}
232+
210233
int main(int argc, char *argv[])
211234
{
212235
TEST_REQUIRE(kvm_is_pmu_enabled());

0 commit comments

Comments
 (0)