x86/paravirt: use common macro for creating simple asm paravirt functions
Subsystems (5)
Juergen Gross
maintainerPATCH v2 1/1 x86/paravirt: use common macro for creating simple asm paravirt functions
There are some paravirt assembler functions which are sharing a common pattern. Introduce a macro DEFINE_PARAVIRT_ASM() for creating them.
Note that this macro is including explicit alignment of the generated functions, leading to __raw_callee_save___kvm_vcpu_is_preempted(), _paravirt_nop() and paravirt_ret0() to be aligned at 4 byte boundaries now.
The explicit _paravirt_nop() prototype in paravirt.c isn't needed, as it is included in paravirt_types.h already.
---
V2:
- expanded commit message (Srivatsa S. Bhat)
--- arch/x86/include/asm/paravirt.h | 12 ++++++ arch/x86/include/asm/qspinlock_paravirt.h | 46 ++++++++++------------- arch/x86/kernel/kvm.c | 19 +++------- arch/x86/kernel/paravirt.c | 22 ++--------- 4 files changed, 40 insertions(+), 59 deletions(-)
arch/x86/include/asm/paravirt.h +12 -0
@@ -730,6 +730,18 @@ static __always_inline unsigned long arch_local_irq_save(void)#undef PVOP_VCALL4#undef PVOP_CALL4 +#define DEFINE_PARAVIRT_ASM (func, instr, sec) \ + asm (".pushsection " #sec ", \"ax\"\n" \ + ".global " #func "\n\t" \ + ".type " #func ", @function\n\t" \ + __ALIGN_STR "\n" \ + #func ":\n\t" \ + ASM_ENDBR \ + instr \ + ASM_RET \ + ".size " #func ", . - " #func "\n\t" \ + ".popsection") +extern void default_banner (void );#else /* __ASSEMBLY__ */
arch/x86/include/asm/qspinlock_paravirt.h +19 -27
59 lines not on this page · raw message
arch/x86/kernel/kvm.c +6 -13
@@ -798,19 +798,12 @@ extern bool __raw_callee_save___kvm_vcpu_is_preempted(long);* Hand-optimize version for x86-64 to avoid 8 64-bit register saving and * restoring to/from the stack. */ -asm( -".pushsection .text;" -".global __raw_callee_save___kvm_vcpu_is_preempted;" -".type __raw_callee_save___kvm_vcpu_is_preempted, @function;" -"__raw_callee_save___kvm_vcpu_is_preempted:" -ASM_ENDBR -"movq __per_cpu_offset(,%rdi,8), %rax;" -"cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax);" -"setne %al;" -ASM_RET -".size __raw_callee_save___kvm_vcpu_is_preempted, .-__raw_callee_save___kvm_vcpu_is_preempted;" -".popsection"); - +#define PV_VCPU_PREEMPTED_ASM \ + "movq __per_cpu_offset(,%rdi,8), %rax\n\t" \ + "cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax)\n\t" \ + "setne %al\n\t" +DEFINE_PARAVIRT_ASM (__raw_callee_save___kvm_vcpu_is_preempted, + PV_VCPU_PREEMPTED_ASM, .text);#endif static void __init kvm_guest_init (void )
arch/x86/kernel/paravirt.c +3 -19
@@ -37,27 +37,11 @@* nop stub, which must not clobber anything *including the stack* to * avoid confusing the entry prologues. */ -extern void _paravirt_nop (void ); -asm (".pushsection .entry.text, \"ax\"\n" -".global _paravirt_nop\n" -"_paravirt_nop:\n\t" -ASM_ENDBR -ASM_RET -".size _paravirt_nop, . - _paravirt_nop\n\t" -".type _paravirt_nop, @function\n\t" -".popsection" ); +DEFINE_PARAVIRT_ASM(_paravirt_nop, "", .entry.text);/* stub always returning 0. */ -asm (".pushsection .entry.text, \"ax\"\n" -".global paravirt_ret0\n" -"paravirt_ret0:\n\t" -ASM_ENDBR -"xor %" _ASM_AX", %" _ASM_AX";\n\t" -ASM_RET -".size paravirt_ret0, . - paravirt_ret0\n\t" -".type paravirt_ret0, @function\n\t" -".popsection" ); - +#define PV_RET0_ASM "xor %" _ASM_AX ", %" _ASM_AX "\n\t" +DEFINE_PARAVIRT_ASM(paravirt_ret0, PV_RET0_ASM, .entry.text);void __init default_banner (void ) {
Signature · 1 line
2.35.3
Quoted 8 lines · Juergen Gross
There are some paravirt assembler functions which are sharing a common pattern. Introduce a macro
DEFINE_PARAVIRT_ASM()for creating them.Note that this macro is including explicit alignment of the generated functions, leading to
__raw_callee_save___kvm_vcpu_is_preempted(),_paravirt_nop()andparavirt_ret0()to be aligned at 4 byte boundaries now.
Quoted 6 lines
The explicit
_paravirt_nop()prototype inparavirt.cisn't needed, as it is included inparavirt_types.halready.Signed-off-by Juergen Gross <[email protected]>Reviewed-by Srivatsa S. Bhat (VMware) <[email protected]>---
Seems nice; I've made the below little edits, but this is certainly a bit large for /urgent at this point in time. So how about I merge locking/urgent into x86/paravirt and munge this on top?
---
arch/x86/include/asm/paravirt.h +1 -1
@@ -737,7 +737,7 @@ static __always_inline unsigned long arc __ALIGN_STR "\n" \#func ":\n\t" \ ASM_ENDBR \ - instr \ + instr "\n\t" \ ASM_RET \ ".size " #func ", . - " #func "\n\t" \ ".popsection")
arch/x86/include/asm/qspinlock_paravirt.h +2 -2
@@ -54,8 +54,8 @@ __PV_CALLEE_SAVE_REGS_THUNK(__pv_queued_"pop %rdx\n\t" \FRAME_END -DEFINE_PARAVIRT_ASM (__raw_callee_save___pv_queued_spin_unlock,PV_UNLOCK_ASM , - .spinlock.text); +DEFINE_PARAVIRT_ASM (__raw_callee_save___pv_queued_spin_unlock, + PV_UNLOCK_ASM, .spinlock.text);#else /* CONFIG_64BIT */
arch/x86/kernel/kvm.c +1 -0
@@ -802,6 +802,7 @@ extern bool __raw_callee_save___kvm_vcpu"movq __per_cpu_offset(,%rdi,8), %rax\n\t" \ "cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax)\n\t" \"setne %al\n\t" +DEFINE_PARAVIRT_ASM (__raw_callee_save___kvm_vcpu_is_preempted, PV_VCPU_PREEMPTED_ASM, .text);#endif
arch/x86/kernel/paravirt.c +1 -2
@@ -40,8 +40,7 @@ DEFINE_PARAVIRT_ASM(_paravirt_nop, "", .entry.text);/* stub always returning 0. */ -#define PV_RET0_ASM "xor %" _ASM_AX ", %" _ASM_AX "\n\t" -DEFINE_PARAVIRT_ASM(paravirt_ret0, PV_RET0_ASM, .entry.text); +DEFINE_PARAVIRT_ASM(paravirt_ret0, "xor %eax,%eax", .entry.text);void __init default_banner (void ) {
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Juergen Gross
maintainerQuoted 12 lines · Peter Zijlstra
Quoted 11 lines · Juergen Gross
There are some paravirt assembler functions which are sharing a common pattern. Introduce a macro
DEFINE_PARAVIRT_ASM()for creating them.Note that this macro is including explicit alignment of the generated functions, leading to
__raw_callee_save___kvm_vcpu_is_preempted(),_paravirt_nop()andparavirt_ret0()to be aligned at 4 byte boundaries now.The explicit
_paravirt_nop()prototype inparavirt.cisn't needed, as it is included inparavirt_types.halready.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Juergen Gross <[email protected]>Reviewed-by Srivatsa S. Bhat (VMware) <[email protected]>---
Seems nice; I've made the below little edits, but this is certainly a bit large for /urgent at this point in time. So how about I merge locking/urgent into x86/paravirt and munge this on top?
Fine with me.
Thanks for looking at the patch,
Juergen
Quoted 39 lines
---
arch/x86/include/asm/paravirt.h +1
-1@@ -737,7 +737,7 @@ static __always_inline unsigned long arc __ALIGN_STR "\n" \#func ":\n\t" \ ASM_ENDBR \ - instr \ + instr "\n\t" \ ASM_RET \ ".size " #func ", . - " #func "\n\t" \ ".popsection")arch/x86/include/asm/qspinlock_paravirt.h +2
-2@@ -54,8 +54,8 @@ __PV_CALLEE_SAVE_REGS_THUNK(__pv_queued_"pop %rdx\n\t" \FRAME_END -DEFINE_PARAVIRT_ASM (__raw_callee_save___pv_queued_spin_unlock,PV_UNLOCK_ASM , - .spinlock.text); +DEFINE_PARAVIRT_ASM (__raw_callee_save___pv_queued_spin_unlock, + PV_UNLOCK_ASM, .spinlock.text);#else /* CONFIG_64BIT */ arch/x86/kernel/kvm.c +1
-0@@ -802,6 +802,7 @@ extern bool __raw_callee_save___kvm_vcpu"movq __per_cpu_offset(,%rdi,8), %rax\n\t" \ "cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax)\n\t" \"setne %al\n\t" +DEFINE_PARAVIRT_ASM (__raw_callee_save___kvm_vcpu_is_preempted, PV_VCPU_PREEMPTED_ASM, .text);#endif
arch/x86/kernel/paravirt.c line 46
Quoted 9 lines
arch/x86/kernel/paravirt.c +1
-2@@ -40,8 +40,7 @@ DEFINE_PARAVIRT_ASM(_paravirt_nop, "", .entry.text);/* stub always returning 0. */ -#define PV_RET0_ASM "xor %" _ASM_AX ", %" _ASM_AX "\n\t" -DEFINE_PARAVIRT_ASM(paravirt_ret0, PV_RET0_ASM, .entry.text); +DEFINE_PARAVIRT_ASM(paravirt_ret0, "xor %eax,%eax", .entry.text);void __init default_banner (void ) {
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[tip: x86/core] x86/paravirt: Use common macro for creating simple asm paravirt functions
In reply to Juergen GrossThe following commit has been merged into the x86/core branch of tip:
The following commit has been merged into the x86/core branch of tip:
Commit-ID: f1a033cc6b9eb6d80322008422df3c87aa5d47a0 Gitweb: https://git.kernel.org/tip/f1a033cc6b9eb6d80322008422df3c87aa5d47a0 Author: Juergen Gross <[email protected]> AuthorDate: Wed, 09 Nov 2022 14:44:18 +01:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Thu, 24 Nov 2022 13:56:44 +01:00
x86/paravirt: Use common macro for creating simple asm paravirt functions
There are some paravirt assembler functions which are sharing a common pattern. Introduce a macro DEFINE_PARAVIRT_ASM() for creating them.
Note that this macro is including explicit alignment of the generated functions, leading to __raw_callee_save___kvm_vcpu_is_preempted(), _paravirt_nop() and paravirt_ret0() to be aligned at 4 byte boundaries now.
The explicit _paravirt_nop() prototype in paravirt.c isn't needed, as it is included in paravirt_types.h already.
--- arch/x86/include/asm/paravirt.h | 12 ++++++- arch/x86/include/asm/qspinlock_paravirt.h | 47 +++++++++------------- arch/x86/kernel/kvm.c | 19 ++------- arch/x86/kernel/paravirt.c | 23 +----------- 4 files changed, 40 insertions(+), 61 deletions(-)
arch/x86/include/asm/paravirt.h +12 -0
@@ -731,6 +731,18 @@ static __always_inline unsigned long arch_local_irq_save(void)#undef PVOP_VCALL4#undef PVOP_CALL4 +#define DEFINE_PARAVIRT_ASM (func, instr, sec) \ + asm (".pushsection " #sec ", \"ax\"\n" \ + ".global " #func "\n\t" \ + ".type " #func ", @function\n\t" \ + ASM_FUNC_ALIGN "\n" \ + #func ":\n\t" \ + ASM_ENDBR \ + instr "\n\t" \ + ASM_RET \ + ".size " #func ", . - " #func "\n\t" \ + ".popsection") +extern void default_banner (void );#else /* __ASSEMBLY__ */
arch/x86/include/asm/qspinlock_paravirt.h +20 -27
60 lines not on this page · raw message
arch/x86/kernel/kvm.c +6 -13
@@ -798,20 +798,13 @@ extern bool __raw_callee_save___kvm_vcpu_is_preempted(long);* Hand-optimize version for x86-64 to avoid 8 64-bit register saving and * restoring to/from the stack. */ -asm( -".pushsection .text;" -".global __raw_callee_save___kvm_vcpu_is_preempted;" -".type __raw_callee_save___kvm_vcpu_is_preempted, @function;" -ASM_FUNC_ALIGN -"__raw_callee_save___kvm_vcpu_is_preempted:" -ASM_ENDBR -"movq __per_cpu_offset(,%rdi,8), %rax;" -"cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax);" -"setne %al;" -ASM_RET -".size __raw_callee_save___kvm_vcpu_is_preempted, .-__raw_callee_save___kvm_vcpu_is_preempted;" -".popsection"); +#define PV_VCPU_PREEMPTED_ASM \ + "movq __per_cpu_offset(,%rdi,8), %rax\n\t" \ + "cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax)\n\t" \ + "setne %al\n\t" +DEFINE_PARAVIRT_ASM (__raw_callee_save___kvm_vcpu_is_preempted, + PV_VCPU_PREEMPTED_ASM, .text);#endif static void __init kvm_guest_init (void )
arch/x86/kernel/paravirt.c +2 -21
@@ -37,29 +37,10 @@* nop stub, which must not clobber anything *including the stack* to * avoid confusing the entry prologues. */ -extern void _paravirt_nop (void ); -asm (".pushsection .entry.text, \"ax\"\n" -".global _paravirt_nop\n" -ASM_FUNC_ALIGN -"_paravirt_nop:\n\t" -ASM_ENDBR -ASM_RET -".size _paravirt_nop, . - _paravirt_nop\n\t" -".type _paravirt_nop, @function\n\t" -".popsection" ); +DEFINE_PARAVIRT_ASM(_paravirt_nop, "", .entry.text);/* stub always returning 0. */ -asm (".pushsection .entry.text, \"ax\"\n" -".global paravirt_ret0\n" -ASM_FUNC_ALIGN -"paravirt_ret0:\n\t" -ASM_ENDBR -"xor %" _ASM_AX", %" _ASM_AX";\n\t" -ASM_RET -".size paravirt_ret0, . - paravirt_ret0\n\t" -".type paravirt_ret0, @function\n\t" -".popsection" ); - +DEFINE_PARAVIRT_ASM(paravirt_ret0, "xor %eax,%eax", .entry.text);void __init default_banner (void ) {