mips.c 42 KB

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