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 --- 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