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

From: Sohil Mehta

Date: Wed Dec 02 2026 - 17:36:48 EST


On 12/2/2026 1:42 PM, Sean Christopherson wrote:

> Rather than
> get cute with a ternary check, what if we separate the two cases (all vs. nothing)?
> That would allow us to "fix" the M:N case entirely, i.e. to also handle the case
> where multiple entry controls are bound to one exit control. E.g. untested, but
> this?
>

I tested that this works for FRED's 1:2 (VM-entry control: VM-exit
control) scenario. I don't think the SDM has a M:1 counterpart but
future-proofing this seems fine to me.

> +
> +/*
> + * Note, one entry control may be paired with multiple exit controls, and vice
> + * versua, 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 exist,
> + * 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 +2736,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, " \
>

This looks good. I'll incorporate it in the next version.


> Heh, yeah, because multi-line block comments inside of macros straight up don't
> work.
>

I wouldn't say it can never work :) call_on_irqstack_cond() does it
twice with \ at the end of each comment line. But in this case there is
no compelling reason to do it.