Re: [PATCH 2/3] KVM: VMX: Move RESET emulation to vmx_vcpu_reset()

From: Sean Christopherson
Date: Thu Sep 16 2021 - 15:06:45 EST


On Thu, Sep 16, 2021, Vitaly Kuznetsov wrote:
> Sean Christopherson <seanjc@xxxxxxxxxx> writes:
> > @@ -10897,6 +10899,9 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
> > kvm_set_rflags(vcpu, X86_EFLAGS_FIXED);
> > kvm_rip_write(vcpu, 0xfff0);
> >
> > + vcpu->arch.cr3 = 0;
> > + kvm_register_mark_dirty(vcpu, VCPU_EXREG_CR3);
> > +
> > /*
> > * CR0.CD/NW are set on RESET, preserved on INIT. Note, some versions
> > * of Intel's SDM list CD/NW as being set on INIT, but they contradict
> >
>
> A selftest for vCPU create/reset would be really helpful. I can even
> volunteer to [eventually] write one :-)

Hmm, I wonder if it would be possible to share code/infrastructure with Erdem's
in-progress TDX selftest framework[*]. TDX forces vCPUs to start at the legacy
reset vector with paging disabled, so it needs a lot of the same glue code as a
from-RESET test would need. TDX forces 32-bit PM instead of RM, but it should
be easy enough to allow an optional opening sequence to get into 32-bit PM.

We could also test INIT without much trouble since INIT to the BSP will send it
back to the reset vector, e.g. set a flag somewhere to avoid an infinite loop and
INIT self.

Let me work with Erdem to see if we can concoct something that will work for
both TDX and tests that want to take control at RESET.

[*] https://lkml.kernel.org/r/20210726183816.1343022-3-erdemaktas@xxxxxxxxxx