xen/arch: Treewide improvement of irq helper APIs
cover xen/arch: Treewide improvement of irq helper APIs
This is a rather old cleanup series which I never got around to finishing. It is restricted to the arch maintainers as it is purely mechanical outside of system.h
The main purpose is to reduce the quantity of code we have which mutates parameters by name.
One ARM point which I've noticed is that system.h is a mix of duplicated common code in the arch{32,64}/ versions, and ifdefary in the common version. Does this perhaps want to be made consistent? I've not touched the layout in this series.
Andrew Cooper (4):
xen/arch: Switch local_*_is_enabled() predicates to return bool xen/arch: Switch local_save_flags() to being a static inline helper xen/arch: Switch local_irq_save() to being a static inline helper xen/arch: Switch local_irq_restore() to being a static inline helper
xen/arch/arm/mm.c | 4 +-- xen/arch/arm/p2m.c | 2 +- xen/arch/x86/acpi/power.c | 2 +- xen/arch/x86/apic.c | 10 +++---- xen/arch/x86/cpu/mtrr/generic.c | 4 +-- xen/arch/x86/cpu/mtrr/main.c | 6 ++-- xen/arch/x86/domain.c | 2 +- xen/arch/x86/domain_page.c | 4 +-- xen/arch/x86/flushtlb.c | 4 +-- xen/arch/x86/genapic/x2apic.c | 4 +-- xen/arch/x86/hpet.c | 3 +- xen/arch/x86/hvm/vmx/vmcs.c | 6 ++-- xen/arch/x86/io_apic.c | 4 +-- xen/arch/x86/nmi.c | 3 +- xen/arch/x86/platform_hypercall.c | 2 +- xen/arch/x86/smp.c | 4 +-- xen/arch/x86/time.c | 5 ++-- xen/arch/x86/traps.c | 2 +- xen/common/cpupool.c | 2 +- xen/common/gdbstub.c | 6 ++-- xen/common/livepatch.c | 4 +-- xen/common/rcupdate.c | 2 +- xen/common/spinlock.c | 3 +- xen/common/timer.c | 2 +- xen/drivers/char/console.c | 5 ++-- xen/drivers/char/serial.c | 4 +-- xen/drivers/passthrough/io.c | 4 +-- xen/include/asm-arm/arm32/system.h | 56 +++++++++++++++++----------------- xen/include/asm-arm/arm64/system.h | 61 ++++++++++++++++++-------------------- xen/include/asm-arm/system.h | 6 ++-- xen/include/asm-x86/system.h | 48 +++++++++++++++--------------- xen/include/xen/rwlock.h | 7 ++--- xen/include/xen/spinlock.h | 2 +- 33 files changed, 133 insertions(+), 150 deletions(-)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/4 xen/arch: Switch local_*_is_enabled() predicates to return bool
No functional change, as the value returned was previously always 0 or 1. While altering these, insert blank lines where appropriate and drop the now-redundant !! from x86's local_irq_is_enabled().
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
--- xen/include/asm-arm/arm32/system.h | 8 ++++++-- xen/include/asm-arm/arm64/system.h | 8 ++++++-- xen/include/asm-arm/system.h | 4 +++- xen/include/asm-x86/system.h | 6 ++++-- 4 files changed, 19 insertions(+), 7 deletions(-)
xen/include/asm-arm/arm32/system.h +6 -2
@@ -28,10 +28,12 @@ : "memory", "cc"); \ }) -static inline int local_irq_is_enabled (void ) +static inline bool local_irq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_IRQ_MASK ); }
@@ -41,10 +43,12 @@ static inline int local_irq_is_enabled(void)#define local_abort_enable () __asm__("cpsie a @ __sta\n" : : : "memory", "cc")#define local_abort_disable () __asm__("cpsid a @ __sta\n" : : : "memory", "cc") -static inline int local_fiq_is_enabled (void ) +static inline bool local_fiq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_FIQ_MASK ); }
xen/include/asm-arm/arm64/system.h +6 -2
@@ -44,17 +44,21 @@ : "memory"); \ }) -static inline int local_irq_is_enabled (void ) +static inline bool local_irq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_IRQ_MASK ); } -static inline int local_fiq_is_enabled (void ) +static inline bool local_fiq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_FIQ_MASK ); }
xen/include/asm-arm/system.h +3 -1
@@ -51,10 +51,12 @@# error "unknown ARM variant"#endif -static inline int local_abort_is_enabled (void ) +static inline bool local_abort_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_ABT_MASK ); }
xen/include/asm-x86/system.h +4 -2
@@ -274,11 +274,13 @@ static inline unsigned long array_index_mask_nospec(unsigned long index, "ri" ( (x) & X86_EFLAGS_IF ) ); \ }) -static inline int local_irq_is_enabled (void ) +static inline bool local_irq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); -return !!(flags &X86_EFLAGS_IF ); + +return flags &X86_EFLAGS_IF ; }#define BROKEN_ACPI_Sx 0x0001
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/4] xen/arch: Switch local_*_is_enabled() predicates to return bool
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 23.11.18 at 17:52, <[email protected]> wrote:
No functional change, as the value returned was previously always 0 or 1. While altering these, insert blank lines where appropriate and drop the now-redundant !! from x86's
local_irq_is_enabled().Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/4] xen/arch: Switch local_*_is_enabled() predicates to return bool
In reply to Andrew CooperHi Andrew,
Quoted 5 lines · Andrew Cooper
No functional change, as the value returned was previously always 0 or 1. While altering these, insert blank lines where appropriate and drop the now-redundant !! from x86's
local_irq_is_enabled().Signed-off-by Andrew Cooper <[email protected]>
Cheers,
Quoted 112 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/include/asm-arm/arm32/system.h | 8 ++++++-- xen/include/asm-arm/arm64/system.h | 8 ++++++-- xen/include/asm-arm/system.h | 4 +++- xen/include/asm-x86/system.h | 6 ++++-- 4 files changed, 19 insertions(+), 7 deletions(-)xen/include/asm-arm/arm32/system.h +6
-2@@ -28,10 +28,12 @@ : "memory", "cc"); \ }) -static inline int local_irq_is_enabled (void ) +static inline bool local_irq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_IRQ_MASK ); }@@ -41,10 +43,12 @@ static inline int local_irq_is_enabled(void)#define local_abort_enable () __asm__("cpsie a @ __sta\n" : : : "memory", "cc")#define local_abort_disable () __asm__("cpsid a @ __sta\n" : : : "memory", "cc") -static inline int local_fiq_is_enabled (void ) +static inline bool local_fiq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_FIQ_MASK ); }xen/include/asm-arm/arm64/system.h +6
-2@@ -44,17 +44,21 @@ : "memory"); \ }) -static inline int local_irq_is_enabled (void ) +static inline bool local_irq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_IRQ_MASK ); } -static inline int local_fiq_is_enabled (void ) +static inline bool local_fiq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_FIQ_MASK ); }xen/include/asm-arm/system.h +3
-1@@ -51,10 +51,12 @@# error "unknown ARM variant"#endif -static inline int local_abort_is_enabled (void ) +static inline bool local_abort_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); +return !(flags &PSR_ABT_MASK ); }xen/include/asm-x86/system.h +4
-2@@ -274,11 +274,13 @@ static inline unsigned long array_index_mask_nospec(unsigned long index, "ri" ( (x) & X86_EFLAGS_IF ) ); \ }) -static inline int local_irq_is_enabled (void ) +static inline bool local_irq_is_enabled (void ) {unsigned long flags; +local_save_flags (flags); -return !!(flags &X86_EFLAGS_IF ); + +return flags &X86_EFLAGS_IF ; }#define BROKEN_ACPI_Sx 0x0001
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/4 xen/arch: Switch local_save_flags() to being a static inline helper
In reply to Andrew Cooper... rather than a macro which writes to its parameter by name. A consequence of this change is that the local variables in local_*_is_enabled() can be dropped.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
--- xen/arch/x86/io_apic.c | 2 +- xen/include/asm-arm/arm32/system.h | 30 +++++++++++++----------------- xen/include/asm-arm/arm64/system.h | 32 ++++++++++++-------------------- xen/include/asm-arm/system.h | 6 +----- xen/include/asm-x86/system.h | 22 +++++++++++----------- 5 files changed, 38 insertions(+), 54 deletions(-)
xen/arch/x86/io_apic.c +1 -1
@@ -1486,7 +1486,7 @@ static int __init timer_irq_works(void) t1 =ACCESS_ONCE (pit0_ticks); -local_save_flags (flags); + flags =local_save_flags ();local_irq_enable ();/* Let ten ticks pass... */ mdelay ((10 *1000 ) /HZ );
xen/include/asm-arm/arm32/system.h +13 -17
@@ -7,15 +7,19 @@#define local_irq_disable () asm volatile ( "cpsid i @ local_irq_disable\n" : : : "cc" )#define local_irq_enable () asm volatile ( "cpsie i @ local_irq_enable\n" : : : "cc" ) -#define local_save_flags (x) \ -({ \ - BUILD_BUG_ON(sizeof(x) != sizeof(long)); \ - asm volatile ( "mrs %0, cpsr @ local_save_flags\n" \ - : "=r" (x) :: "memory", "cc" ); \ -}) +static inline unsigned long local_save_flags (void ) +{ +unsigned long flags; + + asmvolatile ("mrs %0, cpsr @ local_SAVE_flags\n" + :"=r" (flags) ::"memory" ,"cc" ); + +return flags; +} +#define local_irq_save (x) \ ({ \ - local_save_flags(x); \ + x = local_save_flags(); \ local_irq_disable(); \ })#define local_irq_restore (x) \
@@ -30,11 +34,7 @@static inline bool local_irq_is_enabled (void ) { -unsigned long flags; - -local_save_flags (flags); - -return !(flags &PSR_IRQ_MASK ); +return !(local_save_flags () &PSR_IRQ_MASK ); }#define local_fiq_enable () __asm__("cpsie f @ __stf\n" : : : "memory", "cc")
@@ -45,11 +45,7 @@ static inline bool local_irq_is_enabled(void)static inline bool local_fiq_is_enabled (void ) { -unsigned long flags; - -local_save_flags (flags); - -return !(flags &PSR_FIQ_MASK ); +return !(local_save_flags () &PSR_FIQ_MASK ); }#define CSDB ".inst 0xe320f014"
xen/include/asm-arm/arm64/system.h +12 -20
@@ -19,19 +19,19 @@#define local_abort_disable () asm volatile ( "msr daifset, #4\n" ::: "memory" )#define local_abort_enable () asm volatile ( "msr daifclr, #4\n" ::: "memory" ) -#define local_save_flags (x) \ -({ \ - BUILD_BUG_ON(sizeof(x) != sizeof(long)); \ - asm volatile( \ - "mrs %0, daif // local_save_flags\n" \ - : "=r" (x) \ - : \ - : "memory"); \ -}) +static inline unsigned long local_save_flags (void ) +{ +unsigned long flags; + + asmvolatile ("mrs %0, daif // local_SAVE_flags\n" + :"=r" (flags) ::"memory" ); + +return flags; +}#define local_irq_save (x) \ ({ \ - local_save_flags(x); \ + x = local_save_flags(); \ local_irq_disable(); \ })#define local_irq_restore (x) \
@@ -46,20 +46,12 @@static inline bool local_irq_is_enabled (void ) { -unsigned long flags; - -local_save_flags (flags); - -return !(flags &PSR_IRQ_MASK ); +return !(local_save_flags () &PSR_IRQ_MASK ); }static inline bool local_fiq_is_enabled (void ) { -unsigned long flags; - -local_save_flags (flags); - -return !(flags &PSR_FIQ_MASK ); +return !(local_save_flags () &PSR_FIQ_MASK ); }#define csdb () asm volatile ( "hint #20" : : : "memory" )
xen/include/asm-arm/system.h +1 -5
@@ -53,11 +53,7 @@static inline bool local_abort_is_enabled (void ) { -unsigned long flags; - -local_save_flags (flags); - -return !(flags &PSR_ABT_MASK ); +return !(local_save_flags () &PSR_ABT_MASK ); }#define arch_fetch_and_add (x, v) __sync_fetch_and_add(x, v)
xen/include/asm-x86/system.h +11 -11
@@ -253,14 +253,18 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,/* used when interrupts are already enabled or to shutdown the processor */ #define halt () asm volatile ( "hlt" : : : "memory" ) -#define local_save_flags (x) \ -({ \ - BUILD_BUG_ON(sizeof(x) != sizeof(long)); \ - asm volatile ( "pushf" __OS " ; pop" __OS " %0" : "=g" (x)); \ -}) +static inline unsigned long local_save_flags (void ) +{ +unsigned long flags; + + asmvolatile ("pushf; pop %0;" :"=g" (flags) ); + +return flags; +} +#define local_irq_save (x) \ ({ \ - local_save_flags(x); \ + x = local_save_flags(); \ local_irq_disable(); \ })#define local_irq_restore (x) \
@@ -276,11 +280,7 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,static inline bool local_irq_is_enabled (void ) { -unsigned long flags; - -local_save_flags (flags); - -return flags &X86_EFLAGS_IF ; +return local_save_flags () &X86_EFLAGS_IF ; }#define BROKEN_ACPI_Sx 0x0001
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/4] xen/arch: Switch local_save_flags() to being a static inline helper
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 23.11.18 at 17:52, <[email protected]> wrote:
xen/include/asm-x86/system.h +0
-3@@ -253,14 +253,18 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,/* used when interrupts are already enabled or to shutdown the processor */ #define halt () asm volatile ( "hlt" : : : "memory" ) -#define local_save_flags (x) \ -({ \ - BUILD_BUG_ON(sizeof(x) != sizeof(long)); \
xen/include/asm-x86/system.h static inline unsigned long array_index_mask_nospec(unsigned long index, · line 263
Quoted 10 lines
xen/include/asm-x86/system.h +8
-2- asmvolatile ("pushf" __OS" ; pop" __OS" %0" :"=g" (x)); \ -}) +static inline unsigned long local_save_flags (void ) +{ +unsigned long flags; + + asmvolatile ("pushf; pop %0;" :"=g" (flags) ); + +return flags; +}
Provided this doesn't defeat the current possibility of the compiler POP-ing directly into a stack variable
Apart from this I'm a little puzzled by the uppercasing of SAVE in the Arm asm() comments, but I'll leave that to the Arm maintainers.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/4] xen/arch: Switch local_save_flags() to being a static inline helper
In reply to Andrew CooperQuoted 43 lines · Andrew Cooper
... rather than a macro which writes to its parameter by name. A consequence of this change is that the local variables in local_*_is_enabled() can be dropped.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/arch/x86/io_apic.c | 2 +- xen/include/asm-arm/arm32/system.h | 30 +++++++++++++----------------- xen/include/asm-arm/arm64/system.h | 32 ++++++++++++-------------------- xen/include/asm-arm/system.h | 6 +----- xen/include/asm-x86/system.h | 22 +++++++++++----------- 5 files changed, 38 insertions(+), 54 deletions(-)xen/arch/x86/io_apic.c +1
-1@@ -1486,7 +1486,7 @@ static int __init timer_irq_works(void) t1 =ACCESS_ONCE (pit0_ticks); -local_save_flags (flags); + flags =local_save_flags ();local_irq_enable ();/* Let ten ticks pass... */ mdelay ((10 *1000 ) /HZ );xen/include/asm-arm/arm32/system.h +0
-1@@ -7,15 +7,19 @@#define local_irq_disable () asm volatile ( "cpsid i @ local_irq_disable\n" : : : "cc" )#define local_irq_enable () asm volatile ( "cpsie i @ local_irq_enable\n" : : : "cc" ) -#define local_save_flags (x) \
xen/include/asm-arm/arm32/system.h line 14
Quoted 10 lines
xen/include/asm-arm/arm32/system.h +5
-5-({ \ -BUILD_BUG_ON (sizeof (x) !=sizeof (long )); \ - asmvolatile ("mrs %0, cpsr @ local_save_flags\n" \ - :"=r" (x) ::"memory" ,"cc" ); \ -}) +static inline unsigned long local_save_flags (void ) +{ +unsigned long flags; + + asm volatile ( "mrs %0, cpsr @ local_SAVE_flags\n"
Any reason for writing "save" in uppercase?
xen/include/asm-arm/arm32/system.h line 19
Quoted 5 lines
xen/include/asm-arm/arm32/system.h +5
-0+ : "=r" (flags) :: "memory", "cc" ); + +return flags; +} +
[...]
The rest of the code looks good to me.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/4 xen/arch: Switch local_irq_save() to being a static inline helper
In reply to Andrew Cooper... rather than a macro which writes to its parameter by name. Take the opportunity to fold the assignment into the flags declaraion where appropriate.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
--- xen/arch/arm/mm.c | 4 ++-- xen/arch/arm/p2m.c | 2 +- xen/arch/x86/acpi/power.c | 2 +- xen/arch/x86/apic.c | 10 +++++----- xen/arch/x86/cpu/mtrr/generic.c | 4 ++-- xen/arch/x86/cpu/mtrr/main.c | 6 ++---- xen/arch/x86/domain.c | 2 +- xen/arch/x86/domain_page.c | 4 ++-- xen/arch/x86/flushtlb.c | 4 ++-- xen/arch/x86/genapic/x2apic.c | 4 ++-- xen/arch/x86/hpet.c | 3 +-- xen/arch/x86/hvm/vmx/vmcs.c | 6 ++---- xen/arch/x86/io_apic.c | 2 +- xen/arch/x86/nmi.c | 3 ++- xen/arch/x86/platform_hypercall.c | 2 +- xen/arch/x86/smp.c | 4 ++-- xen/arch/x86/time.c | 5 ++--- xen/arch/x86/traps.c | 2 +- xen/common/cpupool.c | 2 +- xen/common/gdbstub.c | 6 ++---- xen/common/livepatch.c | 4 ++-- xen/common/rcupdate.c | 2 +- xen/common/spinlock.c | 3 +-- xen/common/timer.c | 2 +- xen/drivers/char/console.c | 5 ++--- xen/drivers/char/serial.c | 4 +--- xen/drivers/passthrough/io.c | 4 ++-- xen/include/asm-arm/arm32/system.h | 14 +++++++++----- xen/include/asm-arm/arm64/system.h | 14 +++++++++----- xen/include/asm-x86/system.h | 14 +++++++++----- xen/include/xen/rwlock.h | 7 +++---- xen/include/xen/spinlock.h | 2 +- 32 files changed, 76 insertions(+), 76 deletions(-)
xen/arch/arm/mm.c +2 -2
@@ -401,7 +401,7 @@ void *map_domain_page(mfn_t mfn)lpae_t pte;int i, slot; -local_irq_save (flags); + flags =local_irq_save ();/* The map is laid out as an open-addressed hash table where each * entry is a 2MB superpage pte. We use the available bits of each
@@ -467,7 +467,7 @@ void unmap_domain_page(const void *va)lpae_t *map =this_cpu (xen_dommap);int slot = ((unsigned long ) va -DOMHEAP_VIRT_START ) >>SECOND_SHIFT ; -local_irq_save (flags); + flags =local_irq_save ();ASSERT (slot >=0 && slot <DOMHEAP_ENTRIES );ASSERT (map[slot].pt.avail !=0 );
xen/arch/arm/p2m.c +1 -1
@@ -146,7 +146,7 @@ static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m) ovttbr =READ_SYSREG64 (VTTBR_EL2 );if ( ovttbr != p2m->vttbr ) { -local_irq_save (flags); + flags =local_irq_save ();WRITE_SYSREG64 (p2m->vttbr,VTTBR_EL2 );isb (); }
xen/arch/x86/acpi/power.c +1 -1
@@ -197,7 +197,7 @@ static int enter_state(u32 state)console_start_sync ();printk ("Entering ACPI S%d state.\n" , state); -local_irq_save (flags); + flags =local_irq_save ();spin_debug_disable ();if ( (error =device_power_down ()) !=SAVED_ALL )
xen/arch/x86/apic.c +5 -5
@@ -718,7 +718,7 @@ int lapic_suspend(void)if (maxlvt >=5 ) apic_pm_state.apic_thmr =apic_read (APIC_LVTTHMR ); -local_irq_save (flags); + flags =local_irq_save ();disable_local_APIC ();iommu_disable_x2apic_IR ();local_irq_restore (flags);
@@ -734,7 +734,7 @@ int lapic_resume(void)if (!apic_pm_state.active)return 0 ; -local_irq_save (flags); + flags =local_irq_save ();/* * Make sure the APICBASE points to the right address
@@ -1094,8 +1094,8 @@ static void __setup_APIC_LVTT(unsigned int clocks)static void setup_APIC_timer (void ) { -unsigned long flags; -local_irq_save (flags); +unsigned long flags =local_irq_save (); +__setup_APIC_LVTT (0 );local_irq_restore (flags); }
@@ -1302,7 +1302,7 @@ void __init setup_boot_APIC_clock(void)check_deadline_errata (); -local_irq_save (flags); + flags =local_irq_save ();calibrate_APIC_clock ();
xen/arch/x86/cpu/mtrr/generic.c +2 -2
@@ -493,7 +493,7 @@ static void generic_set_all(void)unsigned long flags;bool pge; -local_irq_save (flags); + flags =local_irq_save (); pge =prepare_set ();/* Actually set the state */
@@ -528,7 +528,7 @@ static void generic_set_mtrr(unsigned int reg, unsigned long base, vr = &mtrr_state.var_ranges[reg]; -local_irq_save (flags); + flags =local_irq_save (); pge =prepare_set ();if (size ==0 ) {
xen/arch/x86/cpu/mtrr/main.c +2 -4
@@ -137,9 +137,7 @@ static void ipi_handler(void *info)*/ {struct set_mtrr_data *data = info; -unsigned long flags; - -local_irq_save (flags); +unsigned long flags =local_irq_save ();atomic_dec (&data->count);while (!atomic_read (&data->gate))
@@ -230,7 +228,7 @@ static void set_mtrr(unsigned int reg, unsigned long base,/* Start the ball rolling on other CPUs */ on_selected_cpus (&allbutself, ipi_handler, &data,0 ); -local_irq_save (flags); + flags =local_irq_save ();while (atomic_read (&data.count))cpu_relax ();
xen/arch/x86/domain.c +1 -1
@@ -1866,7 +1866,7 @@ int __sync_local_execstate(void)unsigned long flags;int switch_required; -local_irq_save (flags); + flags =local_irq_save (); switch_required = (this_cpu (curr_vcpu) != current);
xen/arch/x86/domain_page.c +2 -2
@@ -92,7 +92,7 @@ void *map_domain_page(mfn_t mfn)perfc_incr (map_domain_page_count); -local_irq_save (flags); + flags =local_irq_save (); hashent = &vcache->hash[MAPHASH_HASHFN (mfn_x (mfn))];if ( hashent->mfn ==mfn_x (mfn) )
@@ -196,7 +196,7 @@ void unmap_domain_page(const void *ptr) mfn =l1e_get_pfn (MAPCACHE_L1ENT (idx)); hashent = &v->arch.pv.mapcache.hash[MAPHASH_HASHFN (mfn)]; -local_irq_save (flags); + flags =local_irq_save ();if ( hashent->idx == idx ) {
xen/arch/x86/flushtlb.c +2 -2
@@ -82,7 +82,7 @@ static void do_tlb_flush(void)u32 t;/* This non-reentrant function is sometimes called in interrupt context. */ -local_irq_save (flags); + flags =local_irq_save (); t =pre_flush ();
@@ -108,7 +108,7 @@ void switch_cr3_cr4(unsigned long cr3, unsigned long cr4)unsigned long old_pcid =cr3_pcid (read_cr3 ());/* This non-reentrant function is sometimes called in interrupt context. */ -local_irq_save (flags); + flags =local_irq_save (); t =pre_flush ();
xen/arch/x86/genapic/x2apic.c +2 -2
@@ -113,7 +113,7 @@ static void send_IPI_mask_x2apic_phys(const cpumask_t *cpumask, int vector)*/ smp_mb (); -local_irq_save (flags); + flags =local_irq_save (); for_each_cpu ( cpu, cpumask ) {
@@ -137,7 +137,7 @@ static void send_IPI_mask_x2apic_cluster(const cpumask_t *cpumask, int vector)smp_mb ();/* See above for an explanation. */ -local_irq_save (flags); + flags =local_irq_save ();cpumask_andnot (ipimask, &cpu_online_map,cpumask_of (cpu));
xen/arch/x86/hpet.c +1 -2
@@ -97,9 +97,8 @@ static inline unsigned long ns2ticks(unsigned long nsec, int shift,static int hpet_next_event (unsigned long delta,int timer) {uint32_t cnt, cmp; -unsigned long flags; +unsigned long flags =local_irq_save (); -local_irq_save (flags); cnt =hpet_read32 (HPET_COUNTER ); cmp = cnt + delta;hpet_write32 (cmp,HPET_Tn_CMP (timer));
xen/arch/x86/hvm/vmx/vmcs.c +2 -4
@@ -549,9 +549,7 @@ static void vmx_clear_vmcs(struct vcpu *v)static void vmx_load_vmcs (struct vcpu *v) { -unsigned long flags; - -local_irq_save (flags); +unsigned long flags =local_irq_save ();if ( v->arch.hvm.vmx.active_cpu ==-1 ) {
@@ -713,7 +711,7 @@ void vmx_cpu_down(void)if ( !this_cpu (vmxon) )return ; -local_irq_save (flags); + flags =local_irq_save ();while ( !list_empty (active_vmcs_list) ) __vmx_clear_vmcs(list_entry(active_vmcs_list->next,
xen/arch/x86/io_apic.c +1 -1
@@ -1883,7 +1883,7 @@ static void __init check_timer(void)unsigned long flags;cpumask_t mask_all; -local_irq_save (flags); + flags =local_irq_save ();/* * get/set the timer IRQ vector:
xen/arch/x86/nmi.c +2 -1
@@ -560,7 +560,8 @@ void self_nmi(void) {unsigned long flags;u32 id =get_apic_id (); -local_irq_save (flags); + + flags =local_irq_save ();apic_wait_icr_idle ();apic_icr_write (APIC_DM_NMI |APIC_DEST_PHYSICAL , id);local_irq_restore (flags);
xen/arch/x86/platform_hypercall.c +1 -1
@@ -147,7 +147,7 @@ void resource_access(void *info)unlikely (entry[1 ].idx ==MSR_IA32_TSC );if (unlikely (read_tsc) ) -local_irq_save (flags); + flags =local_irq_save (); ret =rdmsr_safe (entry->idx, entry->val);
xen/arch/x86/smp.c +2 -2
@@ -134,7 +134,7 @@ void send_IPI_mask_flat(const cpumask_t *cpumask, int vector)if ( mask ==0 )return ; -local_irq_save (flags); + flags =local_irq_save ();/* * Wait for idle.
@@ -165,7 +165,7 @@ void send_IPI_mask_phys(const cpumask_t *mask, int vector)unsigned long cfg, flags;unsigned int query_cpu; -local_irq_save (flags); + flags =local_irq_save (); for_each_cpu ( query_cpu, mask ) {
xen/arch/x86/time.c +2 -3
@@ -1585,9 +1585,8 @@ static struct cpu_time_stamp ap_bringup_ref;void time_latch_stamps (void ) { -unsigned long flags; +unsigned long flags =local_irq_save (); -local_irq_save (flags); ap_bringup_ref.master_stime =read_platform_stime (NULL ); ap_bringup_ref.local_tsc =rdtsc_ordered ();local_irq_restore (flags);
@@ -1655,7 +1654,7 @@ void init_percpu_time(void) } } -local_irq_save (flags); + flags =local_irq_save (); now =read_platform_stime (NULL ); tsc =rdtsc_ordered ();local_irq_restore (flags);
xen/arch/x86/traps.c +1 -1
@@ -1315,7 +1315,7 @@ static enum pf_type spurious_page_fault(unsigned long addr,* Disabling interrupts prevents TLB flushing, and hence prevents * page tables from becoming invalid under our feet during the walk. */ -local_irq_save (flags); + flags =local_irq_save (); pf_type =__page_fault_type (addr, regs);local_irq_restore (flags);
xen/common/cpupool.c +1 -1
@@ -739,7 +739,7 @@ void dump_runq(unsigned char key)struct cpupool **c;spin_lock (&cpupool_lock); -local_irq_save (flags); + flags =local_irq_save ();printk ("sched_smt_power_savings: %s\n" , sched_smt_power_savings?"enabled" :"disabled" );
xen/common/gdbstub.c +2 -4
@@ -603,7 +603,7 @@ __trap_to_gdb(struct cpu_user_regs *regs, unsigned long cookie)gdb_smp_pause (); -local_irq_save (flags); + flags =local_irq_save ();watchdog_disable ();console_start_sync ();
@@ -661,9 +661,7 @@ presmp_initcall(initialise_gdb);static void gdb_pause_this_cpu (void *unused) { -unsigned long flags; - -local_irq_save (flags); +unsigned long flags =local_irq_save ();atomic_set (&gdb_cpu[smp_processor_id ()].ack,1 );atomic_inc (&gdb_smp_paused_count);
xen/common/livepatch.c +2 -2
@@ -1357,7 +1357,7 @@ void check_for_livepatch_work(void)if ( !livepatch_spin (&livepatch_work.semaphore, timeout, cpus,"IRQ" ) ) { -local_irq_save (flags); + flags =local_irq_save ();/* Do the patching. */ livepatch_do_action ();/* Serialize and flush out the CPU via CPUID instruction (on x86). */
@@ -1384,7 +1384,7 @@ void check_for_livepatch_work(void)cpu_relax ();/* Disable IRQs and signal. */ -local_irq_save (flags); + flags =local_irq_save ();/* * We re-use the sempahore, so MUST have it reset by master before * we exit the loop above.
xen/common/rcupdate.c +1 -1
@@ -224,7 +224,7 @@ void call_rcu(struct rcu_head *head, head->func = func; head->next =NULL ; -local_irq_save (flags); + flags =local_irq_save (); rdp = &__get_cpu_var (rcu_data); *rdp->nxttail = head; rdp->nxttail = &head->next;
xen/common/spinlock.c +1 -2
@@ -169,9 +169,8 @@ void _spin_lock_irq(spinlock_t *lock)unsigned long _spin_lock_irqsave (spinlock_t *lock) { -unsigned long flags; +unsigned long flags =local_irq_save (); -local_irq_save (flags);_spin_lock (lock);return flags; }
xen/common/timer.c +1 -1
@@ -256,7 +256,7 @@ static inline bool_t timer_lock(struct timer *timer)#define timer_lock_irqsave (t, flags) ({ \ bool_t __x; \ - local_irq_save(flags); \ + flags = local_irq_save(); \ if ( !(__x = timer_lock(t)) ) \ local_irq_restore(flags); \ __x; \
xen/drivers/char/console.c +2 -3
@@ -817,7 +817,7 @@ static void vprintk_common(const char *prefix, const char *fmt, va_list args)unsigned long flags;/* console_lock can be acquired recursively from __printk_ratelimit(). */ -local_irq_save (flags); + flags =local_irq_save ();spin_lock_recursive (&console_lock); state = &this_cpu (state);
@@ -1050,9 +1050,8 @@ void console_end_log_everything(void)unsigned long console_lock_recursive_irqsave (void ) { -unsigned long flags; +unsigned long flags =local_irq_save (); -local_irq_save (flags);spin_lock_recursive (&console_lock);return flags;
xen/drivers/char/serial.c +1 -3
@@ -71,9 +71,7 @@ void serial_rx_interrupt(struct serial_port *port, struct cpu_user_regs *regs)void serial_tx_interrupt (struct serial_port *port,struct cpu_user_regs *regs) {int i, n; -unsigned long flags; - -local_irq_save (flags); +unsigned long flags =local_irq_save ();/* * Avoid spinning for a long time: if there is a long-term lock holder
xen/drivers/passthrough/io.c +2 -2
@@ -67,7 +67,7 @@ static void raise_softirq_for(struct hvm_pirq_dpci *pirq_dpci)get_knownalive_domain (pirq_dpci->dom); -local_irq_save (flags); + flags =local_irq_save ();list_add_tail (&pirq_dpci->softirq_list, &this_cpu (dpci_list));local_irq_restore (flags);
@@ -1057,7 +1057,7 @@ static void dpci_softirq(void)unsigned long flags;/* Put back on the list and retry. */ -local_irq_save (flags); + flags =local_irq_save ();list_add_tail (&pirq_dpci->softirq_list, &this_cpu (dpci_list));local_irq_restore (flags);
xen/include/asm-arm/arm32/system.h +9 -5
@@ -17,11 +17,15 @@ static inline unsigned long local_save_flags(void)return flags; } -#define local_irq_save (x) \ -({ \ - x = local_save_flags(); \ - local_irq_disable(); \ -}) +static inline unsigned long local_irq_save (void ) +{ +unsigned long flags =local_save_flags (); + +local_irq_disable (); + +return flags; +} +#define local_irq_restore (x) \ ({ \ BUILD_BUG_ON(sizeof(x) != sizeof(long)); \
xen/include/asm-arm/arm64/system.h +9 -5
@@ -29,11 +29,15 @@ static inline unsigned long local_save_flags(void)return flags; } -#define local_irq_save (x) \ -({ \ - x = local_save_flags(); \ - local_irq_disable(); \ -}) +static inline unsigned long local_irq_save (void ) +{ +unsigned long flags =local_save_flags (); + +local_irq_disable (); + +return flags; +} +#define local_irq_restore (x) \ ({ \ BUILD_BUG_ON(sizeof(x) != sizeof(long)); \
xen/include/asm-x86/system.h +9 -5
@@ -262,11 +262,15 @@ static inline unsigned long local_save_flags(void)return flags; } -#define local_irq_save (x) \ -({ \ - x = local_save_flags(); \ - local_irq_disable(); \ -}) +static inline unsigned long local_irq_save (void ) +{ +unsigned long flags =local_save_flags (); + +local_irq_disable (); + +return flags; +} +#define local_irq_restore (x) \ ({ \ BUILD_BUG_ON(sizeof(x) != sizeof(long)); \
xen/include/xen/rwlock.h +3 -4
@@ -79,8 +79,8 @@ static inline void _read_lock_irq(rwlock_t *lock)static inline unsigned long _read_lock_irqsave (rwlock_t *lock) { -unsigned long flags; -local_irq_save (flags); +unsigned long flags =local_irq_save (); +_read_lock (lock);return flags; }
@@ -136,9 +136,8 @@ static inline void _write_lock_irq(rwlock_t *lock)static inline unsigned long _write_lock_irqsave (rwlock_t *lock) { -unsigned long flags; +unsigned long flags =local_irq_save (); -local_irq_save (flags);_write_lock (lock);return flags; }
xen/include/xen/spinlock.h +1 -1
@@ -187,7 +187,7 @@ void _spin_unlock_recursive(spinlock_t *lock);#define spin_trylock_irqsave (lock, flags) \ ({ \ - local_irq_save(flags); \ + flags = local_irq_save(); \ spin_trylock(lock) ? \ 1 : ({ local_irq_restore(flags); 0; }); \ })
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/4] xen/arch: Switch local_irq_save() to being a static inline helper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.11.18 at 17:52, <[email protected]> wrote:
... rather than a macro which writes to its parameter by name. Take the opportunity to fold the assignment into the flags declaraion where appropriate.
Do you really? Why not ...
xen/arch/arm/mm.c void *map_domain_page(mfn_t mfn) · line 404
Quoted 8 lines
xen/arch/arm/mm.c +1
-1@@ -401,7 +401,7 @@ void *map_domain_page(mfn_t mfn)lpae_t pte;int i, slot; -local_irq_save (flags); + flags =local_irq_save ();
... here, for example? There are a few more cases, I think.
Quoted 9 lines
xen/include/asm-x86/system.h +0
-3@@ -262,11 +262,15 @@ static inline unsigned long local_save_flags(void)return flags; } -#define local_irq_save (x) \ -({ \ - x = local_save_flags(); \
xen/include/asm-x86/system.h static inline unsigned long local_save_flags(void) · line 272
Quoted 10 lines
xen/include/asm-x86/system.h +8
-2-local_irq_disable (); \ -}) +static inline unsigned long local_irq_save (void ) +{ +unsigned long flags =local_save_flags (); + +local_irq_disable (); + +return flags; +}
Do we really need/want to retain this as a per-arch construct? Since you touch all instances anyway, do we really want to stick to its misleading name?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/4 xen/arch: Switch local_irq_restore() to being a static inline helper
In reply to Andrew CooperThere is no need for these to be macros, so change them for symetry with local_irq_save().
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
RFC, as I expect this patch to get some objection for removing the IRQ safety check, but the only reasons that change was made in e5fc6434d7 was because I talk talked into doing it while trying to clean up some unnecessary use of magic numbers.
No users are changing any flags (seeing as I've auditing them all in this series), and the improvement in emitted code nets us:
add/remove: 1/2 grow/shrink: 2/50 up/down: 835/-2049 (-1214)
Function old new delta __page_fault_type - 692 +692 reprogram_hpet_evt_channel 243 354 +111 do_page_fault 1249 1281 +32 time_latch_stamps 73 62 -11 vmx_cpu_down 152 136 -16 setup_boot_APIC_clock 896 880 -16 send_IPI_mask_flat 181 165 -16 resource_access 311 295 -16 map_domain_page 1204 1188 -16 lapic_resume 1100 1084 -16 hvm_do_IRQ_dpci 210 194 -16 generic_set_mtrr 258 242 -16 flush_area_local 604 588 -16 dump_runq 293 277 -16 dpci_softirq 726 710 -16 csched2_sys_cntl 237 221 -16 csched2_init_pdata 229 213 -16 csched2_deinit_pdata 354 338 -16 csched2_alloc_domdata 402 386 -16 __printk_ratelimit 332 316 -16 vmx_load_vmcs 156 139 -17 timer_irq_works 85 68 -17 switch_cr3_cr4 249 232 -17 send_IPI_mask_x2apic_phys 199 182 -17 setup_APIC_timer 31 13 -18 serial_tx_interrupt 286 268 -18 console_unlock_recursive_irqrestore 38 20 -18 _spin_unlock_irqrestore 49 31 -18 send_IPI_mask_x2apic_cluster 423 404 -19 csched2_dump 1297 1278 -19 __sync_local_execstate 83 64 -19 enter_state_helper 1210 1190 -20 vprintk_common 346 322 -24 unmap_domain_page 475 451 -24 set_mtrr 346 322 -24 lapic_suspend 742 718 -24 kill_timer 562 538 -24 ipi_handler 155 131 -24 init_percpu_time 411 387 -24 generic_set_all 703 679 -24 csched2_free_domdata 138 114 -24 send_IPI_mask_phys 305 278 -27 call_rcu 223 196 -27 self_nmi 144 112 -32 erst_write 620 588 -32 _ehci_dbgp_poll 473 433 -40 timer_expires_before 328 285 -43 check_for_livepatch_work 813 767 -46 stop_timer 400 352 -48 set_timer 499 450 -49 init_timer 395 346 -49 csched2_dom_cntl 1573 1516 -57 setup_IO_APIC 4797 4738 -59 hpet_next_event 84 - -84
spurious_page_fault 756 - -756
Total: Before=3301185, After=3299971, chg -0.04%
which in particular changes some inlining considerations.
We could have an assertion that system flags dont change, and might want to consider having some kind of CONFIG_HARDEN for use in release builds, but given 6 years of hindsight, it would be better for developer builds to complain loudly for misuses, rather than to silenty squash the error.
--- xen/include/asm-arm/arm32/system.h | 14 +++++--------- xen/include/asm-arm/arm64/system.h | 15 ++++++--------- xen/include/asm-x86/system.h | 14 ++++---------- 3 files changed, 15 insertions(+), 28 deletions(-)
xen/include/asm-arm/arm32/system.h +5 -9
@@ -26,15 +26,11 @@ static inline unsigned long local_irq_save(void)return flags; } -#define local_irq_restore (x) \ -({ \ - BUILD_BUG_ON(sizeof(x) != sizeof(long)); \ - asm volatile ( \ - "msr cpsr_c, %0 @ local_irq_restore\n" \ - : \ - : "r" (x) \ - : "memory", "cc"); \ -}) +static inline void local_irq_restore (unsigned long flags) +{ + asmvolatile ("msr cpsr_c, %0 @ local_irq_restore\n" + ::"r" (flags) :"memory" ,"cc" ); +}static inline bool local_irq_is_enabled (void ) {
xen/include/asm-arm/arm64/system.h +6 -9
@@ -38,15 +38,12 @@ static inline unsigned long local_irq_save(void)return flags; } -#define local_irq_restore (x) \ -({ \ - BUILD_BUG_ON(sizeof(x) != sizeof(long)); \ - asm volatile ( \ - "msr daif, %0 // local_irq_restore" \ - : \ - : "r" (x) \ - : "memory"); \ -}) +static inline void local_irq_restore (unsigned long flags) +{ + asmvolatile ("msr daif, %0 // local_irq_restore" + ::"r" (flags) :"memory" ); + +}static inline bool local_irq_is_enabled (void ) {
xen/include/asm-x86/system.h +4 -10
@@ -271,16 +271,10 @@ static inline unsigned long local_irq_save(void)return flags; } -#define local_irq_restore (x) \ -({ \ - BUILD_BUG_ON(sizeof(x) != sizeof(long)); \ - asm volatile ( "pushfq\n\t" \ - "andq %0, (%%rsp)\n\t" \ - "orq %1, (%%rsp)\n\t" \ - "popfq" \ - : : "i?r" ( ~X86_EFLAGS_IF ), \ - "ri" ( (x) & X86_EFLAGS_IF ) ); \ -}) +static inline void local_irq_restore (unsigned long flags) +{ + asmvolatile ("push %0; popf;" ::"g" (flags) :"memory" ); +}static inline bool local_irq_is_enabled (void ) {
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 4/4] xen/arch: Switch local_irq_restore() to being a static inline helper
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 23.11.18 at 17:52, <[email protected]> wrote:
RFC, as I expect this patch to get some objection for removing the IRQ safety check, but the only reasons that change was made in
e5fc6434d7was because I talk talked into doing it while trying to clean up some unnecessary use of magic numbers.No users are changing any flags (seeing as I've auditing them all in this series), and the improvement in emitted code nets us:
Users not changing any flags as per your audit is only one half of it:
I assume you mean the value returned from local_irq_save() gets passed back unmodified into local_irq_restore(). The other question is whether intermediately another change to the CPU register has occurred, which is meant to persist. With Arm also controlling e.g. enabled status of aborts this way, it may be even more of an issue there than on x86.
xen/include/asm-x86/system.h static inline unsigned long local_irq_save(void) · line 276
Quoted 3 lines
xen/include/asm-x86/system.h +3
-0+static inline void local_irq_restore (unsigned long flags) +{ + asmvolatile ("push %0; popf;" ::"g" (flags) :"memory" );
I'm afraid this is not entirely right (but perhaps benign): Not all constants are valid to be handed to PUSH. If you want to allow immediates in the first place, this would need to be "rme", I think.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Andrew,
Quoted 11 lines · Andrew Cooper
This is a rather old cleanup series which I never got around to finishing. It is restricted to the arch maintainers as it is purely mechanical outside of
system.hThe main purpose is to reduce the quantity of code we have which mutates parameters by name.
One ARM point which I've noticed is that
system.his a mix of duplicated common code in the arch{32,64}/ versions, and ifdefary in the common version. Does this perhaps want to be made consistent? I've not touched the layout in this series.
Hmmm, I don't really want to have the barrier split between multiple headers. So we would have to duplicate them in arm32 and arm64.
For the IRQ helpers, we can probably be a bit smarter. I can have a look at clean-up once this is merged.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel