Re: [PATCH v8 8/8] KVM: selftests: Add PERF_METRICS and fixed counter 3 tests
"Chen, Zide" <[email protected]>
| Newsgroups | org.kernel.vger.kvm,dev.linux.lists.sashiko-reviews |
|---|---|
| Message-ID | <[email protected]> |
On 8/17/2026 1:57 PM, [email protected] wrote: > Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: > - [Medium] Unhandled #GP / Selftest Crash when writing 0xdeaddead to MSR_PERF_METRICS. > -- > > --- Patch [8]: [PATCH v8 8/8] KVM: selftests: Add PERF_METRICS and fixed counter 3 tests --- > commit 19d6869fac1fbdcc63ff54623403cec33b922848 > Author: Zide Chen <[email protected]> > > KVM: selftests: Add PERF_METRICS and fixed counter 3 tests > > This commit adds a test case to exercise IA32_PERF_METRICS for Topdown > (TMA) Level 1 metrics and extends the PMU selftest to cover Intel fixed > counter 3. > >> diff --git a/tools/testing/selftests/kvm/x86/pmu_counters_test.c b/tools/testing/selftests/kvm/x86/pmu_counters_test.c >> --- a/tools/testing/selftests/kvm/x86/pmu_counters_test.c >> +++ b/tools/testing/selftests/kvm/x86/pmu_counters_test.c > [ ... ] >> +static void __guest_test_perf_metrics(void) >> +{ > [ ... ] >> + /* Sanity check after PERF_METRICS disabled. */ >> + __asm__ __volatile__("loop ." : "+c"((int){NUM_LOOPS})); >> + GUEST_ASSERT_EQ(rdmsr(MSR_PERF_METRICS), metrics); >> + wrmsr(MSR_PERF_METRICS, 0xdeaddead); >> + >> + guest_test_rdpmc(INTEL_RDPMC_METRICS, true, 0xdeaddead); >> +} > > [Severity: Medium] > Will this wrmsr(MSR_PERF_METRICS, 0xdeaddead) cause an unhandled #GP and > crash the selftest on hosts with Mediated PMU pass-through? > > Writing an architecturally invalid non-zero value to MSR_PERF_METRICS > generates a #GP on real hardware. Under Mediated PMU, KVM configures the > VMCS to pass-through MSR accesses directly to hardware, so this fault > would be injected into the guest. 0xdeaddead is a valid non-zero value. So this statement is supposed to work well. > > If the hardware silently discards the write instead of faulting, will the > subsequent guest_test_rdpmc() assertion fail because it expects to read back > 0xdeaddead, while the hardware holds the previous value? >