mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] KVM: VMX: Add support for the secondary VM-exit controls
@ 2026-11-26  2:27 Sohil Mehta
  2026-11-26  2:27 ` [PATCH 1/3] " Sohil Mehta
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sohil Mehta @ 2026-11-26  2:27 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Sean Christopherson, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, H . Peter Anvin, Xin Li,
	Shivansh Dhiman, David Woodhouse, Chao Gao, Binbin Wu,
	Sohil Mehta, Chang S . Bae, Zhao Liu, Jon Kohler, x86,
	linux-kernel

Sean, Paolo,

These patches started out as part of the FRED KVM series [1]. However, the
series is getting bulky (30+ patches) and hard to manage as well as review. I
am working on splitting it into smaller parts [2] for easier review and merge.

The overall goal is to get the infrastructure pieces ready first and then the
FRED guest support followed by the nested FRED support. Some core x86 patches
that were part of the FRED KVM series are already in place [3] with more on
the way [4].

This series focusses on getting the secondary VM-exit controls support in
place independent of FRED. Please let me know if you prefer a different
approach or have any suggestions.

Background
----------
The secondary VM-exit controls are a 64-bit VMCS field, activated by bit 31 of
the primary VM-exit controls. The SDM defines four of them so far: "save
FRED", "load FRED", "load IA32_SPEC_CTRL" and "prematurely busy shadow stack".

With this series, KVM discovers the field and programs it in vmcs01 and
vmcs02, so that FRED or any other user of these controls only has to set its
own bits later on.

Patches
-------
Patch 1 adds the support for the secondary VM-exit controls.

Changes from FRED KVM v10:
 - Reword the commit message and add some minor changes to match the name
   and placement with neighboring code.
 - Copy the secondary controls into vmcs02 to fix the issue described below.
   In v10 this lived in the nested patches [5] which tied the FRED guest
   support to the nested support.

Binbin, I have kept your review tag since the changes are minor. Please let me
know if you have any concerns.

Patch 2 fixes an issue reported by sashiko related to the entry/exit pair
checking [6] and patch 3 adds the new field to the VMCS dump. The last two
patches are optional, but they help complete the support.

The patches are based on the kvm-x86/next branch (kvm-x86-next-2026.11.11).

vmcs02 issue
------------
KVM seeds vmcs02's VM-exit controls from vmcs01's, so vmcs02 inherits bit
31 but not the secondary controls themselves. vmcs02 then runs with the
secondary controls active but empty, which is harmless only while every
bit is clear.

Once FRED sets its controls in vmcs01, vmcs02 also inherits FRED's VM-entry
control. Entering any L2 loads FRED state, but the exit from L2 doesn't
restore the host's. Until the next VM entry the host runs with a zeroed FRED
configuration, and any event in that window hangs the CPU. 

This isn't specific to FRED, any future secondary VM-exit control would
likewise be silently off whenever an L2 runs.

Testing
-------
I tested it on a CWF system with FRED enabled as well as fred=off. The CPU
enumerates all four secondary VM-exit controls (IA32_VMX_EXIT_CTLS2 = 0xf), so
KVM activates the field in vmcs01 and copies it into vmcs02, with every bit
clear.

A debug dump_vmcs() on first VM exit from vmcs01 and from vmcs02 shows the
same controls in both:
    ExitControls=0x902befff SecondaryExitControls=0x0000000000000000

KVM selftests and kvm-unit-tests show no regressions.

Links
-----
[1]: https://lore.kernel.org/lkml/20260911213659.2025974-2-sohil.mehta@intel.com/
[2]: https://lore.kernel.org/lkml/12f686a4-a9f8-4347-a7f4-c0f893addfb9@intel.com/
[3]: https://lore.kernel.org/lkml/179545148741.92412.5844266518161867015.tip-bot2@tip-bot2/
[4]: https://lore.kernel.org/lkml/c662df85-4431-4303-9865-4189d186a94c@intel.com/
[5]: https://lore.kernel.org/lkml/20260911213659.2025974-21-sohil.mehta@intel.com/
[6]: https://lore.kernel.org/lkml/20260911220046.1A4A91F000FF@smtp.kernel.org/

Sohil Mehta (1):
  KVM: VMX: Treat partial support of an entry/exit pair as inconsistent

Xin Li (Intel) (2):
  KVM: VMX: Add support for the secondary VM-exit controls
  KVM: VMX: Dump the secondary VM-exit controls in dump_vmcs()

 arch/x86/include/asm/msr-index.h |  1 +
 arch/x86/include/asm/vmx.h       |  3 +++
 arch/x86/kvm/vmx/capabilities.h  |  6 +++++
 arch/x86/kvm/vmx/nested.c        |  3 +++
 arch/x86/kvm/vmx/vmcs.h          |  1 +
 arch/x86/kvm/vmx/vmx.c           | 46 +++++++++++++++++++++++++++++---
 arch/x86/kvm/vmx/vmx.h           |  7 ++++-
 7 files changed, 62 insertions(+), 5 deletions(-)


base-commit: cbe54fc3462b3949ab27b9ae81fb9ddb509040c7
-- 
2.43.0


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

* [PATCH 1/3] KVM: VMX: Add support for the secondary VM-exit controls
  2026-11-26  2:27 [PATCH 0/3] KVM: VMX: Add support for the secondary VM-exit controls Sohil Mehta
@ 2026-11-26  2:27 ` Sohil Mehta
  2026-11-26  2:27 ` [PATCH 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent Sohil Mehta
  2026-11-26  2:27 ` [PATCH 3/3] KVM: VMX: Dump the secondary VM-exit controls in dump_vmcs() Sohil Mehta
  2 siblings, 0 replies; 4+ messages in thread
From: Sohil Mehta @ 2026-11-26  2:27 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Sean Christopherson, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, H . Peter Anvin, Xin Li,
	Shivansh Dhiman, David Woodhouse, Chao Gao, Binbin Wu,
	Sohil Mehta, Chang S . Bae, Zhao Liu, Jon Kohler, x86,
	linux-kernel

From: "Xin Li (Intel)" <xin@zytor.com>

The secondary VM-exit controls are a 64-bit VMCS field for controls that
no longer fit in the 32-bit primary field. Bit 31 of the primary VM-exit
controls activates them. No feature KVM supports uses any of these
controls yet, but the upcoming FRED KVM support is planning to use them.

Add the VMCS field, its 64-bit controls shadow and the vmcs_config
plumbing, and activate the controls in vmcs01 whenever hardware supports
them. With every control bit clear, KVM behaves exactly as before.

Check the secondary controls through their own entry/exit pair table.
Avoid using a shared table because a failed check would clear the
activation bit and turn off every secondary control, not just the
inconsistent one. The new table stays empty until the first feature adds
a pair.

Copy the controls into vmcs02 as well. vmcs02 inherits the activation
bit from vmcs01, so without the copy it would run with the secondary
controls active but empty. That is harmless while every bit is clear.
Once a feature sets one, though, L2 would run with it silently off,
leaving the host with L2's state after a VM exit.

Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Co-developed-by: Sohil Mehta <sohil.mehta@intel.com>
Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
---
v1:
(Changes from FRED KVM v10):
 - Set the secondary VM-exit controls in vmcs02 too, so that no commit
   leaves vmcs02 with the controls activated but empty. (Prevents a CPU
   hang on exits from L2 once FRED guest support lands without the
   nested patches.)
 - Match the names and placement of the new variables and code to their
   neighbours.
 - Reword the changelog and also say why the secondary entry/exit pair
   table is separate from the primary one.
---
 arch/x86/include/asm/msr-index.h |  1 +
 arch/x86/include/asm/vmx.h       |  3 +++
 arch/x86/kvm/vmx/capabilities.h  |  6 ++++++
 arch/x86/kvm/vmx/nested.c        |  3 +++
 arch/x86/kvm/vmx/vmcs.h          |  1 +
 arch/x86/kvm/vmx/vmx.c           | 25 +++++++++++++++++++++++++
 arch/x86/kvm/vmx/vmx.h           |  7 ++++++-
 7 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index c0914829a925..ba26b8eccb01 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -1288,6 +1288,7 @@
 #define MSR_IA32_VMX_TRUE_ENTRY_CTLS     0x00000490
 #define MSR_IA32_VMX_VMFUNC             0x00000491
 #define MSR_IA32_VMX_PROCBASED_CTLS3	0x00000492
+#define MSR_IA32_VMX_EXIT_CTLS2		0x00000493
 
 #define MSR_IA32_MCU_STAGING_MBOX_ADDR	0x000007a5
 
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index e49b836c7313..a0802af63dc3 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -127,6 +127,7 @@ struct vmcs {
 #define VM_EXIT_CLEAR_IA32_RTIT_CTL		0x02000000
 #define VM_EXIT_LOAD_CET_STATE                  0x10000000
 #define VM_EXIT_SAVE_IA32_PERF_GLOBAL_CTRL	0x40000000
+#define VM_EXIT_ACTIVATE_SECONDARY_CONTROLS	0x80000000
 
 #define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR	0x00036dff
 
@@ -283,6 +284,8 @@ enum vmcs_field {
 	SHARED_EPT_POINTER		= 0x0000203C,
 	PID_POINTER_TABLE		= 0x00002042,
 	PID_POINTER_TABLE_HIGH		= 0x00002043,
+	SECONDARY_VM_EXIT_CONTROLS	= 0x00002044,
+	SECONDARY_VM_EXIT_CONTROLS_HIGH	= 0x00002045,
 	GUEST_PHYSICAL_ADDRESS          = 0x00002400,
 	GUEST_PHYSICAL_ADDRESS_HIGH     = 0x00002401,
 	VMCS_LINK_POINTER               = 0x00002800,
diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h
index 810119167f79..5737e79bf2da 100644
--- a/arch/x86/kvm/vmx/capabilities.h
+++ b/arch/x86/kvm/vmx/capabilities.h
@@ -58,6 +58,7 @@ struct vmcs_config {
 	u32 cpu_based_2nd_exec_ctrl;
 	u64 cpu_based_3rd_exec_ctrl;
 	u32 vmexit_ctrl;
+	u64 vmexit_2nd_ctrl;
 	u32 vmentry_ctrl;
 	u64 misc;
 	struct nested_vmx_msrs nested;
@@ -149,6 +150,11 @@ static inline bool cpu_has_tertiary_exec_ctrls(void)
 		CPU_BASED_ACTIVATE_TERTIARY_CONTROLS;
 }
 
+static inline bool cpu_has_secondary_vmexit_ctrls(void)
+{
+	return vmcs_config.vmexit_ctrl & VM_EXIT_ACTIVATE_SECONDARY_CONTROLS;
+}
+
 static inline bool cpu_has_vmx_virtualize_apic_accesses(void)
 {
 	return vmcs_config.cpu_based_2nd_exec_ctrl &
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 1a98f28651f7..0f39309cc7f3 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2559,6 +2559,9 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct loaded_vmcs *vmcs0
 		exec_control &= ~VM_EXIT_LOAD_IA32_EFER;
 	vm_exit_controls_set(vmx, exec_control);
 
+	if (exec_control & VM_EXIT_ACTIVATE_SECONDARY_CONTROLS)
+		secondary_vm_exit_controls_set(vmx, __secondary_vm_exit_controls_get(vmcs01));
+
 	/*
 	 * Interrupt/Exception Fields
 	 */
diff --git a/arch/x86/kvm/vmx/vmcs.h b/arch/x86/kvm/vmx/vmcs.h
index 1f16ddeae9cb..ca341c59bab1 100644
--- a/arch/x86/kvm/vmx/vmcs.h
+++ b/arch/x86/kvm/vmx/vmcs.h
@@ -45,6 +45,7 @@ struct vmcs_host_state {
 struct vmcs_controls_shadow {
 	u32 vm_entry;
 	u32 vm_exit;
+	u64 secondary_vm_exit;
 	u32 pin;
 	u32 exec;
 	u32 secondary_exec;
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 68fa251dda60..3752a86c3fca 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -2752,6 +2752,7 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 	u32 _cpu_based_2nd_exec_control = 0;
 	u64 _cpu_based_3rd_exec_control = 0;
 	u32 _vmexit_control = 0;
+	u64 _vmexit_2nd_control = 0;
 	u32 _vmentry_control = 0;
 	struct msr val;
 	u64 basic_msr;
@@ -2774,6 +2775,12 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 		{ VM_ENTRY_LOAD_CET_STATE,		VM_EXIT_LOAD_CET_STATE },
 	};
 
+	struct {
+		u32 entry_control;
+		u64 exit_control;
+	} const vmcs_entry_exit_2nd_pairs[] = {
+	};
+
 	memset(vmcs_conf, 0, sizeof(*vmcs_conf));
 
 	if (adjust_vmx_controls(KVM_REQUIRED_VMX_CPU_BASED_VM_EXEC_CONTROL,
@@ -2864,6 +2871,11 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 				&_vmexit_control))
 		return -EIO;
 
+	if (_vmexit_control & VM_EXIT_ACTIVATE_SECONDARY_CONTROLS)
+		_vmexit_2nd_control =
+			adjust_vmx_controls64(KVM_OPTIONAL_VMX_SECONDARY_VM_EXIT_CONTROLS,
+					      MSR_IA32_VMX_EXIT_CTLS2);
+
 	if (adjust_vmx_controls(KVM_REQUIRED_VMX_PIN_BASED_VM_EXEC_CONTROL,
 				KVM_OPTIONAL_VMX_PIN_BASED_VM_EXEC_CONTROL,
 				MSR_IA32_VMX_PINBASED_CTLS,
@@ -2886,6 +2898,10 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 				       _vmentry_control, _vmexit_control))
 		return -EIO;
 
+	if (vmx_check_entry_exit_pairs(vmcs_entry_exit_2nd_pairs,
+				       _vmentry_control, _vmexit_2nd_control))
+		return -EIO;
+
 	/*
 	 * Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they
 	 * can't be used due to an errata where VM Exit may incorrectly clear
@@ -2935,6 +2951,7 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 	vmcs_conf->cpu_based_2nd_exec_ctrl = _cpu_based_2nd_exec_control;
 	vmcs_conf->cpu_based_3rd_exec_ctrl = _cpu_based_3rd_exec_control;
 	vmcs_conf->vmexit_ctrl         = _vmexit_control;
+	vmcs_conf->vmexit_2nd_ctrl     = _vmexit_2nd_control;
 	vmcs_conf->vmentry_ctrl        = _vmentry_control;
 	vmcs_conf->misc	= misc_msr;
 
@@ -4629,6 +4646,11 @@ static u32 vmx_get_initial_vmexit_ctrl(void)
 		  VM_EXIT_SAVE_IA32_PERF_GLOBAL_CTRL);
 }
 
+static u64 vmx_get_initial_secondary_vmexit_ctrl(void)
+{
+	return vmcs_config.vmexit_2nd_ctrl;
+}
+
 void vmx_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu)
 {
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -4973,6 +4995,9 @@ static void init_vmcs(struct kvm_vcpu *vcpu)
 
 	vm_exit_controls_set(vmx, vmx_get_initial_vmexit_ctrl());
 
+	if (cpu_has_secondary_vmexit_ctrls())
+		secondary_vm_exit_controls_set(vmx, vmx_get_initial_secondary_vmexit_ctrl());
+
 	/* 22.2.1, 20.8.1 */
 	vm_entry_controls_set(vmx, vmx_get_initial_vmentry_ctrl());
 
diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
index 74cd50f29fa4..e8c6ce23168a 100644
--- a/arch/x86/kvm/vmx/vmx.h
+++ b/arch/x86/kvm/vmx/vmx.h
@@ -457,7 +457,11 @@ static inline u8 vmx_get_rvi(void)
 	       VM_EXIT_PT_CONCEAL_PIP |					\
 	       VM_EXIT_CLEAR_IA32_RTIT_CTL |				\
 	       VM_EXIT_LOAD_CET_STATE |					\
-	       VM_EXIT_SAVE_IA32_PERF_GLOBAL_CTRL)
+	       VM_EXIT_SAVE_IA32_PERF_GLOBAL_CTRL |			\
+	       VM_EXIT_ACTIVATE_SECONDARY_CONTROLS)
+
+#define KVM_REQUIRED_VMX_SECONDARY_VM_EXIT_CONTROLS 0
+#define KVM_OPTIONAL_VMX_SECONDARY_VM_EXIT_CONTROLS 0
 
 #define KVM_REQUIRED_VMX_PIN_BASED_VM_EXEC_CONTROL			\
 	(PIN_BASED_EXT_INTR_MASK |					\
@@ -571,6 +575,7 @@ static __always_inline void lname##_controls_changebit(struct vcpu_vmx *vmx, u##
 }
 BUILD_CONTROLS_SHADOW(vm_entry, VM_ENTRY_CONTROLS, 32)
 BUILD_CONTROLS_SHADOW(vm_exit, VM_EXIT_CONTROLS, 32)
+BUILD_CONTROLS_SHADOW(secondary_vm_exit, SECONDARY_VM_EXIT_CONTROLS, 64)
 BUILD_CONTROLS_SHADOW(pin, PIN_BASED_VM_EXEC_CONTROL, 32)
 BUILD_CONTROLS_SHADOW(exec, CPU_BASED_VM_EXEC_CONTROL, 32)
 BUILD_CONTROLS_SHADOW(secondary_exec, SECONDARY_VM_EXEC_CONTROL, 32)
-- 
2.43.0


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

* [PATCH 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent
  2026-11-26  2:27 [PATCH 0/3] KVM: VMX: Add support for the secondary VM-exit controls Sohil Mehta
  2026-11-26  2:27 ` [PATCH 1/3] " Sohil Mehta
@ 2026-11-26  2:27 ` Sohil Mehta
  2026-11-26  2:27 ` [PATCH 3/3] KVM: VMX: Dump the secondary VM-exit controls in dump_vmcs() Sohil Mehta
  2 siblings, 0 replies; 4+ messages in thread
From: Sohil Mehta @ 2026-11-26  2:27 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Sean Christopherson, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, H . Peter Anvin, Xin Li,
	Shivansh Dhiman, David Woodhouse, Chao Gao, Binbin Wu,
	Sohil Mehta, Chang S . Bae, Zhao Liu, Jon Kohler, x86,
	linux-kernel

The VM-entry/VM-exit pair check only requires one of a pair's exit
controls to be supported along with the entry control. That is fine
while every pair has a single exit control.

However, a feature can have multiple exit controls paired with a single
entry control. For example, PAT and EFER each have two exit controls,
but KVM doesn't use their save controls. In future, FRED will use both:
its state is loaded on VM-entry, and both saved and restored on VM-exit.

If hardware supports only one of those exit controls, the existing check
passes and the feature would be enabled with part of its state left
unswitched. Require all of a pair's controls to be supported, or none of
them. The existing pairs are unaffected.

Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
---
v1:
 - New patch. It addresses a gap Sashiko found in v10 patch 2:
   https://lore.kernel.org/all/20260911220046.1A4A91F000FF@smtp.kernel.org/
 - Doesn't include a fixes tag because all existing pairs have a single
   exit control.
---
 arch/x86/kvm/vmx/vmx.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 3752a86c3fca..d35bad8b29a7 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -2716,6 +2716,11 @@ static u64 adjust_vmx_controls64(u64 ctl_opt, u32 msr)
 	return  ctl_opt & allowed;
 }
 
+/*
+ * A pair may consist of one entry control and several exit controls. It
+ * is consistent only if all of its controls are supported, or none of them
+ * are.
+ */
 #define vmx_check_entry_exit_pairs(pairs, entry_controls, exit_controls)	\
 ({										\
 	int i, r = 0;								\
@@ -2727,7 +2732,8 @@ static u64 adjust_vmx_controls64(u64 ctl_opt, u32 msr)
 		typeof(entry_controls) n_ctrl = pairs[i].entry_control;		\
 		typeof(exit_controls) x_ctrl = pairs[i].exit_control;		\
 										\
-		if (!(entry_controls & n_ctrl) == !(exit_controls & x_ctrl))	\
+		if ((exit_controls & x_ctrl) ==					\
+		    ((entry_controls & n_ctrl) ? x_ctrl : 0))			\
 			continue;						\
 										\
 		pr_warn_once("Inconsistent VM-Entry/VM-Exit pair, "		\
-- 
2.43.0


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

* [PATCH 3/3] KVM: VMX: Dump the secondary VM-exit controls in dump_vmcs()
  2026-11-26  2:27 [PATCH 0/3] KVM: VMX: Add support for the secondary VM-exit controls Sohil Mehta
  2026-11-26  2:27 ` [PATCH 1/3] " Sohil Mehta
  2026-11-26  2:27 ` [PATCH 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent Sohil Mehta
@ 2026-11-26  2:27 ` Sohil Mehta
  2 siblings, 0 replies; 4+ messages in thread
From: Sohil Mehta @ 2026-11-26  2:27 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Sean Christopherson, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, H . Peter Anvin, Xin Li,
	Shivansh Dhiman, David Woodhouse, Chao Gao, Binbin Wu,
	Sohil Mehta, Chang S . Bae, Zhao Liu, Jon Kohler, x86,
	linux-kernel

From: "Xin Li (Intel)" <xin@zytor.com>

KVM now activates the secondary VM-exit controls whenever hardware
supports them. Print them next to the primary VM-exit controls in the
VMCS dump to help debug failed VM-entries.

While at it, give the entry and exit controls the 0x prefix that the
execution control fields already have.

Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
---
v1:
 - New patch, split out of FRED KVM v10 series so that the dump covers
   the field this series adds.
---
 arch/x86/kvm/vmx/vmx.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index d35bad8b29a7..7291c2916ff6 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6493,7 +6493,7 @@ void dump_vmcs(struct kvm_vcpu *vcpu)
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
 	u32 vmentry_ctl, vmexit_ctl;
 	u32 cpu_based_exec_ctrl, pin_based_exec_ctrl, secondary_exec_control;
-	u64 tertiary_exec_control;
+	u64 tertiary_exec_control, secondary_vmexit_ctl;
 	unsigned long cr4;
 	int efer_slot;
 
@@ -6518,6 +6518,11 @@ void dump_vmcs(struct kvm_vcpu *vcpu)
 	else
 		tertiary_exec_control = 0;
 
+	if (cpu_has_secondary_vmexit_ctrls())
+		secondary_vmexit_ctl = vmcs_read64(SECONDARY_VM_EXIT_CONTROLS);
+	else
+		secondary_vmexit_ctl = 0;
+
 	pr_err("VMCS %p, last attempted VM-entry on CPU %d\n",
 	       vmx->loaded_vmcs->vmcs, vcpu->arch.last_vmentry_cpu);
 	pr_err("*** Guest State ***\n");
@@ -6626,8 +6631,10 @@ void dump_vmcs(struct kvm_vcpu *vcpu)
 	pr_err("*** Control State ***\n");
 	pr_err("CPUBased=0x%08x SecondaryExec=0x%08x TertiaryExec=0x%016llx\n",
 	       cpu_based_exec_ctrl, secondary_exec_control, tertiary_exec_control);
-	pr_err("PinBased=0x%08x EntryControls=%08x ExitControls=%08x\n",
-	       pin_based_exec_ctrl, vmentry_ctl, vmexit_ctl);
+	pr_err("PinBased=0x%08x EntryControls=0x%08x\n",
+	       pin_based_exec_ctrl, vmentry_ctl);
+	pr_err("ExitControls=0x%08x SecondaryExitControls=0x%016llx\n",
+	       vmexit_ctl, secondary_vmexit_ctl);
 	pr_err("ExceptionBitmap=%08x PFECmask=%08x PFECmatch=%08x\n",
 	       vmcs_read32(EXCEPTION_BITMAP),
 	       vmcs_read32(PAGE_FAULT_ERROR_CODE_MASK),
-- 
2.43.0


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

end of thread, other threads:[~2026-11-26  2:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26  2:27 [PATCH 0/3] KVM: VMX: Add support for the secondary VM-exit controls Sohil Mehta
2026-11-26  2:27 ` [PATCH 1/3] " Sohil Mehta
2026-11-26  2:27 ` [PATCH 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent Sohil Mehta
2026-11-26  2:27 ` [PATCH 3/3] KVM: VMX: Dump the secondary VM-exit controls in dump_vmcs() Sohil Mehta

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®