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 unsigned long read_cr0(void)
  38. {
  39. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
  40. }
  41. static inline void write_cr0(unsigned long x)
  42. {
  43. PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
  44. }
  45. static inline unsigned long read_cr2(void)
  46. {
  47. return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
  48. }
  49. static inline void write_cr2(unsigned long x)
  50. {
  51. PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
  52. }
  53. static inline unsigned long read_cr3(void)
  54. {
  55. return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
  56. }
  57. static inline void write_cr3(unsigned long x)
  58. {
  59. PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
  60. }
  61. static inline unsigned long __read_cr4(void)
  62. {
  63. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
  64. }
  65. static inline void __write_cr4(unsigned long x)
  66. {
  67. PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
  68. }
  69. #ifdef CONFIG_X86_64
  70. static inline unsigned long read_cr8(void)
  71. {
  72. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8);
  73. }
  74. static inline void write_cr8(unsigned long x)
  75. {
  76. PVOP_VCALL1(pv_cpu_ops.write_cr8, x);
  77. }
  78. #endif
  79. static inline void arch_safe_halt(void)
  80. {
  81. PVOP_VCALL0(pv_irq_ops.safe_halt);
  82. }
  83. static inline void halt(void)
  84. {
  85. PVOP_VCALL0(pv_irq_ops.halt);
  86. }
  87. static inline void wbinvd(void)
  88. {
  89. PVOP_VCALL0(pv_cpu_ops.wbinvd);
  90. }
  91. #define get_kernel_rpl() (pv_info.kernel_rpl)
  92. static inline u64 paravirt_read_msr(unsigned msr)
  93. {
  94. return PVOP_CALL1(u64, pv_cpu_ops.read_msr, msr);
  95. }
  96. static inline void paravirt_write_msr(unsigned msr,
  97. unsigned low, unsigned high)
  98. {
  99. return PVOP_VCALL3(pv_cpu_ops.write_msr, msr, low, high);
  100. }
  101. static inline u64 paravirt_read_msr_safe(unsigned msr, int *err)
  102. {
  103. return PVOP_CALL2(u64, pv_cpu_ops.read_msr_safe, msr, err);
  104. }
  105. static inline int paravirt_write_msr_safe(unsigned msr,
  106. unsigned low, unsigned high)
  107. {
  108. return PVOP_CALL3(int, pv_cpu_ops.write_msr_safe, msr, low, high);
  109. }
  110. #define rdmsr(msr, val1, val2) \
  111. do { \
  112. u64 _l = paravirt_read_msr(msr); \
  113. val1 = (u32)_l; \
  114. val2 = _l >> 32; \
  115. } while (0)
  116. #define wrmsr(msr, val1, val2) \
  117. do { \
  118. paravirt_write_msr(msr, val1, val2); \
  119. } while (0)
  120. #define rdmsrl(msr, val) \
  121. do { \
  122. val = paravirt_read_msr(msr); \
  123. } while (0)
  124. static inline void wrmsrl(unsigned msr, u64 val)
  125. {
  126. wrmsr(msr, (u32)val, (u32)(val>>32));
  127. }
  128. #define wrmsr_safe(msr, a, b) paravirt_write_msr_safe(msr, a, b)
  129. /* rdmsr with exception handling */
  130. #define rdmsr_safe(msr, a, b) \
  131. ({ \
  132. int _err; \
  133. u64 _l = paravirt_read_msr_safe(msr, &_err); \
  134. (*a) = (u32)_l; \
  135. (*b) = _l >> 32; \
  136. _err; \
  137. })
  138. static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
  139. {
  140. int err;
  141. *p = paravirt_read_msr_safe(msr, &err);
  142. return err;
  143. }
  144. static inline unsigned long long paravirt_sched_clock(void)
  145. {
  146. return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
  147. }
  148. struct static_key;
  149. extern struct static_key paravirt_steal_enabled;
  150. extern struct static_key paravirt_steal_rq_enabled;
  151. static inline u64 paravirt_steal_clock(int cpu)
  152. {
  153. return PVOP_CALL1(u64, pv_time_ops.steal_clock, cpu);
  154. }
  155. static inline unsigned long long paravirt_read_pmc(int counter)
  156. {
  157. return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
  158. }
  159. #define rdpmc(counter, low, high) \
  160. do { \
  161. u64 _l = paravirt_read_pmc(counter); \
  162. low = (u32)_l; \
  163. high = _l >> 32; \
  164. } while (0)
  165. #define rdpmcl(counter, val) ((val) = paravirt_read_pmc(counter))
  166. static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
  167. {
  168. PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries);
  169. }
  170. static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
  171. {
  172. PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries);
  173. }
  174. static inline void load_TR_desc(void)
  175. {
  176. PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
  177. }
  178. static inline void load_gdt(const struct desc_ptr *dtr)
  179. {
  180. PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
  181. }
  182. static inline void load_idt(const struct desc_ptr *dtr)
  183. {
  184. PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
  185. }
  186. static inline void set_ldt(const void *addr, unsigned entries)
  187. {
  188. PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
  189. }
  190. static inline void store_idt(struct desc_ptr *dtr)
  191. {
  192. PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
  193. }
  194. static inline unsigned long paravirt_store_tr(void)
  195. {
  196. return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
  197. }
  198. #define store_tr(tr) ((tr) = paravirt_store_tr())
  199. static inline void load_TLS(struct thread_struct *t, unsigned cpu)
  200. {
  201. PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
  202. }
  203. #ifdef CONFIG_X86_64
  204. static inline void load_gs_index(unsigned int gs)
  205. {
  206. PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
  207. }
  208. #endif
  209. static inline void write_ldt_entry(struct desc_struct *dt, int entry,
  210. const void *desc)
  211. {
  212. PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
  213. }
  214. static inline void write_gdt_entry(struct desc_struct *dt, int entry,
  215. void *desc, int type)
  216. {
  217. PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
  218. }
  219. static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
  220. {
  221. PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
  222. }
  223. static inline void set_iopl_mask(unsigned mask)
  224. {
  225. PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
  226. }
  227. /* The paravirtualized I/O functions */
  228. static inline void slow_down_io(void)
  229. {
  230. pv_cpu_ops.io_delay();
  231. #ifdef REALLY_SLOW_IO
  232. pv_cpu_ops.io_delay();
  233. pv_cpu_ops.io_delay();
  234. pv_cpu_ops.io_delay();
  235. #endif
  236. }
  237. static inline void paravirt_activate_mm(struct mm_struct *prev,
  238. struct mm_struct *next)
  239. {
  240. PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
  241. }
  242. static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm,
  243. struct mm_struct *mm)
  244. {
  245. PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
  246. }
  247. static inline void paravirt_arch_exit_mmap(struct mm_struct *mm)
  248. {
  249. PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
  250. }
  251. static inline void __flush_tlb(void)
  252. {
  253. PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
  254. }
  255. static inline void __flush_tlb_global(void)
  256. {
  257. PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
  258. }
  259. static inline void __flush_tlb_single(unsigned long addr)
  260. {
  261. PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
  262. }
  263. static inline void flush_tlb_others(const struct cpumask *cpumask,
  264. struct mm_struct *mm,
  265. unsigned long start,
  266. unsigned long end)
  267. {
  268. PVOP_VCALL4(pv_mmu_ops.flush_tlb_others, cpumask, mm, start, end);
  269. }
  270. static inline int paravirt_pgd_alloc(struct mm_struct *mm)
  271. {
  272. return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
  273. }
  274. static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
  275. {
  276. PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
  277. }
  278. static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
  279. {
  280. PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
  281. }
  282. static inline void paravirt_release_pte(unsigned long pfn)
  283. {
  284. PVOP_VCALL1(pv_mmu_ops.release_pte, pfn);
  285. }
  286. static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
  287. {
  288. PVOP_VCALL2(pv_mmu_ops.alloc_pmd, mm, pfn);
  289. }
  290. static inline void paravirt_release_pmd(unsigned long pfn)
  291. {
  292. PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn);
  293. }
  294. static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
  295. {
  296. PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn);
  297. }
  298. static inline void paravirt_release_pud(unsigned long pfn)
  299. {
  300. PVOP_VCALL1(pv_mmu_ops.release_pud, pfn);
  301. }
  302. static inline void pte_update(struct mm_struct *mm, unsigned long addr,
  303. pte_t *ptep)
  304. {
  305. PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
  306. }
  307. static inline pte_t __pte(pteval_t val)
  308. {
  309. pteval_t ret;
  310. if (sizeof(pteval_t) > sizeof(long))
  311. ret = PVOP_CALLEE2(pteval_t,
  312. pv_mmu_ops.make_pte,
  313. val, (u64)val >> 32);
  314. else
  315. ret = PVOP_CALLEE1(pteval_t,
  316. pv_mmu_ops.make_pte,
  317. val);
  318. return (pte_t) { .pte = ret };
  319. }
  320. static inline pteval_t pte_val(pte_t pte)
  321. {
  322. pteval_t ret;
  323. if (sizeof(pteval_t) > sizeof(long))
  324. ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val,
  325. pte.pte, (u64)pte.pte >> 32);
  326. else
  327. ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val,
  328. pte.pte);
  329. return ret;
  330. }
  331. static inline pgd_t __pgd(pgdval_t val)
  332. {
  333. pgdval_t ret;
  334. if (sizeof(pgdval_t) > sizeof(long))
  335. ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd,
  336. val, (u64)val >> 32);
  337. else
  338. ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd,
  339. val);
  340. return (pgd_t) { ret };
  341. }
  342. static inline pgdval_t pgd_val(pgd_t pgd)
  343. {
  344. pgdval_t ret;
  345. if (sizeof(pgdval_t) > sizeof(long))
  346. ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val,
  347. pgd.pgd, (u64)pgd.pgd >> 32);
  348. else
  349. ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val,
  350. pgd.pgd);
  351. return ret;
  352. }
  353. #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
  354. static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
  355. pte_t *ptep)
  356. {
  357. pteval_t ret;
  358. ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
  359. mm, addr, ptep);
  360. return (pte_t) { .pte = ret };
  361. }
  362. static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
  363. pte_t *ptep, pte_t pte)
  364. {
  365. if (sizeof(pteval_t) > sizeof(long))
  366. /* 5 arg words */
  367. pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
  368. else
  369. PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
  370. mm, addr, ptep, pte.pte);
  371. }
  372. static inline void set_pte(pte_t *ptep, pte_t pte)
  373. {
  374. if (sizeof(pteval_t) > sizeof(long))
  375. PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
  376. pte.pte, (u64)pte.pte >> 32);
  377. else
  378. PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
  379. pte.pte);
  380. }
  381. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  382. pte_t *ptep, pte_t pte)
  383. {
  384. if (sizeof(pteval_t) > sizeof(long))
  385. /* 5 arg words */
  386. pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
  387. else
  388. PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
  389. }
  390. static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  391. pmd_t *pmdp, pmd_t pmd)
  392. {
  393. if (sizeof(pmdval_t) > sizeof(long))
  394. /* 5 arg words */
  395. pv_mmu_ops.set_pmd_at(mm, addr, pmdp, pmd);
  396. else
  397. PVOP_VCALL4(pv_mmu_ops.set_pmd_at, mm, addr, pmdp,
  398. native_pmd_val(pmd));
  399. }
  400. static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
  401. {
  402. pmdval_t val = native_pmd_val(pmd);
  403. if (sizeof(pmdval_t) > sizeof(long))
  404. PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
  405. else
  406. PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
  407. }
  408. #if CONFIG_PGTABLE_LEVELS >= 3
  409. static inline pmd_t __pmd(pmdval_t val)
  410. {
  411. pmdval_t ret;
  412. if (sizeof(pmdval_t) > sizeof(long))
  413. ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd,
  414. val, (u64)val >> 32);
  415. else
  416. ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd,
  417. val);
  418. return (pmd_t) { ret };
  419. }
  420. static inline pmdval_t pmd_val(pmd_t pmd)
  421. {
  422. pmdval_t ret;
  423. if (sizeof(pmdval_t) > sizeof(long))
  424. ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val,
  425. pmd.pmd, (u64)pmd.pmd >> 32);
  426. else
  427. ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val,
  428. pmd.pmd);
  429. return ret;
  430. }
  431. static inline void set_pud(pud_t *pudp, pud_t pud)
  432. {
  433. pudval_t val = native_pud_val(pud);
  434. if (sizeof(pudval_t) > sizeof(long))
  435. PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
  436. val, (u64)val >> 32);
  437. else
  438. PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
  439. val);
  440. }
  441. #if CONFIG_PGTABLE_LEVELS == 4
  442. static inline pud_t __pud(pudval_t val)
  443. {
  444. pudval_t ret;
  445. if (sizeof(pudval_t) > sizeof(long))
  446. ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud,
  447. val, (u64)val >> 32);
  448. else
  449. ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud,
  450. val);
  451. return (pud_t) { ret };
  452. }
  453. static inline pudval_t pud_val(pud_t pud)
  454. {
  455. pudval_t ret;
  456. if (sizeof(pudval_t) > sizeof(long))
  457. ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val,
  458. pud.pud, (u64)pud.pud >> 32);
  459. else
  460. ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val,
  461. pud.pud);
  462. return ret;
  463. }
  464. static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
  465. {
  466. pgdval_t val = native_pgd_val(pgd);
  467. if (sizeof(pgdval_t) > sizeof(long))
  468. PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
  469. val, (u64)val >> 32);
  470. else
  471. PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
  472. val);
  473. }
  474. static inline void pgd_clear(pgd_t *pgdp)
  475. {
  476. set_pgd(pgdp, __pgd(0));
  477. }
  478. static inline void pud_clear(pud_t *pudp)
  479. {
  480. set_pud(pudp, __pud(0));
  481. }
  482. #endif /* CONFIG_PGTABLE_LEVELS == 4 */
  483. #endif /* CONFIG_PGTABLE_LEVELS >= 3 */
  484. #ifdef CONFIG_X86_PAE
  485. /* Special-case pte-setting operations for PAE, which can't update a
  486. 64-bit pte atomically */
  487. static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
  488. {
  489. PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
  490. pte.pte, pte.pte >> 32);
  491. }
  492. static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
  493. pte_t *ptep)
  494. {
  495. PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
  496. }
  497. static inline void pmd_clear(pmd_t *pmdp)
  498. {
  499. PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
  500. }
  501. #else /* !CONFIG_X86_PAE */
  502. static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
  503. {
  504. set_pte(ptep, pte);
  505. }
  506. static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
  507. pte_t *ptep)
  508. {
  509. set_pte_at(mm, addr, ptep, __pte(0));
  510. }
  511. static inline void pmd_clear(pmd_t *pmdp)
  512. {
  513. set_pmd(pmdp, __pmd(0));
  514. }
  515. #endif /* CONFIG_X86_PAE */
  516. #define __HAVE_ARCH_START_CONTEXT_SWITCH
  517. static inline void arch_start_context_switch(struct task_struct *prev)
  518. {
  519. PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
  520. }
  521. static inline void arch_end_context_switch(struct task_struct *next)
  522. {
  523. PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
  524. }
  525. #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
  526. static inline void arch_enter_lazy_mmu_mode(void)
  527. {
  528. PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
  529. }
  530. static inline void arch_leave_lazy_mmu_mode(void)
  531. {
  532. PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
  533. }
  534. static inline void arch_flush_lazy_mmu_mode(void)
  535. {
  536. PVOP_VCALL0(pv_mmu_ops.lazy_mode.flush);
  537. }
  538. static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
  539. phys_addr_t phys, pgprot_t flags)
  540. {
  541. pv_mmu_ops.set_fixmap(idx, phys, flags);
  542. }
  543. #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
  544. static __always_inline void pv_queued_spin_lock_slowpath(struct qspinlock *lock,
  545. u32 val)
  546. {
  547. PVOP_VCALL2(pv_lock_ops.queued_spin_lock_slowpath, lock, val);
  548. }
  549. static __always_inline void pv_queued_spin_unlock(struct qspinlock *lock)
  550. {
  551. PVOP_VCALLEE1(pv_lock_ops.queued_spin_unlock, lock);
  552. }
  553. static __always_inline void pv_wait(u8 *ptr, u8 val)
  554. {
  555. PVOP_VCALL2(pv_lock_ops.wait, ptr, val);
  556. }
  557. static __always_inline void pv_kick(int cpu)
  558. {
  559. PVOP_VCALL1(pv_lock_ops.kick, cpu);
  560. }
  561. static __always_inline bool pv_vcpu_is_preempted(long cpu)
  562. {
  563. return PVOP_CALLEE1(bool, pv_lock_ops.vcpu_is_preempted, 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 */