On Sun, Oct 12, 2025 at 6:00 PM H. Peter Anvin hpa@zytor.com wrote:
On October 12, 2025 7:20:16 AM PDT, Sasha Levin sashal@kernel.org wrote:
This is a note to let you know that I've just added the patch titled
x86/vdso: Fix output operand size of RDPID
to the 6.16-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git%3Ba=su...
The filename of the patch is: x86-vdso-fix-output-operand-size-of-rdpid.patch and it can be found in the queue-6.16 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let stable@vger.kernel.org know about it.
commit 9e09c5e5e76f1bb0480722f36d5a266d2faaf00d Author: Uros Bizjak ubizjak@gmail.com Date: Mon Jun 16 11:52:57 2025 +0200
x86/vdso: Fix output operand size of RDPID
[ Upstream commit ac9c408ed19d535289ca59200dd6a44a6a2d6036 ]
RDPID instruction outputs to a word-sized register (64-bit on x86_64 and 32-bit on x86_32). Use an unsigned long variable to store the correct size.
LSL outputs to 32-bit register, use %k operand prefix to always print the 32-bit name of the register.
Use RDPID insn mnemonic while at it as the minimum binutils version of 2.30 supports it.
[ bp: Merge two patches touching the same function into a single one. ]
Fixes: ffebbaedc861 ("x86/vdso: Introduce helper functions for CPU and node number") Signed-off-by: Uros Bizjak ubizjak@gmail.com Signed-off-by: Borislav Petkov (AMD) bp@alien8.de Link: https://lore.kernel.org/20250616095315.230620-1-ubizjak@gmail.com Signed-off-by: Sasha Levin sashal@kernel.org
diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h index 77d8f49b92bdd..f59ae7186940a 100644 --- a/arch/x86/include/asm/segment.h +++ b/arch/x86/include/asm/segment.h @@ -244,7 +244,7 @@ static inline unsigned long vdso_encode_cpunode(int cpu, unsigned long node)
static inline void vdso_read_cpunode(unsigned *cpu, unsigned *node) {
unsigned int p;
unsigned long p; /* * Load CPU and node number from the GDT. LSL is faster than RDTSCP
@@ -254,10 +254,10 @@ static inline void vdso_read_cpunode(unsigned *cpu, unsigned *node) * * If RDPID is available, use it. */
alternative_io ("lsl %[seg],%[p]",
".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */
alternative_io ("lsl %[seg],%k[p]",
"rdpid %[p]", X86_FEATURE_RDPID,
[p] "=a" (p), [seg] "r" (__CPUNODE_SEG));
[p] "=r" (p), [seg] "r" (__CPUNODE_SEG)); if (cpu) *cpu = (p & VDSO_CPUNODE_MASK);
What the actual hell?!
Doesn't *anyone* know that x86 zero-extends a 32-bit value to 64 bits?
Yes, this is what %k does with LSL.
All this code does is put a completely unnecessary REX prefix on RDPID.
No, it doesn't.
$ more rdpid.s rdpid %eax $ gcc -c rdpid.s rdpid.s: Assembler messages: rdpid.s:1: Error: operand size mismatch for `rdpid'
$ more rdpid.s rdpid %rax $ gcc -c rdpid.s $ objdump -dr rdpid.o
rdpid.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <.text>: 0: f3 0f c7 f8 rdpid %rax
Uros.