[PATCH v10 03/20] KVM: x86: Support EGPRs on vCPU RESET/INIT events
From: Chang S. Bae
Date: Mon Nov 23 2026 - 13:18:17 EST
Zero EGPRs on vCPU RESET and preserve them on INIT, matching the
hardware specification.
Signed-off-by: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
Reviewed-by: Jim Mattson <jmattson@xxxxxxxxxx>
---
V9 -> V10:
* Use NR_VCPU_LEGACY_GPRS instead of a hard-coded number, then the
change looks small, reverting the previous refactoring as well. (Jim)
* Add a review tag, thanks!
---
arch/x86/include/asm/kvm_host.h | 6 ++++++
arch/x86/kvm/x86.c | 9 +++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 7db87bc99f4a..327d26e38cbc 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -211,6 +211,12 @@ enum kvm_reg {
NR_VCPU_TOTAL_REGS,
};
+#ifdef CONFIG_X86_64
+#define NR_VCPU_LEGACY_GPRS (VCPU_REGS_R15 + 1)
+#else
+#define NR_VCPU_LEGACY_GPRS (VCPU_REGS_RDI + 1)
+#endif
+
enum {
VCPU_SREG_ES,
VCPU_SREG_CS,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2cd9ee316aad..c2ce1bc8c77f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9673,8 +9673,13 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
kvm_msr_write(vcpu, MSR_IA32_XSS, 0);
}
- /* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
- memset(vcpu->arch.regs, 0, sizeof(vcpu->arch.regs));
+ /*
+ * All legacy GPRs except RDX (handled below) are zeroed on RESET/INIT.
+ * EGPRs (R16-R31) are zeroed on RESET, but are unchanged on INIT.
+ */
+ memset(vcpu->arch.regs, 0,
+ init_event ? NR_VCPU_LEGACY_GPRS * sizeof(vcpu->arch.regs[0]) :
+ sizeof(vcpu->arch.regs));
kvm_register_mark_dirty(vcpu, VCPU_REGS_RSP);
/*
--
2.53.0