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> |
Paul Gortmaker | 66b15db | 2011-05-27 10:46:24 -0400 | [diff] [blame] | 19 | #include <linux/export.h> |
Stephen Rothwell | 329d20b | 2010-04-27 15:49:17 +1000 | [diff] [blame] | 20 | #include <linux/slab.h> |
Alexander Graf | 398a76c | 2013-12-09 13:53:42 +0100 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/miscdevice.h> |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 23 | |
| 24 | #include <asm/reg.h> |
| 25 | #include <asm/cputable.h> |
| 26 | #include <asm/cacheflush.h> |
| 27 | #include <asm/tlbflush.h> |
| 28 | #include <asm/uaccess.h> |
| 29 | #include <asm/io.h> |
| 30 | #include <asm/kvm_ppc.h> |
| 31 | #include <asm/kvm_book3s.h> |
| 32 | #include <asm/mmu_context.h> |
Paul Mackerras | 149dbdb | 2011-06-29 00:16:42 +0000 | [diff] [blame] | 33 | #include <asm/page.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/gfp.h> |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 35 | #include <linux/sched.h> |
| 36 | #include <linux/vmalloc.h> |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 37 | #include <linux/highmem.h> |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 38 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 39 | #include "book3s.h" |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 40 | #include "trace.h" |
| 41 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 42 | #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU |
| 43 | |
| 44 | /* #define EXIT_DEBUG */ |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 45 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 46 | struct kvm_stats_debugfs_item debugfs_entries[] = { |
| 47 | { "exits", VCPU_STAT(sum_exits) }, |
| 48 | { "mmio", VCPU_STAT(mmio_exits) }, |
| 49 | { "sig", VCPU_STAT(signal_exits) }, |
| 50 | { "sysc", VCPU_STAT(syscall_exits) }, |
| 51 | { "inst_emu", VCPU_STAT(emulated_inst_exits) }, |
| 52 | { "dec", VCPU_STAT(dec_exits) }, |
| 53 | { "ext_intr", VCPU_STAT(ext_intr_exits) }, |
| 54 | { "queue_intr", VCPU_STAT(queue_intr) }, |
| 55 | { "halt_wakeup", VCPU_STAT(halt_wakeup) }, |
| 56 | { "pf_storage", VCPU_STAT(pf_storage) }, |
| 57 | { "sp_storage", VCPU_STAT(sp_storage) }, |
| 58 | { "pf_instruc", VCPU_STAT(pf_instruc) }, |
| 59 | { "sp_instruc", VCPU_STAT(sp_instruc) }, |
| 60 | { "ld", VCPU_STAT(ld) }, |
| 61 | { "ld_slow", VCPU_STAT(ld_slow) }, |
| 62 | { "st", VCPU_STAT(st) }, |
| 63 | { "st_slow", VCPU_STAT(st_slow) }, |
| 64 | { NULL } |
| 65 | }; |
| 66 | |
| 67 | void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu) |
| 72 | { |
| 73 | } |
| 74 | |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 75 | static inline unsigned long kvmppc_interrupt_offset(struct kvm_vcpu *vcpu) |
| 76 | { |
Aneesh Kumar K.V | a78b55d | 2013-10-07 22:18:02 +0530 | [diff] [blame] | 77 | if (!is_kvmppc_hv_enabled(vcpu->kvm)) |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 78 | return to_book3s(vcpu)->hior; |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu, |
| 83 | unsigned long pending_now, unsigned long old_pending) |
| 84 | { |
Aneesh Kumar K.V | a78b55d | 2013-10-07 22:18:02 +0530 | [diff] [blame] | 85 | if (is_kvmppc_hv_enabled(vcpu->kvm)) |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 86 | return; |
| 87 | if (pending_now) |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 88 | kvmppc_set_int_pending(vcpu, 1); |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 89 | else if (old_pending) |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 90 | kvmppc_set_int_pending(vcpu, 0); |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu) |
| 94 | { |
| 95 | ulong crit_raw; |
| 96 | ulong crit_r1; |
| 97 | bool crit; |
| 98 | |
Aneesh Kumar K.V | a78b55d | 2013-10-07 22:18:02 +0530 | [diff] [blame] | 99 | if (is_kvmppc_hv_enabled(vcpu->kvm)) |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 100 | return false; |
| 101 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 102 | crit_raw = kvmppc_get_critical(vcpu); |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 103 | crit_r1 = kvmppc_get_gpr(vcpu, 1); |
| 104 | |
| 105 | /* Truncate crit indicators in 32 bit mode */ |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 106 | if (!(kvmppc_get_msr(vcpu) & MSR_SF)) { |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 107 | crit_raw &= 0xffffffff; |
| 108 | crit_r1 &= 0xffffffff; |
| 109 | } |
| 110 | |
| 111 | /* Critical section when crit == r1 */ |
| 112 | crit = (crit_raw == crit_r1); |
| 113 | /* ... and we're in supervisor mode */ |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 114 | crit = crit && !(kvmppc_get_msr(vcpu) & MSR_PR); |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 115 | |
| 116 | return crit; |
| 117 | } |
| 118 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 119 | void kvmppc_inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 flags) |
| 120 | { |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 121 | kvmppc_set_srr0(vcpu, kvmppc_get_pc(vcpu)); |
| 122 | kvmppc_set_srr1(vcpu, kvmppc_get_msr(vcpu) | flags); |
Paul Mackerras | f05ed4d | 2011-06-29 00:17:58 +0000 | [diff] [blame] | 123 | kvmppc_set_pc(vcpu, kvmppc_interrupt_offset(vcpu) + vec); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 124 | vcpu->arch.mmu.reset_msr(vcpu); |
| 125 | } |
| 126 | |
Alexander Graf | 583617b | 2009-12-21 20:21:23 +0100 | [diff] [blame] | 127 | static int kvmppc_book3s_vec2irqprio(unsigned int vec) |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 128 | { |
| 129 | unsigned int prio; |
| 130 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 131 | switch (vec) { |
| 132 | case 0x100: prio = BOOK3S_IRQPRIO_SYSTEM_RESET; break; |
| 133 | case 0x200: prio = BOOK3S_IRQPRIO_MACHINE_CHECK; break; |
| 134 | case 0x300: prio = BOOK3S_IRQPRIO_DATA_STORAGE; break; |
| 135 | case 0x380: prio = BOOK3S_IRQPRIO_DATA_SEGMENT; break; |
| 136 | case 0x400: prio = BOOK3S_IRQPRIO_INST_STORAGE; break; |
| 137 | case 0x480: prio = BOOK3S_IRQPRIO_INST_SEGMENT; break; |
| 138 | case 0x500: prio = BOOK3S_IRQPRIO_EXTERNAL; break; |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 139 | case 0x501: prio = BOOK3S_IRQPRIO_EXTERNAL_LEVEL; break; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 140 | case 0x600: prio = BOOK3S_IRQPRIO_ALIGNMENT; break; |
| 141 | case 0x700: prio = BOOK3S_IRQPRIO_PROGRAM; break; |
| 142 | case 0x800: prio = BOOK3S_IRQPRIO_FP_UNAVAIL; break; |
| 143 | case 0x900: prio = BOOK3S_IRQPRIO_DECREMENTER; break; |
| 144 | case 0xc00: prio = BOOK3S_IRQPRIO_SYSCALL; break; |
| 145 | case 0xd00: prio = BOOK3S_IRQPRIO_DEBUG; break; |
| 146 | case 0xf20: prio = BOOK3S_IRQPRIO_ALTIVEC; break; |
| 147 | case 0xf40: prio = BOOK3S_IRQPRIO_VSX; break; |
Alexander Graf | 616dff8 | 2014-04-29 16:48:44 +0200 | [diff] [blame] | 148 | case 0xf60: prio = BOOK3S_IRQPRIO_FAC_UNAVAIL; break; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 149 | default: prio = BOOK3S_IRQPRIO_MAX; break; |
| 150 | } |
| 151 | |
Alexander Graf | 583617b | 2009-12-21 20:21:23 +0100 | [diff] [blame] | 152 | return prio; |
| 153 | } |
| 154 | |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 155 | void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu, |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 156 | unsigned int vec) |
| 157 | { |
Paul Mackerras | f05ed4d | 2011-06-29 00:17:58 +0000 | [diff] [blame] | 158 | unsigned long old_pending = vcpu->arch.pending_exceptions; |
| 159 | |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 160 | clear_bit(kvmppc_book3s_vec2irqprio(vec), |
| 161 | &vcpu->arch.pending_exceptions); |
Alexander Graf | 9ee18b1 | 2010-08-05 12:24:40 +0200 | [diff] [blame] | 162 | |
Paul Mackerras | f05ed4d | 2011-06-29 00:17:58 +0000 | [diff] [blame] | 163 | kvmppc_update_int_pending(vcpu, vcpu->arch.pending_exceptions, |
| 164 | old_pending); |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Alexander Graf | 583617b | 2009-12-21 20:21:23 +0100 | [diff] [blame] | 167 | void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec) |
| 168 | { |
| 169 | vcpu->stat.queue_intr++; |
| 170 | |
| 171 | set_bit(kvmppc_book3s_vec2irqprio(vec), |
| 172 | &vcpu->arch.pending_exceptions); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 173 | #ifdef EXIT_DEBUG |
| 174 | printk(KERN_INFO "Queueing interrupt %x\n", vec); |
| 175 | #endif |
| 176 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 177 | EXPORT_SYMBOL_GPL(kvmppc_book3s_queue_irqprio); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 178 | |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 179 | void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags) |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 180 | { |
Paul Mackerras | 3cf658b | 2011-06-29 00:18:52 +0000 | [diff] [blame] | 181 | /* might as well deliver this straight away */ |
| 182 | kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_PROGRAM, flags); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 183 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 184 | EXPORT_SYMBOL_GPL(kvmppc_core_queue_program); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 185 | |
| 186 | void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu) |
| 187 | { |
| 188 | kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER); |
| 189 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 190 | EXPORT_SYMBOL_GPL(kvmppc_core_queue_dec); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 191 | |
| 192 | int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu) |
| 193 | { |
Paul Mackerras | 44075d9 | 2011-05-11 00:38:50 +0000 | [diff] [blame] | 194 | return test_bit(BOOK3S_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 195 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 196 | EXPORT_SYMBOL_GPL(kvmppc_core_pending_dec); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 197 | |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 198 | void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu) |
| 199 | { |
| 200 | kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER); |
| 201 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 202 | EXPORT_SYMBOL_GPL(kvmppc_core_dequeue_dec); |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 203 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 204 | void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 205 | struct kvm_interrupt *irq) |
| 206 | { |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 207 | unsigned int vec = BOOK3S_INTERRUPT_EXTERNAL; |
| 208 | |
| 209 | if (irq->irq == KVM_INTERRUPT_SET_LEVEL) |
| 210 | vec = BOOK3S_INTERRUPT_EXTERNAL_LEVEL; |
| 211 | |
| 212 | kvmppc_book3s_queue_irqprio(vcpu, vec); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Paul Mackerras | 4fe27d2 | 2013-02-14 14:00:25 +0000 | [diff] [blame] | 215 | void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu) |
Alexander Graf | 1897876 | 2010-03-24 21:48:18 +0100 | [diff] [blame] | 216 | { |
| 217 | kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL); |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 218 | kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL_LEVEL); |
Alexander Graf | 1897876 | 2010-03-24 21:48:18 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 221 | int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority) |
| 222 | { |
| 223 | int deliver = 1; |
| 224 | int vec = 0; |
Paul Mackerras | f05ed4d | 2011-06-29 00:17:58 +0000 | [diff] [blame] | 225 | bool crit = kvmppc_critical_section(vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 226 | |
| 227 | switch (priority) { |
| 228 | case BOOK3S_IRQPRIO_DECREMENTER: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 229 | deliver = (kvmppc_get_msr(vcpu) & MSR_EE) && !crit; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 230 | vec = BOOK3S_INTERRUPT_DECREMENTER; |
| 231 | break; |
| 232 | case BOOK3S_IRQPRIO_EXTERNAL: |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 233 | case BOOK3S_IRQPRIO_EXTERNAL_LEVEL: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 234 | deliver = (kvmppc_get_msr(vcpu) & MSR_EE) && !crit; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 235 | vec = BOOK3S_INTERRUPT_EXTERNAL; |
| 236 | break; |
| 237 | case BOOK3S_IRQPRIO_SYSTEM_RESET: |
| 238 | vec = BOOK3S_INTERRUPT_SYSTEM_RESET; |
| 239 | break; |
| 240 | case BOOK3S_IRQPRIO_MACHINE_CHECK: |
| 241 | vec = BOOK3S_INTERRUPT_MACHINE_CHECK; |
| 242 | break; |
| 243 | case BOOK3S_IRQPRIO_DATA_STORAGE: |
| 244 | vec = BOOK3S_INTERRUPT_DATA_STORAGE; |
| 245 | break; |
| 246 | case BOOK3S_IRQPRIO_INST_STORAGE: |
| 247 | vec = BOOK3S_INTERRUPT_INST_STORAGE; |
| 248 | break; |
| 249 | case BOOK3S_IRQPRIO_DATA_SEGMENT: |
| 250 | vec = BOOK3S_INTERRUPT_DATA_SEGMENT; |
| 251 | break; |
| 252 | case BOOK3S_IRQPRIO_INST_SEGMENT: |
| 253 | vec = BOOK3S_INTERRUPT_INST_SEGMENT; |
| 254 | break; |
| 255 | case BOOK3S_IRQPRIO_ALIGNMENT: |
| 256 | vec = BOOK3S_INTERRUPT_ALIGNMENT; |
| 257 | break; |
| 258 | case BOOK3S_IRQPRIO_PROGRAM: |
| 259 | vec = BOOK3S_INTERRUPT_PROGRAM; |
| 260 | break; |
| 261 | case BOOK3S_IRQPRIO_VSX: |
| 262 | vec = BOOK3S_INTERRUPT_VSX; |
| 263 | break; |
| 264 | case BOOK3S_IRQPRIO_ALTIVEC: |
| 265 | vec = BOOK3S_INTERRUPT_ALTIVEC; |
| 266 | break; |
| 267 | case BOOK3S_IRQPRIO_FP_UNAVAIL: |
| 268 | vec = BOOK3S_INTERRUPT_FP_UNAVAIL; |
| 269 | break; |
| 270 | case BOOK3S_IRQPRIO_SYSCALL: |
| 271 | vec = BOOK3S_INTERRUPT_SYSCALL; |
| 272 | break; |
| 273 | case BOOK3S_IRQPRIO_DEBUG: |
| 274 | vec = BOOK3S_INTERRUPT_TRACE; |
| 275 | break; |
| 276 | case BOOK3S_IRQPRIO_PERFORMANCE_MONITOR: |
| 277 | vec = BOOK3S_INTERRUPT_PERFMON; |
| 278 | break; |
Alexander Graf | 616dff8 | 2014-04-29 16:48:44 +0200 | [diff] [blame] | 279 | case BOOK3S_IRQPRIO_FAC_UNAVAIL: |
| 280 | vec = BOOK3S_INTERRUPT_FAC_UNAVAIL; |
| 281 | break; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 282 | default: |
| 283 | deliver = 0; |
| 284 | printk(KERN_ERR "KVM: Unknown interrupt: 0x%x\n", priority); |
| 285 | break; |
| 286 | } |
| 287 | |
| 288 | #if 0 |
| 289 | printk(KERN_INFO "Deliver interrupt 0x%x? %x\n", vec, deliver); |
| 290 | #endif |
| 291 | |
| 292 | if (deliver) |
Paul Mackerras | 3cf658b | 2011-06-29 00:18:52 +0000 | [diff] [blame] | 293 | kvmppc_inject_interrupt(vcpu, vec, 0); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 294 | |
| 295 | return deliver; |
| 296 | } |
| 297 | |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 298 | /* |
| 299 | * This function determines if an irqprio should be cleared once issued. |
| 300 | */ |
| 301 | static bool clear_irqprio(struct kvm_vcpu *vcpu, unsigned int priority) |
| 302 | { |
| 303 | switch (priority) { |
| 304 | case BOOK3S_IRQPRIO_DECREMENTER: |
| 305 | /* DEC interrupts get cleared by mtdec */ |
| 306 | return false; |
| 307 | case BOOK3S_IRQPRIO_EXTERNAL_LEVEL: |
| 308 | /* External interrupts get cleared by userspace */ |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | return true; |
| 313 | } |
| 314 | |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 315 | int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu) |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 316 | { |
| 317 | unsigned long *pending = &vcpu->arch.pending_exceptions; |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame] | 318 | unsigned long old_pending = vcpu->arch.pending_exceptions; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 319 | unsigned int priority; |
| 320 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 321 | #ifdef EXIT_DEBUG |
| 322 | if (vcpu->arch.pending_exceptions) |
| 323 | printk(KERN_EMERG "KVM: Check pending: %lx\n", vcpu->arch.pending_exceptions); |
| 324 | #endif |
| 325 | priority = __ffs(*pending); |
Alexander Graf | ada7ba1 | 2010-04-16 00:11:56 +0200 | [diff] [blame] | 326 | while (priority < BOOK3S_IRQPRIO_MAX) { |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 327 | if (kvmppc_book3s_irqprio_deliver(vcpu, priority) && |
Alexander Graf | 17bd158 | 2010-08-30 10:44:15 +0200 | [diff] [blame] | 328 | clear_irqprio(vcpu, priority)) { |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 329 | clear_bit(priority, &vcpu->arch.pending_exceptions); |
| 330 | break; |
| 331 | } |
| 332 | |
| 333 | priority = find_next_bit(pending, |
| 334 | BITS_PER_BYTE * sizeof(*pending), |
| 335 | priority + 1); |
| 336 | } |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame] | 337 | |
| 338 | /* Tell the guest about our interrupt status */ |
Paul Mackerras | f05ed4d | 2011-06-29 00:17:58 +0000 | [diff] [blame] | 339 | kvmppc_update_int_pending(vcpu, *pending, old_pending); |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 340 | |
| 341 | return 0; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 342 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 343 | EXPORT_SYMBOL_GPL(kvmppc_core_prepare_to_enter); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 344 | |
Paul Mackerras | 93b159b | 2013-09-20 14:52:51 +1000 | [diff] [blame] | 345 | pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, bool writing, |
| 346 | bool *writable) |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 347 | { |
| 348 | ulong mp_pa = vcpu->arch.magic_page_pa; |
| 349 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 350 | if (!(kvmppc_get_msr(vcpu) & MSR_SF)) |
Benjamin Herrenschmidt | bbcc9c0 | 2012-03-13 21:52:44 +0000 | [diff] [blame] | 351 | mp_pa = (uint32_t)mp_pa; |
| 352 | |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 353 | /* Magic page override */ |
| 354 | if (unlikely(mp_pa) && |
| 355 | unlikely(((gfn << PAGE_SHIFT) & KVM_PAM) == |
| 356 | ((mp_pa & PAGE_MASK) & KVM_PAM))) { |
| 357 | ulong shared_page = ((ulong)vcpu->arch.shared) & PAGE_MASK; |
| 358 | pfn_t pfn; |
| 359 | |
| 360 | pfn = (pfn_t)virt_to_phys((void*)shared_page) >> PAGE_SHIFT; |
| 361 | get_page(pfn_to_page(pfn)); |
Paul Mackerras | 93b159b | 2013-09-20 14:52:51 +1000 | [diff] [blame] | 362 | if (writable) |
| 363 | *writable = true; |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 364 | return pfn; |
| 365 | } |
| 366 | |
Paul Mackerras | 93b159b | 2013-09-20 14:52:51 +1000 | [diff] [blame] | 367 | return gfn_to_pfn_prot(vcpu->kvm, gfn, writing, writable); |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 368 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 369 | EXPORT_SYMBOL_GPL(kvmppc_gfn_to_pfn); |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 370 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 371 | static int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, bool data, |
Paul Mackerras | 93b159b | 2013-09-20 14:52:51 +1000 | [diff] [blame] | 372 | bool iswrite, struct kvmppc_pte *pte) |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 373 | { |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 374 | int relocated = (kvmppc_get_msr(vcpu) & (data ? MSR_DR : MSR_IR)); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 375 | int r; |
| 376 | |
| 377 | if (relocated) { |
Paul Mackerras | 93b159b | 2013-09-20 14:52:51 +1000 | [diff] [blame] | 378 | r = vcpu->arch.mmu.xlate(vcpu, eaddr, pte, data, iswrite); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 379 | } else { |
| 380 | pte->eaddr = eaddr; |
Alexander Graf | 28e83b4 | 2010-07-29 14:47:52 +0200 | [diff] [blame] | 381 | pte->raddr = eaddr & KVM_PAM; |
Alexander Graf | 3eeafd7 | 2010-03-24 21:48:17 +0100 | [diff] [blame] | 382 | pte->vpage = VSID_REAL | eaddr >> 12; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 383 | pte->may_read = true; |
| 384 | pte->may_write = true; |
| 385 | pte->may_execute = true; |
| 386 | r = 0; |
| 387 | } |
| 388 | |
| 389 | return r; |
| 390 | } |
| 391 | |
| 392 | static hva_t kvmppc_bad_hva(void) |
| 393 | { |
| 394 | return PAGE_OFFSET; |
| 395 | } |
| 396 | |
| 397 | static hva_t kvmppc_pte_to_hva(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte, |
| 398 | bool read) |
| 399 | { |
| 400 | hva_t hpage; |
| 401 | |
| 402 | if (read && !pte->may_read) |
| 403 | goto err; |
| 404 | |
| 405 | if (!read && !pte->may_write) |
| 406 | goto err; |
| 407 | |
| 408 | hpage = gfn_to_hva(vcpu->kvm, pte->raddr >> PAGE_SHIFT); |
| 409 | if (kvm_is_error_hva(hpage)) |
| 410 | goto err; |
| 411 | |
| 412 | return hpage | (pte->raddr & ~PAGE_MASK); |
| 413 | err: |
| 414 | return kvmppc_bad_hva(); |
| 415 | } |
| 416 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 417 | int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, |
| 418 | bool data) |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 419 | { |
| 420 | struct kvmppc_pte pte; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 421 | |
| 422 | vcpu->stat.st++; |
| 423 | |
Paul Mackerras | 93b159b | 2013-09-20 14:52:51 +1000 | [diff] [blame] | 424 | if (kvmppc_xlate(vcpu, *eaddr, data, true, &pte)) |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 425 | return -ENOENT; |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 426 | |
| 427 | *eaddr = pte.raddr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 428 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 429 | if (!pte.may_write) |
| 430 | return -EPERM; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 431 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 432 | if (kvm_write_guest(vcpu->kvm, pte.raddr, ptr, size)) |
| 433 | return EMULATE_DO_MMIO; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 434 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 435 | return EMULATE_DONE; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 436 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 437 | EXPORT_SYMBOL_GPL(kvmppc_st); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 438 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 439 | 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] | 440 | bool data) |
| 441 | { |
| 442 | struct kvmppc_pte pte; |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 443 | hva_t hva = *eaddr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 444 | |
| 445 | vcpu->stat.ld++; |
| 446 | |
Paul Mackerras | 93b159b | 2013-09-20 14:52:51 +1000 | [diff] [blame] | 447 | if (kvmppc_xlate(vcpu, *eaddr, data, false, &pte)) |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 448 | goto nopte; |
| 449 | |
| 450 | *eaddr = pte.raddr; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 451 | |
| 452 | hva = kvmppc_pte_to_hva(vcpu, &pte, true); |
| 453 | if (kvm_is_error_hva(hva)) |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 454 | goto mmio; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 455 | |
| 456 | if (copy_from_user(ptr, (void __user *)hva, size)) { |
| 457 | printk(KERN_INFO "kvmppc_ld at 0x%lx failed\n", hva); |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 458 | goto mmio; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 461 | return EMULATE_DONE; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 462 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 463 | nopte: |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 464 | return -ENOENT; |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 465 | mmio: |
| 466 | return EMULATE_DO_MMIO; |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 467 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 468 | EXPORT_SYMBOL_GPL(kvmppc_ld); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 469 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 470 | int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) |
| 471 | { |
| 472 | return 0; |
| 473 | } |
| 474 | |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 475 | int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu) |
| 476 | { |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu) |
| 481 | { |
| 482 | } |
| 483 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 484 | int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, |
| 485 | struct kvm_sregs *sregs) |
| 486 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 487 | return vcpu->kvm->arch.kvm_ops->get_sregs(vcpu, sregs); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, |
| 491 | struct kvm_sregs *sregs) |
| 492 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 493 | return vcpu->kvm->arch.kvm_ops->set_sregs(vcpu, sregs); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 494 | } |
| 495 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 496 | int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 497 | { |
| 498 | int i; |
| 499 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 500 | regs->pc = kvmppc_get_pc(vcpu); |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 501 | regs->cr = kvmppc_get_cr(vcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 502 | regs->ctr = kvmppc_get_ctr(vcpu); |
| 503 | regs->lr = kvmppc_get_lr(vcpu); |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 504 | regs->xer = kvmppc_get_xer(vcpu); |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 505 | regs->msr = kvmppc_get_msr(vcpu); |
| 506 | regs->srr0 = kvmppc_get_srr0(vcpu); |
| 507 | regs->srr1 = kvmppc_get_srr1(vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 508 | regs->pid = vcpu->arch.pid; |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 509 | regs->sprg0 = kvmppc_get_sprg0(vcpu); |
| 510 | regs->sprg1 = kvmppc_get_sprg1(vcpu); |
| 511 | regs->sprg2 = kvmppc_get_sprg2(vcpu); |
| 512 | regs->sprg3 = kvmppc_get_sprg3(vcpu); |
| 513 | regs->sprg4 = kvmppc_get_sprg4(vcpu); |
| 514 | regs->sprg5 = kvmppc_get_sprg5(vcpu); |
| 515 | regs->sprg6 = kvmppc_get_sprg6(vcpu); |
| 516 | regs->sprg7 = kvmppc_get_sprg7(vcpu); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 517 | |
| 518 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 519 | regs->gpr[i] = kvmppc_get_gpr(vcpu, i); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 525 | { |
| 526 | int i; |
| 527 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 528 | kvmppc_set_pc(vcpu, regs->pc); |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 529 | kvmppc_set_cr(vcpu, regs->cr); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 530 | kvmppc_set_ctr(vcpu, regs->ctr); |
| 531 | kvmppc_set_lr(vcpu, regs->lr); |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 532 | kvmppc_set_xer(vcpu, regs->xer); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 533 | kvmppc_set_msr(vcpu, regs->msr); |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 534 | kvmppc_set_srr0(vcpu, regs->srr0); |
| 535 | kvmppc_set_srr1(vcpu, regs->srr1); |
| 536 | kvmppc_set_sprg0(vcpu, regs->sprg0); |
| 537 | kvmppc_set_sprg1(vcpu, regs->sprg1); |
| 538 | kvmppc_set_sprg2(vcpu, regs->sprg2); |
| 539 | kvmppc_set_sprg3(vcpu, regs->sprg3); |
| 540 | kvmppc_set_sprg4(vcpu, regs->sprg4); |
| 541 | kvmppc_set_sprg5(vcpu, regs->sprg5); |
| 542 | kvmppc_set_sprg6(vcpu, regs->sprg6); |
| 543 | kvmppc_set_sprg7(vcpu, regs->sprg7); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 544 | |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 545 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
| 546 | kvmppc_set_gpr(vcpu, i, regs->gpr[i]); |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 551 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 552 | { |
| 553 | return -ENOTSUPP; |
| 554 | } |
| 555 | |
| 556 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 557 | { |
| 558 | return -ENOTSUPP; |
| 559 | } |
| 560 | |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 561 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
| 562 | { |
| 563 | int r; |
| 564 | union kvmppc_one_reg val; |
| 565 | int size; |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 566 | long int i; |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 567 | |
| 568 | size = one_reg_size(reg->id); |
| 569 | if (size > sizeof(val)) |
| 570 | return -EINVAL; |
| 571 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 572 | r = vcpu->kvm->arch.kvm_ops->get_one_reg(vcpu, reg->id, &val); |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 573 | if (r == -EINVAL) { |
| 574 | r = 0; |
| 575 | switch (reg->id) { |
| 576 | case KVM_REG_PPC_DAR: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 577 | val = get_reg_val(reg->id, kvmppc_get_dar(vcpu)); |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 578 | break; |
| 579 | case KVM_REG_PPC_DSISR: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 580 | val = get_reg_val(reg->id, kvmppc_get_dsisr(vcpu)); |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 581 | break; |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 582 | case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31: |
| 583 | i = reg->id - KVM_REG_PPC_FPR0; |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 584 | val = get_reg_val(reg->id, VCPU_FPR(vcpu, i)); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 585 | break; |
| 586 | case KVM_REG_PPC_FPSCR: |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 587 | val = get_reg_val(reg->id, vcpu->arch.fp.fpscr); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 588 | break; |
| 589 | #ifdef CONFIG_ALTIVEC |
| 590 | case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31: |
| 591 | if (!cpu_has_feature(CPU_FTR_ALTIVEC)) { |
| 592 | r = -ENXIO; |
| 593 | break; |
| 594 | } |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 595 | val.vval = vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0]; |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 596 | break; |
| 597 | case KVM_REG_PPC_VSCR: |
| 598 | if (!cpu_has_feature(CPU_FTR_ALTIVEC)) { |
| 599 | r = -ENXIO; |
| 600 | break; |
| 601 | } |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 602 | val = get_reg_val(reg->id, vcpu->arch.vr.vscr.u[3]); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 603 | break; |
Paul Mackerras | c0867fd | 2013-09-06 13:18:32 +1000 | [diff] [blame] | 604 | case KVM_REG_PPC_VRSAVE: |
| 605 | val = get_reg_val(reg->id, vcpu->arch.vrsave); |
| 606 | break; |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 607 | #endif /* CONFIG_ALTIVEC */ |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 608 | #ifdef CONFIG_VSX |
| 609 | case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31: |
| 610 | if (cpu_has_feature(CPU_FTR_VSX)) { |
| 611 | long int i = reg->id - KVM_REG_PPC_VSR0; |
| 612 | val.vsxval[0] = vcpu->arch.fp.fpr[i][0]; |
| 613 | val.vsxval[1] = vcpu->arch.fp.fpr[i][1]; |
| 614 | } else { |
| 615 | r = -ENXIO; |
| 616 | } |
| 617 | break; |
| 618 | #endif /* CONFIG_VSX */ |
Bharat Bhushan | 8c32a2e | 2013-03-20 20:24:58 +0000 | [diff] [blame] | 619 | case KVM_REG_PPC_DEBUG_INST: { |
| 620 | u32 opcode = INS_TW; |
| 621 | r = copy_to_user((u32 __user *)(long)reg->addr, |
| 622 | &opcode, sizeof(u32)); |
| 623 | break; |
| 624 | } |
Paul Mackerras | 8b78645 | 2013-04-17 20:32:26 +0000 | [diff] [blame] | 625 | #ifdef CONFIG_KVM_XICS |
| 626 | case KVM_REG_PPC_ICP_STATE: |
| 627 | if (!vcpu->arch.icp) { |
| 628 | r = -ENXIO; |
| 629 | break; |
| 630 | } |
| 631 | val = get_reg_val(reg->id, kvmppc_xics_get_icp(vcpu)); |
| 632 | break; |
| 633 | #endif /* CONFIG_KVM_XICS */ |
Alexander Graf | 616dff8 | 2014-04-29 16:48:44 +0200 | [diff] [blame] | 634 | case KVM_REG_PPC_FSCR: |
| 635 | val = get_reg_val(reg->id, vcpu->arch.fscr); |
| 636 | break; |
Alexander Graf | e14e7a1 | 2014-04-22 12:26:58 +0200 | [diff] [blame] | 637 | case KVM_REG_PPC_TAR: |
| 638 | val = get_reg_val(reg->id, vcpu->arch.tar); |
| 639 | break; |
Alexander Graf | 2e23f54 | 2014-04-29 13:36:21 +0200 | [diff] [blame] | 640 | case KVM_REG_PPC_EBBHR: |
| 641 | val = get_reg_val(reg->id, vcpu->arch.ebbhr); |
| 642 | break; |
| 643 | case KVM_REG_PPC_EBBRR: |
| 644 | val = get_reg_val(reg->id, vcpu->arch.ebbrr); |
| 645 | break; |
| 646 | case KVM_REG_PPC_BESCR: |
| 647 | val = get_reg_val(reg->id, vcpu->arch.bescr); |
| 648 | break; |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 649 | default: |
| 650 | r = -EINVAL; |
| 651 | break; |
| 652 | } |
| 653 | } |
| 654 | if (r) |
| 655 | return r; |
| 656 | |
| 657 | if (copy_to_user((char __user *)(unsigned long)reg->addr, &val, size)) |
| 658 | r = -EFAULT; |
| 659 | |
| 660 | return r; |
| 661 | } |
| 662 | |
| 663 | int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
| 664 | { |
| 665 | int r; |
| 666 | union kvmppc_one_reg val; |
| 667 | int size; |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 668 | long int i; |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 669 | |
| 670 | size = one_reg_size(reg->id); |
| 671 | if (size > sizeof(val)) |
| 672 | return -EINVAL; |
| 673 | |
| 674 | if (copy_from_user(&val, (char __user *)(unsigned long)reg->addr, size)) |
| 675 | return -EFAULT; |
| 676 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 677 | r = vcpu->kvm->arch.kvm_ops->set_one_reg(vcpu, reg->id, &val); |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 678 | if (r == -EINVAL) { |
| 679 | r = 0; |
| 680 | switch (reg->id) { |
| 681 | case KVM_REG_PPC_DAR: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 682 | kvmppc_set_dar(vcpu, set_reg_val(reg->id, val)); |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 683 | break; |
| 684 | case KVM_REG_PPC_DSISR: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 685 | kvmppc_set_dsisr(vcpu, set_reg_val(reg->id, val)); |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 686 | break; |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 687 | case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31: |
| 688 | i = reg->id - KVM_REG_PPC_FPR0; |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 689 | VCPU_FPR(vcpu, i) = set_reg_val(reg->id, val); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 690 | break; |
| 691 | case KVM_REG_PPC_FPSCR: |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 692 | vcpu->arch.fp.fpscr = set_reg_val(reg->id, val); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 693 | break; |
| 694 | #ifdef CONFIG_ALTIVEC |
| 695 | case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31: |
| 696 | if (!cpu_has_feature(CPU_FTR_ALTIVEC)) { |
| 697 | r = -ENXIO; |
| 698 | break; |
| 699 | } |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 700 | vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0] = val.vval; |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 701 | break; |
| 702 | case KVM_REG_PPC_VSCR: |
| 703 | if (!cpu_has_feature(CPU_FTR_ALTIVEC)) { |
| 704 | r = -ENXIO; |
| 705 | break; |
| 706 | } |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 707 | vcpu->arch.vr.vscr.u[3] = set_reg_val(reg->id, val); |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 708 | break; |
Paul Mackerras | c0867fd | 2013-09-06 13:18:32 +1000 | [diff] [blame] | 709 | case KVM_REG_PPC_VRSAVE: |
| 710 | if (!cpu_has_feature(CPU_FTR_ALTIVEC)) { |
| 711 | r = -ENXIO; |
| 712 | break; |
| 713 | } |
| 714 | vcpu->arch.vrsave = set_reg_val(reg->id, val); |
| 715 | break; |
Paul Mackerras | a8bd19e | 2012-09-25 20:32:30 +0000 | [diff] [blame] | 716 | #endif /* CONFIG_ALTIVEC */ |
Paul Mackerras | efff191 | 2013-10-15 20:43:02 +1100 | [diff] [blame] | 717 | #ifdef CONFIG_VSX |
| 718 | case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31: |
| 719 | if (cpu_has_feature(CPU_FTR_VSX)) { |
| 720 | long int i = reg->id - KVM_REG_PPC_VSR0; |
| 721 | vcpu->arch.fp.fpr[i][0] = val.vsxval[0]; |
| 722 | vcpu->arch.fp.fpr[i][1] = val.vsxval[1]; |
| 723 | } else { |
| 724 | r = -ENXIO; |
| 725 | } |
| 726 | break; |
| 727 | #endif /* CONFIG_VSX */ |
Paul Mackerras | 8b78645 | 2013-04-17 20:32:26 +0000 | [diff] [blame] | 728 | #ifdef CONFIG_KVM_XICS |
| 729 | case KVM_REG_PPC_ICP_STATE: |
| 730 | if (!vcpu->arch.icp) { |
| 731 | r = -ENXIO; |
| 732 | break; |
| 733 | } |
| 734 | r = kvmppc_xics_set_icp(vcpu, |
| 735 | set_reg_val(reg->id, val)); |
| 736 | break; |
| 737 | #endif /* CONFIG_KVM_XICS */ |
Alexander Graf | 616dff8 | 2014-04-29 16:48:44 +0200 | [diff] [blame] | 738 | case KVM_REG_PPC_FSCR: |
| 739 | vcpu->arch.fscr = set_reg_val(reg->id, val); |
| 740 | break; |
Alexander Graf | e14e7a1 | 2014-04-22 12:26:58 +0200 | [diff] [blame] | 741 | case KVM_REG_PPC_TAR: |
| 742 | vcpu->arch.tar = set_reg_val(reg->id, val); |
| 743 | break; |
Alexander Graf | 2e23f54 | 2014-04-29 13:36:21 +0200 | [diff] [blame] | 744 | case KVM_REG_PPC_EBBHR: |
| 745 | vcpu->arch.ebbhr = set_reg_val(reg->id, val); |
| 746 | break; |
| 747 | case KVM_REG_PPC_EBBRR: |
| 748 | vcpu->arch.ebbrr = set_reg_val(reg->id, val); |
| 749 | break; |
| 750 | case KVM_REG_PPC_BESCR: |
| 751 | vcpu->arch.bescr = set_reg_val(reg->id, val); |
| 752 | break; |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 753 | default: |
| 754 | r = -EINVAL; |
| 755 | break; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | return r; |
| 760 | } |
| 761 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 762 | void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) |
| 763 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 764 | vcpu->kvm->arch.kvm_ops->vcpu_load(vcpu, cpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) |
| 768 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 769 | vcpu->kvm->arch.kvm_ops->vcpu_put(vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr) |
| 773 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 774 | vcpu->kvm->arch.kvm_ops->set_msr(vcpu, msr); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 775 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 776 | EXPORT_SYMBOL_GPL(kvmppc_set_msr); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 777 | |
| 778 | int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) |
| 779 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 780 | return vcpu->kvm->arch.kvm_ops->vcpu_run(kvm_run, vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 781 | } |
| 782 | |
Alexander Graf | 2f4cf5e | 2009-10-30 05:47:10 +0000 | [diff] [blame] | 783 | int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, |
| 784 | struct kvm_translation *tr) |
| 785 | { |
| 786 | return 0; |
| 787 | } |
| 788 | |
Bharat Bhushan | 092d62e | 2013-04-08 00:32:12 +0000 | [diff] [blame] | 789 | int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, |
| 790 | struct kvm_guest_debug *dbg) |
| 791 | { |
| 792 | return -EINVAL; |
| 793 | } |
| 794 | |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 795 | void kvmppc_decrementer_func(unsigned long data) |
| 796 | { |
| 797 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; |
| 798 | |
| 799 | kvmppc_core_queue_dec(vcpu); |
| 800 | kvm_vcpu_kick(vcpu); |
| 801 | } |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 802 | |
| 803 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) |
| 804 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 805 | return kvm->arch.kvm_ops->vcpu_create(kvm, id); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) |
| 809 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 810 | vcpu->kvm->arch.kvm_ops->vcpu_free(vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | int kvmppc_core_check_requests(struct kvm_vcpu *vcpu) |
| 814 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 815 | return vcpu->kvm->arch.kvm_ops->check_requests(vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) |
| 819 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 820 | return kvm->arch.kvm_ops->get_dirty_log(kvm, log); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 821 | } |
| 822 | |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 823 | void kvmppc_core_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 824 | struct kvm_memory_slot *dont) |
| 825 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 826 | kvm->arch.kvm_ops->free_memslot(free, dont); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 827 | } |
| 828 | |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 829 | int kvmppc_core_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 830 | unsigned long npages) |
| 831 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 832 | return kvm->arch.kvm_ops->create_memslot(slot, npages); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot) |
| 836 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 837 | kvm->arch.kvm_ops->flush_memslot(kvm, memslot); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
| 841 | struct kvm_memory_slot *memslot, |
| 842 | struct kvm_userspace_memory_region *mem) |
| 843 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 844 | return kvm->arch.kvm_ops->prepare_memory_region(kvm, memslot, mem); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | void kvmppc_core_commit_memory_region(struct kvm *kvm, |
| 848 | struct kvm_userspace_memory_region *mem, |
| 849 | const struct kvm_memory_slot *old) |
| 850 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 851 | kvm->arch.kvm_ops->commit_memory_region(kvm, mem, old); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | int kvm_unmap_hva(struct kvm *kvm, unsigned long hva) |
| 855 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 856 | return kvm->arch.kvm_ops->unmap_hva(kvm, hva); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 857 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 858 | EXPORT_SYMBOL_GPL(kvm_unmap_hva); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 859 | |
| 860 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) |
| 861 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 862 | return kvm->arch.kvm_ops->unmap_hva_range(kvm, start, end); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | int kvm_age_hva(struct kvm *kvm, unsigned long hva) |
| 866 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 867 | return kvm->arch.kvm_ops->age_hva(kvm, hva); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | int kvm_test_age_hva(struct kvm *kvm, unsigned long hva) |
| 871 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 872 | return kvm->arch.kvm_ops->test_age_hva(kvm, hva); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) |
| 876 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 877 | kvm->arch.kvm_ops->set_spte_hva(kvm, hva, pte); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu) |
| 881 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 882 | vcpu->kvm->arch.kvm_ops->mmu_destroy(vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | int kvmppc_core_init_vm(struct kvm *kvm) |
| 886 | { |
| 887 | |
| 888 | #ifdef CONFIG_PPC64 |
| 889 | INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables); |
| 890 | INIT_LIST_HEAD(&kvm->arch.rtas_tokens); |
| 891 | #endif |
| 892 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 893 | return kvm->arch.kvm_ops->init_vm(kvm); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | void kvmppc_core_destroy_vm(struct kvm *kvm) |
| 897 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 898 | kvm->arch.kvm_ops->destroy_vm(kvm); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 899 | |
| 900 | #ifdef CONFIG_PPC64 |
| 901 | kvmppc_rtas_tokens_free(kvm); |
| 902 | WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables)); |
| 903 | #endif |
| 904 | } |
| 905 | |
| 906 | int kvmppc_core_check_processor_compat(void) |
| 907 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 908 | /* |
| 909 | * We always return 0 for book3s. We check |
| 910 | * for compatability while loading the HV |
| 911 | * or PR module |
| 912 | */ |
| 913 | return 0; |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 914 | } |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 915 | |
| 916 | static int kvmppc_book3s_init(void) |
| 917 | { |
| 918 | int r; |
| 919 | |
| 920 | r = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE); |
| 921 | if (r) |
| 922 | return r; |
Alexander Graf | ab78475 | 2014-04-06 23:31:48 +0200 | [diff] [blame] | 923 | #ifdef CONFIG_KVM_BOOK3S_32_HANDLER |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 924 | r = kvmppc_book3s_init_pr(); |
| 925 | #endif |
| 926 | return r; |
| 927 | |
| 928 | } |
| 929 | |
| 930 | static void kvmppc_book3s_exit(void) |
| 931 | { |
Alexander Graf | ab78475 | 2014-04-06 23:31:48 +0200 | [diff] [blame] | 932 | #ifdef CONFIG_KVM_BOOK3S_32_HANDLER |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 933 | kvmppc_book3s_exit_pr(); |
| 934 | #endif |
| 935 | kvm_exit(); |
| 936 | } |
| 937 | |
| 938 | module_init(kvmppc_book3s_init); |
| 939 | module_exit(kvmppc_book3s_exit); |
Alexander Graf | 398a76c | 2013-12-09 13:53:42 +0100 | [diff] [blame] | 940 | |
| 941 | /* On 32bit this is our one and only kernel module */ |
Alexander Graf | ab78475 | 2014-04-06 23:31:48 +0200 | [diff] [blame] | 942 | #ifdef CONFIG_KVM_BOOK3S_32_HANDLER |
Alexander Graf | 398a76c | 2013-12-09 13:53:42 +0100 | [diff] [blame] | 943 | MODULE_ALIAS_MISCDEV(KVM_MINOR); |
| 944 | MODULE_ALIAS("devname:kvm"); |
| 945 | #endif |