book3s.c 27.9 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
A
Alexander Graf 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2009. SUSE Linux Products GmbH. All rights reserved.
 *
 * Authors:
 *    Alexander Graf <agraf@suse.de>
 *    Kevin Wolf <mail@kevin-wolf.de>
 *
 * Description:
 * This file is derived from arch/powerpc/kvm/44x.c,
 * by Hollis Blanchard <hollisb@us.ibm.com>.
 */

#include <linux/kvm_host.h>
#include <linux/err.h>
16
#include <linux/export.h>
17
#include <linux/slab.h>
18 19
#include <linux/module.h>
#include <linux/miscdevice.h>
20 21 22 23
#include <linux/gfp.h>
#include <linux/sched.h>
#include <linux/vmalloc.h>
#include <linux/highmem.h>
A
Alexander Graf 已提交
24 25 26 27

#include <asm/reg.h>
#include <asm/cputable.h>
#include <asm/cacheflush.h>
28
#include <linux/uaccess.h>
A
Alexander Graf 已提交
29 30 31 32
#include <asm/io.h>
#include <asm/kvm_ppc.h>
#include <asm/kvm_book3s.h>
#include <asm/mmu_context.h>
33
#include <asm/page.h>
34
#include <asm/xive.h>
A
Alexander Graf 已提交
35

36
#include "book3s.h"
37 38
#include "trace.h"

A
Alexander Graf 已提交
39
/* #define EXIT_DEBUG */
40

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
	KVM_GENERIC_VM_STATS(),
	STATS_DESC_ICOUNTER(VM, num_2M_pages),
	STATS_DESC_ICOUNTER(VM, num_1G_pages)
};
static_assert(ARRAY_SIZE(kvm_vm_stats_desc) ==
		sizeof(struct kvm_vm_stat) / sizeof(u64));

const struct kvm_stats_header kvm_vm_stats_header = {
	.name_size = KVM_STATS_NAME_SIZE,
	.num_desc = ARRAY_SIZE(kvm_vm_stats_desc),
	.id_offset = sizeof(struct kvm_stats_header),
	.desc_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE,
	.data_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE +
		       sizeof(kvm_vm_stats_desc),
};

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
	KVM_GENERIC_VCPU_STATS(),
	STATS_DESC_COUNTER(VCPU, sum_exits),
	STATS_DESC_COUNTER(VCPU, mmio_exits),
	STATS_DESC_COUNTER(VCPU, signal_exits),
	STATS_DESC_COUNTER(VCPU, light_exits),
	STATS_DESC_COUNTER(VCPU, itlb_real_miss_exits),
	STATS_DESC_COUNTER(VCPU, itlb_virt_miss_exits),
	STATS_DESC_COUNTER(VCPU, dtlb_real_miss_exits),
	STATS_DESC_COUNTER(VCPU, dtlb_virt_miss_exits),
	STATS_DESC_COUNTER(VCPU, syscall_exits),
	STATS_DESC_COUNTER(VCPU, isi_exits),
	STATS_DESC_COUNTER(VCPU, dsi_exits),
	STATS_DESC_COUNTER(VCPU, emulated_inst_exits),
	STATS_DESC_COUNTER(VCPU, dec_exits),
	STATS_DESC_COUNTER(VCPU, ext_intr_exits),
	STATS_DESC_TIME_NSEC(VCPU, halt_wait_ns),
	STATS_DESC_COUNTER(VCPU, halt_successful_wait),
	STATS_DESC_COUNTER(VCPU, dbell_exits),
	STATS_DESC_COUNTER(VCPU, gdbell_exits),
	STATS_DESC_COUNTER(VCPU, ld),
	STATS_DESC_COUNTER(VCPU, st),
	STATS_DESC_COUNTER(VCPU, pf_storage),
	STATS_DESC_COUNTER(VCPU, pf_instruc),
	STATS_DESC_COUNTER(VCPU, sp_storage),
	STATS_DESC_COUNTER(VCPU, sp_instruc),
	STATS_DESC_COUNTER(VCPU, queue_intr),
	STATS_DESC_COUNTER(VCPU, ld_slow),
	STATS_DESC_COUNTER(VCPU, st_slow),
	STATS_DESC_COUNTER(VCPU, pthru_all),
	STATS_DESC_COUNTER(VCPU, pthru_host),
	STATS_DESC_COUNTER(VCPU, pthru_bad_aff)
};
static_assert(ARRAY_SIZE(kvm_vcpu_stats_desc) ==
		sizeof(struct kvm_vcpu_stat) / sizeof(u64));

const struct kvm_stats_header kvm_vcpu_stats_header = {
	.name_size = KVM_STATS_NAME_SIZE,
	.num_desc = ARRAY_SIZE(kvm_vcpu_stats_desc),
	.id_offset = sizeof(struct kvm_stats_header),
	.desc_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE,
	.data_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE +
		       sizeof(kvm_vcpu_stats_desc),
};

103 104 105
static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu,
			unsigned long pending_now, unsigned long old_pending)
{
106
	if (is_kvmppc_hv_enabled(vcpu->kvm))
107 108
		return;
	if (pending_now)
109
		kvmppc_set_int_pending(vcpu, 1);
110
	else if (old_pending)
111
		kvmppc_set_int_pending(vcpu, 0);
112 113 114 115 116 117 118 119
}

static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu)
{
	ulong crit_raw;
	ulong crit_r1;
	bool crit;

120
	if (is_kvmppc_hv_enabled(vcpu->kvm))
121 122
		return false;

123
	crit_raw = kvmppc_get_critical(vcpu);
124 125 126
	crit_r1 = kvmppc_get_gpr(vcpu, 1);

	/* Truncate crit indicators in 32 bit mode */
127
	if (!(kvmppc_get_msr(vcpu) & MSR_SF)) {
128 129 130 131 132 133 134
		crit_raw &= 0xffffffff;
		crit_r1 &= 0xffffffff;
	}

	/* Critical section when crit == r1 */
	crit = (crit_raw == crit_r1);
	/* ... and we're in supervisor mode */
135
	crit = crit && !(kvmppc_get_msr(vcpu) & MSR_PR);
136 137 138 139

	return crit;
}

A
Alexander Graf 已提交
140 141
void kvmppc_inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 flags)
{
142
	vcpu->kvm->arch.kvm_ops->inject_interrupt(vcpu, vec, flags);
A
Alexander Graf 已提交
143 144
}

145
static int kvmppc_book3s_vec2irqprio(unsigned int vec)
A
Alexander Graf 已提交
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
{
	unsigned int prio;

	switch (vec) {
	case 0x100: prio = BOOK3S_IRQPRIO_SYSTEM_RESET;		break;
	case 0x200: prio = BOOK3S_IRQPRIO_MACHINE_CHECK;	break;
	case 0x300: prio = BOOK3S_IRQPRIO_DATA_STORAGE;		break;
	case 0x380: prio = BOOK3S_IRQPRIO_DATA_SEGMENT;		break;
	case 0x400: prio = BOOK3S_IRQPRIO_INST_STORAGE;		break;
	case 0x480: prio = BOOK3S_IRQPRIO_INST_SEGMENT;		break;
	case 0x500: prio = BOOK3S_IRQPRIO_EXTERNAL;		break;
	case 0x600: prio = BOOK3S_IRQPRIO_ALIGNMENT;		break;
	case 0x700: prio = BOOK3S_IRQPRIO_PROGRAM;		break;
	case 0x800: prio = BOOK3S_IRQPRIO_FP_UNAVAIL;		break;
	case 0x900: prio = BOOK3S_IRQPRIO_DECREMENTER;		break;
	case 0xc00: prio = BOOK3S_IRQPRIO_SYSCALL;		break;
	case 0xd00: prio = BOOK3S_IRQPRIO_DEBUG;		break;
	case 0xf20: prio = BOOK3S_IRQPRIO_ALTIVEC;		break;
	case 0xf40: prio = BOOK3S_IRQPRIO_VSX;			break;
165
	case 0xf60: prio = BOOK3S_IRQPRIO_FAC_UNAVAIL;		break;
A
Alexander Graf 已提交
166 167 168
	default:    prio = BOOK3S_IRQPRIO_MAX;			break;
	}

169 170 171
	return prio;
}

172
void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu,
173 174
					  unsigned int vec)
{
175 176
	unsigned long old_pending = vcpu->arch.pending_exceptions;

177 178
	clear_bit(kvmppc_book3s_vec2irqprio(vec),
		  &vcpu->arch.pending_exceptions);
179

180 181
	kvmppc_update_int_pending(vcpu, vcpu->arch.pending_exceptions,
				  old_pending);
182 183
}

184 185 186 187 188 189
void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)
{
	vcpu->stat.queue_intr++;

	set_bit(kvmppc_book3s_vec2irqprio(vec),
		&vcpu->arch.pending_exceptions);
A
Alexander Graf 已提交
190 191 192 193
#ifdef EXIT_DEBUG
	printk(KERN_INFO "Queueing interrupt %x\n", vec);
#endif
}
194
EXPORT_SYMBOL_GPL(kvmppc_book3s_queue_irqprio);
A
Alexander Graf 已提交
195

196 197 198 199 200 201 202
void kvmppc_core_queue_machine_check(struct kvm_vcpu *vcpu, ulong flags)
{
	/* might as well deliver this straight away */
	kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_MACHINE_CHECK, flags);
}
EXPORT_SYMBOL_GPL(kvmppc_core_queue_machine_check);

203 204 205 206 207 208
void kvmppc_core_queue_syscall(struct kvm_vcpu *vcpu)
{
	kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_SYSCALL, 0);
}
EXPORT_SYMBOL(kvmppc_core_queue_syscall);

209
void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags)
A
Alexander Graf 已提交
210
{
211 212
	/* might as well deliver this straight away */
	kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_PROGRAM, flags);
A
Alexander Graf 已提交
213
}
214
EXPORT_SYMBOL_GPL(kvmppc_core_queue_program);
A
Alexander Graf 已提交
215

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
void kvmppc_core_queue_fpunavail(struct kvm_vcpu *vcpu)
{
	/* might as well deliver this straight away */
	kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, 0);
}

void kvmppc_core_queue_vec_unavail(struct kvm_vcpu *vcpu)
{
	/* might as well deliver this straight away */
	kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_ALTIVEC, 0);
}

void kvmppc_core_queue_vsx_unavail(struct kvm_vcpu *vcpu)
{
	/* might as well deliver this straight away */
	kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_VSX, 0);
}

A
Alexander Graf 已提交
234 235 236 237
void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu)
{
	kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER);
}
238
EXPORT_SYMBOL_GPL(kvmppc_core_queue_dec);
A
Alexander Graf 已提交
239 240 241

int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
{
242
	return test_bit(BOOK3S_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
A
Alexander Graf 已提交
243
}
244
EXPORT_SYMBOL_GPL(kvmppc_core_pending_dec);
A
Alexander Graf 已提交
245

246 247 248 249
void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
{
	kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER);
}
250
EXPORT_SYMBOL_GPL(kvmppc_core_dequeue_dec);
251

A
Alexander Graf 已提交
252 253 254
void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
                                struct kvm_interrupt *irq)
{
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
	/*
	 * This case (KVM_INTERRUPT_SET) should never actually arise for
	 * a pseries guest (because pseries guests expect their interrupt
	 * controllers to continue asserting an external interrupt request
	 * until it is acknowledged at the interrupt controller), but is
	 * included to avoid ABI breakage and potentially for other
	 * sorts of guest.
	 *
	 * There is a subtlety here: HV KVM does not test the
	 * external_oneshot flag in the code that synthesizes
	 * external interrupts for the guest just before entering
	 * the guest.  That is OK even if userspace did do a
	 * KVM_INTERRUPT_SET on a pseries guest vcpu, because the
	 * caller (kvm_vcpu_ioctl_interrupt) does a kvm_vcpu_kick()
	 * which ends up doing a smp_send_reschedule(), which will
	 * pull the guest all the way out to the host, meaning that
	 * we will call kvmppc_core_prepare_to_enter() before entering
	 * the guest again, and that will handle the external_oneshot
	 * flag correctly.
	 */
	if (irq->irq == KVM_INTERRUPT_SET)
		vcpu->arch.external_oneshot = 1;

	kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL);
A
Alexander Graf 已提交
279 280
}

281
void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu)
282 283 284 285
{
	kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL);
}

286 287 288 289 290
void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, ulong dar,
				    ulong flags)
{
	kvmppc_set_dar(vcpu, dar);
	kvmppc_set_dsisr(vcpu, flags);
291
	kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_DATA_STORAGE, 0);
292
}
293
EXPORT_SYMBOL_GPL(kvmppc_core_queue_data_storage);
294 295 296

void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, ulong flags)
{
297
	kvmppc_inject_interrupt(vcpu, BOOK3S_INTERRUPT_INST_STORAGE, flags);
298
}
299
EXPORT_SYMBOL_GPL(kvmppc_core_queue_inst_storage);
300

T
Thomas Huth 已提交
301 302
static int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu,
					 unsigned int priority)
A
Alexander Graf 已提交
303 304 305
{
	int deliver = 1;
	int vec = 0;
306
	bool crit = kvmppc_critical_section(vcpu);
A
Alexander Graf 已提交
307 308 309

	switch (priority) {
	case BOOK3S_IRQPRIO_DECREMENTER:
310
		deliver = (kvmppc_get_msr(vcpu) & MSR_EE) && !crit;
A
Alexander Graf 已提交
311 312 313
		vec = BOOK3S_INTERRUPT_DECREMENTER;
		break;
	case BOOK3S_IRQPRIO_EXTERNAL:
314
		deliver = (kvmppc_get_msr(vcpu) & MSR_EE) && !crit;
A
Alexander Graf 已提交
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
		vec = BOOK3S_INTERRUPT_EXTERNAL;
		break;
	case BOOK3S_IRQPRIO_SYSTEM_RESET:
		vec = BOOK3S_INTERRUPT_SYSTEM_RESET;
		break;
	case BOOK3S_IRQPRIO_MACHINE_CHECK:
		vec = BOOK3S_INTERRUPT_MACHINE_CHECK;
		break;
	case BOOK3S_IRQPRIO_DATA_STORAGE:
		vec = BOOK3S_INTERRUPT_DATA_STORAGE;
		break;
	case BOOK3S_IRQPRIO_INST_STORAGE:
		vec = BOOK3S_INTERRUPT_INST_STORAGE;
		break;
	case BOOK3S_IRQPRIO_DATA_SEGMENT:
		vec = BOOK3S_INTERRUPT_DATA_SEGMENT;
		break;
	case BOOK3S_IRQPRIO_INST_SEGMENT:
		vec = BOOK3S_INTERRUPT_INST_SEGMENT;
		break;
	case BOOK3S_IRQPRIO_ALIGNMENT:
		vec = BOOK3S_INTERRUPT_ALIGNMENT;
		break;
	case BOOK3S_IRQPRIO_PROGRAM:
		vec = BOOK3S_INTERRUPT_PROGRAM;
		break;
	case BOOK3S_IRQPRIO_VSX:
		vec = BOOK3S_INTERRUPT_VSX;
		break;
	case BOOK3S_IRQPRIO_ALTIVEC:
		vec = BOOK3S_INTERRUPT_ALTIVEC;
		break;
	case BOOK3S_IRQPRIO_FP_UNAVAIL:
		vec = BOOK3S_INTERRUPT_FP_UNAVAIL;
		break;
	case BOOK3S_IRQPRIO_SYSCALL:
		vec = BOOK3S_INTERRUPT_SYSCALL;
		break;
	case BOOK3S_IRQPRIO_DEBUG:
		vec = BOOK3S_INTERRUPT_TRACE;
		break;
	case BOOK3S_IRQPRIO_PERFORMANCE_MONITOR:
		vec = BOOK3S_INTERRUPT_PERFMON;
		break;
359 360 361
	case BOOK3S_IRQPRIO_FAC_UNAVAIL:
		vec = BOOK3S_INTERRUPT_FAC_UNAVAIL;
		break;
A
Alexander Graf 已提交
362 363 364 365 366 367 368 369 370 371 372
	default:
		deliver = 0;
		printk(KERN_ERR "KVM: Unknown interrupt: 0x%x\n", priority);
		break;
	}

#if 0
	printk(KERN_INFO "Deliver interrupt 0x%x? %x\n", vec, deliver);
#endif

	if (deliver)
373
		kvmppc_inject_interrupt(vcpu, vec, 0);
A
Alexander Graf 已提交
374 375 376 377

	return deliver;
}

378 379 380 381 382 383 384 385 386
/*
 * This function determines if an irqprio should be cleared once issued.
 */
static bool clear_irqprio(struct kvm_vcpu *vcpu, unsigned int priority)
{
	switch (priority) {
		case BOOK3S_IRQPRIO_DECREMENTER:
			/* DEC interrupts get cleared by mtdec */
			return false;
387 388 389 390 391 392 393 394 395 396
		case BOOK3S_IRQPRIO_EXTERNAL:
			/*
			 * External interrupts get cleared by userspace
			 * except when set by the KVM_INTERRUPT ioctl with
			 * KVM_INTERRUPT_SET (not KVM_INTERRUPT_SET_LEVEL).
			 */
			if (vcpu->arch.external_oneshot) {
				vcpu->arch.external_oneshot = 0;
				return true;
			}
397 398 399 400 401 402
			return false;
	}

	return true;
}

403
int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
A
Alexander Graf 已提交
404 405
{
	unsigned long *pending = &vcpu->arch.pending_exceptions;
406
	unsigned long old_pending = vcpu->arch.pending_exceptions;
A
Alexander Graf 已提交
407 408 409 410 411 412 413
	unsigned int priority;

#ifdef EXIT_DEBUG
	if (vcpu->arch.pending_exceptions)
		printk(KERN_EMERG "KVM: Check pending: %lx\n", vcpu->arch.pending_exceptions);
#endif
	priority = __ffs(*pending);
A
Alexander Graf 已提交
414
	while (priority < BOOK3S_IRQPRIO_MAX) {
415
		if (kvmppc_book3s_irqprio_deliver(vcpu, priority) &&
416
		    clear_irqprio(vcpu, priority)) {
A
Alexander Graf 已提交
417 418 419 420 421 422 423 424
			clear_bit(priority, &vcpu->arch.pending_exceptions);
			break;
		}

		priority = find_next_bit(pending,
					 BITS_PER_BYTE * sizeof(*pending),
					 priority + 1);
	}
425 426

	/* Tell the guest about our interrupt status */
427
	kvmppc_update_int_pending(vcpu, *pending, old_pending);
428 429

	return 0;
A
Alexander Graf 已提交
430
}
431
EXPORT_SYMBOL_GPL(kvmppc_core_prepare_to_enter);
A
Alexander Graf 已提交
432

D
Dan Williams 已提交
433
kvm_pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, bool writing,
434
			bool *writable)
435
{
436 437
	ulong mp_pa = vcpu->arch.magic_page_pa & KVM_PAM;
	gfn_t gfn = gpa >> PAGE_SHIFT;
438

439
	if (!(kvmppc_get_msr(vcpu) & MSR_SF))
440 441
		mp_pa = (uint32_t)mp_pa;

442
	/* Magic page override */
443 444
	gpa &= ~0xFFFULL;
	if (unlikely(mp_pa) && unlikely((gpa & KVM_PAM) == mp_pa)) {
445
		ulong shared_page = ((ulong)vcpu->arch.shared) & PAGE_MASK;
D
Dan Williams 已提交
446
		kvm_pfn_t pfn;
447

D
Dan Williams 已提交
448
		pfn = (kvm_pfn_t)virt_to_phys((void*)shared_page) >> PAGE_SHIFT;
449
		get_page(pfn_to_page(pfn));
450 451
		if (writable)
			*writable = true;
452 453 454
		return pfn;
	}

455
	return gfn_to_pfn_prot(vcpu->kvm, gfn, writing, writable);
456
}
457
EXPORT_SYMBOL_GPL(kvmppc_gpa_to_pfn);
458

459 460
int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, enum xlate_instdata xlid,
		 enum xlate_readwrite xlrw, struct kvmppc_pte *pte)
A
Alexander Graf 已提交
461
{
462 463
	bool data = (xlid == XLATE_DATA);
	bool iswrite = (xlrw == XLATE_WRITE);
464
	int relocated = (kvmppc_get_msr(vcpu) & (data ? MSR_DR : MSR_IR));
A
Alexander Graf 已提交
465 466 467
	int r;

	if (relocated) {
468
		r = vcpu->arch.mmu.xlate(vcpu, eaddr, pte, data, iswrite);
A
Alexander Graf 已提交
469 470
	} else {
		pte->eaddr = eaddr;
A
Alexander Graf 已提交
471
		pte->raddr = eaddr & KVM_PAM;
472
		pte->vpage = VSID_REAL | eaddr >> 12;
A
Alexander Graf 已提交
473 474 475 476
		pte->may_read = true;
		pte->may_write = true;
		pte->may_execute = true;
		r = 0;
477 478 479 480 481 482 483

		if ((kvmppc_get_msr(vcpu) & (MSR_IR | MSR_DR)) == MSR_DR &&
		    !data) {
			if ((vcpu->arch.hflags & BOOK3S_HFLAG_SPLIT_HACK) &&
			    ((eaddr & SPLIT_HACK_MASK) == SPLIT_HACK_OFFS))
			pte->raddr &= ~SPLIT_HACK_MASK;
		}
A
Alexander Graf 已提交
484 485 486 487 488
	}

	return r;
}

489 490
int kvmppc_load_last_inst(struct kvm_vcpu *vcpu,
		enum instruction_fetch_type type, u32 *inst)
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
{
	ulong pc = kvmppc_get_pc(vcpu);
	int r;

	if (type == INST_SC)
		pc -= 4;

	r = kvmppc_ld(vcpu, &pc, sizeof(u32), inst, false);
	if (r == EMULATE_DONE)
		return r;
	else
		return EMULATE_AGAIN;
}
EXPORT_SYMBOL_GPL(kvmppc_load_last_inst);

506 507 508 509 510 511 512 513 514
int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu)
{
	return 0;
}

void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu)
{
}

515 516 517
int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
				  struct kvm_sregs *sregs)
{
518 519 520 521 522 523 524
	int ret;

	vcpu_load(vcpu);
	ret = vcpu->kvm->arch.kvm_ops->get_sregs(vcpu, sregs);
	vcpu_put(vcpu);

	return ret;
525 526 527 528 529
}

int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
				  struct kvm_sregs *sregs)
{
530 531 532 533 534 535 536
	int ret;

	vcpu_load(vcpu);
	ret = vcpu->kvm->arch.kvm_ops->set_sregs(vcpu, sregs);
	vcpu_put(vcpu);

	return ret;
537 538
}

A
Alexander Graf 已提交
539 540 541 542
int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
{
	int i;

543
	regs->pc = kvmppc_get_pc(vcpu);
544
	regs->cr = kvmppc_get_cr(vcpu);
545 546
	regs->ctr = kvmppc_get_ctr(vcpu);
	regs->lr = kvmppc_get_lr(vcpu);
547
	regs->xer = kvmppc_get_xer(vcpu);
548 549 550
	regs->msr = kvmppc_get_msr(vcpu);
	regs->srr0 = kvmppc_get_srr0(vcpu);
	regs->srr1 = kvmppc_get_srr1(vcpu);
A
Alexander Graf 已提交
551
	regs->pid = vcpu->arch.pid;
552 553 554 555 556 557 558 559
	regs->sprg0 = kvmppc_get_sprg0(vcpu);
	regs->sprg1 = kvmppc_get_sprg1(vcpu);
	regs->sprg2 = kvmppc_get_sprg2(vcpu);
	regs->sprg3 = kvmppc_get_sprg3(vcpu);
	regs->sprg4 = kvmppc_get_sprg4(vcpu);
	regs->sprg5 = kvmppc_get_sprg5(vcpu);
	regs->sprg6 = kvmppc_get_sprg6(vcpu);
	regs->sprg7 = kvmppc_get_sprg7(vcpu);
A
Alexander Graf 已提交
560 561

	for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
562
		regs->gpr[i] = kvmppc_get_gpr(vcpu, i);
A
Alexander Graf 已提交
563 564 565 566 567 568 569 570

	return 0;
}

int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
{
	int i;

571
	kvmppc_set_pc(vcpu, regs->pc);
572
	kvmppc_set_cr(vcpu, regs->cr);
573 574
	kvmppc_set_ctr(vcpu, regs->ctr);
	kvmppc_set_lr(vcpu, regs->lr);
575
	kvmppc_set_xer(vcpu, regs->xer);
A
Alexander Graf 已提交
576
	kvmppc_set_msr(vcpu, regs->msr);
577 578 579 580 581 582 583 584 585 586
	kvmppc_set_srr0(vcpu, regs->srr0);
	kvmppc_set_srr1(vcpu, regs->srr1);
	kvmppc_set_sprg0(vcpu, regs->sprg0);
	kvmppc_set_sprg1(vcpu, regs->sprg1);
	kvmppc_set_sprg2(vcpu, regs->sprg2);
	kvmppc_set_sprg3(vcpu, regs->sprg3);
	kvmppc_set_sprg4(vcpu, regs->sprg4);
	kvmppc_set_sprg5(vcpu, regs->sprg5);
	kvmppc_set_sprg6(vcpu, regs->sprg6);
	kvmppc_set_sprg7(vcpu, regs->sprg7);
A
Alexander Graf 已提交
587

588 589
	for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
		kvmppc_set_gpr(vcpu, i, regs->gpr[i]);
A
Alexander Graf 已提交
590 591 592 593 594 595

	return 0;
}

int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
{
596
	return -EOPNOTSUPP;
A
Alexander Graf 已提交
597 598 599 600
}

int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
{
601
	return -EOPNOTSUPP;
A
Alexander Graf 已提交
602 603
}

604 605
int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
			union kvmppc_one_reg *val)
606
{
607
	int r = 0;
608
	long int i;
609

610
	r = vcpu->kvm->arch.kvm_ops->get_one_reg(vcpu, id, val);
611 612
	if (r == -EINVAL) {
		r = 0;
613
		switch (id) {
614
		case KVM_REG_PPC_DAR:
615
			*val = get_reg_val(id, kvmppc_get_dar(vcpu));
616 617
			break;
		case KVM_REG_PPC_DSISR:
618
			*val = get_reg_val(id, kvmppc_get_dsisr(vcpu));
619
			break;
620
		case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
621 622
			i = id - KVM_REG_PPC_FPR0;
			*val = get_reg_val(id, VCPU_FPR(vcpu, i));
623 624
			break;
		case KVM_REG_PPC_FPSCR:
625
			*val = get_reg_val(id, vcpu->arch.fp.fpscr);
626
			break;
627 628 629
#ifdef CONFIG_VSX
		case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
			if (cpu_has_feature(CPU_FTR_VSX)) {
630 631 632
				i = id - KVM_REG_PPC_VSR0;
				val->vsxval[0] = vcpu->arch.fp.fpr[i][0];
				val->vsxval[1] = vcpu->arch.fp.fpr[i][1];
633 634 635 636 637
			} else {
				r = -ENXIO;
			}
			break;
#endif /* CONFIG_VSX */
638 639
		case KVM_REG_PPC_DEBUG_INST:
			*val = get_reg_val(id, INS_TW);
640
			break;
641 642
#ifdef CONFIG_KVM_XICS
		case KVM_REG_PPC_ICP_STATE:
643
			if (!vcpu->arch.icp && !vcpu->arch.xive_vcpu) {
644 645 646
				r = -ENXIO;
				break;
			}
647
			if (xics_on_xive())
648 649 650
				*val = get_reg_val(id, kvmppc_xive_get_icp(vcpu));
			else
				*val = get_reg_val(id, kvmppc_xics_get_icp(vcpu));
651 652
			break;
#endif /* CONFIG_KVM_XICS */
653 654 655 656 657 658 659 660 661 662 663 664
#ifdef CONFIG_KVM_XIVE
		case KVM_REG_PPC_VP_STATE:
			if (!vcpu->arch.xive_vcpu) {
				r = -ENXIO;
				break;
			}
			if (xive_enabled())
				r = kvmppc_xive_native_get_vp(vcpu, val);
			else
				r = -ENXIO;
			break;
#endif /* CONFIG_KVM_XIVE */
665
		case KVM_REG_PPC_FSCR:
666
			*val = get_reg_val(id, vcpu->arch.fscr);
667
			break;
668
		case KVM_REG_PPC_TAR:
669
			*val = get_reg_val(id, vcpu->arch.tar);
670
			break;
671
		case KVM_REG_PPC_EBBHR:
672
			*val = get_reg_val(id, vcpu->arch.ebbhr);
673 674
			break;
		case KVM_REG_PPC_EBBRR:
675
			*val = get_reg_val(id, vcpu->arch.ebbrr);
676 677
			break;
		case KVM_REG_PPC_BESCR:
678
			*val = get_reg_val(id, vcpu->arch.bescr);
679
			break;
680
		case KVM_REG_PPC_IC:
681
			*val = get_reg_val(id, vcpu->arch.ic);
682
			break;
683 684 685 686 687 688 689 690 691
		default:
			r = -EINVAL;
			break;
		}
	}

	return r;
}

692 693
int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,
			union kvmppc_one_reg *val)
694
{
695
	int r = 0;
696
	long int i;
697

698
	r = vcpu->kvm->arch.kvm_ops->set_one_reg(vcpu, id, val);
699 700
	if (r == -EINVAL) {
		r = 0;
701
		switch (id) {
702
		case KVM_REG_PPC_DAR:
703
			kvmppc_set_dar(vcpu, set_reg_val(id, *val));
704 705
			break;
		case KVM_REG_PPC_DSISR:
706
			kvmppc_set_dsisr(vcpu, set_reg_val(id, *val));
707
			break;
708
		case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
709 710
			i = id - KVM_REG_PPC_FPR0;
			VCPU_FPR(vcpu, i) = set_reg_val(id, *val);
711 712
			break;
		case KVM_REG_PPC_FPSCR:
713
			vcpu->arch.fp.fpscr = set_reg_val(id, *val);
714
			break;
715 716 717
#ifdef CONFIG_VSX
		case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
			if (cpu_has_feature(CPU_FTR_VSX)) {
718 719 720
				i = id - KVM_REG_PPC_VSR0;
				vcpu->arch.fp.fpr[i][0] = val->vsxval[0];
				vcpu->arch.fp.fpr[i][1] = val->vsxval[1];
721 722 723 724 725
			} else {
				r = -ENXIO;
			}
			break;
#endif /* CONFIG_VSX */
726 727
#ifdef CONFIG_KVM_XICS
		case KVM_REG_PPC_ICP_STATE:
728
			if (!vcpu->arch.icp && !vcpu->arch.xive_vcpu) {
729 730 731
				r = -ENXIO;
				break;
			}
732
			if (xics_on_xive())
733 734 735
				r = kvmppc_xive_set_icp(vcpu, set_reg_val(id, *val));
			else
				r = kvmppc_xics_set_icp(vcpu, set_reg_val(id, *val));
736 737
			break;
#endif /* CONFIG_KVM_XICS */
738 739 740 741 742 743 744 745 746 747 748 749
#ifdef CONFIG_KVM_XIVE
		case KVM_REG_PPC_VP_STATE:
			if (!vcpu->arch.xive_vcpu) {
				r = -ENXIO;
				break;
			}
			if (xive_enabled())
				r = kvmppc_xive_native_set_vp(vcpu, val);
			else
				r = -ENXIO;
			break;
#endif /* CONFIG_KVM_XIVE */
750
		case KVM_REG_PPC_FSCR:
751
			vcpu->arch.fscr = set_reg_val(id, *val);
752
			break;
753
		case KVM_REG_PPC_TAR:
754
			vcpu->arch.tar = set_reg_val(id, *val);
755
			break;
756
		case KVM_REG_PPC_EBBHR:
757
			vcpu->arch.ebbhr = set_reg_val(id, *val);
758 759
			break;
		case KVM_REG_PPC_EBBRR:
760
			vcpu->arch.ebbrr = set_reg_val(id, *val);
761 762
			break;
		case KVM_REG_PPC_BESCR:
763
			vcpu->arch.bescr = set_reg_val(id, *val);
764
			break;
765
		case KVM_REG_PPC_IC:
766
			vcpu->arch.ic = set_reg_val(id, *val);
767
			break;
768 769 770 771 772 773 774 775 776
		default:
			r = -EINVAL;
			break;
		}
	}

	return r;
}

777 778
void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
{
779
	vcpu->kvm->arch.kvm_ops->vcpu_load(vcpu, cpu);
780 781 782 783
}

void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
{
784
	vcpu->kvm->arch.kvm_ops->vcpu_put(vcpu);
785 786 787 788
}

void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr)
{
789
	vcpu->kvm->arch.kvm_ops->set_msr(vcpu, msr);
790
}
791
EXPORT_SYMBOL_GPL(kvmppc_set_msr);
792

793
int kvmppc_vcpu_run(struct kvm_vcpu *vcpu)
794
{
795
	return vcpu->kvm->arch.kvm_ops->vcpu_run(vcpu);
796 797
}

A
Alexander Graf 已提交
798 799 800 801 802 803
int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
                                  struct kvm_translation *tr)
{
	return 0;
}

804 805 806
int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
					struct kvm_guest_debug *dbg)
{
807
	vcpu_load(vcpu);
808
	vcpu->guest_debug = dbg->control;
809
	vcpu_put(vcpu);
810
	return 0;
811 812
}

813
void kvmppc_decrementer_func(struct kvm_vcpu *vcpu)
814 815 816 817
{
	kvmppc_core_queue_dec(vcpu);
	kvm_vcpu_kick(vcpu);
}
818

819
int kvmppc_core_vcpu_create(struct kvm_vcpu *vcpu)
820
{
821
	return vcpu->kvm->arch.kvm_ops->vcpu_create(vcpu);
822 823 824 825
}

void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
{
826
	vcpu->kvm->arch.kvm_ops->vcpu_free(vcpu);
827 828 829 830
}

int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
{
831
	return vcpu->kvm->arch.kvm_ops->check_requests(vcpu);
832 833
}

834 835 836 837 838
void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot)
{

}

839 840
int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
{
841
	return kvm->arch.kvm_ops->get_dirty_log(kvm, log);
842 843
}

844
void kvmppc_core_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
845
{
846
	kvm->arch.kvm_ops->free_memslot(slot);
847 848 849 850
}

void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
{
851
	kvm->arch.kvm_ops->flush_memslot(kvm, memslot);
852 853 854 855
}

int kvmppc_core_prepare_memory_region(struct kvm *kvm,
				struct kvm_memory_slot *memslot,
856 857
				const struct kvm_userspace_memory_region *mem,
				enum kvm_mr_change change)
858
{
859 860
	return kvm->arch.kvm_ops->prepare_memory_region(kvm, memslot, mem,
							change);
861 862 863
}

void kvmppc_core_commit_memory_region(struct kvm *kvm,
864
				const struct kvm_userspace_memory_region *mem,
865
				const struct kvm_memory_slot *old,
866 867
				const struct kvm_memory_slot *new,
				enum kvm_mr_change change)
868
{
869
	kvm->arch.kvm_ops->commit_memory_region(kvm, mem, old, new, change);
870 871
}

872
bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range)
873
{
874
	return kvm->arch.kvm_ops->unmap_gfn_range(kvm, range);
875 876
}

877
bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
878
{
879
	return kvm->arch.kvm_ops->age_gfn(kvm, range);
880 881
}

882
bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
883
{
884
	return kvm->arch.kvm_ops->test_age_gfn(kvm, range);
885 886
}

887
bool kvm_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
888
{
889
	return kvm->arch.kvm_ops->set_spte_gfn(kvm, range);
890 891 892 893 894 895
}

int kvmppc_core_init_vm(struct kvm *kvm)
{

#ifdef CONFIG_PPC64
896
	INIT_LIST_HEAD_RCU(&kvm->arch.spapr_tce_tables);
897
	INIT_LIST_HEAD(&kvm->arch.rtas_tokens);
898
	mutex_init(&kvm->arch.rtas_token_lock);
899 900
#endif

901
	return kvm->arch.kvm_ops->init_vm(kvm);
902 903 904 905
}

void kvmppc_core_destroy_vm(struct kvm *kvm)
{
906
	kvm->arch.kvm_ops->destroy_vm(kvm);
907 908 909 910 911

#ifdef CONFIG_PPC64
	kvmppc_rtas_tokens_free(kvm);
	WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables));
#endif
912 913 914

#ifdef CONFIG_KVM_XICS
	/*
915
	 * Free the XIVE and XICS devices which are not directly freed by the
916 917 918 919 920 921
	 * device 'release' method
	 */
	kfree(kvm->arch.xive_devices.native);
	kvm->arch.xive_devices.native = NULL;
	kfree(kvm->arch.xive_devices.xics_on_xive);
	kvm->arch.xive_devices.xics_on_xive = NULL;
922 923
	kfree(kvm->arch.xics_device);
	kvm->arch.xics_device = NULL;
924
#endif /* CONFIG_KVM_XICS */
925 926
}

927 928 929 930 931
int kvmppc_h_logical_ci_load(struct kvm_vcpu *vcpu)
{
	unsigned long size = kvmppc_get_gpr(vcpu, 4);
	unsigned long addr = kvmppc_get_gpr(vcpu, 5);
	u64 buf;
932
	int srcu_idx;
933 934 935 936 937
	int ret;

	if (!is_power_of_2(size) || (size > sizeof(buf)))
		return H_TOO_HARD;

938
	srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
939
	ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, addr, size, &buf);
940
	srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx);
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
	if (ret != 0)
		return H_TOO_HARD;

	switch (size) {
	case 1:
		kvmppc_set_gpr(vcpu, 4, *(u8 *)&buf);
		break;

	case 2:
		kvmppc_set_gpr(vcpu, 4, be16_to_cpu(*(__be16 *)&buf));
		break;

	case 4:
		kvmppc_set_gpr(vcpu, 4, be32_to_cpu(*(__be32 *)&buf));
		break;

	case 8:
		kvmppc_set_gpr(vcpu, 4, be64_to_cpu(*(__be64 *)&buf));
		break;

	default:
		BUG();
	}

	return H_SUCCESS;
}
EXPORT_SYMBOL_GPL(kvmppc_h_logical_ci_load);

int kvmppc_h_logical_ci_store(struct kvm_vcpu *vcpu)
{
	unsigned long size = kvmppc_get_gpr(vcpu, 4);
	unsigned long addr = kvmppc_get_gpr(vcpu, 5);
	unsigned long val = kvmppc_get_gpr(vcpu, 6);
	u64 buf;
975
	int srcu_idx;
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
	int ret;

	switch (size) {
	case 1:
		*(u8 *)&buf = val;
		break;

	case 2:
		*(__be16 *)&buf = cpu_to_be16(val);
		break;

	case 4:
		*(__be32 *)&buf = cpu_to_be32(val);
		break;

	case 8:
		*(__be64 *)&buf = cpu_to_be64(val);
		break;

	default:
		return H_TOO_HARD;
	}

999
	srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
1000
	ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, addr, size, &buf);
1001
	srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx);
1002 1003 1004 1005 1006 1007 1008
	if (ret != 0)
		return H_TOO_HARD;

	return H_SUCCESS;
}
EXPORT_SYMBOL_GPL(kvmppc_h_logical_ci_store);

1009 1010
int kvmppc_core_check_processor_compat(void)
{
1011 1012
	/*
	 * We always return 0 for book3s. We check
1013
	 * for compatibility while loading the HV
1014 1015 1016 1017 1018
	 * or PR module
	 */
	return 0;
}

1019 1020 1021 1022 1023
int kvmppc_book3s_hcall_implemented(struct kvm *kvm, unsigned long hcall)
{
	return kvm->arch.kvm_ops->hcall_implemented(hcall);
}

1024 1025 1026 1027
#ifdef CONFIG_KVM_XICS
int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level,
		bool line_status)
{
1028
	if (xics_on_xive())
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
		return kvmppc_xive_set_irq(kvm, irq_source_id, irq, level,
					   line_status);
	else
		return kvmppc_xics_set_irq(kvm, irq_source_id, irq, level,
					   line_status);
}

int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *irq_entry,
			      struct kvm *kvm, int irq_source_id,
			      int level, bool line_status)
{
	return kvm_set_irq(kvm, irq_source_id, irq_entry->gsi,
			   level, line_status);
}
static int kvmppc_book3s_set_irq(struct kvm_kernel_irq_routing_entry *e,
				 struct kvm *kvm, int irq_source_id, int level,
				 bool line_status)
{
	return kvm_set_irq(kvm, irq_source_id, e->gsi, level, line_status);
}

int kvm_irq_map_gsi(struct kvm *kvm,
		    struct kvm_kernel_irq_routing_entry *entries, int gsi)
{
	entries->gsi = gsi;
	entries->type = KVM_IRQ_ROUTING_IRQCHIP;
	entries->set = kvmppc_book3s_set_irq;
	entries->irqchip.irqchip = 0;
	entries->irqchip.pin = gsi;
	return 1;
}

int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned irqchip, unsigned pin)
{
	return pin;
}

#endif /* CONFIG_KVM_XICS */

1068 1069 1070 1071 1072 1073 1074
static int kvmppc_book3s_init(void)
{
	int r;

	r = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
	if (r)
		return r;
1075
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
1076 1077 1078
	r = kvmppc_book3s_init_pr();
#endif

1079 1080
#ifdef CONFIG_KVM_XICS
#ifdef CONFIG_KVM_XIVE
1081
	if (xics_on_xive()) {
1082
		kvm_register_device_ops(&kvm_xive_ops, KVM_DEV_TYPE_XICS);
1083
		if (kvmppc_xive_native_supported())
1084 1085
			kvm_register_device_ops(&kvm_xive_native_ops,
						KVM_DEV_TYPE_XIVE);
1086 1087 1088 1089 1090
	} else
#endif
		kvm_register_device_ops(&kvm_xics_ops, KVM_DEV_TYPE_XICS);
#endif
	return r;
1091 1092 1093 1094
}

static void kvmppc_book3s_exit(void)
{
1095
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
1096 1097 1098
	kvmppc_book3s_exit_pr();
#endif
	kvm_exit();
1099
}
1100 1101 1102

module_init(kvmppc_book3s_init);
module_exit(kvmppc_book3s_exit);
1103 1104

/* On 32bit this is our one and only kernel module */
1105
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
1106 1107 1108
MODULE_ALIAS_MISCDEV(KVM_MINOR);
MODULE_ALIAS("devname:kvm");
#endif