kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] VMX: cleanups and nested support improvements
@ 2016-10-28  4:00 Jan Dakinevich
  2016-10-28  4:00 ` [PATCH v2 1/2] KVM: VMX: clean up declaration of VPID/EPT invalidation types Jan Dakinevich
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jan Dakinevich @ 2016-10-28  4:00 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, kernellwp, lprosek, Jan Dakinevich

From: Jan Dakinevich <jan.dakinevich@gmail.com>

v2: taking into account the comments
v1: http://www.spinics.net/lists/kvm/msg138838.html

Jan Dakinevich (2):
  KVM: VMX: clean up declaration of VPID/EPT invalidation types
  KVM: nVMX: invvpid handling improvements

 arch/x86/include/asm/vmx.h |  5 ++++-
 arch/x86/kvm/vmx.c         | 36 ++++++++++++++++++++++++------------
 2 files changed, 28 insertions(+), 13 deletions(-)

-- 
1.9.1


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

* [PATCH v2 1/2] KVM: VMX: clean up declaration of VPID/EPT invalidation types
  2016-10-28  4:00 [PATCH v2 0/2] VMX: cleanups and nested support improvements Jan Dakinevich
@ 2016-10-28  4:00 ` Jan Dakinevich
  2016-11-22 16:28   ` Radim Krčmář
  2016-10-28  4:00 ` [PATCH v2 2/2] KVM: nVMX: invvpid handling improvements Jan Dakinevich
  2016-11-02  8:36 ` [PATCH v2 0/2] VMX: cleanups and nested support improvements Ladi Prosek
  2 siblings, 1 reply; 6+ messages in thread
From: Jan Dakinevich @ 2016-10-28  4:00 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, kernellwp, lprosek, Jan Dakinevich

From: Jan Dakinevich <jan.dakinevich@gmail.com>

 - Remove VMX_EPT_EXTENT_INDIVIDUAL_ADDR, since there is no such type of
   EPT invalidation

 - Add missing VPID types names

Signed-off-by: Jan Dakinevich <jan.dakinevich@gmail.com>
---
 arch/x86/include/asm/vmx.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index a002b07..6899cf1 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -399,10 +399,11 @@ enum vmcs_field {
 #define IDENTITY_PAGETABLE_PRIVATE_MEMSLOT	(KVM_USER_MEM_SLOTS + 2)
 
 #define VMX_NR_VPIDS				(1 << 16)
+#define VMX_VPID_EXTENT_INDIVIDUAL_ADDR		0
 #define VMX_VPID_EXTENT_SINGLE_CONTEXT		1
 #define VMX_VPID_EXTENT_ALL_CONTEXT		2
+#define VMX_VPID_EXTENT_SINGLE_NON_GLOBAL	3
 
-#define VMX_EPT_EXTENT_INDIVIDUAL_ADDR		0
 #define VMX_EPT_EXTENT_CONTEXT			1
 #define VMX_EPT_EXTENT_GLOBAL			2
 #define VMX_EPT_EXTENT_SHIFT			24
@@ -419,8 +420,10 @@ enum vmcs_field {
 #define VMX_EPT_EXTENT_GLOBAL_BIT		(1ull << 26)
 
 #define VMX_VPID_INVVPID_BIT                    (1ull << 0) /* (32 - 32) */
+#define VMX_VPID_EXTENT_INDIVIDUAL_ADDR_BIT     (1ull << 8) /* (40 - 32) */
 #define VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT      (1ull << 9) /* (41 - 32) */
 #define VMX_VPID_EXTENT_GLOBAL_CONTEXT_BIT      (1ull << 10) /* (42 - 32) */
+#define VMX_VPID_EXTENT_SINGLE_NON_GLOBAL_BIT   (1ull << 11) /* (43 - 32) */
 
 #define VMX_EPT_DEFAULT_GAW			3
 #define VMX_EPT_MAX_GAW				0x4
-- 
1.9.1


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

* [PATCH v2 2/2] KVM: nVMX: invvpid handling improvements
  2016-10-28  4:00 [PATCH v2 0/2] VMX: cleanups and nested support improvements Jan Dakinevich
  2016-10-28  4:00 ` [PATCH v2 1/2] KVM: VMX: clean up declaration of VPID/EPT invalidation types Jan Dakinevich
@ 2016-10-28  4:00 ` Jan Dakinevich
  2016-11-22 16:28   ` Radim Krčmář
  2016-11-02  8:36 ` [PATCH v2 0/2] VMX: cleanups and nested support improvements Ladi Prosek
  2 siblings, 1 reply; 6+ messages in thread
From: Jan Dakinevich @ 2016-10-28  4:00 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, kernellwp, lprosek, Jan Dakinevich

From: Jan Dakinevich <jan.dakinevich@gmail.com>

 - Expose all invalidation types to the L1

 - Reject invvpid instruction, if L1 passed zero vpid value to single
   context invalidations

Signed-off-by: Jan Dakinevich <jan.dakinevich@gmail.com>
---
 arch/x86/kvm/vmx.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index af1168e8..31f1782 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -132,6 +132,12 @@
 
 #define VMX_MISC_EMULATED_PREEMPTION_TIMER_RATE 5
 
+#define VMX_VPID_EXTENT_SUPPORTED_MASK		\
+	(VMX_VPID_EXTENT_INDIVIDUAL_ADDR_BIT |	\
+	VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT |	\
+	VMX_VPID_EXTENT_GLOBAL_CONTEXT_BIT |	\
+	VMX_VPID_EXTENT_SINGLE_NON_GLOBAL_BIT)
+
 /*
  * These 2 parameters are used to config the controls for Pause-Loop Exiting:
  * ple_gap:    upper bound on the amount of time between two successive
@@ -2838,8 +2844,7 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx)
 	 */
 	if (enable_vpid)
 		vmx->nested.nested_vmx_vpid_caps = VMX_VPID_INVVPID_BIT |
-				VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT |
-				VMX_VPID_EXTENT_GLOBAL_CONTEXT_BIT;
+			VMX_VPID_EXTENT_SUPPORTED_MASK;
 	else
 		vmx->nested.nested_vmx_vpid_caps = 0;
 
@@ -7720,7 +7725,8 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
 	vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
 	type = kvm_register_readl(vcpu, (vmx_instruction_info >> 28) & 0xf);
 
-	types = (vmx->nested.nested_vmx_vpid_caps >> 8) & 0x7;
+	types = (vmx->nested.nested_vmx_vpid_caps &
+			VMX_VPID_EXTENT_SUPPORTED_MASK) >> 8;
 
 	if (!(types & (1UL << type))) {
 		nested_vmx_failValid(vcpu,
@@ -7742,21 +7748,27 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
 	}
 
 	switch (type) {
+	case VMX_VPID_EXTENT_INDIVIDUAL_ADDR:
 	case VMX_VPID_EXTENT_SINGLE_CONTEXT:
-		/*
-		 * Old versions of KVM use the single-context version so we
-		 * have to support it; just treat it the same as all-context.
-		 */
+	case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL:
+		if (!vpid) {
+			nested_vmx_failValid(vcpu,
+				VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID);
+			skip_emulated_instruction(vcpu);
+			return 1;
+		}
+		break;
 	case VMX_VPID_EXTENT_ALL_CONTEXT:
-		__vmx_flush_tlb(vcpu, to_vmx(vcpu)->nested.vpid02);
-		nested_vmx_succeed(vcpu);
 		break;
 	default:
-		/* Trap individual address invalidation invvpid calls */
-		BUG_ON(1);
-		break;
+		WARN_ON_ONCE(1);
+		skip_emulated_instruction(vcpu);
+		return 1;
 	}
 
+	__vmx_flush_tlb(vcpu, vmx->nested.vpid02);
+	nested_vmx_succeed(vcpu);
+
 	skip_emulated_instruction(vcpu);
 	return 1;
 }
-- 
1.9.1


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

* Re: [PATCH v2 0/2] VMX: cleanups and nested support improvements
  2016-10-28  4:00 [PATCH v2 0/2] VMX: cleanups and nested support improvements Jan Dakinevich
  2016-10-28  4:00 ` [PATCH v2 1/2] KVM: VMX: clean up declaration of VPID/EPT invalidation types Jan Dakinevich
  2016-10-28  4:00 ` [PATCH v2 2/2] KVM: nVMX: invvpid handling improvements Jan Dakinevich
@ 2016-11-02  8:36 ` Ladi Prosek
  2 siblings, 0 replies; 6+ messages in thread
From: Ladi Prosek @ 2016-11-02  8:36 UTC (permalink / raw)
  To: Jan Dakinevich; +Cc: KVM list, Paolo Bonzini, Radim Krcmar, Wanpeng Li

On Fri, Oct 28, 2016 at 6:00 AM, Jan Dakinevich
<jan.dakinevich@gmail.com> wrote:
> From: Jan Dakinevich <jan.dakinevich@gmail.com>
>
> v2: taking into account the comments
> v1: http://www.spinics.net/lists/kvm/msg138838.html
>
> Jan Dakinevich (2):
>   KVM: VMX: clean up declaration of VPID/EPT invalidation types
>   KVM: nVMX: invvpid handling improvements
>
>  arch/x86/include/asm/vmx.h |  5 ++++-
>  arch/x86/kvm/vmx.c         | 36 ++++++++++++++++++++++++------------
>  2 files changed, 28 insertions(+), 13 deletions(-)

Tested with a Hyper-V enabled Windows Server 2016 guest.

Tested-by: Ladi Prosek <lprosek@redhat.com>

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

* Re: [PATCH v2 2/2] KVM: nVMX: invvpid handling improvements
  2016-10-28  4:00 ` [PATCH v2 2/2] KVM: nVMX: invvpid handling improvements Jan Dakinevich
@ 2016-11-22 16:28   ` Radim Krčmář
  0 siblings, 0 replies; 6+ messages in thread
From: Radim Krčmář @ 2016-11-22 16:28 UTC (permalink / raw)
  To: Jan Dakinevich; +Cc: kvm, pbonzini, kernellwp, lprosek

2016-10-28 07:00+0300, Jan Dakinevich:
> From: Jan Dakinevich <jan.dakinevich@gmail.com>
> 
>  - Expose all invalidation types to the L1
> 
>  - Reject invvpid instruction, if L1 passed zero vpid value to single
>    context invalidations
> 
> Signed-off-by: Jan Dakinevich <jan.dakinevich@gmail.com>
> ---
>  arch/x86/kvm/vmx.c | 36 ++++++++++++++++++++++++------------
>  1 file changed, 24 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> @@ -132,6 +132,12 @@
>  
>  #define VMX_MISC_EMULATED_PREEMPTION_TIMER_RATE 5
>  
> +#define VMX_VPID_EXTENT_SUPPORTED_MASK		\
> +	(VMX_VPID_EXTENT_INDIVIDUAL_ADDR_BIT |	\
> +	VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT |	\
> +	VMX_VPID_EXTENT_GLOBAL_CONTEXT_BIT |	\
> +	VMX_VPID_EXTENT_SINGLE_NON_GLOBAL_BIT)
> +
>  /*
>   * These 2 parameters are used to config the controls for Pause-Loop Exiting:
>   * ple_gap:    upper bound on the amount of time between two successive
> @@ -2838,8 +2844,7 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx)
>  	 */
>  	if (enable_vpid)
>  		vmx->nested.nested_vmx_vpid_caps = VMX_VPID_INVVPID_BIT |
> -				VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT |
> -				VMX_VPID_EXTENT_GLOBAL_CONTEXT_BIT;
> +			VMX_VPID_EXTENT_SUPPORTED_MASK;
>  	else
>  		vmx->nested.nested_vmx_vpid_caps = 0;
>  
> @@ -7720,7 +7725,8 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
>  	vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
>  	type = kvm_register_readl(vcpu, (vmx_instruction_info >> 28) & 0xf);
>  
> -	types = (vmx->nested.nested_vmx_vpid_caps >> 8) & 0x7;
> +	types = (vmx->nested.nested_vmx_vpid_caps &
> +			VMX_VPID_EXTENT_SUPPORTED_MASK) >> 8;
>  
>  	if (!(types & (1UL << type))) {

Sorry for the late review.

This condition changed in 4.9-rc2, with 85c856b39b47 ("kvm: nVMX: Fix
kernel panics induced by illegal INVEPT/INVVPID types").

I applied the patch to kvm/queue without any changes as I think it
didn't affect this patch.

>  		nested_vmx_failValid(vcpu,
> @@ -7742,21 +7748,27 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
>  	}
>  
>  	switch (type) {
> +	case VMX_VPID_EXTENT_INDIVIDUAL_ADDR:
>  	case VMX_VPID_EXTENT_SINGLE_CONTEXT:
> -		/*
> -		 * Old versions of KVM use the single-context version so we
> -		 * have to support it; just treat it the same as all-context.
> -		 */
> +	case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL:
> +		if (!vpid) {
> +			nested_vmx_failValid(vcpu,
> +				VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID);
> +			skip_emulated_instruction(vcpu);
> +			return 1;

In v1, I said here:

  (Just break and share the code.)

by the code I meant

  skip_emulated_instruction(vcpu);
  return 1;

> +		}
> +		break;
>  	case VMX_VPID_EXTENT_ALL_CONTEXT:
> -		__vmx_flush_tlb(vcpu, to_vmx(vcpu)->nested.vpid02);
> -		nested_vmx_succeed(vcpu);
>  		break;

as I actually prefer v1, which had here:

  		 __vmx_flush_tlb(vcpu, vmx->nested.vpid02);
  		 nested_vmx_succeed(vcpu);
  		 break;

>  	default:
> -		/* Trap individual address invalidation invvpid calls */
> -		BUG_ON(1);
> -		break;
> +		WARN_ON_ONCE(1);
> +		skip_emulated_instruction(vcpu);
> +		return 1;

You could also omit the skip and return here ...

>  	}
>  
> +	__vmx_flush_tlb(vcpu, vmx->nested.vpid02);
> +	nested_vmx_succeed(vcpu);
> +

... if this block was in the switch.
Do you wish to change the code?

Thanks.

>  	skip_emulated_instruction(vcpu);
>  	return 1;
>  }

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

* Re: [PATCH v2 1/2] KVM: VMX: clean up declaration of VPID/EPT invalidation types
  2016-10-28  4:00 ` [PATCH v2 1/2] KVM: VMX: clean up declaration of VPID/EPT invalidation types Jan Dakinevich
@ 2016-11-22 16:28   ` Radim Krčmář
  0 siblings, 0 replies; 6+ messages in thread
From: Radim Krčmář @ 2016-11-22 16:28 UTC (permalink / raw)
  To: Jan Dakinevich; +Cc: kvm, pbonzini, kernellwp, lprosek

2016-10-28 07:00+0300, Jan Dakinevich:
> From: Jan Dakinevich <jan.dakinevich@gmail.com>
> 
>  - Remove VMX_EPT_EXTENT_INDIVIDUAL_ADDR, since there is no such type of
>    EPT invalidation
> 
>  - Add missing VPID types names
> 
> Signed-off-by: Jan Dakinevich <jan.dakinevich@gmail.com>
> ---

Applied to kvm/queue, thanks.

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

end of thread, other threads:[~2016-11-22 16:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-28  4:00 [PATCH v2 0/2] VMX: cleanups and nested support improvements Jan Dakinevich
2016-10-28  4:00 ` [PATCH v2 1/2] KVM: VMX: clean up declaration of VPID/EPT invalidation types Jan Dakinevich
2016-11-22 16:28   ` Radim Krčmář
2016-10-28  4:00 ` [PATCH v2 2/2] KVM: nVMX: invvpid handling improvements Jan Dakinevich
2016-11-22 16:28   ` Radim Krčmář
2016-11-02  8:36 ` [PATCH v2 0/2] VMX: cleanups and nested support improvements Ladi Prosek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).