x86/paravirt: Switch functions with custom code to ALTERNATIVE
[linux-block.git] / arch / x86 / include / asm / paravirt_types.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_PARAVIRT_TYPES_H
3 #define _ASM_X86_PARAVIRT_TYPES_H
4
5 /* Bitmask of what can be clobbered: usually at least eax. */
6 #define CLBR_EAX  (1 << 0)
7 #define CLBR_ECX  (1 << 1)
8 #define CLBR_EDX  (1 << 2)
9 #define CLBR_EDI  (1 << 3)
10
11 #ifdef CONFIG_X86_32
12 /* CLBR_ANY should match all regs platform has. For i386, that's just it */
13 #define CLBR_ANY  ((1 << 4) - 1)
14
15 #define CLBR_ARG_REGS   (CLBR_EAX | CLBR_EDX | CLBR_ECX)
16 #define CLBR_RET_REG    (CLBR_EAX | CLBR_EDX)
17 #else
18 #define CLBR_RAX  CLBR_EAX
19 #define CLBR_RCX  CLBR_ECX
20 #define CLBR_RDX  CLBR_EDX
21 #define CLBR_RDI  CLBR_EDI
22 #define CLBR_RSI  (1 << 4)
23 #define CLBR_R8   (1 << 5)
24 #define CLBR_R9   (1 << 6)
25 #define CLBR_R10  (1 << 7)
26 #define CLBR_R11  (1 << 8)
27
28 #define CLBR_ANY  ((1 << 9) - 1)
29
30 #define CLBR_ARG_REGS   (CLBR_RDI | CLBR_RSI | CLBR_RDX | \
31                          CLBR_RCX | CLBR_R8 | CLBR_R9)
32 #define CLBR_RET_REG    (CLBR_RAX)
33
34 #endif /* X86_64 */
35
36 #ifndef __ASSEMBLY__
37
38 #include <asm/desc_defs.h>
39 #include <asm/pgtable_types.h>
40 #include <asm/nospec-branch.h>
41
42 struct page;
43 struct thread_struct;
44 struct desc_ptr;
45 struct tss_struct;
46 struct mm_struct;
47 struct desc_struct;
48 struct task_struct;
49 struct cpumask;
50 struct flush_tlb_info;
51 struct mmu_gather;
52 struct vm_area_struct;
53
54 /*
55  * Wrapper type for pointers to code which uses the non-standard
56  * calling convention.  See PV_CALL_SAVE_REGS_THUNK below.
57  */
58 struct paravirt_callee_save {
59         void *func;
60 };
61
62 /* general info */
63 struct pv_info {
64 #ifdef CONFIG_PARAVIRT_XXL
65         u16 extra_user_64bit_cs;  /* __USER_CS if none */
66 #endif
67
68         const char *name;
69 };
70
71 struct pv_init_ops {
72         /*
73          * Patch may replace one of the defined code sequences with
74          * arbitrary code, subject to the same register constraints.
75          * This generally means the code is not free to clobber any
76          * registers other than EAX.  The patch function should return
77          * the number of bytes of code generated, as we nop pad the
78          * rest in generic code.
79          */
80         unsigned (*patch)(u8 type, void *insn_buff,
81                           unsigned long addr, unsigned len);
82 } __no_randomize_layout;
83
84 #ifdef CONFIG_PARAVIRT_XXL
85 struct pv_lazy_ops {
86         /* Set deferred update mode, used for batching operations. */
87         void (*enter)(void);
88         void (*leave)(void);
89         void (*flush)(void);
90 } __no_randomize_layout;
91 #endif
92
93 struct pv_cpu_ops {
94         /* hooks for various privileged instructions */
95         void (*io_delay)(void);
96
97 #ifdef CONFIG_PARAVIRT_XXL
98         unsigned long (*get_debugreg)(int regno);
99         void (*set_debugreg)(int regno, unsigned long value);
100
101         unsigned long (*read_cr0)(void);
102         void (*write_cr0)(unsigned long);
103
104         void (*write_cr4)(unsigned long);
105
106         /* Segment descriptor handling */
107         void (*load_tr_desc)(void);
108         void (*load_gdt)(const struct desc_ptr *);
109         void (*load_idt)(const struct desc_ptr *);
110         void (*set_ldt)(const void *desc, unsigned entries);
111         unsigned long (*store_tr)(void);
112         void (*load_tls)(struct thread_struct *t, unsigned int cpu);
113         void (*load_gs_index)(unsigned int idx);
114         void (*write_ldt_entry)(struct desc_struct *ldt, int entrynum,
115                                 const void *desc);
116         void (*write_gdt_entry)(struct desc_struct *,
117                                 int entrynum, const void *desc, int size);
118         void (*write_idt_entry)(gate_desc *,
119                                 int entrynum, const gate_desc *gate);
120         void (*alloc_ldt)(struct desc_struct *ldt, unsigned entries);
121         void (*free_ldt)(struct desc_struct *ldt, unsigned entries);
122
123         void (*load_sp0)(unsigned long sp0);
124
125 #ifdef CONFIG_X86_IOPL_IOPERM
126         void (*invalidate_io_bitmap)(void);
127         void (*update_io_bitmap)(void);
128 #endif
129
130         void (*wbinvd)(void);
131
132         /* cpuid emulation, mostly so that caps bits can be disabled */
133         void (*cpuid)(unsigned int *eax, unsigned int *ebx,
134                       unsigned int *ecx, unsigned int *edx);
135
136         /* Unsafe MSR operations.  These will warn or panic on failure. */
137         u64 (*read_msr)(unsigned int msr);
138         void (*write_msr)(unsigned int msr, unsigned low, unsigned high);
139
140         /*
141          * Safe MSR operations.
142          * read sets err to 0 or -EIO.  write returns 0 or -EIO.
143          */
144         u64 (*read_msr_safe)(unsigned int msr, int *err);
145         int (*write_msr_safe)(unsigned int msr, unsigned low, unsigned high);
146
147         u64 (*read_pmc)(int counter);
148
149         void (*start_context_switch)(struct task_struct *prev);
150         void (*end_context_switch)(struct task_struct *next);
151 #endif
152 } __no_randomize_layout;
153
154 struct pv_irq_ops {
155 #ifdef CONFIG_PARAVIRT_XXL
156         /*
157          * Get/set interrupt state.  save_fl is expected to use X86_EFLAGS_IF;
158          * all other bits returned from save_fl are undefined.
159          *
160          * NOTE: These functions callers expect the callee to preserve
161          * more registers than the standard C calling convention.
162          */
163         struct paravirt_callee_save save_fl;
164         struct paravirt_callee_save irq_disable;
165         struct paravirt_callee_save irq_enable;
166
167         void (*safe_halt)(void);
168         void (*halt)(void);
169 #endif
170 } __no_randomize_layout;
171
172 struct pv_mmu_ops {
173         /* TLB operations */
174         void (*flush_tlb_user)(void);
175         void (*flush_tlb_kernel)(void);
176         void (*flush_tlb_one_user)(unsigned long addr);
177         void (*flush_tlb_others)(const struct cpumask *cpus,
178                                  const struct flush_tlb_info *info);
179
180         void (*tlb_remove_table)(struct mmu_gather *tlb, void *table);
181
182         /* Hook for intercepting the destruction of an mm_struct. */
183         void (*exit_mmap)(struct mm_struct *mm);
184
185 #ifdef CONFIG_PARAVIRT_XXL
186         struct paravirt_callee_save read_cr2;
187         void (*write_cr2)(unsigned long);
188
189         unsigned long (*read_cr3)(void);
190         void (*write_cr3)(unsigned long);
191
192         /* Hooks for intercepting the creation/use of an mm_struct. */
193         void (*activate_mm)(struct mm_struct *prev,
194                             struct mm_struct *next);
195         void (*dup_mmap)(struct mm_struct *oldmm,
196                          struct mm_struct *mm);
197
198         /* Hooks for allocating and freeing a pagetable top-level */
199         int  (*pgd_alloc)(struct mm_struct *mm);
200         void (*pgd_free)(struct mm_struct *mm, pgd_t *pgd);
201
202         /*
203          * Hooks for allocating/releasing pagetable pages when they're
204          * attached to a pagetable
205          */
206         void (*alloc_pte)(struct mm_struct *mm, unsigned long pfn);
207         void (*alloc_pmd)(struct mm_struct *mm, unsigned long pfn);
208         void (*alloc_pud)(struct mm_struct *mm, unsigned long pfn);
209         void (*alloc_p4d)(struct mm_struct *mm, unsigned long pfn);
210         void (*release_pte)(unsigned long pfn);
211         void (*release_pmd)(unsigned long pfn);
212         void (*release_pud)(unsigned long pfn);
213         void (*release_p4d)(unsigned long pfn);
214
215         /* Pagetable manipulation functions */
216         void (*set_pte)(pte_t *ptep, pte_t pteval);
217         void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
218
219         pte_t (*ptep_modify_prot_start)(struct vm_area_struct *vma, unsigned long addr,
220                                         pte_t *ptep);
221         void (*ptep_modify_prot_commit)(struct vm_area_struct *vma, unsigned long addr,
222                                         pte_t *ptep, pte_t pte);
223
224         struct paravirt_callee_save pte_val;
225         struct paravirt_callee_save make_pte;
226
227         struct paravirt_callee_save pgd_val;
228         struct paravirt_callee_save make_pgd;
229
230         void (*set_pud)(pud_t *pudp, pud_t pudval);
231
232         struct paravirt_callee_save pmd_val;
233         struct paravirt_callee_save make_pmd;
234
235         struct paravirt_callee_save pud_val;
236         struct paravirt_callee_save make_pud;
237
238         void (*set_p4d)(p4d_t *p4dp, p4d_t p4dval);
239
240 #if CONFIG_PGTABLE_LEVELS >= 5
241         struct paravirt_callee_save p4d_val;
242         struct paravirt_callee_save make_p4d;
243
244         void (*set_pgd)(pgd_t *pgdp, pgd_t pgdval);
245 #endif  /* CONFIG_PGTABLE_LEVELS >= 5 */
246
247         struct pv_lazy_ops lazy_mode;
248
249         /* dom0 ops */
250
251         /* Sometimes the physical address is a pfn, and sometimes its
252            an mfn.  We can tell which is which from the index. */
253         void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
254                            phys_addr_t phys, pgprot_t flags);
255 #endif
256 } __no_randomize_layout;
257
258 struct arch_spinlock;
259 #ifdef CONFIG_SMP
260 #include <asm/spinlock_types.h>
261 #endif
262
263 struct qspinlock;
264
265 struct pv_lock_ops {
266         void (*queued_spin_lock_slowpath)(struct qspinlock *lock, u32 val);
267         struct paravirt_callee_save queued_spin_unlock;
268
269         void (*wait)(u8 *ptr, u8 val);
270         void (*kick)(int cpu);
271
272         struct paravirt_callee_save vcpu_is_preempted;
273 } __no_randomize_layout;
274
275 /* This contains all the paravirt structures: we get a convenient
276  * number for each function using the offset which we use to indicate
277  * what to patch. */
278 struct paravirt_patch_template {
279         struct pv_init_ops      init;
280         struct pv_cpu_ops       cpu;
281         struct pv_irq_ops       irq;
282         struct pv_mmu_ops       mmu;
283         struct pv_lock_ops      lock;
284 } __no_randomize_layout;
285
286 extern struct pv_info pv_info;
287 extern struct paravirt_patch_template pv_ops;
288 extern void (*paravirt_iret)(void);
289
290 #define PARAVIRT_PATCH(x)                                       \
291         (offsetof(struct paravirt_patch_template, x) / sizeof(void *))
292
293 #define paravirt_type(op)                               \
294         [paravirt_typenum] "i" (PARAVIRT_PATCH(op)),    \
295         [paravirt_opptr] "i" (&(pv_ops.op))
296 #define paravirt_clobber(clobber)               \
297         [paravirt_clobber] "i" (clobber)
298
299 /*
300  * Generate some code, and mark it as patchable by the
301  * apply_paravirt() alternate instruction patcher.
302  */
303 #define _paravirt_alt(insn_string, type, clobber)       \
304         "771:\n\t" insn_string "\n" "772:\n"            \
305         ".pushsection .parainstructions,\"a\"\n"        \
306         _ASM_ALIGN "\n"                                 \
307         _ASM_PTR " 771b\n"                              \
308         "  .byte " type "\n"                            \
309         "  .byte 772b-771b\n"                           \
310         "  .short " clobber "\n"                        \
311         ".popsection\n"
312
313 /* Generate patchable code, with the default asm parameters. */
314 #define paravirt_alt(insn_string)                                       \
315         _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
316
317 /* Simple instruction patching code. */
318 #define NATIVE_LABEL(a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t"
319
320 unsigned paravirt_patch_default(u8 type, void *insn_buff, unsigned long addr, unsigned len);
321 unsigned paravirt_patch_insns(void *insn_buff, unsigned len, const char *start, const char *end);
322
323 unsigned native_patch(u8 type, void *insn_buff, unsigned long addr, unsigned len);
324
325 int paravirt_disable_iospace(void);
326
327 /*
328  * This generates an indirect call based on the operation type number.
329  * The type number, computed in PARAVIRT_PATCH, is derived from the
330  * offset into the paravirt_patch_template structure, and can therefore be
331  * freely converted back into a structure offset.
332  */
333 #define PARAVIRT_CALL                                   \
334         ANNOTATE_RETPOLINE_SAFE                         \
335         "call *%c[paravirt_opptr];"
336
337 /*
338  * These macros are intended to wrap calls through one of the paravirt
339  * ops structs, so that they can be later identified and patched at
340  * runtime.
341  *
342  * Normally, a call to a pv_op function is a simple indirect call:
343  * (pv_op_struct.operations)(args...).
344  *
345  * Unfortunately, this is a relatively slow operation for modern CPUs,
346  * because it cannot necessarily determine what the destination
347  * address is.  In this case, the address is a runtime constant, so at
348  * the very least we can patch the call to e a simple direct call, or
349  * ideally, patch an inline implementation into the callsite.  (Direct
350  * calls are essentially free, because the call and return addresses
351  * are completely predictable.)
352  *
353  * For i386, these macros rely on the standard gcc "regparm(3)" calling
354  * convention, in which the first three arguments are placed in %eax,
355  * %edx, %ecx (in that order), and the remaining arguments are placed
356  * on the stack.  All caller-save registers (eax,edx,ecx) are expected
357  * to be modified (either clobbered or used for return values).
358  * X86_64, on the other hand, already specifies a register-based calling
359  * conventions, returning at %rax, with parameteres going on %rdi, %rsi,
360  * %rdx, and %rcx. Note that for this reason, x86_64 does not need any
361  * special handling for dealing with 4 arguments, unlike i386.
362  * However, x86_64 also have to clobber all caller saved registers, which
363  * unfortunately, are quite a bit (r8 - r11)
364  *
365  * The call instruction itself is marked by placing its start address
366  * and size into the .parainstructions section, so that
367  * apply_paravirt() in arch/i386/kernel/alternative.c can do the
368  * appropriate patching under the control of the backend pv_init_ops
369  * implementation.
370  *
371  * Unfortunately there's no way to get gcc to generate the args setup
372  * for the call, and then allow the call itself to be generated by an
373  * inline asm.  Because of this, we must do the complete arg setup and
374  * return value handling from within these macros.  This is fairly
375  * cumbersome.
376  *
377  * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
378  * It could be extended to more arguments, but there would be little
379  * to be gained from that.  For each number of arguments, there are
380  * the two VCALL and CALL variants for void and non-void functions.
381  *
382  * When there is a return value, the invoker of the macro must specify
383  * the return type.  The macro then uses sizeof() on that type to
384  * determine whether its a 32 or 64 bit value, and places the return
385  * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
386  * 64-bit). For x86_64 machines, it just returns at %rax regardless of
387  * the return value size.
388  *
389  * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
390  * i386 also passes 64-bit arguments as a pair of adjacent 32-bit arguments
391  * in low,high order
392  *
393  * Small structures are passed and returned in registers.  The macro
394  * calling convention can't directly deal with this, so the wrapper
395  * functions must do this.
396  *
397  * These PVOP_* macros are only defined within this header.  This
398  * means that all uses must be wrapped in inline functions.  This also
399  * makes sure the incoming and outgoing types are always correct.
400  */
401 #ifdef CONFIG_X86_32
402 #define PVOP_CALL_ARGS                                                  \
403         unsigned long __eax = __eax, __edx = __edx, __ecx = __ecx;
404
405 #define PVOP_CALL_ARG1(x)               "a" ((unsigned long)(x))
406 #define PVOP_CALL_ARG2(x)               "d" ((unsigned long)(x))
407 #define PVOP_CALL_ARG3(x)               "c" ((unsigned long)(x))
408
409 #define PVOP_VCALL_CLOBBERS             "=a" (__eax), "=d" (__edx),     \
410                                         "=c" (__ecx)
411 #define PVOP_CALL_CLOBBERS              PVOP_VCALL_CLOBBERS
412
413 #define PVOP_VCALLEE_CLOBBERS           "=a" (__eax), "=d" (__edx)
414 #define PVOP_CALLEE_CLOBBERS            PVOP_VCALLEE_CLOBBERS
415
416 #define EXTRA_CLOBBERS
417 #define VEXTRA_CLOBBERS
418 #else  /* CONFIG_X86_64 */
419 /* [re]ax isn't an arg, but the return val */
420 #define PVOP_CALL_ARGS                                          \
421         unsigned long __edi = __edi, __esi = __esi,             \
422                 __edx = __edx, __ecx = __ecx, __eax = __eax;
423
424 #define PVOP_CALL_ARG1(x)               "D" ((unsigned long)(x))
425 #define PVOP_CALL_ARG2(x)               "S" ((unsigned long)(x))
426 #define PVOP_CALL_ARG3(x)               "d" ((unsigned long)(x))
427 #define PVOP_CALL_ARG4(x)               "c" ((unsigned long)(x))
428
429 #define PVOP_VCALL_CLOBBERS     "=D" (__edi),                           \
430                                 "=S" (__esi), "=d" (__edx),             \
431                                 "=c" (__ecx)
432 #define PVOP_CALL_CLOBBERS      PVOP_VCALL_CLOBBERS, "=a" (__eax)
433
434 /* void functions are still allowed [re]ax for scratch */
435 #define PVOP_VCALLEE_CLOBBERS   "=a" (__eax)
436 #define PVOP_CALLEE_CLOBBERS    PVOP_VCALLEE_CLOBBERS
437
438 #define EXTRA_CLOBBERS   , "r8", "r9", "r10", "r11"
439 #define VEXTRA_CLOBBERS  , "rax", "r8", "r9", "r10", "r11"
440 #endif  /* CONFIG_X86_32 */
441
442 #ifdef CONFIG_PARAVIRT_DEBUG
443 #define PVOP_TEST_NULL(op)      BUG_ON(pv_ops.op == NULL)
444 #else
445 #define PVOP_TEST_NULL(op)      ((void)pv_ops.op)
446 #endif
447
448 #define PVOP_RETVAL(rettype)                                            \
449         ({      unsigned long __mask = ~0UL;                            \
450                 BUILD_BUG_ON(sizeof(rettype) > sizeof(unsigned long));  \
451                 switch (sizeof(rettype)) {                              \
452                 case 1: __mask =       0xffUL; break;                   \
453                 case 2: __mask =     0xffffUL; break;                   \
454                 case 4: __mask = 0xffffffffUL; break;                   \
455                 default: break;                                         \
456                 }                                                       \
457                 __mask & __eax;                                         \
458         })
459
460
461 #define ____PVOP_CALL(ret, op, clbr, call_clbr, extra_clbr, ...)        \
462         ({                                                              \
463                 PVOP_CALL_ARGS;                                         \
464                 PVOP_TEST_NULL(op);                                     \
465                 asm volatile(paravirt_alt(PARAVIRT_CALL)                \
466                              : call_clbr, ASM_CALL_CONSTRAINT           \
467                              : paravirt_type(op),                       \
468                                paravirt_clobber(clbr),                  \
469                                ##__VA_ARGS__                            \
470                              : "memory", "cc" extra_clbr);              \
471                 ret;                                                    \
472         })
473
474 #define ____PVOP_ALT_CALL(ret, op, alt, cond, clbr, call_clbr,          \
475                           extra_clbr, ...)                              \
476         ({                                                              \
477                 PVOP_CALL_ARGS;                                         \
478                 PVOP_TEST_NULL(op);                                     \
479                 asm volatile(ALTERNATIVE(paravirt_alt(PARAVIRT_CALL),   \
480                                          alt, cond)                     \
481                              : call_clbr, ASM_CALL_CONSTRAINT           \
482                              : paravirt_type(op),                       \
483                                paravirt_clobber(clbr),                  \
484                                ##__VA_ARGS__                            \
485                              : "memory", "cc" extra_clbr);              \
486                 ret;                                                    \
487         })
488
489 #define __PVOP_CALL(rettype, op, ...)                                   \
490         ____PVOP_CALL(PVOP_RETVAL(rettype), op, CLBR_ANY,               \
491                       PVOP_CALL_CLOBBERS, EXTRA_CLOBBERS, ##__VA_ARGS__)
492
493 #define __PVOP_ALT_CALL(rettype, op, alt, cond, ...)                    \
494         ____PVOP_ALT_CALL(PVOP_RETVAL(rettype), op, alt, cond, CLBR_ANY,\
495                           PVOP_CALL_CLOBBERS, EXTRA_CLOBBERS,           \
496                           ##__VA_ARGS__)
497
498 #define __PVOP_CALLEESAVE(rettype, op, ...)                             \
499         ____PVOP_CALL(PVOP_RETVAL(rettype), op.func, CLBR_RET_REG,      \
500                       PVOP_CALLEE_CLOBBERS, , ##__VA_ARGS__)
501
502 #define __PVOP_ALT_CALLEESAVE(rettype, op, alt, cond, ...)              \
503         ____PVOP_ALT_CALL(PVOP_RETVAL(rettype), op.func, alt, cond,     \
504                           CLBR_RET_REG, PVOP_CALLEE_CLOBBERS, , ##__VA_ARGS__)
505
506
507 #define __PVOP_VCALL(op, ...)                                           \
508         (void)____PVOP_CALL(, op, CLBR_ANY, PVOP_VCALL_CLOBBERS,        \
509                        VEXTRA_CLOBBERS, ##__VA_ARGS__)
510
511 #define __PVOP_ALT_VCALL(op, alt, cond, ...)                            \
512         (void)____PVOP_ALT_CALL(, op, alt, cond, CLBR_ANY,              \
513                                 PVOP_VCALL_CLOBBERS, VEXTRA_CLOBBERS,   \
514                                 ##__VA_ARGS__)
515
516 #define __PVOP_VCALLEESAVE(op, ...)                                     \
517         (void)____PVOP_CALL(, op.func, CLBR_RET_REG,                    \
518                             PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__)
519
520 #define __PVOP_ALT_VCALLEESAVE(op, alt, cond, ...)                      \
521         (void)____PVOP_ALT_CALL(, op.func, alt, cond, CLBR_RET_REG,     \
522                                 PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__)
523
524
525 #define PVOP_CALL0(rettype, op)                                         \
526         __PVOP_CALL(rettype, op)
527 #define PVOP_VCALL0(op)                                                 \
528         __PVOP_VCALL(op)
529 #define PVOP_ALT_CALL0(rettype, op, alt, cond)                          \
530         __PVOP_ALT_CALL(rettype, op, alt, cond)
531 #define PVOP_ALT_VCALL0(op, alt, cond)                                  \
532         __PVOP_ALT_VCALL(op, alt, cond)
533
534 #define PVOP_CALLEE0(rettype, op)                                       \
535         __PVOP_CALLEESAVE(rettype, op)
536 #define PVOP_VCALLEE0(op)                                               \
537         __PVOP_VCALLEESAVE(op)
538 #define PVOP_ALT_CALLEE0(rettype, op, alt, cond)                        \
539         __PVOP_ALT_CALLEESAVE(rettype, op, alt, cond)
540 #define PVOP_ALT_VCALLEE0(op, alt, cond)                                \
541         __PVOP_ALT_VCALLEESAVE(op, alt, cond)
542
543
544 #define PVOP_CALL1(rettype, op, arg1)                                   \
545         __PVOP_CALL(rettype, op, PVOP_CALL_ARG1(arg1))
546 #define PVOP_VCALL1(op, arg1)                                           \
547         __PVOP_VCALL(op, PVOP_CALL_ARG1(arg1))
548 #define PVOP_ALT_VCALL1(op, arg1, alt, cond)                            \
549         __PVOP_ALT_VCALL(op, alt, cond, PVOP_CALL_ARG1(arg1))
550
551 #define PVOP_CALLEE1(rettype, op, arg1)                                 \
552         __PVOP_CALLEESAVE(rettype, op, PVOP_CALL_ARG1(arg1))
553 #define PVOP_VCALLEE1(op, arg1)                                         \
554         __PVOP_VCALLEESAVE(op, PVOP_CALL_ARG1(arg1))
555 #define PVOP_ALT_CALLEE1(rettype, op, arg1, alt, cond)                  \
556         __PVOP_ALT_CALLEESAVE(rettype, op, alt, cond, PVOP_CALL_ARG1(arg1))
557 #define PVOP_ALT_VCALLEE1(op, arg1, alt, cond)                          \
558         __PVOP_ALT_VCALLEESAVE(op, alt, cond, PVOP_CALL_ARG1(arg1))
559
560
561 #define PVOP_CALL2(rettype, op, arg1, arg2)                             \
562         __PVOP_CALL(rettype, op, PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2))
563 #define PVOP_VCALL2(op, arg1, arg2)                                     \
564         __PVOP_VCALL(op, PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2))
565
566 #define PVOP_CALL3(rettype, op, arg1, arg2, arg3)                       \
567         __PVOP_CALL(rettype, op, PVOP_CALL_ARG1(arg1),                  \
568                     PVOP_CALL_ARG2(arg2), PVOP_CALL_ARG3(arg3))
569 #define PVOP_VCALL3(op, arg1, arg2, arg3)                               \
570         __PVOP_VCALL(op, PVOP_CALL_ARG1(arg1),                          \
571                      PVOP_CALL_ARG2(arg2), PVOP_CALL_ARG3(arg3))
572
573 #define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4)                 \
574         __PVOP_CALL(rettype, op,                                        \
575                     PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2),         \
576                     PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4))
577 #define PVOP_VCALL4(op, arg1, arg2, arg3, arg4)                         \
578         __PVOP_VCALL(op, PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2),    \
579                      PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4))
580
581 /* Lazy mode for batching updates / context switch */
582 enum paravirt_lazy_mode {
583         PARAVIRT_LAZY_NONE,
584         PARAVIRT_LAZY_MMU,
585         PARAVIRT_LAZY_CPU,
586 };
587
588 enum paravirt_lazy_mode paravirt_get_lazy_mode(void);
589 void paravirt_start_context_switch(struct task_struct *prev);
590 void paravirt_end_context_switch(struct task_struct *next);
591
592 void paravirt_enter_lazy_mmu(void);
593 void paravirt_leave_lazy_mmu(void);
594 void paravirt_flush_lazy_mmu(void);
595
596 void _paravirt_nop(void);
597 u64 _paravirt_ident_64(u64);
598
599 #define paravirt_nop    ((void *)_paravirt_nop)
600
601 /* These all sit in the .parainstructions section to tell us what to patch. */
602 struct paravirt_patch_site {
603         u8 *instr;              /* original instructions */
604         u8 type;                /* type of this instruction */
605         u8 len;                 /* length of original instruction */
606 };
607
608 extern struct paravirt_patch_site __parainstructions[],
609         __parainstructions_end[];
610
611 #endif  /* __ASSEMBLY__ */
612
613 #endif  /* _ASM_X86_PARAVIRT_TYPES_H */