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 v2 0/4] KVM: x86/pmu: Always defer PMU reprogramming on nested transitions
Date: Wed, 2 Dec 2026 05:27:50 +0000 [thread overview]
Message-ID: <20261202052754.3170526-1-yosry@kernel.org> (raw)
When Host-Only/Guest-Only bits handling was added [1], we went back and
forth between deferring PMU reprogramming vs doing it synchronously.
Deferring all reprogramming is incorrect, because on mode changes (e.g.
VMRUN or WRMSR(EFER.SVME)), this would only update the to-be-emulated
PMCs after the instruction is emulated, which would count the
instruction in the previous mode. Real AMD hardware counts instructions
in the mode they retire in.
We ended up with a hybrid approach where architectural mode changes do
reprogramming synchronously, but force-leaving nested defers it, as it
may not be safe to do it synchronously.
This mini-series unifies all nested transition paths by always
calculating to-be-emulated PMCs synchronously and deferring the rest
(e.g. similar to WRMSR(EVENTSEL)).
The motivation for the series was an unprotected SRCU access from
KVM_SET_SREGS -> svm_set_efer -> svm_pmu_handle_nested_transition() ->
... -> pmc_is_event_allowed(). v2 added prepended a separate
stable-friendly fix (from Sean, pending SoB). The stable-friendly fix
could have been sent out separate from the series, but I kept them
together to retain historical context, and more importantly because I am
lazy.
[1] https://lore.kernel.org/kvm/20260527234711.4175166-1-yosry@kernel.org/
v1 -> v2:
- Prepend Sean's stable-friendly fix (needs SoB).
v1: https://lore.kernel.org/kvm/20261125182703.1694998-1-yosry@kernel.org/
Sean Christopherson (1):
KVM: x86: Acquire SRCU read lock in KVM_SET_SREGS[2]
Yosry Ahmed (3):
KVM: x86/pmu: Recalc PMC emulation when deferring counter
reprogramming
KVM: x86/pmu: Always defer PMU reprogramming on SVM nested transitions
KVM: selftests: Set EFER.SVME via KVM_SET_SREGS in
svm_pmu_host_guest_test
arch/x86/kvm/pmu.c | 1 -
arch/x86/kvm/pmu.h | 32 ++++++++-----------
arch/x86/kvm/regs.c | 13 +++-----
arch/x86/kvm/svm/nested.c | 10 +-----
arch/x86/kvm/svm/svm.h | 18 ++---------
.../kvm/x86/svm_pmu_host_guest_test.c | 31 +++++++++++++++---
6 files changed, 49 insertions(+), 56 deletions(-)
base-commit: cbe54fc3462b3949ab27b9ae81fb9ddb509040c7
--
2.56.1.911.g883d8bcb20-goog
next reply other threads:[~2026-12-02 5:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 5:27 Yosry Ahmed [this message]
2026-12-02 5:27 ` [PATCH v2 1/4] KVM: x86: Acquire SRCU read lock in KVM_SET_SREGS[2] Yosry Ahmed
2026-12-02 5:27 ` [PATCH v2 2/4] KVM: x86/pmu: Recalc PMC emulation when deferring counter reprogramming Yosry Ahmed
2026-12-02 5:27 ` [PATCH v2 3/4] KVM: x86/pmu: Always defer PMU reprogramming on SVM nested transitions Yosry Ahmed
2026-12-02 5:27 ` [PATCH v2 4/4] KVM: selftests: Set EFER.SVME via KVM_SET_SREGS in svm_pmu_host_guest_test Yosry Ahmed
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=20261202052754.3170526-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®