paravirt.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. #ifndef _ASM_X86_PARAVIRT_H
  2. #define _ASM_X86_PARAVIRT_H
  3. /* Various instructions on x86 need to be replaced for
  4. * para-virtualization: those hooks are defined here. */
  5. #ifdef CONFIG_PARAVIRT
  6. #include <asm/pgtable_types.h>
  7. #include <asm/asm.h>
  8. #include <asm/paravirt_types.h>
  9. #ifndef __ASSEMBLY__
  10. #include <linux/bug.h>
  11. #include <linux/types.h>
  12. #include <linux/cpumask.h>
  13. #include <asm/frame.h>
  14. static inline void load_sp0(struct tss_struct *tss,
  15. struct thread_struct *thread)
  16. {
  17. PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
  18. }
  19. /* The paravirtualized CPUID instruction. */
  20. static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
  21. unsigned int *ecx, unsigned int *edx)
  22. {
  23. PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
  24. }
  25. /*
  26. * These special macros can be used to get or set a debugging register
  27. */
  28. static inline unsigned long paravirt_get_debugreg(int reg)
  29. {
  30. return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
  31. }
  32. #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
  33. static inline void set_debugreg(unsigned long val, int reg)
  34. {
  35. PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
  36. }
  37. static inline void clts(void)
  38. {
  39. PVOP_VCALL0(pv_cpu_ops.clts);
  40. }
  41. static inline unsigned long read_cr0(void)
  42. {
  43. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
  44. }
  45. static inline void write_cr0(unsigned long x)
  46. {
  47. PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
  48. }
  49. static inline unsigned long read_cr2(void)
  50. {
  51. return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
  52. }
  53. static inline void write_cr2(unsigned long x)
  54. {
  55. PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
  56. }
  57. static inline unsigned long read_cr3(void)
  58. {
  59. return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
  60. }
  61. static inline void write_cr3(unsigned long x)
  62. {
  63. PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
  64. }
  65. static inline unsigned long __read_cr4(void)
  66. {
  67. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
  68. }
  69. static inline void __write_cr4(unsigned long x)
  70. {
  71. PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
  72. }
  73. #ifdef CONFIG_X86_64
  74. static inline unsigned long read_cr8(void)
  75. {
  76. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8);
  77. }
  78. static inline void write_cr8(unsigned long x)
  79. {
  80. PVOP_VCALL1(pv_cpu_ops.write_cr8, x);
  81. }
  82. #endif
  83. static inline void arch_safe_halt(void)
  84. {
  85. PVOP_VCALL0(pv_irq_ops.safe_halt);
  86. }
  87. static inline void halt(void)
  88. {
  89. PVOP_VCALL0(pv_irq_ops.halt);
  90. }
  91. static inline void wbinvd(void)
  92. {
  93. PVOP_VCALL0(pv_cpu_ops.wbinvd);
  94. }
  95. #define get_kernel_rpl() (pv_info.kernel_rpl)
  96. static inline u64 paravirt_read_msr(unsigned msr)
  97. {
  98. return PVOP_CALL1(u64, pv_cpu_ops.read_msr, msr);
  99. }
  100. static inline void paravirt_write_msr(unsigned msr,
  101. unsigned low, unsigned high)
  102. {
  103. return PVOP_VCALL3(pv_cpu_ops.write_msr, msr, low, high);
  104. }
  105. static inline u64 paravirt_read_msr_safe(unsigned msr, int *err)
  106. {
  107. return PVOP_CALL2(u64, pv_cpu_ops.read_msr_safe, msr, err);
  108. }
  109. static inline int paravirt_write_msr_safe(unsigned msr,
  110. unsigned low, unsigned high)
  111. {
  112. return PVOP_CALL3(int, pv_cpu_ops.write_msr_safe, msr, low, high);
  113. }
  114. #define rdmsr(msr, val1, val2) \
  115. do { \
  116. u64 _l = paravirt_read_msr(msr); \
  117. val1 = (u32)_l; \
  118. val2 = _l >> 32; \
  119. } while (0)
  120. #define wrmsr(msr, val1, val2) \
  121. do { \
  122. paravirt_write_msr(msr, val1, val2); \
  123. } while (0)
  124. #define rdmsrl(msr, val) \
  125. do { \
  126. val = paravirt_read_msr(msr); \
  127. } while (0)
  128. static inline void wrmsrl(unsigned msr, u64 val)
  129. {
  130. wrmsr(msr, (u32)val, (u32)(val>>32));
  131. }
  132. #define wrmsr_safe(msr, a, b) paravirt_write_msr_safe(msr, a, b)
  133. /* rdmsr with exception handling */
  134. #define rdmsr_safe(msr, a, b) \
  135. ({ \
  136. int _err; \
  137. u64 _l = paravirt_read_msr_safe(msr, &_err); \
  138. (*a) = (u32)_l; \
  139. (*b) = _l >> 32; \
  140. _err; \
  141. })
  142. static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
  143. {
  144. int err;
  145. *p = paravirt_read_msr_safe(msr, &err);
  146. return err;
  147. }
  148. static inline unsigned long long paravirt_sched_clock(void)
  149. {
  150. return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
  151. }
  152. struct static_key;
  153. extern struct static_key paravirt_steal_enabled;
  154. extern struct static_key paravirt_steal_rq_enabled;
  155. static inline u64 paravirt_steal_clock(int cpu)
  156. {
  157. return PVOP_CALL1(u64, pv_time_ops.steal_clock, cpu);
  158. }
  159. static inline unsigned long long paravirt_read_pmc(int counter)
  160. {
  161. return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
  162. }
  163. #define rdpmc(counter, low, high) \
  164. do { \
  165. u64 _l = paravirt_read_pmc(counter); \
  166. low = (u32)_l; \
  167. high = _l >> 32; \
  168. } while (0)
  169. #define rdpmcl(counter, val) ((val) = paravirt_read_pmc(counter))
  170. static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
  171. {
  172. PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries);
  173. }
  174. static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
  175. {
  176. PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries);
  177. }
  178. static inline void load_TR_desc(void)
  179. {
  180. PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
  181. }
  182. static inline void load_gdt(const struct desc_ptr *dtr)
  183. {
  184. PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
  185. }
  186. static inline void load_idt(const struct desc_ptr *dtr)
  187. {
  188. PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
  189. }
  190. static inline void set_ldt(const void *addr, unsigned entries)
  191. {
  192. PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
  193. }
  194. static inline void store_idt(struct desc_ptr *dtr)
  195. {
  196. PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
  197. }
  198. static inline unsigned long paravirt_store_tr(void)
  199. {
  200. return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
  201. }
  202. #define store_tr(tr) ((tr) = paravirt_store_tr())
  203. static inline void load_TLS(struct thread_struct *t, unsigned cpu)
  204. {
  205. PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
  206. }
  207. #ifdef CONFIG_X86_64
  208. static inline void load_gs_index(unsigned int gs)
  209. {
  210. PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
  211. }
  212. #endif
  213. static inline void write_ldt_entry(struct desc_struct *dt, int entry,
  214. const void *desc)
  215. {
  216. PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
  217. }
  218. static inline void write_gdt_entry(struct desc_struct *dt, int entry,
  219. void *desc, int type)
  220. {
  221. PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
  222. }
  223. static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
  224. {
  225. PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
  226. }
  227. static inline void set_iopl_mask(unsigned mask)
  228. {
  229. PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
  230. }
  231. /* The paravirtualized I/O functions */
  232. static inline void slow_down_io(void)
  233. {
  234. pv_cpu_ops.io_delay();
  235. #ifdef REALLY_SLOW_IO
  236. pv_cpu_ops.io_delay();
  237. pv_cpu_ops.io_delay();
  238. pv_cpu_ops.io_delay();
  239. #endif
  240. }
  241. static inline void paravirt_activate_mm(struct mm_struct *prev,
  242. struct mm_struct *next)
  243. {
  244. PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
  245. }
  246. static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm,
  247. struct mm_struct *mm)
  248. {
  249. PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
  250. }
  251. static inline void paravirt_arch_exit_mmap(struct mm_struct *mm)
  252. {
  253. PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
  254. }
  255. static inline void __flush_tlb(void)
  256. {
  257. PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
  258. }
  259. static inline void __flush_tlb_global(void)
  260. {
  261. PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
  262. }
  263. static inline void __flush_tlb_single(unsigned long addr)
  264. {
  265. PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
  266. }
  267. static inline void flush_tlb_others(const struct cpumask *cpumask,
  268. struct mm_struct *mm,
  269. unsigned long start,
  270. unsigned long end)
  271. {
  272. PVOP_VCALL4(pv_mmu_ops.flush_tlb_others, cpumask, mm, start, end);
  273. }
  274. static inline int paravirt_pgd_alloc(struct mm_struct *mm)
  275. {
  276. return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
  277. }
  278. static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
  279. {
  280. PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
  281. }
  282. static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
  283. {
  284. PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
  285. }
  286. static inline void paravirt_release_pte(unsigned long pfn)
  287. {
  288. PVOP_VCALL1(pv_mmu_ops.release_pte, pfn);
  289. }
  290. static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
  291. {
  292. PVOP_VCALL2(pv_mmu_ops.alloc_pmd, mm, pfn);
  293. }
  294. static inline void paravirt_release_pmd(unsigned long pfn)
  295. {
  296. PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn);
  297. }
  298. static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
  299. {
  300. PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn);
  301. }
  302. static inline void paravirt_release_pud(unsigned long pfn)
  303. {
  304. PVOP_VCALL1(pv_mmu_ops.release_pud, pfn);
  305. }
  306. static inline void pte_update(struct mm_struct *mm, unsigned long addr,
  307. pte_t *ptep)
  308. {
  309. PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
  310. }
  311. static inline pte_t __pte(pteval_t val)
  312. {
  313. pteval_t ret;
  314. if (sizeof(pteval_t) > sizeof(long))
  315. ret = PVOP_CALLEE2(pteval_t,
  316. pv_mmu_ops.make_pte,
  317. val, (u64)val >> 32);
  318. else
  319. ret = PVOP_CALLEE1(pteval_t,
  320. pv_mmu_ops.make_pte,
  321. val);
  322. return (pte_t) { .pte = ret };
  323. }
  324. static inline pteval_t pte_val(pte_t pte)
  325. {
  326. pteval_t ret;
  327. if (sizeof(pteval_t) > sizeof(long))
  328. ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val,
  329. pte.pte, (u64)pte.pte >> 32);
  330. else
  331. ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val,
  332. pte.pte);
  333. return ret;
  334. }
  335. static inline pgd_t __pgd(pgdval_t val)
  336. {
  337. pgdval_t ret;
  338. if (sizeof(pgdval_t) > sizeof(long))
  339. ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd,
  340. val, (u64)val >> 32);
  341. else
  342. ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd,
  343. val);
  344. return (pgd_t) { ret };
  345. }
  346. static inline pgdval_t pgd_val(pgd_t pgd)
  347. {
  348. pgdval_t ret;
  349. if (sizeof(pgdval_t) > sizeof(long))
  350. ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val,
  351. pgd.pgd, (u64)pgd.pgd >> 32);
  352. else
  353. ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val,
  354. pgd.pgd);
  355. return ret;
  356. }
  357. #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
  358. static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
  359. pte_t *ptep)
  360. {
  361. pteval_t ret;
  362. ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
  363. mm, addr, ptep);
  364. return (pte_t) { .pte = ret };
  365. }
  366. static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
  367. pte_t *ptep, pte_t pte)
  368. {
  369. if (sizeof(pteval_t) > sizeof(long))
  370. /* 5 arg words */
  371. pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
  372. else
  373. PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
  374. mm, addr, ptep, pte.pte);
  375. }
  376. static inline void set_pte(pte_t *ptep, pte_t pte)
  377. {
  378. if (sizeof(pteval_t) > sizeof(long))
  379. PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
  380. pte.pte, (u64)pte.pte >> 32);
  381. else
  382. PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
  383. pte.pte);
  384. }
  385. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  386. pte_t *ptep, pte_t pte)
  387. {
  388. if (sizeof(pteval_t) > sizeof(long))
  389. /* 5 arg words */
  390. pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
  391. else
  392. PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
  393. }
  394. static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  395. pmd_t *pmdp, pmd_t pmd)
  396. {
  397. if (sizeof(pmdval_t) > sizeof(long))
  398. /* 5 arg words */
  399. pv_mmu_ops.set_pmd_at(mm, addr, pmdp, pmd);
  400. else
  401. PVOP_VCALL4(pv_mmu_ops.set_pmd_at, mm, addr, pmdp,
  402. native_pmd_val(pmd));
  403. }
  404. static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
  405. {
  406. pmdval_t val = native_pmd_val(pmd);
  407. if (sizeof(pmdval_t) > sizeof(long))
  408. PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
  409. else
  410. PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
  411. }
  412. #if CONFIG_PGTABLE_LEVELS >= 3
  413. static inline pmd_t __pmd(pmdval_t val)
  414. {
  415. pmdval_t ret;
  416. if (sizeof(pmdval_t) > sizeof(long))
  417. ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd,
  418. val, (u64)val >> 32);
  419. else
  420. ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd,
  421. val);
  422. return (pmd_t) { ret };
  423. }
  424. static inline pmdval_t pmd_val(pmd_t pmd)
  425. {
  426. pmdval_t ret;
  427. if (sizeof(pmdval_t) > sizeof(long))
  428. ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val,
  429. pmd.pmd, (u64)pmd.pmd >> 32);
  430. else
  431. ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val,
  432. pmd.pmd);
  433. return ret;
  434. }
  435. static inline void set_pud(pud_t *pudp, pud_t pud)
  436. {
  437. pudval_t val = native_pud_val(pud);
  438. if (sizeof(pudval_t) > sizeof(long))
  439. PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
  440. val, (u64)val >> 32);
  441. else
  442. PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
  443. val);
  444. }
  445. #if CONFIG_PGTABLE_LEVELS == 4
  446. static inline pud_t __pud(pudval_t val)
  447. {
  448. pudval_t ret;
  449. if (sizeof(pudval_t) > sizeof(long))
  450. ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud,
  451. val, (u64)val >> 32);
  452. else
  453. ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud,
  454. val);
  455. return (pud_t) { ret };
  456. }
  457. static inline pudval_t pud_val(pud_t pud)
  458. {
  459. pudval_t ret;
  460. if (sizeof(pudval_t) > sizeof(long))
  461. ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val,
  462. pud.pud, (u64)pud.pud >> 32);
  463. else
  464. ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val,
  465. pud.pud);
  466. return ret;
  467. }
  468. static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
  469. {
  470. pgdval_t val = native_pgd_val(pgd);
  471. if (sizeof(pgdval_t) > sizeof(long))
  472. PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
  473. val, (u64)val >> 32);
  474. else
  475. PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
  476. val);
  477. }
  478. static inline void pgd_clear(pgd_t *pgdp)
  479. {
  480. set_pgd(pgdp, __pgd(0));
  481. }
  482. static inline void pud_clear(pud_t *pudp)
  483. {
  484. set_pud(pudp, __pud(0));
  485. }
  486. #endif /* CONFIG_PGTABLE_LEVELS == 4 */
  487. #endif /* CONFIG_PGTABLE_LEVELS >= 3 */
  488. #ifdef CONFIG_X86_PAE
  489. /* Special-case pte-setting operations for PAE, which can't update a
  490. 64-bit pte atomically */
  491. static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
  492. {
  493. PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
  494. pte.pte, pte.pte >> 32);
  495. }
  496. static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
  497. pte_t *ptep)
  498. {
  499. PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
  500. }
  501. static inline void pmd_clear(pmd_t *pmdp)
  502. {
  503. PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
  504. }
  505. #else /* !CONFIG_X86_PAE */
  506. static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
  507. {
  508. set_pte(ptep, pte);
  509. }
  510. static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
  511. pte_t *ptep)
  512. {
  513. set_pte_at(mm, addr, ptep, __pte(0));
  514. }
  515. static inline void pmd_clear(pmd_t *pmdp)
  516. {
  517. set_pmd(pmdp, __pmd(0));
  518. }
  519. #endif /* CONFIG_X86_PAE */
  520. #define __HAVE_ARCH_START_CONTEXT_SWITCH
  521. static inline void arch_start_context_switch(struct task_struct *prev)
  522. {
  523. PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
  524. }
  525. static inline void arch_end_context_switch(struct task_struct *next)
  526. {
  527. PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
  528. }
  529. #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
  530. static inline void arch_enter_lazy_mmu_mode(void)
  531. {
  532. PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
  533. }
  534. static inline void arch_leave_lazy_mmu_mode(void)
  535. {
  536. PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
  537. }
  538. static inline void arch_flush_lazy_mmu_mode(void)
  539. {
  540. PVOP_VCALL0(pv_mmu_ops.lazy_mode.flush);
  541. }
  542. static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
  543. phys_addr_t phys, pgprot_t flags)
  544. {
  545. pv_mmu_ops.set_fixmap(idx, phys, flags);
  546. }
  547. #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
  548. static __always_inline void pv_queued_spin_lock_slowpath(struct qspinlock *lock,
  549. u32 val)
  550. {
  551. PVOP_VCALL2(pv_lock_ops.queued_spin_lock_slowpath, lock, val);
  552. }
  553. static __always_inline void pv_queued_spin_unlock(struct qspinlock *lock)
  554. {
  555. PVOP_VCALLEE1(pv_lock_ops.queued_spin_unlock, lock);
  556. }
  557. static __always_inline void pv_wait(u8 *ptr, u8 val)
  558. {
  559. PVOP_VCALL2(pv_lock_ops.wait, ptr, val);
  560. }
  561. static __always_inline void pv_kick(int cpu)
  562. {
  563. PVOP_VCALL1(pv_lock_ops.kick, cpu);
  564. }
  565. #endif /* SMP && PARAVIRT_SPINLOCKS */
  566. #ifdef CONFIG_X86_32
  567. #define PV_SAVE_REGS "pushl %ecx; pushl %edx;"
  568. #define PV_RESTORE_REGS "popl %edx; popl %ecx;"
  569. /* save and restore all caller-save registers, except return value */
  570. #define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
  571. #define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
  572. #define PV_FLAGS_ARG "0"
  573. #define PV_EXTRA_CLOBBERS
  574. #define PV_VEXTRA_CLOBBERS
  575. #else
  576. /* save and restore all caller-save registers, except return value */
  577. #define PV_SAVE_ALL_CALLER_REGS \
  578. "push %rcx;" \
  579. "push %rdx;" \
  580. "push %rsi;" \
  581. "push %rdi;" \
  582. "push %r8;" \
  583. "push %r9;" \
  584. "push %r10;" \
  585. "push %r11;"
  586. #define PV_RESTORE_ALL_CALLER_REGS \
  587. "pop %r11;" \
  588. "pop %r10;" \
  589. "pop %r9;" \
  590. "pop %r8;" \
  591. "pop %rdi;" \
  592. "pop %rsi;" \
  593. "pop %rdx;" \
  594. "pop %rcx;"
  595. /* We save some registers, but all of them, that's too much. We clobber all
  596. * caller saved registers but the argument parameter */
  597. #define PV_SAVE_REGS "pushq %%rdi;"
  598. #define PV_RESTORE_REGS "popq %%rdi;"
  599. #define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi"
  600. #define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi"
  601. #define PV_FLAGS_ARG "D"
  602. #endif
  603. /*
  604. * Generate a thunk around a function which saves all caller-save
  605. * registers except for the return value. This allows C functions to
  606. * be called from assembler code where fewer than normal registers are
  607. * available. It may also help code generation around calls from C
  608. * code if the common case doesn't use many registers.
  609. *
  610. * When a callee is wrapped in a thunk, the caller can assume that all
  611. * arg regs and all scratch registers are preserved across the
  612. * call. The return value in rax/eax will not be saved, even for void
  613. * functions.
  614. */
  615. #define PV_THUNK_NAME(func) "__raw_callee_save_" #func
  616. #define PV_CALLEE_SAVE_REGS_THUNK(func) \
  617. extern typeof(func) __raw_callee_save_##func; \
  618. \
  619. asm(".pushsection .text;" \
  620. ".globl " PV_THUNK_NAME(func) ";" \
  621. ".type " PV_THUNK_NAME(func) ", @function;" \
  622. PV_THUNK_NAME(func) ":" \
  623. FRAME_BEGIN \
  624. PV_SAVE_ALL_CALLER_REGS \
  625. "call " #func ";" \
  626. PV_RESTORE_ALL_CALLER_REGS \
  627. FRAME_END \
  628. "ret;" \
  629. ".popsection")
  630. /* Get a reference to a callee-save function */
  631. #define PV_CALLEE_SAVE(func) \
  632. ((struct paravirt_callee_save) { __raw_callee_save_##func })
  633. /* Promise that "func" already uses the right calling convention */
  634. #define __PV_IS_CALLEE_SAVE(func) \
  635. ((struct paravirt_callee_save) { func })
  636. static inline notrace unsigned long arch_local_save_flags(void)
  637. {
  638. return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl);
  639. }
  640. static inline notrace void arch_local_irq_restore(unsigned long f)
  641. {
  642. PVOP_VCALLEE1(pv_irq_ops.restore_fl, f);
  643. }
  644. static inline notrace void arch_local_irq_disable(void)
  645. {
  646. PVOP_VCALLEE0(pv_irq_ops.irq_disable);
  647. }
  648. static inline notrace void arch_local_irq_enable(void)
  649. {
  650. PVOP_VCALLEE0(pv_irq_ops.irq_enable);
  651. }
  652. static inline notrace unsigned long arch_local_irq_save(void)
  653. {
  654. unsigned long f;
  655. f = arch_local_save_flags();
  656. arch_local_irq_disable();
  657. return f;
  658. }
  659. /* Make sure as little as possible of this mess escapes. */
  660. #undef PARAVIRT_CALL
  661. #undef __PVOP_CALL
  662. #undef __PVOP_VCALL
  663. #undef PVOP_VCALL0
  664. #undef PVOP_CALL0
  665. #undef PVOP_VCALL1
  666. #undef PVOP_CALL1
  667. #undef PVOP_VCALL2
  668. #undef PVOP_CALL2
  669. #undef PVOP_VCALL3
  670. #undef PVOP_CALL3
  671. #undef PVOP_VCALL4
  672. #undef PVOP_CALL4
  673. extern void default_banner(void);
  674. #else /* __ASSEMBLY__ */
  675. #define _PVSITE(ptype, clobbers, ops, word, algn) \
  676. 771:; \
  677. ops; \
  678. 772:; \
  679. .pushsection .parainstructions,"a"; \
  680. .align algn; \
  681. word 771b; \
  682. .byte ptype; \
  683. .byte 772b-771b; \
  684. .short clobbers; \
  685. .popsection
  686. #define COND_PUSH(set, mask, reg) \
  687. .if ((~(set)) & mask); push %reg; .endif
  688. #define COND_POP(set, mask, reg) \
  689. .if ((~(set)) & mask); pop %reg; .endif
  690. #ifdef CONFIG_X86_64
  691. #define PV_SAVE_REGS(set) \
  692. COND_PUSH(set, CLBR_RAX, rax); \
  693. COND_PUSH(set, CLBR_RCX, rcx); \
  694. COND_PUSH(set, CLBR_RDX, rdx); \
  695. COND_PUSH(set, CLBR_RSI, rsi); \
  696. COND_PUSH(set, CLBR_RDI, rdi); \
  697. COND_PUSH(set, CLBR_R8, r8); \
  698. COND_PUSH(set, CLBR_R9, r9); \
  699. COND_PUSH(set, CLBR_R10, r10); \
  700. COND_PUSH(set, CLBR_R11, r11)
  701. #define PV_RESTORE_REGS(set) \
  702. COND_POP(set, CLBR_R11, r11); \
  703. COND_POP(set, CLBR_R10, r10); \
  704. COND_POP(set, CLBR_R9, r9); \
  705. COND_POP(set, CLBR_R8, r8); \
  706. COND_POP(set, CLBR_RDI, rdi); \
  707. COND_POP(set, CLBR_RSI, rsi); \
  708. COND_POP(set, CLBR_RDX, rdx); \
  709. COND_POP(set, CLBR_RCX, rcx); \
  710. COND_POP(set, CLBR_RAX, rax)
  711. #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
  712. #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
  713. #define PARA_INDIRECT(addr) *addr(%rip)
  714. #else
  715. #define PV_SAVE_REGS(set) \
  716. COND_PUSH(set, CLBR_EAX, eax); \
  717. COND_PUSH(set, CLBR_EDI, edi); \
  718. COND_PUSH(set, CLBR_ECX, ecx); \
  719. COND_PUSH(set, CLBR_EDX, edx)
  720. #define PV_RESTORE_REGS(set) \
  721. COND_POP(set, CLBR_EDX, edx); \
  722. COND_POP(set, CLBR_ECX, ecx); \
  723. COND_POP(set, CLBR_EDI, edi); \
  724. COND_POP(set, CLBR_EAX, eax)
  725. #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
  726. #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
  727. #define PARA_INDIRECT(addr) *%cs:addr
  728. #endif
  729. #define INTERRUPT_RETURN \
  730. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
  731. jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
  732. #define DISABLE_INTERRUPTS(clobbers) \
  733. PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
  734. PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
  735. call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
  736. PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
  737. #define ENABLE_INTERRUPTS(clobbers) \
  738. PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
  739. PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
  740. call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
  741. PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
  742. #ifdef CONFIG_X86_32
  743. #define GET_CR0_INTO_EAX \
  744. push %ecx; push %edx; \
  745. call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
  746. pop %edx; pop %ecx
  747. #else /* !CONFIG_X86_32 */
  748. /*
  749. * If swapgs is used while the userspace stack is still current,
  750. * there's no way to call a pvop. The PV replacement *must* be
  751. * inlined, or the swapgs instruction must be trapped and emulated.
  752. */
  753. #define SWAPGS_UNSAFE_STACK \
  754. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
  755. swapgs)
  756. /*
  757. * Note: swapgs is very special, and in practise is either going to be
  758. * implemented with a single "swapgs" instruction or something very
  759. * special. Either way, we don't need to save any registers for
  760. * it.
  761. */
  762. #define SWAPGS \
  763. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
  764. call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
  765. )
  766. #define GET_CR2_INTO_RAX \
  767. call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2)
  768. #define PARAVIRT_ADJUST_EXCEPTION_FRAME \
  769. PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \
  770. CLBR_NONE, \
  771. call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame))
  772. #define USERGS_SYSRET64 \
  773. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
  774. CLBR_NONE, \
  775. jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
  776. #endif /* CONFIG_X86_32 */
  777. #endif /* __ASSEMBLY__ */
  778. #else /* CONFIG_PARAVIRT */
  779. # define default_banner x86_init_noop
  780. #ifndef __ASSEMBLY__
  781. static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm,
  782. struct mm_struct *mm)
  783. {
  784. }
  785. static inline void paravirt_arch_exit_mmap(struct mm_struct *mm)
  786. {
  787. }
  788. #endif /* __ASSEMBLY__ */
  789. #endif /* !CONFIG_PARAVIRT */
  790. #endif /* _ASM_X86_PARAVIRT_H */