21 #include <linux/errno.h>
25 #include <linux/hrtimer.h>
27 #include <linux/slab.h>
28 #include <asm/cputable.h>
29 #include <asm/uaccess.h>
31 #include <asm/tlbflush.h>
34 #include "../mm/mmu_decl.h"
36 #define CREATE_TRACE_POINTS
41 return !(v->
arch.shared->msr & MSR_WE) ||
42 !!(v->
arch.pending_exceptions) ||
53 int nr = kvmppc_get_gpr(vcpu, 11);
61 if (!(vcpu->
arch.shared->msr & MSR_SF)) {
73 vcpu->
arch.magic_page_ea = param2;
82 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
94 kvmppc_set_gpr(vcpu, 4, r2);
111 #ifdef CONFIG_KVM_BOOK3S_64_HV
113 if (!vcpu->
arch.papr_enabled)
117 #ifdef CONFIG_KVM_BOOKE_HV
152 kvmppc_get_last_inst(vcpu));
234 #ifndef CONFIG_KVM_BOOK3S_64_HV
238 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
247 #ifdef CONFIG_PPC_BOOK3S_64
253 #ifdef CONFIG_KVM_BOOK3S_64_HV
274 #ifdef CONFIG_KVM_BOOK3S_64_HV
283 #ifdef CONFIG_PPC_BOOK3S_64
297 unsigned int ioctl,
unsigned long arg)
305 if (!dont || free->
arch.rmap != dont->
arch.rmap) {
314 if (!slot->
arch.rmap)
351 vcpu->
arch.wqp = &vcpu->
wq;
386 tasklet_schedule(&vcpu->
arch.tasklet);
396 vcpu->arch.dec_expires = ~(
u64)0;
398 #ifdef CONFIG_KVM_EXIT_TIMING
441 static void kvmppc_complete_dcr_load(
struct kvm_vcpu *vcpu,
444 kvmppc_set_gpr(vcpu, vcpu->
arch.io_gpr, run->
dcr.data);
447 static void kvmppc_complete_mmio_load(
struct kvm_vcpu *vcpu,
452 if (run->
mmio.len >
sizeof(gpr)) {
457 if (vcpu->
arch.mmio_is_bigendian) {
458 switch (run->
mmio.len) {
459 case 8: gpr = *(
u64 *)run->
mmio.data;
break;
460 case 4: gpr = *(
u32 *)run->
mmio.data;
break;
461 case 2: gpr = *(
u16 *)run->
mmio.data;
break;
462 case 1: gpr = *(
u8 *)run->
mmio.data;
break;
466 switch (run->
mmio.len) {
467 case 4: gpr = ld_le32((
u32 *)run->
mmio.data);
break;
468 case 2: gpr = ld_le16((
u16 *)run->
mmio.data);
break;
469 case 1: gpr = *(
u8 *)run->
mmio.data;
break;
473 if (vcpu->
arch.mmio_sign_extend) {
474 switch (run->
mmio.len) {
489 kvmppc_set_gpr(vcpu, vcpu->
arch.io_gpr, gpr);
493 kvmppc_set_gpr(vcpu, vcpu->
arch.io_gpr, gpr);
498 #ifdef CONFIG_PPC_BOOK3S
513 unsigned int rt,
unsigned int bytes,
int is_bigendian)
515 if (bytes >
sizeof(run->
mmio.data)) {
520 run->
mmio.phys_addr = vcpu->
arch.paddr_accessed;
522 run->
mmio.is_write = 0;
524 vcpu->
arch.io_gpr = rt;
525 vcpu->
arch.mmio_is_bigendian = is_bigendian;
526 vcpu->mmio_needed = 1;
527 vcpu->mmio_is_write = 0;
528 vcpu->
arch.mmio_sign_extend = 0;
535 unsigned int rt,
unsigned int bytes,
int is_bigendian)
540 vcpu->
arch.mmio_sign_extend = 1;
550 if (bytes >
sizeof(run->
mmio.data)) {
555 run->
mmio.phys_addr = vcpu->
arch.paddr_accessed;
557 run->
mmio.is_write = 1;
558 vcpu->mmio_needed = 1;
559 vcpu->mmio_is_write = 1;
564 case 8: *(
u64 *)data = val;
break;
565 case 4: *(
u32 *)data = val;
break;
566 case 2: *(
u16 *)data = val;
break;
567 case 1: *(
u8 *)data = val;
break;
572 case 4: st_le32(data, val);
break;
573 case 2: st_le16(data, val);
break;
574 case 1: *(
u8 *)data = val;
break;
589 if (vcpu->mmio_needed) {
590 if (!vcpu->mmio_is_write)
591 kvmppc_complete_mmio_load(vcpu, run);
592 vcpu->mmio_needed = 0;
593 }
else if (vcpu->
arch.dcr_needed) {
594 if (!vcpu->
arch.dcr_is_write)
595 kvmppc_complete_dcr_load(vcpu, run);
596 vcpu->
arch.dcr_needed = 0;
597 }
else if (vcpu->
arch.osi_needed) {
598 u64 *gprs = run->
osi.gprs;
601 for (i = 0; i < 32; i++)
602 kvmppc_set_gpr(vcpu, i, gprs[i]);
603 vcpu->
arch.osi_needed = 0;
604 }
else if (vcpu->
arch.hcall_needed) {
608 for (i = 0; i < 9; ++
i)
609 kvmppc_set_gpr(vcpu, 4 + i, run->
papr_hcall.args[i]);
610 vcpu->
arch.hcall_needed = 0;
635 static int kvm_vcpu_ioctl_enable_cap(
struct kvm_vcpu *vcpu,
646 vcpu->
arch.osi_enabled =
true;
650 vcpu->
arch.papr_enabled =
true;
652 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
689 unsigned int ioctl,
unsigned long arg)
711 r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
729 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
749 return VM_FAULT_SIGBUS;
754 u32 inst_lis = 0x3c000000;
755 u32 inst_ori = 0x60000000;
756 u32 inst_nop = 0x60000000;
757 u32 inst_sc = 0x44000002;
758 u32 inst_imm_mask = 0xffff;
771 pvinfo->
hcall[2] = inst_sc;
772 pvinfo->
hcall[3] = inst_nop;
778 unsigned int ioctl,
unsigned long arg)
786 memset(&pvinfo, 0,
sizeof(pvinfo));
787 r = kvm_vm_ioctl_get_pvinfo(&pvinfo);
795 #ifdef CONFIG_PPC_BOOK3S_64
808 #ifdef CONFIG_KVM_BOOK3S_64_HV
837 #ifdef CONFIG_PPC_BOOK3S_64
842 memset(&info, 0,
sizeof(info));
858 static unsigned long nr_lpids;
866 if (lpid >= nr_lpids) {
867 pr_err(
"%s: No LPIDs free\n", __func__);
888 memset(lpid_inuse, 0,
sizeof(lpid_inuse));