login
Header Space

 
 

[PATCH 19 of 36] paravirt_ops: define PARA_INDIRECT for indirect asm calls

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Ingo Molnar <mingo@...>
Cc: LKML <linux-kernel@...>, <x86@...>, xen-devel <xen-devel@...>, Stephen Tweedie <sct@...>, Eduardo Habkost <ehabkost@...>, Mark McLoughlin <markmc@...>
Date: Wednesday, June 25, 2008 - 12:19 am

On 32-bit it's best to use a %cs: prefix to access memory where the
other segments may not bet set up properly yet.  On 64-bit it's best
to use a rip-relative addressing mode.  Define PARA_INDIRECT() to
abstract this and generate the proper addressing mode in each case.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
 include/asm-x86/paravirt.h |   30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/include/asm-x86/paravirt.h b/include/asm-x86/paravirt.h
--- a/include/asm-x86/paravirt.h
+++ b/include/asm-x86/paravirt.h
@@ -1456,55 +1456,57 @@
 #define PV_RESTORE_REGS popq %rdx; popq %rcx; popq %rdi; popq %rax
 #define PARA_PATCH(struct, off)        ((PARAVIRT_PATCH_##struct + (off)) / 8)
 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
+#define PARA_INDIRECT(addr)	*addr(%rip)
 #else
 #define PV_SAVE_REGS   pushl %eax; pushl %edi; pushl %ecx; pushl %edx
 #define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax
 #define PARA_PATCH(struct, off)        ((PARAVIRT_PATCH_##struct + (off)) / 4)
 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
+#define PARA_INDIRECT(addr)	*%cs:addr
 #endif
 
 #define INTERRUPT_RETURN						\
 	PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE,	\
-		  jmp *%cs:pv_cpu_ops+PV_CPU_iret)
+		  jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
 
 #define INTERRUPT_RETURN_NMI_SAFE					\
 	PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_nmi_return), CLBR_NONE,	\
-		  jmp *%cs:pv_cpu_ops+PV_CPU_nmi_return)
+		  jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_nmi_return))
 
 #define DISABLE_INTERRUPTS(clobbers)					\
 	PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
-		  PV_SAVE_REGS;			\
-		  call *%cs:pv_irq_ops+PV_IRQ_irq_disable;		\
+		  PV_SAVE_REGS;						\
+		  call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable);	\
 		  PV_RESTORE_REGS;)			\
 
 #define ENABLE_INTERRUPTS(clobbers)					\
 	PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers,	\
-		  PV_SAVE_REGS;			\
-		  call *%cs:pv_irq_ops+PV_IRQ_irq_enable;		\
+		  PV_SAVE_REGS;						\
+		  call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable);	\
 		  PV_RESTORE_REGS;)
 
 #define ENABLE_INTERRUPTS_SYSCALL_RET					\
 	PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_syscall_ret),\
 		  CLBR_NONE,						\
-		  jmp *%cs:pv_cpu_ops+PV_CPU_irq_enable_syscall_ret)
+		  jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_syscall_ret))
 
 
 #ifdef CONFIG_X86_32
-#define GET_CR0_INTO_EAX			\
-	push %ecx; push %edx;			\
-	call *pv_cpu_ops+PV_CPU_read_cr0;	\
+#define GET_CR0_INTO_EAX				\
+	push %ecx; push %edx;				\
+	call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);	\
 	pop %edx; pop %ecx
 #else
 #define SWAPGS								\
 	PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE,	\
 		  PV_SAVE_REGS;						\
-		  call *pv_cpu_ops+PV_CPU_swapgs;			\
+		  call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs);		\
 		  PV_RESTORE_REGS					\
 		 )
 
-#define GET_CR2_INTO_RCX			\
-	call *pv_mmu_ops+PV_MMU_read_cr2;	\
-	movq %rax, %rcx;			\
+#define GET_CR2_INTO_RCX				\
+	call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2);	\
+	movq %rax, %rcx;				\
 	xorq %rax, %rax;
 
 #endif


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00 of 36] x86/paravirt: groundwork for 64-bit Xen sup..., Jeremy Fitzhardinge, (Wed Jun 25, 12:18 am)
Re: [PATCH 00 of 36] x86/paravirt: groundwork for 64-bit Xen..., Jeremy Fitzhardinge, (Wed Jun 25, 4:03 pm)
Re: [PATCH 00 of 36] x86/paravirt: groundwork for 64-bit Xen..., Jeremy Fitzhardinge, (Wed Jun 25, 4:12 pm)
Re: [PATCH 00 of 36] x86/paravirt: groundwork for 64-bit Xen..., Jeremy Fitzhardinge, (Thu Jun 26, 3:02 pm)
Re: [PATCH 00 of 36] x86/paravirt: groundwork for 64-bit Xen..., Jeremy Fitzhardinge, (Thu Jun 26, 2:25 pm)
Re: [PATCH 00 of 36] x86/paravirt: groundwork for 64-bit Xen..., Jeremy Fitzhardinge, (Thu Jun 26, 10:28 am)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Thu Jun 26, 10:34 am)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Fri Jun 27, 3:04 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Sun Jun 29, 11:02 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Mon Jun 30, 7:04 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Tue Jul 1, 12:14 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Thu Jul 3, 2:25 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Thu Jul 3, 2:41 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Thu Jul 3, 11:47 am)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Tue Jul 1, 12:10 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Mon Jun 30, 1:57 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Mon Jun 30, 1:17 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Mon Jun 30, 2:36 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Mon Jun 30, 1:32 am)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Fri Jun 27, 12:02 pm)
Re: [Xen-devel] Re: [PATCH 00 of 36] x86/paravirt: groundwor..., Jeremy Fitzhardinge, (Fri Jun 27, 12:25 pm)
Re: [PATCH 00 of 36] x86/paravirt: groundwork for 64-bit Xen..., Jeremy Fitzhardinge, (Wed Jun 25, 7:46 am)
[PATCH 36 of 36] x86_64/paravirt: Make load_gs_index() a par..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
Re: [PATCH 36 of 36] x86_64/paravirt: Make load_gs_index() a..., Jeremy Fitzhardinge, (Wed Jun 25, 7:48 am)
[PATCH 26 of 36] x86_64: Split set_pte_vaddr(), Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 35 of 36] x86_64/paravirt: add adjust_exception_frame, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 04 of 36] x86: remove open-coded save/load segment op..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 25 of 36] x86_64: PSE no longer a hard requirement, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 18 of 36] x86/paravirt: add debugging for missing ope..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 01 of 36] x86: asm-x86/pgtable.h: fix compiler warning, Jeremy Fitzhardinge, (Wed Jun 25, 12:18 am)
[PATCH 32 of 36] Add sysret/sysexit pvops for returning to 3..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 31 of 36] x86_64 pvops: don't restore user rsp within..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 06 of 36] x86_64: use p??_populate() to attach pages ..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 07 of 36] x86_64: unify early_ioremap, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 19 of 36] paravirt_ops: define PARA_INDIRECT for indi..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 28 of 36] Save %fs and %gs before load_TLS() and arch..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 30 of 36] x86/paravirt_ops: split sysret and sysexit, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 21 of 36] x86-64: add FIX_PARAVIRT_BOOTMAP fixmap slot, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 20 of 36] paravirt/x86_64: move __PAGE_OFFSET to leav..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 34 of 36] x86_64: swapgs pvop with a user-stack can n..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 05 of 36] x86_64: use write_gdt_entry in vsyscall_set..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 33 of 36] x86_64: ia32entry: replace privileged instr..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 27 of 36] x86_64: __switch_to(): Move arch_leave_lazy..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 29 of 36] Use __KERNEL_DS as SS when returning to a k..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 24 of 36] x86_64: create small vmemmap mappings if PS..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 10 of 36] x86: unify pgd_index, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 11 of 36] x86: unify mmu_context.h, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 08 of 36] x86_64: Add gate_offset() and gate_segment(..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 09 of 36] x86_64: Use __pgd() on mk_kernel_pgd(), Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 23 of 36] x86_64: adjust mapping of physical pagetabl..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 14 of 36] x86_64: add sync_cmpxchg, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 03 of 36] x86: add memory barriers to wrmsr, Jeremy Fitzhardinge, (Wed Jun 25, 12:18 am)
Re: [PATCH 03 of 36] x86: add memory barriers to wrmsr, Arjan van de Ven, (Wed Jun 25, 12:44 am)
Re: [PATCH 03 of 36] x86: add memory barriers to wrmsr, Jeremy Fitzhardinge, (Wed Jun 25, 5:08 pm)
Re: [PATCH 03 of 36] x86: add memory barriers to wrmsr, Arjan van de Ven, (Wed Jun 25, 6:31 pm)
Re: [PATCH 03 of 36] x86: add memory barriers to wrmsr, H. Peter Anvin, (Wed Jun 25, 7:18 pm)
Re: [PATCH 03 of 36] x86: add memory barriers to wrmsr, Jeremy Fitzhardinge, (Wed Jun 25, 7:37 pm)
Re: [PATCH 03 of 36] x86: add memory barriers to wrmsr, H. Peter Anvin, (Wed Jun 25, 7:42 pm)
Re: [PATCH 03 of 36] x86: add memory barriers to wrmsr, Jeremy Fitzhardinge, (Wed Jun 25, 7:05 pm)
[PATCH 13 of 36] x86_64: add prototype for x86_64_start_kern..., Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 12 of 36] x86_64: replace end_pfn with num_physpages, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 17 of 36] x86: preallocate and prepopulate separately, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 15 of 36] x86: simplify vmalloc_sync_all, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 22 of 36] x86_64: split x86_64_start_kernel, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 16 of 36] x86/paravirt: add a pgd_alloc/free hooks, Jeremy Fitzhardinge, (Wed Jun 25, 12:19 am)
[PATCH 02 of 36] x86: add memory clobber to save/loadsegment, Jeremy Fitzhardinge, (Wed Jun 25, 12:18 am)
speck-geostationary