Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009. SUSE Linux Products GmbH. All rights reserved. |
| 3 | * |
| 4 | * Authors: |
| 5 | * Alexander Graf <agraf@suse.de> |
| 6 | * Kevin Wolf <mail@kevin-wolf.de> |
| 7 | * |
| 8 | * Description: |
| 9 | * This file is derived from arch/powerpc/kvm/44x.c, |
| 10 | * by Hollis Blanchard <hollisb@us.ibm.com>. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License, version 2, as |
| 14 | * published by the Free Software Foundation. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kvm_host.h> |
| 18 | #include <linux/err.h> |
Stephen Rothwell | 329d20b | 2010-04-27 15:49:17 +1000 | [diff] [blame] | 19 | #include <linux/slab.h> |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 20 | |
| 21 | #include <asm/reg.h> |
| 22 | #include <asm/cputable.h> |
| 23 | #include <asm/cacheflush.h> |
| 24 | #include <asm/tlbflush.h> |
| 25 | #include <asm/uaccess.h> |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/kvm_ppc.h> |
| 28 | #include <asm/kvm_book3s.h> |
| 29 | #include <asm/mmu_context.h> |
Paul Mackerras | 149dbdb | 2011-06-29 00:16:42 +0000 | [diff] [blame] | 30 | #include <asm/page.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/gfp.h> |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 32 | #include <linux/sched.h> |
| 33 | #include <linux/vmalloc.h> |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 34 | #include <linux/highmem.h> |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 35 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame^] | 36 | #include "trace.h" |
| 37 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 38 | #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU |
| 39 | |
| 40 | /* #define EXIT_DEBUG */ |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 41 | /* #define DEBUG_EXT */ |
| 42 | |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 43 | static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr, |
| 44 | ulong msr); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 45 | |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 46 | /* Some compatibility defines */ |
| 47 | #ifdef CONFIG_PPC_BOOK3S_32 |
| 48 | #define MSR_USER32 MSR_USER |
| 49 | #define MSR_USER64 MSR_USER |
| 50 | #define HW_PAGE_SIZE PAGE_SIZE |
| 51 | #endif |
| 52 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 53 | struct kvm_stats_debugfs_item debugfs_entries[] = { |
| 54 | { "exits", VCPU_STAT(sum_exits) }, |
| 55 | { "mmio", VCPU_STAT(mmio_exits) }, |
| 56 | { "sig", VCPU_STAT(signal_exits) }, |
| 57 | { "sysc", VCPU_STAT(syscall_exits) }, |
| 58 | { "inst_emu", VCPU_STAT(emulated_inst_exits) }, |
| 59 | { "dec", VCPU_STAT(dec_exits) }, |
| 60 | { "ext_intr", VCPU_STAT(ext_intr_exits) }, |
| 61 | { "queue_intr", VCPU_STAT(queue_intr) }, |
| 62 | { "halt_wakeup", VCPU_STAT(halt_wakeup) }, |
| 63 | { "pf_storage", VCPU_STAT(pf_storage) }, |
| 64 | { "sp_storage", VCPU_STAT(sp_storage) }, |
| 65 | { "pf_instruc", VCPU_STAT(pf_instruc) }, |
| 66 | { "sp_instruc", VCPU_STAT(sp_instruc) }, |
| 67 | { "ld", VCPU_STAT(ld) }, |
| 68 | { "ld_slow", VCPU_STAT(ld_slow) }, |
| 69 | { "st", VCPU_STAT(st) }, |
| 70 | { "st_slow", VCPU_STAT(st_slow) }, |
| 71 | { NULL } |
| 72 | }; |
| 73 | |
| 74 | void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu) |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) |
| 83 | { |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 84 | #ifdef CONFIG_PPC_BOOK3S_64 |
| 85 | memcpy(to_svcpu(vcpu)->slb, to_book3s(vcpu)->slb_shadow, sizeof(to_svcpu(vcpu)->slb)); |
| 86 | memcpy(&get_paca()->shadow_vcpu, to_book3s(vcpu)->shadow_vcpu, |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 87 | sizeof(get_paca()->shadow_vcpu)); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 88 | to_svcpu(vcpu)->slb_max = to_book3s(vcpu)->slb_shadow_max; |
| 89 | #endif |
| 90 | |
| 91 | #ifdef CONFIG_PPC_BOOK3S_32 |
| 92 | current->thread.kvm_shadow_vcpu = to_book3s(vcpu)->shadow_vcpu; |
| 93 | #endif |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) |
| 97 | { |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 98 | #ifdef CONFIG_PPC_BOOK3S_64 |
| 99 | memcpy(to_book3s(vcpu)->slb_shadow, to_svcpu(vcpu)->slb, sizeof(to_svcpu(vcpu)->slb)); |
| 100 | memcpy(to_book3s(vcpu)->shadow_vcpu, &get_paca()->shadow_vcpu, |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 101 | sizeof(get_paca()->shadow_vcpu)); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 102 | to_book3s(vcpu)->slb_shadow_max = to_svcpu(vcpu)->slb_max; |
| 103 | #endif |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 104 | |
| 105 | kvmppc_giveup_ext(vcpu, MSR_FP); |
| 106 | kvmppc_giveup_ext(vcpu, MSR_VEC); |
| 107 | kvmppc_giveup_ext(vcpu, MSR_VSX); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 110 | static void kvmppc_recalc_shadow_msr(struct kvm_vcpu *vcpu) |
| 111 | { |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 112 | ulong smsr = vcpu->arch.shared->msr; |
| 113 | |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 114 | /* Guest MSR values */ |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 115 | smsr &= MSR_FE0 | MSR_FE1 | MSR_SF | MSR_SE | MSR_BE | MSR_DE; |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 116 | /* Process MSR values */ |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 117 | smsr |= MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_PR | MSR_EE; |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 118 | /* External providers the guest reserved */ |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 119 | smsr |= (vcpu->arch.shared->msr & vcpu->arch.guest_owned_ext); |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 120 | /* 64-bit Process MSR values */ |
| 121 | #ifdef CONFIG_PPC_BOOK3S_64 |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 122 | smsr |= MSR_ISF | MSR_HV; |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 123 | #endif |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 124 | vcpu->arch.shadow_msr = smsr; |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 125 | } |
| 126 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 127 | void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr) |
| 128 | { |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 129 | ulong old_msr = vcpu->arch.shared->msr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 130 | |
| 131 | #ifdef EXIT_DEBUG |
| 132 | printk(KERN_INFO "KVM: Set MSR to 0x%llx\n", msr); |
| 133 | #endif |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 134 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 135 | msr &= to_book3s(vcpu)->msr_mask; |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 136 | vcpu->arch.shared->msr = msr; |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 137 | kvmppc_recalc_shadow_msr(vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 138 | |
Alexander Graf | 296c19d | 2010-08-15 08:39:19 +0200 | [diff] [blame] | 139 | if (msr & MSR_POW) { |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 140 | if (!vcpu->arch.pending_exceptions) { |
| 141 | kvm_vcpu_block(vcpu); |
| 142 | vcpu->stat.halt_wakeup++; |
Alexander Graf | 296c19d | 2010-08-15 08:39:19 +0200 | [diff] [blame] | 143 | |
| 144 | /* Unset POW bit after we woke up */ |
| 145 | msr &= ~MSR_POW; |
| 146 | vcpu->arch.shared->msr = msr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 150 | if ((vcpu->arch.shared->msr & (MSR_PR|MSR_IR|MSR_DR)) != |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 151 | (old_msr & (MSR_PR|MSR_IR|MSR_DR))) { |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 152 | kvmppc_mmu_flush_segments(vcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 153 | kvmppc_mmu_map_segment(vcpu, kvmppc_get_pc(vcpu)); |
Alexander Graf | 4cb6b7e | 2010-08-02 16:08:22 +0200 | [diff] [blame] | 154 | |
| 155 | /* Preload magic page segment when in kernel mode */ |
| 156 | if (!(msr & MSR_PR) && vcpu->arch.magic_page_pa) { |
| 157 | struct kvm_vcpu_arch *a = &vcpu->arch; |
| 158 | |
| 159 | if (msr & MSR_DR) |
| 160 | kvmppc_mmu_map_segment(vcpu, a->magic_page_ea); |
| 161 | else |
| 162 | kvmppc_mmu_map_segment(vcpu, a->magic_page_pa); |
| 163 | } |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 164 | } |
Alexander Graf | d1bab74 | 2010-02-19 11:00:35 +0100 | [diff] [blame] | 165 | |
| 166 | /* Preload FPU if it's enabled */ |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 167 | if (vcpu->arch.shared->msr & MSR_FP) |
Alexander Graf | d1bab74 | 2010-02-19 11:00:35 +0100 | [diff] [blame] | 168 | kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void kvmppc_inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 flags) |
| 172 | { |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 173 | vcpu->arch.shared->srr0 = kvmppc_get_pc(vcpu); |
| 174 | vcpu->arch.shared->srr1 = vcpu->arch.shared->msr | flags; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 175 | kvmppc_set_pc(vcpu, to_book3s(vcpu)->hior + vec); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 176 | vcpu->arch.mmu.reset_msr(vcpu); |
| 177 | } |
| 178 | |
Alexander Graf | 583617b | 2009-12-21 20:21:23 +0100 | [diff] [blame] | 179 | static int kvmppc_book3s_vec2irqprio(unsigned int vec) |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 180 | { |
| 181 | unsigned int prio; |
| 182 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 183 | switch (vec) { |
| 184 | case 0x100: prio = BOOK3S_IRQPRIO_SYSTEM_RESET; break; |
| 185 | case 0x200: prio = BOOK3S_IRQPRIO_MACHINE_CHECK; break; |
| 186 | case 0x300: prio = BOOK3S_IRQPRIO_DATA_STORAGE; break; |
| 187 | case 0x380: prio = BOOK3S_IRQPRIO_DATA_SEGMENT; break; |
| 188 | case 0x400: prio = BOOK3S_IRQPRIO_INST_STORAGE; break; |
| 189 | case 0x480: prio = BOOK3S_IRQPRIO_INST_SEGMENT; break; |
| 190 | case 0x500: prio = BOOK3S_IRQPRIO_EXTERNAL; break; |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 191 | case 0x501: prio = BOOK3S_IRQPRIO_EXTERNAL_LEVEL; break; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 192 | case 0x600: prio = BOOK3S_IRQPRIO_ALIGNMENT; break; |
| 193 | case 0x700: prio = BOOK3S_IRQPRIO_PROGRAM; break; |
| 194 | case 0x800: prio = BOOK3S_IRQPRIO_FP_UNAVAIL; break; |
| 195 | case 0x900: prio = BOOK3S_IRQPRIO_DECREMENTER; break; |
| 196 | case 0xc00: prio = BOOK3S_IRQPRIO_SYSCALL; break; |
| 197 | case 0xd00: prio = BOOK3S_IRQPRIO_DEBUG; break; |
| 198 | case 0xf20: prio = BOOK3S_IRQPRIO_ALTIVEC; break; |
| 199 | case 0xf40: prio = BOOK3S_IRQPRIO_VSX; break; |
| 200 | default: prio = BOOK3S_IRQPRIO_MAX; break; |
| 201 | } |
| 202 | |
Alexander Graf | 583617b | 2009-12-21 20:21:23 +0100 | [diff] [blame] | 203 | return prio; |
| 204 | } |
| 205 | |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 206 | static void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu, |
| 207 | unsigned int vec) |
| 208 | { |
| 209 | clear_bit(kvmppc_book3s_vec2irqprio(vec), |
| 210 | &vcpu->arch.pending_exceptions); |
Alexander Graf | 9ee18b1 | 2010-08-05 12:24:40 +0200 | [diff] [blame] | 211 | |
| 212 | if (!vcpu->arch.pending_exceptions) |
| 213 | vcpu->arch.shared->int_pending = 0; |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Alexander Graf | 583617b | 2009-12-21 20:21:23 +0100 | [diff] [blame] | 216 | void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec) |
| 217 | { |
| 218 | vcpu->stat.queue_intr++; |
| 219 | |
| 220 | set_bit(kvmppc_book3s_vec2irqprio(vec), |
| 221 | &vcpu->arch.pending_exceptions); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 222 | #ifdef EXIT_DEBUG |
| 223 | printk(KERN_INFO "Queueing interrupt %x\n", vec); |
| 224 | #endif |
| 225 | } |
| 226 | |
| 227 | |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 228 | void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags) |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 229 | { |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 230 | to_book3s(vcpu)->prog_flags = flags; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 231 | kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_PROGRAM); |
| 232 | } |
| 233 | |
| 234 | void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu) |
| 235 | { |
| 236 | kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER); |
| 237 | } |
| 238 | |
| 239 | int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu) |
| 240 | { |
Paul Mackerras | 44075d9 | 2011-05-11 00:38:50 +0000 | [diff] [blame] | 241 | return test_bit(BOOK3S_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 244 | void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu) |
| 245 | { |
| 246 | kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER); |
| 247 | } |
| 248 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 249 | void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 250 | struct kvm_interrupt *irq) |
| 251 | { |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 252 | unsigned int vec = BOOK3S_INTERRUPT_EXTERNAL; |
| 253 | |
| 254 | if (irq->irq == KVM_INTERRUPT_SET_LEVEL) |
| 255 | vec = BOOK3S_INTERRUPT_EXTERNAL_LEVEL; |
| 256 | |
| 257 | kvmppc_book3s_queue_irqprio(vcpu, vec); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Alexander Graf | 1897876 | 2010-03-24 21:48:18 +0100 | [diff] [blame] | 260 | void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu, |
| 261 | struct kvm_interrupt *irq) |
| 262 | { |
| 263 | kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL); |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 264 | kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL_LEVEL); |
Alexander Graf | 1897876 | 2010-03-24 21:48:18 +0100 | [diff] [blame] | 265 | } |
| 266 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 267 | int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority) |
| 268 | { |
| 269 | int deliver = 1; |
| 270 | int vec = 0; |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 271 | ulong flags = 0ULL; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 272 | ulong crit_raw = vcpu->arch.shared->critical; |
| 273 | ulong crit_r1 = kvmppc_get_gpr(vcpu, 1); |
| 274 | bool crit; |
| 275 | |
| 276 | /* Truncate crit indicators in 32 bit mode */ |
| 277 | if (!(vcpu->arch.shared->msr & MSR_SF)) { |
| 278 | crit_raw &= 0xffffffff; |
| 279 | crit_r1 &= 0xffffffff; |
| 280 | } |
| 281 | |
| 282 | /* Critical section when crit == r1 */ |
| 283 | crit = (crit_raw == crit_r1); |
| 284 | /* ... and we're in supervisor mode */ |
| 285 | crit = crit && !(vcpu->arch.shared->msr & MSR_PR); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 286 | |
| 287 | switch (priority) { |
| 288 | case BOOK3S_IRQPRIO_DECREMENTER: |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 289 | deliver = (vcpu->arch.shared->msr & MSR_EE) && !crit; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 290 | vec = BOOK3S_INTERRUPT_DECREMENTER; |
| 291 | break; |
| 292 | case BOOK3S_IRQPRIO_EXTERNAL: |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 293 | case BOOK3S_IRQPRIO_EXTERNAL_LEVEL: |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 294 | deliver = (vcpu->arch.shared->msr & MSR_EE) && !crit; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 295 | vec = BOOK3S_INTERRUPT_EXTERNAL; |
| 296 | break; |
| 297 | case BOOK3S_IRQPRIO_SYSTEM_RESET: |
| 298 | vec = BOOK3S_INTERRUPT_SYSTEM_RESET; |
| 299 | break; |
| 300 | case BOOK3S_IRQPRIO_MACHINE_CHECK: |
| 301 | vec = BOOK3S_INTERRUPT_MACHINE_CHECK; |
| 302 | break; |
| 303 | case BOOK3S_IRQPRIO_DATA_STORAGE: |
| 304 | vec = BOOK3S_INTERRUPT_DATA_STORAGE; |
| 305 | break; |
| 306 | case BOOK3S_IRQPRIO_INST_STORAGE: |
| 307 | vec = BOOK3S_INTERRUPT_INST_STORAGE; |
| 308 | break; |
| 309 | case BOOK3S_IRQPRIO_DATA_SEGMENT: |
| 310 | vec = BOOK3S_INTERRUPT_DATA_SEGMENT; |
| 311 | break; |
| 312 | case BOOK3S_IRQPRIO_INST_SEGMENT: |
| 313 | vec = BOOK3S_INTERRUPT_INST_SEGMENT; |
| 314 | break; |
| 315 | case BOOK3S_IRQPRIO_ALIGNMENT: |
| 316 | vec = BOOK3S_INTERRUPT_ALIGNMENT; |
| 317 | break; |
| 318 | case BOOK3S_IRQPRIO_PROGRAM: |
| 319 | vec = BOOK3S_INTERRUPT_PROGRAM; |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 320 | flags = to_book3s(vcpu)->prog_flags; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 321 | break; |
| 322 | case BOOK3S_IRQPRIO_VSX: |
| 323 | vec = BOOK3S_INTERRUPT_VSX; |
| 324 | break; |
| 325 | case BOOK3S_IRQPRIO_ALTIVEC: |
| 326 | vec = BOOK3S_INTERRUPT_ALTIVEC; |
| 327 | break; |
| 328 | case BOOK3S_IRQPRIO_FP_UNAVAIL: |
| 329 | vec = BOOK3S_INTERRUPT_FP_UNAVAIL; |
| 330 | break; |
| 331 | case BOOK3S_IRQPRIO_SYSCALL: |
| 332 | vec = BOOK3S_INTERRUPT_SYSCALL; |
| 333 | break; |
| 334 | case BOOK3S_IRQPRIO_DEBUG: |
| 335 | vec = BOOK3S_INTERRUPT_TRACE; |
| 336 | break; |
| 337 | case BOOK3S_IRQPRIO_PERFORMANCE_MONITOR: |
| 338 | vec = BOOK3S_INTERRUPT_PERFMON; |
| 339 | break; |
| 340 | default: |
| 341 | deliver = 0; |
| 342 | printk(KERN_ERR "KVM: Unknown interrupt: 0x%x\n", priority); |
| 343 | break; |
| 344 | } |
| 345 | |
| 346 | #if 0 |
| 347 | printk(KERN_INFO "Deliver interrupt 0x%x? %x\n", vec, deliver); |
| 348 | #endif |
| 349 | |
| 350 | if (deliver) |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 351 | kvmppc_inject_interrupt(vcpu, vec, flags); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 352 | |
| 353 | return deliver; |
| 354 | } |
| 355 | |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 356 | /* |
| 357 | * This function determines if an irqprio should be cleared once issued. |
| 358 | */ |
| 359 | static bool clear_irqprio(struct kvm_vcpu *vcpu, unsigned int priority) |
| 360 | { |
| 361 | switch (priority) { |
| 362 | case BOOK3S_IRQPRIO_DECREMENTER: |
| 363 | /* DEC interrupts get cleared by mtdec */ |
| 364 | return false; |
| 365 | case BOOK3S_IRQPRIO_EXTERNAL_LEVEL: |
| 366 | /* External interrupts get cleared by userspace */ |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | return true; |
| 371 | } |
| 372 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 373 | void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu) |
| 374 | { |
| 375 | unsigned long *pending = &vcpu->arch.pending_exceptions; |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame] | 376 | unsigned long old_pending = vcpu->arch.pending_exceptions; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 377 | unsigned int priority; |
| 378 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 379 | #ifdef EXIT_DEBUG |
| 380 | if (vcpu->arch.pending_exceptions) |
| 381 | printk(KERN_EMERG "KVM: Check pending: %lx\n", vcpu->arch.pending_exceptions); |
| 382 | #endif |
| 383 | priority = __ffs(*pending); |
Alexander Graf | ada7ba1 | 2010-04-16 00:11:56 +0200 | [diff] [blame] | 384 | while (priority < BOOK3S_IRQPRIO_MAX) { |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 385 | if (kvmppc_book3s_irqprio_deliver(vcpu, priority) && |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 386 | clear_irqprio(vcpu, priority)) { |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 387 | clear_bit(priority, &vcpu->arch.pending_exceptions); |
| 388 | break; |
| 389 | } |
| 390 | |
| 391 | priority = find_next_bit(pending, |
| 392 | BITS_PER_BYTE * sizeof(*pending), |
| 393 | priority + 1); |
| 394 | } |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame] | 395 | |
| 396 | /* Tell the guest about our interrupt status */ |
| 397 | if (*pending) |
| 398 | vcpu->arch.shared->int_pending = 1; |
| 399 | else if (old_pending) |
| 400 | vcpu->arch.shared->int_pending = 0; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr) |
| 404 | { |
Alexander Graf | b83d4a9 | 2010-04-20 02:49:54 +0200 | [diff] [blame] | 405 | u32 host_pvr; |
| 406 | |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 407 | vcpu->arch.hflags &= ~BOOK3S_HFLAG_SLB; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 408 | vcpu->arch.pvr = pvr; |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 409 | #ifdef CONFIG_PPC_BOOK3S_64 |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 410 | if ((pvr >= 0x330000) && (pvr < 0x70330000)) { |
| 411 | kvmppc_mmu_book3s_64_init(vcpu); |
| 412 | to_book3s(vcpu)->hior = 0xfff00000; |
| 413 | to_book3s(vcpu)->msr_mask = 0xffffffffffffffffULL; |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 414 | } else |
| 415 | #endif |
| 416 | { |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 417 | kvmppc_mmu_book3s_32_init(vcpu); |
| 418 | to_book3s(vcpu)->hior = 0; |
| 419 | to_book3s(vcpu)->msr_mask = 0xffffffffULL; |
| 420 | } |
| 421 | |
| 422 | /* If we are in hypervisor level on 970, we can tell the CPU to |
| 423 | * treat DCBZ as 32 bytes store */ |
| 424 | vcpu->arch.hflags &= ~BOOK3S_HFLAG_DCBZ32; |
| 425 | if (vcpu->arch.mmu.is_dcbz32(vcpu) && (mfmsr() & MSR_HV) && |
| 426 | !strcmp(cur_cpu_spec->platform, "ppc970")) |
| 427 | vcpu->arch.hflags |= BOOK3S_HFLAG_DCBZ32; |
| 428 | |
Alexander Graf | 05b0ab1 | 2010-03-24 21:48:37 +0100 | [diff] [blame] | 429 | /* Cell performs badly if MSR_FEx are set. So let's hope nobody |
| 430 | really needs them in a VM on Cell and force disable them. */ |
| 431 | if (!strcmp(cur_cpu_spec->platform, "ppc-cell-be")) |
| 432 | to_book3s(vcpu)->msr_mask &= ~(MSR_FE0 | MSR_FE1); |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 433 | |
| 434 | #ifdef CONFIG_PPC_BOOK3S_32 |
| 435 | /* 32 bit Book3S always has 32 byte dcbz */ |
| 436 | vcpu->arch.hflags |= BOOK3S_HFLAG_DCBZ32; |
| 437 | #endif |
Alexander Graf | b83d4a9 | 2010-04-20 02:49:54 +0200 | [diff] [blame] | 438 | |
| 439 | /* On some CPUs we can execute paired single operations natively */ |
| 440 | asm ( "mfpvr %0" : "=r"(host_pvr)); |
| 441 | switch (host_pvr) { |
| 442 | case 0x00080200: /* lonestar 2.0 */ |
| 443 | case 0x00088202: /* lonestar 2.2 */ |
| 444 | case 0x70000100: /* gekko 1.0 */ |
| 445 | case 0x00080100: /* gekko 2.0 */ |
| 446 | case 0x00083203: /* gekko 2.3a */ |
| 447 | case 0x00083213: /* gekko 2.3b */ |
| 448 | case 0x00083204: /* gekko 2.4 */ |
| 449 | case 0x00083214: /* gekko 2.4e (8SE) - retail HW2 */ |
| 450 | case 0x00087200: /* broadway */ |
| 451 | vcpu->arch.hflags |= BOOK3S_HFLAG_NATIVE_PS; |
| 452 | /* Enable HID2.PSE - in case we need it later */ |
| 453 | mtspr(SPRN_HID2_GEKKO, mfspr(SPRN_HID2_GEKKO) | (1 << 29)); |
| 454 | } |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 457 | pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn) |
| 458 | { |
| 459 | ulong mp_pa = vcpu->arch.magic_page_pa; |
| 460 | |
| 461 | /* Magic page override */ |
| 462 | if (unlikely(mp_pa) && |
| 463 | unlikely(((gfn << PAGE_SHIFT) & KVM_PAM) == |
| 464 | ((mp_pa & PAGE_MASK) & KVM_PAM))) { |
| 465 | ulong shared_page = ((ulong)vcpu->arch.shared) & PAGE_MASK; |
| 466 | pfn_t pfn; |
| 467 | |
| 468 | pfn = (pfn_t)virt_to_phys((void*)shared_page) >> PAGE_SHIFT; |
| 469 | get_page(pfn_to_page(pfn)); |
| 470 | return pfn; |
| 471 | } |
| 472 | |
| 473 | return gfn_to_pfn(vcpu->kvm, gfn); |
| 474 | } |
| 475 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 476 | /* Book3s_32 CPUs always have 32 bytes cache line size, which Linux assumes. To |
| 477 | * make Book3s_32 Linux work on Book3s_64, we have to make sure we trap dcbz to |
| 478 | * emulate 32 bytes dcbz length. |
| 479 | * |
| 480 | * The Book3s_64 inventors also realized this case and implemented a special bit |
| 481 | * in the HID5 register, which is a hypervisor ressource. Thus we can't use it. |
| 482 | * |
| 483 | * My approach here is to patch the dcbz instruction on executing pages. |
| 484 | */ |
| 485 | static void kvmppc_patch_dcbz(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte) |
| 486 | { |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 487 | struct page *hpage; |
| 488 | u64 hpage_offset; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 489 | u32 *page; |
| 490 | int i; |
| 491 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 492 | hpage = gfn_to_page(vcpu->kvm, pte->raddr >> PAGE_SHIFT); |
Wei Yongjun | 646bab5 | 2010-08-17 10:08:52 +0800 | [diff] [blame] | 493 | if (is_error_page(hpage)) { |
| 494 | kvm_release_page_clean(hpage); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 495 | return; |
Wei Yongjun | 646bab5 | 2010-08-17 10:08:52 +0800 | [diff] [blame] | 496 | } |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 497 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 498 | hpage_offset = pte->raddr & ~PAGE_MASK; |
| 499 | hpage_offset &= ~0xFFFULL; |
| 500 | hpage_offset /= 4; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 501 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 502 | get_page(hpage); |
| 503 | page = kmap_atomic(hpage, KM_USER0); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 504 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 505 | /* patch dcbz into reserved instruction, so we trap */ |
| 506 | for (i=hpage_offset; i < hpage_offset + (HW_PAGE_SIZE / 4); i++) |
| 507 | if ((page[i] & 0xff0007ff) == INS_DCBZ) |
| 508 | page[i] &= 0xfffffff7; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 509 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 510 | kunmap_atomic(page, KM_USER0); |
| 511 | put_page(hpage); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | static int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, bool data, |
| 515 | struct kvmppc_pte *pte) |
| 516 | { |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 517 | int relocated = (vcpu->arch.shared->msr & (data ? MSR_DR : MSR_IR)); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 518 | int r; |
| 519 | |
| 520 | if (relocated) { |
| 521 | r = vcpu->arch.mmu.xlate(vcpu, eaddr, pte, data); |
| 522 | } else { |
| 523 | pte->eaddr = eaddr; |
Alexander Graf | 28e83b4 | 2010-07-29 14:47:52 +0200 | [diff] [blame] | 524 | pte->raddr = eaddr & KVM_PAM; |
Alexander Graf | 3eeafd7 | 2010-03-24 21:48:17 +0100 | [diff] [blame] | 525 | pte->vpage = VSID_REAL | eaddr >> 12; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 526 | pte->may_read = true; |
| 527 | pte->may_write = true; |
| 528 | pte->may_execute = true; |
| 529 | r = 0; |
| 530 | } |
| 531 | |
| 532 | return r; |
| 533 | } |
| 534 | |
| 535 | static hva_t kvmppc_bad_hva(void) |
| 536 | { |
| 537 | return PAGE_OFFSET; |
| 538 | } |
| 539 | |
| 540 | static hva_t kvmppc_pte_to_hva(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte, |
| 541 | bool read) |
| 542 | { |
| 543 | hva_t hpage; |
| 544 | |
| 545 | if (read && !pte->may_read) |
| 546 | goto err; |
| 547 | |
| 548 | if (!read && !pte->may_write) |
| 549 | goto err; |
| 550 | |
| 551 | hpage = gfn_to_hva(vcpu->kvm, pte->raddr >> PAGE_SHIFT); |
| 552 | if (kvm_is_error_hva(hpage)) |
| 553 | goto err; |
| 554 | |
| 555 | return hpage | (pte->raddr & ~PAGE_MASK); |
| 556 | err: |
| 557 | return kvmppc_bad_hva(); |
| 558 | } |
| 559 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 560 | int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, |
| 561 | bool data) |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 562 | { |
| 563 | struct kvmppc_pte pte; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 564 | |
| 565 | vcpu->stat.st++; |
| 566 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 567 | if (kvmppc_xlate(vcpu, *eaddr, data, &pte)) |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 568 | return -ENOENT; |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 569 | |
| 570 | *eaddr = pte.raddr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 571 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 572 | if (!pte.may_write) |
| 573 | return -EPERM; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 574 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 575 | if (kvm_write_guest(vcpu->kvm, pte.raddr, ptr, size)) |
| 576 | return EMULATE_DO_MMIO; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 577 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 578 | return EMULATE_DONE; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 581 | int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 582 | bool data) |
| 583 | { |
| 584 | struct kvmppc_pte pte; |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 585 | hva_t hva = *eaddr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 586 | |
| 587 | vcpu->stat.ld++; |
| 588 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 589 | if (kvmppc_xlate(vcpu, *eaddr, data, &pte)) |
| 590 | goto nopte; |
| 591 | |
| 592 | *eaddr = pte.raddr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 593 | |
| 594 | hva = kvmppc_pte_to_hva(vcpu, &pte, true); |
| 595 | if (kvm_is_error_hva(hva)) |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 596 | goto mmio; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 597 | |
| 598 | if (copy_from_user(ptr, (void __user *)hva, size)) { |
| 599 | printk(KERN_INFO "kvmppc_ld at 0x%lx failed\n", hva); |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 600 | goto mmio; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 603 | return EMULATE_DONE; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 604 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 605 | nopte: |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 606 | return -ENOENT; |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 607 | mmio: |
| 608 | return EMULATE_DO_MMIO; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static int kvmppc_visible_gfn(struct kvm_vcpu *vcpu, gfn_t gfn) |
| 612 | { |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 613 | ulong mp_pa = vcpu->arch.magic_page_pa; |
| 614 | |
| 615 | if (unlikely(mp_pa) && |
| 616 | unlikely((mp_pa & KVM_PAM) >> PAGE_SHIFT == gfn)) { |
| 617 | return 1; |
| 618 | } |
| 619 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 620 | return kvm_is_visible_gfn(vcpu->kvm, gfn); |
| 621 | } |
| 622 | |
| 623 | int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 624 | ulong eaddr, int vec) |
| 625 | { |
| 626 | bool data = (vec == BOOK3S_INTERRUPT_DATA_STORAGE); |
| 627 | int r = RESUME_GUEST; |
| 628 | int relocated; |
| 629 | int page_found = 0; |
| 630 | struct kvmppc_pte pte; |
| 631 | bool is_mmio = false; |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 632 | bool dr = (vcpu->arch.shared->msr & MSR_DR) ? true : false; |
| 633 | bool ir = (vcpu->arch.shared->msr & MSR_IR) ? true : false; |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 634 | u64 vsid; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 635 | |
Alexander Graf | 3eeafd7 | 2010-03-24 21:48:17 +0100 | [diff] [blame] | 636 | relocated = data ? dr : ir; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 637 | |
| 638 | /* Resolve real address if translation turned on */ |
| 639 | if (relocated) { |
| 640 | page_found = vcpu->arch.mmu.xlate(vcpu, eaddr, &pte, data); |
| 641 | } else { |
| 642 | pte.may_execute = true; |
| 643 | pte.may_read = true; |
| 644 | pte.may_write = true; |
Alexander Graf | 28e83b4 | 2010-07-29 14:47:52 +0200 | [diff] [blame] | 645 | pte.raddr = eaddr & KVM_PAM; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 646 | pte.eaddr = eaddr; |
| 647 | pte.vpage = eaddr >> 12; |
Alexander Graf | 3eeafd7 | 2010-03-24 21:48:17 +0100 | [diff] [blame] | 648 | } |
| 649 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 650 | switch (vcpu->arch.shared->msr & (MSR_DR|MSR_IR)) { |
Alexander Graf | 3eeafd7 | 2010-03-24 21:48:17 +0100 | [diff] [blame] | 651 | case 0: |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 652 | pte.vpage |= ((u64)VSID_REAL << (SID_SHIFT - 12)); |
Alexander Graf | 3eeafd7 | 2010-03-24 21:48:17 +0100 | [diff] [blame] | 653 | break; |
| 654 | case MSR_DR: |
Alexander Graf | 3eeafd7 | 2010-03-24 21:48:17 +0100 | [diff] [blame] | 655 | case MSR_IR: |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 656 | vcpu->arch.mmu.esid_to_vsid(vcpu, eaddr >> SID_SHIFT, &vsid); |
| 657 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 658 | if ((vcpu->arch.shared->msr & (MSR_DR|MSR_IR)) == MSR_DR) |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 659 | pte.vpage |= ((u64)VSID_REAL_DR << (SID_SHIFT - 12)); |
| 660 | else |
| 661 | pte.vpage |= ((u64)VSID_REAL_IR << (SID_SHIFT - 12)); |
| 662 | pte.vpage |= vsid; |
| 663 | |
| 664 | if (vsid == -1) |
| 665 | page_found = -EINVAL; |
Alexander Graf | 3eeafd7 | 2010-03-24 21:48:17 +0100 | [diff] [blame] | 666 | break; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | if (vcpu->arch.mmu.is_dcbz32(vcpu) && |
| 670 | (!(vcpu->arch.hflags & BOOK3S_HFLAG_DCBZ32))) { |
| 671 | /* |
| 672 | * If we do the dcbz hack, we have to NX on every execution, |
| 673 | * so we can patch the executing code. This renders our guest |
| 674 | * NX-less. |
| 675 | */ |
| 676 | pte.may_execute = !data; |
| 677 | } |
| 678 | |
| 679 | if (page_found == -ENOENT) { |
| 680 | /* Page not found in guest PTE entries */ |
Alexander Graf | 5e03018 | 2010-07-29 14:47:45 +0200 | [diff] [blame] | 681 | vcpu->arch.shared->dar = kvmppc_get_fault_dar(vcpu); |
Alexander Graf | d562de4 | 2010-07-29 14:47:44 +0200 | [diff] [blame] | 682 | vcpu->arch.shared->dsisr = to_svcpu(vcpu)->fault_dsisr; |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 683 | vcpu->arch.shared->msr |= |
| 684 | (to_svcpu(vcpu)->shadow_srr1 & 0x00000000f8000000ULL); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 685 | kvmppc_book3s_queue_irqprio(vcpu, vec); |
| 686 | } else if (page_found == -EPERM) { |
| 687 | /* Storage protection */ |
Alexander Graf | 5e03018 | 2010-07-29 14:47:45 +0200 | [diff] [blame] | 688 | vcpu->arch.shared->dar = kvmppc_get_fault_dar(vcpu); |
Alexander Graf | d562de4 | 2010-07-29 14:47:44 +0200 | [diff] [blame] | 689 | vcpu->arch.shared->dsisr = |
| 690 | to_svcpu(vcpu)->fault_dsisr & ~DSISR_NOHPTE; |
| 691 | vcpu->arch.shared->dsisr |= DSISR_PROTFAULT; |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 692 | vcpu->arch.shared->msr |= |
| 693 | (to_svcpu(vcpu)->shadow_srr1 & 0x00000000f8000000ULL); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 694 | kvmppc_book3s_queue_irqprio(vcpu, vec); |
| 695 | } else if (page_found == -EINVAL) { |
| 696 | /* Page not found in guest SLB */ |
Alexander Graf | 5e03018 | 2010-07-29 14:47:45 +0200 | [diff] [blame] | 697 | vcpu->arch.shared->dar = kvmppc_get_fault_dar(vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 698 | kvmppc_book3s_queue_irqprio(vcpu, vec + 0x80); |
| 699 | } else if (!is_mmio && |
| 700 | kvmppc_visible_gfn(vcpu, pte.raddr >> PAGE_SHIFT)) { |
| 701 | /* The guest's PTE is not mapped yet. Map on the host */ |
| 702 | kvmppc_mmu_map_page(vcpu, &pte); |
| 703 | if (data) |
| 704 | vcpu->stat.sp_storage++; |
| 705 | else if (vcpu->arch.mmu.is_dcbz32(vcpu) && |
| 706 | (!(vcpu->arch.hflags & BOOK3S_HFLAG_DCBZ32))) |
| 707 | kvmppc_patch_dcbz(vcpu, &pte); |
| 708 | } else { |
| 709 | /* MMIO */ |
| 710 | vcpu->stat.mmio_exits++; |
| 711 | vcpu->arch.paddr_accessed = pte.raddr; |
| 712 | r = kvmppc_emulate_mmio(run, vcpu); |
| 713 | if ( r == RESUME_HOST_NV ) |
| 714 | r = RESUME_HOST; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | return r; |
| 718 | } |
| 719 | |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 720 | static inline int get_fpr_index(int i) |
| 721 | { |
| 722 | #ifdef CONFIG_VSX |
| 723 | i *= 2; |
| 724 | #endif |
| 725 | return i; |
| 726 | } |
| 727 | |
| 728 | /* Give up external provider (FPU, Altivec, VSX) */ |
Alexander Graf | aba3bd7 | 2010-02-19 11:00:39 +0100 | [diff] [blame] | 729 | void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr) |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 730 | { |
| 731 | struct thread_struct *t = ¤t->thread; |
| 732 | u64 *vcpu_fpr = vcpu->arch.fpr; |
Alexander Graf | a2b0766 | 2010-03-24 21:48:31 +0100 | [diff] [blame] | 733 | #ifdef CONFIG_VSX |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 734 | u64 *vcpu_vsx = vcpu->arch.vsr; |
Alexander Graf | a2b0766 | 2010-03-24 21:48:31 +0100 | [diff] [blame] | 735 | #endif |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 736 | u64 *thread_fpr = (u64*)t->fpr; |
| 737 | int i; |
| 738 | |
| 739 | if (!(vcpu->arch.guest_owned_ext & msr)) |
| 740 | return; |
| 741 | |
| 742 | #ifdef DEBUG_EXT |
| 743 | printk(KERN_INFO "Giving up ext 0x%lx\n", msr); |
| 744 | #endif |
| 745 | |
| 746 | switch (msr) { |
| 747 | case MSR_FP: |
| 748 | giveup_fpu(current); |
| 749 | for (i = 0; i < ARRAY_SIZE(vcpu->arch.fpr); i++) |
| 750 | vcpu_fpr[i] = thread_fpr[get_fpr_index(i)]; |
| 751 | |
| 752 | vcpu->arch.fpscr = t->fpscr.val; |
| 753 | break; |
| 754 | case MSR_VEC: |
| 755 | #ifdef CONFIG_ALTIVEC |
| 756 | giveup_altivec(current); |
| 757 | memcpy(vcpu->arch.vr, t->vr, sizeof(vcpu->arch.vr)); |
| 758 | vcpu->arch.vscr = t->vscr; |
| 759 | #endif |
| 760 | break; |
| 761 | case MSR_VSX: |
| 762 | #ifdef CONFIG_VSX |
| 763 | __giveup_vsx(current); |
| 764 | for (i = 0; i < ARRAY_SIZE(vcpu->arch.vsr); i++) |
| 765 | vcpu_vsx[i] = thread_fpr[get_fpr_index(i) + 1]; |
| 766 | #endif |
| 767 | break; |
| 768 | default: |
| 769 | BUG(); |
| 770 | } |
| 771 | |
| 772 | vcpu->arch.guest_owned_ext &= ~msr; |
| 773 | current->thread.regs->msr &= ~msr; |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 774 | kvmppc_recalc_shadow_msr(vcpu); |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 775 | } |
| 776 | |
Alexander Graf | 8963221 | 2010-03-24 21:48:21 +0100 | [diff] [blame] | 777 | static int kvmppc_read_inst(struct kvm_vcpu *vcpu) |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 778 | { |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 779 | ulong srr0 = kvmppc_get_pc(vcpu); |
| 780 | u32 last_inst = kvmppc_get_last_inst(vcpu); |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 781 | int ret; |
| 782 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 783 | ret = kvmppc_ld(vcpu, &srr0, sizeof(u32), &last_inst, false); |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 784 | if (ret == -ENOENT) { |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 785 | ulong msr = vcpu->arch.shared->msr; |
| 786 | |
| 787 | msr = kvmppc_set_field(msr, 33, 33, 1); |
| 788 | msr = kvmppc_set_field(msr, 34, 36, 0); |
| 789 | vcpu->arch.shared->msr = kvmppc_set_field(msr, 42, 47, 0); |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 790 | kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_INST_STORAGE); |
Alexander Graf | 8963221 | 2010-03-24 21:48:21 +0100 | [diff] [blame] | 791 | return EMULATE_AGAIN; |
| 792 | } |
| 793 | |
| 794 | return EMULATE_DONE; |
| 795 | } |
| 796 | |
| 797 | static int kvmppc_check_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr) |
| 798 | { |
| 799 | |
| 800 | /* Need to do paired single emulation? */ |
| 801 | if (!(vcpu->arch.hflags & BOOK3S_HFLAG_PAIRED_SINGLE)) |
| 802 | return EMULATE_DONE; |
| 803 | |
| 804 | /* Read out the instruction */ |
| 805 | if (kvmppc_read_inst(vcpu) == EMULATE_DONE) |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 806 | /* Need to emulate */ |
| 807 | return EMULATE_FAIL; |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 808 | |
| 809 | return EMULATE_AGAIN; |
| 810 | } |
| 811 | |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 812 | /* Handle external providers (FPU, Altivec, VSX) */ |
| 813 | static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr, |
| 814 | ulong msr) |
| 815 | { |
| 816 | struct thread_struct *t = ¤t->thread; |
| 817 | u64 *vcpu_fpr = vcpu->arch.fpr; |
Alexander Graf | a2b0766 | 2010-03-24 21:48:31 +0100 | [diff] [blame] | 818 | #ifdef CONFIG_VSX |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 819 | u64 *vcpu_vsx = vcpu->arch.vsr; |
Alexander Graf | a2b0766 | 2010-03-24 21:48:31 +0100 | [diff] [blame] | 820 | #endif |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 821 | u64 *thread_fpr = (u64*)t->fpr; |
| 822 | int i; |
| 823 | |
Alexander Graf | 3c402a7 | 2010-02-19 11:00:32 +0100 | [diff] [blame] | 824 | /* When we have paired singles, we emulate in software */ |
| 825 | if (vcpu->arch.hflags & BOOK3S_HFLAG_PAIRED_SINGLE) |
| 826 | return RESUME_GUEST; |
| 827 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 828 | if (!(vcpu->arch.shared->msr & msr)) { |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 829 | kvmppc_book3s_queue_irqprio(vcpu, exit_nr); |
| 830 | return RESUME_GUEST; |
| 831 | } |
| 832 | |
Alexander Graf | c245369 | 2010-03-24 21:48:22 +0100 | [diff] [blame] | 833 | /* We already own the ext */ |
| 834 | if (vcpu->arch.guest_owned_ext & msr) { |
| 835 | return RESUME_GUEST; |
| 836 | } |
| 837 | |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 838 | #ifdef DEBUG_EXT |
| 839 | printk(KERN_INFO "Loading up ext 0x%lx\n", msr); |
| 840 | #endif |
| 841 | |
| 842 | current->thread.regs->msr |= msr; |
| 843 | |
| 844 | switch (msr) { |
| 845 | case MSR_FP: |
| 846 | for (i = 0; i < ARRAY_SIZE(vcpu->arch.fpr); i++) |
| 847 | thread_fpr[get_fpr_index(i)] = vcpu_fpr[i]; |
| 848 | |
| 849 | t->fpscr.val = vcpu->arch.fpscr; |
| 850 | t->fpexc_mode = 0; |
| 851 | kvmppc_load_up_fpu(); |
| 852 | break; |
| 853 | case MSR_VEC: |
| 854 | #ifdef CONFIG_ALTIVEC |
| 855 | memcpy(t->vr, vcpu->arch.vr, sizeof(vcpu->arch.vr)); |
| 856 | t->vscr = vcpu->arch.vscr; |
| 857 | t->vrsave = -1; |
| 858 | kvmppc_load_up_altivec(); |
| 859 | #endif |
| 860 | break; |
| 861 | case MSR_VSX: |
| 862 | #ifdef CONFIG_VSX |
| 863 | for (i = 0; i < ARRAY_SIZE(vcpu->arch.vsr); i++) |
| 864 | thread_fpr[get_fpr_index(i) + 1] = vcpu_vsx[i]; |
| 865 | kvmppc_load_up_vsx(); |
| 866 | #endif |
| 867 | break; |
| 868 | default: |
| 869 | BUG(); |
| 870 | } |
| 871 | |
| 872 | vcpu->arch.guest_owned_ext |= msr; |
| 873 | |
Alexander Graf | a76f849 | 2010-01-15 14:49:14 +0100 | [diff] [blame] | 874 | kvmppc_recalc_shadow_msr(vcpu); |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 875 | |
| 876 | return RESUME_GUEST; |
| 877 | } |
| 878 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 879 | int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 880 | unsigned int exit_nr) |
| 881 | { |
| 882 | int r = RESUME_HOST; |
| 883 | |
| 884 | vcpu->stat.sum_exits++; |
| 885 | |
| 886 | run->exit_reason = KVM_EXIT_UNKNOWN; |
| 887 | run->ready_for_interrupt_injection = 1; |
Alexander Graf | bed1ed9 | 2010-08-02 11:06:26 +0200 | [diff] [blame] | 888 | |
| 889 | trace_kvm_book3s_exit(exit_nr, vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 890 | kvm_resched(vcpu); |
| 891 | switch (exit_nr) { |
| 892 | case BOOK3S_INTERRUPT_INST_STORAGE: |
| 893 | vcpu->stat.pf_instruc++; |
Alexander Graf | 61db97c | 2010-04-16 00:11:52 +0200 | [diff] [blame] | 894 | |
| 895 | #ifdef CONFIG_PPC_BOOK3S_32 |
| 896 | /* We set segments as unused segments when invalidating them. So |
| 897 | * treat the respective fault as segment fault. */ |
| 898 | if (to_svcpu(vcpu)->sr[kvmppc_get_pc(vcpu) >> SID_SHIFT] |
| 899 | == SR_INVALID) { |
| 900 | kvmppc_mmu_map_segment(vcpu, kvmppc_get_pc(vcpu)); |
| 901 | r = RESUME_GUEST; |
| 902 | break; |
| 903 | } |
| 904 | #endif |
| 905 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 906 | /* only care about PTEG not found errors, but leave NX alone */ |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 907 | if (to_svcpu(vcpu)->shadow_srr1 & 0x40000000) { |
| 908 | r = kvmppc_handle_pagefault(run, vcpu, kvmppc_get_pc(vcpu), exit_nr); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 909 | vcpu->stat.sp_instruc++; |
| 910 | } else if (vcpu->arch.mmu.is_dcbz32(vcpu) && |
| 911 | (!(vcpu->arch.hflags & BOOK3S_HFLAG_DCBZ32))) { |
| 912 | /* |
| 913 | * XXX If we do the dcbz hack we use the NX bit to flush&patch the page, |
| 914 | * so we can't use the NX bit inside the guest. Let's cross our fingers, |
| 915 | * that no guest that needs the dcbz hack does NX. |
| 916 | */ |
Alexander Graf | af7b4d1 | 2010-04-20 02:49:46 +0200 | [diff] [blame] | 917 | kvmppc_mmu_pte_flush(vcpu, kvmppc_get_pc(vcpu), ~0xFFFUL); |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 918 | r = RESUME_GUEST; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 919 | } else { |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 920 | vcpu->arch.shared->msr |= |
| 921 | to_svcpu(vcpu)->shadow_srr1 & 0x58000000; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 922 | kvmppc_book3s_queue_irqprio(vcpu, exit_nr); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 923 | r = RESUME_GUEST; |
| 924 | } |
| 925 | break; |
| 926 | case BOOK3S_INTERRUPT_DATA_STORAGE: |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 927 | { |
| 928 | ulong dar = kvmppc_get_fault_dar(vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 929 | vcpu->stat.pf_storage++; |
Alexander Graf | 61db97c | 2010-04-16 00:11:52 +0200 | [diff] [blame] | 930 | |
| 931 | #ifdef CONFIG_PPC_BOOK3S_32 |
| 932 | /* We set segments as unused segments when invalidating them. So |
| 933 | * treat the respective fault as segment fault. */ |
| 934 | if ((to_svcpu(vcpu)->sr[dar >> SID_SHIFT]) == SR_INVALID) { |
| 935 | kvmppc_mmu_map_segment(vcpu, dar); |
| 936 | r = RESUME_GUEST; |
| 937 | break; |
| 938 | } |
| 939 | #endif |
| 940 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 941 | /* The only case we need to handle is missing shadow PTEs */ |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 942 | if (to_svcpu(vcpu)->fault_dsisr & DSISR_NOHPTE) { |
| 943 | r = kvmppc_handle_pagefault(run, vcpu, dar, exit_nr); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 944 | } else { |
Alexander Graf | 5e03018 | 2010-07-29 14:47:45 +0200 | [diff] [blame] | 945 | vcpu->arch.shared->dar = dar; |
Alexander Graf | d562de4 | 2010-07-29 14:47:44 +0200 | [diff] [blame] | 946 | vcpu->arch.shared->dsisr = to_svcpu(vcpu)->fault_dsisr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 947 | kvmppc_book3s_queue_irqprio(vcpu, exit_nr); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 948 | r = RESUME_GUEST; |
| 949 | } |
| 950 | break; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 951 | } |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 952 | case BOOK3S_INTERRUPT_DATA_SEGMENT: |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 953 | if (kvmppc_mmu_map_segment(vcpu, kvmppc_get_fault_dar(vcpu)) < 0) { |
Alexander Graf | 5e03018 | 2010-07-29 14:47:45 +0200 | [diff] [blame] | 954 | vcpu->arch.shared->dar = kvmppc_get_fault_dar(vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 955 | kvmppc_book3s_queue_irqprio(vcpu, |
| 956 | BOOK3S_INTERRUPT_DATA_SEGMENT); |
| 957 | } |
| 958 | r = RESUME_GUEST; |
| 959 | break; |
| 960 | case BOOK3S_INTERRUPT_INST_SEGMENT: |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 961 | if (kvmppc_mmu_map_segment(vcpu, kvmppc_get_pc(vcpu)) < 0) { |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 962 | kvmppc_book3s_queue_irqprio(vcpu, |
| 963 | BOOK3S_INTERRUPT_INST_SEGMENT); |
| 964 | } |
| 965 | r = RESUME_GUEST; |
| 966 | break; |
| 967 | /* We're good on these - the host merely wanted to get our attention */ |
| 968 | case BOOK3S_INTERRUPT_DECREMENTER: |
| 969 | vcpu->stat.dec_exits++; |
| 970 | r = RESUME_GUEST; |
| 971 | break; |
| 972 | case BOOK3S_INTERRUPT_EXTERNAL: |
| 973 | vcpu->stat.ext_intr_exits++; |
| 974 | r = RESUME_GUEST; |
| 975 | break; |
Alexander Graf | 7fdaec9 | 2010-04-20 02:49:47 +0200 | [diff] [blame] | 976 | case BOOK3S_INTERRUPT_PERFMON: |
| 977 | r = RESUME_GUEST; |
| 978 | break; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 979 | case BOOK3S_INTERRUPT_PROGRAM: |
| 980 | { |
| 981 | enum emulation_result er; |
Alexander Graf | ff1ca3f | 2010-01-08 02:58:09 +0100 | [diff] [blame] | 982 | ulong flags; |
| 983 | |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 984 | program_interrupt: |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 985 | flags = to_svcpu(vcpu)->shadow_srr1 & 0x1f0000ull; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 986 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 987 | if (vcpu->arch.shared->msr & MSR_PR) { |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 988 | #ifdef EXIT_DEBUG |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 989 | printk(KERN_INFO "Userspace triggered 0x700 exception at 0x%lx (0x%x)\n", kvmppc_get_pc(vcpu), kvmppc_get_last_inst(vcpu)); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 990 | #endif |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 991 | if ((kvmppc_get_last_inst(vcpu) & 0xff0007ff) != |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 992 | (INS_DCBZ & 0xfffffff7)) { |
Alexander Graf | ff1ca3f | 2010-01-08 02:58:09 +0100 | [diff] [blame] | 993 | kvmppc_core_queue_program(vcpu, flags); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 994 | r = RESUME_GUEST; |
| 995 | break; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | vcpu->stat.emulated_inst_exits++; |
| 1000 | er = kvmppc_emulate_instruction(run, vcpu); |
| 1001 | switch (er) { |
| 1002 | case EMULATE_DONE: |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 1003 | r = RESUME_GUEST_NV; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1004 | break; |
Alexander Graf | 37f5bca | 2010-02-19 11:00:31 +0100 | [diff] [blame] | 1005 | case EMULATE_AGAIN: |
| 1006 | r = RESUME_GUEST; |
| 1007 | break; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1008 | case EMULATE_FAIL: |
| 1009 | printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n", |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1010 | __func__, kvmppc_get_pc(vcpu), kvmppc_get_last_inst(vcpu)); |
Alexander Graf | ff1ca3f | 2010-01-08 02:58:09 +0100 | [diff] [blame] | 1011 | kvmppc_core_queue_program(vcpu, flags); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1012 | r = RESUME_GUEST; |
| 1013 | break; |
Alexander Graf | e5c29e9 | 2010-02-19 11:00:43 +0100 | [diff] [blame] | 1014 | case EMULATE_DO_MMIO: |
| 1015 | run->exit_reason = KVM_EXIT_MMIO; |
| 1016 | r = RESUME_HOST_NV; |
| 1017 | break; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1018 | default: |
| 1019 | BUG(); |
| 1020 | } |
| 1021 | break; |
| 1022 | } |
| 1023 | case BOOK3S_INTERRUPT_SYSCALL: |
Alexander Graf | ad0a048 | 2010-03-24 21:48:30 +0100 | [diff] [blame] | 1024 | if (vcpu->arch.osi_enabled && |
| 1025 | (((u32)kvmppc_get_gpr(vcpu, 3)) == OSI_SC_MAGIC_R3) && |
| 1026 | (((u32)kvmppc_get_gpr(vcpu, 4)) == OSI_SC_MAGIC_R4)) { |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 1027 | /* MOL hypercalls */ |
Alexander Graf | ad0a048 | 2010-03-24 21:48:30 +0100 | [diff] [blame] | 1028 | u64 *gprs = run->osi.gprs; |
| 1029 | int i; |
| 1030 | |
| 1031 | run->exit_reason = KVM_EXIT_OSI; |
| 1032 | for (i = 0; i < 32; i++) |
| 1033 | gprs[i] = kvmppc_get_gpr(vcpu, i); |
| 1034 | vcpu->arch.osi_needed = 1; |
| 1035 | r = RESUME_HOST_NV; |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 1036 | } else if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 1037 | (((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) { |
| 1038 | /* KVM PV hypercalls */ |
| 1039 | kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); |
| 1040 | r = RESUME_GUEST; |
Alexander Graf | ad0a048 | 2010-03-24 21:48:30 +0100 | [diff] [blame] | 1041 | } else { |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 1042 | /* Guest syscalls */ |
Alexander Graf | ad0a048 | 2010-03-24 21:48:30 +0100 | [diff] [blame] | 1043 | vcpu->stat.syscall_exits++; |
| 1044 | kvmppc_book3s_queue_irqprio(vcpu, exit_nr); |
| 1045 | r = RESUME_GUEST; |
| 1046 | } |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1047 | break; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1048 | case BOOK3S_INTERRUPT_FP_UNAVAIL: |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1049 | case BOOK3S_INTERRUPT_ALTIVEC: |
| 1050 | case BOOK3S_INTERRUPT_VSX: |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 1051 | { |
| 1052 | int ext_msr = 0; |
| 1053 | |
| 1054 | switch (exit_nr) { |
| 1055 | case BOOK3S_INTERRUPT_FP_UNAVAIL: ext_msr = MSR_FP; break; |
| 1056 | case BOOK3S_INTERRUPT_ALTIVEC: ext_msr = MSR_VEC; break; |
| 1057 | case BOOK3S_INTERRUPT_VSX: ext_msr = MSR_VSX; break; |
| 1058 | } |
| 1059 | |
| 1060 | switch (kvmppc_check_ext(vcpu, exit_nr)) { |
| 1061 | case EMULATE_DONE: |
| 1062 | /* everything ok - let's enable the ext */ |
| 1063 | r = kvmppc_handle_ext(vcpu, exit_nr, ext_msr); |
| 1064 | break; |
| 1065 | case EMULATE_FAIL: |
| 1066 | /* we need to emulate this instruction */ |
| 1067 | goto program_interrupt; |
| 1068 | break; |
| 1069 | default: |
| 1070 | /* nothing to worry about - go again */ |
| 1071 | break; |
| 1072 | } |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1073 | break; |
Alexander Graf | c8c0b6f | 2010-02-19 11:00:34 +0100 | [diff] [blame] | 1074 | } |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 1075 | case BOOK3S_INTERRUPT_ALIGNMENT: |
| 1076 | if (kvmppc_read_inst(vcpu) == EMULATE_DONE) { |
Alexander Graf | d562de4 | 2010-07-29 14:47:44 +0200 | [diff] [blame] | 1077 | vcpu->arch.shared->dsisr = kvmppc_alignment_dsisr(vcpu, |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1078 | kvmppc_get_last_inst(vcpu)); |
Alexander Graf | 5e03018 | 2010-07-29 14:47:45 +0200 | [diff] [blame] | 1079 | vcpu->arch.shared->dar = kvmppc_alignment_dar(vcpu, |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1080 | kvmppc_get_last_inst(vcpu)); |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 1081 | kvmppc_book3s_queue_irqprio(vcpu, exit_nr); |
| 1082 | } |
| 1083 | r = RESUME_GUEST; |
| 1084 | break; |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1085 | case BOOK3S_INTERRUPT_MACHINE_CHECK: |
| 1086 | case BOOK3S_INTERRUPT_TRACE: |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1087 | kvmppc_book3s_queue_irqprio(vcpu, exit_nr); |
| 1088 | r = RESUME_GUEST; |
| 1089 | break; |
| 1090 | default: |
| 1091 | /* Ugh - bork here! What did we get? */ |
Alexander Graf | f7adbba | 2010-01-15 14:49:13 +0100 | [diff] [blame] | 1092 | printk(KERN_EMERG "exit_nr=0x%x | pc=0x%lx | msr=0x%lx\n", |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1093 | exit_nr, kvmppc_get_pc(vcpu), to_svcpu(vcpu)->shadow_srr1); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1094 | r = RESUME_HOST; |
| 1095 | BUG(); |
| 1096 | break; |
| 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | if (!(r & RESUME_HOST)) { |
| 1101 | /* To avoid clobbering exit_reason, only check for signals if |
| 1102 | * we aren't already exiting to userspace for some other |
| 1103 | * reason. */ |
| 1104 | if (signal_pending(current)) { |
| 1105 | #ifdef EXIT_DEBUG |
| 1106 | printk(KERN_EMERG "KVM: Going back to host\n"); |
| 1107 | #endif |
| 1108 | vcpu->stat.signal_exits++; |
| 1109 | run->exit_reason = KVM_EXIT_INTR; |
| 1110 | r = -EINTR; |
| 1111 | } else { |
| 1112 | /* In case an interrupt came in that was triggered |
| 1113 | * from userspace (like DEC), we need to check what |
| 1114 | * to inject now! */ |
| 1115 | kvmppc_core_deliver_interrupts(vcpu); |
| 1116 | } |
| 1117 | } |
| 1118 | |
Alexander Graf | bed1ed9 | 2010-08-02 11:06:26 +0200 | [diff] [blame] | 1119 | trace_kvm_book3s_reenter(r, vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1120 | |
| 1121 | return r; |
| 1122 | } |
| 1123 | |
| 1124 | int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) |
| 1125 | { |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 1130 | { |
| 1131 | int i; |
| 1132 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1133 | regs->pc = kvmppc_get_pc(vcpu); |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1134 | regs->cr = kvmppc_get_cr(vcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1135 | regs->ctr = kvmppc_get_ctr(vcpu); |
| 1136 | regs->lr = kvmppc_get_lr(vcpu); |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1137 | regs->xer = kvmppc_get_xer(vcpu); |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 1138 | regs->msr = vcpu->arch.shared->msr; |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 1139 | regs->srr0 = vcpu->arch.shared->srr0; |
| 1140 | regs->srr1 = vcpu->arch.shared->srr1; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1141 | regs->pid = vcpu->arch.pid; |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 1142 | regs->sprg0 = vcpu->arch.shared->sprg0; |
| 1143 | regs->sprg1 = vcpu->arch.shared->sprg1; |
| 1144 | regs->sprg2 = vcpu->arch.shared->sprg2; |
| 1145 | regs->sprg3 = vcpu->arch.shared->sprg3; |
Peter Tyser | bc9c193 | 2010-12-29 13:51:25 -0600 | [diff] [blame] | 1146 | regs->sprg4 = vcpu->arch.sprg4; |
| 1147 | regs->sprg5 = vcpu->arch.sprg5; |
| 1148 | regs->sprg6 = vcpu->arch.sprg6; |
| 1149 | regs->sprg7 = vcpu->arch.sprg7; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1150 | |
| 1151 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 1152 | regs->gpr[i] = kvmppc_get_gpr(vcpu, i); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1153 | |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 1158 | { |
| 1159 | int i; |
| 1160 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1161 | kvmppc_set_pc(vcpu, regs->pc); |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1162 | kvmppc_set_cr(vcpu, regs->cr); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1163 | kvmppc_set_ctr(vcpu, regs->ctr); |
| 1164 | kvmppc_set_lr(vcpu, regs->lr); |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 1165 | kvmppc_set_xer(vcpu, regs->xer); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1166 | kvmppc_set_msr(vcpu, regs->msr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 1167 | vcpu->arch.shared->srr0 = regs->srr0; |
| 1168 | vcpu->arch.shared->srr1 = regs->srr1; |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 1169 | vcpu->arch.shared->sprg0 = regs->sprg0; |
| 1170 | vcpu->arch.shared->sprg1 = regs->sprg1; |
| 1171 | vcpu->arch.shared->sprg2 = regs->sprg2; |
| 1172 | vcpu->arch.shared->sprg3 = regs->sprg3; |
Peter Tyser | bc9c193 | 2010-12-29 13:51:25 -0600 | [diff] [blame] | 1173 | vcpu->arch.sprg4 = regs->sprg4; |
| 1174 | vcpu->arch.sprg5 = regs->sprg5; |
| 1175 | vcpu->arch.sprg6 = regs->sprg6; |
| 1176 | vcpu->arch.sprg7 = regs->sprg7; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1177 | |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 1178 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
| 1179 | kvmppc_set_gpr(vcpu, i, regs->gpr[i]); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1180 | |
| 1181 | return 0; |
| 1182 | } |
| 1183 | |
| 1184 | int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, |
| 1185 | struct kvm_sregs *sregs) |
| 1186 | { |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 1187 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
| 1188 | int i; |
| 1189 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1190 | sregs->pvr = vcpu->arch.pvr; |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 1191 | |
| 1192 | sregs->u.s.sdr1 = to_book3s(vcpu)->sdr1; |
| 1193 | if (vcpu->arch.hflags & BOOK3S_HFLAG_SLB) { |
| 1194 | for (i = 0; i < 64; i++) { |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame^] | 1195 | sregs->u.s.ppc64.slb[i].slbe = vcpu->arch.slb[i].orige | i; |
| 1196 | sregs->u.s.ppc64.slb[i].slbv = vcpu->arch.slb[i].origv; |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 1197 | } |
| 1198 | } else { |
Alexander Graf | df1bfa2 | 2010-08-03 02:29:27 +0200 | [diff] [blame] | 1199 | for (i = 0; i < 16; i++) |
| 1200 | sregs->u.s.ppc32.sr[i] = vcpu->arch.shared->sr[i]; |
| 1201 | |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 1202 | for (i = 0; i < 8; i++) { |
| 1203 | sregs->u.s.ppc32.ibat[i] = vcpu3s->ibat[i].raw; |
| 1204 | sregs->u.s.ppc32.dbat[i] = vcpu3s->dbat[i].raw; |
| 1205 | } |
| 1206 | } |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1207 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1208 | return 0; |
| 1209 | } |
| 1210 | |
| 1211 | int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, |
| 1212 | struct kvm_sregs *sregs) |
| 1213 | { |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 1214 | struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); |
| 1215 | int i; |
| 1216 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1217 | kvmppc_set_pvr(vcpu, sregs->pvr); |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 1218 | |
| 1219 | vcpu3s->sdr1 = sregs->u.s.sdr1; |
| 1220 | if (vcpu->arch.hflags & BOOK3S_HFLAG_SLB) { |
| 1221 | for (i = 0; i < 64; i++) { |
| 1222 | vcpu->arch.mmu.slbmte(vcpu, sregs->u.s.ppc64.slb[i].slbv, |
| 1223 | sregs->u.s.ppc64.slb[i].slbe); |
| 1224 | } |
| 1225 | } else { |
| 1226 | for (i = 0; i < 16; i++) { |
| 1227 | vcpu->arch.mmu.mtsrin(vcpu, i, sregs->u.s.ppc32.sr[i]); |
| 1228 | } |
| 1229 | for (i = 0; i < 8; i++) { |
| 1230 | kvmppc_set_bat(vcpu, &(vcpu3s->ibat[i]), false, |
| 1231 | (u32)sregs->u.s.ppc32.ibat[i]); |
| 1232 | kvmppc_set_bat(vcpu, &(vcpu3s->ibat[i]), true, |
| 1233 | (u32)(sregs->u.s.ppc32.ibat[i] >> 32)); |
| 1234 | kvmppc_set_bat(vcpu, &(vcpu3s->dbat[i]), false, |
| 1235 | (u32)sregs->u.s.ppc32.dbat[i]); |
| 1236 | kvmppc_set_bat(vcpu, &(vcpu3s->dbat[i]), true, |
| 1237 | (u32)(sregs->u.s.ppc32.dbat[i] >> 32)); |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | /* Flush the MMU after messing with the segments */ |
| 1242 | kvmppc_mmu_pte_flush(vcpu, 0, 0); |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 1243 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1244 | return 0; |
| 1245 | } |
| 1246 | |
| 1247 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 1248 | { |
| 1249 | return -ENOTSUPP; |
| 1250 | } |
| 1251 | |
| 1252 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 1253 | { |
| 1254 | return -ENOTSUPP; |
| 1255 | } |
| 1256 | |
| 1257 | int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, |
| 1258 | struct kvm_translation *tr) |
| 1259 | { |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | /* |
| 1264 | * Get (and clear) the dirty memory log for a memory slot. |
| 1265 | */ |
| 1266 | int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, |
| 1267 | struct kvm_dirty_log *log) |
| 1268 | { |
| 1269 | struct kvm_memory_slot *memslot; |
| 1270 | struct kvm_vcpu *vcpu; |
| 1271 | ulong ga, ga_end; |
| 1272 | int is_dirty = 0; |
Takuya Yoshikawa | 87bf6e7 | 2010-04-12 19:35:35 +0900 | [diff] [blame] | 1273 | int r; |
| 1274 | unsigned long n; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1275 | |
Marcelo Tosatti | 79fac95 | 2009-12-23 14:35:26 -0200 | [diff] [blame] | 1276 | mutex_lock(&kvm->slots_lock); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1277 | |
| 1278 | r = kvm_get_dirty_log(kvm, log, &is_dirty); |
| 1279 | if (r) |
| 1280 | goto out; |
| 1281 | |
| 1282 | /* If nothing is dirty, don't bother messing with page tables. */ |
| 1283 | if (is_dirty) { |
Marcelo Tosatti | 46a26bf | 2009-12-23 14:35:16 -0200 | [diff] [blame] | 1284 | memslot = &kvm->memslots->memslots[log->slot]; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1285 | |
| 1286 | ga = memslot->base_gfn << PAGE_SHIFT; |
| 1287 | ga_end = ga + (memslot->npages << PAGE_SHIFT); |
| 1288 | |
| 1289 | kvm_for_each_vcpu(n, vcpu, kvm) |
| 1290 | kvmppc_mmu_pte_pflush(vcpu, ga, ga_end); |
| 1291 | |
Takuya Yoshikawa | 87bf6e7 | 2010-04-12 19:35:35 +0900 | [diff] [blame] | 1292 | n = kvm_dirty_bitmap_bytes(memslot); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1293 | memset(memslot->dirty_bitmap, 0, n); |
| 1294 | } |
| 1295 | |
| 1296 | r = 0; |
| 1297 | out: |
Marcelo Tosatti | 79fac95 | 2009-12-23 14:35:26 -0200 | [diff] [blame] | 1298 | mutex_unlock(&kvm->slots_lock); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1299 | return r; |
| 1300 | } |
| 1301 | |
| 1302 | int kvmppc_core_check_processor_compat(void) |
| 1303 | { |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
| 1307 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) |
| 1308 | { |
| 1309 | struct kvmppc_vcpu_book3s *vcpu_book3s; |
| 1310 | struct kvm_vcpu *vcpu; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1311 | int err = -ENOMEM; |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 1312 | unsigned long p; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1313 | |
Takuya Yoshikawa | 2653503 | 2010-11-02 10:49:34 +0900 | [diff] [blame] | 1314 | vcpu_book3s = vzalloc(sizeof(struct kvmppc_vcpu_book3s)); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1315 | if (!vcpu_book3s) |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1316 | goto out; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1317 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1318 | vcpu_book3s->shadow_vcpu = (struct kvmppc_book3s_shadow_vcpu *) |
| 1319 | kzalloc(sizeof(*vcpu_book3s->shadow_vcpu), GFP_KERNEL); |
| 1320 | if (!vcpu_book3s->shadow_vcpu) |
| 1321 | goto free_vcpu; |
| 1322 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1323 | vcpu = &vcpu_book3s->vcpu; |
| 1324 | err = kvm_vcpu_init(vcpu, kvm, id); |
| 1325 | if (err) |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1326 | goto free_shadow_vcpu; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1327 | |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 1328 | p = __get_free_page(GFP_KERNEL|__GFP_ZERO); |
| 1329 | /* the real shared page fills the last 4k of our page */ |
| 1330 | vcpu->arch.shared = (void*)(p + PAGE_SIZE - 4096); |
| 1331 | if (!p) |
Alexander Graf | 96bc451 | 2010-07-29 14:47:42 +0200 | [diff] [blame] | 1332 | goto uninit_vcpu; |
| 1333 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1334 | vcpu->arch.host_retip = kvm_return_point; |
| 1335 | vcpu->arch.host_msr = mfmsr(); |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 1336 | #ifdef CONFIG_PPC_BOOK3S_64 |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1337 | /* default to book3s_64 (970fx) */ |
| 1338 | vcpu->arch.pvr = 0x3C0301; |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 1339 | #else |
| 1340 | /* default to book3s_32 (750) */ |
| 1341 | vcpu->arch.pvr = 0x84202; |
| 1342 | #endif |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1343 | kvmppc_set_pvr(vcpu, vcpu->arch.pvr); |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame^] | 1344 | vcpu->arch.slb_nr = 64; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1345 | |
| 1346 | /* remember where some real-mode handlers are */ |
Paul Mackerras | 149dbdb | 2011-06-29 00:16:42 +0000 | [diff] [blame] | 1347 | vcpu->arch.trampoline_lowmem = __pa(kvmppc_handler_lowmem_trampoline); |
| 1348 | vcpu->arch.trampoline_enter = __pa(kvmppc_handler_trampoline_enter); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1349 | vcpu->arch.highmem_handler = (ulong)kvmppc_handler_highmem; |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 1350 | #ifdef CONFIG_PPC_BOOK3S_64 |
Alexander Graf | 021ec9c | 2010-01-08 02:58:06 +0100 | [diff] [blame] | 1351 | vcpu->arch.rmcall = *(ulong*)kvmppc_rmcall; |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 1352 | #else |
| 1353 | vcpu->arch.rmcall = (ulong)kvmppc_rmcall; |
| 1354 | #endif |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1355 | |
| 1356 | vcpu->arch.shadow_msr = MSR_USER64; |
| 1357 | |
Alexander Graf | 9cc5e95 | 2010-04-16 00:11:45 +0200 | [diff] [blame] | 1358 | err = kvmppc_mmu_init(vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1359 | if (err < 0) |
Alexander Graf | 96bc451 | 2010-07-29 14:47:42 +0200 | [diff] [blame] | 1360 | goto uninit_vcpu; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1361 | |
| 1362 | return vcpu; |
| 1363 | |
Alexander Graf | 96bc451 | 2010-07-29 14:47:42 +0200 | [diff] [blame] | 1364 | uninit_vcpu: |
| 1365 | kvm_vcpu_uninit(vcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1366 | free_shadow_vcpu: |
| 1367 | kfree(vcpu_book3s->shadow_vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1368 | free_vcpu: |
Alexander Graf | 032c340 | 2010-02-19 12:24:33 +0100 | [diff] [blame] | 1369 | vfree(vcpu_book3s); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1370 | out: |
| 1371 | return ERR_PTR(err); |
| 1372 | } |
| 1373 | |
| 1374 | void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) |
| 1375 | { |
| 1376 | struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu); |
| 1377 | |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 1378 | free_page((unsigned long)vcpu->arch.shared & PAGE_MASK); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1379 | kvm_vcpu_uninit(vcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 1380 | kfree(vcpu_book3s->shadow_vcpu); |
Alexander Graf | 032c340 | 2010-02-19 12:24:33 +0100 | [diff] [blame] | 1381 | vfree(vcpu_book3s); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | extern int __kvmppc_vcpu_entry(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); |
| 1385 | int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) |
| 1386 | { |
| 1387 | int ret; |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1388 | double fpr[32][TS_FPRWIDTH]; |
| 1389 | unsigned int fpscr; |
| 1390 | int fpexc_mode; |
Alexander Graf | a2b0766 | 2010-03-24 21:48:31 +0100 | [diff] [blame] | 1391 | #ifdef CONFIG_ALTIVEC |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1392 | vector128 vr[32]; |
| 1393 | vector128 vscr; |
| 1394 | unsigned long uninitialized_var(vrsave); |
| 1395 | int used_vr; |
Alexander Graf | a2b0766 | 2010-03-24 21:48:31 +0100 | [diff] [blame] | 1396 | #endif |
| 1397 | #ifdef CONFIG_VSX |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1398 | int used_vsr; |
Alexander Graf | a2b0766 | 2010-03-24 21:48:31 +0100 | [diff] [blame] | 1399 | #endif |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1400 | ulong ext_msr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1401 | |
| 1402 | /* No need to go into the guest when all we do is going out */ |
| 1403 | if (signal_pending(current)) { |
| 1404 | kvm_run->exit_reason = KVM_EXIT_INTR; |
| 1405 | return -EINTR; |
| 1406 | } |
| 1407 | |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1408 | /* Save FPU state in stack */ |
| 1409 | if (current->thread.regs->msr & MSR_FP) |
| 1410 | giveup_fpu(current); |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1411 | memcpy(fpr, current->thread.fpr, sizeof(current->thread.fpr)); |
| 1412 | fpscr = current->thread.fpscr.val; |
| 1413 | fpexc_mode = current->thread.fpexc_mode; |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1414 | |
| 1415 | #ifdef CONFIG_ALTIVEC |
| 1416 | /* Save Altivec state in stack */ |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1417 | used_vr = current->thread.used_vr; |
| 1418 | if (used_vr) { |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1419 | if (current->thread.regs->msr & MSR_VEC) |
| 1420 | giveup_altivec(current); |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1421 | memcpy(vr, current->thread.vr, sizeof(current->thread.vr)); |
| 1422 | vscr = current->thread.vscr; |
| 1423 | vrsave = current->thread.vrsave; |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1424 | } |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1425 | #endif |
| 1426 | |
| 1427 | #ifdef CONFIG_VSX |
| 1428 | /* Save VSX state in stack */ |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1429 | used_vsr = current->thread.used_vsr; |
| 1430 | if (used_vsr && (current->thread.regs->msr & MSR_VSX)) |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1431 | __giveup_vsx(current); |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1432 | #endif |
| 1433 | |
| 1434 | /* Remember the MSR with disabled extensions */ |
| 1435 | ext_msr = current->thread.regs->msr; |
| 1436 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1437 | /* XXX we get called with irq disabled - change that! */ |
| 1438 | local_irq_enable(); |
| 1439 | |
Alexander Graf | d1bab74 | 2010-02-19 11:00:35 +0100 | [diff] [blame] | 1440 | /* Preload FPU if it's enabled */ |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 1441 | if (vcpu->arch.shared->msr & MSR_FP) |
Alexander Graf | d1bab74 | 2010-02-19 11:00:35 +0100 | [diff] [blame] | 1442 | kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP); |
| 1443 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1444 | ret = __kvmppc_vcpu_entry(kvm_run, vcpu); |
| 1445 | |
| 1446 | local_irq_disable(); |
| 1447 | |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1448 | current->thread.regs->msr = ext_msr; |
| 1449 | |
| 1450 | /* Make sure we save the guest FPU/Altivec/VSX state */ |
| 1451 | kvmppc_giveup_ext(vcpu, MSR_FP); |
| 1452 | kvmppc_giveup_ext(vcpu, MSR_VEC); |
| 1453 | kvmppc_giveup_ext(vcpu, MSR_VSX); |
| 1454 | |
| 1455 | /* Restore FPU state from stack */ |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1456 | memcpy(current->thread.fpr, fpr, sizeof(current->thread.fpr)); |
| 1457 | current->thread.fpscr.val = fpscr; |
| 1458 | current->thread.fpexc_mode = fpexc_mode; |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1459 | |
| 1460 | #ifdef CONFIG_ALTIVEC |
| 1461 | /* Restore Altivec state from stack */ |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1462 | if (used_vr && current->thread.used_vr) { |
| 1463 | memcpy(current->thread.vr, vr, sizeof(current->thread.vr)); |
| 1464 | current->thread.vscr = vscr; |
| 1465 | current->thread.vrsave = vrsave; |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1466 | } |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1467 | current->thread.used_vr = used_vr; |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1468 | #endif |
| 1469 | |
| 1470 | #ifdef CONFIG_VSX |
Andreas Schwab | 49f6be8 | 2010-05-31 21:59:13 +0200 | [diff] [blame] | 1471 | current->thread.used_vsr = used_vsr; |
Alexander Graf | 180a34d | 2010-01-15 14:49:11 +0100 | [diff] [blame] | 1472 | #endif |
| 1473 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1474 | return ret; |
| 1475 | } |
| 1476 | |
| 1477 | static int kvmppc_book3s_init(void) |
| 1478 | { |
Alexander Graf | fef093be | 2010-06-30 15:18:46 +0200 | [diff] [blame] | 1479 | int r; |
| 1480 | |
| 1481 | r = kvm_init(NULL, sizeof(struct kvmppc_vcpu_book3s), 0, |
| 1482 | THIS_MODULE); |
| 1483 | |
| 1484 | if (r) |
| 1485 | return r; |
| 1486 | |
| 1487 | r = kvmppc_mmu_hpte_sysinit(); |
| 1488 | |
| 1489 | return r; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | static void kvmppc_book3s_exit(void) |
| 1493 | { |
Alexander Graf | fef093be | 2010-06-30 15:18:46 +0200 | [diff] [blame] | 1494 | kvmppc_mmu_hpte_sysexit(); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 1495 | kvm_exit(); |
| 1496 | } |
| 1497 | |
| 1498 | module_init(kvmppc_book3s_init); |
| 1499 | module_exit(kvmppc_book3s_exit); |