diff mbox series

[v2,4/7] KVM: nVMX: Force enlightened VMCS sync from nested_vmx_failValid()

Message ID 20210517135054.1914802-5-vkuznets@redhat.com (mailing list archive)
State New, archived
Headers show
Series KVM: nVMX: Fixes for nested state migration when eVMCS is in use | expand

Commit Message

Vitaly Kuznetsov May 17, 2021, 1:50 p.m. UTC
'need_vmcs12_to_shadow_sync' is used for both shadow and enlightened
VMCS sync when we exit to L1. The comment in nested_vmx_failValid()
validly states why shadow vmcs sync can be omitted but this doesn't
apply to enlightened VMCS as it 'shadows' all VMCS12 fields.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kvm/vmx/nested.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Maxim Levitsky May 24, 2021, 12:27 p.m. UTC | #1
On Mon, 2021-05-17 at 15:50 +0200, Vitaly Kuznetsov wrote:
> 'need_vmcs12_to_shadow_sync' is used for both shadow and enlightened
> VMCS sync when we exit to L1. The comment in nested_vmx_failValid()
> validly states why shadow vmcs sync can be omitted but this doesn't
> apply to enlightened VMCS as it 'shadows' all VMCS12 fields.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  arch/x86/kvm/vmx/nested.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index ec476f64df73..eb2d25a93356 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -194,9 +194,13 @@ static int nested_vmx_failValid(struct kvm_vcpu *vcpu,
>  			| X86_EFLAGS_ZF);
>  	get_vmcs12(vcpu)->vm_instruction_error = vm_instruction_error;
>  	/*
> -	 * We don't need to force a shadow sync because
> -	 * VM_INSTRUCTION_ERROR is not shadowed
> +	 * We don't need to force sync to shadow VMCS because
> +	 * VM_INSTRUCTION_ERROR is not shadowed. Enlightened VMCS 'shadows' all
> +	 * fields and thus must be synced.
>  	 */
> +	if (nested_evmcs_is_used(to_vmx(vcpu)))
> +		to_vmx(vcpu)->nested.need_vmcs12_to_shadow_sync = true;

Cool, this is a bug that I noticed too while reviewing
previous patches in this series.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>

Best regards,
	Maxim Levitsky

> +
>  	return kvm_skip_emulated_instruction(vcpu);
>  }
>
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index ec476f64df73..eb2d25a93356 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -194,9 +194,13 @@  static int nested_vmx_failValid(struct kvm_vcpu *vcpu,
 			| X86_EFLAGS_ZF);
 	get_vmcs12(vcpu)->vm_instruction_error = vm_instruction_error;
 	/*
-	 * We don't need to force a shadow sync because
-	 * VM_INSTRUCTION_ERROR is not shadowed
+	 * We don't need to force sync to shadow VMCS because
+	 * VM_INSTRUCTION_ERROR is not shadowed. Enlightened VMCS 'shadows' all
+	 * fields and thus must be synced.
 	 */
+	if (nested_evmcs_is_used(to_vmx(vcpu)))
+		to_vmx(vcpu)->nested.need_vmcs12_to_shadow_sync = true;
+
 	return kvm_skip_emulated_instruction(vcpu);
 }