Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/boot: Use 32-bit XOR to clear registers

x86_64 zero extends 32-bit operations, so for 64-bit operands,
XORL r32,r32 is functionally equal to XORQ r64,r64, but avoids
a REX prefix byte when legacy registers are used.

Slightly smaller code generated, no change in functionality.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20240124103859.611372-1-ubizjak@gmail.com

authored by

Uros Bizjak and committed by
Ingo Molnar
721f791c 891f8890

+4 -4
+3 -3
arch/x86/kernel/head_64.S
··· 169 169 ANNOTATE_NOENDBR 170 170 171 171 /* Clear %R15 which holds the boot_params pointer on the boot CPU */ 172 - xorq %r15, %r15 172 + xorl %r15d, %r15d 173 173 174 174 /* 175 175 * Retrieve the modifier (SME encryption mask if SME is active) to be ··· 178 178 #ifdef CONFIG_AMD_MEM_ENCRYPT 179 179 movq sme_me_mask, %rax 180 180 #else 181 - xorq %rax, %rax 181 + xorl %eax, %eax 182 182 #endif 183 183 184 184 /* Form the CR3 value being sure to include the CR3 modifier */ ··· 295 295 296 296 .Llookup_AP: 297 297 /* EAX contains the APIC ID of the current CPU */ 298 - xorq %rcx, %rcx 298 + xorl %ecx, %ecx 299 299 leaq cpuid_to_apicid(%rip), %rbx 300 300 301 301 .Lfind_cpunr:
+1 -1
arch/x86/kernel/sev_verify_cbit.S
··· 77 77 * The check failed, prevent any forward progress to prevent ROP 78 78 * attacks, invalidate the stack and go into a hlt loop. 79 79 */ 80 - xorq %rsp, %rsp 80 + xorl %esp, %esp 81 81 subq $0x1000, %rsp 82 82 2: hlt 83 83 jmp 2b