From: "Jan Beulich" Subject: [PATCH] x86: unify local_irq_XXX() Date: Thu, 11 Dec 2008 10:35:32 +0000 Message-ID: <4940FB04.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This also removes an inconsistency in that x86-64's __save_flags() had a memory clobber, while x86_32's didn't. It further adds type checking since blindly using {pop,push}{l,q} on a memory operand of unknown size bares the risk of corrupting other data. Finally, it eliminates the redundant (with local_irq_restore()) __restore_flags() macro and renames __save_flags() to local_save_flags(), making the naming consistent with Linux (again?). Signed-off-by: Jan Beulich --- 2008-11-20.orig/xen/include/asm-x86/system.h 2008-04-30 = 11:54:44.000000000 +0200 +++ 2008-11-20/xen/include/asm-x86/system.h 2008-12-11 09:51:06.0000000= 00 +0100 @@ -1,8 +1,7 @@ #ifndef __ASM_SYSTEM_H #define __ASM_SYSTEM_H =20 -#include -#include +#include #include =20 #define read_segment_register(name) \ @@ -171,10 +170,27 @@ static always_inline unsigned long __cmp /* used when interrupts are already enabled or to shutdown the processor = */ #define halt() asm volatile ( "hlt" : : : "memory" ) =20 +#define local_save_flags(x) \ +({ \ + BUILD_BUG_ON(sizeof(x) !=3D sizeof(long)); \ + asm volatile ( "pushf" __OS " ; pop" __OS " %0" : "=3Dg" (x)); \ +}) +#define local_irq_save(x) \ +({ \ + local_save_flags(x); \ + local_irq_disable(); \ +}) +#define local_irq_restore(x) \ +({ \ + BUILD_BUG_ON(sizeof(x) !=3D sizeof(long)); \ + asm volatile ( "push" __OS " %0 ; popf" __OS \ + : : "g" (x) : "memory", "cc" ); \ +}) + static inline int local_irq_is_enabled(void) { unsigned long flags; - __save_flags(flags); + local_save_flags(flags); return !!(flags & (1<<9)); /* EFLAGS_IF */ } =20 --- 2008-11-20.orig/xen/include/asm-x86/x86_32/system.h 2007-11-26 = 16:57:03.000000000 +0100 +++ 2008-11-20/xen/include/asm-x86/x86_32/system.h 2008-12-11 = 09:33:14.000000000 +0100 @@ -101,14 +101,4 @@ static inline void atomic_write64(uint64 #define mb() \ asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" ) =20 -#define __save_flags(x) \ - asm volatile ( "pushfl ; popl %0" : "=3Dg" (x) : ) -#define __restore_flags(x) \ - asm volatile ( "pushl %0 ; popfl" : : "g" (x) : "memory", "cc" ) - -#define local_irq_save(x) \ - asm volatile ( "pushfl ; popl %0 ; cli" : "=3Dg" (x) : : "memory" ) -#define local_irq_restore(x) \ - __restore_flags(x) - #endif /* __X86_32_SYSTEM_H__ */ --- 2008-11-20.orig/xen/include/asm-x86/x86_64/system.h 2007-11-26 = 16:57:03.000000000 +0100 +++ 2008-11-20/xen/include/asm-x86/x86_64/system.h 2008-12-11 = 09:33:40.000000000 +0100 @@ -55,14 +55,4 @@ static inline void atomic_write64(uint64 #define mb() \ asm volatile ( "mfence" : : : "memory" ) =20 -#define __save_flags(x) \ - asm volatile ( "pushfq ; popq %q0" : "=3Dg" (x) : :"memory" ) -#define __restore_flags(x) \ - asm volatile ( "pushq %0 ; popfq" : : "g" (x) : "memory", "cc" ) - -#define local_irq_save(x) \ - asm volatile ( "pushfq ; popq %0 ; cli" : "=3Dg" (x) : : "memory" ) -#define local_irq_restore(x) \ - __restore_flags(x) - #endif /* __X86_64_SYSTEM_H__ */