Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com> |
| 3 | * Copyright (C) 2009. SUSE Linux Products GmbH. All rights reserved. |
| 4 | * |
| 5 | * Authors: |
| 6 | * Paul Mackerras <paulus@au1.ibm.com> |
| 7 | * Alexander Graf <agraf@suse.de> |
| 8 | * Kevin Wolf <mail@kevin-wolf.de> |
| 9 | * |
| 10 | * Description: KVM functions specific to running on Book 3S |
| 11 | * processors in hypervisor mode (specifically POWER7 and later). |
| 12 | * |
| 13 | * This file is derived from arch/powerpc/kvm/book3s.c, |
| 14 | * by Alexander Graf <agraf@suse.de>. |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License, version 2, as |
| 18 | * published by the Free Software Foundation. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kvm_host.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/preempt.h> |
| 25 | #include <linux/sched.h> |
| 26 | #include <linux/delay.h> |
Paul Gortmaker | 66b15db | 2011-05-27 10:46:24 -0400 | [diff] [blame] | 27 | #include <linux/export.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 28 | #include <linux/fs.h> |
| 29 | #include <linux/anon_inodes.h> |
| 30 | #include <linux/cpumask.h> |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 31 | #include <linux/spinlock.h> |
| 32 | #include <linux/page-flags.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 33 | |
| 34 | #include <asm/reg.h> |
| 35 | #include <asm/cputable.h> |
| 36 | #include <asm/cacheflush.h> |
| 37 | #include <asm/tlbflush.h> |
| 38 | #include <asm/uaccess.h> |
| 39 | #include <asm/io.h> |
| 40 | #include <asm/kvm_ppc.h> |
| 41 | #include <asm/kvm_book3s.h> |
| 42 | #include <asm/mmu_context.h> |
| 43 | #include <asm/lppaca.h> |
| 44 | #include <asm/processor.h> |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 45 | #include <asm/cputhreads.h> |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 46 | #include <asm/page.h> |
Michael Neuling | de1d924 | 2011-11-09 20:39:49 +0000 | [diff] [blame] | 47 | #include <asm/hvcall.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 48 | #include <asm/switch_to.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 49 | #include <linux/gfp.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 50 | #include <linux/vmalloc.h> |
| 51 | #include <linux/highmem.h> |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 52 | #include <linux/hugetlb.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 53 | |
| 54 | /* #define EXIT_DEBUG */ |
| 55 | /* #define EXIT_DEBUG_SIMPLE */ |
| 56 | /* #define EXIT_DEBUG_INT */ |
| 57 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 58 | static void kvmppc_end_cede(struct kvm_vcpu *vcpu); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 59 | static int kvmppc_hv_setup_rma(struct kvm_vcpu *vcpu); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 60 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 61 | void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) |
| 62 | { |
| 63 | local_paca->kvm_hstate.kvm_vcpu = vcpu; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 64 | local_paca->kvm_hstate.kvm_vcore = vcpu->arch.vcore; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) |
| 68 | { |
| 69 | } |
| 70 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 71 | void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr) |
| 72 | { |
| 73 | vcpu->arch.shregs.msr = msr; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 74 | kvmppc_end_cede(vcpu); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr) |
| 78 | { |
| 79 | vcpu->arch.pvr = pvr; |
| 80 | } |
| 81 | |
| 82 | void kvmppc_dump_regs(struct kvm_vcpu *vcpu) |
| 83 | { |
| 84 | int r; |
| 85 | |
| 86 | pr_err("vcpu %p (%d):\n", vcpu, vcpu->vcpu_id); |
| 87 | pr_err("pc = %.16lx msr = %.16llx trap = %x\n", |
| 88 | vcpu->arch.pc, vcpu->arch.shregs.msr, vcpu->arch.trap); |
| 89 | for (r = 0; r < 16; ++r) |
| 90 | pr_err("r%2d = %.16lx r%d = %.16lx\n", |
| 91 | r, kvmppc_get_gpr(vcpu, r), |
| 92 | r+16, kvmppc_get_gpr(vcpu, r+16)); |
| 93 | pr_err("ctr = %.16lx lr = %.16lx\n", |
| 94 | vcpu->arch.ctr, vcpu->arch.lr); |
| 95 | pr_err("srr0 = %.16llx srr1 = %.16llx\n", |
| 96 | vcpu->arch.shregs.srr0, vcpu->arch.shregs.srr1); |
| 97 | pr_err("sprg0 = %.16llx sprg1 = %.16llx\n", |
| 98 | vcpu->arch.shregs.sprg0, vcpu->arch.shregs.sprg1); |
| 99 | pr_err("sprg2 = %.16llx sprg3 = %.16llx\n", |
| 100 | vcpu->arch.shregs.sprg2, vcpu->arch.shregs.sprg3); |
| 101 | pr_err("cr = %.8x xer = %.16lx dsisr = %.8x\n", |
| 102 | vcpu->arch.cr, vcpu->arch.xer, vcpu->arch.shregs.dsisr); |
| 103 | pr_err("dar = %.16llx\n", vcpu->arch.shregs.dar); |
| 104 | pr_err("fault dar = %.16lx dsisr = %.8x\n", |
| 105 | vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); |
| 106 | pr_err("SLB (%d entries):\n", vcpu->arch.slb_max); |
| 107 | for (r = 0; r < vcpu->arch.slb_max; ++r) |
| 108 | pr_err(" ESID = %.16llx VSID = %.16llx\n", |
| 109 | vcpu->arch.slb[r].orige, vcpu->arch.slb[r].origv); |
| 110 | pr_err("lpcr = %.16lx sdr1 = %.16lx last_inst = %.8x\n", |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 111 | vcpu->kvm->arch.lpcr, vcpu->kvm->arch.sdr1, |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 112 | vcpu->arch.last_inst); |
| 113 | } |
| 114 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 115 | struct kvm_vcpu *kvmppc_find_vcpu(struct kvm *kvm, int id) |
| 116 | { |
| 117 | int r; |
| 118 | struct kvm_vcpu *v, *ret = NULL; |
| 119 | |
| 120 | mutex_lock(&kvm->lock); |
| 121 | kvm_for_each_vcpu(r, v, kvm) { |
| 122 | if (v->vcpu_id == id) { |
| 123 | ret = v; |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | mutex_unlock(&kvm->lock); |
| 128 | return ret; |
| 129 | } |
| 130 | |
| 131 | static void init_vpa(struct kvm_vcpu *vcpu, struct lppaca *vpa) |
| 132 | { |
| 133 | vpa->shared_proc = 1; |
| 134 | vpa->yield_count = 1; |
| 135 | } |
| 136 | |
| 137 | static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu, |
| 138 | unsigned long flags, |
| 139 | unsigned long vcpuid, unsigned long vpa) |
| 140 | { |
| 141 | struct kvm *kvm = vcpu->kvm; |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 142 | unsigned long len, nb; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 143 | void *va; |
| 144 | struct kvm_vcpu *tvcpu; |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 145 | int err = H_PARAMETER; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 146 | |
| 147 | tvcpu = kvmppc_find_vcpu(kvm, vcpuid); |
| 148 | if (!tvcpu) |
| 149 | return H_PARAMETER; |
| 150 | |
| 151 | flags >>= 63 - 18; |
| 152 | flags &= 7; |
| 153 | if (flags == 0 || flags == 4) |
| 154 | return H_PARAMETER; |
| 155 | if (flags < 4) { |
| 156 | if (vpa & 0x7f) |
| 157 | return H_PARAMETER; |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 158 | if (flags >= 2 && !tvcpu->arch.vpa) |
| 159 | return H_RESOURCE; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 160 | /* registering new area; convert logical addr to real */ |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 161 | va = kvmppc_pin_guest_page(kvm, vpa, &nb); |
| 162 | if (va == NULL) |
Paul Mackerras | b2b2f16 | 2011-12-12 12:28:21 +0000 | [diff] [blame] | 163 | return H_PARAMETER; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 164 | if (flags <= 1) |
| 165 | len = *(unsigned short *)(va + 4); |
| 166 | else |
| 167 | len = *(unsigned int *)(va + 4); |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 168 | if (len > nb) |
| 169 | goto out_unpin; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 170 | switch (flags) { |
| 171 | case 1: /* register VPA */ |
| 172 | if (len < 640) |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 173 | goto out_unpin; |
| 174 | if (tvcpu->arch.vpa) |
| 175 | kvmppc_unpin_guest_page(kvm, vcpu->arch.vpa); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 176 | tvcpu->arch.vpa = va; |
| 177 | init_vpa(vcpu, va); |
| 178 | break; |
| 179 | case 2: /* register DTL */ |
| 180 | if (len < 48) |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 181 | goto out_unpin; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 182 | len -= len % 48; |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 183 | if (tvcpu->arch.dtl) |
| 184 | kvmppc_unpin_guest_page(kvm, vcpu->arch.dtl); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 185 | tvcpu->arch.dtl = va; |
| 186 | tvcpu->arch.dtl_end = va + len; |
| 187 | break; |
| 188 | case 3: /* register SLB shadow buffer */ |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 189 | if (len < 16) |
| 190 | goto out_unpin; |
| 191 | if (tvcpu->arch.slb_shadow) |
| 192 | kvmppc_unpin_guest_page(kvm, vcpu->arch.slb_shadow); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 193 | tvcpu->arch.slb_shadow = va; |
| 194 | break; |
| 195 | } |
| 196 | } else { |
| 197 | switch (flags) { |
| 198 | case 5: /* unregister VPA */ |
| 199 | if (tvcpu->arch.slb_shadow || tvcpu->arch.dtl) |
| 200 | return H_RESOURCE; |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 201 | if (!tvcpu->arch.vpa) |
| 202 | break; |
| 203 | kvmppc_unpin_guest_page(kvm, tvcpu->arch.vpa); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 204 | tvcpu->arch.vpa = NULL; |
| 205 | break; |
| 206 | case 6: /* unregister DTL */ |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 207 | if (!tvcpu->arch.dtl) |
| 208 | break; |
| 209 | kvmppc_unpin_guest_page(kvm, tvcpu->arch.dtl); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 210 | tvcpu->arch.dtl = NULL; |
| 211 | break; |
| 212 | case 7: /* unregister SLB shadow buffer */ |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 213 | if (!tvcpu->arch.slb_shadow) |
| 214 | break; |
| 215 | kvmppc_unpin_guest_page(kvm, tvcpu->arch.slb_shadow); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 216 | tvcpu->arch.slb_shadow = NULL; |
| 217 | break; |
| 218 | } |
| 219 | } |
| 220 | return H_SUCCESS; |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 221 | |
| 222 | out_unpin: |
| 223 | kvmppc_unpin_guest_page(kvm, va); |
| 224 | return err; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) |
| 228 | { |
| 229 | unsigned long req = kvmppc_get_gpr(vcpu, 3); |
| 230 | unsigned long target, ret = H_SUCCESS; |
| 231 | struct kvm_vcpu *tvcpu; |
| 232 | |
| 233 | switch (req) { |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 234 | case H_ENTER: |
| 235 | ret = kvmppc_virtmode_h_enter(vcpu, kvmppc_get_gpr(vcpu, 4), |
| 236 | kvmppc_get_gpr(vcpu, 5), |
| 237 | kvmppc_get_gpr(vcpu, 6), |
| 238 | kvmppc_get_gpr(vcpu, 7)); |
| 239 | break; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 240 | case H_CEDE: |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 241 | break; |
| 242 | case H_PROD: |
| 243 | target = kvmppc_get_gpr(vcpu, 4); |
| 244 | tvcpu = kvmppc_find_vcpu(vcpu->kvm, target); |
| 245 | if (!tvcpu) { |
| 246 | ret = H_PARAMETER; |
| 247 | break; |
| 248 | } |
| 249 | tvcpu->arch.prodded = 1; |
| 250 | smp_mb(); |
| 251 | if (vcpu->arch.ceded) { |
| 252 | if (waitqueue_active(&vcpu->wq)) { |
| 253 | wake_up_interruptible(&vcpu->wq); |
| 254 | vcpu->stat.halt_wakeup++; |
| 255 | } |
| 256 | } |
| 257 | break; |
| 258 | case H_CONFER: |
| 259 | break; |
| 260 | case H_REGISTER_VPA: |
| 261 | ret = do_h_register_vpa(vcpu, kvmppc_get_gpr(vcpu, 4), |
| 262 | kvmppc_get_gpr(vcpu, 5), |
| 263 | kvmppc_get_gpr(vcpu, 6)); |
| 264 | break; |
| 265 | default: |
| 266 | return RESUME_HOST; |
| 267 | } |
| 268 | kvmppc_set_gpr(vcpu, 3, ret); |
| 269 | vcpu->arch.hcall_needed = 0; |
| 270 | return RESUME_GUEST; |
| 271 | } |
| 272 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 273 | static int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 274 | struct task_struct *tsk) |
| 275 | { |
| 276 | int r = RESUME_HOST; |
| 277 | |
| 278 | vcpu->stat.sum_exits++; |
| 279 | |
| 280 | run->exit_reason = KVM_EXIT_UNKNOWN; |
| 281 | run->ready_for_interrupt_injection = 1; |
| 282 | switch (vcpu->arch.trap) { |
| 283 | /* We're good on these - the host merely wanted to get our attention */ |
| 284 | case BOOK3S_INTERRUPT_HV_DECREMENTER: |
| 285 | vcpu->stat.dec_exits++; |
| 286 | r = RESUME_GUEST; |
| 287 | break; |
| 288 | case BOOK3S_INTERRUPT_EXTERNAL: |
| 289 | vcpu->stat.ext_intr_exits++; |
| 290 | r = RESUME_GUEST; |
| 291 | break; |
| 292 | case BOOK3S_INTERRUPT_PERFMON: |
| 293 | r = RESUME_GUEST; |
| 294 | break; |
| 295 | case BOOK3S_INTERRUPT_PROGRAM: |
| 296 | { |
| 297 | ulong flags; |
| 298 | /* |
| 299 | * Normally program interrupts are delivered directly |
| 300 | * to the guest by the hardware, but we can get here |
| 301 | * as a result of a hypervisor emulation interrupt |
| 302 | * (e40) getting turned into a 700 by BML RTAS. |
| 303 | */ |
| 304 | flags = vcpu->arch.shregs.msr & 0x1f0000ull; |
| 305 | kvmppc_core_queue_program(vcpu, flags); |
| 306 | r = RESUME_GUEST; |
| 307 | break; |
| 308 | } |
| 309 | case BOOK3S_INTERRUPT_SYSCALL: |
| 310 | { |
| 311 | /* hcall - punt to userspace */ |
| 312 | int i; |
| 313 | |
| 314 | if (vcpu->arch.shregs.msr & MSR_PR) { |
| 315 | /* sc 1 from userspace - reflect to guest syscall */ |
| 316 | kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_SYSCALL); |
| 317 | r = RESUME_GUEST; |
| 318 | break; |
| 319 | } |
| 320 | run->papr_hcall.nr = kvmppc_get_gpr(vcpu, 3); |
| 321 | for (i = 0; i < 9; ++i) |
| 322 | run->papr_hcall.args[i] = kvmppc_get_gpr(vcpu, 4 + i); |
| 323 | run->exit_reason = KVM_EXIT_PAPR_HCALL; |
| 324 | vcpu->arch.hcall_needed = 1; |
| 325 | r = RESUME_HOST; |
| 326 | break; |
| 327 | } |
| 328 | /* |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 329 | * We get these next two if the guest accesses a page which it thinks |
| 330 | * it has mapped but which is not actually present, either because |
| 331 | * it is for an emulated I/O device or because the corresonding |
| 332 | * host page has been paged out. Any other HDSI/HISI interrupts |
| 333 | * have been handled already. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 334 | */ |
| 335 | case BOOK3S_INTERRUPT_H_DATA_STORAGE: |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 336 | r = kvmppc_book3s_hv_page_fault(run, vcpu, |
| 337 | vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 338 | break; |
| 339 | case BOOK3S_INTERRUPT_H_INST_STORAGE: |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 340 | r = kvmppc_book3s_hv_page_fault(run, vcpu, |
| 341 | kvmppc_get_pc(vcpu), 0); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 342 | break; |
| 343 | /* |
| 344 | * This occurs if the guest executes an illegal instruction. |
| 345 | * We just generate a program interrupt to the guest, since |
| 346 | * we don't emulate any guest instructions at this stage. |
| 347 | */ |
| 348 | case BOOK3S_INTERRUPT_H_EMUL_ASSIST: |
| 349 | kvmppc_core_queue_program(vcpu, 0x80000); |
| 350 | r = RESUME_GUEST; |
| 351 | break; |
| 352 | default: |
| 353 | kvmppc_dump_regs(vcpu); |
| 354 | printk(KERN_EMERG "trap=0x%x | pc=0x%lx | msr=0x%llx\n", |
| 355 | vcpu->arch.trap, kvmppc_get_pc(vcpu), |
| 356 | vcpu->arch.shregs.msr); |
| 357 | r = RESUME_HOST; |
| 358 | BUG(); |
| 359 | break; |
| 360 | } |
| 361 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 362 | return r; |
| 363 | } |
| 364 | |
| 365 | int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, |
| 366 | struct kvm_sregs *sregs) |
| 367 | { |
| 368 | int i; |
| 369 | |
| 370 | sregs->pvr = vcpu->arch.pvr; |
| 371 | |
| 372 | memset(sregs, 0, sizeof(struct kvm_sregs)); |
| 373 | for (i = 0; i < vcpu->arch.slb_max; i++) { |
| 374 | sregs->u.s.ppc64.slb[i].slbe = vcpu->arch.slb[i].orige; |
| 375 | sregs->u.s.ppc64.slb[i].slbv = vcpu->arch.slb[i].origv; |
| 376 | } |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, |
| 382 | struct kvm_sregs *sregs) |
| 383 | { |
| 384 | int i, j; |
| 385 | |
| 386 | kvmppc_set_pvr(vcpu, sregs->pvr); |
| 387 | |
| 388 | j = 0; |
| 389 | for (i = 0; i < vcpu->arch.slb_nr; i++) { |
| 390 | if (sregs->u.s.ppc64.slb[i].slbe & SLB_ESID_V) { |
| 391 | vcpu->arch.slb[j].orige = sregs->u.s.ppc64.slb[i].slbe; |
| 392 | vcpu->arch.slb[j].origv = sregs->u.s.ppc64.slb[i].slbv; |
| 393 | ++j; |
| 394 | } |
| 395 | } |
| 396 | vcpu->arch.slb_max = j; |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 401 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
| 402 | { |
| 403 | int r = -EINVAL; |
| 404 | |
| 405 | switch (reg->id) { |
| 406 | case KVM_REG_PPC_HIOR: |
| 407 | r = put_user(0, (u64 __user *)reg->addr); |
| 408 | break; |
| 409 | default: |
| 410 | break; |
| 411 | } |
| 412 | |
| 413 | return r; |
| 414 | } |
| 415 | |
| 416 | int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
| 417 | { |
| 418 | int r = -EINVAL; |
| 419 | |
| 420 | switch (reg->id) { |
| 421 | case KVM_REG_PPC_HIOR: |
| 422 | { |
| 423 | u64 hior; |
| 424 | /* Only allow this to be set to zero */ |
| 425 | r = get_user(hior, (u64 __user *)reg->addr); |
| 426 | if (!r && (hior != 0)) |
| 427 | r = -EINVAL; |
| 428 | break; |
| 429 | } |
| 430 | default: |
| 431 | break; |
| 432 | } |
| 433 | |
| 434 | return r; |
| 435 | } |
| 436 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 437 | int kvmppc_core_check_processor_compat(void) |
| 438 | { |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 439 | if (cpu_has_feature(CPU_FTR_HVMODE)) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 440 | return 0; |
| 441 | return -EIO; |
| 442 | } |
| 443 | |
| 444 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) |
| 445 | { |
| 446 | struct kvm_vcpu *vcpu; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 447 | int err = -EINVAL; |
| 448 | int core; |
| 449 | struct kvmppc_vcore *vcore; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 450 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 451 | core = id / threads_per_core; |
| 452 | if (core >= KVM_MAX_VCORES) |
| 453 | goto out; |
| 454 | |
| 455 | err = -ENOMEM; |
Sasha Levin | 6b75e6b | 2011-12-07 10:24:56 +0200 | [diff] [blame] | 456 | vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 457 | if (!vcpu) |
| 458 | goto out; |
| 459 | |
| 460 | err = kvm_vcpu_init(vcpu, kvm, id); |
| 461 | if (err) |
| 462 | goto free_vcpu; |
| 463 | |
| 464 | vcpu->arch.shared = &vcpu->arch.shregs; |
| 465 | vcpu->arch.last_cpu = -1; |
| 466 | vcpu->arch.mmcr[0] = MMCR0_FC; |
| 467 | vcpu->arch.ctrl = CTRL_RUNLATCH; |
| 468 | /* default to host PVR, since we can't spoof it */ |
| 469 | vcpu->arch.pvr = mfspr(SPRN_PVR); |
| 470 | kvmppc_set_pvr(vcpu, vcpu->arch.pvr); |
| 471 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 472 | kvmppc_mmu_book3s_hv_init(vcpu); |
| 473 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 474 | /* |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 475 | * We consider the vcpu stopped until we see the first run ioctl for it. |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 476 | */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 477 | vcpu->arch.state = KVMPPC_VCPU_STOPPED; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 478 | |
| 479 | init_waitqueue_head(&vcpu->arch.cpu_run); |
| 480 | |
| 481 | mutex_lock(&kvm->lock); |
| 482 | vcore = kvm->arch.vcores[core]; |
| 483 | if (!vcore) { |
| 484 | vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL); |
| 485 | if (vcore) { |
| 486 | INIT_LIST_HEAD(&vcore->runnable_threads); |
| 487 | spin_lock_init(&vcore->lock); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 488 | init_waitqueue_head(&vcore->wq); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 489 | } |
| 490 | kvm->arch.vcores[core] = vcore; |
| 491 | } |
| 492 | mutex_unlock(&kvm->lock); |
| 493 | |
| 494 | if (!vcore) |
| 495 | goto free_vcpu; |
| 496 | |
| 497 | spin_lock(&vcore->lock); |
| 498 | ++vcore->num_threads; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 499 | spin_unlock(&vcore->lock); |
| 500 | vcpu->arch.vcore = vcore; |
| 501 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 502 | vcpu->arch.cpu_type = KVM_CPU_3S_64; |
| 503 | kvmppc_sanity_check(vcpu); |
| 504 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 505 | return vcpu; |
| 506 | |
| 507 | free_vcpu: |
Sasha Levin | 6b75e6b | 2011-12-07 10:24:56 +0200 | [diff] [blame] | 508 | kmem_cache_free(kvm_vcpu_cache, vcpu); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 509 | out: |
| 510 | return ERR_PTR(err); |
| 511 | } |
| 512 | |
| 513 | void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) |
| 514 | { |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 515 | if (vcpu->arch.dtl) |
| 516 | kvmppc_unpin_guest_page(vcpu->kvm, vcpu->arch.dtl); |
| 517 | if (vcpu->arch.slb_shadow) |
| 518 | kvmppc_unpin_guest_page(vcpu->kvm, vcpu->arch.slb_shadow); |
| 519 | if (vcpu->arch.vpa) |
| 520 | kvmppc_unpin_guest_page(vcpu->kvm, vcpu->arch.vpa); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 521 | kvm_vcpu_uninit(vcpu); |
Sasha Levin | 6b75e6b | 2011-12-07 10:24:56 +0200 | [diff] [blame] | 522 | kmem_cache_free(kvm_vcpu_cache, vcpu); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 525 | static void kvmppc_set_timer(struct kvm_vcpu *vcpu) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 526 | { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 527 | unsigned long dec_nsec, now; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 528 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 529 | now = get_tb(); |
| 530 | if (now > vcpu->arch.dec_expires) { |
| 531 | /* decrementer has already gone negative */ |
| 532 | kvmppc_core_queue_dec(vcpu); |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 533 | kvmppc_core_prepare_to_enter(vcpu); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 534 | return; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 535 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 536 | dec_nsec = (vcpu->arch.dec_expires - now) * NSEC_PER_SEC |
| 537 | / tb_ticks_per_sec; |
| 538 | hrtimer_start(&vcpu->arch.dec_timer, ktime_set(0, dec_nsec), |
| 539 | HRTIMER_MODE_REL); |
| 540 | vcpu->arch.timer_running = 1; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 543 | static void kvmppc_end_cede(struct kvm_vcpu *vcpu) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 544 | { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 545 | vcpu->arch.ceded = 0; |
| 546 | if (vcpu->arch.timer_running) { |
| 547 | hrtimer_try_to_cancel(&vcpu->arch.dec_timer); |
| 548 | vcpu->arch.timer_running = 0; |
| 549 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | extern int __kvmppc_vcore_entry(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); |
| 553 | extern void xics_wake_cpu(int cpu); |
| 554 | |
| 555 | static void kvmppc_remove_runnable(struct kvmppc_vcore *vc, |
| 556 | struct kvm_vcpu *vcpu) |
| 557 | { |
| 558 | struct kvm_vcpu *v; |
| 559 | |
| 560 | if (vcpu->arch.state != KVMPPC_VCPU_RUNNABLE) |
| 561 | return; |
| 562 | vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; |
| 563 | --vc->n_runnable; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 564 | ++vc->n_busy; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 565 | /* decrement the physical thread id of each following vcpu */ |
| 566 | v = vcpu; |
| 567 | list_for_each_entry_continue(v, &vc->runnable_threads, arch.run_list) |
| 568 | --v->arch.ptid; |
| 569 | list_del(&vcpu->arch.run_list); |
| 570 | } |
| 571 | |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame^] | 572 | static int kvmppc_grab_hwthread(int cpu) |
| 573 | { |
| 574 | struct paca_struct *tpaca; |
| 575 | long timeout = 1000; |
| 576 | |
| 577 | tpaca = &paca[cpu]; |
| 578 | |
| 579 | /* Ensure the thread won't go into the kernel if it wakes */ |
| 580 | tpaca->kvm_hstate.hwthread_req = 1; |
| 581 | |
| 582 | /* |
| 583 | * If the thread is already executing in the kernel (e.g. handling |
| 584 | * a stray interrupt), wait for it to get back to nap mode. |
| 585 | * The smp_mb() is to ensure that our setting of hwthread_req |
| 586 | * is visible before we look at hwthread_state, so if this |
| 587 | * races with the code at system_reset_pSeries and the thread |
| 588 | * misses our setting of hwthread_req, we are sure to see its |
| 589 | * setting of hwthread_state, and vice versa. |
| 590 | */ |
| 591 | smp_mb(); |
| 592 | while (tpaca->kvm_hstate.hwthread_state == KVM_HWTHREAD_IN_KERNEL) { |
| 593 | if (--timeout <= 0) { |
| 594 | pr_err("KVM: couldn't grab cpu %d\n", cpu); |
| 595 | return -EBUSY; |
| 596 | } |
| 597 | udelay(1); |
| 598 | } |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | static void kvmppc_release_hwthread(int cpu) |
| 603 | { |
| 604 | struct paca_struct *tpaca; |
| 605 | |
| 606 | tpaca = &paca[cpu]; |
| 607 | tpaca->kvm_hstate.hwthread_req = 0; |
| 608 | tpaca->kvm_hstate.kvm_vcpu = NULL; |
| 609 | } |
| 610 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 611 | static void kvmppc_start_thread(struct kvm_vcpu *vcpu) |
| 612 | { |
| 613 | int cpu; |
| 614 | struct paca_struct *tpaca; |
| 615 | struct kvmppc_vcore *vc = vcpu->arch.vcore; |
| 616 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 617 | if (vcpu->arch.timer_running) { |
| 618 | hrtimer_try_to_cancel(&vcpu->arch.dec_timer); |
| 619 | vcpu->arch.timer_running = 0; |
| 620 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 621 | cpu = vc->pcpu + vcpu->arch.ptid; |
| 622 | tpaca = &paca[cpu]; |
| 623 | tpaca->kvm_hstate.kvm_vcpu = vcpu; |
| 624 | tpaca->kvm_hstate.kvm_vcore = vc; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 625 | tpaca->kvm_hstate.napping = 0; |
| 626 | vcpu->cpu = vc->pcpu; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 627 | smp_wmb(); |
Michael Neuling | 251da03 | 2011-11-10 16:03:20 +0000 | [diff] [blame] | 628 | #if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 629 | if (vcpu->arch.ptid) { |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame^] | 630 | kvmppc_grab_hwthread(cpu); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 631 | xics_wake_cpu(cpu); |
| 632 | ++vc->n_woken; |
| 633 | } |
| 634 | #endif |
| 635 | } |
| 636 | |
| 637 | static void kvmppc_wait_for_nap(struct kvmppc_vcore *vc) |
| 638 | { |
| 639 | int i; |
| 640 | |
| 641 | HMT_low(); |
| 642 | i = 0; |
| 643 | while (vc->nap_count < vc->n_woken) { |
| 644 | if (++i >= 1000000) { |
| 645 | pr_err("kvmppc_wait_for_nap timeout %d %d\n", |
| 646 | vc->nap_count, vc->n_woken); |
| 647 | break; |
| 648 | } |
| 649 | cpu_relax(); |
| 650 | } |
| 651 | HMT_medium(); |
| 652 | } |
| 653 | |
| 654 | /* |
| 655 | * Check that we are on thread 0 and that any other threads in |
| 656 | * this core are off-line. |
| 657 | */ |
| 658 | static int on_primary_thread(void) |
| 659 | { |
| 660 | int cpu = smp_processor_id(); |
| 661 | int thr = cpu_thread_in_core(cpu); |
| 662 | |
| 663 | if (thr) |
| 664 | return 0; |
| 665 | while (++thr < threads_per_core) |
| 666 | if (cpu_online(cpu + thr)) |
| 667 | return 0; |
| 668 | return 1; |
| 669 | } |
| 670 | |
| 671 | /* |
| 672 | * Run a set of guest threads on a physical core. |
| 673 | * Called with vc->lock held. |
| 674 | */ |
| 675 | static int kvmppc_run_core(struct kvmppc_vcore *vc) |
| 676 | { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 677 | struct kvm_vcpu *vcpu, *vcpu0, *vnext; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 678 | long ret; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 679 | u64 now; |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame^] | 680 | int ptid, i; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 681 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 682 | /* don't start if any threads have a signal pending */ |
| 683 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) |
| 684 | if (signal_pending(vcpu->arch.run_task)) |
| 685 | return 0; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 686 | |
| 687 | /* |
| 688 | * Make sure we are running on thread 0, and that |
| 689 | * secondary threads are offline. |
| 690 | * XXX we should also block attempts to bring any |
| 691 | * secondary threads online. |
| 692 | */ |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 693 | if (threads_per_core > 1 && !on_primary_thread()) { |
| 694 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) |
| 695 | vcpu->arch.ret = -EBUSY; |
| 696 | goto out; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 699 | /* |
| 700 | * Assign physical thread IDs, first to non-ceded vcpus |
| 701 | * and then to ceded ones. |
| 702 | */ |
| 703 | ptid = 0; |
| 704 | vcpu0 = NULL; |
| 705 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { |
| 706 | if (!vcpu->arch.ceded) { |
| 707 | if (!ptid) |
| 708 | vcpu0 = vcpu; |
| 709 | vcpu->arch.ptid = ptid++; |
| 710 | } |
| 711 | } |
| 712 | if (!vcpu0) |
| 713 | return 0; /* nothing to run */ |
| 714 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) |
| 715 | if (vcpu->arch.ceded) |
| 716 | vcpu->arch.ptid = ptid++; |
| 717 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 718 | vc->n_woken = 0; |
| 719 | vc->nap_count = 0; |
| 720 | vc->entry_exit_count = 0; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 721 | vc->vcore_state = VCORE_RUNNING; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 722 | vc->in_guest = 0; |
| 723 | vc->pcpu = smp_processor_id(); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 724 | vc->napping_threads = 0; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 725 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) |
| 726 | kvmppc_start_thread(vcpu); |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame^] | 727 | /* Grab any remaining hw threads so they can't go into the kernel */ |
| 728 | for (i = ptid; i < threads_per_core; ++i) |
| 729 | kvmppc_grab_hwthread(vc->pcpu + i); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 730 | |
| 731 | preempt_disable(); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 732 | spin_unlock(&vc->lock); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 733 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 734 | kvm_guest_enter(); |
| 735 | __kvmppc_vcore_entry(NULL, vcpu0); |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame^] | 736 | for (i = 0; i < threads_per_core; ++i) |
| 737 | kvmppc_release_hwthread(vc->pcpu + i); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 738 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 739 | spin_lock(&vc->lock); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 740 | /* disable sending of IPIs on virtual external irqs */ |
| 741 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) |
| 742 | vcpu->cpu = -1; |
| 743 | /* wait for secondary threads to finish writing their state to memory */ |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 744 | if (vc->nap_count < vc->n_woken) |
| 745 | kvmppc_wait_for_nap(vc); |
| 746 | /* prevent other vcpu threads from doing kvmppc_start_thread() now */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 747 | vc->vcore_state = VCORE_EXITING; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 748 | spin_unlock(&vc->lock); |
| 749 | |
| 750 | /* make sure updates to secondary vcpu structs are visible now */ |
| 751 | smp_mb(); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 752 | kvm_guest_exit(); |
| 753 | |
| 754 | preempt_enable(); |
| 755 | kvm_resched(vcpu); |
| 756 | |
| 757 | now = get_tb(); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 758 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { |
| 759 | /* cancel pending dec exception if dec is positive */ |
| 760 | if (now < vcpu->arch.dec_expires && |
| 761 | kvmppc_core_pending_dec(vcpu)) |
| 762 | kvmppc_core_dequeue_dec(vcpu); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 763 | |
| 764 | ret = RESUME_GUEST; |
| 765 | if (vcpu->arch.trap) |
| 766 | ret = kvmppc_handle_exit(vcpu->arch.kvm_run, vcpu, |
| 767 | vcpu->arch.run_task); |
| 768 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 769 | vcpu->arch.ret = ret; |
| 770 | vcpu->arch.trap = 0; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 771 | |
| 772 | if (vcpu->arch.ceded) { |
| 773 | if (ret != RESUME_GUEST) |
| 774 | kvmppc_end_cede(vcpu); |
| 775 | else |
| 776 | kvmppc_set_timer(vcpu); |
| 777 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 778 | } |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 779 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 780 | spin_lock(&vc->lock); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 781 | out: |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 782 | vc->vcore_state = VCORE_INACTIVE; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 783 | list_for_each_entry_safe(vcpu, vnext, &vc->runnable_threads, |
| 784 | arch.run_list) { |
| 785 | if (vcpu->arch.ret != RESUME_GUEST) { |
| 786 | kvmppc_remove_runnable(vc, vcpu); |
| 787 | wake_up(&vcpu->arch.cpu_run); |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | return 1; |
| 792 | } |
| 793 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 794 | /* |
| 795 | * Wait for some other vcpu thread to execute us, and |
| 796 | * wake us up when we need to handle something in the host. |
| 797 | */ |
| 798 | static void kvmppc_wait_for_exec(struct kvm_vcpu *vcpu, int wait_state) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 799 | { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 800 | DEFINE_WAIT(wait); |
| 801 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 802 | prepare_to_wait(&vcpu->arch.cpu_run, &wait, wait_state); |
| 803 | if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) |
| 804 | schedule(); |
| 805 | finish_wait(&vcpu->arch.cpu_run, &wait); |
| 806 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 807 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 808 | /* |
| 809 | * All the vcpus in this vcore are idle, so wait for a decrementer |
| 810 | * or external interrupt to one of the vcpus. vc->lock is held. |
| 811 | */ |
| 812 | static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) |
| 813 | { |
| 814 | DEFINE_WAIT(wait); |
| 815 | struct kvm_vcpu *v; |
| 816 | int all_idle = 1; |
| 817 | |
| 818 | prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE); |
| 819 | vc->vcore_state = VCORE_SLEEPING; |
| 820 | spin_unlock(&vc->lock); |
| 821 | list_for_each_entry(v, &vc->runnable_threads, arch.run_list) { |
| 822 | if (!v->arch.ceded || v->arch.pending_exceptions) { |
| 823 | all_idle = 0; |
| 824 | break; |
| 825 | } |
| 826 | } |
| 827 | if (all_idle) |
| 828 | schedule(); |
| 829 | finish_wait(&vc->wq, &wait); |
| 830 | spin_lock(&vc->lock); |
| 831 | vc->vcore_state = VCORE_INACTIVE; |
| 832 | } |
| 833 | |
| 834 | static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) |
| 835 | { |
| 836 | int n_ceded; |
| 837 | int prev_state; |
| 838 | struct kvmppc_vcore *vc; |
| 839 | struct kvm_vcpu *v, *vn; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 840 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 841 | kvm_run->exit_reason = 0; |
| 842 | vcpu->arch.ret = RESUME_GUEST; |
| 843 | vcpu->arch.trap = 0; |
| 844 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 845 | /* |
| 846 | * Synchronize with other threads in this virtual core |
| 847 | */ |
| 848 | vc = vcpu->arch.vcore; |
| 849 | spin_lock(&vc->lock); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 850 | vcpu->arch.ceded = 0; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 851 | vcpu->arch.run_task = current; |
| 852 | vcpu->arch.kvm_run = kvm_run; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 853 | prev_state = vcpu->arch.state; |
| 854 | vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 855 | list_add_tail(&vcpu->arch.run_list, &vc->runnable_threads); |
| 856 | ++vc->n_runnable; |
| 857 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 858 | /* |
| 859 | * This happens the first time this is called for a vcpu. |
| 860 | * If the vcore is already running, we may be able to start |
| 861 | * this thread straight away and have it join in. |
| 862 | */ |
| 863 | if (prev_state == KVMPPC_VCPU_STOPPED) { |
| 864 | if (vc->vcore_state == VCORE_RUNNING && |
| 865 | VCORE_EXIT_COUNT(vc) == 0) { |
| 866 | vcpu->arch.ptid = vc->n_runnable - 1; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 867 | kvmppc_start_thread(vcpu); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 868 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 869 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 870 | } else if (prev_state == KVMPPC_VCPU_BUSY_IN_HOST) |
| 871 | --vc->n_busy; |
| 872 | |
| 873 | while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE && |
| 874 | !signal_pending(current)) { |
| 875 | if (vc->n_busy || vc->vcore_state != VCORE_INACTIVE) { |
| 876 | spin_unlock(&vc->lock); |
| 877 | kvmppc_wait_for_exec(vcpu, TASK_INTERRUPTIBLE); |
| 878 | spin_lock(&vc->lock); |
| 879 | continue; |
| 880 | } |
| 881 | n_ceded = 0; |
| 882 | list_for_each_entry(v, &vc->runnable_threads, arch.run_list) |
| 883 | n_ceded += v->arch.ceded; |
| 884 | if (n_ceded == vc->n_runnable) |
| 885 | kvmppc_vcore_blocked(vc); |
| 886 | else |
| 887 | kvmppc_run_core(vc); |
| 888 | |
| 889 | list_for_each_entry_safe(v, vn, &vc->runnable_threads, |
| 890 | arch.run_list) { |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 891 | kvmppc_core_prepare_to_enter(v); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 892 | if (signal_pending(v->arch.run_task)) { |
| 893 | kvmppc_remove_runnable(vc, v); |
| 894 | v->stat.signal_exits++; |
| 895 | v->arch.kvm_run->exit_reason = KVM_EXIT_INTR; |
| 896 | v->arch.ret = -EINTR; |
| 897 | wake_up(&v->arch.cpu_run); |
| 898 | } |
| 899 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 902 | if (signal_pending(current)) { |
| 903 | if (vc->vcore_state == VCORE_RUNNING || |
| 904 | vc->vcore_state == VCORE_EXITING) { |
| 905 | spin_unlock(&vc->lock); |
| 906 | kvmppc_wait_for_exec(vcpu, TASK_UNINTERRUPTIBLE); |
| 907 | spin_lock(&vc->lock); |
| 908 | } |
| 909 | if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) { |
| 910 | kvmppc_remove_runnable(vc, vcpu); |
| 911 | vcpu->stat.signal_exits++; |
| 912 | kvm_run->exit_reason = KVM_EXIT_INTR; |
| 913 | vcpu->arch.ret = -EINTR; |
| 914 | } |
| 915 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 916 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 917 | spin_unlock(&vc->lock); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 918 | return vcpu->arch.ret; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 921 | int kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu) |
| 922 | { |
| 923 | int r; |
| 924 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 925 | if (!vcpu->arch.sane) { |
| 926 | run->exit_reason = KVM_EXIT_INTERNAL_ERROR; |
| 927 | return -EINVAL; |
| 928 | } |
| 929 | |
Scott Wood | 25051b5a | 2011-11-08 18:23:23 -0600 | [diff] [blame] | 930 | kvmppc_core_prepare_to_enter(vcpu); |
| 931 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 932 | /* No need to go into the guest when all we'll do is come back out */ |
| 933 | if (signal_pending(current)) { |
| 934 | run->exit_reason = KVM_EXIT_INTR; |
| 935 | return -EINTR; |
| 936 | } |
| 937 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 938 | /* On the first time here, set up VRMA or RMA */ |
| 939 | if (!vcpu->kvm->arch.rma_setup_done) { |
| 940 | r = kvmppc_hv_setup_rma(vcpu); |
| 941 | if (r) |
| 942 | return r; |
| 943 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 944 | |
| 945 | flush_fp_to_thread(current); |
| 946 | flush_altivec_to_thread(current); |
| 947 | flush_vsx_to_thread(current); |
| 948 | vcpu->arch.wqp = &vcpu->arch.vcore->wq; |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 949 | vcpu->arch.pgdir = current->mm->pgd; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 950 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 951 | do { |
| 952 | r = kvmppc_run_vcpu(run, vcpu); |
| 953 | |
| 954 | if (run->exit_reason == KVM_EXIT_PAPR_HCALL && |
| 955 | !(vcpu->arch.shregs.msr & MSR_PR)) { |
| 956 | r = kvmppc_pseries_do_hcall(vcpu); |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 957 | kvmppc_core_prepare_to_enter(vcpu); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 958 | } |
| 959 | } while (r == RESUME_GUEST); |
| 960 | return r; |
| 961 | } |
| 962 | |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 963 | static long kvmppc_stt_npages(unsigned long window_size) |
| 964 | { |
| 965 | return ALIGN((window_size >> SPAPR_TCE_SHIFT) |
| 966 | * sizeof(u64), PAGE_SIZE) / PAGE_SIZE; |
| 967 | } |
| 968 | |
| 969 | static void release_spapr_tce_table(struct kvmppc_spapr_tce_table *stt) |
| 970 | { |
| 971 | struct kvm *kvm = stt->kvm; |
| 972 | int i; |
| 973 | |
| 974 | mutex_lock(&kvm->lock); |
| 975 | list_del(&stt->list); |
| 976 | for (i = 0; i < kvmppc_stt_npages(stt->window_size); i++) |
| 977 | __free_page(stt->pages[i]); |
| 978 | kfree(stt); |
| 979 | mutex_unlock(&kvm->lock); |
| 980 | |
| 981 | kvm_put_kvm(kvm); |
| 982 | } |
| 983 | |
| 984 | static int kvm_spapr_tce_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
| 985 | { |
| 986 | struct kvmppc_spapr_tce_table *stt = vma->vm_file->private_data; |
| 987 | struct page *page; |
| 988 | |
| 989 | if (vmf->pgoff >= kvmppc_stt_npages(stt->window_size)) |
| 990 | return VM_FAULT_SIGBUS; |
| 991 | |
| 992 | page = stt->pages[vmf->pgoff]; |
| 993 | get_page(page); |
| 994 | vmf->page = page; |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | static const struct vm_operations_struct kvm_spapr_tce_vm_ops = { |
| 999 | .fault = kvm_spapr_tce_fault, |
| 1000 | }; |
| 1001 | |
| 1002 | static int kvm_spapr_tce_mmap(struct file *file, struct vm_area_struct *vma) |
| 1003 | { |
| 1004 | vma->vm_ops = &kvm_spapr_tce_vm_ops; |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
| 1008 | static int kvm_spapr_tce_release(struct inode *inode, struct file *filp) |
| 1009 | { |
| 1010 | struct kvmppc_spapr_tce_table *stt = filp->private_data; |
| 1011 | |
| 1012 | release_spapr_tce_table(stt); |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | static struct file_operations kvm_spapr_tce_fops = { |
| 1017 | .mmap = kvm_spapr_tce_mmap, |
| 1018 | .release = kvm_spapr_tce_release, |
| 1019 | }; |
| 1020 | |
| 1021 | long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, |
| 1022 | struct kvm_create_spapr_tce *args) |
| 1023 | { |
| 1024 | struct kvmppc_spapr_tce_table *stt = NULL; |
| 1025 | long npages; |
| 1026 | int ret = -ENOMEM; |
| 1027 | int i; |
| 1028 | |
| 1029 | /* Check this LIOBN hasn't been previously allocated */ |
| 1030 | list_for_each_entry(stt, &kvm->arch.spapr_tce_tables, list) { |
| 1031 | if (stt->liobn == args->liobn) |
| 1032 | return -EBUSY; |
| 1033 | } |
| 1034 | |
| 1035 | npages = kvmppc_stt_npages(args->window_size); |
| 1036 | |
| 1037 | stt = kzalloc(sizeof(*stt) + npages* sizeof(struct page *), |
| 1038 | GFP_KERNEL); |
| 1039 | if (!stt) |
| 1040 | goto fail; |
| 1041 | |
| 1042 | stt->liobn = args->liobn; |
| 1043 | stt->window_size = args->window_size; |
| 1044 | stt->kvm = kvm; |
| 1045 | |
| 1046 | for (i = 0; i < npages; i++) { |
| 1047 | stt->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO); |
| 1048 | if (!stt->pages[i]) |
| 1049 | goto fail; |
| 1050 | } |
| 1051 | |
| 1052 | kvm_get_kvm(kvm); |
| 1053 | |
| 1054 | mutex_lock(&kvm->lock); |
| 1055 | list_add(&stt->list, &kvm->arch.spapr_tce_tables); |
| 1056 | |
| 1057 | mutex_unlock(&kvm->lock); |
| 1058 | |
| 1059 | return anon_inode_getfd("kvm-spapr-tce", &kvm_spapr_tce_fops, |
| 1060 | stt, O_RDWR); |
| 1061 | |
| 1062 | fail: |
| 1063 | if (stt) { |
| 1064 | for (i = 0; i < npages; i++) |
| 1065 | if (stt->pages[i]) |
| 1066 | __free_page(stt->pages[i]); |
| 1067 | |
| 1068 | kfree(stt); |
| 1069 | } |
| 1070 | return ret; |
| 1071 | } |
| 1072 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1073 | /* Work out RMLS (real mode limit selector) field value for a given RMA size. |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1074 | Assumes POWER7 or PPC970. */ |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1075 | static inline int lpcr_rmls(unsigned long rma_size) |
| 1076 | { |
| 1077 | switch (rma_size) { |
| 1078 | case 32ul << 20: /* 32 MB */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1079 | if (cpu_has_feature(CPU_FTR_ARCH_206)) |
| 1080 | return 8; /* only supported on POWER7 */ |
| 1081 | return -1; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1082 | case 64ul << 20: /* 64 MB */ |
| 1083 | return 3; |
| 1084 | case 128ul << 20: /* 128 MB */ |
| 1085 | return 7; |
| 1086 | case 256ul << 20: /* 256 MB */ |
| 1087 | return 4; |
| 1088 | case 1ul << 30: /* 1 GB */ |
| 1089 | return 2; |
| 1090 | case 16ul << 30: /* 16 GB */ |
| 1091 | return 1; |
| 1092 | case 256ul << 30: /* 256 GB */ |
| 1093 | return 0; |
| 1094 | default: |
| 1095 | return -1; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | static int kvm_rma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
| 1100 | { |
Alexander Graf | b4e7061 | 2012-01-16 16:50:10 +0100 | [diff] [blame] | 1101 | struct kvmppc_linear_info *ri = vma->vm_file->private_data; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1102 | struct page *page; |
| 1103 | |
| 1104 | if (vmf->pgoff >= ri->npages) |
| 1105 | return VM_FAULT_SIGBUS; |
| 1106 | |
| 1107 | page = pfn_to_page(ri->base_pfn + vmf->pgoff); |
| 1108 | get_page(page); |
| 1109 | vmf->page = page; |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
| 1113 | static const struct vm_operations_struct kvm_rma_vm_ops = { |
| 1114 | .fault = kvm_rma_fault, |
| 1115 | }; |
| 1116 | |
| 1117 | static int kvm_rma_mmap(struct file *file, struct vm_area_struct *vma) |
| 1118 | { |
| 1119 | vma->vm_flags |= VM_RESERVED; |
| 1120 | vma->vm_ops = &kvm_rma_vm_ops; |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
| 1124 | static int kvm_rma_release(struct inode *inode, struct file *filp) |
| 1125 | { |
Alexander Graf | b4e7061 | 2012-01-16 16:50:10 +0100 | [diff] [blame] | 1126 | struct kvmppc_linear_info *ri = filp->private_data; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1127 | |
| 1128 | kvm_release_rma(ri); |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | static struct file_operations kvm_rma_fops = { |
| 1133 | .mmap = kvm_rma_mmap, |
| 1134 | .release = kvm_rma_release, |
| 1135 | }; |
| 1136 | |
| 1137 | long kvm_vm_ioctl_allocate_rma(struct kvm *kvm, struct kvm_allocate_rma *ret) |
| 1138 | { |
Alexander Graf | b4e7061 | 2012-01-16 16:50:10 +0100 | [diff] [blame] | 1139 | struct kvmppc_linear_info *ri; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1140 | long fd; |
| 1141 | |
| 1142 | ri = kvm_alloc_rma(); |
| 1143 | if (!ri) |
| 1144 | return -ENOMEM; |
| 1145 | |
| 1146 | fd = anon_inode_getfd("kvm-rma", &kvm_rma_fops, ri, O_RDWR); |
| 1147 | if (fd < 0) |
| 1148 | kvm_release_rma(ri); |
| 1149 | |
| 1150 | ret->rma_size = ri->npages << PAGE_SHIFT; |
| 1151 | return fd; |
| 1152 | } |
| 1153 | |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 1154 | /* |
| 1155 | * Get (and clear) the dirty memory log for a memory slot. |
| 1156 | */ |
| 1157 | int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) |
| 1158 | { |
| 1159 | struct kvm_memory_slot *memslot; |
| 1160 | int r; |
| 1161 | unsigned long n; |
| 1162 | |
| 1163 | mutex_lock(&kvm->slots_lock); |
| 1164 | |
| 1165 | r = -EINVAL; |
| 1166 | if (log->slot >= KVM_MEMORY_SLOTS) |
| 1167 | goto out; |
| 1168 | |
| 1169 | memslot = id_to_memslot(kvm->memslots, log->slot); |
| 1170 | r = -ENOENT; |
| 1171 | if (!memslot->dirty_bitmap) |
| 1172 | goto out; |
| 1173 | |
| 1174 | n = kvm_dirty_bitmap_bytes(memslot); |
| 1175 | memset(memslot->dirty_bitmap, 0, n); |
| 1176 | |
| 1177 | r = kvmppc_hv_get_dirty_log(kvm, memslot); |
| 1178 | if (r) |
| 1179 | goto out; |
| 1180 | |
| 1181 | r = -EFAULT; |
| 1182 | if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) |
| 1183 | goto out; |
| 1184 | |
| 1185 | r = 0; |
| 1186 | out: |
| 1187 | mutex_unlock(&kvm->slots_lock); |
| 1188 | return r; |
| 1189 | } |
| 1190 | |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1191 | static unsigned long slb_pgsize_encoding(unsigned long psize) |
| 1192 | { |
| 1193 | unsigned long senc = 0; |
| 1194 | |
| 1195 | if (psize > 0x1000) { |
| 1196 | senc = SLB_VSID_L; |
| 1197 | if (psize == 0x10000) |
| 1198 | senc |= SLB_VSID_LP_01; |
| 1199 | } |
| 1200 | return senc; |
| 1201 | } |
| 1202 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1203 | int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
| 1204 | struct kvm_userspace_memory_region *mem) |
| 1205 | { |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1206 | unsigned long npages; |
Paul Mackerras | b2b2f16 | 2011-12-12 12:28:21 +0000 | [diff] [blame] | 1207 | unsigned long *phys; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1208 | |
Paul Mackerras | b2b2f16 | 2011-12-12 12:28:21 +0000 | [diff] [blame] | 1209 | /* Allocate a slot_phys array */ |
Paul Mackerras | b2b2f16 | 2011-12-12 12:28:21 +0000 | [diff] [blame] | 1210 | phys = kvm->arch.slot_phys[mem->slot]; |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1211 | if (!kvm->arch.using_mmu_notifiers && !phys) { |
| 1212 | npages = mem->memory_size >> PAGE_SHIFT; |
Paul Mackerras | b2b2f16 | 2011-12-12 12:28:21 +0000 | [diff] [blame] | 1213 | phys = vzalloc(npages * sizeof(unsigned long)); |
| 1214 | if (!phys) |
| 1215 | return -ENOMEM; |
| 1216 | kvm->arch.slot_phys[mem->slot] = phys; |
| 1217 | kvm->arch.slot_npages[mem->slot] = npages; |
| 1218 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1219 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1220 | return 0; |
| 1221 | } |
| 1222 | |
| 1223 | static void unpin_slot(struct kvm *kvm, int slot_id) |
| 1224 | { |
| 1225 | unsigned long *physp; |
| 1226 | unsigned long j, npages, pfn; |
| 1227 | struct page *page; |
| 1228 | |
| 1229 | physp = kvm->arch.slot_phys[slot_id]; |
| 1230 | npages = kvm->arch.slot_npages[slot_id]; |
| 1231 | if (physp) { |
| 1232 | spin_lock(&kvm->arch.slot_phys_lock); |
| 1233 | for (j = 0; j < npages; j++) { |
| 1234 | if (!(physp[j] & KVMPPC_GOT_PAGE)) |
| 1235 | continue; |
| 1236 | pfn = physp[j] >> PAGE_SHIFT; |
| 1237 | page = pfn_to_page(pfn); |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1238 | if (PageHuge(page)) |
| 1239 | page = compound_head(page); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1240 | SetPageDirty(page); |
| 1241 | put_page(page); |
| 1242 | } |
| 1243 | kvm->arch.slot_phys[slot_id] = NULL; |
| 1244 | spin_unlock(&kvm->arch.slot_phys_lock); |
| 1245 | vfree(physp); |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | void kvmppc_core_commit_memory_region(struct kvm *kvm, |
| 1250 | struct kvm_userspace_memory_region *mem) |
| 1251 | { |
| 1252 | } |
| 1253 | |
| 1254 | static int kvmppc_hv_setup_rma(struct kvm_vcpu *vcpu) |
| 1255 | { |
| 1256 | int err = 0; |
| 1257 | struct kvm *kvm = vcpu->kvm; |
Alexander Graf | b4e7061 | 2012-01-16 16:50:10 +0100 | [diff] [blame] | 1258 | struct kvmppc_linear_info *ri = NULL; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1259 | unsigned long hva; |
| 1260 | struct kvm_memory_slot *memslot; |
| 1261 | struct vm_area_struct *vma; |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1262 | unsigned long lpcr, senc; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1263 | unsigned long psize, porder; |
| 1264 | unsigned long rma_size; |
| 1265 | unsigned long rmls; |
| 1266 | unsigned long *physp; |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1267 | unsigned long i, npages; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1268 | |
| 1269 | mutex_lock(&kvm->lock); |
| 1270 | if (kvm->arch.rma_setup_done) |
| 1271 | goto out; /* another vcpu beat us to it */ |
| 1272 | |
| 1273 | /* Look up the memslot for guest physical address 0 */ |
| 1274 | memslot = gfn_to_memslot(kvm, 0); |
| 1275 | |
| 1276 | /* We must have some memory at 0 by now */ |
| 1277 | err = -EINVAL; |
| 1278 | if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) |
| 1279 | goto out; |
| 1280 | |
| 1281 | /* Look up the VMA for the start of this memory slot */ |
| 1282 | hva = memslot->userspace_addr; |
| 1283 | down_read(¤t->mm->mmap_sem); |
| 1284 | vma = find_vma(current->mm, hva); |
| 1285 | if (!vma || vma->vm_start > hva || (vma->vm_flags & VM_IO)) |
| 1286 | goto up_out; |
| 1287 | |
| 1288 | psize = vma_kernel_pagesize(vma); |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1289 | porder = __ilog2(psize); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1290 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1291 | /* Is this one of our preallocated RMAs? */ |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1292 | if (vma->vm_file && vma->vm_file->f_op == &kvm_rma_fops && |
| 1293 | hva == vma->vm_start) |
| 1294 | ri = vma->vm_file->private_data; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1295 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1296 | up_read(¤t->mm->mmap_sem); |
| 1297 | |
| 1298 | if (!ri) { |
| 1299 | /* On POWER7, use VRMA; on PPC970, give up */ |
| 1300 | err = -EPERM; |
| 1301 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
| 1302 | pr_err("KVM: CPU requires an RMO\n"); |
| 1303 | goto out; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1304 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1305 | |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1306 | /* We can handle 4k, 64k or 16M pages in the VRMA */ |
| 1307 | err = -EINVAL; |
| 1308 | if (!(psize == 0x1000 || psize == 0x10000 || |
| 1309 | psize == 0x1000000)) |
| 1310 | goto out; |
| 1311 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1312 | /* Update VRMASD field in the LPCR */ |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1313 | senc = slb_pgsize_encoding(psize); |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1314 | kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T | |
| 1315 | (VRMA_VSID << SLB_VSID_SHIFT_1T); |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1316 | lpcr = kvm->arch.lpcr & ~LPCR_VRMASD; |
| 1317 | lpcr |= senc << (LPCR_VRMASD_SH - 4); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1318 | kvm->arch.lpcr = lpcr; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1319 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1320 | /* Create HPTEs in the hash page table for the VRMA */ |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1321 | kvmppc_map_vrma(vcpu, memslot, porder); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1322 | |
| 1323 | } else { |
| 1324 | /* Set up to use an RMO region */ |
| 1325 | rma_size = ri->npages; |
| 1326 | if (rma_size > memslot->npages) |
| 1327 | rma_size = memslot->npages; |
| 1328 | rma_size <<= PAGE_SHIFT; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1329 | rmls = lpcr_rmls(rma_size); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1330 | err = -EINVAL; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1331 | if (rmls < 0) { |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1332 | pr_err("KVM: Can't use RMA of 0x%lx bytes\n", rma_size); |
| 1333 | goto out; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1334 | } |
| 1335 | atomic_inc(&ri->use_count); |
| 1336 | kvm->arch.rma = ri; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1337 | |
| 1338 | /* Update LPCR and RMOR */ |
| 1339 | lpcr = kvm->arch.lpcr; |
| 1340 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
| 1341 | /* PPC970; insert RMLS value (split field) in HID4 */ |
| 1342 | lpcr &= ~((1ul << HID4_RMLS0_SH) | |
| 1343 | (3ul << HID4_RMLS2_SH)); |
| 1344 | lpcr |= ((rmls >> 2) << HID4_RMLS0_SH) | |
| 1345 | ((rmls & 3) << HID4_RMLS2_SH); |
| 1346 | /* RMOR is also in HID4 */ |
| 1347 | lpcr |= ((ri->base_pfn >> (26 - PAGE_SHIFT)) & 0xffff) |
| 1348 | << HID4_RMOR_SH; |
| 1349 | } else { |
| 1350 | /* POWER7 */ |
| 1351 | lpcr &= ~(LPCR_VPM0 | LPCR_VRMA_L); |
| 1352 | lpcr |= rmls << LPCR_RMLS_SH; |
| 1353 | kvm->arch.rmor = kvm->arch.rma->base_pfn << PAGE_SHIFT; |
| 1354 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1355 | kvm->arch.lpcr = lpcr; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1356 | pr_info("KVM: Using RMO at %lx size %lx (LPCR = %lx)\n", |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1357 | ri->base_pfn << PAGE_SHIFT, rma_size, lpcr); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1358 | |
| 1359 | /* Initialize phys addrs of pages in RMO */ |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1360 | npages = ri->npages; |
| 1361 | porder = __ilog2(npages); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1362 | physp = kvm->arch.slot_phys[memslot->id]; |
| 1363 | spin_lock(&kvm->arch.slot_phys_lock); |
| 1364 | for (i = 0; i < npages; ++i) |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 1365 | physp[i] = ((ri->base_pfn + i) << PAGE_SHIFT) + porder; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1366 | spin_unlock(&kvm->arch.slot_phys_lock); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1369 | /* Order updates to kvm->arch.lpcr etc. vs. rma_setup_done */ |
| 1370 | smp_wmb(); |
| 1371 | kvm->arch.rma_setup_done = 1; |
| 1372 | err = 0; |
| 1373 | out: |
| 1374 | mutex_unlock(&kvm->lock); |
| 1375 | return err; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1376 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1377 | up_out: |
| 1378 | up_read(¤t->mm->mmap_sem); |
| 1379 | goto out; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | int kvmppc_core_init_vm(struct kvm *kvm) |
| 1383 | { |
| 1384 | long r; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1385 | unsigned long lpcr; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1386 | |
| 1387 | /* Allocate hashed page table */ |
| 1388 | r = kvmppc_alloc_hpt(kvm); |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 1389 | if (r) |
| 1390 | return r; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1391 | |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 1392 | INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1393 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1394 | kvm->arch.rma = NULL; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1395 | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1396 | kvm->arch.host_sdr1 = mfspr(SPRN_SDR1); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1397 | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1398 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
| 1399 | /* PPC970; HID4 is effectively the LPCR */ |
| 1400 | unsigned long lpid = kvm->arch.lpid; |
| 1401 | kvm->arch.host_lpid = 0; |
| 1402 | kvm->arch.host_lpcr = lpcr = mfspr(SPRN_HID4); |
| 1403 | lpcr &= ~((3 << HID4_LPID1_SH) | (0xful << HID4_LPID5_SH)); |
| 1404 | lpcr |= ((lpid >> 4) << HID4_LPID1_SH) | |
| 1405 | ((lpid & 0xf) << HID4_LPID5_SH); |
| 1406 | } else { |
| 1407 | /* POWER7; init LPCR for virtual RMA mode */ |
| 1408 | kvm->arch.host_lpid = mfspr(SPRN_LPID); |
| 1409 | kvm->arch.host_lpcr = lpcr = mfspr(SPRN_LPCR); |
| 1410 | lpcr &= LPCR_PECE | LPCR_LPES; |
| 1411 | lpcr |= (4UL << LPCR_DPFD_SH) | LPCR_HDICE | |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1412 | LPCR_VPM0 | LPCR_VPM1; |
| 1413 | kvm->arch.vrma_slb_v = SLB_VSID_B_1T | |
| 1414 | (VRMA_VSID << SLB_VSID_SHIFT_1T); |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1415 | } |
| 1416 | kvm->arch.lpcr = lpcr; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1417 | |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1418 | kvm->arch.using_mmu_notifiers = !!cpu_has_feature(CPU_FTR_ARCH_206); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1419 | spin_lock_init(&kvm->arch.slot_phys_lock); |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 1420 | return 0; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | void kvmppc_core_destroy_vm(struct kvm *kvm) |
| 1424 | { |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1425 | unsigned long i; |
| 1426 | |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1427 | if (!kvm->arch.using_mmu_notifiers) |
| 1428 | for (i = 0; i < KVM_MEM_SLOTS_NUM; i++) |
| 1429 | unpin_slot(kvm, i); |
Paul Mackerras | b2b2f16 | 2011-12-12 12:28:21 +0000 | [diff] [blame] | 1430 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1431 | if (kvm->arch.rma) { |
| 1432 | kvm_release_rma(kvm->arch.rma); |
| 1433 | kvm->arch.rma = NULL; |
| 1434 | } |
| 1435 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1436 | kvmppc_free_hpt(kvm); |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 1437 | WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables)); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /* These are stubs for now */ |
| 1441 | void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end) |
| 1442 | { |
| 1443 | } |
| 1444 | |
| 1445 | /* We don't need to emulate any privileged instructions or dcbz */ |
| 1446 | int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 1447 | unsigned int inst, int *advance) |
| 1448 | { |
| 1449 | return EMULATE_FAIL; |
| 1450 | } |
| 1451 | |
| 1452 | int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) |
| 1453 | { |
| 1454 | return EMULATE_FAIL; |
| 1455 | } |
| 1456 | |
| 1457 | int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) |
| 1458 | { |
| 1459 | return EMULATE_FAIL; |
| 1460 | } |
| 1461 | |
| 1462 | static int kvmppc_book3s_hv_init(void) |
| 1463 | { |
| 1464 | int r; |
| 1465 | |
| 1466 | r = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE); |
| 1467 | |
| 1468 | if (r) |
| 1469 | return r; |
| 1470 | |
| 1471 | r = kvmppc_mmu_hv_init(); |
| 1472 | |
| 1473 | return r; |
| 1474 | } |
| 1475 | |
| 1476 | static void kvmppc_book3s_hv_exit(void) |
| 1477 | { |
| 1478 | kvm_exit(); |
| 1479 | } |
| 1480 | |
| 1481 | module_init(kvmppc_book3s_hv_init); |
| 1482 | module_exit(kvmppc_book3s_hv_exit); |