Skip to content

Commit 1159799

Browse files
sean-jcpull[bot]
authored andcommitted
KVM: x86: Do not mark all registers as avail/dirty during RESET/INIT
Do not blindly mark all registers as available+dirty at RESET/INIT, and instead rely on writes to registers to go through the proper mutators or to explicitly mark registers as dirty. INIT in particular does not blindly overwrite all registers, e.g. select bits in CR0 are preserved across INIT, thus marking registers available+dirty without first reading the register from hardware is incorrect. In practice this is a benign bug as KVM doesn't let the guest control CR0 bits that are preserved across INIT, and all other true registers are explicitly written during the RESET/INIT flows. The PDPTRs and EX_INFO "registers" are not explicitly written, but accessing those values during RESET/INIT is nonsensical and would be a KVM bug regardless of register caching. Fixes: 66f7b72 ("KVM: x86: Make register state after reset conform to specification") [sean: !!! NOT FOR STABLE !!!] Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20210921000303.400537-4-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 5591310 commit 1159799

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4449,6 +4449,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
44494449
kvm_set_cr8(vcpu, 0);
44504450

44514451
vmx_segment_cache_clear(vmx);
4452+
kvm_register_mark_available(vcpu, VCPU_EXREG_SEGMENTS);
44524453

44534454
seg_setup(VCPU_SREG_CS);
44544455
vmcs_write16(GUEST_CS_SELECTOR, 0xf000);

arch/x86/kvm/x86.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10688,9 +10688,9 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
1068810688
vcpu->arch.xcr0 = XFEATURE_MASK_FP;
1068910689
}
1069010690

10691+
/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
1069110692
memset(vcpu->arch.regs, 0, sizeof(vcpu->arch.regs));
10692-
vcpu->arch.regs_avail = ~0;
10693-
vcpu->arch.regs_dirty = ~0;
10693+
kvm_register_mark_dirty(vcpu, VCPU_REGS_RSP);
1069410694

1069510695
/*
1069610696
* Fall back to KVM's default Family/Model/Stepping of 0x600 (P6/Athlon)

0 commit comments

Comments
 (0)