From: Sean Christopherson <seanjc@google.com>
To: Yosry Ahmed <yosry@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Jim Mattson <jmattson@google.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 6/6] KVM: selftests: Add svm_pmu_host_guest_test for Host-Only/Guest-Only bits
Date: Mon, 6 Apr 2026 18:39:02 -0700 [thread overview]
Message-ID: <adRgNinmj0V0h6nH@google.com> (raw)
In-Reply-To: <20260326031150.3774017-7-yosry@kernel.org>
On Thu, Mar 26, 2026, Yosry Ahmed wrote:
> From: Jim Mattson <jmattson@google.com>
>
> Add a selftest to verify KVM correctly virtualizes the AMD PMU Host-Only
> (bit 41) and Guest-Only (bit 40) event selector bits across all relevant
> SVM state transitions.
>
> The test programs 4 PMCs simultaneously with all combinations of the
> Host-Only and Guest-Only bits, then verifies correct counting behavior:
> 1. SVME=0: all counters count (Host-Only/Guest-Only bits ignored)
> 2. Set SVME=1: Host-Only and neither/both count; Guest-Only stops
> 3. VMRUN to L2: Guest-Only and neither/both count; Host-Only stops
> 4. VMEXIT to L1: Host-Only and neither/both count; Guest-Only stops
> 5. Clear SVME=0: all counters count (bits ignored again)
>
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Signed-off-by: Yosry Ahmed <yosry@kernel.org>
> ---
> tools/testing/selftests/kvm/Makefile.kvm | 1 +
> tools/testing/selftests/kvm/include/x86/pmu.h | 6 +
> .../selftests/kvm/include/x86/processor.h | 2 +
> .../kvm/x86/svm_pmu_host_guest_test.c | 199 ++++++++++++++++++
> 4 files changed, 208 insertions(+)
> create mode 100644 tools/testing/selftests/kvm/x86/svm_pmu_host_guest_test.c
>
> diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
> index 3d372d78a2756..9418c45291231 100644
> --- a/tools/testing/selftests/kvm/Makefile.kvm
> +++ b/tools/testing/selftests/kvm/Makefile.kvm
> @@ -116,6 +116,7 @@ TEST_GEN_PROGS_x86 += x86/svm_nested_invalid_vmcb12_gpa
> TEST_GEN_PROGS_x86 += x86/svm_nested_shutdown_test
> TEST_GEN_PROGS_x86 += x86/svm_nested_soft_inject_test
> TEST_GEN_PROGS_x86 += x86/svm_lbr_nested_state
> +TEST_GEN_PROGS_x86 += x86/svm_pmu_host_guest_test
> TEST_GEN_PROGS_x86 += x86/tsc_scaling_sync
> TEST_GEN_PROGS_x86 += x86/sync_regs_test
> TEST_GEN_PROGS_x86 += x86/ucna_injection_test
> diff --git a/tools/testing/selftests/kvm/include/x86/pmu.h b/tools/testing/selftests/kvm/include/x86/pmu.h
> index 72575eadb63a0..af9b279c78df4 100644
> --- a/tools/testing/selftests/kvm/include/x86/pmu.h
> +++ b/tools/testing/selftests/kvm/include/x86/pmu.h
> @@ -38,6 +38,12 @@
> #define ARCH_PERFMON_EVENTSEL_INV BIT_ULL(23)
> #define ARCH_PERFMON_EVENTSEL_CMASK GENMASK_ULL(31, 24)
>
> +/*
> + * These are AMD-specific bits.
> + */
> +#define AMD64_EVENTSEL_GUESTONLY BIT_ULL(40)
> +#define AMD64_EVENTSEL_HOSTONLY BIT_ULL(41)
> +
> /* RDPMC control flags, Intel only. */
> #define INTEL_RDPMC_METRICS BIT_ULL(29)
> #define INTEL_RDPMC_FIXED BIT_ULL(30)
> diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h
> index d8634a760a609..4cc1ba8752347 100644
> --- a/tools/testing/selftests/kvm/include/x86/processor.h
> +++ b/tools/testing/selftests/kvm/include/x86/processor.h
> @@ -19,6 +19,8 @@
> #include "kvm_util.h"
> #include "ucall_common.h"
>
> +#define __stack_aligned__ __aligned(16)
I would much prefer to provide a macro helper to declare the stack in a prep patch,
and update the bajillion instances of "unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]"
through KVM selftests.
A blurb in the changelog explaining why _this_ test needs to honor alignment
while we've managed to squeak by without problems in other tests would also be
helpful
> +
> extern bool host_cpu_is_intel;
> extern bool host_cpu_is_amd;
> extern bool host_cpu_is_hygon;
next prev parent reply other threads:[~2026-04-07 1:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 3:11 [PATCH v4 0/6] KVM: x86/pmu: Add support for AMD Host-Only/Guest-Only bits Yosry Ahmed
2026-03-26 3:11 ` [PATCH v4 1/6] KVM: x86: Move enable_pmu/enable_mediated_pmu to pmu.h and pmu.c Yosry Ahmed
2026-03-26 3:11 ` [PATCH v4 2/6] KVM: x86: Move guest_mode helpers to x86.h Yosry Ahmed
2026-03-26 22:48 ` kernel test robot
2026-03-26 23:18 ` Yosry Ahmed
2026-03-27 3:15 ` kernel test robot
2026-03-26 3:11 ` [PATCH v4 3/6] KVM: x86/pmu: Disable counters based on Host-Only/Guest-Only bits in SVM Yosry Ahmed
2026-04-07 1:30 ` Sean Christopherson
2026-03-26 3:11 ` [PATCH v4 4/6] KVM: x86/pmu: Re-evaluate Host-Only/Guest-Only on nested SVM transitions Yosry Ahmed
2026-04-07 1:35 ` Sean Christopherson
2026-03-26 3:11 ` [PATCH v4 5/6] KVM: x86/pmu: Allow Host-Only/Guest-Only bits with nSVM and mediated PMU Yosry Ahmed
2026-03-26 3:11 ` [PATCH v4 6/6] KVM: selftests: Add svm_pmu_host_guest_test for Host-Only/Guest-Only bits Yosry Ahmed
2026-04-07 1:39 ` Sean Christopherson [this message]
2026-04-07 3:23 ` Jim Mattson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adRgNinmj0V0h6nH@google.com \
--to=seanjc@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=yosry@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox