From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796247724; b=3spA/PWiRVLrPPCKs4mPzCX88eq0Qc0FOidEXIL7WEuBezRAVqso/Ie9bXzQUO8y3GM1 1i4D4b8YApZjLxK+iM8QzlJDst/2csGtKBAg60NE/mAnrp+RS0UhQ+bV0lPHGC5HmW5sR 4xkq+7nQQiD1b2n7rcz5srk9jSwAujOwTiR9NvKlyqwoQzN3sc40I36E4CPHQMg9iubxX /swgRdaOVv/BA/3aJsH34EaczvFHmxqbxECs2U99nkTbyVdTLMJy5EsMqZdeXRhyS3ojo ZrZnaoKvx2A8PubhrQvAYHgvIEKUy/4p58y+JGApMgeR/uPvwVHUP0ThRteTeOEdQXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796247724; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type: Content-Transfer-Encoding; bh=DXPAxL/KJXj8lcJ/VTEIfrb//EVTPqIYqHF3ND15wZQ=; b=2b0N/XgeecyutHqlPQfDlTxJSrRFuIYB5sNkw00EM16jdSW4tDA9N6LEbd5sphNY8k03 S4zaASOnsHFUk+eDoBoCrcpMWUAjXJSa/W4HGoO/24y+IIKyVM7RTYwAfhtbZFu0g2QPu c/ipVB2FoyUo6JDnCf9BiPnwTDOM1+o6MTAwEd/v5xNWlTva4wHFgSKZ9HIL7uQUH5Xrh 1T9sLqauQAhe2nkgHivkrudeBoaB/KZEbUUXJVYYqnLtwmvoFNRM/+clCZIoge0KdwSqI ZpBLVOyKMU6oDtyt2EoMcuudXWN8x4uLUw6lMMXa4mOqubARU/pWWlPSiWjp1PgJ4Gg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ptzAdUHV; arc=none smtp.remote-ip=209.85.214.200 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1500606A322 for ; Wed, 2 Dec 2026 21:42:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F1500606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ptzAdUHV Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2f05c68629cso99990755ad.1 for ; Wed, 02 Dec 2026 13:42:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796247722; x=1796852522; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=DXPAxL/KJXj8lcJ/VTEIfrb//EVTPqIYqHF3ND15wZQ=; b=ptzAdUHV6ljExI+UuVe3MjelEfGGDeCuBreFU2BEBqA7vzo3AmNYmHQvahW0nLd+dU GC5E8MqoViCpy+ZRoLjEVz0BmFxG2CaZgRZQ8QoHm6p7shU9Kd+qYKcip3QZ/KXbOgDU IFDH3lPXHB/OK8obD0fZTPboa4H9rLDFLro6/O3qMU5Dur3/P0RQhsmqrFE8RKcjjt4B /aeOPuBt/dTkV3Q28KiNnd35C75vsa1sDoB7dL7rNuLuDDDYj1w3JY16X3IXR9IB0EN0 MvgcGWCFTRozH4nNe1/aBOGJdXZobajphREpGuHHfOCtz4kUU1AwxAJ/3YuokGMWMUcl PfrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796247722; x=1796852522; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DXPAxL/KJXj8lcJ/VTEIfrb//EVTPqIYqHF3ND15wZQ=; b=iSykQsenmq1asXia+wKcF6dHQhmiLlAlpZDIiU63RJIesPFoc4XCMQxTKpxBAGc6tI 1gwNHGS3Npy/VeVIXYtEsIjNwWhl47bYU3X11HIyf2RNHWYrBM4avptdE3RvqmONqXlW A5uhAdz6s3JMndnXEhw315TIeE38jBswPp6EUrjEiWXxTOfShXVBCDeGdtBQP2/JhhVP nPiCa/4Sf57RZJfu6QYPPOstz8HfmIRU6dYDHBXMkRZLUYkJghB6Cy57brsJj6LH8FsF YJkISI8kjABYwQ3LbryIVY2iZhnSoFa0z0AoLLcsW01kyUxI5NaPpYCFybixGBEV3lg0 5OIQ== X-Forwarded-Encrypted: i=1; AL+hErFD/jNdvP5CV1JzmxqJe3AEtCC1KKE+IIaBP+cDL8VORnU7FWSPwZhGqdCKHrRo8xh23Xt8NMck8bqsJd4=@vger.kernel.org X-Gm-Message-State: APuU4Z8eGgYJ4M4PDrk1imAM6iX0J/cwbmCoNr6N4LkvrOX+GQ4bD0xb BJ7ET2mOXpwvxeB3SOFgMi7HN+Jiuk5FewUHPzKoD3IZOYTwNk4YiZJjhgCFtpEmJa4xhDgU+dg gwY76OQ== X-Received: from plbkv15.prod.google.com ([2002:a17:903:28cf:b0:2e2:c8c0:e8eb]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:110c:b0:2f1:6c6f:a685 with SMTP id d9443c01a7336-2f16c6fb216mr70935535ad.39.1796247721958; Wed, 02 Dec 2026 13:42:01 -0800 (PST) Date: Wed, 2 Dec 2026 13:42:01 -0800 In-Reply-To: <154d3685-bf48-4d18-a2d9-40f2425fa03c@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 References: <20261126022743.4082392-1-sohil.mehta@intel.com> <20261126022743.4082392-3-sohil.mehta@intel.com> <11528fd2-7045-4184-bf27-b3b115327f7d@intel.com> <154d3685-bf48-4d18-a2d9-40f2425fa03c@intel.com> Message-ID: Subject: Re: [PATCH 2/3] KVM: VMX: Treat partial support of an entry/exit pair as inconsistent From: Sean Christopherson To: Sohil Mehta Cc: "Chang S. Bae" , kvm@vger.kernel.org, Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Xin Li , Shivansh Dhiman , David Woodhouse , Chao Gao , Binbin Wu , Zhao Liu , Jon Kohler , x86@kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Wed, Dec 02, 2026, Sohil Mehta wrote: > On 12/2/2026 10:12 AM, Chang S. Bae wrote: > > On 11/25/2026 6:27 PM, Sohil Mehta wrote: > >> =C2=A0 +/* > >> + * 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. > >> + */ > >> =C2=A0 #define vmx_check_entry_exit_pairs(pairs, entry_controls, > >> exit_controls)=C2=A0=C2=A0=C2=A0 \ > >> =C2=A0 ({=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 \ > > ... > >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!(entry_controls & n_c= trl) =3D=3D !(exit_controls & > >> x_ctrl))=C2=A0=C2=A0=C2=A0 \ > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if ((exit_controls & x_ctr= l) =3D=3D=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((= entry_controls & n_ctrl) ? x_ctrl : 0))=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ Oof, this is impressively difficult to read. It took me a *long* time to t= ease out that the "? x_ctrl" was the exit control, not the entry control. Rathe= r than get cute with a ternary check, what if we separate the two cases (all vs. n= othing)? 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? if (((entry_controls & n_ctrl) =3D=3D n_ctrl) && \ ((exit_controls & x_ctrl) =3D=3D x_ctrl)) \ continue; \ \ if (!(entry_controls & n_ctrl) && !(exit_controls & x_ctrl)) \ continue; \ With an updated comment: diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b341af4c6057..dd7b9b67aaec 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2716,6 +2716,15 @@ static u64 adjust_vmx_controls64(u64 ctl_opt, u32 ms= r) return ctl_opt & allowed; } + +/* + * 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 e= xist, + * 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 =3D 0; \ @@ -2727,7 +2736,11 @@ static u64 adjust_vmx_controls64(u64 ctl_opt, u32 ms= r) typeof(entry_controls) n_ctrl =3D pairs[i].entry_control; \ typeof(exit_controls) x_ctrl =3D pairs[i].exit_control; \ \ - if (!(entry_controls & n_ctrl) =3D=3D !(exit_controls & x_ctrl)) \ + if (((entry_controls & n_ctrl) =3D=3D n_ctrl) && \ + ((exit_controls & x_ctrl) =3D=3D x_ctrl)) \ + continue; \ + \ + if (!(entry_controls & n_ctrl) && !(exit_controls & x_ctrl)) \ continue; \ \ pr_warn_once("Inconsistent VM-Entry/VM-Exit pair, " \ > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 continue;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 \ > >=20 > > Nit: Since this condition is a little difficult to follow without > > explanation nearby, perhaps better to move the comment down right there= . >=20 > I considered it but a multi-line comment inside a macro body felt odd. I > don't think any KVM macro or other arch/x86 code typically does it. Heh, yeah, because multi-line block comments inside of macros straight up d= on't work. > The comment describes what makes a pair consistent, which is what the > whole macro checks as well. So, I think it looks okay above the macro. > I'd prefer to keep it there unless you feel strongly about it. Yes, leave it exactly where it is.