* [PATCH 0/2] KVM: SVM: Add fast MMIO bus writes
@ 2025-11-13 22:16 Sean Christopherson
2025-11-13 22:16 ` [PATCH 1/2] KVM: SVM: Rename "fault_address" to "gpa" in npf_interception() Sean Christopherson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sean Christopherson @ 2025-11-13 22:16 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
Add support for expediting fast MMIO bus writes in SVM's npt_interception()
to match VMX's support in handle_ept_misconfig().
I don't recall what prompted me to write the patches; I suspect it was a
"well, why not?" situation. They've been sitting in one of my bajillion
branches since May, and I rediscovered them while looking for something
else.
Sean Christopherson (2):
KVM: SVM: Rename "fault_address" to "gpa" in npf_interception()
KVM: SVM: Add support for expedited writes to the fast MMIO bus
arch/x86/kvm/svm/svm.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
base-commit: 16ec4fb4ac95d878b879192d280db2baeec43272
--
2.52.0.rc1.455.g30608eb744-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] KVM: SVM: Rename "fault_address" to "gpa" in npf_interception()
2025-11-13 22:16 [PATCH 0/2] KVM: SVM: Add fast MMIO bus writes Sean Christopherson
@ 2025-11-13 22:16 ` Sean Christopherson
2025-11-13 22:16 ` [PATCH 2/2] KVM: SVM: Add support for expedited writes to the fast MMIO bus Sean Christopherson
2026-01-12 17:38 ` [PATCH 0/2] KVM: SVM: Add fast MMIO bus writes Sean Christopherson
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2025-11-13 22:16 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
Rename "fault_address" to "gpa" in KVM's #NPF handler and track it as a
gpa_t to more precisely document what type of address is being captured,
and because "gpa" is much more succinct.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/svm/svm.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index fc42bcdbb520..1fd097e8240e 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1857,8 +1857,8 @@ static int npf_interception(struct kvm_vcpu *vcpu)
struct vcpu_svm *svm = to_svm(vcpu);
int rc;
- u64 fault_address = svm->vmcb->control.exit_info_2;
u64 error_code = svm->vmcb->control.exit_info_1;
+ gpa_t gpa = svm->vmcb->control.exit_info_2;
/*
* WARN if hardware generates a fault with an error code that collides
@@ -1872,14 +1872,14 @@ static int npf_interception(struct kvm_vcpu *vcpu)
if (sev_snp_guest(vcpu->kvm) && (error_code & PFERR_GUEST_ENC_MASK))
error_code |= PFERR_PRIVATE_ACCESS;
- trace_kvm_page_fault(vcpu, fault_address, error_code);
- rc = kvm_mmu_page_fault(vcpu, fault_address, error_code,
+ trace_kvm_page_fault(vcpu, gpa, error_code);
+ rc = kvm_mmu_page_fault(vcpu, gpa, error_code,
static_cpu_has(X86_FEATURE_DECODEASSISTS) ?
svm->vmcb->control.insn_bytes : NULL,
svm->vmcb->control.insn_len);
if (rc > 0 && error_code & PFERR_GUEST_RMP_MASK)
- sev_handle_rmp_fault(vcpu, fault_address, error_code);
+ sev_handle_rmp_fault(vcpu, gpa, error_code);
return rc;
}
--
2.52.0.rc1.455.g30608eb744-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] KVM: SVM: Add support for expedited writes to the fast MMIO bus
2025-11-13 22:16 [PATCH 0/2] KVM: SVM: Add fast MMIO bus writes Sean Christopherson
2025-11-13 22:16 ` [PATCH 1/2] KVM: SVM: Rename "fault_address" to "gpa" in npf_interception() Sean Christopherson
@ 2025-11-13 22:16 ` Sean Christopherson
2026-01-12 17:38 ` [PATCH 0/2] KVM: SVM: Add fast MMIO bus writes Sean Christopherson
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2025-11-13 22:16 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
Wire up SVM's #NPF handler to fast MMIO. While SVM doesn't provide a
dedicated exit reason, it's trivial to key off PFERR_RSVD_MASK. Like VMX,
restrict the fast path to L1 to avoid having to deal with nGPA=>GPA
translations.
For simplicity, use the fast path if and only if the next RIP is known.
While KVM could utilize EMULTYPE_SKIP, doing so would require additional
logic to deal with SEV guests, e.g. to go down the slow path if the
instruction buffer is empty. All modern CPUs support next RIP, and in
practice the next RIP will be available for any guest fast path.
Copy+paste the kvm_io_bus_write() + trace_kvm_fast_mmio() logic even
though KVM would ideally provide a small helper, as such a helper would
need to either be a macro or non-inline to avoid including trace.h in a
header (trace.h must not be included by x86.c prior to CREATE_TRACE_POINTS
being defined).
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/svm/svm.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 1fd097e8240e..9fce0f46f79e 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1852,6 +1852,9 @@ static int pf_interception(struct kvm_vcpu *vcpu)
svm->vmcb->control.insn_len);
}
+static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
+ void *insn, int insn_len);
+
static int npf_interception(struct kvm_vcpu *vcpu)
{
struct vcpu_svm *svm = to_svm(vcpu);
@@ -1869,6 +1872,24 @@ static int npf_interception(struct kvm_vcpu *vcpu)
if (WARN_ON_ONCE(error_code & PFERR_SYNTHETIC_MASK))
error_code &= ~PFERR_SYNTHETIC_MASK;
+ /*
+ * Expedite fast MMIO kicks if the next RIP is known and KVM is allowed
+ * emulate a page fault, e.g. skipping the current instruction is wrong
+ * if the #NPF occurred while vectoring an event.
+ */
+ if ((error_code & PFERR_RSVD_MASK) && !is_guest_mode(vcpu)) {
+ const int emul_type = EMULTYPE_PF | EMULTYPE_NO_DECODE;
+
+ if (svm_check_emulate_instruction(vcpu, emul_type, NULL, 0))
+ return 1;
+
+ if (nrips && svm->vmcb->control.next_rip &&
+ !kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) {
+ trace_kvm_fast_mmio(gpa);
+ return kvm_skip_emulated_instruction(vcpu);
+ }
+ }
+
if (sev_snp_guest(vcpu->kvm) && (error_code & PFERR_GUEST_ENC_MASK))
error_code |= PFERR_PRIVATE_ACCESS;
--
2.52.0.rc1.455.g30608eb744-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] KVM: SVM: Add fast MMIO bus writes
2025-11-13 22:16 [PATCH 0/2] KVM: SVM: Add fast MMIO bus writes Sean Christopherson
2025-11-13 22:16 ` [PATCH 1/2] KVM: SVM: Rename "fault_address" to "gpa" in npf_interception() Sean Christopherson
2025-11-13 22:16 ` [PATCH 2/2] KVM: SVM: Add support for expedited writes to the fast MMIO bus Sean Christopherson
@ 2026-01-12 17:38 ` Sean Christopherson
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2026-01-12 17:38 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
On Thu, 13 Nov 2025 14:16:40 -0800, Sean Christopherson wrote:
> Add support for expediting fast MMIO bus writes in SVM's npt_interception()
> to match VMX's support in handle_ept_misconfig().
>
> I don't recall what prompted me to write the patches; I suspect it was a
> "well, why not?" situation. They've been sitting in one of my bajillion
> branches since May, and I rediscovered them while looking for something
> else.
>
> [...]
Applied to kvm-x86 svm, thanks!
[1/2] KVM: SVM: Rename "fault_address" to "gpa" in npf_interception()
https://github.com/kvm-x86/linux/commit/737f2a382f89
[2/2] KVM: SVM: Add support for expedited writes to the fast MMIO bus
https://github.com/kvm-x86/linux/commit/01cde4eaaeca
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-12 17:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-13 22:16 [PATCH 0/2] KVM: SVM: Add fast MMIO bus writes Sean Christopherson
2025-11-13 22:16 ` [PATCH 1/2] KVM: SVM: Rename "fault_address" to "gpa" in npf_interception() Sean Christopherson
2025-11-13 22:16 ` [PATCH 2/2] KVM: SVM: Add support for expedited writes to the fast MMIO bus Sean Christopherson
2026-01-12 17:38 ` [PATCH 0/2] KVM: SVM: Add fast MMIO bus writes Sean Christopherson
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®