diff mbox

nVMX: Keep arch.pat in sync on L1-L2 switches

Message ID 51FE7087.3060008@web.de (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Kiszka Aug. 4, 2013, 3:17 p.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

When asking vmx to load the PAT MSR for us while switching from L1 to L2
or vice versa, we have to update arch.pat as well as it may later be
used again to load or read out the MSR content.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

Arthur, please add your tested-by also officially.

 arch/x86/kvm/vmx.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

Comments

Arthur Chunqi Li Aug. 5, 2013, 2:19 a.m. UTC | #1
On Sun, Aug 4, 2013 at 11:17 PM, Jan Kiszka <jan.kiszka@web.de> wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
>
> When asking vmx to load the PAT MSR for us while switching from L1 to L2
> or vice versa, we have to update arch.pat as well as it may later be
> used again to load or read out the MSR content.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>
> Arthur, please add your tested-by also officially.
This patch is generally good expect that we need to add
VM_EXIT_LOAD_IA32_PAT/VM_EXIT_SAVE_IA32_PAT to
nested_vmx_exit_ctls_high in function nested_vmx_setup_ctls_msrs() to
enable these two features. Currently only VM_ENTRY_LOAD_IA32_PAT is
enabled while all three are implemented.

Arthur
>
>  arch/x86/kvm/vmx.c |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 45fd70c..396572d 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -7535,9 +7535,10 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
>         vmcs_write32(VM_ENTRY_CONTROLS, vmcs12->vm_entry_controls |
>                 (vmcs_config.vmentry_ctrl & ~VM_ENTRY_IA32E_MODE));
>
> -       if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT)
> +       if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT) {
>                 vmcs_write64(GUEST_IA32_PAT, vmcs12->guest_ia32_pat);
> -       else if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT)
> +               vcpu->arch.pat = vmcs12->guest_ia32_pat;
> +       } else if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT)
>                 vmcs_write64(GUEST_IA32_PAT, vmx->vcpu.arch.pat);
>
>
> @@ -8025,8 +8026,10 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
>         vmcs_writel(GUEST_IDTR_BASE, vmcs12->host_idtr_base);
>         vmcs_writel(GUEST_GDTR_BASE, vmcs12->host_gdtr_base);
>
> -       if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT)
> +       if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT) {
>                 vmcs_write64(GUEST_IA32_PAT, vmcs12->host_ia32_pat);
> +               vcpu->arch.pat = vmcs12->host_ia32_pat;
> +       }
>         if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL)
>                 vmcs_write64(GUEST_IA32_PERF_GLOBAL_CTRL,
>                         vmcs12->host_ia32_perf_global_ctrl);
> --
> 1.7.3.4
--
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
Jan Kiszka Aug. 5, 2013, 6:27 a.m. UTC | #2
On 2013-08-05 04:19, Arthur Chunqi Li wrote:
> On Sun, Aug 4, 2013 at 11:17 PM, Jan Kiszka <jan.kiszka@web.de> wrote:
>> From: Jan Kiszka <jan.kiszka@siemens.com>
>>
>> When asking vmx to load the PAT MSR for us while switching from L1 to L2
>> or vice versa, we have to update arch.pat as well as it may later be
>> used again to load or read out the MSR content.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>>
>> Arthur, please add your tested-by also officially.
> This patch is generally good expect that we need to add
> VM_EXIT_LOAD_IA32_PAT/VM_EXIT_SAVE_IA32_PAT to
> nested_vmx_exit_ctls_high in function nested_vmx_setup_ctls_msrs() to
> enable these two features. Currently only VM_ENTRY_LOAD_IA32_PAT is
> enabled while all three are implemented.

Yes, feel free to follow up with a corresponding patch.

Jan
Gleb Natapov Aug. 5, 2013, 8:40 a.m. UTC | #3
On Sun, Aug 04, 2013 at 05:17:27PM +0200, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> When asking vmx to load the PAT MSR for us while switching from L1 to L2
> or vice versa, we have to update arch.pat as well as it may later be
> used again to load or read out the MSR content.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Reviewed-by: Gleb Natapov <gleb@redhat.com>

> ---
> 
> Arthur, please add your tested-by also officially.
> 
>  arch/x86/kvm/vmx.c |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 45fd70c..396572d 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -7535,9 +7535,10 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
>  	vmcs_write32(VM_ENTRY_CONTROLS, vmcs12->vm_entry_controls |
>  		(vmcs_config.vmentry_ctrl & ~VM_ENTRY_IA32E_MODE));
>  
> -	if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT)
> +	if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT) {
>  		vmcs_write64(GUEST_IA32_PAT, vmcs12->guest_ia32_pat);
> -	else if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT)
> +		vcpu->arch.pat = vmcs12->guest_ia32_pat;
> +	} else if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT)
>  		vmcs_write64(GUEST_IA32_PAT, vmx->vcpu.arch.pat);
>  
>  
> @@ -8025,8 +8026,10 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
>  	vmcs_writel(GUEST_IDTR_BASE, vmcs12->host_idtr_base);
>  	vmcs_writel(GUEST_GDTR_BASE, vmcs12->host_gdtr_base);
>  
> -	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT)
> +	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT) {
>  		vmcs_write64(GUEST_IA32_PAT, vmcs12->host_ia32_pat);
> +		vcpu->arch.pat = vmcs12->host_ia32_pat;
> +	}
>  	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL)
>  		vmcs_write64(GUEST_IA32_PERF_GLOBAL_CTRL,
>  			vmcs12->host_ia32_perf_global_ctrl);
> -- 
> 1.7.3.4

--
			Gleb.
--
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
Arthur Chunqi Li Aug. 6, 2013, 10:45 a.m. UTC | #4
On Sun, Aug 4, 2013 at 11:17 PM, Jan Kiszka <jan.kiszka@web.de> wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
>
> When asking vmx to load the PAT MSR for us while switching from L1 to L2
> or vice versa, we have to update arch.pat as well as it may later be
> used again to load or read out the MSR content.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Tested-by: Arthur Chunqi Li <yzt356@gmail.com>
    Should cooperate with patch
http://www.mail-archive.com/kvm@vger.kernel.org/msg94349.html,
VM_EXIT_SAVE_IA32_PAT and VM_EXIT_LOAD_IA32_PAT should be advertised.

> ---
>
> Arthur, please add your tested-by also officially.
>
>  arch/x86/kvm/vmx.c |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 45fd70c..396572d 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -7535,9 +7535,10 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
>         vmcs_write32(VM_ENTRY_CONTROLS, vmcs12->vm_entry_controls |
>                 (vmcs_config.vmentry_ctrl & ~VM_ENTRY_IA32E_MODE));
>
> -       if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT)
> +       if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT) {
>                 vmcs_write64(GUEST_IA32_PAT, vmcs12->guest_ia32_pat);
> -       else if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT)
> +               vcpu->arch.pat = vmcs12->guest_ia32_pat;
> +       } else if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT)
>                 vmcs_write64(GUEST_IA32_PAT, vmx->vcpu.arch.pat);
>
>
> @@ -8025,8 +8026,10 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
>         vmcs_writel(GUEST_IDTR_BASE, vmcs12->host_idtr_base);
>         vmcs_writel(GUEST_GDTR_BASE, vmcs12->host_gdtr_base);
>
> -       if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT)
> +       if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT) {
>                 vmcs_write64(GUEST_IA32_PAT, vmcs12->host_ia32_pat);
> +               vcpu->arch.pat = vmcs12->host_ia32_pat;
> +       }
>         if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL)
>                 vmcs_write64(GUEST_IA32_PERF_GLOBAL_CTRL,
>                         vmcs12->host_ia32_perf_global_ctrl);
> --
> 1.7.3.4
--
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
diff mbox

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 45fd70c..396572d 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -7535,9 +7535,10 @@  static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
 	vmcs_write32(VM_ENTRY_CONTROLS, vmcs12->vm_entry_controls |
 		(vmcs_config.vmentry_ctrl & ~VM_ENTRY_IA32E_MODE));
 
-	if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT)
+	if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT) {
 		vmcs_write64(GUEST_IA32_PAT, vmcs12->guest_ia32_pat);
-	else if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT)
+		vcpu->arch.pat = vmcs12->guest_ia32_pat;
+	} else if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT)
 		vmcs_write64(GUEST_IA32_PAT, vmx->vcpu.arch.pat);
 
 
@@ -8025,8 +8026,10 @@  static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
 	vmcs_writel(GUEST_IDTR_BASE, vmcs12->host_idtr_base);
 	vmcs_writel(GUEST_GDTR_BASE, vmcs12->host_gdtr_base);
 
-	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT)
+	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT) {
 		vmcs_write64(GUEST_IA32_PAT, vmcs12->host_ia32_pat);
+		vcpu->arch.pat = vmcs12->host_ia32_pat;
+	}
 	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL)
 		vmcs_write64(GUEST_IA32_PERF_GLOBAL_CTRL,
 			vmcs12->host_ia32_perf_global_ctrl);