Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796366932; b=3yUB1650Y+DeO2+Zgk2mh9ywtg6gEeBQJpxXUOwQxVyrtfbvs4MRXLY/H8DUl2EmpS+k YTxtiCLhko15+3qa8B/8GUkafVgzcOCTOo81DBGwzjNwISSpNTDXi+vG42JW6kxRTZqFP HDwiL54aokfNYu41URhDfMDTCyvsMalfG3X60TKVedd9/oQ0j4aT9JNjpQIbLbVXA0Oab MrdqmJuFRTl0Unk535h3puHT4Ht/ycvWHOspqMrgJT849MrYyZybwX11ZNJTgShUsFqYs tss+f8o1BPmZT+fehMTSCQquPb8ohvdqPsf7hj2in+8YQMxjEijVKGUN/JVy8XFrpHQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366932; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=hRZnfwIY1TSF+fegHpS7n99ZlXwI9TEqyOA9A+jXRk8=; b=Ot4gvomUoKOadfp97mhsiQoN3Ggags2tqcGi3AgxOXf+BEHtJLx+m6LOwz0RnqicSclW dolevfUZWL45cjgGSbhrQhVnmJmkojxO1CENxwWz/cZFHrkhOvIiWuWdg1UI7RP9/VYZT mKSaWzbBf0XUvBGlEqiWe9QlJ93+tmFYeu43Lga9CWEDeJAOCOxMM0gwtQwCvUT1ULFq1 YQ0fTOYqUxnS+ps3B2VHSjZ81/P2RLEBrhM1GstouohTR3sxdsrhVsmJEGN/tTUfa9vWj TDjkcXP2rRh8I12bXn2iqz5tqTVMmNIQWAme6VJeDamr/bZSqjQFTgT6ibWc5/ToByg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=WnxumAmh; arc=none smtp.remote-ip=192.198.163.18 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3F83606A335; Fri, 4 Dec 2026 06:48:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C3F83606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=WnxumAmh DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796366933; x=1827902933; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hRZnfwIY1TSF+fegHpS7n99ZlXwI9TEqyOA9A+jXRk8=; b=WnxumAmhHvQ5G9mKRsFKcVml9OrTq9vFdnvzgNwGPkM/qTPoaKiGRkTv fqzUU41gidPPVwI9mWA3kVi0hNx1vfOOQAa6kanoD7nLc4vEO6lEJEURJ kPqPi/jFef/k48NKyfnZAVbcfGSHuuWj7aw2Cxwi3D3UP1Y1bQCB20gnf kcsii9ktHRZ5zhf7uCjq2E4Ynj3sWgv2Odr5ErH+LabGYiIPOcNwD18O5 tLwpcAfZuva+wyNlRb0AB/Iqshr1PotJsxTpZUcSjZFB5yLLXG1Ix8qKw GzqCi25QKEsNvVBg5nJi1vNSjKpo1/+sly73Sxb7aW/zheTkz/NqnYDC0 g==; X-CSE-ConnectionGUID: Y+u/DpynRrOsQDf8BxyQ7w== X-CSE-MsgGUID: j89RXJRUTryDJ7v1sk1b9g== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5353853" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5353853" Received: from fmviesa012.fm.intel.com ([10.60.135.152]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:48:50 -0800 X-CSE-ConnectionGUID: zUK+39NuTBi/sWMWLdZR2g== X-CSE-MsgGUID: Ytm2CxAhTIuAvByB5dBCeQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="15659840" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa012.fm.intel.com with ESMTP; 03 Dec 2026 22:48:49 -0800 From: Sohil Mehta To: kvm@vger.kernel.org, Sean Christopherson Cc: Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Xin Li , Shivansh Dhiman , David Woodhouse , Chao Gao , Binbin Wu , Vitaly Kuznetsov , Sohil Mehta , "Chang S . Bae" , Zhao Liu , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent Date: Thu, 3 Dec 2026 22:46:33 -0800 Message-ID: <20261204064634.1569133-3-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204064634.1569133-1-sohil.mehta@intel.com> References: <20261204064634.1569133-1-sohil.mehta@intel.com> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Chao Gao Reviewed-by: Binbin Wu --- 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