From: Sohil Mehta <sohil.mehta@intel.com>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>, Xin Li <xin@zytor.com>,
Shivansh Dhiman <shivansh.dhiman@amd.com>,
David Woodhouse <dwmw@amazon.co.uk>,
Chao Gao <chao.gao@intel.com>,
Binbin Wu <binbin.wu@linux.intel.com>,
Sohil Mehta <sohil.mehta@intel.com>,
"Chang S . Bae" <chang.seok.bae@intel.com>,
Zhao Liu <zhao1.liu@intel.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent
Date: Wed, 2 Dec 2026 22:51:48 -0800 [thread overview]
Message-ID: <20261203065149.2952509-3-sohil.mehta@intel.com> (raw)
In-Reply-To: <20261203065149.2952509-1-sohil.mehta@intel.com>
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
next prev parent reply other threads:[~2026-12-03 6:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Sohil Mehta [this message]
2026-12-03 14:22 ` [PATCH v2 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent Binbin Wu
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 14:24 ` Binbin Wu
2026-12-03 13:24 ` [PATCH v2 0/3] KVM: VMX: Support the secondary VM-exit controls Chao Gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203065149.2952509-3-sohil.mehta@intel.com \
--to=sohil.mehta@intel.com \
--cc=binbin.wu@linux.intel.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=chao.gao@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw@amazon.co.uk \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shivansh.dhiman@amd.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=xin@zytor.com \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®