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 | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 33 | #include <linux/srcu.h> |
Alexander Graf | 398a76c | 2013-12-09 13:53:42 +0100 | [diff] [blame] | 34 | #include <linux/miscdevice.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 35 | |
| 36 | #include <asm/reg.h> |
| 37 | #include <asm/cputable.h> |
| 38 | #include <asm/cacheflush.h> |
| 39 | #include <asm/tlbflush.h> |
| 40 | #include <asm/uaccess.h> |
| 41 | #include <asm/io.h> |
| 42 | #include <asm/kvm_ppc.h> |
| 43 | #include <asm/kvm_book3s.h> |
| 44 | #include <asm/mmu_context.h> |
| 45 | #include <asm/lppaca.h> |
| 46 | #include <asm/processor.h> |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 47 | #include <asm/cputhreads.h> |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 48 | #include <asm/page.h> |
Michael Neuling | de1d924 | 2011-11-09 20:39:49 +0000 | [diff] [blame] | 49 | #include <asm/hvcall.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 50 | #include <asm/switch_to.h> |
Paul Mackerras | 512691d | 2012-10-15 01:15:41 +0000 | [diff] [blame] | 51 | #include <asm/smp.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 52 | #include <linux/gfp.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 53 | #include <linux/vmalloc.h> |
| 54 | #include <linux/highmem.h> |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 55 | #include <linux/hugetlb.h> |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 56 | #include <linux/module.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 57 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 58 | #include "book3s.h" |
| 59 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 60 | /* #define EXIT_DEBUG */ |
| 61 | /* #define EXIT_DEBUG_SIMPLE */ |
| 62 | /* #define EXIT_DEBUG_INT */ |
| 63 | |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 64 | /* Used to indicate that a guest page fault needs to be handled */ |
| 65 | #define RESUME_PAGE_FAULT (RESUME_GUEST | RESUME_FLAG_ARCH1) |
| 66 | |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 67 | /* Used as a "null" value for timebase values */ |
| 68 | #define TB_NIL (~(u64)0) |
| 69 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 70 | static void kvmppc_end_cede(struct kvm_vcpu *vcpu); |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 71 | static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 72 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 73 | static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu) |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 74 | { |
| 75 | int me; |
| 76 | int cpu = vcpu->cpu; |
| 77 | wait_queue_head_t *wqp; |
| 78 | |
| 79 | wqp = kvm_arch_vcpu_wq(vcpu); |
| 80 | if (waitqueue_active(wqp)) { |
| 81 | wake_up_interruptible(wqp); |
| 82 | ++vcpu->stat.halt_wakeup; |
| 83 | } |
| 84 | |
| 85 | me = get_cpu(); |
| 86 | |
| 87 | /* CPU points to the first thread of the core */ |
| 88 | if (cpu != me && cpu >= 0 && cpu < nr_cpu_ids) { |
Anton Blanchard | 7505258 | 2014-03-25 10:47:01 +1100 | [diff] [blame] | 89 | #ifdef CONFIG_PPC_ICP_NATIVE |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 90 | int real_cpu = cpu + vcpu->arch.ptid; |
| 91 | if (paca[real_cpu].kvm_hstate.xics_phys) |
| 92 | xics_wake_cpu(real_cpu); |
Andreas Schwab | 48eaef0 | 2013-12-30 15:36:56 +0100 | [diff] [blame] | 93 | else |
| 94 | #endif |
| 95 | if (cpu_online(cpu)) |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 96 | smp_send_reschedule(cpu); |
| 97 | } |
| 98 | put_cpu(); |
| 99 | } |
| 100 | |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 101 | /* |
| 102 | * We use the vcpu_load/put functions to measure stolen time. |
| 103 | * Stolen time is counted as time when either the vcpu is able to |
| 104 | * run as part of a virtual core, but the task running the vcore |
| 105 | * is preempted or sleeping, or when the vcpu needs something done |
| 106 | * in the kernel by the task running the vcpu, but that task is |
| 107 | * preempted or sleeping. Those two things have to be counted |
| 108 | * separately, since one of the vcpu tasks will take on the job |
| 109 | * of running the core, and the other vcpu tasks in the vcore will |
| 110 | * sleep waiting for it to do that, but that sleep shouldn't count |
| 111 | * as stolen time. |
| 112 | * |
| 113 | * Hence we accumulate stolen time when the vcpu can run as part of |
| 114 | * a vcore using vc->stolen_tb, and the stolen time when the vcpu |
| 115 | * needs its task to do other things in the kernel (for example, |
| 116 | * service a page fault) in busy_stolen. We don't accumulate |
| 117 | * stolen time for a vcore when it is inactive, or for a vcpu |
| 118 | * when it is in state RUNNING or NOTREADY. NOTREADY is a bit of |
| 119 | * a misnomer; it means that the vcpu task is not executing in |
| 120 | * the KVM_VCPU_RUN ioctl, i.e. it is in userspace or elsewhere in |
| 121 | * the kernel. We don't have any way of dividing up that time |
| 122 | * between time that the vcpu is genuinely stopped, time that |
| 123 | * the task is actively working on behalf of the vcpu, and time |
| 124 | * that the task is preempted, so we don't count any of it as |
| 125 | * stolen. |
| 126 | * |
| 127 | * Updates to busy_stolen are protected by arch.tbacct_lock; |
| 128 | * updates to vc->stolen_tb are protected by the arch.tbacct_lock |
| 129 | * of the vcpu that has taken responsibility for running the vcore |
| 130 | * (i.e. vc->runner). The stolen times are measured in units of |
| 131 | * timebase ticks. (Note that the != TB_NIL checks below are |
| 132 | * purely defensive; they should never fail.) |
| 133 | */ |
| 134 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 135 | static void kvmppc_core_vcpu_load_hv(struct kvm_vcpu *vcpu, int cpu) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 136 | { |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 137 | struct kvmppc_vcore *vc = vcpu->arch.vcore; |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 138 | unsigned long flags; |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 139 | |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 140 | spin_lock_irqsave(&vcpu->arch.tbacct_lock, flags); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 141 | if (vc->runner == vcpu && vc->vcore_state != VCORE_INACTIVE && |
| 142 | vc->preempt_tb != TB_NIL) { |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 143 | vc->stolen_tb += mftb() - vc->preempt_tb; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 144 | vc->preempt_tb = TB_NIL; |
| 145 | } |
| 146 | if (vcpu->arch.state == KVMPPC_VCPU_BUSY_IN_HOST && |
| 147 | vcpu->arch.busy_preempt != TB_NIL) { |
| 148 | vcpu->arch.busy_stolen += mftb() - vcpu->arch.busy_preempt; |
| 149 | vcpu->arch.busy_preempt = TB_NIL; |
| 150 | } |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 151 | spin_unlock_irqrestore(&vcpu->arch.tbacct_lock, flags); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 154 | static void kvmppc_core_vcpu_put_hv(struct kvm_vcpu *vcpu) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 155 | { |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 156 | struct kvmppc_vcore *vc = vcpu->arch.vcore; |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 157 | unsigned long flags; |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 158 | |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 159 | spin_lock_irqsave(&vcpu->arch.tbacct_lock, flags); |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 160 | if (vc->runner == vcpu && vc->vcore_state != VCORE_INACTIVE) |
| 161 | vc->preempt_tb = mftb(); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 162 | if (vcpu->arch.state == KVMPPC_VCPU_BUSY_IN_HOST) |
| 163 | vcpu->arch.busy_preempt = mftb(); |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 164 | spin_unlock_irqrestore(&vcpu->arch.tbacct_lock, flags); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 167 | static void kvmppc_set_msr_hv(struct kvm_vcpu *vcpu, u64 msr) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 168 | { |
| 169 | vcpu->arch.shregs.msr = msr; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 170 | kvmppc_end_cede(vcpu); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 173 | void kvmppc_set_pvr_hv(struct kvm_vcpu *vcpu, u32 pvr) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 174 | { |
| 175 | vcpu->arch.pvr = pvr; |
| 176 | } |
| 177 | |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 178 | int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat) |
| 179 | { |
| 180 | unsigned long pcr = 0; |
| 181 | struct kvmppc_vcore *vc = vcpu->arch.vcore; |
| 182 | |
| 183 | if (arch_compat) { |
| 184 | if (!cpu_has_feature(CPU_FTR_ARCH_206)) |
| 185 | return -EINVAL; /* 970 has no compat mode support */ |
| 186 | |
| 187 | switch (arch_compat) { |
| 188 | case PVR_ARCH_205: |
Paul Mackerras | 5557ae0 | 2014-01-08 21:25:24 +1100 | [diff] [blame] | 189 | /* |
| 190 | * If an arch bit is set in PCR, all the defined |
| 191 | * higher-order arch bits also have to be set. |
| 192 | */ |
| 193 | pcr = PCR_ARCH_206 | PCR_ARCH_205; |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 194 | break; |
| 195 | case PVR_ARCH_206: |
| 196 | case PVR_ARCH_206p: |
Paul Mackerras | 5557ae0 | 2014-01-08 21:25:24 +1100 | [diff] [blame] | 197 | pcr = PCR_ARCH_206; |
| 198 | break; |
| 199 | case PVR_ARCH_207: |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 200 | break; |
| 201 | default: |
| 202 | return -EINVAL; |
| 203 | } |
Paul Mackerras | 5557ae0 | 2014-01-08 21:25:24 +1100 | [diff] [blame] | 204 | |
| 205 | if (!cpu_has_feature(CPU_FTR_ARCH_207S)) { |
| 206 | /* POWER7 can't emulate POWER8 */ |
| 207 | if (!(pcr & PCR_ARCH_206)) |
| 208 | return -EINVAL; |
| 209 | pcr &= ~PCR_ARCH_206; |
| 210 | } |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | spin_lock(&vc->lock); |
| 214 | vc->arch_compat = arch_compat; |
| 215 | vc->pcr = pcr; |
| 216 | spin_unlock(&vc->lock); |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 221 | void kvmppc_dump_regs(struct kvm_vcpu *vcpu) |
| 222 | { |
| 223 | int r; |
| 224 | |
| 225 | pr_err("vcpu %p (%d):\n", vcpu, vcpu->vcpu_id); |
| 226 | pr_err("pc = %.16lx msr = %.16llx trap = %x\n", |
| 227 | vcpu->arch.pc, vcpu->arch.shregs.msr, vcpu->arch.trap); |
| 228 | for (r = 0; r < 16; ++r) |
| 229 | pr_err("r%2d = %.16lx r%d = %.16lx\n", |
| 230 | r, kvmppc_get_gpr(vcpu, r), |
| 231 | r+16, kvmppc_get_gpr(vcpu, r+16)); |
| 232 | pr_err("ctr = %.16lx lr = %.16lx\n", |
| 233 | vcpu->arch.ctr, vcpu->arch.lr); |
| 234 | pr_err("srr0 = %.16llx srr1 = %.16llx\n", |
| 235 | vcpu->arch.shregs.srr0, vcpu->arch.shregs.srr1); |
| 236 | pr_err("sprg0 = %.16llx sprg1 = %.16llx\n", |
| 237 | vcpu->arch.shregs.sprg0, vcpu->arch.shregs.sprg1); |
| 238 | pr_err("sprg2 = %.16llx sprg3 = %.16llx\n", |
| 239 | vcpu->arch.shregs.sprg2, vcpu->arch.shregs.sprg3); |
| 240 | pr_err("cr = %.8x xer = %.16lx dsisr = %.8x\n", |
| 241 | vcpu->arch.cr, vcpu->arch.xer, vcpu->arch.shregs.dsisr); |
| 242 | pr_err("dar = %.16llx\n", vcpu->arch.shregs.dar); |
| 243 | pr_err("fault dar = %.16lx dsisr = %.8x\n", |
| 244 | vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); |
| 245 | pr_err("SLB (%d entries):\n", vcpu->arch.slb_max); |
| 246 | for (r = 0; r < vcpu->arch.slb_max; ++r) |
| 247 | pr_err(" ESID = %.16llx VSID = %.16llx\n", |
| 248 | vcpu->arch.slb[r].orige, vcpu->arch.slb[r].origv); |
| 249 | pr_err("lpcr = %.16lx sdr1 = %.16lx last_inst = %.8x\n", |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 250 | vcpu->arch.vcore->lpcr, vcpu->kvm->arch.sdr1, |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 251 | vcpu->arch.last_inst); |
| 252 | } |
| 253 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 254 | struct kvm_vcpu *kvmppc_find_vcpu(struct kvm *kvm, int id) |
| 255 | { |
| 256 | int r; |
| 257 | struct kvm_vcpu *v, *ret = NULL; |
| 258 | |
| 259 | mutex_lock(&kvm->lock); |
| 260 | kvm_for_each_vcpu(r, v, kvm) { |
| 261 | if (v->vcpu_id == id) { |
| 262 | ret = v; |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | mutex_unlock(&kvm->lock); |
| 267 | return ret; |
| 268 | } |
| 269 | |
| 270 | static void init_vpa(struct kvm_vcpu *vcpu, struct lppaca *vpa) |
| 271 | { |
Anton Blanchard | f13c13a | 2013-08-07 02:01:26 +1000 | [diff] [blame] | 272 | vpa->__old_status |= LPPACA_OLD_SHARED_PROC; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 273 | vpa->yield_count = 1; |
| 274 | } |
| 275 | |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 276 | static int set_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *v, |
| 277 | unsigned long addr, unsigned long len) |
| 278 | { |
| 279 | /* check address is cacheline aligned */ |
| 280 | if (addr & (L1_CACHE_BYTES - 1)) |
| 281 | return -EINVAL; |
| 282 | spin_lock(&vcpu->arch.vpa_update_lock); |
| 283 | if (v->next_gpa != addr || v->len != len) { |
| 284 | v->next_gpa = addr; |
| 285 | v->len = addr ? len : 0; |
| 286 | v->update_pending = 1; |
| 287 | } |
| 288 | spin_unlock(&vcpu->arch.vpa_update_lock); |
| 289 | return 0; |
| 290 | } |
| 291 | |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 292 | /* Length for a per-processor buffer is passed in at offset 4 in the buffer */ |
| 293 | struct reg_vpa { |
| 294 | u32 dummy; |
| 295 | union { |
| 296 | u16 hword; |
| 297 | u32 word; |
| 298 | } length; |
| 299 | }; |
| 300 | |
| 301 | static int vpa_is_registered(struct kvmppc_vpa *vpap) |
| 302 | { |
| 303 | if (vpap->update_pending) |
| 304 | return vpap->next_gpa != 0; |
| 305 | return vpap->pinned_addr != NULL; |
| 306 | } |
| 307 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 308 | static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu, |
| 309 | unsigned long flags, |
| 310 | unsigned long vcpuid, unsigned long vpa) |
| 311 | { |
| 312 | struct kvm *kvm = vcpu->kvm; |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 313 | unsigned long len, nb; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 314 | void *va; |
| 315 | struct kvm_vcpu *tvcpu; |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 316 | int err; |
| 317 | int subfunc; |
| 318 | struct kvmppc_vpa *vpap; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 319 | |
| 320 | tvcpu = kvmppc_find_vcpu(kvm, vcpuid); |
| 321 | if (!tvcpu) |
| 322 | return H_PARAMETER; |
| 323 | |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 324 | subfunc = (flags >> H_VPA_FUNC_SHIFT) & H_VPA_FUNC_MASK; |
| 325 | if (subfunc == H_VPA_REG_VPA || subfunc == H_VPA_REG_DTL || |
| 326 | subfunc == H_VPA_REG_SLB) { |
| 327 | /* Registering new area - address must be cache-line aligned */ |
| 328 | if ((vpa & (L1_CACHE_BYTES - 1)) || !vpa) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 329 | return H_PARAMETER; |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 330 | |
| 331 | /* convert logical addr to kernel addr and read length */ |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 332 | va = kvmppc_pin_guest_page(kvm, vpa, &nb); |
| 333 | if (va == NULL) |
Paul Mackerras | b2b2f16 | 2011-12-12 12:28:21 +0000 | [diff] [blame] | 334 | return H_PARAMETER; |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 335 | if (subfunc == H_VPA_REG_VPA) |
| 336 | len = ((struct reg_vpa *)va)->length.hword; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 337 | else |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 338 | len = ((struct reg_vpa *)va)->length.word; |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 339 | kvmppc_unpin_guest_page(kvm, va, vpa, false); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 340 | |
| 341 | /* Check length */ |
| 342 | if (len > nb || len < sizeof(struct reg_vpa)) |
| 343 | return H_PARAMETER; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 344 | } else { |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 345 | vpa = 0; |
| 346 | len = 0; |
| 347 | } |
| 348 | |
| 349 | err = H_PARAMETER; |
| 350 | vpap = NULL; |
| 351 | spin_lock(&tvcpu->arch.vpa_update_lock); |
| 352 | |
| 353 | switch (subfunc) { |
| 354 | case H_VPA_REG_VPA: /* register VPA */ |
| 355 | if (len < sizeof(struct lppaca)) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 356 | break; |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 357 | vpap = &tvcpu->arch.vpa; |
| 358 | err = 0; |
| 359 | break; |
| 360 | |
| 361 | case H_VPA_REG_DTL: /* register DTL */ |
| 362 | if (len < sizeof(struct dtl_entry)) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 363 | break; |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 364 | len -= len % sizeof(struct dtl_entry); |
| 365 | |
| 366 | /* Check that they have previously registered a VPA */ |
| 367 | err = H_RESOURCE; |
| 368 | if (!vpa_is_registered(&tvcpu->arch.vpa)) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 369 | break; |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 370 | |
| 371 | vpap = &tvcpu->arch.dtl; |
| 372 | err = 0; |
| 373 | break; |
| 374 | |
| 375 | case H_VPA_REG_SLB: /* register SLB shadow buffer */ |
| 376 | /* Check that they have previously registered a VPA */ |
| 377 | err = H_RESOURCE; |
| 378 | if (!vpa_is_registered(&tvcpu->arch.vpa)) |
| 379 | break; |
| 380 | |
| 381 | vpap = &tvcpu->arch.slb_shadow; |
| 382 | err = 0; |
| 383 | break; |
| 384 | |
| 385 | case H_VPA_DEREG_VPA: /* deregister VPA */ |
| 386 | /* Check they don't still have a DTL or SLB buf registered */ |
| 387 | err = H_RESOURCE; |
| 388 | if (vpa_is_registered(&tvcpu->arch.dtl) || |
| 389 | vpa_is_registered(&tvcpu->arch.slb_shadow)) |
| 390 | break; |
| 391 | |
| 392 | vpap = &tvcpu->arch.vpa; |
| 393 | err = 0; |
| 394 | break; |
| 395 | |
| 396 | case H_VPA_DEREG_DTL: /* deregister DTL */ |
| 397 | vpap = &tvcpu->arch.dtl; |
| 398 | err = 0; |
| 399 | break; |
| 400 | |
| 401 | case H_VPA_DEREG_SLB: /* deregister SLB shadow buffer */ |
| 402 | vpap = &tvcpu->arch.slb_shadow; |
| 403 | err = 0; |
| 404 | break; |
| 405 | } |
| 406 | |
| 407 | if (vpap) { |
| 408 | vpap->next_gpa = vpa; |
| 409 | vpap->len = len; |
| 410 | vpap->update_pending = 1; |
| 411 | } |
| 412 | |
| 413 | spin_unlock(&tvcpu->arch.vpa_update_lock); |
| 414 | |
| 415 | return err; |
| 416 | } |
| 417 | |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 418 | static void kvmppc_update_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *vpap) |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 419 | { |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 420 | struct kvm *kvm = vcpu->kvm; |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 421 | void *va; |
| 422 | unsigned long nb; |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 423 | unsigned long gpa; |
| 424 | |
| 425 | /* |
| 426 | * We need to pin the page pointed to by vpap->next_gpa, |
| 427 | * but we can't call kvmppc_pin_guest_page under the lock |
| 428 | * as it does get_user_pages() and down_read(). So we |
| 429 | * have to drop the lock, pin the page, then get the lock |
| 430 | * again and check that a new area didn't get registered |
| 431 | * in the meantime. |
| 432 | */ |
| 433 | for (;;) { |
| 434 | gpa = vpap->next_gpa; |
| 435 | spin_unlock(&vcpu->arch.vpa_update_lock); |
| 436 | va = NULL; |
| 437 | nb = 0; |
| 438 | if (gpa) |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 439 | va = kvmppc_pin_guest_page(kvm, gpa, &nb); |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 440 | spin_lock(&vcpu->arch.vpa_update_lock); |
| 441 | if (gpa == vpap->next_gpa) |
| 442 | break; |
| 443 | /* sigh... unpin that one and try again */ |
| 444 | if (va) |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 445 | kvmppc_unpin_guest_page(kvm, va, gpa, false); |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 446 | } |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 447 | |
| 448 | vpap->update_pending = 0; |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 449 | if (va && nb < vpap->len) { |
| 450 | /* |
| 451 | * If it's now too short, it must be that userspace |
| 452 | * has changed the mappings underlying guest memory, |
| 453 | * so unregister the region. |
| 454 | */ |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 455 | kvmppc_unpin_guest_page(kvm, va, gpa, false); |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 456 | va = NULL; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 457 | } |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 458 | if (vpap->pinned_addr) |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 459 | kvmppc_unpin_guest_page(kvm, vpap->pinned_addr, vpap->gpa, |
| 460 | vpap->dirty); |
| 461 | vpap->gpa = gpa; |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 462 | vpap->pinned_addr = va; |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 463 | vpap->dirty = false; |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 464 | if (va) |
| 465 | vpap->pinned_end = va + vpap->len; |
| 466 | } |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 467 | |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 468 | static void kvmppc_update_vpas(struct kvm_vcpu *vcpu) |
| 469 | { |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 470 | if (!(vcpu->arch.vpa.update_pending || |
| 471 | vcpu->arch.slb_shadow.update_pending || |
| 472 | vcpu->arch.dtl.update_pending)) |
| 473 | return; |
| 474 | |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 475 | spin_lock(&vcpu->arch.vpa_update_lock); |
| 476 | if (vcpu->arch.vpa.update_pending) { |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 477 | kvmppc_update_vpa(vcpu, &vcpu->arch.vpa); |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 478 | if (vcpu->arch.vpa.pinned_addr) |
| 479 | init_vpa(vcpu, vcpu->arch.vpa.pinned_addr); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 480 | } |
| 481 | if (vcpu->arch.dtl.update_pending) { |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 482 | kvmppc_update_vpa(vcpu, &vcpu->arch.dtl); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 483 | vcpu->arch.dtl_ptr = vcpu->arch.dtl.pinned_addr; |
| 484 | vcpu->arch.dtl_index = 0; |
| 485 | } |
| 486 | if (vcpu->arch.slb_shadow.update_pending) |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 487 | kvmppc_update_vpa(vcpu, &vcpu->arch.slb_shadow); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 488 | spin_unlock(&vcpu->arch.vpa_update_lock); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 491 | /* |
| 492 | * Return the accumulated stolen time for the vcore up until `now'. |
| 493 | * The caller should hold the vcore lock. |
| 494 | */ |
| 495 | static u64 vcore_stolen_time(struct kvmppc_vcore *vc, u64 now) |
| 496 | { |
| 497 | u64 p; |
| 498 | |
| 499 | /* |
| 500 | * If we are the task running the vcore, then since we hold |
| 501 | * the vcore lock, we can't be preempted, so stolen_tb/preempt_tb |
| 502 | * can't be updated, so we don't need the tbacct_lock. |
| 503 | * If the vcore is inactive, it can't become active (since we |
| 504 | * hold the vcore lock), so the vcpu load/put functions won't |
| 505 | * update stolen_tb/preempt_tb, and we don't need tbacct_lock. |
| 506 | */ |
| 507 | if (vc->vcore_state != VCORE_INACTIVE && |
| 508 | vc->runner->arch.run_task != current) { |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 509 | spin_lock_irq(&vc->runner->arch.tbacct_lock); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 510 | p = vc->stolen_tb; |
| 511 | if (vc->preempt_tb != TB_NIL) |
| 512 | p += now - vc->preempt_tb; |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 513 | spin_unlock_irq(&vc->runner->arch.tbacct_lock); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 514 | } else { |
| 515 | p = vc->stolen_tb; |
| 516 | } |
| 517 | return p; |
| 518 | } |
| 519 | |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 520 | static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, |
| 521 | struct kvmppc_vcore *vc) |
| 522 | { |
| 523 | struct dtl_entry *dt; |
| 524 | struct lppaca *vpa; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 525 | unsigned long stolen; |
| 526 | unsigned long core_stolen; |
| 527 | u64 now; |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 528 | |
| 529 | dt = vcpu->arch.dtl_ptr; |
| 530 | vpa = vcpu->arch.vpa.pinned_addr; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 531 | now = mftb(); |
| 532 | core_stolen = vcore_stolen_time(vc, now); |
| 533 | stolen = core_stolen - vcpu->arch.stolen_logged; |
| 534 | vcpu->arch.stolen_logged = core_stolen; |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 535 | spin_lock_irq(&vcpu->arch.tbacct_lock); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 536 | stolen += vcpu->arch.busy_stolen; |
| 537 | vcpu->arch.busy_stolen = 0; |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 538 | spin_unlock_irq(&vcpu->arch.tbacct_lock); |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 539 | if (!dt || !vpa) |
| 540 | return; |
| 541 | memset(dt, 0, sizeof(struct dtl_entry)); |
| 542 | dt->dispatch_reason = 7; |
| 543 | dt->processor_id = vc->pcpu + vcpu->arch.ptid; |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 544 | dt->timebase = now + vc->tb_offset; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 545 | dt->enqueue_to_dispatch_time = stolen; |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 546 | dt->srr0 = kvmppc_get_pc(vcpu); |
| 547 | dt->srr1 = vcpu->arch.shregs.msr; |
| 548 | ++dt; |
| 549 | if (dt == vcpu->arch.dtl.pinned_end) |
| 550 | dt = vcpu->arch.dtl.pinned_addr; |
| 551 | vcpu->arch.dtl_ptr = dt; |
| 552 | /* order writing *dt vs. writing vpa->dtl_idx */ |
| 553 | smp_wmb(); |
| 554 | vpa->dtl_idx = ++vcpu->arch.dtl_index; |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 555 | vcpu->arch.dtl.dirty = true; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) |
| 559 | { |
| 560 | unsigned long req = kvmppc_get_gpr(vcpu, 3); |
| 561 | unsigned long target, ret = H_SUCCESS; |
| 562 | struct kvm_vcpu *tvcpu; |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 563 | int idx, rc; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 564 | |
| 565 | switch (req) { |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 566 | case H_ENTER: |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 567 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 568 | ret = kvmppc_virtmode_h_enter(vcpu, kvmppc_get_gpr(vcpu, 4), |
| 569 | kvmppc_get_gpr(vcpu, 5), |
| 570 | kvmppc_get_gpr(vcpu, 6), |
| 571 | kvmppc_get_gpr(vcpu, 7)); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 572 | srcu_read_unlock(&vcpu->kvm->srcu, idx); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 573 | break; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 574 | case H_CEDE: |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 575 | break; |
| 576 | case H_PROD: |
| 577 | target = kvmppc_get_gpr(vcpu, 4); |
| 578 | tvcpu = kvmppc_find_vcpu(vcpu->kvm, target); |
| 579 | if (!tvcpu) { |
| 580 | ret = H_PARAMETER; |
| 581 | break; |
| 582 | } |
| 583 | tvcpu->arch.prodded = 1; |
| 584 | smp_mb(); |
| 585 | if (vcpu->arch.ceded) { |
| 586 | if (waitqueue_active(&vcpu->wq)) { |
| 587 | wake_up_interruptible(&vcpu->wq); |
| 588 | vcpu->stat.halt_wakeup++; |
| 589 | } |
| 590 | } |
| 591 | break; |
| 592 | case H_CONFER: |
Paul Mackerras | 42d7604 | 2013-09-06 13:23:21 +1000 | [diff] [blame] | 593 | target = kvmppc_get_gpr(vcpu, 4); |
| 594 | if (target == -1) |
| 595 | break; |
| 596 | tvcpu = kvmppc_find_vcpu(vcpu->kvm, target); |
| 597 | if (!tvcpu) { |
| 598 | ret = H_PARAMETER; |
| 599 | break; |
| 600 | } |
| 601 | kvm_vcpu_yield_to(tvcpu); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 602 | break; |
| 603 | case H_REGISTER_VPA: |
| 604 | ret = do_h_register_vpa(vcpu, kvmppc_get_gpr(vcpu, 4), |
| 605 | kvmppc_get_gpr(vcpu, 5), |
| 606 | kvmppc_get_gpr(vcpu, 6)); |
| 607 | break; |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 608 | case H_RTAS: |
| 609 | if (list_empty(&vcpu->kvm->arch.rtas_tokens)) |
| 610 | return RESUME_HOST; |
| 611 | |
Paul Mackerras | c943809 | 2013-11-16 17:46:05 +1100 | [diff] [blame] | 612 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 613 | rc = kvmppc_rtas_hcall(vcpu); |
Paul Mackerras | c943809 | 2013-11-16 17:46:05 +1100 | [diff] [blame] | 614 | srcu_read_unlock(&vcpu->kvm->srcu, idx); |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 615 | |
| 616 | if (rc == -ENOENT) |
| 617 | return RESUME_HOST; |
| 618 | else if (rc == 0) |
| 619 | break; |
| 620 | |
| 621 | /* Send the error out to userspace via KVM_RUN */ |
| 622 | return rc; |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 623 | |
| 624 | case H_XIRR: |
| 625 | case H_CPPR: |
| 626 | case H_EOI: |
| 627 | case H_IPI: |
Paul Mackerras | 8e44ddc | 2013-05-23 15:42:21 +0000 | [diff] [blame] | 628 | case H_IPOLL: |
| 629 | case H_XIRR_X: |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 630 | if (kvmppc_xics_enabled(vcpu)) { |
| 631 | ret = kvmppc_xics_hcall(vcpu, req); |
| 632 | break; |
| 633 | } /* fallthrough */ |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 634 | default: |
| 635 | return RESUME_HOST; |
| 636 | } |
| 637 | kvmppc_set_gpr(vcpu, 3, ret); |
| 638 | vcpu->arch.hcall_needed = 0; |
| 639 | return RESUME_GUEST; |
| 640 | } |
| 641 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 642 | static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 643 | struct task_struct *tsk) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 644 | { |
| 645 | int r = RESUME_HOST; |
| 646 | |
| 647 | vcpu->stat.sum_exits++; |
| 648 | |
| 649 | run->exit_reason = KVM_EXIT_UNKNOWN; |
| 650 | run->ready_for_interrupt_injection = 1; |
| 651 | switch (vcpu->arch.trap) { |
| 652 | /* We're good on these - the host merely wanted to get our attention */ |
| 653 | case BOOK3S_INTERRUPT_HV_DECREMENTER: |
| 654 | vcpu->stat.dec_exits++; |
| 655 | r = RESUME_GUEST; |
| 656 | break; |
| 657 | case BOOK3S_INTERRUPT_EXTERNAL: |
Paul Mackerras | 5d00f66 | 2014-01-08 21:25:28 +1100 | [diff] [blame] | 658 | case BOOK3S_INTERRUPT_H_DOORBELL: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 659 | vcpu->stat.ext_intr_exits++; |
| 660 | r = RESUME_GUEST; |
| 661 | break; |
| 662 | case BOOK3S_INTERRUPT_PERFMON: |
| 663 | r = RESUME_GUEST; |
| 664 | break; |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 665 | case BOOK3S_INTERRUPT_MACHINE_CHECK: |
| 666 | /* |
| 667 | * Deliver a machine check interrupt to the guest. |
| 668 | * We have to do this, even if the host has handled the |
| 669 | * machine check, because machine checks use SRR0/1 and |
| 670 | * the interrupt might have trashed guest state in them. |
| 671 | */ |
| 672 | kvmppc_book3s_queue_irqprio(vcpu, |
| 673 | BOOK3S_INTERRUPT_MACHINE_CHECK); |
| 674 | r = RESUME_GUEST; |
| 675 | break; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 676 | case BOOK3S_INTERRUPT_PROGRAM: |
| 677 | { |
| 678 | ulong flags; |
| 679 | /* |
| 680 | * Normally program interrupts are delivered directly |
| 681 | * to the guest by the hardware, but we can get here |
| 682 | * as a result of a hypervisor emulation interrupt |
| 683 | * (e40) getting turned into a 700 by BML RTAS. |
| 684 | */ |
| 685 | flags = vcpu->arch.shregs.msr & 0x1f0000ull; |
| 686 | kvmppc_core_queue_program(vcpu, flags); |
| 687 | r = RESUME_GUEST; |
| 688 | break; |
| 689 | } |
| 690 | case BOOK3S_INTERRUPT_SYSCALL: |
| 691 | { |
| 692 | /* hcall - punt to userspace */ |
| 693 | int i; |
| 694 | |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 695 | /* hypercall with MSR_PR has already been handled in rmode, |
| 696 | * and never reaches here. |
| 697 | */ |
| 698 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 699 | run->papr_hcall.nr = kvmppc_get_gpr(vcpu, 3); |
| 700 | for (i = 0; i < 9; ++i) |
| 701 | run->papr_hcall.args[i] = kvmppc_get_gpr(vcpu, 4 + i); |
| 702 | run->exit_reason = KVM_EXIT_PAPR_HCALL; |
| 703 | vcpu->arch.hcall_needed = 1; |
| 704 | r = RESUME_HOST; |
| 705 | break; |
| 706 | } |
| 707 | /* |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 708 | * We get these next two if the guest accesses a page which it thinks |
| 709 | * it has mapped but which is not actually present, either because |
| 710 | * it is for an emulated I/O device or because the corresonding |
| 711 | * host page has been paged out. Any other HDSI/HISI interrupts |
| 712 | * have been handled already. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 713 | */ |
| 714 | case BOOK3S_INTERRUPT_H_DATA_STORAGE: |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 715 | r = RESUME_PAGE_FAULT; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 716 | break; |
| 717 | case BOOK3S_INTERRUPT_H_INST_STORAGE: |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 718 | vcpu->arch.fault_dar = kvmppc_get_pc(vcpu); |
| 719 | vcpu->arch.fault_dsisr = 0; |
| 720 | r = RESUME_PAGE_FAULT; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 721 | break; |
| 722 | /* |
| 723 | * This occurs if the guest executes an illegal instruction. |
| 724 | * We just generate a program interrupt to the guest, since |
| 725 | * we don't emulate any guest instructions at this stage. |
| 726 | */ |
| 727 | case BOOK3S_INTERRUPT_H_EMUL_ASSIST: |
Michael Ellerman | bd3048b | 2014-01-08 21:25:23 +1100 | [diff] [blame] | 728 | kvmppc_core_queue_program(vcpu, SRR1_PROGILL); |
| 729 | r = RESUME_GUEST; |
| 730 | break; |
| 731 | /* |
| 732 | * This occurs if the guest (kernel or userspace), does something that |
| 733 | * is prohibited by HFSCR. We just generate a program interrupt to |
| 734 | * the guest. |
| 735 | */ |
| 736 | case BOOK3S_INTERRUPT_H_FAC_UNAVAIL: |
| 737 | kvmppc_core_queue_program(vcpu, SRR1_PROGILL); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 738 | r = RESUME_GUEST; |
| 739 | break; |
| 740 | default: |
| 741 | kvmppc_dump_regs(vcpu); |
| 742 | printk(KERN_EMERG "trap=0x%x | pc=0x%lx | msr=0x%llx\n", |
| 743 | vcpu->arch.trap, kvmppc_get_pc(vcpu), |
| 744 | vcpu->arch.shregs.msr); |
Paul Mackerras | f3271d4 | 2013-09-20 14:52:41 +1000 | [diff] [blame] | 745 | run->hw.hardware_exit_reason = vcpu->arch.trap; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 746 | r = RESUME_HOST; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 747 | break; |
| 748 | } |
| 749 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 750 | return r; |
| 751 | } |
| 752 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 753 | static int kvm_arch_vcpu_ioctl_get_sregs_hv(struct kvm_vcpu *vcpu, |
| 754 | struct kvm_sregs *sregs) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 755 | { |
| 756 | int i; |
| 757 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 758 | memset(sregs, 0, sizeof(struct kvm_sregs)); |
Aneesh Kumar K.V | 8791644 | 2013-08-22 17:08:39 +0530 | [diff] [blame] | 759 | sregs->pvr = vcpu->arch.pvr; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 760 | for (i = 0; i < vcpu->arch.slb_max; i++) { |
| 761 | sregs->u.s.ppc64.slb[i].slbe = vcpu->arch.slb[i].orige; |
| 762 | sregs->u.s.ppc64.slb[i].slbv = vcpu->arch.slb[i].origv; |
| 763 | } |
| 764 | |
| 765 | return 0; |
| 766 | } |
| 767 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 768 | static int kvm_arch_vcpu_ioctl_set_sregs_hv(struct kvm_vcpu *vcpu, |
| 769 | struct kvm_sregs *sregs) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 770 | { |
| 771 | int i, j; |
| 772 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 773 | kvmppc_set_pvr_hv(vcpu, sregs->pvr); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 774 | |
| 775 | j = 0; |
| 776 | for (i = 0; i < vcpu->arch.slb_nr; i++) { |
| 777 | if (sregs->u.s.ppc64.slb[i].slbe & SLB_ESID_V) { |
| 778 | vcpu->arch.slb[j].orige = sregs->u.s.ppc64.slb[i].slbe; |
| 779 | vcpu->arch.slb[j].origv = sregs->u.s.ppc64.slb[i].slbv; |
| 780 | ++j; |
| 781 | } |
| 782 | } |
| 783 | vcpu->arch.slb_max = j; |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 788 | static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 new_lpcr) |
| 789 | { |
| 790 | struct kvmppc_vcore *vc = vcpu->arch.vcore; |
| 791 | u64 mask; |
| 792 | |
| 793 | spin_lock(&vc->lock); |
| 794 | /* |
Anton Blanchard | d682916 | 2014-01-08 21:25:30 +1100 | [diff] [blame] | 795 | * If ILE (interrupt little-endian) has changed, update the |
| 796 | * MSR_LE bit in the intr_msr for each vcpu in this vcore. |
| 797 | */ |
| 798 | if ((new_lpcr & LPCR_ILE) != (vc->lpcr & LPCR_ILE)) { |
| 799 | struct kvm *kvm = vcpu->kvm; |
| 800 | struct kvm_vcpu *vcpu; |
| 801 | int i; |
| 802 | |
| 803 | mutex_lock(&kvm->lock); |
| 804 | kvm_for_each_vcpu(i, vcpu, kvm) { |
| 805 | if (vcpu->arch.vcore != vc) |
| 806 | continue; |
| 807 | if (new_lpcr & LPCR_ILE) |
| 808 | vcpu->arch.intr_msr |= MSR_LE; |
| 809 | else |
| 810 | vcpu->arch.intr_msr &= ~MSR_LE; |
| 811 | } |
| 812 | mutex_unlock(&kvm->lock); |
| 813 | } |
| 814 | |
| 815 | /* |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 816 | * Userspace can only modify DPFD (default prefetch depth), |
| 817 | * ILE (interrupt little-endian) and TC (translation control). |
Paul Mackerras | e0622bd | 2014-01-08 21:25:27 +1100 | [diff] [blame] | 818 | * On POWER8 userspace can also modify AIL (alt. interrupt loc.) |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 819 | */ |
| 820 | mask = LPCR_DPFD | LPCR_ILE | LPCR_TC; |
Paul Mackerras | e0622bd | 2014-01-08 21:25:27 +1100 | [diff] [blame] | 821 | if (cpu_has_feature(CPU_FTR_ARCH_207S)) |
| 822 | mask |= LPCR_AIL; |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 823 | vc->lpcr = (vc->lpcr & ~mask) | (new_lpcr & mask); |
| 824 | spin_unlock(&vc->lock); |
| 825 | } |
| 826 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 827 | static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, |
| 828 | union kvmppc_one_reg *val) |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 829 | { |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 830 | int r = 0; |
| 831 | long int i; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 832 | |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 833 | switch (id) { |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 834 | case KVM_REG_PPC_HIOR: |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 835 | *val = get_reg_val(id, 0); |
| 836 | break; |
| 837 | case KVM_REG_PPC_DABR: |
| 838 | *val = get_reg_val(id, vcpu->arch.dabr); |
| 839 | break; |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 840 | case KVM_REG_PPC_DABRX: |
| 841 | *val = get_reg_val(id, vcpu->arch.dabrx); |
| 842 | break; |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 843 | case KVM_REG_PPC_DSCR: |
| 844 | *val = get_reg_val(id, vcpu->arch.dscr); |
| 845 | break; |
| 846 | case KVM_REG_PPC_PURR: |
| 847 | *val = get_reg_val(id, vcpu->arch.purr); |
| 848 | break; |
| 849 | case KVM_REG_PPC_SPURR: |
| 850 | *val = get_reg_val(id, vcpu->arch.spurr); |
| 851 | break; |
| 852 | case KVM_REG_PPC_AMR: |
| 853 | *val = get_reg_val(id, vcpu->arch.amr); |
| 854 | break; |
| 855 | case KVM_REG_PPC_UAMOR: |
| 856 | *val = get_reg_val(id, vcpu->arch.uamor); |
| 857 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 858 | case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCRS: |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 859 | i = id - KVM_REG_PPC_MMCR0; |
| 860 | *val = get_reg_val(id, vcpu->arch.mmcr[i]); |
| 861 | break; |
| 862 | case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8: |
| 863 | i = id - KVM_REG_PPC_PMC1; |
| 864 | *val = get_reg_val(id, vcpu->arch.pmc[i]); |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 865 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 866 | case KVM_REG_PPC_SPMC1 ... KVM_REG_PPC_SPMC2: |
| 867 | i = id - KVM_REG_PPC_SPMC1; |
| 868 | *val = get_reg_val(id, vcpu->arch.spmc[i]); |
| 869 | break; |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 870 | case KVM_REG_PPC_SIAR: |
| 871 | *val = get_reg_val(id, vcpu->arch.siar); |
| 872 | break; |
| 873 | case KVM_REG_PPC_SDAR: |
| 874 | *val = get_reg_val(id, vcpu->arch.sdar); |
| 875 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 876 | case KVM_REG_PPC_SIER: |
| 877 | *val = get_reg_val(id, vcpu->arch.sier); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 878 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 879 | case KVM_REG_PPC_IAMR: |
| 880 | *val = get_reg_val(id, vcpu->arch.iamr); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 881 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 882 | case KVM_REG_PPC_FSCR: |
| 883 | *val = get_reg_val(id, vcpu->arch.fscr); |
| 884 | break; |
| 885 | case KVM_REG_PPC_PSPB: |
| 886 | *val = get_reg_val(id, vcpu->arch.pspb); |
| 887 | break; |
| 888 | case KVM_REG_PPC_EBBHR: |
| 889 | *val = get_reg_val(id, vcpu->arch.ebbhr); |
| 890 | break; |
| 891 | case KVM_REG_PPC_EBBRR: |
| 892 | *val = get_reg_val(id, vcpu->arch.ebbrr); |
| 893 | break; |
| 894 | case KVM_REG_PPC_BESCR: |
| 895 | *val = get_reg_val(id, vcpu->arch.bescr); |
| 896 | break; |
| 897 | case KVM_REG_PPC_TAR: |
| 898 | *val = get_reg_val(id, vcpu->arch.tar); |
| 899 | break; |
| 900 | case KVM_REG_PPC_DPDES: |
| 901 | *val = get_reg_val(id, vcpu->arch.vcore->dpdes); |
| 902 | break; |
| 903 | case KVM_REG_PPC_DAWR: |
| 904 | *val = get_reg_val(id, vcpu->arch.dawr); |
| 905 | break; |
| 906 | case KVM_REG_PPC_DAWRX: |
| 907 | *val = get_reg_val(id, vcpu->arch.dawrx); |
| 908 | break; |
| 909 | case KVM_REG_PPC_CIABR: |
| 910 | *val = get_reg_val(id, vcpu->arch.ciabr); |
| 911 | break; |
| 912 | case KVM_REG_PPC_IC: |
| 913 | *val = get_reg_val(id, vcpu->arch.ic); |
| 914 | break; |
| 915 | case KVM_REG_PPC_VTB: |
| 916 | *val = get_reg_val(id, vcpu->arch.vtb); |
| 917 | break; |
| 918 | case KVM_REG_PPC_CSIGR: |
| 919 | *val = get_reg_val(id, vcpu->arch.csigr); |
| 920 | break; |
| 921 | case KVM_REG_PPC_TACR: |
| 922 | *val = get_reg_val(id, vcpu->arch.tacr); |
| 923 | break; |
| 924 | case KVM_REG_PPC_TCSCR: |
| 925 | *val = get_reg_val(id, vcpu->arch.tcscr); |
| 926 | break; |
| 927 | case KVM_REG_PPC_PID: |
| 928 | *val = get_reg_val(id, vcpu->arch.pid); |
| 929 | break; |
| 930 | case KVM_REG_PPC_ACOP: |
| 931 | *val = get_reg_val(id, vcpu->arch.acop); |
| 932 | break; |
| 933 | case KVM_REG_PPC_WORT: |
| 934 | *val = get_reg_val(id, vcpu->arch.wort); |
| 935 | break; |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 936 | case KVM_REG_PPC_VPA_ADDR: |
| 937 | spin_lock(&vcpu->arch.vpa_update_lock); |
| 938 | *val = get_reg_val(id, vcpu->arch.vpa.next_gpa); |
| 939 | spin_unlock(&vcpu->arch.vpa_update_lock); |
| 940 | break; |
| 941 | case KVM_REG_PPC_VPA_SLB: |
| 942 | spin_lock(&vcpu->arch.vpa_update_lock); |
| 943 | val->vpaval.addr = vcpu->arch.slb_shadow.next_gpa; |
| 944 | val->vpaval.length = vcpu->arch.slb_shadow.len; |
| 945 | spin_unlock(&vcpu->arch.vpa_update_lock); |
| 946 | break; |
| 947 | case KVM_REG_PPC_VPA_DTL: |
| 948 | spin_lock(&vcpu->arch.vpa_update_lock); |
| 949 | val->vpaval.addr = vcpu->arch.dtl.next_gpa; |
| 950 | val->vpaval.length = vcpu->arch.dtl.len; |
| 951 | spin_unlock(&vcpu->arch.vpa_update_lock); |
| 952 | break; |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 953 | case KVM_REG_PPC_TB_OFFSET: |
| 954 | *val = get_reg_val(id, vcpu->arch.vcore->tb_offset); |
| 955 | break; |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 956 | case KVM_REG_PPC_LPCR: |
| 957 | *val = get_reg_val(id, vcpu->arch.vcore->lpcr); |
| 958 | break; |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 959 | case KVM_REG_PPC_PPR: |
| 960 | *val = get_reg_val(id, vcpu->arch.ppr); |
| 961 | break; |
Michael Neuling | a7d80d0 | 2014-03-25 10:47:03 +1100 | [diff] [blame] | 962 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 963 | case KVM_REG_PPC_TFHAR: |
| 964 | *val = get_reg_val(id, vcpu->arch.tfhar); |
| 965 | break; |
| 966 | case KVM_REG_PPC_TFIAR: |
| 967 | *val = get_reg_val(id, vcpu->arch.tfiar); |
| 968 | break; |
| 969 | case KVM_REG_PPC_TEXASR: |
| 970 | *val = get_reg_val(id, vcpu->arch.texasr); |
| 971 | break; |
| 972 | case KVM_REG_PPC_TM_GPR0 ... KVM_REG_PPC_TM_GPR31: |
| 973 | i = id - KVM_REG_PPC_TM_GPR0; |
| 974 | *val = get_reg_val(id, vcpu->arch.gpr_tm[i]); |
| 975 | break; |
| 976 | case KVM_REG_PPC_TM_VSR0 ... KVM_REG_PPC_TM_VSR63: |
| 977 | { |
| 978 | int j; |
| 979 | i = id - KVM_REG_PPC_TM_VSR0; |
| 980 | if (i < 32) |
| 981 | for (j = 0; j < TS_FPRWIDTH; j++) |
| 982 | val->vsxval[j] = vcpu->arch.fp_tm.fpr[i][j]; |
| 983 | else { |
| 984 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 985 | val->vval = vcpu->arch.vr_tm.vr[i-32]; |
| 986 | else |
| 987 | r = -ENXIO; |
| 988 | } |
| 989 | break; |
| 990 | } |
| 991 | case KVM_REG_PPC_TM_CR: |
| 992 | *val = get_reg_val(id, vcpu->arch.cr_tm); |
| 993 | break; |
| 994 | case KVM_REG_PPC_TM_LR: |
| 995 | *val = get_reg_val(id, vcpu->arch.lr_tm); |
| 996 | break; |
| 997 | case KVM_REG_PPC_TM_CTR: |
| 998 | *val = get_reg_val(id, vcpu->arch.ctr_tm); |
| 999 | break; |
| 1000 | case KVM_REG_PPC_TM_FPSCR: |
| 1001 | *val = get_reg_val(id, vcpu->arch.fp_tm.fpscr); |
| 1002 | break; |
| 1003 | case KVM_REG_PPC_TM_AMR: |
| 1004 | *val = get_reg_val(id, vcpu->arch.amr_tm); |
| 1005 | break; |
| 1006 | case KVM_REG_PPC_TM_PPR: |
| 1007 | *val = get_reg_val(id, vcpu->arch.ppr_tm); |
| 1008 | break; |
| 1009 | case KVM_REG_PPC_TM_VRSAVE: |
| 1010 | *val = get_reg_val(id, vcpu->arch.vrsave_tm); |
| 1011 | break; |
| 1012 | case KVM_REG_PPC_TM_VSCR: |
| 1013 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 1014 | *val = get_reg_val(id, vcpu->arch.vr_tm.vscr.u[3]); |
| 1015 | else |
| 1016 | r = -ENXIO; |
| 1017 | break; |
| 1018 | case KVM_REG_PPC_TM_DSCR: |
| 1019 | *val = get_reg_val(id, vcpu->arch.dscr_tm); |
| 1020 | break; |
| 1021 | case KVM_REG_PPC_TM_TAR: |
| 1022 | *val = get_reg_val(id, vcpu->arch.tar_tm); |
| 1023 | break; |
| 1024 | #endif |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 1025 | case KVM_REG_PPC_ARCH_COMPAT: |
| 1026 | *val = get_reg_val(id, vcpu->arch.vcore->arch_compat); |
| 1027 | break; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1028 | default: |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1029 | r = -EINVAL; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1030 | break; |
| 1031 | } |
| 1032 | |
| 1033 | return r; |
| 1034 | } |
| 1035 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1036 | static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, |
| 1037 | union kvmppc_one_reg *val) |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1038 | { |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1039 | int r = 0; |
| 1040 | long int i; |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 1041 | unsigned long addr, len; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1042 | |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1043 | switch (id) { |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1044 | case KVM_REG_PPC_HIOR: |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1045 | /* Only allow this to be set to zero */ |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1046 | if (set_reg_val(id, *val)) |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1047 | r = -EINVAL; |
| 1048 | break; |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1049 | case KVM_REG_PPC_DABR: |
| 1050 | vcpu->arch.dabr = set_reg_val(id, *val); |
| 1051 | break; |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 1052 | case KVM_REG_PPC_DABRX: |
| 1053 | vcpu->arch.dabrx = set_reg_val(id, *val) & ~DABRX_HYP; |
| 1054 | break; |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1055 | case KVM_REG_PPC_DSCR: |
| 1056 | vcpu->arch.dscr = set_reg_val(id, *val); |
| 1057 | break; |
| 1058 | case KVM_REG_PPC_PURR: |
| 1059 | vcpu->arch.purr = set_reg_val(id, *val); |
| 1060 | break; |
| 1061 | case KVM_REG_PPC_SPURR: |
| 1062 | vcpu->arch.spurr = set_reg_val(id, *val); |
| 1063 | break; |
| 1064 | case KVM_REG_PPC_AMR: |
| 1065 | vcpu->arch.amr = set_reg_val(id, *val); |
| 1066 | break; |
| 1067 | case KVM_REG_PPC_UAMOR: |
| 1068 | vcpu->arch.uamor = set_reg_val(id, *val); |
| 1069 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1070 | case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCRS: |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1071 | i = id - KVM_REG_PPC_MMCR0; |
| 1072 | vcpu->arch.mmcr[i] = set_reg_val(id, *val); |
| 1073 | break; |
| 1074 | case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8: |
| 1075 | i = id - KVM_REG_PPC_PMC1; |
| 1076 | vcpu->arch.pmc[i] = set_reg_val(id, *val); |
| 1077 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1078 | case KVM_REG_PPC_SPMC1 ... KVM_REG_PPC_SPMC2: |
| 1079 | i = id - KVM_REG_PPC_SPMC1; |
| 1080 | vcpu->arch.spmc[i] = set_reg_val(id, *val); |
| 1081 | break; |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 1082 | case KVM_REG_PPC_SIAR: |
| 1083 | vcpu->arch.siar = set_reg_val(id, *val); |
| 1084 | break; |
| 1085 | case KVM_REG_PPC_SDAR: |
| 1086 | vcpu->arch.sdar = set_reg_val(id, *val); |
| 1087 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1088 | case KVM_REG_PPC_SIER: |
| 1089 | vcpu->arch.sier = set_reg_val(id, *val); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 1090 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1091 | case KVM_REG_PPC_IAMR: |
| 1092 | vcpu->arch.iamr = set_reg_val(id, *val); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 1093 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1094 | case KVM_REG_PPC_FSCR: |
| 1095 | vcpu->arch.fscr = set_reg_val(id, *val); |
| 1096 | break; |
| 1097 | case KVM_REG_PPC_PSPB: |
| 1098 | vcpu->arch.pspb = set_reg_val(id, *val); |
| 1099 | break; |
| 1100 | case KVM_REG_PPC_EBBHR: |
| 1101 | vcpu->arch.ebbhr = set_reg_val(id, *val); |
| 1102 | break; |
| 1103 | case KVM_REG_PPC_EBBRR: |
| 1104 | vcpu->arch.ebbrr = set_reg_val(id, *val); |
| 1105 | break; |
| 1106 | case KVM_REG_PPC_BESCR: |
| 1107 | vcpu->arch.bescr = set_reg_val(id, *val); |
| 1108 | break; |
| 1109 | case KVM_REG_PPC_TAR: |
| 1110 | vcpu->arch.tar = set_reg_val(id, *val); |
| 1111 | break; |
| 1112 | case KVM_REG_PPC_DPDES: |
| 1113 | vcpu->arch.vcore->dpdes = set_reg_val(id, *val); |
| 1114 | break; |
| 1115 | case KVM_REG_PPC_DAWR: |
| 1116 | vcpu->arch.dawr = set_reg_val(id, *val); |
| 1117 | break; |
| 1118 | case KVM_REG_PPC_DAWRX: |
| 1119 | vcpu->arch.dawrx = set_reg_val(id, *val) & ~DAWRX_HYP; |
| 1120 | break; |
| 1121 | case KVM_REG_PPC_CIABR: |
| 1122 | vcpu->arch.ciabr = set_reg_val(id, *val); |
| 1123 | /* Don't allow setting breakpoints in hypervisor code */ |
| 1124 | if ((vcpu->arch.ciabr & CIABR_PRIV) == CIABR_PRIV_HYPER) |
| 1125 | vcpu->arch.ciabr &= ~CIABR_PRIV; /* disable */ |
| 1126 | break; |
| 1127 | case KVM_REG_PPC_IC: |
| 1128 | vcpu->arch.ic = set_reg_val(id, *val); |
| 1129 | break; |
| 1130 | case KVM_REG_PPC_VTB: |
| 1131 | vcpu->arch.vtb = set_reg_val(id, *val); |
| 1132 | break; |
| 1133 | case KVM_REG_PPC_CSIGR: |
| 1134 | vcpu->arch.csigr = set_reg_val(id, *val); |
| 1135 | break; |
| 1136 | case KVM_REG_PPC_TACR: |
| 1137 | vcpu->arch.tacr = set_reg_val(id, *val); |
| 1138 | break; |
| 1139 | case KVM_REG_PPC_TCSCR: |
| 1140 | vcpu->arch.tcscr = set_reg_val(id, *val); |
| 1141 | break; |
| 1142 | case KVM_REG_PPC_PID: |
| 1143 | vcpu->arch.pid = set_reg_val(id, *val); |
| 1144 | break; |
| 1145 | case KVM_REG_PPC_ACOP: |
| 1146 | vcpu->arch.acop = set_reg_val(id, *val); |
| 1147 | break; |
| 1148 | case KVM_REG_PPC_WORT: |
| 1149 | vcpu->arch.wort = set_reg_val(id, *val); |
| 1150 | break; |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 1151 | case KVM_REG_PPC_VPA_ADDR: |
| 1152 | addr = set_reg_val(id, *val); |
| 1153 | r = -EINVAL; |
| 1154 | if (!addr && (vcpu->arch.slb_shadow.next_gpa || |
| 1155 | vcpu->arch.dtl.next_gpa)) |
| 1156 | break; |
| 1157 | r = set_vpa(vcpu, &vcpu->arch.vpa, addr, sizeof(struct lppaca)); |
| 1158 | break; |
| 1159 | case KVM_REG_PPC_VPA_SLB: |
| 1160 | addr = val->vpaval.addr; |
| 1161 | len = val->vpaval.length; |
| 1162 | r = -EINVAL; |
| 1163 | if (addr && !vcpu->arch.vpa.next_gpa) |
| 1164 | break; |
| 1165 | r = set_vpa(vcpu, &vcpu->arch.slb_shadow, addr, len); |
| 1166 | break; |
| 1167 | case KVM_REG_PPC_VPA_DTL: |
| 1168 | addr = val->vpaval.addr; |
| 1169 | len = val->vpaval.length; |
| 1170 | r = -EINVAL; |
Paul Mackerras | 9f8c8c7 | 2012-10-15 01:18:37 +0000 | [diff] [blame] | 1171 | if (addr && (len < sizeof(struct dtl_entry) || |
| 1172 | !vcpu->arch.vpa.next_gpa)) |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 1173 | break; |
| 1174 | len -= len % sizeof(struct dtl_entry); |
| 1175 | r = set_vpa(vcpu, &vcpu->arch.dtl, addr, len); |
| 1176 | break; |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 1177 | case KVM_REG_PPC_TB_OFFSET: |
| 1178 | /* round up to multiple of 2^24 */ |
| 1179 | vcpu->arch.vcore->tb_offset = |
| 1180 | ALIGN(set_reg_val(id, *val), 1UL << 24); |
| 1181 | break; |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 1182 | case KVM_REG_PPC_LPCR: |
| 1183 | kvmppc_set_lpcr(vcpu, set_reg_val(id, *val)); |
| 1184 | break; |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 1185 | case KVM_REG_PPC_PPR: |
| 1186 | vcpu->arch.ppr = set_reg_val(id, *val); |
| 1187 | break; |
Michael Neuling | a7d80d0 | 2014-03-25 10:47:03 +1100 | [diff] [blame] | 1188 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 1189 | case KVM_REG_PPC_TFHAR: |
| 1190 | vcpu->arch.tfhar = set_reg_val(id, *val); |
| 1191 | break; |
| 1192 | case KVM_REG_PPC_TFIAR: |
| 1193 | vcpu->arch.tfiar = set_reg_val(id, *val); |
| 1194 | break; |
| 1195 | case KVM_REG_PPC_TEXASR: |
| 1196 | vcpu->arch.texasr = set_reg_val(id, *val); |
| 1197 | break; |
| 1198 | case KVM_REG_PPC_TM_GPR0 ... KVM_REG_PPC_TM_GPR31: |
| 1199 | i = id - KVM_REG_PPC_TM_GPR0; |
| 1200 | vcpu->arch.gpr_tm[i] = set_reg_val(id, *val); |
| 1201 | break; |
| 1202 | case KVM_REG_PPC_TM_VSR0 ... KVM_REG_PPC_TM_VSR63: |
| 1203 | { |
| 1204 | int j; |
| 1205 | i = id - KVM_REG_PPC_TM_VSR0; |
| 1206 | if (i < 32) |
| 1207 | for (j = 0; j < TS_FPRWIDTH; j++) |
| 1208 | vcpu->arch.fp_tm.fpr[i][j] = val->vsxval[j]; |
| 1209 | else |
| 1210 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 1211 | vcpu->arch.vr_tm.vr[i-32] = val->vval; |
| 1212 | else |
| 1213 | r = -ENXIO; |
| 1214 | break; |
| 1215 | } |
| 1216 | case KVM_REG_PPC_TM_CR: |
| 1217 | vcpu->arch.cr_tm = set_reg_val(id, *val); |
| 1218 | break; |
| 1219 | case KVM_REG_PPC_TM_LR: |
| 1220 | vcpu->arch.lr_tm = set_reg_val(id, *val); |
| 1221 | break; |
| 1222 | case KVM_REG_PPC_TM_CTR: |
| 1223 | vcpu->arch.ctr_tm = set_reg_val(id, *val); |
| 1224 | break; |
| 1225 | case KVM_REG_PPC_TM_FPSCR: |
| 1226 | vcpu->arch.fp_tm.fpscr = set_reg_val(id, *val); |
| 1227 | break; |
| 1228 | case KVM_REG_PPC_TM_AMR: |
| 1229 | vcpu->arch.amr_tm = set_reg_val(id, *val); |
| 1230 | break; |
| 1231 | case KVM_REG_PPC_TM_PPR: |
| 1232 | vcpu->arch.ppr_tm = set_reg_val(id, *val); |
| 1233 | break; |
| 1234 | case KVM_REG_PPC_TM_VRSAVE: |
| 1235 | vcpu->arch.vrsave_tm = set_reg_val(id, *val); |
| 1236 | break; |
| 1237 | case KVM_REG_PPC_TM_VSCR: |
| 1238 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 1239 | vcpu->arch.vr.vscr.u[3] = set_reg_val(id, *val); |
| 1240 | else |
| 1241 | r = - ENXIO; |
| 1242 | break; |
| 1243 | case KVM_REG_PPC_TM_DSCR: |
| 1244 | vcpu->arch.dscr_tm = set_reg_val(id, *val); |
| 1245 | break; |
| 1246 | case KVM_REG_PPC_TM_TAR: |
| 1247 | vcpu->arch.tar_tm = set_reg_val(id, *val); |
| 1248 | break; |
| 1249 | #endif |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 1250 | case KVM_REG_PPC_ARCH_COMPAT: |
| 1251 | r = kvmppc_set_arch_compat(vcpu, set_reg_val(id, *val)); |
| 1252 | break; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1253 | default: |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1254 | r = -EINVAL; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1255 | break; |
| 1256 | } |
| 1257 | |
| 1258 | return r; |
| 1259 | } |
| 1260 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1261 | static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct kvm *kvm, |
| 1262 | unsigned int id) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1263 | { |
| 1264 | struct kvm_vcpu *vcpu; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1265 | int err = -EINVAL; |
| 1266 | int core; |
| 1267 | struct kvmppc_vcore *vcore; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1268 | |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1269 | core = id / threads_per_subcore; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1270 | if (core >= KVM_MAX_VCORES) |
| 1271 | goto out; |
| 1272 | |
| 1273 | err = -ENOMEM; |
Sasha Levin | 6b75e6b | 2011-12-07 10:24:56 +0200 | [diff] [blame] | 1274 | vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1275 | if (!vcpu) |
| 1276 | goto out; |
| 1277 | |
| 1278 | err = kvm_vcpu_init(vcpu, kvm, id); |
| 1279 | if (err) |
| 1280 | goto free_vcpu; |
| 1281 | |
| 1282 | vcpu->arch.shared = &vcpu->arch.shregs; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1283 | vcpu->arch.mmcr[0] = MMCR0_FC; |
| 1284 | vcpu->arch.ctrl = CTRL_RUNLATCH; |
| 1285 | /* default to host PVR, since we can't spoof it */ |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1286 | kvmppc_set_pvr_hv(vcpu, mfspr(SPRN_PVR)); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1287 | spin_lock_init(&vcpu->arch.vpa_update_lock); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1288 | spin_lock_init(&vcpu->arch.tbacct_lock); |
| 1289 | vcpu->arch.busy_preempt = TB_NIL; |
Anton Blanchard | d682916 | 2014-01-08 21:25:30 +1100 | [diff] [blame] | 1290 | vcpu->arch.intr_msr = MSR_SF | MSR_ME; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1291 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1292 | kvmppc_mmu_book3s_hv_init(vcpu); |
| 1293 | |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1294 | vcpu->arch.state = KVMPPC_VCPU_NOTREADY; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1295 | |
| 1296 | init_waitqueue_head(&vcpu->arch.cpu_run); |
| 1297 | |
| 1298 | mutex_lock(&kvm->lock); |
| 1299 | vcore = kvm->arch.vcores[core]; |
| 1300 | if (!vcore) { |
| 1301 | vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL); |
| 1302 | if (vcore) { |
| 1303 | INIT_LIST_HEAD(&vcore->runnable_threads); |
| 1304 | spin_lock_init(&vcore->lock); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1305 | init_waitqueue_head(&vcore->wq); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1306 | vcore->preempt_tb = TB_NIL; |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 1307 | vcore->lpcr = kvm->arch.lpcr; |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1308 | vcore->first_vcpuid = core * threads_per_subcore; |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1309 | vcore->kvm = kvm; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1310 | } |
| 1311 | kvm->arch.vcores[core] = vcore; |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 1312 | kvm->arch.online_vcores++; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1313 | } |
| 1314 | mutex_unlock(&kvm->lock); |
| 1315 | |
| 1316 | if (!vcore) |
| 1317 | goto free_vcpu; |
| 1318 | |
| 1319 | spin_lock(&vcore->lock); |
| 1320 | ++vcore->num_threads; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1321 | spin_unlock(&vcore->lock); |
| 1322 | vcpu->arch.vcore = vcore; |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1323 | vcpu->arch.ptid = vcpu->vcpu_id - vcore->first_vcpuid; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1324 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 1325 | vcpu->arch.cpu_type = KVM_CPU_3S_64; |
| 1326 | kvmppc_sanity_check(vcpu); |
| 1327 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1328 | return vcpu; |
| 1329 | |
| 1330 | free_vcpu: |
Sasha Levin | 6b75e6b | 2011-12-07 10:24:56 +0200 | [diff] [blame] | 1331 | kmem_cache_free(kvm_vcpu_cache, vcpu); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1332 | out: |
| 1333 | return ERR_PTR(err); |
| 1334 | } |
| 1335 | |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 1336 | static void unpin_vpa(struct kvm *kvm, struct kvmppc_vpa *vpa) |
| 1337 | { |
| 1338 | if (vpa->pinned_addr) |
| 1339 | kvmppc_unpin_guest_page(kvm, vpa->pinned_addr, vpa->gpa, |
| 1340 | vpa->dirty); |
| 1341 | } |
| 1342 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1343 | static void kvmppc_core_vcpu_free_hv(struct kvm_vcpu *vcpu) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1344 | { |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1345 | spin_lock(&vcpu->arch.vpa_update_lock); |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 1346 | unpin_vpa(vcpu->kvm, &vcpu->arch.dtl); |
| 1347 | unpin_vpa(vcpu->kvm, &vcpu->arch.slb_shadow); |
| 1348 | unpin_vpa(vcpu->kvm, &vcpu->arch.vpa); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1349 | spin_unlock(&vcpu->arch.vpa_update_lock); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1350 | kvm_vcpu_uninit(vcpu); |
Sasha Levin | 6b75e6b | 2011-12-07 10:24:56 +0200 | [diff] [blame] | 1351 | kmem_cache_free(kvm_vcpu_cache, vcpu); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1354 | static int kvmppc_core_check_requests_hv(struct kvm_vcpu *vcpu) |
| 1355 | { |
| 1356 | /* Indicate we want to get back into the guest */ |
| 1357 | return 1; |
| 1358 | } |
| 1359 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1360 | static void kvmppc_set_timer(struct kvm_vcpu *vcpu) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1361 | { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1362 | unsigned long dec_nsec, now; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1363 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1364 | now = get_tb(); |
| 1365 | if (now > vcpu->arch.dec_expires) { |
| 1366 | /* decrementer has already gone negative */ |
| 1367 | kvmppc_core_queue_dec(vcpu); |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 1368 | kvmppc_core_prepare_to_enter(vcpu); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1369 | return; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1370 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1371 | dec_nsec = (vcpu->arch.dec_expires - now) * NSEC_PER_SEC |
| 1372 | / tb_ticks_per_sec; |
| 1373 | hrtimer_start(&vcpu->arch.dec_timer, ktime_set(0, dec_nsec), |
| 1374 | HRTIMER_MODE_REL); |
| 1375 | vcpu->arch.timer_running = 1; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1378 | static void kvmppc_end_cede(struct kvm_vcpu *vcpu) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1379 | { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1380 | vcpu->arch.ceded = 0; |
| 1381 | if (vcpu->arch.timer_running) { |
| 1382 | hrtimer_try_to_cancel(&vcpu->arch.dec_timer); |
| 1383 | vcpu->arch.timer_running = 0; |
| 1384 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1387 | extern void __kvmppc_vcore_entry(void); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1388 | |
| 1389 | static void kvmppc_remove_runnable(struct kvmppc_vcore *vc, |
| 1390 | struct kvm_vcpu *vcpu) |
| 1391 | { |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1392 | u64 now; |
| 1393 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1394 | if (vcpu->arch.state != KVMPPC_VCPU_RUNNABLE) |
| 1395 | return; |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 1396 | spin_lock_irq(&vcpu->arch.tbacct_lock); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1397 | now = mftb(); |
| 1398 | vcpu->arch.busy_stolen += vcore_stolen_time(vc, now) - |
| 1399 | vcpu->arch.stolen_logged; |
| 1400 | vcpu->arch.busy_preempt = now; |
| 1401 | vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 1402 | spin_unlock_irq(&vcpu->arch.tbacct_lock); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1403 | --vc->n_runnable; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1404 | list_del(&vcpu->arch.run_list); |
| 1405 | } |
| 1406 | |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 1407 | static int kvmppc_grab_hwthread(int cpu) |
| 1408 | { |
| 1409 | struct paca_struct *tpaca; |
| 1410 | long timeout = 1000; |
| 1411 | |
| 1412 | tpaca = &paca[cpu]; |
| 1413 | |
| 1414 | /* Ensure the thread won't go into the kernel if it wakes */ |
| 1415 | tpaca->kvm_hstate.hwthread_req = 1; |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1416 | tpaca->kvm_hstate.kvm_vcpu = NULL; |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 1417 | |
| 1418 | /* |
| 1419 | * If the thread is already executing in the kernel (e.g. handling |
| 1420 | * a stray interrupt), wait for it to get back to nap mode. |
| 1421 | * The smp_mb() is to ensure that our setting of hwthread_req |
| 1422 | * is visible before we look at hwthread_state, so if this |
| 1423 | * races with the code at system_reset_pSeries and the thread |
| 1424 | * misses our setting of hwthread_req, we are sure to see its |
| 1425 | * setting of hwthread_state, and vice versa. |
| 1426 | */ |
| 1427 | smp_mb(); |
| 1428 | while (tpaca->kvm_hstate.hwthread_state == KVM_HWTHREAD_IN_KERNEL) { |
| 1429 | if (--timeout <= 0) { |
| 1430 | pr_err("KVM: couldn't grab cpu %d\n", cpu); |
| 1431 | return -EBUSY; |
| 1432 | } |
| 1433 | udelay(1); |
| 1434 | } |
| 1435 | return 0; |
| 1436 | } |
| 1437 | |
| 1438 | static void kvmppc_release_hwthread(int cpu) |
| 1439 | { |
| 1440 | struct paca_struct *tpaca; |
| 1441 | |
| 1442 | tpaca = &paca[cpu]; |
| 1443 | tpaca->kvm_hstate.hwthread_req = 0; |
| 1444 | tpaca->kvm_hstate.kvm_vcpu = NULL; |
| 1445 | } |
| 1446 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1447 | static void kvmppc_start_thread(struct kvm_vcpu *vcpu) |
| 1448 | { |
| 1449 | int cpu; |
| 1450 | struct paca_struct *tpaca; |
| 1451 | struct kvmppc_vcore *vc = vcpu->arch.vcore; |
| 1452 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1453 | if (vcpu->arch.timer_running) { |
| 1454 | hrtimer_try_to_cancel(&vcpu->arch.dec_timer); |
| 1455 | vcpu->arch.timer_running = 0; |
| 1456 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1457 | cpu = vc->pcpu + vcpu->arch.ptid; |
| 1458 | tpaca = &paca[cpu]; |
| 1459 | tpaca->kvm_hstate.kvm_vcpu = vcpu; |
| 1460 | tpaca->kvm_hstate.kvm_vcore = vc; |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1461 | tpaca->kvm_hstate.ptid = vcpu->arch.ptid; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1462 | vcpu->cpu = vc->pcpu; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1463 | smp_wmb(); |
Michael Neuling | 251da03 | 2011-11-10 16:03:20 +0000 | [diff] [blame] | 1464 | #if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1465 | if (cpu != smp_processor_id()) { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1466 | xics_wake_cpu(cpu); |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1467 | if (vcpu->arch.ptid) |
| 1468 | ++vc->n_woken; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1469 | } |
| 1470 | #endif |
| 1471 | } |
| 1472 | |
| 1473 | static void kvmppc_wait_for_nap(struct kvmppc_vcore *vc) |
| 1474 | { |
| 1475 | int i; |
| 1476 | |
| 1477 | HMT_low(); |
| 1478 | i = 0; |
| 1479 | while (vc->nap_count < vc->n_woken) { |
| 1480 | if (++i >= 1000000) { |
| 1481 | pr_err("kvmppc_wait_for_nap timeout %d %d\n", |
| 1482 | vc->nap_count, vc->n_woken); |
| 1483 | break; |
| 1484 | } |
| 1485 | cpu_relax(); |
| 1486 | } |
| 1487 | HMT_medium(); |
| 1488 | } |
| 1489 | |
| 1490 | /* |
| 1491 | * Check that we are on thread 0 and that any other threads in |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1492 | * this core are off-line. Then grab the threads so they can't |
| 1493 | * enter the kernel. |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1494 | */ |
| 1495 | static int on_primary_thread(void) |
| 1496 | { |
| 1497 | int cpu = smp_processor_id(); |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1498 | int thr; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1499 | |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1500 | /* Are we on a primary subcore? */ |
| 1501 | if (cpu_thread_in_subcore(cpu)) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1502 | return 0; |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1503 | |
| 1504 | thr = 0; |
| 1505 | while (++thr < threads_per_subcore) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1506 | if (cpu_online(cpu + thr)) |
| 1507 | return 0; |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1508 | |
| 1509 | /* Grab all hw threads so they can't go into the kernel */ |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1510 | for (thr = 1; thr < threads_per_subcore; ++thr) { |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1511 | if (kvmppc_grab_hwthread(cpu + thr)) { |
| 1512 | /* Couldn't grab one; let the others go */ |
| 1513 | do { |
| 1514 | kvmppc_release_hwthread(cpu + thr); |
| 1515 | } while (--thr > 0); |
| 1516 | return 0; |
| 1517 | } |
| 1518 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1519 | return 1; |
| 1520 | } |
| 1521 | |
| 1522 | /* |
| 1523 | * Run a set of guest threads on a physical core. |
| 1524 | * Called with vc->lock held. |
| 1525 | */ |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1526 | static void kvmppc_run_core(struct kvmppc_vcore *vc) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1527 | { |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1528 | struct kvm_vcpu *vcpu, *vnext; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1529 | long ret; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1530 | u64 now; |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1531 | int i, need_vpa_update; |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 1532 | int srcu_idx; |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1533 | struct kvm_vcpu *vcpus_to_update[threads_per_core]; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1534 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1535 | /* don't start if any threads have a signal pending */ |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 1536 | need_vpa_update = 0; |
| 1537 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1538 | if (signal_pending(vcpu->arch.run_task)) |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1539 | return; |
| 1540 | if (vcpu->arch.vpa.update_pending || |
| 1541 | vcpu->arch.slb_shadow.update_pending || |
| 1542 | vcpu->arch.dtl.update_pending) |
| 1543 | vcpus_to_update[need_vpa_update++] = vcpu; |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | /* |
| 1547 | * Initialize *vc, in particular vc->vcore_state, so we can |
| 1548 | * drop the vcore lock if necessary. |
| 1549 | */ |
| 1550 | vc->n_woken = 0; |
| 1551 | vc->nap_count = 0; |
| 1552 | vc->entry_exit_count = 0; |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1553 | vc->vcore_state = VCORE_STARTING; |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 1554 | vc->in_guest = 0; |
| 1555 | vc->napping_threads = 0; |
| 1556 | |
| 1557 | /* |
| 1558 | * Updating any of the vpas requires calling kvmppc_pin_guest_page, |
| 1559 | * which can't be called with any spinlocks held. |
| 1560 | */ |
| 1561 | if (need_vpa_update) { |
| 1562 | spin_unlock(&vc->lock); |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1563 | for (i = 0; i < need_vpa_update; ++i) |
| 1564 | kvmppc_update_vpas(vcpus_to_update[i]); |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 1565 | spin_lock(&vc->lock); |
| 1566 | } |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1567 | |
| 1568 | /* |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1569 | * Make sure we are running on primary threads, and that secondary |
| 1570 | * threads are offline. Also check if the number of threads in this |
| 1571 | * guest are greater than the current system threads per guest. |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1572 | */ |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1573 | if ((threads_per_core > 1) && |
| 1574 | ((vc->num_threads > threads_per_subcore) || !on_primary_thread())) { |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1575 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) |
| 1576 | vcpu->arch.ret = -EBUSY; |
| 1577 | goto out; |
| 1578 | } |
| 1579 | |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1580 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1581 | vc->pcpu = smp_processor_id(); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1582 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1583 | kvmppc_start_thread(vcpu); |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 1584 | kvmppc_create_dtl_entry(vcpu, vc); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1585 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1586 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1587 | /* Set this explicitly in case thread 0 doesn't have a vcpu */ |
| 1588 | get_paca()->kvm_hstate.kvm_vcore = vc; |
| 1589 | get_paca()->kvm_hstate.ptid = 0; |
| 1590 | |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1591 | vc->vcore_state = VCORE_RUNNING; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1592 | preempt_disable(); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1593 | spin_unlock(&vc->lock); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1594 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1595 | kvm_guest_enter(); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 1596 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1597 | srcu_idx = srcu_read_lock(&vc->kvm->srcu); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 1598 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1599 | __kvmppc_vcore_entry(); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1600 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1601 | spin_lock(&vc->lock); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1602 | /* disable sending of IPIs on virtual external irqs */ |
| 1603 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) |
| 1604 | vcpu->cpu = -1; |
| 1605 | /* wait for secondary threads to finish writing their state to memory */ |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1606 | if (vc->nap_count < vc->n_woken) |
| 1607 | kvmppc_wait_for_nap(vc); |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame^] | 1608 | for (i = 0; i < threads_per_subcore; ++i) |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1609 | kvmppc_release_hwthread(vc->pcpu + i); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1610 | /* prevent other vcpu threads from doing kvmppc_start_thread() now */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1611 | vc->vcore_state = VCORE_EXITING; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1612 | spin_unlock(&vc->lock); |
| 1613 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1614 | srcu_read_unlock(&vc->kvm->srcu, srcu_idx); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 1615 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1616 | /* make sure updates to secondary vcpu structs are visible now */ |
| 1617 | smp_mb(); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1618 | kvm_guest_exit(); |
| 1619 | |
| 1620 | preempt_enable(); |
Takuya Yoshikawa | c08ac06 | 2013-12-13 15:07:21 +0900 | [diff] [blame] | 1621 | cond_resched(); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1622 | |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1623 | spin_lock(&vc->lock); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1624 | now = get_tb(); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1625 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { |
| 1626 | /* cancel pending dec exception if dec is positive */ |
| 1627 | if (now < vcpu->arch.dec_expires && |
| 1628 | kvmppc_core_pending_dec(vcpu)) |
| 1629 | kvmppc_core_dequeue_dec(vcpu); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1630 | |
| 1631 | ret = RESUME_GUEST; |
| 1632 | if (vcpu->arch.trap) |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1633 | ret = kvmppc_handle_exit_hv(vcpu->arch.kvm_run, vcpu, |
| 1634 | vcpu->arch.run_task); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1635 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1636 | vcpu->arch.ret = ret; |
| 1637 | vcpu->arch.trap = 0; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1638 | |
| 1639 | if (vcpu->arch.ceded) { |
Greg Kurz | e59d24e | 2014-02-06 17:36:56 +0100 | [diff] [blame] | 1640 | if (!is_kvmppc_resume_guest(ret)) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1641 | kvmppc_end_cede(vcpu); |
| 1642 | else |
| 1643 | kvmppc_set_timer(vcpu); |
| 1644 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1645 | } |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1646 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1647 | out: |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1648 | vc->vcore_state = VCORE_INACTIVE; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1649 | list_for_each_entry_safe(vcpu, vnext, &vc->runnable_threads, |
| 1650 | arch.run_list) { |
Greg Kurz | e59d24e | 2014-02-06 17:36:56 +0100 | [diff] [blame] | 1651 | if (!is_kvmppc_resume_guest(vcpu->arch.ret)) { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1652 | kvmppc_remove_runnable(vc, vcpu); |
| 1653 | wake_up(&vcpu->arch.cpu_run); |
| 1654 | } |
| 1655 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1658 | /* |
| 1659 | * Wait for some other vcpu thread to execute us, and |
| 1660 | * wake us up when we need to handle something in the host. |
| 1661 | */ |
| 1662 | 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] | 1663 | { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1664 | DEFINE_WAIT(wait); |
| 1665 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1666 | prepare_to_wait(&vcpu->arch.cpu_run, &wait, wait_state); |
| 1667 | if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) |
| 1668 | schedule(); |
| 1669 | finish_wait(&vcpu->arch.cpu_run, &wait); |
| 1670 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1671 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1672 | /* |
| 1673 | * All the vcpus in this vcore are idle, so wait for a decrementer |
| 1674 | * or external interrupt to one of the vcpus. vc->lock is held. |
| 1675 | */ |
| 1676 | static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) |
| 1677 | { |
| 1678 | DEFINE_WAIT(wait); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1679 | |
| 1680 | prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE); |
| 1681 | vc->vcore_state = VCORE_SLEEPING; |
| 1682 | spin_unlock(&vc->lock); |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1683 | schedule(); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1684 | finish_wait(&vc->wq, &wait); |
| 1685 | spin_lock(&vc->lock); |
| 1686 | vc->vcore_state = VCORE_INACTIVE; |
| 1687 | } |
| 1688 | |
| 1689 | static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) |
| 1690 | { |
| 1691 | int n_ceded; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1692 | struct kvmppc_vcore *vc; |
| 1693 | struct kvm_vcpu *v, *vn; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1694 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1695 | kvm_run->exit_reason = 0; |
| 1696 | vcpu->arch.ret = RESUME_GUEST; |
| 1697 | vcpu->arch.trap = 0; |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1698 | kvmppc_update_vpas(vcpu); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1699 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1700 | /* |
| 1701 | * Synchronize with other threads in this virtual core |
| 1702 | */ |
| 1703 | vc = vcpu->arch.vcore; |
| 1704 | spin_lock(&vc->lock); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1705 | vcpu->arch.ceded = 0; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1706 | vcpu->arch.run_task = current; |
| 1707 | vcpu->arch.kvm_run = kvm_run; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1708 | vcpu->arch.stolen_logged = vcore_stolen_time(vc, mftb()); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1709 | vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1710 | vcpu->arch.busy_preempt = TB_NIL; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1711 | list_add_tail(&vcpu->arch.run_list, &vc->runnable_threads); |
| 1712 | ++vc->n_runnable; |
| 1713 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1714 | /* |
| 1715 | * This happens the first time this is called for a vcpu. |
| 1716 | * If the vcore is already running, we may be able to start |
| 1717 | * this thread straight away and have it join in. |
| 1718 | */ |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1719 | if (!signal_pending(current)) { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1720 | if (vc->vcore_state == VCORE_RUNNING && |
| 1721 | VCORE_EXIT_COUNT(vc) == 0) { |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1722 | kvmppc_create_dtl_entry(vcpu, vc); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1723 | kvmppc_start_thread(vcpu); |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1724 | } else if (vc->vcore_state == VCORE_SLEEPING) { |
| 1725 | wake_up(&vc->wq); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1726 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1727 | |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1728 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1729 | |
| 1730 | while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE && |
| 1731 | !signal_pending(current)) { |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1732 | if (vc->vcore_state != VCORE_INACTIVE) { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1733 | spin_unlock(&vc->lock); |
| 1734 | kvmppc_wait_for_exec(vcpu, TASK_INTERRUPTIBLE); |
| 1735 | spin_lock(&vc->lock); |
| 1736 | continue; |
| 1737 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1738 | list_for_each_entry_safe(v, vn, &vc->runnable_threads, |
| 1739 | arch.run_list) { |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 1740 | kvmppc_core_prepare_to_enter(v); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1741 | if (signal_pending(v->arch.run_task)) { |
| 1742 | kvmppc_remove_runnable(vc, v); |
| 1743 | v->stat.signal_exits++; |
| 1744 | v->arch.kvm_run->exit_reason = KVM_EXIT_INTR; |
| 1745 | v->arch.ret = -EINTR; |
| 1746 | wake_up(&v->arch.cpu_run); |
| 1747 | } |
| 1748 | } |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1749 | if (!vc->n_runnable || vcpu->arch.state != KVMPPC_VCPU_RUNNABLE) |
| 1750 | break; |
| 1751 | vc->runner = vcpu; |
| 1752 | n_ceded = 0; |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1753 | list_for_each_entry(v, &vc->runnable_threads, arch.run_list) { |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1754 | if (!v->arch.pending_exceptions) |
| 1755 | n_ceded += v->arch.ceded; |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1756 | else |
| 1757 | v->arch.ceded = 0; |
| 1758 | } |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1759 | if (n_ceded == vc->n_runnable) |
| 1760 | kvmppc_vcore_blocked(vc); |
| 1761 | else |
| 1762 | kvmppc_run_core(vc); |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 1763 | vc->runner = NULL; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1766 | while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE && |
| 1767 | (vc->vcore_state == VCORE_RUNNING || |
| 1768 | vc->vcore_state == VCORE_EXITING)) { |
| 1769 | spin_unlock(&vc->lock); |
| 1770 | kvmppc_wait_for_exec(vcpu, TASK_UNINTERRUPTIBLE); |
| 1771 | spin_lock(&vc->lock); |
| 1772 | } |
| 1773 | |
| 1774 | if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) { |
| 1775 | kvmppc_remove_runnable(vc, vcpu); |
| 1776 | vcpu->stat.signal_exits++; |
| 1777 | kvm_run->exit_reason = KVM_EXIT_INTR; |
| 1778 | vcpu->arch.ret = -EINTR; |
| 1779 | } |
| 1780 | |
| 1781 | if (vc->n_runnable && vc->vcore_state == VCORE_INACTIVE) { |
| 1782 | /* Wake up some vcpu to run the core */ |
| 1783 | v = list_first_entry(&vc->runnable_threads, |
| 1784 | struct kvm_vcpu, arch.run_list); |
| 1785 | wake_up(&v->arch.cpu_run); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1786 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1787 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1788 | spin_unlock(&vc->lock); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1789 | return vcpu->arch.ret; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1792 | static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1793 | { |
| 1794 | int r; |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1795 | int srcu_idx; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1796 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 1797 | if (!vcpu->arch.sane) { |
| 1798 | run->exit_reason = KVM_EXIT_INTERNAL_ERROR; |
| 1799 | return -EINVAL; |
| 1800 | } |
| 1801 | |
Scott Wood | 25051b5a | 2011-11-08 18:23:23 -0600 | [diff] [blame] | 1802 | kvmppc_core_prepare_to_enter(vcpu); |
| 1803 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1804 | /* No need to go into the guest when all we'll do is come back out */ |
| 1805 | if (signal_pending(current)) { |
| 1806 | run->exit_reason = KVM_EXIT_INTR; |
| 1807 | return -EINTR; |
| 1808 | } |
| 1809 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1810 | atomic_inc(&vcpu->kvm->arch.vcpus_running); |
| 1811 | /* Order vcpus_running vs. rma_setup_done, see kvmppc_alloc_reset_hpt */ |
| 1812 | smp_mb(); |
| 1813 | |
| 1814 | /* On the first time here, set up HTAB and VRMA or RMA */ |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1815 | if (!vcpu->kvm->arch.rma_setup_done) { |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1816 | r = kvmppc_hv_setup_htab_rma(vcpu); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1817 | if (r) |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1818 | goto out; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1819 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1820 | |
| 1821 | flush_fp_to_thread(current); |
| 1822 | flush_altivec_to_thread(current); |
| 1823 | flush_vsx_to_thread(current); |
| 1824 | vcpu->arch.wqp = &vcpu->arch.vcore->wq; |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1825 | vcpu->arch.pgdir = current->mm->pgd; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1826 | vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1827 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1828 | do { |
| 1829 | r = kvmppc_run_vcpu(run, vcpu); |
| 1830 | |
| 1831 | if (run->exit_reason == KVM_EXIT_PAPR_HCALL && |
| 1832 | !(vcpu->arch.shregs.msr & MSR_PR)) { |
| 1833 | r = kvmppc_pseries_do_hcall(vcpu); |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 1834 | kvmppc_core_prepare_to_enter(vcpu); |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1835 | } else if (r == RESUME_PAGE_FAULT) { |
| 1836 | srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); |
| 1837 | r = kvmppc_book3s_hv_page_fault(run, vcpu, |
| 1838 | vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); |
| 1839 | srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1840 | } |
Greg Kurz | e59d24e | 2014-02-06 17:36:56 +0100 | [diff] [blame] | 1841 | } while (is_kvmppc_resume_guest(r)); |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1842 | |
| 1843 | out: |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1844 | vcpu->arch.state = KVMPPC_VCPU_NOTREADY; |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1845 | atomic_dec(&vcpu->kvm->arch.vcpus_running); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1846 | return r; |
| 1847 | } |
| 1848 | |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 1849 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1850 | /* 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] | 1851 | Assumes POWER7 or PPC970. */ |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1852 | static inline int lpcr_rmls(unsigned long rma_size) |
| 1853 | { |
| 1854 | switch (rma_size) { |
| 1855 | case 32ul << 20: /* 32 MB */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1856 | if (cpu_has_feature(CPU_FTR_ARCH_206)) |
| 1857 | return 8; /* only supported on POWER7 */ |
| 1858 | return -1; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1859 | case 64ul << 20: /* 64 MB */ |
| 1860 | return 3; |
| 1861 | case 128ul << 20: /* 128 MB */ |
| 1862 | return 7; |
| 1863 | case 256ul << 20: /* 256 MB */ |
| 1864 | return 4; |
| 1865 | case 1ul << 30: /* 1 GB */ |
| 1866 | return 2; |
| 1867 | case 16ul << 30: /* 16 GB */ |
| 1868 | return 1; |
| 1869 | case 256ul << 30: /* 256 GB */ |
| 1870 | return 0; |
| 1871 | default: |
| 1872 | return -1; |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | static int kvm_rma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
| 1877 | { |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1878 | struct page *page; |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1879 | struct kvm_rma_info *ri = vma->vm_file->private_data; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1880 | |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1881 | if (vmf->pgoff >= kvm_rma_pages) |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1882 | return VM_FAULT_SIGBUS; |
| 1883 | |
| 1884 | page = pfn_to_page(ri->base_pfn + vmf->pgoff); |
| 1885 | get_page(page); |
| 1886 | vmf->page = page; |
| 1887 | return 0; |
| 1888 | } |
| 1889 | |
| 1890 | static const struct vm_operations_struct kvm_rma_vm_ops = { |
| 1891 | .fault = kvm_rma_fault, |
| 1892 | }; |
| 1893 | |
| 1894 | static int kvm_rma_mmap(struct file *file, struct vm_area_struct *vma) |
| 1895 | { |
Konstantin Khlebnikov | 314e51b | 2012-10-08 16:29:02 -0700 | [diff] [blame] | 1896 | vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1897 | vma->vm_ops = &kvm_rma_vm_ops; |
| 1898 | return 0; |
| 1899 | } |
| 1900 | |
| 1901 | static int kvm_rma_release(struct inode *inode, struct file *filp) |
| 1902 | { |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1903 | struct kvm_rma_info *ri = filp->private_data; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1904 | |
| 1905 | kvm_release_rma(ri); |
| 1906 | return 0; |
| 1907 | } |
| 1908 | |
Al Viro | 75ef9de | 2013-04-04 19:09:41 -0400 | [diff] [blame] | 1909 | static const struct file_operations kvm_rma_fops = { |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1910 | .mmap = kvm_rma_mmap, |
| 1911 | .release = kvm_rma_release, |
| 1912 | }; |
| 1913 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1914 | static long kvm_vm_ioctl_allocate_rma(struct kvm *kvm, |
| 1915 | struct kvm_allocate_rma *ret) |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1916 | { |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1917 | long fd; |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1918 | struct kvm_rma_info *ri; |
| 1919 | /* |
| 1920 | * Only do this on PPC970 in HV mode |
| 1921 | */ |
| 1922 | if (!cpu_has_feature(CPU_FTR_HVMODE) || |
| 1923 | !cpu_has_feature(CPU_FTR_ARCH_201)) |
| 1924 | return -EINVAL; |
| 1925 | |
| 1926 | if (!kvm_rma_pages) |
| 1927 | return -EINVAL; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1928 | |
| 1929 | ri = kvm_alloc_rma(); |
| 1930 | if (!ri) |
| 1931 | return -ENOMEM; |
| 1932 | |
Yann Droneaud | 2f84d5e | 2013-08-24 22:14:08 +0200 | [diff] [blame] | 1933 | fd = anon_inode_getfd("kvm-rma", &kvm_rma_fops, ri, O_RDWR | O_CLOEXEC); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1934 | if (fd < 0) |
| 1935 | kvm_release_rma(ri); |
| 1936 | |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1937 | ret->rma_size = kvm_rma_pages << PAGE_SHIFT; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1938 | return fd; |
| 1939 | } |
| 1940 | |
Benjamin Herrenschmidt | 5b74716 | 2012-04-26 19:43:42 +0000 | [diff] [blame] | 1941 | static void kvmppc_add_seg_page_size(struct kvm_ppc_one_seg_page_size **sps, |
| 1942 | int linux_psize) |
| 1943 | { |
| 1944 | struct mmu_psize_def *def = &mmu_psize_defs[linux_psize]; |
| 1945 | |
| 1946 | if (!def->shift) |
| 1947 | return; |
| 1948 | (*sps)->page_shift = def->shift; |
| 1949 | (*sps)->slb_enc = def->sllp; |
| 1950 | (*sps)->enc[0].page_shift = def->shift; |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 1951 | /* |
| 1952 | * Only return base page encoding. We don't want to return |
| 1953 | * all the supporting pte_enc, because our H_ENTER doesn't |
| 1954 | * support MPSS yet. Once they do, we can start passing all |
| 1955 | * support pte_enc here |
| 1956 | */ |
| 1957 | (*sps)->enc[0].pte_enc = def->penc[linux_psize]; |
Benjamin Herrenschmidt | 5b74716 | 2012-04-26 19:43:42 +0000 | [diff] [blame] | 1958 | (*sps)++; |
| 1959 | } |
| 1960 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1961 | static int kvm_vm_ioctl_get_smmu_info_hv(struct kvm *kvm, |
| 1962 | struct kvm_ppc_smmu_info *info) |
Benjamin Herrenschmidt | 5b74716 | 2012-04-26 19:43:42 +0000 | [diff] [blame] | 1963 | { |
| 1964 | struct kvm_ppc_one_seg_page_size *sps; |
| 1965 | |
| 1966 | info->flags = KVM_PPC_PAGE_SIZES_REAL; |
| 1967 | if (mmu_has_feature(MMU_FTR_1T_SEGMENT)) |
| 1968 | info->flags |= KVM_PPC_1T_SEGMENTS; |
| 1969 | info->slb_size = mmu_slb_size; |
| 1970 | |
| 1971 | /* We only support these sizes for now, and no muti-size segments */ |
| 1972 | sps = &info->sps[0]; |
| 1973 | kvmppc_add_seg_page_size(&sps, MMU_PAGE_4K); |
| 1974 | kvmppc_add_seg_page_size(&sps, MMU_PAGE_64K); |
| 1975 | kvmppc_add_seg_page_size(&sps, MMU_PAGE_16M); |
| 1976 | |
| 1977 | return 0; |
| 1978 | } |
| 1979 | |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 1980 | /* |
| 1981 | * Get (and clear) the dirty memory log for a memory slot. |
| 1982 | */ |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1983 | static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm, |
| 1984 | struct kvm_dirty_log *log) |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 1985 | { |
| 1986 | struct kvm_memory_slot *memslot; |
| 1987 | int r; |
| 1988 | unsigned long n; |
| 1989 | |
| 1990 | mutex_lock(&kvm->slots_lock); |
| 1991 | |
| 1992 | r = -EINVAL; |
Alex Williamson | bbacc0c | 2012-12-10 10:33:09 -0700 | [diff] [blame] | 1993 | if (log->slot >= KVM_USER_MEM_SLOTS) |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 1994 | goto out; |
| 1995 | |
| 1996 | memslot = id_to_memslot(kvm->memslots, log->slot); |
| 1997 | r = -ENOENT; |
| 1998 | if (!memslot->dirty_bitmap) |
| 1999 | goto out; |
| 2000 | |
| 2001 | n = kvm_dirty_bitmap_bytes(memslot); |
| 2002 | memset(memslot->dirty_bitmap, 0, n); |
| 2003 | |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 2004 | r = kvmppc_hv_get_dirty_log(kvm, memslot, memslot->dirty_bitmap); |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 2005 | if (r) |
| 2006 | goto out; |
| 2007 | |
| 2008 | r = -EFAULT; |
| 2009 | if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) |
| 2010 | goto out; |
| 2011 | |
| 2012 | r = 0; |
| 2013 | out: |
| 2014 | mutex_unlock(&kvm->slots_lock); |
| 2015 | return r; |
| 2016 | } |
| 2017 | |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2018 | static void unpin_slot(struct kvm_memory_slot *memslot) |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2019 | { |
| 2020 | unsigned long *physp; |
| 2021 | unsigned long j, npages, pfn; |
| 2022 | struct page *page; |
| 2023 | |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2024 | physp = memslot->arch.slot_phys; |
| 2025 | npages = memslot->npages; |
| 2026 | if (!physp) |
| 2027 | return; |
| 2028 | for (j = 0; j < npages; j++) { |
| 2029 | if (!(physp[j] & KVMPPC_GOT_PAGE)) |
| 2030 | continue; |
| 2031 | pfn = physp[j] >> PAGE_SHIFT; |
| 2032 | page = pfn_to_page(pfn); |
| 2033 | SetPageDirty(page); |
| 2034 | put_page(page); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2035 | } |
| 2036 | } |
| 2037 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2038 | static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free, |
| 2039 | struct kvm_memory_slot *dont) |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2040 | { |
| 2041 | if (!dont || free->arch.rmap != dont->arch.rmap) { |
| 2042 | vfree(free->arch.rmap); |
| 2043 | free->arch.rmap = NULL; |
| 2044 | } |
| 2045 | if (!dont || free->arch.slot_phys != dont->arch.slot_phys) { |
| 2046 | unpin_slot(free); |
| 2047 | vfree(free->arch.slot_phys); |
| 2048 | free->arch.slot_phys = NULL; |
| 2049 | } |
| 2050 | } |
| 2051 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2052 | static int kvmppc_core_create_memslot_hv(struct kvm_memory_slot *slot, |
| 2053 | unsigned long npages) |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2054 | { |
| 2055 | slot->arch.rmap = vzalloc(npages * sizeof(*slot->arch.rmap)); |
| 2056 | if (!slot->arch.rmap) |
| 2057 | return -ENOMEM; |
| 2058 | slot->arch.slot_phys = NULL; |
| 2059 | |
| 2060 | return 0; |
| 2061 | } |
| 2062 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2063 | static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm, |
| 2064 | struct kvm_memory_slot *memslot, |
| 2065 | struct kvm_userspace_memory_region *mem) |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2066 | { |
| 2067 | unsigned long *phys; |
| 2068 | |
| 2069 | /* Allocate a slot_phys array if needed */ |
| 2070 | phys = memslot->arch.slot_phys; |
| 2071 | if (!kvm->arch.using_mmu_notifiers && !phys && memslot->npages) { |
| 2072 | phys = vzalloc(memslot->npages * sizeof(unsigned long)); |
| 2073 | if (!phys) |
| 2074 | return -ENOMEM; |
| 2075 | memslot->arch.slot_phys = phys; |
| 2076 | } |
| 2077 | |
| 2078 | return 0; |
| 2079 | } |
| 2080 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2081 | static void kvmppc_core_commit_memory_region_hv(struct kvm *kvm, |
| 2082 | struct kvm_userspace_memory_region *mem, |
| 2083 | const struct kvm_memory_slot *old) |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2084 | { |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 2085 | unsigned long npages = mem->memory_size >> PAGE_SHIFT; |
| 2086 | struct kvm_memory_slot *memslot; |
| 2087 | |
Takuya Yoshikawa | 8482644 | 2013-02-27 19:45:25 +0900 | [diff] [blame] | 2088 | if (npages && old->npages) { |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 2089 | /* |
| 2090 | * If modifying a memslot, reset all the rmap dirty bits. |
| 2091 | * If this is a new memslot, we don't need to do anything |
| 2092 | * since the rmap array starts out as all zeroes, |
| 2093 | * i.e. no pages are dirty. |
| 2094 | */ |
| 2095 | memslot = id_to_memslot(kvm->memslots, mem->slot); |
| 2096 | kvmppc_hv_get_dirty_log(kvm, memslot, NULL); |
| 2097 | } |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2100 | /* |
| 2101 | * Update LPCR values in kvm->arch and in vcores. |
| 2102 | * Caller must hold kvm->lock. |
| 2103 | */ |
| 2104 | void kvmppc_update_lpcr(struct kvm *kvm, unsigned long lpcr, unsigned long mask) |
| 2105 | { |
| 2106 | long int i; |
| 2107 | u32 cores_done = 0; |
| 2108 | |
| 2109 | if ((kvm->arch.lpcr & mask) == lpcr) |
| 2110 | return; |
| 2111 | |
| 2112 | kvm->arch.lpcr = (kvm->arch.lpcr & ~mask) | lpcr; |
| 2113 | |
| 2114 | for (i = 0; i < KVM_MAX_VCORES; ++i) { |
| 2115 | struct kvmppc_vcore *vc = kvm->arch.vcores[i]; |
| 2116 | if (!vc) |
| 2117 | continue; |
| 2118 | spin_lock(&vc->lock); |
| 2119 | vc->lpcr = (vc->lpcr & ~mask) | lpcr; |
| 2120 | spin_unlock(&vc->lock); |
| 2121 | if (++cores_done >= kvm->arch.online_vcores) |
| 2122 | break; |
| 2123 | } |
| 2124 | } |
| 2125 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2126 | static void kvmppc_mmu_destroy_hv(struct kvm_vcpu *vcpu) |
| 2127 | { |
| 2128 | return; |
| 2129 | } |
| 2130 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2131 | static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu) |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2132 | { |
| 2133 | int err = 0; |
| 2134 | struct kvm *kvm = vcpu->kvm; |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 2135 | struct kvm_rma_info *ri = NULL; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2136 | unsigned long hva; |
| 2137 | struct kvm_memory_slot *memslot; |
| 2138 | struct vm_area_struct *vma; |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2139 | unsigned long lpcr = 0, senc; |
| 2140 | unsigned long lpcr_mask = 0; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2141 | unsigned long psize, porder; |
| 2142 | unsigned long rma_size; |
| 2143 | unsigned long rmls; |
| 2144 | unsigned long *physp; |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2145 | unsigned long i, npages; |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2146 | int srcu_idx; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2147 | |
| 2148 | mutex_lock(&kvm->lock); |
| 2149 | if (kvm->arch.rma_setup_done) |
| 2150 | goto out; /* another vcpu beat us to it */ |
| 2151 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2152 | /* Allocate hashed page table (if not done already) and reset it */ |
| 2153 | if (!kvm->arch.hpt_virt) { |
| 2154 | err = kvmppc_alloc_hpt(kvm, NULL); |
| 2155 | if (err) { |
| 2156 | pr_err("KVM: Couldn't alloc HPT\n"); |
| 2157 | goto out; |
| 2158 | } |
| 2159 | } |
| 2160 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2161 | /* Look up the memslot for guest physical address 0 */ |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2162 | srcu_idx = srcu_read_lock(&kvm->srcu); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2163 | memslot = gfn_to_memslot(kvm, 0); |
| 2164 | |
| 2165 | /* We must have some memory at 0 by now */ |
| 2166 | err = -EINVAL; |
| 2167 | if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2168 | goto out_srcu; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2169 | |
| 2170 | /* Look up the VMA for the start of this memory slot */ |
| 2171 | hva = memslot->userspace_addr; |
| 2172 | down_read(¤t->mm->mmap_sem); |
| 2173 | vma = find_vma(current->mm, hva); |
| 2174 | if (!vma || vma->vm_start > hva || (vma->vm_flags & VM_IO)) |
| 2175 | goto up_out; |
| 2176 | |
| 2177 | psize = vma_kernel_pagesize(vma); |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2178 | porder = __ilog2(psize); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2179 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2180 | /* Is this one of our preallocated RMAs? */ |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2181 | if (vma->vm_file && vma->vm_file->f_op == &kvm_rma_fops && |
| 2182 | hva == vma->vm_start) |
| 2183 | ri = vma->vm_file->private_data; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2184 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2185 | up_read(¤t->mm->mmap_sem); |
| 2186 | |
| 2187 | if (!ri) { |
| 2188 | /* On POWER7, use VRMA; on PPC970, give up */ |
| 2189 | err = -EPERM; |
| 2190 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
| 2191 | pr_err("KVM: CPU requires an RMO\n"); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2192 | goto out_srcu; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2193 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2194 | |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2195 | /* We can handle 4k, 64k or 16M pages in the VRMA */ |
| 2196 | err = -EINVAL; |
| 2197 | if (!(psize == 0x1000 || psize == 0x10000 || |
| 2198 | psize == 0x1000000)) |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2199 | goto out_srcu; |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2200 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2201 | /* Update VRMASD field in the LPCR */ |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2202 | senc = slb_pgsize_encoding(psize); |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 2203 | kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T | |
| 2204 | (VRMA_VSID << SLB_VSID_SHIFT_1T); |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2205 | lpcr_mask = LPCR_VRMASD; |
| 2206 | /* the -4 is to account for senc values starting at 0x10 */ |
| 2207 | lpcr = senc << (LPCR_VRMASD_SH - 4); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2208 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2209 | /* Create HPTEs in the hash page table for the VRMA */ |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2210 | kvmppc_map_vrma(vcpu, memslot, porder); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2211 | |
| 2212 | } else { |
| 2213 | /* Set up to use an RMO region */ |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 2214 | rma_size = kvm_rma_pages; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2215 | if (rma_size > memslot->npages) |
| 2216 | rma_size = memslot->npages; |
| 2217 | rma_size <<= PAGE_SHIFT; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2218 | rmls = lpcr_rmls(rma_size); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2219 | err = -EINVAL; |
Chen Gang | 5d226ae | 2013-07-22 14:32:35 +0800 | [diff] [blame] | 2220 | if ((long)rmls < 0) { |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2221 | pr_err("KVM: Can't use RMA of 0x%lx bytes\n", rma_size); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2222 | goto out_srcu; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2223 | } |
| 2224 | atomic_inc(&ri->use_count); |
| 2225 | kvm->arch.rma = ri; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2226 | |
| 2227 | /* Update LPCR and RMOR */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2228 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
| 2229 | /* PPC970; insert RMLS value (split field) in HID4 */ |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2230 | lpcr_mask = (1ul << HID4_RMLS0_SH) | |
| 2231 | (3ul << HID4_RMLS2_SH) | HID4_RMOR; |
| 2232 | lpcr = ((rmls >> 2) << HID4_RMLS0_SH) | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2233 | ((rmls & 3) << HID4_RMLS2_SH); |
| 2234 | /* RMOR is also in HID4 */ |
| 2235 | lpcr |= ((ri->base_pfn >> (26 - PAGE_SHIFT)) & 0xffff) |
| 2236 | << HID4_RMOR_SH; |
| 2237 | } else { |
| 2238 | /* POWER7 */ |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2239 | lpcr_mask = LPCR_VPM0 | LPCR_VRMA_L | LPCR_RMLS; |
| 2240 | lpcr = rmls << LPCR_RMLS_SH; |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 2241 | kvm->arch.rmor = ri->base_pfn << PAGE_SHIFT; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2242 | } |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2243 | pr_info("KVM: Using RMO at %lx size %lx (LPCR = %lx)\n", |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2244 | ri->base_pfn << PAGE_SHIFT, rma_size, lpcr); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2245 | |
| 2246 | /* Initialize phys addrs of pages in RMO */ |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 2247 | npages = kvm_rma_pages; |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2248 | porder = __ilog2(npages); |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2249 | physp = memslot->arch.slot_phys; |
| 2250 | if (physp) { |
| 2251 | if (npages > memslot->npages) |
| 2252 | npages = memslot->npages; |
| 2253 | spin_lock(&kvm->arch.slot_phys_lock); |
| 2254 | for (i = 0; i < npages; ++i) |
| 2255 | physp[i] = ((ri->base_pfn + i) << PAGE_SHIFT) + |
| 2256 | porder; |
| 2257 | spin_unlock(&kvm->arch.slot_phys_lock); |
| 2258 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2261 | kvmppc_update_lpcr(kvm, lpcr, lpcr_mask); |
| 2262 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2263 | /* Order updates to kvm->arch.lpcr etc. vs. rma_setup_done */ |
| 2264 | smp_wmb(); |
| 2265 | kvm->arch.rma_setup_done = 1; |
| 2266 | err = 0; |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2267 | out_srcu: |
| 2268 | srcu_read_unlock(&kvm->srcu, srcu_idx); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2269 | out: |
| 2270 | mutex_unlock(&kvm->lock); |
| 2271 | return err; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2272 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2273 | up_out: |
| 2274 | up_read(¤t->mm->mmap_sem); |
Lai Jiangshan | 505d642 | 2013-03-16 00:50:49 +0800 | [diff] [blame] | 2275 | goto out_srcu; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2278 | static int kvmppc_core_init_vm_hv(struct kvm *kvm) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2279 | { |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2280 | unsigned long lpcr, lpid; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2281 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2282 | /* Allocate the guest's logical partition ID */ |
| 2283 | |
| 2284 | lpid = kvmppc_alloc_lpid(); |
Chen Gang | 5d226ae | 2013-07-22 14:32:35 +0800 | [diff] [blame] | 2285 | if ((long)lpid < 0) |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2286 | return -ENOMEM; |
| 2287 | kvm->arch.lpid = lpid; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2288 | |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 2289 | /* |
| 2290 | * Since we don't flush the TLB when tearing down a VM, |
| 2291 | * and this lpid might have previously been used, |
| 2292 | * make sure we flush on each core before running the new VM. |
| 2293 | */ |
| 2294 | cpumask_setall(&kvm->arch.need_tlb_flush); |
| 2295 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2296 | kvm->arch.rma = NULL; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2297 | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2298 | kvm->arch.host_sdr1 = mfspr(SPRN_SDR1); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2299 | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2300 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
| 2301 | /* PPC970; HID4 is effectively the LPCR */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2302 | kvm->arch.host_lpid = 0; |
| 2303 | kvm->arch.host_lpcr = lpcr = mfspr(SPRN_HID4); |
| 2304 | lpcr &= ~((3 << HID4_LPID1_SH) | (0xful << HID4_LPID5_SH)); |
| 2305 | lpcr |= ((lpid >> 4) << HID4_LPID1_SH) | |
| 2306 | ((lpid & 0xf) << HID4_LPID5_SH); |
| 2307 | } else { |
| 2308 | /* POWER7; init LPCR for virtual RMA mode */ |
| 2309 | kvm->arch.host_lpid = mfspr(SPRN_LPID); |
| 2310 | kvm->arch.host_lpcr = lpcr = mfspr(SPRN_LPCR); |
| 2311 | lpcr &= LPCR_PECE | LPCR_LPES; |
| 2312 | lpcr |= (4UL << LPCR_DPFD_SH) | LPCR_HDICE | |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 2313 | LPCR_VPM0 | LPCR_VPM1; |
| 2314 | kvm->arch.vrma_slb_v = SLB_VSID_B_1T | |
| 2315 | (VRMA_VSID << SLB_VSID_SHIFT_1T); |
Paul Mackerras | e0622bd | 2014-01-08 21:25:27 +1100 | [diff] [blame] | 2316 | /* On POWER8 turn on online bit to enable PURR/SPURR */ |
| 2317 | if (cpu_has_feature(CPU_FTR_ARCH_207S)) |
| 2318 | lpcr |= LPCR_ONL; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2319 | } |
| 2320 | kvm->arch.lpcr = lpcr; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2321 | |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2322 | kvm->arch.using_mmu_notifiers = !!cpu_has_feature(CPU_FTR_ARCH_206); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2323 | spin_lock_init(&kvm->arch.slot_phys_lock); |
Paul Mackerras | 512691d | 2012-10-15 01:15:41 +0000 | [diff] [blame] | 2324 | |
| 2325 | /* |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 2326 | * Track that we now have a HV mode VM active. This blocks secondary |
| 2327 | * CPU threads from coming online. |
Paul Mackerras | 512691d | 2012-10-15 01:15:41 +0000 | [diff] [blame] | 2328 | */ |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 2329 | kvm_hv_vm_activated(); |
Paul Mackerras | 512691d | 2012-10-15 01:15:41 +0000 | [diff] [blame] | 2330 | |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 2331 | return 0; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2332 | } |
| 2333 | |
Paul Mackerras | f1378b1 | 2013-09-27 15:33:43 +0530 | [diff] [blame] | 2334 | static void kvmppc_free_vcores(struct kvm *kvm) |
| 2335 | { |
| 2336 | long int i; |
| 2337 | |
| 2338 | for (i = 0; i < KVM_MAX_VCORES; ++i) |
| 2339 | kfree(kvm->arch.vcores[i]); |
| 2340 | kvm->arch.online_vcores = 0; |
| 2341 | } |
| 2342 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2343 | static void kvmppc_core_destroy_vm_hv(struct kvm *kvm) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2344 | { |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 2345 | kvm_hv_vm_deactivated(); |
Paul Mackerras | 512691d | 2012-10-15 01:15:41 +0000 | [diff] [blame] | 2346 | |
Paul Mackerras | f1378b1 | 2013-09-27 15:33:43 +0530 | [diff] [blame] | 2347 | kvmppc_free_vcores(kvm); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2348 | if (kvm->arch.rma) { |
| 2349 | kvm_release_rma(kvm->arch.rma); |
| 2350 | kvm->arch.rma = NULL; |
| 2351 | } |
| 2352 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2353 | kvmppc_free_hpt(kvm); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | /* We don't need to emulate any privileged instructions or dcbz */ |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2357 | static int kvmppc_core_emulate_op_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 2358 | unsigned int inst, int *advance) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2359 | { |
| 2360 | return EMULATE_FAIL; |
| 2361 | } |
| 2362 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2363 | static int kvmppc_core_emulate_mtspr_hv(struct kvm_vcpu *vcpu, int sprn, |
| 2364 | ulong spr_val) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2365 | { |
| 2366 | return EMULATE_FAIL; |
| 2367 | } |
| 2368 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2369 | static int kvmppc_core_emulate_mfspr_hv(struct kvm_vcpu *vcpu, int sprn, |
| 2370 | ulong *spr_val) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2371 | { |
| 2372 | return EMULATE_FAIL; |
| 2373 | } |
| 2374 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2375 | static int kvmppc_core_check_processor_compat_hv(void) |
| 2376 | { |
| 2377 | if (!cpu_has_feature(CPU_FTR_HVMODE)) |
| 2378 | return -EIO; |
| 2379 | return 0; |
| 2380 | } |
| 2381 | |
| 2382 | static long kvm_arch_vm_ioctl_hv(struct file *filp, |
| 2383 | unsigned int ioctl, unsigned long arg) |
| 2384 | { |
| 2385 | struct kvm *kvm __maybe_unused = filp->private_data; |
| 2386 | void __user *argp = (void __user *)arg; |
| 2387 | long r; |
| 2388 | |
| 2389 | switch (ioctl) { |
| 2390 | |
| 2391 | case KVM_ALLOCATE_RMA: { |
| 2392 | struct kvm_allocate_rma rma; |
| 2393 | struct kvm *kvm = filp->private_data; |
| 2394 | |
| 2395 | r = kvm_vm_ioctl_allocate_rma(kvm, &rma); |
| 2396 | if (r >= 0 && copy_to_user(argp, &rma, sizeof(rma))) |
| 2397 | r = -EFAULT; |
| 2398 | break; |
| 2399 | } |
| 2400 | |
| 2401 | case KVM_PPC_ALLOCATE_HTAB: { |
| 2402 | u32 htab_order; |
| 2403 | |
| 2404 | r = -EFAULT; |
| 2405 | if (get_user(htab_order, (u32 __user *)argp)) |
| 2406 | break; |
| 2407 | r = kvmppc_alloc_reset_hpt(kvm, &htab_order); |
| 2408 | if (r) |
| 2409 | break; |
| 2410 | r = -EFAULT; |
| 2411 | if (put_user(htab_order, (u32 __user *)argp)) |
| 2412 | break; |
| 2413 | r = 0; |
| 2414 | break; |
| 2415 | } |
| 2416 | |
| 2417 | case KVM_PPC_GET_HTAB_FD: { |
| 2418 | struct kvm_get_htab_fd ghf; |
| 2419 | |
| 2420 | r = -EFAULT; |
| 2421 | if (copy_from_user(&ghf, argp, sizeof(ghf))) |
| 2422 | break; |
| 2423 | r = kvm_vm_ioctl_get_htab_fd(kvm, &ghf); |
| 2424 | break; |
| 2425 | } |
| 2426 | |
| 2427 | default: |
| 2428 | r = -ENOTTY; |
| 2429 | } |
| 2430 | |
| 2431 | return r; |
| 2432 | } |
| 2433 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2434 | static struct kvmppc_ops kvm_ops_hv = { |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2435 | .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, |
| 2436 | .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv, |
| 2437 | .get_one_reg = kvmppc_get_one_reg_hv, |
| 2438 | .set_one_reg = kvmppc_set_one_reg_hv, |
| 2439 | .vcpu_load = kvmppc_core_vcpu_load_hv, |
| 2440 | .vcpu_put = kvmppc_core_vcpu_put_hv, |
| 2441 | .set_msr = kvmppc_set_msr_hv, |
| 2442 | .vcpu_run = kvmppc_vcpu_run_hv, |
| 2443 | .vcpu_create = kvmppc_core_vcpu_create_hv, |
| 2444 | .vcpu_free = kvmppc_core_vcpu_free_hv, |
| 2445 | .check_requests = kvmppc_core_check_requests_hv, |
| 2446 | .get_dirty_log = kvm_vm_ioctl_get_dirty_log_hv, |
| 2447 | .flush_memslot = kvmppc_core_flush_memslot_hv, |
| 2448 | .prepare_memory_region = kvmppc_core_prepare_memory_region_hv, |
| 2449 | .commit_memory_region = kvmppc_core_commit_memory_region_hv, |
| 2450 | .unmap_hva = kvm_unmap_hva_hv, |
| 2451 | .unmap_hva_range = kvm_unmap_hva_range_hv, |
| 2452 | .age_hva = kvm_age_hva_hv, |
| 2453 | .test_age_hva = kvm_test_age_hva_hv, |
| 2454 | .set_spte_hva = kvm_set_spte_hva_hv, |
| 2455 | .mmu_destroy = kvmppc_mmu_destroy_hv, |
| 2456 | .free_memslot = kvmppc_core_free_memslot_hv, |
| 2457 | .create_memslot = kvmppc_core_create_memslot_hv, |
| 2458 | .init_vm = kvmppc_core_init_vm_hv, |
| 2459 | .destroy_vm = kvmppc_core_destroy_vm_hv, |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2460 | .get_smmu_info = kvm_vm_ioctl_get_smmu_info_hv, |
| 2461 | .emulate_op = kvmppc_core_emulate_op_hv, |
| 2462 | .emulate_mtspr = kvmppc_core_emulate_mtspr_hv, |
| 2463 | .emulate_mfspr = kvmppc_core_emulate_mfspr_hv, |
| 2464 | .fast_vcpu_kick = kvmppc_fast_vcpu_kick_hv, |
| 2465 | .arch_vm_ioctl = kvm_arch_vm_ioctl_hv, |
| 2466 | }; |
| 2467 | |
| 2468 | static int kvmppc_book3s_init_hv(void) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2469 | { |
| 2470 | int r; |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2471 | /* |
| 2472 | * FIXME!! Do we need to check on all cpus ? |
| 2473 | */ |
| 2474 | r = kvmppc_core_check_processor_compat_hv(); |
| 2475 | if (r < 0) |
Paul Mackerras | 739e242 | 2014-03-25 10:47:05 +1100 | [diff] [blame] | 2476 | return -ENODEV; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2477 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2478 | kvm_ops_hv.owner = THIS_MODULE; |
| 2479 | kvmppc_hv_ops = &kvm_ops_hv; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2480 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2481 | r = kvmppc_mmu_hv_init(); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2482 | return r; |
| 2483 | } |
| 2484 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2485 | static void kvmppc_book3s_exit_hv(void) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2486 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2487 | kvmppc_hv_ops = NULL; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2490 | module_init(kvmppc_book3s_init_hv); |
| 2491 | module_exit(kvmppc_book3s_exit_hv); |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 2492 | MODULE_LICENSE("GPL"); |
Alexander Graf | 398a76c | 2013-12-09 13:53:42 +0100 | [diff] [blame] | 2493 | MODULE_ALIAS_MISCDEV(KVM_MINOR); |
| 2494 | MODULE_ALIAS("devname:kvm"); |