Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License, version 2, as |
| 4 | * published by the Free Software Foundation. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9 | * GNU General Public License for more details. |
| 10 | * |
| 11 | * You should have received a copy of the GNU General Public License |
| 12 | * along with this program; if not, write to the Free Software |
| 13 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 14 | * |
| 15 | * Copyright IBM Corp. 2007 |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 16 | * Copyright 2010-2011 Freescale Semiconductor, Inc. |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 17 | * |
| 18 | * Authors: Hollis Blanchard <hollisb@us.ibm.com> |
| 19 | * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com> |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 20 | * Scott Wood <scottwood@freescale.com> |
| 21 | * Varun Sethi <varun.sethi@freescale.com> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/err.h> |
| 26 | #include <linux/kvm_host.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/gfp.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/vmalloc.h> |
| 30 | #include <linux/fs.h> |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 31 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 32 | #include <asm/cputable.h> |
| 33 | #include <asm/uaccess.h> |
| 34 | #include <asm/kvm_ppc.h> |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 35 | #include <asm/cacheflush.h> |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 36 | #include <asm/dbell.h> |
| 37 | #include <asm/hw_irq.h> |
| 38 | #include <asm/irq.h> |
Mihai Caraman | b50df19 | 2012-10-11 06:13:19 +0000 | [diff] [blame] | 39 | #include <asm/time.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 40 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 41 | #include "timing.h" |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 42 | #include "booke.h" |
Aneesh Kumar K.V | dba291f | 2013-10-07 22:17:58 +0530 | [diff] [blame] | 43 | |
| 44 | #define CREATE_TRACE_POINTS |
| 45 | #include "trace_booke.h" |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 46 | |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 47 | unsigned long kvmppc_booke_handlers; |
| 48 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 49 | #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM |
| 50 | #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU |
| 51 | |
| 52 | struct kvm_stats_debugfs_item debugfs_entries[] = { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 53 | { "mmio", VCPU_STAT(mmio_exits) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 54 | { "sig", VCPU_STAT(signal_exits) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 55 | { "itlb_r", VCPU_STAT(itlb_real_miss_exits) }, |
| 56 | { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) }, |
| 57 | { "dtlb_r", VCPU_STAT(dtlb_real_miss_exits) }, |
| 58 | { "dtlb_v", VCPU_STAT(dtlb_virt_miss_exits) }, |
| 59 | { "sysc", VCPU_STAT(syscall_exits) }, |
| 60 | { "isi", VCPU_STAT(isi_exits) }, |
| 61 | { "dsi", VCPU_STAT(dsi_exits) }, |
| 62 | { "inst_emu", VCPU_STAT(emulated_inst_exits) }, |
| 63 | { "dec", VCPU_STAT(dec_exits) }, |
| 64 | { "ext_intr", VCPU_STAT(ext_intr_exits) }, |
Hollis Blanchard | 45c5eb6 | 2008-04-25 17:55:49 -0500 | [diff] [blame] | 65 | { "halt_wakeup", VCPU_STAT(halt_wakeup) }, |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 66 | { "doorbell", VCPU_STAT(dbell_exits) }, |
| 67 | { "guest doorbell", VCPU_STAT(gdbell_exits) }, |
Alexander Graf | cf1c5ca | 2012-08-01 12:56:51 +0200 | [diff] [blame] | 68 | { "remote_tlb_flush", VM_STAT(remote_tlb_flush) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 69 | { NULL } |
| 70 | }; |
| 71 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 72 | /* TODO: use vcpu_printf() */ |
| 73 | void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu) |
| 74 | { |
| 75 | int i; |
| 76 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 77 | 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] | 78 | printk("lr: %08lx ctr: %08lx\n", vcpu->arch.lr, vcpu->arch.ctr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 79 | printk("srr0: %08llx srr1: %08llx\n", vcpu->arch.shared->srr0, |
| 80 | vcpu->arch.shared->srr1); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 81 | |
| 82 | printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions); |
| 83 | |
| 84 | for (i = 0; i < 32; i += 4) { |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 85 | printk("gpr%02d: %08lx %08lx %08lx %08lx\n", i, |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 86 | kvmppc_get_gpr(vcpu, i), |
| 87 | kvmppc_get_gpr(vcpu, i+1), |
| 88 | kvmppc_get_gpr(vcpu, i+2), |
| 89 | kvmppc_get_gpr(vcpu, i+3)); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 93 | #ifdef CONFIG_SPE |
| 94 | void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu) |
| 95 | { |
| 96 | preempt_disable(); |
| 97 | enable_kernel_spe(); |
| 98 | kvmppc_save_guest_spe(vcpu); |
| 99 | vcpu->arch.shadow_msr &= ~MSR_SPE; |
| 100 | preempt_enable(); |
| 101 | } |
| 102 | |
| 103 | static void kvmppc_vcpu_enable_spe(struct kvm_vcpu *vcpu) |
| 104 | { |
| 105 | preempt_disable(); |
| 106 | enable_kernel_spe(); |
| 107 | kvmppc_load_guest_spe(vcpu); |
| 108 | vcpu->arch.shadow_msr |= MSR_SPE; |
| 109 | preempt_enable(); |
| 110 | } |
| 111 | |
| 112 | static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu) |
| 113 | { |
| 114 | if (vcpu->arch.shared->msr & MSR_SPE) { |
| 115 | if (!(vcpu->arch.shadow_msr & MSR_SPE)) |
| 116 | kvmppc_vcpu_enable_spe(vcpu); |
| 117 | } else if (vcpu->arch.shadow_msr & MSR_SPE) { |
| 118 | kvmppc_vcpu_disable_spe(vcpu); |
| 119 | } |
| 120 | } |
| 121 | #else |
| 122 | static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu) |
| 123 | { |
| 124 | } |
| 125 | #endif |
| 126 | |
Mihai Caraman | 3efc7da | 2014-08-20 16:36:22 +0300 | [diff] [blame] | 127 | /* |
| 128 | * Load up guest vcpu FP state if it's needed. |
| 129 | * It also set the MSR_FP in thread so that host know |
| 130 | * we're holding FPU, and then host can help to save |
| 131 | * guest vcpu FP state if other threads require to use FPU. |
| 132 | * This simulates an FP unavailable fault. |
| 133 | * |
| 134 | * It requires to be called with preemption disabled. |
| 135 | */ |
| 136 | static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu) |
| 137 | { |
| 138 | #ifdef CONFIG_PPC_FPU |
| 139 | if (!(current->thread.regs->msr & MSR_FP)) { |
| 140 | enable_kernel_fp(); |
| 141 | load_fp_state(&vcpu->arch.fp); |
| 142 | current->thread.fp_save_area = &vcpu->arch.fp; |
| 143 | current->thread.regs->msr |= MSR_FP; |
| 144 | } |
| 145 | #endif |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Save guest vcpu FP state into thread. |
| 150 | * It requires to be called with preemption disabled. |
| 151 | */ |
| 152 | static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu) |
| 153 | { |
| 154 | #ifdef CONFIG_PPC_FPU |
| 155 | if (current->thread.regs->msr & MSR_FP) |
| 156 | giveup_fpu(current); |
| 157 | current->thread.fp_save_area = NULL; |
| 158 | #endif |
| 159 | } |
| 160 | |
Alexander Graf | 7a08c27 | 2012-08-16 13:10:16 +0200 | [diff] [blame] | 161 | static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu) |
| 162 | { |
| 163 | #if defined(CONFIG_PPC_FPU) && !defined(CONFIG_KVM_BOOKE_HV) |
| 164 | /* We always treat the FP bit as enabled from the host |
| 165 | perspective, so only need to adjust the shadow MSR */ |
| 166 | vcpu->arch.shadow_msr &= ~MSR_FP; |
| 167 | vcpu->arch.shadow_msr |= vcpu->arch.shared->msr & MSR_FP; |
| 168 | #endif |
| 169 | } |
| 170 | |
Mihai Caraman | 95d80a2 | 2014-08-20 16:36:23 +0300 | [diff] [blame] | 171 | /* |
| 172 | * Simulate AltiVec unavailable fault to load guest state |
| 173 | * from thread to AltiVec unit. |
| 174 | * It requires to be called with preemption disabled. |
| 175 | */ |
| 176 | static inline void kvmppc_load_guest_altivec(struct kvm_vcpu *vcpu) |
| 177 | { |
| 178 | #ifdef CONFIG_ALTIVEC |
| 179 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) { |
| 180 | if (!(current->thread.regs->msr & MSR_VEC)) { |
| 181 | enable_kernel_altivec(); |
| 182 | load_vr_state(&vcpu->arch.vr); |
| 183 | current->thread.vr_save_area = &vcpu->arch.vr; |
| 184 | current->thread.regs->msr |= MSR_VEC; |
| 185 | } |
| 186 | } |
| 187 | #endif |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Save guest vcpu AltiVec state into thread. |
| 192 | * It requires to be called with preemption disabled. |
| 193 | */ |
| 194 | static inline void kvmppc_save_guest_altivec(struct kvm_vcpu *vcpu) |
| 195 | { |
| 196 | #ifdef CONFIG_ALTIVEC |
| 197 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) { |
| 198 | if (current->thread.regs->msr & MSR_VEC) |
| 199 | giveup_altivec(current); |
| 200 | current->thread.vr_save_area = NULL; |
| 201 | } |
| 202 | #endif |
| 203 | } |
| 204 | |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 205 | static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu) |
| 206 | { |
| 207 | /* Synchronize guest's desire to get debug interrupts into shadow MSR */ |
| 208 | #ifndef CONFIG_KVM_BOOKE_HV |
| 209 | vcpu->arch.shadow_msr &= ~MSR_DE; |
| 210 | vcpu->arch.shadow_msr |= vcpu->arch.shared->msr & MSR_DE; |
| 211 | #endif |
| 212 | |
| 213 | /* Force enable debug interrupts when user space wants to debug */ |
| 214 | if (vcpu->guest_debug) { |
| 215 | #ifdef CONFIG_KVM_BOOKE_HV |
| 216 | /* |
| 217 | * Since there is no shadow MSR, sync MSR_DE into the guest |
| 218 | * visible MSR. |
| 219 | */ |
| 220 | vcpu->arch.shared->msr |= MSR_DE; |
| 221 | #else |
| 222 | vcpu->arch.shadow_msr |= MSR_DE; |
| 223 | vcpu->arch.shared->msr &= ~MSR_DE; |
| 224 | #endif |
| 225 | } |
| 226 | } |
| 227 | |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 228 | /* |
| 229 | * Helper function for "full" MSR writes. No need to call this if only |
| 230 | * EE/CE/ME/DE/RI are changing. |
| 231 | */ |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 232 | void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr) |
| 233 | { |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 234 | u32 old_msr = vcpu->arch.shared->msr; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 235 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 236 | #ifdef CONFIG_KVM_BOOKE_HV |
| 237 | new_msr |= MSR_GS; |
| 238 | #endif |
| 239 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 240 | vcpu->arch.shared->msr = new_msr; |
| 241 | |
Liu Yu | dd9ebf1f | 2011-06-14 18:35:14 -0500 | [diff] [blame] | 242 | kvmppc_mmu_msr_notify(vcpu, old_msr); |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 243 | kvmppc_vcpu_sync_spe(vcpu); |
Alexander Graf | 7a08c27 | 2012-08-16 13:10:16 +0200 | [diff] [blame] | 244 | kvmppc_vcpu_sync_fpu(vcpu); |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 245 | kvmppc_vcpu_sync_debug(vcpu); |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 246 | } |
| 247 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 248 | static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, |
| 249 | unsigned int priority) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 250 | { |
Alexander Graf | 6346046 | 2012-08-08 00:44:52 +0200 | [diff] [blame] | 251 | trace_kvm_booke_queue_irqprio(vcpu, priority); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 252 | set_bit(priority, &vcpu->arch.pending_exceptions); |
| 253 | } |
| 254 | |
Alexander Graf | 8de1201 | 2014-06-18 21:56:55 +0200 | [diff] [blame] | 255 | void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, |
| 256 | ulong dear_flags, ulong esr_flags) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 257 | { |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 258 | vcpu->arch.queued_dear = dear_flags; |
| 259 | vcpu->arch.queued_esr = esr_flags; |
| 260 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS); |
| 261 | } |
| 262 | |
Alexander Graf | 8de1201 | 2014-06-18 21:56:55 +0200 | [diff] [blame] | 263 | void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, |
| 264 | ulong dear_flags, ulong esr_flags) |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 265 | { |
| 266 | vcpu->arch.queued_dear = dear_flags; |
| 267 | vcpu->arch.queued_esr = esr_flags; |
| 268 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE); |
| 269 | } |
| 270 | |
Alexander Graf | 8de1201 | 2014-06-18 21:56:55 +0200 | [diff] [blame] | 271 | void kvmppc_core_queue_itlb_miss(struct kvm_vcpu *vcpu) |
| 272 | { |
| 273 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS); |
| 274 | } |
| 275 | |
| 276 | void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, ulong esr_flags) |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 277 | { |
| 278 | vcpu->arch.queued_esr = esr_flags; |
| 279 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE); |
| 280 | } |
| 281 | |
Alexander Graf | 011da89 | 2013-01-31 14:17:38 +0100 | [diff] [blame] | 282 | static void kvmppc_core_queue_alignment(struct kvm_vcpu *vcpu, ulong dear_flags, |
| 283 | ulong esr_flags) |
| 284 | { |
| 285 | vcpu->arch.queued_dear = dear_flags; |
| 286 | vcpu->arch.queued_esr = esr_flags; |
| 287 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ALIGNMENT); |
| 288 | } |
| 289 | |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 290 | void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags) |
| 291 | { |
| 292 | vcpu->arch.queued_esr = esr_flags; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 293 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu) |
| 297 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 298 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DECREMENTER); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu) |
| 302 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 303 | return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 304 | } |
| 305 | |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 306 | void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu) |
| 307 | { |
| 308 | clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
| 309 | } |
| 310 | |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 311 | void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 312 | struct kvm_interrupt *irq) |
| 313 | { |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 314 | unsigned int prio = BOOKE_IRQPRIO_EXTERNAL; |
| 315 | |
| 316 | if (irq->irq == KVM_INTERRUPT_SET_LEVEL) |
| 317 | prio = BOOKE_IRQPRIO_EXTERNAL_LEVEL; |
| 318 | |
| 319 | kvmppc_booke_queue_irqprio(vcpu, prio); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 320 | } |
| 321 | |
Paul Mackerras | 4fe27d2 | 2013-02-14 14:00:25 +0000 | [diff] [blame] | 322 | void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu) |
Alexander Graf | 4496f97 | 2010-04-07 10:03:25 +0200 | [diff] [blame] | 323 | { |
| 324 | clear_bit(BOOKE_IRQPRIO_EXTERNAL, &vcpu->arch.pending_exceptions); |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 325 | clear_bit(BOOKE_IRQPRIO_EXTERNAL_LEVEL, &vcpu->arch.pending_exceptions); |
Alexander Graf | 4496f97 | 2010-04-07 10:03:25 +0200 | [diff] [blame] | 326 | } |
| 327 | |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 328 | static void kvmppc_core_queue_watchdog(struct kvm_vcpu *vcpu) |
| 329 | { |
| 330 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_WATCHDOG); |
| 331 | } |
| 332 | |
| 333 | static void kvmppc_core_dequeue_watchdog(struct kvm_vcpu *vcpu) |
| 334 | { |
| 335 | clear_bit(BOOKE_IRQPRIO_WATCHDOG, &vcpu->arch.pending_exceptions); |
| 336 | } |
| 337 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 338 | static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 339 | { |
Bharat Bhushan | 31579ee | 2014-07-17 17:01:36 +0530 | [diff] [blame] | 340 | kvmppc_set_srr0(vcpu, srr0); |
| 341 | kvmppc_set_srr1(vcpu, srr1); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static void set_guest_csrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 345 | { |
| 346 | vcpu->arch.csrr0 = srr0; |
| 347 | vcpu->arch.csrr1 = srr1; |
| 348 | } |
| 349 | |
| 350 | static void set_guest_dsrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 351 | { |
| 352 | if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC)) { |
| 353 | vcpu->arch.dsrr0 = srr0; |
| 354 | vcpu->arch.dsrr1 = srr1; |
| 355 | } else { |
| 356 | set_guest_csrr(vcpu, srr0, srr1); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | static void set_guest_mcsrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) |
| 361 | { |
| 362 | vcpu->arch.mcsrr0 = srr0; |
| 363 | vcpu->arch.mcsrr1 = srr1; |
| 364 | } |
| 365 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 366 | /* Deliver the interrupt of the corresponding priority, if possible. */ |
| 367 | static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, |
| 368 | unsigned int priority) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 369 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 370 | int allowed = 0; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 371 | ulong msr_mask = 0; |
Alexander Graf | 1c81063 | 2013-01-04 18:12:48 +0100 | [diff] [blame] | 372 | bool update_esr = false, update_dear = false, update_epr = false; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 373 | ulong crit_raw = vcpu->arch.shared->critical; |
| 374 | ulong crit_r1 = kvmppc_get_gpr(vcpu, 1); |
| 375 | bool crit; |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 376 | bool keep_irq = false; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 377 | enum int_class int_class; |
Mihai Caraman | 95e90b4 | 2012-10-11 06:13:26 +0000 | [diff] [blame] | 378 | ulong new_msr = vcpu->arch.shared->msr; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 379 | |
| 380 | /* Truncate crit indicators in 32 bit mode */ |
| 381 | if (!(vcpu->arch.shared->msr & MSR_SF)) { |
| 382 | crit_raw &= 0xffffffff; |
| 383 | crit_r1 &= 0xffffffff; |
| 384 | } |
| 385 | |
| 386 | /* Critical section when crit == r1 */ |
| 387 | crit = (crit_raw == crit_r1); |
| 388 | /* ... and we're in supervisor mode */ |
| 389 | crit = crit && !(vcpu->arch.shared->msr & MSR_PR); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 390 | |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 391 | if (priority == BOOKE_IRQPRIO_EXTERNAL_LEVEL) { |
| 392 | priority = BOOKE_IRQPRIO_EXTERNAL; |
| 393 | keep_irq = true; |
| 394 | } |
| 395 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 396 | if ((priority == BOOKE_IRQPRIO_EXTERNAL) && vcpu->arch.epr_flags) |
Alexander Graf | 1c81063 | 2013-01-04 18:12:48 +0100 | [diff] [blame] | 397 | update_epr = true; |
| 398 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 399 | switch (priority) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 400 | case BOOKE_IRQPRIO_DTLB_MISS: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 401 | case BOOKE_IRQPRIO_DATA_STORAGE: |
Alexander Graf | 011da89 | 2013-01-31 14:17:38 +0100 | [diff] [blame] | 402 | case BOOKE_IRQPRIO_ALIGNMENT: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 403 | update_dear = true; |
| 404 | /* fall through */ |
| 405 | case BOOKE_IRQPRIO_INST_STORAGE: |
| 406 | case BOOKE_IRQPRIO_PROGRAM: |
| 407 | update_esr = true; |
| 408 | /* fall through */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 409 | case BOOKE_IRQPRIO_ITLB_MISS: |
| 410 | case BOOKE_IRQPRIO_SYSCALL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 411 | case BOOKE_IRQPRIO_FP_UNAVAIL: |
Mihai Caraman | 95d80a2 | 2014-08-20 16:36:23 +0300 | [diff] [blame] | 412 | #ifdef CONFIG_SPE_POSSIBLE |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 413 | case BOOKE_IRQPRIO_SPE_UNAVAIL: |
| 414 | case BOOKE_IRQPRIO_SPE_FP_DATA: |
| 415 | case BOOKE_IRQPRIO_SPE_FP_ROUND: |
Mihai Caraman | 95d80a2 | 2014-08-20 16:36:23 +0300 | [diff] [blame] | 416 | #endif |
| 417 | #ifdef CONFIG_ALTIVEC |
| 418 | case BOOKE_IRQPRIO_ALTIVEC_UNAVAIL: |
| 419 | case BOOKE_IRQPRIO_ALTIVEC_ASSIST: |
| 420 | #endif |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 421 | case BOOKE_IRQPRIO_AP_UNAVAIL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 422 | allowed = 1; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 423 | msr_mask = MSR_CE | MSR_ME | MSR_DE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 424 | int_class = INT_CLASS_NONCRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 425 | break; |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 426 | case BOOKE_IRQPRIO_WATCHDOG: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 427 | case BOOKE_IRQPRIO_CRITICAL: |
Alexander Graf | 4ab9691 | 2012-02-15 13:28:48 +0000 | [diff] [blame] | 428 | case BOOKE_IRQPRIO_DBELL_CRIT: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 429 | allowed = vcpu->arch.shared->msr & MSR_CE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 430 | allowed = allowed && !crit; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 431 | msr_mask = MSR_ME; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 432 | int_class = INT_CLASS_CRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 433 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 434 | case BOOKE_IRQPRIO_MACHINE_CHECK: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 435 | allowed = vcpu->arch.shared->msr & MSR_ME; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 436 | allowed = allowed && !crit; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 437 | int_class = INT_CLASS_MC; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 438 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 439 | case BOOKE_IRQPRIO_DECREMENTER: |
| 440 | case BOOKE_IRQPRIO_FIT: |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 441 | keep_irq = true; |
| 442 | /* fall through */ |
| 443 | case BOOKE_IRQPRIO_EXTERNAL: |
Alexander Graf | 4ab9691 | 2012-02-15 13:28:48 +0000 | [diff] [blame] | 444 | case BOOKE_IRQPRIO_DBELL: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 445 | allowed = vcpu->arch.shared->msr & MSR_EE; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 446 | allowed = allowed && !crit; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 447 | msr_mask = MSR_CE | MSR_ME | MSR_DE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 448 | int_class = INT_CLASS_NONCRIT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 449 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 450 | case BOOKE_IRQPRIO_DEBUG: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 451 | allowed = vcpu->arch.shared->msr & MSR_DE; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 452 | allowed = allowed && !crit; |
Alexander Graf | 79300f8 | 2012-02-15 19:12:29 +0000 | [diff] [blame] | 453 | msr_mask = MSR_ME; |
Bharat Bhushan | 9fee756 | 2014-08-06 12:08:51 +0530 | [diff] [blame] | 454 | if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC)) |
| 455 | int_class = INT_CLASS_DBG; |
| 456 | else |
| 457 | int_class = INT_CLASS_CRIT; |
| 458 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 459 | break; |
| 460 | } |
| 461 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 462 | if (allowed) { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 463 | switch (int_class) { |
| 464 | case INT_CLASS_NONCRIT: |
| 465 | set_guest_srr(vcpu, vcpu->arch.pc, |
| 466 | vcpu->arch.shared->msr); |
| 467 | break; |
| 468 | case INT_CLASS_CRIT: |
| 469 | set_guest_csrr(vcpu, vcpu->arch.pc, |
| 470 | vcpu->arch.shared->msr); |
| 471 | break; |
| 472 | case INT_CLASS_DBG: |
| 473 | set_guest_dsrr(vcpu, vcpu->arch.pc, |
| 474 | vcpu->arch.shared->msr); |
| 475 | break; |
| 476 | case INT_CLASS_MC: |
| 477 | set_guest_mcsrr(vcpu, vcpu->arch.pc, |
| 478 | vcpu->arch.shared->msr); |
| 479 | break; |
| 480 | } |
| 481 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 482 | vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority]; |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 483 | if (update_esr == true) |
Bharat Bhushan | dc16854 | 2014-07-17 17:01:38 +0530 | [diff] [blame] | 484 | kvmppc_set_esr(vcpu, vcpu->arch.queued_esr); |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 485 | if (update_dear == true) |
Bharat Bhushan | a5414d4 | 2014-07-17 17:01:37 +0530 | [diff] [blame] | 486 | kvmppc_set_dar(vcpu, vcpu->arch.queued_dear); |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 487 | if (update_epr == true) { |
| 488 | if (vcpu->arch.epr_flags & KVMPPC_EPR_USER) |
| 489 | kvm_make_request(KVM_REQ_EPR_EXIT, vcpu); |
Scott Wood | eb1e4f4 | 2013-04-12 14:08:47 +0000 | [diff] [blame] | 490 | else if (vcpu->arch.epr_flags & KVMPPC_EPR_KERNEL) { |
| 491 | BUG_ON(vcpu->arch.irq_type != KVMPPC_IRQ_MPIC); |
| 492 | kvmppc_mpic_set_epr(vcpu); |
| 493 | } |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 494 | } |
Mihai Caraman | 95e90b4 | 2012-10-11 06:13:26 +0000 | [diff] [blame] | 495 | |
| 496 | new_msr &= msr_mask; |
| 497 | #if defined(CONFIG_64BIT) |
| 498 | if (vcpu->arch.epcr & SPRN_EPCR_ICM) |
| 499 | new_msr |= MSR_CM; |
| 500 | #endif |
| 501 | kvmppc_set_msr(vcpu, new_msr); |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 502 | |
Alexander Graf | c5335f1 | 2010-08-30 14:03:24 +0200 | [diff] [blame] | 503 | if (!keep_irq) |
| 504 | clear_bit(priority, &vcpu->arch.pending_exceptions); |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 505 | } |
| 506 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 507 | #ifdef CONFIG_KVM_BOOKE_HV |
| 508 | /* |
| 509 | * If an interrupt is pending but masked, raise a guest doorbell |
| 510 | * so that we are notified when the guest enables the relevant |
| 511 | * MSR bit. |
| 512 | */ |
| 513 | if (vcpu->arch.pending_exceptions & BOOKE_IRQMASK_EE) |
| 514 | kvmppc_set_pending_interrupt(vcpu, INT_CLASS_NONCRIT); |
| 515 | if (vcpu->arch.pending_exceptions & BOOKE_IRQMASK_CE) |
| 516 | kvmppc_set_pending_interrupt(vcpu, INT_CLASS_CRIT); |
| 517 | if (vcpu->arch.pending_exceptions & BOOKE_IRQPRIO_MACHINE_CHECK) |
| 518 | kvmppc_set_pending_interrupt(vcpu, INT_CLASS_MC); |
| 519 | #endif |
| 520 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 521 | return allowed; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 522 | } |
| 523 | |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 524 | /* |
| 525 | * Return the number of jiffies until the next timeout. If the timeout is |
| 526 | * longer than the NEXT_TIMER_MAX_DELTA, then return NEXT_TIMER_MAX_DELTA |
| 527 | * because the larger value can break the timer APIs. |
| 528 | */ |
| 529 | static unsigned long watchdog_next_timeout(struct kvm_vcpu *vcpu) |
| 530 | { |
| 531 | u64 tb, wdt_tb, wdt_ticks = 0; |
| 532 | u64 nr_jiffies = 0; |
| 533 | u32 period = TCR_GET_WP(vcpu->arch.tcr); |
| 534 | |
| 535 | wdt_tb = 1ULL << (63 - period); |
| 536 | tb = get_tb(); |
| 537 | /* |
| 538 | * The watchdog timeout will hapeen when TB bit corresponding |
| 539 | * to watchdog will toggle from 0 to 1. |
| 540 | */ |
| 541 | if (tb & wdt_tb) |
| 542 | wdt_ticks = wdt_tb; |
| 543 | |
| 544 | wdt_ticks += wdt_tb - (tb & (wdt_tb - 1)); |
| 545 | |
| 546 | /* Convert timebase ticks to jiffies */ |
| 547 | nr_jiffies = wdt_ticks; |
| 548 | |
| 549 | if (do_div(nr_jiffies, tb_ticks_per_jiffy)) |
| 550 | nr_jiffies++; |
| 551 | |
| 552 | return min_t(unsigned long long, nr_jiffies, NEXT_TIMER_MAX_DELTA); |
| 553 | } |
| 554 | |
| 555 | static void arm_next_watchdog(struct kvm_vcpu *vcpu) |
| 556 | { |
| 557 | unsigned long nr_jiffies; |
| 558 | unsigned long flags; |
| 559 | |
| 560 | /* |
| 561 | * If TSR_ENW and TSR_WIS are not set then no need to exit to |
| 562 | * userspace, so clear the KVM_REQ_WATCHDOG request. |
| 563 | */ |
| 564 | if ((vcpu->arch.tsr & (TSR_ENW | TSR_WIS)) != (TSR_ENW | TSR_WIS)) |
| 565 | clear_bit(KVM_REQ_WATCHDOG, &vcpu->requests); |
| 566 | |
| 567 | spin_lock_irqsave(&vcpu->arch.wdt_lock, flags); |
| 568 | nr_jiffies = watchdog_next_timeout(vcpu); |
| 569 | /* |
| 570 | * If the number of jiffies of watchdog timer >= NEXT_TIMER_MAX_DELTA |
| 571 | * then do not run the watchdog timer as this can break timer APIs. |
| 572 | */ |
| 573 | if (nr_jiffies < NEXT_TIMER_MAX_DELTA) |
| 574 | mod_timer(&vcpu->arch.wdt_timer, jiffies + nr_jiffies); |
| 575 | else |
| 576 | del_timer(&vcpu->arch.wdt_timer); |
| 577 | spin_unlock_irqrestore(&vcpu->arch.wdt_lock, flags); |
| 578 | } |
| 579 | |
| 580 | void kvmppc_watchdog_func(unsigned long data) |
| 581 | { |
| 582 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; |
| 583 | u32 tsr, new_tsr; |
| 584 | int final; |
| 585 | |
| 586 | do { |
| 587 | new_tsr = tsr = vcpu->arch.tsr; |
| 588 | final = 0; |
| 589 | |
| 590 | /* Time out event */ |
| 591 | if (tsr & TSR_ENW) { |
| 592 | if (tsr & TSR_WIS) |
| 593 | final = 1; |
| 594 | else |
| 595 | new_tsr = tsr | TSR_WIS; |
| 596 | } else { |
| 597 | new_tsr = tsr | TSR_ENW; |
| 598 | } |
| 599 | } while (cmpxchg(&vcpu->arch.tsr, tsr, new_tsr) != tsr); |
| 600 | |
| 601 | if (new_tsr & TSR_WIS) { |
| 602 | smp_wmb(); |
| 603 | kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu); |
| 604 | kvm_vcpu_kick(vcpu); |
| 605 | } |
| 606 | |
| 607 | /* |
| 608 | * If this is final watchdog expiry and some action is required |
| 609 | * then exit to userspace. |
| 610 | */ |
| 611 | if (final && (vcpu->arch.tcr & TCR_WRC_MASK) && |
| 612 | vcpu->arch.watchdog_enabled) { |
| 613 | smp_wmb(); |
| 614 | kvm_make_request(KVM_REQ_WATCHDOG, vcpu); |
| 615 | kvm_vcpu_kick(vcpu); |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * Stop running the watchdog timer after final expiration to |
| 620 | * prevent the host from being flooded with timers if the |
| 621 | * guest sets a short period. |
| 622 | * Timers will resume when TSR/TCR is updated next time. |
| 623 | */ |
| 624 | if (!final) |
| 625 | arm_next_watchdog(vcpu); |
| 626 | } |
| 627 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 628 | static void update_timer_ints(struct kvm_vcpu *vcpu) |
| 629 | { |
| 630 | if ((vcpu->arch.tcr & TCR_DIE) && (vcpu->arch.tsr & TSR_DIS)) |
| 631 | kvmppc_core_queue_dec(vcpu); |
| 632 | else |
| 633 | kvmppc_core_dequeue_dec(vcpu); |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 634 | |
| 635 | if ((vcpu->arch.tcr & TCR_WIE) && (vcpu->arch.tsr & TSR_WIS)) |
| 636 | kvmppc_core_queue_watchdog(vcpu); |
| 637 | else |
| 638 | kvmppc_core_dequeue_watchdog(vcpu); |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 641 | static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 642 | { |
| 643 | unsigned long *pending = &vcpu->arch.pending_exceptions; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 644 | unsigned int priority; |
| 645 | |
Hollis Blanchard | 9ab8084 | 2008-11-05 09:36:22 -0600 | [diff] [blame] | 646 | priority = __ffs(*pending); |
Alexander Graf | 8b3a00f | 2012-02-16 14:12:46 +0000 | [diff] [blame] | 647 | while (priority < BOOKE_IRQPRIO_MAX) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 648 | if (kvmppc_booke_irqprio_deliver(vcpu, priority)) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 649 | break; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 650 | |
| 651 | priority = find_next_bit(pending, |
| 652 | BITS_PER_BYTE * sizeof(*pending), |
| 653 | priority + 1); |
| 654 | } |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame] | 655 | |
| 656 | /* Tell the guest about our interrupt status */ |
Scott Wood | 29ac26e | 2011-11-08 18:23:27 -0600 | [diff] [blame] | 657 | vcpu->arch.shared->int_pending = !!*pending; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 658 | } |
| 659 | |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 660 | /* Check pending exceptions and deliver one, if possible. */ |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 661 | int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu) |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 662 | { |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 663 | int r = 0; |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 664 | WARN_ON_ONCE(!irqs_disabled()); |
| 665 | |
| 666 | kvmppc_core_check_exceptions(vcpu); |
| 667 | |
Alexander Graf | b8c649a | 2012-12-20 04:52:39 +0000 | [diff] [blame] | 668 | if (vcpu->requests) { |
| 669 | /* Exception delivery raised request; start over */ |
| 670 | return 1; |
| 671 | } |
| 672 | |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 673 | if (vcpu->arch.shared->msr & MSR_WE) { |
| 674 | local_irq_enable(); |
| 675 | kvm_vcpu_block(vcpu); |
Alexander Graf | 966cd0f | 2012-03-14 16:55:08 +0100 | [diff] [blame] | 676 | clear_bit(KVM_REQ_UNHALT, &vcpu->requests); |
Scott Wood | 6c85f52 | 2014-01-09 19:18:40 -0600 | [diff] [blame] | 677 | hard_irq_disable(); |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 678 | |
| 679 | kvmppc_set_exit_type(vcpu, EMULATED_MTMSRWE_EXITS); |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 680 | r = 1; |
Scott Wood | c59a6a3 | 2011-11-08 18:23:25 -0600 | [diff] [blame] | 681 | }; |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 682 | |
| 683 | return r; |
| 684 | } |
| 685 | |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 686 | int kvmppc_core_check_requests(struct kvm_vcpu *vcpu) |
Alexander Graf | 4ffc635 | 2012-08-08 20:31:13 +0200 | [diff] [blame] | 687 | { |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 688 | int r = 1; /* Indicate we want to get back into the guest */ |
| 689 | |
Alexander Graf | 2d8185d | 2012-08-10 12:31:12 +0200 | [diff] [blame] | 690 | if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) |
| 691 | update_timer_ints(vcpu); |
Alexander Graf | 862d31f | 2012-07-31 00:19:50 +0200 | [diff] [blame] | 692 | #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC) |
Alexander Graf | 2d8185d | 2012-08-10 12:31:12 +0200 | [diff] [blame] | 693 | if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu)) |
| 694 | kvmppc_core_flush_tlb(vcpu); |
Alexander Graf | 862d31f | 2012-07-31 00:19:50 +0200 | [diff] [blame] | 695 | #endif |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 696 | |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 697 | if (kvm_check_request(KVM_REQ_WATCHDOG, vcpu)) { |
| 698 | vcpu->run->exit_reason = KVM_EXIT_WATCHDOG; |
| 699 | r = 0; |
| 700 | } |
| 701 | |
Alexander Graf | 1c81063 | 2013-01-04 18:12:48 +0100 | [diff] [blame] | 702 | if (kvm_check_request(KVM_REQ_EPR_EXIT, vcpu)) { |
| 703 | vcpu->run->epr.epr = 0; |
| 704 | vcpu->arch.epr_needed = true; |
| 705 | vcpu->run->exit_reason = KVM_EXIT_EPR; |
| 706 | r = 0; |
| 707 | } |
| 708 | |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 709 | return r; |
Alexander Graf | 4ffc635 | 2012-08-08 20:31:13 +0200 | [diff] [blame] | 710 | } |
| 711 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 712 | int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) |
| 713 | { |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 714 | int ret, s; |
Scott Wood | f5f9721 | 2013-11-22 15:52:29 -0600 | [diff] [blame] | 715 | struct debug_reg debug; |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 716 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 717 | if (!vcpu->arch.sane) { |
| 718 | kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR; |
| 719 | return -EINVAL; |
| 720 | } |
| 721 | |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 722 | s = kvmppc_prepare_to_enter(vcpu); |
| 723 | if (s <= 0) { |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 724 | ret = s; |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 725 | goto out; |
| 726 | } |
Scott Wood | 6c85f52 | 2014-01-09 19:18:40 -0600 | [diff] [blame] | 727 | /* interrupts now hard-disabled */ |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 728 | |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 729 | #ifdef CONFIG_PPC_FPU |
| 730 | /* Save userspace FPU state in stack */ |
| 731 | enable_kernel_fp(); |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 732 | |
| 733 | /* |
| 734 | * Since we can't trap on MSR_FP in GS-mode, we consider the guest |
Mihai Caraman | 3efc7da | 2014-08-20 16:36:22 +0300 | [diff] [blame] | 735 | * as always using the FPU. |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 736 | */ |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 737 | kvmppc_load_guest_fp(vcpu); |
| 738 | #endif |
| 739 | |
Mihai Caraman | 95d80a2 | 2014-08-20 16:36:23 +0300 | [diff] [blame] | 740 | #ifdef CONFIG_ALTIVEC |
| 741 | /* Save userspace AltiVec state in stack */ |
| 742 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 743 | enable_kernel_altivec(); |
| 744 | /* |
| 745 | * Since we can't trap on MSR_VEC in GS-mode, we consider the guest |
| 746 | * as always using the AltiVec. |
| 747 | */ |
| 748 | kvmppc_load_guest_altivec(vcpu); |
| 749 | #endif |
| 750 | |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 751 | /* Switch to guest debug context */ |
Bharat Bhushan | 348ba71 | 2014-08-06 12:08:55 +0530 | [diff] [blame] | 752 | debug = vcpu->arch.dbg_reg; |
Scott Wood | f5f9721 | 2013-11-22 15:52:29 -0600 | [diff] [blame] | 753 | switch_booke_debug_regs(&debug); |
| 754 | debug = current->thread.debug; |
Bharat Bhushan | 348ba71 | 2014-08-06 12:08:55 +0530 | [diff] [blame] | 755 | current->thread.debug = vcpu->arch.dbg_reg; |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 756 | |
Bharat Bhushan | 08c9a18 | 2013-11-18 11:18:54 +0530 | [diff] [blame] | 757 | vcpu->arch.pgdir = current->mm->pgd; |
Scott Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 758 | kvmppc_fix_ee_before_entry(); |
Scott Wood | f8941fbe | 2013-06-11 11:38:31 -0500 | [diff] [blame] | 759 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 760 | ret = __kvmppc_vcpu_run(kvm_run, vcpu); |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 761 | |
Alexander Graf | 24afa37b | 2012-08-12 12:42:30 +0200 | [diff] [blame] | 762 | /* No need for kvm_guest_exit. It's done in handle_exit. |
| 763 | We also get here with interrupts enabled. */ |
| 764 | |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 765 | /* Switch back to user space debug context */ |
Scott Wood | f5f9721 | 2013-11-22 15:52:29 -0600 | [diff] [blame] | 766 | switch_booke_debug_regs(&debug); |
| 767 | current->thread.debug = debug; |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 768 | |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 769 | #ifdef CONFIG_PPC_FPU |
| 770 | kvmppc_save_guest_fp(vcpu); |
Scott Wood | 8fae845 | 2011-12-20 15:34:45 +0000 | [diff] [blame] | 771 | #endif |
| 772 | |
Mihai Caraman | 95d80a2 | 2014-08-20 16:36:23 +0300 | [diff] [blame] | 773 | #ifdef CONFIG_ALTIVEC |
| 774 | kvmppc_save_guest_altivec(vcpu); |
| 775 | #endif |
| 776 | |
Scott Wood | 1d1ef22 | 2011-11-08 16:11:59 -0600 | [diff] [blame] | 777 | out: |
Alexander Graf | d69c643 | 2012-08-08 20:44:20 +0200 | [diff] [blame] | 778 | vcpu->mode = OUTSIDE_GUEST_MODE; |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 779 | return ret; |
| 780 | } |
| 781 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 782 | static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) |
| 783 | { |
| 784 | enum emulation_result er; |
| 785 | |
| 786 | er = kvmppc_emulate_instruction(run, vcpu); |
| 787 | switch (er) { |
| 788 | case EMULATE_DONE: |
| 789 | /* don't overwrite subtypes, just account kvm_stats */ |
| 790 | kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS); |
| 791 | /* Future optimization: only reload non-volatiles if |
| 792 | * they were actually modified by emulation. */ |
| 793 | return RESUME_GUEST_NV; |
| 794 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 795 | case EMULATE_AGAIN: |
| 796 | return RESUME_GUEST; |
| 797 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 798 | case EMULATE_FAIL: |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 799 | printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n", |
| 800 | __func__, vcpu->arch.pc, vcpu->arch.last_inst); |
| 801 | /* For debugging, encode the failing instruction and |
| 802 | * report it to userspace. */ |
| 803 | run->hw.hardware_exit_reason = ~0ULL << 32; |
| 804 | run->hw.hardware_exit_reason |= vcpu->arch.last_inst; |
Alexander Graf | d1ff549 | 2012-02-16 13:24:03 +0000 | [diff] [blame] | 805 | kvmppc_core_queue_program(vcpu, ESR_PIL); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 806 | return RESUME_HOST; |
| 807 | |
Bharat Bhushan | 9b4f530 | 2013-04-08 00:32:15 +0000 | [diff] [blame] | 808 | case EMULATE_EXIT_USER: |
| 809 | return RESUME_HOST; |
| 810 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 811 | default: |
| 812 | BUG(); |
| 813 | } |
| 814 | } |
| 815 | |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 816 | static int kvmppc_handle_debug(struct kvm_run *run, struct kvm_vcpu *vcpu) |
| 817 | { |
Bharat Bhushan | 348ba71 | 2014-08-06 12:08:55 +0530 | [diff] [blame] | 818 | struct debug_reg *dbg_reg = &(vcpu->arch.dbg_reg); |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 819 | u32 dbsr = vcpu->arch.dbsr; |
| 820 | |
Bharat Bhushan | 2190991 | 2014-08-06 12:08:54 +0530 | [diff] [blame] | 821 | /* Clear guest dbsr (vcpu->arch.dbsr) */ |
| 822 | vcpu->arch.dbsr = 0; |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 823 | run->debug.arch.status = 0; |
| 824 | run->debug.arch.address = vcpu->arch.pc; |
| 825 | |
| 826 | if (dbsr & (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) { |
| 827 | run->debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT; |
| 828 | } else { |
| 829 | if (dbsr & (DBSR_DAC1W | DBSR_DAC2W)) |
| 830 | run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE; |
| 831 | else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R)) |
| 832 | run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ; |
| 833 | if (dbsr & (DBSR_DAC1R | DBSR_DAC1W)) |
| 834 | run->debug.arch.address = dbg_reg->dac1; |
| 835 | else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W)) |
| 836 | run->debug.arch.address = dbg_reg->dac2; |
| 837 | } |
| 838 | |
| 839 | return RESUME_HOST; |
| 840 | } |
| 841 | |
Alexander Graf | 4e642cc | 2012-02-20 23:57:26 +0100 | [diff] [blame] | 842 | static void kvmppc_fill_pt_regs(struct pt_regs *regs) |
| 843 | { |
| 844 | ulong r1, ip, msr, lr; |
| 845 | |
| 846 | asm("mr %0, 1" : "=r"(r1)); |
| 847 | asm("mflr %0" : "=r"(lr)); |
| 848 | asm("mfmsr %0" : "=r"(msr)); |
| 849 | asm("bl 1f; 1: mflr %0" : "=r"(ip)); |
| 850 | |
| 851 | memset(regs, 0, sizeof(*regs)); |
| 852 | regs->gpr[1] = r1; |
| 853 | regs->nip = ip; |
| 854 | regs->msr = msr; |
| 855 | regs->link = lr; |
| 856 | } |
| 857 | |
Bharat Bhushan | 6328e59 | 2012-06-20 05:56:53 +0000 | [diff] [blame] | 858 | /* |
| 859 | * For interrupts needed to be handled by host interrupt handlers, |
| 860 | * corresponding host handler are called from here in similar way |
| 861 | * (but not exact) as they are called from low level handler |
| 862 | * (such as from arch/powerpc/kernel/head_fsl_booke.S). |
| 863 | */ |
Alexander Graf | 4e642cc | 2012-02-20 23:57:26 +0100 | [diff] [blame] | 864 | static void kvmppc_restart_interrupt(struct kvm_vcpu *vcpu, |
| 865 | unsigned int exit_nr) |
| 866 | { |
| 867 | struct pt_regs regs; |
| 868 | |
| 869 | switch (exit_nr) { |
| 870 | case BOOKE_INTERRUPT_EXTERNAL: |
| 871 | kvmppc_fill_pt_regs(®s); |
| 872 | do_IRQ(®s); |
| 873 | break; |
| 874 | case BOOKE_INTERRUPT_DECREMENTER: |
| 875 | kvmppc_fill_pt_regs(®s); |
| 876 | timer_interrupt(®s); |
| 877 | break; |
Tiejun Chen | 5f17ce8 | 2013-05-13 10:00:45 +0800 | [diff] [blame] | 878 | #if defined(CONFIG_PPC_DOORBELL) |
Alexander Graf | 4e642cc | 2012-02-20 23:57:26 +0100 | [diff] [blame] | 879 | case BOOKE_INTERRUPT_DOORBELL: |
| 880 | kvmppc_fill_pt_regs(®s); |
| 881 | doorbell_exception(®s); |
| 882 | break; |
| 883 | #endif |
| 884 | case BOOKE_INTERRUPT_MACHINE_CHECK: |
| 885 | /* FIXME */ |
| 886 | break; |
Alexander Graf | 7cc1e8e | 2012-02-22 16:26:34 +0100 | [diff] [blame] | 887 | case BOOKE_INTERRUPT_PERFORMANCE_MONITOR: |
| 888 | kvmppc_fill_pt_regs(®s); |
| 889 | performance_monitor_exception(®s); |
| 890 | break; |
Bharat Bhushan | 6328e59 | 2012-06-20 05:56:53 +0000 | [diff] [blame] | 891 | case BOOKE_INTERRUPT_WATCHDOG: |
| 892 | kvmppc_fill_pt_regs(®s); |
| 893 | #ifdef CONFIG_BOOKE_WDT |
| 894 | WatchdogException(®s); |
| 895 | #else |
| 896 | unknown_exception(®s); |
| 897 | #endif |
| 898 | break; |
| 899 | case BOOKE_INTERRUPT_CRITICAL: |
| 900 | unknown_exception(®s); |
| 901 | break; |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 902 | case BOOKE_INTERRUPT_DEBUG: |
| 903 | /* Save DBSR before preemption is enabled */ |
| 904 | vcpu->arch.dbsr = mfspr(SPRN_DBSR); |
| 905 | kvmppc_clear_dbsr(); |
| 906 | break; |
Alexander Graf | 4e642cc | 2012-02-20 23:57:26 +0100 | [diff] [blame] | 907 | } |
| 908 | } |
| 909 | |
Mihai Caraman | f525047 | 2014-07-23 19:06:22 +0300 | [diff] [blame] | 910 | static int kvmppc_resume_inst_load(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 911 | enum emulation_result emulated, u32 last_inst) |
| 912 | { |
| 913 | switch (emulated) { |
| 914 | case EMULATE_AGAIN: |
| 915 | return RESUME_GUEST; |
| 916 | |
| 917 | case EMULATE_FAIL: |
| 918 | pr_debug("%s: load instruction from guest address %lx failed\n", |
| 919 | __func__, vcpu->arch.pc); |
| 920 | /* For debugging, encode the failing instruction and |
| 921 | * report it to userspace. */ |
| 922 | run->hw.hardware_exit_reason = ~0ULL << 32; |
| 923 | run->hw.hardware_exit_reason |= last_inst; |
| 924 | kvmppc_core_queue_program(vcpu, ESR_PIL); |
| 925 | return RESUME_HOST; |
| 926 | |
| 927 | default: |
| 928 | BUG(); |
| 929 | } |
| 930 | } |
| 931 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 932 | /** |
| 933 | * kvmppc_handle_exit |
| 934 | * |
| 935 | * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV) |
| 936 | */ |
| 937 | int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 938 | unsigned int exit_nr) |
| 939 | { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 940 | int r = RESUME_HOST; |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 941 | int s; |
Scott Wood | f1e8902 | 2013-06-06 19:16:31 -0500 | [diff] [blame] | 942 | int idx; |
Mihai Caraman | f525047 | 2014-07-23 19:06:22 +0300 | [diff] [blame] | 943 | u32 last_inst = KVM_INST_FETCH_FAILED; |
| 944 | enum emulation_result emulated = EMULATE_DONE; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 945 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 946 | /* update before a new last_exit_type is rewritten */ |
| 947 | kvmppc_update_timing_stats(vcpu); |
| 948 | |
Alexander Graf | 4e642cc | 2012-02-20 23:57:26 +0100 | [diff] [blame] | 949 | /* restart interrupts if they were meant for the host */ |
| 950 | kvmppc_restart_interrupt(vcpu, exit_nr); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 951 | |
Mihai Caraman | f525047 | 2014-07-23 19:06:22 +0300 | [diff] [blame] | 952 | /* |
| 953 | * get last instruction before beeing preempted |
| 954 | * TODO: for e6500 check also BOOKE_INTERRUPT_LRAT_ERROR & ESR_DATA |
| 955 | */ |
| 956 | switch (exit_nr) { |
| 957 | case BOOKE_INTERRUPT_DATA_STORAGE: |
| 958 | case BOOKE_INTERRUPT_DTLB_MISS: |
| 959 | case BOOKE_INTERRUPT_HV_PRIV: |
| 960 | emulated = kvmppc_get_last_inst(vcpu, false, &last_inst); |
| 961 | break; |
| 962 | default: |
| 963 | break; |
| 964 | } |
| 965 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 966 | local_irq_enable(); |
| 967 | |
Alexander Graf | 97c9505 | 2012-08-02 15:10:00 +0200 | [diff] [blame] | 968 | trace_kvm_exit(exit_nr, vcpu); |
Alexander Graf | 706fb73 | 2012-08-12 11:29:09 +0200 | [diff] [blame] | 969 | kvm_guest_exit(); |
Alexander Graf | 97c9505 | 2012-08-02 15:10:00 +0200 | [diff] [blame] | 970 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 971 | run->exit_reason = KVM_EXIT_UNKNOWN; |
| 972 | run->ready_for_interrupt_injection = 1; |
| 973 | |
Mihai Caraman | f525047 | 2014-07-23 19:06:22 +0300 | [diff] [blame] | 974 | if (emulated != EMULATE_DONE) { |
| 975 | r = kvmppc_resume_inst_load(run, vcpu, emulated, last_inst); |
| 976 | goto out; |
| 977 | } |
| 978 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 979 | switch (exit_nr) { |
| 980 | case BOOKE_INTERRUPT_MACHINE_CHECK: |
Alexander Graf | c35c9d8 | 2012-02-20 12:21:18 +0100 | [diff] [blame] | 981 | printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR)); |
| 982 | kvmppc_dump_vcpu(vcpu); |
| 983 | /* For debugging, send invalid exit reason to user space */ |
| 984 | run->hw.hardware_exit_reason = ~1ULL << 32; |
| 985 | run->hw.hardware_exit_reason |= mfspr(SPRN_MCSR); |
| 986 | r = RESUME_HOST; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 987 | break; |
| 988 | |
| 989 | case BOOKE_INTERRUPT_EXTERNAL: |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 990 | kvmppc_account_exit(vcpu, EXT_INTR_EXITS); |
Hollis Blanchard | 1b6766c | 2008-11-05 09:36:21 -0600 | [diff] [blame] | 991 | r = RESUME_GUEST; |
| 992 | break; |
| 993 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 994 | case BOOKE_INTERRUPT_DECREMENTER: |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 995 | kvmppc_account_exit(vcpu, DEC_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 996 | r = RESUME_GUEST; |
| 997 | break; |
| 998 | |
Bharat Bhushan | 6328e59 | 2012-06-20 05:56:53 +0000 | [diff] [blame] | 999 | case BOOKE_INTERRUPT_WATCHDOG: |
| 1000 | r = RESUME_GUEST; |
| 1001 | break; |
| 1002 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1003 | case BOOKE_INTERRUPT_DOORBELL: |
| 1004 | kvmppc_account_exit(vcpu, DBELL_EXITS); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1005 | r = RESUME_GUEST; |
| 1006 | break; |
| 1007 | |
| 1008 | case BOOKE_INTERRUPT_GUEST_DBELL_CRIT: |
| 1009 | kvmppc_account_exit(vcpu, GDBELL_EXITS); |
| 1010 | |
| 1011 | /* |
| 1012 | * We are here because there is a pending guest interrupt |
| 1013 | * which could not be delivered as MSR_CE or MSR_ME was not |
| 1014 | * set. Once we break from here we will retry delivery. |
| 1015 | */ |
| 1016 | r = RESUME_GUEST; |
| 1017 | break; |
| 1018 | |
| 1019 | case BOOKE_INTERRUPT_GUEST_DBELL: |
| 1020 | kvmppc_account_exit(vcpu, GDBELL_EXITS); |
| 1021 | |
| 1022 | /* |
| 1023 | * We are here because there is a pending guest interrupt |
| 1024 | * which could not be delivered as MSR_EE was not set. Once |
| 1025 | * we break from here we will retry delivery. |
| 1026 | */ |
| 1027 | r = RESUME_GUEST; |
| 1028 | break; |
| 1029 | |
Alexander Graf | 95f2e92 | 2012-02-20 22:45:12 +0100 | [diff] [blame] | 1030 | case BOOKE_INTERRUPT_PERFORMANCE_MONITOR: |
| 1031 | r = RESUME_GUEST; |
| 1032 | break; |
| 1033 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1034 | case BOOKE_INTERRUPT_HV_PRIV: |
| 1035 | r = emulation_exit(run, vcpu); |
| 1036 | break; |
| 1037 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1038 | case BOOKE_INTERRUPT_PROGRAM: |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1039 | if (vcpu->arch.shared->msr & (MSR_PR | MSR_GS)) { |
Alexander Graf | 0268597c | 2012-02-20 12:33:22 +0100 | [diff] [blame] | 1040 | /* |
| 1041 | * Program traps generated by user-level software must |
| 1042 | * be handled by the guest kernel. |
| 1043 | * |
| 1044 | * In GS mode, hypervisor privileged instructions trap |
| 1045 | * on BOOKE_INTERRUPT_HV_PRIV, not here, so these are |
| 1046 | * actual program interrupts, handled by the guest. |
| 1047 | */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 1048 | kvmppc_core_queue_program(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1049 | r = RESUME_GUEST; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1050 | kvmppc_account_exit(vcpu, USR_PR_INST); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1051 | break; |
| 1052 | } |
| 1053 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1054 | r = emulation_exit(run, vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1055 | break; |
| 1056 | |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 1057 | case BOOKE_INTERRUPT_FP_UNAVAIL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 1058 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1059 | kvmppc_account_exit(vcpu, FP_UNAVAIL); |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 1060 | r = RESUME_GUEST; |
| 1061 | break; |
| 1062 | |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 1063 | #ifdef CONFIG_SPE |
| 1064 | case BOOKE_INTERRUPT_SPE_UNAVAIL: { |
| 1065 | if (vcpu->arch.shared->msr & MSR_SPE) |
| 1066 | kvmppc_vcpu_enable_spe(vcpu); |
| 1067 | else |
| 1068 | kvmppc_booke_queue_irqprio(vcpu, |
| 1069 | BOOKE_IRQPRIO_SPE_UNAVAIL); |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 1070 | r = RESUME_GUEST; |
| 1071 | break; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 1072 | } |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 1073 | |
| 1074 | case BOOKE_INTERRUPT_SPE_FP_DATA: |
| 1075 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA); |
| 1076 | r = RESUME_GUEST; |
| 1077 | break; |
| 1078 | |
| 1079 | case BOOKE_INTERRUPT_SPE_FP_ROUND: |
| 1080 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND); |
| 1081 | r = RESUME_GUEST; |
| 1082 | break; |
Mihai Caraman | 95d80a2 | 2014-08-20 16:36:23 +0300 | [diff] [blame] | 1083 | #elif defined(CONFIG_SPE_POSSIBLE) |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 1084 | case BOOKE_INTERRUPT_SPE_UNAVAIL: |
| 1085 | /* |
| 1086 | * Guest wants SPE, but host kernel doesn't support it. Send |
| 1087 | * an "unimplemented operation" program check to the guest. |
| 1088 | */ |
| 1089 | kvmppc_core_queue_program(vcpu, ESR_PUO | ESR_SPV); |
| 1090 | r = RESUME_GUEST; |
| 1091 | break; |
| 1092 | |
| 1093 | /* |
| 1094 | * These really should never happen without CONFIG_SPE, |
| 1095 | * as we should never enable the real MSR[SPE] in the guest. |
| 1096 | */ |
| 1097 | case BOOKE_INTERRUPT_SPE_FP_DATA: |
| 1098 | case BOOKE_INTERRUPT_SPE_FP_ROUND: |
| 1099 | printk(KERN_CRIT "%s: unexpected SPE interrupt %u at %08lx\n", |
| 1100 | __func__, exit_nr, vcpu->arch.pc); |
| 1101 | run->hw.hardware_exit_reason = exit_nr; |
| 1102 | r = RESUME_HOST; |
| 1103 | break; |
Mihai Caraman | 95d80a2 | 2014-08-20 16:36:23 +0300 | [diff] [blame] | 1104 | #endif /* CONFIG_SPE_POSSIBLE */ |
| 1105 | |
| 1106 | /* |
| 1107 | * On cores with Vector category, KVM is loaded only if CONFIG_ALTIVEC, |
| 1108 | * see kvmppc_core_check_processor_compat(). |
| 1109 | */ |
| 1110 | #ifdef CONFIG_ALTIVEC |
| 1111 | case BOOKE_INTERRUPT_ALTIVEC_UNAVAIL: |
| 1112 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ALTIVEC_UNAVAIL); |
| 1113 | r = RESUME_GUEST; |
| 1114 | break; |
| 1115 | |
| 1116 | case BOOKE_INTERRUPT_ALTIVEC_ASSIST: |
| 1117 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ALTIVEC_ASSIST); |
| 1118 | r = RESUME_GUEST; |
| 1119 | break; |
Scott Wood | 4cd35f6 | 2011-06-14 18:34:31 -0500 | [diff] [blame] | 1120 | #endif |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 1121 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1122 | case BOOKE_INTERRUPT_DATA_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 1123 | kvmppc_core_queue_data_storage(vcpu, vcpu->arch.fault_dear, |
| 1124 | vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1125 | kvmppc_account_exit(vcpu, DSI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1126 | r = RESUME_GUEST; |
| 1127 | break; |
| 1128 | |
| 1129 | case BOOKE_INTERRUPT_INST_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 1130 | kvmppc_core_queue_inst_storage(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1131 | kvmppc_account_exit(vcpu, ISI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1132 | r = RESUME_GUEST; |
| 1133 | break; |
| 1134 | |
Alexander Graf | 011da89 | 2013-01-31 14:17:38 +0100 | [diff] [blame] | 1135 | case BOOKE_INTERRUPT_ALIGNMENT: |
| 1136 | kvmppc_core_queue_alignment(vcpu, vcpu->arch.fault_dear, |
| 1137 | vcpu->arch.fault_esr); |
| 1138 | r = RESUME_GUEST; |
| 1139 | break; |
| 1140 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1141 | #ifdef CONFIG_KVM_BOOKE_HV |
| 1142 | case BOOKE_INTERRUPT_HV_SYSCALL: |
| 1143 | if (!(vcpu->arch.shared->msr & MSR_PR)) { |
| 1144 | kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); |
| 1145 | } else { |
| 1146 | /* |
| 1147 | * hcall from guest userspace -- send privileged |
| 1148 | * instruction program check. |
| 1149 | */ |
| 1150 | kvmppc_core_queue_program(vcpu, ESR_PPR); |
| 1151 | } |
| 1152 | |
| 1153 | r = RESUME_GUEST; |
| 1154 | break; |
| 1155 | #else |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1156 | case BOOKE_INTERRUPT_SYSCALL: |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 1157 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 1158 | (((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) { |
| 1159 | /* KVM PV hypercalls */ |
| 1160 | kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); |
| 1161 | r = RESUME_GUEST; |
| 1162 | } else { |
| 1163 | /* Guest syscalls */ |
| 1164 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL); |
| 1165 | } |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1166 | kvmppc_account_exit(vcpu, SYSCALL_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1167 | r = RESUME_GUEST; |
| 1168 | break; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1169 | #endif |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1170 | |
| 1171 | case BOOKE_INTERRUPT_DTLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1172 | unsigned long eaddr = vcpu->arch.fault_dear; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 1173 | int gtlb_index; |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 1174 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1175 | gfn_t gfn; |
| 1176 | |
Alexander Graf | bf7ca4b | 2012-02-15 23:40:00 +0000 | [diff] [blame] | 1177 | #ifdef CONFIG_KVM_E500V2 |
Scott Wood | a4cd8b2 | 2011-06-14 18:34:41 -0500 | [diff] [blame] | 1178 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 1179 | (eaddr & PAGE_MASK) == vcpu->arch.magic_page_ea) { |
| 1180 | kvmppc_map_magic(vcpu); |
| 1181 | kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS); |
| 1182 | r = RESUME_GUEST; |
| 1183 | |
| 1184 | break; |
| 1185 | } |
| 1186 | #endif |
| 1187 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1188 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 1189 | gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 1190 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1191 | /* The guest didn't have a mapping for it. */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 1192 | kvmppc_core_queue_dtlb_miss(vcpu, |
| 1193 | vcpu->arch.fault_dear, |
| 1194 | vcpu->arch.fault_esr); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 1195 | kvmppc_mmu_dtlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1196 | kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1197 | r = RESUME_GUEST; |
| 1198 | break; |
| 1199 | } |
| 1200 | |
Scott Wood | f1e8902 | 2013-06-06 19:16:31 -0500 | [diff] [blame] | 1201 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
| 1202 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 1203 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 1204 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1205 | |
| 1206 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 1207 | /* The guest TLB had a mapping, but the shadow TLB |
| 1208 | * didn't, and it is RAM. This could be because: |
| 1209 | * a) the entry is mapping the host kernel, or |
| 1210 | * b) the guest used a large mapping which we're faking |
| 1211 | * Either way, we need to satisfy the fault without |
| 1212 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 1213 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1214 | kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1215 | r = RESUME_GUEST; |
| 1216 | } else { |
| 1217 | /* Guest has mapped and accessed a page which is not |
| 1218 | * actually RAM. */ |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 1219 | vcpu->arch.paddr_accessed = gpaddr; |
Alexander Graf | 6020c0f | 2012-03-12 02:26:30 +0100 | [diff] [blame] | 1220 | vcpu->arch.vaddr_accessed = eaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1221 | r = kvmppc_emulate_mmio(run, vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1222 | kvmppc_account_exit(vcpu, MMIO_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1223 | } |
| 1224 | |
Scott Wood | f1e8902 | 2013-06-06 19:16:31 -0500 | [diff] [blame] | 1225 | srcu_read_unlock(&vcpu->kvm->srcu, idx); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1226 | break; |
| 1227 | } |
| 1228 | |
| 1229 | case BOOKE_INTERRUPT_ITLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1230 | unsigned long eaddr = vcpu->arch.pc; |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 1231 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1232 | gfn_t gfn; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 1233 | int gtlb_index; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1234 | |
| 1235 | r = RESUME_GUEST; |
| 1236 | |
| 1237 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 1238 | gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 1239 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1240 | /* The guest didn't have a mapping for it. */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 1241 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 1242 | kvmppc_mmu_itlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1243 | kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1244 | break; |
| 1245 | } |
| 1246 | |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1247 | kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1248 | |
Scott Wood | f1e8902 | 2013-06-06 19:16:31 -0500 | [diff] [blame] | 1249 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
| 1250 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 1251 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 1252 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1253 | |
| 1254 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 1255 | /* The guest TLB had a mapping, but the shadow TLB |
| 1256 | * didn't. This could be because: |
| 1257 | * a) the entry is mapping the host kernel, or |
| 1258 | * b) the guest used a large mapping which we're faking |
| 1259 | * Either way, we need to satisfy the fault without |
| 1260 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 1261 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1262 | } else { |
| 1263 | /* Guest mapped and leaped at non-RAM! */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 1264 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1265 | } |
| 1266 | |
Scott Wood | f1e8902 | 2013-06-06 19:16:31 -0500 | [diff] [blame] | 1267 | srcu_read_unlock(&vcpu->kvm->srcu, idx); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1268 | break; |
| 1269 | } |
| 1270 | |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 1271 | case BOOKE_INTERRUPT_DEBUG: { |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 1272 | r = kvmppc_handle_debug(run, vcpu); |
| 1273 | if (r == RESUME_HOST) |
| 1274 | run->exit_reason = KVM_EXIT_DEBUG; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 1275 | kvmppc_account_exit(vcpu, DEBUG_EXITS); |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 1276 | break; |
| 1277 | } |
| 1278 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1279 | default: |
| 1280 | printk(KERN_EMERG "exit_nr %d\n", exit_nr); |
| 1281 | BUG(); |
| 1282 | } |
| 1283 | |
Mihai Caraman | f525047 | 2014-07-23 19:06:22 +0300 | [diff] [blame] | 1284 | out: |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 1285 | /* |
| 1286 | * To avoid clobbering exit_reason, only check for signals if we |
| 1287 | * aren't already exiting to userspace for some other reason. |
| 1288 | */ |
Alexander Graf | 03660ba | 2012-02-28 12:00:41 +0100 | [diff] [blame] | 1289 | if (!(r & RESUME_HOST)) { |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 1290 | s = kvmppc_prepare_to_enter(vcpu); |
Scott Wood | 6c85f52 | 2014-01-09 19:18:40 -0600 | [diff] [blame] | 1291 | if (s <= 0) |
Alexander Graf | 7ee7885 | 2012-08-13 12:44:41 +0200 | [diff] [blame] | 1292 | r = (s << 2) | RESUME_HOST | (r & RESUME_FLAG_NV); |
Scott Wood | 6c85f52 | 2014-01-09 19:18:40 -0600 | [diff] [blame] | 1293 | else { |
| 1294 | /* interrupts now hard-disabled */ |
Scott Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 1295 | kvmppc_fix_ee_before_entry(); |
Mihai Caraman | 3efc7da | 2014-08-20 16:36:22 +0300 | [diff] [blame] | 1296 | kvmppc_load_guest_fp(vcpu); |
Mihai Caraman | 95d80a2 | 2014-08-20 16:36:23 +0300 | [diff] [blame] | 1297 | kvmppc_load_guest_altivec(vcpu); |
Alexander Graf | 03660ba | 2012-02-28 12:00:41 +0100 | [diff] [blame] | 1298 | } |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | return r; |
| 1302 | } |
| 1303 | |
Bharat Bhushan | d26f22c | 2013-02-24 18:57:11 +0000 | [diff] [blame] | 1304 | static void kvmppc_set_tsr(struct kvm_vcpu *vcpu, u32 new_tsr) |
| 1305 | { |
| 1306 | u32 old_tsr = vcpu->arch.tsr; |
| 1307 | |
| 1308 | vcpu->arch.tsr = new_tsr; |
| 1309 | |
| 1310 | if ((old_tsr ^ vcpu->arch.tsr) & (TSR_ENW | TSR_WIS)) |
| 1311 | arm_next_watchdog(vcpu); |
| 1312 | |
| 1313 | update_timer_ints(vcpu); |
| 1314 | } |
| 1315 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1316 | /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */ |
| 1317 | int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) |
| 1318 | { |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 1319 | int i; |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 1320 | int r; |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 1321 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1322 | vcpu->arch.pc = 0; |
Scott Wood | b590497 | 2011-11-08 18:23:30 -0600 | [diff] [blame] | 1323 | vcpu->arch.shared->pir = vcpu->vcpu_id; |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 1324 | kvmppc_set_gpr(vcpu, 1, (16<<20) - 8); /* -8 for the callee-save LR slot */ |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1325 | kvmppc_set_msr(vcpu, 0); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1326 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1327 | #ifndef CONFIG_KVM_BOOKE_HV |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 1328 | vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS; |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 1329 | vcpu->arch.shadow_pid = 1; |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 1330 | vcpu->arch.shared->msr = 0; |
| 1331 | #endif |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 1332 | |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 1333 | /* Eye-catching numbers so we know if the guest takes an interrupt |
| 1334 | * before it's programmed its own IVPR/IVORs. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1335 | vcpu->arch.ivpr = 0x55550000; |
Hollis Blanchard | 082decf | 2010-08-07 10:33:56 -0700 | [diff] [blame] | 1336 | for (i = 0; i < BOOKE_IRQPRIO_MAX; i++) |
| 1337 | vcpu->arch.ivor[i] = 0x7700 | i * 4; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1338 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 1339 | kvmppc_init_timing_stats(vcpu); |
| 1340 | |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 1341 | r = kvmppc_core_vcpu_setup(vcpu); |
| 1342 | kvmppc_sanity_check(vcpu); |
| 1343 | return r; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1344 | } |
| 1345 | |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 1346 | int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu) |
| 1347 | { |
| 1348 | /* setup watchdog timer once */ |
| 1349 | spin_lock_init(&vcpu->arch.wdt_lock); |
| 1350 | setup_timer(&vcpu->arch.wdt_timer, kvmppc_watchdog_func, |
| 1351 | (unsigned long)vcpu); |
| 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu) |
| 1357 | { |
| 1358 | del_timer_sync(&vcpu->arch.wdt_timer); |
| 1359 | } |
| 1360 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1361 | int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 1362 | { |
| 1363 | int i; |
| 1364 | |
| 1365 | regs->pc = vcpu->arch.pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1366 | regs->cr = kvmppc_get_cr(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1367 | regs->ctr = vcpu->arch.ctr; |
| 1368 | regs->lr = vcpu->arch.lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1369 | regs->xer = kvmppc_get_xer(vcpu); |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 1370 | regs->msr = vcpu->arch.shared->msr; |
Bharat Bhushan | 31579ee | 2014-07-17 17:01:36 +0530 | [diff] [blame] | 1371 | regs->srr0 = kvmppc_get_srr0(vcpu); |
| 1372 | regs->srr1 = kvmppc_get_srr1(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1373 | regs->pid = vcpu->arch.pid; |
Bharat Bhushan | c1b8a01 | 2014-07-17 17:01:39 +0530 | [diff] [blame] | 1374 | regs->sprg0 = kvmppc_get_sprg0(vcpu); |
| 1375 | regs->sprg1 = kvmppc_get_sprg1(vcpu); |
| 1376 | regs->sprg2 = kvmppc_get_sprg2(vcpu); |
| 1377 | regs->sprg3 = kvmppc_get_sprg3(vcpu); |
| 1378 | regs->sprg4 = kvmppc_get_sprg4(vcpu); |
| 1379 | regs->sprg5 = kvmppc_get_sprg5(vcpu); |
| 1380 | regs->sprg6 = kvmppc_get_sprg6(vcpu); |
| 1381 | regs->sprg7 = kvmppc_get_sprg7(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1382 | |
| 1383 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 1384 | regs->gpr[i] = kvmppc_get_gpr(vcpu, i); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1385 | |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
| 1389 | int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 1390 | { |
| 1391 | int i; |
| 1392 | |
| 1393 | vcpu->arch.pc = regs->pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1394 | kvmppc_set_cr(vcpu, regs->cr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1395 | vcpu->arch.ctr = regs->ctr; |
| 1396 | vcpu->arch.lr = regs->lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1397 | kvmppc_set_xer(vcpu, regs->xer); |
Hollis Blanchard | b8fd68a | 2008-11-05 09:36:20 -0600 | [diff] [blame] | 1398 | kvmppc_set_msr(vcpu, regs->msr); |
Bharat Bhushan | 31579ee | 2014-07-17 17:01:36 +0530 | [diff] [blame] | 1399 | kvmppc_set_srr0(vcpu, regs->srr0); |
| 1400 | kvmppc_set_srr1(vcpu, regs->srr1); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1401 | kvmppc_set_pid(vcpu, regs->pid); |
Bharat Bhushan | c1b8a01 | 2014-07-17 17:01:39 +0530 | [diff] [blame] | 1402 | kvmppc_set_sprg0(vcpu, regs->sprg0); |
| 1403 | kvmppc_set_sprg1(vcpu, regs->sprg1); |
| 1404 | kvmppc_set_sprg2(vcpu, regs->sprg2); |
| 1405 | kvmppc_set_sprg3(vcpu, regs->sprg3); |
| 1406 | kvmppc_set_sprg4(vcpu, regs->sprg4); |
| 1407 | kvmppc_set_sprg5(vcpu, regs->sprg5); |
| 1408 | kvmppc_set_sprg6(vcpu, regs->sprg6); |
| 1409 | kvmppc_set_sprg7(vcpu, regs->sprg7); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1410 | |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 1411 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
| 1412 | kvmppc_set_gpr(vcpu, i, regs->gpr[i]); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1413 | |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1417 | static void get_sregs_base(struct kvm_vcpu *vcpu, |
| 1418 | struct kvm_sregs *sregs) |
| 1419 | { |
| 1420 | u64 tb = get_tb(); |
| 1421 | |
| 1422 | sregs->u.e.features |= KVM_SREGS_E_BASE; |
| 1423 | |
| 1424 | sregs->u.e.csrr0 = vcpu->arch.csrr0; |
| 1425 | sregs->u.e.csrr1 = vcpu->arch.csrr1; |
| 1426 | sregs->u.e.mcsr = vcpu->arch.mcsr; |
Bharat Bhushan | dc16854 | 2014-07-17 17:01:38 +0530 | [diff] [blame] | 1427 | sregs->u.e.esr = kvmppc_get_esr(vcpu); |
Bharat Bhushan | a5414d4 | 2014-07-17 17:01:37 +0530 | [diff] [blame] | 1428 | sregs->u.e.dear = kvmppc_get_dar(vcpu); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1429 | sregs->u.e.tsr = vcpu->arch.tsr; |
| 1430 | sregs->u.e.tcr = vcpu->arch.tcr; |
| 1431 | sregs->u.e.dec = kvmppc_get_dec(vcpu, tb); |
| 1432 | sregs->u.e.tb = tb; |
| 1433 | sregs->u.e.vrsave = vcpu->arch.vrsave; |
| 1434 | } |
| 1435 | |
| 1436 | static int set_sregs_base(struct kvm_vcpu *vcpu, |
| 1437 | struct kvm_sregs *sregs) |
| 1438 | { |
| 1439 | if (!(sregs->u.e.features & KVM_SREGS_E_BASE)) |
| 1440 | return 0; |
| 1441 | |
| 1442 | vcpu->arch.csrr0 = sregs->u.e.csrr0; |
| 1443 | vcpu->arch.csrr1 = sregs->u.e.csrr1; |
| 1444 | vcpu->arch.mcsr = sregs->u.e.mcsr; |
Bharat Bhushan | dc16854 | 2014-07-17 17:01:38 +0530 | [diff] [blame] | 1445 | kvmppc_set_esr(vcpu, sregs->u.e.esr); |
Bharat Bhushan | a5414d4 | 2014-07-17 17:01:37 +0530 | [diff] [blame] | 1446 | kvmppc_set_dar(vcpu, sregs->u.e.dear); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1447 | vcpu->arch.vrsave = sregs->u.e.vrsave; |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1448 | kvmppc_set_tcr(vcpu, sregs->u.e.tcr); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1449 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1450 | if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_DEC) { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1451 | vcpu->arch.dec = sregs->u.e.dec; |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1452 | kvmppc_emulate_dec(vcpu); |
| 1453 | } |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1454 | |
Bharat Bhushan | d26f22c | 2013-02-24 18:57:11 +0000 | [diff] [blame] | 1455 | if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_TSR) |
| 1456 | kvmppc_set_tsr(vcpu, sregs->u.e.tsr); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1457 | |
| 1458 | return 0; |
| 1459 | } |
| 1460 | |
| 1461 | static void get_sregs_arch206(struct kvm_vcpu *vcpu, |
| 1462 | struct kvm_sregs *sregs) |
| 1463 | { |
| 1464 | sregs->u.e.features |= KVM_SREGS_E_ARCH206; |
| 1465 | |
Scott Wood | 841741f | 2011-09-02 17:39:37 -0500 | [diff] [blame] | 1466 | sregs->u.e.pir = vcpu->vcpu_id; |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1467 | sregs->u.e.mcsrr0 = vcpu->arch.mcsrr0; |
| 1468 | sregs->u.e.mcsrr1 = vcpu->arch.mcsrr1; |
| 1469 | sregs->u.e.decar = vcpu->arch.decar; |
| 1470 | sregs->u.e.ivpr = vcpu->arch.ivpr; |
| 1471 | } |
| 1472 | |
| 1473 | static int set_sregs_arch206(struct kvm_vcpu *vcpu, |
| 1474 | struct kvm_sregs *sregs) |
| 1475 | { |
| 1476 | if (!(sregs->u.e.features & KVM_SREGS_E_ARCH206)) |
| 1477 | return 0; |
| 1478 | |
Scott Wood | 841741f | 2011-09-02 17:39:37 -0500 | [diff] [blame] | 1479 | if (sregs->u.e.pir != vcpu->vcpu_id) |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1480 | return -EINVAL; |
| 1481 | |
| 1482 | vcpu->arch.mcsrr0 = sregs->u.e.mcsrr0; |
| 1483 | vcpu->arch.mcsrr1 = sregs->u.e.mcsrr1; |
| 1484 | vcpu->arch.decar = sregs->u.e.decar; |
| 1485 | vcpu->arch.ivpr = sregs->u.e.ivpr; |
| 1486 | |
| 1487 | return 0; |
| 1488 | } |
| 1489 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1490 | int kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1491 | { |
| 1492 | sregs->u.e.features |= KVM_SREGS_E_IVOR; |
| 1493 | |
| 1494 | sregs->u.e.ivor_low[0] = vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL]; |
| 1495 | sregs->u.e.ivor_low[1] = vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK]; |
| 1496 | sregs->u.e.ivor_low[2] = vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE]; |
| 1497 | sregs->u.e.ivor_low[3] = vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE]; |
| 1498 | sregs->u.e.ivor_low[4] = vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL]; |
| 1499 | sregs->u.e.ivor_low[5] = vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT]; |
| 1500 | sregs->u.e.ivor_low[6] = vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM]; |
| 1501 | sregs->u.e.ivor_low[7] = vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL]; |
| 1502 | sregs->u.e.ivor_low[8] = vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL]; |
| 1503 | sregs->u.e.ivor_low[9] = vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL]; |
| 1504 | sregs->u.e.ivor_low[10] = vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER]; |
| 1505 | sregs->u.e.ivor_low[11] = vcpu->arch.ivor[BOOKE_IRQPRIO_FIT]; |
| 1506 | sregs->u.e.ivor_low[12] = vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG]; |
| 1507 | sregs->u.e.ivor_low[13] = vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS]; |
| 1508 | sregs->u.e.ivor_low[14] = vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS]; |
| 1509 | sregs->u.e.ivor_low[15] = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG]; |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 1510 | return 0; |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) |
| 1514 | { |
| 1515 | if (!(sregs->u.e.features & KVM_SREGS_E_IVOR)) |
| 1516 | return 0; |
| 1517 | |
| 1518 | vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL] = sregs->u.e.ivor_low[0]; |
| 1519 | vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK] = sregs->u.e.ivor_low[1]; |
| 1520 | vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE] = sregs->u.e.ivor_low[2]; |
| 1521 | vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE] = sregs->u.e.ivor_low[3]; |
| 1522 | vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL] = sregs->u.e.ivor_low[4]; |
| 1523 | vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT] = sregs->u.e.ivor_low[5]; |
| 1524 | vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM] = sregs->u.e.ivor_low[6]; |
| 1525 | vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL] = sregs->u.e.ivor_low[7]; |
| 1526 | vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL] = sregs->u.e.ivor_low[8]; |
| 1527 | vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL] = sregs->u.e.ivor_low[9]; |
| 1528 | vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER] = sregs->u.e.ivor_low[10]; |
| 1529 | vcpu->arch.ivor[BOOKE_IRQPRIO_FIT] = sregs->u.e.ivor_low[11]; |
| 1530 | vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG] = sregs->u.e.ivor_low[12]; |
| 1531 | vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS] = sregs->u.e.ivor_low[13]; |
| 1532 | vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS] = sregs->u.e.ivor_low[14]; |
| 1533 | vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG] = sregs->u.e.ivor_low[15]; |
| 1534 | |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1538 | int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, |
| 1539 | struct kvm_sregs *sregs) |
| 1540 | { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1541 | sregs->pvr = vcpu->arch.pvr; |
| 1542 | |
| 1543 | get_sregs_base(vcpu, sregs); |
| 1544 | get_sregs_arch206(vcpu, sregs); |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 1545 | return vcpu->kvm->arch.kvm_ops->get_sregs(vcpu, sregs); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, |
| 1549 | struct kvm_sregs *sregs) |
| 1550 | { |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 1551 | int ret; |
| 1552 | |
| 1553 | if (vcpu->arch.pvr != sregs->pvr) |
| 1554 | return -EINVAL; |
| 1555 | |
| 1556 | ret = set_sregs_base(vcpu, sregs); |
| 1557 | if (ret < 0) |
| 1558 | return ret; |
| 1559 | |
| 1560 | ret = set_sregs_arch206(vcpu, sregs); |
| 1561 | if (ret < 0) |
| 1562 | return ret; |
| 1563 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 1564 | return vcpu->kvm->arch.kvm_ops->set_sregs(vcpu, sregs); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1565 | } |
| 1566 | |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1567 | int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, |
| 1568 | union kvmppc_one_reg *val) |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1569 | { |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1570 | int r = 0; |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1571 | |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1572 | switch (id) { |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1573 | case KVM_REG_PPC_IAC1: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1574 | *val = get_reg_val(id, vcpu->arch.dbg_reg.iac1); |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1575 | break; |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1576 | case KVM_REG_PPC_IAC2: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1577 | *val = get_reg_val(id, vcpu->arch.dbg_reg.iac2); |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1578 | break; |
| 1579 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 1580 | case KVM_REG_PPC_IAC3: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1581 | *val = get_reg_val(id, vcpu->arch.dbg_reg.iac3); |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1582 | break; |
| 1583 | case KVM_REG_PPC_IAC4: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1584 | *val = get_reg_val(id, vcpu->arch.dbg_reg.iac4); |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1585 | break; |
| 1586 | #endif |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1587 | case KVM_REG_PPC_DAC1: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1588 | *val = get_reg_val(id, vcpu->arch.dbg_reg.dac1); |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1589 | break; |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1590 | case KVM_REG_PPC_DAC2: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1591 | *val = get_reg_val(id, vcpu->arch.dbg_reg.dac2); |
Bharat Bhushan | 2c50967 | 2014-08-06 12:08:56 +0530 | [diff] [blame] | 1592 | break; |
Alexander Graf | 324b3e6 | 2013-01-04 18:28:51 +0100 | [diff] [blame] | 1593 | case KVM_REG_PPC_EPR: { |
Bharat Bhushan | 34f754b | 2014-07-17 17:01:40 +0530 | [diff] [blame] | 1594 | u32 epr = kvmppc_get_epr(vcpu); |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1595 | *val = get_reg_val(id, epr); |
Alexander Graf | 324b3e6 | 2013-01-04 18:28:51 +0100 | [diff] [blame] | 1596 | break; |
| 1597 | } |
Mihai Caraman | 352df1d | 2012-10-11 06:13:29 +0000 | [diff] [blame] | 1598 | #if defined(CONFIG_64BIT) |
| 1599 | case KVM_REG_PPC_EPCR: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1600 | *val = get_reg_val(id, vcpu->arch.epcr); |
Mihai Caraman | 352df1d | 2012-10-11 06:13:29 +0000 | [diff] [blame] | 1601 | break; |
| 1602 | #endif |
Bharat Bhushan | 78accda | 2013-02-24 18:57:12 +0000 | [diff] [blame] | 1603 | case KVM_REG_PPC_TCR: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1604 | *val = get_reg_val(id, vcpu->arch.tcr); |
Bharat Bhushan | 78accda | 2013-02-24 18:57:12 +0000 | [diff] [blame] | 1605 | break; |
| 1606 | case KVM_REG_PPC_TSR: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1607 | *val = get_reg_val(id, vcpu->arch.tsr); |
Bharat Bhushan | 78accda | 2013-02-24 18:57:12 +0000 | [diff] [blame] | 1608 | break; |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1609 | case KVM_REG_PPC_DEBUG_INST: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1610 | *val = get_reg_val(id, KVMPPC_INST_EHPRIV_DEBUG); |
Bharat Bhushan | 8c32a2e | 2013-03-20 20:24:58 +0000 | [diff] [blame] | 1611 | break; |
Paul Mackerras | 8b75cbb | 2013-09-20 14:52:37 +1000 | [diff] [blame] | 1612 | case KVM_REG_PPC_VRSAVE: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1613 | *val = get_reg_val(id, vcpu->arch.vrsave); |
Bharat Bhushan | 8c32a2e | 2013-03-20 20:24:58 +0000 | [diff] [blame] | 1614 | break; |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1615 | default: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1616 | r = vcpu->kvm->arch.kvm_ops->get_one_reg(vcpu, id, val); |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1617 | break; |
| 1618 | } |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1619 | |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1620 | return r; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1623 | int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, |
| 1624 | union kvmppc_one_reg *val) |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1625 | { |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1626 | int r = 0; |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1627 | |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1628 | switch (id) { |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1629 | case KVM_REG_PPC_IAC1: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1630 | vcpu->arch.dbg_reg.iac1 = set_reg_val(id, *val); |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1631 | break; |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1632 | case KVM_REG_PPC_IAC2: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1633 | vcpu->arch.dbg_reg.iac2 = set_reg_val(id, *val); |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1634 | break; |
| 1635 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 1636 | case KVM_REG_PPC_IAC3: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1637 | vcpu->arch.dbg_reg.iac3 = set_reg_val(id, *val); |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1638 | break; |
| 1639 | case KVM_REG_PPC_IAC4: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1640 | vcpu->arch.dbg_reg.iac4 = set_reg_val(id, *val); |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1641 | break; |
| 1642 | #endif |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1643 | case KVM_REG_PPC_DAC1: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1644 | vcpu->arch.dbg_reg.dac1 = set_reg_val(id, *val); |
Bharat Bhushan | 547465e | 2013-07-04 12:27:46 +0530 | [diff] [blame] | 1645 | break; |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1646 | case KVM_REG_PPC_DAC2: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1647 | vcpu->arch.dbg_reg.dac2 = set_reg_val(id, *val); |
Bharat Bhushan | 2c50967 | 2014-08-06 12:08:56 +0530 | [diff] [blame] | 1648 | break; |
Alexander Graf | 324b3e6 | 2013-01-04 18:28:51 +0100 | [diff] [blame] | 1649 | case KVM_REG_PPC_EPR: { |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1650 | u32 new_epr = set_reg_val(id, *val); |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1651 | kvmppc_set_epr(vcpu, new_epr); |
Alexander Graf | 324b3e6 | 2013-01-04 18:28:51 +0100 | [diff] [blame] | 1652 | break; |
| 1653 | } |
Mihai Caraman | 352df1d | 2012-10-11 06:13:29 +0000 | [diff] [blame] | 1654 | #if defined(CONFIG_64BIT) |
| 1655 | case KVM_REG_PPC_EPCR: { |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1656 | u32 new_epcr = set_reg_val(id, *val); |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1657 | kvmppc_set_epcr(vcpu, new_epcr); |
Mihai Caraman | 352df1d | 2012-10-11 06:13:29 +0000 | [diff] [blame] | 1658 | break; |
| 1659 | } |
| 1660 | #endif |
Bharat Bhushan | 78accda | 2013-02-24 18:57:12 +0000 | [diff] [blame] | 1661 | case KVM_REG_PPC_OR_TSR: { |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1662 | u32 tsr_bits = set_reg_val(id, *val); |
Bharat Bhushan | 78accda | 2013-02-24 18:57:12 +0000 | [diff] [blame] | 1663 | kvmppc_set_tsr_bits(vcpu, tsr_bits); |
| 1664 | break; |
| 1665 | } |
| 1666 | case KVM_REG_PPC_CLEAR_TSR: { |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1667 | u32 tsr_bits = set_reg_val(id, *val); |
Bharat Bhushan | 78accda | 2013-02-24 18:57:12 +0000 | [diff] [blame] | 1668 | kvmppc_clr_tsr_bits(vcpu, tsr_bits); |
| 1669 | break; |
| 1670 | } |
| 1671 | case KVM_REG_PPC_TSR: { |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1672 | u32 tsr = set_reg_val(id, *val); |
Bharat Bhushan | 78accda | 2013-02-24 18:57:12 +0000 | [diff] [blame] | 1673 | kvmppc_set_tsr(vcpu, tsr); |
| 1674 | break; |
| 1675 | } |
| 1676 | case KVM_REG_PPC_TCR: { |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1677 | u32 tcr = set_reg_val(id, *val); |
Bharat Bhushan | 78accda | 2013-02-24 18:57:12 +0000 | [diff] [blame] | 1678 | kvmppc_set_tcr(vcpu, tcr); |
| 1679 | break; |
| 1680 | } |
Paul Mackerras | 8b75cbb | 2013-09-20 14:52:37 +1000 | [diff] [blame] | 1681 | case KVM_REG_PPC_VRSAVE: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1682 | vcpu->arch.vrsave = set_reg_val(id, *val); |
Paul Mackerras | 8b75cbb | 2013-09-20 14:52:37 +1000 | [diff] [blame] | 1683 | break; |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1684 | default: |
Mihai Caraman | 8a41ea5 | 2014-08-20 16:36:24 +0300 | [diff] [blame^] | 1685 | r = vcpu->kvm->arch.kvm_ops->set_one_reg(vcpu, id, val); |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1686 | break; |
| 1687 | } |
Mihai Caraman | 35b299e | 2013-04-11 00:03:07 +0000 | [diff] [blame] | 1688 | |
Bharat Bhushan | 6df8d3f | 2012-08-08 21:17:55 +0000 | [diff] [blame] | 1689 | return r; |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1692 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 1693 | { |
| 1694 | return -ENOTSUPP; |
| 1695 | } |
| 1696 | |
| 1697 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 1698 | { |
| 1699 | return -ENOTSUPP; |
| 1700 | } |
| 1701 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1702 | int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, |
| 1703 | struct kvm_translation *tr) |
| 1704 | { |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1705 | int r; |
| 1706 | |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1707 | r = kvmppc_core_vcpu_translate(vcpu, tr); |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1708 | return r; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1709 | } |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 1710 | |
Alexander Graf | 4e75575 | 2009-10-30 05:47:01 +0000 | [diff] [blame] | 1711 | int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) |
| 1712 | { |
| 1713 | return -ENOTSUPP; |
| 1714 | } |
| 1715 | |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 1716 | void kvmppc_core_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 1717 | struct kvm_memory_slot *dont) |
| 1718 | { |
| 1719 | } |
| 1720 | |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 1721 | int kvmppc_core_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 1722 | unsigned long npages) |
| 1723 | { |
| 1724 | return 0; |
| 1725 | } |
| 1726 | |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 1727 | int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 1728 | struct kvm_memory_slot *memslot, |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 1729 | struct kvm_userspace_memory_region *mem) |
| 1730 | { |
| 1731 | return 0; |
| 1732 | } |
| 1733 | |
| 1734 | void kvmppc_core_commit_memory_region(struct kvm *kvm, |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 1735 | struct kvm_userspace_memory_region *mem, |
Takuya Yoshikawa | 8482644 | 2013-02-27 19:45:25 +0900 | [diff] [blame] | 1736 | const struct kvm_memory_slot *old) |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 1737 | { |
| 1738 | } |
| 1739 | |
| 1740 | void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot) |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 1741 | { |
| 1742 | } |
| 1743 | |
Mihai Caraman | 38f9882 | 2012-10-11 06:13:27 +0000 | [diff] [blame] | 1744 | void kvmppc_set_epcr(struct kvm_vcpu *vcpu, u32 new_epcr) |
| 1745 | { |
| 1746 | #if defined(CONFIG_64BIT) |
| 1747 | vcpu->arch.epcr = new_epcr; |
| 1748 | #ifdef CONFIG_KVM_BOOKE_HV |
| 1749 | vcpu->arch.shadow_epcr &= ~SPRN_EPCR_GICM; |
| 1750 | if (vcpu->arch.epcr & SPRN_EPCR_ICM) |
| 1751 | vcpu->arch.shadow_epcr |= SPRN_EPCR_GICM; |
| 1752 | #endif |
| 1753 | #endif |
| 1754 | } |
| 1755 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1756 | void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr) |
| 1757 | { |
| 1758 | vcpu->arch.tcr = new_tcr; |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 1759 | arm_next_watchdog(vcpu); |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1760 | update_timer_ints(vcpu); |
| 1761 | } |
| 1762 | |
| 1763 | void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits) |
| 1764 | { |
| 1765 | set_bits(tsr_bits, &vcpu->arch.tsr); |
| 1766 | smp_wmb(); |
| 1767 | kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu); |
| 1768 | kvm_vcpu_kick(vcpu); |
| 1769 | } |
| 1770 | |
| 1771 | void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits) |
| 1772 | { |
| 1773 | clear_bits(tsr_bits, &vcpu->arch.tsr); |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 1774 | |
| 1775 | /* |
| 1776 | * We may have stopped the watchdog due to |
| 1777 | * being stuck on final expiration. |
| 1778 | */ |
| 1779 | if (tsr_bits & (TSR_ENW | TSR_WIS)) |
| 1780 | arm_next_watchdog(vcpu); |
| 1781 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1782 | update_timer_ints(vcpu); |
| 1783 | } |
| 1784 | |
| 1785 | void kvmppc_decrementer_func(unsigned long data) |
| 1786 | { |
| 1787 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; |
| 1788 | |
Bharat Bhushan | 21bd000 | 2012-05-20 23:21:23 +0000 | [diff] [blame] | 1789 | if (vcpu->arch.tcr & TCR_ARE) { |
| 1790 | vcpu->arch.dec = vcpu->arch.decar; |
| 1791 | kvmppc_emulate_dec(vcpu); |
| 1792 | } |
| 1793 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 1794 | kvmppc_set_tsr_bits(vcpu, TSR_DIS); |
| 1795 | } |
| 1796 | |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 1797 | static int kvmppc_booke_add_breakpoint(struct debug_reg *dbg_reg, |
| 1798 | uint64_t addr, int index) |
| 1799 | { |
| 1800 | switch (index) { |
| 1801 | case 0: |
| 1802 | dbg_reg->dbcr0 |= DBCR0_IAC1; |
| 1803 | dbg_reg->iac1 = addr; |
| 1804 | break; |
| 1805 | case 1: |
| 1806 | dbg_reg->dbcr0 |= DBCR0_IAC2; |
| 1807 | dbg_reg->iac2 = addr; |
| 1808 | break; |
| 1809 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 1810 | case 2: |
| 1811 | dbg_reg->dbcr0 |= DBCR0_IAC3; |
| 1812 | dbg_reg->iac3 = addr; |
| 1813 | break; |
| 1814 | case 3: |
| 1815 | dbg_reg->dbcr0 |= DBCR0_IAC4; |
| 1816 | dbg_reg->iac4 = addr; |
| 1817 | break; |
| 1818 | #endif |
| 1819 | default: |
| 1820 | return -EINVAL; |
| 1821 | } |
| 1822 | |
| 1823 | dbg_reg->dbcr0 |= DBCR0_IDM; |
| 1824 | return 0; |
| 1825 | } |
| 1826 | |
| 1827 | static int kvmppc_booke_add_watchpoint(struct debug_reg *dbg_reg, uint64_t addr, |
| 1828 | int type, int index) |
| 1829 | { |
| 1830 | switch (index) { |
| 1831 | case 0: |
| 1832 | if (type & KVMPPC_DEBUG_WATCH_READ) |
| 1833 | dbg_reg->dbcr0 |= DBCR0_DAC1R; |
| 1834 | if (type & KVMPPC_DEBUG_WATCH_WRITE) |
| 1835 | dbg_reg->dbcr0 |= DBCR0_DAC1W; |
| 1836 | dbg_reg->dac1 = addr; |
| 1837 | break; |
| 1838 | case 1: |
| 1839 | if (type & KVMPPC_DEBUG_WATCH_READ) |
| 1840 | dbg_reg->dbcr0 |= DBCR0_DAC2R; |
| 1841 | if (type & KVMPPC_DEBUG_WATCH_WRITE) |
| 1842 | dbg_reg->dbcr0 |= DBCR0_DAC2W; |
| 1843 | dbg_reg->dac2 = addr; |
| 1844 | break; |
| 1845 | default: |
| 1846 | return -EINVAL; |
| 1847 | } |
| 1848 | |
| 1849 | dbg_reg->dbcr0 |= DBCR0_IDM; |
| 1850 | return 0; |
| 1851 | } |
| 1852 | void kvm_guest_protect_msr(struct kvm_vcpu *vcpu, ulong prot_bitmap, bool set) |
| 1853 | { |
| 1854 | /* XXX: Add similar MSR protection for BookE-PR */ |
| 1855 | #ifdef CONFIG_KVM_BOOKE_HV |
| 1856 | BUG_ON(prot_bitmap & ~(MSRP_UCLEP | MSRP_DEP | MSRP_PMMP)); |
| 1857 | if (set) { |
| 1858 | if (prot_bitmap & MSR_UCLE) |
| 1859 | vcpu->arch.shadow_msrp |= MSRP_UCLEP; |
| 1860 | if (prot_bitmap & MSR_DE) |
| 1861 | vcpu->arch.shadow_msrp |= MSRP_DEP; |
| 1862 | if (prot_bitmap & MSR_PMM) |
| 1863 | vcpu->arch.shadow_msrp |= MSRP_PMMP; |
| 1864 | } else { |
| 1865 | if (prot_bitmap & MSR_UCLE) |
| 1866 | vcpu->arch.shadow_msrp &= ~MSRP_UCLEP; |
| 1867 | if (prot_bitmap & MSR_DE) |
| 1868 | vcpu->arch.shadow_msrp &= ~MSRP_DEP; |
| 1869 | if (prot_bitmap & MSR_PMM) |
| 1870 | vcpu->arch.shadow_msrp &= ~MSRP_PMMP; |
| 1871 | } |
| 1872 | #endif |
| 1873 | } |
| 1874 | |
Alexander Graf | 7d15c06 | 2014-06-20 13:52:36 +0200 | [diff] [blame] | 1875 | int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, enum xlate_instdata xlid, |
| 1876 | enum xlate_readwrite xlrw, struct kvmppc_pte *pte) |
| 1877 | { |
| 1878 | int gtlb_index; |
| 1879 | gpa_t gpaddr; |
| 1880 | |
| 1881 | #ifdef CONFIG_KVM_E500V2 |
| 1882 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 1883 | (eaddr & PAGE_MASK) == vcpu->arch.magic_page_ea) { |
| 1884 | pte->eaddr = eaddr; |
| 1885 | pte->raddr = (vcpu->arch.magic_page_pa & PAGE_MASK) | |
| 1886 | (eaddr & ~PAGE_MASK); |
| 1887 | pte->vpage = eaddr >> PAGE_SHIFT; |
| 1888 | pte->may_read = true; |
| 1889 | pte->may_write = true; |
| 1890 | pte->may_execute = true; |
| 1891 | |
| 1892 | return 0; |
| 1893 | } |
| 1894 | #endif |
| 1895 | |
| 1896 | /* Check the guest TLB. */ |
| 1897 | switch (xlid) { |
| 1898 | case XLATE_INST: |
| 1899 | gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr); |
| 1900 | break; |
| 1901 | case XLATE_DATA: |
| 1902 | gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr); |
| 1903 | break; |
| 1904 | default: |
| 1905 | BUG(); |
| 1906 | } |
| 1907 | |
| 1908 | /* Do we have a TLB entry at all? */ |
| 1909 | if (gtlb_index < 0) |
| 1910 | return -ENOENT; |
| 1911 | |
| 1912 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
| 1913 | |
| 1914 | pte->eaddr = eaddr; |
| 1915 | pte->raddr = (gpaddr & PAGE_MASK) | (eaddr & ~PAGE_MASK); |
| 1916 | pte->vpage = eaddr >> PAGE_SHIFT; |
| 1917 | |
| 1918 | /* XXX read permissions from the guest TLB */ |
| 1919 | pte->may_read = true; |
| 1920 | pte->may_write = true; |
| 1921 | pte->may_execute = true; |
| 1922 | |
| 1923 | return 0; |
| 1924 | } |
| 1925 | |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 1926 | int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, |
| 1927 | struct kvm_guest_debug *dbg) |
| 1928 | { |
| 1929 | struct debug_reg *dbg_reg; |
| 1930 | int n, b = 0, w = 0; |
| 1931 | |
| 1932 | if (!(dbg->control & KVM_GUESTDBG_ENABLE)) { |
Bharat Bhushan | 348ba71 | 2014-08-06 12:08:55 +0530 | [diff] [blame] | 1933 | vcpu->arch.dbg_reg.dbcr0 = 0; |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 1934 | vcpu->guest_debug = 0; |
| 1935 | kvm_guest_protect_msr(vcpu, MSR_DE, false); |
| 1936 | return 0; |
| 1937 | } |
| 1938 | |
| 1939 | kvm_guest_protect_msr(vcpu, MSR_DE, true); |
| 1940 | vcpu->guest_debug = dbg->control; |
Bharat Bhushan | 348ba71 | 2014-08-06 12:08:55 +0530 | [diff] [blame] | 1941 | vcpu->arch.dbg_reg.dbcr0 = 0; |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 1942 | |
| 1943 | if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) |
Bharat Bhushan | 348ba71 | 2014-08-06 12:08:55 +0530 | [diff] [blame] | 1944 | vcpu->arch.dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC; |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 1945 | |
| 1946 | /* Code below handles only HW breakpoints */ |
Bharat Bhushan | 348ba71 | 2014-08-06 12:08:55 +0530 | [diff] [blame] | 1947 | dbg_reg = &(vcpu->arch.dbg_reg); |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 1948 | |
| 1949 | #ifdef CONFIG_KVM_BOOKE_HV |
| 1950 | /* |
| 1951 | * On BookE-HV (e500mc) the guest is always executed with MSR.GS=1 |
| 1952 | * DBCR1 and DBCR2 are set to trigger debug events when MSR.PR is 0 |
| 1953 | */ |
| 1954 | dbg_reg->dbcr1 = 0; |
| 1955 | dbg_reg->dbcr2 = 0; |
| 1956 | #else |
| 1957 | /* |
| 1958 | * On BookE-PR (e500v2) the guest is always executed with MSR.PR=1 |
| 1959 | * We set DBCR1 and DBCR2 to only trigger debug events when MSR.PR |
| 1960 | * is set. |
| 1961 | */ |
| 1962 | dbg_reg->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US | DBCR1_IAC3US | |
| 1963 | DBCR1_IAC4US; |
| 1964 | dbg_reg->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US; |
| 1965 | #endif |
| 1966 | |
| 1967 | if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) |
| 1968 | return 0; |
| 1969 | |
| 1970 | for (n = 0; n < (KVMPPC_BOOKE_IAC_NUM + KVMPPC_BOOKE_DAC_NUM); n++) { |
| 1971 | uint64_t addr = dbg->arch.bp[n].addr; |
| 1972 | uint32_t type = dbg->arch.bp[n].type; |
| 1973 | |
| 1974 | if (type == KVMPPC_DEBUG_NONE) |
| 1975 | continue; |
| 1976 | |
| 1977 | if (type & !(KVMPPC_DEBUG_WATCH_READ | |
| 1978 | KVMPPC_DEBUG_WATCH_WRITE | |
| 1979 | KVMPPC_DEBUG_BREAKPOINT)) |
| 1980 | return -EINVAL; |
| 1981 | |
| 1982 | if (type & KVMPPC_DEBUG_BREAKPOINT) { |
| 1983 | /* Setting H/W breakpoint */ |
| 1984 | if (kvmppc_booke_add_breakpoint(dbg_reg, addr, b++)) |
| 1985 | return -EINVAL; |
| 1986 | } else { |
| 1987 | /* Setting H/W watchpoint */ |
| 1988 | if (kvmppc_booke_add_watchpoint(dbg_reg, addr, |
| 1989 | type, w++)) |
| 1990 | return -EINVAL; |
| 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | return 0; |
| 1995 | } |
| 1996 | |
Scott Wood | 94fa9d9 | 2011-12-20 15:34:22 +0000 | [diff] [blame] | 1997 | void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu) |
| 1998 | { |
Paul Mackerras | a47d72f | 2012-09-20 19:35:51 +0000 | [diff] [blame] | 1999 | vcpu->cpu = smp_processor_id(); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 2000 | current->thread.kvm_vcpu = vcpu; |
Scott Wood | 94fa9d9 | 2011-12-20 15:34:22 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu) |
| 2004 | { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 2005 | current->thread.kvm_vcpu = NULL; |
Paul Mackerras | a47d72f | 2012-09-20 19:35:51 +0000 | [diff] [blame] | 2006 | vcpu->cpu = -1; |
Bharat Bhushan | ce11e48 | 2013-07-04 12:27:47 +0530 | [diff] [blame] | 2007 | |
| 2008 | /* Clear pending debug event in DBSR */ |
| 2009 | kvmppc_clear_dbsr(); |
Scott Wood | 94fa9d9 | 2011-12-20 15:34:22 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2012 | void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu) |
| 2013 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2014 | vcpu->kvm->arch.kvm_ops->mmu_destroy(vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | int kvmppc_core_init_vm(struct kvm *kvm) |
| 2018 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2019 | return kvm->arch.kvm_ops->init_vm(kvm); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) |
| 2023 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2024 | return kvm->arch.kvm_ops->vcpu_create(kvm, id); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) |
| 2028 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2029 | vcpu->kvm->arch.kvm_ops->vcpu_free(vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | void kvmppc_core_destroy_vm(struct kvm *kvm) |
| 2033 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2034 | kvm->arch.kvm_ops->destroy_vm(kvm); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) |
| 2038 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2039 | vcpu->kvm->arch.kvm_ops->vcpu_load(vcpu, cpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) |
| 2043 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 2044 | vcpu->kvm->arch.kvm_ops->vcpu_put(vcpu); |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | int __init kvmppc_booke_init(void) |
| 2048 | { |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 2049 | #ifndef CONFIG_KVM_BOOKE_HV |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 2050 | unsigned long ivor[16]; |
Bharat Bhushan | 1d542d9 | 2013-01-15 22:24:39 +0000 | [diff] [blame] | 2051 | unsigned long *handler = kvmppc_booke_handler_addr; |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 2052 | unsigned long max_ivor = 0; |
Bharat Bhushan | 1d542d9 | 2013-01-15 22:24:39 +0000 | [diff] [blame] | 2053 | unsigned long handler_len; |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 2054 | int i; |
| 2055 | |
| 2056 | /* We install our own exception handlers by hijacking IVPR. IVPR must |
| 2057 | * be 16-bit aligned, so we need a 64KB allocation. */ |
| 2058 | kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO, |
| 2059 | VCPU_SIZE_ORDER); |
| 2060 | if (!kvmppc_booke_handlers) |
| 2061 | return -ENOMEM; |
| 2062 | |
| 2063 | /* XXX make sure our handlers are smaller than Linux's */ |
| 2064 | |
| 2065 | /* Copy our interrupt handlers to match host IVORs. That way we don't |
| 2066 | * have to swap the IVORs on every guest/host transition. */ |
| 2067 | ivor[0] = mfspr(SPRN_IVOR0); |
| 2068 | ivor[1] = mfspr(SPRN_IVOR1); |
| 2069 | ivor[2] = mfspr(SPRN_IVOR2); |
| 2070 | ivor[3] = mfspr(SPRN_IVOR3); |
| 2071 | ivor[4] = mfspr(SPRN_IVOR4); |
| 2072 | ivor[5] = mfspr(SPRN_IVOR5); |
| 2073 | ivor[6] = mfspr(SPRN_IVOR6); |
| 2074 | ivor[7] = mfspr(SPRN_IVOR7); |
| 2075 | ivor[8] = mfspr(SPRN_IVOR8); |
| 2076 | ivor[9] = mfspr(SPRN_IVOR9); |
| 2077 | ivor[10] = mfspr(SPRN_IVOR10); |
| 2078 | ivor[11] = mfspr(SPRN_IVOR11); |
| 2079 | ivor[12] = mfspr(SPRN_IVOR12); |
| 2080 | ivor[13] = mfspr(SPRN_IVOR13); |
| 2081 | ivor[14] = mfspr(SPRN_IVOR14); |
| 2082 | ivor[15] = mfspr(SPRN_IVOR15); |
| 2083 | |
| 2084 | for (i = 0; i < 16; i++) { |
| 2085 | if (ivor[i] > max_ivor) |
Bharat Bhushan | 1d542d9 | 2013-01-15 22:24:39 +0000 | [diff] [blame] | 2086 | max_ivor = i; |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 2087 | |
Bharat Bhushan | 1d542d9 | 2013-01-15 22:24:39 +0000 | [diff] [blame] | 2088 | handler_len = handler[i + 1] - handler[i]; |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 2089 | memcpy((void *)kvmppc_booke_handlers + ivor[i], |
Bharat Bhushan | 1d542d9 | 2013-01-15 22:24:39 +0000 | [diff] [blame] | 2090 | (void *)handler[i], handler_len); |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 2091 | } |
Bharat Bhushan | 1d542d9 | 2013-01-15 22:24:39 +0000 | [diff] [blame] | 2092 | |
| 2093 | handler_len = handler[max_ivor + 1] - handler[max_ivor]; |
| 2094 | flush_icache_range(kvmppc_booke_handlers, kvmppc_booke_handlers + |
| 2095 | ivor[max_ivor] + handler_len); |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 2096 | #endif /* !BOOKE_HV */ |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 2097 | return 0; |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 2098 | } |
| 2099 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 2100 | void __exit kvmppc_booke_exit(void) |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 2101 | { |
| 2102 | free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER); |
| 2103 | kvm_exit(); |
| 2104 | } |