From: "Jan Beulich" Subject: [PATCH 1/3] x86: use MOV instead of PUSH/POP when saving/restoring register state Date: Tue, 02 Oct 2012 16:26:23 +0100 Message-ID: <506B23BF020000780009F29A@nat28.tlf.novell.com> References: <506B2268020000780009F273@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartDBEAED8F.0__=" Return-path: In-Reply-To: <506B2268020000780009F273@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartDBEAED8F.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Signed-off-by: Jan Beulich --- a/xen/arch/x86/x86_64/compat/entry.S +++ b/xen/arch/x86/x86_64/compat/entry.S @@ -21,8 +21,7 @@ ENTRY(compat_hypercall) UNLIKELY_START(ne, msi_check) movl $HYPERCALL_VECTOR,%edi call check_for_unexpected_msi - RESTORE_ALL - SAVE_ALL + LOAD_C_CLOBBERED UNLIKELY_END(msi_check) =20 GET_CURRENT(%rbx) @@ -173,8 +172,7 @@ compat_bad_hypercall: /* %rbx: struct vcpu, interrupts disabled */ compat_restore_all_guest: ASSERT_INTERRUPTS_DISABLED - RESTORE_ALL - addq $8,%rsp + RESTORE_ALL adj=3D8 .Lft0: iretq =20 .section .fixup,"ax" --- a/xen/arch/x86/x86_64/entry.S +++ b/xen/arch/x86/x86_64/entry.S @@ -47,12 +47,10 @@ restore_all_guest: cmpl $1,%ecx ja .Lforce_iret =20 - addq $8,%rsp - popq %rcx # RIP - popq %r11 # CS - cmpw $FLAT_USER_CS32,%r11 - popq %r11 # RFLAGS - popq %rsp # RSP + cmpw $FLAT_USER_CS32,16(%rsp)# CS + movq 8(%rsp),%rcx # RIP + movq 24(%rsp),%r11 # RFLAGS + movq 32(%rsp),%rsp # RSP je 1f sysretq 1: sysretl @@ -101,8 +99,7 @@ failsafe_callback: ALIGN /* No special register assumptions. */ restore_all_xen: - RESTORE_ALL - addq $8,%rsp + RESTORE_ALL adj=3D8 iretq =20 /* @@ -311,8 +308,7 @@ ENTRY(int80_direct_trap) UNLIKELY_START(ne, msi_check) movl $0x80,%edi call check_for_unexpected_msi - RESTORE_ALL - SAVE_ALL + LOAD_C_CLOBBERED UNLIKELY_END(msi_check) =20 GET_CURRENT(%rbx) --- a/xen/include/asm-x86/x86_64/asm_defns.h +++ b/xen/include/asm-x86/x86_64/asm_defns.h @@ -5,11 +5,11 @@ =20 #ifdef CONFIG_FRAME_POINTER /* Indicate special exception stack frame by inverting the frame pointer. = */ -#define SETUP_EXCEPTION_FRAME_POINTER \ - movq %rsp,%rbp; \ +#define SETUP_EXCEPTION_FRAME_POINTER(offs) \ + leaq offs(%rsp),%rbp; \ notq %rbp #else -#define SETUP_EXCEPTION_FRAME_POINTER +#define SETUP_EXCEPTION_FRAME_POINTER(off) #endif =20 #ifndef NDEBUG @@ -27,40 +27,49 @@ #define ASSERT_INTERRUPTS_DISABLED ASSERT_INTERRUPT_STATUS(z) =20 #define SAVE_ALL \ + addq $-(UREGS_error_code-UREGS_r15), %rsp; \ cld; \ - pushq %rdi; \ - pushq %rsi; \ - pushq %rdx; \ - pushq %rcx; \ - pushq %rax; \ - pushq %r8; \ - pushq %r9; \ - pushq %r10; \ - pushq %r11; \ - pushq %rbx; \ - pushq %rbp; \ - SETUP_EXCEPTION_FRAME_POINTER; \ - pushq %r12; \ - pushq %r13; \ - pushq %r14; \ - pushq %r15; - -#define RESTORE_ALL \ - popq %r15; \ - popq %r14; \ - popq %r13; \ - popq %r12; \ - popq %rbp; \ - popq %rbx; \ - popq %r11; \ - popq %r10; \ - popq %r9; \ - popq %r8; \ - popq %rax; \ - popq %rcx; \ - popq %rdx; \ - popq %rsi; \ - popq %rdi; + movq %rdi,UREGS_rdi(%rsp); \ + movq %rsi,UREGS_rsi(%rsp); \ + movq %rdx,UREGS_rdx(%rsp); \ + movq %rcx,UREGS_rcx(%rsp); \ + movq %rax,UREGS_rax(%rsp); \ + movq %r8,UREGS_r8(%rsp); \ + movq %r9,UREGS_r9(%rsp); \ + movq %r10,UREGS_r10(%rsp); \ + movq %r11,UREGS_r11(%rsp); \ + movq %rbx,UREGS_rbx(%rsp); \ + movq %rbp,UREGS_rbp(%rsp); \ + SETUP_EXCEPTION_FRAME_POINTER(UREGS_rbp); \ + movq %r12,UREGS_r12(%rsp); \ + movq %r13,UREGS_r13(%rsp); \ + movq %r14,UREGS_r14(%rsp); \ + movq %r15,UREGS_r15(%rsp); \ + +#ifdef __ASSEMBLY__ +.macro LOAD_C_CLOBBERED + movq UREGS_r11(%rsp),%r11 + movq UREGS_r10(%rsp),%r10 + movq UREGS_r9(%rsp),%r9 + movq UREGS_r8(%rsp),%r8 + movq UREGS_rax(%rsp),%rax + movq UREGS_rcx(%rsp),%rcx + movq UREGS_rdx(%rsp),%rdx + movq UREGS_rsi(%rsp),%rsi + movq UREGS_rdi(%rsp),%rdi +.endm + +.macro RESTORE_ALL adj=3D0 + movq UREGS_r15(%rsp),%r15 + movq UREGS_r14(%rsp),%r14 + movq UREGS_r13(%rsp),%r13 + movq UREGS_r12(%rsp),%r12 + movq UREGS_rbp(%rsp),%rbp + movq UREGS_rbx(%rsp),%rbx + LOAD_C_CLOBBERED + subq $-(UREGS_error_code-UREGS_r15+\adj), %rsp +.endm +#endif =20 #ifdef PERF_COUNTERS #define PERFC_INCR(_name,_idx,_cur) \ @@ -94,7 +103,7 @@ __asm__( \ "\n" __ALIGN_STR"\n" \ "common_interrupt:\n\t" \ - STR(SAVE_ALL) \ + STR(SAVE_ALL) "\n\t" \ "movq %rsp,%rdi\n\t" \ "callq " STR(do_IRQ) "\n\t" \ "jmp ret_from_intr\n"); --=__PartDBEAED8F.0__= Content-Type: text/plain; name="x86-save-restore-all-mov.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-save-restore-all-mov.patch" x86: use MOV instead of PUSH/POP when saving/restoring register state=0A=0A= Signed-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/x86_= 64/compat/entry.S=0A+++ b/xen/arch/x86/x86_64/compat/entry.S=0A@@ -21,8 = +21,7 @@ ENTRY(compat_hypercall)=0A UNLIKELY_START(ne, msi_check)=0A = movl $HYPERCALL_VECTOR,%edi=0A call check_for_unexpected_msi=0A= - RESTORE_ALL=0A- SAVE_ALL=0A+ LOAD_C_CLOBBERED=0A = UNLIKELY_END(msi_check)=0A =0A GET_CURRENT(%rbx)=0A@@ -173,8 = +172,7 @@ compat_bad_hypercall:=0A /* %rbx: struct vcpu, interrupts = disabled */=0A compat_restore_all_guest:=0A ASSERT_INTERRUPTS_DISAB= LED=0A- RESTORE_ALL=0A- addq $8,%rsp=0A+ RESTORE_ALL = adj=3D8=0A .Lft0: iretq=0A =0A .section .fixup,"ax"=0A--- a/xen/arch/x86/x= 86_64/entry.S=0A+++ b/xen/arch/x86/x86_64/entry.S=0A@@ -47,12 +47,10 @@ = restore_all_guest:=0A cmpl $1,%ecx=0A ja .Lforce_iret= =0A =0A- addq $8,%rsp=0A- popq %rcx # = RIP=0A- popq %r11 # CS=0A- cmpw = $FLAT_USER_CS32,%r11=0A- popq %r11 # RFLAGS=0A- = popq %rsp # RSP=0A+ cmpw $FLAT_USER_CS32= ,16(%rsp)# CS=0A+ movq 8(%rsp),%rcx # RIP=0A+ = movq 24(%rsp),%r11 # RFLAGS=0A+ movq 32(%rsp),%rsp = # RSP=0A je 1f=0A sysretq=0A 1: sysretl=0A@@ = -101,8 +99,7 @@ failsafe_callback:=0A ALIGN=0A /* No special = register assumptions. */=0A restore_all_xen:=0A- RESTORE_ALL=0A- = addq $8,%rsp=0A+ RESTORE_ALL adj=3D8=0A iretq=0A =0A = /*=0A@@ -311,8 +308,7 @@ ENTRY(int80_direct_trap)=0A UNLIKELY_START(ne, = msi_check)=0A movl $0x80,%edi=0A call check_for_unexpecte= d_msi=0A- RESTORE_ALL=0A- SAVE_ALL=0A+ LOAD_C_CLOBBERE= D=0A UNLIKELY_END(msi_check)=0A =0A GET_CURRENT(%rbx)=0A--- = a/xen/include/asm-x86/x86_64/asm_defns.h=0A+++ b/xen/include/asm-x86/x86_64= /asm_defns.h=0A@@ -5,11 +5,11 @@=0A =0A #ifdef CONFIG_FRAME_POINTER=0A /* = Indicate special exception stack frame by inverting the frame pointer. = */=0A-#define SETUP_EXCEPTION_FRAME_POINTER \=0A- movq = %rsp,%rbp; \=0A+#define SETUP_EXCEPTION_FRAME_POINTE= R(offs) \=0A+ leaq offs(%rsp),%rbp; \=0A = notq %rbp=0A #else=0A-#define SETUP_EXCEPTION_FRAME_POINTER=0A+#define = SETUP_EXCEPTION_FRAME_POINTER(off)=0A #endif=0A =0A #ifndef NDEBUG=0A@@ = -27,40 +27,49 @@=0A #define ASSERT_INTERRUPTS_DISABLED ASSERT_INTERRUPT_STA= TUS(z)=0A =0A #define SAVE_ALL \=0A+ = addq $-(UREGS_error_code-UREGS_r15), %rsp; \=0A cld; = \=0A- pushq %rdi; = \=0A- pushq %rsi; \=0A- pushq = %rdx; \=0A- pushq %rcx; = \=0A- pushq %rax; \=0A- = pushq %r8; \=0A- pushq %r9; = \=0A- pushq %r10; = \=0A- pushq %r11; \=0A- pushq = %rbx; \=0A- pushq %rbp; = \=0A- SETUP_EXCEPTION_FRAME_POINTER; \=0A- = pushq %r12; \=0A- pushq %r13; = \=0A- pushq %r14; = \=0A- pushq %r15;=0A-=0A-#define RESTORE_ALL = \=0A- popq %r15; \=0A- = popq %r14; \=0A- popq %r13; = \=0A- popq %r12; = \=0A- popq %rbp; \=0A- popq = %rbx; \=0A- popq %r11; = \=0A- popq %r10; \=0A- = popq %r9; \=0A- popq %r8; = \=0A- popq %rax; = \=0A- popq %rcx; \=0A- popq = %rdx; \=0A- popq %rsi; = \=0A- popq %rdi;=0A+ movq %rdi,UREGS_rdi(%rsp);= \=0A+ movq %rsi,UREGS_rsi(%rsp); \=0A+ = movq %rdx,UREGS_rdx(%rsp); \=0A+ movq %rcx,UREGS_r= cx(%rsp); \=0A+ movq %rax,UREGS_rax(%rsp); = \=0A+ movq %r8,UREGS_r8(%rsp); \=0A+ movq = %r9,UREGS_r9(%rsp); \=0A+ movq %r10,UREGS_r10(%rsp); = \=0A+ movq %r11,UREGS_r11(%rsp); \=0A+ = movq %rbx,UREGS_rbx(%rsp); \=0A+ movq %rbp,UREGS_rb= p(%rsp); \=0A+ SETUP_EXCEPTION_FRAME_POINTER(UREGS_rbp);= \=0A+ movq %r12,UREGS_r12(%rsp); \=0A+ movq = %r13,UREGS_r13(%rsp); \=0A+ movq %r14,UREGS_r14(%rsp); = \=0A+ movq %r15,UREGS_r15(%rsp); \=0A+=0A+#= ifdef __ASSEMBLY__=0A+.macro LOAD_C_CLOBBERED=0A+ movq UREGS_r11(%r= sp),%r11=0A+ movq UREGS_r10(%rsp),%r10=0A+ movq UREGS_r9(%r= sp),%r9=0A+ movq UREGS_r8(%rsp),%r8=0A+ movq UREGS_rax(%rsp= ),%rax=0A+ movq UREGS_rcx(%rsp),%rcx=0A+ movq UREGS_rdx(%rs= p),%rdx=0A+ movq UREGS_rsi(%rsp),%rsi=0A+ movq UREGS_rdi(%r= sp),%rdi=0A+.endm=0A+=0A+.macro RESTORE_ALL adj=3D0=0A+ movq = UREGS_r15(%rsp),%r15=0A+ movq UREGS_r14(%rsp),%r14=0A+ movq = UREGS_r13(%rsp),%r13=0A+ movq UREGS_r12(%rsp),%r12=0A+ = movq UREGS_rbp(%rsp),%rbp=0A+ movq UREGS_rbx(%rsp),%rbx=0A+ = LOAD_C_CLOBBERED=0A+ subq $-(UREGS_error_code-UREGS_r15+\adj), = %rsp=0A+.endm=0A+#endif=0A =0A #ifdef PERF_COUNTERS=0A #define PERFC_INCR(_= name,_idx,_cur) \=0A@@ -94,7 +103,7 @@=0A __asm__( = \=0A "\n" __ALIGN_STR"\n" = \=0A "common_interrupt:\n\t" \=0A- = STR(SAVE_ALL) \=0A+ STR(SAVE_ALL) "\n\t" = \=0A "movq %rsp,%rdi\n\t" = \=0A "callq " STR(do_IRQ) "\n\t" \=0A "jmp = ret_from_intr\n");=0A --=__PartDBEAED8F.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartDBEAED8F.0__=--