MIPS: KVM: Fix NULL pointer dereference

After commit 45c7e8af4a5e3f0bea4ac209 ("MIPS: Remove KVM_TE support") we
get a NULL pointer dereference when creating a KVM guest:

[ 146.243409] Starting KVM with MIPS VZ extensions
[ 149.849151] CPU 3 Unable to handle kernel paging request at virtual address 0000000000000300, epc == ffffffffc06356ec, ra == ffffffffc063568c
[ 149.849177] Oops[#1]:
[ 149.849182] CPU: 3 PID: 2265 Comm: qemu-system-mip Not tainted 6.4.0-rc3+ #1671
[ 149.849188] Hardware name: THTF CX TL630 Series/THTF-LS3A4000-7A1000-ML4A, BIOS KL4.1F.TF.D.166.201225.R 12/25/2020
[ 149.849192] $ 0 : 0000000000000000 000000007400cce0 0000000000400004 ffffffff8119c740
[ 149.849209] $ 4 : 000000007400cce1 000000007400cce1 0000000000000000 0000000000000000
[ 149.849221] $ 8 : 000000240058bb36 ffffffff81421ac0 0000000000000000 0000000000400dc0
[ 149.849233] $12 : 9800000102a07cc8 ffffffff80e40e38 0000000000000001 0000000000400dc0
[ 149.849245] $16 : 0000000000000000 9800000106cd0000 9800000106cd0000 9800000100cce000
[ 149.849257] $20 : ffffffffc0632b28 ffffffffc05b31b0 9800000100ccca00 0000000000400000
[ 149.849269] $24 : 9800000106cd09ce ffffffff802f69d0
[ 149.849281] $28 : 9800000102a04000 9800000102a07cd0 98000001106a8000 ffffffffc063568c
[ 149.849293] Hi : 00000335b2111e66
[ 149.849295] Lo : 6668d90061ae0ae9
[ 149.849298] epc : ffffffffc06356ec kvm_vz_vcpu_setup+0xc4/0x328 [kvm]
[ 149.849324] ra : ffffffffc063568c kvm_vz_vcpu_setup+0x64/0x328 [kvm]
[ 149.849336] Status: 7400cce3 KX SX UX KERNEL EXL IE
[ 149.849351] Cause : 1000000c (ExcCode 03)
[ 149.849354] BadVA : 0000000000000300
[ 149.849357] PrId : 0014c004 (ICT Loongson-3)
[ 149.849360] Modules linked in: kvm nfnetlink_queue nfnetlink_log nfnetlink fuse sha256_generic libsha256 cfg80211 rfkill binfmt_misc vfat fat snd_hda_codec_hdmi input_leds led_class snd_hda_intel snd_intel_dspcfg snd_hda_codec snd_hda_core snd_pcm snd_timer snd serio_raw xhci_pci radeon drm_suballoc_helper drm_display_helper xhci_hcd ip_tables x_tables
[ 149.849432] Process qemu-system-mip (pid: 2265, threadinfo=00000000ae2982d2, task=0000000038e09ad4, tls=000000ffeba16030)
[ 149.849439] Stack : 9800000000000003 9800000100ccca00 9800000100ccc000 ffffffffc062cef4
[ 149.849453] 9800000102a07d18 c89b63a7ab338e00 0000000000000000 ffffffff811a0000
[ 149.849465] 0000000000000000 9800000106cd0000 ffffffff80e59938 98000001106a8920
[ 149.849476] ffffffff80e57f30 ffffffffc062854c ffffffff811a0000 9800000102bf4240
[ 149.849488] ffffffffc05b0000 ffffffff80e3a798 000000ff78000000 000000ff78000010
[ 149.849500] 0000000000000255 98000001021f7de0 98000001023f0078 ffffffff81434000
[ 149.849511] 0000000000000000 0000000000000000 9800000102ae0000 980000025e92ae28
[ 149.849523] 0000000000000000 c89b63a7ab338e00 0000000000000001 ffffffff8119dce0
[ 149.849535] 000000ff78000010 ffffffff804f3d3c 9800000102a07eb0 0000000000000255
[ 149.849546] 0000000000000000 ffffffff8049460c 000000ff78000010 0000000000000255
[ 149.849558] ...
[ 149.849565] Call Trace:
[ 149.849567] [<ffffffffc06356ec>] kvm_vz_vcpu_setup+0xc4/0x328 [kvm]
[ 149.849586] [<ffffffffc062cef4>] kvm_arch_vcpu_create+0x184/0x228 [kvm]
[ 149.849605] [<ffffffffc062854c>] kvm_vm_ioctl+0x64c/0xf28 [kvm]
[ 149.849623] [<ffffffff805209c0>] sys_ioctl+0xc8/0x118
[ 149.849631] [<ffffffff80219eb0>] syscall_common+0x34/0x58

The root cause is the deletion of kvm_mips_commpage_init() leaves vcpu
->arch.cop0 NULL. So fix it by making cop0 from a pointer to an embedded
object.

Fixes: 45c7e8af4a5e3f0bea4ac209 ("MIPS: Remove KVM_TE support")
Cc: stable@vger.kernel.org
Reported-by: Yu Zhao <yuzhao@google.com>
Suggested-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by Huacai Chen and committed by Thomas Bogendoerfer e4de2057 65fee014

+36 -36
+3 -3
arch/mips/include/asm/kvm_host.h
··· 317 unsigned int aux_inuse; 318 319 /* COP0 State */ 320 - struct mips_coproc *cop0; 321 322 /* Resume PC after MMIO completion */ 323 unsigned long io_pc; ··· 698 static inline bool kvm_mips_guest_has_fpu(struct kvm_vcpu_arch *vcpu) 699 { 700 return kvm_mips_guest_can_have_fpu(vcpu) && 701 - kvm_read_c0_guest_config1(vcpu->cop0) & MIPS_CONF1_FP; 702 } 703 704 static inline bool kvm_mips_guest_can_have_msa(struct kvm_vcpu_arch *vcpu) ··· 710 static inline bool kvm_mips_guest_has_msa(struct kvm_vcpu_arch *vcpu) 711 { 712 return kvm_mips_guest_can_have_msa(vcpu) && 713 - kvm_read_c0_guest_config3(vcpu->cop0) & MIPS_CONF3_MSA; 714 } 715 716 struct kvm_mips_callbacks {
··· 317 unsigned int aux_inuse; 318 319 /* COP0 State */ 320 + struct mips_coproc cop0; 321 322 /* Resume PC after MMIO completion */ 323 unsigned long io_pc; ··· 698 static inline bool kvm_mips_guest_has_fpu(struct kvm_vcpu_arch *vcpu) 699 { 700 return kvm_mips_guest_can_have_fpu(vcpu) && 701 + kvm_read_c0_guest_config1(&vcpu->cop0) & MIPS_CONF1_FP; 702 } 703 704 static inline bool kvm_mips_guest_can_have_msa(struct kvm_vcpu_arch *vcpu) ··· 710 static inline bool kvm_mips_guest_has_msa(struct kvm_vcpu_arch *vcpu) 711 { 712 return kvm_mips_guest_can_have_msa(vcpu) && 713 + kvm_read_c0_guest_config3(&vcpu->cop0) & MIPS_CONF3_MSA; 714 } 715 716 struct kvm_mips_callbacks {
+11 -11
arch/mips/kvm/emulate.c
··· 312 */ 313 int kvm_mips_count_disabled(struct kvm_vcpu *vcpu) 314 { 315 - struct mips_coproc *cop0 = vcpu->arch.cop0; 316 317 return (vcpu->arch.count_ctl & KVM_REG_MIPS_COUNT_CTL_DC) || 318 (kvm_read_c0_guest_cause(cop0) & CAUSEF_DC); ··· 384 */ 385 static u32 kvm_mips_read_count_running(struct kvm_vcpu *vcpu, ktime_t now) 386 { 387 - struct mips_coproc *cop0 = vcpu->arch.cop0; 388 ktime_t expires, threshold; 389 u32 count, compare; 390 int running; ··· 444 */ 445 u32 kvm_mips_read_count(struct kvm_vcpu *vcpu) 446 { 447 - struct mips_coproc *cop0 = vcpu->arch.cop0; 448 449 /* If count disabled just read static copy of count */ 450 if (kvm_mips_count_disabled(vcpu)) ··· 502 static void kvm_mips_resume_hrtimer(struct kvm_vcpu *vcpu, 503 ktime_t now, u32 count) 504 { 505 - struct mips_coproc *cop0 = vcpu->arch.cop0; 506 u32 compare; 507 u64 delta; 508 ktime_t expire; ··· 603 */ 604 void kvm_mips_write_count(struct kvm_vcpu *vcpu, u32 count) 605 { 606 - struct mips_coproc *cop0 = vcpu->arch.cop0; 607 ktime_t now; 608 609 /* Calculate bias */ ··· 649 */ 650 int kvm_mips_set_count_hz(struct kvm_vcpu *vcpu, s64 count_hz) 651 { 652 - struct mips_coproc *cop0 = vcpu->arch.cop0; 653 int dc; 654 ktime_t now; 655 u32 count; ··· 696 */ 697 void kvm_mips_write_compare(struct kvm_vcpu *vcpu, u32 compare, bool ack) 698 { 699 - struct mips_coproc *cop0 = vcpu->arch.cop0; 700 int dc; 701 u32 old_compare = kvm_read_c0_guest_compare(cop0); 702 s32 delta = compare - old_compare; ··· 779 */ 780 static ktime_t kvm_mips_count_disable(struct kvm_vcpu *vcpu) 781 { 782 - struct mips_coproc *cop0 = vcpu->arch.cop0; 783 u32 count; 784 ktime_t now; 785 ··· 806 */ 807 void kvm_mips_count_disable_cause(struct kvm_vcpu *vcpu) 808 { 809 - struct mips_coproc *cop0 = vcpu->arch.cop0; 810 811 kvm_set_c0_guest_cause(cop0, CAUSEF_DC); 812 if (!(vcpu->arch.count_ctl & KVM_REG_MIPS_COUNT_CTL_DC)) ··· 826 */ 827 void kvm_mips_count_enable_cause(struct kvm_vcpu *vcpu) 828 { 829 - struct mips_coproc *cop0 = vcpu->arch.cop0; 830 u32 count; 831 832 kvm_clear_c0_guest_cause(cop0, CAUSEF_DC); ··· 852 */ 853 int kvm_mips_set_count_ctl(struct kvm_vcpu *vcpu, s64 count_ctl) 854 { 855 - struct mips_coproc *cop0 = vcpu->arch.cop0; 856 s64 changed = count_ctl ^ vcpu->arch.count_ctl; 857 s64 delta; 858 ktime_t expire, now;
··· 312 */ 313 int kvm_mips_count_disabled(struct kvm_vcpu *vcpu) 314 { 315 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 316 317 return (vcpu->arch.count_ctl & KVM_REG_MIPS_COUNT_CTL_DC) || 318 (kvm_read_c0_guest_cause(cop0) & CAUSEF_DC); ··· 384 */ 385 static u32 kvm_mips_read_count_running(struct kvm_vcpu *vcpu, ktime_t now) 386 { 387 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 388 ktime_t expires, threshold; 389 u32 count, compare; 390 int running; ··· 444 */ 445 u32 kvm_mips_read_count(struct kvm_vcpu *vcpu) 446 { 447 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 448 449 /* If count disabled just read static copy of count */ 450 if (kvm_mips_count_disabled(vcpu)) ··· 502 static void kvm_mips_resume_hrtimer(struct kvm_vcpu *vcpu, 503 ktime_t now, u32 count) 504 { 505 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 506 u32 compare; 507 u64 delta; 508 ktime_t expire; ··· 603 */ 604 void kvm_mips_write_count(struct kvm_vcpu *vcpu, u32 count) 605 { 606 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 607 ktime_t now; 608 609 /* Calculate bias */ ··· 649 */ 650 int kvm_mips_set_count_hz(struct kvm_vcpu *vcpu, s64 count_hz) 651 { 652 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 653 int dc; 654 ktime_t now; 655 u32 count; ··· 696 */ 697 void kvm_mips_write_compare(struct kvm_vcpu *vcpu, u32 compare, bool ack) 698 { 699 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 700 int dc; 701 u32 old_compare = kvm_read_c0_guest_compare(cop0); 702 s32 delta = compare - old_compare; ··· 779 */ 780 static ktime_t kvm_mips_count_disable(struct kvm_vcpu *vcpu) 781 { 782 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 783 u32 count; 784 ktime_t now; 785 ··· 806 */ 807 void kvm_mips_count_disable_cause(struct kvm_vcpu *vcpu) 808 { 809 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 810 811 kvm_set_c0_guest_cause(cop0, CAUSEF_DC); 812 if (!(vcpu->arch.count_ctl & KVM_REG_MIPS_COUNT_CTL_DC)) ··· 826 */ 827 void kvm_mips_count_enable_cause(struct kvm_vcpu *vcpu) 828 { 829 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 830 u32 count; 831 832 kvm_clear_c0_guest_cause(cop0, CAUSEF_DC); ··· 852 */ 853 int kvm_mips_set_count_ctl(struct kvm_vcpu *vcpu, s64 count_ctl) 854 { 855 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 856 s64 changed = count_ctl ^ vcpu->arch.count_ctl; 857 s64 delta; 858 ktime_t expire, now;
+8 -8
arch/mips/kvm/mips.c
··· 649 static int kvm_mips_get_reg(struct kvm_vcpu *vcpu, 650 const struct kvm_one_reg *reg) 651 { 652 - struct mips_coproc *cop0 = vcpu->arch.cop0; 653 struct mips_fpu_struct *fpu = &vcpu->arch.fpu; 654 int ret; 655 s64 v; ··· 761 static int kvm_mips_set_reg(struct kvm_vcpu *vcpu, 762 const struct kvm_one_reg *reg) 763 { 764 - struct mips_coproc *cop0 = vcpu->arch.cop0; 765 struct mips_fpu_struct *fpu = &vcpu->arch.fpu; 766 s64 v; 767 s64 vs[2]; ··· 1086 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) 1087 { 1088 return kvm_mips_pending_timer(vcpu) || 1089 - kvm_read_c0_guest_cause(vcpu->arch.cop0) & C_TI; 1090 } 1091 1092 int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu) ··· 1110 kvm_debug("\thi: 0x%08lx\n", vcpu->arch.hi); 1111 kvm_debug("\tlo: 0x%08lx\n", vcpu->arch.lo); 1112 1113 - cop0 = vcpu->arch.cop0; 1114 kvm_debug("\tStatus: 0x%08x, Cause: 0x%08x\n", 1115 kvm_read_c0_guest_status(cop0), 1116 kvm_read_c0_guest_cause(cop0)); ··· 1232 1233 case EXCCODE_TLBS: 1234 kvm_debug("TLB ST fault: cause %#x, status %#x, PC: %p, BadVaddr: %#lx\n", 1235 - cause, kvm_read_c0_guest_status(vcpu->arch.cop0), opc, 1236 badvaddr); 1237 1238 ++vcpu->stat.tlbmiss_st_exits; ··· 1304 kvm_get_badinstr(opc, vcpu, &inst); 1305 kvm_err("Exception Code: %d, not yet handled, @ PC: %p, inst: 0x%08x BadVaddr: %#lx Status: %#x\n", 1306 exccode, opc, inst, badvaddr, 1307 - kvm_read_c0_guest_status(vcpu->arch.cop0)); 1308 kvm_arch_vcpu_dump_regs(vcpu); 1309 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 1310 ret = RESUME_HOST; ··· 1377 /* Enable FPU for guest and restore context */ 1378 void kvm_own_fpu(struct kvm_vcpu *vcpu) 1379 { 1380 - struct mips_coproc *cop0 = vcpu->arch.cop0; 1381 unsigned int sr, cfg5; 1382 1383 preempt_disable(); ··· 1421 /* Enable MSA for guest and restore context */ 1422 void kvm_own_msa(struct kvm_vcpu *vcpu) 1423 { 1424 - struct mips_coproc *cop0 = vcpu->arch.cop0; 1425 unsigned int sr, cfg5; 1426 1427 preempt_disable();
··· 649 static int kvm_mips_get_reg(struct kvm_vcpu *vcpu, 650 const struct kvm_one_reg *reg) 651 { 652 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 653 struct mips_fpu_struct *fpu = &vcpu->arch.fpu; 654 int ret; 655 s64 v; ··· 761 static int kvm_mips_set_reg(struct kvm_vcpu *vcpu, 762 const struct kvm_one_reg *reg) 763 { 764 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 765 struct mips_fpu_struct *fpu = &vcpu->arch.fpu; 766 s64 v; 767 s64 vs[2]; ··· 1086 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) 1087 { 1088 return kvm_mips_pending_timer(vcpu) || 1089 + kvm_read_c0_guest_cause(&vcpu->arch.cop0) & C_TI; 1090 } 1091 1092 int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu) ··· 1110 kvm_debug("\thi: 0x%08lx\n", vcpu->arch.hi); 1111 kvm_debug("\tlo: 0x%08lx\n", vcpu->arch.lo); 1112 1113 + cop0 = &vcpu->arch.cop0; 1114 kvm_debug("\tStatus: 0x%08x, Cause: 0x%08x\n", 1115 kvm_read_c0_guest_status(cop0), 1116 kvm_read_c0_guest_cause(cop0)); ··· 1232 1233 case EXCCODE_TLBS: 1234 kvm_debug("TLB ST fault: cause %#x, status %#x, PC: %p, BadVaddr: %#lx\n", 1235 + cause, kvm_read_c0_guest_status(&vcpu->arch.cop0), opc, 1236 badvaddr); 1237 1238 ++vcpu->stat.tlbmiss_st_exits; ··· 1304 kvm_get_badinstr(opc, vcpu, &inst); 1305 kvm_err("Exception Code: %d, not yet handled, @ PC: %p, inst: 0x%08x BadVaddr: %#lx Status: %#x\n", 1306 exccode, opc, inst, badvaddr, 1307 + kvm_read_c0_guest_status(&vcpu->arch.cop0)); 1308 kvm_arch_vcpu_dump_regs(vcpu); 1309 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 1310 ret = RESUME_HOST; ··· 1377 /* Enable FPU for guest and restore context */ 1378 void kvm_own_fpu(struct kvm_vcpu *vcpu) 1379 { 1380 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 1381 unsigned int sr, cfg5; 1382 1383 preempt_disable(); ··· 1421 /* Enable MSA for guest and restore context */ 1422 void kvm_own_msa(struct kvm_vcpu *vcpu) 1423 { 1424 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 1425 unsigned int sr, cfg5; 1426 1427 preempt_disable();
+4 -4
arch/mips/kvm/trace.h
··· 322 ), 323 324 TP_fast_assign( 325 - __entry->epc = kvm_read_c0_guest_epc(vcpu->arch.cop0); 326 __entry->pc = vcpu->arch.pc; 327 - __entry->badvaddr = kvm_read_c0_guest_badvaddr(vcpu->arch.cop0); 328 - __entry->status = kvm_read_c0_guest_status(vcpu->arch.cop0); 329 - __entry->cause = kvm_read_c0_guest_cause(vcpu->arch.cop0); 330 ), 331 332 TP_printk("EPC: 0x%08lx PC: 0x%08lx Status: 0x%08x Cause: 0x%08x BadVAddr: 0x%08lx",
··· 322 ), 323 324 TP_fast_assign( 325 + __entry->epc = kvm_read_c0_guest_epc(&vcpu->arch.cop0); 326 __entry->pc = vcpu->arch.pc; 327 + __entry->badvaddr = kvm_read_c0_guest_badvaddr(&vcpu->arch.cop0); 328 + __entry->status = kvm_read_c0_guest_status(&vcpu->arch.cop0); 329 + __entry->cause = kvm_read_c0_guest_cause(&vcpu->arch.cop0); 330 ), 331 332 TP_printk("EPC: 0x%08lx PC: 0x%08lx Status: 0x%08x Cause: 0x%08x BadVAddr: 0x%08lx",
+10 -10
arch/mips/kvm/vz.c
··· 422 */ 423 static void kvm_vz_restore_timer(struct kvm_vcpu *vcpu) 424 { 425 - struct mips_coproc *cop0 = vcpu->arch.cop0; 426 u32 cause, compare; 427 428 compare = kvm_read_sw_gc0_compare(cop0); ··· 517 */ 518 static void kvm_vz_save_timer(struct kvm_vcpu *vcpu) 519 { 520 - struct mips_coproc *cop0 = vcpu->arch.cop0; 521 u32 gctl0, compare, cause; 522 523 gctl0 = read_c0_guestctl0(); ··· 863 864 static void kvm_write_maari(struct kvm_vcpu *vcpu, unsigned long val) 865 { 866 - struct mips_coproc *cop0 = vcpu->arch.cop0; 867 868 val &= MIPS_MAARI_INDEX; 869 if (val == MIPS_MAARI_INDEX) ··· 876 u32 *opc, u32 cause, 877 struct kvm_vcpu *vcpu) 878 { 879 - struct mips_coproc *cop0 = vcpu->arch.cop0; 880 enum emulation_result er = EMULATE_DONE; 881 u32 rt, rd, sel; 882 unsigned long curr_pc; ··· 1911 const struct kvm_one_reg *reg, 1912 s64 *v) 1913 { 1914 - struct mips_coproc *cop0 = vcpu->arch.cop0; 1915 unsigned int idx; 1916 1917 switch (reg->id) { ··· 2081 case KVM_REG_MIPS_CP0_MAARI: 2082 if (!cpu_guest_has_maar || cpu_guest_has_dyn_maar) 2083 return -EINVAL; 2084 - *v = kvm_read_sw_gc0_maari(vcpu->arch.cop0); 2085 break; 2086 #ifdef CONFIG_64BIT 2087 case KVM_REG_MIPS_CP0_XCONTEXT: ··· 2135 const struct kvm_one_reg *reg, 2136 s64 v) 2137 { 2138 - struct mips_coproc *cop0 = vcpu->arch.cop0; 2139 unsigned int idx; 2140 int ret = 0; 2141 unsigned int cur, change; ··· 2562 2563 static int kvm_vz_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 2564 { 2565 - struct mips_coproc *cop0 = vcpu->arch.cop0; 2566 bool migrated, all; 2567 2568 /* ··· 2704 2705 static int kvm_vz_vcpu_put(struct kvm_vcpu *vcpu, int cpu) 2706 { 2707 - struct mips_coproc *cop0 = vcpu->arch.cop0; 2708 2709 if (current->flags & PF_VCPU) 2710 kvm_vz_vcpu_save_wired(vcpu); ··· 3076 3077 static int kvm_vz_vcpu_setup(struct kvm_vcpu *vcpu) 3078 { 3079 - struct mips_coproc *cop0 = vcpu->arch.cop0; 3080 unsigned long count_hz = 100*1000*1000; /* default to 100 MHz */ 3081 3082 /*
··· 422 */ 423 static void kvm_vz_restore_timer(struct kvm_vcpu *vcpu) 424 { 425 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 426 u32 cause, compare; 427 428 compare = kvm_read_sw_gc0_compare(cop0); ··· 517 */ 518 static void kvm_vz_save_timer(struct kvm_vcpu *vcpu) 519 { 520 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 521 u32 gctl0, compare, cause; 522 523 gctl0 = read_c0_guestctl0(); ··· 863 864 static void kvm_write_maari(struct kvm_vcpu *vcpu, unsigned long val) 865 { 866 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 867 868 val &= MIPS_MAARI_INDEX; 869 if (val == MIPS_MAARI_INDEX) ··· 876 u32 *opc, u32 cause, 877 struct kvm_vcpu *vcpu) 878 { 879 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 880 enum emulation_result er = EMULATE_DONE; 881 u32 rt, rd, sel; 882 unsigned long curr_pc; ··· 1911 const struct kvm_one_reg *reg, 1912 s64 *v) 1913 { 1914 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 1915 unsigned int idx; 1916 1917 switch (reg->id) { ··· 2081 case KVM_REG_MIPS_CP0_MAARI: 2082 if (!cpu_guest_has_maar || cpu_guest_has_dyn_maar) 2083 return -EINVAL; 2084 + *v = kvm_read_sw_gc0_maari(&vcpu->arch.cop0); 2085 break; 2086 #ifdef CONFIG_64BIT 2087 case KVM_REG_MIPS_CP0_XCONTEXT: ··· 2135 const struct kvm_one_reg *reg, 2136 s64 v) 2137 { 2138 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 2139 unsigned int idx; 2140 int ret = 0; 2141 unsigned int cur, change; ··· 2562 2563 static int kvm_vz_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 2564 { 2565 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 2566 bool migrated, all; 2567 2568 /* ··· 2704 2705 static int kvm_vz_vcpu_put(struct kvm_vcpu *vcpu, int cpu) 2706 { 2707 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 2708 2709 if (current->flags & PF_VCPU) 2710 kvm_vz_vcpu_save_wired(vcpu); ··· 3076 3077 static int kvm_vz_vcpu_setup(struct kvm_vcpu *vcpu) 3078 { 3079 + struct mips_coproc *cop0 = &vcpu->arch.cop0; 3080 unsigned long count_hz = 100*1000*1000; /* default to 100 MHz */ 3081 3082 /*