x86/kexec: Merge x86_32 and x86_64 code using macros from asm.h
PATCH 1/1 x86/kexec: Merge x86_32 and x86_64 code using macros from asm.h
Merge common x86_32 and x86_64 code in crash_setup_regs() using macros from asm/asm.h.
The compiled object files before and after the patch are unchanged.
--- arch/x86/include/asm/asm.h | 2 ++ arch/x86/include/asm/kexec.h | 44 +++++++++++++++--------------------- 2 files changed, 20 insertions(+), 26 deletions(-)
arch/x86/include/asm/asm.h +2 -0
@@ -41,6 +41,8 @@#define _ASM_SUB __ASM_SIZE(sub)#define _ASM_XADD __ASM_SIZE(xadd)#define _ASM_MUL __ASM_SIZE(mul) +#define _ASM_PUSHF __ASM_SIZE(pushf) +#define _ASM_POP __ASM_SIZE(pop)#define _ASM_AX __ASM_REG(ax)#define _ASM_BX __ASM_REG(bx)
arch/x86/include/asm/kexec.h +18 -26
63 lines not on this page · raw message
Signature · 1 line
2.42.0
H. Peter Anvin
reviewerQuoted 89 lines · Uros Bizjak
Merge common
x86_32andx86_64code incrash_setup_regs()using macros fromasm/asm.h.The compiled object files before and after the patch are unchanged.
Signed-off-by Uros Bizjak <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc Dave Hansen <[email protected]>Cc "H. Peter Anvin" <[email protected]>---
arch/x86/include/asm/asm.h| 2 ++arch/x86/include/asm/kexec.h| 44 +++++++++++++++---------------------2 files changed, 20 insertions(+), 26 deletions(-)arch/x86/include/asm/asm.h +2
-0@@ -41,6 +41,8 @@#define _ASM_SUB __ASM_SIZE(sub)#define _ASM_XADD __ASM_SIZE(xadd)#define _ASM_MUL __ASM_SIZE(mul) +#define _ASM_PUSHF __ASM_SIZE(pushf) +#define _ASM_POP __ASM_SIZE(pop)#define _ASM_AX __ASM_REG(ax)#define _ASM_BX __ASM_REG(bx)arch/x86/include/asm/kexec.h +11
-26@@ -18,6 +18,7 @@#include <linux/string.h> #include <linux/kernel.h> +#include <asm/asm.h> #include <asm/page.h> #include <asm/ptrace.h> @@ -71,29 +72,15 @@ static inline void crash_setup_regs(struct pt_regs *newregs,if (oldregs) {memcpy (newregs, oldregs,sizeof (*newregs)); }else { -#ifdef CONFIG_X86_32 - asmvolatile ("movl %%ebx,%0" :"=m" (newregs->bx)); - asmvolatile ("movl %%ecx,%0" :"=m" (newregs->cx)); - asmvolatile ("movl %%edx,%0" :"=m" (newregs->dx)); - asmvolatile ("movl %%esi,%0" :"=m" (newregs->si)); - asmvolatile ("movl %%edi,%0" :"=m" (newregs->di)); - asmvolatile ("movl %%ebp,%0" :"=m" (newregs->bp)); - asmvolatile ("movl %%eax,%0" :"=m" (newregs->ax)); - asmvolatile ("movl %%esp,%0" :"=m" (newregs->sp)); - asmvolatile ("movl %%ss, %%eax;" :"=a" (newregs->ss)); - asmvolatile ("movl %%cs, %%eax;" :"=a" (newregs->cs)); - asmvolatile ("movl %%ds, %%eax;" :"=a" (newregs->ds)); - asmvolatile ("movl %%es, %%eax;" :"=a" (newregs->es)); - asmvolatile ("pushfl; popl %0" :"=m" (newregs->flags)); -#else - asmvolatile ("movq %%rbx,%0" :"=m" (newregs->bx)); - asmvolatile ("movq %%rcx,%0" :"=m" (newregs->cx)); - asmvolatile ("movq %%rdx,%0" :"=m" (newregs->dx)); - asmvolatile ("movq %%rsi,%0" :"=m" (newregs->si)); - asmvolatile ("movq %%rdi,%0" :"=m" (newregs->di)); - asmvolatile ("movq %%rbp,%0" :"=m" (newregs->bp)); - asmvolatile ("movq %%rax,%0" :"=m" (newregs->ax)); - asmvolatile ("movq %%rsp,%0" :"=m" (newregs->sp)); + asmvolatile (_ASM_MOV" %%" _ASM_BX",%0" :"=m" (newregs->bx)); + asmvolatile (_ASM_MOV" %%" _ASM_CX",%0" :"=m" (newregs->cx)); + asmvolatile (_ASM_MOV" %%" _ASM_DX",%0" :"=m" (newregs->dx)); + asmvolatile (_ASM_MOV" %%" _ASM_SI",%0" :"=m" (newregs->si)); + asmvolatile (_ASM_MOV" %%" _ASM_DI",%0" :"=m" (newregs->di)); + asmvolatile (_ASM_MOV" %%" _ASM_BP",%0" :"=m" (newregs->bp)); + asmvolatile (_ASM_MOV" %%" _ASM_AX",%0" :"=m" (newregs->ax)); + asmvolatile (_ASM_MOV" %%" _ASM_SP",%0" :"=m" (newregs->sp)); +#ifdef CONFIG_X86_64 asmvolatile ("movq %%r8,%0" :"=m" (newregs->r8)); asmvolatile ("movq %%r9,%0" :"=m" (newregs->r9)); asmvolatile ("movq %%r10,%0" :"=m" (newregs->r10));@@ -102,10 +89,15 @@ static inline void crash_setup_regs(struct pt_regs *newregs, asmvolatile ("movq %%r13,%0" :"=m" (newregs->r13)); asmvolatile ("movq %%r14,%0" :"=m" (newregs->r14)); asmvolatile ("movq %%r15,%0" :"=m" (newregs->r15)); - asmvolatile ("movl %%ss, %%eax;" :"=a" (newregs->ss)); - asmvolatile ("movl %%cs, %%eax;" :"=a" (newregs->cs)); - asmvolatile ("pushfq; popq %0" :"=m" (newregs->flags));#endif + asmvolatile ("movl %%ss,%k0" :"=a" (newregs->ss));
arch/x86/include/asm/kexec.h static inline void crash_setup_regs(struct pt_regs *newregs, · line 103
Quoted 10 lines
arch/x86/include/asm/kexec.h +7
-0+ asmvolatile ("movl %%cs,%k0" :"=a" (newregs->cs)); +#ifdef CONFIG_X86_32 + asmvolatile ("movl %%ds,%k0" :"=a" (newregs->ds)); + asmvolatile ("movl %%es,%k0" :"=a" (newregs->es)); +#endif + asmvolatile (_ASM_PUSHF"\n\t" + _ASM_POP" %0" :"=m" (newregs->flags)); newregs->ip = _THIS_IP_; } }
There is no reason to stick a size suffix on if it is unambiguous. Normally pushf/popf never are, since stack operations are promoted automatically.
Quoted 95 lines · H. Peter Anvin
Quoted 93 lines · Uros Bizjak
Merge common
x86_32andx86_64code incrash_setup_regs()using macros fromasm/asm.h.The compiled object files before and after the patch are unchanged.
Signed-off-by Uros Bizjak <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc Dave Hansen <[email protected]>Cc "H. Peter Anvin" <[email protected]>---
arch/x86/include/asm/asm.h| 2 ++arch/x86/include/asm/kexec.h| 44 +++++++++++++++---------------------2 files changed, 20 insertions(+), 26 deletions(-)arch/x86/include/asm/asm.h +2
-0@@ -41,6 +41,8 @@#define _ASM_SUB __ASM_SIZE(sub)#define _ASM_XADD __ASM_SIZE(xadd)#define _ASM_MUL __ASM_SIZE(mul) +#define _ASM_PUSHF __ASM_SIZE(pushf) +#define _ASM_POP __ASM_SIZE(pop)#define _ASM_AX __ASM_REG(ax)#define _ASM_BX __ASM_REG(bx)arch/x86/include/asm/kexec.h +15
-26@@ -18,6 +18,7 @@#include <linux/string.h> #include <linux/kernel.h> +#include <asm/asm.h> #include <asm/page.h> #include <asm/ptrace.h> @@ -71,29 +72,15 @@ static inline void crash_setup_regs(struct pt_regs *newregs,if (oldregs) {memcpy (newregs, oldregs,sizeof (*newregs)); }else { -#ifdef CONFIG_X86_32 - asmvolatile ("movl %%ebx,%0" :"=m" (newregs->bx)); - asmvolatile ("movl %%ecx,%0" :"=m" (newregs->cx)); - asmvolatile ("movl %%edx,%0" :"=m" (newregs->dx)); - asmvolatile ("movl %%esi,%0" :"=m" (newregs->si)); - asmvolatile ("movl %%edi,%0" :"=m" (newregs->di)); - asmvolatile ("movl %%ebp,%0" :"=m" (newregs->bp)); - asmvolatile ("movl %%eax,%0" :"=m" (newregs->ax)); - asmvolatile ("movl %%esp,%0" :"=m" (newregs->sp)); - asmvolatile ("movl %%ss, %%eax;" :"=a" (newregs->ss)); - asmvolatile ("movl %%cs, %%eax;" :"=a" (newregs->cs)); - asmvolatile ("movl %%ds, %%eax;" :"=a" (newregs->ds)); - asmvolatile ("movl %%es, %%eax;" :"=a" (newregs->es)); - asmvolatile ("pushfl; popl %0" :"=m" (newregs->flags)); -#else - asmvolatile ("movq %%rbx,%0" :"=m" (newregs->bx)); - asmvolatile ("movq %%rcx,%0" :"=m" (newregs->cx)); - asmvolatile ("movq %%rdx,%0" :"=m" (newregs->dx)); - asmvolatile ("movq %%rsi,%0" :"=m" (newregs->si)); - asmvolatile ("movq %%rdi,%0" :"=m" (newregs->di)); - asmvolatile ("movq %%rbp,%0" :"=m" (newregs->bp)); - asmvolatile ("movq %%rax,%0" :"=m" (newregs->ax)); - asmvolatile ("movq %%rsp,%0" :"=m" (newregs->sp)); + asmvolatile (_ASM_MOV" %%" _ASM_BX",%0" :"=m" (newregs->bx)); + asmvolatile (_ASM_MOV" %%" _ASM_CX",%0" :"=m" (newregs->cx)); + asmvolatile (_ASM_MOV" %%" _ASM_DX",%0" :"=m" (newregs->dx)); + asmvolatile (_ASM_MOV" %%" _ASM_SI",%0" :"=m" (newregs->si)); + asmvolatile (_ASM_MOV" %%" _ASM_DI",%0" :"=m" (newregs->di)); + asmvolatile (_ASM_MOV" %%" _ASM_BP",%0" :"=m" (newregs->bp)); + asmvolatile (_ASM_MOV" %%" _ASM_AX",%0" :"=m" (newregs->ax)); + asmvolatile (_ASM_MOV" %%" _ASM_SP",%0" :"=m" (newregs->sp)); +#ifdef CONFIG_X86_64 asmvolatile ("movq %%r8,%0" :"=m" (newregs->r8)); asmvolatile ("movq %%r9,%0" :"=m" (newregs->r9)); asmvolatile ("movq %%r10,%0" :"=m" (newregs->r10));@@ -102,10 +89,15 @@ static inline void crash_setup_regs(struct pt_regs *newregs, asmvolatile ("movq %%r13,%0" :"=m" (newregs->r13)); asmvolatile ("movq %%r14,%0" :"=m" (newregs->r14)); asmvolatile ("movq %%r15,%0" :"=m" (newregs->r15)); - asmvolatile ("movl %%ss, %%eax;" :"=a" (newregs->ss)); - asmvolatile ("movl %%cs, %%eax;" :"=a" (newregs->cs)); - asmvolatile ("pushfq; popq %0" :"=m" (newregs->flags));#endif + asmvolatile ("movl %%ss,%k0" :"=a" (newregs->ss)); + asmvolatile ("movl %%cs,%k0" :"=a" (newregs->cs)); +#ifdef CONFIG_X86_32 + asmvolatile ("movl %%ds,%k0" :"=a" (newregs->ds)); + asmvolatile ("movl %%es,%k0" :"=a" (newregs->es));
Quoted 8 lines
arch/x86/include/asm/kexec.h static inline void crash_setup_regs(struct pt_regs *newregs, · line 103
Quoted 6 lines
arch/x86/include/asm/kexec.h +3
-0+#endif + asmvolatile (_ASM_PUSHF"\n\t" + _ASM_POP" %0" :"=m" (newregs->flags)); newregs->ip = _THIS_IP_; } }There is no reason to stick a size suffix on if it is unambiguous. Normally pushf/popf never are, since stack operations are promoted automatically.
Thanks, I'll provide a v2 with removed suffixes.
BR,
Uros.