Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License, version 2, as |
| 4 | * published by the Free Software Foundation. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9 | * GNU General Public License for more details. |
| 10 | * |
| 11 | * You should have received a copy of the GNU General Public License |
| 12 | * along with this program; if not, write to the Free Software |
| 13 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 14 | * |
| 15 | * Copyright IBM Corp. 2007 |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 16 | * Copyright 2010-2011 Freescale Semiconductor, Inc. |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 17 | * |
| 18 | * Authors: Hollis Blanchard <hollisb@us.ibm.com> |
| 19 | * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com> |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 20 | * Scott Wood <scottwood@freescale.com> |
| 21 | * Varun Sethi <varun.sethi@freescale.com> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/err.h> |
| 26 | #include <linux/kvm_host.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/gfp.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/vmalloc.h> |
| 30 | #include <linux/fs.h> |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 31 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 32 | #include <asm/cputable.h> |
| 33 | #include <asm/uaccess.h> |
| 34 | #include <asm/kvm_ppc.h> |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 35 | #include <asm/cacheflush.h> |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 36 | #include <asm/dbell.h> |
| 37 | #include <asm/hw_irq.h> |
| 38 | #include <asm/irq.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 39 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 40 | #include "timing.h" |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 41 | #include "booke.h" |
Alexander Graf | 97c9505 | 2012-08-02 15:10:00 +0200 | [diff] [blame] | 42 | #include "trace.h" |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 43 | |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 44 | unsigned long kvmppc_booke_handlers; |
| 45 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 46 | #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM |
| 47 | #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU |
| 48 | |
| 49 | struct kvm_stats_debugfs_item debugfs_entries[] = { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 50 | { "mmio", VCPU_STAT(mmio_exits) }, |
| 51 | { "dcr", VCPU_STAT(dcr_exits) }, |
| 52 | { "sig", VCPU_STAT(signal_exits) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 53 | { "itlb_r", VCPU_STAT(itlb_real_miss_exits) }, |
| 54 | { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) }, |
| 55 | { "dtlb_r", VCPU_STAT(dtlb_real_miss_exits) }, |
| 56 | { "dtlb_v", VCPU_STAT(dtlb_virt_miss_exits) }, |
| 57 | { "sysc", VCPU_STAT(syscall_exits) }, |
| 58 | { "isi", VCPU_STAT(isi_exits) }, |
| 59 | { "dsi", VCPU_STAT(dsi_exits) }, |
| 60 | { "inst_emu", VCPU_STAT(emulated_inst_exits) }, |
| 61 | { "dec", VCPU_STAT(dec_exits) }, |
| 62 | { "ext_intr", VCPU_STAT(ext_intr_exits) }, |
Hollis Blanchard | 45c5eb6 | 2008-04-25 17:55:49 -0500 | [diff] [blame] | 63 | { "halt_wakeup", VCPU_STAT(halt_wakeup) }, |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 64 | { "doorbell", VCPU_STAT(dbell_exits) }, |
| 65 | { "guest doorbell", VCPU_STAT(gdbell_exits) }, |
Alexander Graf | cf1c5ca | 2012-08-01 12:56:51 +0200 | [diff] [blame] | 66 | { "remote_tlb_flush", VM_STAT(remote_tlb_flush) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 67 | { NULL } |
| 68 | }; |
| 69 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 70 | /* TODO: use vcpu_printf() */ |
| 71 | void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu) |
| 72 | { |
| 73 | int i; |
| 74 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 75 | printk("pc: %08lx msr: %08llx\n", vcpu->arch.pc, vcpu->arch.shared->msr); |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 76 | printk("lr: %08lx ctr: %08lx\n", vcpu->arch.lr, vcpu->arch.ctr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 77 | printk("srr0: %08llx srr1: %08llx\n", vcpu->arch.shared->srr0, |
| 78 | vcpu->arch.shared->srr1); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 79 | |
| 80 | printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions); |
| 81 | |
| 82 | for (i = 0; i < 32; i += 4) { |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 83 | printk("gpr%02d: %08lx %08lx %08lx %08lx\n", i, |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 84 | kvmppc_get_gpr(vcpu, i), |
| 85 | kvmppc_get_gpr(vcpu, i+1), |
| 86 | kvmppc_get_gpr(vcpu, i+2), |
| 87 | kvmppc_get_gpr(vcpu, i+3)); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 91 | #ifdef CONFIG_SPE |
| 92 | void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu) |
| 93 | { |
| 94 | preempt_disable(); |
| 95 | enable_kernel_spe(); |
| 96 | kvmppc_save_guest_spe(vcpu); |
| 97 | vcpu->arch.shadow_msr &= ~MSR_SPE; |
| 98 | preempt_enable(); |
| 99 | } |
| 100 | |
| 101 | static void kvmppc_vcpu_enable_spe(struct kvm_vcpu *vcpu) |
| 102 | { |
| 103 | preempt_disable(); |
| 104 | enable_kernel_spe(); |
| 105 | kvmppc_load_guest_spe(vcpu); |
| 106 | vcpu->arch.shadow_msr |= MSR_SPE; |
| 107 | preempt_enable(); |
| 108 | } |
| 109 | |
| 110 | static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu) |
| 111 | { |
| 112 | if (vcpu->arch.shared->msr & MSR_SPE) { |
| 113 | if (!(vcpu->arch.shadow_msr & MSR_SPE)) |
| 114 | kvmppc_vcpu_enable_spe(vcpu); |
| 115 | } else if (vcpu->arch.shadow_msr & MSR_SPE) { |
| 116 | kvmppc_vcpu_disable_spe(vcpu); |
| 117 | } |
| 118 | } |
| 119 | #else |
| 120 | static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu) |
| 121 | { |
| 122 | } |
| 123 | #endif |
| 124 | |
Alexander Graf | 7a08c27 | 2012-08-16 13:10:16 +0200 | [diff] [blame] | 125 | static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu) |
| 126 | { |
| 127 | #if defined(CONFIG_PPC_FPU) && !defined(CONFIG_KVM_BOOKE_HV) |
| 128 | /* We always treat the FP bit as enabled from the host |
| 129 | perspective, so only need to adjust the shadow MSR */ |
| 130 | vcpu->arch.shadow_msr &= ~MSR_FP; |
| 131 | vcpu->arch.shadow_msr |= vcpu->arch.shared->msr & MSR_FP; |
| 132 | #endif |
| 133 | } |
| 134 | |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 135 | /* |
| 136 | * Helper function for "full" MSR writes. No need to call this if only |
| 137 | * EE/CE/ME/DE/RI are changing. |
| 138 | */ |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 139 | void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr) |
| 140 | { |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 141 | u32 old_msr = vcpu->arch.shared->msr; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 142 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 143 | #ifdef CONFIG_KVM_BOOKE_HV |
| 144 | new_msr |= MSR_GS; |
| 145 | #endif |
| 146 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 147 | vcpu->arch.shared->msr = new_msr; |
| 148 | |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 149 | kvmppc_mmu_msr_notify(vcpu, old_msr); |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 150 | kvmppc_vcpu_sync_spe(vcpu); |
Alexander Graf | 7a08c27 | 2012-08-16 13:10:16 +0200 | [diff] [blame] | 151 | kvmppc_vcpu_sync_fpu(vcpu); |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 152 | } |
| 153 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 154 | static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, |
| 155 | unsigned int priority) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 156 | { |
Alexander Graf | 6346046 | 2012-08-08 00:44:52 +0200 | [diff] [blame] | 157 | trace_kvm_booke_queue_irqprio(vcpu, priority); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 158 | set_bit(priority, &vcpu->arch.pending_exceptions); |
| 159 | } |
| 160 | |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 161 | static void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, |
| 162 | ulong dear_flags, ulong esr_flags) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 163 | { |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 164 | vcpu->arch.queued_dear = dear_flags; |
| 165 | vcpu->arch.queued_esr = esr_flags; |
| 166 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS); |
| 167 | } |
| 168 | |
| 169 | static void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, |
| 170 | ulong dear_flags, ulong esr_flags) |
| 171 | { |
| 172 | vcpu->arch.queued_dear = dear_flags; |
| 173 | vcpu->arch.queued_esr = esr_flags; |
| 174 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE); |
| 175 | } |
| 176 | |
| 177 | static void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, |
| 178 | ulong esr_flags) |
| 179 | { |
| 180 | vcpu->arch.queued_esr = esr_flags; |
| 181 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE); |
| 182 | } |
| 183 | |
| 184 | void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags) |
| 185 | { |
| 186 | vcpu->arch.queued_esr = esr_flags; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 187 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu) |
| 191 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 192 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DECREMENTER); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu) |
| 196 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 197 | return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 198 | } |
| 199 | |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 200 | void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu) |
| 201 | { |
| 202 | clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
| 203 | } |
| 204 | |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 205 | void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 206 | struct kvm_interrupt *irq) |
| 207 | { |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 208 | unsigned int prio = BOOKE_IRQPRIO_EXTERNAL; |
| 209 | |
| 210 | if (irq->irq == KVM_INTERRUPT_SET_LEVEL) |
| 211 | prio = BOOKE_IRQPRIO_EXTERNAL_LEVEL; |
| 212 | |
| 213 | kvmppc_booke_queue_irqprio(vcpu, prio); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 214 | } |
| 215 | |
Alexander Graf | 4496f97 | 2010-04-07 10:03:25 +0200 | [diff] [blame] | 216 | void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu, |
| 217 | struct kvm_interrupt *irq) |
| 218 | { |
| 219 | clear_bit(BOOKE_IRQPRIO_EXTERNAL, &vcpu->arch.pending_exceptions); |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 220 | clear_bit(BOOKE_IRQPRIO_EXTERNAL_LEVEL, &vcpu->arch.pending_exceptions); |
Alexander Graf | 4496f97 | 2010-04-07 10:03:25 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 223 | static void kvmppc_core_queue_watchdog(struct kvm_vcpu *vcpu) |
| 224 | { |
| 225 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_WATCHDOG); |
| 226 | } |
| 227 | |
| 228 | static void kvmppc_core_dequeue_watchdog(struct kvm_vcpu *vcpu) |
| 229 | { |
| 230 | clear_bit(BOOKE_IRQPRIO_WATCHDOG, &vcpu->arch.pending_exceptions); |
| 231 | } |
| 232 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 233 | static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 234 | { |
| 235 | #ifdef CONFIG_KVM_BOOKE_HV |
| 236 | mtspr(SPRN_GSRR0, srr0); |
| 237 | mtspr(SPRN_GSRR1, srr1); |
| 238 | #else |
| 239 | vcpu->arch.shared->srr0 = srr0; |
| 240 | vcpu->arch.shared->srr1 = srr1; |
| 241 | #endif |
| 242 | } |
| 243 | |
| 244 | static void set_guest_csrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 245 | { |
| 246 | vcpu->arch.csrr0 = srr0; |
| 247 | vcpu->arch.csrr1 = srr1; |
| 248 | } |
| 249 | |
| 250 | static void set_guest_dsrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 251 | { |
| 252 | if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC)) { |
| 253 | vcpu->arch.dsrr0 = srr0; |
| 254 | vcpu->arch.dsrr1 = srr1; |
| 255 | } else { |
| 256 | set_guest_csrr(vcpu, srr0, srr1); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | static void set_guest_mcsrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 261 | { |
| 262 | vcpu->arch.mcsrr0 = srr0; |
| 263 | vcpu->arch.mcsrr1 = srr1; |
| 264 | } |
| 265 | |
| 266 | static unsigned long get_guest_dear(struct kvm_vcpu *vcpu) |
| 267 | { |
| 268 | #ifdef CONFIG_KVM_BOOKE_HV |
| 269 | return mfspr(SPRN_GDEAR); |
| 270 | #else |
| 271 | return vcpu->arch.shared->dar; |
| 272 | #endif |
| 273 | } |
| 274 | |
| 275 | static void set_guest_dear(struct kvm_vcpu *vcpu, unsigned long dear) |
| 276 | { |
| 277 | #ifdef CONFIG_KVM_BOOKE_HV |
| 278 | mtspr(SPRN_GDEAR, dear); |
| 279 | #else |
| 280 | vcpu->arch.shared->dar = dear; |
| 281 | #endif |
| 282 | } |
| 283 | |
| 284 | static unsigned long get_guest_esr(struct kvm_vcpu *vcpu) |
| 285 | { |
| 286 | #ifdef CONFIG_KVM_BOOKE_HV |
| 287 | return mfspr(SPRN_GESR); |
| 288 | #else |
| 289 | return vcpu->arch.shared->esr; |
| 290 | #endif |
| 291 | } |
| 292 | |
| 293 | static void set_guest_esr(struct kvm_vcpu *vcpu, u32 esr) |
| 294 | { |
| 295 | #ifdef CONFIG_KVM_BOOKE_HV |
| 296 | mtspr(SPRN_GESR, esr); |
| 297 | #else |
| 298 | vcpu->arch.shared->esr = esr; |
| 299 | #endif |
| 300 | } |
| 301 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 302 | /* Deliver the interrupt of the corresponding priority, if possible. */ |
| 303 | static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, |
| 304 | unsigned int priority) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 305 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 306 | int allowed = 0; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 307 | ulong msr_mask = 0; |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 308 | bool update_esr = false, update_dear = false; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 309 | ulong crit_raw = vcpu->arch.shared->critical; |
| 310 | ulong crit_r1 = kvmppc_get_gpr(vcpu, 1); |
| 311 | bool crit; |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 312 | bool keep_irq = false; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 313 | enum int_class int_class; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 314 | |
| 315 | /* Truncate crit indicators in 32 bit mode */ |
| 316 | if (!(vcpu->arch.shared->msr & MSR_SF)) { |
| 317 | crit_raw &= 0xffffffff; |
| 318 | crit_r1 &= 0xffffffff; |
| 319 | } |
| 320 | |
| 321 | /* Critical section when crit == r1 */ |
| 322 | crit = (crit_raw == crit_r1); |
| 323 | /* ... and we're in supervisor mode */ |
| 324 | crit = crit && !(vcpu->arch.shared->msr & MSR_PR); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 325 | |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 326 | if (priority == BOOKE_IRQPRIO_EXTERNAL_LEVEL) { |
| 327 | priority = BOOKE_IRQPRIO_EXTERNAL; |
| 328 | keep_irq = true; |
| 329 | } |
| 330 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 331 | switch (priority) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 332 | case BOOKE_IRQPRIO_DTLB_MISS: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 333 | case BOOKE_IRQPRIO_DATA_STORAGE: |
| 334 | update_dear = true; |
| 335 | /* fall through */ |
| 336 | case BOOKE_IRQPRIO_INST_STORAGE: |
| 337 | case BOOKE_IRQPRIO_PROGRAM: |
| 338 | update_esr = true; |
| 339 | /* fall through */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 340 | case BOOKE_IRQPRIO_ITLB_MISS: |
| 341 | case BOOKE_IRQPRIO_SYSCALL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 342 | case BOOKE_IRQPRIO_FP_UNAVAIL: |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 343 | case BOOKE_IRQPRIO_SPE_UNAVAIL: |
| 344 | case BOOKE_IRQPRIO_SPE_FP_DATA: |
| 345 | case BOOKE_IRQPRIO_SPE_FP_ROUND: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 346 | case BOOKE_IRQPRIO_AP_UNAVAIL: |
| 347 | case BOOKE_IRQPRIO_ALIGNMENT: |
| 348 | allowed = 1; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 349 | msr_mask = MSR_CE | MSR_ME | MSR_DE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 350 | int_class = INT_CLASS_NONCRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 351 | break; |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 352 | case BOOKE_IRQPRIO_WATCHDOG: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 353 | case BOOKE_IRQPRIO_CRITICAL: |
Alexander Graf | 4ab9691 | 2012-02-15 13:28:48 +0000 | [diff] [blame] | 354 | case BOOKE_IRQPRIO_DBELL_CRIT: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 355 | allowed = vcpu->arch.shared->msr & MSR_CE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 356 | allowed = allowed && !crit; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 357 | msr_mask = MSR_ME; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 358 | int_class = INT_CLASS_CRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 359 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 360 | case BOOKE_IRQPRIO_MACHINE_CHECK: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 361 | allowed = vcpu->arch.shared->msr & MSR_ME; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 362 | allowed = allowed && !crit; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 363 | int_class = INT_CLASS_MC; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 364 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 365 | case BOOKE_IRQPRIO_DECREMENTER: |
| 366 | case BOOKE_IRQPRIO_FIT: |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 367 | keep_irq = true; |
| 368 | /* fall through */ |
| 369 | case BOOKE_IRQPRIO_EXTERNAL: |
Alexander Graf | 4ab9691 | 2012-02-15 13:28:48 +0000 | [diff] [blame] | 370 | case BOOKE_IRQPRIO_DBELL: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 371 | allowed = vcpu->arch.shared->msr & MSR_EE; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 372 | allowed = allowed && !crit; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 373 | msr_mask = MSR_CE | MSR_ME | MSR_DE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 374 | int_class = INT_CLASS_NONCRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 375 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 376 | case BOOKE_IRQPRIO_DEBUG: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 377 | allowed = vcpu->arch.shared->msr & MSR_DE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 378 | allowed = allowed && !crit; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 379 | msr_mask = MSR_ME; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 380 | int_class = INT_CLASS_CRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 381 | break; |
| 382 | } |
| 383 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 384 | if (allowed) { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 385 | switch (int_class) { |
| 386 | case INT_CLASS_NONCRIT: |
| 387 | set_guest_srr(vcpu, vcpu->arch.pc, |
| 388 | vcpu->arch.shared->msr); |
| 389 | break; |
| 390 | case INT_CLASS_CRIT: |
| 391 | set_guest_csrr(vcpu, vcpu->arch.pc, |
| 392 | vcpu->arch.shared->msr); |
| 393 | break; |
| 394 | case INT_CLASS_DBG: |
| 395 | set_guest_dsrr(vcpu, vcpu->arch.pc, |
| 396 | vcpu->arch.shared->msr); |
| 397 | break; |
| 398 | case INT_CLASS_MC: |
| 399 | set_guest_mcsrr(vcpu, vcpu->arch.pc, |
| 400 | vcpu->arch.shared->msr); |
| 401 | break; |
| 402 | } |
| 403 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 404 | vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority]; |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 405 | if (update_esr == true) |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 406 | set_guest_esr(vcpu, vcpu->arch.queued_esr); |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 407 | if (update_dear == true) |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 408 | set_guest_dear(vcpu, vcpu->arch.queued_dear); |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 409 | kvmppc_set_msr(vcpu, vcpu->arch.shared->msr & msr_mask); |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 410 | |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 411 | if (!keep_irq) |
| 412 | clear_bit(priority, &vcpu->arch.pending_exceptions); |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 413 | } |
| 414 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 415 | #ifdef CONFIG_KVM_BOOKE_HV |
| 416 | /* |
| 417 | * If an interrupt is pending but masked, raise a guest doorbell |
| 418 | * so that we are notified when the guest enables the relevant |
| 419 | * MSR bit. |
| 420 | */ |
| 421 | if (vcpu->arch.pending_exceptions & BOOKE_IRQMASK_EE) |
| 422 | kvmppc_set_pending_interrupt(vcpu, INT_CLASS_NONCRIT); |
| 423 | if (vcpu->arch.pending_exceptions & BOOKE_IRQMASK_CE) |
| 424 | kvmppc_set_pending_interrupt(vcpu, INT_CLASS_CRIT); |
| 425 | if (vcpu->arch.pending_exceptions & BOOKE_IRQPRIO_MACHINE_CHECK) |
| 426 | kvmppc_set_pending_interrupt(vcpu, INT_CLASS_MC); |
| 427 | #endif |
| 428 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 429 | return allowed; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 430 | } |
| 431 | |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 432 | /* |
| 433 | * Return the number of jiffies until the next timeout. If the timeout is |
| 434 | * longer than the NEXT_TIMER_MAX_DELTA, then return NEXT_TIMER_MAX_DELTA |
| 435 | * because the larger value can break the timer APIs. |
| 436 | */ |
| 437 | static unsigned long watchdog_next_timeout(struct kvm_vcpu *vcpu) |
| 438 | { |
| 439 | u64 tb, wdt_tb, wdt_ticks = 0; |
| 440 | u64 nr_jiffies = 0; |
| 441 | u32 period = TCR_GET_WP(vcpu->arch.tcr); |
| 442 | |
| 443 | wdt_tb = 1ULL << (63 - period); |
| 444 | tb = get_tb(); |
| 445 | /* |
| 446 | * The watchdog timeout will hapeen when TB bit corresponding |
| 447 | * to watchdog will toggle from 0 to 1. |
| 448 | */ |
| 449 | if (tb & wdt_tb) |
| 450 | wdt_ticks = wdt_tb; |
| 451 | |
| 452 | wdt_ticks += wdt_tb - (tb & (wdt_tb - 1)); |
| 453 | |
| 454 | /* Convert timebase ticks to jiffies */ |
| 455 | nr_jiffies = wdt_ticks; |
| 456 | |
| 457 | if (do_div(nr_jiffies, tb_ticks_per_jiffy)) |
| 458 | nr_jiffies++; |
| 459 | |
| 460 | return min_t(unsigned long long, nr_jiffies, NEXT_TIMER_MAX_DELTA); |
| 461 | } |
| 462 | |
| 463 | static void arm_next_watchdog(struct kvm_vcpu *vcpu) |
| 464 | { |
| 465 | unsigned long nr_jiffies; |
| 466 | unsigned long flags; |
| 467 | |
| 468 | /* |
| 469 | * If TSR_ENW and TSR_WIS are not set then no need to exit to |
| 470 | * userspace, so clear the KVM_REQ_WATCHDOG request. |
| 471 | */ |
| 472 | if ((vcpu->arch.tsr & (TSR_ENW | TSR_WIS)) != (TSR_ENW | TSR_WIS)) |
| 473 | clear_bit(KVM_REQ_WATCHDOG, &vcpu->requests); |
| 474 | |
| 475 | spin_lock_irqsave(&vcpu->arch.wdt_lock, flags); |
| 476 | nr_jiffies = watchdog_next_timeout(vcpu); |
| 477 | /* |
| 478 | * If the number of jiffies of watchdog timer >= NEXT_TIMER_MAX_DELTA |
| 479 | * then do not run the watchdog timer as this can break timer APIs. |
| 480 | */ |
| 481 | if (nr_jiffies < NEXT_TIMER_MAX_DELTA) |
| 482 | mod_timer(&vcpu->arch.wdt_timer, jiffies + nr_jiffies); |
| 483 | else |
| 484 | del_timer(&vcpu->arch.wdt_timer); |
| 485 | spin_unlock_irqrestore(&vcpu->arch.wdt_lock, flags); |
| 486 | } |
| 487 | |
| 488 | void kvmppc_watchdog_func(unsigned long data) |
| 489 | { |
| 490 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; |
| 491 | u32 tsr, new_tsr; |
| 492 | int final; |
| 493 | |
| 494 | do { |
| 495 | new_tsr = tsr = vcpu->arch.tsr; |
| 496 | final = 0; |
| 497 | |
| 498 | /* Time out event */ |
| 499 | if (tsr & TSR_ENW) { |
| 500 | if (tsr & TSR_WIS) |
| 501 | final = 1; |
| 502 | else |
| 503 | new_tsr = tsr | TSR_WIS; |
| 504 | } else { |
| 505 | new_tsr = tsr | TSR_ENW; |
| 506 | } |
| 507 | } while (cmpxchg(&vcpu->arch.tsr, tsr, new_tsr) != tsr); |
| 508 | |
| 509 | if (new_tsr & TSR_WIS) { |
| 510 | smp_wmb(); |
| 511 | kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu); |
| 512 | kvm_vcpu_kick(vcpu); |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * If this is final watchdog expiry and some action is required |
| 517 | * then exit to userspace. |
| 518 | */ |
| 519 | if (final && (vcpu->arch.tcr & TCR_WRC_MASK) && |
| 520 | vcpu->arch.watchdog_enabled) { |
| 521 | smp_wmb(); |
| 522 | kvm_make_request(KVM_REQ_WATCHDOG, vcpu); |
| 523 | kvm_vcpu_kick(vcpu); |
| 524 | } |
| 525 | |
| 526 | /* |
| 527 | * Stop running the watchdog timer after final expiration to |
| 528 | * prevent the host from being flooded with timers if the |
| 529 | * guest sets a short period. |
| 530 | * Timers will resume when TSR/TCR is updated next time. |
| 531 | */ |
| 532 | if (!final) |
| 533 | arm_next_watchdog(vcpu); |
| 534 | } |
| 535 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 536 | static void update_timer_ints(struct kvm_vcpu *vcpu) |
| 537 | { |
| 538 | if ((vcpu->arch.tcr & TCR_DIE) && (vcpu->arch.tsr & TSR_DIS)) |
| 539 | kvmppc_core_queue_dec(vcpu); |
| 540 | else |
| 541 | kvmppc_core_dequeue_dec(vcpu); |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 542 | |
| 543 | if ((vcpu->arch.tcr & TCR_WIE) && (vcpu->arch.tsr & TSR_WIS)) |
| 544 | kvmppc_core_queue_watchdog(vcpu); |
| 545 | else |
| 546 | kvmppc_core_dequeue_watchdog(vcpu); |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 549 | static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 550 | { |
| 551 | unsigned long *pending = &vcpu->arch.pending_exceptions; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 552 | unsigned int priority; |
| 553 | |
Hollis Blanchard | 9ab8084 | 2008-11-05 09:36:22 -0600 | [diff] [blame] | 554 | priority = __ffs(*pending); |
Alexander Graf | 8b3a00f | 2012-02-16 14:12:46 +0000 | [diff] [blame] | 555 | while (priority < BOOKE_IRQPRIO_MAX) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 556 | if (kvmppc_booke_irqprio_deliver(vcpu, priority)) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 557 | break; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 558 | |
| 559 | priority = find_next_bit(pending, |
| 560 | BITS_PER_BYTE * sizeof(*pending), |
| 561 | priority + 1); |
| 562 | } |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame] | 563 | |
| 564 | /* Tell the guest about our interrupt status */ |
Scott Wood | 29ac26e | 2011-11-08 18:23:27 -0600 | [diff] [blame] | 565 | vcpu->arch.shared->int_pending = !!*pending; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 566 | } |
| 567 | |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 568 | /* Check pending exceptions and deliver one, if possible. */ |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 569 | int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu) |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 570 | { |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 571 | int r = 0; |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 572 | WARN_ON_ONCE(!irqs_disabled()); |
| 573 | |
| 574 | kvmppc_core_check_exceptions(vcpu); |
| 575 | |
| 576 | if (vcpu->arch.shared->msr & MSR_WE) { |
| 577 | local_irq_enable(); |
| 578 | kvm_vcpu_block(vcpu); |
Alexander Graf | 966cd0f | 2012-03-14 16:55:08 +0100 | [diff] [blame] | 579 | clear_bit(KVM_REQ_UNHALT, &vcpu->requests); |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 580 | local_irq_disable(); |
| 581 | |
| 582 | kvmppc_set_exit_type(vcpu, EMULATED_MTMSRWE_EXITS); |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 583 | r = 1; |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 584 | }; |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 585 | |
| 586 | return r; |
| 587 | } |
| 588 | |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 589 | int kvmppc_core_check_requests(struct kvm_vcpu *vcpu) |
Alexander Graf | 4ffc635 | 2012-08-08 20:31:13 +0200 | [diff] [blame] | 590 | { |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 591 | int r = 1; /* Indicate we want to get back into the guest */ |
| 592 | |
Alexander Graf | 2d8185d | 2012-08-10 12:31:12 +0200 | [diff] [blame] | 593 | if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) |
| 594 | update_timer_ints(vcpu); |
Alexander Graf | 862d31f | 2012-07-31 00:19:50 +0200 | [diff] [blame] | 595 | #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC) |
Alexander Graf | 2d8185d | 2012-08-10 12:31:12 +0200 | [diff] [blame] | 596 | if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu)) |
| 597 | kvmppc_core_flush_tlb(vcpu); |
Alexander Graf | 862d31f | 2012-07-31 00:19:50 +0200 | [diff] [blame] | 598 | #endif |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 599 | |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 600 | if (kvm_check_request(KVM_REQ_WATCHDOG, vcpu)) { |
| 601 | vcpu->run->exit_reason = KVM_EXIT_WATCHDOG; |
| 602 | r = 0; |
| 603 | } |
| 604 | |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 605 | return r; |
Alexander Graf | 4ffc635 | 2012-08-08 20:31:13 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 608 | int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) |
| 609 | { |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 610 | int ret, s; |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 611 | #ifdef CONFIG_PPC_FPU |
| 612 | unsigned int fpscr; |
| 613 | int fpexc_mode; |
| 614 | u64 fpr[32]; |
| 615 | #endif |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 616 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 617 | if (!vcpu->arch.sane) { |
| 618 | kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR; |
| 619 | return -EINVAL; |
| 620 | } |
| 621 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 622 | local_irq_disable(); |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 623 | s = kvmppc_prepare_to_enter(vcpu); |
| 624 | if (s <= 0) { |
Alexander Graf | 24afa37 | 2012-08-12 12:42:30 +0200 | [diff] [blame] | 625 | local_irq_enable(); |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 626 | ret = s; |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 627 | goto out; |
| 628 | } |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 629 | kvmppc_lazy_ee_enable(); |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 630 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 631 | kvm_guest_enter(); |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 632 | |
| 633 | #ifdef CONFIG_PPC_FPU |
| 634 | /* Save userspace FPU state in stack */ |
| 635 | enable_kernel_fp(); |
| 636 | memcpy(fpr, current->thread.fpr, sizeof(current->thread.fpr)); |
| 637 | fpscr = current->thread.fpscr.val; |
| 638 | fpexc_mode = current->thread.fpexc_mode; |
| 639 | |
| 640 | /* Restore guest FPU state to thread */ |
| 641 | memcpy(current->thread.fpr, vcpu->arch.fpr, sizeof(vcpu->arch.fpr)); |
| 642 | current->thread.fpscr.val = vcpu->arch.fpscr; |
| 643 | |
| 644 | /* |
| 645 | * Since we can't trap on MSR_FP in GS-mode, we consider the guest |
| 646 | * as always using the FPU. Kernel usage of FP (via |
| 647 | * enable_kernel_fp()) in this thread must not occur while |
| 648 | * vcpu->fpu_active is set. |
| 649 | */ |
| 650 | vcpu->fpu_active = 1; |
| 651 | |
| 652 | kvmppc_load_guest_fp(vcpu); |
| 653 | #endif |
| 654 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 655 | ret = __kvmppc_vcpu_run(kvm_run, vcpu); |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 656 | |
Alexander Graf | 24afa37 | 2012-08-12 12:42:30 +0200 | [diff] [blame] | 657 | /* No need for kvm_guest_exit. It's done in handle_exit. |
| 658 | We also get here with interrupts enabled. */ |
| 659 | |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 660 | #ifdef CONFIG_PPC_FPU |
| 661 | kvmppc_save_guest_fp(vcpu); |
| 662 | |
| 663 | vcpu->fpu_active = 0; |
| 664 | |
| 665 | /* Save guest FPU state from thread */ |
| 666 | memcpy(vcpu->arch.fpr, current->thread.fpr, sizeof(vcpu->arch.fpr)); |
| 667 | vcpu->arch.fpscr = current->thread.fpscr.val; |
| 668 | |
| 669 | /* Restore userspace FPU state from stack */ |
| 670 | memcpy(current->thread.fpr, fpr, sizeof(current->thread.fpr)); |
| 671 | current->thread.fpscr.val = fpscr; |
| 672 | current->thread.fpexc_mode = fpexc_mode; |
| 673 | #endif |
| 674 | |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 675 | out: |
Alexander Graf | d69c643 | 2012-08-08 20:44:20 +0200 | [diff] [blame] | 676 | vcpu->mode = OUTSIDE_GUEST_MODE; |
| 677 | smp_wmb(); |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 678 | return ret; |
| 679 | } |
| 680 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 681 | static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) |
| 682 | { |
| 683 | enum emulation_result er; |
| 684 | |
| 685 | er = kvmppc_emulate_instruction(run, vcpu); |
| 686 | switch (er) { |
| 687 | case EMULATE_DONE: |
| 688 | /* don't overwrite subtypes, just account kvm_stats */ |
| 689 | kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS); |
| 690 | /* Future optimization: only reload non-volatiles if |
| 691 | * they were actually modified by emulation. */ |
| 692 | return RESUME_GUEST_NV; |
| 693 | |
| 694 | case EMULATE_DO_DCR: |
| 695 | run->exit_reason = KVM_EXIT_DCR; |
| 696 | return RESUME_HOST; |
| 697 | |
| 698 | case EMULATE_FAIL: |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 699 | printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n", |
| 700 | __func__, vcpu->arch.pc, vcpu->arch.last_inst); |
| 701 | /* For debugging, encode the failing instruction and |
| 702 | * report it to userspace. */ |
| 703 | run->hw.hardware_exit_reason = ~0ULL << 32; |
| 704 | run->hw.hardware_exit_reason |= vcpu->arch.last_inst; |
Alexander Graf | d1ff549 | 2012-02-16 13:24:03 +0000 | [diff] [blame] | 705 | kvmppc_core_queue_program(vcpu, ESR_PIL); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 706 | return RESUME_HOST; |
| 707 | |
| 708 | default: |
| 709 | BUG(); |
| 710 | } |
| 711 | } |
| 712 | |
Alexander Graf | 4e642cc | 2012-02-20 23:57:26 +0100 | [diff] [blame] | 713 | static void kvmppc_fill_pt_regs(struct pt_regs *regs) |
| 714 | { |
| 715 | ulong r1, ip, msr, lr; |
| 716 | |
| 717 | asm("mr %0, 1" : "=r"(r1)); |
| 718 | asm("mflr %0" : "=r"(lr)); |
| 719 | asm("mfmsr %0" : "=r"(msr)); |
| 720 | asm("bl 1f; 1: mflr %0" : "=r"(ip)); |
| 721 | |
| 722 | memset(regs, 0, sizeof(*regs)); |
| 723 | regs->gpr[1] = r1; |
| 724 | regs->nip = ip; |
| 725 | regs->msr = msr; |
| 726 | regs->link = lr; |
| 727 | } |
| 728 | |
Bharat Bhushan | 6328e59 | 2012-06-20 05:56:53 +0000 | [diff] [blame] | 729 | /* |
| 730 | * For interrupts needed to be handled by host interrupt handlers, |
| 731 | * corresponding host handler are called from here in similar way |
| 732 | * (but not exact) as they are called from low level handler |
| 733 | * (such as from arch/powerpc/kernel/head_fsl_booke.S). |
| 734 | */ |
Alexander Graf | 4e642cc | 2012-02-20 23:57:26 +0100 | [diff] [blame] | 735 | static void kvmppc_restart_interrupt(struct kvm_vcpu *vcpu, |
| 736 | unsigned int exit_nr) |
| 737 | { |
| 738 | struct pt_regs regs; |
| 739 | |
| 740 | switch (exit_nr) { |
| 741 | case BOOKE_INTERRUPT_EXTERNAL: |
| 742 | kvmppc_fill_pt_regs(®s); |
| 743 | do_IRQ(®s); |
| 744 | break; |
| 745 | case BOOKE_INTERRUPT_DECREMENTER: |
| 746 | kvmppc_fill_pt_regs(®s); |
| 747 | timer_interrupt(®s); |
| 748 | break; |
| 749 | #if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3E_64) |
| 750 | case BOOKE_INTERRUPT_DOORBELL: |
| 751 | kvmppc_fill_pt_regs(®s); |
| 752 | doorbell_exception(®s); |
| 753 | break; |
| 754 | #endif |
| 755 | case BOOKE_INTERRUPT_MACHINE_CHECK: |
| 756 | /* FIXME */ |
| 757 | break; |
Alexander Graf | 7cc1e8e | 2012-02-22 16:26:34 +0100 | [diff] [blame] | 758 | case BOOKE_INTERRUPT_PERFORMANCE_MONITOR: |
| 759 | kvmppc_fill_pt_regs(®s); |
| 760 | performance_monitor_exception(®s); |
| 761 | break; |
Bharat Bhushan | 6328e59 | 2012-06-20 05:56:53 +0000 | [diff] [blame] | 762 | case BOOKE_INTERRUPT_WATCHDOG: |
| 763 | kvmppc_fill_pt_regs(®s); |
| 764 | #ifdef CONFIG_BOOKE_WDT |
| 765 | WatchdogException(®s); |
| 766 | #else |
| 767 | unknown_exception(®s); |
| 768 | #endif |
| 769 | break; |
| 770 | case BOOKE_INTERRUPT_CRITICAL: |
| 771 | unknown_exception(®s); |
| 772 | break; |
Alexander Graf | 4e642cc | 2012-02-20 23:57:26 +0100 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 776 | /** |
| 777 | * kvmppc_handle_exit |
| 778 | * |
| 779 | * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV) |
| 780 | */ |
| 781 | int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 782 | unsigned int exit_nr) |
| 783 | { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 784 | int r = RESUME_HOST; |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 785 | int s; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 786 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 787 | /* update before a new last_exit_type is rewritten */ |
| 788 | kvmppc_update_timing_stats(vcpu); |
| 789 | |
Alexander Graf | 4e642cc | 2012-02-20 23:57:26 +0100 | [diff] [blame] | 790 | /* restart interrupts if they were meant for the host */ |
| 791 | kvmppc_restart_interrupt(vcpu, exit_nr); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 792 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 793 | local_irq_enable(); |
| 794 | |
Alexander Graf | 97c9505 | 2012-08-02 15:10:00 +0200 | [diff] [blame] | 795 | trace_kvm_exit(exit_nr, vcpu); |
Alexander Graf | 706fb73 | 2012-08-12 11:29:09 +0200 | [diff] [blame] | 796 | kvm_guest_exit(); |
Alexander Graf | 97c9505 | 2012-08-02 15:10:00 +0200 | [diff] [blame] | 797 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 798 | run->exit_reason = KVM_EXIT_UNKNOWN; |
| 799 | run->ready_for_interrupt_injection = 1; |
| 800 | |
| 801 | switch (exit_nr) { |
| 802 | case BOOKE_INTERRUPT_MACHINE_CHECK: |
Alexander Graf | c35c9d8 | 2012-02-20 12:21:18 +0100 | [diff] [blame] | 803 | printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR)); |
| 804 | kvmppc_dump_vcpu(vcpu); |
| 805 | /* For debugging, send invalid exit reason to user space */ |
| 806 | run->hw.hardware_exit_reason = ~1ULL << 32; |
| 807 | run->hw.hardware_exit_reason |= mfspr(SPRN_MCSR); |
| 808 | r = RESUME_HOST; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 809 | break; |
| 810 | |
| 811 | case BOOKE_INTERRUPT_EXTERNAL: |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 812 | kvmppc_account_exit(vcpu, EXT_INTR_EXITS); |
Hollis Blanchard | 1b6766c | 2008-11-05 09:36:21 -0600 | [diff] [blame] | 813 | r = RESUME_GUEST; |
| 814 | break; |
| 815 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 816 | case BOOKE_INTERRUPT_DECREMENTER: |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 817 | kvmppc_account_exit(vcpu, DEC_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 818 | r = RESUME_GUEST; |
| 819 | break; |
| 820 | |
Bharat Bhushan | 6328e59 | 2012-06-20 05:56:53 +0000 | [diff] [blame] | 821 | case BOOKE_INTERRUPT_WATCHDOG: |
| 822 | r = RESUME_GUEST; |
| 823 | break; |
| 824 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 825 | case BOOKE_INTERRUPT_DOORBELL: |
| 826 | kvmppc_account_exit(vcpu, DBELL_EXITS); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 827 | r = RESUME_GUEST; |
| 828 | break; |
| 829 | |
| 830 | case BOOKE_INTERRUPT_GUEST_DBELL_CRIT: |
| 831 | kvmppc_account_exit(vcpu, GDBELL_EXITS); |
| 832 | |
| 833 | /* |
| 834 | * We are here because there is a pending guest interrupt |
| 835 | * which could not be delivered as MSR_CE or MSR_ME was not |
| 836 | * set. Once we break from here we will retry delivery. |
| 837 | */ |
| 838 | r = RESUME_GUEST; |
| 839 | break; |
| 840 | |
| 841 | case BOOKE_INTERRUPT_GUEST_DBELL: |
| 842 | kvmppc_account_exit(vcpu, GDBELL_EXITS); |
| 843 | |
| 844 | /* |
| 845 | * We are here because there is a pending guest interrupt |
| 846 | * which could not be delivered as MSR_EE was not set. Once |
| 847 | * we break from here we will retry delivery. |
| 848 | */ |
| 849 | r = RESUME_GUEST; |
| 850 | break; |
| 851 | |
Alexander Graf | 95f2e92 | 2012-02-20 22:45:12 +0100 | [diff] [blame] | 852 | case BOOKE_INTERRUPT_PERFORMANCE_MONITOR: |
| 853 | r = RESUME_GUEST; |
| 854 | break; |
| 855 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 856 | case BOOKE_INTERRUPT_HV_PRIV: |
| 857 | r = emulation_exit(run, vcpu); |
| 858 | break; |
| 859 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 860 | case BOOKE_INTERRUPT_PROGRAM: |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 861 | if (vcpu->arch.shared->msr & (MSR_PR | MSR_GS)) { |
Alexander Graf | 0268597 | 2012-02-20 12:33:22 +0100 | [diff] [blame] | 862 | /* |
| 863 | * Program traps generated by user-level software must |
| 864 | * be handled by the guest kernel. |
| 865 | * |
| 866 | * In GS mode, hypervisor privileged instructions trap |
| 867 | * on BOOKE_INTERRUPT_HV_PRIV, not here, so these are |
| 868 | * actual program interrupts, handled by the guest. |
| 869 | */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 870 | kvmppc_core_queue_program(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 871 | r = RESUME_GUEST; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 872 | kvmppc_account_exit(vcpu, USR_PR_INST); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 873 | break; |
| 874 | } |
| 875 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 876 | r = emulation_exit(run, vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 877 | break; |
| 878 | |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 879 | case BOOKE_INTERRUPT_FP_UNAVAIL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 880 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 881 | kvmppc_account_exit(vcpu, FP_UNAVAIL); |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 882 | r = RESUME_GUEST; |
| 883 | break; |
| 884 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 885 | #ifdef CONFIG_SPE |
| 886 | case BOOKE_INTERRUPT_SPE_UNAVAIL: { |
| 887 | if (vcpu->arch.shared->msr & MSR_SPE) |
| 888 | kvmppc_vcpu_enable_spe(vcpu); |
| 889 | else |
| 890 | kvmppc_booke_queue_irqprio(vcpu, |
| 891 | BOOKE_IRQPRIO_SPE_UNAVAIL); |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 892 | r = RESUME_GUEST; |
| 893 | break; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 894 | } |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 895 | |
| 896 | case BOOKE_INTERRUPT_SPE_FP_DATA: |
| 897 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA); |
| 898 | r = RESUME_GUEST; |
| 899 | break; |
| 900 | |
| 901 | case BOOKE_INTERRUPT_SPE_FP_ROUND: |
| 902 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND); |
| 903 | r = RESUME_GUEST; |
| 904 | break; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 905 | #else |
| 906 | case BOOKE_INTERRUPT_SPE_UNAVAIL: |
| 907 | /* |
| 908 | * Guest wants SPE, but host kernel doesn't support it. Send |
| 909 | * an "unimplemented operation" program check to the guest. |
| 910 | */ |
| 911 | kvmppc_core_queue_program(vcpu, ESR_PUO | ESR_SPV); |
| 912 | r = RESUME_GUEST; |
| 913 | break; |
| 914 | |
| 915 | /* |
| 916 | * These really should never happen without CONFIG_SPE, |
| 917 | * as we should never enable the real MSR[SPE] in the guest. |
| 918 | */ |
| 919 | case BOOKE_INTERRUPT_SPE_FP_DATA: |
| 920 | case BOOKE_INTERRUPT_SPE_FP_ROUND: |
| 921 | printk(KERN_CRIT "%s: unexpected SPE interrupt %u at %08lx\n", |
| 922 | __func__, exit_nr, vcpu->arch.pc); |
| 923 | run->hw.hardware_exit_reason = exit_nr; |
| 924 | r = RESUME_HOST; |
| 925 | break; |
| 926 | #endif |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 927 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 928 | case BOOKE_INTERRUPT_DATA_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 929 | kvmppc_core_queue_data_storage(vcpu, vcpu->arch.fault_dear, |
| 930 | vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 931 | kvmppc_account_exit(vcpu, DSI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 932 | r = RESUME_GUEST; |
| 933 | break; |
| 934 | |
| 935 | case BOOKE_INTERRUPT_INST_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 936 | kvmppc_core_queue_inst_storage(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 937 | kvmppc_account_exit(vcpu, ISI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 938 | r = RESUME_GUEST; |
| 939 | break; |
| 940 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 941 | #ifdef CONFIG_KVM_BOOKE_HV |
| 942 | case BOOKE_INTERRUPT_HV_SYSCALL: |
| 943 | if (!(vcpu->arch.shared->msr & MSR_PR)) { |
| 944 | kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); |
| 945 | } else { |
| 946 | /* |
| 947 | * hcall from guest userspace -- send privileged |
| 948 | * instruction program check. |
| 949 | */ |
| 950 | kvmppc_core_queue_program(vcpu, ESR_PPR); |
| 951 | } |
| 952 | |
| 953 | r = RESUME_GUEST; |
| 954 | break; |
| 955 | #else |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 956 | case BOOKE_INTERRUPT_SYSCALL: |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 957 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 958 | (((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) { |
| 959 | /* KVM PV hypercalls */ |
| 960 | kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); |
| 961 | r = RESUME_GUEST; |
| 962 | } else { |
| 963 | /* Guest syscalls */ |
| 964 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL); |
| 965 | } |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 966 | kvmppc_account_exit(vcpu, SYSCALL_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 967 | r = RESUME_GUEST; |
| 968 | break; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 969 | #endif |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 970 | |
| 971 | case BOOKE_INTERRUPT_DTLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 972 | unsigned long eaddr = vcpu->arch.fault_dear; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 973 | int gtlb_index; |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 974 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 975 | gfn_t gfn; |
| 976 | |
Alexander Graf | bf7ca4b | 2012-02-15 23:40:00 +0000 | [diff] [blame] | 977 | #ifdef CONFIG_KVM_E500V2 |
Scott Wood | a4cd8b2 | 2011-06-14 18:34:41 -0500 | [diff] [blame] | 978 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 979 | (eaddr & PAGE_MASK) == vcpu->arch.magic_page_ea) { |
| 980 | kvmppc_map_magic(vcpu); |
| 981 | kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS); |
| 982 | r = RESUME_GUEST; |
| 983 | |
| 984 | break; |
| 985 | } |
| 986 | #endif |
| 987 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 988 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 989 | gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 990 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 991 | /* The guest didn't have a mapping for it. */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 992 | kvmppc_core_queue_dtlb_miss(vcpu, |
| 993 | vcpu->arch.fault_dear, |
| 994 | vcpu->arch.fault_esr); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 995 | kvmppc_mmu_dtlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 996 | kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 997 | r = RESUME_GUEST; |
| 998 | break; |
| 999 | } |
| 1000 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 1001 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 1002 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1003 | |
| 1004 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 1005 | /* The guest TLB had a mapping, but the shadow TLB |
| 1006 | * didn't, and it is RAM. This could be because: |
| 1007 | * a) the entry is mapping the host kernel, or |
| 1008 | * b) the guest used a large mapping which we're faking |
| 1009 | * Either way, we need to satisfy the fault without |
| 1010 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 1011 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1012 | kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1013 | r = RESUME_GUEST; |
| 1014 | } else { |
| 1015 | /* Guest has mapped and accessed a page which is not |
| 1016 | * actually RAM. */ |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 1017 | vcpu->arch.paddr_accessed = gpaddr; |
Alexander Graf | 6020c0f | 2012-03-12 02:26:30 +0100 | [diff] [blame] | 1018 | vcpu->arch.vaddr_accessed = eaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1019 | r = kvmppc_emulate_mmio(run, vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1020 | kvmppc_account_exit(vcpu, MMIO_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | break; |
| 1024 | } |
| 1025 | |
| 1026 | case BOOKE_INTERRUPT_ITLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1027 | unsigned long eaddr = vcpu->arch.pc; |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 1028 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1029 | gfn_t gfn; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 1030 | int gtlb_index; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1031 | |
| 1032 | r = RESUME_GUEST; |
| 1033 | |
| 1034 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 1035 | gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 1036 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1037 | /* The guest didn't have a mapping for it. */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 1038 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 1039 | kvmppc_mmu_itlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1040 | kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1041 | break; |
| 1042 | } |
| 1043 | |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1044 | kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1045 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 1046 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 1047 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1048 | |
| 1049 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 1050 | /* The guest TLB had a mapping, but the shadow TLB |
| 1051 | * didn't. This could be because: |
| 1052 | * a) the entry is mapping the host kernel, or |
| 1053 | * b) the guest used a large mapping which we're faking |
| 1054 | * Either way, we need to satisfy the fault without |
| 1055 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 1056 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1057 | } else { |
| 1058 | /* Guest mapped and leaped at non-RAM! */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 1059 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | break; |
| 1063 | } |
| 1064 | |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 1065 | case BOOKE_INTERRUPT_DEBUG: { |
| 1066 | u32 dbsr; |
| 1067 | |
| 1068 | vcpu->arch.pc = mfspr(SPRN_CSRR0); |
| 1069 | |
| 1070 | /* clear IAC events in DBSR register */ |
| 1071 | dbsr = mfspr(SPRN_DBSR); |
| 1072 | dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4; |
| 1073 | mtspr(SPRN_DBSR, dbsr); |
| 1074 | |
| 1075 | run->exit_reason = KVM_EXIT_DEBUG; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1076 | kvmppc_account_exit(vcpu, DEBUG_EXITS); |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 1077 | r = RESUME_HOST; |
| 1078 | break; |
| 1079 | } |
| 1080 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1081 | default: |
| 1082 | printk(KERN_EMERG "exit_nr %d\n", exit_nr); |
| 1083 | BUG(); |
| 1084 | } |
| 1085 | |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 1086 | /* |
| 1087 | * To avoid clobbering exit_reason, only check for signals if we |
| 1088 | * aren't already exiting to userspace for some other reason. |
| 1089 | */ |
Alexander Graf | 03660ba | 2012-02-28 12:00:41 +0100 | [diff] [blame] | 1090 | if (!(r & RESUME_HOST)) { |
| 1091 | local_irq_disable(); |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 1092 | s = kvmppc_prepare_to_enter(vcpu); |
| 1093 | if (s <= 0) { |
Alexander Graf | 24afa37 | 2012-08-12 12:42:30 +0200 | [diff] [blame] | 1094 | local_irq_enable(); |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 1095 | r = (s << 2) | RESUME_HOST | (r & RESUME_FLAG_NV); |
Alexander Graf | 24afa37 | 2012-08-12 12:42:30 +0200 | [diff] [blame] | 1096 | } else { |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 1097 | kvmppc_lazy_ee_enable(); |
Alexander Graf | 03660ba | 2012-02-28 12:00:41 +0100 | [diff] [blame] | 1098 | } |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | return r; |
| 1102 | } |
| 1103 | |
| 1104 | /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */ |
| 1105 | int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) |
| 1106 | { |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 1107 | int i; |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 1108 | int r; |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 1109 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1110 | vcpu->arch.pc = 0; |
Scott Wood | b590497 | 2011-11-08 18:23:30 -0600 | [diff] [blame] | 1111 | vcpu->arch.shared->pir = vcpu->vcpu_id; |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 1112 | kvmppc_set_gpr(vcpu, 1, (16<<20) - 8); /* -8 for the callee-save LR slot */ |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1113 | kvmppc_set_msr(vcpu, 0); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1114 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1115 | #ifndef CONFIG_KVM_BOOKE_HV |
| 1116 | vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS; |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 1117 | vcpu->arch.shadow_pid = 1; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1118 | vcpu->arch.shared->msr = 0; |
| 1119 | #endif |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 1120 | |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 1121 | /* Eye-catching numbers so we know if the guest takes an interrupt |
| 1122 | * before it's programmed its own IVPR/IVORs. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1123 | vcpu->arch.ivpr = 0x55550000; |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 1124 | for (i = 0; i < BOOKE_IRQPRIO_MAX; i++) |
| 1125 | vcpu->arch.ivor[i] = 0x7700 | i * 4; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1126 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 1127 | kvmppc_init_timing_stats(vcpu); |
| 1128 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 1129 | r = kvmppc_core_vcpu_setup(vcpu); |
| 1130 | kvmppc_sanity_check(vcpu); |
| 1131 | return r; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1132 | } |
| 1133 | |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 1134 | int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu) |
| 1135 | { |
| 1136 | /* setup watchdog timer once */ |
| 1137 | spin_lock_init(&vcpu->arch.wdt_lock); |
| 1138 | setup_timer(&vcpu->arch.wdt_timer, kvmppc_watchdog_func, |
| 1139 | (unsigned long)vcpu); |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu) |
| 1145 | { |
| 1146 | del_timer_sync(&vcpu->arch.wdt_timer); |
| 1147 | } |
| 1148 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1149 | int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 1150 | { |
| 1151 | int i; |
| 1152 | |
| 1153 | regs->pc = vcpu->arch.pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1154 | regs->cr = kvmppc_get_cr(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1155 | regs->ctr = vcpu->arch.ctr; |
| 1156 | regs->lr = vcpu->arch.lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1157 | regs->xer = kvmppc_get_xer(vcpu); |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 1158 | regs->msr = vcpu->arch.shared->msr; |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 1159 | regs->srr0 = vcpu->arch.shared->srr0; |
| 1160 | regs->srr1 = vcpu->arch.shared->srr1; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1161 | regs->pid = vcpu->arch.pid; |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 1162 | regs->sprg0 = vcpu->arch.shared->sprg0; |
| 1163 | regs->sprg1 = vcpu->arch.shared->sprg1; |
| 1164 | regs->sprg2 = vcpu->arch.shared->sprg2; |
| 1165 | regs->sprg3 = vcpu->arch.shared->sprg3; |
Scott Wood | b590497 | 2011-11-08 18:23:30 -0600 | [diff] [blame] | 1166 | regs->sprg4 = vcpu->arch.shared->sprg4; |
| 1167 | regs->sprg5 = vcpu->arch.shared->sprg5; |
| 1168 | regs->sprg6 = vcpu->arch.shared->sprg6; |
| 1169 | regs->sprg7 = vcpu->arch.shared->sprg7; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1170 | |
| 1171 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 1172 | regs->gpr[i] = kvmppc_get_gpr(vcpu, i); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1173 | |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 1178 | { |
| 1179 | int i; |
| 1180 | |
| 1181 | vcpu->arch.pc = regs->pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1182 | kvmppc_set_cr(vcpu, regs->cr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1183 | vcpu->arch.ctr = regs->ctr; |
| 1184 | vcpu->arch.lr = regs->lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1185 | kvmppc_set_xer(vcpu, regs->xer); |
Hollis Blanchard | b8fd68a | 2008-11-05 09:36:20 -0600 | [diff] [blame] | 1186 | kvmppc_set_msr(vcpu, regs->msr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 1187 | vcpu->arch.shared->srr0 = regs->srr0; |
| 1188 | vcpu->arch.shared->srr1 = regs->srr1; |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1189 | kvmppc_set_pid(vcpu, regs->pid); |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 1190 | vcpu->arch.shared->sprg0 = regs->sprg0; |
| 1191 | vcpu->arch.shared->sprg1 = regs->sprg1; |
| 1192 | vcpu->arch.shared->sprg2 = regs->sprg2; |
| 1193 | vcpu->arch.shared->sprg3 = regs->sprg3; |
Scott Wood | b590497 | 2011-11-08 18:23:30 -0600 | [diff] [blame] | 1194 | vcpu->arch.shared->sprg4 = regs->sprg4; |
| 1195 | vcpu->arch.shared->sprg5 = regs->sprg5; |
| 1196 | vcpu->arch.shared->sprg6 = regs->sprg6; |
| 1197 | vcpu->arch.shared->sprg7 = regs->sprg7; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1198 | |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 1199 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
| 1200 | kvmppc_set_gpr(vcpu, i, regs->gpr[i]); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1201 | |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1205 | static void get_sregs_base(struct kvm_vcpu *vcpu, |
| 1206 | struct kvm_sregs *sregs) |
| 1207 | { |
| 1208 | u64 tb = get_tb(); |
| 1209 | |
| 1210 | sregs->u.e.features |= KVM_SREGS_E_BASE; |
| 1211 | |
| 1212 | sregs->u.e.csrr0 = vcpu->arch.csrr0; |
| 1213 | sregs->u.e.csrr1 = vcpu->arch.csrr1; |
| 1214 | sregs->u.e.mcsr = vcpu->arch.mcsr; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1215 | sregs->u.e.esr = get_guest_esr(vcpu); |
| 1216 | sregs->u.e.dear = get_guest_dear(vcpu); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1217 | sregs->u.e.tsr = vcpu->arch.tsr; |
| 1218 | sregs->u.e.tcr = vcpu->arch.tcr; |
| 1219 | sregs->u.e.dec = kvmppc_get_dec(vcpu, tb); |
| 1220 | sregs->u.e.tb = tb; |
| 1221 | sregs->u.e.vrsave = vcpu->arch.vrsave; |
| 1222 | } |
| 1223 | |
| 1224 | static int set_sregs_base(struct kvm_vcpu *vcpu, |
| 1225 | struct kvm_sregs *sregs) |
| 1226 | { |
| 1227 | if (!(sregs->u.e.features & KVM_SREGS_E_BASE)) |
| 1228 | return 0; |
| 1229 | |
| 1230 | vcpu->arch.csrr0 = sregs->u.e.csrr0; |
| 1231 | vcpu->arch.csrr1 = sregs->u.e.csrr1; |
| 1232 | vcpu->arch.mcsr = sregs->u.e.mcsr; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1233 | set_guest_esr(vcpu, sregs->u.e.esr); |
| 1234 | set_guest_dear(vcpu, sregs->u.e.dear); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1235 | vcpu->arch.vrsave = sregs->u.e.vrsave; |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1236 | kvmppc_set_tcr(vcpu, sregs->u.e.tcr); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1237 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1238 | if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_DEC) { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1239 | vcpu->arch.dec = sregs->u.e.dec; |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1240 | kvmppc_emulate_dec(vcpu); |
| 1241 | } |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1242 | |
| 1243 | if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_TSR) { |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 1244 | u32 old_tsr = vcpu->arch.tsr; |
| 1245 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1246 | vcpu->arch.tsr = sregs->u.e.tsr; |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 1247 | |
| 1248 | if ((old_tsr ^ vcpu->arch.tsr) & (TSR_ENW | TSR_WIS)) |
| 1249 | arm_next_watchdog(vcpu); |
| 1250 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1251 | update_timer_ints(vcpu); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | static void get_sregs_arch206(struct kvm_vcpu *vcpu, |
| 1258 | struct kvm_sregs *sregs) |
| 1259 | { |
| 1260 | sregs->u.e.features |= KVM_SREGS_E_ARCH206; |
| 1261 | |
Scott Wood | 841741f | 2011-09-02 17:39:37 -0500 | [diff] [blame] | 1262 | sregs->u.e.pir = vcpu->vcpu_id; |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1263 | sregs->u.e.mcsrr0 = vcpu->arch.mcsrr0; |
| 1264 | sregs->u.e.mcsrr1 = vcpu->arch.mcsrr1; |
| 1265 | sregs->u.e.decar = vcpu->arch.decar; |
| 1266 | sregs->u.e.ivpr = vcpu->arch.ivpr; |
| 1267 | } |
| 1268 | |
| 1269 | static int set_sregs_arch206(struct kvm_vcpu *vcpu, |
| 1270 | struct kvm_sregs *sregs) |
| 1271 | { |
| 1272 | if (!(sregs->u.e.features & KVM_SREGS_E_ARCH206)) |
| 1273 | return 0; |
| 1274 | |
Scott Wood | 841741f | 2011-09-02 17:39:37 -0500 | [diff] [blame] | 1275 | if (sregs->u.e.pir != vcpu->vcpu_id) |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1276 | return -EINVAL; |
| 1277 | |
| 1278 | vcpu->arch.mcsrr0 = sregs->u.e.mcsrr0; |
| 1279 | vcpu->arch.mcsrr1 = sregs->u.e.mcsrr1; |
| 1280 | vcpu->arch.decar = sregs->u.e.decar; |
| 1281 | vcpu->arch.ivpr = sregs->u.e.ivpr; |
| 1282 | |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
| 1286 | void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) |
| 1287 | { |
| 1288 | sregs->u.e.features |= KVM_SREGS_E_IVOR; |
| 1289 | |
| 1290 | sregs->u.e.ivor_low[0] = vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL]; |
| 1291 | sregs->u.e.ivor_low[1] = vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK]; |
| 1292 | sregs->u.e.ivor_low[2] = vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE]; |
| 1293 | sregs->u.e.ivor_low[3] = vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE]; |
| 1294 | sregs->u.e.ivor_low[4] = vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL]; |
| 1295 | sregs->u.e.ivor_low[5] = vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT]; |
| 1296 | sregs->u.e.ivor_low[6] = vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM]; |
| 1297 | sregs->u.e.ivor_low[7] = vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL]; |
| 1298 | sregs->u.e.ivor_low[8] = vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL]; |
| 1299 | sregs->u.e.ivor_low[9] = vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL]; |
| 1300 | sregs->u.e.ivor_low[10] = vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER]; |
| 1301 | sregs->u.e.ivor_low[11] = vcpu->arch.ivor[BOOKE_IRQPRIO_FIT]; |
| 1302 | sregs->u.e.ivor_low[12] = vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG]; |
| 1303 | sregs->u.e.ivor_low[13] = vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS]; |
| 1304 | sregs->u.e.ivor_low[14] = vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS]; |
| 1305 | sregs->u.e.ivor_low[15] = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG]; |
| 1306 | } |
| 1307 | |
| 1308 | int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) |
| 1309 | { |
| 1310 | if (!(sregs->u.e.features & KVM_SREGS_E_IVOR)) |
| 1311 | return 0; |
| 1312 | |
| 1313 | vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL] = sregs->u.e.ivor_low[0]; |
| 1314 | vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK] = sregs->u.e.ivor_low[1]; |
| 1315 | vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE] = sregs->u.e.ivor_low[2]; |
| 1316 | vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE] = sregs->u.e.ivor_low[3]; |
| 1317 | vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL] = sregs->u.e.ivor_low[4]; |
| 1318 | vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT] = sregs->u.e.ivor_low[5]; |
| 1319 | vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM] = sregs->u.e.ivor_low[6]; |
| 1320 | vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL] = sregs->u.e.ivor_low[7]; |
| 1321 | vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL] = sregs->u.e.ivor_low[8]; |
| 1322 | vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL] = sregs->u.e.ivor_low[9]; |
| 1323 | vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER] = sregs->u.e.ivor_low[10]; |
| 1324 | vcpu->arch.ivor[BOOKE_IRQPRIO_FIT] = sregs->u.e.ivor_low[11]; |
| 1325 | vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG] = sregs->u.e.ivor_low[12]; |
| 1326 | vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS] = sregs->u.e.ivor_low[13]; |
| 1327 | vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS] = sregs->u.e.ivor_low[14]; |
| 1328 | vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG] = sregs->u.e.ivor_low[15]; |
| 1329 | |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1333 | int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, |
| 1334 | struct kvm_sregs *sregs) |
| 1335 | { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1336 | sregs->pvr = vcpu->arch.pvr; |
| 1337 | |
| 1338 | get_sregs_base(vcpu, sregs); |
| 1339 | get_sregs_arch206(vcpu, sregs); |
| 1340 | kvmppc_core_get_sregs(vcpu, sregs); |
| 1341 | return 0; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, |
| 1345 | struct kvm_sregs *sregs) |
| 1346 | { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1347 | int ret; |
| 1348 | |
| 1349 | if (vcpu->arch.pvr != sregs->pvr) |
| 1350 | return -EINVAL; |
| 1351 | |
| 1352 | ret = set_sregs_base(vcpu, sregs); |
| 1353 | if (ret < 0) |
| 1354 | return ret; |
| 1355 | |
| 1356 | ret = set_sregs_arch206(vcpu, sregs); |
| 1357 | if (ret < 0) |
| 1358 | return ret; |
| 1359 | |
| 1360 | return kvmppc_core_set_sregs(vcpu, sregs); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1361 | } |
| 1362 | |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1363 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
| 1364 | { |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1365 | int r = -EINVAL; |
| 1366 | |
| 1367 | switch (reg->id) { |
| 1368 | case KVM_REG_PPC_IAC1: |
| 1369 | case KVM_REG_PPC_IAC2: |
| 1370 | case KVM_REG_PPC_IAC3: |
| 1371 | case KVM_REG_PPC_IAC4: { |
| 1372 | int iac = reg->id - KVM_REG_PPC_IAC1; |
| 1373 | r = copy_to_user((u64 __user *)(long)reg->addr, |
| 1374 | &vcpu->arch.dbg_reg.iac[iac], sizeof(u64)); |
| 1375 | break; |
| 1376 | } |
| 1377 | case KVM_REG_PPC_DAC1: |
| 1378 | case KVM_REG_PPC_DAC2: { |
| 1379 | int dac = reg->id - KVM_REG_PPC_DAC1; |
| 1380 | r = copy_to_user((u64 __user *)(long)reg->addr, |
| 1381 | &vcpu->arch.dbg_reg.dac[dac], sizeof(u64)); |
| 1382 | break; |
| 1383 | } |
| 1384 | default: |
| 1385 | break; |
| 1386 | } |
| 1387 | return r; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
| 1391 | { |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1392 | int r = -EINVAL; |
| 1393 | |
| 1394 | switch (reg->id) { |
| 1395 | case KVM_REG_PPC_IAC1: |
| 1396 | case KVM_REG_PPC_IAC2: |
| 1397 | case KVM_REG_PPC_IAC3: |
| 1398 | case KVM_REG_PPC_IAC4: { |
| 1399 | int iac = reg->id - KVM_REG_PPC_IAC1; |
| 1400 | r = copy_from_user(&vcpu->arch.dbg_reg.iac[iac], |
| 1401 | (u64 __user *)(long)reg->addr, sizeof(u64)); |
| 1402 | break; |
| 1403 | } |
| 1404 | case KVM_REG_PPC_DAC1: |
| 1405 | case KVM_REG_PPC_DAC2: { |
| 1406 | int dac = reg->id - KVM_REG_PPC_DAC1; |
| 1407 | r = copy_from_user(&vcpu->arch.dbg_reg.dac[dac], |
| 1408 | (u64 __user *)(long)reg->addr, sizeof(u64)); |
| 1409 | break; |
| 1410 | } |
| 1411 | default: |
| 1412 | break; |
| 1413 | } |
| 1414 | return r; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1417 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 1418 | { |
| 1419 | return -ENOTSUPP; |
| 1420 | } |
| 1421 | |
| 1422 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 1423 | { |
| 1424 | return -ENOTSUPP; |
| 1425 | } |
| 1426 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1427 | int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, |
| 1428 | struct kvm_translation *tr) |
| 1429 | { |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1430 | int r; |
| 1431 | |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1432 | r = kvmppc_core_vcpu_translate(vcpu, tr); |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1433 | return r; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1434 | } |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1435 | |
Alexander Graf | 4e75575 | 2009-10-30 05:47:01 +0000 | [diff] [blame] | 1436 | int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) |
| 1437 | { |
| 1438 | return -ENOTSUPP; |
| 1439 | } |
| 1440 | |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 1441 | void kvmppc_core_free_memslot(struct kvm_memory_slot *free, |
| 1442 | struct kvm_memory_slot *dont) |
| 1443 | { |
| 1444 | } |
| 1445 | |
| 1446 | int kvmppc_core_create_memslot(struct kvm_memory_slot *slot, |
| 1447 | unsigned long npages) |
| 1448 | { |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 1452 | int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 1453 | struct kvm_memory_slot *memslot, |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 1454 | struct kvm_userspace_memory_region *mem) |
| 1455 | { |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
| 1459 | void kvmppc_core_commit_memory_region(struct kvm *kvm, |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 1460 | struct kvm_userspace_memory_region *mem, |
| 1461 | struct kvm_memory_slot old) |
| 1462 | { |
| 1463 | } |
| 1464 | |
| 1465 | void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot) |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 1466 | { |
| 1467 | } |
| 1468 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1469 | void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr) |
| 1470 | { |
| 1471 | vcpu->arch.tcr = new_tcr; |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 1472 | arm_next_watchdog(vcpu); |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1473 | update_timer_ints(vcpu); |
| 1474 | } |
| 1475 | |
| 1476 | void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits) |
| 1477 | { |
| 1478 | set_bits(tsr_bits, &vcpu->arch.tsr); |
| 1479 | smp_wmb(); |
| 1480 | kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu); |
| 1481 | kvm_vcpu_kick(vcpu); |
| 1482 | } |
| 1483 | |
| 1484 | void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits) |
| 1485 | { |
| 1486 | clear_bits(tsr_bits, &vcpu->arch.tsr); |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 1487 | |
| 1488 | /* |
| 1489 | * We may have stopped the watchdog due to |
| 1490 | * being stuck on final expiration. |
| 1491 | */ |
| 1492 | if (tsr_bits & (TSR_ENW | TSR_WIS)) |
| 1493 | arm_next_watchdog(vcpu); |
| 1494 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1495 | update_timer_ints(vcpu); |
| 1496 | } |
| 1497 | |
| 1498 | void kvmppc_decrementer_func(unsigned long data) |
| 1499 | { |
| 1500 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; |
| 1501 | |
Bharat Bhushan | 21bd000 | 2012-05-20 23:21:23 +0000 | [diff] [blame] | 1502 | if (vcpu->arch.tcr & TCR_ARE) { |
| 1503 | vcpu->arch.dec = vcpu->arch.decar; |
| 1504 | kvmppc_emulate_dec(vcpu); |
| 1505 | } |
| 1506 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1507 | kvmppc_set_tsr_bits(vcpu, TSR_DIS); |
| 1508 | } |
| 1509 | |
Scott Wood | 94fa9d9 | 2011-12-20 15:34:22 +0000 | [diff] [blame] | 1510 | void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu) |
| 1511 | { |
Paul Mackerras | a47d72f | 2012-09-20 19:35:51 +0000 | [diff] [blame^] | 1512 | vcpu->cpu = smp_processor_id(); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1513 | current->thread.kvm_vcpu = vcpu; |
Scott Wood | 94fa9d9 | 2011-12-20 15:34:22 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu) |
| 1517 | { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1518 | current->thread.kvm_vcpu = NULL; |
Paul Mackerras | a47d72f | 2012-09-20 19:35:51 +0000 | [diff] [blame^] | 1519 | vcpu->cpu = -1; |
Scott Wood | 94fa9d9 | 2011-12-20 15:34:22 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Stephen Rothwell | 2986b8c | 2009-06-02 11:46:14 +1000 | [diff] [blame] | 1522 | int __init kvmppc_booke_init(void) |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1523 | { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1524 | #ifndef CONFIG_KVM_BOOKE_HV |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1525 | unsigned long ivor[16]; |
| 1526 | unsigned long max_ivor = 0; |
| 1527 | int i; |
| 1528 | |
| 1529 | /* We install our own exception handlers by hijacking IVPR. IVPR must |
| 1530 | * be 16-bit aligned, so we need a 64KB allocation. */ |
| 1531 | kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO, |
| 1532 | VCPU_SIZE_ORDER); |
| 1533 | if (!kvmppc_booke_handlers) |
| 1534 | return -ENOMEM; |
| 1535 | |
| 1536 | /* XXX make sure our handlers are smaller than Linux's */ |
| 1537 | |
| 1538 | /* Copy our interrupt handlers to match host IVORs. That way we don't |
| 1539 | * have to swap the IVORs on every guest/host transition. */ |
| 1540 | ivor[0] = mfspr(SPRN_IVOR0); |
| 1541 | ivor[1] = mfspr(SPRN_IVOR1); |
| 1542 | ivor[2] = mfspr(SPRN_IVOR2); |
| 1543 | ivor[3] = mfspr(SPRN_IVOR3); |
| 1544 | ivor[4] = mfspr(SPRN_IVOR4); |
| 1545 | ivor[5] = mfspr(SPRN_IVOR5); |
| 1546 | ivor[6] = mfspr(SPRN_IVOR6); |
| 1547 | ivor[7] = mfspr(SPRN_IVOR7); |
| 1548 | ivor[8] = mfspr(SPRN_IVOR8); |
| 1549 | ivor[9] = mfspr(SPRN_IVOR9); |
| 1550 | ivor[10] = mfspr(SPRN_IVOR10); |
| 1551 | ivor[11] = mfspr(SPRN_IVOR11); |
| 1552 | ivor[12] = mfspr(SPRN_IVOR12); |
| 1553 | ivor[13] = mfspr(SPRN_IVOR13); |
| 1554 | ivor[14] = mfspr(SPRN_IVOR14); |
| 1555 | ivor[15] = mfspr(SPRN_IVOR15); |
| 1556 | |
| 1557 | for (i = 0; i < 16; i++) { |
| 1558 | if (ivor[i] > max_ivor) |
| 1559 | max_ivor = ivor[i]; |
| 1560 | |
| 1561 | memcpy((void *)kvmppc_booke_handlers + ivor[i], |
| 1562 | kvmppc_handlers_start + i * kvmppc_handler_len, |
| 1563 | kvmppc_handler_len); |
| 1564 | } |
| 1565 | flush_icache_range(kvmppc_booke_handlers, |
| 1566 | kvmppc_booke_handlers + max_ivor + kvmppc_handler_len); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1567 | #endif /* !BOOKE_HV */ |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 1568 | return 0; |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1569 | } |
| 1570 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 1571 | void __exit kvmppc_booke_exit(void) |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1572 | { |
| 1573 | free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER); |
| 1574 | kvm_exit(); |
| 1575 | } |