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> |
| 20 | */ |
| 21 | |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/err.h> |
| 24 | #include <linux/kvm_host.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/gfp.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 26 | #include <linux/module.h> |
| 27 | #include <linux/vmalloc.h> |
| 28 | #include <linux/fs.h> |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 29 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 30 | #include <asm/cputable.h> |
| 31 | #include <asm/uaccess.h> |
| 32 | #include <asm/kvm_ppc.h> |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 33 | #include "timing.h" |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 34 | #include <asm/cacheflush.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 35 | |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 36 | #include "booke.h" |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 37 | |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 38 | unsigned long kvmppc_booke_handlers; |
| 39 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 40 | #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM |
| 41 | #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU |
| 42 | |
| 43 | struct kvm_stats_debugfs_item debugfs_entries[] = { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 44 | { "mmio", VCPU_STAT(mmio_exits) }, |
| 45 | { "dcr", VCPU_STAT(dcr_exits) }, |
| 46 | { "sig", VCPU_STAT(signal_exits) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 47 | { "itlb_r", VCPU_STAT(itlb_real_miss_exits) }, |
| 48 | { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) }, |
| 49 | { "dtlb_r", VCPU_STAT(dtlb_real_miss_exits) }, |
| 50 | { "dtlb_v", VCPU_STAT(dtlb_virt_miss_exits) }, |
| 51 | { "sysc", VCPU_STAT(syscall_exits) }, |
| 52 | { "isi", VCPU_STAT(isi_exits) }, |
| 53 | { "dsi", VCPU_STAT(dsi_exits) }, |
| 54 | { "inst_emu", VCPU_STAT(emulated_inst_exits) }, |
| 55 | { "dec", VCPU_STAT(dec_exits) }, |
| 56 | { "ext_intr", VCPU_STAT(ext_intr_exits) }, |
Hollis Blanchard | 45c5eb6 | 2008-04-25 17:55:49 -0500 | [diff] [blame] | 57 | { "halt_wakeup", VCPU_STAT(halt_wakeup) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 58 | { NULL } |
| 59 | }; |
| 60 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 61 | /* TODO: use vcpu_printf() */ |
| 62 | void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu) |
| 63 | { |
| 64 | int i; |
| 65 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 66 | 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] | 67 | printk("lr: %08lx ctr: %08lx\n", vcpu->arch.lr, vcpu->arch.ctr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 68 | printk("srr0: %08llx srr1: %08llx\n", vcpu->arch.shared->srr0, |
| 69 | vcpu->arch.shared->srr1); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 70 | |
| 71 | printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions); |
| 72 | |
| 73 | for (i = 0; i < 32; i += 4) { |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 74 | printk("gpr%02d: %08lx %08lx %08lx %08lx\n", i, |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 75 | kvmppc_get_gpr(vcpu, i), |
| 76 | kvmppc_get_gpr(vcpu, i+1), |
| 77 | kvmppc_get_gpr(vcpu, i+2), |
| 78 | kvmppc_get_gpr(vcpu, i+3)); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 82 | #ifdef CONFIG_SPE |
| 83 | void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu) |
| 84 | { |
| 85 | preempt_disable(); |
| 86 | enable_kernel_spe(); |
| 87 | kvmppc_save_guest_spe(vcpu); |
| 88 | vcpu->arch.shadow_msr &= ~MSR_SPE; |
| 89 | preempt_enable(); |
| 90 | } |
| 91 | |
| 92 | static void kvmppc_vcpu_enable_spe(struct kvm_vcpu *vcpu) |
| 93 | { |
| 94 | preempt_disable(); |
| 95 | enable_kernel_spe(); |
| 96 | kvmppc_load_guest_spe(vcpu); |
| 97 | vcpu->arch.shadow_msr |= MSR_SPE; |
| 98 | preempt_enable(); |
| 99 | } |
| 100 | |
| 101 | static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu) |
| 102 | { |
| 103 | if (vcpu->arch.shared->msr & MSR_SPE) { |
| 104 | if (!(vcpu->arch.shadow_msr & MSR_SPE)) |
| 105 | kvmppc_vcpu_enable_spe(vcpu); |
| 106 | } else if (vcpu->arch.shadow_msr & MSR_SPE) { |
| 107 | kvmppc_vcpu_disable_spe(vcpu); |
| 108 | } |
| 109 | } |
| 110 | #else |
| 111 | static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu) |
| 112 | { |
| 113 | } |
| 114 | #endif |
| 115 | |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 116 | /* |
| 117 | * Helper function for "full" MSR writes. No need to call this if only |
| 118 | * EE/CE/ME/DE/RI are changing. |
| 119 | */ |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 120 | void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr) |
| 121 | { |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 122 | u32 old_msr = vcpu->arch.shared->msr; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 123 | |
| 124 | vcpu->arch.shared->msr = new_msr; |
| 125 | |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 126 | kvmppc_mmu_msr_notify(vcpu, old_msr); |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 127 | kvmppc_vcpu_sync_spe(vcpu); |
| 128 | } |
| 129 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 130 | static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, |
| 131 | unsigned int priority) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 132 | { |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 133 | set_bit(priority, &vcpu->arch.pending_exceptions); |
| 134 | } |
| 135 | |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 136 | static void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, |
| 137 | ulong dear_flags, ulong esr_flags) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 138 | { |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 139 | vcpu->arch.queued_dear = dear_flags; |
| 140 | vcpu->arch.queued_esr = esr_flags; |
| 141 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS); |
| 142 | } |
| 143 | |
| 144 | static void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, |
| 145 | ulong dear_flags, ulong esr_flags) |
| 146 | { |
| 147 | vcpu->arch.queued_dear = dear_flags; |
| 148 | vcpu->arch.queued_esr = esr_flags; |
| 149 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE); |
| 150 | } |
| 151 | |
| 152 | static void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, |
| 153 | ulong esr_flags) |
| 154 | { |
| 155 | vcpu->arch.queued_esr = esr_flags; |
| 156 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE); |
| 157 | } |
| 158 | |
| 159 | void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags) |
| 160 | { |
| 161 | vcpu->arch.queued_esr = esr_flags; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 162 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu) |
| 166 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 167 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DECREMENTER); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu) |
| 171 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 172 | return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 173 | } |
| 174 | |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 175 | void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu) |
| 176 | { |
| 177 | clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
| 178 | } |
| 179 | |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 180 | void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 181 | struct kvm_interrupt *irq) |
| 182 | { |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 183 | unsigned int prio = BOOKE_IRQPRIO_EXTERNAL; |
| 184 | |
| 185 | if (irq->irq == KVM_INTERRUPT_SET_LEVEL) |
| 186 | prio = BOOKE_IRQPRIO_EXTERNAL_LEVEL; |
| 187 | |
| 188 | kvmppc_booke_queue_irqprio(vcpu, prio); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 189 | } |
| 190 | |
Alexander Graf | 4496f97 | 2010-04-07 10:03:25 +0200 | [diff] [blame] | 191 | void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu, |
| 192 | struct kvm_interrupt *irq) |
| 193 | { |
| 194 | clear_bit(BOOKE_IRQPRIO_EXTERNAL, &vcpu->arch.pending_exceptions); |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 195 | clear_bit(BOOKE_IRQPRIO_EXTERNAL_LEVEL, &vcpu->arch.pending_exceptions); |
Alexander Graf | 4496f97 | 2010-04-07 10:03:25 +0200 | [diff] [blame] | 196 | } |
| 197 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 198 | /* Deliver the interrupt of the corresponding priority, if possible. */ |
| 199 | static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, |
| 200 | unsigned int priority) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 201 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 202 | int allowed = 0; |
Asias He | 6045be5 | 2010-06-19 16:52:12 +0800 | [diff] [blame] | 203 | ulong uninitialized_var(msr_mask); |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 204 | bool update_esr = false, update_dear = false; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 205 | ulong crit_raw = vcpu->arch.shared->critical; |
| 206 | ulong crit_r1 = kvmppc_get_gpr(vcpu, 1); |
| 207 | bool crit; |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 208 | bool keep_irq = false; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 209 | |
| 210 | /* Truncate crit indicators in 32 bit mode */ |
| 211 | if (!(vcpu->arch.shared->msr & MSR_SF)) { |
| 212 | crit_raw &= 0xffffffff; |
| 213 | crit_r1 &= 0xffffffff; |
| 214 | } |
| 215 | |
| 216 | /* Critical section when crit == r1 */ |
| 217 | crit = (crit_raw == crit_r1); |
| 218 | /* ... and we're in supervisor mode */ |
| 219 | crit = crit && !(vcpu->arch.shared->msr & MSR_PR); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 220 | |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 221 | if (priority == BOOKE_IRQPRIO_EXTERNAL_LEVEL) { |
| 222 | priority = BOOKE_IRQPRIO_EXTERNAL; |
| 223 | keep_irq = true; |
| 224 | } |
| 225 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 226 | switch (priority) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 227 | case BOOKE_IRQPRIO_DTLB_MISS: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 228 | case BOOKE_IRQPRIO_DATA_STORAGE: |
| 229 | update_dear = true; |
| 230 | /* fall through */ |
| 231 | case BOOKE_IRQPRIO_INST_STORAGE: |
| 232 | case BOOKE_IRQPRIO_PROGRAM: |
| 233 | update_esr = true; |
| 234 | /* fall through */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 235 | case BOOKE_IRQPRIO_ITLB_MISS: |
| 236 | case BOOKE_IRQPRIO_SYSCALL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 237 | case BOOKE_IRQPRIO_FP_UNAVAIL: |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 238 | case BOOKE_IRQPRIO_SPE_UNAVAIL: |
| 239 | case BOOKE_IRQPRIO_SPE_FP_DATA: |
| 240 | case BOOKE_IRQPRIO_SPE_FP_ROUND: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 241 | case BOOKE_IRQPRIO_AP_UNAVAIL: |
| 242 | case BOOKE_IRQPRIO_ALIGNMENT: |
| 243 | allowed = 1; |
| 244 | msr_mask = MSR_CE|MSR_ME|MSR_DE; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 245 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 246 | case BOOKE_IRQPRIO_CRITICAL: |
| 247 | case BOOKE_IRQPRIO_WATCHDOG: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 248 | allowed = vcpu->arch.shared->msr & MSR_CE; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 249 | msr_mask = MSR_ME; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 250 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 251 | case BOOKE_IRQPRIO_MACHINE_CHECK: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 252 | allowed = vcpu->arch.shared->msr & MSR_ME; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 253 | msr_mask = 0; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 254 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 255 | case BOOKE_IRQPRIO_EXTERNAL: |
| 256 | case BOOKE_IRQPRIO_DECREMENTER: |
| 257 | case BOOKE_IRQPRIO_FIT: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 258 | allowed = vcpu->arch.shared->msr & MSR_EE; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 259 | allowed = allowed && !crit; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 260 | msr_mask = MSR_CE|MSR_ME|MSR_DE; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 261 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 262 | case BOOKE_IRQPRIO_DEBUG: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 263 | allowed = vcpu->arch.shared->msr & MSR_DE; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 264 | msr_mask = MSR_ME; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 265 | break; |
| 266 | } |
| 267 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 268 | if (allowed) { |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 269 | vcpu->arch.shared->srr0 = vcpu->arch.pc; |
| 270 | vcpu->arch.shared->srr1 = vcpu->arch.shared->msr; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 271 | vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority]; |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 272 | if (update_esr == true) |
| 273 | vcpu->arch.esr = vcpu->arch.queued_esr; |
| 274 | if (update_dear == true) |
Alexander Graf | 5e03018 | 2010-07-29 14:47:45 +0200 | [diff] [blame] | 275 | vcpu->arch.shared->dar = vcpu->arch.queued_dear; |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 276 | kvmppc_set_msr(vcpu, vcpu->arch.shared->msr & msr_mask); |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 277 | |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 278 | if (!keep_irq) |
| 279 | clear_bit(priority, &vcpu->arch.pending_exceptions); |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | return allowed; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 283 | } |
| 284 | |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 285 | static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 286 | { |
| 287 | unsigned long *pending = &vcpu->arch.pending_exceptions; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 288 | unsigned int priority; |
| 289 | |
Hollis Blanchard | 9ab8084 | 2008-11-05 09:36:22 -0600 | [diff] [blame] | 290 | priority = __ffs(*pending); |
Hollis Blanchard | bdc89f1 | 2009-01-03 16:23:12 -0600 | [diff] [blame] | 291 | while (priority <= BOOKE_IRQPRIO_MAX) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 292 | if (kvmppc_booke_irqprio_deliver(vcpu, priority)) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 293 | break; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 294 | |
| 295 | priority = find_next_bit(pending, |
| 296 | BITS_PER_BYTE * sizeof(*pending), |
| 297 | priority + 1); |
| 298 | } |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame] | 299 | |
| 300 | /* Tell the guest about our interrupt status */ |
Scott Wood | 29ac26e | 2011-11-08 18:23:27 -0600 | [diff] [blame] | 301 | vcpu->arch.shared->int_pending = !!*pending; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 302 | } |
| 303 | |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 304 | /* Check pending exceptions and deliver one, if possible. */ |
| 305 | void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu) |
| 306 | { |
| 307 | WARN_ON_ONCE(!irqs_disabled()); |
| 308 | |
| 309 | kvmppc_core_check_exceptions(vcpu); |
| 310 | |
| 311 | if (vcpu->arch.shared->msr & MSR_WE) { |
| 312 | local_irq_enable(); |
| 313 | kvm_vcpu_block(vcpu); |
| 314 | local_irq_disable(); |
| 315 | |
| 316 | kvmppc_set_exit_type(vcpu, EMULATED_MTMSRWE_EXITS); |
| 317 | kvmppc_core_check_exceptions(vcpu); |
| 318 | }; |
| 319 | } |
| 320 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 321 | int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) |
| 322 | { |
| 323 | int ret; |
| 324 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 325 | if (!vcpu->arch.sane) { |
| 326 | kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR; |
| 327 | return -EINVAL; |
| 328 | } |
| 329 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 330 | local_irq_disable(); |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 331 | |
Scott Wood | 25051b5 | 2011-11-08 18:23:23 -0600 | [diff] [blame] | 332 | kvmppc_core_prepare_to_enter(vcpu); |
| 333 | |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 334 | if (signal_pending(current)) { |
| 335 | kvm_run->exit_reason = KVM_EXIT_INTR; |
| 336 | ret = -EINTR; |
| 337 | goto out; |
| 338 | } |
| 339 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 340 | kvm_guest_enter(); |
| 341 | ret = __kvmppc_vcpu_run(kvm_run, vcpu); |
| 342 | kvm_guest_exit(); |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 343 | |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 344 | out: |
| 345 | local_irq_enable(); |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 346 | return ret; |
| 347 | } |
| 348 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 349 | /** |
| 350 | * kvmppc_handle_exit |
| 351 | * |
| 352 | * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV) |
| 353 | */ |
| 354 | int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 355 | unsigned int exit_nr) |
| 356 | { |
| 357 | enum emulation_result er; |
| 358 | int r = RESUME_HOST; |
| 359 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 360 | /* update before a new last_exit_type is rewritten */ |
| 361 | kvmppc_update_timing_stats(vcpu); |
| 362 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 363 | local_irq_enable(); |
| 364 | |
| 365 | run->exit_reason = KVM_EXIT_UNKNOWN; |
| 366 | run->ready_for_interrupt_injection = 1; |
| 367 | |
| 368 | switch (exit_nr) { |
| 369 | case BOOKE_INTERRUPT_MACHINE_CHECK: |
| 370 | printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR)); |
| 371 | kvmppc_dump_vcpu(vcpu); |
| 372 | r = RESUME_HOST; |
| 373 | break; |
| 374 | |
| 375 | case BOOKE_INTERRUPT_EXTERNAL: |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 376 | kvmppc_account_exit(vcpu, EXT_INTR_EXITS); |
Hollis Blanchard | 1b6766c | 2008-11-05 09:36:21 -0600 | [diff] [blame] | 377 | if (need_resched()) |
| 378 | cond_resched(); |
| 379 | r = RESUME_GUEST; |
| 380 | break; |
| 381 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 382 | case BOOKE_INTERRUPT_DECREMENTER: |
| 383 | /* Since we switched IVPR back to the host's value, the host |
| 384 | * handled this interrupt the moment we enabled interrupts. |
| 385 | * Now we just offer it a chance to reschedule the guest. */ |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 386 | kvmppc_account_exit(vcpu, DEC_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 387 | if (need_resched()) |
| 388 | cond_resched(); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 389 | r = RESUME_GUEST; |
| 390 | break; |
| 391 | |
| 392 | case BOOKE_INTERRUPT_PROGRAM: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 393 | if (vcpu->arch.shared->msr & MSR_PR) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 394 | /* Program traps generated by user-level software must be handled |
| 395 | * by the guest kernel. */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 396 | kvmppc_core_queue_program(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 397 | r = RESUME_GUEST; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 398 | kvmppc_account_exit(vcpu, USR_PR_INST); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 399 | break; |
| 400 | } |
| 401 | |
| 402 | er = kvmppc_emulate_instruction(run, vcpu); |
| 403 | switch (er) { |
| 404 | case EMULATE_DONE: |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 405 | /* don't overwrite subtypes, just account kvm_stats */ |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 406 | kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 407 | /* Future optimization: only reload non-volatiles if |
| 408 | * they were actually modified by emulation. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 409 | r = RESUME_GUEST_NV; |
| 410 | break; |
| 411 | case EMULATE_DO_DCR: |
| 412 | run->exit_reason = KVM_EXIT_DCR; |
| 413 | r = RESUME_HOST; |
| 414 | break; |
| 415 | case EMULATE_FAIL: |
| 416 | /* XXX Deliver Program interrupt to guest. */ |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 417 | printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n", |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 418 | __func__, vcpu->arch.pc, vcpu->arch.last_inst); |
| 419 | /* For debugging, encode the failing instruction and |
| 420 | * report it to userspace. */ |
| 421 | run->hw.hardware_exit_reason = ~0ULL << 32; |
| 422 | run->hw.hardware_exit_reason |= vcpu->arch.last_inst; |
| 423 | r = RESUME_HOST; |
| 424 | break; |
| 425 | default: |
| 426 | BUG(); |
| 427 | } |
| 428 | break; |
| 429 | |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 430 | case BOOKE_INTERRUPT_FP_UNAVAIL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 431 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 432 | kvmppc_account_exit(vcpu, FP_UNAVAIL); |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 433 | r = RESUME_GUEST; |
| 434 | break; |
| 435 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 436 | #ifdef CONFIG_SPE |
| 437 | case BOOKE_INTERRUPT_SPE_UNAVAIL: { |
| 438 | if (vcpu->arch.shared->msr & MSR_SPE) |
| 439 | kvmppc_vcpu_enable_spe(vcpu); |
| 440 | else |
| 441 | kvmppc_booke_queue_irqprio(vcpu, |
| 442 | BOOKE_IRQPRIO_SPE_UNAVAIL); |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 443 | r = RESUME_GUEST; |
| 444 | break; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 445 | } |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 446 | |
| 447 | case BOOKE_INTERRUPT_SPE_FP_DATA: |
| 448 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA); |
| 449 | r = RESUME_GUEST; |
| 450 | break; |
| 451 | |
| 452 | case BOOKE_INTERRUPT_SPE_FP_ROUND: |
| 453 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND); |
| 454 | r = RESUME_GUEST; |
| 455 | break; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 456 | #else |
| 457 | case BOOKE_INTERRUPT_SPE_UNAVAIL: |
| 458 | /* |
| 459 | * Guest wants SPE, but host kernel doesn't support it. Send |
| 460 | * an "unimplemented operation" program check to the guest. |
| 461 | */ |
| 462 | kvmppc_core_queue_program(vcpu, ESR_PUO | ESR_SPV); |
| 463 | r = RESUME_GUEST; |
| 464 | break; |
| 465 | |
| 466 | /* |
| 467 | * These really should never happen without CONFIG_SPE, |
| 468 | * as we should never enable the real MSR[SPE] in the guest. |
| 469 | */ |
| 470 | case BOOKE_INTERRUPT_SPE_FP_DATA: |
| 471 | case BOOKE_INTERRUPT_SPE_FP_ROUND: |
| 472 | printk(KERN_CRIT "%s: unexpected SPE interrupt %u at %08lx\n", |
| 473 | __func__, exit_nr, vcpu->arch.pc); |
| 474 | run->hw.hardware_exit_reason = exit_nr; |
| 475 | r = RESUME_HOST; |
| 476 | break; |
| 477 | #endif |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 478 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 479 | case BOOKE_INTERRUPT_DATA_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 480 | kvmppc_core_queue_data_storage(vcpu, vcpu->arch.fault_dear, |
| 481 | vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 482 | kvmppc_account_exit(vcpu, DSI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 483 | r = RESUME_GUEST; |
| 484 | break; |
| 485 | |
| 486 | case BOOKE_INTERRUPT_INST_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 487 | kvmppc_core_queue_inst_storage(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 488 | kvmppc_account_exit(vcpu, ISI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 489 | r = RESUME_GUEST; |
| 490 | break; |
| 491 | |
| 492 | case BOOKE_INTERRUPT_SYSCALL: |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 493 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 494 | (((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) { |
| 495 | /* KVM PV hypercalls */ |
| 496 | kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); |
| 497 | r = RESUME_GUEST; |
| 498 | } else { |
| 499 | /* Guest syscalls */ |
| 500 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL); |
| 501 | } |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 502 | kvmppc_account_exit(vcpu, SYSCALL_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 503 | r = RESUME_GUEST; |
| 504 | break; |
| 505 | |
| 506 | case BOOKE_INTERRUPT_DTLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 507 | unsigned long eaddr = vcpu->arch.fault_dear; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 508 | int gtlb_index; |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 509 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 510 | gfn_t gfn; |
| 511 | |
Scott Wood | a4cd8b2 | 2011-06-14 18:34:41 -0500 | [diff] [blame] | 512 | #ifdef CONFIG_KVM_E500 |
| 513 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 514 | (eaddr & PAGE_MASK) == vcpu->arch.magic_page_ea) { |
| 515 | kvmppc_map_magic(vcpu); |
| 516 | kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS); |
| 517 | r = RESUME_GUEST; |
| 518 | |
| 519 | break; |
| 520 | } |
| 521 | #endif |
| 522 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 523 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 524 | gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 525 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 526 | /* The guest didn't have a mapping for it. */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 527 | kvmppc_core_queue_dtlb_miss(vcpu, |
| 528 | vcpu->arch.fault_dear, |
| 529 | vcpu->arch.fault_esr); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 530 | kvmppc_mmu_dtlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 531 | kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 532 | r = RESUME_GUEST; |
| 533 | break; |
| 534 | } |
| 535 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 536 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 537 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 538 | |
| 539 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 540 | /* The guest TLB had a mapping, but the shadow TLB |
| 541 | * didn't, and it is RAM. This could be because: |
| 542 | * a) the entry is mapping the host kernel, or |
| 543 | * b) the guest used a large mapping which we're faking |
| 544 | * Either way, we need to satisfy the fault without |
| 545 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 546 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 547 | kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 548 | r = RESUME_GUEST; |
| 549 | } else { |
| 550 | /* Guest has mapped and accessed a page which is not |
| 551 | * actually RAM. */ |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 552 | vcpu->arch.paddr_accessed = gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 553 | r = kvmppc_emulate_mmio(run, vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 554 | kvmppc_account_exit(vcpu, MMIO_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | break; |
| 558 | } |
| 559 | |
| 560 | case BOOKE_INTERRUPT_ITLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 561 | unsigned long eaddr = vcpu->arch.pc; |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 562 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 563 | gfn_t gfn; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 564 | int gtlb_index; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 565 | |
| 566 | r = RESUME_GUEST; |
| 567 | |
| 568 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 569 | gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 570 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 571 | /* The guest didn't have a mapping for it. */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 572 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 573 | kvmppc_mmu_itlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 574 | kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 575 | break; |
| 576 | } |
| 577 | |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 578 | kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 579 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 580 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 581 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 582 | |
| 583 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 584 | /* The guest TLB had a mapping, but the shadow TLB |
| 585 | * didn't. This could be because: |
| 586 | * a) the entry is mapping the host kernel, or |
| 587 | * b) the guest used a large mapping which we're faking |
| 588 | * Either way, we need to satisfy the fault without |
| 589 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 590 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 591 | } else { |
| 592 | /* Guest mapped and leaped at non-RAM! */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 593 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | break; |
| 597 | } |
| 598 | |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 599 | case BOOKE_INTERRUPT_DEBUG: { |
| 600 | u32 dbsr; |
| 601 | |
| 602 | vcpu->arch.pc = mfspr(SPRN_CSRR0); |
| 603 | |
| 604 | /* clear IAC events in DBSR register */ |
| 605 | dbsr = mfspr(SPRN_DBSR); |
| 606 | dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4; |
| 607 | mtspr(SPRN_DBSR, dbsr); |
| 608 | |
| 609 | run->exit_reason = KVM_EXIT_DEBUG; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 610 | kvmppc_account_exit(vcpu, DEBUG_EXITS); |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 611 | r = RESUME_HOST; |
| 612 | break; |
| 613 | } |
| 614 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 615 | default: |
| 616 | printk(KERN_EMERG "exit_nr %d\n", exit_nr); |
| 617 | BUG(); |
| 618 | } |
| 619 | |
| 620 | local_irq_disable(); |
| 621 | |
Scott Wood | 7e28e60e | 2011-11-08 18:23:20 -0600 | [diff] [blame] | 622 | kvmppc_core_prepare_to_enter(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 623 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 624 | if (!(r & RESUME_HOST)) { |
| 625 | /* To avoid clobbering exit_reason, only check for signals if |
| 626 | * we aren't already exiting to userspace for some other |
| 627 | * reason. */ |
| 628 | if (signal_pending(current)) { |
| 629 | run->exit_reason = KVM_EXIT_INTR; |
| 630 | r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 631 | kvmppc_account_exit(vcpu, SIGNAL_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
| 635 | return r; |
| 636 | } |
| 637 | |
| 638 | /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */ |
| 639 | int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) |
| 640 | { |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 641 | int i; |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 642 | int r; |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 643 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 644 | vcpu->arch.pc = 0; |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 645 | vcpu->arch.shared->msr = 0; |
Scott Wood | ecee273 | 2011-06-14 18:34:29 -0500 | [diff] [blame] | 646 | vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS; |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 647 | kvmppc_set_gpr(vcpu, 1, (16<<20) - 8); /* -8 for the callee-save LR slot */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 648 | |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 649 | vcpu->arch.shadow_pid = 1; |
| 650 | |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 651 | /* Eye-catching numbers so we know if the guest takes an interrupt |
| 652 | * before it's programmed its own IVPR/IVORs. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 653 | vcpu->arch.ivpr = 0x55550000; |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 654 | for (i = 0; i < BOOKE_IRQPRIO_MAX; i++) |
| 655 | vcpu->arch.ivor[i] = 0x7700 | i * 4; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 656 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 657 | kvmppc_init_timing_stats(vcpu); |
| 658 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 659 | r = kvmppc_core_vcpu_setup(vcpu); |
| 660 | kvmppc_sanity_check(vcpu); |
| 661 | return r; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 665 | { |
| 666 | int i; |
| 667 | |
| 668 | regs->pc = vcpu->arch.pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 669 | regs->cr = kvmppc_get_cr(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 670 | regs->ctr = vcpu->arch.ctr; |
| 671 | regs->lr = vcpu->arch.lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 672 | regs->xer = kvmppc_get_xer(vcpu); |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 673 | regs->msr = vcpu->arch.shared->msr; |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 674 | regs->srr0 = vcpu->arch.shared->srr0; |
| 675 | regs->srr1 = vcpu->arch.shared->srr1; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 676 | regs->pid = vcpu->arch.pid; |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 677 | regs->sprg0 = vcpu->arch.shared->sprg0; |
| 678 | regs->sprg1 = vcpu->arch.shared->sprg1; |
| 679 | regs->sprg2 = vcpu->arch.shared->sprg2; |
| 680 | regs->sprg3 = vcpu->arch.shared->sprg3; |
Peter Tyser | bc9c193 | 2010-12-29 13:51:25 -0600 | [diff] [blame] | 681 | regs->sprg4 = vcpu->arch.sprg4; |
| 682 | regs->sprg5 = vcpu->arch.sprg5; |
| 683 | regs->sprg6 = vcpu->arch.sprg6; |
| 684 | regs->sprg7 = vcpu->arch.sprg7; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 685 | |
| 686 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 687 | regs->gpr[i] = kvmppc_get_gpr(vcpu, i); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 693 | { |
| 694 | int i; |
| 695 | |
| 696 | vcpu->arch.pc = regs->pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 697 | kvmppc_set_cr(vcpu, regs->cr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 698 | vcpu->arch.ctr = regs->ctr; |
| 699 | vcpu->arch.lr = regs->lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 700 | kvmppc_set_xer(vcpu, regs->xer); |
Hollis Blanchard | b8fd68a | 2008-11-05 09:36:20 -0600 | [diff] [blame] | 701 | kvmppc_set_msr(vcpu, regs->msr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 702 | vcpu->arch.shared->srr0 = regs->srr0; |
| 703 | vcpu->arch.shared->srr1 = regs->srr1; |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 704 | kvmppc_set_pid(vcpu, regs->pid); |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 705 | vcpu->arch.shared->sprg0 = regs->sprg0; |
| 706 | vcpu->arch.shared->sprg1 = regs->sprg1; |
| 707 | vcpu->arch.shared->sprg2 = regs->sprg2; |
| 708 | vcpu->arch.shared->sprg3 = regs->sprg3; |
Peter Tyser | bc9c193 | 2010-12-29 13:51:25 -0600 | [diff] [blame] | 709 | vcpu->arch.sprg4 = regs->sprg4; |
| 710 | vcpu->arch.sprg5 = regs->sprg5; |
| 711 | vcpu->arch.sprg6 = regs->sprg6; |
| 712 | vcpu->arch.sprg7 = regs->sprg7; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 713 | |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 714 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
| 715 | kvmppc_set_gpr(vcpu, i, regs->gpr[i]); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 716 | |
| 717 | return 0; |
| 718 | } |
| 719 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 720 | static void get_sregs_base(struct kvm_vcpu *vcpu, |
| 721 | struct kvm_sregs *sregs) |
| 722 | { |
| 723 | u64 tb = get_tb(); |
| 724 | |
| 725 | sregs->u.e.features |= KVM_SREGS_E_BASE; |
| 726 | |
| 727 | sregs->u.e.csrr0 = vcpu->arch.csrr0; |
| 728 | sregs->u.e.csrr1 = vcpu->arch.csrr1; |
| 729 | sregs->u.e.mcsr = vcpu->arch.mcsr; |
| 730 | sregs->u.e.esr = vcpu->arch.esr; |
| 731 | sregs->u.e.dear = vcpu->arch.shared->dar; |
| 732 | sregs->u.e.tsr = vcpu->arch.tsr; |
| 733 | sregs->u.e.tcr = vcpu->arch.tcr; |
| 734 | sregs->u.e.dec = kvmppc_get_dec(vcpu, tb); |
| 735 | sregs->u.e.tb = tb; |
| 736 | sregs->u.e.vrsave = vcpu->arch.vrsave; |
| 737 | } |
| 738 | |
| 739 | static int set_sregs_base(struct kvm_vcpu *vcpu, |
| 740 | struct kvm_sregs *sregs) |
| 741 | { |
| 742 | if (!(sregs->u.e.features & KVM_SREGS_E_BASE)) |
| 743 | return 0; |
| 744 | |
| 745 | vcpu->arch.csrr0 = sregs->u.e.csrr0; |
| 746 | vcpu->arch.csrr1 = sregs->u.e.csrr1; |
| 747 | vcpu->arch.mcsr = sregs->u.e.mcsr; |
| 748 | vcpu->arch.esr = sregs->u.e.esr; |
| 749 | vcpu->arch.shared->dar = sregs->u.e.dear; |
| 750 | vcpu->arch.vrsave = sregs->u.e.vrsave; |
| 751 | vcpu->arch.tcr = sregs->u.e.tcr; |
| 752 | |
| 753 | if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_DEC) |
| 754 | vcpu->arch.dec = sregs->u.e.dec; |
| 755 | |
| 756 | kvmppc_emulate_dec(vcpu); |
| 757 | |
| 758 | if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_TSR) { |
| 759 | /* |
| 760 | * FIXME: existing KVM timer handling is incomplete. |
| 761 | * TSR cannot be read by the guest, and its value in |
| 762 | * vcpu->arch is always zero. For now, just handle |
| 763 | * the case where the caller is trying to inject a |
| 764 | * decrementer interrupt. |
| 765 | */ |
| 766 | |
| 767 | if ((sregs->u.e.tsr & TSR_DIS) && |
| 768 | (vcpu->arch.tcr & TCR_DIE)) |
| 769 | kvmppc_core_queue_dec(vcpu); |
| 770 | } |
| 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | static void get_sregs_arch206(struct kvm_vcpu *vcpu, |
| 776 | struct kvm_sregs *sregs) |
| 777 | { |
| 778 | sregs->u.e.features |= KVM_SREGS_E_ARCH206; |
| 779 | |
Scott Wood | 841741f | 2011-09-02 17:39:37 -0500 | [diff] [blame] | 780 | sregs->u.e.pir = vcpu->vcpu_id; |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 781 | sregs->u.e.mcsrr0 = vcpu->arch.mcsrr0; |
| 782 | sregs->u.e.mcsrr1 = vcpu->arch.mcsrr1; |
| 783 | sregs->u.e.decar = vcpu->arch.decar; |
| 784 | sregs->u.e.ivpr = vcpu->arch.ivpr; |
| 785 | } |
| 786 | |
| 787 | static int set_sregs_arch206(struct kvm_vcpu *vcpu, |
| 788 | struct kvm_sregs *sregs) |
| 789 | { |
| 790 | if (!(sregs->u.e.features & KVM_SREGS_E_ARCH206)) |
| 791 | return 0; |
| 792 | |
Scott Wood | 841741f | 2011-09-02 17:39:37 -0500 | [diff] [blame] | 793 | if (sregs->u.e.pir != vcpu->vcpu_id) |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 794 | return -EINVAL; |
| 795 | |
| 796 | vcpu->arch.mcsrr0 = sregs->u.e.mcsrr0; |
| 797 | vcpu->arch.mcsrr1 = sregs->u.e.mcsrr1; |
| 798 | vcpu->arch.decar = sregs->u.e.decar; |
| 799 | vcpu->arch.ivpr = sregs->u.e.ivpr; |
| 800 | |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) |
| 805 | { |
| 806 | sregs->u.e.features |= KVM_SREGS_E_IVOR; |
| 807 | |
| 808 | sregs->u.e.ivor_low[0] = vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL]; |
| 809 | sregs->u.e.ivor_low[1] = vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK]; |
| 810 | sregs->u.e.ivor_low[2] = vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE]; |
| 811 | sregs->u.e.ivor_low[3] = vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE]; |
| 812 | sregs->u.e.ivor_low[4] = vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL]; |
| 813 | sregs->u.e.ivor_low[5] = vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT]; |
| 814 | sregs->u.e.ivor_low[6] = vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM]; |
| 815 | sregs->u.e.ivor_low[7] = vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL]; |
| 816 | sregs->u.e.ivor_low[8] = vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL]; |
| 817 | sregs->u.e.ivor_low[9] = vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL]; |
| 818 | sregs->u.e.ivor_low[10] = vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER]; |
| 819 | sregs->u.e.ivor_low[11] = vcpu->arch.ivor[BOOKE_IRQPRIO_FIT]; |
| 820 | sregs->u.e.ivor_low[12] = vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG]; |
| 821 | sregs->u.e.ivor_low[13] = vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS]; |
| 822 | sregs->u.e.ivor_low[14] = vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS]; |
| 823 | sregs->u.e.ivor_low[15] = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG]; |
| 824 | } |
| 825 | |
| 826 | int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) |
| 827 | { |
| 828 | if (!(sregs->u.e.features & KVM_SREGS_E_IVOR)) |
| 829 | return 0; |
| 830 | |
| 831 | vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL] = sregs->u.e.ivor_low[0]; |
| 832 | vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK] = sregs->u.e.ivor_low[1]; |
| 833 | vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE] = sregs->u.e.ivor_low[2]; |
| 834 | vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE] = sregs->u.e.ivor_low[3]; |
| 835 | vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL] = sregs->u.e.ivor_low[4]; |
| 836 | vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT] = sregs->u.e.ivor_low[5]; |
| 837 | vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM] = sregs->u.e.ivor_low[6]; |
| 838 | vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL] = sregs->u.e.ivor_low[7]; |
| 839 | vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL] = sregs->u.e.ivor_low[8]; |
| 840 | vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL] = sregs->u.e.ivor_low[9]; |
| 841 | vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER] = sregs->u.e.ivor_low[10]; |
| 842 | vcpu->arch.ivor[BOOKE_IRQPRIO_FIT] = sregs->u.e.ivor_low[11]; |
| 843 | vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG] = sregs->u.e.ivor_low[12]; |
| 844 | vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS] = sregs->u.e.ivor_low[13]; |
| 845 | vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS] = sregs->u.e.ivor_low[14]; |
| 846 | vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG] = sregs->u.e.ivor_low[15]; |
| 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 851 | int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, |
| 852 | struct kvm_sregs *sregs) |
| 853 | { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 854 | sregs->pvr = vcpu->arch.pvr; |
| 855 | |
| 856 | get_sregs_base(vcpu, sregs); |
| 857 | get_sregs_arch206(vcpu, sregs); |
| 858 | kvmppc_core_get_sregs(vcpu, sregs); |
| 859 | return 0; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, |
| 863 | struct kvm_sregs *sregs) |
| 864 | { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 865 | int ret; |
| 866 | |
| 867 | if (vcpu->arch.pvr != sregs->pvr) |
| 868 | return -EINVAL; |
| 869 | |
| 870 | ret = set_sregs_base(vcpu, sregs); |
| 871 | if (ret < 0) |
| 872 | return ret; |
| 873 | |
| 874 | ret = set_sregs_arch206(vcpu, sregs); |
| 875 | if (ret < 0) |
| 876 | return ret; |
| 877 | |
| 878 | return kvmppc_core_set_sregs(vcpu, sregs); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 882 | { |
| 883 | return -ENOTSUPP; |
| 884 | } |
| 885 | |
| 886 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 887 | { |
| 888 | return -ENOTSUPP; |
| 889 | } |
| 890 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 891 | int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, |
| 892 | struct kvm_translation *tr) |
| 893 | { |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 894 | int r; |
| 895 | |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 896 | r = kvmppc_core_vcpu_translate(vcpu, tr); |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 897 | return r; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 898 | } |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 899 | |
Alexander Graf | 4e75575 | 2009-10-30 05:47:01 +0000 | [diff] [blame] | 900 | int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) |
| 901 | { |
| 902 | return -ENOTSUPP; |
| 903 | } |
| 904 | |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 905 | int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
| 906 | struct kvm_userspace_memory_region *mem) |
| 907 | { |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | void kvmppc_core_commit_memory_region(struct kvm *kvm, |
| 912 | struct kvm_userspace_memory_region *mem) |
| 913 | { |
| 914 | } |
| 915 | |
| 916 | int kvmppc_core_init_vm(struct kvm *kvm) |
| 917 | { |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | void kvmppc_core_destroy_vm(struct kvm *kvm) |
| 922 | { |
| 923 | } |
| 924 | |
Stephen Rothwell | 2986b8c | 2009-06-02 11:46:14 +1000 | [diff] [blame] | 925 | int __init kvmppc_booke_init(void) |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 926 | { |
| 927 | unsigned long ivor[16]; |
| 928 | unsigned long max_ivor = 0; |
| 929 | int i; |
| 930 | |
| 931 | /* We install our own exception handlers by hijacking IVPR. IVPR must |
| 932 | * be 16-bit aligned, so we need a 64KB allocation. */ |
| 933 | kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO, |
| 934 | VCPU_SIZE_ORDER); |
| 935 | if (!kvmppc_booke_handlers) |
| 936 | return -ENOMEM; |
| 937 | |
| 938 | /* XXX make sure our handlers are smaller than Linux's */ |
| 939 | |
| 940 | /* Copy our interrupt handlers to match host IVORs. That way we don't |
| 941 | * have to swap the IVORs on every guest/host transition. */ |
| 942 | ivor[0] = mfspr(SPRN_IVOR0); |
| 943 | ivor[1] = mfspr(SPRN_IVOR1); |
| 944 | ivor[2] = mfspr(SPRN_IVOR2); |
| 945 | ivor[3] = mfspr(SPRN_IVOR3); |
| 946 | ivor[4] = mfspr(SPRN_IVOR4); |
| 947 | ivor[5] = mfspr(SPRN_IVOR5); |
| 948 | ivor[6] = mfspr(SPRN_IVOR6); |
| 949 | ivor[7] = mfspr(SPRN_IVOR7); |
| 950 | ivor[8] = mfspr(SPRN_IVOR8); |
| 951 | ivor[9] = mfspr(SPRN_IVOR9); |
| 952 | ivor[10] = mfspr(SPRN_IVOR10); |
| 953 | ivor[11] = mfspr(SPRN_IVOR11); |
| 954 | ivor[12] = mfspr(SPRN_IVOR12); |
| 955 | ivor[13] = mfspr(SPRN_IVOR13); |
| 956 | ivor[14] = mfspr(SPRN_IVOR14); |
| 957 | ivor[15] = mfspr(SPRN_IVOR15); |
| 958 | |
| 959 | for (i = 0; i < 16; i++) { |
| 960 | if (ivor[i] > max_ivor) |
| 961 | max_ivor = ivor[i]; |
| 962 | |
| 963 | memcpy((void *)kvmppc_booke_handlers + ivor[i], |
| 964 | kvmppc_handlers_start + i * kvmppc_handler_len, |
| 965 | kvmppc_handler_len); |
| 966 | } |
| 967 | flush_icache_range(kvmppc_booke_handlers, |
| 968 | kvmppc_booke_handlers + max_ivor + kvmppc_handler_len); |
| 969 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 970 | return 0; |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 971 | } |
| 972 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 973 | void __exit kvmppc_booke_exit(void) |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 974 | { |
| 975 | free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER); |
| 976 | kvm_exit(); |
| 977 | } |