From: Yosry Ahmed <yosry@kernel.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Jim Mattson <jmattson@google.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Yosry Ahmed <yosry@kernel.org>
Subject: [PATCH 3/3] KVM: selftests: Set EFER.SVME via KVM_SET_SREGS in svm_pmu_host_guest_test
Date: Wed, 25 Nov 2026 18:27:03 +0000 [thread overview]
Message-ID: <20261125182703.1694998-4-yosry@kernel.org> (raw)
In-Reply-To: <20261125182703.1694998-1-yosry@kernel.org>
Extend svm_pmu_host_guest_test to set EFER.SVME from userspace via
KVM_SET_SREGS and verify that Host-Only counters resume counting. Switch
the existing filter syncs to GUEST_SYNC2() so the guest can select
between updating the PMU event filter and setting EFER.SVME.
Setting EFER.SVME via KVM_SET_SREGS exercises the __set_sregs_common()
-> svm_set_efer() -> svm_pmu_handle_nested_transition() path from
userspace (and specifically from KVM_SET_SREGS, where kvm->srcu is not
held).
Signed-off-by: Yosry Ahmed <yosry@kernel.org>
---
.../kvm/x86/svm_pmu_host_guest_test.c | 31 ++++++++++++++++---
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86/svm_pmu_host_guest_test.c b/tools/testing/selftests/kvm/x86/svm_pmu_host_guest_test.c
index c5b5cd788d93f..3f743dbaf851f 100644
--- a/tools/testing/selftests/kvm/x86/svm_pmu_host_guest_test.c
+++ b/tools/testing/selftests/kvm/x86/svm_pmu_host_guest_test.c
@@ -37,6 +37,11 @@
#define LOOP_INSNS 1000
+enum sync_cmd {
+ SYNC_SET_FILTER,
+ SYNC_SET_SVME,
+};
+
static __always_inline void run_instruction_loop(void)
{
unsigned int i;
@@ -128,12 +133,12 @@ static void l1_guest_code(struct svm_test_data *svm)
assert_pmc_counts(deltas, BIT(PMC_NONE) | BIT(PMC_H) | BIT(PMC_HG));
/* Step 5: Set KVM_PMU_EVENT_DENY - all counters stop */
- GUEST_SYNC(KVM_PMU_EVENT_DENY);
+ GUEST_SYNC2(SYNC_SET_FILTER, KVM_PMU_EVENT_DENY);
run_and_measure(deltas);
assert_pmc_counts(deltas, 0);
/* Step 6: Set KVM_PMU_EVENT_ALLOW - back to all except Guest-only */
- GUEST_SYNC(KVM_PMU_EVENT_ALLOW);
+ GUEST_SYNC2(SYNC_SET_FILTER, KVM_PMU_EVENT_ALLOW);
run_and_measure(deltas);
assert_pmc_counts(deltas, BIT(PMC_NONE) | BIT(PMC_H) | BIT(PMC_HG));
@@ -153,6 +158,11 @@ static void l1_guest_code(struct svm_test_data *svm)
run_and_measure(deltas);
assert_pmc_counts(deltas, BIT(PMC_NONE));
+ /* Step 10: Set SVME via KVM_SET_SREGS - Host-Only counters resume */
+ GUEST_SYNC1(SYNC_SET_SVME);
+ run_and_measure(deltas);
+ assert_pmc_counts(deltas, BIT(PMC_NONE) | BIT(PMC_H) | BIT(PMC_HG));
+
GUEST_DONE();
}
@@ -174,6 +184,7 @@ static struct kvm_pmu_event_filter *alloc_event_filter(u64 event)
int main(int argc, char *argv[])
{
struct kvm_pmu_event_filter *filter;
+ struct kvm_sregs sregs;
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
struct ucall uc;
@@ -201,8 +212,20 @@ int main(int argc, char *argv[])
case UCALL_DONE:
goto done;
case UCALL_SYNC:
- filter->action = uc.args[1];
- vm_ioctl(vm, KVM_SET_PMU_EVENT_FILTER, filter);
+ switch (uc.args[0]) {
+ case SYNC_SET_FILTER:
+ filter->action = uc.args[1];
+ vm_ioctl(vm, KVM_SET_PMU_EVENT_FILTER, filter);
+ break;
+ case SYNC_SET_SVME:
+ vcpu_sregs_get(vcpu, &sregs);
+ sregs.efer |= EFER_SVME;
+ vcpu_sregs_set(vcpu, &sregs);
+ break;
+ default:
+ TEST_FAIL("Unknown sync cmd %lu", uc.args[0]);
+ goto done;
+ }
break;
default:
TEST_FAIL("Unknown ucall %lu", uc.cmd);
--
2.56.1.839.g22a8290db9-goog
prev parent reply other threads:[~2026-11-25 18:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 18:27 [PATCH 0/3] KVM: x86/pmu: Always defer PMU reprogramming on nested transitions Yosry Ahmed
2026-11-25 18:27 ` [PATCH 1/3] KVM: x86/pmu: Recalc PMC emulation when deferring counter reprogramming Yosry Ahmed
2026-11-25 18:27 ` [PATCH 2/3] KVM: x86/pmu: Always defer PMU reprogramming on SVM nested transitions Yosry Ahmed
2026-12-01 17:14 ` Sean Christopherson
2026-12-01 17:23 ` Yosry Ahmed
2026-12-01 23:47 ` Sean Christopherson
2026-12-02 5:16 ` Yosry Ahmed
2026-11-25 18:27 ` Yosry Ahmed [this message]
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=20261125182703.1694998-4-yosry@kernel.org \
--to=yosry@kernel.org \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.