From: Christian Ehrhardt <ehrhardt@xxxxxxxxxxxxxxxxxx> Interrupt delivery is usually followed by several exits to fetch e.g. dear, esr, srr0, srr1. To easen that this patch adds guest code rewriting using the magic page mechanism for these four special purpose registers. This patch rewrites reads and writes to this registers and also the kvm code in the interrupt delivery/ rfi path that writes/reads those. Since this patch is touching the dump_tlb and dump_vcpu functions it is fixing all the missing printk KERN_* levels avoiding checkpatch noise. Signed-off-by: Christian Ehrhardt <ehrhardt@xxxxxxxxxxxxxxxxxx> --- [diffstat] arch/powerpc/kvm/booke_guest.c | 43 ++++++++++++---- arch/powerpc/kvm/emulate.c | 107 +++++++++++++++++++++++++++++++++++++---- include/asm-powerpc/kvm_para.h | 4 + 3 files changed, 134 insertions(+), 20 deletions(-) [diff] diff --git a/arch/powerpc/kvm/booke_guest.c b/arch/powerpc/kvm/booke_guest.c --- a/arch/powerpc/kvm/booke_guest.c +++ b/arch/powerpc/kvm/booke_guest.c @@ -120,14 +120,14 @@ struct tlbe *tlbe; int i; - printk("vcpu %d TLB dump:\n", vcpu->vcpu_id); - printk("| %2s | %3s | %8s | %8s | %8s |\n", + printk(KERN_ERR"vcpu %d TLB dump:\n", vcpu->vcpu_id); + printk(KERN_ERR"| %2s | %3s | %8s | %8s | %8s |\n", "nr", "tid", "word0", "word1", "word2"); for (i = 0; i < PPC44x_TLB_SIZE; i++) { tlbe = &vcpu->arch.guest_tlb[i]; if (tlbe->word0 & PPC44x_TLB_VALID) - printk(" G%2d | %02X | %08X | %08X | %08X |\n", + printk(KERN_ERR" G%2d | %02X | %08X | %08X | %08X |\n", i, tlbe->tid, tlbe->word0, tlbe->word1, tlbe->word2); } @@ -135,7 +135,7 @@ for (i = 0; i < PPC44x_TLB_SIZE; i++) { tlbe = &vcpu->arch.shadow_tlb[i]; if (tlbe->word0 & PPC44x_TLB_VALID) - printk(" S%2d | %02X | %08X | %08X | %08X |\n", + printk(KERN_ERR" S%2d | %02X | %08X | %08X | %08X |\n", i, tlbe->tid, tlbe->word0, tlbe->word1, tlbe->word2); } @@ -146,18 +146,28 @@ { int i; - printk("pc: %08x msr: %08x\n", vcpu->arch.pc, vcpu->arch.msr); - printk("lr: %08x ctr: %08x\n", vcpu->arch.lr, vcpu->arch.ctr); - printk("srr0: %08x srr1: %08x\n", vcpu->arch.srr0, vcpu->arch.srr1); + printk(KERN_ERR"pc: %08x msr: %08x\n", + vcpu->arch.pc, vcpu->arch.msr); + printk(KERN_ERR"lr: %08x ctr: %08x\n", + vcpu->arch.lr, vcpu->arch.ctr); + printk(KERN_ERR"srr0: %08x srr1: %08x\n", + vcpu->arch.srr0, vcpu->arch.srr1); printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions); for (i = 0; i < 32; i += 4) { - printk("gpr%02d: %08x %08x %08x %08x\n", i, + printk(KERN_ERR"gpr%02d: %08x %08x %08x %08x\n", i, vcpu->arch.gpr[i], vcpu->arch.gpr[i+1], vcpu->arch.gpr[i+2], vcpu->arch.gpr[i+3]); + } + + if (kvmppc_has_pvmem(vcpu)) { + printk(KERN_ERR"vcpu has pvmem enabled\n"); + printk(KERN_ERR"srr0: %08x srr1: %08x (PVMEM)\n", + kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR0), + kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR1)); } } @@ -203,8 +213,17 @@ break; } - vcpu->arch.srr0 = vcpu->arch.pc; - vcpu->arch.srr1 = vcpu->arch.msr; + if (kvmppc_has_pvmem(vcpu)) { + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR0, vcpu->arch.pc); + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR1, vcpu->arch.msr); + /* only modified on interrupt delivery path */ + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_DEAR, vcpu->arch.dear); + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_ESR, vcpu->arch.esr); + } else { + vcpu->arch.srr0 = vcpu->arch.pc; + vcpu->arch.srr1 = vcpu->arch.msr; + } + vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[interrupt]; kvmppc_set_msr(vcpu, vcpu->arch.msr & interrupt_msr_mask[interrupt]); } @@ -549,6 +568,8 @@ regs->sprg1 = kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SPRG1); regs->sprg2 = kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SPRG2); regs->sprg3 = kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SPRG3); + regs->srr0 = kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR0); + regs->srr1 = kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR1); } return 0; @@ -582,6 +603,8 @@ kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SPRG1, regs->sprg1); kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SPRG2, regs->sprg2); kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SPRG3, regs->sprg3); + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR0, regs->srr0); + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR1, regs->srr1); } return 0; diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c --- a/arch/powerpc/kvm/emulate.c +++ b/arch/powerpc/kvm/emulate.c @@ -233,8 +233,14 @@ static void kvmppc_emul_rfi(struct kvm_vcpu *vcpu) { - vcpu->arch.pc = vcpu->arch.srr0; - kvmppc_set_msr(vcpu, vcpu->arch.srr1); + if (kvmppc_has_pvmem(vcpu)) { + vcpu->arch.pc = kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR0); + kvmppc_set_msr(vcpu, + kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR1)); + } else { + vcpu->arch.pc = vcpu->arch.srr0; + kvmppc_set_msr(vcpu, vcpu->arch.srr1); + } } int kvmppc_do_hypercall(struct kvm_vcpu *vcpu) @@ -265,6 +271,14 @@ vcpu->arch.sprg2); kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SPRG3, vcpu->arch.sprg3); + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR0, + vcpu->arch.srr0); + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR1, + vcpu->arch.srr1); + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_DEAR, + vcpu->arch.dear); + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_ESR, + vcpu->arch.esr); break; default: printk(KERN_ERR "unknown hypercall %d\n", vcpu->arch.gpr[11]); @@ -306,6 +320,18 @@ case SPRN_SPRG3: offset = KVM_PPCPV_OFFSET_SPRG3; break; + case SPRN_SRR0: + offset = KVM_PPCPV_OFFSET_SRR0; + break; + case SPRN_SRR1: + offset = KVM_PPCPV_OFFSET_SRR1; + break; + case SPRN_DEAR: + offset = KVM_PPCPV_OFFSET_DEAR; + break; + case SPRN_ESR: + offset = KVM_PPCPV_OFFSET_ESR; + break; default: err = -EFAULT; } @@ -325,6 +351,18 @@ break; case SPRN_SPRG3: offset = KVM_PPCPV_OFFSET_SPRG3; + break; + case SPRN_SRR0: + offset = KVM_PPCPV_OFFSET_SRR0; + break; + case SPRN_SRR1: + offset = KVM_PPCPV_OFFSET_SRR1; + break; + case SPRN_DEAR: + offset = KVM_PPCPV_OFFSET_DEAR; + break; + case SPRN_ESR: + offset = KVM_PPCPV_OFFSET_ESR; break; default: err = -EFAULT; @@ -411,6 +449,22 @@ sprn = get_sprn(inst); rt = get_rt(inst); switch (sprn) { + case SPRN_SRR0: + vcpu->arch.gpr[rt] = kvmppc_get_pvreg(vcpu, + KVM_PPCPV_OFFSET_SRR0); + break; + case SPRN_SRR1: + vcpu->arch.gpr[rt] = kvmppc_get_pvreg(vcpu, + KVM_PPCPV_OFFSET_SRR1); + break; + case SPRN_DEAR: + vcpu->arch.gpr[rt] = kvmppc_get_pvreg(vcpu, + KVM_PPCPV_OFFSET_DEAR); + break; + case SPRN_ESR: + vcpu->arch.gpr[rt] = kvmppc_get_pvreg(vcpu, + KVM_PPCPV_OFFSET_ESR); + break; case SPRN_SPRG0: vcpu->arch.gpr[rt] = kvmppc_get_pvreg(vcpu, KVM_PPCPV_OFFSET_SPRG0); @@ -438,6 +492,23 @@ sprn = get_sprn(inst); rs = get_rs(inst); switch (sprn) { + case SPRN_SRR0: + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR0, + vcpu->arch.gpr[rs]); + break; + case SPRN_SRR1: + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SRR1, + vcpu->arch.gpr[rs]); + break; + case SPRN_DEAR: + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_DEAR, + vcpu->arch.gpr[rs]); + break; + case SPRN_ESR: + kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_ESR, + vcpu->arch.gpr[rs]); + break; + case SPRN_SPRG0: kvmppc_set_pvreg(vcpu, KVM_PPCPV_OFFSET_SPRG0, vcpu->arch.gpr[rs]); @@ -643,9 +714,13 @@ switch (sprn) { case SPRN_SRR0: - vcpu->arch.gpr[rt] = vcpu->arch.srr0; break; + vcpu->arch.gpr[rt] = vcpu->arch.srr0; + rewritable = 1; + break; case SPRN_SRR1: - vcpu->arch.gpr[rt] = vcpu->arch.srr1; break; + vcpu->arch.gpr[rt] = vcpu->arch.srr1; + rewritable = 1; + break; case SPRN_MMUCR: vcpu->arch.gpr[rt] = vcpu->arch.mmucr; break; case SPRN_PID: @@ -659,9 +734,13 @@ case SPRN_PVR: vcpu->arch.gpr[rt] = vcpu->arch.pvr; break; case SPRN_DEAR: - vcpu->arch.gpr[rt] = vcpu->arch.dear; break; + vcpu->arch.gpr[rt] = vcpu->arch.dear; + rewritable = 1; + break; case SPRN_ESR: - vcpu->arch.gpr[rt] = vcpu->arch.esr; break; + vcpu->arch.gpr[rt] = vcpu->arch.esr; + rewritable = 1; + break; case SPRN_DBCR0: vcpu->arch.gpr[rt] = vcpu->arch.dbcr0; break; case SPRN_DBCR1: @@ -783,9 +862,13 @@ rs = get_rs(inst); switch (sprn) { case SPRN_SRR0: - vcpu->arch.srr0 = vcpu->arch.gpr[rs]; break; + vcpu->arch.srr0 = vcpu->arch.gpr[rs]; + rewritable = 1; + break; case SPRN_SRR1: - vcpu->arch.srr1 = vcpu->arch.gpr[rs]; break; + vcpu->arch.srr1 = vcpu->arch.gpr[rs]; + rewritable = 1; + break; case SPRN_MMUCR: vcpu->arch.mmucr = vcpu->arch.gpr[rs]; break; case SPRN_PID: @@ -795,9 +878,13 @@ case SPRN_CCR1: vcpu->arch.ccr1 = vcpu->arch.gpr[rs]; break; case SPRN_DEAR: - vcpu->arch.dear = vcpu->arch.gpr[rs]; break; + vcpu->arch.dear = vcpu->arch.gpr[rs]; + rewritable = 1; + break; case SPRN_ESR: - vcpu->arch.esr = vcpu->arch.gpr[rs]; break; + vcpu->arch.esr = vcpu->arch.gpr[rs]; + rewritable = 1; + break; case SPRN_DBCR0: vcpu->arch.dbcr0 = vcpu->arch.gpr[rs]; break; case SPRN_DBCR1: diff --git a/include/asm-powerpc/kvm_para.h b/include/asm-powerpc/kvm_para.h --- a/include/asm-powerpc/kvm_para.h +++ b/include/asm-powerpc/kvm_para.h @@ -44,6 +44,10 @@ #define KVM_PPCPV_OFFSET_SPRG1 0x04 #define KVM_PPCPV_OFFSET_SPRG2 0x08 #define KVM_PPCPV_OFFSET_SPRG3 0x0C +#define KVM_PPCPV_OFFSET_SRR0 0x10 +#define KVM_PPCPV_OFFSET_SRR1 0x14 +#define KVM_PPCPV_OFFSET_DEAR 0x18 +#define KVM_PPCPV_OFFSET_ESR 0x1C static inline int kvm_para_available(void) { -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html