aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>2013-10-07 12:47:53 -0400
committerAlexander Graf <agraf@suse.de>2013-10-17 09:24:26 -0400
commit3a167beac07cba597856c12b87638a06b0d53db7 (patch)
treeb7d484f8cb3519aec3177f914304b1d5e129d193
parent9975f5e3692d320b4259a4d2edd8a979adb1e535 (diff)
kvm: powerpc: Add kvmppc_ops callback
This patch add a new callback kvmppc_ops. This will help us in enabling both HV and PR KVM together in the same kernel. The actual change to enable them together is done in the later patch in the series. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> [agraf: squash in booke changes] Signed-off-by: Alexander Graf <agraf@suse.de>
-rw-r--r--arch/powerpc/include/asm/kvm_book3s.h1
-rw-r--r--arch/powerpc/include/asm/kvm_ppc.h89
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S2
-rw-r--r--arch/powerpc/kvm/44x.c55
-rw-r--r--arch/powerpc/kvm/44x_emulate.c8
-rw-r--r--arch/powerpc/kvm/44x_tlb.c2
-rw-r--r--arch/powerpc/kvm/book3s.c145
-rw-r--r--arch/powerpc/kvm/book3s.h32
-rw-r--r--arch/powerpc/kvm/book3s_32_mmu_host.c2
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_host.c2
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_hv.c17
-rw-r--r--arch/powerpc/kvm/book3s_emulate.c8
-rw-r--r--arch/powerpc/kvm/book3s_hv.c220
-rw-r--r--arch/powerpc/kvm/book3s_interrupts.S2
-rw-r--r--arch/powerpc/kvm/book3s_pr.c194
-rw-r--r--arch/powerpc/kvm/book3s_xics.c4
-rw-r--r--arch/powerpc/kvm/booke.c47
-rw-r--r--arch/powerpc/kvm/booke.h24
-rw-r--r--arch/powerpc/kvm/e500.c53
-rw-r--r--arch/powerpc/kvm/e500_emulate.c8
-rw-r--r--arch/powerpc/kvm/e500_mmu.c2
-rw-r--r--arch/powerpc/kvm/e500mc.c54
-rw-r--r--arch/powerpc/kvm/emulate.c6
-rw-r--r--arch/powerpc/kvm/powerpc.c58
24 files changed, 748 insertions, 287 deletions
diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h
index 99ef8711e906..315a5d692417 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -124,7 +124,6 @@ extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong ea, ulong ea_mask)
124extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask); 124extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
125extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end); 125extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end);
126extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr); 126extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
127extern void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr);
128extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu); 127extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
129extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu); 128extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
130extern void kvmppc_mmu_book3s_hv_init(struct kvm_vcpu *vcpu); 129extern void kvmppc_mmu_book3s_hv_init(struct kvm_vcpu *vcpu);
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index 1823f38906c6..326033c99385 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -106,13 +106,6 @@ extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
106 struct kvm_interrupt *irq); 106 struct kvm_interrupt *irq);
107extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu); 107extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu);
108extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu); 108extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu);
109
110extern int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
111 unsigned int op, int *advance);
112extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn,
113 ulong val);
114extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn,
115 ulong *val);
116extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu); 109extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu);
117 110
118extern int kvmppc_booke_init(void); 111extern int kvmppc_booke_init(void);
@@ -135,8 +128,6 @@ extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
135 struct kvm_create_spapr_tce *args); 128 struct kvm_create_spapr_tce *args);
136extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn, 129extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
137 unsigned long ioba, unsigned long tce); 130 unsigned long ioba, unsigned long tce);
138extern long kvm_vm_ioctl_allocate_rma(struct kvm *kvm,
139 struct kvm_allocate_rma *rma);
140extern struct kvm_rma_info *kvm_alloc_rma(void); 131extern struct kvm_rma_info *kvm_alloc_rma(void);
141extern void kvm_release_rma(struct kvm_rma_info *ri); 132extern void kvm_release_rma(struct kvm_rma_info *ri);
142extern struct page *kvm_alloc_hpt(unsigned long nr_pages); 133extern struct page *kvm_alloc_hpt(unsigned long nr_pages);
@@ -177,6 +168,66 @@ extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, u32 *server,
177extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq); 168extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq);
178extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq); 169extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq);
179 170
171union kvmppc_one_reg {
172 u32 wval;
173 u64 dval;
174 vector128 vval;
175 u64 vsxval[2];
176 struct {
177 u64 addr;
178 u64 length;
179 } vpaval;
180};
181
182struct kvmppc_ops {
183 int (*get_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
184 int (*set_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
185 int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id,
186 union kvmppc_one_reg *val);
187 int (*set_one_reg)(struct kvm_vcpu *vcpu, u64 id,
188 union kvmppc_one_reg *val);
189 void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
190 void (*vcpu_put)(struct kvm_vcpu *vcpu);
191 void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr);
192 int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu);
193 struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned int id);
194 void (*vcpu_free)(struct kvm_vcpu *vcpu);
195 int (*check_requests)(struct kvm_vcpu *vcpu);
196 int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log);
197 void (*flush_memslot)(struct kvm *kvm, struct kvm_memory_slot *memslot);
198 int (*prepare_memory_region)(struct kvm *kvm,
199 struct kvm_memory_slot *memslot,
200 struct kvm_userspace_memory_region *mem);
201 void (*commit_memory_region)(struct kvm *kvm,
202 struct kvm_userspace_memory_region *mem,
203 const struct kvm_memory_slot *old);
204 int (*unmap_hva)(struct kvm *kvm, unsigned long hva);
205 int (*unmap_hva_range)(struct kvm *kvm, unsigned long start,
206 unsigned long end);
207 int (*age_hva)(struct kvm *kvm, unsigned long hva);
208 int (*test_age_hva)(struct kvm *kvm, unsigned long hva);
209 void (*set_spte_hva)(struct kvm *kvm, unsigned long hva, pte_t pte);
210 void (*mmu_destroy)(struct kvm_vcpu *vcpu);
211 void (*free_memslot)(struct kvm_memory_slot *free,
212 struct kvm_memory_slot *dont);
213 int (*create_memslot)(struct kvm_memory_slot *slot,
214 unsigned long npages);
215 int (*init_vm)(struct kvm *kvm);
216 void (*destroy_vm)(struct kvm *kvm);
217 int (*check_processor_compat)(void);
218 int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info);
219 int (*emulate_op)(struct kvm_run *run, struct kvm_vcpu *vcpu,
220 unsigned int inst, int *advance);
221 int (*emulate_mtspr)(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);
222 int (*emulate_mfspr)(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val);
223 void (*fast_vcpu_kick)(struct kvm_vcpu *vcpu);
224 long (*arch_vm_ioctl)(struct file *filp, unsigned int ioctl,
225 unsigned long arg);
226
227};
228
229extern struct kvmppc_ops *kvmppc_ops;
230
180/* 231/*
181 * Cuts out inst bits with ordering according to spec. 232 * Cuts out inst bits with ordering according to spec.
182 * That means the leftmost bit is zero. All given bits are included. 233 * That means the leftmost bit is zero. All given bits are included.
@@ -210,17 +261,6 @@ static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value)
210 return r; 261 return r;
211} 262}
212 263
213union kvmppc_one_reg {
214 u32 wval;
215 u64 dval;
216 vector128 vval;
217 u64 vsxval[2];
218 struct {
219 u64 addr;
220 u64 length;
221 } vpaval;
222};
223
224#define one_reg_size(id) \ 264#define one_reg_size(id) \
225 (1ul << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) 265 (1ul << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
226 266
@@ -245,10 +285,10 @@ union kvmppc_one_reg {
245 __v; \ 285 __v; \
246}) 286})
247 287
248void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); 288int kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
249int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); 289int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
250 290
251void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); 291int kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
252int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); 292int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
253 293
254int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg); 294int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
@@ -281,7 +321,10 @@ static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi)
281 paca[cpu].kvm_hstate.host_ipi = host_ipi; 321 paca[cpu].kvm_hstate.host_ipi = host_ipi;
282} 322}
283 323
284extern void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu); 324static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu)
325{
326 kvmppc_ops->fast_vcpu_kick(vcpu);
327}
285 328
286#else 329#else
287static inline void __init kvm_cma_reserve(void) 330static inline void __init kvm_cma_reserve(void)
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 3d1c42b03c89..9f905e40922e 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -126,7 +126,7 @@ BEGIN_FTR_SECTION
126 bgt cr1,. 126 bgt cr1,.
127 GET_PACA(r13) 127 GET_PACA(r13)
128 128
129#ifdef CONFIG_KVM_BOOK3S_64_HV 129#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
130 li r0,KVM_HWTHREAD_IN_KERNEL 130 li r0,KVM_HWTHREAD_IN_KERNEL
131 stb r0,HSTATE_HWTHREAD_STATE(r13) 131 stb r0,HSTATE_HWTHREAD_STATE(r13)
132 /* Order setting hwthread_state vs. testing hwthread_req */ 132 /* Order setting hwthread_state vs. testing hwthread_req */
diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c
index 2f5c6b6d6877..a765bcd74fbb 100644
--- a/arch/powerpc/kvm/44x.c
+++ b/arch/powerpc/kvm/44x.c
@@ -31,13 +31,13 @@
31#include "44x_tlb.h" 31#include "44x_tlb.h"
32#include "booke.h" 32#include "booke.h"
33 33
34void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 34static void kvmppc_core_vcpu_load_44x(struct kvm_vcpu *vcpu, int cpu)
35{ 35{
36 kvmppc_booke_vcpu_load(vcpu, cpu); 36 kvmppc_booke_vcpu_load(vcpu, cpu);
37 kvmppc_44x_tlb_load(vcpu); 37 kvmppc_44x_tlb_load(vcpu);
38} 38}
39 39
40void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) 40static void kvmppc_core_vcpu_put_44x(struct kvm_vcpu *vcpu)
41{ 41{
42 kvmppc_44x_tlb_put(vcpu); 42 kvmppc_44x_tlb_put(vcpu);
43 kvmppc_booke_vcpu_put(vcpu); 43 kvmppc_booke_vcpu_put(vcpu);
@@ -114,29 +114,32 @@ int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
114 return 0; 114 return 0;
115} 115}
116 116
117void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 117static int kvmppc_core_get_sregs_44x(struct kvm_vcpu *vcpu,
118 struct kvm_sregs *sregs)
118{ 119{
119 kvmppc_get_sregs_ivor(vcpu, sregs); 120 return kvmppc_get_sregs_ivor(vcpu, sregs);
120} 121}
121 122
122int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 123static int kvmppc_core_set_sregs_44x(struct kvm_vcpu *vcpu,
124 struct kvm_sregs *sregs)
123{ 125{
124 return kvmppc_set_sregs_ivor(vcpu, sregs); 126 return kvmppc_set_sregs_ivor(vcpu, sregs);
125} 127}
126 128
127int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, 129static int kvmppc_get_one_reg_44x(struct kvm_vcpu *vcpu, u64 id,
128 union kvmppc_one_reg *val) 130 union kvmppc_one_reg *val)
129{ 131{
130 return -EINVAL; 132 return -EINVAL;
131} 133}
132 134
133int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, 135static int kvmppc_set_one_reg_44x(struct kvm_vcpu *vcpu, u64 id,
134 union kvmppc_one_reg *val) 136 union kvmppc_one_reg *val)
135{ 137{
136 return -EINVAL; 138 return -EINVAL;
137} 139}
138 140
139struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) 141static struct kvm_vcpu *kvmppc_core_vcpu_create_44x(struct kvm *kvm,
142 unsigned int id)
140{ 143{
141 struct kvmppc_vcpu_44x *vcpu_44x; 144 struct kvmppc_vcpu_44x *vcpu_44x;
142 struct kvm_vcpu *vcpu; 145 struct kvm_vcpu *vcpu;
@@ -167,7 +170,7 @@ out:
167 return ERR_PTR(err); 170 return ERR_PTR(err);
168} 171}
169 172
170void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) 173static void kvmppc_core_vcpu_free_44x(struct kvm_vcpu *vcpu)
171{ 174{
172 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 175 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
173 176
@@ -176,24 +179,46 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
176 kmem_cache_free(kvm_vcpu_cache, vcpu_44x); 179 kmem_cache_free(kvm_vcpu_cache, vcpu_44x);
177} 180}
178 181
179int kvmppc_core_init_vm(struct kvm *kvm) 182static int kvmppc_core_init_vm_44x(struct kvm *kvm)
180{ 183{
181 return 0; 184 return 0;
182} 185}
183 186
184void kvmppc_core_destroy_vm(struct kvm *kvm) 187static void kvmppc_core_destroy_vm_44x(struct kvm *kvm)
185{ 188{
186} 189}
187 190
191static struct kvmppc_ops kvm_ops_44x = {
192 .get_sregs = kvmppc_core_get_sregs_44x,
193 .set_sregs = kvmppc_core_set_sregs_44x,
194 .get_one_reg = kvmppc_get_one_reg_44x,
195 .set_one_reg = kvmppc_set_one_reg_44x,
196 .vcpu_load = kvmppc_core_vcpu_load_44x,
197 .vcpu_put = kvmppc_core_vcpu_put_44x,
198 .vcpu_create = kvmppc_core_vcpu_create_44x,
199 .vcpu_free = kvmppc_core_vcpu_free_44x,
200 .mmu_destroy = kvmppc_mmu_destroy_44x,
201 .init_vm = kvmppc_core_init_vm_44x,
202 .destroy_vm = kvmppc_core_destroy_vm_44x,
203 .emulate_op = kvmppc_core_emulate_op_44x,
204 .emulate_mtspr = kvmppc_core_emulate_mtspr_44x,
205 .emulate_mfspr = kvmppc_core_emulate_mfspr_44x,
206};
207
188static int __init kvmppc_44x_init(void) 208static int __init kvmppc_44x_init(void)
189{ 209{
190 int r; 210 int r;
191 211
192 r = kvmppc_booke_init(); 212 r = kvmppc_booke_init();
193 if (r) 213 if (r)
194 return r; 214 goto err_out;
195 215
196 return kvm_init(NULL, sizeof(struct kvmppc_vcpu_44x), 0, THIS_MODULE); 216 r = kvm_init(&kvm_ops_44x, sizeof(struct kvmppc_vcpu_44x),
217 0, THIS_MODULE);
218 if (r)
219 goto err_out;
220err_out:
221 return r;
197} 222}
198 223
199static void __exit kvmppc_44x_exit(void) 224static void __exit kvmppc_44x_exit(void)
diff --git a/arch/powerpc/kvm/44x_emulate.c b/arch/powerpc/kvm/44x_emulate.c
index 35ec0a8547da..92c9ab4bcfec 100644
--- a/arch/powerpc/kvm/44x_emulate.c
+++ b/arch/powerpc/kvm/44x_emulate.c
@@ -91,8 +91,8 @@ static int emulate_mfdcr(struct kvm_vcpu *vcpu, int rt, int dcrn)
91 return EMULATE_DONE; 91 return EMULATE_DONE;
92} 92}
93 93
94int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, 94int kvmppc_core_emulate_op_44x(struct kvm_run *run, struct kvm_vcpu *vcpu,
95 unsigned int inst, int *advance) 95 unsigned int inst, int *advance)
96{ 96{
97 int emulated = EMULATE_DONE; 97 int emulated = EMULATE_DONE;
98 int dcrn = get_dcrn(inst); 98 int dcrn = get_dcrn(inst);
@@ -152,7 +152,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
152 return emulated; 152 return emulated;
153} 153}
154 154
155int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) 155int kvmppc_core_emulate_mtspr_44x(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
156{ 156{
157 int emulated = EMULATE_DONE; 157 int emulated = EMULATE_DONE;
158 158
@@ -172,7 +172,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
172 return emulated; 172 return emulated;
173} 173}
174 174
175int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val) 175int kvmppc_core_emulate_mfspr_44x(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
176{ 176{
177 int emulated = EMULATE_DONE; 177 int emulated = EMULATE_DONE;
178 178
diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c
index ed0385448148..0deef1082e02 100644
--- a/arch/powerpc/kvm/44x_tlb.c
+++ b/arch/powerpc/kvm/44x_tlb.c
@@ -268,7 +268,7 @@ static void kvmppc_44x_shadow_release(struct kvmppc_vcpu_44x *vcpu_44x,
268 trace_kvm_stlb_inval(stlb_index); 268 trace_kvm_stlb_inval(stlb_index);
269} 269}
270 270
271void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu) 271void kvmppc_mmu_destroy_44x(struct kvm_vcpu *vcpu)
272{ 272{
273 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 273 struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
274 int i; 274 int i;
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 807103ad2628..784a1d5ccb04 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -422,6 +422,18 @@ void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu)
422{ 422{
423} 423}
424 424
425int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
426 struct kvm_sregs *sregs)
427{
428 return kvmppc_ops->get_sregs(vcpu, sregs);
429}
430
431int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
432 struct kvm_sregs *sregs)
433{
434 return kvmppc_ops->set_sregs(vcpu, sregs);
435}
436
425int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) 437int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
426{ 438{
427 int i; 439 int i;
@@ -498,8 +510,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
498 if (size > sizeof(val)) 510 if (size > sizeof(val))
499 return -EINVAL; 511 return -EINVAL;
500 512
501 r = kvmppc_get_one_reg(vcpu, reg->id, &val); 513 r = kvmppc_ops->get_one_reg(vcpu, reg->id, &val);
502
503 if (r == -EINVAL) { 514 if (r == -EINVAL) {
504 r = 0; 515 r = 0;
505 switch (reg->id) { 516 switch (reg->id) {
@@ -578,8 +589,7 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
578 if (copy_from_user(&val, (char __user *)(unsigned long)reg->addr, size)) 589 if (copy_from_user(&val, (char __user *)(unsigned long)reg->addr, size))
579 return -EFAULT; 590 return -EFAULT;
580 591
581 r = kvmppc_set_one_reg(vcpu, reg->id, &val); 592 r = kvmppc_ops->set_one_reg(vcpu, reg->id, &val);
582
583 if (r == -EINVAL) { 593 if (r == -EINVAL) {
584 r = 0; 594 r = 0;
585 switch (reg->id) { 595 switch (reg->id) {
@@ -638,6 +648,26 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
638 return r; 648 return r;
639} 649}
640 650
651void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
652{
653 kvmppc_ops->vcpu_load(vcpu, cpu);
654}
655
656void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
657{
658 kvmppc_ops->vcpu_put(vcpu);
659}
660
661void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr)
662{
663 kvmppc_ops->set_msr(vcpu, msr);
664}
665
666int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
667{
668 return kvmppc_ops->vcpu_run(kvm_run, vcpu);
669}
670
641int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, 671int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
642 struct kvm_translation *tr) 672 struct kvm_translation *tr)
643{ 673{
@@ -657,3 +687,110 @@ void kvmppc_decrementer_func(unsigned long data)
657 kvmppc_core_queue_dec(vcpu); 687 kvmppc_core_queue_dec(vcpu);
658 kvm_vcpu_kick(vcpu); 688 kvm_vcpu_kick(vcpu);
659} 689}
690
691struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
692{
693 return kvmppc_ops->vcpu_create(kvm, id);
694}
695
696void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
697{
698 kvmppc_ops->vcpu_free(vcpu);
699}
700
701int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
702{
703 return kvmppc_ops->check_requests(vcpu);
704}
705
706int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
707{
708 return kvmppc_ops->get_dirty_log(kvm, log);
709}
710
711void kvmppc_core_free_memslot(struct kvm_memory_slot *free,
712 struct kvm_memory_slot *dont)
713{
714 kvmppc_ops->free_memslot(free, dont);
715}
716
717int kvmppc_core_create_memslot(struct kvm_memory_slot *slot,
718 unsigned long npages)
719{
720 return kvmppc_ops->create_memslot(slot, npages);
721}
722
723void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
724{
725 kvmppc_ops->flush_memslot(kvm, memslot);
726}
727
728int kvmppc_core_prepare_memory_region(struct kvm *kvm,
729 struct kvm_memory_slot *memslot,
730 struct kvm_userspace_memory_region *mem)
731{
732 return kvmppc_ops->prepare_memory_region(kvm, memslot, mem);
733}
734
735void kvmppc_core_commit_memory_region(struct kvm *kvm,
736 struct kvm_userspace_memory_region *mem,
737 const struct kvm_memory_slot *old)
738{
739 kvmppc_ops->commit_memory_region(kvm, mem, old);
740}
741
742int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
743{
744 return kvmppc_ops->unmap_hva(kvm, hva);
745}
746
747int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end)
748{
749 return kvmppc_ops->unmap_hva_range(kvm, start, end);
750}
751
752int kvm_age_hva(struct kvm *kvm, unsigned long hva)
753{
754 return kvmppc_ops->age_hva(kvm, hva);
755}
756
757int kvm_test_age_hva(struct kvm *kvm, unsigned long hva)
758{
759 return kvmppc_ops->test_age_hva(kvm, hva);
760}
761
762void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte)
763{
764 kvmppc_ops->set_spte_hva(kvm, hva, pte);
765}
766
767void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)
768{
769 kvmppc_ops->mmu_destroy(vcpu);
770}
771
772int kvmppc_core_init_vm(struct kvm *kvm)
773{
774
775#ifdef CONFIG_PPC64
776 INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables);
777 INIT_LIST_HEAD(&kvm->arch.rtas_tokens);
778#endif
779
780 return kvmppc_ops->init_vm(kvm);
781}
782
783void kvmppc_core_destroy_vm(struct kvm *kvm)
784{
785 kvmppc_ops->destroy_vm(kvm);
786
787#ifdef CONFIG_PPC64
788 kvmppc_rtas_tokens_free(kvm);
789 WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables));
790#endif
791}
792
793int kvmppc_core_check_processor_compat(void)
794{
795 return kvmppc_ops->check_processor_compat();
796}
diff --git a/arch/powerpc/kvm/book3s.h b/arch/powerpc/kvm/book3s.h
new file mode 100644
index 000000000000..9e5b3a341943
--- /dev/null
+++ b/arch/powerpc/kvm/book3s.h
@@ -0,0 +1,32 @@
1/*
2 * Copyright IBM Corporation, 2013
3 * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License or (at your optional) any later version of the license.
9 *
10 */
11
12#ifndef __POWERPC_KVM_BOOK3S_H__
13#define __POWERPC_KVM_BOOK3S_H__
14
15extern void kvmppc_core_flush_memslot_hv(struct kvm *kvm,
16 struct kvm_memory_slot *memslot);
17extern int kvm_unmap_hva_hv(struct kvm *kvm, unsigned long hva);
18extern int kvm_unmap_hva_range_hv(struct kvm *kvm, unsigned long start,
19 unsigned long end);
20extern int kvm_age_hva_hv(struct kvm *kvm, unsigned long hva);
21extern int kvm_test_age_hva_hv(struct kvm *kvm, unsigned long hva);
22extern void kvm_set_spte_hva_hv(struct kvm *kvm, unsigned long hva, pte_t pte);
23
24extern void kvmppc_mmu_destroy_pr(struct kvm_vcpu *vcpu);
25extern int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
26 unsigned int inst, int *advance);
27extern int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu,
28 int sprn, ulong spr_val);
29extern int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu,
30 int sprn, ulong *spr_val);
31
32#endif
diff --git a/arch/powerpc/kvm/book3s_32_mmu_host.c b/arch/powerpc/kvm/book3s_32_mmu_host.c
index 673322329238..3a0abd2e5a15 100644
--- a/arch/powerpc/kvm/book3s_32_mmu_host.c
+++ b/arch/powerpc/kvm/book3s_32_mmu_host.c
@@ -349,7 +349,7 @@ void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu)
349 svcpu_put(svcpu); 349 svcpu_put(svcpu);
350} 350}
351 351
352void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu) 352void kvmppc_mmu_destroy_pr(struct kvm_vcpu *vcpu)
353{ 353{
354 int i; 354 int i;
355 355
diff --git a/arch/powerpc/kvm/book3s_64_mmu_host.c b/arch/powerpc/kvm/book3s_64_mmu_host.c
index e2ab8a747fbe..819672c9d787 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_host.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_host.c
@@ -378,7 +378,7 @@ void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu)
378 svcpu_put(svcpu); 378 svcpu_put(svcpu);
379} 379}
380 380
381void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu) 381void kvmppc_mmu_destroy_pr(struct kvm_vcpu *vcpu)
382{ 382{
383 kvmppc_mmu_hpte_destroy(vcpu); 383 kvmppc_mmu_hpte_destroy(vcpu);
384 __destroy_context(to_book3s(vcpu)->context_id[0]); 384 __destroy_context(to_book3s(vcpu)->context_id[0]);
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 394fef820f0c..f3ff587a8b7d 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -260,10 +260,6 @@ int kvmppc_mmu_hv_init(void)
260 return 0; 260 return 0;
261} 261}
262 262
263void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)
264{
265}
266
267static void kvmppc_mmu_book3s_64_hv_reset_msr(struct kvm_vcpu *vcpu) 263static void kvmppc_mmu_book3s_64_hv_reset_msr(struct kvm_vcpu *vcpu)
268{ 264{
269 kvmppc_set_msr(vcpu, MSR_SF | MSR_ME); 265 kvmppc_set_msr(vcpu, MSR_SF | MSR_ME);
@@ -906,21 +902,22 @@ static int kvm_unmap_rmapp(struct kvm *kvm, unsigned long *rmapp,
906 return 0; 902 return 0;
907} 903}
908 904
909int kvm_unmap_hva(struct kvm *kvm, unsigned long hva) 905int kvm_unmap_hva_hv(struct kvm *kvm, unsigned long hva)
910{ 906{
911 if (kvm->arch.using_mmu_notifiers) 907 if (kvm->arch.using_mmu_notifiers)
912 kvm_handle_hva(kvm, hva, kvm_unmap_rmapp); 908 kvm_handle_hva(kvm, hva, kvm_unmap_rmapp);
913 return 0; 909 return 0;
914} 910}
915 911
916int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) 912int kvm_unmap_hva_range_hv(struct kvm *kvm, unsigned long start, unsigned long end)
917{ 913{
918 if (kvm->arch.using_mmu_notifiers) 914 if (kvm->arch.using_mmu_notifiers)
919 kvm_handle_hva_range(kvm, start, end, kvm_unmap_rmapp); 915 kvm_handle_hva_range(kvm, start, end, kvm_unmap_rmapp);
920 return 0; 916 return 0;
921} 917}
922 918
923void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot) 919void kvmppc_core_flush_memslot_hv(struct kvm *kvm,
920 struct kvm_memory_slot *memslot)
924{ 921{
925 unsigned long *rmapp; 922 unsigned long *rmapp;
926 unsigned long gfn; 923 unsigned long gfn;
@@ -994,7 +991,7 @@ static int kvm_age_rmapp(struct kvm *kvm, unsigned long *rmapp,
994 return ret; 991 return ret;
995} 992}
996 993
997int kvm_age_hva(struct kvm *kvm, unsigned long hva) 994int kvm_age_hva_hv(struct kvm *kvm, unsigned long hva)
998{ 995{
999 if (!kvm->arch.using_mmu_notifiers) 996 if (!kvm->arch.using_mmu_notifiers)
1000 return 0; 997 return 0;
@@ -1032,14 +1029,14 @@ static int kvm_test_age_rmapp(struct kvm *kvm, unsigned long *rmapp,
1032 return ret; 1029 return ret;
1033} 1030}
1034 1031
1035int kvm_test_age_hva(struct kvm *kvm, unsigned long hva) 1032int kvm_test_age_hva_hv(struct kvm *kvm, unsigned long hva)
1036{ 1033{
1037 if (!kvm->arch.using_mmu_notifiers) 1034 if (!kvm->arch.using_mmu_notifiers)
1038 return 0; 1035 return 0;
1039 return kvm_handle_hva(kvm, hva, kvm_test_age_rmapp); 1036 return kvm_handle_hva(kvm, hva, kvm_test_age_rmapp);
1040} 1037}
1041 1038
1042void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) 1039void kvm_set_spte_hva_hv(struct kvm *kvm, unsigned long hva, pte_t pte)
1043{ 1040{
1044 if (!kvm->arch.using_mmu_notifiers) 1041 if (!kvm->arch.using_mmu_notifiers)
1045 return; 1042 return;
diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c
index 34044b111daa..b9841ad844fb 100644
--- a/arch/powerpc/kvm/book3s_emulate.c
+++ b/arch/powerpc/kvm/book3s_emulate.c
@@ -86,8 +86,8 @@ static bool spr_allowed(struct kvm_vcpu *vcpu, enum priv_level level)
86 return true; 86 return true;
87} 87}
88 88
89int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, 89int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
90 unsigned int inst, int *advance) 90 unsigned int inst, int *advance)
91{ 91{
92 int emulated = EMULATE_DONE; 92 int emulated = EMULATE_DONE;
93 int rt = get_rt(inst); 93 int rt = get_rt(inst);
@@ -345,7 +345,7 @@ static struct kvmppc_bat *kvmppc_find_bat(struct kvm_vcpu *vcpu, int sprn)
345 return bat; 345 return bat;
346} 346}
347 347
348int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) 348int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
349{ 349{
350 int emulated = EMULATE_DONE; 350 int emulated = EMULATE_DONE;
351 351
@@ -468,7 +468,7 @@ unprivileged:
468 return emulated; 468 return emulated;
469} 469}
470 470
471int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val) 471int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
472{ 472{
473 int emulated = EMULATE_DONE; 473 int emulated = EMULATE_DONE;
474 474
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index b4d5b3b06769..3d7079a08d2a 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -53,6 +53,8 @@
53#include <linux/highmem.h> 53#include <linux/highmem.h>
54#include <linux/hugetlb.h> 54#include <linux/hugetlb.h>
55 55
56#include "book3s.h"
57
56/* #define EXIT_DEBUG */ 58/* #define EXIT_DEBUG */
57/* #define EXIT_DEBUG_SIMPLE */ 59/* #define EXIT_DEBUG_SIMPLE */
58/* #define EXIT_DEBUG_INT */ 60/* #define EXIT_DEBUG_INT */
@@ -66,7 +68,7 @@
66static void kvmppc_end_cede(struct kvm_vcpu *vcpu); 68static void kvmppc_end_cede(struct kvm_vcpu *vcpu);
67static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu); 69static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu);
68 70
69void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu) 71static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
70{ 72{
71 int me; 73 int me;
72 int cpu = vcpu->cpu; 74 int cpu = vcpu->cpu;
@@ -125,7 +127,7 @@ void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu)
125 * purely defensive; they should never fail.) 127 * purely defensive; they should never fail.)
126 */ 128 */
127 129
128void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 130static void kvmppc_core_vcpu_load_hv(struct kvm_vcpu *vcpu, int cpu)
129{ 131{
130 struct kvmppc_vcore *vc = vcpu->arch.vcore; 132 struct kvmppc_vcore *vc = vcpu->arch.vcore;
131 133
@@ -143,7 +145,7 @@ void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
143 spin_unlock(&vcpu->arch.tbacct_lock); 145 spin_unlock(&vcpu->arch.tbacct_lock);
144} 146}
145 147
146void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) 148static void kvmppc_core_vcpu_put_hv(struct kvm_vcpu *vcpu)
147{ 149{
148 struct kvmppc_vcore *vc = vcpu->arch.vcore; 150 struct kvmppc_vcore *vc = vcpu->arch.vcore;
149 151
@@ -155,13 +157,13 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
155 spin_unlock(&vcpu->arch.tbacct_lock); 157 spin_unlock(&vcpu->arch.tbacct_lock);
156} 158}
157 159
158void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr) 160static void kvmppc_set_msr_hv(struct kvm_vcpu *vcpu, u64 msr)
159{ 161{
160 vcpu->arch.shregs.msr = msr; 162 vcpu->arch.shregs.msr = msr;
161 kvmppc_end_cede(vcpu); 163 kvmppc_end_cede(vcpu);
162} 164}
163 165
164void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr) 166void kvmppc_set_pvr_hv(struct kvm_vcpu *vcpu, u32 pvr)
165{ 167{
166 vcpu->arch.pvr = pvr; 168 vcpu->arch.pvr = pvr;
167} 169}
@@ -614,8 +616,8 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
614 return RESUME_GUEST; 616 return RESUME_GUEST;
615} 617}
616 618
617static int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, 619static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
618 struct task_struct *tsk) 620 struct task_struct *tsk)
619{ 621{
620 int r = RESUME_HOST; 622 int r = RESUME_HOST;
621 623
@@ -717,8 +719,8 @@ static int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
717 return r; 719 return r;
718} 720}
719 721
720int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, 722static int kvm_arch_vcpu_ioctl_get_sregs_hv(struct kvm_vcpu *vcpu,
721 struct kvm_sregs *sregs) 723 struct kvm_sregs *sregs)
722{ 724{
723 int i; 725 int i;
724 726
@@ -732,12 +734,12 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
732 return 0; 734 return 0;
733} 735}
734 736
735int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, 737static int kvm_arch_vcpu_ioctl_set_sregs_hv(struct kvm_vcpu *vcpu,
736 struct kvm_sregs *sregs) 738 struct kvm_sregs *sregs)
737{ 739{
738 int i, j; 740 int i, j;
739 741
740 kvmppc_set_pvr(vcpu, sregs->pvr); 742 kvmppc_set_pvr_hv(vcpu, sregs->pvr);
741 743
742 j = 0; 744 j = 0;
743 for (i = 0; i < vcpu->arch.slb_nr; i++) { 745 for (i = 0; i < vcpu->arch.slb_nr; i++) {
@@ -767,7 +769,8 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 new_lpcr)
767 spin_unlock(&vc->lock); 769 spin_unlock(&vc->lock);
768} 770}
769 771
770int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val) 772static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
773 union kvmppc_one_reg *val)
771{ 774{
772 int r = 0; 775 int r = 0;
773 long int i; 776 long int i;
@@ -866,7 +869,8 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
866 return r; 869 return r;
867} 870}
868 871
869int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val) 872static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
873 union kvmppc_one_reg *val)
870{ 874{
871 int r = 0; 875 int r = 0;
872 long int i; 876 long int i;
@@ -979,14 +983,8 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
979 return r; 983 return r;
980} 984}
981 985
982int kvmppc_core_check_processor_compat(void) 986static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct kvm *kvm,
983{ 987 unsigned int id)
984 if (cpu_has_feature(CPU_FTR_HVMODE))
985 return 0;
986 return -EIO;
987}
988
989struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
990{ 988{
991 struct kvm_vcpu *vcpu; 989 struct kvm_vcpu *vcpu;
992 int err = -EINVAL; 990 int err = -EINVAL;
@@ -1010,8 +1008,7 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
1010 vcpu->arch.mmcr[0] = MMCR0_FC; 1008 vcpu->arch.mmcr[0] = MMCR0_FC;
1011 vcpu->arch.ctrl = CTRL_RUNLATCH; 1009 vcpu->arch.ctrl = CTRL_RUNLATCH;
1012 /* default to host PVR, since we can't spoof it */ 1010 /* default to host PVR, since we can't spoof it */
1013 vcpu->arch.pvr = mfspr(SPRN_PVR); 1011 kvmppc_set_pvr_hv(vcpu, mfspr(SPRN_PVR));
1014 kvmppc_set_pvr(vcpu, vcpu->arch.pvr);
1015 spin_lock_init(&vcpu->arch.vpa_update_lock); 1012 spin_lock_init(&vcpu->arch.vpa_update_lock);
1016 spin_lock_init(&vcpu->arch.tbacct_lock); 1013 spin_lock_init(&vcpu->arch.tbacct_lock);
1017 vcpu->arch.busy_preempt = TB_NIL; 1014 vcpu->arch.busy_preempt = TB_NIL;
@@ -1064,7 +1061,7 @@ static void unpin_vpa(struct kvm *kvm, struct kvmppc_vpa *vpa)
1064 vpa->dirty); 1061 vpa->dirty);
1065} 1062}
1066 1063
1067void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) 1064static void kvmppc_core_vcpu_free_hv(struct kvm_vcpu *vcpu)
1068{ 1065{
1069 spin_lock(&vcpu->arch.vpa_update_lock); 1066 spin_lock(&vcpu->arch.vpa_update_lock);
1070 unpin_vpa(vcpu->kvm, &vcpu->arch.dtl); 1067 unpin_vpa(vcpu->kvm, &vcpu->arch.dtl);
@@ -1075,6 +1072,12 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
1075 kmem_cache_free(kvm_vcpu_cache, vcpu); 1072 kmem_cache_free(kvm_vcpu_cache, vcpu);
1076} 1073}
1077 1074
1075static int kvmppc_core_check_requests_hv(struct kvm_vcpu *vcpu)
1076{
1077 /* Indicate we want to get back into the guest */
1078 return 1;
1079}
1080
1078static void kvmppc_set_timer(struct kvm_vcpu *vcpu) 1081static void kvmppc_set_timer(struct kvm_vcpu *vcpu)
1079{ 1082{
1080 unsigned long dec_nsec, now; 1083 unsigned long dec_nsec, now;
@@ -1356,8 +1359,8 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)
1356 1359
1357 ret = RESUME_GUEST; 1360 ret = RESUME_GUEST;
1358 if (vcpu->arch.trap) 1361 if (vcpu->arch.trap)
1359 ret = kvmppc_handle_exit(vcpu->arch.kvm_run, vcpu, 1362 ret = kvmppc_handle_exit_hv(vcpu->arch.kvm_run, vcpu,
1360 vcpu->arch.run_task); 1363 vcpu->arch.run_task);
1361 1364
1362 vcpu->arch.ret = ret; 1365 vcpu->arch.ret = ret;
1363 vcpu->arch.trap = 0; 1366 vcpu->arch.trap = 0;
@@ -1516,7 +1519,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1516 return vcpu->arch.ret; 1519 return vcpu->arch.ret;
1517} 1520}
1518 1521
1519int kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu) 1522static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu)
1520{ 1523{
1521 int r; 1524 int r;
1522 int srcu_idx; 1525 int srcu_idx;
@@ -1638,7 +1641,8 @@ static const struct file_operations kvm_rma_fops = {
1638 .release = kvm_rma_release, 1641 .release = kvm_rma_release,
1639}; 1642};
1640 1643
1641long kvm_vm_ioctl_allocate_rma(struct kvm *kvm, struct kvm_allocate_rma *ret) 1644static long kvm_vm_ioctl_allocate_rma(struct kvm *kvm,
1645 struct kvm_allocate_rma *ret)
1642{ 1646{
1643 long fd; 1647 long fd;
1644 struct kvm_rma_info *ri; 1648 struct kvm_rma_info *ri;
@@ -1684,7 +1688,8 @@ static void kvmppc_add_seg_page_size(struct kvm_ppc_one_seg_page_size **sps,
1684 (*sps)++; 1688 (*sps)++;
1685} 1689}
1686 1690
1687int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, struct kvm_ppc_smmu_info *info) 1691static int kvm_vm_ioctl_get_smmu_info_hv(struct kvm *kvm,
1692 struct kvm_ppc_smmu_info *info)
1688{ 1693{
1689 struct kvm_ppc_one_seg_page_size *sps; 1694 struct kvm_ppc_one_seg_page_size *sps;
1690 1695
@@ -1705,7 +1710,8 @@ int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, struct kvm_ppc_smmu_info *info)
1705/* 1710/*
1706 * Get (and clear) the dirty memory log for a memory slot. 1711 * Get (and clear) the dirty memory log for a memory slot.
1707 */ 1712 */
1708int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) 1713static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
1714 struct kvm_dirty_log *log)
1709{ 1715{
1710 struct kvm_memory_slot *memslot; 1716 struct kvm_memory_slot *memslot;
1711 int r; 1717 int r;
@@ -1759,8 +1765,8 @@ static void unpin_slot(struct kvm_memory_slot *memslot)
1759 } 1765 }
1760} 1766}
1761 1767
1762void kvmppc_core_free_memslot(struct kvm_memory_slot *free, 1768static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free,
1763 struct kvm_memory_slot *dont) 1769 struct kvm_memory_slot *dont)
1764{ 1770{
1765 if (!dont || free->arch.rmap != dont->arch.rmap) { 1771 if (!dont || free->arch.rmap != dont->arch.rmap) {
1766 vfree(free->arch.rmap); 1772 vfree(free->arch.rmap);
@@ -1773,8 +1779,8 @@ void kvmppc_core_free_memslot(struct kvm_memory_slot *free,
1773 } 1779 }
1774} 1780}
1775 1781
1776int kvmppc_core_create_memslot(struct kvm_memory_slot *slot, 1782static int kvmppc_core_create_memslot_hv(struct kvm_memory_slot *slot,
1777 unsigned long npages) 1783 unsigned long npages)
1778{ 1784{
1779 slot->arch.rmap = vzalloc(npages * sizeof(*slot->arch.rmap)); 1785 slot->arch.rmap = vzalloc(npages * sizeof(*slot->arch.rmap));
1780 if (!slot->arch.rmap) 1786 if (!slot->arch.rmap)
@@ -1784,9 +1790,9 @@ int kvmppc_core_create_memslot(struct kvm_memory_slot *slot,
1784 return 0; 1790 return 0;
1785} 1791}
1786 1792
1787int kvmppc_core_prepare_memory_region(struct kvm *kvm, 1793static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm,
1788 struct kvm_memory_slot *memslot, 1794 struct kvm_memory_slot *memslot,
1789 struct kvm_userspace_memory_region *mem) 1795 struct kvm_userspace_memory_region *mem)
1790{ 1796{
1791 unsigned long *phys; 1797 unsigned long *phys;
1792 1798
@@ -1802,9 +1808,9 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm,
1802 return 0; 1808 return 0;
1803} 1809}
1804 1810
1805void kvmppc_core_commit_memory_region(struct kvm *kvm, 1811static void kvmppc_core_commit_memory_region_hv(struct kvm *kvm,
1806 struct kvm_userspace_memory_region *mem, 1812 struct kvm_userspace_memory_region *mem,
1807 const struct kvm_memory_slot *old) 1813 const struct kvm_memory_slot *old)
1808{ 1814{
1809 unsigned long npages = mem->memory_size >> PAGE_SHIFT; 1815 unsigned long npages = mem->memory_size >> PAGE_SHIFT;
1810 struct kvm_memory_slot *memslot; 1816 struct kvm_memory_slot *memslot;
@@ -1847,6 +1853,11 @@ void kvmppc_update_lpcr(struct kvm *kvm, unsigned long lpcr, unsigned long mask)
1847 } 1853 }
1848} 1854}
1849 1855
1856static void kvmppc_mmu_destroy_hv(struct kvm_vcpu *vcpu)
1857{
1858 return;
1859}
1860
1850static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu) 1861static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
1851{ 1862{
1852 int err = 0; 1863 int err = 0;
@@ -1994,7 +2005,7 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
1994 goto out_srcu; 2005 goto out_srcu;
1995} 2006}
1996 2007
1997int kvmppc_core_init_vm(struct kvm *kvm) 2008static int kvmppc_core_init_vm_hv(struct kvm *kvm)
1998{ 2009{
1999 unsigned long lpcr, lpid; 2010 unsigned long lpcr, lpid;
2000 2011
@@ -2012,9 +2023,6 @@ int kvmppc_core_init_vm(struct kvm *kvm)
2012 */ 2023 */
2013 cpumask_setall(&kvm->arch.need_tlb_flush); 2024 cpumask_setall(&kvm->arch.need_tlb_flush);
2014 2025
2015 INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables);
2016 INIT_LIST_HEAD(&kvm->arch.rtas_tokens);
2017
2018 kvm->arch.rma = NULL; 2026 kvm->arch.rma = NULL;
2019 2027
2020 kvm->arch.host_sdr1 = mfspr(SPRN_SDR1); 2028 kvm->arch.host_sdr1 = mfspr(SPRN_SDR1);
@@ -2059,7 +2067,7 @@ static void kvmppc_free_vcores(struct kvm *kvm)
2059 kvm->arch.online_vcores = 0; 2067 kvm->arch.online_vcores = 0;
2060} 2068}
2061 2069
2062void kvmppc_core_destroy_vm(struct kvm *kvm) 2070static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)
2063{ 2071{
2064 uninhibit_secondary_onlining(); 2072 uninhibit_secondary_onlining();
2065 2073
@@ -2069,39 +2077,127 @@ void kvmppc_core_destroy_vm(struct kvm *kvm)
2069 kvm->arch.rma = NULL; 2077 kvm->arch.rma = NULL;
2070 } 2078 }
2071 2079
2072 kvmppc_rtas_tokens_free(kvm);
2073
2074 kvmppc_free_hpt(kvm); 2080 kvmppc_free_hpt(kvm);
2075 WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables));
2076} 2081}
2077 2082
2078/* These are stubs for now */ 2083/* We don't need to emulate any privileged instructions or dcbz */
2079void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end) 2084static int kvmppc_core_emulate_op_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
2085 unsigned int inst, int *advance)
2080{ 2086{
2087 return EMULATE_FAIL;
2081} 2088}
2082 2089
2083/* We don't need to emulate any privileged instructions or dcbz */ 2090static int kvmppc_core_emulate_mtspr_hv(struct kvm_vcpu *vcpu, int sprn,
2084int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, 2091 ulong spr_val)
2085 unsigned int inst, int *advance)
2086{ 2092{
2087 return EMULATE_FAIL; 2093 return EMULATE_FAIL;
2088} 2094}
2089 2095
2090int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) 2096static int kvmppc_core_emulate_mfspr_hv(struct kvm_vcpu *vcpu, int sprn,
2097 ulong *spr_val)
2091{ 2098{
2092 return EMULATE_FAIL; 2099 return EMULATE_FAIL;
2093} 2100}
2094 2101
2095int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val) 2102static int kvmppc_core_check_processor_compat_hv(void)
2096{ 2103{
2097 return EMULATE_FAIL; 2104 if (!cpu_has_feature(CPU_FTR_HVMODE))
2105 return -EIO;
2106 return 0;
2098} 2107}
2099 2108
2100static int kvmppc_book3s_hv_init(void) 2109static long kvm_arch_vm_ioctl_hv(struct file *filp,
2110 unsigned int ioctl, unsigned long arg)
2111{
2112 struct kvm *kvm __maybe_unused = filp->private_data;
2113 void __user *argp = (void __user *)arg;
2114 long r;
2115
2116 switch (ioctl) {
2117
2118 case KVM_ALLOCATE_RMA: {
2119 struct kvm_allocate_rma rma;
2120 struct kvm *kvm = filp->private_data;
2121
2122 r = kvm_vm_ioctl_allocate_rma(kvm, &rma);
2123 if (r >= 0 && copy_to_user(argp, &rma, sizeof(rma)))
2124 r = -EFAULT;
2125 break;
2126 }
2127
2128 case KVM_PPC_ALLOCATE_HTAB: {
2129 u32 htab_order;
2130
2131 r = -EFAULT;
2132 if (get_user(htab_order, (u32 __user *)argp))
2133 break;
2134 r = kvmppc_alloc_reset_hpt(kvm, &htab_order);
2135 if (r)
2136 break;
2137 r = -EFAULT;
2138 if (put_user(htab_order, (u32 __user *)argp))
2139 break;
2140 r = 0;
2141 break;
2142 }
2143
2144 case KVM_PPC_GET_HTAB_FD: {
2145 struct kvm_get_htab_fd ghf;
2146
2147 r = -EFAULT;
2148 if (copy_from_user(&ghf, argp, sizeof(ghf)))
2149 break;
2150 r = kvm_vm_ioctl_get_htab_fd(kvm, &ghf);
2151 break;
2152 }
2153
2154 default:
2155 r = -ENOTTY;
2156 }
2157
2158 return r;
2159}
2160
2161static struct kvmppc_ops kvmppc_hv_ops = {
2162 .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv,
2163 .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv,
2164 .get_one_reg = kvmppc_get_one_reg_hv,
2165 .set_one_reg = kvmppc_set_one_reg_hv,
2166 .vcpu_load = kvmppc_core_vcpu_load_hv,
2167 .vcpu_put = kvmppc_core_vcpu_put_hv,
2168 .set_msr = kvmppc_set_msr_hv,
2169 .vcpu_run = kvmppc_vcpu_run_hv,
2170 .vcpu_create = kvmppc_core_vcpu_create_hv,
2171 .vcpu_free = kvmppc_core_vcpu_free_hv,
2172 .check_requests = kvmppc_core_check_requests_hv,
2173 .get_dirty_log = kvm_vm_ioctl_get_dirty_log_hv,
2174 .flush_memslot = kvmppc_core_flush_memslot_hv,
2175 .prepare_memory_region = kvmppc_core_prepare_memory_region_hv,
2176 .commit_memory_region = kvmppc_core_commit_memory_region_hv,
2177 .unmap_hva = kvm_unmap_hva_hv,
2178 .unmap_hva_range = kvm_unmap_hva_range_hv,
2179 .age_hva = kvm_age_hva_hv,
2180 .test_age_hva = kvm_test_age_hva_hv,
2181 .set_spte_hva = kvm_set_spte_hva_hv,
2182 .mmu_destroy = kvmppc_mmu_destroy_hv,
2183 .free_memslot = kvmppc_core_free_memslot_hv,
2184 .create_memslot = kvmppc_core_create_memslot_hv,
2185 .init_vm = kvmppc_core_init_vm_hv,
2186 .destroy_vm = kvmppc_core_destroy_vm_hv,
2187 .check_processor_compat = kvmppc_core_check_processor_compat_hv,
2188 .get_smmu_info = kvm_vm_ioctl_get_smmu_info_hv,
2189 .emulate_op = kvmppc_core_emulate_op_hv,
2190 .emulate_mtspr = kvmppc_core_emulate_mtspr_hv,
2191 .emulate_mfspr = kvmppc_core_emulate_mfspr_hv,
2192 .fast_vcpu_kick = kvmppc_fast_vcpu_kick_hv,
2193 .arch_vm_ioctl = kvm_arch_vm_ioctl_hv,
2194};
2195
2196static int kvmppc_book3s_init_hv(void)
2101{ 2197{
2102 int r; 2198 int r;
2103 2199
2104 r = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE); 2200 r = kvm_init(&kvmppc_hv_ops, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
2105 2201
2106 if (r) 2202 if (r)
2107 return r; 2203 return r;
@@ -2111,10 +2207,10 @@ static int kvmppc_book3s_hv_init(void)
2111 return r; 2207 return r;
2112} 2208}
2113 2209
2114static void kvmppc_book3s_hv_exit(void) 2210static void kvmppc_book3s_exit_hv(void)
2115{ 2211{
2116 kvm_exit(); 2212 kvm_exit();
2117} 2213}
2118 2214
2119module_init(kvmppc_book3s_hv_init); 2215module_init(kvmppc_book3s_init_hv);
2120module_exit(kvmppc_book3s_hv_exit); 2216module_exit(kvmppc_book3s_exit_hv);
diff --git a/arch/powerpc/kvm/book3s_interrupts.S b/arch/powerpc/kvm/book3s_interrupts.S
index 38166ab2f19c..f4dd041c14ea 100644
--- a/arch/powerpc/kvm/book3s_interrupts.S
+++ b/arch/powerpc/kvm/book3s_interrupts.S
@@ -181,7 +181,7 @@ kvm_start_lightweight:
181 181
182 /* Restore r3 (kvm_run) and r4 (vcpu) */ 182 /* Restore r3 (kvm_run) and r4 (vcpu) */
183 REST_2GPRS(3, r1) 183 REST_2GPRS(3, r1)
184 bl FUNC(kvmppc_handle_exit) 184 bl FUNC(kvmppc_handle_exit_pr)
185 185
186 /* If RESUME_GUEST, get back in the loop */ 186 /* If RESUME_GUEST, get back in the loop */
187 cmpwi r3, RESUME_GUEST 187 cmpwi r3, RESUME_GUEST
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 6075dbd0b364..05d28cf4a06c 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -41,6 +41,7 @@
41#include <linux/vmalloc.h> 41#include <linux/vmalloc.h>
42#include <linux/highmem.h> 42#include <linux/highmem.h>
43 43
44#include "book3s.h"
44#include "trace.h" 45#include "trace.h"
45 46
46/* #define EXIT_DEBUG */ 47/* #define EXIT_DEBUG */
@@ -56,7 +57,7 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,
56#define HW_PAGE_SIZE PAGE_SIZE 57#define HW_PAGE_SIZE PAGE_SIZE
57#endif 58#endif
58 59
59void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 60static void kvmppc_core_vcpu_load_pr(struct kvm_vcpu *vcpu, int cpu)
60{ 61{
61#ifdef CONFIG_PPC_BOOK3S_64 62#ifdef CONFIG_PPC_BOOK3S_64
62 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); 63 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
@@ -70,7 +71,7 @@ void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
70#endif 71#endif
71} 72}
72 73
73void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) 74static void kvmppc_core_vcpu_put_pr(struct kvm_vcpu *vcpu)
74{ 75{
75#ifdef CONFIG_PPC_BOOK3S_64 76#ifdef CONFIG_PPC_BOOK3S_64
76 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); 77 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
@@ -137,7 +138,7 @@ void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu,
137 vcpu->arch.last_inst = svcpu->last_inst; 138 vcpu->arch.last_inst = svcpu->last_inst;
138} 139}
139 140
140int kvmppc_core_check_requests(struct kvm_vcpu *vcpu) 141static int kvmppc_core_check_requests_pr(struct kvm_vcpu *vcpu)
141{ 142{
142 int r = 1; /* Indicate we want to get back into the guest */ 143 int r = 1; /* Indicate we want to get back into the guest */
143 144
@@ -180,7 +181,7 @@ static void do_kvm_unmap_hva(struct kvm *kvm, unsigned long start,
180 } 181 }
181} 182}
182 183
183int kvm_unmap_hva(struct kvm *kvm, unsigned long hva) 184static int kvm_unmap_hva_pr(struct kvm *kvm, unsigned long hva)
184{ 185{
185 trace_kvm_unmap_hva(hva); 186 trace_kvm_unmap_hva(hva);
186 187
@@ -189,26 +190,27 @@ int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
189 return 0; 190 return 0;
190} 191}
191 192
192int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) 193static int kvm_unmap_hva_range_pr(struct kvm *kvm, unsigned long start,
194 unsigned long end)
193{ 195{
194 do_kvm_unmap_hva(kvm, start, end); 196 do_kvm_unmap_hva(kvm, start, end);
195 197
196 return 0; 198 return 0;
197} 199}
198 200
199int kvm_age_hva(struct kvm *kvm, unsigned long hva) 201static int kvm_age_hva_pr(struct kvm *kvm, unsigned long hva)
200{ 202{
201 /* XXX could be more clever ;) */ 203 /* XXX could be more clever ;) */
202 return 0; 204 return 0;
203} 205}
204 206
205int kvm_test_age_hva(struct kvm *kvm, unsigned long hva) 207static int kvm_test_age_hva_pr(struct kvm *kvm, unsigned long hva)
206{ 208{
207 /* XXX could be more clever ;) */ 209 /* XXX could be more clever ;) */
208 return 0; 210 return 0;
209} 211}
210 212
211void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) 213static void kvm_set_spte_hva_pr(struct kvm *kvm, unsigned long hva, pte_t pte)
212{ 214{
213 /* The page will get remapped properly on its next fault */ 215 /* The page will get remapped properly on its next fault */
214 do_kvm_unmap_hva(kvm, hva, hva + PAGE_SIZE); 216 do_kvm_unmap_hva(kvm, hva, hva + PAGE_SIZE);
@@ -233,7 +235,7 @@ static void kvmppc_recalc_shadow_msr(struct kvm_vcpu *vcpu)
233 vcpu->arch.shadow_msr = smsr; 235 vcpu->arch.shadow_msr = smsr;
234} 236}
235 237
236void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr) 238static void kvmppc_set_msr_pr(struct kvm_vcpu *vcpu, u64 msr)
237{ 239{
238 ulong old_msr = vcpu->arch.shared->msr; 240 ulong old_msr = vcpu->arch.shared->msr;
239 241
@@ -293,7 +295,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr)
293 kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP); 295 kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP);
294} 296}
295 297
296void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr) 298void kvmppc_set_pvr_pr(struct kvm_vcpu *vcpu, u32 pvr)
297{ 299{
298 u32 host_pvr; 300 u32 host_pvr;
299 301
@@ -725,8 +727,8 @@ static void kvmppc_handle_lost_ext(struct kvm_vcpu *vcpu)
725 current->thread.regs->msr |= lost_ext; 727 current->thread.regs->msr |= lost_ext;
726} 728}
727 729
728int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, 730int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
729 unsigned int exit_nr) 731 unsigned int exit_nr)
730{ 732{
731 int r = RESUME_HOST; 733 int r = RESUME_HOST;
732 int s; 734 int s;
@@ -1034,8 +1036,8 @@ program_interrupt:
1034 return r; 1036 return r;
1035} 1037}
1036 1038
1037int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, 1039static int kvm_arch_vcpu_ioctl_get_sregs_pr(struct kvm_vcpu *vcpu,
1038 struct kvm_sregs *sregs) 1040 struct kvm_sregs *sregs)
1039{ 1041{
1040 struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); 1042 struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
1041 int i; 1043 int i;
@@ -1061,13 +1063,13 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
1061 return 0; 1063 return 0;
1062} 1064}
1063 1065
1064int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, 1066static int kvm_arch_vcpu_ioctl_set_sregs_pr(struct kvm_vcpu *vcpu,
1065 struct kvm_sregs *sregs) 1067 struct kvm_sregs *sregs)
1066{ 1068{
1067 struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu); 1069 struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
1068 int i; 1070 int i;
1069 1071
1070 kvmppc_set_pvr(vcpu, sregs->pvr); 1072 kvmppc_set_pvr_pr(vcpu, sregs->pvr);
1071 1073
1072 vcpu3s->sdr1 = sregs->u.s.sdr1; 1074 vcpu3s->sdr1 = sregs->u.s.sdr1;
1073 if (vcpu->arch.hflags & BOOK3S_HFLAG_SLB) { 1075 if (vcpu->arch.hflags & BOOK3S_HFLAG_SLB) {
@@ -1097,7 +1099,8 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
1097 return 0; 1099 return 0;
1098} 1100}
1099 1101
1100int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val) 1102static int kvmppc_get_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,
1103 union kvmppc_one_reg *val)
1101{ 1104{
1102 int r = 0; 1105 int r = 0;
1103 1106
@@ -1126,7 +1129,8 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
1126 return r; 1129 return r;
1127} 1130}
1128 1131
1129int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val) 1132static int kvmppc_set_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,
1133 union kvmppc_one_reg *val)
1130{ 1134{
1131 int r = 0; 1135 int r = 0;
1132 1136
@@ -1156,12 +1160,8 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
1156 return r; 1160 return r;
1157} 1161}
1158 1162
1159int kvmppc_core_check_processor_compat(void) 1163static struct kvm_vcpu *kvmppc_core_vcpu_create_pr(struct kvm *kvm,
1160{ 1164 unsigned int id)
1161 return 0;
1162}
1163
1164struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
1165{ 1165{
1166 struct kvmppc_vcpu_book3s *vcpu_book3s; 1166 struct kvmppc_vcpu_book3s *vcpu_book3s;
1167 struct kvm_vcpu *vcpu; 1167 struct kvm_vcpu *vcpu;
@@ -1208,7 +1208,7 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
1208 /* default to book3s_32 (750) */ 1208 /* default to book3s_32 (750) */
1209 vcpu->arch.pvr = 0x84202; 1209 vcpu->arch.pvr = 0x84202;
1210#endif 1210#endif
1211 kvmppc_set_pvr(vcpu, vcpu->arch.pvr); 1211 kvmppc_set_pvr_pr(vcpu, vcpu->arch.pvr);
1212 vcpu->arch.slb_nr = 64; 1212 vcpu->arch.slb_nr = 64;
1213 1213
1214 vcpu->arch.shadow_msr = MSR_USER64; 1214 vcpu->arch.shadow_msr = MSR_USER64;
@@ -1233,7 +1233,7 @@ out:
1233 return ERR_PTR(err); 1233 return ERR_PTR(err);
1234} 1234}
1235 1235
1236void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) 1236static void kvmppc_core_vcpu_free_pr(struct kvm_vcpu *vcpu)
1237{ 1237{
1238 struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu); 1238 struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu);
1239 1239
@@ -1246,7 +1246,7 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
1246 kmem_cache_free(kvm_vcpu_cache, vcpu); 1246 kmem_cache_free(kvm_vcpu_cache, vcpu);
1247} 1247}
1248 1248
1249int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) 1249static int kvmppc_vcpu_run_pr(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1250{ 1250{
1251 int ret; 1251 int ret;
1252 double fpr[32][TS_FPRWIDTH]; 1252 double fpr[32][TS_FPRWIDTH];
@@ -1355,8 +1355,8 @@ out:
1355/* 1355/*
1356 * Get (and clear) the dirty memory log for a memory slot. 1356 * Get (and clear) the dirty memory log for a memory slot.
1357 */ 1357 */
1358int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, 1358static int kvm_vm_ioctl_get_dirty_log_pr(struct kvm *kvm,
1359 struct kvm_dirty_log *log) 1359 struct kvm_dirty_log *log)
1360{ 1360{
1361 struct kvm_memory_slot *memslot; 1361 struct kvm_memory_slot *memslot;
1362 struct kvm_vcpu *vcpu; 1362 struct kvm_vcpu *vcpu;
@@ -1391,8 +1391,42 @@ out:
1391 return r; 1391 return r;
1392} 1392}
1393 1393
1394static void kvmppc_core_flush_memslot_pr(struct kvm *kvm,
1395 struct kvm_memory_slot *memslot)
1396{
1397 return;
1398}
1399
1400static int kvmppc_core_prepare_memory_region_pr(struct kvm *kvm,
1401 struct kvm_memory_slot *memslot,
1402 struct kvm_userspace_memory_region *mem)
1403{
1404 return 0;
1405}
1406
1407static void kvmppc_core_commit_memory_region_pr(struct kvm *kvm,
1408 struct kvm_userspace_memory_region *mem,
1409 const struct kvm_memory_slot *old)
1410{
1411 return;
1412}
1413
1414static void kvmppc_core_free_memslot_pr(struct kvm_memory_slot *free,
1415 struct kvm_memory_slot *dont)
1416{
1417 return;
1418}
1419
1420static int kvmppc_core_create_memslot_pr(struct kvm_memory_slot *slot,
1421 unsigned long npages)
1422{
1423 return 0;
1424}
1425
1426
1394#ifdef CONFIG_PPC64 1427#ifdef CONFIG_PPC64
1395int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, struct kvm_ppc_smmu_info *info) 1428static int kvm_vm_ioctl_get_smmu_info_pr(struct kvm *kvm,
1429 struct kvm_ppc_smmu_info *info)
1396{ 1430{
1397 long int i; 1431 long int i;
1398 struct kvm_vcpu *vcpu; 1432 struct kvm_vcpu *vcpu;
@@ -1436,45 +1470,20 @@ int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, struct kvm_ppc_smmu_info *info)
1436 1470
1437 return 0; 1471 return 0;
1438} 1472}
1439#endif /* CONFIG_PPC64 */ 1473#else
1440 1474static int kvm_vm_ioctl_get_smmu_info_pr(struct kvm *kvm,
1441void kvmppc_core_free_memslot(struct kvm_memory_slot *free, 1475 struct kvm_ppc_smmu_info *info)
1442 struct kvm_memory_slot *dont)
1443{
1444}
1445
1446int kvmppc_core_create_memslot(struct kvm_memory_slot *slot,
1447 unsigned long npages)
1448{
1449 return 0;
1450}
1451
1452int kvmppc_core_prepare_memory_region(struct kvm *kvm,
1453 struct kvm_memory_slot *memslot,
1454 struct kvm_userspace_memory_region *mem)
1455{
1456 return 0;
1457}
1458
1459void kvmppc_core_commit_memory_region(struct kvm *kvm,
1460 struct kvm_userspace_memory_region *mem,
1461 const struct kvm_memory_slot *old)
1462{
1463}
1464
1465void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
1466{ 1476{
1477 /* We should not get called */
1478 BUG();
1467} 1479}
1480#endif /* CONFIG_PPC64 */
1468 1481
1469static unsigned int kvm_global_user_count = 0; 1482static unsigned int kvm_global_user_count = 0;
1470static DEFINE_SPINLOCK(kvm_global_user_count_lock); 1483static DEFINE_SPINLOCK(kvm_global_user_count_lock);
1471 1484
1472int kvmppc_core_init_vm(struct kvm *kvm) 1485static int kvmppc_core_init_vm_pr(struct kvm *kvm)
1473{ 1486{
1474#ifdef CONFIG_PPC64
1475 INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables);
1476 INIT_LIST_HEAD(&kvm->arch.rtas_tokens);
1477#endif
1478 mutex_init(&kvm->arch.hpt_mutex); 1487 mutex_init(&kvm->arch.hpt_mutex);
1479 1488
1480 if (firmware_has_feature(FW_FEATURE_SET_MODE)) { 1489 if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
@@ -1486,7 +1495,7 @@ int kvmppc_core_init_vm(struct kvm *kvm)
1486 return 0; 1495 return 0;
1487} 1496}
1488 1497
1489void kvmppc_core_destroy_vm(struct kvm *kvm) 1498static void kvmppc_core_destroy_vm_pr(struct kvm *kvm)
1490{ 1499{
1491#ifdef CONFIG_PPC64 1500#ifdef CONFIG_PPC64
1492 WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables)); 1501 WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables));
@@ -1501,11 +1510,58 @@ void kvmppc_core_destroy_vm(struct kvm *kvm)
1501 } 1510 }
1502} 1511}
1503 1512
1504static int kvmppc_book3s_init(void) 1513static int kvmppc_core_check_processor_compat_pr(void)
1514{
1515 /* we are always compatible */
1516 return 0;
1517}
1518
1519static long kvm_arch_vm_ioctl_pr(struct file *filp,
1520 unsigned int ioctl, unsigned long arg)
1521{
1522 return -ENOTTY;
1523}
1524
1525static struct kvmppc_ops kvmppc_pr_ops = {
1526 .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_pr,
1527 .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_pr,
1528 .get_one_reg = kvmppc_get_one_reg_pr,
1529 .set_one_reg = kvmppc_set_one_reg_pr,
1530 .vcpu_load = kvmppc_core_vcpu_load_pr,
1531 .vcpu_put = kvmppc_core_vcpu_put_pr,
1532 .set_msr = kvmppc_set_msr_pr,
1533 .vcpu_run = kvmppc_vcpu_run_pr,
1534 .vcpu_create = kvmppc_core_vcpu_create_pr,
1535 .vcpu_free = kvmppc_core_vcpu_free_pr,
1536 .check_requests = kvmppc_core_check_requests_pr,
1537 .get_dirty_log = kvm_vm_ioctl_get_dirty_log_pr,
1538 .flush_memslot = kvmppc_core_flush_memslot_pr,
1539 .prepare_memory_region = kvmppc_core_prepare_memory_region_pr,
1540 .commit_memory_region = kvmppc_core_commit_memory_region_pr,
1541 .unmap_hva = kvm_unmap_hva_pr,
1542 .unmap_hva_range = kvm_unmap_hva_range_pr,
1543 .age_hva = kvm_age_hva_pr,
1544 .test_age_hva = kvm_test_age_hva_pr,
1545 .set_spte_hva = kvm_set_spte_hva_pr,
1546 .mmu_destroy = kvmppc_mmu_destroy_pr,
1547 .free_memslot = kvmppc_core_free_memslot_pr,
1548 .create_memslot = kvmppc_core_create_memslot_pr,
1549 .init_vm = kvmppc_core_init_vm_pr,
1550 .destroy_vm = kvmppc_core_destroy_vm_pr,
1551 .check_processor_compat = kvmppc_core_check_processor_compat_pr,
1552 .get_smmu_info = kvm_vm_ioctl_get_smmu_info_pr,
1553 .emulate_op = kvmppc_core_emulate_op_pr,
1554 .emulate_mtspr = kvmppc_core_emulate_mtspr_pr,
1555 .emulate_mfspr = kvmppc_core_emulate_mfspr_pr,
1556 .fast_vcpu_kick = kvm_vcpu_kick,
1557 .arch_vm_ioctl = kvm_arch_vm_ioctl_pr,
1558};
1559
1560static int kvmppc_book3s_init_pr(void)
1505{ 1561{
1506 int r; 1562 int r;
1507 1563
1508 r = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE); 1564 r = kvm_init(&kvmppc_pr_ops, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
1509 1565
1510 if (r) 1566 if (r)
1511 return r; 1567 return r;
@@ -1515,11 +1571,11 @@ static int kvmppc_book3s_init(void)
1515 return r; 1571 return r;
1516} 1572}
1517 1573
1518static void kvmppc_book3s_exit(void) 1574static void kvmppc_book3s_exit_pr(void)
1519{ 1575{
1520 kvmppc_mmu_hpte_sysexit(); 1576 kvmppc_mmu_hpte_sysexit();
1521 kvm_exit(); 1577 kvm_exit();
1522} 1578}
1523 1579
1524module_init(kvmppc_book3s_init); 1580module_init(kvmppc_book3s_init_pr);
1525module_exit(kvmppc_book3s_exit); 1581module_exit(kvmppc_book3s_exit_pr);
diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index a3a5cb8ee7ea..51ed1ea440e0 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -1250,13 +1250,13 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type)
1250 1250
1251 xics_debugfs_init(xics); 1251 xics_debugfs_init(xics);
1252 1252
1253#ifdef CONFIG_KVM_BOOK3S_64_HV 1253#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
1254 if (cpu_has_feature(CPU_FTR_ARCH_206)) { 1254 if (cpu_has_feature(CPU_FTR_ARCH_206)) {
1255 /* Enable real mode support */ 1255 /* Enable real mode support */
1256 xics->real_mode = ENABLE_REALMODE; 1256 xics->real_mode = ENABLE_REALMODE;
1257 xics->real_mode_dbg = DEBUG_REALMODE; 1257 xics->real_mode_dbg = DEBUG_REALMODE;
1258 } 1258 }
1259#endif /* CONFIG_KVM_BOOK3S_64_HV */ 1259#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
1260 1260
1261 return 0; 1261 return 0;
1262} 1262}
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 8b6a790c0562..e5f8ba793c31 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1415,7 +1415,7 @@ static int set_sregs_arch206(struct kvm_vcpu *vcpu,
1415 return 0; 1415 return 0;
1416} 1416}
1417 1417
1418void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 1418int kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
1419{ 1419{
1420 sregs->u.e.features |= KVM_SREGS_E_IVOR; 1420 sregs->u.e.features |= KVM_SREGS_E_IVOR;
1421 1421
@@ -1435,6 +1435,7 @@ void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
1435 sregs->u.e.ivor_low[13] = vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS]; 1435 sregs->u.e.ivor_low[13] = vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS];
1436 sregs->u.e.ivor_low[14] = vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS]; 1436 sregs->u.e.ivor_low[14] = vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS];
1437 sregs->u.e.ivor_low[15] = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG]; 1437 sregs->u.e.ivor_low[15] = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG];
1438 return 0;
1438} 1439}
1439 1440
1440int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 1441int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
@@ -1469,8 +1470,7 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
1469 1470
1470 get_sregs_base(vcpu, sregs); 1471 get_sregs_base(vcpu, sregs);
1471 get_sregs_arch206(vcpu, sregs); 1472 get_sregs_arch206(vcpu, sregs);
1472 kvmppc_core_get_sregs(vcpu, sregs); 1473 return kvmppc_ops->get_sregs(vcpu, sregs);
1473 return 0;
1474} 1474}
1475 1475
1476int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, 1476int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
@@ -1489,7 +1489,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
1489 if (ret < 0) 1489 if (ret < 0)
1490 return ret; 1490 return ret;
1491 1491
1492 return kvmppc_core_set_sregs(vcpu, sregs); 1492 return kvmppc_ops->set_sregs(vcpu, sregs);
1493} 1493}
1494 1494
1495int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) 1495int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
@@ -1546,7 +1546,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
1546 val = get_reg_val(reg->id, vcpu->arch.vrsave); 1546 val = get_reg_val(reg->id, vcpu->arch.vrsave);
1547 break; 1547 break;
1548 default: 1548 default:
1549 r = kvmppc_get_one_reg(vcpu, reg->id, &val); 1549 r = kvmppc_ops->get_one_reg(vcpu, reg->id, &val);
1550 break; 1550 break;
1551 } 1551 }
1552 1552
@@ -1629,7 +1629,7 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
1629 vcpu->arch.vrsave = set_reg_val(reg->id, val); 1629 vcpu->arch.vrsave = set_reg_val(reg->id, val);
1630 break; 1630 break;
1631 default: 1631 default:
1632 r = kvmppc_set_one_reg(vcpu, reg->id, &val); 1632 r = kvmppc_ops->set_one_reg(vcpu, reg->id, &val);
1633 break; 1633 break;
1634 } 1634 }
1635 1635
@@ -1907,6 +1907,41 @@ void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu)
1907 kvmppc_clear_dbsr(); 1907 kvmppc_clear_dbsr();
1908} 1908}
1909 1909
1910void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)
1911{
1912 kvmppc_ops->mmu_destroy(vcpu);
1913}
1914
1915int kvmppc_core_init_vm(struct kvm *kvm)
1916{
1917 return kvmppc_ops->init_vm(kvm);
1918}
1919
1920struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
1921{
1922 return kvmppc_ops->vcpu_create(kvm, id);
1923}
1924
1925void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
1926{
1927 kvmppc_ops->vcpu_free(vcpu);
1928}
1929
1930void kvmppc_core_destroy_vm(struct kvm *kvm)
1931{
1932 kvmppc_ops->destroy_vm(kvm);
1933}
1934
1935void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
1936{
1937 kvmppc_ops->vcpu_load(vcpu, cpu);
1938}
1939
1940void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
1941{
1942 kvmppc_ops->vcpu_put(vcpu);
1943}
1944
1910int __init kvmppc_booke_init(void) 1945int __init kvmppc_booke_init(void)
1911{ 1946{
1912#ifndef CONFIG_KVM_BOOKE_HV 1947#ifndef CONFIG_KVM_BOOKE_HV
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index a1ff67d04022..09bfd9bc7cf8 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -99,6 +99,30 @@ enum int_class {
99 99
100void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type); 100void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type);
101 101
102extern void kvmppc_mmu_destroy_44x(struct kvm_vcpu *vcpu);
103extern int kvmppc_core_emulate_op_44x(struct kvm_run *run, struct kvm_vcpu *vcpu,
104 unsigned int inst, int *advance);
105extern int kvmppc_core_emulate_mtspr_44x(struct kvm_vcpu *vcpu, int sprn,
106 ulong spr_val);
107extern int kvmppc_core_emulate_mfspr_44x(struct kvm_vcpu *vcpu, int sprn,
108 ulong *spr_val);
109extern void kvmppc_mmu_destroy_e500(struct kvm_vcpu *vcpu);
110extern int kvmppc_core_emulate_op_e500(struct kvm_run *run,
111 struct kvm_vcpu *vcpu,
112 unsigned int inst, int *advance);
113extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn,
114 ulong spr_val);
115extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
116 ulong *spr_val);
117extern void kvmppc_mmu_destroy_e500(struct kvm_vcpu *vcpu);
118extern int kvmppc_core_emulate_op_e500(struct kvm_run *run,
119 struct kvm_vcpu *vcpu,
120 unsigned int inst, int *advance);
121extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn,
122 ulong spr_val);
123extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
124 ulong *spr_val);
125
102/* 126/*
103 * Load up guest vcpu FP state if it's needed. 127 * Load up guest vcpu FP state if it's needed.
104 * It also set the MSR_FP in thread so that host know 128 * It also set the MSR_FP in thread so that host know
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index ce6b73c29612..d225d5ebddcc 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -305,7 +305,7 @@ void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
305{ 305{
306} 306}
307 307
308void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 308static void kvmppc_core_vcpu_load_e500(struct kvm_vcpu *vcpu, int cpu)
309{ 309{
310 kvmppc_booke_vcpu_load(vcpu, cpu); 310 kvmppc_booke_vcpu_load(vcpu, cpu);
311 311
@@ -313,7 +313,7 @@ void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
313 kvmppc_e500_recalc_shadow_pid(to_e500(vcpu)); 313 kvmppc_e500_recalc_shadow_pid(to_e500(vcpu));
314} 314}
315 315
316void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) 316static void kvmppc_core_vcpu_put_e500(struct kvm_vcpu *vcpu)
317{ 317{
318#ifdef CONFIG_SPE 318#ifdef CONFIG_SPE
319 if (vcpu->arch.shadow_msr & MSR_SPE) 319 if (vcpu->arch.shadow_msr & MSR_SPE)
@@ -367,7 +367,8 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
367 return 0; 367 return 0;
368} 368}
369 369
370void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 370static int kvmppc_core_get_sregs_e500(struct kvm_vcpu *vcpu,
371 struct kvm_sregs *sregs)
371{ 372{
372 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 373 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
373 374
@@ -388,9 +389,11 @@ void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
388 389
389 kvmppc_get_sregs_ivor(vcpu, sregs); 390 kvmppc_get_sregs_ivor(vcpu, sregs);
390 kvmppc_get_sregs_e500_tlb(vcpu, sregs); 391 kvmppc_get_sregs_e500_tlb(vcpu, sregs);
392 return 0;
391} 393}
392 394
393int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 395static int kvmppc_core_set_sregs_e500(struct kvm_vcpu *vcpu,
396 struct kvm_sregs *sregs)
394{ 397{
395 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 398 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
396 int ret; 399 int ret;
@@ -425,21 +428,22 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
425 return kvmppc_set_sregs_ivor(vcpu, sregs); 428 return kvmppc_set_sregs_ivor(vcpu, sregs);
426} 429}
427 430
428int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, 431static int kvmppc_get_one_reg_e500(struct kvm_vcpu *vcpu, u64 id,
429 union kvmppc_one_reg *val) 432 union kvmppc_one_reg *val)
430{ 433{
431 int r = kvmppc_get_one_reg_e500_tlb(vcpu, id, val); 434 int r = kvmppc_get_one_reg_e500_tlb(vcpu, id, val);
432 return r; 435 return r;
433} 436}
434 437
435int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, 438static int kvmppc_set_one_reg_e500(struct kvm_vcpu *vcpu, u64 id,
436 union kvmppc_one_reg *val) 439 union kvmppc_one_reg *val)
437{ 440{
438 int r = kvmppc_get_one_reg_e500_tlb(vcpu, id, val); 441 int r = kvmppc_get_one_reg_e500_tlb(vcpu, id, val);
439 return r; 442 return r;
440} 443}
441 444
442struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) 445static struct kvm_vcpu *kvmppc_core_vcpu_create_e500(struct kvm *kvm,
446 unsigned int id)
443{ 447{
444 struct kvmppc_vcpu_e500 *vcpu_e500; 448 struct kvmppc_vcpu_e500 *vcpu_e500;
445 struct kvm_vcpu *vcpu; 449 struct kvm_vcpu *vcpu;
@@ -481,7 +485,7 @@ out:
481 return ERR_PTR(err); 485 return ERR_PTR(err);
482} 486}
483 487
484void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) 488static void kvmppc_core_vcpu_free_e500(struct kvm_vcpu *vcpu)
485{ 489{
486 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 490 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
487 491
@@ -492,15 +496,32 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
492 kmem_cache_free(kvm_vcpu_cache, vcpu_e500); 496 kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
493} 497}
494 498
495int kvmppc_core_init_vm(struct kvm *kvm) 499static int kvmppc_core_init_vm_e500(struct kvm *kvm)
496{ 500{
497 return 0; 501 return 0;
498} 502}
499 503
500void kvmppc_core_destroy_vm(struct kvm *kvm) 504static void kvmppc_core_destroy_vm_e500(struct kvm *kvm)
501{ 505{
502} 506}
503 507
508static struct kvmppc_ops kvm_ops_e500 = {
509 .get_sregs = kvmppc_core_get_sregs_e500,
510 .set_sregs = kvmppc_core_set_sregs_e500,
511 .get_one_reg = kvmppc_get_one_reg_e500,
512 .set_one_reg = kvmppc_set_one_reg_e500,
513 .vcpu_load = kvmppc_core_vcpu_load_e500,
514 .vcpu_put = kvmppc_core_vcpu_put_e500,
515 .vcpu_create = kvmppc_core_vcpu_create_e500,
516 .vcpu_free = kvmppc_core_vcpu_free_e500,
517 .mmu_destroy = kvmppc_mmu_destroy_e500,
518 .init_vm = kvmppc_core_init_vm_e500,
519 .destroy_vm = kvmppc_core_destroy_vm_e500,
520 .emulate_op = kvmppc_core_emulate_op_e500,
521 .emulate_mtspr = kvmppc_core_emulate_mtspr_e500,
522 .emulate_mfspr = kvmppc_core_emulate_mfspr_e500,
523};
524
504static int __init kvmppc_e500_init(void) 525static int __init kvmppc_e500_init(void)
505{ 526{
506 int r, i; 527 int r, i;
@@ -512,11 +533,11 @@ static int __init kvmppc_e500_init(void)
512 533
513 r = kvmppc_core_check_processor_compat(); 534 r = kvmppc_core_check_processor_compat();
514 if (r) 535 if (r)
515 return r; 536 goto err_out;
516 537
517 r = kvmppc_booke_init(); 538 r = kvmppc_booke_init();
518 if (r) 539 if (r)
519 return r; 540 goto err_out;
520 541
521 /* copy extra E500 exception handlers */ 542 /* copy extra E500 exception handlers */
522 ivor[0] = mfspr(SPRN_IVOR32); 543 ivor[0] = mfspr(SPRN_IVOR32);
@@ -534,7 +555,9 @@ static int __init kvmppc_e500_init(void)
534 flush_icache_range(kvmppc_booke_handlers, kvmppc_booke_handlers + 555 flush_icache_range(kvmppc_booke_handlers, kvmppc_booke_handlers +
535 ivor[max_ivor] + handler_len); 556 ivor[max_ivor] + handler_len);
536 557
537 return kvm_init(NULL, sizeof(struct kvmppc_vcpu_e500), 0, THIS_MODULE); 558 r = kvm_init(&kvm_ops_e500, sizeof(struct kvmppc_vcpu_e500), 0, THIS_MODULE);
559err_out:
560 return r;
538} 561}
539 562
540static void __exit kvmppc_e500_exit(void) 563static void __exit kvmppc_e500_exit(void)
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 6163a0318d2a..89b7f821f6c4 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -103,8 +103,8 @@ static int kvmppc_e500_emul_ehpriv(struct kvm_run *run, struct kvm_vcpu *vcpu,
103 return emulated; 103 return emulated;
104} 104}
105 105
106int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, 106int kvmppc_core_emulate_op_e500(struct kvm_run *run, struct kvm_vcpu *vcpu,
107 unsigned int inst, int *advance) 107 unsigned int inst, int *advance)
108{ 108{
109 int emulated = EMULATE_DONE; 109 int emulated = EMULATE_DONE;
110 int ra = get_ra(inst); 110 int ra = get_ra(inst);
@@ -172,7 +172,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
172 return emulated; 172 return emulated;
173} 173}
174 174
175int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) 175int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
176{ 176{
177 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 177 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
178 int emulated = EMULATE_DONE; 178 int emulated = EMULATE_DONE;
@@ -263,7 +263,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
263 return emulated; 263 return emulated;
264} 264}
265 265
266int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val) 266int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
267{ 267{
268 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 268 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
269 int emulated = EMULATE_DONE; 269 int emulated = EMULATE_DONE;
diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index 6d6f153b6c1d..d25bb75aec90 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -536,7 +536,7 @@ gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int index,
536 return get_tlb_raddr(gtlbe) | (eaddr & pgmask); 536 return get_tlb_raddr(gtlbe) | (eaddr & pgmask);
537} 537}
538 538
539void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu) 539void kvmppc_mmu_destroy_e500(struct kvm_vcpu *vcpu)
540{ 540{
541} 541}
542 542
diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index 19c8379575f7..db6a383401c7 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -110,7 +110,7 @@ void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr)
110 110
111static DEFINE_PER_CPU(struct kvm_vcpu *, last_vcpu_on_cpu); 111static DEFINE_PER_CPU(struct kvm_vcpu *, last_vcpu_on_cpu);
112 112
113void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 113static void kvmppc_core_vcpu_load_e500mc(struct kvm_vcpu *vcpu, int cpu)
114{ 114{
115 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 115 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
116 116
@@ -147,7 +147,7 @@ void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
147 kvmppc_load_guest_fp(vcpu); 147 kvmppc_load_guest_fp(vcpu);
148} 148}
149 149
150void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) 150static void kvmppc_core_vcpu_put_e500mc(struct kvm_vcpu *vcpu)
151{ 151{
152 vcpu->arch.eplc = mfspr(SPRN_EPLC); 152 vcpu->arch.eplc = mfspr(SPRN_EPLC);
153 vcpu->arch.epsc = mfspr(SPRN_EPSC); 153 vcpu->arch.epsc = mfspr(SPRN_EPSC);
@@ -204,7 +204,8 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
204 return 0; 204 return 0;
205} 205}
206 206
207void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 207static int kvmppc_core_get_sregs_e500mc(struct kvm_vcpu *vcpu,
208 struct kvm_sregs *sregs)
208{ 209{
209 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 210 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
210 211
@@ -224,10 +225,11 @@ void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
224 sregs->u.e.ivor_high[4] = vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL]; 225 sregs->u.e.ivor_high[4] = vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL];
225 sregs->u.e.ivor_high[5] = vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL_CRIT]; 226 sregs->u.e.ivor_high[5] = vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL_CRIT];
226 227
227 kvmppc_get_sregs_ivor(vcpu, sregs); 228 return kvmppc_get_sregs_ivor(vcpu, sregs);
228} 229}
229 230
230int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 231static int kvmppc_core_set_sregs_e500mc(struct kvm_vcpu *vcpu,
232 struct kvm_sregs *sregs)
231{ 233{
232 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 234 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
233 int ret; 235 int ret;
@@ -260,21 +262,22 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
260 return kvmppc_set_sregs_ivor(vcpu, sregs); 262 return kvmppc_set_sregs_ivor(vcpu, sregs);
261} 263}
262 264
263int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, 265static int kvmppc_get_one_reg_e500mc(struct kvm_vcpu *vcpu, u64 id,
264 union kvmppc_one_reg *val) 266 union kvmppc_one_reg *val)
265{ 267{
266 int r = kvmppc_get_one_reg_e500_tlb(vcpu, id, val); 268 int r = kvmppc_get_one_reg_e500_tlb(vcpu, id, val);
267 return r; 269 return r;
268} 270}
269 271
270int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, 272static int kvmppc_set_one_reg_e500mc(struct kvm_vcpu *vcpu, u64 id,
271 union kvmppc_one_reg *val) 273 union kvmppc_one_reg *val)
272{ 274{
273 int r = kvmppc_set_one_reg_e500_tlb(vcpu, id, val); 275 int r = kvmppc_set_one_reg_e500_tlb(vcpu, id, val);
274 return r; 276 return r;
275} 277}
276 278
277struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) 279static struct kvm_vcpu *kvmppc_core_vcpu_create_e500mc(struct kvm *kvm,
280 unsigned int id)
278{ 281{
279 struct kvmppc_vcpu_e500 *vcpu_e500; 282 struct kvmppc_vcpu_e500 *vcpu_e500;
280 struct kvm_vcpu *vcpu; 283 struct kvm_vcpu *vcpu;
@@ -315,7 +318,7 @@ out:
315 return ERR_PTR(err); 318 return ERR_PTR(err);
316} 319}
317 320
318void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu) 321static void kvmppc_core_vcpu_free_e500mc(struct kvm_vcpu *vcpu)
319{ 322{
320 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 323 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
321 324
@@ -325,7 +328,7 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
325 kmem_cache_free(kvm_vcpu_cache, vcpu_e500); 328 kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
326} 329}
327 330
328int kvmppc_core_init_vm(struct kvm *kvm) 331static int kvmppc_core_init_vm_e500mc(struct kvm *kvm)
329{ 332{
330 int lpid; 333 int lpid;
331 334
@@ -337,23 +340,44 @@ int kvmppc_core_init_vm(struct kvm *kvm)
337 return 0; 340 return 0;
338} 341}
339 342
340void kvmppc_core_destroy_vm(struct kvm *kvm) 343static void kvmppc_core_destroy_vm_e500mc(struct kvm *kvm)
341{ 344{
342 kvmppc_free_lpid(kvm->arch.lpid); 345 kvmppc_free_lpid(kvm->arch.lpid);
343} 346}
344 347
348static struct kvmppc_ops kvm_ops_e500mc = {
349 .get_sregs = kvmppc_core_get_sregs_e500mc,
350 .set_sregs = kvmppc_core_set_sregs_e500mc,
351 .get_one_reg = kvmppc_get_one_reg_e500mc,
352 .set_one_reg = kvmppc_set_one_reg_e500mc,
353 .vcpu_load = kvmppc_core_vcpu_load_e500mc,
354 .vcpu_put = kvmppc_core_vcpu_put_e500mc,
355 .vcpu_create = kvmppc_core_vcpu_create_e500mc,
356 .vcpu_free = kvmppc_core_vcpu_free_e500mc,
357 .mmu_destroy = kvmppc_mmu_destroy_e500,
358 .init_vm = kvmppc_core_init_vm_e500mc,
359 .destroy_vm = kvmppc_core_destroy_vm_e500mc,
360 .emulate_op = kvmppc_core_emulate_op_e500,
361 .emulate_mtspr = kvmppc_core_emulate_mtspr_e500,
362 .emulate_mfspr = kvmppc_core_emulate_mfspr_e500,
363};
364
345static int __init kvmppc_e500mc_init(void) 365static int __init kvmppc_e500mc_init(void)
346{ 366{
347 int r; 367 int r;
348 368
349 r = kvmppc_booke_init(); 369 r = kvmppc_booke_init();
350 if (r) 370 if (r)
351 return r; 371 goto err_out;
352 372
353 kvmppc_init_lpid(64); 373 kvmppc_init_lpid(64);
354 kvmppc_claim_lpid(0); /* host */ 374 kvmppc_claim_lpid(0); /* host */
355 375
356 return kvm_init(NULL, sizeof(struct kvmppc_vcpu_e500), 0, THIS_MODULE); 376 r = kvm_init(&kvm_ops_e500mc, sizeof(struct kvmppc_vcpu_e500), 0, THIS_MODULE);
377 if (r)
378 goto err_out;
379err_out:
380 return r;
357} 381}
358 382
359static void __exit kvmppc_e500mc_exit(void) 383static void __exit kvmppc_e500mc_exit(void)
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 751cd45f65a0..81762eb7957e 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -130,7 +130,7 @@ static int kvmppc_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
130 case SPRN_PIR: break; 130 case SPRN_PIR: break;
131 131
132 default: 132 default:
133 emulated = kvmppc_core_emulate_mtspr(vcpu, sprn, 133 emulated = kvmppc_ops->emulate_mtspr(vcpu, sprn,
134 spr_val); 134 spr_val);
135 if (emulated == EMULATE_FAIL) 135 if (emulated == EMULATE_FAIL)
136 printk(KERN_INFO "mtspr: unknown spr " 136 printk(KERN_INFO "mtspr: unknown spr "
@@ -191,7 +191,7 @@ static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
191 spr_val = kvmppc_get_dec(vcpu, get_tb()); 191 spr_val = kvmppc_get_dec(vcpu, get_tb());
192 break; 192 break;
193 default: 193 default:
194 emulated = kvmppc_core_emulate_mfspr(vcpu, sprn, 194 emulated = kvmppc_ops->emulate_mfspr(vcpu, sprn,
195 &spr_val); 195 &spr_val);
196 if (unlikely(emulated == EMULATE_FAIL)) { 196 if (unlikely(emulated == EMULATE_FAIL)) {
197 printk(KERN_INFO "mfspr: unknown spr " 197 printk(KERN_INFO "mfspr: unknown spr "
@@ -464,7 +464,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
464 } 464 }
465 465
466 if (emulated == EMULATE_FAIL) { 466 if (emulated == EMULATE_FAIL) {
467 emulated = kvmppc_core_emulate_op(run, vcpu, inst, &advance); 467 emulated = kvmppc_ops->emulate_op(run, vcpu, inst, &advance);
468 if (emulated == EMULATE_AGAIN) { 468 if (emulated == EMULATE_AGAIN) {
469 advance = 0; 469 advance = 0;
470 } else if (emulated == EMULATE_FAIL) { 470 } else if (emulated == EMULATE_FAIL) {
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 07c0106fab76..69b930550d2e 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -39,6 +39,8 @@
39#define CREATE_TRACE_POINTS 39#define CREATE_TRACE_POINTS
40#include "trace.h" 40#include "trace.h"
41 41
42struct kvmppc_ops *kvmppc_ops;
43
42int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) 44int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
43{ 45{
44 return !!(v->arch.pending_exceptions) || 46 return !!(v->arch.pending_exceptions) ||
@@ -1024,52 +1026,11 @@ long kvm_arch_vm_ioctl(struct file *filp,
1024 r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce); 1026 r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce);
1025 goto out; 1027 goto out;
1026 } 1028 }
1027#endif /* CONFIG_PPC_BOOK3S_64 */
1028
1029#ifdef CONFIG_KVM_BOOK3S_64_HV
1030 case KVM_ALLOCATE_RMA: {
1031 struct kvm_allocate_rma rma;
1032 struct kvm *kvm = filp->private_data;
1033
1034 r = kvm_vm_ioctl_allocate_rma(kvm, &rma);
1035 if (r >= 0 && copy_to_user(argp, &rma, sizeof(rma)))
1036 r = -EFAULT;
1037 break;
1038 }
1039
1040 case KVM_PPC_ALLOCATE_HTAB: {
1041 u32 htab_order;
1042
1043 r = -EFAULT;
1044 if (get_user(htab_order, (u32 __user *)argp))
1045 break;
1046 r = kvmppc_alloc_reset_hpt(kvm, &htab_order);
1047 if (r)
1048 break;
1049 r = -EFAULT;
1050 if (put_user(htab_order, (u32 __user *)argp))
1051 break;
1052 r = 0;
1053 break;
1054 }
1055
1056 case KVM_PPC_GET_HTAB_FD: {
1057 struct kvm_get_htab_fd ghf;
1058
1059 r = -EFAULT;
1060 if (copy_from_user(&ghf, argp, sizeof(ghf)))
1061 break;
1062 r = kvm_vm_ioctl_get_htab_fd(kvm, &ghf);
1063 break;
1064 }
1065#endif /* CONFIG_KVM_BOOK3S_64_HV */
1066
1067#ifdef CONFIG_PPC_BOOK3S_64
1068 case KVM_PPC_GET_SMMU_INFO: { 1029 case KVM_PPC_GET_SMMU_INFO: {
1069 struct kvm_ppc_smmu_info info; 1030 struct kvm_ppc_smmu_info info;
1070 1031
1071 memset(&info, 0, sizeof(info)); 1032 memset(&info, 0, sizeof(info));
1072 r = kvm_vm_ioctl_get_smmu_info(kvm, &info); 1033 r = kvmppc_ops->get_smmu_info(kvm, &info);
1073 if (r >= 0 && copy_to_user(argp, &info, sizeof(info))) 1034 if (r >= 0 && copy_to_user(argp, &info, sizeof(info)))
1074 r = -EFAULT; 1035 r = -EFAULT;
1075 break; 1036 break;
@@ -1080,11 +1041,14 @@ long kvm_arch_vm_ioctl(struct file *filp,
1080 r = kvm_vm_ioctl_rtas_define_token(kvm, argp); 1041 r = kvm_vm_ioctl_rtas_define_token(kvm, argp);
1081 break; 1042 break;
1082 } 1043 }
1083#endif /* CONFIG_PPC_BOOK3S_64 */ 1044 default:
1045 r = kvmppc_ops->arch_vm_ioctl(filp, ioctl, arg);
1046
1047#else /* CONFIG_PPC_BOOK3S_64 */
1084 default: 1048 default:
1085 r = -ENOTTY; 1049 r = -ENOTTY;
1050#endif
1086 } 1051 }
1087
1088out: 1052out:
1089 return r; 1053 return r;
1090} 1054}
@@ -1125,9 +1089,15 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
1125 1089
1126int kvm_arch_init(void *opaque) 1090int kvm_arch_init(void *opaque)
1127{ 1091{
1092 if (kvmppc_ops) {
1093 printk(KERN_ERR "kvm: already loaded the other module\n");
1094 return -EEXIST;
1095 }
1096 kvmppc_ops = (struct kvmppc_ops *)opaque;
1128 return 0; 1097 return 0;
1129} 1098}
1130 1099
1131void kvm_arch_exit(void) 1100void kvm_arch_exit(void)
1132{ 1101{
1102 kvmppc_ops = NULL;
1133} 1103}