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_PSPB: |
| 883 | *val = get_reg_val(id, vcpu->arch.pspb); |
| 884 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 885 | case KVM_REG_PPC_DPDES: |
| 886 | *val = get_reg_val(id, vcpu->arch.vcore->dpdes); |
| 887 | break; |
| 888 | case KVM_REG_PPC_DAWR: |
| 889 | *val = get_reg_val(id, vcpu->arch.dawr); |
| 890 | break; |
| 891 | case KVM_REG_PPC_DAWRX: |
| 892 | *val = get_reg_val(id, vcpu->arch.dawrx); |
| 893 | break; |
| 894 | case KVM_REG_PPC_CIABR: |
| 895 | *val = get_reg_val(id, vcpu->arch.ciabr); |
| 896 | break; |
| 897 | case KVM_REG_PPC_IC: |
| 898 | *val = get_reg_val(id, vcpu->arch.ic); |
| 899 | break; |
| 900 | case KVM_REG_PPC_VTB: |
| 901 | *val = get_reg_val(id, vcpu->arch.vtb); |
| 902 | break; |
| 903 | case KVM_REG_PPC_CSIGR: |
| 904 | *val = get_reg_val(id, vcpu->arch.csigr); |
| 905 | break; |
| 906 | case KVM_REG_PPC_TACR: |
| 907 | *val = get_reg_val(id, vcpu->arch.tacr); |
| 908 | break; |
| 909 | case KVM_REG_PPC_TCSCR: |
| 910 | *val = get_reg_val(id, vcpu->arch.tcscr); |
| 911 | break; |
| 912 | case KVM_REG_PPC_PID: |
| 913 | *val = get_reg_val(id, vcpu->arch.pid); |
| 914 | break; |
| 915 | case KVM_REG_PPC_ACOP: |
| 916 | *val = get_reg_val(id, vcpu->arch.acop); |
| 917 | break; |
| 918 | case KVM_REG_PPC_WORT: |
| 919 | *val = get_reg_val(id, vcpu->arch.wort); |
| 920 | break; |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 921 | case KVM_REG_PPC_VPA_ADDR: |
| 922 | spin_lock(&vcpu->arch.vpa_update_lock); |
| 923 | *val = get_reg_val(id, vcpu->arch.vpa.next_gpa); |
| 924 | spin_unlock(&vcpu->arch.vpa_update_lock); |
| 925 | break; |
| 926 | case KVM_REG_PPC_VPA_SLB: |
| 927 | spin_lock(&vcpu->arch.vpa_update_lock); |
| 928 | val->vpaval.addr = vcpu->arch.slb_shadow.next_gpa; |
| 929 | val->vpaval.length = vcpu->arch.slb_shadow.len; |
| 930 | spin_unlock(&vcpu->arch.vpa_update_lock); |
| 931 | break; |
| 932 | case KVM_REG_PPC_VPA_DTL: |
| 933 | spin_lock(&vcpu->arch.vpa_update_lock); |
| 934 | val->vpaval.addr = vcpu->arch.dtl.next_gpa; |
| 935 | val->vpaval.length = vcpu->arch.dtl.len; |
| 936 | spin_unlock(&vcpu->arch.vpa_update_lock); |
| 937 | break; |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 938 | case KVM_REG_PPC_TB_OFFSET: |
| 939 | *val = get_reg_val(id, vcpu->arch.vcore->tb_offset); |
| 940 | break; |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 941 | case KVM_REG_PPC_LPCR: |
| 942 | *val = get_reg_val(id, vcpu->arch.vcore->lpcr); |
| 943 | break; |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 944 | case KVM_REG_PPC_PPR: |
| 945 | *val = get_reg_val(id, vcpu->arch.ppr); |
| 946 | break; |
Michael Neuling | a7d80d0 | 2014-03-25 10:47:03 +1100 | [diff] [blame] | 947 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 948 | case KVM_REG_PPC_TFHAR: |
| 949 | *val = get_reg_val(id, vcpu->arch.tfhar); |
| 950 | break; |
| 951 | case KVM_REG_PPC_TFIAR: |
| 952 | *val = get_reg_val(id, vcpu->arch.tfiar); |
| 953 | break; |
| 954 | case KVM_REG_PPC_TEXASR: |
| 955 | *val = get_reg_val(id, vcpu->arch.texasr); |
| 956 | break; |
| 957 | case KVM_REG_PPC_TM_GPR0 ... KVM_REG_PPC_TM_GPR31: |
| 958 | i = id - KVM_REG_PPC_TM_GPR0; |
| 959 | *val = get_reg_val(id, vcpu->arch.gpr_tm[i]); |
| 960 | break; |
| 961 | case KVM_REG_PPC_TM_VSR0 ... KVM_REG_PPC_TM_VSR63: |
| 962 | { |
| 963 | int j; |
| 964 | i = id - KVM_REG_PPC_TM_VSR0; |
| 965 | if (i < 32) |
| 966 | for (j = 0; j < TS_FPRWIDTH; j++) |
| 967 | val->vsxval[j] = vcpu->arch.fp_tm.fpr[i][j]; |
| 968 | else { |
| 969 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 970 | val->vval = vcpu->arch.vr_tm.vr[i-32]; |
| 971 | else |
| 972 | r = -ENXIO; |
| 973 | } |
| 974 | break; |
| 975 | } |
| 976 | case KVM_REG_PPC_TM_CR: |
| 977 | *val = get_reg_val(id, vcpu->arch.cr_tm); |
| 978 | break; |
| 979 | case KVM_REG_PPC_TM_LR: |
| 980 | *val = get_reg_val(id, vcpu->arch.lr_tm); |
| 981 | break; |
| 982 | case KVM_REG_PPC_TM_CTR: |
| 983 | *val = get_reg_val(id, vcpu->arch.ctr_tm); |
| 984 | break; |
| 985 | case KVM_REG_PPC_TM_FPSCR: |
| 986 | *val = get_reg_val(id, vcpu->arch.fp_tm.fpscr); |
| 987 | break; |
| 988 | case KVM_REG_PPC_TM_AMR: |
| 989 | *val = get_reg_val(id, vcpu->arch.amr_tm); |
| 990 | break; |
| 991 | case KVM_REG_PPC_TM_PPR: |
| 992 | *val = get_reg_val(id, vcpu->arch.ppr_tm); |
| 993 | break; |
| 994 | case KVM_REG_PPC_TM_VRSAVE: |
| 995 | *val = get_reg_val(id, vcpu->arch.vrsave_tm); |
| 996 | break; |
| 997 | case KVM_REG_PPC_TM_VSCR: |
| 998 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 999 | *val = get_reg_val(id, vcpu->arch.vr_tm.vscr.u[3]); |
| 1000 | else |
| 1001 | r = -ENXIO; |
| 1002 | break; |
| 1003 | case KVM_REG_PPC_TM_DSCR: |
| 1004 | *val = get_reg_val(id, vcpu->arch.dscr_tm); |
| 1005 | break; |
| 1006 | case KVM_REG_PPC_TM_TAR: |
| 1007 | *val = get_reg_val(id, vcpu->arch.tar_tm); |
| 1008 | break; |
| 1009 | #endif |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 1010 | case KVM_REG_PPC_ARCH_COMPAT: |
| 1011 | *val = get_reg_val(id, vcpu->arch.vcore->arch_compat); |
| 1012 | break; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1013 | default: |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1014 | r = -EINVAL; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1015 | break; |
| 1016 | } |
| 1017 | |
| 1018 | return r; |
| 1019 | } |
| 1020 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1021 | static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, |
| 1022 | union kvmppc_one_reg *val) |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1023 | { |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1024 | int r = 0; |
| 1025 | long int i; |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 1026 | unsigned long addr, len; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1027 | |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1028 | switch (id) { |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1029 | case KVM_REG_PPC_HIOR: |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1030 | /* Only allow this to be set to zero */ |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1031 | if (set_reg_val(id, *val)) |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1032 | r = -EINVAL; |
| 1033 | break; |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1034 | case KVM_REG_PPC_DABR: |
| 1035 | vcpu->arch.dabr = set_reg_val(id, *val); |
| 1036 | break; |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 1037 | case KVM_REG_PPC_DABRX: |
| 1038 | vcpu->arch.dabrx = set_reg_val(id, *val) & ~DABRX_HYP; |
| 1039 | break; |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1040 | case KVM_REG_PPC_DSCR: |
| 1041 | vcpu->arch.dscr = set_reg_val(id, *val); |
| 1042 | break; |
| 1043 | case KVM_REG_PPC_PURR: |
| 1044 | vcpu->arch.purr = set_reg_val(id, *val); |
| 1045 | break; |
| 1046 | case KVM_REG_PPC_SPURR: |
| 1047 | vcpu->arch.spurr = set_reg_val(id, *val); |
| 1048 | break; |
| 1049 | case KVM_REG_PPC_AMR: |
| 1050 | vcpu->arch.amr = set_reg_val(id, *val); |
| 1051 | break; |
| 1052 | case KVM_REG_PPC_UAMOR: |
| 1053 | vcpu->arch.uamor = set_reg_val(id, *val); |
| 1054 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1055 | case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCRS: |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1056 | i = id - KVM_REG_PPC_MMCR0; |
| 1057 | vcpu->arch.mmcr[i] = set_reg_val(id, *val); |
| 1058 | break; |
| 1059 | case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8: |
| 1060 | i = id - KVM_REG_PPC_PMC1; |
| 1061 | vcpu->arch.pmc[i] = set_reg_val(id, *val); |
| 1062 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1063 | case KVM_REG_PPC_SPMC1 ... KVM_REG_PPC_SPMC2: |
| 1064 | i = id - KVM_REG_PPC_SPMC1; |
| 1065 | vcpu->arch.spmc[i] = set_reg_val(id, *val); |
| 1066 | break; |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 1067 | case KVM_REG_PPC_SIAR: |
| 1068 | vcpu->arch.siar = set_reg_val(id, *val); |
| 1069 | break; |
| 1070 | case KVM_REG_PPC_SDAR: |
| 1071 | vcpu->arch.sdar = set_reg_val(id, *val); |
| 1072 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1073 | case KVM_REG_PPC_SIER: |
| 1074 | vcpu->arch.sier = set_reg_val(id, *val); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 1075 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1076 | case KVM_REG_PPC_IAMR: |
| 1077 | vcpu->arch.iamr = set_reg_val(id, *val); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 1078 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1079 | case KVM_REG_PPC_PSPB: |
| 1080 | vcpu->arch.pspb = set_reg_val(id, *val); |
| 1081 | break; |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1082 | case KVM_REG_PPC_DPDES: |
| 1083 | vcpu->arch.vcore->dpdes = set_reg_val(id, *val); |
| 1084 | break; |
| 1085 | case KVM_REG_PPC_DAWR: |
| 1086 | vcpu->arch.dawr = set_reg_val(id, *val); |
| 1087 | break; |
| 1088 | case KVM_REG_PPC_DAWRX: |
| 1089 | vcpu->arch.dawrx = set_reg_val(id, *val) & ~DAWRX_HYP; |
| 1090 | break; |
| 1091 | case KVM_REG_PPC_CIABR: |
| 1092 | vcpu->arch.ciabr = set_reg_val(id, *val); |
| 1093 | /* Don't allow setting breakpoints in hypervisor code */ |
| 1094 | if ((vcpu->arch.ciabr & CIABR_PRIV) == CIABR_PRIV_HYPER) |
| 1095 | vcpu->arch.ciabr &= ~CIABR_PRIV; /* disable */ |
| 1096 | break; |
| 1097 | case KVM_REG_PPC_IC: |
| 1098 | vcpu->arch.ic = set_reg_val(id, *val); |
| 1099 | break; |
| 1100 | case KVM_REG_PPC_VTB: |
| 1101 | vcpu->arch.vtb = set_reg_val(id, *val); |
| 1102 | break; |
| 1103 | case KVM_REG_PPC_CSIGR: |
| 1104 | vcpu->arch.csigr = set_reg_val(id, *val); |
| 1105 | break; |
| 1106 | case KVM_REG_PPC_TACR: |
| 1107 | vcpu->arch.tacr = set_reg_val(id, *val); |
| 1108 | break; |
| 1109 | case KVM_REG_PPC_TCSCR: |
| 1110 | vcpu->arch.tcscr = set_reg_val(id, *val); |
| 1111 | break; |
| 1112 | case KVM_REG_PPC_PID: |
| 1113 | vcpu->arch.pid = set_reg_val(id, *val); |
| 1114 | break; |
| 1115 | case KVM_REG_PPC_ACOP: |
| 1116 | vcpu->arch.acop = set_reg_val(id, *val); |
| 1117 | break; |
| 1118 | case KVM_REG_PPC_WORT: |
| 1119 | vcpu->arch.wort = set_reg_val(id, *val); |
| 1120 | break; |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 1121 | case KVM_REG_PPC_VPA_ADDR: |
| 1122 | addr = set_reg_val(id, *val); |
| 1123 | r = -EINVAL; |
| 1124 | if (!addr && (vcpu->arch.slb_shadow.next_gpa || |
| 1125 | vcpu->arch.dtl.next_gpa)) |
| 1126 | break; |
| 1127 | r = set_vpa(vcpu, &vcpu->arch.vpa, addr, sizeof(struct lppaca)); |
| 1128 | break; |
| 1129 | case KVM_REG_PPC_VPA_SLB: |
| 1130 | addr = val->vpaval.addr; |
| 1131 | len = val->vpaval.length; |
| 1132 | r = -EINVAL; |
| 1133 | if (addr && !vcpu->arch.vpa.next_gpa) |
| 1134 | break; |
| 1135 | r = set_vpa(vcpu, &vcpu->arch.slb_shadow, addr, len); |
| 1136 | break; |
| 1137 | case KVM_REG_PPC_VPA_DTL: |
| 1138 | addr = val->vpaval.addr; |
| 1139 | len = val->vpaval.length; |
| 1140 | r = -EINVAL; |
Paul Mackerras | 9f8c8c7 | 2012-10-15 01:18:37 +0000 | [diff] [blame] | 1141 | if (addr && (len < sizeof(struct dtl_entry) || |
| 1142 | !vcpu->arch.vpa.next_gpa)) |
Paul Mackerras | 55b665b | 2012-09-25 20:33:06 +0000 | [diff] [blame] | 1143 | break; |
| 1144 | len -= len % sizeof(struct dtl_entry); |
| 1145 | r = set_vpa(vcpu, &vcpu->arch.dtl, addr, len); |
| 1146 | break; |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 1147 | case KVM_REG_PPC_TB_OFFSET: |
| 1148 | /* round up to multiple of 2^24 */ |
| 1149 | vcpu->arch.vcore->tb_offset = |
| 1150 | ALIGN(set_reg_val(id, *val), 1UL << 24); |
| 1151 | break; |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 1152 | case KVM_REG_PPC_LPCR: |
| 1153 | kvmppc_set_lpcr(vcpu, set_reg_val(id, *val)); |
| 1154 | break; |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 1155 | case KVM_REG_PPC_PPR: |
| 1156 | vcpu->arch.ppr = set_reg_val(id, *val); |
| 1157 | break; |
Michael Neuling | a7d80d0 | 2014-03-25 10:47:03 +1100 | [diff] [blame] | 1158 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 1159 | case KVM_REG_PPC_TFHAR: |
| 1160 | vcpu->arch.tfhar = set_reg_val(id, *val); |
| 1161 | break; |
| 1162 | case KVM_REG_PPC_TFIAR: |
| 1163 | vcpu->arch.tfiar = set_reg_val(id, *val); |
| 1164 | break; |
| 1165 | case KVM_REG_PPC_TEXASR: |
| 1166 | vcpu->arch.texasr = set_reg_val(id, *val); |
| 1167 | break; |
| 1168 | case KVM_REG_PPC_TM_GPR0 ... KVM_REG_PPC_TM_GPR31: |
| 1169 | i = id - KVM_REG_PPC_TM_GPR0; |
| 1170 | vcpu->arch.gpr_tm[i] = set_reg_val(id, *val); |
| 1171 | break; |
| 1172 | case KVM_REG_PPC_TM_VSR0 ... KVM_REG_PPC_TM_VSR63: |
| 1173 | { |
| 1174 | int j; |
| 1175 | i = id - KVM_REG_PPC_TM_VSR0; |
| 1176 | if (i < 32) |
| 1177 | for (j = 0; j < TS_FPRWIDTH; j++) |
| 1178 | vcpu->arch.fp_tm.fpr[i][j] = val->vsxval[j]; |
| 1179 | else |
| 1180 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 1181 | vcpu->arch.vr_tm.vr[i-32] = val->vval; |
| 1182 | else |
| 1183 | r = -ENXIO; |
| 1184 | break; |
| 1185 | } |
| 1186 | case KVM_REG_PPC_TM_CR: |
| 1187 | vcpu->arch.cr_tm = set_reg_val(id, *val); |
| 1188 | break; |
| 1189 | case KVM_REG_PPC_TM_LR: |
| 1190 | vcpu->arch.lr_tm = set_reg_val(id, *val); |
| 1191 | break; |
| 1192 | case KVM_REG_PPC_TM_CTR: |
| 1193 | vcpu->arch.ctr_tm = set_reg_val(id, *val); |
| 1194 | break; |
| 1195 | case KVM_REG_PPC_TM_FPSCR: |
| 1196 | vcpu->arch.fp_tm.fpscr = set_reg_val(id, *val); |
| 1197 | break; |
| 1198 | case KVM_REG_PPC_TM_AMR: |
| 1199 | vcpu->arch.amr_tm = set_reg_val(id, *val); |
| 1200 | break; |
| 1201 | case KVM_REG_PPC_TM_PPR: |
| 1202 | vcpu->arch.ppr_tm = set_reg_val(id, *val); |
| 1203 | break; |
| 1204 | case KVM_REG_PPC_TM_VRSAVE: |
| 1205 | vcpu->arch.vrsave_tm = set_reg_val(id, *val); |
| 1206 | break; |
| 1207 | case KVM_REG_PPC_TM_VSCR: |
| 1208 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 1209 | vcpu->arch.vr.vscr.u[3] = set_reg_val(id, *val); |
| 1210 | else |
| 1211 | r = - ENXIO; |
| 1212 | break; |
| 1213 | case KVM_REG_PPC_TM_DSCR: |
| 1214 | vcpu->arch.dscr_tm = set_reg_val(id, *val); |
| 1215 | break; |
| 1216 | case KVM_REG_PPC_TM_TAR: |
| 1217 | vcpu->arch.tar_tm = set_reg_val(id, *val); |
| 1218 | break; |
| 1219 | #endif |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 1220 | case KVM_REG_PPC_ARCH_COMPAT: |
| 1221 | r = kvmppc_set_arch_compat(vcpu, set_reg_val(id, *val)); |
| 1222 | break; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1223 | default: |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 1224 | r = -EINVAL; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1225 | break; |
| 1226 | } |
| 1227 | |
| 1228 | return r; |
| 1229 | } |
| 1230 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1231 | static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct kvm *kvm, |
| 1232 | unsigned int id) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1233 | { |
| 1234 | struct kvm_vcpu *vcpu; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1235 | int err = -EINVAL; |
| 1236 | int core; |
| 1237 | struct kvmppc_vcore *vcore; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1238 | |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1239 | core = id / threads_per_subcore; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1240 | if (core >= KVM_MAX_VCORES) |
| 1241 | goto out; |
| 1242 | |
| 1243 | err = -ENOMEM; |
Sasha Levin | 6b75e6b | 2011-12-07 10:24:56 +0200 | [diff] [blame] | 1244 | vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1245 | if (!vcpu) |
| 1246 | goto out; |
| 1247 | |
| 1248 | err = kvm_vcpu_init(vcpu, kvm, id); |
| 1249 | if (err) |
| 1250 | goto free_vcpu; |
| 1251 | |
| 1252 | vcpu->arch.shared = &vcpu->arch.shregs; |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 1253 | #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE |
| 1254 | /* |
| 1255 | * The shared struct is never shared on HV, |
| 1256 | * so we can always use host endianness |
| 1257 | */ |
| 1258 | #ifdef __BIG_ENDIAN__ |
| 1259 | vcpu->arch.shared_big_endian = true; |
| 1260 | #else |
| 1261 | vcpu->arch.shared_big_endian = false; |
| 1262 | #endif |
| 1263 | #endif |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1264 | vcpu->arch.mmcr[0] = MMCR0_FC; |
| 1265 | vcpu->arch.ctrl = CTRL_RUNLATCH; |
| 1266 | /* default to host PVR, since we can't spoof it */ |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1267 | kvmppc_set_pvr_hv(vcpu, mfspr(SPRN_PVR)); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1268 | spin_lock_init(&vcpu->arch.vpa_update_lock); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1269 | spin_lock_init(&vcpu->arch.tbacct_lock); |
| 1270 | vcpu->arch.busy_preempt = TB_NIL; |
Anton Blanchard | d682916 | 2014-01-08 21:25:30 +1100 | [diff] [blame] | 1271 | vcpu->arch.intr_msr = MSR_SF | MSR_ME; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1272 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1273 | kvmppc_mmu_book3s_hv_init(vcpu); |
| 1274 | |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1275 | vcpu->arch.state = KVMPPC_VCPU_NOTREADY; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1276 | |
| 1277 | init_waitqueue_head(&vcpu->arch.cpu_run); |
| 1278 | |
| 1279 | mutex_lock(&kvm->lock); |
| 1280 | vcore = kvm->arch.vcores[core]; |
| 1281 | if (!vcore) { |
| 1282 | vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL); |
| 1283 | if (vcore) { |
| 1284 | INIT_LIST_HEAD(&vcore->runnable_threads); |
| 1285 | spin_lock_init(&vcore->lock); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1286 | init_waitqueue_head(&vcore->wq); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1287 | vcore->preempt_tb = TB_NIL; |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 1288 | vcore->lpcr = kvm->arch.lpcr; |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1289 | vcore->first_vcpuid = core * threads_per_subcore; |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1290 | vcore->kvm = kvm; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1291 | } |
| 1292 | kvm->arch.vcores[core] = vcore; |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 1293 | kvm->arch.online_vcores++; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1294 | } |
| 1295 | mutex_unlock(&kvm->lock); |
| 1296 | |
| 1297 | if (!vcore) |
| 1298 | goto free_vcpu; |
| 1299 | |
| 1300 | spin_lock(&vcore->lock); |
| 1301 | ++vcore->num_threads; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1302 | spin_unlock(&vcore->lock); |
| 1303 | vcpu->arch.vcore = vcore; |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1304 | vcpu->arch.ptid = vcpu->vcpu_id - vcore->first_vcpuid; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1305 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 1306 | vcpu->arch.cpu_type = KVM_CPU_3S_64; |
| 1307 | kvmppc_sanity_check(vcpu); |
| 1308 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1309 | return vcpu; |
| 1310 | |
| 1311 | free_vcpu: |
Sasha Levin | 6b75e6b | 2011-12-07 10:24:56 +0200 | [diff] [blame] | 1312 | kmem_cache_free(kvm_vcpu_cache, vcpu); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1313 | out: |
| 1314 | return ERR_PTR(err); |
| 1315 | } |
| 1316 | |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 1317 | static void unpin_vpa(struct kvm *kvm, struct kvmppc_vpa *vpa) |
| 1318 | { |
| 1319 | if (vpa->pinned_addr) |
| 1320 | kvmppc_unpin_guest_page(kvm, vpa->pinned_addr, vpa->gpa, |
| 1321 | vpa->dirty); |
| 1322 | } |
| 1323 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1324 | static void kvmppc_core_vcpu_free_hv(struct kvm_vcpu *vcpu) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1325 | { |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1326 | spin_lock(&vcpu->arch.vpa_update_lock); |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 1327 | unpin_vpa(vcpu->kvm, &vcpu->arch.dtl); |
| 1328 | unpin_vpa(vcpu->kvm, &vcpu->arch.slb_shadow); |
| 1329 | unpin_vpa(vcpu->kvm, &vcpu->arch.vpa); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1330 | spin_unlock(&vcpu->arch.vpa_update_lock); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1331 | kvm_vcpu_uninit(vcpu); |
Sasha Levin | 6b75e6b | 2011-12-07 10:24:56 +0200 | [diff] [blame] | 1332 | kmem_cache_free(kvm_vcpu_cache, vcpu); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1335 | static int kvmppc_core_check_requests_hv(struct kvm_vcpu *vcpu) |
| 1336 | { |
| 1337 | /* Indicate we want to get back into the guest */ |
| 1338 | return 1; |
| 1339 | } |
| 1340 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1341 | static void kvmppc_set_timer(struct kvm_vcpu *vcpu) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1342 | { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1343 | unsigned long dec_nsec, now; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1344 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1345 | now = get_tb(); |
| 1346 | if (now > vcpu->arch.dec_expires) { |
| 1347 | /* decrementer has already gone negative */ |
| 1348 | kvmppc_core_queue_dec(vcpu); |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 1349 | kvmppc_core_prepare_to_enter(vcpu); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1350 | return; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1351 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1352 | dec_nsec = (vcpu->arch.dec_expires - now) * NSEC_PER_SEC |
| 1353 | / tb_ticks_per_sec; |
| 1354 | hrtimer_start(&vcpu->arch.dec_timer, ktime_set(0, dec_nsec), |
| 1355 | HRTIMER_MODE_REL); |
| 1356 | vcpu->arch.timer_running = 1; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1359 | static void kvmppc_end_cede(struct kvm_vcpu *vcpu) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1360 | { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1361 | vcpu->arch.ceded = 0; |
| 1362 | if (vcpu->arch.timer_running) { |
| 1363 | hrtimer_try_to_cancel(&vcpu->arch.dec_timer); |
| 1364 | vcpu->arch.timer_running = 0; |
| 1365 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1368 | extern void __kvmppc_vcore_entry(void); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1369 | |
| 1370 | static void kvmppc_remove_runnable(struct kvmppc_vcore *vc, |
| 1371 | struct kvm_vcpu *vcpu) |
| 1372 | { |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1373 | u64 now; |
| 1374 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1375 | if (vcpu->arch.state != KVMPPC_VCPU_RUNNABLE) |
| 1376 | return; |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 1377 | spin_lock_irq(&vcpu->arch.tbacct_lock); |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1378 | now = mftb(); |
| 1379 | vcpu->arch.busy_stolen += vcore_stolen_time(vc, now) - |
| 1380 | vcpu->arch.stolen_logged; |
| 1381 | vcpu->arch.busy_preempt = now; |
| 1382 | vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; |
Paul Mackerras | bf3d32e | 2013-11-16 17:46:04 +1100 | [diff] [blame] | 1383 | spin_unlock_irq(&vcpu->arch.tbacct_lock); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1384 | --vc->n_runnable; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1385 | list_del(&vcpu->arch.run_list); |
| 1386 | } |
| 1387 | |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 1388 | static int kvmppc_grab_hwthread(int cpu) |
| 1389 | { |
| 1390 | struct paca_struct *tpaca; |
| 1391 | long timeout = 1000; |
| 1392 | |
| 1393 | tpaca = &paca[cpu]; |
| 1394 | |
| 1395 | /* Ensure the thread won't go into the kernel if it wakes */ |
| 1396 | tpaca->kvm_hstate.hwthread_req = 1; |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1397 | tpaca->kvm_hstate.kvm_vcpu = NULL; |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 1398 | |
| 1399 | /* |
| 1400 | * If the thread is already executing in the kernel (e.g. handling |
| 1401 | * a stray interrupt), wait for it to get back to nap mode. |
| 1402 | * The smp_mb() is to ensure that our setting of hwthread_req |
| 1403 | * is visible before we look at hwthread_state, so if this |
| 1404 | * races with the code at system_reset_pSeries and the thread |
| 1405 | * misses our setting of hwthread_req, we are sure to see its |
| 1406 | * setting of hwthread_state, and vice versa. |
| 1407 | */ |
| 1408 | smp_mb(); |
| 1409 | while (tpaca->kvm_hstate.hwthread_state == KVM_HWTHREAD_IN_KERNEL) { |
| 1410 | if (--timeout <= 0) { |
| 1411 | pr_err("KVM: couldn't grab cpu %d\n", cpu); |
| 1412 | return -EBUSY; |
| 1413 | } |
| 1414 | udelay(1); |
| 1415 | } |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
| 1419 | static void kvmppc_release_hwthread(int cpu) |
| 1420 | { |
| 1421 | struct paca_struct *tpaca; |
| 1422 | |
| 1423 | tpaca = &paca[cpu]; |
| 1424 | tpaca->kvm_hstate.hwthread_req = 0; |
| 1425 | tpaca->kvm_hstate.kvm_vcpu = NULL; |
| 1426 | } |
| 1427 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1428 | static void kvmppc_start_thread(struct kvm_vcpu *vcpu) |
| 1429 | { |
| 1430 | int cpu; |
| 1431 | struct paca_struct *tpaca; |
| 1432 | struct kvmppc_vcore *vc = vcpu->arch.vcore; |
| 1433 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1434 | if (vcpu->arch.timer_running) { |
| 1435 | hrtimer_try_to_cancel(&vcpu->arch.dec_timer); |
| 1436 | vcpu->arch.timer_running = 0; |
| 1437 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1438 | cpu = vc->pcpu + vcpu->arch.ptid; |
| 1439 | tpaca = &paca[cpu]; |
| 1440 | tpaca->kvm_hstate.kvm_vcpu = vcpu; |
| 1441 | tpaca->kvm_hstate.kvm_vcore = vc; |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1442 | tpaca->kvm_hstate.ptid = vcpu->arch.ptid; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1443 | vcpu->cpu = vc->pcpu; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1444 | smp_wmb(); |
Michael Neuling | 251da03 | 2011-11-10 16:03:20 +0000 | [diff] [blame] | 1445 | #if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1446 | if (cpu != smp_processor_id()) { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1447 | xics_wake_cpu(cpu); |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1448 | if (vcpu->arch.ptid) |
| 1449 | ++vc->n_woken; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1450 | } |
| 1451 | #endif |
| 1452 | } |
| 1453 | |
| 1454 | static void kvmppc_wait_for_nap(struct kvmppc_vcore *vc) |
| 1455 | { |
| 1456 | int i; |
| 1457 | |
| 1458 | HMT_low(); |
| 1459 | i = 0; |
| 1460 | while (vc->nap_count < vc->n_woken) { |
| 1461 | if (++i >= 1000000) { |
| 1462 | pr_err("kvmppc_wait_for_nap timeout %d %d\n", |
| 1463 | vc->nap_count, vc->n_woken); |
| 1464 | break; |
| 1465 | } |
| 1466 | cpu_relax(); |
| 1467 | } |
| 1468 | HMT_medium(); |
| 1469 | } |
| 1470 | |
| 1471 | /* |
| 1472 | * 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] | 1473 | * this core are off-line. Then grab the threads so they can't |
| 1474 | * enter the kernel. |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1475 | */ |
| 1476 | static int on_primary_thread(void) |
| 1477 | { |
| 1478 | int cpu = smp_processor_id(); |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1479 | int thr; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1480 | |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1481 | /* Are we on a primary subcore? */ |
| 1482 | if (cpu_thread_in_subcore(cpu)) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1483 | return 0; |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1484 | |
| 1485 | thr = 0; |
| 1486 | while (++thr < threads_per_subcore) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1487 | if (cpu_online(cpu + thr)) |
| 1488 | return 0; |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1489 | |
| 1490 | /* Grab all hw threads so they can't go into the kernel */ |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1491 | for (thr = 1; thr < threads_per_subcore; ++thr) { |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1492 | if (kvmppc_grab_hwthread(cpu + thr)) { |
| 1493 | /* Couldn't grab one; let the others go */ |
| 1494 | do { |
| 1495 | kvmppc_release_hwthread(cpu + thr); |
| 1496 | } while (--thr > 0); |
| 1497 | return 0; |
| 1498 | } |
| 1499 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1500 | return 1; |
| 1501 | } |
| 1502 | |
| 1503 | /* |
| 1504 | * Run a set of guest threads on a physical core. |
| 1505 | * Called with vc->lock held. |
| 1506 | */ |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1507 | static void kvmppc_run_core(struct kvmppc_vcore *vc) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1508 | { |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1509 | struct kvm_vcpu *vcpu, *vnext; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1510 | long ret; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1511 | u64 now; |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1512 | int i, need_vpa_update; |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 1513 | int srcu_idx; |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1514 | struct kvm_vcpu *vcpus_to_update[threads_per_core]; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1515 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1516 | /* don't start if any threads have a signal pending */ |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 1517 | need_vpa_update = 0; |
| 1518 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1519 | if (signal_pending(vcpu->arch.run_task)) |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1520 | return; |
| 1521 | if (vcpu->arch.vpa.update_pending || |
| 1522 | vcpu->arch.slb_shadow.update_pending || |
| 1523 | vcpu->arch.dtl.update_pending) |
| 1524 | vcpus_to_update[need_vpa_update++] = vcpu; |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /* |
| 1528 | * Initialize *vc, in particular vc->vcore_state, so we can |
| 1529 | * drop the vcore lock if necessary. |
| 1530 | */ |
| 1531 | vc->n_woken = 0; |
| 1532 | vc->nap_count = 0; |
| 1533 | vc->entry_exit_count = 0; |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1534 | vc->vcore_state = VCORE_STARTING; |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 1535 | vc->in_guest = 0; |
| 1536 | vc->napping_threads = 0; |
| 1537 | |
| 1538 | /* |
| 1539 | * Updating any of the vpas requires calling kvmppc_pin_guest_page, |
| 1540 | * which can't be called with any spinlocks held. |
| 1541 | */ |
| 1542 | if (need_vpa_update) { |
| 1543 | spin_unlock(&vc->lock); |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1544 | for (i = 0; i < need_vpa_update; ++i) |
| 1545 | kvmppc_update_vpas(vcpus_to_update[i]); |
Paul Mackerras | 081f323 | 2012-06-01 20:20:24 +1000 | [diff] [blame] | 1546 | spin_lock(&vc->lock); |
| 1547 | } |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1548 | |
| 1549 | /* |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1550 | * Make sure we are running on primary threads, and that secondary |
| 1551 | * threads are offline. Also check if the number of threads in this |
| 1552 | * guest are greater than the current system threads per guest. |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1553 | */ |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1554 | if ((threads_per_core > 1) && |
| 1555 | ((vc->num_threads > threads_per_subcore) || !on_primary_thread())) { |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 1556 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) |
| 1557 | vcpu->arch.ret = -EBUSY; |
| 1558 | goto out; |
| 1559 | } |
| 1560 | |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1561 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1562 | vc->pcpu = smp_processor_id(); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1563 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1564 | kvmppc_start_thread(vcpu); |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 1565 | kvmppc_create_dtl_entry(vcpu, vc); |
Paul Mackerras | 2e25aa5 | 2012-02-19 17:46:32 +0000 | [diff] [blame] | 1566 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1567 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1568 | /* Set this explicitly in case thread 0 doesn't have a vcpu */ |
| 1569 | get_paca()->kvm_hstate.kvm_vcore = vc; |
| 1570 | get_paca()->kvm_hstate.ptid = 0; |
| 1571 | |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1572 | vc->vcore_state = VCORE_RUNNING; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1573 | preempt_disable(); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1574 | spin_unlock(&vc->lock); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1575 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1576 | kvm_guest_enter(); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 1577 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1578 | srcu_idx = srcu_read_lock(&vc->kvm->srcu); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 1579 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1580 | __kvmppc_vcore_entry(); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1581 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1582 | spin_lock(&vc->lock); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1583 | /* disable sending of IPIs on virtual external irqs */ |
| 1584 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) |
| 1585 | vcpu->cpu = -1; |
| 1586 | /* wait for secondary threads to finish writing their state to memory */ |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1587 | if (vc->nap_count < vc->n_woken) |
| 1588 | kvmppc_wait_for_nap(vc); |
Michael Ellerman | 3102f78 | 2014-05-23 18:15:29 +1000 | [diff] [blame] | 1589 | for (i = 0; i < threads_per_subcore; ++i) |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1590 | kvmppc_release_hwthread(vc->pcpu + i); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1591 | /* prevent other vcpu threads from doing kvmppc_start_thread() now */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1592 | vc->vcore_state = VCORE_EXITING; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1593 | spin_unlock(&vc->lock); |
| 1594 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1595 | srcu_read_unlock(&vc->kvm->srcu, srcu_idx); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 1596 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1597 | /* make sure updates to secondary vcpu structs are visible now */ |
| 1598 | smp_mb(); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1599 | kvm_guest_exit(); |
| 1600 | |
| 1601 | preempt_enable(); |
Takuya Yoshikawa | c08ac06 | 2013-12-13 15:07:21 +0900 | [diff] [blame] | 1602 | cond_resched(); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1603 | |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1604 | spin_lock(&vc->lock); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1605 | now = get_tb(); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1606 | list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { |
| 1607 | /* cancel pending dec exception if dec is positive */ |
| 1608 | if (now < vcpu->arch.dec_expires && |
| 1609 | kvmppc_core_pending_dec(vcpu)) |
| 1610 | kvmppc_core_dequeue_dec(vcpu); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1611 | |
| 1612 | ret = RESUME_GUEST; |
| 1613 | if (vcpu->arch.trap) |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1614 | ret = kvmppc_handle_exit_hv(vcpu->arch.kvm_run, vcpu, |
| 1615 | vcpu->arch.run_task); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1616 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1617 | vcpu->arch.ret = ret; |
| 1618 | vcpu->arch.trap = 0; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1619 | |
| 1620 | if (vcpu->arch.ceded) { |
Greg Kurz | e59d24e | 2014-02-06 17:36:56 +0100 | [diff] [blame] | 1621 | if (!is_kvmppc_resume_guest(ret)) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1622 | kvmppc_end_cede(vcpu); |
| 1623 | else |
| 1624 | kvmppc_set_timer(vcpu); |
| 1625 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1626 | } |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1627 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1628 | out: |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1629 | vc->vcore_state = VCORE_INACTIVE; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1630 | list_for_each_entry_safe(vcpu, vnext, &vc->runnable_threads, |
| 1631 | arch.run_list) { |
Greg Kurz | e59d24e | 2014-02-06 17:36:56 +0100 | [diff] [blame] | 1632 | if (!is_kvmppc_resume_guest(vcpu->arch.ret)) { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1633 | kvmppc_remove_runnable(vc, vcpu); |
| 1634 | wake_up(&vcpu->arch.cpu_run); |
| 1635 | } |
| 1636 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1639 | /* |
| 1640 | * Wait for some other vcpu thread to execute us, and |
| 1641 | * wake us up when we need to handle something in the host. |
| 1642 | */ |
| 1643 | 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] | 1644 | { |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1645 | DEFINE_WAIT(wait); |
| 1646 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1647 | prepare_to_wait(&vcpu->arch.cpu_run, &wait, wait_state); |
| 1648 | if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) |
| 1649 | schedule(); |
| 1650 | finish_wait(&vcpu->arch.cpu_run, &wait); |
| 1651 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1652 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1653 | /* |
| 1654 | * All the vcpus in this vcore are idle, so wait for a decrementer |
| 1655 | * or external interrupt to one of the vcpus. vc->lock is held. |
| 1656 | */ |
| 1657 | static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) |
| 1658 | { |
| 1659 | DEFINE_WAIT(wait); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1660 | |
| 1661 | prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE); |
| 1662 | vc->vcore_state = VCORE_SLEEPING; |
| 1663 | spin_unlock(&vc->lock); |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1664 | schedule(); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1665 | finish_wait(&vc->wq, &wait); |
| 1666 | spin_lock(&vc->lock); |
| 1667 | vc->vcore_state = VCORE_INACTIVE; |
| 1668 | } |
| 1669 | |
| 1670 | static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) |
| 1671 | { |
| 1672 | int n_ceded; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1673 | struct kvmppc_vcore *vc; |
| 1674 | struct kvm_vcpu *v, *vn; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1675 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1676 | kvm_run->exit_reason = 0; |
| 1677 | vcpu->arch.ret = RESUME_GUEST; |
| 1678 | vcpu->arch.trap = 0; |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1679 | kvmppc_update_vpas(vcpu); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1680 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1681 | /* |
| 1682 | * Synchronize with other threads in this virtual core |
| 1683 | */ |
| 1684 | vc = vcpu->arch.vcore; |
| 1685 | spin_lock(&vc->lock); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1686 | vcpu->arch.ceded = 0; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1687 | vcpu->arch.run_task = current; |
| 1688 | vcpu->arch.kvm_run = kvm_run; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1689 | vcpu->arch.stolen_logged = vcore_stolen_time(vc, mftb()); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1690 | vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1691 | vcpu->arch.busy_preempt = TB_NIL; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1692 | list_add_tail(&vcpu->arch.run_list, &vc->runnable_threads); |
| 1693 | ++vc->n_runnable; |
| 1694 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1695 | /* |
| 1696 | * This happens the first time this is called for a vcpu. |
| 1697 | * If the vcore is already running, we may be able to start |
| 1698 | * this thread straight away and have it join in. |
| 1699 | */ |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1700 | if (!signal_pending(current)) { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1701 | if (vc->vcore_state == VCORE_RUNNING && |
| 1702 | VCORE_EXIT_COUNT(vc) == 0) { |
Paul Mackerras | 2f12f03 | 2012-10-15 01:17:17 +0000 | [diff] [blame] | 1703 | kvmppc_create_dtl_entry(vcpu, vc); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1704 | kvmppc_start_thread(vcpu); |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1705 | } else if (vc->vcore_state == VCORE_SLEEPING) { |
| 1706 | wake_up(&vc->wq); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1707 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1708 | |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1709 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1710 | |
| 1711 | while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE && |
| 1712 | !signal_pending(current)) { |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1713 | if (vc->vcore_state != VCORE_INACTIVE) { |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1714 | spin_unlock(&vc->lock); |
| 1715 | kvmppc_wait_for_exec(vcpu, TASK_INTERRUPTIBLE); |
| 1716 | spin_lock(&vc->lock); |
| 1717 | continue; |
| 1718 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1719 | list_for_each_entry_safe(v, vn, &vc->runnable_threads, |
| 1720 | arch.run_list) { |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 1721 | kvmppc_core_prepare_to_enter(v); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1722 | if (signal_pending(v->arch.run_task)) { |
| 1723 | kvmppc_remove_runnable(vc, v); |
| 1724 | v->stat.signal_exits++; |
| 1725 | v->arch.kvm_run->exit_reason = KVM_EXIT_INTR; |
| 1726 | v->arch.ret = -EINTR; |
| 1727 | wake_up(&v->arch.cpu_run); |
| 1728 | } |
| 1729 | } |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1730 | if (!vc->n_runnable || vcpu->arch.state != KVMPPC_VCPU_RUNNABLE) |
| 1731 | break; |
| 1732 | vc->runner = vcpu; |
| 1733 | n_ceded = 0; |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1734 | list_for_each_entry(v, &vc->runnable_threads, arch.run_list) { |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1735 | if (!v->arch.pending_exceptions) |
| 1736 | n_ceded += v->arch.ceded; |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1737 | else |
| 1738 | v->arch.ceded = 0; |
| 1739 | } |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1740 | if (n_ceded == vc->n_runnable) |
| 1741 | kvmppc_vcore_blocked(vc); |
| 1742 | else |
| 1743 | kvmppc_run_core(vc); |
Paul Mackerras | 0456ec4 | 2012-02-03 00:56:21 +0000 | [diff] [blame] | 1744 | vc->runner = NULL; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Paul Mackerras | 8455d79 | 2012-10-15 01:17:42 +0000 | [diff] [blame] | 1747 | while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE && |
| 1748 | (vc->vcore_state == VCORE_RUNNING || |
| 1749 | vc->vcore_state == VCORE_EXITING)) { |
| 1750 | spin_unlock(&vc->lock); |
| 1751 | kvmppc_wait_for_exec(vcpu, TASK_UNINTERRUPTIBLE); |
| 1752 | spin_lock(&vc->lock); |
| 1753 | } |
| 1754 | |
| 1755 | if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) { |
| 1756 | kvmppc_remove_runnable(vc, vcpu); |
| 1757 | vcpu->stat.signal_exits++; |
| 1758 | kvm_run->exit_reason = KVM_EXIT_INTR; |
| 1759 | vcpu->arch.ret = -EINTR; |
| 1760 | } |
| 1761 | |
| 1762 | if (vc->n_runnable && vc->vcore_state == VCORE_INACTIVE) { |
| 1763 | /* Wake up some vcpu to run the core */ |
| 1764 | v = list_first_entry(&vc->runnable_threads, |
| 1765 | struct kvm_vcpu, arch.run_list); |
| 1766 | wake_up(&v->arch.cpu_run); |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1767 | } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1768 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1769 | spin_unlock(&vc->lock); |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 1770 | return vcpu->arch.ret; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1773 | 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] | 1774 | { |
| 1775 | int r; |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1776 | int srcu_idx; |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1777 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 1778 | if (!vcpu->arch.sane) { |
| 1779 | run->exit_reason = KVM_EXIT_INTERNAL_ERROR; |
| 1780 | return -EINVAL; |
| 1781 | } |
| 1782 | |
Scott Wood | 25051b5 | 2011-11-08 18:23:23 -0600 | [diff] [blame] | 1783 | kvmppc_core_prepare_to_enter(vcpu); |
| 1784 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1785 | /* No need to go into the guest when all we'll do is come back out */ |
| 1786 | if (signal_pending(current)) { |
| 1787 | run->exit_reason = KVM_EXIT_INTR; |
| 1788 | return -EINTR; |
| 1789 | } |
| 1790 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1791 | atomic_inc(&vcpu->kvm->arch.vcpus_running); |
| 1792 | /* Order vcpus_running vs. rma_setup_done, see kvmppc_alloc_reset_hpt */ |
| 1793 | smp_mb(); |
| 1794 | |
| 1795 | /* On the first time here, set up HTAB and VRMA or RMA */ |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1796 | if (!vcpu->kvm->arch.rma_setup_done) { |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1797 | r = kvmppc_hv_setup_htab_rma(vcpu); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1798 | if (r) |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1799 | goto out; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 1800 | } |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1801 | |
| 1802 | flush_fp_to_thread(current); |
| 1803 | flush_altivec_to_thread(current); |
| 1804 | flush_vsx_to_thread(current); |
| 1805 | vcpu->arch.wqp = &vcpu->arch.vcore->wq; |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1806 | vcpu->arch.pgdir = current->mm->pgd; |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1807 | vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1808 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1809 | do { |
| 1810 | r = kvmppc_run_vcpu(run, vcpu); |
| 1811 | |
| 1812 | if (run->exit_reason == KVM_EXIT_PAPR_HCALL && |
| 1813 | !(vcpu->arch.shregs.msr & MSR_PR)) { |
| 1814 | r = kvmppc_pseries_do_hcall(vcpu); |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 1815 | kvmppc_core_prepare_to_enter(vcpu); |
Paul Mackerras | 913d3ff9a | 2012-10-15 01:16:48 +0000 | [diff] [blame] | 1816 | } else if (r == RESUME_PAGE_FAULT) { |
| 1817 | srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); |
| 1818 | r = kvmppc_book3s_hv_page_fault(run, vcpu, |
| 1819 | vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); |
| 1820 | srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1821 | } |
Greg Kurz | e59d24e | 2014-02-06 17:36:56 +0100 | [diff] [blame] | 1822 | } while (is_kvmppc_resume_guest(r)); |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1823 | |
| 1824 | out: |
Paul Mackerras | c7b6767 | 2012-10-15 01:18:07 +0000 | [diff] [blame] | 1825 | vcpu->arch.state = KVMPPC_VCPU_NOTREADY; |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 1826 | atomic_dec(&vcpu->kvm->arch.vcpus_running); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1827 | return r; |
| 1828 | } |
| 1829 | |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 1830 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1831 | /* 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] | 1832 | Assumes POWER7 or PPC970. */ |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1833 | static inline int lpcr_rmls(unsigned long rma_size) |
| 1834 | { |
| 1835 | switch (rma_size) { |
| 1836 | case 32ul << 20: /* 32 MB */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1837 | if (cpu_has_feature(CPU_FTR_ARCH_206)) |
| 1838 | return 8; /* only supported on POWER7 */ |
| 1839 | return -1; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1840 | case 64ul << 20: /* 64 MB */ |
| 1841 | return 3; |
| 1842 | case 128ul << 20: /* 128 MB */ |
| 1843 | return 7; |
| 1844 | case 256ul << 20: /* 256 MB */ |
| 1845 | return 4; |
| 1846 | case 1ul << 30: /* 1 GB */ |
| 1847 | return 2; |
| 1848 | case 16ul << 30: /* 16 GB */ |
| 1849 | return 1; |
| 1850 | case 256ul << 30: /* 256 GB */ |
| 1851 | return 0; |
| 1852 | default: |
| 1853 | return -1; |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | static int kvm_rma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
| 1858 | { |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1859 | struct page *page; |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1860 | struct kvm_rma_info *ri = vma->vm_file->private_data; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1861 | |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1862 | if (vmf->pgoff >= kvm_rma_pages) |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1863 | return VM_FAULT_SIGBUS; |
| 1864 | |
| 1865 | page = pfn_to_page(ri->base_pfn + vmf->pgoff); |
| 1866 | get_page(page); |
| 1867 | vmf->page = page; |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
| 1871 | static const struct vm_operations_struct kvm_rma_vm_ops = { |
| 1872 | .fault = kvm_rma_fault, |
| 1873 | }; |
| 1874 | |
| 1875 | static int kvm_rma_mmap(struct file *file, struct vm_area_struct *vma) |
| 1876 | { |
Konstantin Khlebnikov | 314e51b | 2012-10-08 16:29:02 -0700 | [diff] [blame] | 1877 | vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1878 | vma->vm_ops = &kvm_rma_vm_ops; |
| 1879 | return 0; |
| 1880 | } |
| 1881 | |
| 1882 | static int kvm_rma_release(struct inode *inode, struct file *filp) |
| 1883 | { |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1884 | struct kvm_rma_info *ri = filp->private_data; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1885 | |
| 1886 | kvm_release_rma(ri); |
| 1887 | return 0; |
| 1888 | } |
| 1889 | |
Al Viro | 75ef9de | 2013-04-04 19:09:41 -0400 | [diff] [blame] | 1890 | static const struct file_operations kvm_rma_fops = { |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1891 | .mmap = kvm_rma_mmap, |
| 1892 | .release = kvm_rma_release, |
| 1893 | }; |
| 1894 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1895 | static long kvm_vm_ioctl_allocate_rma(struct kvm *kvm, |
| 1896 | struct kvm_allocate_rma *ret) |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1897 | { |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1898 | long fd; |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1899 | struct kvm_rma_info *ri; |
| 1900 | /* |
| 1901 | * Only do this on PPC970 in HV mode |
| 1902 | */ |
| 1903 | if (!cpu_has_feature(CPU_FTR_HVMODE) || |
| 1904 | !cpu_has_feature(CPU_FTR_ARCH_201)) |
| 1905 | return -EINVAL; |
| 1906 | |
| 1907 | if (!kvm_rma_pages) |
| 1908 | return -EINVAL; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1909 | |
| 1910 | ri = kvm_alloc_rma(); |
| 1911 | if (!ri) |
| 1912 | return -ENOMEM; |
| 1913 | |
Yann Droneaud | 2f84d5e | 2013-08-24 22:14:08 +0200 | [diff] [blame] | 1914 | 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] | 1915 | if (fd < 0) |
| 1916 | kvm_release_rma(ri); |
| 1917 | |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 1918 | ret->rma_size = kvm_rma_pages << PAGE_SHIFT; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 1919 | return fd; |
| 1920 | } |
| 1921 | |
Benjamin Herrenschmidt | 5b74716 | 2012-04-26 19:43:42 +0000 | [diff] [blame] | 1922 | static void kvmppc_add_seg_page_size(struct kvm_ppc_one_seg_page_size **sps, |
| 1923 | int linux_psize) |
| 1924 | { |
| 1925 | struct mmu_psize_def *def = &mmu_psize_defs[linux_psize]; |
| 1926 | |
| 1927 | if (!def->shift) |
| 1928 | return; |
| 1929 | (*sps)->page_shift = def->shift; |
| 1930 | (*sps)->slb_enc = def->sllp; |
| 1931 | (*sps)->enc[0].page_shift = def->shift; |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 1932 | /* |
| 1933 | * Only return base page encoding. We don't want to return |
| 1934 | * all the supporting pte_enc, because our H_ENTER doesn't |
| 1935 | * support MPSS yet. Once they do, we can start passing all |
| 1936 | * support pte_enc here |
| 1937 | */ |
| 1938 | (*sps)->enc[0].pte_enc = def->penc[linux_psize]; |
Aneesh Kumar K.V | 1f365bb | 2014-05-06 23:31:36 +0530 | [diff] [blame] | 1939 | /* |
| 1940 | * Add 16MB MPSS support if host supports it |
| 1941 | */ |
| 1942 | if (linux_psize != MMU_PAGE_16M && def->penc[MMU_PAGE_16M] != -1) { |
| 1943 | (*sps)->enc[1].page_shift = 24; |
| 1944 | (*sps)->enc[1].pte_enc = def->penc[MMU_PAGE_16M]; |
| 1945 | } |
Benjamin Herrenschmidt | 5b74716 | 2012-04-26 19:43:42 +0000 | [diff] [blame] | 1946 | (*sps)++; |
| 1947 | } |
| 1948 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1949 | static int kvm_vm_ioctl_get_smmu_info_hv(struct kvm *kvm, |
| 1950 | struct kvm_ppc_smmu_info *info) |
Benjamin Herrenschmidt | 5b74716 | 2012-04-26 19:43:42 +0000 | [diff] [blame] | 1951 | { |
| 1952 | struct kvm_ppc_one_seg_page_size *sps; |
| 1953 | |
| 1954 | info->flags = KVM_PPC_PAGE_SIZES_REAL; |
| 1955 | if (mmu_has_feature(MMU_FTR_1T_SEGMENT)) |
| 1956 | info->flags |= KVM_PPC_1T_SEGMENTS; |
| 1957 | info->slb_size = mmu_slb_size; |
| 1958 | |
| 1959 | /* We only support these sizes for now, and no muti-size segments */ |
| 1960 | sps = &info->sps[0]; |
| 1961 | kvmppc_add_seg_page_size(&sps, MMU_PAGE_4K); |
| 1962 | kvmppc_add_seg_page_size(&sps, MMU_PAGE_64K); |
| 1963 | kvmppc_add_seg_page_size(&sps, MMU_PAGE_16M); |
| 1964 | |
| 1965 | return 0; |
| 1966 | } |
| 1967 | |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 1968 | /* |
| 1969 | * Get (and clear) the dirty memory log for a memory slot. |
| 1970 | */ |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1971 | static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm, |
| 1972 | struct kvm_dirty_log *log) |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 1973 | { |
| 1974 | struct kvm_memory_slot *memslot; |
| 1975 | int r; |
| 1976 | unsigned long n; |
| 1977 | |
| 1978 | mutex_lock(&kvm->slots_lock); |
| 1979 | |
| 1980 | r = -EINVAL; |
Alex Williamson | bbacc0c | 2012-12-10 10:33:09 -0700 | [diff] [blame] | 1981 | if (log->slot >= KVM_USER_MEM_SLOTS) |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 1982 | goto out; |
| 1983 | |
| 1984 | memslot = id_to_memslot(kvm->memslots, log->slot); |
| 1985 | r = -ENOENT; |
| 1986 | if (!memslot->dirty_bitmap) |
| 1987 | goto out; |
| 1988 | |
| 1989 | n = kvm_dirty_bitmap_bytes(memslot); |
| 1990 | memset(memslot->dirty_bitmap, 0, n); |
| 1991 | |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 1992 | r = kvmppc_hv_get_dirty_log(kvm, memslot, memslot->dirty_bitmap); |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 1993 | if (r) |
| 1994 | goto out; |
| 1995 | |
| 1996 | r = -EFAULT; |
| 1997 | if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) |
| 1998 | goto out; |
| 1999 | |
| 2000 | r = 0; |
| 2001 | out: |
| 2002 | mutex_unlock(&kvm->slots_lock); |
| 2003 | return r; |
| 2004 | } |
| 2005 | |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2006 | static void unpin_slot(struct kvm_memory_slot *memslot) |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2007 | { |
| 2008 | unsigned long *physp; |
| 2009 | unsigned long j, npages, pfn; |
| 2010 | struct page *page; |
| 2011 | |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2012 | physp = memslot->arch.slot_phys; |
| 2013 | npages = memslot->npages; |
| 2014 | if (!physp) |
| 2015 | return; |
| 2016 | for (j = 0; j < npages; j++) { |
| 2017 | if (!(physp[j] & KVMPPC_GOT_PAGE)) |
| 2018 | continue; |
| 2019 | pfn = physp[j] >> PAGE_SHIFT; |
| 2020 | page = pfn_to_page(pfn); |
| 2021 | SetPageDirty(page); |
| 2022 | put_page(page); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2023 | } |
| 2024 | } |
| 2025 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2026 | static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free, |
| 2027 | struct kvm_memory_slot *dont) |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2028 | { |
| 2029 | if (!dont || free->arch.rmap != dont->arch.rmap) { |
| 2030 | vfree(free->arch.rmap); |
| 2031 | free->arch.rmap = NULL; |
| 2032 | } |
| 2033 | if (!dont || free->arch.slot_phys != dont->arch.slot_phys) { |
| 2034 | unpin_slot(free); |
| 2035 | vfree(free->arch.slot_phys); |
| 2036 | free->arch.slot_phys = NULL; |
| 2037 | } |
| 2038 | } |
| 2039 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2040 | static int kvmppc_core_create_memslot_hv(struct kvm_memory_slot *slot, |
| 2041 | unsigned long npages) |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2042 | { |
| 2043 | slot->arch.rmap = vzalloc(npages * sizeof(*slot->arch.rmap)); |
| 2044 | if (!slot->arch.rmap) |
| 2045 | return -ENOMEM; |
| 2046 | slot->arch.slot_phys = NULL; |
| 2047 | |
| 2048 | return 0; |
| 2049 | } |
| 2050 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2051 | static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm, |
| 2052 | struct kvm_memory_slot *memslot, |
| 2053 | struct kvm_userspace_memory_region *mem) |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2054 | { |
| 2055 | unsigned long *phys; |
| 2056 | |
| 2057 | /* Allocate a slot_phys array if needed */ |
| 2058 | phys = memslot->arch.slot_phys; |
| 2059 | if (!kvm->arch.using_mmu_notifiers && !phys && memslot->npages) { |
| 2060 | phys = vzalloc(memslot->npages * sizeof(unsigned long)); |
| 2061 | if (!phys) |
| 2062 | return -ENOMEM; |
| 2063 | memslot->arch.slot_phys = phys; |
| 2064 | } |
| 2065 | |
| 2066 | return 0; |
| 2067 | } |
| 2068 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2069 | static void kvmppc_core_commit_memory_region_hv(struct kvm *kvm, |
| 2070 | struct kvm_userspace_memory_region *mem, |
| 2071 | const struct kvm_memory_slot *old) |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2072 | { |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 2073 | unsigned long npages = mem->memory_size >> PAGE_SHIFT; |
| 2074 | struct kvm_memory_slot *memslot; |
| 2075 | |
Takuya Yoshikawa | 8482644 | 2013-02-27 19:45:25 +0900 | [diff] [blame] | 2076 | if (npages && old->npages) { |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 2077 | /* |
| 2078 | * If modifying a memslot, reset all the rmap dirty bits. |
| 2079 | * If this is a new memslot, we don't need to do anything |
| 2080 | * since the rmap array starts out as all zeroes, |
| 2081 | * i.e. no pages are dirty. |
| 2082 | */ |
| 2083 | memslot = id_to_memslot(kvm->memslots, mem->slot); |
| 2084 | kvmppc_hv_get_dirty_log(kvm, memslot, NULL); |
| 2085 | } |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2088 | /* |
| 2089 | * Update LPCR values in kvm->arch and in vcores. |
| 2090 | * Caller must hold kvm->lock. |
| 2091 | */ |
| 2092 | void kvmppc_update_lpcr(struct kvm *kvm, unsigned long lpcr, unsigned long mask) |
| 2093 | { |
| 2094 | long int i; |
| 2095 | u32 cores_done = 0; |
| 2096 | |
| 2097 | if ((kvm->arch.lpcr & mask) == lpcr) |
| 2098 | return; |
| 2099 | |
| 2100 | kvm->arch.lpcr = (kvm->arch.lpcr & ~mask) | lpcr; |
| 2101 | |
| 2102 | for (i = 0; i < KVM_MAX_VCORES; ++i) { |
| 2103 | struct kvmppc_vcore *vc = kvm->arch.vcores[i]; |
| 2104 | if (!vc) |
| 2105 | continue; |
| 2106 | spin_lock(&vc->lock); |
| 2107 | vc->lpcr = (vc->lpcr & ~mask) | lpcr; |
| 2108 | spin_unlock(&vc->lock); |
| 2109 | if (++cores_done >= kvm->arch.online_vcores) |
| 2110 | break; |
| 2111 | } |
| 2112 | } |
| 2113 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2114 | static void kvmppc_mmu_destroy_hv(struct kvm_vcpu *vcpu) |
| 2115 | { |
| 2116 | return; |
| 2117 | } |
| 2118 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2119 | static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu) |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2120 | { |
| 2121 | int err = 0; |
| 2122 | struct kvm *kvm = vcpu->kvm; |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 2123 | struct kvm_rma_info *ri = NULL; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2124 | unsigned long hva; |
| 2125 | struct kvm_memory_slot *memslot; |
| 2126 | struct vm_area_struct *vma; |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2127 | unsigned long lpcr = 0, senc; |
| 2128 | unsigned long lpcr_mask = 0; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2129 | unsigned long psize, porder; |
| 2130 | unsigned long rma_size; |
| 2131 | unsigned long rmls; |
| 2132 | unsigned long *physp; |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2133 | unsigned long i, npages; |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2134 | int srcu_idx; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2135 | |
| 2136 | mutex_lock(&kvm->lock); |
| 2137 | if (kvm->arch.rma_setup_done) |
| 2138 | goto out; /* another vcpu beat us to it */ |
| 2139 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2140 | /* Allocate hashed page table (if not done already) and reset it */ |
| 2141 | if (!kvm->arch.hpt_virt) { |
| 2142 | err = kvmppc_alloc_hpt(kvm, NULL); |
| 2143 | if (err) { |
| 2144 | pr_err("KVM: Couldn't alloc HPT\n"); |
| 2145 | goto out; |
| 2146 | } |
| 2147 | } |
| 2148 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2149 | /* Look up the memslot for guest physical address 0 */ |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2150 | srcu_idx = srcu_read_lock(&kvm->srcu); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2151 | memslot = gfn_to_memslot(kvm, 0); |
| 2152 | |
| 2153 | /* We must have some memory at 0 by now */ |
| 2154 | err = -EINVAL; |
| 2155 | if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2156 | goto out_srcu; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2157 | |
| 2158 | /* Look up the VMA for the start of this memory slot */ |
| 2159 | hva = memslot->userspace_addr; |
| 2160 | down_read(¤t->mm->mmap_sem); |
| 2161 | vma = find_vma(current->mm, hva); |
| 2162 | if (!vma || vma->vm_start > hva || (vma->vm_flags & VM_IO)) |
| 2163 | goto up_out; |
| 2164 | |
| 2165 | psize = vma_kernel_pagesize(vma); |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2166 | porder = __ilog2(psize); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2167 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2168 | /* Is this one of our preallocated RMAs? */ |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2169 | if (vma->vm_file && vma->vm_file->f_op == &kvm_rma_fops && |
| 2170 | hva == vma->vm_start) |
| 2171 | ri = vma->vm_file->private_data; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2172 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2173 | up_read(¤t->mm->mmap_sem); |
| 2174 | |
| 2175 | if (!ri) { |
| 2176 | /* On POWER7, use VRMA; on PPC970, give up */ |
| 2177 | err = -EPERM; |
| 2178 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
| 2179 | pr_err("KVM: CPU requires an RMO\n"); |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2180 | goto out_srcu; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2181 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2182 | |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2183 | /* We can handle 4k, 64k or 16M pages in the VRMA */ |
| 2184 | err = -EINVAL; |
| 2185 | if (!(psize == 0x1000 || psize == 0x10000 || |
| 2186 | psize == 0x1000000)) |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2187 | goto out_srcu; |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2188 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2189 | /* Update VRMASD field in the LPCR */ |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2190 | senc = slb_pgsize_encoding(psize); |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 2191 | kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T | |
| 2192 | (VRMA_VSID << SLB_VSID_SHIFT_1T); |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2193 | lpcr_mask = LPCR_VRMASD; |
| 2194 | /* the -4 is to account for senc values starting at 0x10 */ |
| 2195 | lpcr = senc << (LPCR_VRMASD_SH - 4); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2196 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2197 | /* Create HPTEs in the hash page table for the VRMA */ |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2198 | kvmppc_map_vrma(vcpu, memslot, porder); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2199 | |
| 2200 | } else { |
| 2201 | /* Set up to use an RMO region */ |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 2202 | rma_size = kvm_rma_pages; |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2203 | if (rma_size > memslot->npages) |
| 2204 | rma_size = memslot->npages; |
| 2205 | rma_size <<= PAGE_SHIFT; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2206 | rmls = lpcr_rmls(rma_size); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2207 | err = -EINVAL; |
Chen Gang | 5d226ae | 2013-07-22 14:32:35 +0800 | [diff] [blame] | 2208 | if ((long)rmls < 0) { |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2209 | 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] | 2210 | goto out_srcu; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2211 | } |
| 2212 | atomic_inc(&ri->use_count); |
| 2213 | kvm->arch.rma = ri; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2214 | |
| 2215 | /* Update LPCR and RMOR */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2216 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
| 2217 | /* PPC970; insert RMLS value (split field) in HID4 */ |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2218 | lpcr_mask = (1ul << HID4_RMLS0_SH) | |
| 2219 | (3ul << HID4_RMLS2_SH) | HID4_RMOR; |
| 2220 | lpcr = ((rmls >> 2) << HID4_RMLS0_SH) | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2221 | ((rmls & 3) << HID4_RMLS2_SH); |
| 2222 | /* RMOR is also in HID4 */ |
| 2223 | lpcr |= ((ri->base_pfn >> (26 - PAGE_SHIFT)) & 0xffff) |
| 2224 | << HID4_RMOR_SH; |
| 2225 | } else { |
| 2226 | /* POWER7 */ |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2227 | lpcr_mask = LPCR_VPM0 | LPCR_VRMA_L | LPCR_RMLS; |
| 2228 | lpcr = rmls << LPCR_RMLS_SH; |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 2229 | kvm->arch.rmor = ri->base_pfn << PAGE_SHIFT; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2230 | } |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2231 | pr_info("KVM: Using RMO at %lx size %lx (LPCR = %lx)\n", |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2232 | ri->base_pfn << PAGE_SHIFT, rma_size, lpcr); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2233 | |
| 2234 | /* Initialize phys addrs of pages in RMO */ |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 2235 | npages = kvm_rma_pages; |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 2236 | porder = __ilog2(npages); |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 2237 | physp = memslot->arch.slot_phys; |
| 2238 | if (physp) { |
| 2239 | if (npages > memslot->npages) |
| 2240 | npages = memslot->npages; |
| 2241 | spin_lock(&kvm->arch.slot_phys_lock); |
| 2242 | for (i = 0; i < npages; ++i) |
| 2243 | physp[i] = ((ri->base_pfn + i) << PAGE_SHIFT) + |
| 2244 | porder; |
| 2245 | spin_unlock(&kvm->arch.slot_phys_lock); |
| 2246 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2247 | } |
| 2248 | |
Paul Mackerras | a0144e2 | 2013-09-20 14:52:38 +1000 | [diff] [blame] | 2249 | kvmppc_update_lpcr(kvm, lpcr, lpcr_mask); |
| 2250 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2251 | /* Order updates to kvm->arch.lpcr etc. vs. rma_setup_done */ |
| 2252 | smp_wmb(); |
| 2253 | kvm->arch.rma_setup_done = 1; |
| 2254 | err = 0; |
Paul Mackerras | 2c9097e | 2012-09-11 13:27:01 +0000 | [diff] [blame] | 2255 | out_srcu: |
| 2256 | srcu_read_unlock(&kvm->srcu, srcu_idx); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2257 | out: |
| 2258 | mutex_unlock(&kvm->lock); |
| 2259 | return err; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2260 | |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2261 | up_out: |
| 2262 | up_read(¤t->mm->mmap_sem); |
Lai Jiangshan | 505d642 | 2013-03-16 00:50:49 +0800 | [diff] [blame] | 2263 | goto out_srcu; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2266 | static int kvmppc_core_init_vm_hv(struct kvm *kvm) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2267 | { |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2268 | unsigned long lpcr, lpid; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2269 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2270 | /* Allocate the guest's logical partition ID */ |
| 2271 | |
| 2272 | lpid = kvmppc_alloc_lpid(); |
Chen Gang | 5d226ae | 2013-07-22 14:32:35 +0800 | [diff] [blame] | 2273 | if ((long)lpid < 0) |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 2274 | return -ENOMEM; |
| 2275 | kvm->arch.lpid = lpid; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2276 | |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 2277 | /* |
| 2278 | * Since we don't flush the TLB when tearing down a VM, |
| 2279 | * and this lpid might have previously been used, |
| 2280 | * make sure we flush on each core before running the new VM. |
| 2281 | */ |
| 2282 | cpumask_setall(&kvm->arch.need_tlb_flush); |
| 2283 | |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2284 | kvm->arch.rma = NULL; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2285 | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2286 | kvm->arch.host_sdr1 = mfspr(SPRN_SDR1); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2287 | |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2288 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
| 2289 | /* PPC970; HID4 is effectively the LPCR */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2290 | kvm->arch.host_lpid = 0; |
| 2291 | kvm->arch.host_lpcr = lpcr = mfspr(SPRN_HID4); |
| 2292 | lpcr &= ~((3 << HID4_LPID1_SH) | (0xful << HID4_LPID5_SH)); |
| 2293 | lpcr |= ((lpid >> 4) << HID4_LPID1_SH) | |
| 2294 | ((lpid & 0xf) << HID4_LPID5_SH); |
| 2295 | } else { |
| 2296 | /* POWER7; init LPCR for virtual RMA mode */ |
| 2297 | kvm->arch.host_lpid = mfspr(SPRN_LPID); |
| 2298 | kvm->arch.host_lpcr = lpcr = mfspr(SPRN_LPCR); |
| 2299 | lpcr &= LPCR_PECE | LPCR_LPES; |
| 2300 | lpcr |= (4UL << LPCR_DPFD_SH) | LPCR_HDICE | |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 2301 | LPCR_VPM0 | LPCR_VPM1; |
| 2302 | kvm->arch.vrma_slb_v = SLB_VSID_B_1T | |
| 2303 | (VRMA_VSID << SLB_VSID_SHIFT_1T); |
Paul Mackerras | e0622bd | 2014-01-08 21:25:27 +1100 | [diff] [blame] | 2304 | /* On POWER8 turn on online bit to enable PURR/SPURR */ |
| 2305 | if (cpu_has_feature(CPU_FTR_ARCH_207S)) |
| 2306 | lpcr |= LPCR_ONL; |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 2307 | } |
| 2308 | kvm->arch.lpcr = lpcr; |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2309 | |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2310 | kvm->arch.using_mmu_notifiers = !!cpu_has_feature(CPU_FTR_ARCH_206); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 2311 | spin_lock_init(&kvm->arch.slot_phys_lock); |
Paul Mackerras | 512691d | 2012-10-15 01:15:41 +0000 | [diff] [blame] | 2312 | |
| 2313 | /* |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 2314 | * Track that we now have a HV mode VM active. This blocks secondary |
| 2315 | * CPU threads from coming online. |
Paul Mackerras | 512691d | 2012-10-15 01:15:41 +0000 | [diff] [blame] | 2316 | */ |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 2317 | kvm_hv_vm_activated(); |
Paul Mackerras | 512691d | 2012-10-15 01:15:41 +0000 | [diff] [blame] | 2318 | |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 2319 | return 0; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
Paul Mackerras | f1378b1 | 2013-09-27 15:33:43 +0530 | [diff] [blame] | 2322 | static void kvmppc_free_vcores(struct kvm *kvm) |
| 2323 | { |
| 2324 | long int i; |
| 2325 | |
| 2326 | for (i = 0; i < KVM_MAX_VCORES; ++i) |
| 2327 | kfree(kvm->arch.vcores[i]); |
| 2328 | kvm->arch.online_vcores = 0; |
| 2329 | } |
| 2330 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2331 | static void kvmppc_core_destroy_vm_hv(struct kvm *kvm) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2332 | { |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 2333 | kvm_hv_vm_deactivated(); |
Paul Mackerras | 512691d | 2012-10-15 01:15:41 +0000 | [diff] [blame] | 2334 | |
Paul Mackerras | f1378b1 | 2013-09-27 15:33:43 +0530 | [diff] [blame] | 2335 | kvmppc_free_vcores(kvm); |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 2336 | if (kvm->arch.rma) { |
| 2337 | kvm_release_rma(kvm->arch.rma); |
| 2338 | kvm->arch.rma = NULL; |
| 2339 | } |
| 2340 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2341 | kvmppc_free_hpt(kvm); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | /* 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] | 2345 | static int kvmppc_core_emulate_op_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 2346 | unsigned int inst, int *advance) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2347 | { |
| 2348 | return EMULATE_FAIL; |
| 2349 | } |
| 2350 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2351 | static int kvmppc_core_emulate_mtspr_hv(struct kvm_vcpu *vcpu, int sprn, |
| 2352 | ulong spr_val) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2353 | { |
| 2354 | return EMULATE_FAIL; |
| 2355 | } |
| 2356 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2357 | static int kvmppc_core_emulate_mfspr_hv(struct kvm_vcpu *vcpu, int sprn, |
| 2358 | ulong *spr_val) |
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_check_processor_compat_hv(void) |
| 2364 | { |
| 2365 | if (!cpu_has_feature(CPU_FTR_HVMODE)) |
| 2366 | return -EIO; |
| 2367 | return 0; |
| 2368 | } |
| 2369 | |
| 2370 | static long kvm_arch_vm_ioctl_hv(struct file *filp, |
| 2371 | unsigned int ioctl, unsigned long arg) |
| 2372 | { |
| 2373 | struct kvm *kvm __maybe_unused = filp->private_data; |
| 2374 | void __user *argp = (void __user *)arg; |
| 2375 | long r; |
| 2376 | |
| 2377 | switch (ioctl) { |
| 2378 | |
| 2379 | case KVM_ALLOCATE_RMA: { |
| 2380 | struct kvm_allocate_rma rma; |
| 2381 | struct kvm *kvm = filp->private_data; |
| 2382 | |
| 2383 | r = kvm_vm_ioctl_allocate_rma(kvm, &rma); |
| 2384 | if (r >= 0 && copy_to_user(argp, &rma, sizeof(rma))) |
| 2385 | r = -EFAULT; |
| 2386 | break; |
| 2387 | } |
| 2388 | |
| 2389 | case KVM_PPC_ALLOCATE_HTAB: { |
| 2390 | u32 htab_order; |
| 2391 | |
| 2392 | r = -EFAULT; |
| 2393 | if (get_user(htab_order, (u32 __user *)argp)) |
| 2394 | break; |
| 2395 | r = kvmppc_alloc_reset_hpt(kvm, &htab_order); |
| 2396 | if (r) |
| 2397 | break; |
| 2398 | r = -EFAULT; |
| 2399 | if (put_user(htab_order, (u32 __user *)argp)) |
| 2400 | break; |
| 2401 | r = 0; |
| 2402 | break; |
| 2403 | } |
| 2404 | |
| 2405 | case KVM_PPC_GET_HTAB_FD: { |
| 2406 | struct kvm_get_htab_fd ghf; |
| 2407 | |
| 2408 | r = -EFAULT; |
| 2409 | if (copy_from_user(&ghf, argp, sizeof(ghf))) |
| 2410 | break; |
| 2411 | r = kvm_vm_ioctl_get_htab_fd(kvm, &ghf); |
| 2412 | break; |
| 2413 | } |
| 2414 | |
| 2415 | default: |
| 2416 | r = -ENOTTY; |
| 2417 | } |
| 2418 | |
| 2419 | return r; |
| 2420 | } |
| 2421 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2422 | static struct kvmppc_ops kvm_ops_hv = { |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2423 | .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, |
| 2424 | .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv, |
| 2425 | .get_one_reg = kvmppc_get_one_reg_hv, |
| 2426 | .set_one_reg = kvmppc_set_one_reg_hv, |
| 2427 | .vcpu_load = kvmppc_core_vcpu_load_hv, |
| 2428 | .vcpu_put = kvmppc_core_vcpu_put_hv, |
| 2429 | .set_msr = kvmppc_set_msr_hv, |
| 2430 | .vcpu_run = kvmppc_vcpu_run_hv, |
| 2431 | .vcpu_create = kvmppc_core_vcpu_create_hv, |
| 2432 | .vcpu_free = kvmppc_core_vcpu_free_hv, |
| 2433 | .check_requests = kvmppc_core_check_requests_hv, |
| 2434 | .get_dirty_log = kvm_vm_ioctl_get_dirty_log_hv, |
| 2435 | .flush_memslot = kvmppc_core_flush_memslot_hv, |
| 2436 | .prepare_memory_region = kvmppc_core_prepare_memory_region_hv, |
| 2437 | .commit_memory_region = kvmppc_core_commit_memory_region_hv, |
| 2438 | .unmap_hva = kvm_unmap_hva_hv, |
| 2439 | .unmap_hva_range = kvm_unmap_hva_range_hv, |
| 2440 | .age_hva = kvm_age_hva_hv, |
| 2441 | .test_age_hva = kvm_test_age_hva_hv, |
| 2442 | .set_spte_hva = kvm_set_spte_hva_hv, |
| 2443 | .mmu_destroy = kvmppc_mmu_destroy_hv, |
| 2444 | .free_memslot = kvmppc_core_free_memslot_hv, |
| 2445 | .create_memslot = kvmppc_core_create_memslot_hv, |
| 2446 | .init_vm = kvmppc_core_init_vm_hv, |
| 2447 | .destroy_vm = kvmppc_core_destroy_vm_hv, |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2448 | .get_smmu_info = kvm_vm_ioctl_get_smmu_info_hv, |
| 2449 | .emulate_op = kvmppc_core_emulate_op_hv, |
| 2450 | .emulate_mtspr = kvmppc_core_emulate_mtspr_hv, |
| 2451 | .emulate_mfspr = kvmppc_core_emulate_mfspr_hv, |
| 2452 | .fast_vcpu_kick = kvmppc_fast_vcpu_kick_hv, |
| 2453 | .arch_vm_ioctl = kvm_arch_vm_ioctl_hv, |
| 2454 | }; |
| 2455 | |
| 2456 | static int kvmppc_book3s_init_hv(void) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2457 | { |
| 2458 | int r; |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2459 | /* |
| 2460 | * FIXME!! Do we need to check on all cpus ? |
| 2461 | */ |
| 2462 | r = kvmppc_core_check_processor_compat_hv(); |
| 2463 | if (r < 0) |
Paul Mackerras | 739e242 | 2014-03-25 10:47:05 +1100 | [diff] [blame] | 2464 | return -ENODEV; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2465 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2466 | kvm_ops_hv.owner = THIS_MODULE; |
| 2467 | kvmppc_hv_ops = &kvm_ops_hv; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2468 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2469 | r = kvmppc_mmu_hv_init(); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2470 | return r; |
| 2471 | } |
| 2472 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2473 | static void kvmppc_book3s_exit_hv(void) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2474 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2475 | kvmppc_hv_ops = NULL; |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2476 | } |
| 2477 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2478 | module_init(kvmppc_book3s_init_hv); |
| 2479 | module_exit(kvmppc_book3s_exit_hv); |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 2480 | MODULE_LICENSE("GPL"); |
Alexander Graf | 398a76c | 2013-12-09 13:53:42 +0100 | [diff] [blame] | 2481 | MODULE_ALIAS_MISCDEV(KVM_MINOR); |
| 2482 | MODULE_ALIAS("devname:kvm"); |