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