From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: seanjc@google.com, Sasha Levin <sashal@kernel.org>
Subject: [PATCH] KVM: SEV: never retry after #NPF on paging structures
Date: Tue, 17 Nov 2026 19:59:22 +0100 [thread overview]
Message-ID: <20261117185922.466255-1-pbonzini@redhat.com> (raw)
KVM cannot walk the encrypted page tables of SEV guests, so there is
no point in emulating the instruction if the #NPF fault was caused by
either data or code. In the latter case the instruction buffer is going
to be empty, so emulation was avoided by resuming the guest, but in the
data case KVM attempted emulation which is pointless.
Apply the existing check for PFERR_GUEST_PAGE_MASK even if the instruction
buffer was filled.
Reported-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/svm/svm.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index af0deb198a84..4f42da3642b6 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -5513,19 +5513,29 @@ static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
}
/*
- * Emulate for SEV guests if the insn buffer is not empty. The buffer
- * will be empty if the DecodeAssist microcode cannot fetch bytes for
- * the faulting instruction because the code fetch itself faulted, e.g.
- * the guest attempted to fetch from emulated MMIO or a guest page
- * table used to translate CS:RIP resides in emulated MMIO.
+ * Under SEV, page tables are encrypted and cannot be read by the
+ * hypervisor, so there is no way to resolve a fault on page tables.
*/
+ error_code = svm->vmcb->control.exit_info_1;
+ if (error_code & PFERR_GUEST_PAGE_MASK)
+ goto resume_guest;
+
if (likely(insn_len))
return X86EMUL_CONTINUE;
/*
- * Detect and workaround Errata 1096 Fam_17h_00_0Fh.
+ * The insn buffer was empty; the DecodeAssist microcode could not fetch
+ * bytes for the faulting instruction because the code fetch itself faulted,
+ * e.g. the guest attempted to fetch from emulated MMIO or a guest page
+ * table used to translate CS:RIP resides in emulated MMIO.
*
- * Errata:
+ * A data fault instead could be Errata 1096 Fam_17h_00_0Fh, so only
+ * retry for a fetch fault and otherwise try to workaround it.
+ */
+ if (error_code & PFERR_FETCH_MASK)
+ goto resume_guest;
+
+ /*
* When CPU raises #NPF on guest data access and vCPU CR4.SMAP=1, it is
* possible that CPU microcode implementing DecodeAssist will fail to
* read guest memory at CS:RIP and vmcb.GuestIntrBytes will incorrectly
@@ -5552,12 +5562,8 @@ static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
* retrieve the instruction bytes is legitimate (see abvoe).
*
* In addition, don't apply the erratum workaround if the #NPF occurred
- * while translating guest page tables (see below).
+ * while translating guest page tables (see above).
*/
- error_code = svm->vmcb->control.exit_info_1;
- if (error_code & (PFERR_GUEST_PAGE_MASK | PFERR_FETCH_MASK))
- goto resume_guest;
-
smep = kvm_is_cr4_bit_set(vcpu, X86_CR4_SMEP);
smap = kvm_is_cr4_bit_set(vcpu, X86_CR4_SMAP);
is_user = svm_get_cpl(vcpu) == 3;
--
2.56.0
next reply other threads:[~2026-11-17 18:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 18:59 Paolo Bonzini [this message]
2026-11-17 20:07 ` Sasha Levin
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=20261117185922.466255-1-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sashal@kernel.org \
--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®