Re: [PATCH v8 01/20] KVM: x86: Extend VCPU registers for EGPRs
From: Chang S. Bae
Date: Fri Nov 06 2026 - 00:33:49 EST
On 11/5/26 15:42, Jim Mattson wrote:
In kvm_vcpu_reset(), KVM unconditionally zeroes the entire vcpu->arch.regs
array on both RESET and INIT:
/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
memset(vcpu->arch.regs, 0, sizeof(vcpu->arch.regs));
However, according to the Intel APX Architecture Specification (rev. 9.0),
section 3.1.4.1.1 and Table 3.7, R16-R31 are unchanged on INIT:
The main difference between EGPRs and legacy GPRs, is that EGPRs are not
enabled by default (specifically XCR0-enabled) in 64-bit mode, and their
INIT behavior is XMM-like; in that EGPRs and many other XSAVE-enabled
register states are un-changed on INIT events as shown in Table 3.7.
By extending NR_VCPU_GENERAL_PURPOSE_REGS to include VCPU_REGS_R16 through
VCPU_REGS_R31 without updating kvm_vcpu_reset(), KVM will erroneously zero
R16-R31 when init_event is true.
Appreciate the review!
This was overlooked since switched away from XSAVE to the VCPU cache. Initially, I thought okay to keep along with other XSTATEs:
The specification deliberately scopes out some areas. For example,
Sections 3.1.4.4.2–7 note that initialization and reset behaviors
follow existing XSTATE conventions.
Yes, you're right. The reset needs to be adjusted.
Thanks,
Chang