mips.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698
  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: MIPS specific KVM APIs
  7. *
  8. * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
  9. * Authors: Sanjay Lal <sanjayl@kymasys.com>
  10. */
  11. #include <linux/bitops.h>
  12. #include <linux/errno.h>
  13. #include <linux/err.h>
  14. #include <linux/kdebug.h>
  15. #include <linux/module.h>
  16. #include <linux/uaccess.h>
  17. #include <linux/vmalloc.h>
  18. #include <linux/sched/signal.h>
  19. #include <linux/fs.h>
  20. #include <linux/bootmem.h>
  21. #include <asm/fpu.h>
  22. #include <asm/page.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/mmu_context.h>
  25. #include <asm/pgalloc.h>
  26. #include <asm/pgtable.h>
  27. #include <linux/kvm_host.h>
  28. #include "interrupt.h"
  29. #include "commpage.h"
  30. #define CREATE_TRACE_POINTS
  31. #include "trace.h"
  32. #ifndef VECTORSPACING
  33. #define VECTORSPACING 0x100 /* for EI/VI mode */
  34. #endif
  35. #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x)
  36. struct kvm_stats_debugfs_item debugfs_entries[] = {
  37. { "wait", VCPU_STAT(wait_exits), KVM_STAT_VCPU },
  38. { "cache", VCPU_STAT(cache_exits), KVM_STAT_VCPU },
  39. { "signal", VCPU_STAT(signal_exits), KVM_STAT_VCPU },
  40. { "interrupt", VCPU_STAT(int_exits), KVM_STAT_VCPU },
  41. { "cop_unsuable", VCPU_STAT(cop_unusable_exits), KVM_STAT_VCPU },
  42. { "tlbmod", VCPU_STAT(tlbmod_exits), KVM_STAT_VCPU },
  43. { "tlbmiss_ld", VCPU_STAT(tlbmiss_ld_exits), KVM_STAT_VCPU },
  44. { "tlbmiss_st", VCPU_STAT(tlbmiss_st_exits), KVM_STAT_VCPU },
  45. { "addrerr_st", VCPU_STAT(addrerr_st_exits), KVM_STAT_VCPU },
  46. { "addrerr_ld", VCPU_STAT(addrerr_ld_exits), KVM_STAT_VCPU },
  47. { "syscall", VCPU_STAT(syscall_exits), KVM_STAT_VCPU },
  48. { "resvd_inst", VCPU_STAT(resvd_inst_exits), KVM_STAT_VCPU },
  49. { "break_inst", VCPU_STAT(break_inst_exits), KVM_STAT_VCPU },
  50. { "trap_inst", VCPU_STAT(trap_inst_exits), KVM_STAT_VCPU },
  51. { "msa_fpe", VCPU_STAT(msa_fpe_exits), KVM_STAT_VCPU },
  52. { "fpe", VCPU_STAT(fpe_exits), KVM_STAT_VCPU },
  53. { "msa_disabled", VCPU_STAT(msa_disabled_exits), KVM_STAT_VCPU },
  54. { "flush_dcache", VCPU_STAT(flush_dcache_exits), KVM_STAT_VCPU },
  55. #ifdef CONFIG_KVM_MIPS_VZ
  56. { "vz_gpsi", VCPU_STAT(vz_gpsi_exits), KVM_STAT_VCPU },
  57. { "vz_gsfc", VCPU_STAT(vz_gsfc_exits), KVM_STAT_VCPU },
  58. { "vz_hc", VCPU_STAT(vz_hc_exits), KVM_STAT_VCPU },
  59. { "vz_grr", VCPU_STAT(vz_grr_exits), KVM_STAT_VCPU },
  60. { "vz_gva", VCPU_STAT(vz_gva_exits), KVM_STAT_VCPU },
  61. { "vz_ghfc", VCPU_STAT(vz_ghfc_exits), KVM_STAT_VCPU },
  62. { "vz_gpa", VCPU_STAT(vz_gpa_exits), KVM_STAT_VCPU },
  63. { "vz_resvd", VCPU_STAT(vz_resvd_exits), KVM_STAT_VCPU },
  64. #endif
  65. { "halt_successful_poll", VCPU_STAT(halt_successful_poll), KVM_STAT_VCPU },
  66. { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll), KVM_STAT_VCPU },
  67. { "halt_poll_invalid", VCPU_STAT(halt_poll_invalid), KVM_STAT_VCPU },
  68. { "halt_wakeup", VCPU_STAT(halt_wakeup), KVM_STAT_VCPU },
  69. {NULL}
  70. };
  71. bool kvm_trace_guest_mode_change;
  72. int kvm_guest_mode_change_trace_reg(void)
  73. {
  74. kvm_trace_guest_mode_change = 1;
  75. return 0;
  76. }
  77. void kvm_guest_mode_change_trace_unreg(void)
  78. {
  79. kvm_trace_guest_mode_change = 0;
  80. }
  81. /*
  82. * XXXKYMA: We are simulatoring a processor that has the WII bit set in
  83. * Config7, so we are "runnable" if interrupts are pending
  84. */
  85. int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
  86. {
  87. return !!(vcpu->arch.pending_exceptions);
  88. }
  89. int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
  90. {
  91. return 1;
  92. }
  93. int kvm_arch_hardware_enable(void)
  94. {
  95. return kvm_mips_callbacks->hardware_enable();
  96. }
  97. void kvm_arch_hardware_disable(void)
  98. {
  99. kvm_mips_callbacks->hardware_disable();
  100. }
  101. int kvm_arch_hardware_setup(void)
  102. {
  103. return 0;
  104. }
  105. void kvm_arch_check_processor_compat(void *rtn)
  106. {
  107. *(int *)rtn = 0;
  108. }
  109. int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
  110. {
  111. switch (type) {
  112. #ifdef CONFIG_KVM_MIPS_VZ
  113. case KVM_VM_MIPS_VZ:
  114. #else
  115. case KVM_VM_MIPS_TE:
  116. #endif
  117. break;
  118. default:
  119. /* Unsupported KVM type */
  120. return -EINVAL;
  121. };
  122. /* Allocate page table to map GPA -> RPA */
  123. kvm->arch.gpa_mm.pgd = kvm_pgd_alloc();
  124. if (!kvm->arch.gpa_mm.pgd)
  125. return -ENOMEM;
  126. return 0;
  127. }
  128. bool kvm_arch_has_vcpu_debugfs(void)
  129. {
  130. return false;
  131. }
  132. int kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
  133. {
  134. return 0;
  135. }
  136. void kvm_mips_free_vcpus(struct kvm *kvm)
  137. {
  138. unsigned int i;
  139. struct kvm_vcpu *vcpu;
  140. kvm_for_each_vcpu(i, vcpu, kvm) {
  141. kvm_arch_vcpu_free(vcpu);
  142. }
  143. mutex_lock(&kvm->lock);
  144. for (i = 0; i < atomic_read(&kvm->online_vcpus); i++)
  145. kvm->vcpus[i] = NULL;
  146. atomic_set(&kvm->online_vcpus, 0);
  147. mutex_unlock(&kvm->lock);
  148. }
  149. static void kvm_mips_free_gpa_pt(struct kvm *kvm)
  150. {
  151. /* It should always be safe to remove after flushing the whole range */
  152. WARN_ON(!kvm_mips_flush_gpa_pt(kvm, 0, ~0));
  153. pgd_free(NULL, kvm->arch.gpa_mm.pgd);
  154. }
  155. void kvm_arch_destroy_vm(struct kvm *kvm)
  156. {
  157. kvm_mips_free_vcpus(kvm);
  158. kvm_mips_free_gpa_pt(kvm);
  159. }
  160. long kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl,
  161. unsigned long arg)
  162. {
  163. return -ENOIOCTLCMD;
  164. }
  165. int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot,
  166. unsigned long npages)
  167. {
  168. return 0;
  169. }
  170. void kvm_arch_flush_shadow_all(struct kvm *kvm)
  171. {
  172. /* Flush whole GPA */
  173. kvm_mips_flush_gpa_pt(kvm, 0, ~0);
  174. /* Let implementation do the rest */
  175. kvm_mips_callbacks->flush_shadow_all(kvm);
  176. }
  177. void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
  178. struct kvm_memory_slot *slot)
  179. {
  180. /*
  181. * The slot has been made invalid (ready for moving or deletion), so we
  182. * need to ensure that it can no longer be accessed by any guest VCPUs.
  183. */
  184. spin_lock(&kvm->mmu_lock);
  185. /* Flush slot from GPA */
  186. kvm_mips_flush_gpa_pt(kvm, slot->base_gfn,
  187. slot->base_gfn + slot->npages - 1);
  188. /* Let implementation do the rest */
  189. kvm_mips_callbacks->flush_shadow_memslot(kvm, slot);
  190. spin_unlock(&kvm->mmu_lock);
  191. }
  192. int kvm_arch_prepare_memory_region(struct kvm *kvm,
  193. struct kvm_memory_slot *memslot,
  194. const struct kvm_userspace_memory_region *mem,
  195. enum kvm_mr_change change)
  196. {
  197. return 0;
  198. }
  199. void kvm_arch_commit_memory_region(struct kvm *kvm,
  200. const struct kvm_userspace_memory_region *mem,
  201. const struct kvm_memory_slot *old,
  202. const struct kvm_memory_slot *new,
  203. enum kvm_mr_change change)
  204. {
  205. int needs_flush;
  206. kvm_debug("%s: kvm: %p slot: %d, GPA: %llx, size: %llx, QVA: %llx\n",
  207. __func__, kvm, mem->slot, mem->guest_phys_addr,
  208. mem->memory_size, mem->userspace_addr);
  209. /*
  210. * If dirty page logging is enabled, write protect all pages in the slot
  211. * ready for dirty logging.
  212. *
  213. * There is no need to do this in any of the following cases:
  214. * CREATE: No dirty mappings will already exist.
  215. * MOVE/DELETE: The old mappings will already have been cleaned up by
  216. * kvm_arch_flush_shadow_memslot()
  217. */
  218. if (change == KVM_MR_FLAGS_ONLY &&
  219. (!(old->flags & KVM_MEM_LOG_DIRTY_PAGES) &&
  220. new->flags & KVM_MEM_LOG_DIRTY_PAGES)) {
  221. spin_lock(&kvm->mmu_lock);
  222. /* Write protect GPA page table entries */
  223. needs_flush = kvm_mips_mkclean_gpa_pt(kvm, new->base_gfn,
  224. new->base_gfn + new->npages - 1);
  225. /* Let implementation do the rest */
  226. if (needs_flush)
  227. kvm_mips_callbacks->flush_shadow_memslot(kvm, new);
  228. spin_unlock(&kvm->mmu_lock);
  229. }
  230. }
  231. static inline void dump_handler(const char *symbol, void *start, void *end)
  232. {
  233. u32 *p;
  234. pr_debug("LEAF(%s)\n", symbol);
  235. pr_debug("\t.set push\n");
  236. pr_debug("\t.set noreorder\n");
  237. for (p = start; p < (u32 *)end; ++p)
  238. pr_debug("\t.word\t0x%08x\t\t# %p\n", *p, p);
  239. pr_debug("\t.set\tpop\n");
  240. pr_debug("\tEND(%s)\n", symbol);
  241. }
  242. struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
  243. {
  244. int err, size;
  245. void *gebase, *p, *handler, *refill_start, *refill_end;
  246. int i;
  247. struct kvm_vcpu *vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL);
  248. if (!vcpu) {
  249. err = -ENOMEM;
  250. goto out;
  251. }
  252. err = kvm_vcpu_init(vcpu, kvm, id);
  253. if (err)
  254. goto out_free_cpu;
  255. kvm_debug("kvm @ %p: create cpu %d at %p\n", kvm, id, vcpu);
  256. /*
  257. * Allocate space for host mode exception handlers that handle
  258. * guest mode exits
  259. */
  260. if (cpu_has_veic || cpu_has_vint)
  261. size = 0x200 + VECTORSPACING * 64;
  262. else
  263. size = 0x4000;
  264. gebase = kzalloc(ALIGN(size, PAGE_SIZE), GFP_KERNEL);
  265. if (!gebase) {
  266. err = -ENOMEM;
  267. goto out_uninit_cpu;
  268. }
  269. kvm_debug("Allocated %d bytes for KVM Exception Handlers @ %p\n",
  270. ALIGN(size, PAGE_SIZE), gebase);
  271. /*
  272. * Check new ebase actually fits in CP0_EBase. The lack of a write gate
  273. * limits us to the low 512MB of physical address space. If the memory
  274. * we allocate is out of range, just give up now.
  275. */
  276. if (!cpu_has_ebase_wg && virt_to_phys(gebase) >= 0x20000000) {
  277. kvm_err("CP0_EBase.WG required for guest exception base %pK\n",
  278. gebase);
  279. err = -ENOMEM;
  280. goto out_free_gebase;
  281. }
  282. /* Save new ebase */
  283. vcpu->arch.guest_ebase = gebase;
  284. /* Build guest exception vectors dynamically in unmapped memory */
  285. handler = gebase + 0x2000;
  286. /* TLB refill (or XTLB refill on 64-bit VZ where KX=1) */
  287. refill_start = gebase;
  288. if (IS_ENABLED(CONFIG_KVM_MIPS_VZ) && IS_ENABLED(CONFIG_64BIT))
  289. refill_start += 0x080;
  290. refill_end = kvm_mips_build_tlb_refill_exception(refill_start, handler);
  291. /* General Exception Entry point */
  292. kvm_mips_build_exception(gebase + 0x180, handler);
  293. /* For vectored interrupts poke the exception code @ all offsets 0-7 */
  294. for (i = 0; i < 8; i++) {
  295. kvm_debug("L1 Vectored handler @ %p\n",
  296. gebase + 0x200 + (i * VECTORSPACING));
  297. kvm_mips_build_exception(gebase + 0x200 + i * VECTORSPACING,
  298. handler);
  299. }
  300. /* General exit handler */
  301. p = handler;
  302. p = kvm_mips_build_exit(p);
  303. /* Guest entry routine */
  304. vcpu->arch.vcpu_run = p;
  305. p = kvm_mips_build_vcpu_run(p);
  306. /* Dump the generated code */
  307. pr_debug("#include <asm/asm.h>\n");
  308. pr_debug("#include <asm/regdef.h>\n");
  309. pr_debug("\n");
  310. dump_handler("kvm_vcpu_run", vcpu->arch.vcpu_run, p);
  311. dump_handler("kvm_tlb_refill", refill_start, refill_end);
  312. dump_handler("kvm_gen_exc", gebase + 0x180, gebase + 0x200);
  313. dump_handler("kvm_exit", gebase + 0x2000, vcpu->arch.vcpu_run);
  314. /* Invalidate the icache for these ranges */
  315. flush_icache_range((unsigned long)gebase,
  316. (unsigned long)gebase + ALIGN(size, PAGE_SIZE));
  317. /*
  318. * Allocate comm page for guest kernel, a TLB will be reserved for
  319. * mapping GVA @ 0xFFFF8000 to this page
  320. */
  321. vcpu->arch.kseg0_commpage = kzalloc(PAGE_SIZE << 1, GFP_KERNEL);
  322. if (!vcpu->arch.kseg0_commpage) {
  323. err = -ENOMEM;
  324. goto out_free_gebase;
  325. }
  326. kvm_debug("Allocated COMM page @ %p\n", vcpu->arch.kseg0_commpage);
  327. kvm_mips_commpage_init(vcpu);
  328. /* Init */
  329. vcpu->arch.last_sched_cpu = -1;
  330. vcpu->arch.last_exec_cpu = -1;
  331. return vcpu;
  332. out_free_gebase:
  333. kfree(gebase);
  334. out_uninit_cpu:
  335. kvm_vcpu_uninit(vcpu);
  336. out_free_cpu:
  337. kfree(vcpu);
  338. out:
  339. return ERR_PTR(err);
  340. }
  341. void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
  342. {
  343. hrtimer_cancel(&vcpu->arch.comparecount_timer);
  344. kvm_vcpu_uninit(vcpu);
  345. kvm_mips_dump_stats(vcpu);
  346. kvm_mmu_free_memory_caches(vcpu);
  347. kfree(vcpu->arch.guest_ebase);
  348. kfree(vcpu->arch.kseg0_commpage);
  349. kfree(vcpu);
  350. }
  351. void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
  352. {
  353. kvm_arch_vcpu_free(vcpu);
  354. }
  355. int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
  356. struct kvm_guest_debug *dbg)
  357. {
  358. return -ENOIOCTLCMD;
  359. }
  360. int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  361. {
  362. int r = -EINTR;
  363. sigset_t sigsaved;
  364. if (vcpu->sigset_active)
  365. sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
  366. if (vcpu->mmio_needed) {
  367. if (!vcpu->mmio_is_write)
  368. kvm_mips_complete_mmio_load(vcpu, run);
  369. vcpu->mmio_needed = 0;
  370. }
  371. if (run->immediate_exit)
  372. goto out;
  373. lose_fpu(1);
  374. local_irq_disable();
  375. guest_enter_irqoff();
  376. trace_kvm_enter(vcpu);
  377. /*
  378. * Make sure the read of VCPU requests in vcpu_run() callback is not
  379. * reordered ahead of the write to vcpu->mode, or we could miss a TLB
  380. * flush request while the requester sees the VCPU as outside of guest
  381. * mode and not needing an IPI.
  382. */
  383. smp_store_mb(vcpu->mode, IN_GUEST_MODE);
  384. r = kvm_mips_callbacks->vcpu_run(run, vcpu);
  385. trace_kvm_out(vcpu);
  386. guest_exit_irqoff();
  387. local_irq_enable();
  388. out:
  389. if (vcpu->sigset_active)
  390. sigprocmask(SIG_SETMASK, &sigsaved, NULL);
  391. return r;
  392. }
  393. int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
  394. struct kvm_mips_interrupt *irq)
  395. {
  396. int intr = (int)irq->irq;
  397. struct kvm_vcpu *dvcpu = NULL;
  398. if (intr == 3 || intr == -3 || intr == 4 || intr == -4)
  399. kvm_debug("%s: CPU: %d, INTR: %d\n", __func__, irq->cpu,
  400. (int)intr);
  401. if (irq->cpu == -1)
  402. dvcpu = vcpu;
  403. else
  404. dvcpu = vcpu->kvm->vcpus[irq->cpu];
  405. if (intr == 2 || intr == 3 || intr == 4) {
  406. kvm_mips_callbacks->queue_io_int(dvcpu, irq);
  407. } else if (intr == -2 || intr == -3 || intr == -4) {
  408. kvm_mips_callbacks->dequeue_io_int(dvcpu, irq);
  409. } else {
  410. kvm_err("%s: invalid interrupt ioctl (%d:%d)\n", __func__,
  411. irq->cpu, irq->irq);
  412. return -EINVAL;
  413. }
  414. dvcpu->arch.wait = 0;
  415. if (swait_active(&dvcpu->wq))
  416. swake_up(&dvcpu->wq);
  417. return 0;
  418. }
  419. int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
  420. struct kvm_mp_state *mp_state)
  421. {
  422. return -ENOIOCTLCMD;
  423. }
  424. int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
  425. struct kvm_mp_state *mp_state)
  426. {
  427. return -ENOIOCTLCMD;
  428. }
  429. static u64 kvm_mips_get_one_regs[] = {
  430. KVM_REG_MIPS_R0,
  431. KVM_REG_MIPS_R1,
  432. KVM_REG_MIPS_R2,
  433. KVM_REG_MIPS_R3,
  434. KVM_REG_MIPS_R4,
  435. KVM_REG_MIPS_R5,
  436. KVM_REG_MIPS_R6,
  437. KVM_REG_MIPS_R7,
  438. KVM_REG_MIPS_R8,
  439. KVM_REG_MIPS_R9,
  440. KVM_REG_MIPS_R10,
  441. KVM_REG_MIPS_R11,
  442. KVM_REG_MIPS_R12,
  443. KVM_REG_MIPS_R13,
  444. KVM_REG_MIPS_R14,
  445. KVM_REG_MIPS_R15,
  446. KVM_REG_MIPS_R16,
  447. KVM_REG_MIPS_R17,
  448. KVM_REG_MIPS_R18,
  449. KVM_REG_MIPS_R19,
  450. KVM_REG_MIPS_R20,
  451. KVM_REG_MIPS_R21,
  452. KVM_REG_MIPS_R22,
  453. KVM_REG_MIPS_R23,
  454. KVM_REG_MIPS_R24,
  455. KVM_REG_MIPS_R25,
  456. KVM_REG_MIPS_R26,
  457. KVM_REG_MIPS_R27,
  458. KVM_REG_MIPS_R28,
  459. KVM_REG_MIPS_R29,
  460. KVM_REG_MIPS_R30,
  461. KVM_REG_MIPS_R31,
  462. #ifndef CONFIG_CPU_MIPSR6
  463. KVM_REG_MIPS_HI,
  464. KVM_REG_MIPS_LO,
  465. #endif
  466. KVM_REG_MIPS_PC,
  467. };
  468. static u64 kvm_mips_get_one_regs_fpu[] = {
  469. KVM_REG_MIPS_FCR_IR,
  470. KVM_REG_MIPS_FCR_CSR,
  471. };
  472. static u64 kvm_mips_get_one_regs_msa[] = {
  473. KVM_REG_MIPS_MSA_IR,
  474. KVM_REG_MIPS_MSA_CSR,
  475. };
  476. static unsigned long kvm_mips_num_regs(struct kvm_vcpu *vcpu)
  477. {
  478. unsigned long ret;
  479. ret = ARRAY_SIZE(kvm_mips_get_one_regs);
  480. if (kvm_mips_guest_can_have_fpu(&vcpu->arch)) {
  481. ret += ARRAY_SIZE(kvm_mips_get_one_regs_fpu) + 48;
  482. /* odd doubles */
  483. if (boot_cpu_data.fpu_id & MIPS_FPIR_F64)
  484. ret += 16;
  485. }
  486. if (kvm_mips_guest_can_have_msa(&vcpu->arch))
  487. ret += ARRAY_SIZE(kvm_mips_get_one_regs_msa) + 32;
  488. ret += kvm_mips_callbacks->num_regs(vcpu);
  489. return ret;
  490. }
  491. static int kvm_mips_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices)
  492. {
  493. u64 index;
  494. unsigned int i;
  495. if (copy_to_user(indices, kvm_mips_get_one_regs,
  496. sizeof(kvm_mips_get_one_regs)))
  497. return -EFAULT;
  498. indices += ARRAY_SIZE(kvm_mips_get_one_regs);
  499. if (kvm_mips_guest_can_have_fpu(&vcpu->arch)) {
  500. if (copy_to_user(indices, kvm_mips_get_one_regs_fpu,
  501. sizeof(kvm_mips_get_one_regs_fpu)))
  502. return -EFAULT;
  503. indices += ARRAY_SIZE(kvm_mips_get_one_regs_fpu);
  504. for (i = 0; i < 32; ++i) {
  505. index = KVM_REG_MIPS_FPR_32(i);
  506. if (copy_to_user(indices, &index, sizeof(index)))
  507. return -EFAULT;
  508. ++indices;
  509. /* skip odd doubles if no F64 */
  510. if (i & 1 && !(boot_cpu_data.fpu_id & MIPS_FPIR_F64))
  511. continue;
  512. index = KVM_REG_MIPS_FPR_64(i);
  513. if (copy_to_user(indices, &index, sizeof(index)))
  514. return -EFAULT;
  515. ++indices;
  516. }
  517. }
  518. if (kvm_mips_guest_can_have_msa(&vcpu->arch)) {
  519. if (copy_to_user(indices, kvm_mips_get_one_regs_msa,
  520. sizeof(kvm_mips_get_one_regs_msa)))
  521. return -EFAULT;
  522. indices += ARRAY_SIZE(kvm_mips_get_one_regs_msa);
  523. for (i = 0; i < 32; ++i) {
  524. index = KVM_REG_MIPS_VEC_128(i);
  525. if (copy_to_user(indices, &index, sizeof(index)))
  526. return -EFAULT;
  527. ++indices;
  528. }
  529. }
  530. return kvm_mips_callbacks->copy_reg_indices(vcpu, indices);
  531. }
  532. static int kvm_mips_get_reg(struct kvm_vcpu *vcpu,
  533. const struct kvm_one_reg *reg)
  534. {
  535. struct mips_coproc *cop0 = vcpu->arch.cop0;
  536. struct mips_fpu_struct *fpu = &vcpu->arch.fpu;
  537. int ret;
  538. s64 v;
  539. s64 vs[2];
  540. unsigned int idx;
  541. switch (reg->id) {
  542. /* General purpose registers */
  543. case KVM_REG_MIPS_R0 ... KVM_REG_MIPS_R31:
  544. v = (long)vcpu->arch.gprs[reg->id - KVM_REG_MIPS_R0];
  545. break;
  546. #ifndef CONFIG_CPU_MIPSR6
  547. case KVM_REG_MIPS_HI:
  548. v = (long)vcpu->arch.hi;
  549. break;
  550. case KVM_REG_MIPS_LO:
  551. v = (long)vcpu->arch.lo;
  552. break;
  553. #endif
  554. case KVM_REG_MIPS_PC:
  555. v = (long)vcpu->arch.pc;
  556. break;
  557. /* Floating point registers */
  558. case KVM_REG_MIPS_FPR_32(0) ... KVM_REG_MIPS_FPR_32(31):
  559. if (!kvm_mips_guest_has_fpu(&vcpu->arch))
  560. return -EINVAL;
  561. idx = reg->id - KVM_REG_MIPS_FPR_32(0);
  562. /* Odd singles in top of even double when FR=0 */
  563. if (kvm_read_c0_guest_status(cop0) & ST0_FR)
  564. v = get_fpr32(&fpu->fpr[idx], 0);
  565. else
  566. v = get_fpr32(&fpu->fpr[idx & ~1], idx & 1);
  567. break;
  568. case KVM_REG_MIPS_FPR_64(0) ... KVM_REG_MIPS_FPR_64(31):
  569. if (!kvm_mips_guest_has_fpu(&vcpu->arch))
  570. return -EINVAL;
  571. idx = reg->id - KVM_REG_MIPS_FPR_64(0);
  572. /* Can't access odd doubles in FR=0 mode */
  573. if (idx & 1 && !(kvm_read_c0_guest_status(cop0) & ST0_FR))
  574. return -EINVAL;
  575. v = get_fpr64(&fpu->fpr[idx], 0);
  576. break;
  577. case KVM_REG_MIPS_FCR_IR:
  578. if (!kvm_mips_guest_has_fpu(&vcpu->arch))
  579. return -EINVAL;
  580. v = boot_cpu_data.fpu_id;
  581. break;
  582. case KVM_REG_MIPS_FCR_CSR:
  583. if (!kvm_mips_guest_has_fpu(&vcpu->arch))
  584. return -EINVAL;
  585. v = fpu->fcr31;
  586. break;
  587. /* MIPS SIMD Architecture (MSA) registers */
  588. case KVM_REG_MIPS_VEC_128(0) ... KVM_REG_MIPS_VEC_128(31):
  589. if (!kvm_mips_guest_has_msa(&vcpu->arch))
  590. return -EINVAL;
  591. /* Can't access MSA registers in FR=0 mode */
  592. if (!(kvm_read_c0_guest_status(cop0) & ST0_FR))
  593. return -EINVAL;
  594. idx = reg->id - KVM_REG_MIPS_VEC_128(0);
  595. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  596. /* least significant byte first */
  597. vs[0] = get_fpr64(&fpu->fpr[idx], 0);
  598. vs[1] = get_fpr64(&fpu->fpr[idx], 1);
  599. #else
  600. /* most significant byte first */
  601. vs[0] = get_fpr64(&fpu->fpr[idx], 1);
  602. vs[1] = get_fpr64(&fpu->fpr[idx], 0);
  603. #endif
  604. break;
  605. case KVM_REG_MIPS_MSA_IR:
  606. if (!kvm_mips_guest_has_msa(&vcpu->arch))
  607. return -EINVAL;
  608. v = boot_cpu_data.msa_id;
  609. break;
  610. case KVM_REG_MIPS_MSA_CSR:
  611. if (!kvm_mips_guest_has_msa(&vcpu->arch))
  612. return -EINVAL;
  613. v = fpu->msacsr;
  614. break;
  615. /* registers to be handled specially */
  616. default:
  617. ret = kvm_mips_callbacks->get_one_reg(vcpu, reg, &v);
  618. if (ret)
  619. return ret;
  620. break;
  621. }
  622. if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U64) {
  623. u64 __user *uaddr64 = (u64 __user *)(long)reg->addr;
  624. return put_user(v, uaddr64);
  625. } else if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U32) {
  626. u32 __user *uaddr32 = (u32 __user *)(long)reg->addr;
  627. u32 v32 = (u32)v;
  628. return put_user(v32, uaddr32);
  629. } else if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U128) {
  630. void __user *uaddr = (void __user *)(long)reg->addr;
  631. return copy_to_user(uaddr, vs, 16) ? -EFAULT : 0;
  632. } else {
  633. return -EINVAL;
  634. }
  635. }
  636. static int kvm_mips_set_reg(struct kvm_vcpu *vcpu,
  637. const struct kvm_one_reg *reg)
  638. {
  639. struct mips_coproc *cop0 = vcpu->arch.cop0;
  640. struct mips_fpu_struct *fpu = &vcpu->arch.fpu;
  641. s64 v;
  642. s64 vs[2];
  643. unsigned int idx;
  644. if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U64) {
  645. u64 __user *uaddr64 = (u64 __user *)(long)reg->addr;
  646. if (get_user(v, uaddr64) != 0)
  647. return -EFAULT;
  648. } else if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U32) {
  649. u32 __user *uaddr32 = (u32 __user *)(long)reg->addr;
  650. s32 v32;
  651. if (get_user(v32, uaddr32) != 0)
  652. return -EFAULT;
  653. v = (s64)v32;
  654. } else if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U128) {
  655. void __user *uaddr = (void __user *)(long)reg->addr;
  656. return copy_from_user(vs, uaddr, 16) ? -EFAULT : 0;
  657. } else {
  658. return -EINVAL;
  659. }
  660. switch (reg->id) {
  661. /* General purpose registers */
  662. case KVM_REG_MIPS_R0:
  663. /* Silently ignore requests to set $0 */
  664. break;
  665. case KVM_REG_MIPS_R1 ... KVM_REG_MIPS_R31:
  666. vcpu->arch.gprs[reg->id - KVM_REG_MIPS_R0] = v;
  667. break;
  668. #ifndef CONFIG_CPU_MIPSR6
  669. case KVM_REG_MIPS_HI:
  670. vcpu->arch.hi = v;
  671. break;
  672. case KVM_REG_MIPS_LO:
  673. vcpu->arch.lo = v;
  674. break;
  675. #endif
  676. case KVM_REG_MIPS_PC:
  677. vcpu->arch.pc = v;
  678. break;
  679. /* Floating point registers */
  680. case KVM_REG_MIPS_FPR_32(0) ... KVM_REG_MIPS_FPR_32(31):
  681. if (!kvm_mips_guest_has_fpu(&vcpu->arch))
  682. return -EINVAL;
  683. idx = reg->id - KVM_REG_MIPS_FPR_32(0);
  684. /* Odd singles in top of even double when FR=0 */
  685. if (kvm_read_c0_guest_status(cop0) & ST0_FR)
  686. set_fpr32(&fpu->fpr[idx], 0, v);
  687. else
  688. set_fpr32(&fpu->fpr[idx & ~1], idx & 1, v);
  689. break;
  690. case KVM_REG_MIPS_FPR_64(0) ... KVM_REG_MIPS_FPR_64(31):
  691. if (!kvm_mips_guest_has_fpu(&vcpu->arch))
  692. return -EINVAL;
  693. idx = reg->id - KVM_REG_MIPS_FPR_64(0);
  694. /* Can't access odd doubles in FR=0 mode */
  695. if (idx & 1 && !(kvm_read_c0_guest_status(cop0) & ST0_FR))
  696. return -EINVAL;
  697. set_fpr64(&fpu->fpr[idx], 0, v);
  698. break;
  699. case KVM_REG_MIPS_FCR_IR:
  700. if (!kvm_mips_guest_has_fpu(&vcpu->arch))
  701. return -EINVAL;
  702. /* Read-only */
  703. break;
  704. case KVM_REG_MIPS_FCR_CSR:
  705. if (!kvm_mips_guest_has_fpu(&vcpu->arch))
  706. return -EINVAL;
  707. fpu->fcr31 = v;
  708. break;
  709. /* MIPS SIMD Architecture (MSA) registers */
  710. case KVM_REG_MIPS_VEC_128(0) ... KVM_REG_MIPS_VEC_128(31):
  711. if (!kvm_mips_guest_has_msa(&vcpu->arch))
  712. return -EINVAL;
  713. idx = reg->id - KVM_REG_MIPS_VEC_128(0);
  714. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  715. /* least significant byte first */
  716. set_fpr64(&fpu->fpr[idx], 0, vs[0]);
  717. set_fpr64(&fpu->fpr[idx], 1, vs[1]);
  718. #else
  719. /* most significant byte first */
  720. set_fpr64(&fpu->fpr[idx], 1, vs[0]);
  721. set_fpr64(&fpu->fpr[idx], 0, vs[1]);
  722. #endif
  723. break;
  724. case KVM_REG_MIPS_MSA_IR:
  725. if (!kvm_mips_guest_has_msa(&vcpu->arch))
  726. return -EINVAL;
  727. /* Read-only */
  728. break;
  729. case KVM_REG_MIPS_MSA_CSR:
  730. if (!kvm_mips_guest_has_msa(&vcpu->arch))
  731. return -EINVAL;
  732. fpu->msacsr = v;
  733. break;
  734. /* registers to be handled specially */
  735. default:
  736. return kvm_mips_callbacks->set_one_reg(vcpu, reg, v);
  737. }
  738. return 0;
  739. }
  740. static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
  741. struct kvm_enable_cap *cap)
  742. {
  743. int r = 0;
  744. if (!kvm_vm_ioctl_check_extension(vcpu->kvm, cap->cap))
  745. return -EINVAL;
  746. if (cap->flags)
  747. return -EINVAL;
  748. if (cap->args[0])
  749. return -EINVAL;
  750. switch (cap->cap) {
  751. case KVM_CAP_MIPS_FPU:
  752. vcpu->arch.fpu_enabled = true;
  753. break;
  754. case KVM_CAP_MIPS_MSA:
  755. vcpu->arch.msa_enabled = true;
  756. break;
  757. default:
  758. r = -EINVAL;
  759. break;
  760. }
  761. return r;
  762. }
  763. long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl,
  764. unsigned long arg)
  765. {
  766. struct kvm_vcpu *vcpu = filp->private_data;
  767. void __user *argp = (void __user *)arg;
  768. long r;
  769. switch (ioctl) {
  770. case KVM_SET_ONE_REG:
  771. case KVM_GET_ONE_REG: {
  772. struct kvm_one_reg reg;
  773. if (copy_from_user(&reg, argp, sizeof(reg)))
  774. return -EFAULT;
  775. if (ioctl == KVM_SET_ONE_REG)
  776. return kvm_mips_set_reg(vcpu, &reg);
  777. else
  778. return kvm_mips_get_reg(vcpu, &reg);
  779. }
  780. case KVM_GET_REG_LIST: {
  781. struct kvm_reg_list __user *user_list = argp;
  782. struct kvm_reg_list reg_list;
  783. unsigned n;
  784. if (copy_from_user(&reg_list, user_list, sizeof(reg_list)))
  785. return -EFAULT;
  786. n = reg_list.n;
  787. reg_list.n = kvm_mips_num_regs(vcpu);
  788. if (copy_to_user(user_list, &reg_list, sizeof(reg_list)))
  789. return -EFAULT;
  790. if (n < reg_list.n)
  791. return -E2BIG;
  792. return kvm_mips_copy_reg_indices(vcpu, user_list->reg);
  793. }
  794. case KVM_INTERRUPT:
  795. {
  796. struct kvm_mips_interrupt irq;
  797. if (copy_from_user(&irq, argp, sizeof(irq)))
  798. return -EFAULT;
  799. kvm_debug("[%d] %s: irq: %d\n", vcpu->vcpu_id, __func__,
  800. irq.irq);
  801. r = kvm_vcpu_ioctl_interrupt(vcpu, &irq);
  802. break;
  803. }
  804. case KVM_ENABLE_CAP: {
  805. struct kvm_enable_cap cap;
  806. if (copy_from_user(&cap, argp, sizeof(cap)))
  807. return -EFAULT;
  808. r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
  809. break;
  810. }
  811. default:
  812. r = -ENOIOCTLCMD;
  813. }
  814. return r;
  815. }
  816. /**
  817. * kvm_vm_ioctl_get_dirty_log - get and clear the log of dirty pages in a slot
  818. * @kvm: kvm instance
  819. * @log: slot id and address to which we copy the log
  820. *
  821. * Steps 1-4 below provide general overview of dirty page logging. See
  822. * kvm_get_dirty_log_protect() function description for additional details.
  823. *
  824. * We call kvm_get_dirty_log_protect() to handle steps 1-3, upon return we
  825. * always flush the TLB (step 4) even if previous step failed and the dirty
  826. * bitmap may be corrupt. Regardless of previous outcome the KVM logging API
  827. * does not preclude user space subsequent dirty log read. Flushing TLB ensures
  828. * writes will be marked dirty for next log read.
  829. *
  830. * 1. Take a snapshot of the bit and clear it if needed.
  831. * 2. Write protect the corresponding page.
  832. * 3. Copy the snapshot to the userspace.
  833. * 4. Flush TLB's if needed.
  834. */
  835. int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
  836. {
  837. struct kvm_memslots *slots;
  838. struct kvm_memory_slot *memslot;
  839. bool is_dirty = false;
  840. int r;
  841. mutex_lock(&kvm->slots_lock);
  842. r = kvm_get_dirty_log_protect(kvm, log, &is_dirty);
  843. if (is_dirty) {
  844. slots = kvm_memslots(kvm);
  845. memslot = id_to_memslot(slots, log->slot);
  846. /* Let implementation handle TLB/GVA invalidation */
  847. kvm_mips_callbacks->flush_shadow_memslot(kvm, memslot);
  848. }
  849. mutex_unlock(&kvm->slots_lock);
  850. return r;
  851. }
  852. long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
  853. {
  854. long r;
  855. switch (ioctl) {
  856. default:
  857. r = -ENOIOCTLCMD;
  858. }
  859. return r;
  860. }
  861. int kvm_arch_init(void *opaque)
  862. {
  863. if (kvm_mips_callbacks) {
  864. kvm_err("kvm: module already exists\n");
  865. return -EEXIST;
  866. }
  867. return kvm_mips_emulation_init(&kvm_mips_callbacks);
  868. }
  869. void kvm_arch_exit(void)
  870. {
  871. kvm_mips_callbacks = NULL;
  872. }
  873. int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
  874. struct kvm_sregs *sregs)
  875. {
  876. return -ENOIOCTLCMD;
  877. }
  878. int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
  879. struct kvm_sregs *sregs)
  880. {
  881. return -ENOIOCTLCMD;
  882. }
  883. void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
  884. {
  885. }
  886. int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  887. {
  888. return -ENOIOCTLCMD;
  889. }
  890. int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  891. {
  892. return -ENOIOCTLCMD;
  893. }
  894. int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
  895. {
  896. return VM_FAULT_SIGBUS;
  897. }
  898. int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
  899. {
  900. int r;
  901. switch (ext) {
  902. case KVM_CAP_ONE_REG:
  903. case KVM_CAP_ENABLE_CAP:
  904. case KVM_CAP_READONLY_MEM:
  905. case KVM_CAP_SYNC_MMU:
  906. case KVM_CAP_IMMEDIATE_EXIT:
  907. r = 1;
  908. break;
  909. case KVM_CAP_NR_VCPUS:
  910. r = num_online_cpus();
  911. break;
  912. case KVM_CAP_MAX_VCPUS:
  913. r = KVM_MAX_VCPUS;
  914. break;
  915. case KVM_CAP_MIPS_FPU:
  916. /* We don't handle systems with inconsistent cpu_has_fpu */
  917. r = !!raw_cpu_has_fpu;
  918. break;
  919. case KVM_CAP_MIPS_MSA:
  920. /*
  921. * We don't support MSA vector partitioning yet:
  922. * 1) It would require explicit support which can't be tested
  923. * yet due to lack of support in current hardware.
  924. * 2) It extends the state that would need to be saved/restored
  925. * by e.g. QEMU for migration.
  926. *
  927. * When vector partitioning hardware becomes available, support
  928. * could be added by requiring a flag when enabling
  929. * KVM_CAP_MIPS_MSA capability to indicate that userland knows
  930. * to save/restore the appropriate extra state.
  931. */
  932. r = cpu_has_msa && !(boot_cpu_data.msa_id & MSA_IR_WRPF);
  933. break;
  934. default:
  935. r = kvm_mips_callbacks->check_extension(kvm, ext);
  936. break;
  937. }
  938. return r;
  939. }
  940. int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
  941. {
  942. return kvm_mips_pending_timer(vcpu) ||
  943. kvm_read_c0_guest_cause(vcpu->arch.cop0) & C_TI;
  944. }
  945. int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu)
  946. {
  947. int i;
  948. struct mips_coproc *cop0;
  949. if (!vcpu)
  950. return -1;
  951. kvm_debug("VCPU Register Dump:\n");
  952. kvm_debug("\tpc = 0x%08lx\n", vcpu->arch.pc);
  953. kvm_debug("\texceptions: %08lx\n", vcpu->arch.pending_exceptions);
  954. for (i = 0; i < 32; i += 4) {
  955. kvm_debug("\tgpr%02d: %08lx %08lx %08lx %08lx\n", i,
  956. vcpu->arch.gprs[i],
  957. vcpu->arch.gprs[i + 1],
  958. vcpu->arch.gprs[i + 2], vcpu->arch.gprs[i + 3]);
  959. }
  960. kvm_debug("\thi: 0x%08lx\n", vcpu->arch.hi);
  961. kvm_debug("\tlo: 0x%08lx\n", vcpu->arch.lo);
  962. cop0 = vcpu->arch.cop0;
  963. kvm_debug("\tStatus: 0x%08x, Cause: 0x%08x\n",
  964. kvm_read_c0_guest_status(cop0),
  965. kvm_read_c0_guest_cause(cop0));
  966. kvm_debug("\tEPC: 0x%08lx\n", kvm_read_c0_guest_epc(cop0));
  967. return 0;
  968. }
  969. int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  970. {
  971. int i;
  972. for (i = 1; i < ARRAY_SIZE(vcpu->arch.gprs); i++)
  973. vcpu->arch.gprs[i] = regs->gpr[i];
  974. vcpu->arch.gprs[0] = 0; /* zero is special, and cannot be set. */
  975. vcpu->arch.hi = regs->hi;
  976. vcpu->arch.lo = regs->lo;
  977. vcpu->arch.pc = regs->pc;
  978. return 0;
  979. }
  980. int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  981. {
  982. int i;
  983. for (i = 0; i < ARRAY_SIZE(vcpu->arch.gprs); i++)
  984. regs->gpr[i] = vcpu->arch.gprs[i];
  985. regs->hi = vcpu->arch.hi;
  986. regs->lo = vcpu->arch.lo;
  987. regs->pc = vcpu->arch.pc;
  988. return 0;
  989. }
  990. static void kvm_mips_comparecount_func(unsigned long data)
  991. {
  992. struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
  993. kvm_mips_callbacks->queue_timer_int(vcpu);
  994. vcpu->arch.wait = 0;
  995. if (swait_active(&vcpu->wq))
  996. swake_up(&vcpu->wq);
  997. }
  998. /* low level hrtimer wake routine */
  999. static enum hrtimer_restart kvm_mips_comparecount_wakeup(struct hrtimer *timer)
  1000. {
  1001. struct kvm_vcpu *vcpu;
  1002. vcpu = container_of(timer, struct kvm_vcpu, arch.comparecount_timer);
  1003. kvm_mips_comparecount_func((unsigned long) vcpu);
  1004. return kvm_mips_count_timeout(vcpu);
  1005. }
  1006. int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
  1007. {
  1008. int err;
  1009. err = kvm_mips_callbacks->vcpu_init(vcpu);
  1010. if (err)
  1011. return err;
  1012. hrtimer_init(&vcpu->arch.comparecount_timer, CLOCK_MONOTONIC,
  1013. HRTIMER_MODE_REL);
  1014. vcpu->arch.comparecount_timer.function = kvm_mips_comparecount_wakeup;
  1015. return 0;
  1016. }
  1017. void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
  1018. {
  1019. kvm_mips_callbacks->vcpu_uninit(vcpu);
  1020. }
  1021. int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
  1022. struct kvm_translation *tr)
  1023. {
  1024. return 0;
  1025. }
  1026. /* Initial guest state */
  1027. int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
  1028. {
  1029. return kvm_mips_callbacks->vcpu_setup(vcpu);
  1030. }
  1031. static void kvm_mips_set_c0_status(void)
  1032. {
  1033. u32 status = read_c0_status();
  1034. if (cpu_has_dsp)
  1035. status |= (ST0_MX);
  1036. write_c0_status(status);
  1037. ehb();
  1038. }
  1039. /*
  1040. * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
  1041. */
  1042. int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
  1043. {
  1044. u32 cause = vcpu->arch.host_cp0_cause;
  1045. u32 exccode = (cause >> CAUSEB_EXCCODE) & 0x1f;
  1046. u32 __user *opc = (u32 __user *) vcpu->arch.pc;
  1047. unsigned long badvaddr = vcpu->arch.host_cp0_badvaddr;
  1048. enum emulation_result er = EMULATE_DONE;
  1049. u32 inst;
  1050. int ret = RESUME_GUEST;
  1051. vcpu->mode = OUTSIDE_GUEST_MODE;
  1052. /* re-enable HTW before enabling interrupts */
  1053. if (!IS_ENABLED(CONFIG_KVM_MIPS_VZ))
  1054. htw_start();
  1055. /* Set a default exit reason */
  1056. run->exit_reason = KVM_EXIT_UNKNOWN;
  1057. run->ready_for_interrupt_injection = 1;
  1058. /*
  1059. * Set the appropriate status bits based on host CPU features,
  1060. * before we hit the scheduler
  1061. */
  1062. kvm_mips_set_c0_status();
  1063. local_irq_enable();
  1064. kvm_debug("kvm_mips_handle_exit: cause: %#x, PC: %p, kvm_run: %p, kvm_vcpu: %p\n",
  1065. cause, opc, run, vcpu);
  1066. trace_kvm_exit(vcpu, exccode);
  1067. if (!IS_ENABLED(CONFIG_KVM_MIPS_VZ)) {
  1068. /*
  1069. * Do a privilege check, if in UM most of these exit conditions
  1070. * end up causing an exception to be delivered to the Guest
  1071. * Kernel
  1072. */
  1073. er = kvm_mips_check_privilege(cause, opc, run, vcpu);
  1074. if (er == EMULATE_PRIV_FAIL) {
  1075. goto skip_emul;
  1076. } else if (er == EMULATE_FAIL) {
  1077. run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
  1078. ret = RESUME_HOST;
  1079. goto skip_emul;
  1080. }
  1081. }
  1082. switch (exccode) {
  1083. case EXCCODE_INT:
  1084. kvm_debug("[%d]EXCCODE_INT @ %p\n", vcpu->vcpu_id, opc);
  1085. ++vcpu->stat.int_exits;
  1086. if (need_resched())
  1087. cond_resched();
  1088. ret = RESUME_GUEST;
  1089. break;
  1090. case EXCCODE_CPU:
  1091. kvm_debug("EXCCODE_CPU: @ PC: %p\n", opc);
  1092. ++vcpu->stat.cop_unusable_exits;
  1093. ret = kvm_mips_callbacks->handle_cop_unusable(vcpu);
  1094. /* XXXKYMA: Might need to return to user space */
  1095. if (run->exit_reason == KVM_EXIT_IRQ_WINDOW_OPEN)
  1096. ret = RESUME_HOST;
  1097. break;
  1098. case EXCCODE_MOD:
  1099. ++vcpu->stat.tlbmod_exits;
  1100. ret = kvm_mips_callbacks->handle_tlb_mod(vcpu);
  1101. break;
  1102. case EXCCODE_TLBS:
  1103. kvm_debug("TLB ST fault: cause %#x, status %#x, PC: %p, BadVaddr: %#lx\n",
  1104. cause, kvm_read_c0_guest_status(vcpu->arch.cop0), opc,
  1105. badvaddr);
  1106. ++vcpu->stat.tlbmiss_st_exits;
  1107. ret = kvm_mips_callbacks->handle_tlb_st_miss(vcpu);
  1108. break;
  1109. case EXCCODE_TLBL:
  1110. kvm_debug("TLB LD fault: cause %#x, PC: %p, BadVaddr: %#lx\n",
  1111. cause, opc, badvaddr);
  1112. ++vcpu->stat.tlbmiss_ld_exits;
  1113. ret = kvm_mips_callbacks->handle_tlb_ld_miss(vcpu);
  1114. break;
  1115. case EXCCODE_ADES:
  1116. ++vcpu->stat.addrerr_st_exits;
  1117. ret = kvm_mips_callbacks->handle_addr_err_st(vcpu);
  1118. break;
  1119. case EXCCODE_ADEL:
  1120. ++vcpu->stat.addrerr_ld_exits;
  1121. ret = kvm_mips_callbacks->handle_addr_err_ld(vcpu);
  1122. break;
  1123. case EXCCODE_SYS:
  1124. ++vcpu->stat.syscall_exits;
  1125. ret = kvm_mips_callbacks->handle_syscall(vcpu);
  1126. break;
  1127. case EXCCODE_RI:
  1128. ++vcpu->stat.resvd_inst_exits;
  1129. ret = kvm_mips_callbacks->handle_res_inst(vcpu);
  1130. break;
  1131. case EXCCODE_BP:
  1132. ++vcpu->stat.break_inst_exits;
  1133. ret = kvm_mips_callbacks->handle_break(vcpu);
  1134. break;
  1135. case EXCCODE_TR:
  1136. ++vcpu->stat.trap_inst_exits;
  1137. ret = kvm_mips_callbacks->handle_trap(vcpu);
  1138. break;
  1139. case EXCCODE_MSAFPE:
  1140. ++vcpu->stat.msa_fpe_exits;
  1141. ret = kvm_mips_callbacks->handle_msa_fpe(vcpu);
  1142. break;
  1143. case EXCCODE_FPE:
  1144. ++vcpu->stat.fpe_exits;
  1145. ret = kvm_mips_callbacks->handle_fpe(vcpu);
  1146. break;
  1147. case EXCCODE_MSADIS:
  1148. ++vcpu->stat.msa_disabled_exits;
  1149. ret = kvm_mips_callbacks->handle_msa_disabled(vcpu);
  1150. break;
  1151. case EXCCODE_GE:
  1152. /* defer exit accounting to handler */
  1153. ret = kvm_mips_callbacks->handle_guest_exit(vcpu);
  1154. break;
  1155. default:
  1156. if (cause & CAUSEF_BD)
  1157. opc += 1;
  1158. inst = 0;
  1159. kvm_get_badinstr(opc, vcpu, &inst);
  1160. kvm_err("Exception Code: %d, not yet handled, @ PC: %p, inst: 0x%08x BadVaddr: %#lx Status: %#x\n",
  1161. exccode, opc, inst, badvaddr,
  1162. kvm_read_c0_guest_status(vcpu->arch.cop0));
  1163. kvm_arch_vcpu_dump_regs(vcpu);
  1164. run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
  1165. ret = RESUME_HOST;
  1166. break;
  1167. }
  1168. skip_emul:
  1169. local_irq_disable();
  1170. if (ret == RESUME_GUEST)
  1171. kvm_vz_acquire_htimer(vcpu);
  1172. if (er == EMULATE_DONE && !(ret & RESUME_HOST))
  1173. kvm_mips_deliver_interrupts(vcpu, cause);
  1174. if (!(ret & RESUME_HOST)) {
  1175. /* Only check for signals if not already exiting to userspace */
  1176. if (signal_pending(current)) {
  1177. run->exit_reason = KVM_EXIT_INTR;
  1178. ret = (-EINTR << 2) | RESUME_HOST;
  1179. ++vcpu->stat.signal_exits;
  1180. trace_kvm_exit(vcpu, KVM_TRACE_EXIT_SIGNAL);
  1181. }
  1182. }
  1183. if (ret == RESUME_GUEST) {
  1184. trace_kvm_reenter(vcpu);
  1185. /*
  1186. * Make sure the read of VCPU requests in vcpu_reenter()
  1187. * callback is not reordered ahead of the write to vcpu->mode,
  1188. * or we could miss a TLB flush request while the requester sees
  1189. * the VCPU as outside of guest mode and not needing an IPI.
  1190. */
  1191. smp_store_mb(vcpu->mode, IN_GUEST_MODE);
  1192. kvm_mips_callbacks->vcpu_reenter(run, vcpu);
  1193. /*
  1194. * If FPU / MSA are enabled (i.e. the guest's FPU / MSA context
  1195. * is live), restore FCR31 / MSACSR.
  1196. *
  1197. * This should be before returning to the guest exception
  1198. * vector, as it may well cause an [MSA] FP exception if there
  1199. * are pending exception bits unmasked. (see
  1200. * kvm_mips_csr_die_notifier() for how that is handled).
  1201. */
  1202. if (kvm_mips_guest_has_fpu(&vcpu->arch) &&
  1203. read_c0_status() & ST0_CU1)
  1204. __kvm_restore_fcsr(&vcpu->arch);
  1205. if (kvm_mips_guest_has_msa(&vcpu->arch) &&
  1206. read_c0_config5() & MIPS_CONF5_MSAEN)
  1207. __kvm_restore_msacsr(&vcpu->arch);
  1208. }
  1209. /* Disable HTW before returning to guest or host */
  1210. if (!IS_ENABLED(CONFIG_KVM_MIPS_VZ))
  1211. htw_stop();
  1212. return ret;
  1213. }
  1214. /* Enable FPU for guest and restore context */
  1215. void kvm_own_fpu(struct kvm_vcpu *vcpu)
  1216. {
  1217. struct mips_coproc *cop0 = vcpu->arch.cop0;
  1218. unsigned int sr, cfg5;
  1219. preempt_disable();
  1220. sr = kvm_read_c0_guest_status(cop0);
  1221. /*
  1222. * If MSA state is already live, it is undefined how it interacts with
  1223. * FR=0 FPU state, and we don't want to hit reserved instruction
  1224. * exceptions trying to save the MSA state later when CU=1 && FR=1, so
  1225. * play it safe and save it first.
  1226. *
  1227. * In theory we shouldn't ever hit this case since kvm_lose_fpu() should
  1228. * get called when guest CU1 is set, however we can't trust the guest
  1229. * not to clobber the status register directly via the commpage.
  1230. */
  1231. if (cpu_has_msa && sr & ST0_CU1 && !(sr & ST0_FR) &&
  1232. vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA)
  1233. kvm_lose_fpu(vcpu);
  1234. /*
  1235. * Enable FPU for guest
  1236. * We set FR and FRE according to guest context
  1237. */
  1238. change_c0_status(ST0_CU1 | ST0_FR, sr);
  1239. if (cpu_has_fre) {
  1240. cfg5 = kvm_read_c0_guest_config5(cop0);
  1241. change_c0_config5(MIPS_CONF5_FRE, cfg5);
  1242. }
  1243. enable_fpu_hazard();
  1244. /* If guest FPU state not active, restore it now */
  1245. if (!(vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU)) {
  1246. __kvm_restore_fpu(&vcpu->arch);
  1247. vcpu->arch.aux_inuse |= KVM_MIPS_AUX_FPU;
  1248. trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_FPU);
  1249. } else {
  1250. trace_kvm_aux(vcpu, KVM_TRACE_AUX_ENABLE, KVM_TRACE_AUX_FPU);
  1251. }
  1252. preempt_enable();
  1253. }
  1254. #ifdef CONFIG_CPU_HAS_MSA
  1255. /* Enable MSA for guest and restore context */
  1256. void kvm_own_msa(struct kvm_vcpu *vcpu)
  1257. {
  1258. struct mips_coproc *cop0 = vcpu->arch.cop0;
  1259. unsigned int sr, cfg5;
  1260. preempt_disable();
  1261. /*
  1262. * Enable FPU if enabled in guest, since we're restoring FPU context
  1263. * anyway. We set FR and FRE according to guest context.
  1264. */
  1265. if (kvm_mips_guest_has_fpu(&vcpu->arch)) {
  1266. sr = kvm_read_c0_guest_status(cop0);
  1267. /*
  1268. * If FR=0 FPU state is already live, it is undefined how it
  1269. * interacts with MSA state, so play it safe and save it first.
  1270. */
  1271. if (!(sr & ST0_FR) &&
  1272. (vcpu->arch.aux_inuse & (KVM_MIPS_AUX_FPU |
  1273. KVM_MIPS_AUX_MSA)) == KVM_MIPS_AUX_FPU)
  1274. kvm_lose_fpu(vcpu);
  1275. change_c0_status(ST0_CU1 | ST0_FR, sr);
  1276. if (sr & ST0_CU1 && cpu_has_fre) {
  1277. cfg5 = kvm_read_c0_guest_config5(cop0);
  1278. change_c0_config5(MIPS_CONF5_FRE, cfg5);
  1279. }
  1280. }
  1281. /* Enable MSA for guest */
  1282. set_c0_config5(MIPS_CONF5_MSAEN);
  1283. enable_fpu_hazard();
  1284. switch (vcpu->arch.aux_inuse & (KVM_MIPS_AUX_FPU | KVM_MIPS_AUX_MSA)) {
  1285. case KVM_MIPS_AUX_FPU:
  1286. /*
  1287. * Guest FPU state already loaded, only restore upper MSA state
  1288. */
  1289. __kvm_restore_msa_upper(&vcpu->arch);
  1290. vcpu->arch.aux_inuse |= KVM_MIPS_AUX_MSA;
  1291. trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_MSA);
  1292. break;
  1293. case 0:
  1294. /* Neither FPU or MSA already active, restore full MSA state */
  1295. __kvm_restore_msa(&vcpu->arch);
  1296. vcpu->arch.aux_inuse |= KVM_MIPS_AUX_MSA;
  1297. if (kvm_mips_guest_has_fpu(&vcpu->arch))
  1298. vcpu->arch.aux_inuse |= KVM_MIPS_AUX_FPU;
  1299. trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE,
  1300. KVM_TRACE_AUX_FPU_MSA);
  1301. break;
  1302. default:
  1303. trace_kvm_aux(vcpu, KVM_TRACE_AUX_ENABLE, KVM_TRACE_AUX_MSA);
  1304. break;
  1305. }
  1306. preempt_enable();
  1307. }
  1308. #endif
  1309. /* Drop FPU & MSA without saving it */
  1310. void kvm_drop_fpu(struct kvm_vcpu *vcpu)
  1311. {
  1312. preempt_disable();
  1313. if (cpu_has_msa && vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA) {
  1314. disable_msa();
  1315. trace_kvm_aux(vcpu, KVM_TRACE_AUX_DISCARD, KVM_TRACE_AUX_MSA);
  1316. vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_MSA;
  1317. }
  1318. if (vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU) {
  1319. clear_c0_status(ST0_CU1 | ST0_FR);
  1320. trace_kvm_aux(vcpu, KVM_TRACE_AUX_DISCARD, KVM_TRACE_AUX_FPU);
  1321. vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_FPU;
  1322. }
  1323. preempt_enable();
  1324. }
  1325. /* Save and disable FPU & MSA */
  1326. void kvm_lose_fpu(struct kvm_vcpu *vcpu)
  1327. {
  1328. /*
  1329. * With T&E, FPU & MSA get disabled in root context (hardware) when it
  1330. * is disabled in guest context (software), but the register state in
  1331. * the hardware may still be in use.
  1332. * This is why we explicitly re-enable the hardware before saving.
  1333. */
  1334. preempt_disable();
  1335. if (cpu_has_msa && vcpu->arch.aux_inuse & KVM_MIPS_AUX_MSA) {
  1336. if (!IS_ENABLED(CONFIG_KVM_MIPS_VZ)) {
  1337. set_c0_config5(MIPS_CONF5_MSAEN);
  1338. enable_fpu_hazard();
  1339. }
  1340. __kvm_save_msa(&vcpu->arch);
  1341. trace_kvm_aux(vcpu, KVM_TRACE_AUX_SAVE, KVM_TRACE_AUX_FPU_MSA);
  1342. /* Disable MSA & FPU */
  1343. disable_msa();
  1344. if (vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU) {
  1345. clear_c0_status(ST0_CU1 | ST0_FR);
  1346. disable_fpu_hazard();
  1347. }
  1348. vcpu->arch.aux_inuse &= ~(KVM_MIPS_AUX_FPU | KVM_MIPS_AUX_MSA);
  1349. } else if (vcpu->arch.aux_inuse & KVM_MIPS_AUX_FPU) {
  1350. if (!IS_ENABLED(CONFIG_KVM_MIPS_VZ)) {
  1351. set_c0_status(ST0_CU1);
  1352. enable_fpu_hazard();
  1353. }
  1354. __kvm_save_fpu(&vcpu->arch);
  1355. vcpu->arch.aux_inuse &= ~KVM_MIPS_AUX_FPU;
  1356. trace_kvm_aux(vcpu, KVM_TRACE_AUX_SAVE, KVM_TRACE_AUX_FPU);
  1357. /* Disable FPU */
  1358. clear_c0_status(ST0_CU1 | ST0_FR);
  1359. disable_fpu_hazard();
  1360. }
  1361. preempt_enable();
  1362. }
  1363. /*
  1364. * Step over a specific ctc1 to FCSR and a specific ctcmsa to MSACSR which are
  1365. * used to restore guest FCSR/MSACSR state and may trigger a "harmless" FP/MSAFP
  1366. * exception if cause bits are set in the value being written.
  1367. */
  1368. static int kvm_mips_csr_die_notify(struct notifier_block *self,
  1369. unsigned long cmd, void *ptr)
  1370. {
  1371. struct die_args *args = (struct die_args *)ptr;
  1372. struct pt_regs *regs = args->regs;
  1373. unsigned long pc;
  1374. /* Only interested in FPE and MSAFPE */
  1375. if (cmd != DIE_FP && cmd != DIE_MSAFP)
  1376. return NOTIFY_DONE;
  1377. /* Return immediately if guest context isn't active */
  1378. if (!(current->flags & PF_VCPU))
  1379. return NOTIFY_DONE;
  1380. /* Should never get here from user mode */
  1381. BUG_ON(user_mode(regs));
  1382. pc = instruction_pointer(regs);
  1383. switch (cmd) {
  1384. case DIE_FP:
  1385. /* match 2nd instruction in __kvm_restore_fcsr */
  1386. if (pc != (unsigned long)&__kvm_restore_fcsr + 4)
  1387. return NOTIFY_DONE;
  1388. break;
  1389. case DIE_MSAFP:
  1390. /* match 2nd/3rd instruction in __kvm_restore_msacsr */
  1391. if (!cpu_has_msa ||
  1392. pc < (unsigned long)&__kvm_restore_msacsr + 4 ||
  1393. pc > (unsigned long)&__kvm_restore_msacsr + 8)
  1394. return NOTIFY_DONE;
  1395. break;
  1396. }
  1397. /* Move PC forward a little and continue executing */
  1398. instruction_pointer(regs) += 4;
  1399. return NOTIFY_STOP;
  1400. }
  1401. static struct notifier_block kvm_mips_csr_die_notifier = {
  1402. .notifier_call = kvm_mips_csr_die_notify,
  1403. };
  1404. static int __init kvm_mips_init(void)
  1405. {
  1406. int ret;
  1407. ret = kvm_mips_entry_setup();
  1408. if (ret)
  1409. return ret;
  1410. ret = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
  1411. if (ret)
  1412. return ret;
  1413. register_die_notifier(&kvm_mips_csr_die_notifier);
  1414. return 0;
  1415. }
  1416. static void __exit kvm_mips_exit(void)
  1417. {
  1418. kvm_exit();
  1419. unregister_die_notifier(&kvm_mips_csr_die_notifier);
  1420. }
  1421. module_init(kvm_mips_init);
  1422. module_exit(kvm_mips_exit);
  1423. EXPORT_TRACEPOINT_SYMBOL(kvm_exit);