Re: [PATCH v7 17/17] KVM: selftests: Add svm_pmu_host_guest_test for Host-Only/Guest-Only bits

From: Sean Christopherson

Date: Thu May 28 2026 - 14:05:26 EST


On Thu, May 28, 2026, Yosry Ahmed wrote:
> On Wed, May 27, 2026 at 7:25 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
> >
> > On Wed, May 27, 2026, Yosry Ahmed wrote:
> > > +int main(int argc, char *argv[])
> > > +{
> > > + struct kvm_pmu_event_filter *filter;
> > > + struct kvm_vcpu *vcpu;
> > > + struct kvm_vm *vm;
> > > + struct ucall uc;
> > > + gva_t svm_gva;
> > > +
> > > + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM));
> > > + TEST_REQUIRE(kvm_is_pmu_enabled());
> > > + TEST_REQUIRE(get_kvm_amd_param_bool("enable_mediated_pmu"));
> >
> > This can and should be handled in a helper, using either host_cpu_is_intel or
> > host_cpu_is_amd_compatible to choose while vendor to query.
> >
> > > + TEST_REQUIRE(host_cpu_is_amd && kvm_cpu_family() >= 0x17);
> >
> > Why the family check? Actually, why check host_cpu_is_amd at all?
>
> I assume you mean that we don't need host_cpu_is_amd because we
> require X86_FEATURE_SVM above?

Yes.

> Unless H/G emulation doesn't really work for cross-vendor emulation? I
> honestly don't know.

Not just cross-vendor emulation, KVM and selftests also support Hygon CPUs.

> I will defer to Jim for the family check, I took this as-is. My guess
> is that maybe older families did not support H/G bits or some of the
> other PMU features used by the test.

If that's true, then the mediated PMU shouldn't be enabled. If the mediated PMU
_can_ be enabled for CPUs that do _and_ don't support H/G bits, then we need to
figure out a way to enumerate H/G support to userspace. Because telling userspace
to check F/M/S ain't going to fly.