From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.15 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796280854; b=z7oRppoWM2uGhk+ukBuzNUrPG2D54vPYXj06pmS2SLivVcOVHYXvkB7Y75K6vAYBoj/d GrwHoNPrwufe0OcfEPsQaOztReUUSycgFgx8qN/g1dZ+EOx/QJAvNuw9f7zgpF14hUnsW V6XEJK4QmnYyeM+z9IJrieSPZTyTkr+6ffhYVhnBX1NCgVkwcOo2AnQMQZ/Gk68hTUSt7 0M2ThvV/HIhjahciG2cayUJ9+4rj2fvNpyh+Psa2FcXy10gZxDFjx/12mUkyWCwZLiDtN LrWRd3anL8I1CC3/2F3DMN394q0qC6EB63wtYw2c194aCr7qV7TUzBpSx0eolVV6zSA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796280854; 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=xjZHFHFFMbSVsNVoX4AhJrAamwjUatOIM1YxSDINiUo=; b=BhjyhLfUNLTPt72MeE5vmQefcKGjGq8UBfr3BviypijssD+SSA5JTKu33UrVcFgda8Gd F3iTD4YQTyDQBI8pfi14SfQy8Fs3YJzBy6YybcXfew2x/OusnF8+xD6lTKbM28+xGXWuu o6DeEGJm3mAQq4wzAKbohiQSnLT0wHetr2khpqJjlQODKRDbZuw7m6ZXoBcPNRiw9zm5b yG9+zYjTj3O97zpdICo3QhAVdDueA4PGvwJr6ZVBpAO0n8oRXUE5qhIHWzAhHJzgc0sw1 zi0DYEUXNPBAoUGVcwaufqpWmDcqyjMb4H56rA6BFE+Pxg4V4zgElZhVzKpD8HYFfYA== 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=krS4VGAm; arc=none smtp.remote-ip=198.175.65.15 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 AD7E8606A330; Thu, 3 Dec 2026 06:54:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AD7E8606A330 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=krS4VGAm DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796280854; x=1827816854; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xjZHFHFFMbSVsNVoX4AhJrAamwjUatOIM1YxSDINiUo=; b=krS4VGAmneAGbetyRLgmsiClpuRAiVLftr3k3+p/CJToDAszwLBSJ2yl y1ggvjGs5GdnM2Na3XvuCpRtU3gPTGK4C30iaNmFG+N/TUkNKIYAY4QOB kDNdpeMGVaouoqBxKJBjno7572+whwbssJCmMDj0/X315GcuC+9zRiFoM 48WCJQB9NRIljJDNtzTj3SBoUnLQ11hTgTtR+Wi0VZwwSgtaqPBA/OrZj bvk3q/zyNr2ZQIQXTGGNnZImOQ+Tqr6g/Ch+MShhldgAdKFWSHhBcsVWU D37Ze0Emfd7kD6Qyjl+XfezAdH4Sx4RM6q2xBJeG+G2a77Oi7+alObPyw g==; X-CSE-ConnectionGUID: LxWPvO0jTN2oZUuAnZ20PA== X-CSE-MsgGUID: sSShCEHMRlC1MbHkvLGxvw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5223572" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5223572" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 22:54:12 -0800 X-CSE-ConnectionGUID: Xm1IYzCjREqLCzzFTim6eQ== X-CSE-MsgGUID: m98xdOP1TQ294iuHFGPTXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="14056229" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa006.fm.intel.com with ESMTP; 02 Dec 2026 22:54:12 -0800 From: Sohil Mehta To: kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Xin Li , Shivansh Dhiman , David Woodhouse , Chao Gao , Binbin Wu , Sohil Mehta , "Chang S . Bae" , Zhao Liu , 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 Message-ID: <20261203065149.2952509-3-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203065149.2952509-1-sohil.mehta@intel.com> References: <20261203065149.2952509-1-sohil.mehta@intel.com> X-Mailing-List: linux-kernel@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 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 --- 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