From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 3E8FE38C415; Sat, 12 Sep 2026 15:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789227693; cv=none; b=bU+Me5ftem0QfKBqjdVZ4azGzhp73oq2wVX4t+Wn9J7xtdVnvrWAbSeFEkkH85uGJQTCSoE3LjkrMMiHY7blvTscmvfvIpFm8dZYjl6ug5boeUkXCvJhJdN5FTMHRaVpf0p+BaImQmWro9mfFo4M9huljZYBH28Uw6bq7X/g+WM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789227693; c=relaxed/simple; bh=hFa3AawmKnbJYRs/qKwhXPya/6NMbQ6FtjqkxBO0sMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gb1/rslDzR/rCfZ4WPboES+dBzFLaSHtitr3Emjd7t+xWECAT7VwOYeoRAR0nKIsYNhnuIMFGjbtW3ImaIczmMbVjfwNyvkyFvmMKvLOxA/E0yag/Tcdyx1OYf2VcPHydNYL7GyIuu7SCCFn28EIKBgfV9clpOjQpqUs5s51gWQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wt3dVGBQ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="wt3dVGBQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C16A1F000FF; Sat, 12 Sep 2026 15:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789227691; bh=3t1fD4eSg6B3+D2NAHwfQqQ/90SazYx53k49U/OglVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wt3dVGBQhqw5GnHbCdsUqgfGY3nlwawrf2IbYp/d57D+Jik21yH2N6BY7tF9bislR +hlLA4RmLu9KNSxYImo6gBksuDGY4yEAYfTZqbOyNt2D8UjckAHE0hG/QvIM2hHtZK MNpNFCyL5jHjLbva+9dbBKE7C1c1IgzzKOTibrIk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Borys Tsyrulnikov , "Kiryl Shutsemau (Meta)" , Dave Hansen , Binbin Wu , Sasha Levin Subject: [PATCH 6.1 0231/1191] x86/tdx: Fix zero-extension for 32-bit port I/O Date: Sat, 12 Sep 2026 08:49:19 +0200 Message-ID: <20260912065553.397277145@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065548.086904252@linuxfoundation.org> References: <20260912065548.086904252@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kiryl Shutsemau (Meta) [ Upstream commit 941370fc93cc3474e26811f4d3b062903eefe2cf ] 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. Use insn_assign_reg() to write the result back into RAX with proper partial-register-write semantics: 1- and 2-byte forms leave the upper bits untouched, the 4-byte form zero-extends to the full register. Fixes: 03149948832a ("x86/tdx: Port I/O: Add runtime hypercalls") Reported-by: Borys Tsyrulnikov Signed-off-by: Kiryl Shutsemau (Meta) Signed-off-by: Dave Hansen Reviewed-by: Binbin Wu Link: https://lore.kernel.org/all/CAKw_Dz96rfSQc6Rn+9QBcUFHhmkK+9zu+P=bxowfZwxrATCBRg@mail.gmail.com/ Cc:stable@vger.kernel.org Link: https://patch.msgid.link/20260713133753.223947-4-kirill@shutemov.name Signed-off-by: Sasha Levin --- arch/x86/coco/tdx/tdx.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index a896d2d6f21f8..2f42892b456e5 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -462,8 +462,8 @@ static bool handle_in(struct pt_regs *regs, int size, int port) .r13 = PORT_READ, .r14 = port, }; - u64 mask = GENMASK(BITS_PER_BYTE * size - 1, 0); bool success; + u64 val; /* * Emulate the I/O read via hypercall. More info about ABI can be found @@ -471,11 +471,9 @@ static bool handle_in(struct pt_regs *regs, int size, int port) * "TDG.VP.VMCALL". */ success = !__tdx_hypercall(&args, TDX_HCALL_HAS_OUTPUT); + val = success ? args.r11 : 0; - /* Update part of the register affected by the emulated instruction */ - regs->ax &= ~mask; - if (success) - regs->ax |= args.r11 & mask; + insn_assign_reg(®s->ax, val, size); return success; } -- 2.53.0