* [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls
@ 2026-12-03 6:51 Sohil Mehta
2026-12-03 6:51 ` [PATCH v2 1/3] " Sohil Mehta
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Sohil Mehta @ 2026-12-03 6:51 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, x86, linux-kernel
Some of these patches started out as part of the FRED KVM series [1]. I am
working towards getting the core infrastructure pieces ready first then the
FRED guest support followed by the nested FRED support.
This series focusses on getting the secondary VM-exit controls support in
place independent of FRED. Preferably, it can be merged into the KVM tree
separately. Otherwise, I'll place the patches at the beginning of the FRED
series for a combined merge.
Changes in v2
-------------
- Split the pair check into "all supported" and "none supported" cases,
which also covers a pair with several entry controls (Sean) [patch 2]
- Lead the changelogs with a small summary of changes (Chang) [patches 1, 2]
- Pick up Chang's review tag [patch 3]
v1: https://lore.kernel.org/lkml/20261126022743.4082392-1-sohil.mehta@intel.com/
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. Binbin, I have
kept your review tag since most of the changes are minor. The only significant
change on top of FRED KVM v10 is the vmcs02 handling described below.
Patch 2 fixes an issue reported by sashiko related to the entry/exit pair
checking [2] 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
-------
This was tested on a FRED capable 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.
Patch 2's new check was also tested with the upcoming FRED guest support,
whose pair has two exit controls. KVM keeps the pair when all three controls
are supported and rejects it when any one is forced off.
Links
-----
[1]: https://lore.kernel.org/lkml/20260911213659.2025974-2-sohil.mehta@intel.com/
[2]: 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: Support 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 | 52 +++++++++++++++++++++++++++++---
arch/x86/kvm/vmx/vmx.h | 7 ++++-
7 files changed, 68 insertions(+), 5 deletions(-)
base-commit: cbe54fc3462b3949ab27b9ae81fb9ddb509040c7
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] KVM: VMX: Support the secondary VM-exit controls
2026-12-03 6:51 [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls Sohil Mehta
@ 2026-12-03 6:51 ` Sohil Mehta
2026-12-03 13:14 ` Chao Gao
2026-12-03 6:51 ` [PATCH v2 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent Sohil Mehta
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Sohil Mehta @ 2026-12-03 6:51 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, x86, linux-kernel
From: "Xin Li (Intel)" <xin@zytor.com>
Add the VMCS field for the secondary VM-exit controls, its controls
shadow and the vmcs_config plumbing. Activate the controls in vmcs01
whenever hardware supports them, and copy them into vmcs02.
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.
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.
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>
---
v2:
- Lead the changelog with the changes, and shorten the subject (Chang).
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] 6+ messages in thread
* [PATCH v2 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent
2026-12-03 6:51 [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls Sohil Mehta
2026-12-03 6:51 ` [PATCH v2 1/3] " Sohil Mehta
@ 2026-12-03 6:51 ` Sohil Mehta
2026-12-03 6:51 ` [PATCH v2 3/3] KVM: VMX: Dump the secondary VM-exit controls in dump_vmcs() Sohil Mehta
2026-12-03 13:24 ` [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls Chao Gao
3 siblings, 0 replies; 6+ messages in thread
From: Sohil Mehta @ 2026-12-03 6:51 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, x86, linux-kernel
Make the VM-entry/VM-exit pair check require all of a pair's controls to
be supported, or none of them. The existing pairs are unaffected.
Currently, the 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. Check the entry side the same way, which also covers a pair
with several entry controls, although no such pair exists today.
Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
---
v2:
- Split the check into "all supported" and "none supported" cases,
which also covers a pair with several entry controls (Sean).
- Lead the changelog with the change.
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 | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 3752a86c3fca..1387d400fded 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -2716,6 +2716,14 @@ static u64 adjust_vmx_controls64(u64 ctl_opt, u32 msr)
return ctl_opt & allowed;
}
+/*
+ * Note, one entry control may be paired with multiple exit controls, and vice
+ * versa, e.g. if there's one entry control to load guest state, and then two
+ * exit controls to save guest state and then load/clear host state. For pairs
+ * of controls, KVM expects all controls to exist if one of the controls exists,
+ * so treat a "pair" as consistent if and only if all of its controls are
+ * supported, or none are supported.
+ */
#define vmx_check_entry_exit_pairs(pairs, entry_controls, exit_controls) \
({ \
int i, r = 0; \
@@ -2727,7 +2735,11 @@ 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 (((entry_controls & n_ctrl) == n_ctrl) && \
+ ((exit_controls & x_ctrl) == x_ctrl)) \
+ continue; \
+ \
+ if (!(entry_controls & n_ctrl) && !(exit_controls & x_ctrl)) \
continue; \
\
pr_warn_once("Inconsistent VM-Entry/VM-Exit pair, " \
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] KVM: VMX: Dump the secondary VM-exit controls in dump_vmcs()
2026-12-03 6:51 [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls Sohil Mehta
2026-12-03 6:51 ` [PATCH v2 1/3] " Sohil Mehta
2026-12-03 6:51 ` [PATCH v2 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent Sohil Mehta
@ 2026-12-03 6:51 ` Sohil Mehta
2026-12-03 13:24 ` [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls Chao Gao
3 siblings, 0 replies; 6+ messages in thread
From: Sohil Mehta @ 2026-12-03 6:51 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, 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>
Reviewed-by: Chang S. Bae <chang.seok.bae@intel.com>
---
v2:
- Pick up Chang's review tag.
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 1387d400fded..7899ec885084 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6499,7 +6499,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;
@@ -6524,6 +6524,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");
@@ -6632,8 +6637,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] 6+ messages in thread
* Re: [PATCH v2 1/3] KVM: VMX: Support the secondary VM-exit controls
2026-12-03 6:51 ` [PATCH v2 1/3] " Sohil Mehta
@ 2026-12-03 13:14 ` Chao Gao
0 siblings, 0 replies; 6+ messages in thread
From: Chao Gao @ 2026-12-03 13:14 UTC (permalink / raw)
To: Sohil Mehta
Cc: kvm, Paolo Bonzini, Sean Christopherson, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H . Peter Anvin,
Xin Li, Shivansh Dhiman, David Woodhouse, Binbin Wu,
Chang S . Bae, Zhao Liu, x86, linux-kernel
On Wed, Dec 02, 2026 at 10:51:47PM -0800, Sohil Mehta wrote:
>From: "Xin Li (Intel)" <xin@zytor.com>
>
>Add the VMCS field for the secondary VM-exit controls, its controls
>shadow and the vmcs_config plumbing. Activate the controls in vmcs01
>whenever hardware supports them, and copy them into vmcs02.
>
>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.
>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.
This only matters with error_on_inconsistent_vmcs_config=0, because
kvm_intel refuses to load on a failed check by default. Sean's reason
in [1] is the stronger one:
"two tables provides better separation, which makes it easier
to follow what's going on, and avoids "polluting" every entry
with empty fields."
I would use it here instead and add a link to that discussion.
[1]: https://lore.kernel.org/all/Z739wdGmk4ZuWJ8v@google.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls
2026-12-03 6:51 [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls Sohil Mehta
` (2 preceding siblings ...)
2026-12-03 6:51 ` [PATCH v2 3/3] KVM: VMX: Dump the secondary VM-exit controls in dump_vmcs() Sohil Mehta
@ 2026-12-03 13:24 ` Chao Gao
3 siblings, 0 replies; 6+ messages in thread
From: Chao Gao @ 2026-12-03 13:24 UTC (permalink / raw)
To: Sohil Mehta
Cc: kvm, Paolo Bonzini, Sean Christopherson, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H . Peter Anvin,
Xin Li, Shivansh Dhiman, David Woodhouse, Binbin Wu,
Chang S . Bae, Zhao Liu, x86, linux-kernel
On Wed, Dec 02, 2026 at 10:51:46PM -0800, Sohil Mehta wrote:
>Some of these patches started out as part of the FRED KVM series [1]. I am
>working towards getting the core infrastructure pieces ready first then the
>FRED guest support followed by the nested FRED support.
>
>This series focusses on getting the secondary VM-exit controls support in
>place independent of FRED. Preferably, it can be merged into the KVM tree
>separately. Otherwise, I'll place the patches at the beginning of the FRED
>series for a combined merge.
The series looks good to me. I just have one nit on the changelog of patch 1.
For the series:
Reviewed-by: Chao Gao <chao.gao@intel.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-03 13:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 6:51 [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls Sohil Mehta
2026-12-03 6:51 ` [PATCH v2 1/3] " Sohil Mehta
2026-12-03 13:14 ` Chao Gao
2026-12-03 6:51 ` [PATCH v2 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent Sohil Mehta
2026-12-03 6:51 ` [PATCH v2 3/3] KVM: VMX: Dump the secondary VM-exit controls in dump_vmcs() Sohil Mehta
2026-12-03 13:24 ` [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls Chao Gao
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®