Re: [PATCH v3 7/9] KVM: nSVM: implement nested_svm_load_cr3() and use it for host->guest switch

Paolo Bonzini
2020-07-09T18:00:00Z

On 09/07/20 19:57, Paolo Bonzini wrote:
> On 09/07/20 16:53, Vitaly Kuznetsov wrote:
>> + if (nested_npt_enabled(svm))
>> + nested_svm_init_mmu_context(&svm->vcpu);
>> +
>> ret = nested_svm_load_cr3(&svm->vcpu, nested_vmcb->save.cr3,
>> nested_npt_enabled(svm));
>
> This needs to be done in svm_set_nested_state, so my suggestion is that
> the previous patch includes a call to nested_svm_load_cr3 in
> svm_set_nested_state, and this one adds the "if" inside
> nested_svm_load_cr3 itself.

Actually no, that doesn't work after the next patch. So the best option
is probably to extract nested_svm_init_mmu as a separate step in
enter_svm_guest_mode. This also leaves nested_prepare_vmcb_save as a
void function.

Paolo

>
> Paolo
>
>> @@ -364,13 +388,6 @@ static int nested_prepare_vmcb_save(struct vcpu_svm *svm, struct vmcb *nested_vm
>> static void nested_prepare_vmcb_control(struct vcpu_svm *svm)
>> {
>> const u32 mask = V_INTR_MASKING_MASK | V_GIF_ENABLE_MASK | V_GIF_MASK;
>> - if (nested_npt_enabled(svm))
>> - nested_svm_init_mmu_context(&svm->vcpu);
>> -
>> - /* Guest paging mode is active - reset mmu */
>> - kvm_mmu_reset_context(&svm->vcpu);
>> -
>> - svm_flush_tlb(&svm->vcpu);
>>
>