ppc patch queue 2012-05-06
Subsystems (4)
Hi Avi,
This is my current patch queue for ppc. Please pull.
Alex
The following changes since commit e726b1bd64b0b8945c171d2d4bf749fba9fc0800:
Christian Borntraeger (1):
KVM: s390: implement KVM_CAP_NR/MAX_VCPUS
are available in the git repository at:
git://github.com/agraf/linux-2.6.git for-upstream
Alexander Graf (8):
KVM: PPC: Restrict PPC_[L|ST]D macro to asm code
KVM: PPC: Book3S: PR: Optimize entry path
KVM: PPC: Book3S: PR: No isync in slbie path
KVM: PPC: Fix stbux emulation
KVM: PPC: Fix PR KVM on POWER7 bare metal
KVM: PPC: Book3S: Enable IRQs during exit handling
KVM: PPC: Emulator: clean up instruction parsing
KVM: PPC: Emulator: clean up SPR reads and writes
Benjamin Herrenschmidt (2):
kvm/book3s: Make kernel emulated H_PUT_TCE available for "PR" KVM kvm/powerpc: Add new ioctl to retreive server MMU infos
Bharat Bhushan (2):
KVM: Use minimum and maximum address mapped by TLB1
KVM: PPC: Use clockevent multiplier and shifter for decrementer
Mihai Caraman (2):
KVM: PPC: bookehv: Use lwz/stw instead of PPC_LL/PPC_STL for 32-bit fields
KVM: PPC: bookehv: Fix r8/r13 storing in level exception handler
Varun Sethi (2):
KVM: PPC: bookehv: Use a Macro for saving/restoring guest registers to/from their 64 bit copies.
KVM: PPC: booke(hv): Fix save/restore of guest accessible SPRGs.
Documentation/virtual/kvm/api.txt | 70 +++++++++++++++ arch/powerpc/include/asm/kvm_asm.h | 10 ++ arch/powerpc/include/asm/kvm_host.h | 4 +- arch/powerpc/include/asm/kvm_ppc.h | 10 ++- arch/powerpc/include/asm/time.h | 1 + arch/powerpc/kernel/ppc_ksyms.c | 4 + arch/powerpc/kernel/time.c | 3 +- arch/powerpc/kvm/44x_emulate.c | 51 ++++------- arch/powerpc/kvm/Makefile | 2 + arch/powerpc/kvm/book3s_64_slb.S | 2 - arch/powerpc/kvm/book3s_64_vio.c | 150 +++++++++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_64_vio_hv.c | 3 + arch/powerpc/kvm/book3s_emulate.c | 106 ++++++++++++----------- arch/powerpc/kvm/book3s_hv.c | 145 ++++++++------------------------ arch/powerpc/kvm/book3s_pr.c | 35 ++++++++ arch/powerpc/kvm/book3s_pr_papr.c | 18 ++++ arch/powerpc/kvm/book3s_segment.S | 48 +++++++---- arch/powerpc/kvm/booke.h | 4 +- arch/powerpc/kvm/booke_emulate.c | 95 ++++++++++++--------- arch/powerpc/kvm/booke_interrupts.S | 8 +- arch/powerpc/kvm/bookehv_interrupts.S | 58 +++++-------- arch/powerpc/kvm/e500.h | 4 + arch/powerpc/kvm/e500_emulate.c | 126 ++++++++++++++++------------ arch/powerpc/kvm/e500_tlb.c | 88 +++++++++++++++++++- arch/powerpc/kvm/emulate.c | 146 +++++++++++--------------------- arch/powerpc/kvm/powerpc.c | 26 +++++- include/linux/kvm.h | 27 ++++++ 27 files changed, 782 insertions(+), 462 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_64_vio.c
PATCH 1/16 KVM: Use minimum and maximum address mapped by TLB1
From: Bharat Bhushan <[email protected]>
Keep track of minimum and maximum address mapped by tlb1.
This helps in TLBMISS handling in KVM to quick check whether the address lies in mapped range. If address does not lies in this range then no need to look in each tlb1 entry of tlb1 array.
--- arch/powerpc/kvm/e500.h | 4 ++ arch/powerpc/kvm/e500_tlb.c | 88 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-)
arch/powerpc/kvm/e500.h +4 -0
@@ -89,6 +89,10 @@ struct kvmppc_vcpu_e500 {u64 *g2h_tlb1_map;unsigned int *h2g_tlb1_rmap; +/* Minimum and maximum address mapped my TLB1 */ +unsigned long tlb1_min_eaddr; +unsigned long tlb1_max_eaddr; +#ifdef CONFIG_KVM_E500V2 u32 pid[E500_PID_NUM ];
arch/powerpc/kvm/e500_tlb.c +86 -2
143 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 2/16 KVM: PPC: Use clockevent multiplier and shifter for decrementer
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
Time for which the hrtimer is started for decrementer emulation is calculated using tb_ticks_per_usec. While hrtimer uses the clockevent for DEC reprogramming (if needed) and which calculate timebase ticks using the multiplier and shifter mechanism implemented within clockevent layer.
It was observed that this conversion (timebase->time->timebase) are not correct because the mechanism are not consistent.
In our setup it adds 2% jitter.
With this patch clockevent multiplier and shifter mechanism are used when starting hrtimer for decrementer emulation. Now the jitter is < 0.5%.
--- arch/powerpc/include/asm/time.h | 1 + arch/powerpc/kernel/time.c | 3 ++- arch/powerpc/kvm/emulate.c | 9 +++++++-- 3 files changed, 10 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/time.h +1 -0
@@ -23,6 +23,7 @@extern unsigned long tb_ticks_per_jiffy;extern unsigned long tb_ticks_per_usec;extern unsigned long tb_ticks_per_sec; +extern struct clock_event_device decrementer_clockevent;struct rtc_time ;extern void to_tm (int tim,struct rtc_time * tm);
arch/powerpc/kernel/time.c +2 -1
@@ -100,7 +100,7 @@ static int decrementer_set_next_event(unsigned long evt,static void decrementer_set_mode (enum clock_event_mode mode,struct clock_event_device *dev); -static struct clock_event_device decrementer_clockevent = { +struct clock_event_device decrementer_clockevent = { .name ="decrementer" , .rating =200 , .irq =0 ,
@@ -108,6 +108,7 @@ static struct clock_event_device decrementer_clockevent = { .set_mode = decrementer_set_mode, .features = CLOCK_EVT_FEAT_ONESHOT, }; +EXPORT_SYMBOL (decrementer_clockevent);DEFINE_PER_CPU (u64, decrementers_next_tb); static DEFINE_PER_CPU(struct clock_event_device, decrementers);
arch/powerpc/kvm/emulate.c +7 -2
@@ -23,6 +23,7 @@#include <linux/types.h> #include <linux/string.h> #include <linux/kvm_host.h> +#include <linux/clockchips.h> #include <asm/reg.h> #include <asm/time.h>
@@ -104,8 +105,12 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)*/ dec_time = vcpu->arch.dec; - dec_time *=1000 ; -do_div (dec_time, tb_ticks_per_usec); +/* +* Guest timebase ticks at the same frequency as host decrementer. +* So use the host decrementer calculations for decrementer emulation. +*/ + dec_time = dec_time << decrementer_clockevent.shift; +do_div (dec_time, decrementer_clockevent.mult); dec_nsec =do_div (dec_time,NSEC_PER_SEC );hrtimer_start (&vcpu->arch.dec_timer,ktime_set (dec_time, dec_nsec),HRTIMER_MODE_REL );
Signature · 1 line
1.6.0.2
PATCH 3/16 KVM: PPC: bookehv: Use a Macro for saving/restoring guest registers to/from their 64 bit copies.
In reply to Alexander GrafFrom: Varun Sethi <[email protected]>
Introduced PPC_STD/PPC_LD macros for saving/restoring guest registers to/from their 64 bit copies.
--- arch/powerpc/include/asm/kvm_asm.h | 8 ++++++++ arch/powerpc/kvm/bookehv_interrupts.S | 24 ++++-------------------- 2 files changed, 12 insertions(+), 20 deletions(-)
arch/powerpc/include/asm/kvm_asm.h +8 -0
@@ -20,6 +20,14 @@#ifndef __POWERPC_KVM_ASM_H__#define __POWERPC_KVM_ASM_H__ +#ifdef CONFIG_64BIT +#define PPC_STD (sreg, offset, areg) std sreg, (offset)(areg) +#define PPC_LD (treg, offset, areg) ld treg, (offset)(areg) +#else +#define PPC_STD (sreg, offset, areg) stw sreg, (offset+4)(areg) +#define PPC_LD (treg, offset, areg) lwz treg, (offset+4)(areg) +#endif +/* IVPR must be 64KiB-aligned. */ #define VCPU_SIZE_ORDER 4#define VCPU_SIZE_LOG (VCPU_SIZE_ORDER + 12)
arch/powerpc/kvm/bookehv_interrupts.S +4 -20
@@ -93,11 +93,7 @@ #endif oris r8, r6, MSR_CE@h -#ifdef CONFIG_64BIT - std r6, (VCPU_SHARED_MSR)(r11) -#else - stw r6, (VCPU_SHARED_MSR + 4)(r11) -#endif + PPC_STD(r6, VCPU_SHARED_MSR, r11) ori r8, r8, MSR_ME | MSR_RI PPC_STL r5, VCPU_PC(r4)
@@ -335,11 +331,7 @@ _GLOBAL(kvmppc_resume_host) stw r5, VCPU_SHARED_MAS0(r11) mfspr r7, SPRN_MAS2 stw r6, VCPU_SHARED_MAS1(r11) -#ifdef CONFIG_64BIT - std r7, (VCPU_SHARED_MAS2)(r11) -#else - stw r7, (VCPU_SHARED_MAS2 + 4)(r11) -#endif + PPC_STD(r7, VCPU_SHARED_MAS2, r11) mfspr r5, SPRN_MAS3 mfspr r6, SPRN_MAS4 stw r5, VCPU_SHARED_MAS7_3+4(r11)
@@ -527,11 +519,7 @@ lightweight_exit: stw r3, VCPU_HOST_MAS6(r4) lwz r3, VCPU_SHARED_MAS0(r11) lwz r5, VCPU_SHARED_MAS1(r11) -#ifdef CONFIG_64BIT - ld r6, (VCPU_SHARED_MAS2)(r11) -#else - lwz r6, (VCPU_SHARED_MAS2 + 4)(r11) -#endif + PPC_LD(r6, VCPU_SHARED_MAS2, r11) lwz r7, VCPU_SHARED_MAS7_3+4(r11) lwz r8, VCPU_SHARED_MAS4(r11) mtspr SPRN_MAS0, r3
@@ -565,11 +553,7 @@ lightweight_exit: PPC_LL r6, VCPU_CTR(r4) PPC_LL r7, VCPU_CR(r4) PPC_LL r8, VCPU_PC(r4) -#ifdef CONFIG_64BIT - ld r9, (VCPU_SHARED_MSR)(r11) -#else - lwz r9, (VCPU_SHARED_MSR + 4)(r11) -#endif + PPC_LD(r9, VCPU_SHARED_MSR, r11) PPC_LL r0, VCPU_GPR(r0)(r4) PPC_LL r1, VCPU_GPR(r1)(r4) PPC_LL r2, VCPU_GPR(r2)(r4)
Signature · 1 line
1.6.0.2
PATCH 4/16 KVM: PPC: Restrict PPC_[L|ST]D macro to asm code
In reply to Alexander GrafWe only want asm code macros to be accessible from asm code, so #ifdef it depending on it.
--- arch/powerpc/include/asm/kvm_asm.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/kvm_asm.h +2 -0
@@ -20,6 +20,7 @@#ifndef __POWERPC_KVM_ASM_H__#define __POWERPC_KVM_ASM_H__ +#ifdef __ASSEMBLY__#ifdef CONFIG_64BIT #define PPC_STD (sreg, offset, areg) std sreg, (offset)(areg)#define PPC_LD (treg, offset, areg) ld treg, (offset)(areg)
@@ -27,6 +28,7 @@#define PPC_STD (sreg, offset, areg) stw sreg, (offset+4)(areg)#define PPC_LD (treg, offset, areg) lwz treg, (offset+4)(areg)#endif +#endif /* IVPR must be 64KiB-aligned. */ #define VCPU_SIZE_ORDER 4
Signature · 1 line
1.6.0.2
PATCH 5/16 KVM: PPC: booke(hv): Fix save/restore of guest accessible SPRGs.
In reply to Alexander GrafFrom: Varun Sethi <[email protected]>
For Guest accessible SPRGs 4-7, save/restore must be handled differently for 64bit and non-64 bit case. Use the PPC_STD/PPC_LD macros for saving/restoring to/from these registers.
--- arch/powerpc/kvm/booke_interrupts.S | 8 ++++---- arch/powerpc/kvm/bookehv_interrupts.S | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-)
arch/powerpc/kvm/booke_interrupts.S +4 -4
@@ -419,13 +419,13 @@ lightweight_exit: * written directly to the shared area, so we * need to reload them here with the guest's values. */ - lwz r3, VCPU_SHARED_SPRG4(r5) + PPC_LD(r3, VCPU_SHARED_SPRG4, r5) mtspr SPRN_SPRG4W, r3 - lwz r3, VCPU_SHARED_SPRG5(r5) + PPC_LD(r3, VCPU_SHARED_SPRG5, r5) mtspr SPRN_SPRG5W, r3 - lwz r3, VCPU_SHARED_SPRG6(r5) + PPC_LD(r3, VCPU_SHARED_SPRG6, r5) mtspr SPRN_SPRG6W, r3 - lwz r3, VCPU_SHARED_SPRG7(r5) + PPC_LD(r3, VCPU_SHARED_SPRG7, r5) mtspr SPRN_SPRG7W, r3 #ifdef CONFIG_KVM_EXIT_TIMING
arch/powerpc/kvm/bookehv_interrupts.S +8 -8
@@ -316,13 +316,13 @@ _GLOBAL(kvmppc_resume_host) PPC_STL r5, VCPU_LR(r4) mfspr r7, SPRN_SPRG5 PPC_STL r3, VCPU_VRSAVE(r4) - PPC_STL r6, VCPU_SHARED_SPRG4(r11) + PPC_STD(r6, VCPU_SHARED_SPRG4, r11) mfspr r8, SPRN_SPRG6 - PPC_STL r7, VCPU_SHARED_SPRG5(r11) + PPC_STD(r7, VCPU_SHARED_SPRG5, r11) mfspr r9, SPRN_SPRG7 - PPC_STL r8, VCPU_SHARED_SPRG6(r11) + PPC_STD(r8, VCPU_SHARED_SPRG6, r11) mfxer r3 - PPC_STL r9, VCPU_SHARED_SPRG7(r11) + PPC_STD(r9, VCPU_SHARED_SPRG7, r11) /* save guest MAS registers and restore host mas4 & mas6 */ mfspr r5, SPRN_MAS0
@@ -537,13 +537,13 @@ lightweight_exit: * SPRGs, so we need to reload them here with the guest's values. */ lwz r3, VCPU_VRSAVE(r4) - lwz r5, VCPU_SHARED_SPRG4(r11) + PPC_LD(r5, VCPU_SHARED_SPRG4, r11) mtspr SPRN_VRSAVE, r3 - lwz r6, VCPU_SHARED_SPRG5(r11) + PPC_LD(r6, VCPU_SHARED_SPRG5, r11) mtspr SPRN_SPRG4W, r5 - lwz r7, VCPU_SHARED_SPRG6(r11) + PPC_LD(r7, VCPU_SHARED_SPRG6, r11) mtspr SPRN_SPRG5W, r6 - lwz r8, VCPU_SHARED_SPRG7(r11) + PPC_LD(r8, VCPU_SHARED_SPRG7, r11) mtspr SPRN_SPRG6W, r7 mtspr SPRN_SPRG7W, r8
Signature · 1 line
1.6.0.2
PATCH 6/16 KVM: PPC: Book3S: PR: Optimize entry path
In reply to Alexander GrafBy shuffling a few instructions around we can execute more memory loads in parallel, giving us a small performance boost.
With this patch and a simple priviledged SPR access loop guest, I get a speed bump from 2013052 to 2035607 exits per second.
--- arch/powerpc/kvm/book3s_segment.S | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
arch/powerpc/kvm/book3s_segment.S +7 -6
@@ -128,24 +128,25 @@ no_dcbz32_on: /* First clear RI in our current MSR value */ li r0, MSR_RI andc r6, r6, r0 - MTMSR_EERI(r6) - mtsrr0 r9 - mtsrr1 r4 PPC_LL r0, SVCPU_R0(r3) PPC_LL r1, SVCPU_R1(r3) PPC_LL r2, SVCPU_R2(r3) - PPC_LL r4, SVCPU_R4(r3) PPC_LL r5, SVCPU_R5(r3) - PPC_LL r6, SVCPU_R6(r3) PPC_LL r7, SVCPU_R7(r3) PPC_LL r8, SVCPU_R8(r3) - PPC_LL r9, SVCPU_R9(r3) PPC_LL r10, SVCPU_R10(r3) PPC_LL r11, SVCPU_R11(r3) PPC_LL r12, SVCPU_R12(r3) PPC_LL r13, SVCPU_R13(r3) + MTMSR_EERI(r6) + mtsrr0 r9 + mtsrr1 r4 + + PPC_LL r4, SVCPU_R4(r3) + PPC_LL r6, SVCPU_R6(r3) + PPC_LL r9, SVCPU_R9(r3) PPC_LL r3, (SVCPU_R3)(r3) RFI
Signature · 1 line
1.6.0.2
PATCH 7/16 KVM: PPC: Book3S: PR: No isync in slbie path
In reply to Alexander GrafWhile messing around with the SLBs we're running in real mode. The entry to guest space goes through rfid, which is context synchronizing, so there's no need to manually synchronize anything through isync.
With this patch and a simple priviledged SPR access loop guest, I get a speed bump from 2035607 to 2181301 exits per second.
--- arch/powerpc/kvm/book3s_64_slb.S | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_64_slb.S +0 -2
@@ -90,8 +90,6 @@ slb_exit_skip_ ## num: or r10, r10, r12 slbie r10 - isync - /* Fill SLB with our shadow */ lbz r12, SVCPU_SLB_MAX(r3)
Signature · 1 line
1.6.0.2
PATCH 8/16 KVM: PPC: bookehv: Use lwz/stw instead of PPC_LL/PPC_STL for 32-bit fields
In reply to Alexander GrafFrom: Mihai Caraman <[email protected]>
Interrupt code used PPC_LL/PPC_STL macros to load/store some of u32 fields which led to memory overflow on 64-bit. Use lwz/stw instead.
--- arch/powerpc/kvm/bookehv_interrupts.S | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +8 -8
@@ -87,9 +87,9 @@ mfspr r8, SPRN_TBRL mfspr r9, SPRN_TBRU cmpw r9, r7 - PPC_STL r8, VCPU_TIMING_EXIT_TBL(r4) + stw r8, VCPU_TIMING_EXIT_TBL(r4) bne- 1b - PPC_STL r9, VCPU_TIMING_EXIT_TBU(r4) + stw r9, VCPU_TIMING_EXIT_TBU(r4) #endif oris r8, r6, MSR_CE@h
@@ -216,7 +216,7 @@ _GLOBAL(kvmppc_handler_\intno\()_\srr1) PPC_STL r4, VCPU_GPR(r4)(r11) PPC_LL r4, THREAD_NORMSAVE(0)(r10) PPC_STL r5, VCPU_GPR(r5)(r11) - PPC_STL r13, VCPU_CR(r11) + stw r13, VCPU_CR(r11) mfspr r5, \srr0 PPC_STL r3, VCPU_GPR(r10)(r11) PPC_LL r3, THREAD_NORMSAVE(2)(r10)
@@ -243,7 +243,7 @@ _GLOBAL(kvmppc_handler_\intno\()_\srr1) PPC_STL r4, VCPU_GPR(r4)(r11) PPC_LL r4, GPR9(r8) PPC_STL r5, VCPU_GPR(r5)(r11) - PPC_STL r9, VCPU_CR(r11) + stw r9, VCPU_CR(r11) mfspr r5, \srr0 PPC_STL r3, VCPU_GPR(r8)(r11) PPC_LL r3, GPR10(r8)
@@ -315,7 +315,7 @@ _GLOBAL(kvmppc_resume_host) mfspr r6, SPRN_SPRG4 PPC_STL r5, VCPU_LR(r4) mfspr r7, SPRN_SPRG5 - PPC_STL r3, VCPU_VRSAVE(r4) + stw r3, VCPU_VRSAVE(r4) PPC_STD(r6, VCPU_SHARED_SPRG4, r11) mfspr r8, SPRN_SPRG6 PPC_STD(r7, VCPU_SHARED_SPRG5, r11)
@@ -551,7 +551,7 @@ lightweight_exit: PPC_LL r3, VCPU_LR(r4) PPC_LL r5, VCPU_XER(r4) PPC_LL r6, VCPU_CTR(r4) - PPC_LL r7, VCPU_CR(r4) + lwz r7, VCPU_CR(r4) PPC_LL r8, VCPU_PC(r4) PPC_LD(r9, VCPU_SHARED_MSR, r11) PPC_LL r0, VCPU_GPR(r0)(r4)
@@ -574,9 +574,9 @@ lightweight_exit: mfspr r9, SPRN_TBRL mfspr r8, SPRN_TBRU cmpw r8, r6 - PPC_STL r9, VCPU_TIMING_LAST_ENTER_TBL(r4) + stw r9, VCPU_TIMING_LAST_ENTER_TBL(r4) bne 1b - PPC_STL r8, VCPU_TIMING_LAST_ENTER_TBU(r4) + stw r8, VCPU_TIMING_LAST_ENTER_TBU(r4) #endif /*
Signature · 1 line
1.6.0.2
PATCH 9/16 KVM: PPC: Fix stbux emulation
In reply to Alexander GrafStbux writes the address it's operating on to the register specified in ra, not into the data source register.
--- arch/powerpc/kvm/emulate.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/kvm/emulate.c +1 -1
@@ -229,7 +229,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) emulated =kvmppc_handle_store (run, vcpu,kvmppc_get_gpr (vcpu, rs),1 ,1 ); -kvmppc_set_gpr (vcpu, rs, vcpu->arch.vaddr_accessed); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_31_XOP_LHAX :
Signature · 1 line
1.6.0.2
PATCH 10/16 KVM: PPC: Fix PR KVM on POWER7 bare metal
In reply to Alexander GrafWhen running on a system that is HV capable, some interrupts use HSRR SPRs instead of the normal SRR SPRs. These are also used in the Linux handlers to jump back to code after an interrupt got processed.
Unfortunately, in our "jump back to the real host handler after we've done the context switch" code, we were only setting the SRR SPRs, rendering Linux to jump back to some invalid IP after it's processed the interrupt.
This fixes random crashes on p7 opal mode with PR KVM for me.
--- arch/powerpc/kvm/book3s_segment.S | 35 ++++++++++++++++++++++------------- 1 files changed, 22 insertions(+), 13 deletions(-)
arch/powerpc/kvm/book3s_segment.S +22 -13
@@ -198,6 +198,7 @@ kvmppc_interrupt: /* Save guest PC and MSR */ #ifdef CONFIG_PPC64 BEGIN_FTR_SECTION + mr r10, r12 andi. r0,r12,0x2 beq 1f mfspr r3,SPRN_HSRR0
@@ -317,23 +318,17 @@ no_dcbz32_off: * Having set up SRR0/1 with the address where we want * to continue with relocation on (potentially in module * space), we either just go straight there with rfi[d], - * or we jump to an interrupt handler with bctr if there - * is an interrupt to be handled first. In the latter - * case, the rfi[d] at the end of the interrupt handler - * will get us back to where we want to continue. + * or we jump to an interrupt handler if there is an + * interrupt to be handled first. In the latter case, + * the rfi[d] at the end of the interrupt handler will + * get us back to where we want to continue. */ - cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL - beq 1f - cmpwi r12, BOOK3S_INTERRUPT_DECREMENTER - beq 1f - cmpwi r12, BOOK3S_INTERRUPT_PERFMON -1: mtctr r12 - /* Register usage at this point: * * R1 = host R1 * R2 = host R2 + * R10 = raw exit handler id * R12 = exit handler id * R13 = shadow vcpu (32-bit) or PACA (64-bit) * SVCPU.* = guest *
@@ -343,12 +338,26 @@ no_dcbz32_off: PPC_LL r6, HSTATE_HOST_MSR(r13) PPC_LL r8, HSTATE_VMHANDLER(r13) - /* Restore host msr -> SRR1 */ +#ifdef CONFIG_PPC64 +BEGIN_FTR_SECTION + andi. r0,r10,0x2 + beq 1f + mtspr SPRN_HSRR1, r6 + mtspr SPRN_HSRR0, r8 +END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) +#endif +1: /* Restore host msr -> SRR1 */ mtsrr1 r6 /* Load highmem handler address */ mtsrr0 r8 /* RFI into the highmem handler, or jump to interrupt handler */ - beqctr + cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL + beqa BOOK3S_INTERRUPT_EXTERNAL + cmpwi r12, BOOK3S_INTERRUPT_DECREMENTER + beqa BOOK3S_INTERRUPT_DECREMENTER + cmpwi r12, BOOK3S_INTERRUPT_PERFMON + beqa BOOK3S_INTERRUPT_PERFMON + RFI kvmppc_handler_trampoline_exit_end:
Signature · 1 line
1.6.0.2
PATCH 11/16 KVM: PPC: Book3S: Enable IRQs during exit handling
In reply to Alexander GrafWhile handling an exit, we should listen for interrupts and make sure to receive them when they arrive, to keep our latencies low.
--- arch/powerpc/kvm/book3s_pr.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_pr.c +3 -0
@@ -548,6 +548,9 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, run->exit_reason =KVM_EXIT_UNKNOWN ; run->ready_for_interrupt_injection =1 ; +/* We get here with MSR.EE=0, so enable it to be a nice citizen */ +__hard_irq_enable (); +trace_kvm_book3s_exit (exit_nr, vcpu);preempt_enable ();kvm_resched (vcpu);
Signature · 1 line
1.6.0.2
PATCH 12/16 KVM: PPC: bookehv: Fix r8/r13 storing in level exception handler
In reply to Alexander GrafFrom: Mihai Caraman <[email protected]>
Guest r8 register is held in the scratch register and stored correctly, so remove the instruction that clobbers it. Guest r13 was missing from vcpu, store it there.
--- arch/powerpc/kvm/bookehv_interrupts.S | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +1 -1
@@ -252,10 +252,10 @@ _GLOBAL(kvmppc_handler_\intno\()_\srr1) mfspr r6, \srr1 PPC_LL r4, GPR11(r8) PPC_STL r7, VCPU_GPR(r7)(r11) - PPC_STL r8, VCPU_GPR(r8)(r11) PPC_STL r3, VCPU_GPR(r10)(r11) mfctr r7 PPC_STL r12, VCPU_GPR(r12)(r11) + PPC_STL r13, VCPU_GPR(r13)(r11) PPC_STL r4, VCPU_GPR(r11)(r11) PPC_STL r7, VCPU_CTR(r11) mr r4, r11
Signature · 1 line
1.6.0.2
PATCH 13/16 kvm/book3s: Make kernel emulated H_PUT_TCE available for "PR" KVM
In reply to Alexander GrafFrom: Benjamin Herrenschmidt <[email protected]>
There is nothing in the code for emulating TCE tables in the kernel that prevents it from working on "PR" KVM... other than ifdef's and location of the code.
This and moves the bulk of the code there to a new file called book3s_64_vio.c.
This speeds things up a bit on my G5.
--- arch/powerpc/include/asm/kvm_host.h | 4 +- arch/powerpc/include/asm/kvm_ppc.h | 2 + arch/powerpc/kvm/Makefile | 2 + arch/powerpc/kvm/book3s_64_vio.c | 150 +++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_64_vio_hv.c | 3 + arch/powerpc/kvm/book3s_hv.c | 109 ------------------------- arch/powerpc/kvm/book3s_pr.c | 7 ++ arch/powerpc/kvm/book3s_pr_papr.c | 18 ++++ arch/powerpc/kvm/powerpc.c | 8 ++- 9 files changed, 191 insertions(+), 112 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_64_vio.c
arch/powerpc/include/asm/kvm_host.h +3 -1
@@ -237,7 +237,6 @@ struct kvm_arch {unsigned long vrma_slb_v;int rma_setup_done;int using_mmu_notifiers; -struct list_head spapr_tce_tables;spinlock_t slot_phys_lock;unsigned long *slot_phys[KVM_MEM_SLOTS_NUM ];int slot_npages[KVM_MEM_SLOTS_NUM ];
@@ -245,6 +244,9 @@ struct kvm_arch {struct kvmppc_vcore *vcores[KVM_MAX_VCORES ];struct kvmppc_linear_info *hpt_li;#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#ifdef CONFIG_PPC_BOOK3S_64 +struct list_head spapr_tce_tables; +#endif };/*
arch/powerpc/include/asm/kvm_ppc.h +2 -0
@@ -126,6 +126,8 @@ extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu,extern int kvmppc_pseries_do_hcall (struct kvm_vcpu *vcpu);extern long kvm_vm_ioctl_create_spapr_tce (struct kvm *kvm,struct kvm_create_spapr_tce *args); +extern long kvmppc_h_put_tce (struct kvm_vcpu *vcpu,unsigned long liobn, +unsigned long ioba,unsigned long tce);extern long kvm_vm_ioctl_allocate_rma (struct kvm *kvm,struct kvm_allocate_rma *rma);extern struct kvmppc_linear_info *kvm_alloc_rma (void );
arch/powerpc/kvm/Makefile +2 -0
@@ -54,6 +54,7 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ book3s_paired_singles.o \ book3s_pr.o \ book3s_pr_papr.o \ + book3s_64_vio_hv.o \ book3s_emulate.o \ book3s_interrupts.o \ book3s_mmu_hpte.o \
@@ -78,6 +79,7 @@ kvm-book3s_64-module-objs := \ powerpc.o \ emulate.o \ book3s.o \ + book3s_64_vio.o \ $(kvm-book3s_64-objs-y) kvm-objs-$(CONFIG_KVM_BOOK3S_64) := $(kvm-book3s_64-module-objs)
arch/powerpc/kvm/book3s_64_vio.c new file +150 -0
150 lines not on this page · raw message
arch/powerpc/kvm/book3s_64_vio_hv.c +3 -0
@@ -38,6 +38,9 @@#define TCES_PER_PAGE (PAGE_SIZE / sizeof(u64)) +/* WARNING: This will be called in real-mode on HV KVM and virtual +* mode on PR KVM +*/ long kvmppc_h_put_tce (struct kvm_vcpu *vcpu,unsigned long liobn,unsigned long ioba,unsigned long tce) {
arch/powerpc/kvm/book3s_hv.c +0 -109
115 lines not on this page · raw message
arch/powerpc/kvm/book3s_pr.c +7 -0
@@ -1171,11 +1171,18 @@ void kvmppc_core_commit_memory_region(struct kvm *kvm,int kvmppc_core_init_vm (struct kvm *kvm) { +#ifdef CONFIG_PPC64 +INIT_LIST_HEAD (&kvm->arch.spapr_tce_tables); +#endif +return 0 ; }void kvmppc_core_destroy_vm (struct kvm *kvm) { +#ifdef CONFIG_PPC64 +WARN_ON (!list_empty (&kvm->arch.spapr_tce_tables)); +#endif }static int kvmppc_book3s_init (void )
arch/powerpc/kvm/book3s_pr_papr.c +18 -0
@@ -15,6 +15,8 @@* published by the Free Software Foundation. */ +#include <linux/anon_inodes.h> +#include <asm/uaccess.h> #include <asm/kvm_ppc.h> #include <asm/kvm_book3s.h>
@@ -211,6 +213,20 @@ static int kvmppc_h_pr_protect(struct kvm_vcpu *vcpu)return EMULATE_DONE ; } +static int kvmppc_h_pr_put_tce (struct kvm_vcpu *vcpu) +{ +unsigned long liobn =kvmppc_get_gpr (vcpu,4 ); +unsigned long ioba =kvmppc_get_gpr (vcpu,5 ); +unsigned long tce =kvmppc_get_gpr (vcpu,6 ); +long rc; + + rc =kvmppc_h_put_tce (vcpu, liobn, ioba, tce); +if (rc ==H_TOO_HARD ) +return EMULATE_FAIL ; +kvmppc_set_gpr (vcpu,3 , rc); +return EMULATE_DONE ; +} +int kvmppc_h_pr (struct kvm_vcpu *vcpu,unsigned long cmd) {switch (cmd) {
@@ -222,6 +238,8 @@ int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd)return kvmppc_h_pr_protect (vcpu);case H_BULK_REMOVE :return kvmppc_h_pr_bulk_remove (vcpu); +case H_PUT_TCE : +return kvmppc_h_pr_put_tce (vcpu);case H_CEDE :kvm_vcpu_block (vcpu);clear_bit (KVM_REQ_UNHALT , &vcpu->requests);
arch/powerpc/kvm/powerpc.c +6 -2
@@ -244,10 +244,12 @@ int kvm_dev_ioctl_check_extension(long ext) r =KVM_COALESCED_MMIO_PAGE_OFFSET ;break ;#endif -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_PPC_BOOK3S_64 case KVM_CAP_SPAPR_TCE : r =1 ;break ; +#endif /* CONFIG_PPC_BOOK3S_64 */ +#ifdef CONFIG_KVM_BOOK3S_64_HV case KVM_CAP_PPC_SMT : r = threads_per_core;break ;
@@ -773,7 +775,7 @@ long kvm_arch_vm_ioctl(struct file *filp,break ; } -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_PPC_BOOK3S_64 case KVM_CREATE_SPAPR_TCE : {struct kvm_create_spapr_tce create_tce;struct kvm *kvm = filp->private_data;
@@ -784,7 +786,9 @@ long kvm_arch_vm_ioctl(struct file *filp, r =kvm_vm_ioctl_create_spapr_tce (kvm, &create_tce); goto out; } +#endif /* CONFIG_PPC_BOOK3S_64 */ +#ifdef CONFIG_KVM_BOOK3S_64_HV case KVM_ALLOCATE_RMA : {struct kvm *kvm = filp->private_data;struct kvm_allocate_rma rma;
Signature · 1 line
1.6.0.2
PATCH 14/16 kvm/powerpc: Add new ioctl to retreive server MMU infos
In reply to Alexander GrafFrom: Benjamin Herrenschmidt <[email protected]>
This is necessary for qemu to be able to pass the right information to the guest, such as the supported page sizes and corresponding encodings in the SLB and hash table, which can vary depending on the processor type, the type of KVM used (PR vs HV) and the version of KVM
--- Documentation/virtual/kvm/api.txt | 70 ++++++++++++++++++++++++++++++++++++ arch/powerpc/include/asm/kvm_ppc.h | 2 + arch/powerpc/kernel/ppc_ksyms.c | 4 ++ arch/powerpc/kvm/book3s_hv.c | 32 ++++++++++++++++ arch/powerpc/kvm/book3s_pr.c | 25 +++++++++++++ arch/powerpc/kvm/powerpc.c | 18 +++++++++- include/linux/kvm.h | 27 ++++++++++++++ 7 files changed, 177 insertions(+), 1 deletions(-)
Documentation/virtual/kvm/api.txt +70 -0
@@ -1860,6 +1860,76 @@ See KVM_GET_PIT2 for details on struct kvm_pit_state2. This IOCTL replaces the obsolete KVM_SET_PIT. +4.74 KVM_PPC_GET_SMMU_INFO + +Capability: KVM_CAP_PPC_GET_SMMU_INFO +Architectures: powerpc +Type: vm ioctl +Parameters: None +Returns: 0 on success, -1 on error + +This populates and returns a structure describing the features of +the "Server" class MMU emulation supported by KVM. +This can in turn be used by userspace to generate the appropariate +device-tree properties for the guest operating system. + +The structure contains some global informations, followed by an +array of supported segment page sizes: + + struct kvm_ppc_smmu_info { + __u64 flags; + __u32 slb_size; + __u32 pad; + struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ]; + }; + +The supported flags are: + + - KVM_PPC_PAGE_SIZES_REAL: + When that flag is set, guest page sizes must "fit" the backing + store page sizes. When not set, any page size in the list can + be used regardless of how they are backed by userspace. + + - KVM_PPC_1T_SEGMENTS + The emulated MMU supports 1T segments in addition to the + standard 256M ones. + +The "slb_size" field indicates how many SLB entries are supported + +The "sps" array contains 8 entries indicating the supported base +page sizes for a segment in increasing order. Each entry is defined +as follow: + + struct kvm_ppc_one_seg_page_size { + __u32 page_shift; /* Base page shift of segment (or 0) */ + __u32 slb_enc; /* SLB encoding for BookS */ + struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ]; + }; + +An entry with a "page_shift" of 0 is unused. Because the array is +organized in increasing order, a lookup can stop when encoutering +such an entry. + +The "slb_enc" field provides the encoding to use in the SLB for the +page size. The bits are in positions such as the value can directly +be OR'ed into the "vsid" argument of the slbmte instruction. + +The "enc" array is a list which for each of those segment base page +size provides the list of supported actual page sizes (which can be +only larger or equal to the base page size), along with the +corresponding encoding in the hash PTE. Similarily, the array is +8 entries sorted by increasing sizes and an entry with a "0" shift +is an empty entry and a terminator: + + struct kvm_ppc_one_page_size { + __u32 page_shift; /* Page shift (or 0) */ + __u32 pte_enc; /* Encoding in the HPTE (>>12) */ + }; + +The "pte_enc" field provides a value that can OR'ed into the hash +PTE's RPN field (ie, it needs to be shifted left by 12 to OR it +into the hash PTE second double word). + 5. The kvm_run structure ------------------------
arch/powerpc/include/asm/kvm_ppc.h +2 -0
@@ -140,6 +140,8 @@ extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem);extern void kvmppc_core_commit_memory_region (struct kvm *kvm,struct kvm_userspace_memory_region *mem); +extern int kvm_vm_ioctl_get_smmu_info (struct kvm *kvm, +struct kvm_ppc_smmu_info *info);extern int kvmppc_bookehv_init (void );extern void kvmppc_bookehv_exit (void );
arch/powerpc/kernel/ppc_ksyms.c +4 -0
@@ -190,3 +190,7 @@ EXPORT_SYMBOL(__arch_hweight16);EXPORT_SYMBOL (__arch_hweight32);EXPORT_SYMBOL (__arch_hweight64);#endif + +#ifdef CONFIG_PPC_BOOK3S_64 +EXPORT_SYMBOL_GPL (mmu_psize_defs); +#endif
arch/powerpc/kvm/book3s_hv.c +32 -0
@@ -1175,6 +1175,38 @@ long kvm_vm_ioctl_allocate_rma(struct kvm *kvm, struct kvm_allocate_rma *ret)return fd; } +static void kvmppc_add_seg_page_size (struct kvm_ppc_one_seg_page_size **sps, +int linux_psize) +{ +struct mmu_psize_def *def = &mmu_psize_defs[linux_psize]; + +if (!def->shift) +return ; + (*sps)->page_shift = def->shift; + (*sps)->slb_enc = def->sllp; + (*sps)->enc[0 ].page_shift = def->shift; + (*sps)->enc[0 ].pte_enc = def->penc; + (*sps)++; +} + +int kvm_vm_ioctl_get_smmu_info (struct kvm *kvm,struct kvm_ppc_smmu_info *info) +{ +struct kvm_ppc_one_seg_page_size *sps; + + info->flags =KVM_PPC_PAGE_SIZES_REAL ; +if (mmu_has_feature (MMU_FTR_1T_SEGMENT )) + info->flags |=KVM_PPC_1T_SEGMENTS ; + info->slb_size = mmu_slb_size; + +/* We only support these sizes for now, and no muti-size segments */ + sps = &info->sps[0 ]; +kvmppc_add_seg_page_size (&sps,MMU_PAGE_4K ); +kvmppc_add_seg_page_size (&sps,MMU_PAGE_64K ); +kvmppc_add_seg_page_size (&sps,MMU_PAGE_16M ); + +return 0 ; +} +/* * Get (and clear) the dirty memory log for a memory slot. */
arch/powerpc/kvm/book3s_pr.c +25 -0
@@ -1158,6 +1158,31 @@ out:return r; } +#ifdef CONFIG_PPC64 +int kvm_vm_ioctl_get_smmu_info (struct kvm *kvm,struct kvm_ppc_smmu_info *info) +{ +/* No flags */ + info->flags =0 ; + +/* SLB is always 64 entries */ + info->slb_size =64 ; + +/* Standard 4k base page size segment */ + info->sps[0 ].page_shift =12 ; + info->sps[0 ].slb_enc =0 ; + info->sps[0 ].enc[0 ].page_shift =12 ; + info->sps[0 ].enc[0 ].pte_enc =0 ; + +/* Standard 16M large page size segment */ + info->sps[1 ].page_shift =24 ; + info->sps[1 ].slb_enc =SLB_VSID_L ; + info->sps[1 ].enc[0 ].page_shift =24 ; + info->sps[1 ].enc[0 ].pte_enc =0 ; + +return 0 ; +} +#endif /* CONFIG_PPC64 */ +int kvmppc_core_prepare_memory_region (struct kvm *kvm,struct kvm_userspace_memory_region *mem) {
arch/powerpc/kvm/powerpc.c +17 -1
@@ -279,6 +279,11 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_MAX_VCPUS : r =KVM_MAX_VCPUS ;break ; +#ifdef CONFIG_PPC_BOOK3S_64 +case KVM_CAP_PPC_GET_SMMU_INFO : + r =1 ; +break ; +#endif default : r =0 ;break ;
@@ -718,7 +723,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp, break; }#endif -default : r = -EINVAL ; }
@@ -800,6 +804,18 @@ long kvm_arch_vm_ioctl(struct file *filp, }#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#ifdef CONFIG_PPC_BOOK3S_64 +case KVM_PPC_GET_SMMU_INFO : { +struct kvm *kvm = filp->private_data; +struct kvm_ppc_smmu_info info; + +memset (&info,0 ,sizeof (info)); + r =kvm_vm_ioctl_get_smmu_info (kvm, &info); +if (r >=0 &©_to_user (argp, &info,sizeof (info))) + r = -EFAULT ; +break ; + } +#endif /* CONFIG_PPC_BOOK3S_64 */ default : r = -ENOTTY ; }
include/linux/kvm.h +27 -0
@@ -449,6 +449,30 @@ struct kvm_ppc_pvinfo {__u8 pad[108 ]; }; +/* for KVM_PPC_GET_SMMU_INFO */ +#define KVM_PPC_PAGE_SIZES_MAX_SZ 8 + +struct kvm_ppc_one_page_size { +__u32 page_shift;/* Page shift (or 0) */ +__u32 pte_enc;/* Encoding in the HPTE (>>12) */ +}; + +struct kvm_ppc_one_seg_page_size { +__u32 page_shift;/* Base page shift of segment (or 0) */ +__u32 slb_enc;/* SLB encoding for BookS */ +struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ ]; +}; + +#define KVM_PPC_PAGE_SIZES_REAL 0x00000001 +#define KVM_PPC_1T_SEGMENTS 0x00000002 + +struct kvm_ppc_smmu_info { +__u64 flags; +__u32 slb_size; +__u32 pad; +struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ ]; +}; +#define KVMIO 0xAE/* machine type bits, to be used as argument to KVM_CREATE_VM */
@@ -591,6 +615,7 @@ struct kvm_ppc_pvinfo {#define KVM_CAP_PCI_2_3 75#define KVM_CAP_KVMCLOCK_CTRL 76#define KVM_CAP_SIGNAL_MSI 77 +#define KVM_CAP_PPC_GET_SMMU_INFO 78#ifdef KVM_CAP_IRQ_ROUTING
@@ -800,6 +825,8 @@ struct kvm_s390_ucas_mapping { struct kvm_assigned_pci_dev)/* Available with KVM_CAP_SIGNAL_MSI */ #define KVM_SIGNAL_MSI _IOW(KVMIO, 0xa5, struct kvm_msi) +/* Available with KVM_CAP_PPC_GET_SMMU_INFO */ +#define KVM_PPC_GET_SMMU_INFO _IOR(KVMIO, 0xa6, struct kvm_ppc_smmu_info)/* * ioctls for vcpu fds
Signature · 1 line
1.6.0.2
PATCH 15/16 KVM: PPC: Emulator: clean up instruction parsing
In reply to Alexander GrafInstructions on PPC are pretty similarly encoded. So instead of every instruction emulation code decoding the instruction fields itself, we can move that code to more generic places and rely on the compiler to optimize the unused bits away.
This has 2 advantages. It makes the code smaller and it makes the code less error prone, as the instruction fields are always available, so accidental misusage is reduced.
Functionally, this patch doesn't change anything.
--- arch/powerpc/kvm/44x_emulate.c | 27 ++++---------- arch/powerpc/kvm/book3s_emulate.c | 72 +++++++++++++++++++----------------- arch/powerpc/kvm/booke_emulate.c | 7 +--- arch/powerpc/kvm/e500_emulate.c | 16 +++------ arch/powerpc/kvm/emulate.c | 71 ++---------------------------------- 5 files changed, 56 insertions(+), 137 deletions(-)
arch/powerpc/kvm/44x_emulate.c +7 -20
@@ -37,22 +37,19 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, unsigned int inst, int *advance) { int emulated = EMULATE_DONE; -int dcrn; -int ra; -int rb; -int rc; -int rs; -int rt; -int ws; +int dcrn =get_dcrn (inst); +int ra =get_ra (inst); +int rb =get_rb (inst); +int rc =get_rc (inst); +int rs =get_rs (inst); +int rt =get_rt (inst); +int ws =get_ws (inst);switch (get_op (inst)) {case 31 :switch (get_xop (inst)) {case XOP_MFDCR : - dcrn =get_dcrn (inst); - rt =get_rt (inst); -/* The guest may access CPR0 registers to determine the timebase * frequency, and it must know the real host frequency because it * can directly access the timebase registers.
@@ -88,9 +85,6 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,break ;case XOP_MTDCR : - dcrn =get_dcrn (inst); - rs =get_rs (inst); -/* emulate some access in kernel */ switch (dcrn) {case DCRN_CPR0_CONFIG_ADDR :
@@ -108,17 +102,10 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,break ;case XOP_TLBWE : - ra =get_ra (inst); - rs =get_rs (inst); - ws =get_ws (inst); emulated =kvmppc_44x_emul_tlbwe (vcpu, ra, rs, ws);break ;case XOP_TLBSX : - rt =get_rt (inst); - ra =get_ra (inst); - rb =get_rb (inst); - rc =get_rc (inst); emulated =kvmppc_44x_emul_tlbsx (vcpu, rt, ra, rb, rc);break ;
arch/powerpc/kvm/book3s_emulate.c +38 -34
178 lines not on this page · raw message
arch/powerpc/kvm/booke_emulate.c +2 -5
@@ -40,8 +40,8 @@ int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, unsigned int inst, int *advance) { int emulated = EMULATE_DONE; -int rs; -int rt; +int rs =get_rs (inst); +int rt =get_rt (inst);switch (get_op (inst)) {case 19 :
@@ -62,19 +62,16 @@ int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,switch (get_xop (inst)) {case OP_31_XOP_MFMSR : - rt =get_rt (inst);kvmppc_set_gpr (vcpu, rt, vcpu->arch.shared->msr);kvmppc_set_exit_type (vcpu,EMULATED_MFMSR_EXITS );break ;case OP_31_XOP_MTMSR : - rs =get_rs (inst);kvmppc_set_exit_type (vcpu,EMULATED_MTMSR_EXITS );kvmppc_set_msr (vcpu,kvmppc_get_gpr (vcpu, rs));break ;case OP_31_XOP_WRTEE : - rs =get_rs (inst); vcpu->arch.shared->msr = (vcpu->arch.shared->msr & ~MSR_EE ) | (kvmppc_get_gpr (vcpu, rs) &MSR_EE );kvmppc_set_exit_type (vcpu,EMULATED_WRTEE_EXITS );
arch/powerpc/kvm/e500_emulate.c +5 -11
@@ -86,9 +86,9 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, unsigned int inst, int *advance) { int emulated = EMULATE_DONE; -int ra; -int rb; -int rt; +int ra =get_ra (inst); +int rb =get_rb (inst); +int rt =get_rt (inst);switch (get_op (inst)) {case 31 :
@@ -96,11 +96,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,#ifdef CONFIG_KVM_E500MC case XOP_MSGSND : - emulated =kvmppc_e500_emul_msgsnd (vcpu,get_rb (inst)); + emulated =kvmppc_e500_emul_msgsnd (vcpu, rb);break ;case XOP_MSGCLR : - emulated =kvmppc_e500_emul_msgclr (vcpu,get_rb (inst)); + emulated =kvmppc_e500_emul_msgclr (vcpu, rb);break ;#endif
@@ -113,20 +113,14 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,break ;case XOP_TLBSX : - rb =get_rb (inst); emulated =kvmppc_e500_emul_tlbsx (vcpu,rb);break ;case XOP_TLBILX : - ra =get_ra (inst); - rb =get_rb (inst); - rt =get_rt (inst); emulated =kvmppc_e500_emul_tlbilx (vcpu, rt, ra, rb);break ;case XOP_TLBIVAX : - ra =get_ra (inst); - rb =get_rb (inst); emulated =kvmppc_e500_emul_tlbivax (vcpu, ra, rb);break ;
arch/powerpc/kvm/emulate.c +4 -67
239 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 16/16 KVM: PPC: Emulator: clean up SPR reads and writes
In reply to Alexander GrafWhen reading and writing SPRs, every SPR emulation piece had to read or write the respective GPR the value was read from or stored in itself.
This approach is pretty prone to failure. What if we accidentally implement mfspr emulation where we just do "break" and nothing else? Suddenly we would get a random value in the return register - which is always a bad idea.
So let's consolidate the generic code paths and only give the core specific SPR handling code readily made variables to read/write from/to.
Functionally, this patch doesn't change anything, but it increases the readability of the code and makes is less prone to bugs.
--- arch/powerpc/include/asm/kvm_ppc.h | 6 +- arch/powerpc/kvm/44x_emulate.c | 24 ++++---- arch/powerpc/kvm/book3s_emulate.c | 34 +++++------ arch/powerpc/kvm/book3s_hv.c | 4 +- arch/powerpc/kvm/booke.h | 4 +- arch/powerpc/kvm/booke_emulate.c | 88 +++++++++++++++++------------ arch/powerpc/kvm/e500_emulate.c | 110 +++++++++++++++++++++-------------- arch/powerpc/kvm/emulate.c | 64 ++++++++++++--------- 8 files changed, 190 insertions(+), 144 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +4 -2
@@ -107,8 +107,10 @@ extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,extern int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int op,int *advance); -extern int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,int rs); -extern int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,int rt); +extern int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn, +ulong val); +extern int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn, +ulong *val);extern int kvmppc_booke_init (void );extern void kvmppc_booke_exit (void );
arch/powerpc/kvm/44x_emulate.c +12 -12
@@ -128,41 +128,41 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,return emulated; } -int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,int rs) +int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) {int emulated =EMULATE_DONE ;switch (sprn) {case SPRN_PID : -kvmppc_set_pid (vcpu,kvmppc_get_gpr (vcpu, rs));break ; +kvmppc_set_pid (vcpu, spr_val);break ;case SPRN_MMUCR : - vcpu->arch.mmucr =kvmppc_get_gpr (vcpu, rs);break ; + vcpu->arch.mmucr = spr_val;break ;case SPRN_CCR0 : - vcpu->arch.ccr0 =kvmppc_get_gpr (vcpu, rs);break ; + vcpu->arch.ccr0 = spr_val;break ;case SPRN_CCR1 : - vcpu->arch.ccr1 =kvmppc_get_gpr (vcpu, rs);break ; + vcpu->arch.ccr1 = spr_val;break ;default : - emulated =kvmppc_booke_emulate_mtspr (vcpu, sprn, rs); + emulated =kvmppc_booke_emulate_mtspr (vcpu, sprn, spr_val); }return emulated; } -int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,int rt) +int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) {int emulated =EMULATE_DONE ;switch (sprn) {case SPRN_PID : -kvmppc_set_gpr (vcpu, rt, vcpu->arch.pid);break ; + *spr_val = vcpu->arch.pid;break ;case SPRN_MMUCR : -kvmppc_set_gpr (vcpu, rt, vcpu->arch.mmucr);break ; + *spr_val = vcpu->arch.mmucr;break ;case SPRN_CCR0 : -kvmppc_set_gpr (vcpu, rt, vcpu->arch.ccr0);break ; + *spr_val = vcpu->arch.ccr0;break ;case SPRN_CCR1 : -kvmppc_set_gpr (vcpu, rt, vcpu->arch.ccr1);break ; + *spr_val = vcpu->arch.ccr1;break ;default : - emulated =kvmppc_booke_emulate_mfspr (vcpu, sprn, rt); + emulated =kvmppc_booke_emulate_mfspr (vcpu, sprn, spr_val); }return emulated;
arch/powerpc/kvm/book3s_emulate.c +16 -18
@@ -318,10 +318,9 @@ static struct kvmppc_bat *kvmppc_find_bat(struct kvm_vcpu *vcpu, int sprn)return bat; } -int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,int rs) +int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) {int emulated =EMULATE_DONE ; -ulong spr_val =kvmppc_get_gpr (vcpu, rs);switch (sprn) {case SPRN_SDR1 :
@@ -433,7 +432,7 @@ unprivileged:return emulated; } -int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,int rt) +int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) {int emulated =EMULATE_DONE ;
@@ -446,46 +445,46 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)struct kvmppc_bat *bat =kvmppc_find_bat (vcpu, sprn);if (sprn %2 ) -kvmppc_set_gpr (vcpu, rt, bat->raw >>32 ); + *spr_val = bat->raw >>32 ;else -kvmppc_set_gpr (vcpu, rt, bat->raw); + *spr_val = bat->raw;break ; }case SPRN_SDR1 :if (!spr_allowed (vcpu,PRIV_HYPER )) goto unprivileged; -kvmppc_set_gpr (vcpu, rt,to_book3s (vcpu)->sdr1); + *spr_val =to_book3s (vcpu)->sdr1;break ;case SPRN_DSISR : -kvmppc_set_gpr (vcpu, rt, vcpu->arch.shared->dsisr); + *spr_val = vcpu->arch.shared->dsisr;break ;case SPRN_DAR : -kvmppc_set_gpr (vcpu, rt, vcpu->arch.shared->dar); + *spr_val = vcpu->arch.shared->dar;break ;case SPRN_HIOR : -kvmppc_set_gpr (vcpu, rt,to_book3s (vcpu)->hior); + *spr_val =to_book3s (vcpu)->hior;break ;case SPRN_HID0 : -kvmppc_set_gpr (vcpu, rt,to_book3s (vcpu)->hid[0 ]); + *spr_val =to_book3s (vcpu)->hid[0 ];break ;case SPRN_HID1 : -kvmppc_set_gpr (vcpu, rt,to_book3s (vcpu)->hid[1 ]); + *spr_val =to_book3s (vcpu)->hid[1 ];break ;case SPRN_HID2 :case SPRN_HID2_GEKKO : -kvmppc_set_gpr (vcpu, rt,to_book3s (vcpu)->hid[2 ]); + *spr_val =to_book3s (vcpu)->hid[2 ];break ;case SPRN_HID4 :case SPRN_HID4_GEKKO : -kvmppc_set_gpr (vcpu, rt,to_book3s (vcpu)->hid[4 ]); + *spr_val =to_book3s (vcpu)->hid[4 ];break ;case SPRN_HID5 : -kvmppc_set_gpr (vcpu, rt,to_book3s (vcpu)->hid[5 ]); + *spr_val =to_book3s (vcpu)->hid[5 ];break ;case SPRN_CFAR :case SPRN_PURR : -kvmppc_set_gpr (vcpu, rt,0 ); + *spr_val =0 ;break ;case SPRN_GQR0 :case SPRN_GQR1 :
@@ -495,8 +494,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)case SPRN_GQR5 :case SPRN_GQR6 :case SPRN_GQR7 : -kvmppc_set_gpr (vcpu, rt, -to_book3s (vcpu)->gqr[sprn -SPRN_GQR0 ]); + *spr_val =to_book3s (vcpu)->gqr[sprn -SPRN_GQR0 ];break ;case SPRN_THRM1 :case SPRN_THRM2 :
@@ -511,7 +509,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)case SPRN_PMC3_GEKKO :case SPRN_PMC4_GEKKO :case SPRN_WPAR_GEKKO : -kvmppc_set_gpr (vcpu, rt,0 ); + *spr_val =0 ;break ;default : unprivileged:
arch/powerpc/kvm/book3s_hv.c +2 -2
@@ -1505,12 +1505,12 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,return EMULATE_FAIL ; } -int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,int rs) +int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) {return EMULATE_FAIL ; } -int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,int rt) +int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) {return EMULATE_FAIL ; }
arch/powerpc/kvm/booke.h +2 -2
@@ -75,8 +75,8 @@ void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);int kvmppc_booke_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int inst,int *advance); -int kvmppc_booke_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,int rt); -int kvmppc_booke_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,int rs); +int kvmppc_booke_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val); +int kvmppc_booke_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val);/* low-level asm code to transfer guest state */ void kvmppc_load_guest_spe (struct kvm_vcpu *vcpu);
arch/powerpc/kvm/booke_emulate.c +52 -36
162 lines not on this page · raw message
arch/powerpc/kvm/e500_emulate.c +66 -44
203 lines not on this page · raw message
arch/powerpc/kvm/emulate.c +36 -28
136 lines not on this page · raw message
Signature · 1 line
1.6.0.2
Quoted 5 lines · Alexander Graf
Hi Avi,
This is my current patch queue for ppc. Please pull.
Thanks, pulled. Next time, please add a short summary of the changes for me to put in the merge commit.
Signature · 1 line
error compiling committee.c: too many arguments to function