linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: Use XORL r32,r32 in __get_user_asm
@ 2020-08-27 16:49 Uros Bizjak
  2020-08-27 17:23 ` H. Peter Anvin
  0 siblings, 1 reply; 2+ messages in thread
From: Uros Bizjak @ 2020-08-27 16:49 UTC (permalink / raw)
  To: x86, linux-kernel
  Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin

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

32bit operation also avoids 0x66 size prefix for 16bit operands
and REX prefix when %sil, %dil and %bpl 8bit registers are used.

As a bonus, 32bit XORL breaks register dependency chains, avoiding
potential partial register stalls with 8 and 16bit operands.

The patch lowers the size of .fixup section by 20 bytes.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
 arch/x86/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index ecefaffd15d4..2bffba2a1b23 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -343,7 +343,7 @@ do {									\
 		     "2:\n"						\
 		     ".section .fixup,\"ax\"\n"				\
 		     "3:	mov %[efault],%[errout]\n"		\
-		     "	xor"itype" %[output],%[output]\n"		\
+		     "	xorl %k[output],%k[output]\n"			\
 		     "	jmp 2b\n"					\
 		     ".previous\n"					\
 		     _ASM_EXTABLE_UA(1b, 3b)				\
-- 
2.26.2


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

* Re: [PATCH] x86: Use XORL r32,r32 in __get_user_asm
  2020-08-27 16:49 [PATCH] x86: Use XORL r32,r32 in __get_user_asm Uros Bizjak
@ 2020-08-27 17:23 ` H. Peter Anvin
  0 siblings, 0 replies; 2+ messages in thread
From: H. Peter Anvin @ 2020-08-27 17:23 UTC (permalink / raw)
  To: Uros Bizjak, x86, linux-kernel
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov

On 2020-08-27 09:49, Uros Bizjak wrote:
> Use XORL r32,r32 for all operand sizes. x86_64 zero extends 32bit
> operations, so for 64bit operands, XORL r32,r32 is functionally
> equal to XORL r64,r64, but avoids a REX prefix byte when legacy
> registers are used.

Please make it clear that this refers specifically to the use case of both
registers being the same, for zeroing. This could otherwise be misread.

"xorl r64,r64" is nonsensical: you're referring to xorq.

The apparent visual mix here between Intel and gas syntax is also confusing.

I would explicily say, using gcc inline syntax:

xorl %0,%0 is equivalent to xorq %0,%0 as both will zero the entire register.


> 32bit operation also avoids 0x66 size prefix for 16bit operands
> and REX prefix when %sil, %dil and %bpl 8bit registers are used.
> 
> As a bonus, 32bit XORL breaks register dependency chains, avoiding
> potential partial register stalls with 8 and 16bit operands.

Please make it clear that zeroing the full register is OK in this use case
(which it is.)

> The patch lowers the size of .fixup section by 20 bytes.

	-hpa



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

end of thread, other threads:[~2020-08-27 17:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 16:49 [PATCH] x86: Use XORL r32,r32 in __get_user_asm Uros Bizjak
2020-08-27 17:23 ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).