tlb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * KVM/MIPS TLB handling, this file is part of the Linux host kernel so that
  7. * TLB handlers run from KSEG0
  8. *
  9. * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
  10. * Authors: Sanjay Lal <sanjayl@kymasys.com>
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/smp.h>
  14. #include <linux/mm.h>
  15. #include <linux/delay.h>
  16. #include <linux/export.h>
  17. #include <linux/kvm_host.h>
  18. #include <linux/srcu.h>
  19. #include <asm/cpu.h>
  20. #include <asm/bootinfo.h>
  21. #include <asm/mmu_context.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/tlb.h>
  25. #include <asm/tlbdebug.h>
  26. #undef CONFIG_MIPS_MT
  27. #include <asm/r4kcache.h>
  28. #define CONFIG_MIPS_MT
  29. #define KVM_GUEST_PC_TLB 0
  30. #define KVM_GUEST_SP_TLB 1
  31. #ifdef CONFIG_KVM_MIPS_VZ
  32. unsigned long GUESTID_MASK;
  33. EXPORT_SYMBOL_GPL(GUESTID_MASK);
  34. unsigned long GUESTID_FIRST_VERSION;
  35. EXPORT_SYMBOL_GPL(GUESTID_FIRST_VERSION);
  36. unsigned long GUESTID_VERSION_MASK;
  37. EXPORT_SYMBOL_GPL(GUESTID_VERSION_MASK);
  38. static u32 kvm_mips_get_root_asid(struct kvm_vcpu *vcpu)
  39. {
  40. struct mm_struct *gpa_mm = &vcpu->kvm->arch.gpa_mm;
  41. if (cpu_has_guestid)
  42. return 0;
  43. else
  44. return cpu_asid(smp_processor_id(), gpa_mm);
  45. }
  46. #endif
  47. static u32 kvm_mips_get_kernel_asid(struct kvm_vcpu *vcpu)
  48. {
  49. struct mm_struct *kern_mm = &vcpu->arch.guest_kernel_mm;
  50. int cpu = smp_processor_id();
  51. return cpu_asid(cpu, kern_mm);
  52. }
  53. static u32 kvm_mips_get_user_asid(struct kvm_vcpu *vcpu)
  54. {
  55. struct mm_struct *user_mm = &vcpu->arch.guest_user_mm;
  56. int cpu = smp_processor_id();
  57. return cpu_asid(cpu, user_mm);
  58. }
  59. /* Structure defining an tlb entry data set. */
  60. void kvm_mips_dump_host_tlbs(void)
  61. {
  62. unsigned long flags;
  63. local_irq_save(flags);
  64. kvm_info("HOST TLBs:\n");
  65. dump_tlb_regs();
  66. pr_info("\n");
  67. dump_tlb_all();
  68. local_irq_restore(flags);
  69. }
  70. EXPORT_SYMBOL_GPL(kvm_mips_dump_host_tlbs);
  71. void kvm_mips_dump_guest_tlbs(struct kvm_vcpu *vcpu)
  72. {
  73. struct mips_coproc *cop0 = vcpu->arch.cop0;
  74. struct kvm_mips_tlb tlb;
  75. int i;
  76. kvm_info("Guest TLBs:\n");
  77. kvm_info("Guest EntryHi: %#lx\n", kvm_read_c0_guest_entryhi(cop0));
  78. for (i = 0; i < KVM_MIPS_GUEST_TLB_SIZE; i++) {
  79. tlb = vcpu->arch.guest_tlb[i];
  80. kvm_info("TLB%c%3d Hi 0x%08lx ",
  81. (tlb.tlb_lo[0] | tlb.tlb_lo[1]) & ENTRYLO_V
  82. ? ' ' : '*',
  83. i, tlb.tlb_hi);
  84. kvm_info("Lo0=0x%09llx %c%c attr %lx ",
  85. (u64) mips3_tlbpfn_to_paddr(tlb.tlb_lo[0]),
  86. (tlb.tlb_lo[0] & ENTRYLO_D) ? 'D' : ' ',
  87. (tlb.tlb_lo[0] & ENTRYLO_G) ? 'G' : ' ',
  88. (tlb.tlb_lo[0] & ENTRYLO_C) >> ENTRYLO_C_SHIFT);
  89. kvm_info("Lo1=0x%09llx %c%c attr %lx sz=%lx\n",
  90. (u64) mips3_tlbpfn_to_paddr(tlb.tlb_lo[1]),
  91. (tlb.tlb_lo[1] & ENTRYLO_D) ? 'D' : ' ',
  92. (tlb.tlb_lo[1] & ENTRYLO_G) ? 'G' : ' ',
  93. (tlb.tlb_lo[1] & ENTRYLO_C) >> ENTRYLO_C_SHIFT,
  94. tlb.tlb_mask);
  95. }
  96. }
  97. EXPORT_SYMBOL_GPL(kvm_mips_dump_guest_tlbs);
  98. int kvm_mips_guest_tlb_lookup(struct kvm_vcpu *vcpu, unsigned long entryhi)
  99. {
  100. int i;
  101. int index = -1;
  102. struct kvm_mips_tlb *tlb = vcpu->arch.guest_tlb;
  103. for (i = 0; i < KVM_MIPS_GUEST_TLB_SIZE; i++) {
  104. if (TLB_HI_VPN2_HIT(tlb[i], entryhi) &&
  105. TLB_HI_ASID_HIT(tlb[i], entryhi)) {
  106. index = i;
  107. break;
  108. }
  109. }
  110. kvm_debug("%s: entryhi: %#lx, index: %d lo0: %#lx, lo1: %#lx\n",
  111. __func__, entryhi, index, tlb[i].tlb_lo[0], tlb[i].tlb_lo[1]);
  112. return index;
  113. }
  114. EXPORT_SYMBOL_GPL(kvm_mips_guest_tlb_lookup);
  115. static int _kvm_mips_host_tlb_inv(unsigned long entryhi)
  116. {
  117. int idx;
  118. write_c0_entryhi(entryhi);
  119. mtc0_tlbw_hazard();
  120. tlb_probe();
  121. tlb_probe_hazard();
  122. idx = read_c0_index();
  123. if (idx >= current_cpu_data.tlbsize)
  124. BUG();
  125. if (idx >= 0) {
  126. write_c0_entryhi(UNIQUE_ENTRYHI(idx));
  127. write_c0_entrylo0(0);
  128. write_c0_entrylo1(0);
  129. mtc0_tlbw_hazard();
  130. tlb_write_indexed();
  131. tlbw_use_hazard();
  132. }
  133. return idx;
  134. }
  135. int kvm_mips_host_tlb_inv(struct kvm_vcpu *vcpu, unsigned long va,
  136. bool user, bool kernel)
  137. {
  138. int idx_user, idx_kernel;
  139. unsigned long flags, old_entryhi;
  140. local_irq_save(flags);
  141. old_entryhi = read_c0_entryhi();
  142. if (user)
  143. idx_user = _kvm_mips_host_tlb_inv((va & VPN2_MASK) |
  144. kvm_mips_get_user_asid(vcpu));
  145. if (kernel)
  146. idx_kernel = _kvm_mips_host_tlb_inv((va & VPN2_MASK) |
  147. kvm_mips_get_kernel_asid(vcpu));
  148. write_c0_entryhi(old_entryhi);
  149. mtc0_tlbw_hazard();
  150. local_irq_restore(flags);
  151. if (user && idx_user >= 0)
  152. kvm_debug("%s: Invalidated guest user entryhi %#lx @ idx %d\n",
  153. __func__, (va & VPN2_MASK) |
  154. kvm_mips_get_user_asid(vcpu), idx_user);
  155. if (kernel && idx_kernel >= 0)
  156. kvm_debug("%s: Invalidated guest kernel entryhi %#lx @ idx %d\n",
  157. __func__, (va & VPN2_MASK) |
  158. kvm_mips_get_kernel_asid(vcpu), idx_kernel);
  159. return 0;
  160. }
  161. EXPORT_SYMBOL_GPL(kvm_mips_host_tlb_inv);
  162. #ifdef CONFIG_KVM_MIPS_VZ
  163. /* GuestID management */
  164. /**
  165. * clear_root_gid() - Set GuestCtl1.RID for normal root operation.
  166. */
  167. static inline void clear_root_gid(void)
  168. {
  169. if (cpu_has_guestid) {
  170. clear_c0_guestctl1(MIPS_GCTL1_RID);
  171. mtc0_tlbw_hazard();
  172. }
  173. }
  174. /**
  175. * set_root_gid_to_guest_gid() - Set GuestCtl1.RID to match GuestCtl1.ID.
  176. *
  177. * Sets the root GuestID to match the current guest GuestID, for TLB operation
  178. * on the GPA->RPA mappings in the root TLB.
  179. *
  180. * The caller must be sure to disable HTW while the root GID is set, and
  181. * possibly longer if TLB registers are modified.
  182. */
  183. static inline void set_root_gid_to_guest_gid(void)
  184. {
  185. unsigned int guestctl1;
  186. if (cpu_has_guestid) {
  187. back_to_back_c0_hazard();
  188. guestctl1 = read_c0_guestctl1();
  189. guestctl1 = (guestctl1 & ~MIPS_GCTL1_RID) |
  190. ((guestctl1 & MIPS_GCTL1_ID) >> MIPS_GCTL1_ID_SHIFT)
  191. << MIPS_GCTL1_RID_SHIFT;
  192. write_c0_guestctl1(guestctl1);
  193. mtc0_tlbw_hazard();
  194. }
  195. }
  196. int kvm_vz_host_tlb_inv(struct kvm_vcpu *vcpu, unsigned long va)
  197. {
  198. int idx;
  199. unsigned long flags, old_entryhi;
  200. local_irq_save(flags);
  201. htw_stop();
  202. /* Set root GuestID for root probe and write of guest TLB entry */
  203. set_root_gid_to_guest_gid();
  204. old_entryhi = read_c0_entryhi();
  205. idx = _kvm_mips_host_tlb_inv((va & VPN2_MASK) |
  206. kvm_mips_get_root_asid(vcpu));
  207. write_c0_entryhi(old_entryhi);
  208. clear_root_gid();
  209. mtc0_tlbw_hazard();
  210. htw_start();
  211. local_irq_restore(flags);
  212. if (idx > 0)
  213. kvm_debug("%s: Invalidated root entryhi %#lx @ idx %d\n",
  214. __func__, (va & VPN2_MASK) |
  215. kvm_mips_get_root_asid(vcpu), idx);
  216. return 0;
  217. }
  218. EXPORT_SYMBOL_GPL(kvm_vz_host_tlb_inv);
  219. /**
  220. * kvm_vz_guest_tlb_lookup() - Lookup a guest VZ TLB mapping.
  221. * @vcpu: KVM VCPU pointer.
  222. * @gpa: Guest virtual address in a TLB mapped guest segment.
  223. * @gpa: Ponter to output guest physical address it maps to.
  224. *
  225. * Converts a guest virtual address in a guest TLB mapped segment to a guest
  226. * physical address, by probing the guest TLB.
  227. *
  228. * Returns: 0 if guest TLB mapping exists for @gva. *@gpa will have been
  229. * written.
  230. * -EFAULT if no guest TLB mapping exists for @gva. *@gpa may not
  231. * have been written.
  232. */
  233. int kvm_vz_guest_tlb_lookup(struct kvm_vcpu *vcpu, unsigned long gva,
  234. unsigned long *gpa)
  235. {
  236. unsigned long o_entryhi, o_entrylo[2], o_pagemask;
  237. unsigned int o_index;
  238. unsigned long entrylo[2], pagemask, pagemaskbit, pa;
  239. unsigned long flags;
  240. int index;
  241. /* Probe the guest TLB for a mapping */
  242. local_irq_save(flags);
  243. /* Set root GuestID for root probe of guest TLB entry */
  244. htw_stop();
  245. set_root_gid_to_guest_gid();
  246. o_entryhi = read_gc0_entryhi();
  247. o_index = read_gc0_index();
  248. write_gc0_entryhi((o_entryhi & 0x3ff) | (gva & ~0xfffl));
  249. mtc0_tlbw_hazard();
  250. guest_tlb_probe();
  251. tlb_probe_hazard();
  252. index = read_gc0_index();
  253. if (index < 0) {
  254. /* No match, fail */
  255. write_gc0_entryhi(o_entryhi);
  256. write_gc0_index(o_index);
  257. clear_root_gid();
  258. htw_start();
  259. local_irq_restore(flags);
  260. return -EFAULT;
  261. }
  262. /* Match! read the TLB entry */
  263. o_entrylo[0] = read_gc0_entrylo0();
  264. o_entrylo[1] = read_gc0_entrylo1();
  265. o_pagemask = read_gc0_pagemask();
  266. mtc0_tlbr_hazard();
  267. guest_tlb_read();
  268. tlb_read_hazard();
  269. entrylo[0] = read_gc0_entrylo0();
  270. entrylo[1] = read_gc0_entrylo1();
  271. pagemask = ~read_gc0_pagemask() & ~0x1fffl;
  272. write_gc0_entryhi(o_entryhi);
  273. write_gc0_index(o_index);
  274. write_gc0_entrylo0(o_entrylo[0]);
  275. write_gc0_entrylo1(o_entrylo[1]);
  276. write_gc0_pagemask(o_pagemask);
  277. clear_root_gid();
  278. htw_start();
  279. local_irq_restore(flags);
  280. /* Select one of the EntryLo values and interpret the GPA */
  281. pagemaskbit = (pagemask ^ (pagemask & (pagemask - 1))) >> 1;
  282. pa = entrylo[!!(gva & pagemaskbit)];
  283. /*
  284. * TLB entry may have become invalid since TLB probe if physical FTLB
  285. * entries are shared between threads (e.g. I6400).
  286. */
  287. if (!(pa & ENTRYLO_V))
  288. return -EFAULT;
  289. /*
  290. * Note, this doesn't take guest MIPS32 XPA into account, where PFN is
  291. * split with XI/RI in the middle.
  292. */
  293. pa = (pa << 6) & ~0xfffl;
  294. pa |= gva & ~(pagemask | pagemaskbit);
  295. *gpa = pa;
  296. return 0;
  297. }
  298. EXPORT_SYMBOL_GPL(kvm_vz_guest_tlb_lookup);
  299. /**
  300. * kvm_vz_local_flush_roottlb_all_guests() - Flush all root TLB entries for
  301. * guests.
  302. *
  303. * Invalidate all entries in root tlb which are GPA mappings.
  304. */
  305. void kvm_vz_local_flush_roottlb_all_guests(void)
  306. {
  307. unsigned long flags;
  308. unsigned long old_entryhi, old_pagemask, old_guestctl1;
  309. int entry;
  310. if (WARN_ON(!cpu_has_guestid))
  311. return;
  312. local_irq_save(flags);
  313. htw_stop();
  314. /* TLBR may clobber EntryHi.ASID, PageMask, and GuestCtl1.RID */
  315. old_entryhi = read_c0_entryhi();
  316. old_pagemask = read_c0_pagemask();
  317. old_guestctl1 = read_c0_guestctl1();
  318. /*
  319. * Invalidate guest entries in root TLB while leaving root entries
  320. * intact when possible.
  321. */
  322. for (entry = 0; entry < current_cpu_data.tlbsize; entry++) {
  323. write_c0_index(entry);
  324. mtc0_tlbw_hazard();
  325. tlb_read();
  326. tlb_read_hazard();
  327. /* Don't invalidate non-guest (RVA) mappings in the root TLB */
  328. if (!(read_c0_guestctl1() & MIPS_GCTL1_RID))
  329. continue;
  330. /* Make sure all entries differ. */
  331. write_c0_entryhi(UNIQUE_ENTRYHI(entry));
  332. write_c0_entrylo0(0);
  333. write_c0_entrylo1(0);
  334. write_c0_guestctl1(0);
  335. mtc0_tlbw_hazard();
  336. tlb_write_indexed();
  337. }
  338. write_c0_entryhi(old_entryhi);
  339. write_c0_pagemask(old_pagemask);
  340. write_c0_guestctl1(old_guestctl1);
  341. tlbw_use_hazard();
  342. htw_start();
  343. local_irq_restore(flags);
  344. }
  345. EXPORT_SYMBOL_GPL(kvm_vz_local_flush_roottlb_all_guests);
  346. /**
  347. * kvm_vz_local_flush_guesttlb_all() - Flush all guest TLB entries.
  348. *
  349. * Invalidate all entries in guest tlb irrespective of guestid.
  350. */
  351. void kvm_vz_local_flush_guesttlb_all(void)
  352. {
  353. unsigned long flags;
  354. unsigned long old_index;
  355. unsigned long old_entryhi;
  356. unsigned long old_entrylo[2];
  357. unsigned long old_pagemask;
  358. int entry;
  359. local_irq_save(flags);
  360. /* Preserve all clobbered guest registers */
  361. old_index = read_gc0_index();
  362. old_entryhi = read_gc0_entryhi();
  363. old_entrylo[0] = read_gc0_entrylo0();
  364. old_entrylo[1] = read_gc0_entrylo1();
  365. old_pagemask = read_gc0_pagemask();
  366. /* Invalidate guest entries in guest TLB */
  367. write_gc0_entrylo0(0);
  368. write_gc0_entrylo1(0);
  369. write_gc0_pagemask(0);
  370. for (entry = 0; entry < current_cpu_data.guest.tlbsize; entry++) {
  371. /* Make sure all entries differ. */
  372. write_gc0_index(entry);
  373. write_gc0_entryhi(UNIQUE_GUEST_ENTRYHI(entry));
  374. mtc0_tlbw_hazard();
  375. guest_tlb_write_indexed();
  376. }
  377. write_gc0_index(old_index);
  378. write_gc0_entryhi(old_entryhi);
  379. write_gc0_entrylo0(old_entrylo[0]);
  380. write_gc0_entrylo1(old_entrylo[1]);
  381. write_gc0_pagemask(old_pagemask);
  382. tlbw_use_hazard();
  383. local_irq_restore(flags);
  384. }
  385. EXPORT_SYMBOL_GPL(kvm_vz_local_flush_guesttlb_all);
  386. /**
  387. * kvm_vz_save_guesttlb() - Save a range of guest TLB entries.
  388. * @buf: Buffer to write TLB entries into.
  389. * @index: Start index.
  390. * @count: Number of entries to save.
  391. *
  392. * Save a range of guest TLB entries. The caller must ensure interrupts are
  393. * disabled.
  394. */
  395. void kvm_vz_save_guesttlb(struct kvm_mips_tlb *buf, unsigned int index,
  396. unsigned int count)
  397. {
  398. unsigned int end = index + count;
  399. unsigned long old_entryhi, old_entrylo0, old_entrylo1, old_pagemask;
  400. unsigned int guestctl1 = 0;
  401. int old_index, i;
  402. /* Save registers we're about to clobber */
  403. old_index = read_gc0_index();
  404. old_entryhi = read_gc0_entryhi();
  405. old_entrylo0 = read_gc0_entrylo0();
  406. old_entrylo1 = read_gc0_entrylo1();
  407. old_pagemask = read_gc0_pagemask();
  408. /* Set root GuestID for root probe */
  409. htw_stop();
  410. set_root_gid_to_guest_gid();
  411. if (cpu_has_guestid)
  412. guestctl1 = read_c0_guestctl1();
  413. /* Read each entry from guest TLB */
  414. for (i = index; i < end; ++i, ++buf) {
  415. write_gc0_index(i);
  416. mtc0_tlbr_hazard();
  417. guest_tlb_read();
  418. tlb_read_hazard();
  419. if (cpu_has_guestid &&
  420. (read_c0_guestctl1() ^ guestctl1) & MIPS_GCTL1_RID) {
  421. /* Entry invalid or belongs to another guest */
  422. buf->tlb_hi = UNIQUE_GUEST_ENTRYHI(i);
  423. buf->tlb_lo[0] = 0;
  424. buf->tlb_lo[1] = 0;
  425. buf->tlb_mask = 0;
  426. } else {
  427. /* Entry belongs to the right guest */
  428. buf->tlb_hi = read_gc0_entryhi();
  429. buf->tlb_lo[0] = read_gc0_entrylo0();
  430. buf->tlb_lo[1] = read_gc0_entrylo1();
  431. buf->tlb_mask = read_gc0_pagemask();
  432. }
  433. }
  434. /* Clear root GuestID again */
  435. clear_root_gid();
  436. htw_start();
  437. /* Restore clobbered registers */
  438. write_gc0_index(old_index);
  439. write_gc0_entryhi(old_entryhi);
  440. write_gc0_entrylo0(old_entrylo0);
  441. write_gc0_entrylo1(old_entrylo1);
  442. write_gc0_pagemask(old_pagemask);
  443. tlbw_use_hazard();
  444. }
  445. EXPORT_SYMBOL_GPL(kvm_vz_save_guesttlb);
  446. /**
  447. * kvm_vz_load_guesttlb() - Save a range of guest TLB entries.
  448. * @buf: Buffer to read TLB entries from.
  449. * @index: Start index.
  450. * @count: Number of entries to load.
  451. *
  452. * Load a range of guest TLB entries. The caller must ensure interrupts are
  453. * disabled.
  454. */
  455. void kvm_vz_load_guesttlb(const struct kvm_mips_tlb *buf, unsigned int index,
  456. unsigned int count)
  457. {
  458. unsigned int end = index + count;
  459. unsigned long old_entryhi, old_entrylo0, old_entrylo1, old_pagemask;
  460. int old_index, i;
  461. /* Save registers we're about to clobber */
  462. old_index = read_gc0_index();
  463. old_entryhi = read_gc0_entryhi();
  464. old_entrylo0 = read_gc0_entrylo0();
  465. old_entrylo1 = read_gc0_entrylo1();
  466. old_pagemask = read_gc0_pagemask();
  467. /* Set root GuestID for root probe */
  468. htw_stop();
  469. set_root_gid_to_guest_gid();
  470. /* Write each entry to guest TLB */
  471. for (i = index; i < end; ++i, ++buf) {
  472. write_gc0_index(i);
  473. write_gc0_entryhi(buf->tlb_hi);
  474. write_gc0_entrylo0(buf->tlb_lo[0]);
  475. write_gc0_entrylo1(buf->tlb_lo[1]);
  476. write_gc0_pagemask(buf->tlb_mask);
  477. mtc0_tlbw_hazard();
  478. guest_tlb_write_indexed();
  479. }
  480. /* Clear root GuestID again */
  481. clear_root_gid();
  482. htw_start();
  483. /* Restore clobbered registers */
  484. write_gc0_index(old_index);
  485. write_gc0_entryhi(old_entryhi);
  486. write_gc0_entrylo0(old_entrylo0);
  487. write_gc0_entrylo1(old_entrylo1);
  488. write_gc0_pagemask(old_pagemask);
  489. tlbw_use_hazard();
  490. }
  491. EXPORT_SYMBOL_GPL(kvm_vz_load_guesttlb);
  492. #endif
  493. /**
  494. * kvm_mips_suspend_mm() - Suspend the active mm.
  495. * @cpu The CPU we're running on.
  496. *
  497. * Suspend the active_mm, ready for a switch to a KVM guest virtual address
  498. * space. This is left active for the duration of guest context, including time
  499. * with interrupts enabled, so we need to be careful not to confuse e.g. cache
  500. * management IPIs.
  501. *
  502. * kvm_mips_resume_mm() should be called before context switching to a different
  503. * process so we don't need to worry about reference counting.
  504. *
  505. * This needs to be in static kernel code to avoid exporting init_mm.
  506. */
  507. void kvm_mips_suspend_mm(int cpu)
  508. {
  509. cpumask_clear_cpu(cpu, mm_cpumask(current->active_mm));
  510. current->active_mm = &init_mm;
  511. }
  512. EXPORT_SYMBOL_GPL(kvm_mips_suspend_mm);
  513. /**
  514. * kvm_mips_resume_mm() - Resume the current process mm.
  515. * @cpu The CPU we're running on.
  516. *
  517. * Resume the mm of the current process, after a switch back from a KVM guest
  518. * virtual address space (see kvm_mips_suspend_mm()).
  519. */
  520. void kvm_mips_resume_mm(int cpu)
  521. {
  522. cpumask_set_cpu(cpu, mm_cpumask(current->mm));
  523. current->active_mm = current->mm;
  524. }
  525. EXPORT_SYMBOL_GPL(kvm_mips_resume_mm);