From nobody Wed Apr 1 11:12:29 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B5B63D34AD; Tue, 31 Mar 2026 11:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774956280; cv=none; b=jHV5LG+Iq3CqEjjwOMDAKAf26hn2sErCf5idKuZn+iRBTiClWeaQauoOLFLozgsUD4accY/r71hD1OUVbk4vsC1VzkPPluYySrBtBe7z6gNrIzvzvxur7fOzdHr6QvB/ElYiGGwopPaS9dtxD1Tn3gbV0pVEzGsKlXYdTJHFR4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774956280; c=relaxed/simple; bh=G+HXWzbrzqhC4JhX7Pf60aGMXBlK3busY8Njcqfv5ds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aED2+JjTxIpW8mTA0CZrO6AK4uT0HiE4wPEvYNBwqyronxDF7qKuCxi0D7yo3ylyMW8NjeAHKYJLXQKK0cLQ3mgTNE4vLGcRmmvZ1/o+qdVl11dadFi4pS/lwIQl+VE37G8kjOojiu/8T/Q5P/KlBX9g3M9Hs9+KFRKuUKg3f64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lWKMLdxx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lWKMLdxx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 625C6C2BCB9; Tue, 31 Mar 2026 11:24:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774956279; bh=G+HXWzbrzqhC4JhX7Pf60aGMXBlK3busY8Njcqfv5ds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lWKMLdxx+WNEUvE4fmQ7IKeNyutGNlR4VXq4lIGLJDn9lBAvLsQpV9glUSt6g3FQe vsrWNe1Io1RhS2Pwl6NSeRzVj53EMelpYt4VALBJXiPrbc3sE09qEl8OnFR9NhU93f Sv1Y43Xy3HMN9zsj3kl3awo9mgY8vuw80YeSZEoHkLRipzi5X/2nti1B/wDDrtWCvp GQ/KFoo7SziXtzK2W1aKfYZ6sxW5xecyp4CAopeENYtznoHtibTUYhSl/anTu4zxe7 3ehJ1+1JMQU5USFnmrRw5B7tqhTINeAlcE4ZACW3Eo/ZxXcmU+AE3l4+4hNWCVprYD GsyG3WxeYVX+Q== Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id 93635F40068; Tue, 31 Mar 2026 07:24:38 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Tue, 31 Mar 2026 07:24:38 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddtjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegrihhl ohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpe fhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpedfmfhirhihlhcuufhh uhhtshgvmhgruhculdfovghtrgdmfdcuoehkrghssehkvghrnhgvlhdrohhrgheqnecugg ftrfgrthhtvghrnhephfdujeefvdegkefffedvkeehkeekueevfedtleehgeetlefgfeev veeukefhtdetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepkhhirhhilhhlodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdduiedu udeivdeiheehqddvkeeggeegjedvkedqkhgrsheppehkvghrnhgvlhdrohhrghesshhhuh htvghmohhvrdhnrghmvgdpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehtghhlgieskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhinh hgohesrhgvughhrghtrdgtohhmpdhrtghpthhtohepsghpsegrlhhivghnkedruggvpdhr tghpthhtohepuggrvhgvrdhhrghnshgvnheslhhinhhugidrihhnthgvlhdrtghomhdprh gtphhtthhopeigkeeisehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrghssehkvghr nhgvlhdrohhrghdprhgtphhtthhopehhphgrseiihihtohhrrdgtohhmpdhrtghpthhtoh eprhhitghkrdhprdgvughgvggtohhmsggvsehinhhtvghlrdgtohhmpdhrtghpthhtohep shgrthhhhigrnhgrrhgrhigrnhgrnhdrkhhuphhpuhhsfigrmhihsehlihhnuhigrdhinh htvghlrdgtohhm X-ME-Proxy: Feedback-ID: i10464835:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 31 Mar 2026 07:24:38 -0400 (EDT) From: "Kiryl Shutsemau (Meta)" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: Kiryl Shutsemau , "H . Peter Anvin" , Rick Edgecombe , Kuppuswamy Sathyanarayanan , Borys Tsyrulnikov , linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/2] x86/tdx: Fix zero-extension for 32-bit port I/O Date: Tue, 31 Mar 2026 12:24:30 +0100 Message-ID: <20260331112430.71425-3-kas@kernel.org> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260331112430.71425-1-kas@kernel.org> References: <20260331112430.71425-1-kas@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" According to x86 architecture rules, 32-bit operations zero-extend the result to 64 bits. The current implementation of handle_in() only masks the lower 32 bits, which preserves the upper 32 bits of RAX when a 32-bit port IN instruction is emulated. Update handle_in() to zero out the entire RAX register when the I/O size is 4 bytes to ensure correct zero-extension. For smaller sizes (1 or 2 bytes), continue to preserve the unaffected upper bits. Fixes: 03149948832a ("x86/tdx: Port I/O: Add runtime hypercalls") Reported-by: Borys Tsyrulnikov Signed-off-by: Kiryl Shutsemau (Meta) Cc: stable@vger.kernel.org Reviewed-by: Kai Huang Reviewed-by: Kuppuswamy Sathyanarayanan --- arch/x86/coco/tdx/tdx.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 4d7f71d50122..b9b9a2d75119 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -703,8 +703,17 @@ static bool handle_in(struct pt_regs *regs, int size, = int port) */ success =3D !__tdx_hypercall(&args); =20 - /* Update part of the register affected by the emulated instruction */ - regs->ax &=3D ~mask; + /* + * Update part of the register affected by the emulated instruction. + * + * 32-bit operands generate a 32-bit result, zero-extended to a 64-bit + * result. + */ + if (size < 4) + regs->ax &=3D ~mask; + else + regs->ax =3D 0; + if (success) regs->ax |=3D args.r11 & mask; =20 --=20 2.51.2