Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull more KVM updates from Paolo Bonzini:
"The guest side of the asynchronous page fault work has been delayed to
5.9 in order to sync with Thomas's interrupt entry rework, but here's
the rest of the KVM updates for this merge window.

MIPS:
- Loongson port

PPC:
- Fixes

ARM:
- Fixes

x86:
- KVM_SET_USER_MEMORY_REGION optimizations
- Fixes
- Selftest fixes"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (62 commits)
KVM: x86: do not pass poisoned hva to __kvm_set_memory_region
KVM: selftests: fix sync_with_host() in smm_test
KVM: async_pf: Inject 'page ready' event only if 'page not present' was previously injected
KVM: async_pf: Cleanup kvm_setup_async_pf()
kvm: i8254: remove redundant assignment to pointer s
KVM: x86: respect singlestep when emulating instruction
KVM: selftests: Don't probe KVM_CAP_HYPERV_ENLIGHTENED_VMCS when nested VMX is unsupported
KVM: selftests: do not substitute SVM/VMX check with KVM_CAP_NESTED_STATE check
KVM: nVMX: Consult only the "basic" exit reason when routing nested exit
KVM: arm64: Move hyp_symbol_addr() to kvm_asm.h
KVM: arm64: Synchronize sysreg state on injecting an AArch32 exception
KVM: arm64: Make vcpu_cp1x() work on Big Endian hosts
KVM: arm64: Remove host_cpu_context member from vcpu structure
KVM: arm64: Stop sparse from moaning at __hyp_this_cpu_ptr
KVM: arm64: Handle PtrAuth traps early
KVM: x86: Unexport x86_fpu_cache and make it static
KVM: selftests: Ignore KVM 5-level paging support for VM_MODE_PXXV48_4K
KVM: arm64: Save the host's PtrAuth keys in non-preemptible context
KVM: arm64: Stop save/restoring ACTLR_EL1
KVM: arm64: Add emulation for 32bit guests accessing ACTLR2
...

+1801 -740
+30 -3
arch/arm64/include/asm/kvm_asm.h
··· 81 81 82 82 extern char __smccc_workaround_1_smc[__SMCCC_WORKAROUND_1_SMC_SZ]; 83 83 84 - /* Home-grown __this_cpu_{ptr,read} variants that always work at HYP */ 84 + /* 85 + * Obtain the PC-relative address of a kernel symbol 86 + * s: symbol 87 + * 88 + * The goal of this macro is to return a symbol's address based on a 89 + * PC-relative computation, as opposed to a loading the VA from a 90 + * constant pool or something similar. This works well for HYP, as an 91 + * absolute VA is guaranteed to be wrong. Only use this if trying to 92 + * obtain the address of a symbol (i.e. not something you obtained by 93 + * following a pointer). 94 + */ 95 + #define hyp_symbol_addr(s) \ 96 + ({ \ 97 + typeof(s) *addr; \ 98 + asm("adrp %0, %1\n" \ 99 + "add %0, %0, :lo12:%1\n" \ 100 + : "=r" (addr) : "S" (&s)); \ 101 + addr; \ 102 + }) 103 + 104 + /* 105 + * Home-grown __this_cpu_{ptr,read} variants that always work at HYP, 106 + * provided that sym is really a *symbol* and not a pointer obtained from 107 + * a data structure. As for SHIFT_PERCPU_PTR(), the creative casting keeps 108 + * sparse quiet. 109 + */ 85 110 #define __hyp_this_cpu_ptr(sym) \ 86 111 ({ \ 87 - void *__ptr = hyp_symbol_addr(sym); \ 112 + void *__ptr; \ 113 + __verify_pcpu_ptr(&sym); \ 114 + __ptr = hyp_symbol_addr(sym); \ 88 115 __ptr += read_sysreg(tpidr_el2); \ 89 - (typeof(&sym))__ptr; \ 116 + (typeof(sym) __kernel __force *)__ptr; \ 90 117 }) 91 118 92 119 #define __hyp_this_cpu_read(sym) \
-6
arch/arm64/include/asm/kvm_emulate.h
··· 112 112 vcpu->arch.hcr_el2 &= ~(HCR_API | HCR_APK); 113 113 } 114 114 115 - static inline void vcpu_ptrauth_setup_lazy(struct kvm_vcpu *vcpu) 116 - { 117 - if (vcpu_has_ptrauth(vcpu)) 118 - vcpu_ptrauth_disable(vcpu); 119 - } 120 - 121 115 static inline unsigned long vcpu_get_vsesr(struct kvm_vcpu *vcpu) 122 116 { 123 117 return vcpu->arch.vsesr_el2;
+4 -5
arch/arm64/include/asm/kvm_host.h
··· 284 284 struct kvm_guest_debug_arch vcpu_debug_state; 285 285 struct kvm_guest_debug_arch external_debug_state; 286 286 287 - /* Pointer to host CPU context */ 288 - struct kvm_cpu_context *host_cpu_context; 289 - 290 287 struct thread_info *host_thread_info; /* hyp VA */ 291 288 struct user_fpsimd_state *host_fpsimd_state; /* hyp VA */ 292 289 ··· 401 404 * CP14 and CP15 live in the same array, as they are backed by the 402 405 * same system registers. 403 406 */ 404 - #define vcpu_cp14(v,r) ((v)->arch.ctxt.copro[(r)]) 405 - #define vcpu_cp15(v,r) ((v)->arch.ctxt.copro[(r)]) 407 + #define CPx_BIAS IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) 408 + 409 + #define vcpu_cp14(v,r) ((v)->arch.ctxt.copro[(r) ^ CPx_BIAS]) 410 + #define vcpu_cp15(v,r) ((v)->arch.ctxt.copro[(r) ^ CPx_BIAS]) 406 411 407 412 struct kvm_vm_stat { 408 413 ulong remote_tlb_flush;
-20
arch/arm64/include/asm/kvm_mmu.h
··· 108 108 #define kern_hyp_va(v) ((typeof(v))(__kern_hyp_va((unsigned long)(v)))) 109 109 110 110 /* 111 - * Obtain the PC-relative address of a kernel symbol 112 - * s: symbol 113 - * 114 - * The goal of this macro is to return a symbol's address based on a 115 - * PC-relative computation, as opposed to a loading the VA from a 116 - * constant pool or something similar. This works well for HYP, as an 117 - * absolute VA is guaranteed to be wrong. Only use this if trying to 118 - * obtain the address of a symbol (i.e. not something you obtained by 119 - * following a pointer). 120 - */ 121 - #define hyp_symbol_addr(s) \ 122 - ({ \ 123 - typeof(s) *addr; \ 124 - asm("adrp %0, %1\n" \ 125 - "add %0, %0, :lo12:%1\n" \ 126 - : "=r" (addr) : "S" (&s)); \ 127 - addr; \ 128 - }) 129 - 130 - /* 131 111 * We currently support using a VM-specified IPA size. For backward 132 112 * compatibility, the default IPA size is fixed to 40bits. 133 113 */
+28
arch/arm64/kvm/aarch32.c
··· 33 33 [7] = { 4, 4 }, /* FIQ, unused */ 34 34 }; 35 35 36 + static bool pre_fault_synchronize(struct kvm_vcpu *vcpu) 37 + { 38 + preempt_disable(); 39 + if (vcpu->arch.sysregs_loaded_on_cpu) { 40 + kvm_arch_vcpu_put(vcpu); 41 + return true; 42 + } 43 + 44 + preempt_enable(); 45 + return false; 46 + } 47 + 48 + static void post_fault_synchronize(struct kvm_vcpu *vcpu, bool loaded) 49 + { 50 + if (loaded) { 51 + kvm_arch_vcpu_load(vcpu, smp_processor_id()); 52 + preempt_enable(); 53 + } 54 + } 55 + 36 56 /* 37 57 * When an exception is taken, most CPSR fields are left unchanged in the 38 58 * handler. However, some are explicitly overridden (e.g. M[4:0]). ··· 175 155 176 156 void kvm_inject_undef32(struct kvm_vcpu *vcpu) 177 157 { 158 + bool loaded = pre_fault_synchronize(vcpu); 159 + 178 160 prepare_fault32(vcpu, PSR_AA32_MODE_UND, 4); 161 + post_fault_synchronize(vcpu, loaded); 179 162 } 180 163 181 164 /* ··· 191 168 u32 vect_offset; 192 169 u32 *far, *fsr; 193 170 bool is_lpae; 171 + bool loaded; 172 + 173 + loaded = pre_fault_synchronize(vcpu); 194 174 195 175 if (is_pabt) { 196 176 vect_offset = 12; ··· 217 191 /* no need to shuffle FS[4] into DFSR[10] as its 0 */ 218 192 *fsr = DFSR_FSC_EXTABT_nLPAE; 219 193 } 194 + 195 + post_fault_synchronize(vcpu, loaded); 220 196 } 221 197 222 198 void kvm_inject_dabt32(struct kvm_vcpu *vcpu, unsigned long addr)
+12 -13
arch/arm64/kvm/arm.c
··· 144 144 return ret; 145 145 } 146 146 147 - int kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu) 148 - { 149 - return 0; 150 - } 151 - 152 147 vm_fault_t kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf) 153 148 { 154 149 return VM_FAULT_SIGBUS; ··· 335 340 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 336 341 { 337 342 int *last_ran; 338 - kvm_host_data_t *cpu_data; 339 343 340 344 last_ran = this_cpu_ptr(vcpu->kvm->arch.last_vcpu_ran); 341 - cpu_data = this_cpu_ptr(&kvm_host_data); 342 345 343 346 /* 344 347 * We might get preempted before the vCPU actually runs, but ··· 348 355 } 349 356 350 357 vcpu->cpu = cpu; 351 - vcpu->arch.host_cpu_context = &cpu_data->host_ctxt; 352 358 353 359 kvm_vgic_load(vcpu); 354 360 kvm_timer_vcpu_load(vcpu); ··· 362 370 else 363 371 vcpu_set_wfx_traps(vcpu); 364 372 365 - vcpu_ptrauth_setup_lazy(vcpu); 373 + if (vcpu_has_ptrauth(vcpu)) 374 + vcpu_ptrauth_disable(vcpu); 366 375 } 367 376 368 377 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) ··· 983 990 * Ensure a rebooted VM will fault in RAM pages and detect if the 984 991 * guest MMU is turned off and flush the caches as needed. 985 992 * 986 - * S2FWB enforces all memory accesses to RAM being cacheable, we 987 - * ensure that the cache is always coherent. 993 + * S2FWB enforces all memory accesses to RAM being cacheable, 994 + * ensuring that the data side is always coherent. We still 995 + * need to invalidate the I-cache though, as FWB does *not* 996 + * imply CTR_EL0.DIC. 988 997 */ 989 - if (vcpu->arch.has_run_once && !cpus_have_const_cap(ARM64_HAS_STAGE2_FWB)) 990 - stage2_unmap_vm(vcpu->kvm); 998 + if (vcpu->arch.has_run_once) { 999 + if (!cpus_have_final_cap(ARM64_HAS_STAGE2_FWB)) 1000 + stage2_unmap_vm(vcpu->kvm); 1001 + else 1002 + __flush_icache_all(); 1003 + } 991 1004 992 1005 vcpu_reset_hcr(vcpu); 993 1006
+3 -29
arch/arm64/kvm/handle_exit.c
··· 162 162 return 1; 163 163 } 164 164 165 - #define __ptrauth_save_key(regs, key) \ 166 - ({ \ 167 - regs[key ## KEYLO_EL1] = read_sysreg_s(SYS_ ## key ## KEYLO_EL1); \ 168 - regs[key ## KEYHI_EL1] = read_sysreg_s(SYS_ ## key ## KEYHI_EL1); \ 169 - }) 170 - 171 - /* 172 - * Handle the guest trying to use a ptrauth instruction, or trying to access a 173 - * ptrauth register. 174 - */ 175 - void kvm_arm_vcpu_ptrauth_trap(struct kvm_vcpu *vcpu) 176 - { 177 - struct kvm_cpu_context *ctxt; 178 - 179 - if (vcpu_has_ptrauth(vcpu)) { 180 - vcpu_ptrauth_enable(vcpu); 181 - ctxt = vcpu->arch.host_cpu_context; 182 - __ptrauth_save_key(ctxt->sys_regs, APIA); 183 - __ptrauth_save_key(ctxt->sys_regs, APIB); 184 - __ptrauth_save_key(ctxt->sys_regs, APDA); 185 - __ptrauth_save_key(ctxt->sys_regs, APDB); 186 - __ptrauth_save_key(ctxt->sys_regs, APGA); 187 - } else { 188 - kvm_inject_undefined(vcpu); 189 - } 190 - } 191 - 192 165 /* 193 166 * Guest usage of a ptrauth instruction (which the guest EL1 did not turn into 194 - * a NOP). 167 + * a NOP). If we get here, it is that we didn't fixup ptrauth on exit, and all 168 + * that we can do is give the guest an UNDEF. 195 169 */ 196 170 static int kvm_handle_ptrauth(struct kvm_vcpu *vcpu, struct kvm_run *run) 197 171 { 198 - kvm_arm_vcpu_ptrauth_trap(vcpu); 172 + kvm_inject_undefined(vcpu); 199 173 return 1; 200 174 } 201 175
+2 -2
arch/arm64/kvm/hyp/debug-sr.c
··· 185 185 if (!(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY)) 186 186 return; 187 187 188 - host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context); 188 + host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt; 189 189 guest_ctxt = &vcpu->arch.ctxt; 190 190 host_dbg = &vcpu->arch.host_debug_state.regs; 191 191 guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr); ··· 207 207 if (!(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY)) 208 208 return; 209 209 210 - host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context); 210 + host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt; 211 211 guest_ctxt = &vcpu->arch.ctxt; 212 212 host_dbg = &vcpu->arch.host_debug_state.regs; 213 213 guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
+63 -2
arch/arm64/kvm/hyp/switch.c
··· 490 490 return true; 491 491 } 492 492 493 + static bool __hyp_text esr_is_ptrauth_trap(u32 esr) 494 + { 495 + u32 ec = ESR_ELx_EC(esr); 496 + 497 + if (ec == ESR_ELx_EC_PAC) 498 + return true; 499 + 500 + if (ec != ESR_ELx_EC_SYS64) 501 + return false; 502 + 503 + switch (esr_sys64_to_sysreg(esr)) { 504 + case SYS_APIAKEYLO_EL1: 505 + case SYS_APIAKEYHI_EL1: 506 + case SYS_APIBKEYLO_EL1: 507 + case SYS_APIBKEYHI_EL1: 508 + case SYS_APDAKEYLO_EL1: 509 + case SYS_APDAKEYHI_EL1: 510 + case SYS_APDBKEYLO_EL1: 511 + case SYS_APDBKEYHI_EL1: 512 + case SYS_APGAKEYLO_EL1: 513 + case SYS_APGAKEYHI_EL1: 514 + return true; 515 + } 516 + 517 + return false; 518 + } 519 + 520 + #define __ptrauth_save_key(regs, key) \ 521 + ({ \ 522 + regs[key ## KEYLO_EL1] = read_sysreg_s(SYS_ ## key ## KEYLO_EL1); \ 523 + regs[key ## KEYHI_EL1] = read_sysreg_s(SYS_ ## key ## KEYHI_EL1); \ 524 + }) 525 + 526 + static bool __hyp_text __hyp_handle_ptrauth(struct kvm_vcpu *vcpu) 527 + { 528 + struct kvm_cpu_context *ctxt; 529 + u64 val; 530 + 531 + if (!vcpu_has_ptrauth(vcpu) || 532 + !esr_is_ptrauth_trap(kvm_vcpu_get_hsr(vcpu))) 533 + return false; 534 + 535 + ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt; 536 + __ptrauth_save_key(ctxt->sys_regs, APIA); 537 + __ptrauth_save_key(ctxt->sys_regs, APIB); 538 + __ptrauth_save_key(ctxt->sys_regs, APDA); 539 + __ptrauth_save_key(ctxt->sys_regs, APDB); 540 + __ptrauth_save_key(ctxt->sys_regs, APGA); 541 + 542 + vcpu_ptrauth_enable(vcpu); 543 + 544 + val = read_sysreg(hcr_el2); 545 + val |= (HCR_API | HCR_APK); 546 + write_sysreg(val, hcr_el2); 547 + 548 + return true; 549 + } 550 + 493 551 /* 494 552 * Return true when we were able to fixup the guest exit and should return to 495 553 * the guest, false when we should restore the host state and return to the ··· 580 522 * Similarly for trapped SVE accesses. 581 523 */ 582 524 if (__hyp_handle_fpsimd(vcpu)) 525 + return true; 526 + 527 + if (__hyp_handle_ptrauth(vcpu)) 583 528 return true; 584 529 585 530 if (!__populate_fault_info(vcpu)) ··· 703 642 struct kvm_cpu_context *guest_ctxt; 704 643 u64 exit_code; 705 644 706 - host_ctxt = vcpu->arch.host_cpu_context; 645 + host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt; 707 646 host_ctxt->__hyp_running_vcpu = vcpu; 708 647 guest_ctxt = &vcpu->arch.ctxt; 709 648 ··· 808 747 809 748 vcpu = kern_hyp_va(vcpu); 810 749 811 - host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context); 750 + host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt; 812 751 host_ctxt->__hyp_running_vcpu = vcpu; 813 752 guest_ctxt = &vcpu->arch.ctxt; 814 753
+4 -4
arch/arm64/kvm/hyp/sysreg-sr.c
··· 39 39 { 40 40 ctxt->sys_regs[CSSELR_EL1] = read_sysreg(csselr_el1); 41 41 ctxt->sys_regs[SCTLR_EL1] = read_sysreg_el1(SYS_SCTLR); 42 - ctxt->sys_regs[ACTLR_EL1] = read_sysreg(actlr_el1); 43 42 ctxt->sys_regs[CPACR_EL1] = read_sysreg_el1(SYS_CPACR); 44 43 ctxt->sys_regs[TTBR0_EL1] = read_sysreg_el1(SYS_TTBR0); 45 44 ctxt->sys_regs[TTBR1_EL1] = read_sysreg_el1(SYS_TTBR1); ··· 122 123 isb(); 123 124 } 124 125 125 - write_sysreg(ctxt->sys_regs[ACTLR_EL1], actlr_el1); 126 126 write_sysreg_el1(ctxt->sys_regs[CPACR_EL1], SYS_CPACR); 127 127 write_sysreg_el1(ctxt->sys_regs[TTBR0_EL1], SYS_TTBR0); 128 128 write_sysreg_el1(ctxt->sys_regs[TTBR1_EL1], SYS_TTBR1); ··· 265 267 */ 266 268 void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu) 267 269 { 268 - struct kvm_cpu_context *host_ctxt = vcpu->arch.host_cpu_context; 269 270 struct kvm_cpu_context *guest_ctxt = &vcpu->arch.ctxt; 271 + struct kvm_cpu_context *host_ctxt; 270 272 271 273 if (!has_vhe()) 272 274 return; 273 275 276 + host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt; 274 277 __sysreg_save_user_state(host_ctxt); 275 278 276 279 /* ··· 302 303 */ 303 304 void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu) 304 305 { 305 - struct kvm_cpu_context *host_ctxt = vcpu->arch.host_cpu_context; 306 306 struct kvm_cpu_context *guest_ctxt = &vcpu->arch.ctxt; 307 + struct kvm_cpu_context *host_ctxt; 307 308 308 309 if (!has_vhe()) 309 310 return; 310 311 312 + host_ctxt = &__hyp_this_cpu_ptr(kvm_host_data)->host_ctxt; 311 313 deactivate_traps_vhe_put(); 312 314 313 315 __sysreg_save_el1_state(guest_ctxt);
+2 -6
arch/arm64/kvm/pmu.c
··· 163 163 */ 164 164 void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) 165 165 { 166 - struct kvm_cpu_context *host_ctxt; 167 166 struct kvm_host_data *host; 168 167 u32 events_guest, events_host; 169 168 170 169 if (!has_vhe()) 171 170 return; 172 171 173 - host_ctxt = vcpu->arch.host_cpu_context; 174 - host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); 172 + host = this_cpu_ptr(&kvm_host_data); 175 173 events_guest = host->pmu_events.events_guest; 176 174 events_host = host->pmu_events.events_host; 177 175 ··· 182 184 */ 183 185 void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) 184 186 { 185 - struct kvm_cpu_context *host_ctxt; 186 187 struct kvm_host_data *host; 187 188 u32 events_guest, events_host; 188 189 189 190 if (!has_vhe()) 190 191 return; 191 192 192 - host_ctxt = vcpu->arch.host_cpu_context; 193 - host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); 193 + host = this_cpu_ptr(&kvm_host_data); 194 194 events_guest = host->pmu_events.events_guest; 195 195 events_host = host->pmu_events.events_host; 196 196
+13 -12
arch/arm64/kvm/sys_regs.c
··· 78 78 switch (reg) { 79 79 case CSSELR_EL1: *val = read_sysreg_s(SYS_CSSELR_EL1); break; 80 80 case SCTLR_EL1: *val = read_sysreg_s(SYS_SCTLR_EL12); break; 81 - case ACTLR_EL1: *val = read_sysreg_s(SYS_ACTLR_EL1); break; 82 81 case CPACR_EL1: *val = read_sysreg_s(SYS_CPACR_EL12); break; 83 82 case TTBR0_EL1: *val = read_sysreg_s(SYS_TTBR0_EL12); break; 84 83 case TTBR1_EL1: *val = read_sysreg_s(SYS_TTBR1_EL12); break; ··· 117 118 switch (reg) { 118 119 case CSSELR_EL1: write_sysreg_s(val, SYS_CSSELR_EL1); break; 119 120 case SCTLR_EL1: write_sysreg_s(val, SYS_SCTLR_EL12); break; 120 - case ACTLR_EL1: write_sysreg_s(val, SYS_ACTLR_EL1); break; 121 121 case CPACR_EL1: write_sysreg_s(val, SYS_CPACR_EL12); break; 122 122 case TTBR0_EL1: write_sysreg_s(val, SYS_TTBR0_EL12); break; 123 123 case TTBR1_EL1: write_sysreg_s(val, SYS_TTBR1_EL12); break; ··· 1032 1034 struct sys_reg_params *p, 1033 1035 const struct sys_reg_desc *rd) 1034 1036 { 1035 - kvm_arm_vcpu_ptrauth_trap(vcpu); 1036 - 1037 1037 /* 1038 - * Return false for both cases as we never skip the trapped 1039 - * instruction: 1040 - * 1041 - * - Either we re-execute the same key register access instruction 1042 - * after enabling ptrauth. 1043 - * - Or an UNDEF is injected as ptrauth is not supported/enabled. 1038 + * If we land here, that is because we didn't fixup the access on exit 1039 + * by allowing the PtrAuth sysregs. The only way this happens is when 1040 + * the guest does not have PtrAuth support enabled. 1044 1041 */ 1042 + kvm_inject_undefined(vcpu); 1043 + 1045 1044 return false; 1046 1045 } 1047 1046 ··· 1314 1319 static bool access_csselr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, 1315 1320 const struct sys_reg_desc *r) 1316 1321 { 1322 + int reg = r->reg; 1323 + 1324 + /* See the 32bit mapping in kvm_host.h */ 1325 + if (p->is_aarch32) 1326 + reg = r->reg / 2; 1327 + 1317 1328 if (p->is_write) 1318 - vcpu_write_sys_reg(vcpu, p->regval, r->reg); 1329 + vcpu_write_sys_reg(vcpu, p->regval, reg); 1319 1330 else 1320 - p->regval = vcpu_read_sys_reg(vcpu, r->reg); 1331 + p->regval = vcpu_read_sys_reg(vcpu, reg); 1321 1332 return true; 1322 1333 } 1323 1334
+10
arch/arm64/kvm/sys_regs_generic_v8.c
··· 27 27 return ignore_write(vcpu, p); 28 28 29 29 p->regval = vcpu_read_sys_reg(vcpu, ACTLR_EL1); 30 + 31 + if (p->is_aarch32) { 32 + if (r->Op2 & 2) 33 + p->regval = upper_32_bits(p->regval); 34 + else 35 + p->regval = lower_32_bits(p->regval); 36 + } 37 + 30 38 return true; 31 39 } 32 40 ··· 54 46 static const struct sys_reg_desc genericv8_cp15_regs[] = { 55 47 /* ACTLR */ 56 48 { Op1(0b000), CRn(0b0001), CRm(0b0000), Op2(0b001), 49 + access_actlr }, 50 + { Op1(0b000), CRn(0b0001), CRm(0b0000), Op2(0b011), 57 51 access_actlr }, 58 52 }; 59 53
+1
arch/mips/Kconfig
··· 1403 1403 select MIPS_L1_CACHE_SHIFT_6 1404 1404 select GPIOLIB 1405 1405 select SWIOTLB 1406 + select HAVE_KVM 1406 1407 help 1407 1408 The Loongson GSx64(GS264/GS464/GS464E/GS464V) series of processor 1408 1409 cores implements the MIPS64R2 instruction set with many extensions,
+3
arch/mips/include/asm/cpu-features.h
··· 682 682 #ifndef cpu_guest_has_htw 683 683 #define cpu_guest_has_htw (cpu_data[0].guest.options & MIPS_CPU_HTW) 684 684 #endif 685 + #ifndef cpu_guest_has_ldpte 686 + #define cpu_guest_has_ldpte (cpu_data[0].guest.options & MIPS_CPU_LDPTE) 687 + #endif 685 688 #ifndef cpu_guest_has_mvh 686 689 #define cpu_guest_has_mvh (cpu_data[0].guest.options & MIPS_CPU_MVH) 687 690 #endif
+49 -3
arch/mips/include/asm/kvm_host.h
··· 23 23 #include <asm/inst.h> 24 24 #include <asm/mipsregs.h> 25 25 26 + #include <kvm/iodev.h> 27 + 26 28 /* MIPS KVM register ids */ 27 29 #define MIPS_CP0_32(_R, _S) \ 28 30 (KVM_REG_MIPS_CP0 | KVM_REG_SIZE_U32 | (8 * (_R) + (_S))) ··· 68 66 #define KVM_REG_MIPS_CP0_CONFIG3 MIPS_CP0_32(16, 3) 69 67 #define KVM_REG_MIPS_CP0_CONFIG4 MIPS_CP0_32(16, 4) 70 68 #define KVM_REG_MIPS_CP0_CONFIG5 MIPS_CP0_32(16, 5) 69 + #define KVM_REG_MIPS_CP0_CONFIG6 MIPS_CP0_32(16, 6) 71 70 #define KVM_REG_MIPS_CP0_CONFIG7 MIPS_CP0_32(16, 7) 72 71 #define KVM_REG_MIPS_CP0_MAARI MIPS_CP0_64(17, 2) 73 72 #define KVM_REG_MIPS_CP0_XCONTEXT MIPS_CP0_64(20, 0) 73 + #define KVM_REG_MIPS_CP0_DIAG MIPS_CP0_32(22, 0) 74 74 #define KVM_REG_MIPS_CP0_ERROREPC MIPS_CP0_64(30, 0) 75 75 #define KVM_REG_MIPS_CP0_KSCRATCH1 MIPS_CP0_64(31, 2) 76 76 #define KVM_REG_MIPS_CP0_KSCRATCH2 MIPS_CP0_64(31, 3) ··· 82 78 #define KVM_REG_MIPS_CP0_KSCRATCH6 MIPS_CP0_64(31, 7) 83 79 84 80 85 - #define KVM_MAX_VCPUS 8 86 - #define KVM_USER_MEM_SLOTS 8 81 + #define KVM_MAX_VCPUS 16 82 + #define KVM_USER_MEM_SLOTS 16 87 83 /* memory slots that does not exposed to userspace */ 88 84 #define KVM_PRIVATE_MEM_SLOTS 0 89 85 ··· 175 171 u64 vz_ghfc_exits; 176 172 u64 vz_gpa_exits; 177 173 u64 vz_resvd_exits; 174 + #ifdef CONFIG_CPU_LOONGSON64 175 + u64 vz_cpucfg_exits; 176 + #endif 178 177 #endif 179 178 u64 halt_successful_poll; 180 179 u64 halt_attempted_poll; ··· 190 183 struct kvm_arch_memory_slot { 191 184 }; 192 185 186 + #ifdef CONFIG_CPU_LOONGSON64 187 + struct ipi_state { 188 + uint32_t status; 189 + uint32_t en; 190 + uint32_t set; 191 + uint32_t clear; 192 + uint64_t buf[4]; 193 + }; 194 + 195 + struct loongson_kvm_ipi; 196 + 197 + struct ipi_io_device { 198 + int node_id; 199 + struct loongson_kvm_ipi *ipi; 200 + struct kvm_io_device device; 201 + }; 202 + 203 + struct loongson_kvm_ipi { 204 + spinlock_t lock; 205 + struct kvm *kvm; 206 + struct ipi_state ipistate[16]; 207 + struct ipi_io_device dev_ipi[4]; 208 + }; 209 + #endif 210 + 193 211 struct kvm_arch { 194 212 /* Guest physical mm */ 195 213 struct mm_struct gpa_mm; 196 214 /* Mask of CPUs needing GPA ASID flush */ 197 215 cpumask_t asid_flush_mask; 216 + #ifdef CONFIG_CPU_LOONGSON64 217 + struct loongson_kvm_ipi ipi; 218 + #endif 198 219 }; 199 220 200 221 #define N_MIPS_COPROC_REGS 32 ··· 260 225 #define MIPS_CP0_WATCH_LO 18 261 226 #define MIPS_CP0_WATCH_HI 19 262 227 #define MIPS_CP0_TLB_XCONTEXT 20 228 + #define MIPS_CP0_DIAG 22 263 229 #define MIPS_CP0_ECC 26 264 230 #define MIPS_CP0_CACHE_ERR 27 265 231 #define MIPS_CP0_TAG_LO 28 ··· 312 276 #define MIPS3_PG_SHIFT 6 313 277 #define MIPS3_PG_FRAME 0x3fffffc0 314 278 279 + #if defined(CONFIG_64BIT) 280 + #define VPN2_MASK GENMASK(cpu_vmbits - 1, 13) 281 + #else 315 282 #define VPN2_MASK 0xffffe000 316 - #define KVM_ENTRYHI_ASID MIPS_ENTRYHI_ASID 283 + #endif 284 + #define KVM_ENTRYHI_ASID cpu_asid_mask(&boot_cpu_data) 317 285 #define TLB_IS_GLOBAL(x) ((x).tlb_lo[0] & (x).tlb_lo[1] & ENTRYLO_G) 318 286 #define TLB_VPN2(x) ((x).tlb_hi & VPN2_MASK) 319 287 #define TLB_ASID(x) ((x).tlb_hi & KVM_ENTRYHI_ASID) ··· 932 892 unsigned int count); 933 893 void kvm_vz_load_guesttlb(const struct kvm_mips_tlb *buf, unsigned int index, 934 894 unsigned int count); 895 + #ifdef CONFIG_CPU_LOONGSON64 896 + void kvm_loongson_clear_guest_vtlb(void); 897 + void kvm_loongson_clear_guest_ftlb(void); 898 + #endif 935 899 #endif 936 900 937 901 void kvm_mips_suspend_mm(int cpu); ··· 1175 1131 /* Misc */ 1176 1132 extern void kvm_mips_dump_stats(struct kvm_vcpu *vcpu); 1177 1133 extern unsigned long kvm_mips_get_ramsize(struct kvm *kvm); 1134 + extern int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, 1135 + struct kvm_mips_interrupt *irq); 1178 1136 1179 1137 static inline void kvm_arch_hardware_unsetup(void) {} 1180 1138 static inline void kvm_arch_sync_events(struct kvm *kvm) {}
+4
arch/mips/include/asm/mipsregs.h
··· 1038 1038 /* Disable Branch Return Cache */ 1039 1039 #define R10K_DIAG_D_BRC (_ULCAST_(1) << 22) 1040 1040 1041 + /* Flush BTB */ 1042 + #define LOONGSON_DIAG_BTB (_ULCAST_(1) << 1) 1041 1043 /* Flush ITLB */ 1042 1044 #define LOONGSON_DIAG_ITLB (_ULCAST_(1) << 2) 1043 1045 /* Flush DTLB */ ··· 2876 2874 __BUILD_SET_C0(cause) 2877 2875 __BUILD_SET_C0(config) 2878 2876 __BUILD_SET_C0(config5) 2877 + __BUILD_SET_C0(config6) 2879 2878 __BUILD_SET_C0(config7) 2879 + __BUILD_SET_C0(diag) 2880 2880 __BUILD_SET_C0(intcontrol) 2881 2881 __BUILD_SET_C0(intctl) 2882 2882 __BUILD_SET_C0(srsmap)
+11
arch/mips/include/uapi/asm/inst.h
··· 1012 1012 ;)))))) 1013 1013 }; 1014 1014 1015 + struct loongson3_lscsr_format { /* Loongson-3 CPUCFG&CSR read/write format */ 1016 + __BITFIELD_FIELD(unsigned int opcode : 6, 1017 + __BITFIELD_FIELD(unsigned int rs : 5, 1018 + __BITFIELD_FIELD(unsigned int fr : 5, 1019 + __BITFIELD_FIELD(unsigned int rd : 5, 1020 + __BITFIELD_FIELD(unsigned int fd : 5, 1021 + __BITFIELD_FIELD(unsigned int func : 6, 1022 + ;)))))) 1023 + }; 1024 + 1015 1025 /* 1016 1026 * MIPS16e instruction formats (16-bit length) 1017 1027 */ ··· 1124 1114 struct mm16_r5_format mm16_r5_format; 1125 1115 struct loongson3_lswc2_format loongson3_lswc2_format; 1126 1116 struct loongson3_lsdc2_format loongson3_lsdc2_format; 1117 + struct loongson3_lscsr_format loongson3_lscsr_format; 1127 1118 }; 1128 1119 1129 1120 union mips16e_instruction {
+4 -1
arch/mips/kernel/cpu-probe.c
··· 2017 2017 if (cfg2 & LOONGSON_CFG2_LEXT2) 2018 2018 c->ases |= MIPS_ASE_LOONGSON_EXT2; 2019 2019 2020 - if (cfg2 & LOONGSON_CFG2_LSPW) 2020 + if (cfg2 & LOONGSON_CFG2_LSPW) { 2021 2021 c->options |= MIPS_CPU_LDPTE; 2022 + c->guest.options |= MIPS_CPU_LDPTE; 2023 + } 2022 2024 2023 2025 if (cfg3 & LOONGSON_CFG3_LCAMP) 2024 2026 c->ases |= MIPS_ASE_LOONGSON_CAM; ··· 2076 2074 c->writecombine = _CACHE_UNCACHED_ACCELERATED; 2077 2075 c->ases |= (MIPS_ASE_LOONGSON_MMI | MIPS_ASE_LOONGSON_CAM | 2078 2076 MIPS_ASE_LOONGSON_EXT | MIPS_ASE_LOONGSON_EXT2); 2077 + c->ases &= ~MIPS_ASE_VZ; /* VZ of Loongson-3A2000/3000 is incomplete */ 2079 2078 break; 2080 2079 case PRID_IMP_LOONGSON_64G: 2081 2080 c->cputype = CPU_LOONGSON64;
+1
arch/mips/kvm/Kconfig
··· 22 22 select EXPORT_UASM 23 23 select PREEMPT_NOTIFIERS 24 24 select KVM_GENERIC_DIRTYLOG_READ_PROTECT 25 + select HAVE_KVM_EVENTFD 25 26 select HAVE_KVM_VCPU_ASYNC_IOCTL 26 27 select KVM_MMIO 27 28 select MMU_NOTIFIER
+4 -1
arch/mips/kvm/Makefile
··· 2 2 # Makefile for KVM support for MIPS 3 3 # 4 4 5 - common-objs-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o) 5 + common-objs-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o eventfd.o) 6 6 7 7 EXTRA_CFLAGS += -Ivirt/kvm -Iarch/mips/kvm 8 8 ··· 13 13 fpu.o 14 14 kvm-objs += hypcall.o 15 15 kvm-objs += mmu.o 16 + ifdef CONFIG_CPU_LOONGSON64 17 + kvm-objs += loongson_ipi.o 18 + endif 16 19 17 20 ifdef CONFIG_KVM_MIPS_VZ 18 21 kvm-objs += vz.o
+492 -11
arch/mips/kvm/emulate.c
··· 1600 1600 struct kvm_run *run, 1601 1601 struct kvm_vcpu *vcpu) 1602 1602 { 1603 + int r; 1603 1604 enum emulation_result er; 1604 1605 u32 rt; 1605 1606 void *data = run->mmio.data; 1607 + unsigned int imme; 1606 1608 unsigned long curr_pc; 1607 1609 1608 1610 /* ··· 1662 1660 vcpu->arch.gprs[rt], *(u8 *)data); 1663 1661 break; 1664 1662 1663 + case swl_op: 1664 + run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa( 1665 + vcpu->arch.host_cp0_badvaddr) & (~0x3); 1666 + run->mmio.len = 4; 1667 + imme = vcpu->arch.host_cp0_badvaddr & 0x3; 1668 + switch (imme) { 1669 + case 0: 1670 + *(u32 *)data = ((*(u32 *)data) & 0xffffff00) | 1671 + (vcpu->arch.gprs[rt] >> 24); 1672 + break; 1673 + case 1: 1674 + *(u32 *)data = ((*(u32 *)data) & 0xffff0000) | 1675 + (vcpu->arch.gprs[rt] >> 16); 1676 + break; 1677 + case 2: 1678 + *(u32 *)data = ((*(u32 *)data) & 0xff000000) | 1679 + (vcpu->arch.gprs[rt] >> 8); 1680 + break; 1681 + case 3: 1682 + *(u32 *)data = vcpu->arch.gprs[rt]; 1683 + break; 1684 + default: 1685 + break; 1686 + } 1687 + 1688 + kvm_debug("[%#lx] OP_SWL: eaddr: %#lx, gpr: %#lx, data: %#x\n", 1689 + vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr, 1690 + vcpu->arch.gprs[rt], *(u32 *)data); 1691 + break; 1692 + 1693 + case swr_op: 1694 + run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa( 1695 + vcpu->arch.host_cp0_badvaddr) & (~0x3); 1696 + run->mmio.len = 4; 1697 + imme = vcpu->arch.host_cp0_badvaddr & 0x3; 1698 + switch (imme) { 1699 + case 0: 1700 + *(u32 *)data = vcpu->arch.gprs[rt]; 1701 + break; 1702 + case 1: 1703 + *(u32 *)data = ((*(u32 *)data) & 0xff) | 1704 + (vcpu->arch.gprs[rt] << 8); 1705 + break; 1706 + case 2: 1707 + *(u32 *)data = ((*(u32 *)data) & 0xffff) | 1708 + (vcpu->arch.gprs[rt] << 16); 1709 + break; 1710 + case 3: 1711 + *(u32 *)data = ((*(u32 *)data) & 0xffffff) | 1712 + (vcpu->arch.gprs[rt] << 24); 1713 + break; 1714 + default: 1715 + break; 1716 + } 1717 + 1718 + kvm_debug("[%#lx] OP_SWR: eaddr: %#lx, gpr: %#lx, data: %#x\n", 1719 + vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr, 1720 + vcpu->arch.gprs[rt], *(u32 *)data); 1721 + break; 1722 + 1723 + case sdl_op: 1724 + run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa( 1725 + vcpu->arch.host_cp0_badvaddr) & (~0x7); 1726 + 1727 + run->mmio.len = 8; 1728 + imme = vcpu->arch.host_cp0_badvaddr & 0x7; 1729 + switch (imme) { 1730 + case 0: 1731 + *(u64 *)data = ((*(u64 *)data) & 0xffffffffffffff00) | 1732 + ((vcpu->arch.gprs[rt] >> 56) & 0xff); 1733 + break; 1734 + case 1: 1735 + *(u64 *)data = ((*(u64 *)data) & 0xffffffffffff0000) | 1736 + ((vcpu->arch.gprs[rt] >> 48) & 0xffff); 1737 + break; 1738 + case 2: 1739 + *(u64 *)data = ((*(u64 *)data) & 0xffffffffff000000) | 1740 + ((vcpu->arch.gprs[rt] >> 40) & 0xffffff); 1741 + break; 1742 + case 3: 1743 + *(u64 *)data = ((*(u64 *)data) & 0xffffffff00000000) | 1744 + ((vcpu->arch.gprs[rt] >> 32) & 0xffffffff); 1745 + break; 1746 + case 4: 1747 + *(u64 *)data = ((*(u64 *)data) & 0xffffff0000000000) | 1748 + ((vcpu->arch.gprs[rt] >> 24) & 0xffffffffff); 1749 + break; 1750 + case 5: 1751 + *(u64 *)data = ((*(u64 *)data) & 0xffff000000000000) | 1752 + ((vcpu->arch.gprs[rt] >> 16) & 0xffffffffffff); 1753 + break; 1754 + case 6: 1755 + *(u64 *)data = ((*(u64 *)data) & 0xff00000000000000) | 1756 + ((vcpu->arch.gprs[rt] >> 8) & 0xffffffffffffff); 1757 + break; 1758 + case 7: 1759 + *(u64 *)data = vcpu->arch.gprs[rt]; 1760 + break; 1761 + default: 1762 + break; 1763 + } 1764 + 1765 + kvm_debug("[%#lx] OP_SDL: eaddr: %#lx, gpr: %#lx, data: %llx\n", 1766 + vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr, 1767 + vcpu->arch.gprs[rt], *(u64 *)data); 1768 + break; 1769 + 1770 + case sdr_op: 1771 + run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa( 1772 + vcpu->arch.host_cp0_badvaddr) & (~0x7); 1773 + 1774 + run->mmio.len = 8; 1775 + imme = vcpu->arch.host_cp0_badvaddr & 0x7; 1776 + switch (imme) { 1777 + case 0: 1778 + *(u64 *)data = vcpu->arch.gprs[rt]; 1779 + break; 1780 + case 1: 1781 + *(u64 *)data = ((*(u64 *)data) & 0xff) | 1782 + (vcpu->arch.gprs[rt] << 8); 1783 + break; 1784 + case 2: 1785 + *(u64 *)data = ((*(u64 *)data) & 0xffff) | 1786 + (vcpu->arch.gprs[rt] << 16); 1787 + break; 1788 + case 3: 1789 + *(u64 *)data = ((*(u64 *)data) & 0xffffff) | 1790 + (vcpu->arch.gprs[rt] << 24); 1791 + break; 1792 + case 4: 1793 + *(u64 *)data = ((*(u64 *)data) & 0xffffffff) | 1794 + (vcpu->arch.gprs[rt] << 32); 1795 + break; 1796 + case 5: 1797 + *(u64 *)data = ((*(u64 *)data) & 0xffffffffff) | 1798 + (vcpu->arch.gprs[rt] << 40); 1799 + break; 1800 + case 6: 1801 + *(u64 *)data = ((*(u64 *)data) & 0xffffffffffff) | 1802 + (vcpu->arch.gprs[rt] << 48); 1803 + break; 1804 + case 7: 1805 + *(u64 *)data = ((*(u64 *)data) & 0xffffffffffffff) | 1806 + (vcpu->arch.gprs[rt] << 56); 1807 + break; 1808 + default: 1809 + break; 1810 + } 1811 + 1812 + kvm_debug("[%#lx] OP_SDR: eaddr: %#lx, gpr: %#lx, data: %llx\n", 1813 + vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr, 1814 + vcpu->arch.gprs[rt], *(u64 *)data); 1815 + break; 1816 + 1817 + #ifdef CONFIG_CPU_LOONGSON64 1818 + case sdc2_op: 1819 + rt = inst.loongson3_lsdc2_format.rt; 1820 + switch (inst.loongson3_lsdc2_format.opcode1) { 1821 + /* 1822 + * Loongson-3 overridden sdc2 instructions. 1823 + * opcode1 instruction 1824 + * 0x0 gssbx: store 1 bytes from GPR 1825 + * 0x1 gsshx: store 2 bytes from GPR 1826 + * 0x2 gsswx: store 4 bytes from GPR 1827 + * 0x3 gssdx: store 8 bytes from GPR 1828 + */ 1829 + case 0x0: 1830 + run->mmio.len = 1; 1831 + *(u8 *)data = vcpu->arch.gprs[rt]; 1832 + 1833 + kvm_debug("[%#lx] OP_GSSBX: eaddr: %#lx, gpr: %#lx, data: %#x\n", 1834 + vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr, 1835 + vcpu->arch.gprs[rt], *(u8 *)data); 1836 + break; 1837 + case 0x1: 1838 + run->mmio.len = 2; 1839 + *(u16 *)data = vcpu->arch.gprs[rt]; 1840 + 1841 + kvm_debug("[%#lx] OP_GSSSHX: eaddr: %#lx, gpr: %#lx, data: %#x\n", 1842 + vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr, 1843 + vcpu->arch.gprs[rt], *(u16 *)data); 1844 + break; 1845 + case 0x2: 1846 + run->mmio.len = 4; 1847 + *(u32 *)data = vcpu->arch.gprs[rt]; 1848 + 1849 + kvm_debug("[%#lx] OP_GSSWX: eaddr: %#lx, gpr: %#lx, data: %#x\n", 1850 + vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr, 1851 + vcpu->arch.gprs[rt], *(u32 *)data); 1852 + break; 1853 + case 0x3: 1854 + run->mmio.len = 8; 1855 + *(u64 *)data = vcpu->arch.gprs[rt]; 1856 + 1857 + kvm_debug("[%#lx] OP_GSSDX: eaddr: %#lx, gpr: %#lx, data: %#llx\n", 1858 + vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr, 1859 + vcpu->arch.gprs[rt], *(u64 *)data); 1860 + break; 1861 + default: 1862 + kvm_err("Godson Exteneded GS-Store not yet supported (inst=0x%08x)\n", 1863 + inst.word); 1864 + break; 1865 + } 1866 + break; 1867 + #endif 1665 1868 default: 1666 1869 kvm_err("Store not yet supported (inst=0x%08x)\n", 1667 1870 inst.word); 1668 1871 goto out_fail; 1669 1872 } 1670 1873 1671 - run->mmio.is_write = 1; 1672 1874 vcpu->mmio_needed = 1; 1875 + run->mmio.is_write = 1; 1673 1876 vcpu->mmio_is_write = 1; 1877 + 1878 + r = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, 1879 + run->mmio.phys_addr, run->mmio.len, data); 1880 + 1881 + if (!r) { 1882 + vcpu->mmio_needed = 0; 1883 + return EMULATE_DONE; 1884 + } 1885 + 1674 1886 return EMULATE_DO_MMIO; 1675 1887 1676 1888 out_fail: ··· 1897 1681 u32 cause, struct kvm_run *run, 1898 1682 struct kvm_vcpu *vcpu) 1899 1683 { 1684 + int r; 1900 1685 enum emulation_result er; 1901 1686 unsigned long curr_pc; 1902 1687 u32 op, rt; 1688 + unsigned int imme; 1903 1689 1904 1690 rt = inst.i_format.rt; 1905 1691 op = inst.i_format.opcode; ··· 1954 1736 run->mmio.len = 1; 1955 1737 break; 1956 1738 1739 + case lwl_op: 1740 + run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa( 1741 + vcpu->arch.host_cp0_badvaddr) & (~0x3); 1742 + 1743 + run->mmio.len = 4; 1744 + imme = vcpu->arch.host_cp0_badvaddr & 0x3; 1745 + switch (imme) { 1746 + case 0: 1747 + vcpu->mmio_needed = 3; /* 1 byte */ 1748 + break; 1749 + case 1: 1750 + vcpu->mmio_needed = 4; /* 2 bytes */ 1751 + break; 1752 + case 2: 1753 + vcpu->mmio_needed = 5; /* 3 bytes */ 1754 + break; 1755 + case 3: 1756 + vcpu->mmio_needed = 6; /* 4 bytes */ 1757 + break; 1758 + default: 1759 + break; 1760 + } 1761 + break; 1762 + 1763 + case lwr_op: 1764 + run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa( 1765 + vcpu->arch.host_cp0_badvaddr) & (~0x3); 1766 + 1767 + run->mmio.len = 4; 1768 + imme = vcpu->arch.host_cp0_badvaddr & 0x3; 1769 + switch (imme) { 1770 + case 0: 1771 + vcpu->mmio_needed = 7; /* 4 bytes */ 1772 + break; 1773 + case 1: 1774 + vcpu->mmio_needed = 8; /* 3 bytes */ 1775 + break; 1776 + case 2: 1777 + vcpu->mmio_needed = 9; /* 2 bytes */ 1778 + break; 1779 + case 3: 1780 + vcpu->mmio_needed = 10; /* 1 byte */ 1781 + break; 1782 + default: 1783 + break; 1784 + } 1785 + break; 1786 + 1787 + case ldl_op: 1788 + run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa( 1789 + vcpu->arch.host_cp0_badvaddr) & (~0x7); 1790 + 1791 + run->mmio.len = 8; 1792 + imme = vcpu->arch.host_cp0_badvaddr & 0x7; 1793 + switch (imme) { 1794 + case 0: 1795 + vcpu->mmio_needed = 11; /* 1 byte */ 1796 + break; 1797 + case 1: 1798 + vcpu->mmio_needed = 12; /* 2 bytes */ 1799 + break; 1800 + case 2: 1801 + vcpu->mmio_needed = 13; /* 3 bytes */ 1802 + break; 1803 + case 3: 1804 + vcpu->mmio_needed = 14; /* 4 bytes */ 1805 + break; 1806 + case 4: 1807 + vcpu->mmio_needed = 15; /* 5 bytes */ 1808 + break; 1809 + case 5: 1810 + vcpu->mmio_needed = 16; /* 6 bytes */ 1811 + break; 1812 + case 6: 1813 + vcpu->mmio_needed = 17; /* 7 bytes */ 1814 + break; 1815 + case 7: 1816 + vcpu->mmio_needed = 18; /* 8 bytes */ 1817 + break; 1818 + default: 1819 + break; 1820 + } 1821 + break; 1822 + 1823 + case ldr_op: 1824 + run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa( 1825 + vcpu->arch.host_cp0_badvaddr) & (~0x7); 1826 + 1827 + run->mmio.len = 8; 1828 + imme = vcpu->arch.host_cp0_badvaddr & 0x7; 1829 + switch (imme) { 1830 + case 0: 1831 + vcpu->mmio_needed = 19; /* 8 bytes */ 1832 + break; 1833 + case 1: 1834 + vcpu->mmio_needed = 20; /* 7 bytes */ 1835 + break; 1836 + case 2: 1837 + vcpu->mmio_needed = 21; /* 6 bytes */ 1838 + break; 1839 + case 3: 1840 + vcpu->mmio_needed = 22; /* 5 bytes */ 1841 + break; 1842 + case 4: 1843 + vcpu->mmio_needed = 23; /* 4 bytes */ 1844 + break; 1845 + case 5: 1846 + vcpu->mmio_needed = 24; /* 3 bytes */ 1847 + break; 1848 + case 6: 1849 + vcpu->mmio_needed = 25; /* 2 bytes */ 1850 + break; 1851 + case 7: 1852 + vcpu->mmio_needed = 26; /* 1 byte */ 1853 + break; 1854 + default: 1855 + break; 1856 + } 1857 + break; 1858 + 1859 + #ifdef CONFIG_CPU_LOONGSON64 1860 + case ldc2_op: 1861 + rt = inst.loongson3_lsdc2_format.rt; 1862 + switch (inst.loongson3_lsdc2_format.opcode1) { 1863 + /* 1864 + * Loongson-3 overridden ldc2 instructions. 1865 + * opcode1 instruction 1866 + * 0x0 gslbx: store 1 bytes from GPR 1867 + * 0x1 gslhx: store 2 bytes from GPR 1868 + * 0x2 gslwx: store 4 bytes from GPR 1869 + * 0x3 gsldx: store 8 bytes from GPR 1870 + */ 1871 + case 0x0: 1872 + run->mmio.len = 1; 1873 + vcpu->mmio_needed = 27; /* signed */ 1874 + break; 1875 + case 0x1: 1876 + run->mmio.len = 2; 1877 + vcpu->mmio_needed = 28; /* signed */ 1878 + break; 1879 + case 0x2: 1880 + run->mmio.len = 4; 1881 + vcpu->mmio_needed = 29; /* signed */ 1882 + break; 1883 + case 0x3: 1884 + run->mmio.len = 8; 1885 + vcpu->mmio_needed = 30; /* signed */ 1886 + break; 1887 + default: 1888 + kvm_err("Godson Exteneded GS-Load for float not yet supported (inst=0x%08x)\n", 1889 + inst.word); 1890 + break; 1891 + } 1892 + break; 1893 + #endif 1894 + 1957 1895 default: 1958 1896 kvm_err("Load not yet supported (inst=0x%08x)\n", 1959 1897 inst.word); ··· 2119 1745 2120 1746 run->mmio.is_write = 0; 2121 1747 vcpu->mmio_is_write = 0; 1748 + 1749 + r = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, 1750 + run->mmio.phys_addr, run->mmio.len, run->mmio.data); 1751 + 1752 + if (!r) { 1753 + kvm_mips_complete_mmio_load(vcpu, run); 1754 + vcpu->mmio_needed = 0; 1755 + return EMULATE_DONE; 1756 + } 1757 + 2122 1758 return EMULATE_DO_MMIO; 2123 1759 } 2124 1760 ··· 2975 2591 2976 2592 switch (run->mmio.len) { 2977 2593 case 8: 2978 - *gpr = *(s64 *)run->mmio.data; 2594 + switch (vcpu->mmio_needed) { 2595 + case 11: 2596 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffffffff) | 2597 + (((*(s64 *)run->mmio.data) & 0xff) << 56); 2598 + break; 2599 + case 12: 2600 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffffff) | 2601 + (((*(s64 *)run->mmio.data) & 0xffff) << 48); 2602 + break; 2603 + case 13: 2604 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffff) | 2605 + (((*(s64 *)run->mmio.data) & 0xffffff) << 40); 2606 + break; 2607 + case 14: 2608 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffff) | 2609 + (((*(s64 *)run->mmio.data) & 0xffffffff) << 32); 2610 + break; 2611 + case 15: 2612 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffff) | 2613 + (((*(s64 *)run->mmio.data) & 0xffffffffff) << 24); 2614 + break; 2615 + case 16: 2616 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffff) | 2617 + (((*(s64 *)run->mmio.data) & 0xffffffffffff) << 16); 2618 + break; 2619 + case 17: 2620 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xff) | 2621 + (((*(s64 *)run->mmio.data) & 0xffffffffffffff) << 8); 2622 + break; 2623 + case 18: 2624 + case 19: 2625 + *gpr = *(s64 *)run->mmio.data; 2626 + break; 2627 + case 20: 2628 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xff00000000000000) | 2629 + ((((*(s64 *)run->mmio.data)) >> 8) & 0xffffffffffffff); 2630 + break; 2631 + case 21: 2632 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffff000000000000) | 2633 + ((((*(s64 *)run->mmio.data)) >> 16) & 0xffffffffffff); 2634 + break; 2635 + case 22: 2636 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffff0000000000) | 2637 + ((((*(s64 *)run->mmio.data)) >> 24) & 0xffffffffff); 2638 + break; 2639 + case 23: 2640 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffff00000000) | 2641 + ((((*(s64 *)run->mmio.data)) >> 32) & 0xffffffff); 2642 + break; 2643 + case 24: 2644 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffff000000) | 2645 + ((((*(s64 *)run->mmio.data)) >> 40) & 0xffffff); 2646 + break; 2647 + case 25: 2648 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffffff0000) | 2649 + ((((*(s64 *)run->mmio.data)) >> 48) & 0xffff); 2650 + break; 2651 + case 26: 2652 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffffffff00) | 2653 + ((((*(s64 *)run->mmio.data)) >> 56) & 0xff); 2654 + break; 2655 + default: 2656 + *gpr = *(s64 *)run->mmio.data; 2657 + } 2979 2658 break; 2980 2659 2981 2660 case 4: 2982 - if (vcpu->mmio_needed == 2) 2983 - *gpr = *(s32 *)run->mmio.data; 2984 - else 2661 + switch (vcpu->mmio_needed) { 2662 + case 1: 2985 2663 *gpr = *(u32 *)run->mmio.data; 2664 + break; 2665 + case 2: 2666 + *gpr = *(s32 *)run->mmio.data; 2667 + break; 2668 + case 3: 2669 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffff) | 2670 + (((*(s32 *)run->mmio.data) & 0xff) << 24); 2671 + break; 2672 + case 4: 2673 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffff) | 2674 + (((*(s32 *)run->mmio.data) & 0xffff) << 16); 2675 + break; 2676 + case 5: 2677 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xff) | 2678 + (((*(s32 *)run->mmio.data) & 0xffffff) << 8); 2679 + break; 2680 + case 6: 2681 + case 7: 2682 + *gpr = *(s32 *)run->mmio.data; 2683 + break; 2684 + case 8: 2685 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xff000000) | 2686 + ((((*(s32 *)run->mmio.data)) >> 8) & 0xffffff); 2687 + break; 2688 + case 9: 2689 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffff0000) | 2690 + ((((*(s32 *)run->mmio.data)) >> 16) & 0xffff); 2691 + break; 2692 + case 10: 2693 + *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffff00) | 2694 + ((((*(s32 *)run->mmio.data)) >> 24) & 0xff); 2695 + break; 2696 + default: 2697 + *gpr = *(s32 *)run->mmio.data; 2698 + } 2986 2699 break; 2987 2700 2988 2701 case 2: 2989 - if (vcpu->mmio_needed == 2) 2990 - *gpr = *(s16 *) run->mmio.data; 2991 - else 2702 + if (vcpu->mmio_needed == 1) 2992 2703 *gpr = *(u16 *)run->mmio.data; 2704 + else 2705 + *gpr = *(s16 *)run->mmio.data; 2993 2706 2994 2707 break; 2995 2708 case 1: 2996 - if (vcpu->mmio_needed == 2) 2997 - *gpr = *(s8 *) run->mmio.data; 2709 + if (vcpu->mmio_needed == 1) 2710 + *gpr = *(u8 *)run->mmio.data; 2998 2711 else 2999 - *gpr = *(u8 *) run->mmio.data; 2712 + *gpr = *(s8 *)run->mmio.data; 3000 2713 break; 3001 2714 } 3002 2715
+18 -1
arch/mips/kvm/entry.c
··· 56 56 #define C0_BADVADDR 8, 0 57 57 #define C0_BADINSTR 8, 1 58 58 #define C0_BADINSTRP 8, 2 59 + #define C0_PGD 9, 7 59 60 #define C0_ENTRYHI 10, 0 60 61 #define C0_GUESTCTL1 10, 4 61 62 #define C0_STATUS 12, 0 ··· 308 307 309 308 #ifdef CONFIG_KVM_MIPS_VZ 310 309 /* Save normal linux process pgd (VZ guarantees pgd_reg is set) */ 311 - UASM_i_MFC0(&p, K0, c0_kscratch(), pgd_reg); 310 + if (cpu_has_ldpte) 311 + UASM_i_MFC0(&p, K0, C0_PWBASE); 312 + else 313 + UASM_i_MFC0(&p, K0, c0_kscratch(), pgd_reg); 312 314 UASM_i_SW(&p, K0, offsetof(struct kvm_vcpu_arch, host_pgd), K1); 313 315 314 316 /* ··· 473 469 u32 *p = addr; 474 470 struct uasm_label labels[2]; 475 471 struct uasm_reloc relocs[2]; 472 + #ifndef CONFIG_CPU_LOONGSON64 476 473 struct uasm_label *l = labels; 477 474 struct uasm_reloc *r = relocs; 475 + #endif 478 476 479 477 memset(labels, 0, sizeof(labels)); 480 478 memset(relocs, 0, sizeof(relocs)); ··· 496 490 */ 497 491 preempt_disable(); 498 492 493 + #ifdef CONFIG_CPU_LOONGSON64 494 + UASM_i_MFC0(&p, K1, C0_PGD); 495 + uasm_i_lddir(&p, K0, K1, 3); /* global page dir */ 496 + #ifndef __PAGETABLE_PMD_FOLDED 497 + uasm_i_lddir(&p, K1, K0, 1); /* middle page dir */ 498 + #endif 499 + uasm_i_ldpte(&p, K1, 0); /* even */ 500 + uasm_i_ldpte(&p, K1, 1); /* odd */ 501 + uasm_i_tlbwr(&p); 502 + #else 499 503 /* 500 504 * Now for the actual refill bit. A lot of this can be common with the 501 505 * Linux TLB refill handler, however we don't need to handle so many ··· 528 512 build_get_ptep(&p, K0, K1); 529 513 build_update_entries(&p, K0, K1); 530 514 build_tlb_write_entry(&p, &l, &r, tlb_random); 515 + #endif 531 516 532 517 preempt_enable(); 533 518
+13 -80
arch/mips/kvm/interrupt.c
··· 61 61 * the EXC code will be set when we are actually 62 62 * delivering the interrupt: 63 63 */ 64 - switch (intr) { 65 - case 2: 66 - kvm_set_c0_guest_cause(vcpu->arch.cop0, (C_IRQ0)); 67 - /* Queue up an INT exception for the core */ 68 - kvm_mips_queue_irq(vcpu, MIPS_EXC_INT_IO); 69 - break; 70 - 71 - case 3: 72 - kvm_set_c0_guest_cause(vcpu->arch.cop0, (C_IRQ1)); 73 - kvm_mips_queue_irq(vcpu, MIPS_EXC_INT_IPI_1); 74 - break; 75 - 76 - case 4: 77 - kvm_set_c0_guest_cause(vcpu->arch.cop0, (C_IRQ2)); 78 - kvm_mips_queue_irq(vcpu, MIPS_EXC_INT_IPI_2); 79 - break; 80 - 81 - default: 82 - break; 83 - } 84 - 64 + kvm_set_c0_guest_cause(vcpu->arch.cop0, 1 << (intr + 8)); 65 + kvm_mips_queue_irq(vcpu, kvm_irq_to_priority(intr)); 85 66 } 86 67 87 68 void kvm_mips_dequeue_io_int_cb(struct kvm_vcpu *vcpu, ··· 70 89 { 71 90 int intr = (int)irq->irq; 72 91 73 - switch (intr) { 74 - case -2: 75 - kvm_clear_c0_guest_cause(vcpu->arch.cop0, (C_IRQ0)); 76 - kvm_mips_dequeue_irq(vcpu, MIPS_EXC_INT_IO); 77 - break; 78 - 79 - case -3: 80 - kvm_clear_c0_guest_cause(vcpu->arch.cop0, (C_IRQ1)); 81 - kvm_mips_dequeue_irq(vcpu, MIPS_EXC_INT_IPI_1); 82 - break; 83 - 84 - case -4: 85 - kvm_clear_c0_guest_cause(vcpu->arch.cop0, (C_IRQ2)); 86 - kvm_mips_dequeue_irq(vcpu, MIPS_EXC_INT_IPI_2); 87 - break; 88 - 89 - default: 90 - break; 91 - } 92 - 92 + kvm_clear_c0_guest_cause(vcpu->arch.cop0, 1 << (-intr + 8)); 93 + kvm_mips_dequeue_irq(vcpu, kvm_irq_to_priority(-intr)); 93 94 } 94 95 95 96 /* Deliver the interrupt of the corresponding priority, if possible. */ ··· 79 116 u32 cause) 80 117 { 81 118 int allowed = 0; 82 - u32 exccode; 119 + u32 exccode, ie; 83 120 84 121 struct kvm_vcpu_arch *arch = &vcpu->arch; 85 122 struct mips_coproc *cop0 = vcpu->arch.cop0; 86 123 87 - switch (priority) { 88 - case MIPS_EXC_INT_TIMER: 89 - if ((kvm_read_c0_guest_status(cop0) & ST0_IE) 90 - && (!(kvm_read_c0_guest_status(cop0) & (ST0_EXL | ST0_ERL))) 91 - && (kvm_read_c0_guest_status(cop0) & IE_IRQ5)) { 92 - allowed = 1; 93 - exccode = EXCCODE_INT; 94 - } 95 - break; 124 + if (priority == MIPS_EXC_MAX) 125 + return 0; 96 126 97 - case MIPS_EXC_INT_IO: 98 - if ((kvm_read_c0_guest_status(cop0) & ST0_IE) 99 - && (!(kvm_read_c0_guest_status(cop0) & (ST0_EXL | ST0_ERL))) 100 - && (kvm_read_c0_guest_status(cop0) & IE_IRQ0)) { 101 - allowed = 1; 102 - exccode = EXCCODE_INT; 103 - } 104 - break; 105 - 106 - case MIPS_EXC_INT_IPI_1: 107 - if ((kvm_read_c0_guest_status(cop0) & ST0_IE) 108 - && (!(kvm_read_c0_guest_status(cop0) & (ST0_EXL | ST0_ERL))) 109 - && (kvm_read_c0_guest_status(cop0) & IE_IRQ1)) { 110 - allowed = 1; 111 - exccode = EXCCODE_INT; 112 - } 113 - break; 114 - 115 - case MIPS_EXC_INT_IPI_2: 116 - if ((kvm_read_c0_guest_status(cop0) & ST0_IE) 117 - && (!(kvm_read_c0_guest_status(cop0) & (ST0_EXL | ST0_ERL))) 118 - && (kvm_read_c0_guest_status(cop0) & IE_IRQ2)) { 119 - allowed = 1; 120 - exccode = EXCCODE_INT; 121 - } 122 - break; 123 - 124 - default: 125 - break; 127 + ie = 1 << (kvm_priority_to_irq[priority] + 8); 128 + if ((kvm_read_c0_guest_status(cop0) & ST0_IE) 129 + && (!(kvm_read_c0_guest_status(cop0) & (ST0_EXL | ST0_ERL))) 130 + && (kvm_read_c0_guest_status(cop0) & ie)) { 131 + allowed = 1; 132 + exccode = EXCCODE_INT; 126 133 } 127 134 128 135 /* Are we allowed to deliver the interrupt ??? */
+9 -5
arch/mips/kvm/interrupt.h
··· 21 21 #define MIPS_EXC_NMI 5 22 22 #define MIPS_EXC_MCHK 6 23 23 #define MIPS_EXC_INT_TIMER 7 24 - #define MIPS_EXC_INT_IO 8 25 - #define MIPS_EXC_EXECUTE 9 26 - #define MIPS_EXC_INT_IPI_1 10 27 - #define MIPS_EXC_INT_IPI_2 11 28 - #define MIPS_EXC_MAX 12 24 + #define MIPS_EXC_INT_IO_1 8 25 + #define MIPS_EXC_INT_IO_2 9 26 + #define MIPS_EXC_EXECUTE 10 27 + #define MIPS_EXC_INT_IPI_1 11 28 + #define MIPS_EXC_INT_IPI_2 12 29 + #define MIPS_EXC_MAX 13 29 30 /* XXXSL More to follow */ 30 31 31 32 #define C_TI (_ULCAST_(1) << 30) ··· 38 37 #define KVM_MIPS_IRQ_DELIVER_ALL_AT_ONCE (0) 39 38 #define KVM_MIPS_IRQ_CLEAR_ALL_AT_ONCE (0) 40 39 #endif 40 + 41 + extern u32 *kvm_priority_to_irq; 42 + u32 kvm_irq_to_priority(u32 irq); 41 43 42 44 void kvm_mips_queue_irq(struct kvm_vcpu *vcpu, unsigned int priority); 43 45 void kvm_mips_dequeue_irq(struct kvm_vcpu *vcpu, unsigned int priority);
+214
arch/mips/kvm/loongson_ipi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Loongson-3 Virtual IPI interrupt support. 4 + * 5 + * Copyright (C) 2019 Loongson Technologies, Inc. All rights reserved. 6 + * 7 + * Authors: Chen Zhu <zhuchen@loongson.cn> 8 + * Authors: Huacai Chen <chenhc@lemote.com> 9 + */ 10 + 11 + #include <linux/kvm_host.h> 12 + 13 + #define IPI_BASE 0x3ff01000ULL 14 + 15 + #define CORE0_STATUS_OFF 0x000 16 + #define CORE0_EN_OFF 0x004 17 + #define CORE0_SET_OFF 0x008 18 + #define CORE0_CLEAR_OFF 0x00c 19 + #define CORE0_BUF_20 0x020 20 + #define CORE0_BUF_28 0x028 21 + #define CORE0_BUF_30 0x030 22 + #define CORE0_BUF_38 0x038 23 + 24 + #define CORE1_STATUS_OFF 0x100 25 + #define CORE1_EN_OFF 0x104 26 + #define CORE1_SET_OFF 0x108 27 + #define CORE1_CLEAR_OFF 0x10c 28 + #define CORE1_BUF_20 0x120 29 + #define CORE1_BUF_28 0x128 30 + #define CORE1_BUF_30 0x130 31 + #define CORE1_BUF_38 0x138 32 + 33 + #define CORE2_STATUS_OFF 0x200 34 + #define CORE2_EN_OFF 0x204 35 + #define CORE2_SET_OFF 0x208 36 + #define CORE2_CLEAR_OFF 0x20c 37 + #define CORE2_BUF_20 0x220 38 + #define CORE2_BUF_28 0x228 39 + #define CORE2_BUF_30 0x230 40 + #define CORE2_BUF_38 0x238 41 + 42 + #define CORE3_STATUS_OFF 0x300 43 + #define CORE3_EN_OFF 0x304 44 + #define CORE3_SET_OFF 0x308 45 + #define CORE3_CLEAR_OFF 0x30c 46 + #define CORE3_BUF_20 0x320 47 + #define CORE3_BUF_28 0x328 48 + #define CORE3_BUF_30 0x330 49 + #define CORE3_BUF_38 0x338 50 + 51 + static int loongson_vipi_read(struct loongson_kvm_ipi *ipi, 52 + gpa_t addr, int len, void *val) 53 + { 54 + uint32_t core = (addr >> 8) & 3; 55 + uint32_t node = (addr >> 44) & 3; 56 + uint32_t id = core + node * 4; 57 + uint64_t offset = addr & 0xff; 58 + void *pbuf; 59 + struct ipi_state *s = &(ipi->ipistate[id]); 60 + 61 + BUG_ON(offset & (len - 1)); 62 + 63 + switch (offset) { 64 + case CORE0_STATUS_OFF: 65 + *(uint64_t *)val = s->status; 66 + break; 67 + 68 + case CORE0_EN_OFF: 69 + *(uint64_t *)val = s->en; 70 + break; 71 + 72 + case CORE0_SET_OFF: 73 + *(uint64_t *)val = 0; 74 + break; 75 + 76 + case CORE0_CLEAR_OFF: 77 + *(uint64_t *)val = 0; 78 + break; 79 + 80 + case CORE0_BUF_20 ... CORE0_BUF_38: 81 + pbuf = (void *)s->buf + (offset - 0x20); 82 + if (len == 8) 83 + *(uint64_t *)val = *(uint64_t *)pbuf; 84 + else /* Assume len == 4 */ 85 + *(uint32_t *)val = *(uint32_t *)pbuf; 86 + break; 87 + 88 + default: 89 + pr_notice("%s with unknown addr %llx\n", __func__, addr); 90 + break; 91 + } 92 + 93 + return 0; 94 + } 95 + 96 + static int loongson_vipi_write(struct loongson_kvm_ipi *ipi, 97 + gpa_t addr, int len, const void *val) 98 + { 99 + uint32_t core = (addr >> 8) & 3; 100 + uint32_t node = (addr >> 44) & 3; 101 + uint32_t id = core + node * 4; 102 + uint64_t data, offset = addr & 0xff; 103 + void *pbuf; 104 + struct kvm *kvm = ipi->kvm; 105 + struct kvm_mips_interrupt irq; 106 + struct ipi_state *s = &(ipi->ipistate[id]); 107 + 108 + data = *(uint64_t *)val; 109 + BUG_ON(offset & (len - 1)); 110 + 111 + switch (offset) { 112 + case CORE0_STATUS_OFF: 113 + break; 114 + 115 + case CORE0_EN_OFF: 116 + s->en = data; 117 + break; 118 + 119 + case CORE0_SET_OFF: 120 + s->status |= data; 121 + irq.cpu = id; 122 + irq.irq = 6; 123 + kvm_vcpu_ioctl_interrupt(kvm->vcpus[id], &irq); 124 + break; 125 + 126 + case CORE0_CLEAR_OFF: 127 + s->status &= ~data; 128 + if (!s->status) { 129 + irq.cpu = id; 130 + irq.irq = -6; 131 + kvm_vcpu_ioctl_interrupt(kvm->vcpus[id], &irq); 132 + } 133 + break; 134 + 135 + case CORE0_BUF_20 ... CORE0_BUF_38: 136 + pbuf = (void *)s->buf + (offset - 0x20); 137 + if (len == 8) 138 + *(uint64_t *)pbuf = (uint64_t)data; 139 + else /* Assume len == 4 */ 140 + *(uint32_t *)pbuf = (uint32_t)data; 141 + break; 142 + 143 + default: 144 + pr_notice("%s with unknown addr %llx\n", __func__, addr); 145 + break; 146 + } 147 + 148 + return 0; 149 + } 150 + 151 + static int kvm_ipi_read(struct kvm_vcpu *vcpu, struct kvm_io_device *dev, 152 + gpa_t addr, int len, void *val) 153 + { 154 + unsigned long flags; 155 + struct loongson_kvm_ipi *ipi; 156 + struct ipi_io_device *ipi_device; 157 + 158 + ipi_device = container_of(dev, struct ipi_io_device, device); 159 + ipi = ipi_device->ipi; 160 + 161 + spin_lock_irqsave(&ipi->lock, flags); 162 + loongson_vipi_read(ipi, addr, len, val); 163 + spin_unlock_irqrestore(&ipi->lock, flags); 164 + 165 + return 0; 166 + } 167 + 168 + static int kvm_ipi_write(struct kvm_vcpu *vcpu, struct kvm_io_device *dev, 169 + gpa_t addr, int len, const void *val) 170 + { 171 + unsigned long flags; 172 + struct loongson_kvm_ipi *ipi; 173 + struct ipi_io_device *ipi_device; 174 + 175 + ipi_device = container_of(dev, struct ipi_io_device, device); 176 + ipi = ipi_device->ipi; 177 + 178 + spin_lock_irqsave(&ipi->lock, flags); 179 + loongson_vipi_write(ipi, addr, len, val); 180 + spin_unlock_irqrestore(&ipi->lock, flags); 181 + 182 + return 0; 183 + } 184 + 185 + static const struct kvm_io_device_ops kvm_ipi_ops = { 186 + .read = kvm_ipi_read, 187 + .write = kvm_ipi_write, 188 + }; 189 + 190 + void kvm_init_loongson_ipi(struct kvm *kvm) 191 + { 192 + int i; 193 + unsigned long addr; 194 + struct loongson_kvm_ipi *s; 195 + struct kvm_io_device *device; 196 + 197 + s = &kvm->arch.ipi; 198 + s->kvm = kvm; 199 + spin_lock_init(&s->lock); 200 + 201 + /* 202 + * Initialize IPI device 203 + */ 204 + for (i = 0; i < 4; i++) { 205 + device = &s->dev_ipi[i].device; 206 + kvm_iodevice_init(device, &kvm_ipi_ops); 207 + addr = (((unsigned long)i) << 44) + IPI_BASE; 208 + mutex_lock(&kvm->slots_lock); 209 + kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, addr, 0x400, device); 210 + mutex_unlock(&kvm->slots_lock); 211 + s->dev_ipi[i].ipi = s; 212 + s->dev_ipi[i].node_id = i; 213 + } 214 + }
+44 -3
arch/mips/kvm/mips.c
··· 67 67 VCPU_STAT("vz_ghfc", vz_ghfc_exits), 68 68 VCPU_STAT("vz_gpa", vz_gpa_exits), 69 69 VCPU_STAT("vz_resvd", vz_resvd_exits), 70 + VCPU_STAT("vz_cpucfg", vz_cpucfg_exits), 70 71 #endif 71 72 VCPU_STAT("halt_successful_poll", halt_successful_poll), 72 73 VCPU_STAT("halt_attempted_poll", halt_attempted_poll), ··· 130 129 return 0; 131 130 } 132 131 132 + extern void kvm_init_loongson_ipi(struct kvm *kvm); 133 + 133 134 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) 134 135 { 135 136 switch (type) { ··· 150 147 kvm->arch.gpa_mm.pgd = kvm_pgd_alloc(); 151 148 if (!kvm->arch.gpa_mm.pgd) 152 149 return -ENOMEM; 150 + 151 + #ifdef CONFIG_CPU_LOONGSON64 152 + kvm_init_loongson_ipi(kvm); 153 + #endif 153 154 154 155 return 0; 155 156 } ··· 497 490 int intr = (int)irq->irq; 498 491 struct kvm_vcpu *dvcpu = NULL; 499 492 500 - if (intr == 3 || intr == -3 || intr == 4 || intr == -4) 493 + if (intr == kvm_priority_to_irq[MIPS_EXC_INT_IPI_1] || 494 + intr == kvm_priority_to_irq[MIPS_EXC_INT_IPI_2] || 495 + intr == (-kvm_priority_to_irq[MIPS_EXC_INT_IPI_1]) || 496 + intr == (-kvm_priority_to_irq[MIPS_EXC_INT_IPI_2])) 501 497 kvm_debug("%s: CPU: %d, INTR: %d\n", __func__, irq->cpu, 502 498 (int)intr); 503 499 ··· 509 499 else 510 500 dvcpu = vcpu->kvm->vcpus[irq->cpu]; 511 501 512 - if (intr == 2 || intr == 3 || intr == 4) { 502 + if (intr == 2 || intr == 3 || intr == 4 || intr == 6) { 513 503 kvm_mips_callbacks->queue_io_int(dvcpu, irq); 514 504 515 - } else if (intr == -2 || intr == -3 || intr == -4) { 505 + } else if (intr == -2 || intr == -3 || intr == -4 || intr == -6) { 516 506 kvm_mips_callbacks->dequeue_io_int(dvcpu, irq); 517 507 } else { 518 508 kvm_err("%s: invalid interrupt ioctl (%d:%d)\n", __func__, ··· 1630 1620 .notifier_call = kvm_mips_csr_die_notify, 1631 1621 }; 1632 1622 1623 + static u32 kvm_default_priority_to_irq[MIPS_EXC_MAX] = { 1624 + [MIPS_EXC_INT_TIMER] = C_IRQ5, 1625 + [MIPS_EXC_INT_IO_1] = C_IRQ0, 1626 + [MIPS_EXC_INT_IPI_1] = C_IRQ1, 1627 + [MIPS_EXC_INT_IPI_2] = C_IRQ2, 1628 + }; 1629 + 1630 + static u32 kvm_loongson3_priority_to_irq[MIPS_EXC_MAX] = { 1631 + [MIPS_EXC_INT_TIMER] = C_IRQ5, 1632 + [MIPS_EXC_INT_IO_1] = C_IRQ0, 1633 + [MIPS_EXC_INT_IO_2] = C_IRQ1, 1634 + [MIPS_EXC_INT_IPI_1] = C_IRQ4, 1635 + }; 1636 + 1637 + u32 *kvm_priority_to_irq = kvm_default_priority_to_irq; 1638 + 1639 + u32 kvm_irq_to_priority(u32 irq) 1640 + { 1641 + int i; 1642 + 1643 + for (i = MIPS_EXC_INT_TIMER; i < MIPS_EXC_MAX; i++) { 1644 + if (kvm_priority_to_irq[i] == (1 << (irq + 8))) 1645 + return i; 1646 + } 1647 + 1648 + return MIPS_EXC_MAX; 1649 + } 1650 + 1633 1651 static int __init kvm_mips_init(void) 1634 1652 { 1635 1653 int ret; ··· 1675 1637 1676 1638 if (ret) 1677 1639 return ret; 1640 + 1641 + if (boot_cpu_type() == CPU_LOONGSON64) 1642 + kvm_priority_to_irq = kvm_loongson3_priority_to_irq; 1678 1643 1679 1644 register_die_notifier(&kvm_mips_csr_die_notifier); 1680 1645
+41
arch/mips/kvm/tlb.c
··· 20 20 21 21 #include <asm/cpu.h> 22 22 #include <asm/bootinfo.h> 23 + #include <asm/mipsregs.h> 23 24 #include <asm/mmu_context.h> 24 25 #include <asm/cacheflush.h> 25 26 #include <asm/tlb.h> ··· 621 620 tlbw_use_hazard(); 622 621 } 623 622 EXPORT_SYMBOL_GPL(kvm_vz_load_guesttlb); 623 + 624 + #ifdef CONFIG_CPU_LOONGSON64 625 + void kvm_loongson_clear_guest_vtlb(void) 626 + { 627 + int idx = read_gc0_index(); 628 + 629 + /* Set root GuestID for root probe and write of guest TLB entry */ 630 + set_root_gid_to_guest_gid(); 631 + 632 + write_gc0_index(0); 633 + guest_tlbinvf(); 634 + write_gc0_index(idx); 635 + 636 + clear_root_gid(); 637 + set_c0_diag(LOONGSON_DIAG_ITLB | LOONGSON_DIAG_DTLB); 638 + } 639 + EXPORT_SYMBOL_GPL(kvm_loongson_clear_guest_vtlb); 640 + 641 + void kvm_loongson_clear_guest_ftlb(void) 642 + { 643 + int i; 644 + int idx = read_gc0_index(); 645 + 646 + /* Set root GuestID for root probe and write of guest TLB entry */ 647 + set_root_gid_to_guest_gid(); 648 + 649 + for (i = current_cpu_data.tlbsizevtlb; 650 + i < (current_cpu_data.tlbsizevtlb + 651 + current_cpu_data.tlbsizeftlbsets); 652 + i++) { 653 + write_gc0_index(i); 654 + guest_tlbinvf(); 655 + } 656 + write_gc0_index(idx); 657 + 658 + clear_root_gid(); 659 + set_c0_diag(LOONGSON_DIAG_ITLB | LOONGSON_DIAG_DTLB); 660 + } 661 + EXPORT_SYMBOL_GPL(kvm_loongson_clear_guest_ftlb); 662 + #endif 624 663 625 664 #endif 626 665
+3
arch/mips/kvm/trap_emul.c
··· 529 529 case KVM_CAP_MIPS_TE: 530 530 r = 1; 531 531 break; 532 + case KVM_CAP_IOEVENTFD: 533 + r = 1; 534 + break; 532 535 default: 533 536 r = 0; 534 537 break;
+175 -62
arch/mips/kvm/vz.c
··· 29 29 #include <linux/kvm_host.h> 30 30 31 31 #include "interrupt.h" 32 + #include "loongson_regs.h" 32 33 33 34 #include "trace.h" 34 35 ··· 127 126 return mask; 128 127 } 129 128 129 + static inline unsigned int kvm_vz_config6_guest_wrmask(struct kvm_vcpu *vcpu) 130 + { 131 + return MIPS_CONF6_LOONGSON_INTIMER | MIPS_CONF6_LOONGSON_EXTIMER; 132 + } 133 + 130 134 /* 131 135 * VZ optionally allows these additional Config bits to be written by root: 132 136 * Config: M, [MT] ··· 186 180 return kvm_vz_config5_guest_wrmask(vcpu) | MIPS_CONF5_MRP; 187 181 } 188 182 183 + static inline unsigned int kvm_vz_config6_user_wrmask(struct kvm_vcpu *vcpu) 184 + { 185 + return kvm_vz_config6_guest_wrmask(vcpu) | 186 + MIPS_CONF6_LOONGSON_SFBEN | MIPS_CONF6_LOONGSON_FTLBDIS; 187 + } 188 + 189 189 static gpa_t kvm_vz_gva_to_gpa_cb(gva_t gva) 190 190 { 191 191 /* VZ guest has already converted gva to gpa */ ··· 237 225 * interrupts are asynchronous to vcpu execution therefore defer guest 238 226 * cp0 accesses 239 227 */ 240 - switch (intr) { 241 - case 2: 242 - kvm_vz_queue_irq(vcpu, MIPS_EXC_INT_IO); 243 - break; 244 - 245 - case 3: 246 - kvm_vz_queue_irq(vcpu, MIPS_EXC_INT_IPI_1); 247 - break; 248 - 249 - case 4: 250 - kvm_vz_queue_irq(vcpu, MIPS_EXC_INT_IPI_2); 251 - break; 252 - 253 - default: 254 - break; 255 - } 256 - 228 + kvm_vz_queue_irq(vcpu, kvm_irq_to_priority(intr)); 257 229 } 258 230 259 231 static void kvm_vz_dequeue_io_int_cb(struct kvm_vcpu *vcpu, ··· 249 253 * interrupts are asynchronous to vcpu execution therefore defer guest 250 254 * cp0 accesses 251 255 */ 252 - switch (intr) { 253 - case -2: 254 - kvm_vz_dequeue_irq(vcpu, MIPS_EXC_INT_IO); 255 - break; 256 - 257 - case -3: 258 - kvm_vz_dequeue_irq(vcpu, MIPS_EXC_INT_IPI_1); 259 - break; 260 - 261 - case -4: 262 - kvm_vz_dequeue_irq(vcpu, MIPS_EXC_INT_IPI_2); 263 - break; 264 - 265 - default: 266 - break; 267 - } 268 - 256 + kvm_vz_dequeue_irq(vcpu, kvm_irq_to_priority(-intr)); 269 257 } 270 - 271 - static u32 kvm_vz_priority_to_irq[MIPS_EXC_MAX] = { 272 - [MIPS_EXC_INT_TIMER] = C_IRQ5, 273 - [MIPS_EXC_INT_IO] = C_IRQ0, 274 - [MIPS_EXC_INT_IPI_1] = C_IRQ1, 275 - [MIPS_EXC_INT_IPI_2] = C_IRQ2, 276 - }; 277 258 278 259 static int kvm_vz_irq_deliver_cb(struct kvm_vcpu *vcpu, unsigned int priority, 279 260 u32 cause) 280 261 { 281 262 u32 irq = (priority < MIPS_EXC_MAX) ? 282 - kvm_vz_priority_to_irq[priority] : 0; 263 + kvm_priority_to_irq[priority] : 0; 283 264 284 265 switch (priority) { 285 266 case MIPS_EXC_INT_TIMER: 286 267 set_gc0_cause(C_TI); 287 268 break; 288 269 289 - case MIPS_EXC_INT_IO: 270 + case MIPS_EXC_INT_IO_1: 271 + case MIPS_EXC_INT_IO_2: 290 272 case MIPS_EXC_INT_IPI_1: 291 273 case MIPS_EXC_INT_IPI_2: 292 274 if (cpu_has_guestctl2) ··· 285 311 u32 cause) 286 312 { 287 313 u32 irq = (priority < MIPS_EXC_MAX) ? 288 - kvm_vz_priority_to_irq[priority] : 0; 314 + kvm_priority_to_irq[priority] : 0; 289 315 290 316 switch (priority) { 291 317 case MIPS_EXC_INT_TIMER: ··· 303 329 } 304 330 break; 305 331 306 - case MIPS_EXC_INT_IO: 332 + case MIPS_EXC_INT_IO_1: 333 + case MIPS_EXC_INT_IO_2: 307 334 case MIPS_EXC_INT_IPI_1: 308 335 case MIPS_EXC_INT_IPI_2: 309 336 /* Clear GuestCtl2.VIP irq if not using Hardware Clear */ ··· 941 966 (sel == 2 || /* SRSCtl */ 942 967 sel == 3)) || /* SRSMap */ 943 968 (rd == MIPS_CP0_CONFIG && 944 - (sel == 7)) || /* Config7 */ 969 + (sel == 6 || /* Config6 */ 970 + sel == 7)) || /* Config7 */ 945 971 (rd == MIPS_CP0_LLADDR && 946 972 (sel == 2) && /* MAARI */ 947 973 cpu_guest_has_maar && ··· 950 974 (rd == MIPS_CP0_ERRCTL && 951 975 (sel == 0))) { /* ErrCtl */ 952 976 val = cop0->reg[rd][sel]; 977 + #ifdef CONFIG_CPU_LOONGSON64 978 + } else if (rd == MIPS_CP0_DIAG && 979 + (sel == 0)) { /* Diag */ 980 + val = cop0->reg[rd][sel]; 981 + #endif 953 982 } else { 954 983 val = 0; 955 984 er = EMULATE_FAIL; ··· 1017 1036 cpu_guest_has_maar && 1018 1037 !cpu_guest_has_dyn_maar) { 1019 1038 kvm_write_maari(vcpu, val); 1039 + } else if (rd == MIPS_CP0_CONFIG && 1040 + (sel == 6)) { 1041 + cop0->reg[rd][sel] = (int)val; 1020 1042 } else if (rd == MIPS_CP0_ERRCTL && 1021 1043 (sel == 0)) { /* ErrCtl */ 1022 1044 /* ignore the written value */ 1045 + #ifdef CONFIG_CPU_LOONGSON64 1046 + } else if (rd == MIPS_CP0_DIAG && 1047 + (sel == 0)) { /* Diag */ 1048 + unsigned long flags; 1049 + 1050 + local_irq_save(flags); 1051 + if (val & LOONGSON_DIAG_BTB) { 1052 + /* Flush BTB */ 1053 + set_c0_diag(LOONGSON_DIAG_BTB); 1054 + } 1055 + if (val & LOONGSON_DIAG_ITLB) { 1056 + /* Flush ITLB */ 1057 + set_c0_diag(LOONGSON_DIAG_ITLB); 1058 + } 1059 + if (val & LOONGSON_DIAG_DTLB) { 1060 + /* Flush DTLB */ 1061 + set_c0_diag(LOONGSON_DIAG_DTLB); 1062 + } 1063 + if (val & LOONGSON_DIAG_VTLB) { 1064 + /* Flush VTLB */ 1065 + kvm_loongson_clear_guest_vtlb(); 1066 + } 1067 + if (val & LOONGSON_DIAG_FTLB) { 1068 + /* Flush FTLB */ 1069 + kvm_loongson_clear_guest_ftlb(); 1070 + } 1071 + local_irq_restore(flags); 1072 + #endif 1023 1073 } else { 1024 1074 er = EMULATE_FAIL; 1025 1075 } ··· 1141 1129 return EMULATE_FAIL; 1142 1130 } 1143 1131 1132 + #ifdef CONFIG_CPU_LOONGSON64 1133 + static enum emulation_result kvm_vz_gpsi_lwc2(union mips_instruction inst, 1134 + u32 *opc, u32 cause, 1135 + struct kvm_run *run, 1136 + struct kvm_vcpu *vcpu) 1137 + { 1138 + unsigned int rs, rd; 1139 + unsigned int hostcfg; 1140 + unsigned long curr_pc; 1141 + enum emulation_result er = EMULATE_DONE; 1142 + 1143 + /* 1144 + * Update PC and hold onto current PC in case there is 1145 + * an error and we want to rollback the PC 1146 + */ 1147 + curr_pc = vcpu->arch.pc; 1148 + er = update_pc(vcpu, cause); 1149 + if (er == EMULATE_FAIL) 1150 + return er; 1151 + 1152 + rs = inst.loongson3_lscsr_format.rs; 1153 + rd = inst.loongson3_lscsr_format.rd; 1154 + switch (inst.loongson3_lscsr_format.fr) { 1155 + case 0x8: /* Read CPUCFG */ 1156 + ++vcpu->stat.vz_cpucfg_exits; 1157 + hostcfg = read_cpucfg(vcpu->arch.gprs[rs]); 1158 + 1159 + switch (vcpu->arch.gprs[rs]) { 1160 + case LOONGSON_CFG0: 1161 + vcpu->arch.gprs[rd] = 0x14c000; 1162 + break; 1163 + case LOONGSON_CFG1: 1164 + hostcfg &= (LOONGSON_CFG1_FP | LOONGSON_CFG1_MMI | 1165 + LOONGSON_CFG1_MSA1 | LOONGSON_CFG1_MSA2 | 1166 + LOONGSON_CFG1_SFBP); 1167 + vcpu->arch.gprs[rd] = hostcfg; 1168 + break; 1169 + case LOONGSON_CFG2: 1170 + hostcfg &= (LOONGSON_CFG2_LEXT1 | LOONGSON_CFG2_LEXT2 | 1171 + LOONGSON_CFG2_LEXT3 | LOONGSON_CFG2_LSPW); 1172 + vcpu->arch.gprs[rd] = hostcfg; 1173 + break; 1174 + case LOONGSON_CFG3: 1175 + vcpu->arch.gprs[rd] = hostcfg; 1176 + break; 1177 + default: 1178 + /* Don't export any other advanced features to guest */ 1179 + vcpu->arch.gprs[rd] = 0; 1180 + break; 1181 + } 1182 + break; 1183 + 1184 + default: 1185 + kvm_err("lwc2 emulate not impl %d rs %lx @%lx\n", 1186 + inst.loongson3_lscsr_format.fr, vcpu->arch.gprs[rs], curr_pc); 1187 + er = EMULATE_FAIL; 1188 + break; 1189 + } 1190 + 1191 + /* Rollback PC only if emulation was unsuccessful */ 1192 + if (er == EMULATE_FAIL) { 1193 + kvm_err("[%#lx]%s: unsupported lwc2 instruction 0x%08x 0x%08x\n", 1194 + curr_pc, __func__, inst.word, inst.loongson3_lscsr_format.fr); 1195 + 1196 + vcpu->arch.pc = curr_pc; 1197 + } 1198 + 1199 + return er; 1200 + } 1201 + #endif 1202 + 1144 1203 static enum emulation_result kvm_trap_vz_handle_gpsi(u32 cause, u32 *opc, 1145 1204 struct kvm_vcpu *vcpu) 1146 1205 { ··· 1239 1156 case cache_op: 1240 1157 trace_kvm_exit(vcpu, KVM_TRACE_EXIT_CACHE); 1241 1158 er = kvm_vz_gpsi_cache(inst, opc, cause, run, vcpu); 1159 + break; 1160 + #endif 1161 + #ifdef CONFIG_CPU_LOONGSON64 1162 + case lwc2_op: 1163 + er = kvm_vz_gpsi_lwc2(inst, opc, cause, run, vcpu); 1242 1164 break; 1243 1165 #endif 1244 1166 case spec3_op: ··· 1740 1652 KVM_REG_MIPS_CP0_CONFIG3, 1741 1653 KVM_REG_MIPS_CP0_CONFIG4, 1742 1654 KVM_REG_MIPS_CP0_CONFIG5, 1655 + KVM_REG_MIPS_CP0_CONFIG6, 1743 1656 #ifdef CONFIG_64BIT 1744 1657 KVM_REG_MIPS_CP0_XCONTEXT, 1745 1658 #endif ··· 1795 1706 ret += ARRAY_SIZE(kvm_vz_get_one_regs_contextconfig); 1796 1707 if (cpu_guest_has_segments) 1797 1708 ret += ARRAY_SIZE(kvm_vz_get_one_regs_segments); 1798 - if (cpu_guest_has_htw) 1709 + if (cpu_guest_has_htw || cpu_guest_has_ldpte) 1799 1710 ret += ARRAY_SIZE(kvm_vz_get_one_regs_htw); 1800 1711 if (cpu_guest_has_maar && !cpu_guest_has_dyn_maar) 1801 1712 ret += 1 + ARRAY_SIZE(vcpu->arch.maar); ··· 1844 1755 return -EFAULT; 1845 1756 indices += ARRAY_SIZE(kvm_vz_get_one_regs_segments); 1846 1757 } 1847 - if (cpu_guest_has_htw) { 1758 + if (cpu_guest_has_htw || cpu_guest_has_ldpte) { 1848 1759 if (copy_to_user(indices, kvm_vz_get_one_regs_htw, 1849 1760 sizeof(kvm_vz_get_one_regs_htw))) 1850 1761 return -EFAULT; ··· 1967 1878 *v = read_gc0_segctl2(); 1968 1879 break; 1969 1880 case KVM_REG_MIPS_CP0_PWBASE: 1970 - if (!cpu_guest_has_htw) 1881 + if (!cpu_guest_has_htw && !cpu_guest_has_ldpte) 1971 1882 return -EINVAL; 1972 1883 *v = read_gc0_pwbase(); 1973 1884 break; 1974 1885 case KVM_REG_MIPS_CP0_PWFIELD: 1975 - if (!cpu_guest_has_htw) 1886 + if (!cpu_guest_has_htw && !cpu_guest_has_ldpte) 1976 1887 return -EINVAL; 1977 1888 *v = read_gc0_pwfield(); 1978 1889 break; 1979 1890 case KVM_REG_MIPS_CP0_PWSIZE: 1980 - if (!cpu_guest_has_htw) 1891 + if (!cpu_guest_has_htw && !cpu_guest_has_ldpte) 1981 1892 return -EINVAL; 1982 1893 *v = read_gc0_pwsize(); 1983 1894 break; ··· 1985 1896 *v = (long)read_gc0_wired(); 1986 1897 break; 1987 1898 case KVM_REG_MIPS_CP0_PWCTL: 1988 - if (!cpu_guest_has_htw) 1899 + if (!cpu_guest_has_htw && !cpu_guest_has_ldpte) 1989 1900 return -EINVAL; 1990 1901 *v = read_gc0_pwctl(); 1991 1902 break; ··· 2067 1978 if (!cpu_guest_has_conf5) 2068 1979 return -EINVAL; 2069 1980 *v = read_gc0_config5(); 1981 + break; 1982 + case KVM_REG_MIPS_CP0_CONFIG6: 1983 + *v = kvm_read_sw_gc0_config6(cop0); 2070 1984 break; 2071 1985 case KVM_REG_MIPS_CP0_MAAR(0) ... KVM_REG_MIPS_CP0_MAAR(0x3f): 2072 1986 if (!cpu_guest_has_maar || cpu_guest_has_dyn_maar) ··· 2193 2101 write_gc0_segctl2(v); 2194 2102 break; 2195 2103 case KVM_REG_MIPS_CP0_PWBASE: 2196 - if (!cpu_guest_has_htw) 2104 + if (!cpu_guest_has_htw && !cpu_guest_has_ldpte) 2197 2105 return -EINVAL; 2198 2106 write_gc0_pwbase(v); 2199 2107 break; 2200 2108 case KVM_REG_MIPS_CP0_PWFIELD: 2201 - if (!cpu_guest_has_htw) 2109 + if (!cpu_guest_has_htw && !cpu_guest_has_ldpte) 2202 2110 return -EINVAL; 2203 2111 write_gc0_pwfield(v); 2204 2112 break; 2205 2113 case KVM_REG_MIPS_CP0_PWSIZE: 2206 - if (!cpu_guest_has_htw) 2114 + if (!cpu_guest_has_htw && !cpu_guest_has_ldpte) 2207 2115 return -EINVAL; 2208 2116 write_gc0_pwsize(v); 2209 2117 break; ··· 2211 2119 change_gc0_wired(MIPSR6_WIRED_WIRED, v); 2212 2120 break; 2213 2121 case KVM_REG_MIPS_CP0_PWCTL: 2214 - if (!cpu_guest_has_htw) 2122 + if (!cpu_guest_has_htw && !cpu_guest_has_ldpte) 2215 2123 return -EINVAL; 2216 2124 write_gc0_pwctl(v); 2217 2125 break; ··· 2338 2246 if (change) { 2339 2247 v = cur ^ change; 2340 2248 write_gc0_config5(v); 2249 + } 2250 + break; 2251 + case KVM_REG_MIPS_CP0_CONFIG6: 2252 + cur = kvm_read_sw_gc0_config6(cop0); 2253 + change = (cur ^ v) & kvm_vz_config6_user_wrmask(vcpu); 2254 + if (change) { 2255 + v = cur ^ change; 2256 + kvm_write_sw_gc0_config6(cop0, (int)v); 2341 2257 } 2342 2258 break; 2343 2259 case KVM_REG_MIPS_CP0_MAAR(0) ... KVM_REG_MIPS_CP0_MAAR(0x3f): ··· 2680 2580 } 2681 2581 2682 2582 /* restore HTW registers */ 2683 - if (cpu_guest_has_htw) { 2583 + if (cpu_guest_has_htw || cpu_guest_has_ldpte) { 2684 2584 kvm_restore_gc0_pwbase(cop0); 2685 2585 kvm_restore_gc0_pwfield(cop0); 2686 2586 kvm_restore_gc0_pwsize(cop0); ··· 2697 2597 * prevents a SC on the next VCPU from succeeding by matching a LL on 2698 2598 * the previous VCPU. 2699 2599 */ 2700 - if (cpu_guest_has_rw_llb) 2600 + if (vcpu->kvm->created_vcpus > 1) 2701 2601 write_gc0_lladdr(0); 2702 2602 2703 2603 return 0; ··· 2785 2685 } 2786 2686 2787 2687 /* save HTW registers if enabled in guest */ 2788 - if (cpu_guest_has_htw && 2789 - kvm_read_sw_gc0_config3(cop0) & MIPS_CONF3_PW) { 2688 + if (cpu_guest_has_ldpte || (cpu_guest_has_htw && 2689 + kvm_read_sw_gc0_config3(cop0) & MIPS_CONF3_PW)) { 2790 2690 kvm_save_gc0_pwbase(cop0); 2791 2691 kvm_save_gc0_pwfield(cop0); 2792 2692 kvm_save_gc0_pwsize(cop0); ··· 2953 2853 write_c0_guestctl0(MIPS_GCTL0_CP0 | 2954 2854 (MIPS_GCTL0_AT_GUEST << MIPS_GCTL0_AT_SHIFT) | 2955 2855 MIPS_GCTL0_CG | MIPS_GCTL0_CF); 2956 - if (cpu_has_guestctl0ext) 2957 - set_c0_guestctl0ext(MIPS_GCTL0EXT_CGI); 2856 + if (cpu_has_guestctl0ext) { 2857 + if (current_cpu_type() != CPU_LOONGSON64) 2858 + set_c0_guestctl0ext(MIPS_GCTL0EXT_CGI); 2859 + else 2860 + clear_c0_guestctl0ext(MIPS_GCTL0EXT_CGI); 2861 + } 2958 2862 2959 2863 if (cpu_has_guestid) { 2960 2864 write_c0_guestctl1(0); ··· 2974 2870 /* clear any pending injected virtual guest interrupts */ 2975 2871 if (cpu_has_guestctl2) 2976 2872 clear_c0_guestctl2(0x3f << 10); 2873 + 2874 + #ifdef CONFIG_CPU_LOONGSON64 2875 + /* Control guest CCA attribute */ 2876 + if (cpu_has_csr()) 2877 + csr_writel(csr_readl(0xffffffec) | 0x1, 0xffffffec); 2878 + #endif 2977 2879 2978 2880 return 0; 2979 2881 } ··· 3037 2927 r = 2; 3038 2928 break; 3039 2929 #endif 2930 + case KVM_CAP_IOEVENTFD: 2931 + r = 1; 2932 + break; 3040 2933 default: 3041 2934 r = 0; 3042 2935 break;
+7 -9
arch/powerpc/include/asm/kvm_book3s.h
··· 155 155 extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr); 156 156 extern void kvmppc_mmu_flush_segment(struct kvm_vcpu *vcpu, ulong eaddr, ulong seg_size); 157 157 extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu); 158 - extern int kvmppc_book3s_hv_page_fault(struct kvm_run *run, 159 - struct kvm_vcpu *vcpu, unsigned long addr, 160 - unsigned long status); 158 + extern int kvmppc_book3s_hv_page_fault(struct kvm_vcpu *vcpu, 159 + unsigned long addr, unsigned long status); 161 160 extern long kvmppc_hv_find_lock_hpte(struct kvm *kvm, gva_t eaddr, 162 161 unsigned long slb_v, unsigned long valid); 163 - extern int kvmppc_hv_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu, 162 + extern int kvmppc_hv_emulate_mmio(struct kvm_vcpu *vcpu, 164 163 unsigned long gpa, gva_t ea, int is_store); 165 164 166 165 extern void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte); ··· 173 174 extern int kvmppc_mmu_hv_init(void); 174 175 extern int kvmppc_book3s_hcall_implemented(struct kvm *kvm, unsigned long hc); 175 176 176 - extern int kvmppc_book3s_radix_page_fault(struct kvm_run *run, 177 - struct kvm_vcpu *vcpu, 177 + extern int kvmppc_book3s_radix_page_fault(struct kvm_vcpu *vcpu, 178 178 unsigned long ea, unsigned long dsisr); 179 179 extern unsigned long __kvmhv_copy_tofrom_guest_radix(int lpid, int pid, 180 180 gva_t eaddr, void *to, void *from, ··· 232 234 extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, 233 235 bool upper, u32 val); 234 236 extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr); 235 - extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu); 237 + extern int kvmppc_emulate_paired_single(struct kvm_vcpu *vcpu); 236 238 extern kvm_pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, 237 239 bool writing, bool *writable); 238 240 extern void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *rev, ··· 298 300 void kvmhv_release_all_nested(struct kvm *kvm); 299 301 long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu); 300 302 long kvmhv_do_nested_tlbie(struct kvm_vcpu *vcpu); 301 - int kvmhv_run_single_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu, 303 + int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, 302 304 u64 time_limit, unsigned long lpcr); 303 305 void kvmhv_save_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr); 304 306 void kvmhv_restore_hv_return_state(struct kvm_vcpu *vcpu, 305 307 struct hv_guest_state *hr); 306 - long int kvmhv_nested_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu); 308 + long int kvmhv_nested_page_fault(struct kvm_vcpu *vcpu); 307 309 308 310 void kvmppc_giveup_fac(struct kvm_vcpu *vcpu, ulong fac); 309 311
-1
arch/powerpc/include/asm/kvm_host.h
··· 795 795 struct mmio_hpte_cache_entry *pgfault_cache; 796 796 797 797 struct task_struct *run_task; 798 - struct kvm_run *kvm_run; 799 798 800 799 spinlock_t vpa_update_lock; 801 800 struct kvmppc_vpa vpa;
+13 -14
arch/powerpc/include/asm/kvm_ppc.h
··· 58 58 XLATE_WRITE /* check for write permissions */ 59 59 }; 60 60 61 - extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); 62 - extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); 61 + extern int kvmppc_vcpu_run(struct kvm_vcpu *vcpu); 62 + extern int __kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu); 63 63 extern void kvmppc_handler_highmem(void); 64 64 65 65 extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu); 66 - extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 66 + extern int kvmppc_handle_load(struct kvm_vcpu *vcpu, 67 67 unsigned int rt, unsigned int bytes, 68 68 int is_default_endian); 69 - extern int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu, 69 + extern int kvmppc_handle_loads(struct kvm_vcpu *vcpu, 70 70 unsigned int rt, unsigned int bytes, 71 71 int is_default_endian); 72 - extern int kvmppc_handle_vsx_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 72 + extern int kvmppc_handle_vsx_load(struct kvm_vcpu *vcpu, 73 73 unsigned int rt, unsigned int bytes, 74 74 int is_default_endian, int mmio_sign_extend); 75 - extern int kvmppc_handle_vmx_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 75 + extern int kvmppc_handle_vmx_load(struct kvm_vcpu *vcpu, 76 76 unsigned int rt, unsigned int bytes, int is_default_endian); 77 - extern int kvmppc_handle_vmx_store(struct kvm_run *run, struct kvm_vcpu *vcpu, 77 + extern int kvmppc_handle_vmx_store(struct kvm_vcpu *vcpu, 78 78 unsigned int rs, unsigned int bytes, int is_default_endian); 79 - extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu, 79 + extern int kvmppc_handle_store(struct kvm_vcpu *vcpu, 80 80 u64 val, unsigned int bytes, 81 81 int is_default_endian); 82 - extern int kvmppc_handle_vsx_store(struct kvm_run *run, struct kvm_vcpu *vcpu, 82 + extern int kvmppc_handle_vsx_store(struct kvm_vcpu *vcpu, 83 83 int rs, unsigned int bytes, 84 84 int is_default_endian); 85 85 ··· 90 90 bool data); 91 91 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, 92 92 bool data); 93 - extern int kvmppc_emulate_instruction(struct kvm_run *run, 94 - struct kvm_vcpu *vcpu); 93 + extern int kvmppc_emulate_instruction(struct kvm_vcpu *vcpu); 95 94 extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu); 96 - extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu); 95 + extern int kvmppc_emulate_mmio(struct kvm_vcpu *vcpu); 97 96 extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu); 98 97 extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb); 99 98 extern void kvmppc_decrementer_func(struct kvm_vcpu *vcpu); ··· 266 267 void (*vcpu_put)(struct kvm_vcpu *vcpu); 267 268 void (*inject_interrupt)(struct kvm_vcpu *vcpu, int vec, u64 srr1_flags); 268 269 void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr); 269 - int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu); 270 + int (*vcpu_run)(struct kvm_vcpu *vcpu); 270 271 int (*vcpu_create)(struct kvm_vcpu *vcpu); 271 272 void (*vcpu_free)(struct kvm_vcpu *vcpu); 272 273 int (*check_requests)(struct kvm_vcpu *vcpu); ··· 290 291 int (*init_vm)(struct kvm *kvm); 291 292 void (*destroy_vm)(struct kvm *kvm); 292 293 int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info); 293 - int (*emulate_op)(struct kvm_run *run, struct kvm_vcpu *vcpu, 294 + int (*emulate_op)(struct kvm_vcpu *vcpu, 294 295 unsigned int inst, int *advance); 295 296 int (*emulate_mtspr)(struct kvm_vcpu *vcpu, int sprn, ulong spr_val); 296 297 int (*emulate_mfspr)(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val);
+2 -2
arch/powerpc/kvm/book3s.c
··· 755 755 } 756 756 EXPORT_SYMBOL_GPL(kvmppc_set_msr); 757 757 758 - int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) 758 + int kvmppc_vcpu_run(struct kvm_vcpu *vcpu) 759 759 { 760 - return vcpu->kvm->arch.kvm_ops->vcpu_run(kvm_run, vcpu); 760 + return vcpu->kvm->arch.kvm_ops->vcpu_run(vcpu); 761 761 } 762 762 763 763 int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
+1 -1
arch/powerpc/kvm/book3s.h
··· 18 18 19 19 extern int kvmppc_mmu_init_pr(struct kvm_vcpu *vcpu); 20 20 extern void kvmppc_mmu_destroy_pr(struct kvm_vcpu *vcpu); 21 - extern int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, 21 + extern int kvmppc_core_emulate_op_pr(struct kvm_vcpu *vcpu, 22 22 unsigned int inst, int *advance); 23 23 extern int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, 24 24 int sprn, ulong spr_val);
+6 -6
arch/powerpc/kvm/book3s_64_mmu_hv.c
··· 412 412 return (instr & mask) != 0; 413 413 } 414 414 415 - int kvmppc_hv_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu, 415 + int kvmppc_hv_emulate_mmio(struct kvm_vcpu *vcpu, 416 416 unsigned long gpa, gva_t ea, int is_store) 417 417 { 418 418 u32 last_inst; ··· 472 472 473 473 vcpu->arch.paddr_accessed = gpa; 474 474 vcpu->arch.vaddr_accessed = ea; 475 - return kvmppc_emulate_mmio(run, vcpu); 475 + return kvmppc_emulate_mmio(vcpu); 476 476 } 477 477 478 - int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu, 478 + int kvmppc_book3s_hv_page_fault(struct kvm_vcpu *vcpu, 479 479 unsigned long ea, unsigned long dsisr) 480 480 { 481 481 struct kvm *kvm = vcpu->kvm; ··· 498 498 pte_t pte, *ptep; 499 499 500 500 if (kvm_is_radix(kvm)) 501 - return kvmppc_book3s_radix_page_fault(run, vcpu, ea, dsisr); 501 + return kvmppc_book3s_radix_page_fault(vcpu, ea, dsisr); 502 502 503 503 /* 504 504 * Real-mode code has already searched the HPT and found the ··· 518 518 gpa_base = r & HPTE_R_RPN & ~(psize - 1); 519 519 gfn_base = gpa_base >> PAGE_SHIFT; 520 520 gpa = gpa_base | (ea & (psize - 1)); 521 - return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea, 521 + return kvmppc_hv_emulate_mmio(vcpu, gpa, ea, 522 522 dsisr & DSISR_ISSTORE); 523 523 } 524 524 } ··· 554 554 555 555 /* No memslot means it's an emulated MMIO region */ 556 556 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) 557 - return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea, 557 + return kvmppc_hv_emulate_mmio(vcpu, gpa, ea, 558 558 dsisr & DSISR_ISSTORE); 559 559 560 560 /*
+28 -8
arch/powerpc/kvm/book3s_64_mmu_radix.c
··· 353 353 354 354 static pte_t *kvmppc_pte_alloc(void) 355 355 { 356 - return kmem_cache_alloc(kvm_pte_cache, GFP_KERNEL); 356 + pte_t *pte; 357 + 358 + pte = kmem_cache_alloc(kvm_pte_cache, GFP_KERNEL); 359 + /* pmd_populate() will only reference _pa(pte). */ 360 + kmemleak_ignore(pte); 361 + 362 + return pte; 357 363 } 358 364 359 365 static void kvmppc_pte_free(pte_t *ptep) ··· 369 363 370 364 static pmd_t *kvmppc_pmd_alloc(void) 371 365 { 372 - return kmem_cache_alloc(kvm_pmd_cache, GFP_KERNEL); 366 + pmd_t *pmd; 367 + 368 + pmd = kmem_cache_alloc(kvm_pmd_cache, GFP_KERNEL); 369 + /* pud_populate() will only reference _pa(pmd). */ 370 + kmemleak_ignore(pmd); 371 + 372 + return pmd; 373 373 } 374 374 375 375 static void kvmppc_pmd_free(pmd_t *pmdp) ··· 429 417 * Callers are responsible for flushing the PWC. 430 418 * 431 419 * When page tables are being unmapped/freed as part of page fault path 432 - * (full == false), ptes are not expected. There is code to unmap them 433 - * and emit a warning if encountered, but there may already be data 434 - * corruption due to the unexpected mappings. 420 + * (full == false), valid ptes are generally not expected; however, there 421 + * is one situation where they arise, which is when dirty page logging is 422 + * turned off for a memslot while the VM is running. The new memslot 423 + * becomes visible to page faults before the memslot commit function 424 + * gets to flush the memslot, which can lead to a 2MB page mapping being 425 + * installed for a guest physical address where there are already 64kB 426 + * (or 4kB) mappings (of sub-pages of the same 2MB page). 435 427 */ 436 428 static void kvmppc_unmap_free_pte(struct kvm *kvm, pte_t *pte, bool full, 437 429 unsigned int lpid) ··· 449 433 for (it = 0; it < PTRS_PER_PTE; ++it, ++p) { 450 434 if (pte_val(*p) == 0) 451 435 continue; 452 - WARN_ON_ONCE(1); 453 436 kvmppc_unmap_pte(kvm, p, 454 437 pte_pfn(*p) << PAGE_SHIFT, 455 438 PAGE_SHIFT, NULL, lpid); ··· 906 891 return ret; 907 892 } 908 893 909 - int kvmppc_book3s_radix_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu, 894 + int kvmppc_book3s_radix_page_fault(struct kvm_vcpu *vcpu, 910 895 unsigned long ea, unsigned long dsisr) 911 896 { 912 897 struct kvm *kvm = vcpu->kvm; ··· 952 937 kvmppc_core_queue_data_storage(vcpu, ea, dsisr); 953 938 return RESUME_GUEST; 954 939 } 955 - return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea, writing); 940 + return kvmppc_hv_emulate_mmio(vcpu, gpa, ea, writing); 956 941 } 957 942 958 943 if (memslot->flags & KVM_MEM_READONLY) { ··· 1157 1142 kvm->arch.lpid); 1158 1143 gpa += PAGE_SIZE; 1159 1144 } 1145 + /* 1146 + * Increase the mmu notifier sequence number to prevent any page 1147 + * fault that read the memslot earlier from writing a PTE. 1148 + */ 1149 + kvm->mmu_notifier_seq++; 1160 1150 spin_unlock(&kvm->mmu_lock); 1161 1151 } 1162 1152
+14 -4
arch/powerpc/kvm/book3s_64_vio.c
··· 73 73 struct kvmppc_spapr_tce_iommu_table *stit, *tmp; 74 74 struct iommu_table_group *table_group = NULL; 75 75 76 + rcu_read_lock(); 76 77 list_for_each_entry_rcu(stt, &kvm->arch.spapr_tce_tables, list) { 77 78 78 79 table_group = iommu_group_get_iommudata(grp); ··· 88 87 kref_put(&stit->kref, kvm_spapr_tce_liobn_put); 89 88 } 90 89 } 90 + cond_resched_rcu(); 91 91 } 92 + rcu_read_unlock(); 92 93 } 93 94 94 95 extern long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd, ··· 108 105 if (!f.file) 109 106 return -EBADF; 110 107 108 + rcu_read_lock(); 111 109 list_for_each_entry_rcu(stt, &kvm->arch.spapr_tce_tables, list) { 112 110 if (stt == f.file->private_data) { 113 111 found = true; 114 112 break; 115 113 } 116 114 } 115 + rcu_read_unlock(); 117 116 118 117 fdput(f); 119 118 ··· 148 143 if (!tbl) 149 144 return -EINVAL; 150 145 146 + rcu_read_lock(); 151 147 list_for_each_entry_rcu(stit, &stt->iommu_tables, next) { 152 148 if (tbl != stit->tbl) 153 149 continue; ··· 156 150 if (!kref_get_unless_zero(&stit->kref)) { 157 151 /* stit is being destroyed */ 158 152 iommu_tce_table_put(tbl); 153 + rcu_read_unlock(); 159 154 return -ENOTTY; 160 155 } 161 156 /* 162 157 * The table is already known to this KVM, we just increased 163 158 * its KVM reference counter and can return. 164 159 */ 160 + rcu_read_unlock(); 165 161 return 0; 166 162 } 163 + rcu_read_unlock(); 167 164 168 165 stit = kzalloc(sizeof(*stit), GFP_KERNEL); 169 166 if (!stit) { ··· 374 365 if (kvmppc_tce_to_ua(stt->kvm, tce, &ua)) 375 366 return H_TOO_HARD; 376 367 368 + rcu_read_lock(); 377 369 list_for_each_entry_rcu(stit, &stt->iommu_tables, next) { 378 370 unsigned long hpa = 0; 379 371 struct mm_iommu_table_group_mem_t *mem; 380 372 long shift = stit->tbl->it_page_shift; 381 373 382 374 mem = mm_iommu_lookup(stt->kvm->mm, ua, 1ULL << shift); 383 - if (!mem) 375 + if (!mem || mm_iommu_ua_to_hpa(mem, ua, shift, &hpa)) { 376 + rcu_read_unlock(); 384 377 return H_TOO_HARD; 385 - 386 - if (mm_iommu_ua_to_hpa(mem, ua, shift, &hpa)) 387 - return H_TOO_HARD; 378 + } 388 379 } 380 + rcu_read_unlock(); 389 381 390 382 return H_SUCCESS; 391 383 }
+5 -5
arch/powerpc/kvm/book3s_emulate.c
··· 235 235 236 236 #endif 237 237 238 - int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, 238 + int kvmppc_core_emulate_op_pr(struct kvm_vcpu *vcpu, 239 239 unsigned int inst, int *advance) 240 240 { 241 241 int emulated = EMULATE_DONE; ··· 371 371 if (kvmppc_h_pr(vcpu, cmd) == EMULATE_DONE) 372 372 break; 373 373 374 - run->papr_hcall.nr = cmd; 374 + vcpu->run->papr_hcall.nr = cmd; 375 375 for (i = 0; i < 9; ++i) { 376 376 ulong gpr = kvmppc_get_gpr(vcpu, 4 + i); 377 - run->papr_hcall.args[i] = gpr; 377 + vcpu->run->papr_hcall.args[i] = gpr; 378 378 } 379 379 380 - run->exit_reason = KVM_EXIT_PAPR_HCALL; 380 + vcpu->run->exit_reason = KVM_EXIT_PAPR_HCALL; 381 381 vcpu->arch.hcall_needed = 1; 382 382 emulated = EMULATE_EXIT_USER; 383 383 break; ··· 629 629 } 630 630 631 631 if (emulated == EMULATE_FAIL) 632 - emulated = kvmppc_emulate_paired_single(run, vcpu); 632 + emulated = kvmppc_emulate_paired_single(vcpu); 633 633 634 634 return emulated; 635 635 }
+40 -35
arch/powerpc/kvm/book3s_hv.c
··· 1094 1094 ret = kvmppc_h_svm_init_done(vcpu->kvm); 1095 1095 break; 1096 1096 case H_SVM_INIT_ABORT: 1097 - ret = H_UNSUPPORTED; 1098 - if (kvmppc_get_srr1(vcpu) & MSR_S) 1099 - ret = kvmppc_h_svm_init_abort(vcpu->kvm); 1097 + /* 1098 + * Even if that call is made by the Ultravisor, the SSR1 value 1099 + * is the guest context one, with the secure bit clear as it has 1100 + * not yet been secured. So we can't check it here. 1101 + * Instead the kvm->arch.secure_guest flag is checked inside 1102 + * kvmppc_h_svm_init_abort(). 1103 + */ 1104 + ret = kvmppc_h_svm_init_abort(vcpu->kvm); 1100 1105 break; 1101 1106 1102 1107 default: ··· 1156 1151 return kvmppc_hcall_impl_hv_realmode(cmd); 1157 1152 } 1158 1153 1159 - static int kvmppc_emulate_debug_inst(struct kvm_run *run, 1160 - struct kvm_vcpu *vcpu) 1154 + static int kvmppc_emulate_debug_inst(struct kvm_vcpu *vcpu) 1161 1155 { 1162 1156 u32 last_inst; 1163 1157 ··· 1170 1166 } 1171 1167 1172 1168 if (last_inst == KVMPPC_INST_SW_BREAKPOINT) { 1173 - run->exit_reason = KVM_EXIT_DEBUG; 1174 - run->debug.arch.address = kvmppc_get_pc(vcpu); 1169 + vcpu->run->exit_reason = KVM_EXIT_DEBUG; 1170 + vcpu->run->debug.arch.address = kvmppc_get_pc(vcpu); 1175 1171 return RESUME_HOST; 1176 1172 } else { 1177 1173 kvmppc_core_queue_program(vcpu, SRR1_PROGILL); ··· 1272 1268 return RESUME_GUEST; 1273 1269 } 1274 1270 1275 - static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, 1271 + static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu, 1276 1272 struct task_struct *tsk) 1277 1273 { 1274 + struct kvm_run *run = vcpu->run; 1278 1275 int r = RESUME_HOST; 1279 1276 1280 1277 vcpu->stat.sum_exits++; ··· 1410 1405 swab32(vcpu->arch.emul_inst) : 1411 1406 vcpu->arch.emul_inst; 1412 1407 if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) { 1413 - r = kvmppc_emulate_debug_inst(run, vcpu); 1408 + r = kvmppc_emulate_debug_inst(vcpu); 1414 1409 } else { 1415 1410 kvmppc_core_queue_program(vcpu, SRR1_PROGILL); 1416 1411 r = RESUME_GUEST; ··· 1462 1457 return r; 1463 1458 } 1464 1459 1465 - static int kvmppc_handle_nested_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) 1460 + static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu) 1466 1461 { 1467 1462 int r; 1468 1463 int srcu_idx; ··· 1520 1515 */ 1521 1516 case BOOK3S_INTERRUPT_H_DATA_STORAGE: 1522 1517 srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 1523 - r = kvmhv_nested_page_fault(run, vcpu); 1518 + r = kvmhv_nested_page_fault(vcpu); 1524 1519 srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx); 1525 1520 break; 1526 1521 case BOOK3S_INTERRUPT_H_INST_STORAGE: ··· 1530 1525 if (vcpu->arch.shregs.msr & HSRR1_HISI_WRITE) 1531 1526 vcpu->arch.fault_dsisr |= DSISR_ISSTORE; 1532 1527 srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 1533 - r = kvmhv_nested_page_fault(run, vcpu); 1528 + r = kvmhv_nested_page_fault(vcpu); 1534 1529 srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx); 1535 1530 break; 1536 1531 ··· 2934 2929 2935 2930 ret = RESUME_GUEST; 2936 2931 if (vcpu->arch.trap) 2937 - ret = kvmppc_handle_exit_hv(vcpu->arch.kvm_run, vcpu, 2932 + ret = kvmppc_handle_exit_hv(vcpu, 2938 2933 vcpu->arch.run_task); 2939 2934 2940 2935 vcpu->arch.ret = ret; ··· 3899 3894 return r; 3900 3895 } 3901 3896 3902 - static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) 3897 + static int kvmppc_run_vcpu(struct kvm_vcpu *vcpu) 3903 3898 { 3899 + struct kvm_run *run = vcpu->run; 3904 3900 int n_ceded, i, r; 3905 3901 struct kvmppc_vcore *vc; 3906 3902 struct kvm_vcpu *v; 3907 3903 3908 3904 trace_kvmppc_run_vcpu_enter(vcpu); 3909 3905 3910 - kvm_run->exit_reason = 0; 3906 + run->exit_reason = 0; 3911 3907 vcpu->arch.ret = RESUME_GUEST; 3912 3908 vcpu->arch.trap = 0; 3913 3909 kvmppc_update_vpas(vcpu); ··· 3920 3914 spin_lock(&vc->lock); 3921 3915 vcpu->arch.ceded = 0; 3922 3916 vcpu->arch.run_task = current; 3923 - vcpu->arch.kvm_run = kvm_run; 3924 3917 vcpu->arch.stolen_logged = vcore_stolen_time(vc, mftb()); 3925 3918 vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; 3926 3919 vcpu->arch.busy_preempt = TB_NIL; ··· 3952 3947 r = kvmhv_setup_mmu(vcpu); 3953 3948 spin_lock(&vc->lock); 3954 3949 if (r) { 3955 - kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY; 3956 - kvm_run->fail_entry. 3950 + run->exit_reason = KVM_EXIT_FAIL_ENTRY; 3951 + run->fail_entry. 3957 3952 hardware_entry_failure_reason = 0; 3958 3953 vcpu->arch.ret = r; 3959 3954 break; ··· 3972 3967 if (signal_pending(v->arch.run_task)) { 3973 3968 kvmppc_remove_runnable(vc, v); 3974 3969 v->stat.signal_exits++; 3975 - v->arch.kvm_run->exit_reason = KVM_EXIT_INTR; 3970 + v->run->exit_reason = KVM_EXIT_INTR; 3976 3971 v->arch.ret = -EINTR; 3977 3972 wake_up(&v->arch.cpu_run); 3978 3973 } ··· 4013 4008 if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) { 4014 4009 kvmppc_remove_runnable(vc, vcpu); 4015 4010 vcpu->stat.signal_exits++; 4016 - kvm_run->exit_reason = KVM_EXIT_INTR; 4011 + run->exit_reason = KVM_EXIT_INTR; 4017 4012 vcpu->arch.ret = -EINTR; 4018 4013 } 4019 4014 ··· 4024 4019 wake_up(&v->arch.cpu_run); 4025 4020 } 4026 4021 4027 - trace_kvmppc_run_vcpu_exit(vcpu, kvm_run); 4022 + trace_kvmppc_run_vcpu_exit(vcpu); 4028 4023 spin_unlock(&vc->lock); 4029 4024 return vcpu->arch.ret; 4030 4025 } 4031 4026 4032 - int kvmhv_run_single_vcpu(struct kvm_run *kvm_run, 4033 - struct kvm_vcpu *vcpu, u64 time_limit, 4027 + int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, 4034 4028 unsigned long lpcr) 4035 4029 { 4030 + struct kvm_run *run = vcpu->run; 4036 4031 int trap, r, pcpu; 4037 4032 int srcu_idx, lpid; 4038 4033 struct kvmppc_vcore *vc; ··· 4041 4036 4042 4037 trace_kvmppc_run_vcpu_enter(vcpu); 4043 4038 4044 - kvm_run->exit_reason = 0; 4039 + run->exit_reason = 0; 4045 4040 vcpu->arch.ret = RESUME_GUEST; 4046 4041 vcpu->arch.trap = 0; 4047 4042 4048 4043 vc = vcpu->arch.vcore; 4049 4044 vcpu->arch.ceded = 0; 4050 4045 vcpu->arch.run_task = current; 4051 - vcpu->arch.kvm_run = kvm_run; 4052 4046 vcpu->arch.stolen_logged = vcore_stolen_time(vc, mftb()); 4053 4047 vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; 4054 4048 vcpu->arch.busy_preempt = TB_NIL; ··· 4165 4161 r = RESUME_GUEST; 4166 4162 if (trap) { 4167 4163 if (!nested) 4168 - r = kvmppc_handle_exit_hv(kvm_run, vcpu, current); 4164 + r = kvmppc_handle_exit_hv(vcpu, current); 4169 4165 else 4170 - r = kvmppc_handle_nested_exit(kvm_run, vcpu); 4166 + r = kvmppc_handle_nested_exit(vcpu); 4171 4167 } 4172 4168 vcpu->arch.ret = r; 4173 4169 ··· 4177 4173 while (vcpu->arch.ceded && !kvmppc_vcpu_woken(vcpu)) { 4178 4174 if (signal_pending(current)) { 4179 4175 vcpu->stat.signal_exits++; 4180 - kvm_run->exit_reason = KVM_EXIT_INTR; 4176 + run->exit_reason = KVM_EXIT_INTR; 4181 4177 vcpu->arch.ret = -EINTR; 4182 4178 break; 4183 4179 } ··· 4193 4189 4194 4190 done: 4195 4191 kvmppc_remove_runnable(vc, vcpu); 4196 - trace_kvmppc_run_vcpu_exit(vcpu, kvm_run); 4192 + trace_kvmppc_run_vcpu_exit(vcpu); 4197 4193 4198 4194 return vcpu->arch.ret; 4199 4195 4200 4196 sigpend: 4201 4197 vcpu->stat.signal_exits++; 4202 - kvm_run->exit_reason = KVM_EXIT_INTR; 4198 + run->exit_reason = KVM_EXIT_INTR; 4203 4199 vcpu->arch.ret = -EINTR; 4204 4200 out: 4205 4201 local_irq_enable(); ··· 4207 4203 goto done; 4208 4204 } 4209 4205 4210 - static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu) 4206 + static int kvmppc_vcpu_run_hv(struct kvm_vcpu *vcpu) 4211 4207 { 4208 + struct kvm_run *run = vcpu->run; 4212 4209 int r; 4213 4210 int srcu_idx; 4214 4211 unsigned long ebb_regs[3] = {}; /* shut up GCC */ ··· 4293 4288 */ 4294 4289 if (kvm->arch.threads_indep && kvm_is_radix(kvm) && 4295 4290 !no_mixing_hpt_and_radix) 4296 - r = kvmhv_run_single_vcpu(run, vcpu, ~(u64)0, 4291 + r = kvmhv_run_single_vcpu(vcpu, ~(u64)0, 4297 4292 vcpu->arch.vcore->lpcr); 4298 4293 else 4299 - r = kvmppc_run_vcpu(run, vcpu); 4294 + r = kvmppc_run_vcpu(vcpu); 4300 4295 4301 4296 if (run->exit_reason == KVM_EXIT_PAPR_HCALL && 4302 4297 !(vcpu->arch.shregs.msr & MSR_PR)) { ··· 4306 4301 kvmppc_core_prepare_to_enter(vcpu); 4307 4302 } else if (r == RESUME_PAGE_FAULT) { 4308 4303 srcu_idx = srcu_read_lock(&kvm->srcu); 4309 - r = kvmppc_book3s_hv_page_fault(run, vcpu, 4304 + r = kvmppc_book3s_hv_page_fault(vcpu, 4310 4305 vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); 4311 4306 srcu_read_unlock(&kvm->srcu, srcu_idx); 4312 4307 } else if (r == RESUME_PASSTHROUGH) { ··· 4980 4975 } 4981 4976 4982 4977 /* We don't need to emulate any privileged instructions or dcbz */ 4983 - static int kvmppc_core_emulate_op_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, 4978 + static int kvmppc_core_emulate_op_hv(struct kvm_vcpu *vcpu, 4984 4979 unsigned int inst, int *advance) 4985 4980 { 4986 4981 return EMULATE_FAIL;
+6 -9
arch/powerpc/kvm/book3s_hv_nested.c
··· 290 290 r = RESUME_HOST; 291 291 break; 292 292 } 293 - r = kvmhv_run_single_vcpu(vcpu->arch.kvm_run, vcpu, hdec_exp, 294 - lpcr); 293 + r = kvmhv_run_single_vcpu(vcpu, hdec_exp, lpcr); 295 294 } while (is_kvmppc_resume_guest(r)); 296 295 297 296 /* save L2 state for return */ ··· 1269 1270 } 1270 1271 1271 1272 /* called with gp->tlb_lock held */ 1272 - static long int __kvmhv_nested_page_fault(struct kvm_run *run, 1273 - struct kvm_vcpu *vcpu, 1273 + static long int __kvmhv_nested_page_fault(struct kvm_vcpu *vcpu, 1274 1274 struct kvm_nested_guest *gp) 1275 1275 { 1276 1276 struct kvm *kvm = vcpu->kvm; ··· 1352 1354 } 1353 1355 1354 1356 /* passthrough of emulated MMIO case */ 1355 - return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea, writing); 1357 + return kvmppc_hv_emulate_mmio(vcpu, gpa, ea, writing); 1356 1358 } 1357 1359 if (memslot->flags & KVM_MEM_READONLY) { 1358 1360 if (writing) { ··· 1427 1429 rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn]; 1428 1430 ret = kvmppc_create_pte(kvm, gp->shadow_pgtable, pte, n_gpa, level, 1429 1431 mmu_seq, gp->shadow_lpid, rmapp, &n_rmap); 1430 - if (n_rmap) 1431 - kfree(n_rmap); 1432 + kfree(n_rmap); 1432 1433 if (ret == -EAGAIN) 1433 1434 ret = RESUME_GUEST; /* Let the guest try again */ 1434 1435 ··· 1438 1441 return RESUME_GUEST; 1439 1442 } 1440 1443 1441 - long int kvmhv_nested_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu) 1444 + long int kvmhv_nested_page_fault(struct kvm_vcpu *vcpu) 1442 1445 { 1443 1446 struct kvm_nested_guest *gp = vcpu->arch.nested; 1444 1447 long int ret; 1445 1448 1446 1449 mutex_lock(&gp->tlb_lock); 1447 - ret = __kvmhv_nested_page_fault(run, vcpu, gp); 1450 + ret = __kvmhv_nested_page_fault(vcpu, gp); 1448 1451 mutex_unlock(&gp->tlb_lock); 1449 1452 return ret; 1450 1453 }
+14
arch/powerpc/kvm/book3s_hv_uvmem.c
··· 749 749 const __be32 *prop; 750 750 u64 size = 0; 751 751 752 + /* 753 + * First try the new ibm,secure-memory nodes which supersede the 754 + * secure-memory-ranges property. 755 + * If we found some, no need to read the deprecated ones. 756 + */ 757 + for_each_compatible_node(np, NULL, "ibm,secure-memory") { 758 + prop = of_get_property(np, "reg", &len); 759 + if (!prop) 760 + continue; 761 + size += of_read_number(prop + 2, 2); 762 + } 763 + if (size) 764 + return size; 765 + 752 766 np = of_find_compatible_node(NULL, NULL, "ibm,uv-firmware"); 753 767 if (!np) 754 768 goto out;
+36 -36
arch/powerpc/kvm/book3s_paired_singles.c
··· 169 169 kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_DATA_STORAGE); 170 170 } 171 171 172 - static int kvmppc_emulate_fpr_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 172 + static int kvmppc_emulate_fpr_load(struct kvm_vcpu *vcpu, 173 173 int rs, ulong addr, int ls_type) 174 174 { 175 175 int emulated = EMULATE_FAIL; ··· 188 188 kvmppc_inject_pf(vcpu, addr, false); 189 189 goto done_load; 190 190 } else if (r == EMULATE_DO_MMIO) { 191 - emulated = kvmppc_handle_load(run, vcpu, KVM_MMIO_REG_FPR | rs, 191 + emulated = kvmppc_handle_load(vcpu, KVM_MMIO_REG_FPR | rs, 192 192 len, 1); 193 193 goto done_load; 194 194 } ··· 213 213 return emulated; 214 214 } 215 215 216 - static int kvmppc_emulate_fpr_store(struct kvm_run *run, struct kvm_vcpu *vcpu, 216 + static int kvmppc_emulate_fpr_store(struct kvm_vcpu *vcpu, 217 217 int rs, ulong addr, int ls_type) 218 218 { 219 219 int emulated = EMULATE_FAIL; ··· 248 248 if (r < 0) { 249 249 kvmppc_inject_pf(vcpu, addr, true); 250 250 } else if (r == EMULATE_DO_MMIO) { 251 - emulated = kvmppc_handle_store(run, vcpu, val, len, 1); 251 + emulated = kvmppc_handle_store(vcpu, val, len, 1); 252 252 } else { 253 253 emulated = EMULATE_DONE; 254 254 } ··· 259 259 return emulated; 260 260 } 261 261 262 - static int kvmppc_emulate_psq_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 262 + static int kvmppc_emulate_psq_load(struct kvm_vcpu *vcpu, 263 263 int rs, ulong addr, bool w, int i) 264 264 { 265 265 int emulated = EMULATE_FAIL; ··· 279 279 kvmppc_inject_pf(vcpu, addr, false); 280 280 goto done_load; 281 281 } else if ((r == EMULATE_DO_MMIO) && w) { 282 - emulated = kvmppc_handle_load(run, vcpu, KVM_MMIO_REG_FPR | rs, 282 + emulated = kvmppc_handle_load(vcpu, KVM_MMIO_REG_FPR | rs, 283 283 4, 1); 284 284 vcpu->arch.qpr[rs] = tmp[1]; 285 285 goto done_load; 286 286 } else if (r == EMULATE_DO_MMIO) { 287 - emulated = kvmppc_handle_load(run, vcpu, KVM_MMIO_REG_FQPR | rs, 287 + emulated = kvmppc_handle_load(vcpu, KVM_MMIO_REG_FQPR | rs, 288 288 8, 1); 289 289 goto done_load; 290 290 } ··· 302 302 return emulated; 303 303 } 304 304 305 - static int kvmppc_emulate_psq_store(struct kvm_run *run, struct kvm_vcpu *vcpu, 305 + static int kvmppc_emulate_psq_store(struct kvm_vcpu *vcpu, 306 306 int rs, ulong addr, bool w, int i) 307 307 { 308 308 int emulated = EMULATE_FAIL; ··· 318 318 if (r < 0) { 319 319 kvmppc_inject_pf(vcpu, addr, true); 320 320 } else if ((r == EMULATE_DO_MMIO) && w) { 321 - emulated = kvmppc_handle_store(run, vcpu, tmp[0], 4, 1); 321 + emulated = kvmppc_handle_store(vcpu, tmp[0], 4, 1); 322 322 } else if (r == EMULATE_DO_MMIO) { 323 323 u64 val = ((u64)tmp[0] << 32) | tmp[1]; 324 - emulated = kvmppc_handle_store(run, vcpu, val, 8, 1); 324 + emulated = kvmppc_handle_store(vcpu, val, 8, 1); 325 325 } else { 326 326 emulated = EMULATE_DONE; 327 327 } ··· 618 618 return EMULATE_DONE; 619 619 } 620 620 621 - int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu) 621 + int kvmppc_emulate_paired_single(struct kvm_vcpu *vcpu) 622 622 { 623 623 u32 inst; 624 624 enum emulation_result emulated = EMULATE_DONE; ··· 680 680 int i = inst_get_field(inst, 17, 19); 681 681 682 682 addr += get_d_signext(inst); 683 - emulated = kvmppc_emulate_psq_load(run, vcpu, ax_rd, addr, w, i); 683 + emulated = kvmppc_emulate_psq_load(vcpu, ax_rd, addr, w, i); 684 684 break; 685 685 } 686 686 case OP_PSQ_LU: ··· 690 690 int i = inst_get_field(inst, 17, 19); 691 691 692 692 addr += get_d_signext(inst); 693 - emulated = kvmppc_emulate_psq_load(run, vcpu, ax_rd, addr, w, i); 693 + emulated = kvmppc_emulate_psq_load(vcpu, ax_rd, addr, w, i); 694 694 695 695 if (emulated == EMULATE_DONE) 696 696 kvmppc_set_gpr(vcpu, ax_ra, addr); ··· 703 703 int i = inst_get_field(inst, 17, 19); 704 704 705 705 addr += get_d_signext(inst); 706 - emulated = kvmppc_emulate_psq_store(run, vcpu, ax_rd, addr, w, i); 706 + emulated = kvmppc_emulate_psq_store(vcpu, ax_rd, addr, w, i); 707 707 break; 708 708 } 709 709 case OP_PSQ_STU: ··· 713 713 int i = inst_get_field(inst, 17, 19); 714 714 715 715 addr += get_d_signext(inst); 716 - emulated = kvmppc_emulate_psq_store(run, vcpu, ax_rd, addr, w, i); 716 + emulated = kvmppc_emulate_psq_store(vcpu, ax_rd, addr, w, i); 717 717 718 718 if (emulated == EMULATE_DONE) 719 719 kvmppc_set_gpr(vcpu, ax_ra, addr); ··· 733 733 int i = inst_get_field(inst, 22, 24); 734 734 735 735 addr += kvmppc_get_gpr(vcpu, ax_rb); 736 - emulated = kvmppc_emulate_psq_load(run, vcpu, ax_rd, addr, w, i); 736 + emulated = kvmppc_emulate_psq_load(vcpu, ax_rd, addr, w, i); 737 737 break; 738 738 } 739 739 case OP_4X_PS_CMPO0: ··· 747 747 int i = inst_get_field(inst, 22, 24); 748 748 749 749 addr += kvmppc_get_gpr(vcpu, ax_rb); 750 - emulated = kvmppc_emulate_psq_load(run, vcpu, ax_rd, addr, w, i); 750 + emulated = kvmppc_emulate_psq_load(vcpu, ax_rd, addr, w, i); 751 751 752 752 if (emulated == EMULATE_DONE) 753 753 kvmppc_set_gpr(vcpu, ax_ra, addr); ··· 824 824 int i = inst_get_field(inst, 22, 24); 825 825 826 826 addr += kvmppc_get_gpr(vcpu, ax_rb); 827 - emulated = kvmppc_emulate_psq_store(run, vcpu, ax_rd, addr, w, i); 827 + emulated = kvmppc_emulate_psq_store(vcpu, ax_rd, addr, w, i); 828 828 break; 829 829 } 830 830 case OP_4XW_PSQ_STUX: ··· 834 834 int i = inst_get_field(inst, 22, 24); 835 835 836 836 addr += kvmppc_get_gpr(vcpu, ax_rb); 837 - emulated = kvmppc_emulate_psq_store(run, vcpu, ax_rd, addr, w, i); 837 + emulated = kvmppc_emulate_psq_store(vcpu, ax_rd, addr, w, i); 838 838 839 839 if (emulated == EMULATE_DONE) 840 840 kvmppc_set_gpr(vcpu, ax_ra, addr); ··· 922 922 { 923 923 ulong addr = (ax_ra ? kvmppc_get_gpr(vcpu, ax_ra) : 0) + full_d; 924 924 925 - emulated = kvmppc_emulate_fpr_load(run, vcpu, ax_rd, addr, 925 + emulated = kvmppc_emulate_fpr_load(vcpu, ax_rd, addr, 926 926 FPU_LS_SINGLE); 927 927 break; 928 928 } ··· 930 930 { 931 931 ulong addr = kvmppc_get_gpr(vcpu, ax_ra) + full_d; 932 932 933 - emulated = kvmppc_emulate_fpr_load(run, vcpu, ax_rd, addr, 933 + emulated = kvmppc_emulate_fpr_load(vcpu, ax_rd, addr, 934 934 FPU_LS_SINGLE); 935 935 936 936 if (emulated == EMULATE_DONE) ··· 941 941 { 942 942 ulong addr = (ax_ra ? kvmppc_get_gpr(vcpu, ax_ra) : 0) + full_d; 943 943 944 - emulated = kvmppc_emulate_fpr_load(run, vcpu, ax_rd, addr, 944 + emulated = kvmppc_emulate_fpr_load(vcpu, ax_rd, addr, 945 945 FPU_LS_DOUBLE); 946 946 break; 947 947 } ··· 949 949 { 950 950 ulong addr = kvmppc_get_gpr(vcpu, ax_ra) + full_d; 951 951 952 - emulated = kvmppc_emulate_fpr_load(run, vcpu, ax_rd, addr, 952 + emulated = kvmppc_emulate_fpr_load(vcpu, ax_rd, addr, 953 953 FPU_LS_DOUBLE); 954 954 955 955 if (emulated == EMULATE_DONE) ··· 960 960 { 961 961 ulong addr = (ax_ra ? kvmppc_get_gpr(vcpu, ax_ra) : 0) + full_d; 962 962 963 - emulated = kvmppc_emulate_fpr_store(run, vcpu, ax_rd, addr, 963 + emulated = kvmppc_emulate_fpr_store(vcpu, ax_rd, addr, 964 964 FPU_LS_SINGLE); 965 965 break; 966 966 } ··· 968 968 { 969 969 ulong addr = kvmppc_get_gpr(vcpu, ax_ra) + full_d; 970 970 971 - emulated = kvmppc_emulate_fpr_store(run, vcpu, ax_rd, addr, 971 + emulated = kvmppc_emulate_fpr_store(vcpu, ax_rd, addr, 972 972 FPU_LS_SINGLE); 973 973 974 974 if (emulated == EMULATE_DONE) ··· 979 979 { 980 980 ulong addr = (ax_ra ? kvmppc_get_gpr(vcpu, ax_ra) : 0) + full_d; 981 981 982 - emulated = kvmppc_emulate_fpr_store(run, vcpu, ax_rd, addr, 982 + emulated = kvmppc_emulate_fpr_store(vcpu, ax_rd, addr, 983 983 FPU_LS_DOUBLE); 984 984 break; 985 985 } ··· 987 987 { 988 988 ulong addr = kvmppc_get_gpr(vcpu, ax_ra) + full_d; 989 989 990 - emulated = kvmppc_emulate_fpr_store(run, vcpu, ax_rd, addr, 990 + emulated = kvmppc_emulate_fpr_store(vcpu, ax_rd, addr, 991 991 FPU_LS_DOUBLE); 992 992 993 993 if (emulated == EMULATE_DONE) ··· 1001 1001 ulong addr = ax_ra ? kvmppc_get_gpr(vcpu, ax_ra) : 0; 1002 1002 1003 1003 addr += kvmppc_get_gpr(vcpu, ax_rb); 1004 - emulated = kvmppc_emulate_fpr_load(run, vcpu, ax_rd, 1004 + emulated = kvmppc_emulate_fpr_load(vcpu, ax_rd, 1005 1005 addr, FPU_LS_SINGLE); 1006 1006 break; 1007 1007 } ··· 1010 1010 ulong addr = kvmppc_get_gpr(vcpu, ax_ra) + 1011 1011 kvmppc_get_gpr(vcpu, ax_rb); 1012 1012 1013 - emulated = kvmppc_emulate_fpr_load(run, vcpu, ax_rd, 1013 + emulated = kvmppc_emulate_fpr_load(vcpu, ax_rd, 1014 1014 addr, FPU_LS_SINGLE); 1015 1015 1016 1016 if (emulated == EMULATE_DONE) ··· 1022 1022 ulong addr = (ax_ra ? kvmppc_get_gpr(vcpu, ax_ra) : 0) + 1023 1023 kvmppc_get_gpr(vcpu, ax_rb); 1024 1024 1025 - emulated = kvmppc_emulate_fpr_load(run, vcpu, ax_rd, 1025 + emulated = kvmppc_emulate_fpr_load(vcpu, ax_rd, 1026 1026 addr, FPU_LS_DOUBLE); 1027 1027 break; 1028 1028 } ··· 1031 1031 ulong addr = kvmppc_get_gpr(vcpu, ax_ra) + 1032 1032 kvmppc_get_gpr(vcpu, ax_rb); 1033 1033 1034 - emulated = kvmppc_emulate_fpr_load(run, vcpu, ax_rd, 1034 + emulated = kvmppc_emulate_fpr_load(vcpu, ax_rd, 1035 1035 addr, FPU_LS_DOUBLE); 1036 1036 1037 1037 if (emulated == EMULATE_DONE) ··· 1043 1043 ulong addr = (ax_ra ? kvmppc_get_gpr(vcpu, ax_ra) : 0) + 1044 1044 kvmppc_get_gpr(vcpu, ax_rb); 1045 1045 1046 - emulated = kvmppc_emulate_fpr_store(run, vcpu, ax_rd, 1046 + emulated = kvmppc_emulate_fpr_store(vcpu, ax_rd, 1047 1047 addr, FPU_LS_SINGLE); 1048 1048 break; 1049 1049 } ··· 1052 1052 ulong addr = kvmppc_get_gpr(vcpu, ax_ra) + 1053 1053 kvmppc_get_gpr(vcpu, ax_rb); 1054 1054 1055 - emulated = kvmppc_emulate_fpr_store(run, vcpu, ax_rd, 1055 + emulated = kvmppc_emulate_fpr_store(vcpu, ax_rd, 1056 1056 addr, FPU_LS_SINGLE); 1057 1057 1058 1058 if (emulated == EMULATE_DONE) ··· 1064 1064 ulong addr = (ax_ra ? kvmppc_get_gpr(vcpu, ax_ra) : 0) + 1065 1065 kvmppc_get_gpr(vcpu, ax_rb); 1066 1066 1067 - emulated = kvmppc_emulate_fpr_store(run, vcpu, ax_rd, 1067 + emulated = kvmppc_emulate_fpr_store(vcpu, ax_rd, 1068 1068 addr, FPU_LS_DOUBLE); 1069 1069 break; 1070 1070 } ··· 1073 1073 ulong addr = kvmppc_get_gpr(vcpu, ax_ra) + 1074 1074 kvmppc_get_gpr(vcpu, ax_rb); 1075 1075 1076 - emulated = kvmppc_emulate_fpr_store(run, vcpu, ax_rd, 1076 + emulated = kvmppc_emulate_fpr_store(vcpu, ax_rd, 1077 1077 addr, FPU_LS_DOUBLE); 1078 1078 1079 1079 if (emulated == EMULATE_DONE) ··· 1085 1085 ulong addr = (ax_ra ? kvmppc_get_gpr(vcpu, ax_ra) : 0) + 1086 1086 kvmppc_get_gpr(vcpu, ax_rb); 1087 1087 1088 - emulated = kvmppc_emulate_fpr_store(run, vcpu, ax_rd, 1088 + emulated = kvmppc_emulate_fpr_store(vcpu, ax_rd, 1089 1089 addr, 1090 1090 FPU_LS_SINGLE_LOW); 1091 1091 break;
+15 -15
arch/powerpc/kvm/book3s_pr.c
··· 700 700 return kvm_is_visible_gfn(vcpu->kvm, gpa >> PAGE_SHIFT); 701 701 } 702 702 703 - int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu, 703 + static int kvmppc_handle_pagefault(struct kvm_vcpu *vcpu, 704 704 ulong eaddr, int vec) 705 705 { 706 706 bool data = (vec == BOOK3S_INTERRUPT_DATA_STORAGE); ··· 795 795 /* The guest's PTE is not mapped yet. Map on the host */ 796 796 if (kvmppc_mmu_map_page(vcpu, &pte, iswrite) == -EIO) { 797 797 /* Exit KVM if mapping failed */ 798 - run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 798 + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 799 799 return RESUME_HOST; 800 800 } 801 801 if (data) ··· 808 808 vcpu->stat.mmio_exits++; 809 809 vcpu->arch.paddr_accessed = pte.raddr; 810 810 vcpu->arch.vaddr_accessed = pte.eaddr; 811 - r = kvmppc_emulate_mmio(run, vcpu); 811 + r = kvmppc_emulate_mmio(vcpu); 812 812 if ( r == RESUME_HOST_NV ) 813 813 r = RESUME_HOST; 814 814 } ··· 992 992 enum emulation_result er = EMULATE_FAIL; 993 993 994 994 if (!(kvmppc_get_msr(vcpu) & MSR_PR)) 995 - er = kvmppc_emulate_instruction(vcpu->run, vcpu); 995 + er = kvmppc_emulate_instruction(vcpu); 996 996 997 997 if ((er != EMULATE_DONE) && (er != EMULATE_AGAIN)) { 998 998 /* Couldn't emulate, trigger interrupt in guest */ ··· 1089 1089 } 1090 1090 } 1091 1091 1092 - static int kvmppc_exit_pr_progint(struct kvm_run *run, struct kvm_vcpu *vcpu, 1093 - unsigned int exit_nr) 1092 + static int kvmppc_exit_pr_progint(struct kvm_vcpu *vcpu, unsigned int exit_nr) 1094 1093 { 1095 1094 enum emulation_result er; 1096 1095 ulong flags; ··· 1123 1124 } 1124 1125 1125 1126 vcpu->stat.emulated_inst_exits++; 1126 - er = kvmppc_emulate_instruction(run, vcpu); 1127 + er = kvmppc_emulate_instruction(vcpu); 1127 1128 switch (er) { 1128 1129 case EMULATE_DONE: 1129 1130 r = RESUME_GUEST_NV; ··· 1138 1139 r = RESUME_GUEST; 1139 1140 break; 1140 1141 case EMULATE_DO_MMIO: 1141 - run->exit_reason = KVM_EXIT_MMIO; 1142 + vcpu->run->exit_reason = KVM_EXIT_MMIO; 1142 1143 r = RESUME_HOST_NV; 1143 1144 break; 1144 1145 case EMULATE_EXIT_USER: ··· 1197 1198 /* only care about PTEG not found errors, but leave NX alone */ 1198 1199 if (shadow_srr1 & 0x40000000) { 1199 1200 int idx = srcu_read_lock(&vcpu->kvm->srcu); 1200 - r = kvmppc_handle_pagefault(run, vcpu, kvmppc_get_pc(vcpu), exit_nr); 1201 + r = kvmppc_handle_pagefault(vcpu, kvmppc_get_pc(vcpu), exit_nr); 1201 1202 srcu_read_unlock(&vcpu->kvm->srcu, idx); 1202 1203 vcpu->stat.sp_instruc++; 1203 1204 } else if (vcpu->arch.mmu.is_dcbz32(vcpu) && ··· 1247 1248 */ 1248 1249 if (fault_dsisr & (DSISR_NOHPTE | DSISR_PROTFAULT)) { 1249 1250 int idx = srcu_read_lock(&vcpu->kvm->srcu); 1250 - r = kvmppc_handle_pagefault(run, vcpu, dar, exit_nr); 1251 + r = kvmppc_handle_pagefault(vcpu, dar, exit_nr); 1251 1252 srcu_read_unlock(&vcpu->kvm->srcu, idx); 1252 1253 } else { 1253 1254 kvmppc_core_queue_data_storage(vcpu, dar, fault_dsisr); ··· 1291 1292 break; 1292 1293 case BOOK3S_INTERRUPT_PROGRAM: 1293 1294 case BOOK3S_INTERRUPT_H_EMUL_ASSIST: 1294 - r = kvmppc_exit_pr_progint(run, vcpu, exit_nr); 1295 + r = kvmppc_exit_pr_progint(vcpu, exit_nr); 1295 1296 break; 1296 1297 case BOOK3S_INTERRUPT_SYSCALL: 1297 1298 { ··· 1369 1370 emul = kvmppc_get_last_inst(vcpu, INST_GENERIC, 1370 1371 &last_inst); 1371 1372 if (emul == EMULATE_DONE) 1372 - r = kvmppc_exit_pr_progint(run, vcpu, exit_nr); 1373 + r = kvmppc_exit_pr_progint(vcpu, exit_nr); 1373 1374 else 1374 1375 r = RESUME_GUEST; 1375 1376 ··· 1824 1825 vfree(vcpu_book3s); 1825 1826 } 1826 1827 1827 - static int kvmppc_vcpu_run_pr(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) 1828 + static int kvmppc_vcpu_run_pr(struct kvm_vcpu *vcpu) 1828 1829 { 1830 + struct kvm_run *run = vcpu->run; 1829 1831 int ret; 1830 1832 #ifdef CONFIG_ALTIVEC 1831 1833 unsigned long uninitialized_var(vrsave); ··· 1834 1834 1835 1835 /* Check if we can run the vcpu at all */ 1836 1836 if (!vcpu->arch.sane) { 1837 - kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 1837 + run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 1838 1838 ret = -EINVAL; 1839 1839 goto out; 1840 1840 } ··· 1861 1861 1862 1862 kvmppc_fix_ee_before_entry(); 1863 1863 1864 - ret = __kvmppc_vcpu_run(kvm_run, vcpu); 1864 + ret = __kvmppc_vcpu_run(run, vcpu); 1865 1865 1866 1866 kvmppc_clear_debug(vcpu); 1867 1867
+19 -17
arch/powerpc/kvm/booke.c
··· 729 729 return r; 730 730 } 731 731 732 - int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) 732 + int kvmppc_vcpu_run(struct kvm_vcpu *vcpu) 733 733 { 734 + struct kvm_run *run = vcpu->run; 734 735 int ret, s; 735 736 struct debug_reg debug; 736 737 737 738 if (!vcpu->arch.sane) { 738 - kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 739 + run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 739 740 return -EINVAL; 740 741 } 741 742 ··· 778 777 vcpu->arch.pgdir = vcpu->kvm->mm->pgd; 779 778 kvmppc_fix_ee_before_entry(); 780 779 781 - ret = __kvmppc_vcpu_run(kvm_run, vcpu); 780 + ret = __kvmppc_vcpu_run(run, vcpu); 782 781 783 782 /* No need for guest_exit. It's done in handle_exit. 784 783 We also get here with interrupts enabled. */ ··· 800 799 return ret; 801 800 } 802 801 803 - static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) 802 + static int emulation_exit(struct kvm_vcpu *vcpu) 804 803 { 805 804 enum emulation_result er; 806 805 807 - er = kvmppc_emulate_instruction(run, vcpu); 806 + er = kvmppc_emulate_instruction(vcpu); 808 807 switch (er) { 809 808 case EMULATE_DONE: 810 809 /* don't overwrite subtypes, just account kvm_stats */ ··· 821 820 __func__, vcpu->arch.regs.nip, vcpu->arch.last_inst); 822 821 /* For debugging, encode the failing instruction and 823 822 * report it to userspace. */ 824 - run->hw.hardware_exit_reason = ~0ULL << 32; 825 - run->hw.hardware_exit_reason |= vcpu->arch.last_inst; 823 + vcpu->run->hw.hardware_exit_reason = ~0ULL << 32; 824 + vcpu->run->hw.hardware_exit_reason |= vcpu->arch.last_inst; 826 825 kvmppc_core_queue_program(vcpu, ESR_PIL); 827 826 return RESUME_HOST; 828 827 ··· 834 833 } 835 834 } 836 835 837 - static int kvmppc_handle_debug(struct kvm_run *run, struct kvm_vcpu *vcpu) 836 + static int kvmppc_handle_debug(struct kvm_vcpu *vcpu) 838 837 { 838 + struct kvm_run *run = vcpu->run; 839 839 struct debug_reg *dbg_reg = &(vcpu->arch.dbg_reg); 840 840 u32 dbsr = vcpu->arch.dbsr; 841 841 ··· 955 953 } 956 954 } 957 955 958 - static int kvmppc_resume_inst_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 956 + static int kvmppc_resume_inst_load(struct kvm_vcpu *vcpu, 959 957 enum emulation_result emulated, u32 last_inst) 960 958 { 961 959 switch (emulated) { ··· 967 965 __func__, vcpu->arch.regs.nip); 968 966 /* For debugging, encode the failing instruction and 969 967 * report it to userspace. */ 970 - run->hw.hardware_exit_reason = ~0ULL << 32; 971 - run->hw.hardware_exit_reason |= last_inst; 968 + vcpu->run->hw.hardware_exit_reason = ~0ULL << 32; 969 + vcpu->run->hw.hardware_exit_reason |= last_inst; 972 970 kvmppc_core_queue_program(vcpu, ESR_PIL); 973 971 return RESUME_HOST; 974 972 ··· 1025 1023 run->ready_for_interrupt_injection = 1; 1026 1024 1027 1025 if (emulated != EMULATE_DONE) { 1028 - r = kvmppc_resume_inst_load(run, vcpu, emulated, last_inst); 1026 + r = kvmppc_resume_inst_load(vcpu, emulated, last_inst); 1029 1027 goto out; 1030 1028 } 1031 1029 ··· 1085 1083 break; 1086 1084 1087 1085 case BOOKE_INTERRUPT_HV_PRIV: 1088 - r = emulation_exit(run, vcpu); 1086 + r = emulation_exit(vcpu); 1089 1087 break; 1090 1088 1091 1089 case BOOKE_INTERRUPT_PROGRAM: ··· 1095 1093 * We are here because of an SW breakpoint instr, 1096 1094 * so lets return to host to handle. 1097 1095 */ 1098 - r = kvmppc_handle_debug(run, vcpu); 1096 + r = kvmppc_handle_debug(vcpu); 1099 1097 run->exit_reason = KVM_EXIT_DEBUG; 1100 1098 kvmppc_account_exit(vcpu, DEBUG_EXITS); 1101 1099 break; ··· 1116 1114 break; 1117 1115 } 1118 1116 1119 - r = emulation_exit(run, vcpu); 1117 + r = emulation_exit(vcpu); 1120 1118 break; 1121 1119 1122 1120 case BOOKE_INTERRUPT_FP_UNAVAIL: ··· 1283 1281 * actually RAM. */ 1284 1282 vcpu->arch.paddr_accessed = gpaddr; 1285 1283 vcpu->arch.vaddr_accessed = eaddr; 1286 - r = kvmppc_emulate_mmio(run, vcpu); 1284 + r = kvmppc_emulate_mmio(vcpu); 1287 1285 kvmppc_account_exit(vcpu, MMIO_EXITS); 1288 1286 } 1289 1287 ··· 1334 1332 } 1335 1333 1336 1334 case BOOKE_INTERRUPT_DEBUG: { 1337 - r = kvmppc_handle_debug(run, vcpu); 1335 + r = kvmppc_handle_debug(vcpu); 1338 1336 if (r == RESUME_HOST) 1339 1337 run->exit_reason = KVM_EXIT_DEBUG; 1340 1338 kvmppc_account_exit(vcpu, DEBUG_EXITS);
+2 -6
arch/powerpc/kvm/booke.h
··· 70 70 void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits); 71 71 void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits); 72 72 73 - int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, 73 + int kvmppc_booke_emulate_op(struct kvm_vcpu *vcpu, 74 74 unsigned int inst, int *advance); 75 75 int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val); 76 76 int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val); ··· 94 94 95 95 void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type); 96 96 97 - extern int kvmppc_core_emulate_op_e500(struct kvm_run *run, 98 - struct kvm_vcpu *vcpu, 97 + extern int kvmppc_core_emulate_op_e500(struct kvm_vcpu *vcpu, 99 98 unsigned int inst, int *advance); 100 99 extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn, 101 100 ulong spr_val); 102 101 extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn, 103 102 ulong *spr_val); 104 - extern int kvmppc_core_emulate_op_e500(struct kvm_run *run, 105 - struct kvm_vcpu *vcpu, 106 - unsigned int inst, int *advance); 107 103 extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn, 108 104 ulong spr_val); 109 105 extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
+1 -1
arch/powerpc/kvm/booke_emulate.c
··· 39 39 kvmppc_set_msr(vcpu, vcpu->arch.csrr1); 40 40 } 41 41 42 - int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, 42 + int kvmppc_booke_emulate_op(struct kvm_vcpu *vcpu, 43 43 unsigned int inst, int *advance) 44 44 { 45 45 int emulated = EMULATE_DONE;
+7 -8
arch/powerpc/kvm/e500_emulate.c
··· 83 83 } 84 84 #endif 85 85 86 - static int kvmppc_e500_emul_ehpriv(struct kvm_run *run, struct kvm_vcpu *vcpu, 86 + static int kvmppc_e500_emul_ehpriv(struct kvm_vcpu *vcpu, 87 87 unsigned int inst, int *advance) 88 88 { 89 89 int emulated = EMULATE_DONE; 90 90 91 91 switch (get_oc(inst)) { 92 92 case EHPRIV_OC_DEBUG: 93 - run->exit_reason = KVM_EXIT_DEBUG; 94 - run->debug.arch.address = vcpu->arch.regs.nip; 95 - run->debug.arch.status = 0; 93 + vcpu->run->exit_reason = KVM_EXIT_DEBUG; 94 + vcpu->run->debug.arch.address = vcpu->arch.regs.nip; 95 + vcpu->run->debug.arch.status = 0; 96 96 kvmppc_account_exit(vcpu, DEBUG_EXITS); 97 97 emulated = EMULATE_EXIT_USER; 98 98 *advance = 0; ··· 125 125 return EMULATE_FAIL; 126 126 } 127 127 128 - int kvmppc_core_emulate_op_e500(struct kvm_run *run, struct kvm_vcpu *vcpu, 128 + int kvmppc_core_emulate_op_e500(struct kvm_vcpu *vcpu, 129 129 unsigned int inst, int *advance) 130 130 { 131 131 int emulated = EMULATE_DONE; ··· 182 182 break; 183 183 184 184 case XOP_EHPRIV: 185 - emulated = kvmppc_e500_emul_ehpriv(run, vcpu, inst, 186 - advance); 185 + emulated = kvmppc_e500_emul_ehpriv(vcpu, inst, advance); 187 186 break; 188 187 189 188 default: ··· 196 197 } 197 198 198 199 if (emulated == EMULATE_FAIL) 199 - emulated = kvmppc_booke_emulate_op(run, vcpu, inst, advance); 200 + emulated = kvmppc_booke_emulate_op(vcpu, inst, advance); 200 201 201 202 return emulated; 202 203 }
+5 -5
arch/powerpc/kvm/emulate.c
··· 191 191 192 192 /* XXX Should probably auto-generate instruction decoding for a particular core 193 193 * from opcode tables in the future. */ 194 - int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) 194 + int kvmppc_emulate_instruction(struct kvm_vcpu *vcpu) 195 195 { 196 196 u32 inst; 197 197 int rs, rt, sprn; ··· 270 270 * these are illegal instructions. 271 271 */ 272 272 if (inst == KVMPPC_INST_SW_BREAKPOINT) { 273 - run->exit_reason = KVM_EXIT_DEBUG; 274 - run->debug.arch.status = 0; 275 - run->debug.arch.address = kvmppc_get_pc(vcpu); 273 + vcpu->run->exit_reason = KVM_EXIT_DEBUG; 274 + vcpu->run->debug.arch.status = 0; 275 + vcpu->run->debug.arch.address = kvmppc_get_pc(vcpu); 276 276 emulated = EMULATE_EXIT_USER; 277 277 advance = 0; 278 278 } else ··· 285 285 } 286 286 287 287 if (emulated == EMULATE_FAIL) { 288 - emulated = vcpu->kvm->arch.kvm_ops->emulate_op(run, vcpu, inst, 288 + emulated = vcpu->kvm->arch.kvm_ops->emulate_op(vcpu, inst, 289 289 &advance); 290 290 if (emulated == EMULATE_AGAIN) { 291 291 advance = 0;
+15 -17
arch/powerpc/kvm/emulate_loadstore.c
··· 71 71 */ 72 72 int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) 73 73 { 74 - struct kvm_run *run = vcpu->run; 75 74 u32 inst; 76 75 enum emulation_result emulated = EMULATE_FAIL; 77 76 int advance = 1; ··· 103 104 int instr_byte_swap = op.type & BYTEREV; 104 105 105 106 if (op.type & SIGNEXT) 106 - emulated = kvmppc_handle_loads(run, vcpu, 107 + emulated = kvmppc_handle_loads(vcpu, 107 108 op.reg, size, !instr_byte_swap); 108 109 else 109 - emulated = kvmppc_handle_load(run, vcpu, 110 + emulated = kvmppc_handle_load(vcpu, 110 111 op.reg, size, !instr_byte_swap); 111 112 112 113 if ((op.type & UPDATE) && (emulated != EMULATE_FAIL)) ··· 123 124 vcpu->arch.mmio_sp64_extend = 1; 124 125 125 126 if (op.type & SIGNEXT) 126 - emulated = kvmppc_handle_loads(run, vcpu, 127 + emulated = kvmppc_handle_loads(vcpu, 127 128 KVM_MMIO_REG_FPR|op.reg, size, 1); 128 129 else 129 - emulated = kvmppc_handle_load(run, vcpu, 130 + emulated = kvmppc_handle_load(vcpu, 130 131 KVM_MMIO_REG_FPR|op.reg, size, 1); 131 132 132 133 if ((op.type & UPDATE) && (emulated != EMULATE_FAIL)) ··· 163 164 164 165 if (size == 16) { 165 166 vcpu->arch.mmio_vmx_copy_nums = 2; 166 - emulated = kvmppc_handle_vmx_load(run, 167 - vcpu, KVM_MMIO_REG_VMX|op.reg, 167 + emulated = kvmppc_handle_vmx_load(vcpu, 168 + KVM_MMIO_REG_VMX|op.reg, 168 169 8, 1); 169 170 } else { 170 171 vcpu->arch.mmio_vmx_copy_nums = 1; 171 - emulated = kvmppc_handle_vmx_load(run, vcpu, 172 + emulated = kvmppc_handle_vmx_load(vcpu, 172 173 KVM_MMIO_REG_VMX|op.reg, 173 174 size, 1); 174 175 } ··· 216 217 io_size_each = op.element_size; 217 218 } 218 219 219 - emulated = kvmppc_handle_vsx_load(run, vcpu, 220 + emulated = kvmppc_handle_vsx_load(vcpu, 220 221 KVM_MMIO_REG_VSX|op.reg, io_size_each, 221 222 1, op.type & SIGNEXT); 222 223 break; ··· 226 227 /* if need byte reverse, op.val has been reversed by 227 228 * analyse_instr(). 228 229 */ 229 - emulated = kvmppc_handle_store(run, vcpu, op.val, 230 - size, 1); 230 + emulated = kvmppc_handle_store(vcpu, op.val, size, 1); 231 231 232 232 if ((op.type & UPDATE) && (emulated != EMULATE_FAIL)) 233 233 kvmppc_set_gpr(vcpu, op.update_reg, op.ea); ··· 248 250 if (op.type & FPCONV) 249 251 vcpu->arch.mmio_sp64_extend = 1; 250 252 251 - emulated = kvmppc_handle_store(run, vcpu, 253 + emulated = kvmppc_handle_store(vcpu, 252 254 VCPU_FPR(vcpu, op.reg), size, 1); 253 255 254 256 if ((op.type & UPDATE) && (emulated != EMULATE_FAIL)) ··· 288 290 289 291 if (size == 16) { 290 292 vcpu->arch.mmio_vmx_copy_nums = 2; 291 - emulated = kvmppc_handle_vmx_store(run, 292 - vcpu, op.reg, 8, 1); 293 + emulated = kvmppc_handle_vmx_store(vcpu, 294 + op.reg, 8, 1); 293 295 } else { 294 296 vcpu->arch.mmio_vmx_copy_nums = 1; 295 - emulated = kvmppc_handle_vmx_store(run, 296 - vcpu, op.reg, size, 1); 297 + emulated = kvmppc_handle_vmx_store(vcpu, 298 + op.reg, size, 1); 297 299 } 298 300 299 301 break; ··· 336 338 io_size_each = op.element_size; 337 339 } 338 340 339 - emulated = kvmppc_handle_vsx_store(run, vcpu, 341 + emulated = kvmppc_handle_vsx_store(vcpu, 340 342 op.reg, io_size_each, 1); 341 343 break; 342 344 }
+37 -35
arch/powerpc/kvm/powerpc.c
··· 279 279 } 280 280 EXPORT_SYMBOL_GPL(kvmppc_sanity_check); 281 281 282 - int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu) 282 + int kvmppc_emulate_mmio(struct kvm_vcpu *vcpu) 283 283 { 284 284 enum emulation_result er; 285 285 int r; ··· 295 295 r = RESUME_GUEST; 296 296 break; 297 297 case EMULATE_DO_MMIO: 298 - run->exit_reason = KVM_EXIT_MMIO; 298 + vcpu->run->exit_reason = KVM_EXIT_MMIO; 299 299 /* We must reload nonvolatiles because "update" load/store 300 300 * instructions modify register state. */ 301 301 /* Future optimization: only reload non-volatiles if they were ··· 1107 1107 #define dp_to_sp(x) (x) 1108 1108 #endif /* CONFIG_PPC_FPU */ 1109 1109 1110 - static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu, 1111 - struct kvm_run *run) 1110 + static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu) 1112 1111 { 1112 + struct kvm_run *run = vcpu->run; 1113 1113 u64 uninitialized_var(gpr); 1114 1114 1115 1115 if (run->mmio.len > sizeof(gpr)) { ··· 1219 1219 } 1220 1220 } 1221 1221 1222 - static int __kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 1222 + static int __kvmppc_handle_load(struct kvm_vcpu *vcpu, 1223 1223 unsigned int rt, unsigned int bytes, 1224 1224 int is_default_endian, int sign_extend) 1225 1225 { 1226 + struct kvm_run *run = vcpu->run; 1226 1227 int idx, ret; 1227 1228 bool host_swabbed; 1228 1229 ··· 1257 1256 srcu_read_unlock(&vcpu->kvm->srcu, idx); 1258 1257 1259 1258 if (!ret) { 1260 - kvmppc_complete_mmio_load(vcpu, run); 1259 + kvmppc_complete_mmio_load(vcpu); 1261 1260 vcpu->mmio_needed = 0; 1262 1261 return EMULATE_DONE; 1263 1262 } ··· 1265 1264 return EMULATE_DO_MMIO; 1266 1265 } 1267 1266 1268 - int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 1267 + int kvmppc_handle_load(struct kvm_vcpu *vcpu, 1269 1268 unsigned int rt, unsigned int bytes, 1270 1269 int is_default_endian) 1271 1270 { 1272 - return __kvmppc_handle_load(run, vcpu, rt, bytes, is_default_endian, 0); 1271 + return __kvmppc_handle_load(vcpu, rt, bytes, is_default_endian, 0); 1273 1272 } 1274 1273 EXPORT_SYMBOL_GPL(kvmppc_handle_load); 1275 1274 1276 1275 /* Same as above, but sign extends */ 1277 - int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu, 1276 + int kvmppc_handle_loads(struct kvm_vcpu *vcpu, 1278 1277 unsigned int rt, unsigned int bytes, 1279 1278 int is_default_endian) 1280 1279 { 1281 - return __kvmppc_handle_load(run, vcpu, rt, bytes, is_default_endian, 1); 1280 + return __kvmppc_handle_load(vcpu, rt, bytes, is_default_endian, 1); 1282 1281 } 1283 1282 1284 1283 #ifdef CONFIG_VSX 1285 - int kvmppc_handle_vsx_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 1284 + int kvmppc_handle_vsx_load(struct kvm_vcpu *vcpu, 1286 1285 unsigned int rt, unsigned int bytes, 1287 1286 int is_default_endian, int mmio_sign_extend) 1288 1287 { ··· 1293 1292 return EMULATE_FAIL; 1294 1293 1295 1294 while (vcpu->arch.mmio_vsx_copy_nums) { 1296 - emulated = __kvmppc_handle_load(run, vcpu, rt, bytes, 1295 + emulated = __kvmppc_handle_load(vcpu, rt, bytes, 1297 1296 is_default_endian, mmio_sign_extend); 1298 1297 1299 1298 if (emulated != EMULATE_DONE) 1300 1299 break; 1301 1300 1302 - vcpu->arch.paddr_accessed += run->mmio.len; 1301 + vcpu->arch.paddr_accessed += vcpu->run->mmio.len; 1303 1302 1304 1303 vcpu->arch.mmio_vsx_copy_nums--; 1305 1304 vcpu->arch.mmio_vsx_offset++; ··· 1308 1307 } 1309 1308 #endif /* CONFIG_VSX */ 1310 1309 1311 - int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu, 1310 + int kvmppc_handle_store(struct kvm_vcpu *vcpu, 1312 1311 u64 val, unsigned int bytes, int is_default_endian) 1313 1312 { 1313 + struct kvm_run *run = vcpu->run; 1314 1314 void *data = run->mmio.data; 1315 1315 int idx, ret; 1316 1316 bool host_swabbed; ··· 1425 1423 return result; 1426 1424 } 1427 1425 1428 - int kvmppc_handle_vsx_store(struct kvm_run *run, struct kvm_vcpu *vcpu, 1426 + int kvmppc_handle_vsx_store(struct kvm_vcpu *vcpu, 1429 1427 int rs, unsigned int bytes, int is_default_endian) 1430 1428 { 1431 1429 u64 val; ··· 1441 1439 if (kvmppc_get_vsr_data(vcpu, rs, &val) == -1) 1442 1440 return EMULATE_FAIL; 1443 1441 1444 - emulated = kvmppc_handle_store(run, vcpu, 1442 + emulated = kvmppc_handle_store(vcpu, 1445 1443 val, bytes, is_default_endian); 1446 1444 1447 1445 if (emulated != EMULATE_DONE) 1448 1446 break; 1449 1447 1450 - vcpu->arch.paddr_accessed += run->mmio.len; 1448 + vcpu->arch.paddr_accessed += vcpu->run->mmio.len; 1451 1449 1452 1450 vcpu->arch.mmio_vsx_copy_nums--; 1453 1451 vcpu->arch.mmio_vsx_offset++; ··· 1456 1454 return emulated; 1457 1455 } 1458 1456 1459 - static int kvmppc_emulate_mmio_vsx_loadstore(struct kvm_vcpu *vcpu, 1460 - struct kvm_run *run) 1457 + static int kvmppc_emulate_mmio_vsx_loadstore(struct kvm_vcpu *vcpu) 1461 1458 { 1459 + struct kvm_run *run = vcpu->run; 1462 1460 enum emulation_result emulated = EMULATE_FAIL; 1463 1461 int r; 1464 1462 1465 1463 vcpu->arch.paddr_accessed += run->mmio.len; 1466 1464 1467 1465 if (!vcpu->mmio_is_write) { 1468 - emulated = kvmppc_handle_vsx_load(run, vcpu, vcpu->arch.io_gpr, 1466 + emulated = kvmppc_handle_vsx_load(vcpu, vcpu->arch.io_gpr, 1469 1467 run->mmio.len, 1, vcpu->arch.mmio_sign_extend); 1470 1468 } else { 1471 - emulated = kvmppc_handle_vsx_store(run, vcpu, 1469 + emulated = kvmppc_handle_vsx_store(vcpu, 1472 1470 vcpu->arch.io_gpr, run->mmio.len, 1); 1473 1471 } 1474 1472 ··· 1492 1490 #endif /* CONFIG_VSX */ 1493 1491 1494 1492 #ifdef CONFIG_ALTIVEC 1495 - int kvmppc_handle_vmx_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 1493 + int kvmppc_handle_vmx_load(struct kvm_vcpu *vcpu, 1496 1494 unsigned int rt, unsigned int bytes, int is_default_endian) 1497 1495 { 1498 1496 enum emulation_result emulated = EMULATE_DONE; ··· 1501 1499 return EMULATE_FAIL; 1502 1500 1503 1501 while (vcpu->arch.mmio_vmx_copy_nums) { 1504 - emulated = __kvmppc_handle_load(run, vcpu, rt, bytes, 1502 + emulated = __kvmppc_handle_load(vcpu, rt, bytes, 1505 1503 is_default_endian, 0); 1506 1504 1507 1505 if (emulated != EMULATE_DONE) 1508 1506 break; 1509 1507 1510 - vcpu->arch.paddr_accessed += run->mmio.len; 1508 + vcpu->arch.paddr_accessed += vcpu->run->mmio.len; 1511 1509 vcpu->arch.mmio_vmx_copy_nums--; 1512 1510 vcpu->arch.mmio_vmx_offset++; 1513 1511 } ··· 1587 1585 return result; 1588 1586 } 1589 1587 1590 - int kvmppc_handle_vmx_store(struct kvm_run *run, struct kvm_vcpu *vcpu, 1588 + int kvmppc_handle_vmx_store(struct kvm_vcpu *vcpu, 1591 1589 unsigned int rs, unsigned int bytes, int is_default_endian) 1592 1590 { 1593 1591 u64 val = 0; ··· 1622 1620 return EMULATE_FAIL; 1623 1621 } 1624 1622 1625 - emulated = kvmppc_handle_store(run, vcpu, val, bytes, 1623 + emulated = kvmppc_handle_store(vcpu, val, bytes, 1626 1624 is_default_endian); 1627 1625 if (emulated != EMULATE_DONE) 1628 1626 break; 1629 1627 1630 - vcpu->arch.paddr_accessed += run->mmio.len; 1628 + vcpu->arch.paddr_accessed += vcpu->run->mmio.len; 1631 1629 vcpu->arch.mmio_vmx_copy_nums--; 1632 1630 vcpu->arch.mmio_vmx_offset++; 1633 1631 } ··· 1635 1633 return emulated; 1636 1634 } 1637 1635 1638 - static int kvmppc_emulate_mmio_vmx_loadstore(struct kvm_vcpu *vcpu, 1639 - struct kvm_run *run) 1636 + static int kvmppc_emulate_mmio_vmx_loadstore(struct kvm_vcpu *vcpu) 1640 1637 { 1638 + struct kvm_run *run = vcpu->run; 1641 1639 enum emulation_result emulated = EMULATE_FAIL; 1642 1640 int r; 1643 1641 1644 1642 vcpu->arch.paddr_accessed += run->mmio.len; 1645 1643 1646 1644 if (!vcpu->mmio_is_write) { 1647 - emulated = kvmppc_handle_vmx_load(run, vcpu, 1645 + emulated = kvmppc_handle_vmx_load(vcpu, 1648 1646 vcpu->arch.io_gpr, run->mmio.len, 1); 1649 1647 } else { 1650 - emulated = kvmppc_handle_vmx_store(run, vcpu, 1648 + emulated = kvmppc_handle_vmx_store(vcpu, 1651 1649 vcpu->arch.io_gpr, run->mmio.len, 1); 1652 1650 } 1653 1651 ··· 1777 1775 if (vcpu->mmio_needed) { 1778 1776 vcpu->mmio_needed = 0; 1779 1777 if (!vcpu->mmio_is_write) 1780 - kvmppc_complete_mmio_load(vcpu, run); 1778 + kvmppc_complete_mmio_load(vcpu); 1781 1779 #ifdef CONFIG_VSX 1782 1780 if (vcpu->arch.mmio_vsx_copy_nums > 0) { 1783 1781 vcpu->arch.mmio_vsx_copy_nums--; ··· 1785 1783 } 1786 1784 1787 1785 if (vcpu->arch.mmio_vsx_copy_nums > 0) { 1788 - r = kvmppc_emulate_mmio_vsx_loadstore(vcpu, run); 1786 + r = kvmppc_emulate_mmio_vsx_loadstore(vcpu); 1789 1787 if (r == RESUME_HOST) { 1790 1788 vcpu->mmio_needed = 1; 1791 1789 goto out; ··· 1799 1797 } 1800 1798 1801 1799 if (vcpu->arch.mmio_vmx_copy_nums > 0) { 1802 - r = kvmppc_emulate_mmio_vmx_loadstore(vcpu, run); 1800 + r = kvmppc_emulate_mmio_vmx_loadstore(vcpu); 1803 1801 if (r == RESUME_HOST) { 1804 1802 vcpu->mmio_needed = 1; 1805 1803 goto out; ··· 1832 1830 if (run->immediate_exit) 1833 1831 r = -EINTR; 1834 1832 else 1835 - r = kvmppc_vcpu_run(run, vcpu); 1833 + r = kvmppc_vcpu_run(vcpu); 1836 1834 1837 1835 kvm_sigset_deactivate(vcpu); 1838 1836
+3 -3
arch/powerpc/kvm/trace_hv.h
··· 472 472 ); 473 473 474 474 TRACE_EVENT(kvmppc_run_vcpu_exit, 475 - TP_PROTO(struct kvm_vcpu *vcpu, struct kvm_run *run), 475 + TP_PROTO(struct kvm_vcpu *vcpu), 476 476 477 - TP_ARGS(vcpu, run), 477 + TP_ARGS(vcpu), 478 478 479 479 TP_STRUCT__entry( 480 480 __field(int, vcpu_id) ··· 484 484 485 485 TP_fast_assign( 486 486 __entry->vcpu_id = vcpu->vcpu_id; 487 - __entry->exit = run->exit_reason; 487 + __entry->exit = vcpu->run->exit_reason; 488 488 __entry->ret = vcpu->arch.ret; 489 489 ), 490 490
+1 -1
arch/s390/include/asm/kvm_host.h
··· 978 978 void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu, 979 979 struct kvm_async_pf *work); 980 980 981 - void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, 981 + bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, 982 982 struct kvm_async_pf *work); 983 983 984 984 void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
+3 -1
arch/s390/kvm/kvm-s390.c
··· 3923 3923 } 3924 3924 } 3925 3925 3926 - void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, 3926 + bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, 3927 3927 struct kvm_async_pf *work) 3928 3928 { 3929 3929 trace_kvm_s390_pfault_init(vcpu, work->arch.pfault_token); 3930 3930 __kvm_inject_pfault_token(vcpu, true, work->arch.pfault_token); 3931 + 3932 + return true; 3931 3933 } 3932 3934 3933 3935 void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
-8
arch/x86/Kconfig
··· 823 823 This option enables the PVH entry point for guest virtual machines 824 824 as specified in the x86/HVM direct boot ABI. 825 825 826 - config KVM_DEBUG_FS 827 - bool "Enable debug information for KVM Guests in debugfs" 828 - depends on KVM_GUEST && DEBUG_FS 829 - ---help--- 830 - This option enables collection of various statistics for KVM guest. 831 - Statistics are displayed in debugfs filesystem. Enabling this option 832 - may incur significant overhead. 833 - 834 826 config PARAVIRT_TIME_ACCOUNTING 835 827 bool "Paravirtual steal time accounting" 836 828 depends on PARAVIRT
+1 -2
arch/x86/include/asm/kvm_host.h
··· 1306 1306 extern u64 __read_mostly host_efer; 1307 1307 1308 1308 extern struct kvm_x86_ops kvm_x86_ops; 1309 - extern struct kmem_cache *x86_fpu_cache; 1310 1309 1311 1310 #define __KVM_HAVE_ARCH_VM_ALLOC 1312 1311 static inline struct kvm *kvm_arch_alloc_vm(void) ··· 1670 1671 void kvm_make_scan_ioapic_request_mask(struct kvm *kvm, 1671 1672 unsigned long *vcpu_bitmap); 1672 1673 1673 - void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, 1674 + bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, 1674 1675 struct kvm_async_pf *work); 1675 1676 void kvm_arch_async_page_present(struct kvm_vcpu *vcpu, 1676 1677 struct kvm_async_pf *work);
-1
arch/x86/kernel/kvm.c
··· 21 21 #include <linux/sched.h> 22 22 #include <linux/slab.h> 23 23 #include <linux/kprobes.h> 24 - #include <linux/debugfs.h> 25 24 #include <linux/nmi.h> 26 25 #include <linux/swait.h> 27 26 #include <asm/timer.h>
+18 -13
arch/x86/kvm/cpuid.c
··· 181 181 r = -E2BIG; 182 182 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) 183 183 goto out; 184 - r = -ENOMEM; 185 184 if (cpuid->nent) { 186 - cpuid_entries = 187 - vmalloc(array_size(sizeof(struct kvm_cpuid_entry), 188 - cpuid->nent)); 189 - if (!cpuid_entries) 185 + cpuid_entries = vmemdup_user(entries, 186 + array_size(sizeof(struct kvm_cpuid_entry), 187 + cpuid->nent)); 188 + if (IS_ERR(cpuid_entries)) { 189 + r = PTR_ERR(cpuid_entries); 190 190 goto out; 191 - r = -EFAULT; 192 - if (copy_from_user(cpuid_entries, entries, 193 - cpuid->nent * sizeof(struct kvm_cpuid_entry))) 194 - goto out; 191 + } 195 192 } 196 193 for (i = 0; i < cpuid->nent; i++) { 197 194 vcpu->arch.cpuid_entries[i].function = cpuid_entries[i].function; ··· 208 211 kvm_x86_ops.cpuid_update(vcpu); 209 212 r = kvm_update_cpuid(vcpu); 210 213 214 + kvfree(cpuid_entries); 211 215 out: 212 - vfree(cpuid_entries); 213 216 return r; 214 217 } 215 218 ··· 322 325 ); 323 326 324 327 kvm_cpu_cap_mask(CPUID_7_ECX, 325 - F(AVX512VBMI) | F(LA57) | 0 /*PKU*/ | 0 /*OSPKE*/ | F(RDPID) | 328 + F(AVX512VBMI) | F(LA57) | F(PKU) | 0 /*OSPKE*/ | F(RDPID) | 326 329 F(AVX512_VPOPCNTDQ) | F(UMIP) | F(AVX512_VBMI2) | F(GFNI) | 327 330 F(VAES) | F(VPCLMULQDQ) | F(AVX512_VNNI) | F(AVX512_BITALG) | 328 331 F(CLDEMOTE) | F(MOVDIRI) | F(MOVDIR64B) | 0 /*WAITPKG*/ ··· 330 333 /* Set LA57 based on hardware capability. */ 331 334 if (cpuid_ecx(7) & F(LA57)) 332 335 kvm_cpu_cap_set(X86_FEATURE_LA57); 336 + 337 + /* 338 + * PKU not yet implemented for shadow paging and requires OSPKE 339 + * to be set on the host. Clear it if that is not the case 340 + */ 341 + if (!tdp_enabled || !boot_cpu_has(X86_FEATURE_OSPKE)) 342 + kvm_cpu_cap_clear(X86_FEATURE_PKU); 333 343 334 344 kvm_cpu_cap_mask(CPUID_7_EDX, 335 345 F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) | ··· 430 426 431 427 struct kvm_cpuid_array { 432 428 struct kvm_cpuid_entry2 *entries; 433 - const int maxnent; 429 + int maxnent; 434 430 int nent; 435 431 }; 436 432 ··· 874 870 875 871 struct kvm_cpuid_array array = { 876 872 .nent = 0, 877 - .maxnent = cpuid->nent, 878 873 }; 879 874 int r, i; 880 875 ··· 889 886 cpuid->nent)); 890 887 if (!array.entries) 891 888 return -ENOMEM; 889 + 890 + array.maxnent = cpuid->nent; 892 891 893 892 for (i = 0; i < ARRAY_SIZE(funcs); i++) { 894 893 r = get_cpuid_func(&array, funcs[i], type);
+5 -5
arch/x86/kvm/debugfs.c
··· 43 43 44 44 DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n"); 45 45 46 - void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu) 46 + void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry) 47 47 { 48 - debugfs_create_file("tsc-offset", 0444, vcpu->debugfs_dentry, vcpu, 48 + debugfs_create_file("tsc-offset", 0444, debugfs_dentry, vcpu, 49 49 &vcpu_tsc_offset_fops); 50 50 51 51 if (lapic_in_kernel(vcpu)) 52 52 debugfs_create_file("lapic_timer_advance_ns", 0444, 53 - vcpu->debugfs_dentry, vcpu, 53 + debugfs_dentry, vcpu, 54 54 &vcpu_timer_advance_ns_fops); 55 55 56 56 if (kvm_has_tsc_control) { 57 57 debugfs_create_file("tsc-scaling-ratio", 0444, 58 - vcpu->debugfs_dentry, vcpu, 58 + debugfs_dentry, vcpu, 59 59 &vcpu_tsc_scaling_fops); 60 60 debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444, 61 - vcpu->debugfs_dentry, vcpu, 61 + debugfs_dentry, vcpu, 62 62 &vcpu_tsc_scaling_frac_fops); 63 63 } 64 64 }
+6 -2
arch/x86/kvm/emulate.c
··· 4800 4800 GP(ModRM | DstReg | SrcMem | Mov | Sse, &pfx_0f_10_0f_11), 4801 4801 GP(ModRM | DstMem | SrcReg | Mov | Sse, &pfx_0f_10_0f_11), 4802 4802 N, N, N, N, N, N, 4803 - D(ImplicitOps | ModRM | SrcMem | NoAccess), 4804 - N, N, N, N, N, N, D(ImplicitOps | ModRM | SrcMem | NoAccess), 4803 + D(ImplicitOps | ModRM | SrcMem | NoAccess), /* 4 * prefetch + 4 * reserved NOP */ 4804 + D(ImplicitOps | ModRM | SrcMem | NoAccess), N, N, 4805 + D(ImplicitOps | ModRM | SrcMem | NoAccess), /* 8 * reserved NOP */ 4806 + D(ImplicitOps | ModRM | SrcMem | NoAccess), /* 8 * reserved NOP */ 4807 + D(ImplicitOps | ModRM | SrcMem | NoAccess), /* 8 * reserved NOP */ 4808 + D(ImplicitOps | ModRM | SrcMem | NoAccess), /* NOP + 7 * reserved NOP */ 4805 4809 /* 0x20 - 0x2F */ 4806 4810 DIP(ModRM | DstMem | Priv | Op3264 | NoMod, cr_read, check_cr_read), 4807 4811 DIP(ModRM | DstMem | Priv | Op3264 | NoMod, dr_read, check_dr_read),
-1
arch/x86/kvm/i8254.c
··· 462 462 if (channel == 3) { 463 463 /* Read-Back Command. */ 464 464 for (channel = 0; channel < 3; channel++) { 465 - s = &pit_state->channels[channel]; 466 465 if (val & (2 << channel)) { 467 466 if (!(val & 0x20)) 468 467 pit_latch_count(pit, channel);
+1 -1
arch/x86/kvm/svm/nested.c
··· 258 258 /* Only a few fields of int_ctl are written by the processor. */ 259 259 mask = V_IRQ_MASK | V_TPR_MASK; 260 260 if (!(svm->nested.ctl.int_ctl & V_INTR_MASKING_MASK) && 261 - is_intercept(svm, SVM_EXIT_VINTR)) { 261 + is_intercept(svm, INTERCEPT_VINTR)) { 262 262 /* 263 263 * In order to request an interrupt window, L0 is usurping 264 264 * svm->vmcb->control.int_ctl and possibly setting V_IRQ
+3 -1
arch/x86/kvm/svm/svm.c
··· 1378 1378 /* Drop int_ctl fields related to VINTR injection. */ 1379 1379 svm->vmcb->control.int_ctl &= mask; 1380 1380 if (is_guest_mode(&svm->vcpu)) { 1381 + svm->nested.hsave->control.int_ctl &= mask; 1382 + 1381 1383 WARN_ON((svm->vmcb->control.int_ctl & V_TPR_MASK) != 1382 1384 (svm->nested.ctl.int_ctl & V_TPR_MASK)); 1383 1385 svm->vmcb->control.int_ctl |= svm->nested.ctl.int_ctl & ~mask; ··· 2001 1999 */ 2002 2000 if (vgif_enabled(svm)) 2003 2001 clr_intercept(svm, INTERCEPT_STGI); 2004 - if (is_intercept(svm, SVM_EXIT_VINTR)) 2002 + if (is_intercept(svm, INTERCEPT_VINTR)) 2005 2003 svm_clear_vintr(svm); 2006 2004 2007 2005 enable_gif(svm);
+44 -38
arch/x86/kvm/vmx/nested.c
··· 4624 4624 } 4625 4625 } 4626 4626 4627 - static int nested_vmx_get_vmptr(struct kvm_vcpu *vcpu, gpa_t *vmpointer) 4627 + static int nested_vmx_get_vmptr(struct kvm_vcpu *vcpu, gpa_t *vmpointer, 4628 + int *ret) 4628 4629 { 4629 4630 gva_t gva; 4630 4631 struct x86_exception e; 4632 + int r; 4631 4633 4632 4634 if (get_vmx_mem_address(vcpu, vmx_get_exit_qual(vcpu), 4633 4635 vmcs_read32(VMX_INSTRUCTION_INFO), false, 4634 - sizeof(*vmpointer), &gva)) 4635 - return 1; 4636 + sizeof(*vmpointer), &gva)) { 4637 + *ret = 1; 4638 + return -EINVAL; 4639 + } 4636 4640 4637 - if (kvm_read_guest_virt(vcpu, gva, vmpointer, sizeof(*vmpointer), &e)) { 4638 - kvm_inject_emulated_page_fault(vcpu, &e); 4639 - return 1; 4641 + r = kvm_read_guest_virt(vcpu, gva, vmpointer, sizeof(*vmpointer), &e); 4642 + if (r != X86EMUL_CONTINUE) { 4643 + *ret = vmx_handle_memory_failure(vcpu, r, &e); 4644 + return -EINVAL; 4640 4645 } 4641 4646 4642 4647 return 0; ··· 4769 4764 return 1; 4770 4765 } 4771 4766 4772 - if (nested_vmx_get_vmptr(vcpu, &vmptr)) 4773 - return 1; 4767 + if (nested_vmx_get_vmptr(vcpu, &vmptr, &ret)) 4768 + return ret; 4774 4769 4775 4770 /* 4776 4771 * SDM 3: 24.11.5 ··· 4843 4838 u32 zero = 0; 4844 4839 gpa_t vmptr; 4845 4840 u64 evmcs_gpa; 4841 + int r; 4846 4842 4847 4843 if (!nested_vmx_check_permission(vcpu)) 4848 4844 return 1; 4849 4845 4850 - if (nested_vmx_get_vmptr(vcpu, &vmptr)) 4851 - return 1; 4846 + if (nested_vmx_get_vmptr(vcpu, &vmptr, &r)) 4847 + return r; 4852 4848 4853 4849 if (!page_address_valid(vcpu, vmptr)) 4854 4850 return nested_vmx_failValid(vcpu, ··· 4908 4902 u64 value; 4909 4903 gva_t gva = 0; 4910 4904 short offset; 4911 - int len; 4905 + int len, r; 4912 4906 4913 4907 if (!nested_vmx_check_permission(vcpu)) 4914 4908 return 1; ··· 4949 4943 instr_info, true, len, &gva)) 4950 4944 return 1; 4951 4945 /* _system ok, nested_vmx_check_permission has verified cpl=0 */ 4952 - if (kvm_write_guest_virt_system(vcpu, gva, &value, len, &e)) { 4953 - kvm_inject_emulated_page_fault(vcpu, &e); 4954 - return 1; 4955 - } 4946 + r = kvm_write_guest_virt_system(vcpu, gva, &value, len, &e); 4947 + if (r != X86EMUL_CONTINUE) 4948 + return vmx_handle_memory_failure(vcpu, r, &e); 4956 4949 } 4957 4950 4958 4951 return nested_vmx_succeed(vcpu); ··· 4992 4987 unsigned long field; 4993 4988 short offset; 4994 4989 gva_t gva; 4995 - int len; 4990 + int len, r; 4996 4991 4997 4992 /* 4998 4993 * The value to write might be 32 or 64 bits, depending on L1's long ··· 5022 5017 if (get_vmx_mem_address(vcpu, exit_qualification, 5023 5018 instr_info, false, len, &gva)) 5024 5019 return 1; 5025 - if (kvm_read_guest_virt(vcpu, gva, &value, len, &e)) { 5026 - kvm_inject_emulated_page_fault(vcpu, &e); 5027 - return 1; 5028 - } 5020 + r = kvm_read_guest_virt(vcpu, gva, &value, len, &e); 5021 + if (r != X86EMUL_CONTINUE) 5022 + return vmx_handle_memory_failure(vcpu, r, &e); 5029 5023 } 5030 5024 5031 5025 field = kvm_register_readl(vcpu, (((instr_info) >> 28) & 0xf)); ··· 5107 5103 { 5108 5104 struct vcpu_vmx *vmx = to_vmx(vcpu); 5109 5105 gpa_t vmptr; 5106 + int r; 5110 5107 5111 5108 if (!nested_vmx_check_permission(vcpu)) 5112 5109 return 1; 5113 5110 5114 - if (nested_vmx_get_vmptr(vcpu, &vmptr)) 5115 - return 1; 5111 + if (nested_vmx_get_vmptr(vcpu, &vmptr, &r)) 5112 + return r; 5116 5113 5117 5114 if (!page_address_valid(vcpu, vmptr)) 5118 5115 return nested_vmx_failValid(vcpu, ··· 5175 5170 gpa_t current_vmptr = to_vmx(vcpu)->nested.current_vmptr; 5176 5171 struct x86_exception e; 5177 5172 gva_t gva; 5173 + int r; 5178 5174 5179 5175 if (!nested_vmx_check_permission(vcpu)) 5180 5176 return 1; ··· 5187 5181 true, sizeof(gpa_t), &gva)) 5188 5182 return 1; 5189 5183 /* *_system ok, nested_vmx_check_permission has verified cpl=0 */ 5190 - if (kvm_write_guest_virt_system(vcpu, gva, (void *)&current_vmptr, 5191 - sizeof(gpa_t), &e)) { 5192 - kvm_inject_emulated_page_fault(vcpu, &e); 5193 - return 1; 5194 - } 5184 + r = kvm_write_guest_virt_system(vcpu, gva, (void *)&current_vmptr, 5185 + sizeof(gpa_t), &e); 5186 + if (r != X86EMUL_CONTINUE) 5187 + return vmx_handle_memory_failure(vcpu, r, &e); 5188 + 5195 5189 return nested_vmx_succeed(vcpu); 5196 5190 } 5197 5191 ··· 5215 5209 struct { 5216 5210 u64 eptp, gpa; 5217 5211 } operand; 5218 - int i; 5212 + int i, r; 5219 5213 5220 5214 if (!(vmx->nested.msrs.secondary_ctls_high & 5221 5215 SECONDARY_EXEC_ENABLE_EPT) || ··· 5242 5236 if (get_vmx_mem_address(vcpu, vmx_get_exit_qual(vcpu), 5243 5237 vmx_instruction_info, false, sizeof(operand), &gva)) 5244 5238 return 1; 5245 - if (kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e)) { 5246 - kvm_inject_emulated_page_fault(vcpu, &e); 5247 - return 1; 5248 - } 5239 + r = kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e); 5240 + if (r != X86EMUL_CONTINUE) 5241 + return vmx_handle_memory_failure(vcpu, r, &e); 5249 5242 5250 5243 /* 5251 5244 * Nested EPT roots are always held through guest_mmu, ··· 5296 5291 u64 gla; 5297 5292 } operand; 5298 5293 u16 vpid02; 5294 + int r; 5299 5295 5300 5296 if (!(vmx->nested.msrs.secondary_ctls_high & 5301 5297 SECONDARY_EXEC_ENABLE_VPID) || ··· 5324 5318 if (get_vmx_mem_address(vcpu, vmx_get_exit_qual(vcpu), 5325 5319 vmx_instruction_info, false, sizeof(operand), &gva)) 5326 5320 return 1; 5327 - if (kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e)) { 5328 - kvm_inject_emulated_page_fault(vcpu, &e); 5329 - return 1; 5330 - } 5321 + r = kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e); 5322 + if (r != X86EMUL_CONTINUE) 5323 + return vmx_handle_memory_failure(vcpu, r, &e); 5324 + 5331 5325 if (operand.vpid >> 16) 5332 5326 return nested_vmx_failValid(vcpu, 5333 5327 VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID); ··· 5672 5666 { 5673 5667 u32 intr_info; 5674 5668 5675 - switch (exit_reason) { 5669 + switch ((u16)exit_reason) { 5676 5670 case EXIT_REASON_EXCEPTION_NMI: 5677 5671 intr_info = vmx_get_intr_info(vcpu); 5678 5672 if (is_nmi(intr_info)) ··· 5733 5727 struct vmcs12 *vmcs12 = get_vmcs12(vcpu); 5734 5728 u32 intr_info; 5735 5729 5736 - switch (exit_reason) { 5730 + switch ((u16)exit_reason) { 5737 5731 case EXIT_REASON_EXCEPTION_NMI: 5738 5732 intr_info = vmx_get_intr_info(vcpu); 5739 5733 if (is_nmi(intr_info))
+1 -1
arch/x86/kvm/vmx/pmu_intel.c
··· 181 181 ret = pmu->version > 1; 182 182 break; 183 183 case MSR_IA32_PERF_CAPABILITIES: 184 - ret = guest_cpuid_has(vcpu, X86_FEATURE_PDCM); 184 + ret = 1; 185 185 break; 186 186 default: 187 187 ret = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0) ||
+30 -8
arch/x86/kvm/vmx/vmx.c
··· 1600 1600 return 1; 1601 1601 } 1602 1602 1603 + /* 1604 + * Handles kvm_read/write_guest_virt*() result and either injects #PF or returns 1605 + * KVM_EXIT_INTERNAL_ERROR for cases not currently handled by KVM. Return value 1606 + * indicates whether exit to userspace is needed. 1607 + */ 1608 + int vmx_handle_memory_failure(struct kvm_vcpu *vcpu, int r, 1609 + struct x86_exception *e) 1610 + { 1611 + if (r == X86EMUL_PROPAGATE_FAULT) { 1612 + kvm_inject_emulated_page_fault(vcpu, e); 1613 + return 1; 1614 + } 1615 + 1616 + /* 1617 + * In case kvm_read/write_guest_virt*() failed with X86EMUL_IO_NEEDED 1618 + * while handling a VMX instruction KVM could've handled the request 1619 + * correctly by exiting to userspace and performing I/O but there 1620 + * doesn't seem to be a real use-case behind such requests, just return 1621 + * KVM_EXIT_INTERNAL_ERROR for now. 1622 + */ 1623 + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 1624 + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; 1625 + vcpu->run->internal.ndata = 0; 1626 + 1627 + return 0; 1628 + } 1603 1629 1604 1630 /* 1605 1631 * Recognizes a pending MTF VM-exit and records the nested state for later ··· 5512 5486 u64 pcid; 5513 5487 u64 gla; 5514 5488 } operand; 5489 + int r; 5515 5490 5516 5491 if (!guest_cpuid_has(vcpu, X86_FEATURE_INVPCID)) { 5517 5492 kvm_queue_exception(vcpu, UD_VECTOR); ··· 5535 5508 sizeof(operand), &gva)) 5536 5509 return 1; 5537 5510 5538 - if (kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e)) { 5539 - kvm_inject_emulated_page_fault(vcpu, &e); 5540 - return 1; 5541 - } 5511 + r = kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e); 5512 + if (r != X86EMUL_CONTINUE) 5513 + return vmx_handle_memory_failure(vcpu, r, &e); 5542 5514 5543 5515 if (operand.pcid >> 12 != 0) { 5544 5516 kvm_inject_gp(vcpu, 0); ··· 7307 7281 kvm_cpu_cap_check_and_set(X86_FEATURE_INVPCID); 7308 7282 if (vmx_pt_mode_is_host_guest()) 7309 7283 kvm_cpu_cap_check_and_set(X86_FEATURE_INTEL_PT); 7310 - 7311 - /* PKU is not yet implemented for shadow paging. */ 7312 - if (enable_ept && boot_cpu_has(X86_FEATURE_OSPKE)) 7313 - kvm_cpu_cap_check_and_set(X86_FEATURE_PKU); 7314 7284 7315 7285 if (vmx_umip_emulated()) 7316 7286 kvm_cpu_cap_set(X86_FEATURE_UMIP);
+2
arch/x86/kvm/vmx/vmx.h
··· 355 355 void pt_update_intercept_for_msr(struct vcpu_vmx *vmx); 356 356 void vmx_update_host_rsp(struct vcpu_vmx *vmx, unsigned long host_rsp); 357 357 int vmx_find_msr_index(struct vmx_msrs *m, u32 msr); 358 + int vmx_handle_memory_failure(struct kvm_vcpu *vcpu, int r, 359 + struct x86_exception *e); 358 360 359 361 #define POSTED_INTR_ON 0 360 362 #define POSTED_INTR_SN 1
+59 -80
arch/x86/kvm/x86.c
··· 239 239 u64 __read_mostly supported_xcr0; 240 240 EXPORT_SYMBOL_GPL(supported_xcr0); 241 241 242 - struct kmem_cache *x86_fpu_cache; 243 - EXPORT_SYMBOL_GPL(x86_fpu_cache); 242 + static struct kmem_cache *x86_fpu_cache; 244 243 245 244 static struct kmem_cache *x86_emulator_cache; 246 245 ··· 5646 5647 /* kvm_write_guest_virt_system can pull in tons of pages. */ 5647 5648 vcpu->arch.l1tf_flush_l1d = true; 5648 5649 5649 - /* 5650 - * FIXME: this should call handle_emulation_failure if X86EMUL_IO_NEEDED 5651 - * is returned, but our callers are not ready for that and they blindly 5652 - * call kvm_inject_page_fault. Ensure that they at least do not leak 5653 - * uninitialized kernel stack memory into cr2 and error code. 5654 - */ 5655 - memset(exception, 0, sizeof(*exception)); 5656 5650 return kvm_write_guest_virt_helper(addr, val, bytes, vcpu, 5657 5651 PFERR_WRITE_MASK, exception); 5658 5652 } ··· 7010 7018 if (!ctxt->have_exception || 7011 7019 exception_type(ctxt->exception.vector) == EXCPT_TRAP) { 7012 7020 kvm_rip_write(vcpu, ctxt->eip); 7013 - if (r && ctxt->tf) 7021 + if (r && (ctxt->tf || (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP))) 7014 7022 r = kvm_vcpu_do_singlestep(vcpu); 7015 7023 if (kvm_x86_ops.update_emulated_instruction) 7016 7024 kvm_x86_ops.update_emulated_instruction(vcpu); ··· 8269 8277 kvm_x86_ops.load_eoi_exitmap(vcpu, eoi_exit_bitmap); 8270 8278 } 8271 8279 8272 - int kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, 8273 - unsigned long start, unsigned long end, 8274 - bool blockable) 8280 + void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, 8281 + unsigned long start, unsigned long end) 8275 8282 { 8276 8283 unsigned long apic_address; 8277 8284 ··· 8281 8290 apic_address = gfn_to_hva(kvm, APIC_DEFAULT_PHYS_BASE >> PAGE_SHIFT); 8282 8291 if (start <= apic_address && apic_address < end) 8283 8292 kvm_make_all_cpus_request(kvm, KVM_REQ_APIC_PAGE_RELOAD); 8284 - 8285 - return 0; 8286 8293 } 8287 8294 8288 8295 void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu) ··· 9951 9962 if (!slot || !slot->npages) 9952 9963 return 0; 9953 9964 9954 - /* 9955 - * Stuff a non-canonical value to catch use-after-delete. This 9956 - * ends up being 0 on 32-bit KVM, but there's no better 9957 - * alternative. 9958 - */ 9959 - hva = (unsigned long)(0xdeadull << 48); 9960 9965 old_npages = slot->npages; 9966 + hva = 0; 9961 9967 } 9962 9968 9963 9969 for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) { ··· 10124 10140 } 10125 10141 10126 10142 static void kvm_mmu_slot_apply_flags(struct kvm *kvm, 10127 - struct kvm_memory_slot *new) 10143 + struct kvm_memory_slot *old, 10144 + struct kvm_memory_slot *new, 10145 + enum kvm_mr_change change) 10128 10146 { 10129 - /* Still write protect RO slot */ 10130 - if (new->flags & KVM_MEM_READONLY) { 10131 - kvm_mmu_slot_remove_write_access(kvm, new, PG_LEVEL_4K); 10147 + /* 10148 + * Nothing to do for RO slots or CREATE/MOVE/DELETE of a slot. 10149 + * See comments below. 10150 + */ 10151 + if ((change != KVM_MR_FLAGS_ONLY) || (new->flags & KVM_MEM_READONLY)) 10132 10152 return; 10133 - } 10134 10153 10135 10154 /* 10136 - * Call kvm_x86_ops dirty logging hooks when they are valid. 10155 + * Dirty logging tracks sptes in 4k granularity, meaning that large 10156 + * sptes have to be split. If live migration is successful, the guest 10157 + * in the source machine will be destroyed and large sptes will be 10158 + * created in the destination. However, if the guest continues to run 10159 + * in the source machine (for example if live migration fails), small 10160 + * sptes will remain around and cause bad performance. 10137 10161 * 10138 - * kvm_x86_ops.slot_disable_log_dirty is called when: 10162 + * Scan sptes if dirty logging has been stopped, dropping those 10163 + * which can be collapsed into a single large-page spte. Later 10164 + * page faults will create the large-page sptes. 10139 10165 * 10140 - * - KVM_MR_CREATE with dirty logging is disabled 10141 - * - KVM_MR_FLAGS_ONLY with dirty logging is disabled in new flag 10166 + * There is no need to do this in any of the following cases: 10167 + * CREATE: No dirty mappings will already exist. 10168 + * MOVE/DELETE: The old mappings will already have been cleaned up by 10169 + * kvm_arch_flush_shadow_memslot() 10170 + */ 10171 + if ((old->flags & KVM_MEM_LOG_DIRTY_PAGES) && 10172 + !(new->flags & KVM_MEM_LOG_DIRTY_PAGES)) 10173 + kvm_mmu_zap_collapsible_sptes(kvm, new); 10174 + 10175 + /* 10176 + * Enable or disable dirty logging for the slot. 10142 10177 * 10143 - * The reason is, in case of PML, we need to set D-bit for any slots 10144 - * with dirty logging disabled in order to eliminate unnecessary GPA 10145 - * logging in PML buffer (and potential PML buffer full VMEXIT). This 10146 - * guarantees leaving PML enabled during guest's lifetime won't have 10147 - * any additional overhead from PML when guest is running with dirty 10148 - * logging disabled for memory slots. 10178 + * For KVM_MR_DELETE and KVM_MR_MOVE, the shadow pages of the old 10179 + * slot have been zapped so no dirty logging updates are needed for 10180 + * the old slot. 10181 + * For KVM_MR_CREATE and KVM_MR_MOVE, once the new slot is visible 10182 + * any mappings that might be created in it will consume the 10183 + * properties of the new slot and do not need to be updated here. 10149 10184 * 10150 - * kvm_x86_ops.slot_enable_log_dirty is called when switching new slot 10151 - * to dirty logging mode. 10185 + * When PML is enabled, the kvm_x86_ops dirty logging hooks are 10186 + * called to enable/disable dirty logging. 10152 10187 * 10153 - * If kvm_x86_ops dirty logging hooks are invalid, use write protect. 10188 + * When disabling dirty logging with PML enabled, the D-bit is set 10189 + * for sptes in the slot in order to prevent unnecessary GPA 10190 + * logging in the PML buffer (and potential PML buffer full VMEXIT). 10191 + * This guarantees leaving PML enabled for the guest's lifetime 10192 + * won't have any additional overhead from PML when the guest is 10193 + * running with dirty logging disabled. 10154 10194 * 10155 - * In case of write protect: 10156 - * 10157 - * Write protect all pages for dirty logging. 10158 - * 10159 - * All the sptes including the large sptes which point to this 10160 - * slot are set to readonly. We can not create any new large 10161 - * spte on this slot until the end of the logging. 10162 - * 10195 + * When enabling dirty logging, large sptes are write-protected 10196 + * so they can be split on first write. New large sptes cannot 10197 + * be created for this slot until the end of the logging. 10163 10198 * See the comments in fast_page_fault(). 10199 + * For small sptes, nothing is done if the dirty log is in the 10200 + * initial-all-set state. Otherwise, depending on whether pml 10201 + * is enabled the D-bit or the W-bit will be cleared. 10164 10202 */ 10165 10203 if (new->flags & KVM_MEM_LOG_DIRTY_PAGES) { 10166 10204 if (kvm_x86_ops.slot_enable_log_dirty) { ··· 10219 10213 kvm_mmu_calculate_default_mmu_pages(kvm)); 10220 10214 10221 10215 /* 10222 - * Dirty logging tracks sptes in 4k granularity, meaning that large 10223 - * sptes have to be split. If live migration is successful, the guest 10224 - * in the source machine will be destroyed and large sptes will be 10225 - * created in the destination. However, if the guest continues to run 10226 - * in the source machine (for example if live migration fails), small 10227 - * sptes will remain around and cause bad performance. 10228 - * 10229 - * Scan sptes if dirty logging has been stopped, dropping those 10230 - * which can be collapsed into a single large-page spte. Later 10231 - * page faults will create the large-page sptes. 10232 - * 10233 - * There is no need to do this in any of the following cases: 10234 - * CREATE: No dirty mappings will already exist. 10235 - * MOVE/DELETE: The old mappings will already have been cleaned up by 10236 - * kvm_arch_flush_shadow_memslot() 10237 - */ 10238 - if (change == KVM_MR_FLAGS_ONLY && 10239 - (old->flags & KVM_MEM_LOG_DIRTY_PAGES) && 10240 - !(new->flags & KVM_MEM_LOG_DIRTY_PAGES)) 10241 - kvm_mmu_zap_collapsible_sptes(kvm, new); 10242 - 10243 - /* 10244 - * Set up write protection and/or dirty logging for the new slot. 10245 - * 10246 - * For KVM_MR_DELETE and KVM_MR_MOVE, the shadow pages of old slot have 10247 - * been zapped so no dirty logging staff is needed for old slot. For 10248 - * KVM_MR_FLAGS_ONLY, the old slot is essentially the same one as the 10249 - * new and it's also covered when dealing with the new slot. 10250 - * 10251 10216 * FIXME: const-ify all uses of struct kvm_memory_slot. 10252 10217 */ 10253 - if (change != KVM_MR_DELETE) 10254 - kvm_mmu_slot_apply_flags(kvm, (struct kvm_memory_slot *) new); 10218 + kvm_mmu_slot_apply_flags(kvm, old, (struct kvm_memory_slot *) new, change); 10255 10219 10256 10220 /* Free the arrays associated with the old memslot. */ 10257 10221 if (change == KVM_MR_MOVE) ··· 10506 10530 return kvm_arch_interrupt_allowed(vcpu); 10507 10531 } 10508 10532 10509 - void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, 10533 + bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, 10510 10534 struct kvm_async_pf *work) 10511 10535 { 10512 10536 struct x86_exception fault; ··· 10523 10547 fault.address = work->arch.token; 10524 10548 fault.async_page_fault = true; 10525 10549 kvm_inject_page_fault(vcpu, &fault); 10550 + return true; 10526 10551 } else { 10527 10552 /* 10528 10553 * It is not possible to deliver a paravirtualized asynchronous ··· 10534 10557 * fault is retried, hopefully the page will be ready in the host. 10535 10558 */ 10536 10559 kvm_make_request(KVM_REQ_APF_HALT, vcpu); 10560 + return false; 10537 10561 } 10538 10562 } 10539 10563 ··· 10552 10574 kvm_del_async_pf_gfn(vcpu, work->arch.gfn); 10553 10575 trace_kvm_async_pf_ready(work->arch.token, work->cr2_or_gpa); 10554 10576 10555 - if (kvm_pv_async_pf_enabled(vcpu) && 10577 + if ((work->wakeup_all || work->notpresent_injected) && 10578 + kvm_pv_async_pf_enabled(vcpu) && 10556 10579 !apf_put_user_ready(vcpu, work->arch.token)) { 10557 10580 vcpu->arch.apf.pageready_pending = true; 10558 10581 kvm_apic_set_irq(vcpu, &irq, NULL);
+4 -4
include/linux/kvm_host.h
··· 206 206 unsigned long addr; 207 207 struct kvm_arch_async_pf arch; 208 208 bool wakeup_all; 209 + bool notpresent_injected; 209 210 }; 210 211 211 212 void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu); ··· 319 318 bool preempted; 320 319 bool ready; 321 320 struct kvm_vcpu_arch arch; 322 - struct dentry *debugfs_dentry; 323 321 }; 324 322 325 323 static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu) ··· 888 888 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu); 889 889 890 890 #ifdef __KVM_HAVE_ARCH_VCPU_DEBUGFS 891 - void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu); 891 + void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry); 892 892 #endif 893 893 894 894 int kvm_arch_hardware_enable(void); ··· 1421 1421 } 1422 1422 #endif /* CONFIG_HAVE_KVM_VCPU_ASYNC_IOCTL */ 1423 1423 1424 - int kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, 1425 - unsigned long start, unsigned long end, bool blockable); 1424 + void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, 1425 + unsigned long start, unsigned long end); 1426 1426 1427 1427 #ifdef CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE 1428 1428 int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu);
+1
tools/testing/selftests/kvm/.gitignore
··· 3 3 /s390x/resets 4 4 /s390x/sync_regs_test 5 5 /x86_64/cr4_cpuid_sync_test 6 + /x86_64/debug_regs 6 7 /x86_64/evmcs_test 7 8 /x86_64/hyperv_cpuid 8 9 /x86_64/mmio_warning_test
+4
tools/testing/selftests/kvm/Makefile
··· 83 83 INSTALL_HDR_PATH = $(top_srcdir)/usr 84 84 LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/ 85 85 LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include 86 + ifeq ($(ARCH),x86_64) 87 + LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include 88 + else 86 89 LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include 90 + endif 87 91 CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ 88 92 -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ 89 93 -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
+1
tools/testing/selftests/kvm/include/x86_64/svm_util.h
··· 33 33 struct svm_test_data *vcpu_alloc_svm(struct kvm_vm *vm, vm_vaddr_t *p_svm_gva); 34 34 void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_rsp); 35 35 void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa); 36 + bool nested_svm_supported(void); 36 37 void nested_svm_check_supported(void); 37 38 38 39 static inline bool cpu_has_svm(void)
+1 -4
tools/testing/selftests/kvm/include/x86_64/vmx.h
··· 598 598 }; 599 599 }; 600 600 601 - union vmx_basic basic; 602 - union vmx_ctrl_msr ctrl_pin_rev; 603 - union vmx_ctrl_msr ctrl_exit_rev; 604 - 605 601 struct vmx_pages *vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva); 606 602 bool prepare_for_vmx_operation(struct vmx_pages *vmx); 607 603 void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp); 608 604 bool load_vmcs(struct vmx_pages *vmx); 609 605 606 + bool nested_vmx_supported(void); 610 607 void nested_vmx_check_supported(void); 611 608 612 609 void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
+9 -2
tools/testing/selftests/kvm/lib/kvm_util.c
··· 195 195 case VM_MODE_PXXV48_4K: 196 196 #ifdef __x86_64__ 197 197 kvm_get_cpu_address_width(&vm->pa_bits, &vm->va_bits); 198 - TEST_ASSERT(vm->va_bits == 48, "Linear address width " 199 - "(%d bits) not supported", vm->va_bits); 198 + /* 199 + * Ignore KVM support for 5-level paging (vm->va_bits == 57), 200 + * it doesn't take effect unless a CR4.LA57 is set, which it 201 + * isn't for this VM_MODE. 202 + */ 203 + TEST_ASSERT(vm->va_bits == 48 || vm->va_bits == 57, 204 + "Linear address width (%d bits) not supported", 205 + vm->va_bits); 200 206 pr_debug("Guest physical address width detected: %d\n", 201 207 vm->pa_bits); 202 208 vm->pgtable_levels = 4; 209 + vm->va_bits = 48; 203 210 #else 204 211 TEST_FAIL("VM_MODE_PXXV48_4K not supported on non-x86 platforms"); 205 212 #endif
+7 -3
tools/testing/selftests/kvm/lib/x86_64/svm.c
··· 148 148 : "r15", "memory"); 149 149 } 150 150 151 - void nested_svm_check_supported(void) 151 + bool nested_svm_supported(void) 152 152 { 153 153 struct kvm_cpuid_entry2 *entry = 154 154 kvm_get_supported_cpuid_entry(0x80000001); 155 155 156 - if (!(entry->ecx & CPUID_SVM)) { 156 + return entry->ecx & CPUID_SVM; 157 + } 158 + 159 + void nested_svm_check_supported(void) 160 + { 161 + if (!nested_svm_supported()) { 157 162 print_skip("nested SVM not enabled"); 158 163 exit(KSFT_SKIP); 159 164 } 160 165 } 161 -
+7 -2
tools/testing/selftests/kvm/lib/x86_64/vmx.c
··· 379 379 init_vmcs_guest_state(guest_rip, guest_rsp); 380 380 } 381 381 382 - void nested_vmx_check_supported(void) 382 + bool nested_vmx_supported(void) 383 383 { 384 384 struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1); 385 385 386 - if (!(entry->ecx & CPUID_VMX)) { 386 + return entry->ecx & CPUID_VMX; 387 + } 388 + 389 + void nested_vmx_check_supported(void) 390 + { 391 + if (!nested_vmx_supported()) { 387 392 print_skip("nested VMX not enabled"); 388 393 exit(KSFT_SKIP); 389 394 }
+3 -2
tools/testing/selftests/kvm/x86_64/evmcs_test.c
··· 94 94 95 95 vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid()); 96 96 97 - if (!kvm_check_cap(KVM_CAP_NESTED_STATE) || 97 + if (!nested_vmx_supported() || 98 + !kvm_check_cap(KVM_CAP_NESTED_STATE) || 98 99 !kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { 99 - print_skip("capabilities not available"); 100 + print_skip("Enlightened VMCS is unsupported"); 100 101 exit(KSFT_SKIP); 101 102 } 102 103
+2 -1
tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
··· 170 170 case 1: 171 171 break; 172 172 case 2: 173 - if (!kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { 173 + if (!nested_vmx_supported() || 174 + !kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { 174 175 print_skip("Enlightened VMCS is unsupported"); 175 176 continue; 176 177 }
+9 -8
tools/testing/selftests/kvm/x86_64/smm_test.c
··· 47 47 0x0f, 0xaa, /* rsm */ 48 48 }; 49 49 50 - void sync_with_host(uint64_t phase) 50 + static inline void sync_with_host(uint64_t phase) 51 51 { 52 52 asm volatile("in $" XSTR(SYNC_PORT)", %%al \n" 53 - : : "a" (phase)); 53 + : "+a" (phase)); 54 54 } 55 55 56 56 void self_smi(void) ··· 118 118 vcpu_set_msr(vm, VCPU_ID, MSR_IA32_SMBASE, SMRAM_GPA); 119 119 120 120 if (kvm_check_cap(KVM_CAP_NESTED_STATE)) { 121 - if (kvm_get_supported_cpuid_entry(0x80000001)->ecx & CPUID_SVM) 121 + if (nested_svm_supported()) 122 122 vcpu_alloc_svm(vm, &nested_gva); 123 - else 123 + else if (nested_vmx_supported()) 124 124 vcpu_alloc_vmx(vm, &nested_gva); 125 - vcpu_args_set(vm, VCPU_ID, 1, nested_gva); 126 - } else { 127 - pr_info("will skip SMM test with VMX enabled\n"); 128 - vcpu_args_set(vm, VCPU_ID, 1, 0); 129 125 } 126 + 127 + if (!nested_gva) 128 + pr_info("will skip SMM test with VMX enabled\n"); 129 + 130 + vcpu_args_set(vm, VCPU_ID, 1, nested_gva); 130 131 131 132 for (stage = 1;; stage++) { 132 133 _vcpu_run(vm, VCPU_ID);
+7 -6
tools/testing/selftests/kvm/x86_64/state_test.c
··· 171 171 vcpu_regs_get(vm, VCPU_ID, &regs1); 172 172 173 173 if (kvm_check_cap(KVM_CAP_NESTED_STATE)) { 174 - if (kvm_get_supported_cpuid_entry(0x80000001)->ecx & CPUID_SVM) 174 + if (nested_svm_supported()) 175 175 vcpu_alloc_svm(vm, &nested_gva); 176 - else 176 + else if (nested_vmx_supported()) 177 177 vcpu_alloc_vmx(vm, &nested_gva); 178 - vcpu_args_set(vm, VCPU_ID, 1, nested_gva); 179 - } else { 180 - pr_info("will skip nested state checks\n"); 181 - vcpu_args_set(vm, VCPU_ID, 1, 0); 182 178 } 179 + 180 + if (!nested_gva) 181 + pr_info("will skip nested state checks\n"); 182 + 183 + vcpu_args_set(vm, VCPU_ID, 1, nested_gva); 183 184 184 185 for (stage = 1;; stage++) { 185 186 _vcpu_run(vm, VCPU_ID);
+4
tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c
··· 31 31 static u64 l2_vmx_pt_start; 32 32 volatile u64 l2_vmx_pt_finish; 33 33 34 + union vmx_basic basic; 35 + union vmx_ctrl_msr ctrl_pin_rev; 36 + union vmx_ctrl_msr ctrl_exit_rev; 37 + 34 38 void l2_guest_code(void) 35 39 { 36 40 u64 vmx_pt_delta;
+7 -14
virt/kvm/async_pf.c
··· 164 164 if (vcpu->async_pf.queued >= ASYNC_PF_PER_VCPU) 165 165 return 0; 166 166 167 - /* setup delayed work */ 167 + /* Arch specific code should not do async PF in this case */ 168 + if (unlikely(kvm_is_error_hva(hva))) 169 + return 0; 168 170 169 171 /* 170 172 * do alloc nowait since if we are going to sleep anyway we ··· 185 183 mmget(work->mm); 186 184 kvm_get_kvm(work->vcpu->kvm); 187 185 188 - /* this can't really happen otherwise gfn_to_pfn_async 189 - would succeed */ 190 - if (unlikely(kvm_is_error_hva(work->addr))) 191 - goto retry_sync; 192 - 193 186 INIT_WORK(&work->work, async_pf_execute); 194 - if (!schedule_work(&work->work)) 195 - goto retry_sync; 196 187 197 188 list_add_tail(&work->queue, &vcpu->async_pf.queue); 198 189 vcpu->async_pf.queued++; 199 - kvm_arch_async_page_not_present(vcpu, work); 190 + work->notpresent_injected = kvm_arch_async_page_not_present(vcpu, work); 191 + 192 + schedule_work(&work->work); 193 + 200 194 return 1; 201 - retry_sync: 202 - kvm_put_kvm(work->vcpu->kvm); 203 - mmput(work->mm); 204 - kmem_cache_free(async_pf_cache, work); 205 - return 0; 206 195 } 207 196 208 197 int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu)
+28 -25
virt/kvm/kvm_main.c
··· 154 154 static unsigned long long kvm_createvm_count; 155 155 static unsigned long long kvm_active_vms; 156 156 157 - __weak int kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, 158 - unsigned long start, unsigned long end, bool blockable) 157 + __weak void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm, 158 + unsigned long start, unsigned long end) 159 159 { 160 - return 0; 161 160 } 162 161 163 162 bool kvm_is_zone_device_pfn(kvm_pfn_t pfn) ··· 382 383 return container_of(mn, struct kvm, mmu_notifier); 383 384 } 384 385 386 + static void kvm_mmu_notifier_invalidate_range(struct mmu_notifier *mn, 387 + struct mm_struct *mm, 388 + unsigned long start, unsigned long end) 389 + { 390 + struct kvm *kvm = mmu_notifier_to_kvm(mn); 391 + int idx; 392 + 393 + idx = srcu_read_lock(&kvm->srcu); 394 + kvm_arch_mmu_notifier_invalidate_range(kvm, start, end); 395 + srcu_read_unlock(&kvm->srcu, idx); 396 + } 397 + 385 398 static void kvm_mmu_notifier_change_pte(struct mmu_notifier *mn, 386 399 struct mm_struct *mm, 387 400 unsigned long address, ··· 418 407 { 419 408 struct kvm *kvm = mmu_notifier_to_kvm(mn); 420 409 int need_tlb_flush = 0, idx; 421 - int ret; 422 410 423 411 idx = srcu_read_lock(&kvm->srcu); 424 412 spin_lock(&kvm->mmu_lock); ··· 434 424 kvm_flush_remote_tlbs(kvm); 435 425 436 426 spin_unlock(&kvm->mmu_lock); 437 - 438 - ret = kvm_arch_mmu_notifier_invalidate_range(kvm, range->start, 439 - range->end, 440 - mmu_notifier_range_blockable(range)); 441 - 442 427 srcu_read_unlock(&kvm->srcu, idx); 443 428 444 - return ret; 429 + return 0; 445 430 } 446 431 447 432 static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn, ··· 542 537 } 543 538 544 539 static const struct mmu_notifier_ops kvm_mmu_notifier_ops = { 540 + .invalidate_range = kvm_mmu_notifier_invalidate_range, 545 541 .invalidate_range_start = kvm_mmu_notifier_invalidate_range_start, 546 542 .invalidate_range_end = kvm_mmu_notifier_invalidate_range_end, 547 543 .clear_flush_young = kvm_mmu_notifier_clear_flush_young, ··· 2976 2970 { 2977 2971 struct kvm_vcpu *vcpu = filp->private_data; 2978 2972 2979 - debugfs_remove_recursive(vcpu->debugfs_dentry); 2980 2973 kvm_put_kvm(vcpu->kvm); 2981 2974 return 0; 2982 2975 } ··· 3002 2997 static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) 3003 2998 { 3004 2999 #ifdef __KVM_HAVE_ARCH_VCPU_DEBUGFS 3000 + struct dentry *debugfs_dentry; 3005 3001 char dir_name[ITOA_MAX_LEN * 2]; 3006 3002 3007 3003 if (!debugfs_initialized()) 3008 3004 return; 3009 3005 3010 3006 snprintf(dir_name, sizeof(dir_name), "vcpu%d", vcpu->vcpu_id); 3011 - vcpu->debugfs_dentry = debugfs_create_dir(dir_name, 3012 - vcpu->kvm->debugfs_dentry); 3007 + debugfs_dentry = debugfs_create_dir(dir_name, 3008 + vcpu->kvm->debugfs_dentry); 3013 3009 3014 - kvm_arch_create_vcpu_debugfs(vcpu); 3010 + kvm_arch_create_vcpu_debugfs(vcpu, debugfs_dentry); 3015 3011 #endif 3016 3012 } 3017 3013 ··· 3749 3743 if (routing.flags) 3750 3744 goto out; 3751 3745 if (routing.nr) { 3752 - r = -ENOMEM; 3753 - entries = vmalloc(array_size(sizeof(*entries), 3754 - routing.nr)); 3755 - if (!entries) 3756 - goto out; 3757 - r = -EFAULT; 3758 3746 urouting = argp; 3759 - if (copy_from_user(entries, urouting->entries, 3760 - routing.nr * sizeof(*entries))) 3761 - goto out_free_irq_routing; 3747 + entries = vmemdup_user(urouting->entries, 3748 + array_size(sizeof(*entries), 3749 + routing.nr)); 3750 + if (IS_ERR(entries)) { 3751 + r = PTR_ERR(entries); 3752 + goto out; 3753 + } 3762 3754 } 3763 3755 r = kvm_set_irq_routing(kvm, entries, routing.nr, 3764 3756 routing.flags); 3765 - out_free_irq_routing: 3766 - vfree(entries); 3757 + kvfree(entries); 3767 3758 break; 3768 3759 } 3769 3760 #endif /* CONFIG_HAVE_KVM_IRQ_ROUTING */