mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-14 06:45:43 -04:00
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/20240802185511.305849-9-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
@@ -207,6 +207,29 @@ KVM_ONE_VCPU_TEST(vmx_pmu_caps, lbr_perf_capabilities, guest_code)
|
||||
TEST_ASSERT(!r, "Writing LBR_TOS should fail after disabling vPMU");
|
||||
}
|
||||
|
||||
KVM_ONE_VCPU_TEST(vmx_pmu_caps, perf_capabilities_unsupported, guest_code)
|
||||
{
|
||||
uint64_t val;
|
||||
int i, r;
|
||||
|
||||
vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities);
|
||||
val = vcpu_get_msr(vcpu, MSR_IA32_PERF_CAPABILITIES);
|
||||
TEST_ASSERT_EQ(val, host_cap.capabilities);
|
||||
|
||||
vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_PDCM);
|
||||
|
||||
val = vcpu_get_msr(vcpu, MSR_IA32_PERF_CAPABILITIES);
|
||||
TEST_ASSERT_EQ(val, 0);
|
||||
|
||||
vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, 0);
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
r = _vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, BIT_ULL(i));
|
||||
TEST_ASSERT(!r, "Setting PERF_CAPABILITIES bit %d (= 0x%llx) should fail without PDCM",
|
||||
i, BIT_ULL(i));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
TEST_REQUIRE(kvm_is_pmu_enabled());
|
||||
|
||||
Reference in New Issue
Block a user