paravirt.h 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  1. #ifndef __ASM_PARAVIRT_H
  2. #define __ASM_PARAVIRT_H
  3. /* Various instructions on x86 need to be replaced for
  4. * para-virtualization: those hooks are defined here. */
  5. #ifdef CONFIG_PARAVIRT
  6. #include <asm/page.h>
  7. #include <asm/asm.h>
  8. /* Bitmask of what can be clobbered: usually at least eax. */
  9. #define CLBR_NONE 0
  10. #define CLBR_EAX (1 << 0)
  11. #define CLBR_ECX (1 << 1)
  12. #define CLBR_EDX (1 << 2)
  13. #ifdef CONFIG_X86_64
  14. #define CLBR_RSI (1 << 3)
  15. #define CLBR_RDI (1 << 4)
  16. #define CLBR_R8 (1 << 5)
  17. #define CLBR_R9 (1 << 6)
  18. #define CLBR_R10 (1 << 7)
  19. #define CLBR_R11 (1 << 8)
  20. #define CLBR_ANY ((1 << 9) - 1)
  21. #include <asm/desc_defs.h>
  22. #else
  23. /* CLBR_ANY should match all regs platform has. For i386, that's just it */
  24. #define CLBR_ANY ((1 << 3) - 1)
  25. #endif /* X86_64 */
  26. #ifndef __ASSEMBLY__
  27. #include <linux/types.h>
  28. #include <linux/cpumask.h>
  29. #include <asm/kmap_types.h>
  30. #include <asm/desc_defs.h>
  31. struct page;
  32. struct thread_struct;
  33. struct desc_ptr;
  34. struct tss_struct;
  35. struct mm_struct;
  36. struct desc_struct;
  37. /* general info */
  38. struct pv_info {
  39. unsigned int kernel_rpl;
  40. int shared_kernel_pmd;
  41. int paravirt_enabled;
  42. const char *name;
  43. };
  44. struct pv_init_ops {
  45. /*
  46. * Patch may replace one of the defined code sequences with
  47. * arbitrary code, subject to the same register constraints.
  48. * This generally means the code is not free to clobber any
  49. * registers other than EAX. The patch function should return
  50. * the number of bytes of code generated, as we nop pad the
  51. * rest in generic code.
  52. */
  53. unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
  54. unsigned long addr, unsigned len);
  55. /* Basic arch-specific setup */
  56. void (*arch_setup)(void);
  57. char *(*memory_setup)(void);
  58. void (*post_allocator_init)(void);
  59. /* Print a banner to identify the environment */
  60. void (*banner)(void);
  61. };
  62. struct pv_lazy_ops {
  63. /* Set deferred update mode, used for batching operations. */
  64. void (*enter)(void);
  65. void (*leave)(void);
  66. };
  67. struct pv_time_ops {
  68. void (*time_init)(void);
  69. /* Set and set time of day */
  70. unsigned long (*get_wallclock)(void);
  71. int (*set_wallclock)(unsigned long);
  72. unsigned long long (*sched_clock)(void);
  73. unsigned long (*get_cpu_khz)(void);
  74. };
  75. struct pv_cpu_ops {
  76. /* hooks for various privileged instructions */
  77. unsigned long (*get_debugreg)(int regno);
  78. void (*set_debugreg)(int regno, unsigned long value);
  79. void (*clts)(void);
  80. unsigned long (*read_cr0)(void);
  81. void (*write_cr0)(unsigned long);
  82. unsigned long (*read_cr4_safe)(void);
  83. unsigned long (*read_cr4)(void);
  84. void (*write_cr4)(unsigned long);
  85. /* Segment descriptor handling */
  86. void (*load_tr_desc)(void);
  87. void (*load_gdt)(const struct desc_ptr *);
  88. void (*load_idt)(const struct desc_ptr *);
  89. void (*store_gdt)(struct desc_ptr *);
  90. void (*store_idt)(struct desc_ptr *);
  91. void (*set_ldt)(const void *desc, unsigned entries);
  92. unsigned long (*store_tr)(void);
  93. void (*load_tls)(struct thread_struct *t, unsigned int cpu);
  94. void (*write_ldt_entry)(struct desc_struct *ldt, int entrynum,
  95. const void *desc);
  96. void (*write_gdt_entry)(struct desc_struct *,
  97. int entrynum, const void *desc, int size);
  98. void (*write_idt_entry)(gate_desc *,
  99. int entrynum, const gate_desc *gate);
  100. void (*load_sp0)(struct tss_struct *tss, struct thread_struct *t);
  101. void (*set_iopl_mask)(unsigned mask);
  102. void (*wbinvd)(void);
  103. void (*io_delay)(void);
  104. /* cpuid emulation, mostly so that caps bits can be disabled */
  105. void (*cpuid)(unsigned int *eax, unsigned int *ebx,
  106. unsigned int *ecx, unsigned int *edx);
  107. /* MSR, PMC and TSR operations.
  108. err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
  109. u64 (*read_msr)(unsigned int msr, int *err);
  110. int (*write_msr)(unsigned int msr, unsigned low, unsigned high);
  111. u64 (*read_tsc)(void);
  112. u64 (*read_pmc)(int counter);
  113. unsigned long long (*read_tscp)(unsigned int *aux);
  114. /* These two are jmp to, not actually called. */
  115. void (*irq_enable_syscall_ret)(void);
  116. void (*iret)(void);
  117. void (*swapgs)(void);
  118. struct pv_lazy_ops lazy_mode;
  119. };
  120. struct pv_irq_ops {
  121. void (*init_IRQ)(void);
  122. /*
  123. * Get/set interrupt state. save_fl and restore_fl are only
  124. * expected to use X86_EFLAGS_IF; all other bits
  125. * returned from save_fl are undefined, and may be ignored by
  126. * restore_fl.
  127. */
  128. unsigned long (*save_fl)(void);
  129. void (*restore_fl)(unsigned long);
  130. void (*irq_disable)(void);
  131. void (*irq_enable)(void);
  132. void (*safe_halt)(void);
  133. void (*halt)(void);
  134. };
  135. struct pv_apic_ops {
  136. #ifdef CONFIG_X86_LOCAL_APIC
  137. /*
  138. * Direct APIC operations, principally for VMI. Ideally
  139. * these shouldn't be in this interface.
  140. */
  141. void (*apic_write)(unsigned long reg, u32 v);
  142. void (*apic_write_atomic)(unsigned long reg, u32 v);
  143. u32 (*apic_read)(unsigned long reg);
  144. void (*setup_boot_clock)(void);
  145. void (*setup_secondary_clock)(void);
  146. void (*startup_ipi_hook)(int phys_apicid,
  147. unsigned long start_eip,
  148. unsigned long start_esp);
  149. #endif
  150. };
  151. struct pv_mmu_ops {
  152. /*
  153. * Called before/after init_mm pagetable setup. setup_start
  154. * may reset %cr3, and may pre-install parts of the pagetable;
  155. * pagetable setup is expected to preserve any existing
  156. * mapping.
  157. */
  158. void (*pagetable_setup_start)(pgd_t *pgd_base);
  159. void (*pagetable_setup_done)(pgd_t *pgd_base);
  160. unsigned long (*read_cr2)(void);
  161. void (*write_cr2)(unsigned long);
  162. unsigned long (*read_cr3)(void);
  163. void (*write_cr3)(unsigned long);
  164. /*
  165. * Hooks for intercepting the creation/use/destruction of an
  166. * mm_struct.
  167. */
  168. void (*activate_mm)(struct mm_struct *prev,
  169. struct mm_struct *next);
  170. void (*dup_mmap)(struct mm_struct *oldmm,
  171. struct mm_struct *mm);
  172. void (*exit_mmap)(struct mm_struct *mm);
  173. /* TLB operations */
  174. void (*flush_tlb_user)(void);
  175. void (*flush_tlb_kernel)(void);
  176. void (*flush_tlb_single)(unsigned long addr);
  177. void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
  178. unsigned long va);
  179. /* Hooks for allocating/releasing pagetable pages */
  180. void (*alloc_pt)(struct mm_struct *mm, u32 pfn);
  181. void (*alloc_pd)(u32 pfn);
  182. void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
  183. void (*release_pt)(u32 pfn);
  184. void (*release_pd)(u32 pfn);
  185. /* Pagetable manipulation functions */
  186. void (*set_pte)(pte_t *ptep, pte_t pteval);
  187. void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
  188. pte_t *ptep, pte_t pteval);
  189. void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
  190. void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
  191. void (*pte_update_defer)(struct mm_struct *mm,
  192. unsigned long addr, pte_t *ptep);
  193. #ifdef CONFIG_X86_PAE
  194. void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
  195. void (*set_pte_present)(struct mm_struct *mm, unsigned long addr,
  196. pte_t *ptep, pte_t pte);
  197. void (*set_pud)(pud_t *pudp, pud_t pudval);
  198. void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
  199. void (*pmd_clear)(pmd_t *pmdp);
  200. unsigned long long (*pte_val)(pte_t);
  201. unsigned long long (*pmd_val)(pmd_t);
  202. unsigned long long (*pgd_val)(pgd_t);
  203. pte_t (*make_pte)(unsigned long long pte);
  204. pmd_t (*make_pmd)(unsigned long long pmd);
  205. pgd_t (*make_pgd)(unsigned long long pgd);
  206. #else
  207. unsigned long (*pte_val)(pte_t);
  208. unsigned long (*pgd_val)(pgd_t);
  209. pte_t (*make_pte)(unsigned long pte);
  210. pgd_t (*make_pgd)(unsigned long pgd);
  211. #endif
  212. #ifdef CONFIG_HIGHPTE
  213. void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
  214. #endif
  215. struct pv_lazy_ops lazy_mode;
  216. };
  217. /* This contains all the paravirt structures: we get a convenient
  218. * number for each function using the offset which we use to indicate
  219. * what to patch. */
  220. struct paravirt_patch_template
  221. {
  222. struct pv_init_ops pv_init_ops;
  223. struct pv_time_ops pv_time_ops;
  224. struct pv_cpu_ops pv_cpu_ops;
  225. struct pv_irq_ops pv_irq_ops;
  226. struct pv_apic_ops pv_apic_ops;
  227. struct pv_mmu_ops pv_mmu_ops;
  228. };
  229. extern struct pv_info pv_info;
  230. extern struct pv_init_ops pv_init_ops;
  231. extern struct pv_time_ops pv_time_ops;
  232. extern struct pv_cpu_ops pv_cpu_ops;
  233. extern struct pv_irq_ops pv_irq_ops;
  234. extern struct pv_apic_ops pv_apic_ops;
  235. extern struct pv_mmu_ops pv_mmu_ops;
  236. #define PARAVIRT_PATCH(x) \
  237. (offsetof(struct paravirt_patch_template, x) / sizeof(void *))
  238. #define paravirt_type(op) \
  239. [paravirt_typenum] "i" (PARAVIRT_PATCH(op)), \
  240. [paravirt_opptr] "m" (op)
  241. #define paravirt_clobber(clobber) \
  242. [paravirt_clobber] "i" (clobber)
  243. /*
  244. * Generate some code, and mark it as patchable by the
  245. * apply_paravirt() alternate instruction patcher.
  246. */
  247. #define _paravirt_alt(insn_string, type, clobber) \
  248. "771:\n\t" insn_string "\n" "772:\n" \
  249. ".pushsection .parainstructions,\"a\"\n" \
  250. _ASM_ALIGN "\n" \
  251. _ASM_PTR " 771b\n" \
  252. " .byte " type "\n" \
  253. " .byte 772b-771b\n" \
  254. " .short " clobber "\n" \
  255. ".popsection\n"
  256. /* Generate patchable code, with the default asm parameters. */
  257. #define paravirt_alt(insn_string) \
  258. _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
  259. unsigned paravirt_patch_nop(void);
  260. unsigned paravirt_patch_ignore(unsigned len);
  261. unsigned paravirt_patch_call(void *insnbuf,
  262. const void *target, u16 tgt_clobbers,
  263. unsigned long addr, u16 site_clobbers,
  264. unsigned len);
  265. unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
  266. unsigned long addr, unsigned len);
  267. unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
  268. unsigned long addr, unsigned len);
  269. unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
  270. const char *start, const char *end);
  271. int paravirt_disable_iospace(void);
  272. /*
  273. * This generates an indirect call based on the operation type number.
  274. * The type number, computed in PARAVIRT_PATCH, is derived from the
  275. * offset into the paravirt_patch_template structure, and can therefore be
  276. * freely converted back into a structure offset.
  277. */
  278. #define PARAVIRT_CALL "call *%[paravirt_opptr];"
  279. /*
  280. * These macros are intended to wrap calls through one of the paravirt
  281. * ops structs, so that they can be later identified and patched at
  282. * runtime.
  283. *
  284. * Normally, a call to a pv_op function is a simple indirect call:
  285. * (pv_op_struct.operations)(args...).
  286. *
  287. * Unfortunately, this is a relatively slow operation for modern CPUs,
  288. * because it cannot necessarily determine what the destination
  289. * address is. In this case, the address is a runtime constant, so at
  290. * the very least we can patch the call to e a simple direct call, or
  291. * ideally, patch an inline implementation into the callsite. (Direct
  292. * calls are essentially free, because the call and return addresses
  293. * are completely predictable.)
  294. *
  295. * For i386, these macros rely on the standard gcc "regparm(3)" calling
  296. * convention, in which the first three arguments are placed in %eax,
  297. * %edx, %ecx (in that order), and the remaining arguments are placed
  298. * on the stack. All caller-save registers (eax,edx,ecx) are expected
  299. * to be modified (either clobbered or used for return values).
  300. * X86_64, on the other hand, already specifies a register-based calling
  301. * conventions, returning at %rax, with parameteres going on %rdi, %rsi,
  302. * %rdx, and %rcx. Note that for this reason, x86_64 does not need any
  303. * special handling for dealing with 4 arguments, unlike i386.
  304. * However, x86_64 also have to clobber all caller saved registers, which
  305. * unfortunately, are quite a bit (r8 - r11)
  306. *
  307. * The call instruction itself is marked by placing its start address
  308. * and size into the .parainstructions section, so that
  309. * apply_paravirt() in arch/i386/kernel/alternative.c can do the
  310. * appropriate patching under the control of the backend pv_init_ops
  311. * implementation.
  312. *
  313. * Unfortunately there's no way to get gcc to generate the args setup
  314. * for the call, and then allow the call itself to be generated by an
  315. * inline asm. Because of this, we must do the complete arg setup and
  316. * return value handling from within these macros. This is fairly
  317. * cumbersome.
  318. *
  319. * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
  320. * It could be extended to more arguments, but there would be little
  321. * to be gained from that. For each number of arguments, there are
  322. * the two VCALL and CALL variants for void and non-void functions.
  323. *
  324. * When there is a return value, the invoker of the macro must specify
  325. * the return type. The macro then uses sizeof() on that type to
  326. * determine whether its a 32 or 64 bit value, and places the return
  327. * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
  328. * 64-bit). For x86_64 machines, it just returns at %rax regardless of
  329. * the return value size.
  330. *
  331. * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
  332. * i386 also passes 64-bit arguments as a pair of adjacent 32-bit arguments
  333. * in low,high order
  334. *
  335. * Small structures are passed and returned in registers. The macro
  336. * calling convention can't directly deal with this, so the wrapper
  337. * functions must do this.
  338. *
  339. * These PVOP_* macros are only defined within this header. This
  340. * means that all uses must be wrapped in inline functions. This also
  341. * makes sure the incoming and outgoing types are always correct.
  342. */
  343. #ifdef CONFIG_X86_32
  344. #define PVOP_VCALL_ARGS unsigned long __eax, __edx, __ecx
  345. #define PVOP_CALL_ARGS PVOP_VCALL_ARGS
  346. #define PVOP_VCALL_CLOBBERS "=a" (__eax), "=d" (__edx), \
  347. "=c" (__ecx)
  348. #define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS
  349. #define EXTRA_CLOBBERS
  350. #define VEXTRA_CLOBBERS
  351. #else
  352. #define PVOP_VCALL_ARGS unsigned long __edi, __esi, __edx, __ecx
  353. #define PVOP_CALL_ARGS PVOP_VCALL_ARGS, __eax
  354. #define PVOP_VCALL_CLOBBERS "=D" (__edi), \
  355. "=S" (__esi), "=d" (__edx), \
  356. "=c" (__ecx)
  357. #define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS, "=a" (__eax)
  358. #define EXTRA_CLOBBERS , "r8", "r9", "r10", "r11"
  359. #define VEXTRA_CLOBBERS , "rax", "r8", "r9", "r10", "r11"
  360. #endif
  361. #define __PVOP_CALL(rettype, op, pre, post, ...) \
  362. ({ \
  363. rettype __ret; \
  364. PVOP_CALL_ARGS; \
  365. /* This is 32-bit specific, but is okay in 64-bit */ \
  366. /* since this condition will never hold */ \
  367. if (sizeof(rettype) > sizeof(unsigned long)) { \
  368. asm volatile(pre \
  369. paravirt_alt(PARAVIRT_CALL) \
  370. post \
  371. : PVOP_CALL_CLOBBERS \
  372. : paravirt_type(op), \
  373. paravirt_clobber(CLBR_ANY), \
  374. ##__VA_ARGS__ \
  375. : "memory", "cc" EXTRA_CLOBBERS); \
  376. __ret = (rettype)((((u64)__edx) << 32) | __eax); \
  377. } else { \
  378. asm volatile(pre \
  379. paravirt_alt(PARAVIRT_CALL) \
  380. post \
  381. : PVOP_CALL_CLOBBERS \
  382. : paravirt_type(op), \
  383. paravirt_clobber(CLBR_ANY), \
  384. ##__VA_ARGS__ \
  385. : "memory", "cc" EXTRA_CLOBBERS); \
  386. __ret = (rettype)__eax; \
  387. } \
  388. __ret; \
  389. })
  390. #define __PVOP_VCALL(op, pre, post, ...) \
  391. ({ \
  392. PVOP_VCALL_ARGS; \
  393. asm volatile(pre \
  394. paravirt_alt(PARAVIRT_CALL) \
  395. post \
  396. : PVOP_VCALL_CLOBBERS \
  397. : paravirt_type(op), \
  398. paravirt_clobber(CLBR_ANY), \
  399. ##__VA_ARGS__ \
  400. : "memory", "cc" VEXTRA_CLOBBERS); \
  401. })
  402. #define PVOP_CALL0(rettype, op) \
  403. __PVOP_CALL(rettype, op, "", "")
  404. #define PVOP_VCALL0(op) \
  405. __PVOP_VCALL(op, "", "")
  406. #define PVOP_CALL1(rettype, op, arg1) \
  407. __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)))
  408. #define PVOP_VCALL1(op, arg1) \
  409. __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)))
  410. #define PVOP_CALL2(rettype, op, arg1, arg2) \
  411. __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)), \
  412. "1" ((unsigned long)(arg2)))
  413. #define PVOP_VCALL2(op, arg1, arg2) \
  414. __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)), \
  415. "1" ((unsigned long)(arg2)))
  416. #define PVOP_CALL3(rettype, op, arg1, arg2, arg3) \
  417. __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)), \
  418. "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)))
  419. #define PVOP_VCALL3(op, arg1, arg2, arg3) \
  420. __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)), \
  421. "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)))
  422. /* This is the only difference in x86_64. We can make it much simpler */
  423. #ifdef CONFIG_X86_32
  424. #define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
  425. __PVOP_CALL(rettype, op, \
  426. "push %[_arg4];", "lea 4(%%esp),%%esp;", \
  427. "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
  428. "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
  429. #define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
  430. __PVOP_VCALL(op, \
  431. "push %[_arg4];", "lea 4(%%esp),%%esp;", \
  432. "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
  433. "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
  434. #else
  435. #define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
  436. __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)), \
  437. "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)), \
  438. "3"((unsigned long)(arg4)))
  439. #define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
  440. __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)), \
  441. "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)), \
  442. "3"((unsigned long)(arg4)))
  443. #endif
  444. static inline int paravirt_enabled(void)
  445. {
  446. return pv_info.paravirt_enabled;
  447. }
  448. static inline void load_sp0(struct tss_struct *tss,
  449. struct thread_struct *thread)
  450. {
  451. PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
  452. }
  453. #define ARCH_SETUP pv_init_ops.arch_setup();
  454. static inline unsigned long get_wallclock(void)
  455. {
  456. return PVOP_CALL0(unsigned long, pv_time_ops.get_wallclock);
  457. }
  458. static inline int set_wallclock(unsigned long nowtime)
  459. {
  460. return PVOP_CALL1(int, pv_time_ops.set_wallclock, nowtime);
  461. }
  462. static inline void (*choose_time_init(void))(void)
  463. {
  464. return pv_time_ops.time_init;
  465. }
  466. /* The paravirtualized CPUID instruction. */
  467. static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
  468. unsigned int *ecx, unsigned int *edx)
  469. {
  470. PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
  471. }
  472. /*
  473. * These special macros can be used to get or set a debugging register
  474. */
  475. static inline unsigned long paravirt_get_debugreg(int reg)
  476. {
  477. return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
  478. }
  479. #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
  480. static inline void set_debugreg(unsigned long val, int reg)
  481. {
  482. PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
  483. }
  484. static inline void clts(void)
  485. {
  486. PVOP_VCALL0(pv_cpu_ops.clts);
  487. }
  488. static inline unsigned long read_cr0(void)
  489. {
  490. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
  491. }
  492. static inline void write_cr0(unsigned long x)
  493. {
  494. PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
  495. }
  496. static inline unsigned long read_cr2(void)
  497. {
  498. return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
  499. }
  500. static inline void write_cr2(unsigned long x)
  501. {
  502. PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
  503. }
  504. static inline unsigned long read_cr3(void)
  505. {
  506. return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
  507. }
  508. static inline void write_cr3(unsigned long x)
  509. {
  510. PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
  511. }
  512. static inline unsigned long read_cr4(void)
  513. {
  514. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
  515. }
  516. static inline unsigned long read_cr4_safe(void)
  517. {
  518. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
  519. }
  520. static inline void write_cr4(unsigned long x)
  521. {
  522. PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
  523. }
  524. static inline void raw_safe_halt(void)
  525. {
  526. PVOP_VCALL0(pv_irq_ops.safe_halt);
  527. }
  528. static inline void halt(void)
  529. {
  530. PVOP_VCALL0(pv_irq_ops.safe_halt);
  531. }
  532. static inline void wbinvd(void)
  533. {
  534. PVOP_VCALL0(pv_cpu_ops.wbinvd);
  535. }
  536. #define get_kernel_rpl() (pv_info.kernel_rpl)
  537. static inline u64 paravirt_read_msr(unsigned msr, int *err)
  538. {
  539. return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
  540. }
  541. static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
  542. {
  543. return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
  544. }
  545. /* These should all do BUG_ON(_err), but our headers are too tangled. */
  546. #define rdmsr(msr,val1,val2) do { \
  547. int _err; \
  548. u64 _l = paravirt_read_msr(msr, &_err); \
  549. val1 = (u32)_l; \
  550. val2 = _l >> 32; \
  551. } while(0)
  552. #define wrmsr(msr,val1,val2) do { \
  553. paravirt_write_msr(msr, val1, val2); \
  554. } while(0)
  555. #define rdmsrl(msr,val) do { \
  556. int _err; \
  557. val = paravirt_read_msr(msr, &_err); \
  558. } while(0)
  559. #define wrmsrl(msr,val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
  560. #define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
  561. /* rdmsr with exception handling */
  562. #define rdmsr_safe(msr,a,b) ({ \
  563. int _err; \
  564. u64 _l = paravirt_read_msr(msr, &_err); \
  565. (*a) = (u32)_l; \
  566. (*b) = _l >> 32; \
  567. _err; })
  568. static inline u64 paravirt_read_tsc(void)
  569. {
  570. return PVOP_CALL0(u64, pv_cpu_ops.read_tsc);
  571. }
  572. #define rdtscl(low) do { \
  573. u64 _l = paravirt_read_tsc(); \
  574. low = (int)_l; \
  575. } while(0)
  576. #define rdtscll(val) (val = paravirt_read_tsc())
  577. static inline unsigned long long paravirt_sched_clock(void)
  578. {
  579. return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
  580. }
  581. #define calculate_cpu_khz() (pv_time_ops.get_cpu_khz())
  582. static inline unsigned long long paravirt_read_pmc(int counter)
  583. {
  584. return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
  585. }
  586. #define rdpmc(counter,low,high) do { \
  587. u64 _l = paravirt_read_pmc(counter); \
  588. low = (u32)_l; \
  589. high = _l >> 32; \
  590. } while(0)
  591. static inline unsigned long long paravirt_rdtscp(unsigned int *aux)
  592. {
  593. return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux);
  594. }
  595. #define rdtscp(low, high, aux) \
  596. do { \
  597. int __aux; \
  598. unsigned long __val = paravirt_rdtscp(&__aux); \
  599. (low) = (u32)__val; \
  600. (high) = (u32)(__val >> 32); \
  601. (aux) = __aux; \
  602. } while (0)
  603. #define rdtscpll(val, aux) \
  604. do { \
  605. unsigned long __aux; \
  606. val = paravirt_rdtscp(&__aux); \
  607. (aux) = __aux; \
  608. } while (0)
  609. static inline void load_TR_desc(void)
  610. {
  611. PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
  612. }
  613. static inline void load_gdt(const struct desc_ptr *dtr)
  614. {
  615. PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
  616. }
  617. static inline void load_idt(const struct desc_ptr *dtr)
  618. {
  619. PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
  620. }
  621. static inline void set_ldt(const void *addr, unsigned entries)
  622. {
  623. PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
  624. }
  625. static inline void store_gdt(struct desc_ptr *dtr)
  626. {
  627. PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
  628. }
  629. static inline void store_idt(struct desc_ptr *dtr)
  630. {
  631. PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
  632. }
  633. static inline unsigned long paravirt_store_tr(void)
  634. {
  635. return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
  636. }
  637. #define store_tr(tr) ((tr) = paravirt_store_tr())
  638. static inline void load_TLS(struct thread_struct *t, unsigned cpu)
  639. {
  640. PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
  641. }
  642. static inline void write_ldt_entry(struct desc_struct *dt, int entry,
  643. const void *desc)
  644. {
  645. PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
  646. }
  647. static inline void write_gdt_entry(struct desc_struct *dt, int entry,
  648. void *desc, int type)
  649. {
  650. PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
  651. }
  652. static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
  653. {
  654. PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
  655. }
  656. static inline void set_iopl_mask(unsigned mask)
  657. {
  658. PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
  659. }
  660. /* The paravirtualized I/O functions */
  661. static inline void slow_down_io(void) {
  662. pv_cpu_ops.io_delay();
  663. #ifdef REALLY_SLOW_IO
  664. pv_cpu_ops.io_delay();
  665. pv_cpu_ops.io_delay();
  666. pv_cpu_ops.io_delay();
  667. #endif
  668. }
  669. #ifdef CONFIG_X86_LOCAL_APIC
  670. /*
  671. * Basic functions accessing APICs.
  672. */
  673. static inline void apic_write(unsigned long reg, u32 v)
  674. {
  675. PVOP_VCALL2(pv_apic_ops.apic_write, reg, v);
  676. }
  677. static inline void apic_write_atomic(unsigned long reg, u32 v)
  678. {
  679. PVOP_VCALL2(pv_apic_ops.apic_write_atomic, reg, v);
  680. }
  681. static inline u32 apic_read(unsigned long reg)
  682. {
  683. return PVOP_CALL1(unsigned long, pv_apic_ops.apic_read, reg);
  684. }
  685. static inline void setup_boot_clock(void)
  686. {
  687. PVOP_VCALL0(pv_apic_ops.setup_boot_clock);
  688. }
  689. static inline void setup_secondary_clock(void)
  690. {
  691. PVOP_VCALL0(pv_apic_ops.setup_secondary_clock);
  692. }
  693. #endif
  694. static inline void paravirt_post_allocator_init(void)
  695. {
  696. if (pv_init_ops.post_allocator_init)
  697. (*pv_init_ops.post_allocator_init)();
  698. }
  699. static inline void paravirt_pagetable_setup_start(pgd_t *base)
  700. {
  701. (*pv_mmu_ops.pagetable_setup_start)(base);
  702. }
  703. static inline void paravirt_pagetable_setup_done(pgd_t *base)
  704. {
  705. (*pv_mmu_ops.pagetable_setup_done)(base);
  706. }
  707. #ifdef CONFIG_SMP
  708. static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
  709. unsigned long start_esp)
  710. {
  711. PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
  712. phys_apicid, start_eip, start_esp);
  713. }
  714. #endif
  715. static inline void paravirt_activate_mm(struct mm_struct *prev,
  716. struct mm_struct *next)
  717. {
  718. PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
  719. }
  720. static inline void arch_dup_mmap(struct mm_struct *oldmm,
  721. struct mm_struct *mm)
  722. {
  723. PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
  724. }
  725. static inline void arch_exit_mmap(struct mm_struct *mm)
  726. {
  727. PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
  728. }
  729. static inline void __flush_tlb(void)
  730. {
  731. PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
  732. }
  733. static inline void __flush_tlb_global(void)
  734. {
  735. PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
  736. }
  737. static inline void __flush_tlb_single(unsigned long addr)
  738. {
  739. PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
  740. }
  741. static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
  742. unsigned long va)
  743. {
  744. PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, &cpumask, mm, va);
  745. }
  746. static inline void paravirt_alloc_pt(struct mm_struct *mm, unsigned pfn)
  747. {
  748. PVOP_VCALL2(pv_mmu_ops.alloc_pt, mm, pfn);
  749. }
  750. static inline void paravirt_release_pt(unsigned pfn)
  751. {
  752. PVOP_VCALL1(pv_mmu_ops.release_pt, pfn);
  753. }
  754. static inline void paravirt_alloc_pd(unsigned pfn)
  755. {
  756. PVOP_VCALL1(pv_mmu_ops.alloc_pd, pfn);
  757. }
  758. static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
  759. unsigned start, unsigned count)
  760. {
  761. PVOP_VCALL4(pv_mmu_ops.alloc_pd_clone, pfn, clonepfn, start, count);
  762. }
  763. static inline void paravirt_release_pd(unsigned pfn)
  764. {
  765. PVOP_VCALL1(pv_mmu_ops.release_pd, pfn);
  766. }
  767. #ifdef CONFIG_HIGHPTE
  768. static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
  769. {
  770. unsigned long ret;
  771. ret = PVOP_CALL2(unsigned long, pv_mmu_ops.kmap_atomic_pte, page, type);
  772. return (void *)ret;
  773. }
  774. #endif
  775. static inline void pte_update(struct mm_struct *mm, unsigned long addr,
  776. pte_t *ptep)
  777. {
  778. PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
  779. }
  780. static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
  781. pte_t *ptep)
  782. {
  783. PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
  784. }
  785. #ifdef CONFIG_X86_PAE
  786. static inline pte_t __pte(unsigned long long val)
  787. {
  788. unsigned long long ret = PVOP_CALL2(unsigned long long,
  789. pv_mmu_ops.make_pte,
  790. val, val >> 32);
  791. return (pte_t) { ret, ret >> 32 };
  792. }
  793. static inline pmd_t __pmd(unsigned long long val)
  794. {
  795. return (pmd_t) { PVOP_CALL2(unsigned long long, pv_mmu_ops.make_pmd,
  796. val, val >> 32) };
  797. }
  798. static inline pgd_t __pgd(unsigned long long val)
  799. {
  800. return (pgd_t) { PVOP_CALL2(unsigned long long, pv_mmu_ops.make_pgd,
  801. val, val >> 32) };
  802. }
  803. static inline unsigned long long pte_val(pte_t x)
  804. {
  805. return PVOP_CALL2(unsigned long long, pv_mmu_ops.pte_val,
  806. x.pte_low, x.pte_high);
  807. }
  808. static inline unsigned long long pmd_val(pmd_t x)
  809. {
  810. return PVOP_CALL2(unsigned long long, pv_mmu_ops.pmd_val,
  811. x.pmd, x.pmd >> 32);
  812. }
  813. static inline unsigned long long pgd_val(pgd_t x)
  814. {
  815. return PVOP_CALL2(unsigned long long, pv_mmu_ops.pgd_val,
  816. x.pgd, x.pgd >> 32);
  817. }
  818. static inline void set_pte(pte_t *ptep, pte_t pteval)
  819. {
  820. PVOP_VCALL3(pv_mmu_ops.set_pte, ptep, pteval.pte_low, pteval.pte_high);
  821. }
  822. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  823. pte_t *ptep, pte_t pteval)
  824. {
  825. /* 5 arg words */
  826. pv_mmu_ops.set_pte_at(mm, addr, ptep, pteval);
  827. }
  828. static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
  829. {
  830. PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
  831. pteval.pte_low, pteval.pte_high);
  832. }
  833. static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
  834. pte_t *ptep, pte_t pte)
  835. {
  836. /* 5 arg words */
  837. pv_mmu_ops.set_pte_present(mm, addr, ptep, pte);
  838. }
  839. static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
  840. {
  841. PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp,
  842. pmdval.pmd, pmdval.pmd >> 32);
  843. }
  844. static inline void set_pud(pud_t *pudp, pud_t pudval)
  845. {
  846. PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
  847. pudval.pgd.pgd, pudval.pgd.pgd >> 32);
  848. }
  849. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  850. {
  851. PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
  852. }
  853. static inline void pmd_clear(pmd_t *pmdp)
  854. {
  855. PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
  856. }
  857. #else /* !CONFIG_X86_PAE */
  858. static inline pte_t __pte(unsigned long val)
  859. {
  860. return (pte_t) { PVOP_CALL1(unsigned long, pv_mmu_ops.make_pte, val) };
  861. }
  862. static inline pgd_t __pgd(unsigned long val)
  863. {
  864. return (pgd_t) { PVOP_CALL1(unsigned long, pv_mmu_ops.make_pgd, val) };
  865. }
  866. static inline unsigned long pte_val(pte_t x)
  867. {
  868. return PVOP_CALL1(unsigned long, pv_mmu_ops.pte_val, x.pte_low);
  869. }
  870. static inline unsigned long pgd_val(pgd_t x)
  871. {
  872. return PVOP_CALL1(unsigned long, pv_mmu_ops.pgd_val, x.pgd);
  873. }
  874. static inline void set_pte(pte_t *ptep, pte_t pteval)
  875. {
  876. PVOP_VCALL2(pv_mmu_ops.set_pte, ptep, pteval.pte_low);
  877. }
  878. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  879. pte_t *ptep, pte_t pteval)
  880. {
  881. PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pteval.pte_low);
  882. }
  883. static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
  884. {
  885. PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, pmdval.pud.pgd.pgd);
  886. }
  887. #endif /* CONFIG_X86_PAE */
  888. /* Lazy mode for batching updates / context switch */
  889. enum paravirt_lazy_mode {
  890. PARAVIRT_LAZY_NONE,
  891. PARAVIRT_LAZY_MMU,
  892. PARAVIRT_LAZY_CPU,
  893. };
  894. enum paravirt_lazy_mode paravirt_get_lazy_mode(void);
  895. void paravirt_enter_lazy_cpu(void);
  896. void paravirt_leave_lazy_cpu(void);
  897. void paravirt_enter_lazy_mmu(void);
  898. void paravirt_leave_lazy_mmu(void);
  899. void paravirt_leave_lazy(enum paravirt_lazy_mode mode);
  900. #define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
  901. static inline void arch_enter_lazy_cpu_mode(void)
  902. {
  903. PVOP_VCALL0(pv_cpu_ops.lazy_mode.enter);
  904. }
  905. static inline void arch_leave_lazy_cpu_mode(void)
  906. {
  907. PVOP_VCALL0(pv_cpu_ops.lazy_mode.leave);
  908. }
  909. static inline void arch_flush_lazy_cpu_mode(void)
  910. {
  911. if (unlikely(paravirt_get_lazy_mode() == PARAVIRT_LAZY_CPU)) {
  912. arch_leave_lazy_cpu_mode();
  913. arch_enter_lazy_cpu_mode();
  914. }
  915. }
  916. #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
  917. static inline void arch_enter_lazy_mmu_mode(void)
  918. {
  919. PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
  920. }
  921. static inline void arch_leave_lazy_mmu_mode(void)
  922. {
  923. PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
  924. }
  925. static inline void arch_flush_lazy_mmu_mode(void)
  926. {
  927. if (unlikely(paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU)) {
  928. arch_leave_lazy_mmu_mode();
  929. arch_enter_lazy_mmu_mode();
  930. }
  931. }
  932. void _paravirt_nop(void);
  933. #define paravirt_nop ((void *)_paravirt_nop)
  934. /* These all sit in the .parainstructions section to tell us what to patch. */
  935. struct paravirt_patch_site {
  936. u8 *instr; /* original instructions */
  937. u8 instrtype; /* type of this instruction */
  938. u8 len; /* length of original instruction */
  939. u16 clobbers; /* what registers you may clobber */
  940. };
  941. extern struct paravirt_patch_site __parainstructions[],
  942. __parainstructions_end[];
  943. #ifdef CONFIG_X86_32
  944. #define PV_SAVE_REGS "pushl %%ecx; pushl %%edx;"
  945. #define PV_RESTORE_REGS "popl %%edx; popl %%ecx"
  946. #define PV_FLAGS_ARG "0"
  947. #define PV_EXTRA_CLOBBERS
  948. #define PV_VEXTRA_CLOBBERS
  949. #else
  950. /* We save some registers, but all of them, that's too much. We clobber all
  951. * caller saved registers but the argument parameter */
  952. #define PV_SAVE_REGS "pushq %%rdi;"
  953. #define PV_RESTORE_REGS "popq %%rdi;"
  954. #define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx"
  955. #define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx"
  956. #define PV_FLAGS_ARG "D"
  957. #endif
  958. static inline unsigned long __raw_local_save_flags(void)
  959. {
  960. unsigned long f;
  961. asm volatile(paravirt_alt(PV_SAVE_REGS
  962. PARAVIRT_CALL
  963. PV_RESTORE_REGS)
  964. : "=a"(f)
  965. : paravirt_type(pv_irq_ops.save_fl),
  966. paravirt_clobber(CLBR_EAX)
  967. : "memory", "cc" PV_VEXTRA_CLOBBERS);
  968. return f;
  969. }
  970. static inline void raw_local_irq_restore(unsigned long f)
  971. {
  972. asm volatile(paravirt_alt(PV_SAVE_REGS
  973. PARAVIRT_CALL
  974. PV_RESTORE_REGS)
  975. : "=a"(f)
  976. : PV_FLAGS_ARG(f),
  977. paravirt_type(pv_irq_ops.restore_fl),
  978. paravirt_clobber(CLBR_EAX)
  979. : "memory", "cc" PV_EXTRA_CLOBBERS);
  980. }
  981. static inline void raw_local_irq_disable(void)
  982. {
  983. asm volatile(paravirt_alt(PV_SAVE_REGS
  984. PARAVIRT_CALL
  985. PV_RESTORE_REGS)
  986. :
  987. : paravirt_type(pv_irq_ops.irq_disable),
  988. paravirt_clobber(CLBR_EAX)
  989. : "memory", "eax", "cc" PV_EXTRA_CLOBBERS);
  990. }
  991. static inline void raw_local_irq_enable(void)
  992. {
  993. asm volatile(paravirt_alt(PV_SAVE_REGS
  994. PARAVIRT_CALL
  995. PV_RESTORE_REGS)
  996. :
  997. : paravirt_type(pv_irq_ops.irq_enable),
  998. paravirt_clobber(CLBR_EAX)
  999. : "memory", "eax", "cc" PV_EXTRA_CLOBBERS);
  1000. }
  1001. static inline unsigned long __raw_local_irq_save(void)
  1002. {
  1003. unsigned long f;
  1004. f = __raw_local_save_flags();
  1005. raw_local_irq_disable();
  1006. return f;
  1007. }
  1008. /* Make sure as little as possible of this mess escapes. */
  1009. #undef PARAVIRT_CALL
  1010. #undef __PVOP_CALL
  1011. #undef __PVOP_VCALL
  1012. #undef PVOP_VCALL0
  1013. #undef PVOP_CALL0
  1014. #undef PVOP_VCALL1
  1015. #undef PVOP_CALL1
  1016. #undef PVOP_VCALL2
  1017. #undef PVOP_CALL2
  1018. #undef PVOP_VCALL3
  1019. #undef PVOP_CALL3
  1020. #undef PVOP_VCALL4
  1021. #undef PVOP_CALL4
  1022. #else /* __ASSEMBLY__ */
  1023. #define _PVSITE(ptype, clobbers, ops, word, algn) \
  1024. 771:; \
  1025. ops; \
  1026. 772:; \
  1027. .pushsection .parainstructions,"a"; \
  1028. .align algn; \
  1029. word 771b; \
  1030. .byte ptype; \
  1031. .byte 772b-771b; \
  1032. .short clobbers; \
  1033. .popsection
  1034. #ifdef CONFIG_X86_64
  1035. #define PV_SAVE_REGS pushq %rax; pushq %rdi; pushq %rcx; pushq %rdx
  1036. #define PV_RESTORE_REGS popq %rdx; popq %rcx; popq %rdi; popq %rax
  1037. #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
  1038. #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
  1039. #else
  1040. #define PV_SAVE_REGS pushl %eax; pushl %edi; pushl %ecx; pushl %edx
  1041. #define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax
  1042. #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
  1043. #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
  1044. #endif
  1045. #define INTERRUPT_RETURN \
  1046. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
  1047. jmp *%cs:pv_cpu_ops+PV_CPU_iret)
  1048. #define DISABLE_INTERRUPTS(clobbers) \
  1049. PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
  1050. PV_SAVE_REGS; \
  1051. call *%cs:pv_irq_ops+PV_IRQ_irq_disable; \
  1052. PV_RESTORE_REGS;) \
  1053. #define ENABLE_INTERRUPTS(clobbers) \
  1054. PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
  1055. PV_SAVE_REGS; \
  1056. call *%cs:pv_irq_ops+PV_IRQ_irq_enable; \
  1057. PV_RESTORE_REGS;)
  1058. #define ENABLE_INTERRUPTS_SYSCALL_RET \
  1059. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_syscall_ret),\
  1060. CLBR_NONE, \
  1061. jmp *%cs:pv_cpu_ops+PV_CPU_irq_enable_syscall_ret)
  1062. #ifdef CONFIG_X86_32
  1063. #define GET_CR0_INTO_EAX \
  1064. push %ecx; push %edx; \
  1065. call *pv_cpu_ops+PV_CPU_read_cr0; \
  1066. pop %edx; pop %ecx
  1067. #else
  1068. #define SWAPGS \
  1069. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
  1070. PV_SAVE_REGS; \
  1071. call *pv_cpu_ops+PV_CPU_swapgs; \
  1072. PV_RESTORE_REGS \
  1073. )
  1074. #define GET_CR2_INTO_RCX \
  1075. call *pv_mmu_ops+PV_MMU_read_cr2; \
  1076. movq %rax, %rcx; \
  1077. xorq %rax, %rax;
  1078. #endif
  1079. #endif /* __ASSEMBLY__ */
  1080. #endif /* CONFIG_PARAVIRT */
  1081. #endif /* __ASM_PARAVIRT_H */