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