[PATCH v3 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent

From: Sohil Mehta

Date: Fri Dec 04 2026 - 01:49:13 EST


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 the future, FRED will use
both exit controls: VM-entry loads the guest FRED state, and VM-exit
saves the guest state and loads the host state.

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@xxxxxxxxx>
Reviewed-by: Chao Gao <chao.gao@xxxxxxxxx>
Reviewed-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>
---
v3:
- Spell out how FRED uses both exit controls (Binbin).
- Pick up Chao's and Binbin's review tags.

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.
---
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 65b44fbedc38..9cc0c37abc44 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