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