Re: [PATCH v5 2/7] nSVM: introduce smv->nested.save to cache save area fields

Maxim Levitsky
2021-11-12T07:44:12Z

On Thu, 2021-11-11 at 14:52 +0100, Paolo Bonzini wrote:
> On 11/3/21 15:05, Emanuele Giuseppe Esposito wrote:
> > Note that in svm_set_nested_state() we want to cache the L2
> > save state only if we are in normal non guest mode, because
> > otherwise it is not touched.
>
> I think that call to nested_copy_vmcb_save_to_cache is not necessary at
> all, because svm->nested.save is not used afterwards and is not valid
> after VMRUN.

Yes, but since setting nested state is absolutely not performance critical,
having it do the same thing as normal VMRUN is always better.

Best regards,
Maxim Levitsky

>
> The relevant checks have already been done before:
>
> if (!(vcpu->arch.efer & EFER_SVME)) {
> /* GIF=1 and no guest mode are required if SVME=0. */
> if (kvm_state->flags != KVM_STATE_NESTED_GIF_SET)
> return -EINVAL;
> }
>
> ...
>
> /*
> * Processor state contains L2 state. Check that it is
> * valid for guest mode (see nested_vmcb_check_save).
> */
> cr0 = kvm_read_cr0(vcpu);
> if (((cr0 & X86_CR0_CD) == 0) && (cr0 & X86_CR0_NW))
> goto out_free;
>
> (and all other checks are done by KVM_SET_SREGS, KVM_SET_DEBUGREGS etc.)
>
> Paolo
>