KVM: PPC: MOL bringup patches v3
Subsystems (4)
cover KVM: PPC: MOL bringup patches v3
Mac-on-Linux has always lacked PPC64 host support. This is going to change now!
This patchset contains minor patches to enable MOL, but is mostly about bug fixes that came out of running Mac OS X. With this set and the current svn version of MOL I have 10.4.11 running as a guest on a 970MP as well as a PS3 host.
v1 -> v2:
- Add documentation for EXIT_OSI and ENABLE_CAP
- Add flags to enable_cap
- Add build fix for !CONFIG_VSX
- Remove in-paca register check
v2 -> v3:
- Document that EXIT_OSI is not migration safe
- Add CAP for ENABLE_CAP
- Improve documentation for ENABLE_CAP
- Add alignment emulation for stfs, stfd, lfd
- Add alignment DAR emulation
- Add CAP for unset irq
- new: Fix dcbz emulation
- new: Add emulation for dcba
- new: Add check if pte was mapped secondary (PS3 fix)
- new: Use ULL for big numbers
- new: Make bools bitfields
- new: Disable MSR_FEx for Cell hosts (PS3 speedup)
Alexander Graf (21):
KVM: PPC: Ensure split mode works
KVM: PPC: Allow userspace to unset the IRQ line
KVM: PPC: Make DSISR 32 bits wide
KVM: PPC: Book3S_32 guest MMU fixes
KVM: PPC: Split instruction reading out
KVM: PPC: Don't reload FPU with invalid values
KVM: PPC: Load VCPU for register fetching
KVM: PPC: Implement mfsr emulation
KVM: PPC: Implement BAT reads
KVM: PPC: Make XER load 32 bit
KVM: PPC: Implement emulation for lbzux and lhax
KVM: PPC: Implement alignment interrupt
KVM: Add support for enabling capabilities per-vcpu
KVM: PPC: Add OSI hypercall interface
KVM: PPC: Make build work without CONFIG_VSX/ALTIVEC
KVM: PPC: Fix dcbz emulation
KVM: PPC: Add emulation for dcba
KVM: PPC: Add check if pte was mapped secondary
KVM: PPC: Use ULL for big numbers
KVM: PPC: Make bools bitfields
KVM: PPC: Disable MSR_FEx for Cell hosts
Documentation/kvm/api.txt | 54 ++++++++- arch/powerpc/include/asm/kvm.h | 3 + arch/powerpc/include/asm/kvm_book3s.h | 47 +++++--- arch/powerpc/include/asm/kvm_host.h | 10 +- arch/powerpc/include/asm/kvm_ppc.h | 2 + arch/powerpc/kvm/book3s.c | 191 +++++++++++++++++++----------- arch/powerpc/kvm/book3s_32_mmu.c | 30 ++++- arch/powerpc/kvm/book3s_64_emulate.c | 146 +++++++++++++++++++++++- arch/powerpc/kvm/book3s_64_interrupts.S | 2 +- arch/powerpc/kvm/book3s_64_mmu_host.c | 7 + arch/powerpc/kvm/book3s_64_slb.S | 2 +- arch/powerpc/kvm/emulate.c | 20 ++++ arch/powerpc/kvm/powerpc.c | 45 +++++++- include/linux/kvm.h | 19 +++ 14 files changed, 468 insertions(+), 110 deletions(-)
PATCH 1/21 KVM: PPC: Ensure split mode works
In reply to a message not in the archiveOn PowerPC we can go into MMU Split Mode. That means that either data relocation is on but instruction relocation is off or vice versa.
That mode didn't work properly, as we weren't always flushing entries when going into a new split mode, potentially mapping different code or data that we're supposed to.
--- arch/powerpc/include/asm/kvm_book3s.h | 9 +++--- arch/powerpc/kvm/book3s.c | 46 +++++++++++++++++--------------- 2 files changed, 29 insertions(+), 26 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +5 -4
@@ -99,10 +99,11 @@ struct kvmppc_vcpu_book3s {#define CONTEXT_GUEST 1#define CONTEXT_GUEST_END 2 -#define VSID_REAL 0xfffffffffff00000 -#define VSID_REAL_DR 0xffffffffffe00000 -#define VSID_REAL_IR 0xffffffffffd00000 -#define VSID_BAT 0xffffffffffc00000 +#define VSID_REAL_DR 0x7ffffffffff00000 +#define VSID_REAL_IR 0x7fffffffffe00000 +#define VSID_SPLIT_MASK 0x7fffffffffe00000 +#define VSID_REAL 0x7fffffffffc00000 +#define VSID_BAT 0x7fffffffffb00000#define VSID_PR 0x8000000000000000extern void kvmppc_mmu_pte_flush (struct kvm_vcpu *vcpu,u64 ea,u64 ea_mask);
arch/powerpc/kvm/book3s.c +24 -22
71 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 2/21 KVM: PPC: Allow userspace to unset the IRQ line
In reply to a message not in the archiveUserspace can tell us that it wants to trigger an interrupt. But so far it can't tell us that it wants to stop triggering one.
So let's interpret the parameter to the ioctl that we have anyways to tell us if we want to raise or lower the interrupt line.
v2 -> v3:
- Add CAP for unset irq
--- arch/powerpc/include/asm/kvm.h | 3 +++ arch/powerpc/include/asm/kvm_ppc.h | 2 ++ arch/powerpc/kvm/book3s.c | 6 ++++++ arch/powerpc/kvm/powerpc.c | 6 +++++- include/linux/kvm.h | 1 + 5 files changed, 17 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/kvm.h +3 -0
@@ -84,4 +84,7 @@ struct kvm_guest_debug_arch {#define KVM_REG_QPR 0x0040#define KVM_REG_FQPR 0x0060 +#define KVM_INTERRUPT_SET -1U +#define KVM_INTERRUPT_UNSET -2U +#endif /* __LINUX_KVM_POWERPC_H */
arch/powerpc/include/asm/kvm_ppc.h +2 -0
@@ -92,6 +92,8 @@ extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu);extern void kvmppc_core_dequeue_dec (struct kvm_vcpu *vcpu);extern void kvmppc_core_queue_external (struct kvm_vcpu *vcpu,struct kvm_interrupt *irq); +extern void kvmppc_core_dequeue_external (struct kvm_vcpu *vcpu, +struct kvm_interrupt *irq);extern int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int op,int *advance);
arch/powerpc/kvm/book3s.c +6 -0
@@ -230,6 +230,12 @@ void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_EXTERNAL ); } +void kvmppc_core_dequeue_external (struct kvm_vcpu *vcpu, +struct kvm_interrupt *irq) +{ +kvmppc_book3s_dequeue_irqprio (vcpu,BOOK3S_INTERRUPT_EXTERNAL ); +} +int kvmppc_book3s_irqprio_deliver (struct kvm_vcpu *vcpu,unsigned int priority) {int deliver =1 ;
arch/powerpc/kvm/powerpc.c +5 -1
@@ -148,6 +148,7 @@ int kvm_dev_ioctl_check_extension(long ext)switch (ext) {case KVM_CAP_PPC_SEGSTATE :case KVM_CAP_PPC_PAIRED_SINGLES : +case KVM_CAP_PPC_UNSET_IRQ : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
@@ -450,7 +451,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)int kvm_vcpu_ioctl_interrupt (struct kvm_vcpu *vcpu,struct kvm_interrupt *irq) { -kvmppc_core_queue_external (vcpu, irq); +if (irq->irq ==KVM_INTERRUPT_UNSET ) +kvmppc_core_dequeue_external (vcpu, irq); +else +kvmppc_core_queue_external (vcpu, irq);if (waitqueue_active (&vcpu->wq)) {wake_up_interruptible (&vcpu->wq);
include/linux/kvm.h +1 -0
@@ -507,6 +507,7 @@ struct kvm_ioeventfd {#define KVM_CAP_DEBUGREGS 50#endif #define KVM_CAP_X86_ROBUST_SINGLESTEP 51 +#define KVM_CAP_PPC_UNSET_IRQ 53#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
1.6.0.2
PATCH 3/21 KVM: PPC: Make DSISR 32 bits wide
In reply to a message not in the archiveDSISR is only defined as 32 bits wide. So let's reflect that in the structs too.
--- arch/powerpc/include/asm/kvm_book3s.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 2 +- arch/powerpc/kvm/book3s_64_interrupts.S | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -1
@@ -84,8 +84,8 @@ struct kvmppc_vcpu_book3s {u64 hid[6 ];u64 gqr[8 ];int slb_nr; +u32 dsisr;u64 sdr1; -u64 dsisr;u64 hior;u64 msr_mask;u64 vsid_first;
arch/powerpc/include/asm/kvm_host.h +1 -1
@@ -260,7 +260,7 @@ struct kvm_vcpu_arch {u32 last_inst;#ifdef CONFIG_PPC64 -ulong fault_dsisr; +u32 fault_dsisr;#endif ulong fault_dear;ulong fault_esr;
arch/powerpc/kvm/book3s_64_interrupts.S +1 -1
@@ -171,7 +171,7 @@ kvmppc_handler_highmem: std r3, VCPU_PC(r7) std r4, VCPU_SHADOW_SRR1(r7) std r5, VCPU_FAULT_DEAR(r7) - std r6, VCPU_FAULT_DSISR(r7) + stw r6, VCPU_FAULT_DSISR(r7) ld r5, VCPU_HFLAGS(r7) rldicl. r5, r5, 0, 63 /* CR = ((r5 & 1) == 0) */
Signature · 1 line
1.6.0.2
PATCH 4/21 KVM: PPC: Book3S_32 guest MMU fixes
In reply to a message not in the archiveThis patch makes the VSID of mapped pages always reflecting all special cases we have, like split mode.
It also changes the tlbie mask to 0x0ffff000 according to the spec. The mask we used before was incorrect.
--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/kvm/book3s_32_mmu.c | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -0
@@ -44,6 +44,7 @@ struct kvmppc_sr {bool Ks;bool Kp;bool nx; +bool valid; };struct kvmppc_bat {
arch/powerpc/kvm/book3s_32_mmu.c +23 -7
@@ -57,6 +57,8 @@ static inline bool check_debug_ip(struct kvm_vcpu *vcpu)static int kvmppc_mmu_book3s_32_xlate_bat (struct kvm_vcpu *vcpu,gva_t eaddr,struct kvmppc_pte *pte,bool data); +static int kvmppc_mmu_book3s_32_esid_to_vsid (struct kvm_vcpu *vcpu,u64 esid, +u64 *vsid);static struct kvmppc_sr *find_sr (struct kvmppc_vcpu_book3s *vcpu_book3s,gva_t eaddr) {
@@ -66,13 +68,14 @@ static struct kvmppc_sr *find_sr(struct kvmppc_vcpu_book3s *vcpu_book3s, gva_t estatic u64 kvmppc_mmu_book3s_32_ea_to_vp (struct kvm_vcpu *vcpu,gva_t eaddr,bool data) { -struct kvmppc_sr *sre =find_sr (to_book3s (vcpu), eaddr); +u64 vsid;struct kvmppc_pte pte;if (!kvmppc_mmu_book3s_32_xlate_bat (vcpu, eaddr, &pte, data))return pte.vpage; -return (((u64 )eaddr >>12 ) &0xffff ) | (((u64 )sre->vsid) <<16 ); +kvmppc_mmu_book3s_32_esid_to_vsid (vcpu, eaddr >>SID_SHIFT , &vsid); +return (((u64 )eaddr >>12 ) &0xffff ) | (vsid <<16 ); }static void kvmppc_mmu_book3s_32_reset_msr (struct kvm_vcpu *vcpu)
@@ -142,8 +145,13 @@ static int kvmppc_mmu_book3s_32_xlate_bat(struct kvm_vcpu *vcpu, gva_t eaddr, bat->bepi_mask); }if ((eaddr & bat->bepi_mask) == bat->bepi) { +u64 vsid; +kvmppc_mmu_book3s_32_esid_to_vsid (vcpu, + eaddr >>SID_SHIFT , &vsid); + vsid <<=16 ; + pte->vpage = (((u64 )eaddr >>12 ) &0xffff ) | vsid; + pte->raddr = bat->brpn | (eaddr & ~bat->bepi_mask); - pte->vpage = (eaddr >>12 ) |VSID_BAT ; pte->may_read = bat->pp; pte->may_write = bat->pp >1 ; pte->may_execute = true;
@@ -302,6 +310,7 @@ static void kvmppc_mmu_book3s_32_mtsrin(struct kvm_vcpu *vcpu, u32 srnum,/* And then put in the new SR */ sre->raw = value; sre->vsid = (value &0x0fffffff ); + sre->valid = (value &0x80000000 ) ? false : true; sre->Ks = (value &0x40000000 ) ? true : false; sre->Kp = (value &0x20000000 ) ? true : false; sre->nx = (value &0x10000000 ) ? true : false;
@@ -312,7 +321,7 @@ static void kvmppc_mmu_book3s_32_mtsrin(struct kvm_vcpu *vcpu, u32 srnum,static void kvmppc_mmu_book3s_32_tlbie (struct kvm_vcpu *vcpu,ulong ea,bool large) { -kvmppc_mmu_pte_flush (vcpu, ea, ~0xFFFULL ); +kvmppc_mmu_pte_flush (vcpu, ea,0x0FFFF000 ); } static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, u64 esid,
@@ -333,15 +342,22 @@ static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, u64 esid,break ;case MSR_DR |MSR_IR : { -ulong ea; - ea = esid <<SID_SHIFT ; - *vsid =find_sr (to_book3s (vcpu), ea)->vsid; +ulong ea = esid <<SID_SHIFT ; +struct kvmppc_sr *sr =find_sr (to_book3s (vcpu), ea); + +if (!sr->valid) +return -1 ; + + *vsid = sr->vsid;break ; }default :BUG (); } +if (vcpu->arch.msr &MSR_PR ) + *vsid |=VSID_PR ; +return 0 ; }
Signature · 1 line
1.6.0.2
PATCH 5/21 KVM: PPC: Split instruction reading out
In reply to Alexander GrafThe current check_ext function reads the instruction and then does the checking. Let's split the reading out so we can reuse it for different functions.
--- arch/powerpc/kvm/book3s.c | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-)
arch/powerpc/kvm/book3s.c +16 -8
@@ -650,26 +650,34 @@ void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr)kvmppc_recalc_shadow_msr (vcpu); } -static int kvmppc_check_ext (struct kvm_vcpu *vcpu,unsigned int exit_nr) +static int kvmppc_read_inst (struct kvm_vcpu *vcpu) {ulong srr0 = vcpu->arch.pc;int ret; -/* Need to do paired single emulation? */ -if (!(vcpu->arch.hflags &BOOK3S_HFLAG_PAIRED_SINGLE )) -return EMULATE_DONE ; - -/* Read out the instruction */ ret =kvmppc_ld (vcpu, &srr0,sizeof (u32), &vcpu->arch.last_inst, false);if (ret = -ENOENT ) { vcpu->arch.msr =kvmppc_set_field (vcpu->arch.msr,33 ,33 ,1 ); vcpu->arch.msr =kvmppc_set_field (vcpu->arch.msr,34 ,36 ,0 ); vcpu->arch.msr =kvmppc_set_field (vcpu->arch.msr,42 ,47 ,0 );kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_INST_STORAGE ); - }else if (ret =EMULATE_DONE ) { +return EMULATE_AGAIN ; + } + +return EMULATE_DONE ; +} + +static int kvmppc_check_ext (struct kvm_vcpu *vcpu,unsigned int exit_nr) +{ + +/* Need to do paired single emulation? */ +if (!(vcpu->arch.hflags &BOOK3S_HFLAG_PAIRED_SINGLE )) +return EMULATE_DONE ; + +/* Read out the instruction */ +if (kvmppc_read_inst (vcpu) =EMULATE_DONE )/* Need to emulate */ return EMULATE_FAIL ; - }return EMULATE_AGAIN ; }
Signature · 1 line
1.6.0.2
PATCH 6/21 KVM: PPC: Don't reload FPU with invalid values
In reply to a message not in the archiveWhen the guest activates the FPU, we load it up. That's fine when it wasn't activated before on the host, but if it was we end up reloading FPU values from last time the FPU was deactivated on the host without writing the proper values back to the vcpu struct.
This patch checks if the FPU is enabled already and if so just doesn't bother activating it, making FPU operations survive guest context switches.
--- arch/powerpc/kvm/book3s.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s.c +5 -0
@@ -701,6 +701,11 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,return RESUME_GUEST ; } +/* We already own the ext */ +if (vcpu->arch.guest_owned_ext & msr) { +return RESUME_GUEST ; + } +#ifdef DEBUG_EXT printk (KERN_INFO "Loading up ext 0x%lx\n" , msr);#endif
Signature · 1 line
1.6.0.2
PATCH 7/21 KVM: PPC: Load VCPU for register fetching
In reply to a message not in the archiveWhen trying to read or store vcpu register data, we should also make sure the vcpu is actually loaded, so we're 100% sure we get the correct values.
--- arch/powerpc/kvm/book3s.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s.c +8 -0
@@ -955,6 +955,8 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) {int i; +vcpu_load (vcpu); + regs->pc = vcpu->arch.pc; regs->cr =kvmppc_get_cr (vcpu); regs->ctr = vcpu->arch.ctr;
@@ -975,6 +977,8 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)for (i =0 ; i <ARRAY_SIZE (regs->gpr); i++) regs->gpr[i] =kvmppc_get_gpr (vcpu, i); +vcpu_put (vcpu); +return 0 ; }
@@ -982,6 +986,8 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) {int i; +vcpu_load (vcpu); + vcpu->arch.pc = regs->pc;kvmppc_set_cr (vcpu, regs->cr); vcpu->arch.ctr = regs->ctr;
@@ -1001,6 +1007,8 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)for (i =0 ; i <ARRAY_SIZE (regs->gpr); i++)kvmppc_set_gpr (vcpu, i, regs->gpr[i]); +vcpu_put (vcpu); +return 0 ; }
Signature · 1 line
1.6.0.2
PATCH 8/21 KVM: PPC: Implement mfsr emulation
In reply to a message not in the archiveWe emulate the mfsrin instruction already, that passes the SR number in a register value. But we lacked support for mfsr that encoded the SR number in the opcode.
So let's implement it.
--- arch/powerpc/kvm/book3s_64_emulate.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_64_emulate.c +13 -0
@@ -35,6 +35,7 @@#define OP_31_XOP_SLBMTE 402#define OP_31_XOP_SLBIE 434#define OP_31_XOP_SLBIA 498 +#define OP_31_XOP_MFSR 595#define OP_31_XOP_MFSRIN 659#define OP_31_XOP_SLBMFEV 851#define OP_31_XOP_EIOIO 854
@@ -90,6 +91,18 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,case OP_31_XOP_MTMSR :kvmppc_set_msr (vcpu,kvmppc_get_gpr (vcpu,get_rs (inst)));break ; +case OP_31_XOP_MFSR : + { +int srnum; + + srnum =kvmppc_get_field (inst,12 +32 ,15 +32 ); +if (vcpu->arch.mmu.mfsrin) { +u32 sr; + sr = vcpu->arch.mmu.mfsrin (vcpu, srnum); +kvmppc_set_gpr (vcpu,get_rt (inst), sr); + } +break ; + }case OP_31_XOP_MFSRIN : {int srnum;
Signature · 1 line
1.6.0.2
PATCH 9/21 KVM: PPC: Implement BAT reads
In reply to a message not in the archiveBATs can't only be written to, you can also read them out! So let's implement emulation for reading BAT values again.
While at it, I also made BAT setting flush the segment cache, so we're absolutely sure there's no MMU state left when writing BATs.
--- arch/powerpc/kvm/book3s_64_emulate.c | 35 ++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_64_emulate.c +35 -0
@@ -239,6 +239,34 @@ void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, bool upper, } } +static u32 kvmppc_read_bat (struct kvm_vcpu *vcpu,int sprn) +{ +struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu); +struct kvmppc_bat *bat; + +switch (sprn) { + case SPRN_IBAT0U ... SPRN_IBAT3L: + bat = &vcpu_book3s->ibat[(sprn -SPRN_IBAT0U ) /2 ]; +break ; + case SPRN_IBAT4U ... SPRN_IBAT7L: + bat = &vcpu_book3s->ibat[4 + ((sprn -SPRN_IBAT4U ) /2 )]; +break ; + case SPRN_DBAT0U ... SPRN_DBAT3L: + bat = &vcpu_book3s->dbat[(sprn -SPRN_DBAT0U ) /2 ]; +break ; + case SPRN_DBAT4U ... SPRN_DBAT7L: + bat = &vcpu_book3s->dbat[4 + ((sprn -SPRN_DBAT4U ) /2 )]; +break ; +default : +BUG (); + } + +if (sprn %2 ) +return bat->raw >>32 ; +else +return bat->raw; +} +static void kvmppc_write_bat (struct kvm_vcpu *vcpu,int sprn,u32 val) {struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu);
@@ -290,6 +318,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)/* BAT writes happen so rarely that we're ok to flush * everything here */ kvmppc_mmu_pte_flush (vcpu,0 ,0 ); +kvmppc_mmu_flush_segments (vcpu);break ;case SPRN_HID0 :to_book3s (vcpu)->hid[0 ] = spr_val;
@@ -373,6 +402,12 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)int emulated =EMULATE_DONE ;switch (sprn) { + case SPRN_IBAT0U ... SPRN_IBAT3L: + case SPRN_IBAT4U ... SPRN_IBAT7L: + case SPRN_DBAT0U ... SPRN_DBAT3L: + case SPRN_DBAT4U ... SPRN_DBAT7L: +kvmppc_set_gpr (vcpu, rt,kvmppc_read_bat (vcpu, sprn)); +break ;case SPRN_SDR1 :kvmppc_set_gpr (vcpu, rt,to_book3s (vcpu)->sdr1);break ;
Signature · 1 line
1.6.0.2
PATCH 10/21 KVM: PPC: Make XER load 32 bit
In reply to Alexander GrafWe have a 32 bit value in the PACA to store XER in. We also do an stw when storing XER in there. But then we load it with ld, completely screwing it up on every entry.
Welcome to the Big Endian world.
--- arch/powerpc/kvm/book3s_64_slb.S | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/kvm/book3s_64_slb.S +1 -1
@@ -145,7 +145,7 @@ slb_do_enter: lwz r11, (PACA_KVM_CR)(r13) mtcr r11 - ld r11, (PACA_KVM_XER)(r13) + lwz r11, (PACA_KVM_XER)(r13) mtxer r11 ld r11, (PACA_KVM_R11)(r13)
Signature · 1 line
1.6.0.2
PATCH 11/21 KVM: PPC: Implement emulation for lbzux and lhax
In reply to a message not in the archiveWe get MMIOs with the weirdest instructions. But every time we do, we need to improve our emulator to implement them.
So let's do that - this time it's lbzux and lhax's round.
--- arch/powerpc/kvm/emulate.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-)
arch/powerpc/kvm/emulate.c +20 -0
@@ -38,10 +38,12 @@#define OP_31_XOP_LBZX 87#define OP_31_XOP_STWX 151#define OP_31_XOP_STBX 215 +#define OP_31_XOP_LBZUX 119#define OP_31_XOP_STBUX 247#define OP_31_XOP_LHZX 279#define OP_31_XOP_LHZUX 311#define OP_31_XOP_MFSPR 339 +#define OP_31_XOP_LHAX 343#define OP_31_XOP_STHX 407#define OP_31_XOP_STHUX 439#define OP_31_XOP_MTSPR 467
@@ -173,6 +175,19 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) emulated =kvmppc_handle_load (run, vcpu, rt,1 ,1 );break ; +case OP_31_XOP_LBZUX : + rt =get_rt (inst); + ra =get_ra (inst); + rb =get_rb (inst); + + ea =kvmppc_get_gpr (vcpu, rb); +if (ra) + ea +=kvmppc_get_gpr (vcpu, ra); + + emulated =kvmppc_handle_load (run, vcpu, rt,1 ,1 ); +kvmppc_set_gpr (vcpu, ra, ea); +break ; +case OP_31_XOP_STWX : rs =get_rs (inst); emulated = kvmppc_handle_store(run, vcpu,
@@ -202,6 +217,11 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)kvmppc_set_gpr (vcpu, rs, ea);break ; +case OP_31_XOP_LHAX : + rt =get_rt (inst); + emulated =kvmppc_handle_loads (run, vcpu, rt,2 ,1 ); +break ; +case OP_31_XOP_LHZX : rt =get_rt (inst); emulated =kvmppc_handle_load (run, vcpu, rt,2 ,1 );
Signature · 1 line
1.6.0.2
PATCH 12/21 KVM: PPC: Implement alignment interrupt
In reply to Alexander GrafMac OS X has some applications - namely the Finder - that require alignment interrupts to work properly. So we need to implement them.
But the spec for 970 and 750 also looks different. While 750 requires the DSISR and DAR fields to reflect some instruction bits (DSISR) and the fault address (DAR), the 970 declares this as an optional feature. So we need to reconstruct DSISR and DAR manually.
---
v2 -> v3:
- add emulation for stfs, stfd, lfd
- add DAR emulation
--- arch/powerpc/include/asm/kvm_book3s.h | 2 + arch/powerpc/kvm/book3s.c | 10 ++++ arch/powerpc/kvm/book3s_64_emulate.c | 75 +++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +2 -0
@@ -131,6 +131,8 @@ extern void kvmppc_rmcall(ulong srr0, ulong srr1);extern void kvmppc_load_up_fpu (void );extern void kvmppc_load_up_altivec (void );extern void kvmppc_load_up_vsx (void ); +extern u32 kvmppc_alignment_dsisr (struct kvm_vcpu *vcpu,unsigned int inst); +extern ulong kvmppc_alignment_dar (struct kvm_vcpu *vcpu,unsigned int inst);static inline struct kvmppc_vcpu_book3s *to_book3s (struct kvm_vcpu *vcpu) {
arch/powerpc/kvm/book3s.c +10 -0
@@ -905,6 +905,16 @@ program_interrupt: }break ; } +case BOOK3S_INTERRUPT_ALIGNMENT : +if (kvmppc_read_inst (vcpu) =EMULATE_DONE ) { +to_book3s (vcpu)->dsisr =kvmppc_alignment_dsisr (vcpu, + vcpu->arch.last_inst); + vcpu->arch.dear =kvmppc_alignment_dar (vcpu, + vcpu->arch.last_inst); +kvmppc_book3s_queue_irqprio (vcpu, exit_nr); + } + r =RESUME_GUEST ; +break ;case BOOK3S_INTERRUPT_MACHINE_CHECK :case BOOK3S_INTERRUPT_TRACE :kvmppc_book3s_queue_irqprio (vcpu, exit_nr);
arch/powerpc/kvm/book3s_64_emulate.c +75 -0
84 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 13/21 KVM: Add support for enabling capabilities per-vcpu
In reply to Alexander GrafSome times we don't want all capabilities to be available to all our vcpus. One example for that is the OSI interface, implemented in the next patch.
In order to have a generic mechanism in how to enable capabilities individually, this patch introduces a new ioctl that can be used for this purpose. That way features we don't want in all guests or userspace configurations can just not be enabled and we're good.
---
v1 -> v2:
- Add flags to enable_cap
- Update documentation for kvm_enable_cap
v2 -> v3:
- Add CAP for ENABLE_CAP
- Improve documentation for ENABLE_CAP
--- Documentation/kvm/api.txt | 35 +++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 27 +++++++++++++++++++++++++++ include/linux/kvm.h | 12 ++++++++++++ 3 files changed, 74 insertions(+), 0 deletions(-)
Documentation/kvm/api.txt +35 -0
@@ -749,6 +749,41 @@ Writes debug registers into the vcpu. See KVM_GET_DEBUGREGS for the data structure. The flags field is unused yet and must be cleared on entry. +4.34 KVM_ENABLE_CAP + +Capability: KVM_CAP_ENABLE_CAP +Architectures: ppc +Type: vcpu ioctl +Parameters: struct kvm_enable_cap (in) +Returns: 0 on success; -1 on error + +Not all extensions are enabled by default. Using this ioctl the application +can enable an extension, making it available to the guest. + +On systems that do not support this ioctl, it always fails. On systems that +do support it, it only works for extensions that are supported for enablement. + +To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should +be used. + +struct kvm_enable_cap { + /* in */ + __u32 cap; + +The capability that is supposed to get enabled. + + __u32 flags; + +A bitfield indicating future enhancements. Has to be 0 for now. + + __u64 args[4]; + +Arguments for enabling a feature. If a feature needs initial values to +function properly, this is the place to put them. + + __u8 pad[64]; +}; + 5. The kvm_run structure
arch/powerpc/kvm/powerpc.c +27 -0
@@ -149,6 +149,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_PPC_SEGSTATE :case KVM_CAP_PPC_PAIRED_SINGLES :case KVM_CAP_PPC_UNSET_IRQ : +case KVM_CAP_ENABLE_CAP : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
@@ -464,6 +465,23 @@ int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq)return 0 ; } +static int kvm_vcpu_ioctl_enable_cap (struct kvm_vcpu *vcpu, +struct kvm_enable_cap *cap) +{ +int r; + +if (cap->flags) +return -EINVAL ; + +switch (cap->cap) { +default : + r = -EINVAL ; +break ; + } + +return r; +} +int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) {
@@ -492,6 +510,15 @@ long kvm_arch_vcpu_ioctl(struct file *filp, r =kvm_vcpu_ioctl_interrupt (vcpu, &irq);break ; } +case KVM_ENABLE_CAP : + { +struct kvm_enable_cap cap; + r = -EFAULT ; +if (copy_from_user (&cap, argp,sizeof (cap))) + goto out; + r =kvm_vcpu_ioctl_enable_cap (vcpu, &cap); +break ; + }default : r = -EINVAL ; }
include/linux/kvm.h +12 -0
@@ -400,6 +400,15 @@ struct kvm_ioeventfd {__u8 pad[36 ]; }; +/* for KVM_ENABLE_CAP */ +struct kvm_enable_cap { +/* in */ +__u32 cap; +__u32 flags; +__u64 args[4 ]; +__u8 pad[64 ]; +}; +#define KVMIO 0xAE/*
@@ -508,6 +517,7 @@ struct kvm_ioeventfd {#endif #define KVM_CAP_X86_ROBUST_SINGLESTEP 51#define KVM_CAP_PPC_UNSET_IRQ 53 +#define KVM_CAP_ENABLE_CAP 54#ifdef KVM_CAP_IRQ_ROUTING
@@ -697,6 +707,8 @@ struct kvm_clock_data {/* Available with KVM_CAP_DEBUGREGS */ #define KVM_GET_DEBUGREGS _IOR(KVMIO, 0xa1, struct kvm_debugregs)#define KVM_SET_DEBUGREGS _IOW(KVMIO, 0xa2, struct kvm_debugregs) +/* No need for CAP, because then it just always fails */ +#define KVM_ENABLE_CAP _IOW(KVMIO, 0xa3, struct kvm_enable_cap)#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
Signature · 1 line
1.6.0.2
PATCH 14/21 KVM: PPC: Add OSI hypercall interface
In reply to a message not in the archiveMOL uses its own hypercall interface to call back into userspace when the guest wants to do something.
So let's implement that as an exit reason, specify it with a CAP and only really use it when userspace wants us to.
The only user of it so far is MOL.
---
v1 -> v2:
- Add documentation for OSI exit struct
v2 -> v3:
- Document that EXIT_OSI is not migration safe
--- Documentation/kvm/api.txt | 19 ++++++++++++++++--- arch/powerpc/include/asm/kvm_book3s.h | 5 +++++ arch/powerpc/include/asm/kvm_host.h | 2 ++ arch/powerpc/kvm/book3s.c | 24 ++++++++++++++++++------ arch/powerpc/kvm/powerpc.c | 12 ++++++++++++ include/linux/kvm.h | 6 ++++++ 6 files changed, 59 insertions(+), 9 deletions(-)
Documentation/kvm/api.txt +16 -3
@@ -895,9 +895,9 @@ executed a memory-mapped I/O instruction which could not be satisfied by kvm. The 'data' member contains the written data if 'is_write' is true, and should be filled by application code otherwise. -NOTE: For KVM_EXIT_IO and KVM_EXIT_MMIO, the corresponding operations -are complete (and guest state is consistent) only after userspace has -re-entered the kernel with KVM_RUN. The kernel side will first finish +NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding +operations are complete (and guest state is consistent) only after userspace +has re-entered the kernel with KVM_RUN. The kernel side will first finish incomplete operations and then check for pending signals. Userspace can re-enter the guest with an unmasked signal pending to complete pending operations.
@@ -952,6 +952,19 @@ s390 specific. powerpc specific. + /* KVM_EXIT_OSI */ + struct { + __u64 gprs[32]; + } osi; + +MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch +hypercalls and exit with this exit struct that contains all the guest gprs. + +If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall. +Userspace can now handle the hypercall and when it's done modify the gprs as +necessary. Upon guest entry all guest GPRs will then be replaced by the values +in this struct. + /* Fix the size of the union. */ char padding[256]; };
arch/powerpc/include/asm/kvm_book3s.h +5 -0
@@ -148,6 +148,11 @@ static inline ulong dsisr(void)extern void kvm_return_point (void ); +/* Magic register values loaded into r3 and r4 before the 'sc' assembly +* instruction for the OSI hypercalls */ +#define OSI_SC_MAGIC_R3 0x113724FA +#define OSI_SC_MAGIC_R4 0x77810F9B +#define INS_DCBZ 0x7c0007ec#endif /* __ASM_KVM_BOOK3S_H__ */
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -273,6 +273,8 @@ struct kvm_vcpu_arch {u8 mmio_sign_extend;u8 dcr_needed;u8 dcr_is_write; +u8 osi_needed; +u8 osi_enabled;u32 cpr0_cfgaddr;/* holds the last set cpr0_cfgaddr */
arch/powerpc/kvm/book3s.c +18 -6
@@ -871,12 +871,24 @@ program_interrupt:break ; }case BOOK3S_INTERRUPT_SYSCALL : -#ifdef EXIT_DEBUG -printk (KERN_INFO "Syscall Nr %d\n" , (int )kvmppc_get_gpr (vcpu,0 )); -#endif - vcpu->stat.syscall_exits++; -kvmppc_book3s_queue_irqprio (vcpu, exit_nr); - r =RESUME_GUEST ; +// XXX make user settable +if (vcpu->arch.osi_enabled && + (((u32 )kvmppc_get_gpr (vcpu,3 )) ==OSI_SC_MAGIC_R3 ) && + (((u32 )kvmppc_get_gpr (vcpu,4 )) ==OSI_SC_MAGIC_R4 )) { +u64 *gprs = run->osi.gprs; +int i; + + run->exit_reason =KVM_EXIT_OSI ; +for (i =0 ; i <32 ; i++) + gprs[i] =kvmppc_get_gpr (vcpu, i); + vcpu->arch.osi_needed =1 ; + r =RESUME_HOST_NV ; + + }else { + vcpu->stat.syscall_exits++; +kvmppc_book3s_queue_irqprio (vcpu, exit_nr); + r =RESUME_GUEST ; + }break ;case BOOK3S_INTERRUPT_FP_UNAVAIL :case BOOK3S_INTERRUPT_ALTIVEC :
arch/powerpc/kvm/powerpc.c +12 -0
@@ -150,6 +150,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_PPC_PAIRED_SINGLES :case KVM_CAP_PPC_UNSET_IRQ :case KVM_CAP_ENABLE_CAP : +case KVM_CAP_PPC_OSI : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
@@ -432,6 +433,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)if (!vcpu->arch.dcr_is_write)kvmppc_complete_dcr_load (vcpu, run); vcpu->arch.dcr_needed =0 ; + }else if (vcpu->arch.osi_needed) { +u64 *gprs = run->osi.gprs; +int i; + +for (i =0 ; i <32 ; i++) +kvmppc_set_gpr (vcpu, i, gprs[i]); + vcpu->arch.osi_needed =0 ; }kvmppc_core_deliver_interrupts (vcpu);
@@ -474,6 +482,10 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,return -EINVAL ;switch (cap->cap) { +case KVM_CAP_PPC_OSI : + r =0 ; + vcpu->arch.osi_enabled = true; +break ;default : r = -EINVAL ;break ;
include/linux/kvm.h +6 -0
@@ -160,6 +160,7 @@ struct kvm_pit_config {#define KVM_EXIT_DCR 15#define KVM_EXIT_NMI 16#define KVM_EXIT_INTERNAL_ERROR 17 +#define KVM_EXIT_OSI 18/* For KVM_EXIT_INTERNAL_ERROR */ #define KVM_INTERNAL_ERROR_EMULATION 1
@@ -259,6 +260,10 @@ struct kvm_run {__u32 ndata;__u64 data[16 ]; } internal; +/* KVM_EXIT_OSI */ +struct { +__u64 gprs[32 ]; + } osi;/* Fix the size of the union. */ char padding[256 ]; };
@@ -516,6 +521,7 @@ struct kvm_enable_cap {#define KVM_CAP_DEBUGREGS 50#endif #define KVM_CAP_X86_ROBUST_SINGLESTEP 51 +#define KVM_CAP_PPC_OSI 52#define KVM_CAP_PPC_UNSET_IRQ 53#define KVM_CAP_ENABLE_CAP 54
Signature · 1 line
1.6.0.2
PATCH 15/21 KVM: PPC: Make build work without CONFIG_VSX/ALTIVEC
In reply to Alexander GrafThe FPU/Altivec/VSX enablement also brought access to some structure elements that are only defined when the respective config options are enabled.
Unfortuately I forgot to check for the config options at some places, so let's do that now.
Unbreaks the build when CONFIG_VSX is not set.
--- arch/powerpc/kvm/book3s.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s.c +8 -0
@@ -608,7 +608,9 @@ void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr) {struct thread_struct *t = ¤t->thread;u64 *vcpu_fpr = vcpu->arch.fpr; +#ifdef CONFIG_VSX u64 *vcpu_vsx = vcpu->arch.vsr; +#endif u64 *thread_fpr = (u64 *)t->fpr;int i;
@@ -688,7 +690,9 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr, {struct thread_struct *t = ¤t->thread;u64 *vcpu_fpr = vcpu->arch.fpr; +#ifdef CONFIG_VSX u64 *vcpu_vsx = vcpu->arch.vsr; +#endif u64 *thread_fpr = (u64 *)t->fpr;int i;
@@ -1219,8 +1223,12 @@ int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) {int ret;struct thread_struct ext_bkp; +#ifdef CONFIG_ALTIVEC bool save_vec = current->thread.used_vr; +#endif +#ifdef CONFIG_VSX bool save_vsx = current->thread.used_vsr; +#endif ulong ext_msr;/* No need to go into the guest when all we do is going out */
Signature · 1 line
1.6.0.2
PATCH 16/21 KVM: PPC: Fix dcbz emulation
In reply to Alexander GrafOn most systems we need to emulate dcbz when running 32 bit guests. So far we've been rather slack, not giving correct DSISR values to the guest.
This patch makes the emulation more accurate, introducing a difference between "page not mapped" and "write protection fault". While at it, it also speeds up dcbz emulation by an order of magnitude by using kmap.
--- arch/powerpc/kvm/book3s.c | 56 +++++++++++++-------------------- arch/powerpc/kvm/book3s_64_emulate.c | 19 +++++++++-- 2 files changed, 37 insertions(+), 38 deletions(-)
arch/powerpc/kvm/book3s.c +22 -34
@@ -28,6 +28,7 @@#include <asm/mmu_context.h> #include <linux/sched.h> #include <linux/vmalloc.h> +#include <linux/highmem.h> #define VCPU_STAT (x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
@@ -368,34 +369,29 @@ void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)*/ static void kvmppc_patch_dcbz (struct kvm_vcpu *vcpu,struct kvmppc_pte *pte) { -bool touched = false; -hva_t hpage; +struct page *hpage; +u64 hpage_offset;u32 *page;int i; - hpage =gfn_to_hva (vcpu->kvm, pte->raddr >>PAGE_SHIFT ); -if (kvm_is_error_hva (hpage)) + hpage =gfn_to_page (vcpu->kvm, pte->raddr >>PAGE_SHIFT ); +if (is_error_page (hpage))return ; - hpage |= pte->raddr & ~PAGE_MASK ; - hpage &= ~0xFFFULL ; - - page =vmalloc (HW_PAGE_SIZE ); - -if (copy_from_user (page, (void __user *)hpage,HW_PAGE_SIZE )) - goto out; + hpage_offset = pte->raddr & ~PAGE_MASK ; + hpage_offset &= ~0xFFFULL ; + hpage_offset /=4 ; -for (i=0 ; i <HW_PAGE_SIZE /4 ; i++) -if ((page[i] &0xff0007ff ) =INS_DCBZ ) { - page[i] &=0xfffffff7 ;// reserved instruction, so we trap - touched = true; - } +get_page (hpage); + page =kmap_atomic (hpage,KM_USER0 ); -if (touched) -copy_to_user ((void __user *)hpage, page,HW_PAGE_SIZE ); +/* patch dcbz into reserved instruction, so we trap */ +for (i=hpage_offset; i < hpage_offset + (HW_PAGE_SIZE /4 ); i++) +if ((page[i] &0xff0007ff ) =INS_DCBZ ) + page[i] &=0xfffffff7 ; -out: -vfree (page); +kunmap_atomic (page,KM_USER0 ); +put_page (hpage); } static int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, bool data,
@@ -448,30 +444,21 @@ int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data) {struct kvmppc_pte pte; -hva_t hva = *eaddr; vcpu->stat.st++;if (kvmppc_xlate (vcpu, *eaddr, data, &pte)) - goto nopte; +return -ENOENT ; *eaddr = pte.raddr; - hva =kvmppc_pte_to_hva (vcpu, &pte, false); -if (kvm_is_error_hva (hva)) - goto mmio; +if (!pte.may_write) +return -EPERM ; -if (copy_to_user ((void __user *)hva, ptr, size)) { -printk (KERN_INFO "kvmppc_st at 0x%lx failed\n" , hva); - goto mmio; - } +if (kvm_write_guest (vcpu->kvm, pte.raddr, ptr, size)) +return EMULATE_DO_MMIO ;return EMULATE_DONE ; - -nopte: -return -ENOENT ; -mmio: -return EMULATE_DO_MMIO ; } int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
@@ -786,6 +773,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,* that no guest that needs the dcbz hack does NX. */ kvmppc_mmu_pte_flush (vcpu, vcpu->arch.pc, ~0xFFFULL ); + r =RESUME_GUEST ; }else { vcpu->arch.msr |= vcpu->arch.shadow_srr1 &0x58000000 ;kvmppc_book3s_queue_irqprio (vcpu, exit_nr);
arch/powerpc/kvm/book3s_64_emulate.c +15 -4
@@ -189,6 +189,8 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,ulong ra =0 ;ulong addr, vaddr;u32 zeros[8 ] = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; +u32 dsisr; +int r;if (get_ra (inst)) ra =kvmppc_get_gpr (vcpu,get_ra (inst));
@@ -198,14 +200,23 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, addr &=0xffffffff ; vaddr = addr; -if (kvmppc_st (vcpu, &addr,32 , zeros, true)) { + r =kvmppc_st (vcpu, &addr,32 , zeros, true); +if ((r = -ENOENT ) || (r = -EPERM )) { + *advance =0 ; vcpu->arch.dear = vaddr; vcpu->arch.fault_dear = vaddr; -to_book3s (vcpu)->dsisr =DSISR_PROTFAULT | -DSISR_ISSTORE ; + + dsisr =DSISR_ISSTORE ; +if (r = -ENOENT ) + dsisr |=DSISR_NOHPTE ; +else if (r = -EPERM ) + dsisr |=DSISR_PROTFAULT ; + +to_book3s (vcpu)->dsisr = dsisr; + vcpu->arch.fault_dsisr = dsisr; +kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_DATA_STORAGE ); -kvmppc_mmu_pte_flush (vcpu, vaddr, ~0xFFFULL ); }break ;
Signature · 1 line
1.6.0.2
PATCH 17/21 KVM: PPC: Add emulation for dcba
In reply to Alexander GrafMac OS X uses the dcba instruction. According to the specification it doesn't guarantee any functionality, so let's just emulate it as nop.
--- arch/powerpc/kvm/book3s_64_emulate.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_64_emulate.c +4 -0
@@ -37,6 +37,7 @@#define OP_31_XOP_SLBIA 498#define OP_31_XOP_MFSR 595#define OP_31_XOP_MFSRIN 659 +#define OP_31_XOP_DCBA 758#define OP_31_XOP_SLBMFEV 851#define OP_31_XOP_EIOIO 854#define OP_31_XOP_SLBMFEE 915
@@ -183,6 +184,9 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,kvmppc_set_gpr (vcpu,get_rt (inst), t); }break ; +case OP_31_XOP_DCBA : +/* Gets treated as NOP */ +break ;case OP_31_XOP_DCBZ : {ulong rb =kvmppc_get_gpr (vcpu,get_rb (inst));
Signature · 1 line
1.6.0.2
PATCH 18/21 KVM: PPC: Add check if pte was mapped secondary
In reply to Alexander GrafSome HTAB providers (namely the PS3) ignore the SECONDARY flag. They just put an entry in the htab as secondary when they see fit.
So we need to check the return value of htab_insert to remember the correct slot id so we can actually invalidate the entry again.
Fixes KVM on the PS3.
--- arch/powerpc/kvm/book3s_64_mmu_host.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_64_mmu_host.c +7 -0
@@ -270,6 +270,13 @@ map_again: (rflags &HPTE_R_N ) ?'-' :'x' , orig_pte->eaddr, hpteg, va, orig_pte->vpage, hpaddr); +/* The ppc_md code may give us a secondary entry even though we +asked for a primary. Fix up. */ +if ((ret & _PTEIDX_SECONDARY) && !(vflags &HPTE_V_SECONDARY )) { + hash = ~hash; + hpteg = ((hash & htab_hash_mask) *HPTES_PER_GROUP ); + } + pte->slot = hpteg + (ret &7 ); pte->host_va = va; pte->pte = *orig_pte;
Signature · 1 line
1.6.0.2
PATCH 19/21 KVM: PPC: Use ULL for big numbers
In reply to Alexander GrafSome constants were bigger than ints. Let's mark them as such so we don't accidently truncate them.
--- arch/powerpc/include/asm/kvm_book3s.h | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +6 -6
@@ -100,12 +100,12 @@ struct kvmppc_vcpu_book3s {#define CONTEXT_GUEST 1#define CONTEXT_GUEST_END 2 -#define VSID_REAL_DR 0x7ffffffffff00000 -#define VSID_REAL_IR 0x7fffffffffe00000 -#define VSID_SPLIT_MASK 0x7fffffffffe00000 -#define VSID_REAL 0x7fffffffffc00000 -#define VSID_BAT 0x7fffffffffb00000 -#define VSID_PR 0x8000000000000000 +#define VSID_REAL_DR 0x7ffffffffff00000ULL +#define VSID_REAL_IR 0x7fffffffffe00000ULL +#define VSID_SPLIT_MASK 0x7fffffffffe00000ULL +#define VSID_REAL 0x7fffffffffc00000ULL +#define VSID_BAT 0x7fffffffffb00000ULL +#define VSID_PR 0x8000000000000000ULLextern void kvmppc_mmu_pte_flush (struct kvm_vcpu *vcpu,u64 ea,u64 ea_mask);extern void kvmppc_mmu_pte_vflush (struct kvm_vcpu *vcpu,u64 vp,u64 vp_mask);
Signature · 1 line
1.6.0.2
PATCH 20/21 KVM: PPC: Make bools bitfields
In reply to a message not in the archiveBool defaults to at least byte width. We usually only want to waste a single bit on this. So let's move all the bool values to bitfields, potentially saving memory.
--- arch/powerpc/include/asm/kvm_book3s.h | 28 ++++++++++++++-------------- arch/powerpc/include/asm/kvm_host.h | 6 +++--- 2 files changed, 17 insertions(+), 17 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +14 -14
@@ -29,40 +29,40 @@ struct kvmppc_slb {u64 vsid;u64 orige;u64 origv; -bool valid; -bool Ks; -bool Kp; -bool nx; -bool large;/* PTEs are 16MB */ -bool tb;/* 1TB segment */ -bool class; + bool valid : 1; + bool Ks : 1; + bool Kp : 1; + bool nx : 1; + bool large : 1; /* PTEs are 16MB */ + bool tb : 1; /* 1TB segment */ + bool class : 1; };struct kvmppc_sr {u32 raw;u32 vsid; -bool Ks; -bool Kp; -bool nx; -bool valid; +bool Ks :1 ; +bool Kp :1 ; +bool nx :1 ; +bool valid :1 ; };struct kvmppc_bat {u64 raw;u32 bepi;u32 bepi_mask; -bool vs; -bool vp;u32 brpn;u8 wimg;u8 pp; +bool vs :1 ; +bool vp :1 ; };struct kvmppc_sid_map {u64 guest_vsid;u64 guest_esid;u64 host_vsid; -bool valid; +bool valid :1 ; };#define SID_MAP_BITS 9
arch/powerpc/include/asm/kvm_host.h +3 -3
@@ -127,9 +127,9 @@ struct kvmppc_pte {u64 eaddr;u64 vpage;u64 raddr; -bool may_read; -bool may_write; -bool may_execute; + bool may_read : 1; + bool may_write : 1; + bool may_execute : 1; };struct kvmppc_mmu {
Signature · 1 line
1.6.0.2
PATCH 21/21 KVM: PPC: Disable MSR_FEx for Cell hosts
In reply to a message not in the archiveCell can't handle MSR_FE0 and MSR_FE1 too well. It gets dog slow. So let's just override the guest whenever we see one of the two and mask them out. See commit ddf5f75a16b3e7460ffee881795aa168dffcd0cf for reference.
--- arch/powerpc/kvm/book3s.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s.c +4 -0
@@ -356,6 +356,10 @@ void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr) !strcmp(cur_cpu_spec->platform, "ppc970")) vcpu->arch.hflags |= BOOK3S_HFLAG_DCBZ32; +/* Cell performs badly if MSR_FEx are set. So let's hope nobody +really needs them in a VM on Cell and force disable them. */ +if (!strcmp (cur_cpu_spec->platform,"ppc-cell-be" )) +to_book3s (vcpu)->msr_mask &= ~(MSR_FE0 |MSR_FE1 ); }/* Book3s_32 CPUs always have 32 bytes cache line size, which Linux assumes. To
Signature · 1 line
1.6.0.2
Avi Kivity
AppliedQuoted 9 lines · Alexander Graf
Mac-on-Linux has always lacked PPC64 host support. This is going to change now!
This patchset contains minor patches to enable MOL, but is mostly about bug fixes that came out of running Mac OS X. With this set and the current svn version of MOL I have 10.4.11 running as a guest on a 970MP as well as a PS3 host.
Applied all, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 13/21] KVM: Add support for enabling capabilities per-vcpu
In reply to a message not in the archiveQuoted 9 lines · Alexander Graf
Some times we don't want all capabilities to be available to all our vcpus. One example for that is the OSI interface, implemented in the next patch.
In order to have a generic mechanism in how to enable capabilities individually, this patch introduces a new ioctl that can be used for this purpose. That way features we don't want in all guests or userspace configurations can just not be enabled and we're good.
Quoted 6 lines
Documentation/kvm/api.txt | 35 +++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 27 +++++++++++++++++++++++++++ include/linux/kvm.h | 12 ++++++++++++ 3 files changed, 74 insertions(+), 0 deletions(-)
Should really have been generic instead of ppc-specific, but can be moved later.
include/linux/kvm.h struct kvm_clock_data { · line 712
Quoted 7 lines
include/linux/kvm.h +2
-0@@ -697,6 +707,8 @@ struct kvm_clock_data {/* Available with KVM_CAP_DEBUGREGS */ #define KVM_GET_DEBUGREGS _IOR(KVMIO, 0xa1, struct kvm_debugregs)#define KVM_SET_DEBUGREGS _IOW(KVMIO, 0xa2, struct kvm_debugregs) +/* No need for CAP, because then it just always fails */ +#define KVM_ENABLE_CAP _IOW(KVMIO, 0xa3, struct kvm_enable_cap)
I dropped this comment while applying.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 13/21] KVM: Add support for enabling capabilities per-vcpu
In reply to a message not in the archiveQuoted 10 lines · Avi Kivity
Quoted 9 lines · Alexander Graf
Some times we don't want all capabilities to be available to all our vcpus. One example for that is the OSI interface, implemented in the next patch.
In order to have a generic mechanism in how to enable capabilities individually, this patch introduces a new ioctl that can be used for this purpose. That way features we don't want in all guests or userspace configurations can just not be enabled and we're good.
Quoted 8 lines
Quoted 6 lines
Documentation/kvm/api.txt | 35 +++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 27 +++++++++++++++++++++++++++ include/linux/kvm.h | 12 ++++++++++++ 3 files changed, 74 insertions(+), 0 deletions(-)Should really have been generic instead of ppc-specific, but can be moved later.
I didn't fully understand your comment about stuff being generic vs arch specific. But I assumed that since you know this ioctl exists now that whenever someone needs something similar now, it's easy to add support for it on other archs.
Quoted 10 lines
include/linux/kvm.h struct kvm_clock_data { · line 712
Quoted 8 lines
include/linux/kvm.h +2
-0@@ -697,6 +707,8 @@ struct kvm_clock_data {/* Available with KVM_CAP_DEBUGREGS */ #define KVM_GET_DEBUGREGS _IOR(KVMIO, 0xa1, struct kvm_debugregs)#define KVM_SET_DEBUGREGS _IOW(KVMIO, 0xa2, struct kvm_debugregs) +/* No need for CAP, because then it just always fails */ +#define KVM_ENABLE_CAP _IOW(KVMIO, 0xa3, struct kvm_enable_cap)I dropped this comment while applying.
Thanks.
Alex
Re: [PATCH 13/21] KVM: Add support for enabling capabilities per-vcpu
In reply to a message not in the archiveQuoted 21 lines · Alexander Graf
Quoted 18 lines · Avi Kivity
Quoted 16 lines · Alexander Graf
Some times we don't want all capabilities to be available to all our vcpus. One example for that is the OSI interface, implemented in the next patch.
In order to have a generic mechanism in how to enable capabilities individually, this patch introduces a new ioctl that can be used for this purpose. That way features we don't want in all guests or userspace configurations can just not be enabled and we're good.
Documentation/kvm/api.txt | 35 +++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 27 +++++++++++++++++++++++++++ include/linux/kvm.h | 12 ++++++++++++ 3 files changed, 74 insertions(+), 0 deletions(-)
Quoted 4 lines
Quoted 2 lines
Should really have been generic instead of ppc-specific, but can be moved later.
I didn't fully understand your comment about stuff being generic vs arch specific. But I assumed that since you know this ioctl exists now that whenever someone needs something similar now, it's easy to add support for it on other archs.
There is nothing arch specific about the interface (though the various caps can be arch specific). No need to add support, just move the code to virt/kvm and add an arch specific callout to handle the data.
Signature · 1 line
error compiling committee.c: too many arguments to function