public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: nVMX: Update MSR load counts on a VMCS switch
@ 2016-10-04 17:48 Jim Mattson
  2016-10-07 12:15 ` Radim Krčmář
  0 siblings, 1 reply; 2+ messages in thread
From: Jim Mattson @ 2016-10-04 17:48 UTC (permalink / raw)
  To: kvm; +Cc: Jim Mattson

When L0 establishes (or removes) an MSR entry in the VM-entry or VM-exit
MSR load lists, the change should affect the dormant VMCS as well as the
current VMCS. Moreover, the vmcs02 MSR-load addresses should be
initialized.

Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kvm/vmx.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 5cede40..bb60515 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -9928,6 +9928,15 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
 	vmx_set_constant_host_state(vmx);
 
 	/*
+	 * Set the MSR load/store lists to match L0's settings.
+	 */
+	vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
+	vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
+	vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
+	vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
+	vmcs_write64(VM_ENTRY_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.guest));
+
+	/*
 	 * HOST_RSP is normally set correctly in vmx_vcpu_run() just before
 	 * entry, but only if the current (host) sp changed from the value
 	 * we wrote last (vmx->host_rsp). This cache is no longer relevant
@@ -10754,6 +10763,8 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
 	load_vmcs12_host_state(vcpu, vmcs12);
 
 	/* Update any VMCS fields that might have changed while L2 ran */
+	vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
+	vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
 	vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset);
 	if (vmx->hv_deadline_tsc == -1)
 		vmcs_clear_bits(PIN_BASED_VM_EXEC_CONTROL,
-- 
2.8.0.rc3.226.g39d4020


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kvm: nVMX: Update MSR load counts on a VMCS switch
  2016-10-04 17:48 [PATCH] kvm: nVMX: Update MSR load counts on a VMCS switch Jim Mattson
@ 2016-10-07 12:15 ` Radim Krčmář
  0 siblings, 0 replies; 2+ messages in thread
From: Radim Krčmář @ 2016-10-07 12:15 UTC (permalink / raw)
  To: Jim Mattson; +Cc: kvm

2016-10-04 10:48-0700, Jim Mattson:
> When L0 establishes (or removes) an MSR entry in the VM-entry or VM-exit
> MSR load lists, the change should affect the dormant VMCS as well as the
> current VMCS. Moreover, the vmcs02 MSR-load addresses should be
> initialized.
> 
> Signed-off-by: Jim Mattson <jmattson@google.com>
> ---

The fixes seem correct and nested performance is already sad, so
continually overwriting few constants won't hurt ...

Applied to kvm/queue, thanks.

> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> @@ -9928,6 +9928,15 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
>  	vmx_set_constant_host_state(vmx);
>  
>  	/*
> +	 * Set the MSR load/store lists to match L0's settings.
> +	 */
> +	vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
> +	vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
> +	vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
> +	vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
> +	vmcs_write64(VM_ENTRY_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.guest));
> +	/*
>  	 * HOST_RSP is normally set correctly in vmx_vcpu_run() just before
>  	 * entry, but only if the current (host) sp changed from the value
>  	 * we wrote last (vmx->host_rsp). This cache is no longer relevant
> @@ -10754,6 +10763,8 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
>  	load_vmcs12_host_state(vcpu, vmcs12);
>  
>  	/* Update any VMCS fields that might have changed while L2 ran */
> +	vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
> +	vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
>  	vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset);
>  	if (vmx->hv_deadline_tsc == -1)
>  		vmcs_clear_bits(PIN_BASED_VM_EXEC_CONTROL,
> -- 
> 2.8.0.rc3.226.g39d4020
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-07 12:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-04 17:48 [PATCH] kvm: nVMX: Update MSR load counts on a VMCS switch Jim Mattson
2016-10-07 12:15 ` Radim Krčmář

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox