1 #ifndef _ASM_X86_PARAVIRT_H
2 #define _ASM_X86_PARAVIRT_H
3 /* Various instructions on x86 need to be replaced for
4 * para-virtualization: those hooks are defined here. */
7 #include <asm/pgtable_types.h>
10 #include <asm/paravirt_types.h>
13 #include <linux/bug.h>
14 #include <linux/types.h>
15 #include <linux/cpumask.h>
17 static inline int paravirt_enabled(void)
19 return pv_info.paravirt_enabled;
22 static inline int paravirt_has_feature(unsigned int feature)
24 WARN_ON_ONCE(!pv_info.paravirt_enabled);
25 return (pv_info.features & feature);
28 static inline void load_sp0(struct tss_struct *tss,
29 struct thread_struct *thread)
31 PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
34 /* The paravirtualized CPUID instruction. */
35 static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
36 unsigned int *ecx, unsigned int *edx)
38 PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
42 * These special macros can be used to get or set a debugging register
44 static inline unsigned long paravirt_get_debugreg(int reg)
46 return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
48 #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
49 static inline void set_debugreg(unsigned long val, int reg)
51 PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
54 static inline void clts(void)
56 PVOP_VCALL0(pv_cpu_ops.clts);
59 static inline unsigned long read_cr0(void)
61 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
64 static inline void write_cr0(unsigned long x)
66 PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
69 static inline unsigned long read_cr2(void)
71 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
74 static inline void write_cr2(unsigned long x)
76 PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
79 static inline unsigned long read_cr3(void)
81 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
84 static inline void write_cr3(unsigned long x)
86 PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
89 static inline unsigned long __read_cr4(void)
91 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
93 static inline unsigned long __read_cr4_safe(void)
95 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
98 static inline void __write_cr4(unsigned long x)
100 PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
104 static inline unsigned long read_cr8(void)
106 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8);
109 static inline void write_cr8(unsigned long x)
111 PVOP_VCALL1(pv_cpu_ops.write_cr8, x);
115 static inline void arch_safe_halt(void)
117 PVOP_VCALL0(pv_irq_ops.safe_halt);
120 static inline void halt(void)
122 PVOP_VCALL0(pv_irq_ops.halt);
125 static inline void wbinvd(void)
127 PVOP_VCALL0(pv_cpu_ops.wbinvd);
130 #define get_kernel_rpl() (pv_info.kernel_rpl)
132 static inline u64 paravirt_read_msr(unsigned msr, int *err)
134 return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
137 static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
139 return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
142 /* These should all do BUG_ON(_err), but our headers are too tangled. */
143 #define rdmsr(msr, val1, val2) \
146 u64 _l = paravirt_read_msr(msr, &_err); \
151 #define wrmsr(msr, val1, val2) \
153 paravirt_write_msr(msr, val1, val2); \
156 #define rdmsrl(msr, val) \
159 val = paravirt_read_msr(msr, &_err); \
162 static inline void wrmsrl(unsigned msr, u64 val)
164 wrmsr(msr, (u32)val, (u32)(val>>32));
167 #define wrmsr_safe(msr, a, b) paravirt_write_msr(msr, a, b)
169 /* rdmsr with exception handling */
170 #define rdmsr_safe(msr, a, b) \
173 u64 _l = paravirt_read_msr(msr, &_err); \
179 static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
183 *p = paravirt_read_msr(msr, &err);
187 static inline unsigned long long paravirt_sched_clock(void)
189 return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
193 extern struct static_key paravirt_steal_enabled;
194 extern struct static_key paravirt_steal_rq_enabled;
196 static inline u64 paravirt_steal_clock(int cpu)
198 return PVOP_CALL1(u64, pv_time_ops.steal_clock, cpu);
201 static inline unsigned long long paravirt_read_pmc(int counter)
203 return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
206 #define rdpmc(counter, low, high) \
208 u64 _l = paravirt_read_pmc(counter); \
213 #define rdpmcl(counter, val) ((val) = paravirt_read_pmc(counter))
215 static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
217 PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries);
220 static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
222 PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries);
225 static inline void load_TR_desc(void)
227 PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
229 static inline void load_gdt(const struct desc_ptr *dtr)
231 PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
233 static inline void load_idt(const struct desc_ptr *dtr)
235 PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
237 static inline void set_ldt(const void *addr, unsigned entries)
239 PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
241 static inline void store_idt(struct desc_ptr *dtr)
243 PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
245 static inline unsigned long paravirt_store_tr(void)
247 return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
249 #define store_tr(tr) ((tr) = paravirt_store_tr())
250 static inline void load_TLS(struct thread_struct *t, unsigned cpu)
252 PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
256 static inline void load_gs_index(unsigned int gs)
258 PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
262 static inline void write_ldt_entry(struct desc_struct *dt, int entry,
265 PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
268 static inline void write_gdt_entry(struct desc_struct *dt, int entry,
269 void *desc, int type)
271 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
274 static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
276 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
278 static inline void set_iopl_mask(unsigned mask)
280 PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
283 /* The paravirtualized I/O functions */
284 static inline void slow_down_io(void)
286 pv_cpu_ops.io_delay();
287 #ifdef REALLY_SLOW_IO
288 pv_cpu_ops.io_delay();
289 pv_cpu_ops.io_delay();
290 pv_cpu_ops.io_delay();
295 static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
296 unsigned long start_esp)
298 PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
299 phys_apicid, start_eip, start_esp);
303 static inline void paravirt_activate_mm(struct mm_struct *prev,
304 struct mm_struct *next)
306 PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
309 static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm,
310 struct mm_struct *mm)
312 PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
315 static inline void paravirt_arch_exit_mmap(struct mm_struct *mm)
317 PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
320 static inline void __flush_tlb(void)
322 PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
324 static inline void __flush_tlb_global(void)
326 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
328 static inline void __flush_tlb_single(unsigned long addr)
330 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
333 static inline void flush_tlb_others(const struct cpumask *cpumask,
334 struct mm_struct *mm,
338 PVOP_VCALL4(pv_mmu_ops.flush_tlb_others, cpumask, mm, start, end);
341 static inline int paravirt_pgd_alloc(struct mm_struct *mm)
343 return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
346 static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
348 PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
351 static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
353 PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
355 static inline void paravirt_release_pte(unsigned long pfn)
357 PVOP_VCALL1(pv_mmu_ops.release_pte, pfn);
360 static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
362 PVOP_VCALL2(pv_mmu_ops.alloc_pmd, mm, pfn);
365 static inline void paravirt_release_pmd(unsigned long pfn)
367 PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn);
370 static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
372 PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn);
374 static inline void paravirt_release_pud(unsigned long pfn)
376 PVOP_VCALL1(pv_mmu_ops.release_pud, pfn);
379 static inline void pte_update(struct mm_struct *mm, unsigned long addr,
382 PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
384 static inline void pmd_update(struct mm_struct *mm, unsigned long addr,
387 PVOP_VCALL3(pv_mmu_ops.pmd_update, mm, addr, pmdp);
390 static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
393 PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
396 static inline void pmd_update_defer(struct mm_struct *mm, unsigned long addr,
399 PVOP_VCALL3(pv_mmu_ops.pmd_update_defer, mm, addr, pmdp);
402 static inline pte_t __pte(pteval_t val)
406 if (sizeof(pteval_t) > sizeof(long))
407 ret = PVOP_CALLEE2(pteval_t,
409 val, (u64)val >> 32);
411 ret = PVOP_CALLEE1(pteval_t,
415 return (pte_t) { .pte = ret };
418 static inline pteval_t pte_val(pte_t pte)
422 if (sizeof(pteval_t) > sizeof(long))
423 ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val,
424 pte.pte, (u64)pte.pte >> 32);
426 ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val,
432 static inline pgd_t __pgd(pgdval_t val)
436 if (sizeof(pgdval_t) > sizeof(long))
437 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd,
438 val, (u64)val >> 32);
440 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd,
443 return (pgd_t) { ret };
446 static inline pgdval_t pgd_val(pgd_t pgd)
450 if (sizeof(pgdval_t) > sizeof(long))
451 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val,
452 pgd.pgd, (u64)pgd.pgd >> 32);
454 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val,
460 #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
461 static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
466 ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
469 return (pte_t) { .pte = ret };
472 static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
473 pte_t *ptep, pte_t pte)
475 if (sizeof(pteval_t) > sizeof(long))
477 pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
479 PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
480 mm, addr, ptep, pte.pte);
483 static inline void set_pte(pte_t *ptep, pte_t pte)
485 if (sizeof(pteval_t) > sizeof(long))
486 PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
487 pte.pte, (u64)pte.pte >> 32);
489 PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
493 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
494 pte_t *ptep, pte_t pte)
496 if (sizeof(pteval_t) > sizeof(long))
498 pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
500 PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
503 static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
504 pmd_t *pmdp, pmd_t pmd)
506 if (sizeof(pmdval_t) > sizeof(long))
508 pv_mmu_ops.set_pmd_at(mm, addr, pmdp, pmd);
510 PVOP_VCALL4(pv_mmu_ops.set_pmd_at, mm, addr, pmdp,
511 native_pmd_val(pmd));
514 static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
516 pmdval_t val = native_pmd_val(pmd);
518 if (sizeof(pmdval_t) > sizeof(long))
519 PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
521 PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
524 #if CONFIG_PGTABLE_LEVELS >= 3
525 static inline pmd_t __pmd(pmdval_t val)
529 if (sizeof(pmdval_t) > sizeof(long))
530 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd,
531 val, (u64)val >> 32);
533 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd,
536 return (pmd_t) { ret };
539 static inline pmdval_t pmd_val(pmd_t pmd)
543 if (sizeof(pmdval_t) > sizeof(long))
544 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val,
545 pmd.pmd, (u64)pmd.pmd >> 32);
547 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val,
553 static inline void set_pud(pud_t *pudp, pud_t pud)
555 pudval_t val = native_pud_val(pud);
557 if (sizeof(pudval_t) > sizeof(long))
558 PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
559 val, (u64)val >> 32);
561 PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
564 #if CONFIG_PGTABLE_LEVELS == 4
565 static inline pud_t __pud(pudval_t val)
569 if (sizeof(pudval_t) > sizeof(long))
570 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud,
571 val, (u64)val >> 32);
573 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud,
576 return (pud_t) { ret };
579 static inline pudval_t pud_val(pud_t pud)
583 if (sizeof(pudval_t) > sizeof(long))
584 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val,
585 pud.pud, (u64)pud.pud >> 32);
587 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val,
593 static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
595 pgdval_t val = native_pgd_val(pgd);
597 if (sizeof(pgdval_t) > sizeof(long))
598 PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
599 val, (u64)val >> 32);
601 PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
605 static inline void pgd_clear(pgd_t *pgdp)
607 set_pgd(pgdp, __pgd(0));
610 static inline void pud_clear(pud_t *pudp)
612 set_pud(pudp, __pud(0));
615 #endif /* CONFIG_PGTABLE_LEVELS == 4 */
617 #endif /* CONFIG_PGTABLE_LEVELS >= 3 */
619 #ifdef CONFIG_X86_PAE
620 /* Special-case pte-setting operations for PAE, which can't update a
621 64-bit pte atomically */
622 static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
624 PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
625 pte.pte, pte.pte >> 32);
628 static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
631 PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
634 static inline void pmd_clear(pmd_t *pmdp)
636 PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
638 #else /* !CONFIG_X86_PAE */
639 static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
644 static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
647 set_pte_at(mm, addr, ptep, __pte(0));
650 static inline void pmd_clear(pmd_t *pmdp)
652 set_pmd(pmdp, __pmd(0));
654 #endif /* CONFIG_X86_PAE */
656 #define __HAVE_ARCH_START_CONTEXT_SWITCH
657 static inline void arch_start_context_switch(struct task_struct *prev)
659 PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
662 static inline void arch_end_context_switch(struct task_struct *next)
664 PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
667 #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
668 static inline void arch_enter_lazy_mmu_mode(void)
670 PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
673 static inline void arch_leave_lazy_mmu_mode(void)
675 PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
678 static inline void arch_flush_lazy_mmu_mode(void)
680 PVOP_VCALL0(pv_mmu_ops.lazy_mode.flush);
683 static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
684 phys_addr_t phys, pgprot_t flags)
686 pv_mmu_ops.set_fixmap(idx, phys, flags);
689 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
691 #ifdef CONFIG_QUEUED_SPINLOCKS
693 static __always_inline void pv_queued_spin_lock_slowpath(struct qspinlock *lock,
696 PVOP_VCALL2(pv_lock_ops.queued_spin_lock_slowpath, lock, val);
699 static __always_inline void pv_queued_spin_unlock(struct qspinlock *lock)
701 PVOP_VCALLEE1(pv_lock_ops.queued_spin_unlock, lock);
704 static __always_inline void pv_wait(u8 *ptr, u8 val)
706 PVOP_VCALL2(pv_lock_ops.wait, ptr, val);
709 static __always_inline void pv_kick(int cpu)
711 PVOP_VCALL1(pv_lock_ops.kick, cpu);
714 #else /* !CONFIG_QUEUED_SPINLOCKS */
716 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
719 PVOP_VCALLEE2(pv_lock_ops.lock_spinning, lock, ticket);
722 static __always_inline void __ticket_unlock_kick(struct arch_spinlock *lock,
725 PVOP_VCALL2(pv_lock_ops.unlock_kick, lock, ticket);
728 #endif /* CONFIG_QUEUED_SPINLOCKS */
730 #endif /* SMP && PARAVIRT_SPINLOCKS */
733 #define PV_SAVE_REGS "pushl %ecx; pushl %edx;"
734 #define PV_RESTORE_REGS "popl %edx; popl %ecx;"
736 /* save and restore all caller-save registers, except return value */
737 #define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
738 #define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
740 #define PV_FLAGS_ARG "0"
741 #define PV_EXTRA_CLOBBERS
742 #define PV_VEXTRA_CLOBBERS
744 /* save and restore all caller-save registers, except return value */
745 #define PV_SAVE_ALL_CALLER_REGS \
754 #define PV_RESTORE_ALL_CALLER_REGS \
764 /* We save some registers, but all of them, that's too much. We clobber all
765 * caller saved registers but the argument parameter */
766 #define PV_SAVE_REGS "pushq %%rdi;"
767 #define PV_RESTORE_REGS "popq %%rdi;"
768 #define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi"
769 #define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi"
770 #define PV_FLAGS_ARG "D"
774 * Generate a thunk around a function which saves all caller-save
775 * registers except for the return value. This allows C functions to
776 * be called from assembler code where fewer than normal registers are
777 * available. It may also help code generation around calls from C
778 * code if the common case doesn't use many registers.
780 * When a callee is wrapped in a thunk, the caller can assume that all
781 * arg regs and all scratch registers are preserved across the
782 * call. The return value in rax/eax will not be saved, even for void
785 #define PV_CALLEE_SAVE_REGS_THUNK(func) \
786 extern typeof(func) __raw_callee_save_##func; \
788 asm(".pushsection .text;" \
789 ".globl __raw_callee_save_" #func " ; " \
790 "__raw_callee_save_" #func ": " \
791 PV_SAVE_ALL_CALLER_REGS \
793 PV_RESTORE_ALL_CALLER_REGS \
797 /* Get a reference to a callee-save function */
798 #define PV_CALLEE_SAVE(func) \
799 ((struct paravirt_callee_save) { __raw_callee_save_##func })
801 /* Promise that "func" already uses the right calling convention */
802 #define __PV_IS_CALLEE_SAVE(func) \
803 ((struct paravirt_callee_save) { func })
805 static inline notrace unsigned long arch_local_save_flags(void)
807 return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl);
810 static inline notrace void arch_local_irq_restore(unsigned long f)
812 PVOP_VCALLEE1(pv_irq_ops.restore_fl, f);
815 static inline notrace void arch_local_irq_disable(void)
817 PVOP_VCALLEE0(pv_irq_ops.irq_disable);
820 static inline notrace void arch_local_irq_enable(void)
822 PVOP_VCALLEE0(pv_irq_ops.irq_enable);
825 static inline notrace unsigned long arch_local_irq_save(void)
829 f = arch_local_save_flags();
830 arch_local_irq_disable();
835 /* Make sure as little as possible of this mess escapes. */
850 extern void default_banner(void);
852 #else /* __ASSEMBLY__ */
854 #define _PVSITE(ptype, clobbers, ops, word, algn) \
858 .pushsection .parainstructions,"a"; \
867 #define COND_PUSH(set, mask, reg) \
868 .if ((~(set)) & mask); push %reg; .endif
869 #define COND_POP(set, mask, reg) \
870 .if ((~(set)) & mask); pop %reg; .endif
874 #define PV_SAVE_REGS(set) \
875 COND_PUSH(set, CLBR_RAX, rax); \
876 COND_PUSH(set, CLBR_RCX, rcx); \
877 COND_PUSH(set, CLBR_RDX, rdx); \
878 COND_PUSH(set, CLBR_RSI, rsi); \
879 COND_PUSH(set, CLBR_RDI, rdi); \
880 COND_PUSH(set, CLBR_R8, r8); \
881 COND_PUSH(set, CLBR_R9, r9); \
882 COND_PUSH(set, CLBR_R10, r10); \
883 COND_PUSH(set, CLBR_R11, r11)
884 #define PV_RESTORE_REGS(set) \
885 COND_POP(set, CLBR_R11, r11); \
886 COND_POP(set, CLBR_R10, r10); \
887 COND_POP(set, CLBR_R9, r9); \
888 COND_POP(set, CLBR_R8, r8); \
889 COND_POP(set, CLBR_RDI, rdi); \
890 COND_POP(set, CLBR_RSI, rsi); \
891 COND_POP(set, CLBR_RDX, rdx); \
892 COND_POP(set, CLBR_RCX, rcx); \
893 COND_POP(set, CLBR_RAX, rax)
895 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
896 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
897 #define PARA_INDIRECT(addr) *addr(%rip)
899 #define PV_SAVE_REGS(set) \
900 COND_PUSH(set, CLBR_EAX, eax); \
901 COND_PUSH(set, CLBR_EDI, edi); \
902 COND_PUSH(set, CLBR_ECX, ecx); \
903 COND_PUSH(set, CLBR_EDX, edx)
904 #define PV_RESTORE_REGS(set) \
905 COND_POP(set, CLBR_EDX, edx); \
906 COND_POP(set, CLBR_ECX, ecx); \
907 COND_POP(set, CLBR_EDI, edi); \
908 COND_POP(set, CLBR_EAX, eax)
910 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
911 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
912 #define PARA_INDIRECT(addr) *%cs:addr
915 #define INTERRUPT_RETURN \
916 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
917 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
919 #define DISABLE_INTERRUPTS(clobbers) \
920 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
921 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
922 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
923 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
925 #define ENABLE_INTERRUPTS(clobbers) \
926 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
927 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
928 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
929 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
931 #define USERGS_SYSRET32 \
932 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32), \
934 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32))
937 #define GET_CR0_INTO_EAX \
938 push %ecx; push %edx; \
939 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
942 #define ENABLE_INTERRUPTS_SYSEXIT \
943 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
945 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
948 #else /* !CONFIG_X86_32 */
951 * If swapgs is used while the userspace stack is still current,
952 * there's no way to call a pvop. The PV replacement *must* be
953 * inlined, or the swapgs instruction must be trapped and emulated.
955 #define SWAPGS_UNSAFE_STACK \
956 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
960 * Note: swapgs is very special, and in practise is either going to be
961 * implemented with a single "swapgs" instruction or something very
962 * special. Either way, we don't need to save any registers for
966 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
967 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
970 #define GET_CR2_INTO_RAX \
971 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2)
973 #define PARAVIRT_ADJUST_EXCEPTION_FRAME \
974 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \
976 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame))
978 #define USERGS_SYSRET64 \
979 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
981 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
982 #endif /* CONFIG_X86_32 */
984 #endif /* __ASSEMBLY__ */
985 #else /* CONFIG_PARAVIRT */
986 # define default_banner x86_init_noop
988 static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm,
989 struct mm_struct *mm)
993 static inline void paravirt_arch_exit_mmap(struct mm_struct *mm)
996 #endif /* __ASSEMBLY__ */
997 #endif /* !CONFIG_PARAVIRT */
998 #endif /* _ASM_X86_PARAVIRT_H */