Linux Confidential Computing Development
 help / color / mirror / Atom feed
* [PATCH] x86/tdx: Fix zero-extension for CPUID emulation
@ 2026-05-12 21:37 Carlos López
  2026-05-12 21:48 ` Edgecombe, Rick P
  0 siblings, 1 reply; 10+ messages in thread
From: Carlos López @ 2026-05-12 21:37 UTC (permalink / raw)
  To: kas, rick.p.edgecombe, x86, linux-coco
  Cc: Carlos López, stable, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, H. Peter Anvin, Andi Kleen,
	Tony Luck, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:X86 TRUST DOMAIN EXTENSIONS (TDX)

In the x86 architecture, 32-bit operations zero-extend the result in the
destination register to 64 bits. This includes the CPUID instruction,
which writes 32-bit values EAX/EBX/ECX/EDX.

When handling the CPUID instruction via #VE, copy only the lower 32-bits
provided by the hypervisor for the output registers, and zero out the
upper half.

Fixes: c141fa2c2bba ("x86/tdx: Handle CPUID via #VE")
Cc: stable@vger.kernel.org
Signed-off-by: Carlos López <clopez@suse.de>
---
 arch/x86/coco/tdx/tdx.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index c8b9e86d0488..a2fe1ae019bd 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -543,10 +543,10 @@ static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve)
 	 * EAX, EBX, ECX, EDX registers after the CPUID instruction execution.
 	 * So copy the register contents back to pt_regs.
 	 */
-	regs->ax = args.r12;
-	regs->bx = args.r13;
-	regs->cx = args.r14;
-	regs->dx = args.r15;
+	regs->ax = lower_32_bits(args.r12);
+	regs->bx = lower_32_bits(args.r13);
+	regs->cx = lower_32_bits(args.r14);
+	regs->dx = lower_32_bits(args.r15);
 
 	return ve_instr_len(ve);
 }
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread
* Re: [PATCH] x86/tdx: Fix zero-extension for CPUID emulation
@ 2026-05-23  0:40 Christian Ludloff
  0 siblings, 0 replies; 10+ messages in thread
From: Christian Ludloff @ 2026-05-23  0:40 UTC (permalink / raw)
  To: Kiryl Shutsemau
  Cc: Dave Hansen, Edgecombe, Rick P, linux-coco@lists.linux.dev,
	clopez@suse.de, x86@kernel.org, ak@linux.intel.com, bp@alien8.de,
	dave.hansen@linux.intel.com, hpa@zytor.com, mingo@redhat.com,
	linux-kernel@vger.kernel.org, Luck, Tony, tglx@kernel.org,
	stable@vger.kernel.org, kvm@vger.kernel.org

On Tue, May 12, 2026 at 03:14:54PM -0700, Dave Hansen wrote:
> CPUID (the instruction) is defined to fill in eax/ebx/ecx/edx.

In the original x64 spec CPUID inherited 32-bit op size from
the pre-x64 days, and although established leaves might all
have followed that definition, the ISA per se doesn't prohibit
an implementation that allows, or defaults to, 64-bit op size.

Having made that statement... the same does go for MSRs.

> Those are 32-bit registers so the normal register rules apply:
> "32-bit operands generate a 32-bit result, zero-extended to a
> 64-bit result in the destination general-purpose register."

...in PM64 ...while outside PM64 and across mode switches
the upper 32 bits are explicitly undefined. Needless to say...
SMM and then VMX and SVM had to violate that to function.

> So a properly-behaving CPUID implementation will always end
> up with the top 32 bits empty on the four CPUID registers after
> a CPUID is executed.

True for a "32-bit op size" implementation. Maybe insert that.

--
C.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-05-23  0:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 21:37 [PATCH] x86/tdx: Fix zero-extension for CPUID emulation Carlos López
2026-05-12 21:48 ` Edgecombe, Rick P
2026-05-12 22:14   ` Dave Hansen
2026-05-12 22:24     ` Edgecombe, Rick P
2026-05-12 22:37       ` Dave Hansen
2026-05-12 22:43         ` Edgecombe, Rick P
2026-05-12 22:33     ` Carlos López
2026-05-22 16:54     ` Kiryl Shutsemau
2026-05-12 22:15   ` Carlos López
  -- strict thread matches above, loose matches on Subject: below --
2026-05-23  0:40 Christian Ludloff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox