Skip to contentSkip to conversation

x86/paravirt: use %rip-relative addressing in hook calls

PATCH Applied Jan Beulich via Virtualization 3 participants 7 messages Sep 30, 2021 – Jan 24, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/paravirt: use %rip-relative addressing in hook calls

While using a plain (constant) address works, its use needlessly invokes a SIB addressing mode, making every call site one byte larger than necessary. Instead of using an "i" constraint with address-of operator and a 'c' operand modifier, simply use an ordinary "m" constraint, which the 64-bit compiler will translate to %rip-relative addressing. This way we also tell the compiler the truth about operand usage - the memory location gets actually read, after all.

32-bit code generation is unaffected by the change.

arch/x86/include/asm/paravirt_types.h +2 -2
@@ -278,7 +278,7 @@ extern void (*paravirt_iret)(void);
 
 #define paravirt_type(op)				\
 	[paravirt_typenum] "i" (PARAVIRT_PATCH(op)),	\
-	[paravirt_opptr] "i" (&(pv_ops.op))
+	[paravirt_opptr] "m" (pv_ops.op)
 #define paravirt_clobber(clobber)		\
 	[paravirt_clobber] "i" (clobber)
 
@@ -315,7 +315,7 @@ int paravirt_disable_iospace(void);
  */
 #define PARAVIRT_CALL					\
 	ANNOTATE_RETPOLINE_SAFE				\
-	"call *%c[paravirt_opptr];"
+	"call *%[paravirt_opptr];"
 
 /*
  * These macros are intended to wrap calls through one of the paravirt

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author Reviewed-by Juergen Gross on v1 1/1
#1 lore raw
Quoted 11 lines · Jan Beulich via Virtualization

While using a plain (constant) address works, its use needlessly invokes a SIB addressing mode, making every call site one byte larger than necessary. Instead of using an "i" constraint with address-of operator and a 'c' operand modifier, simply use an ordinary "m" constraint, which the 64-bit compiler will translate to %rip-relative addressing. This way we also tell the compiler the truth about operand usage - the memory location gets actually read, after all.

32-bit code generation is unaffected by the change.

Juergen

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#2 lore raw
Quoted 9 lines · Juergen Gross
Quoted 8 lines · Jan Beulich via Virtualization

While using a plain (constant) address works, its use needlessly invokes a SIB addressing mode, making every call site one byte larger than necessary. Instead of using an "i" constraint with address-of operator and a 'c' operand modifier, simply use an ordinary "m" constraint, which the 64-bit compiler will translate to %rip-relative addressing. This way we also tell the compiler the truth about operand usage - the memory location gets actually read, after all.

Quoted 5 lines
Quoted 3 lines

32-bit code generation is unaffected by the change.

Thanks. I notice this wasn't part of your 5.16-rc1 pull request, nor did it make it into Linus'es tree via any other route. May I ask what the plans here are?

Jan

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#3 lore raw
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Juergen Gross
Quoted 10 lines · Jan Beulich via Virtualization

While using a plain (constant) address works, its use needlessly invokes a SIB addressing mode, making every call site one byte larger than necessary. Instead of using an "i" constraint with address-of operator and a 'c' operand modifier, simply use an ordinary "m" constraint, which the 64-bit compiler will translate to %rip-relative addressing. This way we also tell the compiler the truth about operand usage - the memory location gets actually read, after all.

32-bit code generation is unaffected by the change.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks. I notice this wasn't part of your 5.16-rc1 pull request, nor did it make it into Linus'es tree via any other route. May I ask what the plans here are?

I CC-ed you on the related mail I sent to the x86 maintainers:

"Re: Which tree for paravirt related patches?" on Nov 4th, and Thomas Gleixner promised to look at your patch. Adding him to this response again in order to remind him.

Juergen

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#4 lore raw
Quoted 21 lines · Juergen Gross via Virtualization
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Juergen Gross
Quoted 10 lines · Jan Beulich via Virtualization

While using a plain (constant) address works, its use needlessly invokes a SIB addressing mode, making every call site one byte larger than necessary. Instead of using an "i" constraint with address-of operator and a 'c' operand modifier, simply use an ordinary "m" constraint, which the 64-bit compiler will translate to %rip-relative addressing. This way we also tell the compiler the truth about operand usage - the memory location gets actually read, after all.

32-bit code generation is unaffected by the change.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks. I notice this wasn't part of your 5.16-rc1 pull request, nor did it make it into Linus'es tree via any other route. May I ask what the plans here are?

Quoted 5 lines

I CC-ed you on the related mail I sent to the x86 maintainers:

"Re: Which tree for paravirt related patches?" on Nov 4th, and Thomas Gleixner promised to look at your patch. Adding him to this response again in order to remind him.

Thomas, another ping. Didn't you want to take this patch more than a month ago? Cc-ing the other x86 maintainers, too.

Juergen

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

maintainer
#5 lore raw
Quoted 2 lines · Juergen Gross

Thomas, another ping. Didn't you want to take this patch more than a month ago? Cc-ing the other x86 maintainers, too.

I'll have a look after the merge window is over.

Thx.

Signature · 8 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
merge bot Applied
#6 lore raw

[tip: x86/paravirt] x86/paravirt: Use %rip-relative addressing in hook calls

In reply to Jan Beulich via Virtualization
The following commit has been merged into the x86/paravirt branch of tip:

The following commit has been merged into the x86/paravirt branch of tip:

Commit-ID:     2e1f8e55f9e054b4a49ffc06c7e33b5d4725f05e
Gitweb:        https://git.kernel.org/tip/2e1f8e55f9e054b4a49ffc06c7e33b5d4725f05e
Author:        Jan Beulich <[email protected]>
AuthorDate:    Thu, 30 Sep 2021 14:40:38 +02:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Mon, 24 Jan 2022 20:21:19 +01:00

x86/paravirt: Use %rip-relative addressing in hook calls

While using a plain (constant) address works, its use needlessly invokes a SIB addressing mode, making every call site one byte larger than necessary:

ff 14 25 98 89 42 82 call *0xffffffff82428998

Instead of using an "i" constraint with address-of operator and a 'c' operand modifier, simply use an ordinary "m" constraint, which the 64-bit compiler will translate to %rip-relative addressing:

ff 15 62 fb d2 00 call *0xd2fb62(%rip) # ffffffff82428998 <pv_ops+0x18>

This way the compiler is also told the truth about operand usage - the memory location gets actually read, after all.

32-bit code generation is unaffected by the change.

[ bp: Remove "we", add examples. ]

---
 arch/x86/include/asm/paravirt_types.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/paravirt_types.h +2 -2
index a69012e..e159146 100644
@@ -279,7 +279,7 @@ extern void (*paravirt_iret)(void);
 
 #define paravirt_type(op)				\
 	[paravirt_typenum] "i" (PARAVIRT_PATCH(op)),	\
-	[paravirt_opptr] "i" (&(pv_ops.op))
+	[paravirt_opptr] "m" (pv_ops.op)
 #define paravirt_clobber(clobber)		\
 	[paravirt_clobber] "i" (clobber)
 
@@ -316,7 +316,7 @@ int paravirt_disable_iospace(void);
  */
 #define PARAVIRT_CALL					\
 	ANNOTATE_RETPOLINE_SAFE				\
-	"call *%c[paravirt_opptr];"
+	"call *%[paravirt_opptr];"
 
 /*
  * These macros are intended to wrap calls through one of the paravirt