mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/hyper-v: Don't WARN on VM-Enter if eVMCS sees VMFUNC[63:32] != 0
@ 2026-10-20 19:34 Manuel Andreas
  2026-10-20 19:36 ` Manuel Andreas
  2026-10-20 22:56 ` Sean Christopherson
  0 siblings, 2 replies; 3+ messages in thread
From: Manuel Andreas @ 2026-10-20 19:34 UTC (permalink / raw)
  To: kvm, linux-kernel, pbonzini, Sean Christopherson, Vitaly Kuznetsov

With the necessary Hyper-V extensions for eVMCS enabled, an L1 guest can
trivially fire a WARN_ON_ONCE in nested_evmcs_check_controls.
While vmcs12->vm_function_control is technically already sanity checked in
nested.c, that check is only performed if VMFUNC functionality is at all enabled
in the secondary processor controls of vmcs12.

vmcs12->vm_function_control seems to only be utilized in the handling
of a VMFUNC initiated from L2, but here a function other than 0 will
just end up in a failure case either way, regardless of whether or not
it is permissive in vmcs12->vm_function_control.
Therefore, the check has no reason to trigger a warning at all.

This patch simply removes the WARN_ON_ONCE and keeps the check.

Fixes: 3ff8a13d41b2 ("KVM: nVMX: WARN once and fail VM-Enter if eVMCS sees VMFUNC[63:32] != 0")
Signed-off-by: Manuel Andreas <manuel.andreas@tum.de>
---
 arch/x86/kvm/vmx/hyperv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/hyperv.c b/arch/x86/kvm/vmx/hyperv.c
index fa41d036acd4..008a06924eb4 100644
--- a/arch/x86/kvm/vmx/hyperv.c
+++ b/arch/x86/kvm/vmx/hyperv.c
@@ -186,7 +186,7 @@ int nested_evmcs_check_controls(struct vmcs12 *vmcs12)
 	 * controls in bits 63:32, i.e. dropping those bits on the consistency
 	 * check is intentional.
 	 */
-	if (WARN_ON_ONCE(vmcs12->vm_function_control >> 32))
+	if (vmcs12->vm_function_control >> 32)
 		return -EINVAL;
 
 	if (CC(!nested_evmcs_is_valid_controls(EVMCS_VMFUNC,
-- 
2.56.0


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

* Re: [PATCH] x86/hyper-v: Don't WARN on VM-Enter if eVMCS sees VMFUNC[63:32] != 0
  2026-10-20 19:34 [PATCH] x86/hyper-v: Don't WARN on VM-Enter if eVMCS sees VMFUNC[63:32] != 0 Manuel Andreas
@ 2026-10-20 19:36 ` Manuel Andreas
  2026-10-20 22:56 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Manuel Andreas @ 2026-10-20 19:36 UTC (permalink / raw)
  To: kvm, linux-kernel, pbonzini, Sean Christopherson, Vitaly Kuznetsov

If relevant I utilized the following KVM unit test to trigger the WARN_ON_ONCE:

---
 x86/unittests.cfg |  6 ++++++
 x86/vmx.h         |  1 +
 x86/vmx_tests.c   | 17 +++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index ae731a93..e46ecad1 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -482,6 +482,12 @@ arch = x86_64
 groups = vmx nested_exception
 check = /sys/module/kvm_intel/parameters/allow_smaller_maxphyaddr=Y

+[vmx_hyperv_vm_func_ctrls_warn]
+file = vmx.flat
+extra_params = -cpu max,+vmx,hv-vapic,hv-evmcs -append vmx_hyperv_vm_func_ctrls_warn
+arch = x86_64
+groups = vmx
+
 [debug]
 file = debug.flat
 arch = x86_64
diff --git a/x86/vmx.h b/x86/vmx.h
index f27ecd72..8d26b1a5 100644
--- a/x86/vmx.h
+++ b/x86/vmx.h
@@ -207,6 +207,7 @@ enum Encoding {
 	APIC_VIRT_ADDR		= 0x2012ul,
 	APIC_ACCS_ADDR		= 0x2014ul,
 	POSTED_INTR_DESC_ADDR	= 0x2016ul,
+	VM_FUNCTION_CONTROL     = 0x2018ul,
 	EPTP			= 0x201aul,
 	EPTP_HI			= 0x201bul,
 	VMREAD_BITMAP           = 0x2026ul,
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 2c0feca0..287336be 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -12084,6 +12084,22 @@ static void vmx_cet_test(void)
 	test_set_guest_finished();
 }

+static void vmx_hyperv_vm_func_ctrls_warn_guest(void) {
+	vmcall();
+}
+
+static void vmx_hyperv_vm_func_ctrls_warn(void)
+{
+	/* Set the unsupported bit */
+	vmcs_write(VM_FUNCTION_CONTROL, 1UL << 32UL);
+
+	test_set_guest(vmx_hyperv_vm_func_ctrls_warn_guest);
+	enter_guest();
+
+	test_set_guest_finished();
+	report(true, "hyperv warn on should have triggered!");
+}
+
 #define TEST(name) { #name, .v2 = name }

 /* name/init/guest_main/exit_handler/vmfail_handler */
@@ -12202,5 +12218,6 @@ struct vmx_test vmx_tests[] = {
 	TEST(vmx_canonical_test),
 	/* "Load CET" VM-entry/exit controls tests. */
 	TEST(vmx_cet_test),
+	TEST(vmx_hyperv_vm_func_ctrls_warn),
 	{ NULL, NULL, NULL, NULL },
 };
--
2.47.3

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

* Re: [PATCH] x86/hyper-v: Don't WARN on VM-Enter if eVMCS sees VMFUNC[63:32] != 0
  2026-10-20 19:34 [PATCH] x86/hyper-v: Don't WARN on VM-Enter if eVMCS sees VMFUNC[63:32] != 0 Manuel Andreas
  2026-10-20 19:36 ` Manuel Andreas
@ 2026-10-20 22:56 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2026-10-20 22:56 UTC (permalink / raw)
  To: Manuel Andreas; +Cc: kvm, linux-kernel, pbonzini, Vitaly Kuznetsov

On Tue, Oct 20, 2026, Manuel Andreas wrote:
> With the necessary Hyper-V extensions for eVMCS enabled, an L1 guest can
> trivially fire a WARN_ON_ONCE in nested_evmcs_check_controls.
> While vmcs12->vm_function_control is technically already sanity checked in
> nested.c, that check is only performed if VMFUNC functionality is at all enabled
> in the secondary processor controls of vmcs12.
> 
> vmcs12->vm_function_control seems to only be utilized in the handling
> of a VMFUNC initiated from L2, but here a function other than 0 will
> just end up in a failure case either way, regardless of whether or not
> it is permissive in vmcs12->vm_function_control.
> Therefore, the check has no reason to trigger a warning at all.
> 
> This patch simply removes the WARN_ON_ONCE and keeps the check.
> 
> Fixes: 3ff8a13d41b2 ("KVM: nVMX: WARN once and fail VM-Enter if eVMCS sees VMFUNC[63:32] != 0")
> Signed-off-by: Manuel Andreas <manuel.andreas@tum.de>
> ---
>  arch/x86/kvm/vmx/hyperv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/hyperv.c b/arch/x86/kvm/vmx/hyperv.c
> index fa41d036acd4..008a06924eb4 100644
> --- a/arch/x86/kvm/vmx/hyperv.c
> +++ b/arch/x86/kvm/vmx/hyperv.c
> @@ -186,7 +186,7 @@ int nested_evmcs_check_controls(struct vmcs12 *vmcs12)
>  	 * controls in bits 63:32, i.e. dropping those bits on the consistency
>  	 * check is intentional.
>  	 */
> -	if (WARN_ON_ONCE(vmcs12->vm_function_control >> 32))

I think the WARN is correct, this code is broken.  Unless I'm missing some eVMCS
magic/quirk, this, and the secondary controls check, should be conditioned on the
field actually being used.

This, over two patches?

diff --git a/arch/x86/kvm/vmx/hyperv.c b/arch/x86/kvm/vmx/hyperv.c
index fa41d036acd4..a1daf8f2ec5a 100644
--- a/arch/x86/kvm/vmx/hyperv.c
+++ b/arch/x86/kvm/vmx/hyperv.c
@@ -169,7 +169,8 @@ int nested_evmcs_check_controls(struct vmcs12 *vmcs12)
 					       vmcs12->cpu_based_vm_exec_control)))
 		return -EINVAL;
 
-	if (CC(!nested_evmcs_is_valid_controls(EVMCS_2NDEXEC,
+	if (nested_cpu_has(vmcs12, CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) &&
+	    CC(!nested_evmcs_is_valid_controls(EVMCS_2NDEXEC,
 					       vmcs12->secondary_vm_exec_control)))
 		return -EINVAL;
 
@@ -186,11 +187,10 @@ int nested_evmcs_check_controls(struct vmcs12 *vmcs12)
 	 * controls in bits 63:32, i.e. dropping those bits on the consistency
 	 * check is intentional.
 	 */
-	if (WARN_ON_ONCE(vmcs12->vm_function_control >> 32))
-		return -EINVAL;
-
-	if (CC(!nested_evmcs_is_valid_controls(EVMCS_VMFUNC,
-					       vmcs12->vm_function_control)))
+	if (nested_cpu_has_vmfunc(vmcs12) &&
+	    (WARN_ON_ONCE(vmcs12->vm_function_control >> 32) ||
+	     CC(!nested_evmcs_is_valid_controls(EVMCS_VMFUNC,
+						vmcs12->vm_function_control))))
 		return -EINVAL;
 
 	return 0;


> +	if (vmcs12->vm_function_control >> 32)
>  		return -EINVAL;
>  
>  	if (CC(!nested_evmcs_is_valid_controls(EVMCS_VMFUNC,

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

end of thread, other threads:[~2026-10-20 22:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 19:34 [PATCH] x86/hyper-v: Don't WARN on VM-Enter if eVMCS sees VMFUNC[63:32] != 0 Manuel Andreas
2026-10-20 19:36 ` Manuel Andreas
2026-10-20 22:56 ` Sean Christopherson

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

all inboxes | Powered by JetHome®