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/types.h>
14 #include <linux/cpumask.h>
16 static inline int paravirt_enabled(void)
18 return pv_info
.paravirt_enabled
;
21 static inline void load_sp0(struct tss_struct
*tss
,
22 struct thread_struct
*thread
)
24 PVOP_VCALL2(pv_cpu_ops
.load_sp0
, tss
, thread
);
27 #define ARCH_SETUP pv_init_ops.arch_setup();
28 static inline unsigned long get_wallclock(void)
30 return PVOP_CALL0(unsigned long, pv_time_ops
.get_wallclock
);
33 static inline int set_wallclock(unsigned long nowtime
)
35 return PVOP_CALL1(int, pv_time_ops
.set_wallclock
, nowtime
);
38 static inline void (*choose_time_init(void))(void)
40 return pv_time_ops
.time_init
;
43 /* The paravirtualized CPUID instruction. */
44 static inline void __cpuid(unsigned int *eax
, unsigned int *ebx
,
45 unsigned int *ecx
, unsigned int *edx
)
47 PVOP_VCALL4(pv_cpu_ops
.cpuid
, eax
, ebx
, ecx
, edx
);
51 * These special macros can be used to get or set a debugging register
53 static inline unsigned long paravirt_get_debugreg(int reg
)
55 return PVOP_CALL1(unsigned long, pv_cpu_ops
.get_debugreg
, reg
);
57 #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
58 static inline void set_debugreg(unsigned long val
, int reg
)
60 PVOP_VCALL2(pv_cpu_ops
.set_debugreg
, reg
, val
);
63 static inline void clts(void)
65 PVOP_VCALL0(pv_cpu_ops
.clts
);
68 static inline unsigned long read_cr0(void)
70 return PVOP_CALL0(unsigned long, pv_cpu_ops
.read_cr0
);
73 static inline void write_cr0(unsigned long x
)
75 PVOP_VCALL1(pv_cpu_ops
.write_cr0
, x
);
78 static inline unsigned long read_cr2(void)
80 return PVOP_CALL0(unsigned long, pv_mmu_ops
.read_cr2
);
83 static inline void write_cr2(unsigned long x
)
85 PVOP_VCALL1(pv_mmu_ops
.write_cr2
, x
);
88 static inline unsigned long read_cr3(void)
90 return PVOP_CALL0(unsigned long, pv_mmu_ops
.read_cr3
);
93 static inline void write_cr3(unsigned long x
)
95 PVOP_VCALL1(pv_mmu_ops
.write_cr3
, x
);
98 static inline unsigned long read_cr4(void)
100 return PVOP_CALL0(unsigned long, pv_cpu_ops
.read_cr4
);
102 static inline unsigned long read_cr4_safe(void)
104 return PVOP_CALL0(unsigned long, pv_cpu_ops
.read_cr4_safe
);
107 static inline void write_cr4(unsigned long x
)
109 PVOP_VCALL1(pv_cpu_ops
.write_cr4
, x
);
113 static inline unsigned long read_cr8(void)
115 return PVOP_CALL0(unsigned long, pv_cpu_ops
.read_cr8
);
118 static inline void write_cr8(unsigned long x
)
120 PVOP_VCALL1(pv_cpu_ops
.write_cr8
, x
);
124 static inline void raw_safe_halt(void)
126 PVOP_VCALL0(pv_irq_ops
.safe_halt
);
129 static inline void halt(void)
131 PVOP_VCALL0(pv_irq_ops
.safe_halt
);
134 static inline void wbinvd(void)
136 PVOP_VCALL0(pv_cpu_ops
.wbinvd
);
139 #define get_kernel_rpl() (pv_info.kernel_rpl)
141 static inline u64
paravirt_read_msr(unsigned msr
, int *err
)
143 return PVOP_CALL2(u64
, pv_cpu_ops
.read_msr
, msr
, err
);
146 static inline int paravirt_rdmsr_regs(u32
*regs
)
148 return PVOP_CALL1(int, pv_cpu_ops
.rdmsr_regs
, regs
);
151 static inline int paravirt_write_msr(unsigned msr
, unsigned low
, unsigned high
)
153 return PVOP_CALL3(int, pv_cpu_ops
.write_msr
, msr
, low
, high
);
156 static inline int paravirt_wrmsr_regs(u32
*regs
)
158 return PVOP_CALL1(int, pv_cpu_ops
.wrmsr_regs
, regs
);
161 /* These should all do BUG_ON(_err), but our headers are too tangled. */
162 #define rdmsr(msr, val1, val2) \
165 u64 _l = paravirt_read_msr(msr, &_err); \
170 #define wrmsr(msr, val1, val2) \
172 paravirt_write_msr(msr, val1, val2); \
175 #define rdmsrl(msr, val) \
178 val = paravirt_read_msr(msr, &_err); \
181 #define wrmsrl(msr, val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
182 #define wrmsr_safe(msr, a, b) paravirt_write_msr(msr, a, b)
184 /* rdmsr with exception handling */
185 #define rdmsr_safe(msr, a, b) \
188 u64 _l = paravirt_read_msr(msr, &_err); \
194 #define rdmsr_safe_regs(regs) paravirt_rdmsr_regs(regs)
195 #define wrmsr_safe_regs(regs) paravirt_wrmsr_regs(regs)
197 static inline int rdmsrl_safe(unsigned msr
, unsigned long long *p
)
201 *p
= paravirt_read_msr(msr
, &err
);
204 static inline int rdmsrl_amd_safe(unsigned msr
, unsigned long long *p
)
210 gprs
[7] = 0x9c5a203a;
212 err
= paravirt_rdmsr_regs(gprs
);
214 *p
= gprs
[0] | ((u64
)gprs
[2] << 32);
219 static inline int wrmsrl_amd_safe(unsigned msr
, unsigned long long val
)
226 gprs
[7] = 0x9c5a203a;
228 return paravirt_wrmsr_regs(gprs
);
231 static inline u64
paravirt_read_tsc(void)
233 return PVOP_CALL0(u64
, pv_cpu_ops
.read_tsc
);
236 #define rdtscl(low) \
238 u64 _l = paravirt_read_tsc(); \
242 #define rdtscll(val) (val = paravirt_read_tsc())
244 static inline unsigned long long paravirt_sched_clock(void)
246 return PVOP_CALL0(unsigned long long, pv_time_ops
.sched_clock
);
248 #define calibrate_tsc() (pv_time_ops.get_tsc_khz())
250 static inline unsigned long long paravirt_read_pmc(int counter
)
252 return PVOP_CALL1(u64
, pv_cpu_ops
.read_pmc
, counter
);
255 #define rdpmc(counter, low, high) \
257 u64 _l = paravirt_read_pmc(counter); \
262 static inline unsigned long long paravirt_rdtscp(unsigned int *aux
)
264 return PVOP_CALL1(u64
, pv_cpu_ops
.read_tscp
, aux
);
267 #define rdtscp(low, high, aux) \
270 unsigned long __val = paravirt_rdtscp(&__aux); \
271 (low) = (u32)__val; \
272 (high) = (u32)(__val >> 32); \
276 #define rdtscpll(val, aux) \
278 unsigned long __aux; \
279 val = paravirt_rdtscp(&__aux); \
283 static inline void paravirt_alloc_ldt(struct desc_struct
*ldt
, unsigned entries
)
285 PVOP_VCALL2(pv_cpu_ops
.alloc_ldt
, ldt
, entries
);
288 static inline void paravirt_free_ldt(struct desc_struct
*ldt
, unsigned entries
)
290 PVOP_VCALL2(pv_cpu_ops
.free_ldt
, ldt
, entries
);
293 static inline void load_TR_desc(void)
295 PVOP_VCALL0(pv_cpu_ops
.load_tr_desc
);
297 static inline void load_gdt(const struct desc_ptr
*dtr
)
299 PVOP_VCALL1(pv_cpu_ops
.load_gdt
, dtr
);
301 static inline void load_idt(const struct desc_ptr
*dtr
)
303 PVOP_VCALL1(pv_cpu_ops
.load_idt
, dtr
);
305 static inline void set_ldt(const void *addr
, unsigned entries
)
307 PVOP_VCALL2(pv_cpu_ops
.set_ldt
, addr
, entries
);
309 static inline void store_gdt(struct desc_ptr
*dtr
)
311 PVOP_VCALL1(pv_cpu_ops
.store_gdt
, dtr
);
313 static inline void store_idt(struct desc_ptr
*dtr
)
315 PVOP_VCALL1(pv_cpu_ops
.store_idt
, dtr
);
317 static inline unsigned long paravirt_store_tr(void)
319 return PVOP_CALL0(unsigned long, pv_cpu_ops
.store_tr
);
321 #define store_tr(tr) ((tr) = paravirt_store_tr())
322 static inline void load_TLS(struct thread_struct
*t
, unsigned cpu
)
324 PVOP_VCALL2(pv_cpu_ops
.load_tls
, t
, cpu
);
328 static inline void load_gs_index(unsigned int gs
)
330 PVOP_VCALL1(pv_cpu_ops
.load_gs_index
, gs
);
334 static inline void write_ldt_entry(struct desc_struct
*dt
, int entry
,
337 PVOP_VCALL3(pv_cpu_ops
.write_ldt_entry
, dt
, entry
, desc
);
340 static inline void write_gdt_entry(struct desc_struct
*dt
, int entry
,
341 void *desc
, int type
)
343 PVOP_VCALL4(pv_cpu_ops
.write_gdt_entry
, dt
, entry
, desc
, type
);
346 static inline void write_idt_entry(gate_desc
*dt
, int entry
, const gate_desc
*g
)
348 PVOP_VCALL3(pv_cpu_ops
.write_idt_entry
, dt
, entry
, g
);
350 static inline void set_iopl_mask(unsigned mask
)
352 PVOP_VCALL1(pv_cpu_ops
.set_iopl_mask
, mask
);
355 /* The paravirtualized I/O functions */
356 static inline void slow_down_io(void)
358 pv_cpu_ops
.io_delay();
359 #ifdef REALLY_SLOW_IO
360 pv_cpu_ops
.io_delay();
361 pv_cpu_ops
.io_delay();
362 pv_cpu_ops
.io_delay();
366 #ifdef CONFIG_X86_LOCAL_APIC
367 static inline void setup_boot_clock(void)
369 PVOP_VCALL0(pv_apic_ops
.setup_boot_clock
);
372 static inline void setup_secondary_clock(void)
374 PVOP_VCALL0(pv_apic_ops
.setup_secondary_clock
);
378 static inline void paravirt_post_allocator_init(void)
380 if (pv_init_ops
.post_allocator_init
)
381 (*pv_init_ops
.post_allocator_init
)();
384 static inline void paravirt_pagetable_setup_start(pgd_t
*base
)
386 (*pv_mmu_ops
.pagetable_setup_start
)(base
);
389 static inline void paravirt_pagetable_setup_done(pgd_t
*base
)
391 (*pv_mmu_ops
.pagetable_setup_done
)(base
);
395 static inline void startup_ipi_hook(int phys_apicid
, unsigned long start_eip
,
396 unsigned long start_esp
)
398 PVOP_VCALL3(pv_apic_ops
.startup_ipi_hook
,
399 phys_apicid
, start_eip
, start_esp
);
403 static inline void paravirt_activate_mm(struct mm_struct
*prev
,
404 struct mm_struct
*next
)
406 PVOP_VCALL2(pv_mmu_ops
.activate_mm
, prev
, next
);
409 static inline void arch_dup_mmap(struct mm_struct
*oldmm
,
410 struct mm_struct
*mm
)
412 PVOP_VCALL2(pv_mmu_ops
.dup_mmap
, oldmm
, mm
);
415 static inline void arch_exit_mmap(struct mm_struct
*mm
)
417 PVOP_VCALL1(pv_mmu_ops
.exit_mmap
, mm
);
420 static inline void __flush_tlb(void)
422 PVOP_VCALL0(pv_mmu_ops
.flush_tlb_user
);
424 static inline void __flush_tlb_global(void)
426 PVOP_VCALL0(pv_mmu_ops
.flush_tlb_kernel
);
428 static inline void __flush_tlb_single(unsigned long addr
)
430 PVOP_VCALL1(pv_mmu_ops
.flush_tlb_single
, addr
);
433 static inline void flush_tlb_others(const struct cpumask
*cpumask
,
434 struct mm_struct
*mm
,
437 PVOP_VCALL3(pv_mmu_ops
.flush_tlb_others
, cpumask
, mm
, va
);
440 static inline int paravirt_pgd_alloc(struct mm_struct
*mm
)
442 return PVOP_CALL1(int, pv_mmu_ops
.pgd_alloc
, mm
);
445 static inline void paravirt_pgd_free(struct mm_struct
*mm
, pgd_t
*pgd
)
447 PVOP_VCALL2(pv_mmu_ops
.pgd_free
, mm
, pgd
);
450 static inline void paravirt_alloc_pte(struct mm_struct
*mm
, unsigned long pfn
)
452 PVOP_VCALL2(pv_mmu_ops
.alloc_pte
, mm
, pfn
);
454 static inline void paravirt_release_pte(unsigned long pfn
)
456 PVOP_VCALL1(pv_mmu_ops
.release_pte
, pfn
);
459 static inline void paravirt_alloc_pmd(struct mm_struct
*mm
, unsigned long pfn
)
461 PVOP_VCALL2(pv_mmu_ops
.alloc_pmd
, mm
, pfn
);
464 static inline void paravirt_alloc_pmd_clone(unsigned long pfn
, unsigned long clonepfn
,
465 unsigned long start
, unsigned long count
)
467 PVOP_VCALL4(pv_mmu_ops
.alloc_pmd_clone
, pfn
, clonepfn
, start
, count
);
469 static inline void paravirt_release_pmd(unsigned long pfn
)
471 PVOP_VCALL1(pv_mmu_ops
.release_pmd
, pfn
);
474 static inline void paravirt_alloc_pud(struct mm_struct
*mm
, unsigned long pfn
)
476 PVOP_VCALL2(pv_mmu_ops
.alloc_pud
, mm
, pfn
);
478 static inline void paravirt_release_pud(unsigned long pfn
)
480 PVOP_VCALL1(pv_mmu_ops
.release_pud
, pfn
);
483 #ifdef CONFIG_HIGHPTE
484 static inline void *kmap_atomic_pte(struct page
*page
, enum km_type type
)
487 ret
= PVOP_CALL2(unsigned long, pv_mmu_ops
.kmap_atomic_pte
, page
, type
);
492 static inline void pte_update(struct mm_struct
*mm
, unsigned long addr
,
495 PVOP_VCALL3(pv_mmu_ops
.pte_update
, mm
, addr
, ptep
);
498 static inline void pte_update_defer(struct mm_struct
*mm
, unsigned long addr
,
501 PVOP_VCALL3(pv_mmu_ops
.pte_update_defer
, mm
, addr
, ptep
);
504 static inline pte_t
__pte(pteval_t val
)
508 if (sizeof(pteval_t
) > sizeof(long))
509 ret
= PVOP_CALLEE2(pteval_t
,
511 val
, (u64
)val
>> 32);
513 ret
= PVOP_CALLEE1(pteval_t
,
517 return (pte_t
) { .pte
= ret
};
520 static inline pteval_t
pte_val(pte_t pte
)
524 if (sizeof(pteval_t
) > sizeof(long))
525 ret
= PVOP_CALLEE2(pteval_t
, pv_mmu_ops
.pte_val
,
526 pte
.pte
, (u64
)pte
.pte
>> 32);
528 ret
= PVOP_CALLEE1(pteval_t
, pv_mmu_ops
.pte_val
,
534 static inline pgd_t
__pgd(pgdval_t val
)
538 if (sizeof(pgdval_t
) > sizeof(long))
539 ret
= PVOP_CALLEE2(pgdval_t
, pv_mmu_ops
.make_pgd
,
540 val
, (u64
)val
>> 32);
542 ret
= PVOP_CALLEE1(pgdval_t
, pv_mmu_ops
.make_pgd
,
545 return (pgd_t
) { ret
};
548 static inline pgdval_t
pgd_val(pgd_t pgd
)
552 if (sizeof(pgdval_t
) > sizeof(long))
553 ret
= PVOP_CALLEE2(pgdval_t
, pv_mmu_ops
.pgd_val
,
554 pgd
.pgd
, (u64
)pgd
.pgd
>> 32);
556 ret
= PVOP_CALLEE1(pgdval_t
, pv_mmu_ops
.pgd_val
,
562 #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
563 static inline pte_t
ptep_modify_prot_start(struct mm_struct
*mm
, unsigned long addr
,
568 ret
= PVOP_CALL3(pteval_t
, pv_mmu_ops
.ptep_modify_prot_start
,
571 return (pte_t
) { .pte
= ret
};
574 static inline void ptep_modify_prot_commit(struct mm_struct
*mm
, unsigned long addr
,
575 pte_t
*ptep
, pte_t pte
)
577 if (sizeof(pteval_t
) > sizeof(long))
579 pv_mmu_ops
.ptep_modify_prot_commit(mm
, addr
, ptep
, pte
);
581 PVOP_VCALL4(pv_mmu_ops
.ptep_modify_prot_commit
,
582 mm
, addr
, ptep
, pte
.pte
);
585 static inline void set_pte(pte_t
*ptep
, pte_t pte
)
587 if (sizeof(pteval_t
) > sizeof(long))
588 PVOP_VCALL3(pv_mmu_ops
.set_pte
, ptep
,
589 pte
.pte
, (u64
)pte
.pte
>> 32);
591 PVOP_VCALL2(pv_mmu_ops
.set_pte
, ptep
,
595 static inline void set_pte_at(struct mm_struct
*mm
, unsigned long addr
,
596 pte_t
*ptep
, pte_t pte
)
598 if (sizeof(pteval_t
) > sizeof(long))
600 pv_mmu_ops
.set_pte_at(mm
, addr
, ptep
, pte
);
602 PVOP_VCALL4(pv_mmu_ops
.set_pte_at
, mm
, addr
, ptep
, pte
.pte
);
605 static inline void set_pmd(pmd_t
*pmdp
, pmd_t pmd
)
607 pmdval_t val
= native_pmd_val(pmd
);
609 if (sizeof(pmdval_t
) > sizeof(long))
610 PVOP_VCALL3(pv_mmu_ops
.set_pmd
, pmdp
, val
, (u64
)val
>> 32);
612 PVOP_VCALL2(pv_mmu_ops
.set_pmd
, pmdp
, val
);
615 #if PAGETABLE_LEVELS >= 3
616 static inline pmd_t
__pmd(pmdval_t val
)
620 if (sizeof(pmdval_t
) > sizeof(long))
621 ret
= PVOP_CALLEE2(pmdval_t
, pv_mmu_ops
.make_pmd
,
622 val
, (u64
)val
>> 32);
624 ret
= PVOP_CALLEE1(pmdval_t
, pv_mmu_ops
.make_pmd
,
627 return (pmd_t
) { ret
};
630 static inline pmdval_t
pmd_val(pmd_t pmd
)
634 if (sizeof(pmdval_t
) > sizeof(long))
635 ret
= PVOP_CALLEE2(pmdval_t
, pv_mmu_ops
.pmd_val
,
636 pmd
.pmd
, (u64
)pmd
.pmd
>> 32);
638 ret
= PVOP_CALLEE1(pmdval_t
, pv_mmu_ops
.pmd_val
,
644 static inline void set_pud(pud_t
*pudp
, pud_t pud
)
646 pudval_t val
= native_pud_val(pud
);
648 if (sizeof(pudval_t
) > sizeof(long))
649 PVOP_VCALL3(pv_mmu_ops
.set_pud
, pudp
,
650 val
, (u64
)val
>> 32);
652 PVOP_VCALL2(pv_mmu_ops
.set_pud
, pudp
,
655 #if PAGETABLE_LEVELS == 4
656 static inline pud_t
__pud(pudval_t val
)
660 if (sizeof(pudval_t
) > sizeof(long))
661 ret
= PVOP_CALLEE2(pudval_t
, pv_mmu_ops
.make_pud
,
662 val
, (u64
)val
>> 32);
664 ret
= PVOP_CALLEE1(pudval_t
, pv_mmu_ops
.make_pud
,
667 return (pud_t
) { ret
};
670 static inline pudval_t
pud_val(pud_t pud
)
674 if (sizeof(pudval_t
) > sizeof(long))
675 ret
= PVOP_CALLEE2(pudval_t
, pv_mmu_ops
.pud_val
,
676 pud
.pud
, (u64
)pud
.pud
>> 32);
678 ret
= PVOP_CALLEE1(pudval_t
, pv_mmu_ops
.pud_val
,
684 static inline void set_pgd(pgd_t
*pgdp
, pgd_t pgd
)
686 pgdval_t val
= native_pgd_val(pgd
);
688 if (sizeof(pgdval_t
) > sizeof(long))
689 PVOP_VCALL3(pv_mmu_ops
.set_pgd
, pgdp
,
690 val
, (u64
)val
>> 32);
692 PVOP_VCALL2(pv_mmu_ops
.set_pgd
, pgdp
,
696 static inline void pgd_clear(pgd_t
*pgdp
)
698 set_pgd(pgdp
, __pgd(0));
701 static inline void pud_clear(pud_t
*pudp
)
703 set_pud(pudp
, __pud(0));
706 #endif /* PAGETABLE_LEVELS == 4 */
708 #endif /* PAGETABLE_LEVELS >= 3 */
710 #ifdef CONFIG_X86_PAE
711 /* Special-case pte-setting operations for PAE, which can't update a
712 64-bit pte atomically */
713 static inline void set_pte_atomic(pte_t
*ptep
, pte_t pte
)
715 PVOP_VCALL3(pv_mmu_ops
.set_pte_atomic
, ptep
,
716 pte
.pte
, pte
.pte
>> 32);
719 static inline void pte_clear(struct mm_struct
*mm
, unsigned long addr
,
722 PVOP_VCALL3(pv_mmu_ops
.pte_clear
, mm
, addr
, ptep
);
725 static inline void pmd_clear(pmd_t
*pmdp
)
727 PVOP_VCALL1(pv_mmu_ops
.pmd_clear
, pmdp
);
729 #else /* !CONFIG_X86_PAE */
730 static inline void set_pte_atomic(pte_t
*ptep
, pte_t pte
)
735 static inline void pte_clear(struct mm_struct
*mm
, unsigned long addr
,
738 set_pte_at(mm
, addr
, ptep
, __pte(0));
741 static inline void pmd_clear(pmd_t
*pmdp
)
743 set_pmd(pmdp
, __pmd(0));
745 #endif /* CONFIG_X86_PAE */
747 #define __HAVE_ARCH_START_CONTEXT_SWITCH
748 static inline void arch_start_context_switch(struct task_struct
*prev
)
750 PVOP_VCALL1(pv_cpu_ops
.start_context_switch
, prev
);
753 static inline void arch_end_context_switch(struct task_struct
*next
)
755 PVOP_VCALL1(pv_cpu_ops
.end_context_switch
, next
);
758 #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
759 static inline void arch_enter_lazy_mmu_mode(void)
761 PVOP_VCALL0(pv_mmu_ops
.lazy_mode
.enter
);
764 static inline void arch_leave_lazy_mmu_mode(void)
766 PVOP_VCALL0(pv_mmu_ops
.lazy_mode
.leave
);
769 void arch_flush_lazy_mmu_mode(void);
771 static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx
,
772 phys_addr_t phys
, pgprot_t flags
)
774 pv_mmu_ops
.set_fixmap(idx
, phys
, flags
);
777 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
779 static inline int __raw_spin_is_locked(struct raw_spinlock
*lock
)
781 return PVOP_CALL1(int, pv_lock_ops
.spin_is_locked
, lock
);
784 static inline int __raw_spin_is_contended(struct raw_spinlock
*lock
)
786 return PVOP_CALL1(int, pv_lock_ops
.spin_is_contended
, lock
);
788 #define __raw_spin_is_contended __raw_spin_is_contended
790 static __always_inline
void __raw_spin_lock(struct raw_spinlock
*lock
)
792 PVOP_VCALL1(pv_lock_ops
.spin_lock
, lock
);
795 static __always_inline
void __raw_spin_lock_flags(struct raw_spinlock
*lock
,
798 PVOP_VCALL2(pv_lock_ops
.spin_lock_flags
, lock
, flags
);
801 static __always_inline
int __raw_spin_trylock(struct raw_spinlock
*lock
)
803 return PVOP_CALL1(int, pv_lock_ops
.spin_trylock
, lock
);
806 static __always_inline
void __raw_spin_unlock(struct raw_spinlock
*lock
)
808 PVOP_VCALL1(pv_lock_ops
.spin_unlock
, lock
);
814 #define PV_SAVE_REGS "pushl %ecx; pushl %edx;"
815 #define PV_RESTORE_REGS "popl %edx; popl %ecx;"
817 /* save and restore all caller-save registers, except return value */
818 #define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
819 #define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
821 #define PV_FLAGS_ARG "0"
822 #define PV_EXTRA_CLOBBERS
823 #define PV_VEXTRA_CLOBBERS
825 /* save and restore all caller-save registers, except return value */
826 #define PV_SAVE_ALL_CALLER_REGS \
835 #define PV_RESTORE_ALL_CALLER_REGS \
845 /* We save some registers, but all of them, that's too much. We clobber all
846 * caller saved registers but the argument parameter */
847 #define PV_SAVE_REGS "pushq %%rdi;"
848 #define PV_RESTORE_REGS "popq %%rdi;"
849 #define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi"
850 #define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi"
851 #define PV_FLAGS_ARG "D"
855 * Generate a thunk around a function which saves all caller-save
856 * registers except for the return value. This allows C functions to
857 * be called from assembler code where fewer than normal registers are
858 * available. It may also help code generation around calls from C
859 * code if the common case doesn't use many registers.
861 * When a callee is wrapped in a thunk, the caller can assume that all
862 * arg regs and all scratch registers are preserved across the
863 * call. The return value in rax/eax will not be saved, even for void
866 #define PV_CALLEE_SAVE_REGS_THUNK(func) \
867 extern typeof(func) __raw_callee_save_##func; \
868 static void *__##func##__ __used = func; \
870 asm(".pushsection .text;" \
871 "__raw_callee_save_" #func ": " \
872 PV_SAVE_ALL_CALLER_REGS \
874 PV_RESTORE_ALL_CALLER_REGS \
878 /* Get a reference to a callee-save function */
879 #define PV_CALLEE_SAVE(func) \
880 ((struct paravirt_callee_save) { __raw_callee_save_##func })
882 /* Promise that "func" already uses the right calling convention */
883 #define __PV_IS_CALLEE_SAVE(func) \
884 ((struct paravirt_callee_save) { func })
886 static inline unsigned long __raw_local_save_flags(void)
890 asm volatile(paravirt_alt(PARAVIRT_CALL
)
892 : paravirt_type(pv_irq_ops
.save_fl
),
893 paravirt_clobber(CLBR_EAX
)
898 static inline void raw_local_irq_restore(unsigned long f
)
900 asm volatile(paravirt_alt(PARAVIRT_CALL
)
903 paravirt_type(pv_irq_ops
.restore_fl
),
904 paravirt_clobber(CLBR_EAX
)
908 static inline void raw_local_irq_disable(void)
910 asm volatile(paravirt_alt(PARAVIRT_CALL
)
912 : paravirt_type(pv_irq_ops
.irq_disable
),
913 paravirt_clobber(CLBR_EAX
)
914 : "memory", "eax", "cc");
917 static inline void raw_local_irq_enable(void)
919 asm volatile(paravirt_alt(PARAVIRT_CALL
)
921 : paravirt_type(pv_irq_ops
.irq_enable
),
922 paravirt_clobber(CLBR_EAX
)
923 : "memory", "eax", "cc");
926 static inline unsigned long __raw_local_irq_save(void)
930 f
= __raw_local_save_flags();
931 raw_local_irq_disable();
936 /* Make sure as little as possible of this mess escapes. */
951 #else /* __ASSEMBLY__ */
953 #define _PVSITE(ptype, clobbers, ops, word, algn) \
957 .pushsection .parainstructions,"a"; \
966 #define COND_PUSH(set, mask, reg) \
967 .if ((~(set)) & mask); push %reg; .endif
968 #define COND_POP(set, mask, reg) \
969 .if ((~(set)) & mask); pop %reg; .endif
973 #define PV_SAVE_REGS(set) \
974 COND_PUSH(set, CLBR_RAX, rax); \
975 COND_PUSH(set, CLBR_RCX, rcx); \
976 COND_PUSH(set, CLBR_RDX, rdx); \
977 COND_PUSH(set, CLBR_RSI, rsi); \
978 COND_PUSH(set, CLBR_RDI, rdi); \
979 COND_PUSH(set, CLBR_R8, r8); \
980 COND_PUSH(set, CLBR_R9, r9); \
981 COND_PUSH(set, CLBR_R10, r10); \
982 COND_PUSH(set, CLBR_R11, r11)
983 #define PV_RESTORE_REGS(set) \
984 COND_POP(set, CLBR_R11, r11); \
985 COND_POP(set, CLBR_R10, r10); \
986 COND_POP(set, CLBR_R9, r9); \
987 COND_POP(set, CLBR_R8, r8); \
988 COND_POP(set, CLBR_RDI, rdi); \
989 COND_POP(set, CLBR_RSI, rsi); \
990 COND_POP(set, CLBR_RDX, rdx); \
991 COND_POP(set, CLBR_RCX, rcx); \
992 COND_POP(set, CLBR_RAX, rax)
994 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
995 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
996 #define PARA_INDIRECT(addr) *addr(%rip)
998 #define PV_SAVE_REGS(set) \
999 COND_PUSH(set, CLBR_EAX, eax); \
1000 COND_PUSH(set, CLBR_EDI, edi); \
1001 COND_PUSH(set, CLBR_ECX, ecx); \
1002 COND_PUSH(set, CLBR_EDX, edx)
1003 #define PV_RESTORE_REGS(set) \
1004 COND_POP(set, CLBR_EDX, edx); \
1005 COND_POP(set, CLBR_ECX, ecx); \
1006 COND_POP(set, CLBR_EDI, edi); \
1007 COND_POP(set, CLBR_EAX, eax)
1009 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
1010 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
1011 #define PARA_INDIRECT(addr) *%cs:addr
1014 #define INTERRUPT_RETURN \
1015 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
1016 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
1018 #define DISABLE_INTERRUPTS(clobbers) \
1019 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
1020 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
1021 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
1022 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
1024 #define ENABLE_INTERRUPTS(clobbers) \
1025 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
1026 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
1027 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
1028 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
1030 #define USERGS_SYSRET32 \
1031 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32), \
1033 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32))
1035 #ifdef CONFIG_X86_32
1036 #define GET_CR0_INTO_EAX \
1037 push %ecx; push %edx; \
1038 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
1041 #define ENABLE_INTERRUPTS_SYSEXIT \
1042 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1044 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1047 #else /* !CONFIG_X86_32 */
1050 * If swapgs is used while the userspace stack is still current,
1051 * there's no way to call a pvop. The PV replacement *must* be
1052 * inlined, or the swapgs instruction must be trapped and emulated.
1054 #define SWAPGS_UNSAFE_STACK \
1055 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
1059 * Note: swapgs is very special, and in practise is either going to be
1060 * implemented with a single "swapgs" instruction or something very
1061 * special. Either way, we don't need to save any registers for
1065 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
1066 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
1069 #define GET_CR2_INTO_RCX \
1070 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2); \
1074 #define PARAVIRT_ADJUST_EXCEPTION_FRAME \
1075 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \
1077 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame))
1079 #define USERGS_SYSRET64 \
1080 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
1082 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
1084 #define ENABLE_INTERRUPTS_SYSEXIT32 \
1085 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1087 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1088 #endif /* CONFIG_X86_32 */
1090 #endif /* __ASSEMBLY__ */
1091 #endif /* CONFIG_PARAVIRT */
1092 #endif /* _ASM_X86_PARAVIRT_H */