1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2ac5672f8SJeremy Fitzhardinge #ifndef _ASM_X86_PARAVIRT_TYPES_H 3ac5672f8SJeremy Fitzhardinge #define _ASM_X86_PARAVIRT_TYPES_H 4ac5672f8SJeremy Fitzhardinge 5ac5672f8SJeremy Fitzhardinge /* Bitmask of what can be clobbered: usually at least eax. */ 6ac5672f8SJeremy Fitzhardinge #define CLBR_NONE 0 7ac5672f8SJeremy Fitzhardinge #define CLBR_EAX (1 << 0) 8ac5672f8SJeremy Fitzhardinge #define CLBR_ECX (1 << 1) 9ac5672f8SJeremy Fitzhardinge #define CLBR_EDX (1 << 2) 10ac5672f8SJeremy Fitzhardinge #define CLBR_EDI (1 << 3) 11ac5672f8SJeremy Fitzhardinge 12ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_32 13ac5672f8SJeremy Fitzhardinge /* CLBR_ANY should match all regs platform has. For i386, that's just it */ 14ac5672f8SJeremy Fitzhardinge #define CLBR_ANY ((1 << 4) - 1) 15ac5672f8SJeremy Fitzhardinge 16ac5672f8SJeremy Fitzhardinge #define CLBR_ARG_REGS (CLBR_EAX | CLBR_EDX | CLBR_ECX) 17ac5672f8SJeremy Fitzhardinge #define CLBR_RET_REG (CLBR_EAX | CLBR_EDX) 18ac5672f8SJeremy Fitzhardinge #define CLBR_SCRATCH (0) 19ac5672f8SJeremy Fitzhardinge #else 20ac5672f8SJeremy Fitzhardinge #define CLBR_RAX CLBR_EAX 21ac5672f8SJeremy Fitzhardinge #define CLBR_RCX CLBR_ECX 22ac5672f8SJeremy Fitzhardinge #define CLBR_RDX CLBR_EDX 23ac5672f8SJeremy Fitzhardinge #define CLBR_RDI CLBR_EDI 24ac5672f8SJeremy Fitzhardinge #define CLBR_RSI (1 << 4) 25ac5672f8SJeremy Fitzhardinge #define CLBR_R8 (1 << 5) 26ac5672f8SJeremy Fitzhardinge #define CLBR_R9 (1 << 6) 27ac5672f8SJeremy Fitzhardinge #define CLBR_R10 (1 << 7) 28ac5672f8SJeremy Fitzhardinge #define CLBR_R11 (1 << 8) 29ac5672f8SJeremy Fitzhardinge 30ac5672f8SJeremy Fitzhardinge #define CLBR_ANY ((1 << 9) - 1) 31ac5672f8SJeremy Fitzhardinge 32ac5672f8SJeremy Fitzhardinge #define CLBR_ARG_REGS (CLBR_RDI | CLBR_RSI | CLBR_RDX | \ 33ac5672f8SJeremy Fitzhardinge CLBR_RCX | CLBR_R8 | CLBR_R9) 34ac5672f8SJeremy Fitzhardinge #define CLBR_RET_REG (CLBR_RAX) 35ac5672f8SJeremy Fitzhardinge #define CLBR_SCRATCH (CLBR_R10 | CLBR_R11) 36ac5672f8SJeremy Fitzhardinge 37ac5672f8SJeremy Fitzhardinge #endif /* X86_64 */ 38ac5672f8SJeremy Fitzhardinge 39ac5672f8SJeremy Fitzhardinge #define CLBR_CALLEE_SAVE ((CLBR_ARG_REGS | CLBR_SCRATCH) & ~CLBR_RET_REG) 40ac5672f8SJeremy Fitzhardinge 41ac5672f8SJeremy Fitzhardinge #ifndef __ASSEMBLY__ 42ac5672f8SJeremy Fitzhardinge 43ac5672f8SJeremy Fitzhardinge #include <asm/desc_defs.h> 44ac5672f8SJeremy Fitzhardinge #include <asm/kmap_types.h> 45318f5a2aSAndy Lutomirski #include <asm/pgtable_types.h> 463010a066SPeter Zijlstra #include <asm/nospec-branch.h> 47ac5672f8SJeremy Fitzhardinge 48ac5672f8SJeremy Fitzhardinge struct page; 49ac5672f8SJeremy Fitzhardinge struct thread_struct; 50ac5672f8SJeremy Fitzhardinge struct desc_ptr; 51ac5672f8SJeremy Fitzhardinge struct tss_struct; 52ac5672f8SJeremy Fitzhardinge struct mm_struct; 53ac5672f8SJeremy Fitzhardinge struct desc_struct; 54ac5672f8SJeremy Fitzhardinge struct task_struct; 55ac5672f8SJeremy Fitzhardinge struct cpumask; 56a2055abeSAndy Lutomirski struct flush_tlb_info; 5748a8b97cSPeter Zijlstra struct mmu_gather; 580cbe3e26SAneesh Kumar K.V struct vm_area_struct; 59ac5672f8SJeremy Fitzhardinge 60ac5672f8SJeremy Fitzhardinge /* 61ac5672f8SJeremy Fitzhardinge * Wrapper type for pointers to code which uses the non-standard 62ac5672f8SJeremy Fitzhardinge * calling convention. See PV_CALL_SAVE_REGS_THUNK below. 63ac5672f8SJeremy Fitzhardinge */ 64ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save { 65ac5672f8SJeremy Fitzhardinge void *func; 66ac5672f8SJeremy Fitzhardinge }; 67ac5672f8SJeremy Fitzhardinge 68ac5672f8SJeremy Fitzhardinge /* general info */ 69ac5672f8SJeremy Fitzhardinge struct pv_info { 7040181646SJuergen Gross #ifdef CONFIG_PARAVIRT_XXL 71ac5672f8SJeremy Fitzhardinge unsigned int kernel_rpl; 72ac5672f8SJeremy Fitzhardinge int shared_kernel_pmd; 73318f5a2aSAndy Lutomirski 74318f5a2aSAndy Lutomirski #ifdef CONFIG_X86_64 75318f5a2aSAndy Lutomirski u16 extra_user_64bit_cs; /* __USER_CS if none */ 76318f5a2aSAndy Lutomirski #endif 7740181646SJuergen Gross #endif 78318f5a2aSAndy Lutomirski 79ac5672f8SJeremy Fitzhardinge const char *name; 80ac5672f8SJeremy Fitzhardinge }; 81ac5672f8SJeremy Fitzhardinge 82ac5672f8SJeremy Fitzhardinge struct pv_init_ops { 83ac5672f8SJeremy Fitzhardinge /* 84ac5672f8SJeremy Fitzhardinge * Patch may replace one of the defined code sequences with 85ac5672f8SJeremy Fitzhardinge * arbitrary code, subject to the same register constraints. 86ac5672f8SJeremy Fitzhardinge * This generally means the code is not free to clobber any 87ac5672f8SJeremy Fitzhardinge * registers other than EAX. The patch function should return 88ac5672f8SJeremy Fitzhardinge * the number of bytes of code generated, as we nop pad the 89ac5672f8SJeremy Fitzhardinge * rest in generic code. 90ac5672f8SJeremy Fitzhardinge */ 911fc654cfSIngo Molnar unsigned (*patch)(u8 type, void *insn_buff, 92ac5672f8SJeremy Fitzhardinge unsigned long addr, unsigned len); 938acdf505SKees Cook } __no_randomize_layout; 94ac5672f8SJeremy Fitzhardinge 95fdc0269eSJuergen Gross #ifdef CONFIG_PARAVIRT_XXL 96ac5672f8SJeremy Fitzhardinge struct pv_lazy_ops { 97ac5672f8SJeremy Fitzhardinge /* Set deferred update mode, used for batching operations. */ 98ac5672f8SJeremy Fitzhardinge void (*enter)(void); 99ac5672f8SJeremy Fitzhardinge void (*leave)(void); 100511ba86eSBoris Ostrovsky void (*flush)(void); 1018acdf505SKees Cook } __no_randomize_layout; 102fdc0269eSJuergen Gross #endif 103ac5672f8SJeremy Fitzhardinge 104ac5672f8SJeremy Fitzhardinge struct pv_time_ops { 105ac5672f8SJeremy Fitzhardinge unsigned long long (*sched_clock)(void); 1063c404b57SGlauber Costa unsigned long long (*steal_clock)(int cpu); 1078acdf505SKees Cook } __no_randomize_layout; 108ac5672f8SJeremy Fitzhardinge 109ac5672f8SJeremy Fitzhardinge struct pv_cpu_ops { 110ac5672f8SJeremy Fitzhardinge /* hooks for various privileged instructions */ 1119bad5658SJuergen Gross void (*io_delay)(void); 1129bad5658SJuergen Gross 1139bad5658SJuergen Gross #ifdef CONFIG_PARAVIRT_XXL 114ac5672f8SJeremy Fitzhardinge unsigned long (*get_debugreg)(int regno); 115ac5672f8SJeremy Fitzhardinge void (*set_debugreg)(int regno, unsigned long value); 116ac5672f8SJeremy Fitzhardinge 117ac5672f8SJeremy Fitzhardinge unsigned long (*read_cr0)(void); 118ac5672f8SJeremy Fitzhardinge void (*write_cr0)(unsigned long); 119ac5672f8SJeremy Fitzhardinge 120ac5672f8SJeremy Fitzhardinge void (*write_cr4)(unsigned long); 121ac5672f8SJeremy Fitzhardinge 122ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_64 123ac5672f8SJeremy Fitzhardinge unsigned long (*read_cr8)(void); 124ac5672f8SJeremy Fitzhardinge void (*write_cr8)(unsigned long); 125ac5672f8SJeremy Fitzhardinge #endif 126ac5672f8SJeremy Fitzhardinge 127ac5672f8SJeremy Fitzhardinge /* Segment descriptor handling */ 128ac5672f8SJeremy Fitzhardinge void (*load_tr_desc)(void); 129ac5672f8SJeremy Fitzhardinge void (*load_gdt)(const struct desc_ptr *); 130ac5672f8SJeremy Fitzhardinge void (*load_idt)(const struct desc_ptr *); 131ac5672f8SJeremy Fitzhardinge void (*set_ldt)(const void *desc, unsigned entries); 132ac5672f8SJeremy Fitzhardinge unsigned long (*store_tr)(void); 133ac5672f8SJeremy Fitzhardinge void (*load_tls)(struct thread_struct *t, unsigned int cpu); 134ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_64 135ac5672f8SJeremy Fitzhardinge void (*load_gs_index)(unsigned int idx); 136ac5672f8SJeremy Fitzhardinge #endif 137ac5672f8SJeremy Fitzhardinge void (*write_ldt_entry)(struct desc_struct *ldt, int entrynum, 138ac5672f8SJeremy Fitzhardinge const void *desc); 139ac5672f8SJeremy Fitzhardinge void (*write_gdt_entry)(struct desc_struct *, 140ac5672f8SJeremy Fitzhardinge int entrynum, const void *desc, int size); 141ac5672f8SJeremy Fitzhardinge void (*write_idt_entry)(gate_desc *, 142ac5672f8SJeremy Fitzhardinge int entrynum, const gate_desc *gate); 143ac5672f8SJeremy Fitzhardinge void (*alloc_ldt)(struct desc_struct *ldt, unsigned entries); 144ac5672f8SJeremy Fitzhardinge void (*free_ldt)(struct desc_struct *ldt, unsigned entries); 145ac5672f8SJeremy Fitzhardinge 146da51da18SAndy Lutomirski void (*load_sp0)(unsigned long sp0); 147ac5672f8SJeremy Fitzhardinge 148ac5672f8SJeremy Fitzhardinge void (*set_iopl_mask)(unsigned mask); 149ac5672f8SJeremy Fitzhardinge 150ac5672f8SJeremy Fitzhardinge void (*wbinvd)(void); 151ac5672f8SJeremy Fitzhardinge 152ac5672f8SJeremy Fitzhardinge /* cpuid emulation, mostly so that caps bits can be disabled */ 153ac5672f8SJeremy Fitzhardinge void (*cpuid)(unsigned int *eax, unsigned int *ebx, 154ac5672f8SJeremy Fitzhardinge unsigned int *ecx, unsigned int *edx); 155ac5672f8SJeremy Fitzhardinge 156dd2f4a00SAndy Lutomirski /* Unsafe MSR operations. These will warn or panic on failure. */ 157dd2f4a00SAndy Lutomirski u64 (*read_msr)(unsigned int msr); 158dd2f4a00SAndy Lutomirski void (*write_msr)(unsigned int msr, unsigned low, unsigned high); 159dd2f4a00SAndy Lutomirski 160dd2f4a00SAndy Lutomirski /* 161dd2f4a00SAndy Lutomirski * Safe MSR operations. 162dd2f4a00SAndy Lutomirski * read sets err to 0 or -EIO. write returns 0 or -EIO. 163dd2f4a00SAndy Lutomirski */ 164c2ee03b2SAndy Lutomirski u64 (*read_msr_safe)(unsigned int msr, int *err); 165c2ee03b2SAndy Lutomirski int (*write_msr_safe)(unsigned int msr, unsigned low, unsigned high); 166ac5672f8SJeremy Fitzhardinge 167ac5672f8SJeremy Fitzhardinge u64 (*read_pmc)(int counter); 168ac5672f8SJeremy Fitzhardinge 169ac5672f8SJeremy Fitzhardinge /* 170ac5672f8SJeremy Fitzhardinge * Switch to usermode gs and return to 64-bit usermode using 171ac5672f8SJeremy Fitzhardinge * sysret. Only used in 64-bit kernels to return to 64-bit 172ac5672f8SJeremy Fitzhardinge * processes. Usermode register state, including %rsp, must 173ac5672f8SJeremy Fitzhardinge * already be restored. 174ac5672f8SJeremy Fitzhardinge */ 175ac5672f8SJeremy Fitzhardinge void (*usergs_sysret64)(void); 176ac5672f8SJeremy Fitzhardinge 177ac5672f8SJeremy Fitzhardinge /* Normal iret. Jump to this with the standard iret stack 178ac5672f8SJeremy Fitzhardinge frame set up. */ 179ac5672f8SJeremy Fitzhardinge void (*iret)(void); 180ac5672f8SJeremy Fitzhardinge 181ac5672f8SJeremy Fitzhardinge void (*swapgs)(void); 182ac5672f8SJeremy Fitzhardinge 183ac5672f8SJeremy Fitzhardinge void (*start_context_switch)(struct task_struct *prev); 184ac5672f8SJeremy Fitzhardinge void (*end_context_switch)(struct task_struct *next); 1859bad5658SJuergen Gross #endif 1868acdf505SKees Cook } __no_randomize_layout; 187ac5672f8SJeremy Fitzhardinge 188ac5672f8SJeremy Fitzhardinge struct pv_irq_ops { 1896da63eb2SJuergen Gross #ifdef CONFIG_PARAVIRT_XXL 190ac5672f8SJeremy Fitzhardinge /* 191ac5672f8SJeremy Fitzhardinge * Get/set interrupt state. save_fl and restore_fl are only 192ac5672f8SJeremy Fitzhardinge * expected to use X86_EFLAGS_IF; all other bits 193ac5672f8SJeremy Fitzhardinge * returned from save_fl are undefined, and may be ignored by 194ac5672f8SJeremy Fitzhardinge * restore_fl. 195ac5672f8SJeremy Fitzhardinge * 196ac5672f8SJeremy Fitzhardinge * NOTE: These functions callers expect the callee to preserve 197ac5672f8SJeremy Fitzhardinge * more registers than the standard C calling convention. 198ac5672f8SJeremy Fitzhardinge */ 199ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save save_fl; 200ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save restore_fl; 201ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save irq_disable; 202ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save irq_enable; 203ac5672f8SJeremy Fitzhardinge 204ac5672f8SJeremy Fitzhardinge void (*safe_halt)(void); 205ac5672f8SJeremy Fitzhardinge void (*halt)(void); 2066da63eb2SJuergen Gross #endif 2078acdf505SKees Cook } __no_randomize_layout; 208ac5672f8SJeremy Fitzhardinge 209ac5672f8SJeremy Fitzhardinge struct pv_mmu_ops { 210ac5672f8SJeremy Fitzhardinge /* TLB operations */ 211ac5672f8SJeremy Fitzhardinge void (*flush_tlb_user)(void); 212ac5672f8SJeremy Fitzhardinge void (*flush_tlb_kernel)(void); 2131299ef1dSAndy Lutomirski void (*flush_tlb_one_user)(unsigned long addr); 214ac5672f8SJeremy Fitzhardinge void (*flush_tlb_others)(const struct cpumask *cpus, 215a2055abeSAndy Lutomirski const struct flush_tlb_info *info); 216ac5672f8SJeremy Fitzhardinge 21748a8b97cSPeter Zijlstra void (*tlb_remove_table)(struct mmu_gather *tlb, void *table); 21848a8b97cSPeter Zijlstra 219fdc0269eSJuergen Gross /* Hook for intercepting the destruction of an mm_struct. */ 220fdc0269eSJuergen Gross void (*exit_mmap)(struct mm_struct *mm); 221fdc0269eSJuergen Gross 222fdc0269eSJuergen Gross #ifdef CONFIG_PARAVIRT_XXL 22355aedddbSPeter Zijlstra struct paravirt_callee_save read_cr2; 224fdc0269eSJuergen Gross void (*write_cr2)(unsigned long); 225fdc0269eSJuergen Gross 226fdc0269eSJuergen Gross unsigned long (*read_cr3)(void); 227fdc0269eSJuergen Gross void (*write_cr3)(unsigned long); 228fdc0269eSJuergen Gross 229fdc0269eSJuergen Gross /* Hooks for intercepting the creation/use of an mm_struct. */ 230fdc0269eSJuergen Gross void (*activate_mm)(struct mm_struct *prev, 231fdc0269eSJuergen Gross struct mm_struct *next); 232fdc0269eSJuergen Gross void (*dup_mmap)(struct mm_struct *oldmm, 233fdc0269eSJuergen Gross struct mm_struct *mm); 234fdc0269eSJuergen Gross 235ac5672f8SJeremy Fitzhardinge /* Hooks for allocating and freeing a pagetable top-level */ 236ac5672f8SJeremy Fitzhardinge int (*pgd_alloc)(struct mm_struct *mm); 237ac5672f8SJeremy Fitzhardinge void (*pgd_free)(struct mm_struct *mm, pgd_t *pgd); 238ac5672f8SJeremy Fitzhardinge 239ac5672f8SJeremy Fitzhardinge /* 240ac5672f8SJeremy Fitzhardinge * Hooks for allocating/releasing pagetable pages when they're 241ac5672f8SJeremy Fitzhardinge * attached to a pagetable 242ac5672f8SJeremy Fitzhardinge */ 243ac5672f8SJeremy Fitzhardinge void (*alloc_pte)(struct mm_struct *mm, unsigned long pfn); 244ac5672f8SJeremy Fitzhardinge void (*alloc_pmd)(struct mm_struct *mm, unsigned long pfn); 245ac5672f8SJeremy Fitzhardinge void (*alloc_pud)(struct mm_struct *mm, unsigned long pfn); 246335437fbSKirill A. Shutemov void (*alloc_p4d)(struct mm_struct *mm, unsigned long pfn); 247ac5672f8SJeremy Fitzhardinge void (*release_pte)(unsigned long pfn); 248ac5672f8SJeremy Fitzhardinge void (*release_pmd)(unsigned long pfn); 249ac5672f8SJeremy Fitzhardinge void (*release_pud)(unsigned long pfn); 250335437fbSKirill A. Shutemov void (*release_p4d)(unsigned long pfn); 251ac5672f8SJeremy Fitzhardinge 252ac5672f8SJeremy Fitzhardinge /* Pagetable manipulation functions */ 253ac5672f8SJeremy Fitzhardinge void (*set_pte)(pte_t *ptep, pte_t pteval); 254ac5672f8SJeremy Fitzhardinge void (*set_pte_at)(struct mm_struct *mm, unsigned long addr, 255ac5672f8SJeremy Fitzhardinge pte_t *ptep, pte_t pteval); 256ac5672f8SJeremy Fitzhardinge void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval); 257ac5672f8SJeremy Fitzhardinge 2580cbe3e26SAneesh Kumar K.V pte_t (*ptep_modify_prot_start)(struct vm_area_struct *vma, unsigned long addr, 259ac5672f8SJeremy Fitzhardinge pte_t *ptep); 2600cbe3e26SAneesh Kumar K.V void (*ptep_modify_prot_commit)(struct vm_area_struct *vma, unsigned long addr, 261ac5672f8SJeremy Fitzhardinge pte_t *ptep, pte_t pte); 262ac5672f8SJeremy Fitzhardinge 263ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save pte_val; 264ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save make_pte; 265ac5672f8SJeremy Fitzhardinge 266ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save pgd_val; 267ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save make_pgd; 268ac5672f8SJeremy Fitzhardinge 26998233368SKirill A. Shutemov #if CONFIG_PGTABLE_LEVELS >= 3 270ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_PAE 271ac5672f8SJeremy Fitzhardinge void (*set_pte_atomic)(pte_t *ptep, pte_t pteval); 272ac5672f8SJeremy Fitzhardinge void (*pte_clear)(struct mm_struct *mm, unsigned long addr, 273ac5672f8SJeremy Fitzhardinge pte_t *ptep); 274ac5672f8SJeremy Fitzhardinge void (*pmd_clear)(pmd_t *pmdp); 275ac5672f8SJeremy Fitzhardinge 276ac5672f8SJeremy Fitzhardinge #endif /* CONFIG_X86_PAE */ 277ac5672f8SJeremy Fitzhardinge 278ac5672f8SJeremy Fitzhardinge void (*set_pud)(pud_t *pudp, pud_t pudval); 279ac5672f8SJeremy Fitzhardinge 280ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save pmd_val; 281ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save make_pmd; 282ac5672f8SJeremy Fitzhardinge 283f2a6a705SKirill A. Shutemov #if CONFIG_PGTABLE_LEVELS >= 4 284ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save pud_val; 285ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save make_pud; 286ac5672f8SJeremy Fitzhardinge 287f2a6a705SKirill A. Shutemov void (*set_p4d)(p4d_t *p4dp, p4d_t p4dval); 288f2a6a705SKirill A. Shutemov 289f2a6a705SKirill A. Shutemov #if CONFIG_PGTABLE_LEVELS >= 5 290335437fbSKirill A. Shutemov struct paravirt_callee_save p4d_val; 291335437fbSKirill A. Shutemov struct paravirt_callee_save make_p4d; 292335437fbSKirill A. Shutemov 293335437fbSKirill A. Shutemov void (*set_pgd)(pgd_t *pgdp, pgd_t pgdval); 294f2a6a705SKirill A. Shutemov #endif /* CONFIG_PGTABLE_LEVELS >= 5 */ 295f2a6a705SKirill A. Shutemov 296f2a6a705SKirill A. Shutemov #endif /* CONFIG_PGTABLE_LEVELS >= 4 */ 297f2a6a705SKirill A. Shutemov 29898233368SKirill A. Shutemov #endif /* CONFIG_PGTABLE_LEVELS >= 3 */ 299ac5672f8SJeremy Fitzhardinge 300ac5672f8SJeremy Fitzhardinge struct pv_lazy_ops lazy_mode; 301ac5672f8SJeremy Fitzhardinge 302ac5672f8SJeremy Fitzhardinge /* dom0 ops */ 303ac5672f8SJeremy Fitzhardinge 304ac5672f8SJeremy Fitzhardinge /* Sometimes the physical address is a pfn, and sometimes its 305ac5672f8SJeremy Fitzhardinge an mfn. We can tell which is which from the index. */ 306ac5672f8SJeremy Fitzhardinge void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx, 307ac5672f8SJeremy Fitzhardinge phys_addr_t phys, pgprot_t flags); 308fdc0269eSJuergen Gross #endif 3098acdf505SKees Cook } __no_randomize_layout; 310ac5672f8SJeremy Fitzhardinge 311445c8951SThomas Gleixner struct arch_spinlock; 312545ac138SJeremy Fitzhardinge #ifdef CONFIG_SMP 313545ac138SJeremy Fitzhardinge #include <asm/spinlock_types.h> 314545ac138SJeremy Fitzhardinge #endif 315545ac138SJeremy Fitzhardinge 316f233f7f1SPeter Zijlstra (Intel) struct qspinlock; 317f233f7f1SPeter Zijlstra (Intel) 318ac5672f8SJeremy Fitzhardinge struct pv_lock_ops { 319f233f7f1SPeter Zijlstra (Intel) void (*queued_spin_lock_slowpath)(struct qspinlock *lock, u32 val); 320f233f7f1SPeter Zijlstra (Intel) struct paravirt_callee_save queued_spin_unlock; 321f233f7f1SPeter Zijlstra (Intel) 322f233f7f1SPeter Zijlstra (Intel) void (*wait)(u8 *ptr, u8 val); 323f233f7f1SPeter Zijlstra (Intel) void (*kick)(int cpu); 324446f3dc8SPan Xinhui 3253cded417SPeter Zijlstra struct paravirt_callee_save vcpu_is_preempted; 3268acdf505SKees Cook } __no_randomize_layout; 327ac5672f8SJeremy Fitzhardinge 328ac5672f8SJeremy Fitzhardinge /* This contains all the paravirt structures: we get a convenient 329ac5672f8SJeremy Fitzhardinge * number for each function using the offset which we use to indicate 330ac5672f8SJeremy Fitzhardinge * what to patch. */ 331ac5672f8SJeremy Fitzhardinge struct paravirt_patch_template { 3325c83511bSJuergen Gross struct pv_init_ops init; 3335c83511bSJuergen Gross struct pv_time_ops time; 3345c83511bSJuergen Gross struct pv_cpu_ops cpu; 3355c83511bSJuergen Gross struct pv_irq_ops irq; 3365c83511bSJuergen Gross struct pv_mmu_ops mmu; 3375c83511bSJuergen Gross struct pv_lock_ops lock; 3388acdf505SKees Cook } __no_randomize_layout; 339ac5672f8SJeremy Fitzhardinge 340ac5672f8SJeremy Fitzhardinge extern struct pv_info pv_info; 3415c83511bSJuergen Gross extern struct paravirt_patch_template pv_ops; 342ac5672f8SJeremy Fitzhardinge 343ac5672f8SJeremy Fitzhardinge #define PARAVIRT_PATCH(x) \ 344ac5672f8SJeremy Fitzhardinge (offsetof(struct paravirt_patch_template, x) / sizeof(void *)) 345ac5672f8SJeremy Fitzhardinge 346ac5672f8SJeremy Fitzhardinge #define paravirt_type(op) \ 347ac5672f8SJeremy Fitzhardinge [paravirt_typenum] "i" (PARAVIRT_PATCH(op)), \ 3485c83511bSJuergen Gross [paravirt_opptr] "i" (&(pv_ops.op)) 349ac5672f8SJeremy Fitzhardinge #define paravirt_clobber(clobber) \ 350ac5672f8SJeremy Fitzhardinge [paravirt_clobber] "i" (clobber) 351ac5672f8SJeremy Fitzhardinge 352a4da3d86SIngo Molnar /* 353a4da3d86SIngo Molnar * Generate some code, and mark it as patchable by the 354a4da3d86SIngo Molnar * apply_paravirt() alternate instruction patcher. 355a4da3d86SIngo Molnar */ 356a4da3d86SIngo Molnar #define _paravirt_alt(insn_string, type, clobber) \ 357a4da3d86SIngo Molnar "771:\n\t" insn_string "\n" "772:\n" \ 358a4da3d86SIngo Molnar ".pushsection .parainstructions,\"a\"\n" \ 359a4da3d86SIngo Molnar _ASM_ALIGN "\n" \ 360a4da3d86SIngo Molnar _ASM_PTR " 771b\n" \ 361a4da3d86SIngo Molnar " .byte " type "\n" \ 362a4da3d86SIngo Molnar " .byte 772b-771b\n" \ 363a4da3d86SIngo Molnar " .short " clobber "\n" \ 364a4da3d86SIngo Molnar ".popsection\n" 365a4da3d86SIngo Molnar 366ac5672f8SJeremy Fitzhardinge /* Generate patchable code, with the default asm parameters. */ 367a4da3d86SIngo Molnar #define paravirt_alt(insn_string) \ 368a4da3d86SIngo Molnar _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]") 369ac5672f8SJeremy Fitzhardinge 370ac5672f8SJeremy Fitzhardinge /* Simple instruction patching code. */ 371824a2870SAndi Kleen #define NATIVE_LABEL(a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t" 372824a2870SAndi Kleen 3731fc654cfSIngo Molnar unsigned paravirt_patch_ident_64(void *insn_buff, unsigned len); 3741fc654cfSIngo Molnar unsigned paravirt_patch_default(u8 type, void *insn_buff, unsigned long addr, unsigned len); 3751fc654cfSIngo Molnar unsigned paravirt_patch_insns(void *insn_buff, unsigned len, const char *start, const char *end); 376ac5672f8SJeremy Fitzhardinge 3771fc654cfSIngo Molnar unsigned native_patch(u8 type, void *insn_buff, unsigned long addr, unsigned len); 378ac5672f8SJeremy Fitzhardinge 379ac5672f8SJeremy Fitzhardinge int paravirt_disable_iospace(void); 380ac5672f8SJeremy Fitzhardinge 381ac5672f8SJeremy Fitzhardinge /* 382a4da3d86SIngo Molnar * This generates an indirect call based on the operation type number. 383a4da3d86SIngo Molnar * The type number, computed in PARAVIRT_PATCH, is derived from the 384a4da3d86SIngo Molnar * offset into the paravirt_patch_template structure, and can therefore be 385a4da3d86SIngo Molnar * freely converted back into a structure offset. 386a4da3d86SIngo Molnar */ 387a4da3d86SIngo Molnar #define PARAVIRT_CALL \ 388a4da3d86SIngo Molnar ANNOTATE_RETPOLINE_SAFE \ 389a4da3d86SIngo Molnar "call *%c[paravirt_opptr];" 390a4da3d86SIngo Molnar 391a4da3d86SIngo Molnar /* 392ac5672f8SJeremy Fitzhardinge * These macros are intended to wrap calls through one of the paravirt 393ac5672f8SJeremy Fitzhardinge * ops structs, so that they can be later identified and patched at 394ac5672f8SJeremy Fitzhardinge * runtime. 395ac5672f8SJeremy Fitzhardinge * 396ac5672f8SJeremy Fitzhardinge * Normally, a call to a pv_op function is a simple indirect call: 397ac5672f8SJeremy Fitzhardinge * (pv_op_struct.operations)(args...). 398ac5672f8SJeremy Fitzhardinge * 399ac5672f8SJeremy Fitzhardinge * Unfortunately, this is a relatively slow operation for modern CPUs, 400ac5672f8SJeremy Fitzhardinge * because it cannot necessarily determine what the destination 401ac5672f8SJeremy Fitzhardinge * address is. In this case, the address is a runtime constant, so at 402ac5672f8SJeremy Fitzhardinge * the very least we can patch the call to e a simple direct call, or 403ac5672f8SJeremy Fitzhardinge * ideally, patch an inline implementation into the callsite. (Direct 404ac5672f8SJeremy Fitzhardinge * calls are essentially free, because the call and return addresses 405ac5672f8SJeremy Fitzhardinge * are completely predictable.) 406ac5672f8SJeremy Fitzhardinge * 407ac5672f8SJeremy Fitzhardinge * For i386, these macros rely on the standard gcc "regparm(3)" calling 408ac5672f8SJeremy Fitzhardinge * convention, in which the first three arguments are placed in %eax, 409ac5672f8SJeremy Fitzhardinge * %edx, %ecx (in that order), and the remaining arguments are placed 410ac5672f8SJeremy Fitzhardinge * on the stack. All caller-save registers (eax,edx,ecx) are expected 411ac5672f8SJeremy Fitzhardinge * to be modified (either clobbered or used for return values). 412ac5672f8SJeremy Fitzhardinge * X86_64, on the other hand, already specifies a register-based calling 413ac5672f8SJeremy Fitzhardinge * conventions, returning at %rax, with parameteres going on %rdi, %rsi, 414ac5672f8SJeremy Fitzhardinge * %rdx, and %rcx. Note that for this reason, x86_64 does not need any 415ac5672f8SJeremy Fitzhardinge * special handling for dealing with 4 arguments, unlike i386. 416ac5672f8SJeremy Fitzhardinge * However, x86_64 also have to clobber all caller saved registers, which 417ac5672f8SJeremy Fitzhardinge * unfortunately, are quite a bit (r8 - r11) 418ac5672f8SJeremy Fitzhardinge * 419ac5672f8SJeremy Fitzhardinge * The call instruction itself is marked by placing its start address 420ac5672f8SJeremy Fitzhardinge * and size into the .parainstructions section, so that 421ac5672f8SJeremy Fitzhardinge * apply_paravirt() in arch/i386/kernel/alternative.c can do the 422ac5672f8SJeremy Fitzhardinge * appropriate patching under the control of the backend pv_init_ops 423ac5672f8SJeremy Fitzhardinge * implementation. 424ac5672f8SJeremy Fitzhardinge * 425ac5672f8SJeremy Fitzhardinge * Unfortunately there's no way to get gcc to generate the args setup 426ac5672f8SJeremy Fitzhardinge * for the call, and then allow the call itself to be generated by an 427ac5672f8SJeremy Fitzhardinge * inline asm. Because of this, we must do the complete arg setup and 428ac5672f8SJeremy Fitzhardinge * return value handling from within these macros. This is fairly 429ac5672f8SJeremy Fitzhardinge * cumbersome. 430ac5672f8SJeremy Fitzhardinge * 431ac5672f8SJeremy Fitzhardinge * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments. 432ac5672f8SJeremy Fitzhardinge * It could be extended to more arguments, but there would be little 433ac5672f8SJeremy Fitzhardinge * to be gained from that. For each number of arguments, there are 434ac5672f8SJeremy Fitzhardinge * the two VCALL and CALL variants for void and non-void functions. 435ac5672f8SJeremy Fitzhardinge * 436ac5672f8SJeremy Fitzhardinge * When there is a return value, the invoker of the macro must specify 437ac5672f8SJeremy Fitzhardinge * the return type. The macro then uses sizeof() on that type to 438ac5672f8SJeremy Fitzhardinge * determine whether its a 32 or 64 bit value, and places the return 439ac5672f8SJeremy Fitzhardinge * in the right register(s) (just %eax for 32-bit, and %edx:%eax for 440ac5672f8SJeremy Fitzhardinge * 64-bit). For x86_64 machines, it just returns at %rax regardless of 441ac5672f8SJeremy Fitzhardinge * the return value size. 442ac5672f8SJeremy Fitzhardinge * 443ac5672f8SJeremy Fitzhardinge * 64-bit arguments are passed as a pair of adjacent 32-bit arguments 444ac5672f8SJeremy Fitzhardinge * i386 also passes 64-bit arguments as a pair of adjacent 32-bit arguments 445ac5672f8SJeremy Fitzhardinge * in low,high order 446ac5672f8SJeremy Fitzhardinge * 447ac5672f8SJeremy Fitzhardinge * Small structures are passed and returned in registers. The macro 448ac5672f8SJeremy Fitzhardinge * calling convention can't directly deal with this, so the wrapper 449ac5672f8SJeremy Fitzhardinge * functions must do this. 450ac5672f8SJeremy Fitzhardinge * 451ac5672f8SJeremy Fitzhardinge * These PVOP_* macros are only defined within this header. This 452ac5672f8SJeremy Fitzhardinge * means that all uses must be wrapped in inline functions. This also 453ac5672f8SJeremy Fitzhardinge * makes sure the incoming and outgoing types are always correct. 454ac5672f8SJeremy Fitzhardinge */ 455ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_32 456ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL_ARGS \ 457f5caf621SJosh Poimboeuf unsigned long __eax = __eax, __edx = __edx, __ecx = __ecx; 458f5caf621SJosh Poimboeuf 459ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARGS PVOP_VCALL_ARGS 460ac5672f8SJeremy Fitzhardinge 461ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG1(x) "a" ((unsigned long)(x)) 462ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG2(x) "d" ((unsigned long)(x)) 463ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG3(x) "c" ((unsigned long)(x)) 464ac5672f8SJeremy Fitzhardinge 465ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL_CLOBBERS "=a" (__eax), "=d" (__edx), \ 466ac5672f8SJeremy Fitzhardinge "=c" (__ecx) 467ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS 468ac5672f8SJeremy Fitzhardinge 469ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE_CLOBBERS "=a" (__eax), "=d" (__edx) 470ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE_CLOBBERS PVOP_VCALLEE_CLOBBERS 471ac5672f8SJeremy Fitzhardinge 472ac5672f8SJeremy Fitzhardinge #define EXTRA_CLOBBERS 473ac5672f8SJeremy Fitzhardinge #define VEXTRA_CLOBBERS 474ac5672f8SJeremy Fitzhardinge #else /* CONFIG_X86_64 */ 47571999d98SJeremy Fitzhardinge /* [re]ax isn't an arg, but the return val */ 476ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL_ARGS \ 477ac5672f8SJeremy Fitzhardinge unsigned long __edi = __edi, __esi = __esi, \ 478f5caf621SJosh Poimboeuf __edx = __edx, __ecx = __ecx, __eax = __eax; 479f5caf621SJosh Poimboeuf 48071999d98SJeremy Fitzhardinge #define PVOP_CALL_ARGS PVOP_VCALL_ARGS 481ac5672f8SJeremy Fitzhardinge 482ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG1(x) "D" ((unsigned long)(x)) 483ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG2(x) "S" ((unsigned long)(x)) 484ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG3(x) "d" ((unsigned long)(x)) 485ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG4(x) "c" ((unsigned long)(x)) 486ac5672f8SJeremy Fitzhardinge 487ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL_CLOBBERS "=D" (__edi), \ 488ac5672f8SJeremy Fitzhardinge "=S" (__esi), "=d" (__edx), \ 489ac5672f8SJeremy Fitzhardinge "=c" (__ecx) 490ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS, "=a" (__eax) 491ac5672f8SJeremy Fitzhardinge 49271999d98SJeremy Fitzhardinge /* void functions are still allowed [re]ax for scratch */ 493ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE_CLOBBERS "=a" (__eax) 494ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE_CLOBBERS PVOP_VCALLEE_CLOBBERS 495ac5672f8SJeremy Fitzhardinge 496ac5672f8SJeremy Fitzhardinge #define EXTRA_CLOBBERS , "r8", "r9", "r10", "r11" 497ac5672f8SJeremy Fitzhardinge #define VEXTRA_CLOBBERS , "rax", "r8", "r9", "r10", "r11" 498ac5672f8SJeremy Fitzhardinge #endif /* CONFIG_X86_32 */ 499ac5672f8SJeremy Fitzhardinge 500ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_PARAVIRT_DEBUG 5015c83511bSJuergen Gross #define PVOP_TEST_NULL(op) BUG_ON(pv_ops.op == NULL) 502ac5672f8SJeremy Fitzhardinge #else 5035c83511bSJuergen Gross #define PVOP_TEST_NULL(op) ((void)pv_ops.op) 504ac5672f8SJeremy Fitzhardinge #endif 505ac5672f8SJeremy Fitzhardinge 50611f254dbSPeter Zijlstra #define PVOP_RETMASK(rettype) \ 50711f254dbSPeter Zijlstra ({ unsigned long __mask = ~0UL; \ 50811f254dbSPeter Zijlstra switch (sizeof(rettype)) { \ 50911f254dbSPeter Zijlstra case 1: __mask = 0xffUL; break; \ 51011f254dbSPeter Zijlstra case 2: __mask = 0xffffUL; break; \ 51111f254dbSPeter Zijlstra case 4: __mask = 0xffffffffUL; break; \ 51211f254dbSPeter Zijlstra default: break; \ 51311f254dbSPeter Zijlstra } \ 51411f254dbSPeter Zijlstra __mask; \ 51511f254dbSPeter Zijlstra }) 51611f254dbSPeter Zijlstra 51711f254dbSPeter Zijlstra 518ac5672f8SJeremy Fitzhardinge #define ____PVOP_CALL(rettype, op, clbr, call_clbr, extra_clbr, \ 519ac5672f8SJeremy Fitzhardinge pre, post, ...) \ 520ac5672f8SJeremy Fitzhardinge ({ \ 521ac5672f8SJeremy Fitzhardinge rettype __ret; \ 522ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARGS; \ 523ac5672f8SJeremy Fitzhardinge PVOP_TEST_NULL(op); \ 524ac5672f8SJeremy Fitzhardinge /* This is 32-bit specific, but is okay in 64-bit */ \ 525ac5672f8SJeremy Fitzhardinge /* since this condition will never hold */ \ 526ac5672f8SJeremy Fitzhardinge if (sizeof(rettype) > sizeof(unsigned long)) { \ 527ac5672f8SJeremy Fitzhardinge asm volatile(pre \ 528a4da3d86SIngo Molnar paravirt_alt(PARAVIRT_CALL) \ 529ac5672f8SJeremy Fitzhardinge post \ 530f5caf621SJosh Poimboeuf : call_clbr, ASM_CALL_CONSTRAINT \ 531ac5672f8SJeremy Fitzhardinge : paravirt_type(op), \ 532ac5672f8SJeremy Fitzhardinge paravirt_clobber(clbr), \ 533ac5672f8SJeremy Fitzhardinge ##__VA_ARGS__ \ 534ac5672f8SJeremy Fitzhardinge : "memory", "cc" extra_clbr); \ 535ac5672f8SJeremy Fitzhardinge __ret = (rettype)((((u64)__edx) << 32) | __eax); \ 536ac5672f8SJeremy Fitzhardinge } else { \ 537ac5672f8SJeremy Fitzhardinge asm volatile(pre \ 538a4da3d86SIngo Molnar paravirt_alt(PARAVIRT_CALL) \ 539ac5672f8SJeremy Fitzhardinge post \ 540f5caf621SJosh Poimboeuf : call_clbr, ASM_CALL_CONSTRAINT \ 541ac5672f8SJeremy Fitzhardinge : paravirt_type(op), \ 542ac5672f8SJeremy Fitzhardinge paravirt_clobber(clbr), \ 543ac5672f8SJeremy Fitzhardinge ##__VA_ARGS__ \ 544ac5672f8SJeremy Fitzhardinge : "memory", "cc" extra_clbr); \ 54511f254dbSPeter Zijlstra __ret = (rettype)(__eax & PVOP_RETMASK(rettype)); \ 546ac5672f8SJeremy Fitzhardinge } \ 547ac5672f8SJeremy Fitzhardinge __ret; \ 548ac5672f8SJeremy Fitzhardinge }) 549ac5672f8SJeremy Fitzhardinge 550ac5672f8SJeremy Fitzhardinge #define __PVOP_CALL(rettype, op, pre, post, ...) \ 551ac5672f8SJeremy Fitzhardinge ____PVOP_CALL(rettype, op, CLBR_ANY, PVOP_CALL_CLOBBERS, \ 552ac5672f8SJeremy Fitzhardinge EXTRA_CLOBBERS, pre, post, ##__VA_ARGS__) 553ac5672f8SJeremy Fitzhardinge 554ac5672f8SJeremy Fitzhardinge #define __PVOP_CALLEESAVE(rettype, op, pre, post, ...) \ 555ac5672f8SJeremy Fitzhardinge ____PVOP_CALL(rettype, op.func, CLBR_RET_REG, \ 556ac5672f8SJeremy Fitzhardinge PVOP_CALLEE_CLOBBERS, , \ 557ac5672f8SJeremy Fitzhardinge pre, post, ##__VA_ARGS__) 558ac5672f8SJeremy Fitzhardinge 559ac5672f8SJeremy Fitzhardinge 560ac5672f8SJeremy Fitzhardinge #define ____PVOP_VCALL(op, clbr, call_clbr, extra_clbr, pre, post, ...) \ 561ac5672f8SJeremy Fitzhardinge ({ \ 562ac5672f8SJeremy Fitzhardinge PVOP_VCALL_ARGS; \ 563ac5672f8SJeremy Fitzhardinge PVOP_TEST_NULL(op); \ 564ac5672f8SJeremy Fitzhardinge asm volatile(pre \ 565a4da3d86SIngo Molnar paravirt_alt(PARAVIRT_CALL) \ 566ac5672f8SJeremy Fitzhardinge post \ 567f5caf621SJosh Poimboeuf : call_clbr, ASM_CALL_CONSTRAINT \ 568ac5672f8SJeremy Fitzhardinge : paravirt_type(op), \ 569ac5672f8SJeremy Fitzhardinge paravirt_clobber(clbr), \ 570ac5672f8SJeremy Fitzhardinge ##__VA_ARGS__ \ 571ac5672f8SJeremy Fitzhardinge : "memory", "cc" extra_clbr); \ 572ac5672f8SJeremy Fitzhardinge }) 573ac5672f8SJeremy Fitzhardinge 574ac5672f8SJeremy Fitzhardinge #define __PVOP_VCALL(op, pre, post, ...) \ 575ac5672f8SJeremy Fitzhardinge ____PVOP_VCALL(op, CLBR_ANY, PVOP_VCALL_CLOBBERS, \ 576ac5672f8SJeremy Fitzhardinge VEXTRA_CLOBBERS, \ 577ac5672f8SJeremy Fitzhardinge pre, post, ##__VA_ARGS__) 578ac5672f8SJeremy Fitzhardinge 57971999d98SJeremy Fitzhardinge #define __PVOP_VCALLEESAVE(op, pre, post, ...) \ 58071999d98SJeremy Fitzhardinge ____PVOP_VCALL(op.func, CLBR_RET_REG, \ 581ac5672f8SJeremy Fitzhardinge PVOP_VCALLEE_CLOBBERS, , \ 582ac5672f8SJeremy Fitzhardinge pre, post, ##__VA_ARGS__) 583ac5672f8SJeremy Fitzhardinge 584ac5672f8SJeremy Fitzhardinge 585ac5672f8SJeremy Fitzhardinge 586ac5672f8SJeremy Fitzhardinge #define PVOP_CALL0(rettype, op) \ 587ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "") 588ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL0(op) \ 589ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "") 590ac5672f8SJeremy Fitzhardinge 591ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE0(rettype, op) \ 592ac5672f8SJeremy Fitzhardinge __PVOP_CALLEESAVE(rettype, op, "", "") 593ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE0(op) \ 594ac5672f8SJeremy Fitzhardinge __PVOP_VCALLEESAVE(op, "", "") 595ac5672f8SJeremy Fitzhardinge 596ac5672f8SJeremy Fitzhardinge 597ac5672f8SJeremy Fitzhardinge #define PVOP_CALL1(rettype, op, arg1) \ 598ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "", PVOP_CALL_ARG1(arg1)) 599ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL1(op, arg1) \ 600ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "", PVOP_CALL_ARG1(arg1)) 601ac5672f8SJeremy Fitzhardinge 602ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE1(rettype, op, arg1) \ 603ac5672f8SJeremy Fitzhardinge __PVOP_CALLEESAVE(rettype, op, "", "", PVOP_CALL_ARG1(arg1)) 604ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE1(op, arg1) \ 605ac5672f8SJeremy Fitzhardinge __PVOP_VCALLEESAVE(op, "", "", PVOP_CALL_ARG1(arg1)) 606ac5672f8SJeremy Fitzhardinge 607ac5672f8SJeremy Fitzhardinge 608ac5672f8SJeremy Fitzhardinge #define PVOP_CALL2(rettype, op, arg1, arg2) \ 609ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "", PVOP_CALL_ARG1(arg1), \ 610ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2)) 611ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL2(op, arg1, arg2) \ 612ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "", PVOP_CALL_ARG1(arg1), \ 613ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2)) 614ac5672f8SJeremy Fitzhardinge 615ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE2(rettype, op, arg1, arg2) \ 616ac5672f8SJeremy Fitzhardinge __PVOP_CALLEESAVE(rettype, op, "", "", PVOP_CALL_ARG1(arg1), \ 617ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2)) 618ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE2(op, arg1, arg2) \ 619ac5672f8SJeremy Fitzhardinge __PVOP_VCALLEESAVE(op, "", "", PVOP_CALL_ARG1(arg1), \ 620ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2)) 621ac5672f8SJeremy Fitzhardinge 622ac5672f8SJeremy Fitzhardinge 623ac5672f8SJeremy Fitzhardinge #define PVOP_CALL3(rettype, op, arg1, arg2, arg3) \ 624ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "", PVOP_CALL_ARG1(arg1), \ 625ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2), PVOP_CALL_ARG3(arg3)) 626ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL3(op, arg1, arg2, arg3) \ 627ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "", PVOP_CALL_ARG1(arg1), \ 628ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2), PVOP_CALL_ARG3(arg3)) 629ac5672f8SJeremy Fitzhardinge 630ac5672f8SJeremy Fitzhardinge /* This is the only difference in x86_64. We can make it much simpler */ 631ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_32 632ac5672f8SJeremy Fitzhardinge #define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \ 633ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, \ 634ac5672f8SJeremy Fitzhardinge "push %[_arg4];", "lea 4(%%esp),%%esp;", \ 635ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \ 636ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG3(arg3), [_arg4] "mr" ((u32)(arg4))) 637ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \ 638ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, \ 639ac5672f8SJeremy Fitzhardinge "push %[_arg4];", "lea 4(%%esp),%%esp;", \ 640ac5672f8SJeremy Fitzhardinge "0" ((u32)(arg1)), "1" ((u32)(arg2)), \ 641ac5672f8SJeremy Fitzhardinge "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4))) 642ac5672f8SJeremy Fitzhardinge #else 643ac5672f8SJeremy Fitzhardinge #define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \ 644ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "", \ 645ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \ 646ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4)) 647ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \ 648ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "", \ 649ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \ 650ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4)) 651ac5672f8SJeremy Fitzhardinge #endif 652ac5672f8SJeremy Fitzhardinge 653ac5672f8SJeremy Fitzhardinge /* Lazy mode for batching updates / context switch */ 654ac5672f8SJeremy Fitzhardinge enum paravirt_lazy_mode { 655ac5672f8SJeremy Fitzhardinge PARAVIRT_LAZY_NONE, 656ac5672f8SJeremy Fitzhardinge PARAVIRT_LAZY_MMU, 657ac5672f8SJeremy Fitzhardinge PARAVIRT_LAZY_CPU, 658ac5672f8SJeremy Fitzhardinge }; 659ac5672f8SJeremy Fitzhardinge 660ac5672f8SJeremy Fitzhardinge enum paravirt_lazy_mode paravirt_get_lazy_mode(void); 661ac5672f8SJeremy Fitzhardinge void paravirt_start_context_switch(struct task_struct *prev); 662ac5672f8SJeremy Fitzhardinge void paravirt_end_context_switch(struct task_struct *next); 663ac5672f8SJeremy Fitzhardinge 664ac5672f8SJeremy Fitzhardinge void paravirt_enter_lazy_mmu(void); 665ac5672f8SJeremy Fitzhardinge void paravirt_leave_lazy_mmu(void); 666511ba86eSBoris Ostrovsky void paravirt_flush_lazy_mmu(void); 667ac5672f8SJeremy Fitzhardinge 668ac5672f8SJeremy Fitzhardinge void _paravirt_nop(void); 669ac5672f8SJeremy Fitzhardinge u64 _paravirt_ident_64(u64); 670ac5672f8SJeremy Fitzhardinge 671ac5672f8SJeremy Fitzhardinge #define paravirt_nop ((void *)_paravirt_nop) 672ac5672f8SJeremy Fitzhardinge 673ac5672f8SJeremy Fitzhardinge /* These all sit in the .parainstructions section to tell us what to patch. */ 674ac5672f8SJeremy Fitzhardinge struct paravirt_patch_site { 675ac5672f8SJeremy Fitzhardinge u8 *instr; /* original instructions */ 67646938cc8SIngo Molnar u8 type; /* type of this instruction */ 677ac5672f8SJeremy Fitzhardinge u8 len; /* length of original instruction */ 678ac5672f8SJeremy Fitzhardinge }; 679ac5672f8SJeremy Fitzhardinge 680ac5672f8SJeremy Fitzhardinge extern struct paravirt_patch_site __parainstructions[], 681ac5672f8SJeremy Fitzhardinge __parainstructions_end[]; 682ac5672f8SJeremy Fitzhardinge 683ac5672f8SJeremy Fitzhardinge #endif /* __ASSEMBLY__ */ 684ac5672f8SJeremy Fitzhardinge 685ac5672f8SJeremy Fitzhardinge #endif /* _ASM_X86_PARAVIRT_TYPES_H */ 686