xen: Use asm inline
cover xen: Use asm inline
Since v1, split into multiple patches. Extend to BUG_FRAME and EXTABLE too.
https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/1819941756
Andrew Cooper (3):
xen: Introduce asm inline and use it for BUG_FRAME
x86: Use asm_inline for ALTERNATIVE() and EXTABLE
ARM: Use asm_inline for ALTERNATIVE()
xen/Kconfig | 4 ++ xen/arch/arm/include/asm/alternative.h | 4 +- xen/arch/arm/include/asm/arm64/flushtlb.h | 4 +- xen/arch/arm/include/asm/arm64/io.h | 43 ++++++++++------- xen/arch/arm/include/asm/bug.h | 6 ++- xen/arch/arm/include/asm/cpuerrata.h | 8 ++-- xen/arch/arm/include/asm/cpufeature.h | 8 ++-- xen/arch/arm/include/asm/page.h | 12 +++-- xen/arch/arm/include/asm/processor.h | 7 +-- xen/arch/arm/include/asm/sysregs.h | 10 ++-- xen/arch/arm/mmu/p2m.c | 3 +- xen/arch/x86/cpu/amd.c | 52 +++++++++++---------- xen/arch/x86/domain.c | 21 +++++---- xen/arch/x86/extable.c | 21 +++++---- xen/arch/x86/hvm/vmx/vmcs.c | 15 +++--- xen/arch/x86/i387.c | 4 +- xen/arch/x86/include/asm/alternative-call.h | 3 +- xen/arch/x86/include/asm/alternative.h | 36 ++++++++------ xen/arch/x86/include/asm/hvm/vmx/vmx.h | 15 +++--- xen/arch/x86/include/asm/uaccess.h | 4 +- xen/arch/x86/pv/misc-hypercalls.c | 19 ++++---- xen/arch/x86/traps.c | 48 ++++++++++--------- xen/arch/x86/usercopy.c | 6 +-- xen/include/xen/bug.h | 11 +++-- xen/include/xen/compiler.h | 15 ++++++ 25 files changed, 219 insertions(+), 160 deletions(-)
Signature · 1 line
2.39.5
PATCH 1/3 xen: Introduce asm inline and use it for BUG_FRAME
Compilers estimate the size of an asm() block for inlining purposes.
Constructs with embedded metadata (BUG_FRAME, ALTERNATIVE, EXTABLE, etc) appear large, depsite often only being a handful of instructions. asm inline() overrides the estimation to identify the block as being small.
This has a substantial impact on inlining decisions, expected to be for the better given that the compiler has a more accurate picture to work with.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
v2:
* Split into multiple patches
* Start with BUG().
The full bloat-o-meter for this on x86 is https://termbin.com/27we although the saving is better than reported.
Note the pairs such as:
vmx_update_secondary_exec_control.part 2 - -2
vmx_update_secondary_exec_control 60 57 -3
This is becuse the UD2 was out-of-lined, and was CALL'd. When inlined, the 5 byte CALL instruction in is replace with the 2 byte UD2. Further than reported, we save another 14 bytes due to the 16 byte function alignment.
This undoes an unanticipated side effect of starting to use asm goto().
--- xen/Kconfig | 4 ++++ xen/arch/arm/include/asm/bug.h | 6 ++++-- xen/include/xen/bug.h | 11 ++++++----- xen/include/xen/compiler.h | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 7 deletions(-)
xen/Kconfig +4 -0
@@ -29,6 +29,10 @@ config LD_IS_GNU config LD_IS_LLVM def_bool $(success,$(LD) --version | head -n 1 | grep -q "^LLD") +config CC_HAS_ASM_INLINE + # GCC >= 9, Clang >= 11 + def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null) + # Use -f{function,data}-sections compiler parameters config CC_SPLIT_SECTIONS bool
xen/arch/arm/include/asm/bug.h +4 -2
@@ -34,7 +34,8 @@ struct bug_frame {#define BUG_FRAME (type, line, file, has_msg, msg) do { \ BUILD_BUG_ON((line) >> 16); \ BUILD_BUG_ON((type) >= BUGFRAME_NR); \ - asm ("1:"BUG_INSTR"\n" \ + asm_inline ( \ + "1:"BUG_INSTR"\n" \ ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ "2:\t.asciz " __stringify(file) "\n" \ "3:\n" \
@@ -60,7 +61,8 @@ struct bug_frame {*/ #define run_in_exception_handler (fn) do { \ register unsigned long _fn asm (STR(BUG_FN_REG)) = (unsigned long)(fn); \ - asm ("1:"BUG_INSTR"\n" \ + asm_inline ( \ + "1:"BUG_INSTR"\n" \ ".pushsection .bug_frames." __stringify(BUGFRAME_run_fn) "," \ " \"a\", %%progbits\n" \ "2:\n" \
xen/include/xen/bug.h +6 -5
@@ -89,11 +89,12 @@ struct bug_frame {#ifndef BUG_FRAME #define BUG_FRAME (type, line, ptr, second_frame, msg) do { \ - BUG_CHECK_LINE_WIDTH(line); \ - BUILD_BUG_ON((type) >= BUGFRAME_NR); \ - asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \ - :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \ -} while ( false ) + BUG_CHECK_LINE_WIDTH(line); \ + BUILD_BUG_ON((type) >= BUGFRAME_NR); \ + asm_inline volatile ( \ + _ASM_BUGFRAME_TEXT(second_frame) \ + :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \ + } while ( false )#endif
xen/include/xen/compiler.h +15 -0
@@ -53,6 +53,21 @@#define unreachable () __builtin_unreachable()#endif +/* +* Compilers estimate the size of an asm() block for inlining purposes. +* +* Constructs with embedded metadata (BUG_FRAME, ALTERNATIVE, EXTABLE, etc) +* appear large, depsite typically only being a handful of instructions. asm +* inline() overrides the estimation to identify the block as being small. +* +* Note: __inline is needed to avoid getting caught up in INIT_SECTIONS_ONLY. +*/ +#if CONFIG_CC_HAS_ASM_INLINE +# define asm_inline asm __inline +#else +# define asm_inline asm +#endif +/* * Add the pseudo keyword 'fallthrough' so case statement blocks * must end with any of these keywords:
Signature · 1 line
2.39.5
Re: [PATCH 1/3] xen: Introduce asm inline and use it for BUG_FRAME
Quoted 6 lines · Andrew Cooper
Compilers estimate the size of an
asm()block for inlining purposes.Constructs with embedded metadata (
BUG_FRAME, ALTERNATIVE, EXTABLE, etc) appear large, depsite often only being a handful of instructions. asminline()overrides the estimation to identify the block as being small.
Quoted 6 lines
This has a substantial impact on inlining decisions, expected to be for the better given that the compiler has a more accurate picture to work with.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Stefano Stabellini
Acked-byRe: [PATCH 1/3] xen: Introduce asm inline and use it for BUG_FRAME
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Compilers estimate the size of an
asm()block for inlining purposes.Constructs with embedded metadata (
BUG_FRAME, ALTERNATIVE, EXTABLE, etc) appear large, depsite often only being a handful of instructions. asminline()overrides the estimation to identify the block as being small.
Quoted 8 lines
Quoted 6 lines
This has a substantial impact on inlining decisions, expected to be for the better given that the compiler has a more accurate picture to work with.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>
arm:
PATCH 2/3 x86: Use asm_inline for ALTERNATIVE() and EXTABLE
In reply to Andrew Cooper... when there really are only a few instructions in line.
In some cases, reformat to reduce left-hand margine space.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
v2:
* New, split out of previous single patch
* Include EXTABLE
There are some uses of _ASM_EXTABLE() which are in blocks with many instructions which are left unconverted. There are also a couple for which I already have pending cleanup, which I've left alone to reduce churn.
--- xen/arch/x86/cpu/amd.c | 52 +++++++++++---------- xen/arch/x86/domain.c | 21 +++++---- xen/arch/x86/extable.c | 21 +++++---- xen/arch/x86/hvm/vmx/vmcs.c | 15 +++--- xen/arch/x86/i387.c | 4 +- xen/arch/x86/include/asm/alternative-call.h | 3 +- xen/arch/x86/include/asm/alternative.h | 36 ++++++++------ xen/arch/x86/include/asm/hvm/vmx/vmx.h | 15 +++--- xen/arch/x86/include/asm/uaccess.h | 4 +- xen/arch/x86/pv/misc-hypercalls.c | 19 ++++---- xen/arch/x86/traps.c | 48 ++++++++++--------- xen/arch/x86/usercopy.c | 6 +-- 12 files changed, 132 insertions(+), 112 deletions(-)
xen/arch/x86/cpu/amd.c +28 -24
@@ -60,41 +60,45 @@ static inline int rdmsr_amd_safe(unsigned int msr, unsigned int *lo, unsigned int *hi) {#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT - asm goto ( "1: rdmsr\n\t" - _ASM_EXTABLE(1b, %l[fault]) - : "=a" (*lo), "=d" (*hi) - : "c" (msr), "D" (0x9c5a203a) - : - : fault ); + asm_inline goto ( + "1: rdmsr\n\t" + _ASM_EXTABLE(1b, %l[fault]) + : "=a" (*lo), "=d" (*hi) + : "c" (msr), "D" (0x9c5a203a) + : + : fault ); +return 0 ; fault:return -EFAULT ;#else -int err; - - asm volatile("1: rdmsr\n2:\n" - ".section .fixup,\"ax\"\n" - "3: movl %6,%2\n" - " jmp 2b\n" - ".previous\n" - _ASM_EXTABLE(1b, 3b) - : "=a" (*lo), "=d" (*hi), "=r" (err) - : "c" (msr), "D" (0x9c5a203a), "2" (0), "i" (-EFAULT)); - -return err; +int err; + + asm_inline volatile ( + "1: rdmsr\n2:\n" + ".section .fixup,\"ax\"\n" + "3: movl %6,%2\n" + " jmp 2b\n" + ".previous\n" + _ASM_EXTABLE(1b, 3b) + : "=a" (*lo), "=d" (*hi), "=r" (err) + : "c" (msr), "D" (0x9c5a203a), "2" (0), "i" (-EFAULT) ); + +return err;#endif }static inline int wrmsr_amd_safe (unsigned int msr,unsigned int lo,unsigned int hi) { - asm goto ( "1: wrmsr\n\t" - _ASM_EXTABLE(1b, %l[fault]) - : - : "c" (msr), "a" (lo), "d" (hi), "D" (0x9c5a203a) - : - : fault ); + asm_inline goto ( + "1: wrmsr\n\t" + _ASM_EXTABLE(1b, %l[fault]) + : + : "c" (msr), "a" (lo), "d" (hi), "D" (0x9c5a203a) + : + : fault );return 0 ;
xen/arch/x86/domain.c +11 -10
@@ -1706,16 +1706,17 @@ static void load_segments(struct vcpu *n)* @all_segs_okay in function scope, and load NUL into @sel. */ #define TRY_LOAD_SEG (seg, val) \ - asm volatile ( "1: mov %k[_val], %%" #seg "\n\t" \ - "2:\n\t" \ - ".section .fixup, \"ax\"\n\t" \ - "3: xor %k[ok], %k[ok]\n\t" \ - " mov %k[ok], %%" #seg "\n\t" \ - " jmp 2b\n\t" \ - ".previous\n\t" \ - _ASM_EXTABLE(1b, 3b) \ - : [ok] "+r" (all_segs_okay) \ - : [_val] "rm" (val) ) + asm_inline volatile ( \ + "1: mov %k[_val], %%" #seg "\n\t" \ + "2:\n\t" \ + ".section .fixup, \"ax\"\n\t" \ + "3: xor %k[ok], %k[ok]\n\t" \ + " mov %k[ok], %%" #seg "\n\t" \ + " jmp 2b\n\t" \ + ".previous\n\t" \ + _ASM_EXTABLE(1b, 3b) \ + : [ok] "+r" (all_segs_okay) \ + : [_val] "rm" (val) )if ( !compat ) {
xen/arch/x86/extable.c +11 -10
@@ -186,16 +186,17 @@ int __init cf_check stub_selftest(void)place_ret (ptr +ARRAY_SIZE (tests[i].opc));unmap_domain_page (ptr); - asmvolatile ("INDIRECT_CALL %[stb]\n" -".Lret%=:\n\t" -".pushsection .fixup,\"ax\"\n" -".Lfix%=:\n\t" -"pop %[exn]\n\t" -"jmp .Lret%=\n\t" -".popsection\n\t" - _ASM_EXTABLE(.Lret%=, .Lfix%=) - : [exn] "+m" (res) ASM_CALL_CONSTRAINT - : [stb] "r" (addr), "a" (tests[i].rax)); + asm_inline volatile ( +"INDIRECT_CALL %[stb]\n" +".Lret%=:\n\t" +".pushsection .fixup,\"ax\"\n" +".Lfix%=:\n\t" +"pop %[exn]\n\t" +"jmp .Lret%=\n\t" +".popsection\n\t" + _ASM_EXTABLE(.Lret%=, .Lfix%=) + : [exn] "+m" (res) ASM_CALL_CONSTRAINT + : [stb] "r" (addr), "a" (tests[i].rax) );if ( res.raw != tests[i].res.raw ) {
xen/arch/x86/hvm/vmx/vmcs.c +8 -7
@@ -749,13 +749,14 @@ static int _vmx_cpu_up(bool bsp)if ( bsp && (rc =vmx_cpu_up_prepare (cpu)) !=0 )return rc; - asm goto ("1: vmxon %[addr]\n\t" -" jbe %l[vmxon_fail]\n\t" - _ASM_EXTABLE(1b, %l[vmxon_fault]) - : - : [addr] "m" (this_cpu(vmxon_region)) - : "memory" - : vmxon_fail, vmxon_fault ); + asm_inline goto ( + "1: vmxon %[addr]\n\t" + " jbe %l[vmxon_fail]\n\t" + _ASM_EXTABLE(1b, %l[vmxon_fault]) + : + : [addr] "m" (this_cpu(vmxon_region)) + : "memory" + : vmxon_fail, vmxon_fault );this_cpu (vmxon) =1 ;
xen/arch/x86/i387.c +2 -2
@@ -62,7 +62,7 @@ static inline void fpu_fxrstor(struct vcpu *v)switch (__builtin_expect (fpu_ctxt->x[FPU_WORD_SIZE_OFFSET ],8 ) ) {default : - asmvolatile ( + asm_inline volatile ("1: fxrstorq %0\n" ".section .fixup,\"ax\" \n" "2: push %%" __OP"ax \n"
@@ -82,7 +82,7 @@ static inline void fpu_fxrstor(struct vcpu *v) : "m" (*fpu_ctxt), "i" (sizeof(*fpu_ctxt) / 4) );break ;case 4 :case 2 : - asmvolatile ( + asm_inline volatile ("1: fxrstor %0 \n" ".section .fixup,\"ax\"\n" "2: push %%" __OP"ax \n"
xen/arch/x86/include/asm/alternative-call.h +2 -1
@@ -87,7 +87,8 @@ struct alt_call {rettype ret_; \ registerunsigned long r10_ asm("r10" ); \ registerunsigned long r11_ asm("r11" ); \ - asmvolatile ("1: call *%c[addr](%%rip)\n\t" \ + asm_inline volatile ( \ +"1: call *%c[addr](%%rip)\n\t" \".pushsection .alt_call_sites, \"a\", @progbits\n\t" \".long 1b - .\n\t" \".popsection" \
xen/arch/x86/include/asm/alternative.h +21 -15
@@ -126,12 +126,15 @@ extern void alternative_instructions(void);* without volatile and memory clobber. */ #define alternative (oldinstr, newinstr, feature) \ - asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) : : : "memory") + asm_inline volatile ( \ + ALTERNATIVE(oldinstr, newinstr, feature) \ + ::: "memory" )#define alternative_2 (oldinstr, newinstr1, feature1, newinstr2, feature2) \ - asm volatile (ALTERNATIVE_2(oldinstr, newinstr1, feature1, \ - newinstr2, feature2) \ - : : : "memory") + asm_inline volatile ( \ + ALTERNATIVE_2(oldinstr, newinstr1, feature1, \ + newinstr2, feature2) \ + ::: "memory" )/* * Alternative inline assembly with input.
@@ -143,14 +146,16 @@ extern void alternative_instructions(void);* If you use variable sized constraints like "m" or "g" in the * replacement make sure to pad to the worst case length. */ -#define alternative_input(oldinstr, newinstr, feature, input...) \ - asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \ - : : input) +#define alternative_input(oldinstr, newinstr, feature, input...) \ + asm_inline volatile ( \ + ALTERNATIVE(oldinstr, newinstr, feature) \ + :: input )/* Like alternative_input, but with a single output argument */ -#define alternative_io(oldinstr, newinstr, feature, output, input...) \ - asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \ - : output : input) +#define alternative_io(oldinstr, newinstr, feature, output, input...) \ + asm_inline volatile ( \ + ALTERNATIVE(oldinstr, newinstr, feature) \ + : output : input )/* * This is similar to alternative_io. But it has two features and
@@ -160,11 +165,12 @@ extern void alternative_instructions(void);* Otherwise, if CPU has feature1, newinstr1 is used. * Otherwise, oldinstr is used. */ -#define alternative_io_2 (oldinstr, newinstr1, feature1, newinstr2, \ - feature2, output, input...) \ - asm volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, \ - newinstr2, feature2) \ - : output : input) +#define alternative_io_2 (oldinstr, newinstr1, feature1, newinstr2, \ + feature2, output, input...) \ + asm_inline volatile ( \ + ALTERNATIVE_2(oldinstr, newinstr1, feature1, \ + newinstr2, feature2) \ + : output : input )/* Use this macro(s) if you need more than one output parameter. */ #define ASM_OUTPUT2(a...) a
xen/arch/x86/include/asm/hvm/vmx/vmx.h +8 -7
@@ -431,13 +431,14 @@ static always_inline void __invvpid(unsigned long type, u16 vpid, u64 gva) } operand = {vpid, 0, gva};/* Fix up #UD exceptions which occur when TLBs are flushed before VMXON. */ - asm goto ("1: invvpid %[operand], %[type]\n\t" -" jbe %l[vmfail]\n\t" - "2:" _ASM_EXTABLE(1b, 2b) - : - : [operand] "m" (operand), [type] "r" (type) - : "memory" - : vmfail ); + asm_inline goto ( + "1: invvpid %[operand], %[type]\n\t" + " jbe %l[vmfail]\n\t" + "2:" _ASM_EXTABLE(1b, 2b) + : + : [operand] "m" (operand), [type] "r" (type) + : "memory" + : vmfail );return ; vmfail:
xen/arch/x86/include/asm/uaccess.h +2 -2
@@ -154,7 +154,7 @@ struct __large_struct { unsigned long buf[100]; };* aliasing issues. */ #define put_unsafe_asm (x, addr,GUARD , err, itype, rtype, ltype, errret) \ - __asm__ __volatile__( \ + asm_inline volatile ( \ GUARD( \ " guest_access_mask_ptr %[ptr], %[scr1], %[scr2]\n" \ ) \
@@ -171,7 +171,7 @@ struct __large_struct { unsigned long buf[100]; }; "[ptr]" (addr), [errno] "i" (errret))#define get_unsafe_asm (x, addr,GUARD , err, rtype, ltype, errret) \ - __asm__ __volatile__( \ + asm_inline volatile ( \ GUARD( \ " guest_access_mask_ptr %[ptr], %[scr1], %[scr2]\n" \ ) \
xen/arch/x86/pv/misc-hypercalls.c +10 -9
@@ -230,15 +230,16 @@ long do_set_segment_base(unsigned int which, unsigned long base)* Anyone wanting to check for errors from this hypercall should * re-read %gs and compare against the input. */ - asmvolatile ("1: mov %[sel], %%gs\n\t" -".section .fixup, \"ax\", @progbits\n\t" -"2: mov %k[flat], %%gs\n\t" -" xor %[sel], %[sel]\n\t" -" jmp 1b\n\t" -".previous\n\t" - _ASM_EXTABLE(1b, 2b) - : [sel] "+r" (sel) - : [flat] "r" (FLAT_USER_DS32) ); + asm_inline volatile ( +"1: mov %[sel], %%gs\n\t" +".section .fixup, \"ax\", @progbits\n\t" +"2: mov %k[flat], %%gs\n\t" +" xor %[sel], %[sel]\n\t" +" jmp 1b\n\t" +".previous\n\t" + _ASM_EXTABLE(1b ,2b ) + : [sel] "+r" (sel) + : [flat] "r" (FLAT_USER_DS32) );/* Update the cache of the inactive base, as read from the GDT/LDT. */ v->arch.pv.gs_base_user =read_gs_base ();
xen/arch/x86/traps.c +26 -22
65 lines not on this page · raw message
xen/arch/x86/usercopy.c +3 -3
@@ -19,7 +19,7 @@ unsigned int copy_to_guest_ll(void __user *to, const void *from, unsigned int n)GUARD (unsigned dummy );stac (); - asmvolatile ( + asm_inline volatile ( GUARD(" guest_access_mask_ptr %[to], %q[scratch1], %q[scratch2]\n" )
@@ -39,7 +39,7 @@ unsigned int copy_from_guest_ll(void *to, const void __user *from, unsigned intunsigned dummy;stac (); - asmvolatile ( + asm_inline volatile ( GUARD(" guest_access_mask_ptr %[from], %q[scratch1], %q[scratch2]\n" )
@@ -101,7 +101,7 @@ unsigned int clear_guest_pv(void __user *to, unsigned int n)long dummy;stac (); - asmvolatile ( + asm_inline volatile (" guest_access_mask_ptr %[to], %[scratch1], %[scratch2]\n" "1: rep stosb\n" "2:\n"
Signature · 1 line
2.39.5
Re: [PATCH 2/3] x86: Use asm_inline for ALTERNATIVE() and EXTABLE
Quoted 7 lines · Andrew Cooper
... when there really are only a few instructions in line.
In some cases, reformat to reduce left-hand margine space.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
PATCH 3/3 ARM: Use asm_inline for ALTERNATIVE()
In reply to Andrew Cooper... when there really are only a few instructions in line.
In some cases, reformat to reduce left-hand margine space.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
v2:
* New, split out of previous single patch
--- xen/arch/arm/include/asm/alternative.h | 4 +-- xen/arch/arm/include/asm/arm64/flushtlb.h | 4 +-- xen/arch/arm/include/asm/arm64/io.h | 43 ++++++++++++++--------- xen/arch/arm/include/asm/cpuerrata.h | 8 ++--- xen/arch/arm/include/asm/cpufeature.h | 8 ++--- xen/arch/arm/include/asm/page.h | 12 ++++--- xen/arch/arm/include/asm/processor.h | 7 ++-- xen/arch/arm/include/asm/sysregs.h | 10 +++--- xen/arch/arm/mmu/p2m.c | 3 +- 9 files changed, 58 insertions(+), 41 deletions(-)
xen/arch/arm/include/asm/alternative.h +2 -2
@@ -209,9 +209,9 @@ alternative_endif#endif /* __ASSEMBLY__ */ /* -* Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature)); +* Usage: asm_inline (ALTERNATIVE(oldinstr, newinstr, feature)); * -* Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature, CONFIG_FOO)); +* Usage: asm_inline (ALTERNATIVE(oldinstr, newinstr, feature, CONFIG_FOO)); * N.B. If CONFIG_FOO is specified, but not selected, the whole block * will be omitted, including oldinstr. */
xen/arch/arm/include/asm/arm64/flushtlb.h +2 -2
@@ -31,7 +31,7 @@#define TLB_HELPER (name, tlbop, sh) \ static inline void name(void) \ { \ - asm volatile( \ + asm_inline volatile ( \ "dsb " # sh "st;" \ "tlbi " # tlbop ";" \ ALTERNATIVE( \
@@ -55,7 +55,7 @@ static inline void name(void) \#define TLB_HELPER_VA (name, tlbop) \ static inline void name(vaddr_t va) \ { \ - asm volatile( \ + asm_inline volatile ( \ "tlbi " # tlbop ", %0;" \ ALTERNATIVE( \ "nop; nop;", \
xen/arch/arm/include/asm/arm64/io.h +27 -16
67 lines not on this page · raw message
xen/arch/arm/include/asm/cpuerrata.h +4 -4
@@ -16,10 +16,10 @@ static inline bool check_workaround_##erratum(void) \ { \register_t ret; \ \ - asm volatile (ALTERNATIVE("mov %0, #0", \ - "mov %0, #1", \ - feature) \ - : "=r" (ret)); \ + asm_inline volatile ( \ + ALTERNATIVE("mov %0, #0", \ + "mov %0, #1", feature) \ + : "=r" (ret) ); \ \return unlikely (ret); \ } \
xen/arch/arm/include/asm/cpufeature.h +4 -4
@@ -102,10 +102,10 @@ static inline bool cpus_have_cap(unsigned int num)#define cpus_have_const_cap (num) ({ \ register_t __ret; \ \ - asm volatile (ALTERNATIVE("mov %0, #0", \ - "mov %0, #1", \ - num) \ - : "=r" (__ret)); \ + asm_inline volatile ( \ + ALTERNATIVE("mov %0, #0", \ + "mov %0, #1", num) \ + : "=r" (__ret) ); \ \ unlikely(__ret); \ })
xen/arch/arm/include/asm/page.h +7 -5
@@ -176,7 +176,8 @@ static inline int invalidate_dcache_va_range(const void *p, unsigned long size) { size -= dcache_line_bytes - ((uintptr_t )p & cacheline_mask); p = (void *)((uintptr_t )p & ~cacheline_mask); - asm volatile (__clean_and_invalidate_dcache_one(0) : : "r" (p)); +asm_inline volatile ( + __clean_and_invalidate_dcache_one(0) :: "r" (p) ); p += dcache_line_bytes; }
@@ -185,7 +186,8 @@ static inline int invalidate_dcache_va_range(const void *p, unsigned long size) asm volatile (__invalidate_dcache_one(0) : : "r" (p + idx));if ( size >0 ) - asm volatile (__clean_and_invalidate_dcache_one(0) : : "r" (p + idx)); + asm_inline volatile ( + __clean_and_invalidate_dcache_one(0) :: "r" (p + idx) );dsb (sy);/* So we know the flushes happen before continuing */
@@ -209,7 +211,7 @@ static inline int clean_dcache_va_range(const void *p, unsigned long size) p = (void *)((uintptr_t )p & ~cacheline_mask);for ( ; size >= dcache_line_bytes; idx += dcache_line_bytes, size -= dcache_line_bytes ) - asm volatile (__clean_dcache_one(0) : : "r" (p + idx)); + asm_inline volatile ( __clean_dcache_one(0) : : "r" (p + idx) );dsb (sy);/* So we know the flushes happen before continuing */ /* ARM callers assume that dcache_* functions cannot fail. */ return 0 ;
@@ -247,7 +249,7 @@ static inline int clean_and_invalidate_dcache_va_rangeif (sizeof (x) >MIN_CACHELINE_BYTES ||sizeof (x) > alignof(x ) ) \clean_dcache_va_range (_p,sizeof (x)); \else \ - asmvolatile ( \ + asm_inline volatile ( \ "dsb sy;" /* Finish all earlier writes */ \ __clean_dcache_one(0) \ "dsb sy;" /* Finish flush before continuing */ \
@@ -259,7 +261,7 @@ static inline int clean_and_invalidate_dcache_va_rangeif (sizeof (x) >MIN_CACHELINE_BYTES ||sizeof (x) > alignof(x ) ) \clean_and_invalidate_dcache_va_range (_p,sizeof (x)); \else \ - asmvolatile ( \ + asm_inline volatile ( \ "dsb sy;" /* Finish all earlier writes */ \ __clean_and_invalidate_dcache_one(0) \ "dsb sy;" /* Finish flush before continuing */ \
xen/arch/arm/include/asm/processor.h +4 -3
@@ -607,9 +607,10 @@ register_t get_default_cptr_flags(void);#define SYNCHRONIZE_SERROR (feat) \ do { \ ASSERT(local_abort_is_enabled()); \ - asm volatile(ALTERNATIVE("dsb sy; isb", \ - "nop; nop", feat) \ - : : : "memory"); \ + asm_inline volatile ( \ + ALTERNATIVE("dsb sy; isb", \ + "nop; nop", feat) \ + ::: "memory" ); \ } while (0)/*
xen/arch/arm/include/asm/sysregs.h +6 -4
@@ -22,11 +22,13 @@ static inline register_t read_sysreg_par(void)* DMB SY before and after accessing it, as part of the workaround for the * errata 1508412. */ - asm volatile(ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412, - CONFIG_ARM64_ERRATUM_1508412)); + asm_inline volatile ( + ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412, + CONFIG_ARM64_ERRATUM_1508412) ); par_el1 =READ_SYSREG64 (PAR_EL1 ); - asm volatile(ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412, - CONFIG_ARM64_ERRATUM_1508412)); + asm_inline volatile ( + ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412, + CONFIG_ARM64_ERRATUM_1508412) );return par_el1; }
xen/arch/arm/mmu/p2m.c +2 -1
@@ -228,7 +228,8 @@ void p2m_restore_state(struct vcpu *n)* registers associated to EL1/EL0 translations regime have been * synchronized. */ - asm volatile(ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_AT_SPECULATE)); +asm_inline volatile ( + ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_AT_SPECULATE) );WRITE_SYSREG64 (p2m->vttbr,VTTBR_EL2 ); last_vcpu_ran = &p2m->last_vcpu_ran[smp_processor_id ()];
Signature · 1 line
2.39.5
Re: [PATCH 3/3] ARM: Use asm_inline for ALTERNATIVE()
Quoted 7 lines · Andrew Cooper
... when there really are only a few instructions in line.
In some cases, reformat to reduce left-hand margine space.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 279 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>v2:
* New, split out of previous single patch--- xen/arch/arm/include/asm/alternative.h | 4 +-- xen/arch/arm/include/asm/arm64/flushtlb.h | 4 +-- xen/arch/arm/include/asm/arm64/io.h | 43 ++++++++++++++--------- xen/arch/arm/include/asm/cpuerrata.h | 8 ++--- xen/arch/arm/include/asm/cpufeature.h | 8 ++--- xen/arch/arm/include/asm/page.h | 12 ++++--- xen/arch/arm/include/asm/processor.h | 7 ++-- xen/arch/arm/include/asm/sysregs.h | 10 +++--- xen/arch/arm/mmu/p2m.c | 3 +- 9 files changed, 58 insertions(+), 41 deletions(-)xen/arch/arm/include/asm/alternative.h +2
-2@@ -209,9 +209,9 @@ alternative_endif#endif /* __ASSEMBLY__ */ /* -* Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature)); +* Usage: asm_inline (ALTERNATIVE(oldinstr, newinstr, feature)); * -* Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature, CONFIG_FOO)); +* Usage: asm_inline (ALTERNATIVE(oldinstr, newinstr, feature, CONFIG_FOO)); * N.B. If CONFIG_FOO is specified, but not selected, the whole block * will be omitted, including oldinstr. */ xen/arch/arm/include/asm/arm64/flushtlb.h +2
-2@@ -31,7 +31,7 @@#define TLB_HELPER (name, tlbop, sh) \ static inline void name(void) \ { \ - asm volatile( \ + asm_inline volatile ( \ "dsb " # sh "st;" \ "tlbi " # tlbop ";" \ ALTERNATIVE( \@@ -55,7 +55,7 @@ static inline void name(void) \#define TLB_HELPER_VA (name, tlbop) \ static inline void name(vaddr_t va) \ { \ - asm volatile( \ + asm_inline volatile ( \ "tlbi " # tlbop ", %0;" \ ALTERNATIVE( \ "nop; nop;", \xen/arch/arm/include/asm/arm64/io.h +27
-16@@ -51,40 +51,51 @@ static inline void __raw_writeq(u64 val, volatile void __iomem *addr)static inline u8 __raw_readb (const volatile void __iomem *addr) {u8 val; - asm volatile(ALTERNATIVE("ldrb %w0, [%1]", - "ldarb %w0, [%1]", - ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) - : "=r" (val) : "r" (addr)); + + asm_inline volatile ( + ALTERNATIVE("ldrb %w0, [%1]", + "ldarb %w0, [%1]", + ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) + : "=r" (val) : "r" (addr) ); +return val; }static inline u16 __raw_readw (const volatile void __iomem *addr) {u16 val; - asm volatile(ALTERNATIVE("ldrh %w0, [%1]", - "ldarh %w0, [%1]", - ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) - : "=r" (val) : "r" (addr)); + asm_inline volatile ( + ALTERNATIVE("ldrh %w0, [%1]", + "ldarh %w0, [%1]", + ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) + : "=r" (val) : "r" (addr) ); +return val; }static inline u32 __raw_readl (const volatile void __iomem *addr) {u32 val; - asm volatile(ALTERNATIVE("ldr %w0, [%1]", - "ldar %w0, [%1]", - ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) - : "=r" (val) : "r" (addr)); + + asm_inline volatile ( + ALTERNATIVE("ldr %w0, [%1]", + "ldar %w0, [%1]", + ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) + : "=r" (val) : "r" (addr) ); +return val; }static inline u64 __raw_readq (const volatile void __iomem *addr) {u64 val; - asm volatile(ALTERNATIVE("ldr %0, [%1]", - "ldar %0, [%1]", - ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) - : "=r" (val) : "r" (addr)); + + asm_inline volatile ( + ALTERNATIVE("ldr %0, [%1]", + "ldar %0, [%1]", + ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) + : "=r" (val) : "r" (addr) ); +return val; }xen/arch/arm/include/asm/cpuerrata.h +4
-4@@ -16,10 +16,10 @@ static inline bool check_workaround_##erratum(void) \ { \register_t ret; \ \ - asm volatile (ALTERNATIVE("mov %0, #0", \ - "mov %0, #1", \ - feature) \ - : "=r" (ret)); \ + asm_inline volatile ( \ + ALTERNATIVE("mov %0, #0", \ + "mov %0, #1", feature) \ + : "=r" (ret) ); \ \return unlikely (ret); \ } \xen/arch/arm/include/asm/cpufeature.h +4
-4@@ -102,10 +102,10 @@ static inline bool cpus_have_cap(unsigned int num)#define cpus_have_const_cap (num) ({ \ register_t __ret; \ \ - asm volatile (ALTERNATIVE("mov %0, #0", \ - "mov %0, #1", \ - num) \ - : "=r" (__ret)); \ + asm_inline volatile ( \ + ALTERNATIVE("mov %0, #0", \ + "mov %0, #1", num) \ + : "=r" (__ret) ); \ \ unlikely(__ret); \ })xen/arch/arm/include/asm/page.h +7
-5@@ -176,7 +176,8 @@ static inline int invalidate_dcache_va_range(const void *p, unsigned long size) { size -= dcache_line_bytes - ((uintptr_t )p & cacheline_mask); p = (void *)((uintptr_t )p & ~cacheline_mask); - asm volatile (__clean_and_invalidate_dcache_one(0) : : "r" (p)); +asm_inline volatile ( + __clean_and_invalidate_dcache_one(0) :: "r" (p) ); p += dcache_line_bytes; }@@ -185,7 +186,8 @@ static inline int invalidate_dcache_va_range(const void *p, unsigned long size) asm volatile (__invalidate_dcache_one(0) : : "r" (p + idx));if ( size >0 ) - asm volatile (__clean_and_invalidate_dcache_one(0) : : "r" (p + idx)); + asm_inline volatile ( + __clean_and_invalidate_dcache_one(0) :: "r" (p + idx) );dsb (sy);/* So we know the flushes happen before continuing */ @@ -209,7 +211,7 @@ static inline int clean_dcache_va_range(const void *p, unsigned long size) p = (void *)((uintptr_t )p & ~cacheline_mask);for ( ; size >= dcache_line_bytes; idx += dcache_line_bytes, size -= dcache_line_bytes ) - asm volatile (__clean_dcache_one(0) : : "r" (p + idx)); + asm_inline volatile ( __clean_dcache_one(0) : : "r" (p + idx) );dsb (sy);/* So we know the flushes happen before continuing */ /* ARM callers assume that dcache_* functions cannot fail. */ return 0 ;@@ -247,7 +249,7 @@ static inline int clean_and_invalidate_dcache_va_rangeif (sizeof (x) >MIN_CACHELINE_BYTES ||sizeof (x) > alignof(x ) ) \clean_dcache_va_range (_p,sizeof (x)); \else \ - asmvolatile ( \ + asm_inline volatile ( \ "dsb sy;" /* Finish all earlier writes */ \ __clean_dcache_one(0) \ "dsb sy;" /* Finish flush before continuing */ \@@ -259,7 +261,7 @@ static inline int clean_and_invalidate_dcache_va_rangeif (sizeof (x) >MIN_CACHELINE_BYTES ||sizeof (x) > alignof(x ) ) \clean_and_invalidate_dcache_va_range (_p,sizeof (x)); \else \ - asmvolatile ( \ + asm_inline volatile ( \ "dsb sy;" /* Finish all earlier writes */ \ __clean_and_invalidate_dcache_one(0) \ "dsb sy;" /* Finish flush before continuing */ \xen/arch/arm/include/asm/processor.h +4
-3@@ -607,9 +607,10 @@ register_t get_default_cptr_flags(void);#define SYNCHRONIZE_SERROR (feat) \ do { \ ASSERT(local_abort_is_enabled()); \ - asm volatile(ALTERNATIVE("dsb sy; isb", \ - "nop; nop", feat) \ - : : : "memory"); \ + asm_inline volatile ( \ + ALTERNATIVE("dsb sy; isb", \ + "nop; nop", feat) \ + ::: "memory" ); \ } while (0)/* xen/arch/arm/include/asm/sysregs.h +6
-4@@ -22,11 +22,13 @@ static inline register_t read_sysreg_par(void)* DMB SY before and after accessing it, as part of the workaround for the * errata 1508412. */ - asm volatile(ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412, - CONFIG_ARM64_ERRATUM_1508412)); + asm_inline volatile ( + ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412, + CONFIG_ARM64_ERRATUM_1508412) ); par_el1 =READ_SYSREG64 (PAR_EL1 ); - asm volatile(ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412, - CONFIG_ARM64_ERRATUM_1508412)); + asm_inline volatile ( + ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412, + CONFIG_ARM64_ERRATUM_1508412) );return par_el1; }xen/arch/arm/mmu/p2m.c +2
-1@@ -228,7 +228,8 @@ void p2m_restore_state(struct vcpu *n)* registers associated to EL1/EL0 translations regime have been * synchronized. */ - asm volatile(ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_AT_SPECULATE)); +asm_inline volatile ( + ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_AT_SPECULATE) );WRITE_SYSREG64 (p2m->vttbr,VTTBR_EL2 ); last_vcpu_ran = &p2m->last_vcpu_ran[smp_processor_id ()];Signature · 1 line
2.39.5