public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: vmx: fix VPID is 0000H in non-root operation
@ 2015-09-16 11:31 Wanpeng Li
  2015-09-16 12:32 ` Jan Kiszka
  0 siblings, 1 reply; 4+ messages in thread
From: Wanpeng Li @ 2015-09-16 11:31 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Jan Kiszka, Bandan Das, Wincy Van, kvm, linux-kernel, Wanpeng Li

Reference SDM 28.1:

The current VPID is 0000H in the following situations:
— Outside VMX operation. (This includes operation in system-management 
  mode under the default treatment of SMIs and SMM with VMX operation; 
  see Section 34.14.)
— In VMX root operation.
— In VMX non-root operation when the “enable VPID” VM-execution control 
  is 0.

The VPID should never be 0000H in non-root operation when "enable VPID" 
VM-execution control is 1. However, commit (34a1cd60: 'kvm: x86: vmx: 
move some vmx setting from vmx_init() to hardware_setup()') remove the 
codes which reserve 0000H for VMX root operation. 

This patch fix it by reintroducing reserve 0000H for VMX root operation.

Reported-by: Wincy Van <fanwenyi0529@gmail.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
 arch/x86/kvm/vmx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 9ff6a3f..a63b9ca 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6056,6 +6056,8 @@ static __init int hardware_setup(void)
 	memcpy(vmx_msr_bitmap_longmode_x2apic,
 			vmx_msr_bitmap_longmode, PAGE_SIZE);
 
+	set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */
+
 	if (enable_apicv) {
 		for (msr = 0x800; msr <= 0x8ff; msr++)
 			vmx_disable_intercept_msr_read_x2apic(msr);
-- 
1.9.1


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

* Re: [PATCH] KVM: vmx: fix VPID is 0000H in non-root operation
  2015-09-16 11:31 [PATCH] KVM: vmx: fix VPID is 0000H in non-root operation Wanpeng Li
@ 2015-09-16 12:32 ` Jan Kiszka
  2015-09-16 12:42   ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kiszka @ 2015-09-16 12:32 UTC (permalink / raw)
  To: Wanpeng Li, Paolo Bonzini; +Cc: Bandan Das, Wincy Van, kvm, linux-kernel

On 2015-09-16 13:31, Wanpeng Li wrote:
> Reference SDM 28.1:
> 
> The current VPID is 0000H in the following situations:
> — Outside VMX operation. (This includes operation in system-management 
>   mode under the default treatment of SMIs and SMM with VMX operation; 
>   see Section 34.14.)
> — In VMX root operation.
> — In VMX non-root operation when the “enable VPID” VM-execution control 
>   is 0.
> 
> The VPID should never be 0000H in non-root operation when "enable VPID" 
> VM-execution control is 1. However, commit (34a1cd60: 'kvm: x86: vmx: 
> move some vmx setting from vmx_init() to hardware_setup()') remove the 
> codes which reserve 0000H for VMX root operation. 
> 
> This patch fix it by reintroducing reserve 0000H for VMX root operation.
> 
> Reported-by: Wincy Van <fanwenyi0529@gmail.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
>  arch/x86/kvm/vmx.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 9ff6a3f..a63b9ca 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -6056,6 +6056,8 @@ static __init int hardware_setup(void)
>  	memcpy(vmx_msr_bitmap_longmode_x2apic,
>  			vmx_msr_bitmap_longmode, PAGE_SIZE);
>  
> +	set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */
> +
>  	if (enable_apicv) {
>  		for (msr = 0x800; msr <= 0x8ff; msr++)
>  			vmx_disable_intercept_msr_read_x2apic(msr);
> 

Good point.

BTW, what will happen if allocate_vpid runs out of free slots and
returns 0? Will we always fail then...?

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux

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

* Re: [PATCH] KVM: vmx: fix VPID is 0000H in non-root operation
  2015-09-16 12:32 ` Jan Kiszka
@ 2015-09-16 12:42   ` Paolo Bonzini
  2015-09-16 13:53     ` Wanpeng Li
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2015-09-16 12:42 UTC (permalink / raw)
  To: Jan Kiszka, Wanpeng Li; +Cc: Bandan Das, Wincy Van, kvm, linux-kernel



On 16/09/2015 14:32, Jan Kiszka wrote:
> 
> BTW, what will happen if allocate_vpid runs out of free slots and
> returns 0? Will we always fail then...?

The return value of vmx_secondary_exec_control will not have
SECONDARY_EXEC_ENABLE_VPID, so it's okay.  However, I think
we need this in the nested VPID patches:

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index c23482cda1a7..e6859b45b00b 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -9456,7 +9460,7 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
 	else
 		vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset);
 
-	if (enable_vpid) {
+	if (vmx->nested.vpid02) {
 		/*
 		 * There is no direct mapping between vpid02 and vpid12, the
 		 * vpid02 is per-vCPU for L0 and reused while the value of

Paolo

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

* Re: [PATCH] KVM: vmx: fix VPID is 0000H in non-root operation
  2015-09-16 12:42   ` Paolo Bonzini
@ 2015-09-16 13:53     ` Wanpeng Li
  0 siblings, 0 replies; 4+ messages in thread
From: Wanpeng Li @ 2015-09-16 13:53 UTC (permalink / raw)
  To: Paolo Bonzini, Jan Kiszka; +Cc: Bandan Das, Wincy Van, kvm, linux-kernel

On 9/16/15 8:42 PM, Paolo Bonzini wrote:
>
> On 16/09/2015 14:32, Jan Kiszka wrote:
>> BTW, what will happen if allocate_vpid runs out of free slots and
>> returns 0? Will we always fail then...?
> The return value of vmx_secondary_exec_control will not have
> SECONDARY_EXEC_ENABLE_VPID, so it's okay.  However, I think
> we need this in the nested VPID patches:
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index c23482cda1a7..e6859b45b00b 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -9456,7 +9460,7 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
>   	else
>   		vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset);
>
> -	if (enable_vpid) {
> +	if (vmx->nested.vpid02) {
>   		/*
>   		 * There is no direct mapping between vpid02 and vpid12, the
>   		 * vpid02 is per-vCPU for L0 and reused while the value of
>

Looks good to me.

Regards,
Wanpeng Li

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

end of thread, other threads:[~2015-09-16 13:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-16 11:31 [PATCH] KVM: vmx: fix VPID is 0000H in non-root operation Wanpeng Li
2015-09-16 12:32 ` Jan Kiszka
2015-09-16 12:42   ` Paolo Bonzini
2015-09-16 13:53     ` Wanpeng Li

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