On Tue, Feb 07, 2017 at 01:56:49PM +1100, Sam Bobroff wrote: > Both radix and hash modes require guests to use > h_register_process_table() to set up the MMU. Implement it using the > new KVM ioctl KVM_PPC_CONFIGURE_V3_MMU. > > This hypercall is also necessary for fully emulated guests, so it will > need to be reworked to integrate with Suraj's TCG patchset. > --- > hw/ppc/spapr_hcall.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > include/hw/ppc/spapr.h | 3 ++- > target/ppc/kvm.c | 12 ++++++++++++ > target/ppc/kvm_ppc.h | 1 + > 4 files changed, 63 insertions(+), 1 deletion(-) > > diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c > index c9bb6624c4..4de511c386 100644 > --- a/hw/ppc/spapr_hcall.c > +++ b/hw/ppc/spapr_hcall.c > @@ -1049,6 +1049,50 @@ static target_ulong > h_client_architecture_support(PowerPCCPU *cpu_, > return H_SUCCESS; > } > > +static target_ulong h_register_process_table(PowerPCCPU *cpu, > + sPAPRMachineState *spapr, > + target_ulong opcode, > + target_ulong *args) > +{ > + static target_ulong last_process_table;
Ewwww.. a static local? Store this info in sPAPRMachineState instead; chances are you'll want it in other places eventually anyway (even if only for debugging). > + target_ulong flags = args[0]; > + target_ulong proc_tbl = args[1]; > + target_ulong page_size = args[2]; > + target_ulong table_size = args[3]; > + uint64_t cflags, cproc; > + > + cflags = (flags & 4) ? KVM_PPC_MMUV3_RADIX : 0; No #defines for the bits in the hcall arguments? > + cflags |= (flags & 1) ? KVM_PPC_MMUV3_GTSE : 0; > + cproc = (flags & 4) ? (1ul << 63) : 0; > + if (!(flags & 0x10)) { > + if ((last_process_table & (1ul << 63)) != cproc) { > + return H_PARAMETER; > + } > + cproc = last_process_table; > + } else if (!(flags & 0x8)) { > + ; /* do nothing */ > + } else if (flags & 4) { > + /* radix */ > + if (table_size > 24 || (proc_tbl & 0xfff) || (proc_tbl >> 60)) { > + return H_PARAMETER; > + } > + cproc |= proc_tbl | table_size; > + } else { > + /* hash, possibly with process table */ > + if (table_size > 24 || (proc_tbl >> 38) || page_size > 7) { > + return H_PARAMETER; > + } > + cproc = (proc_tbl << 25) | (page_size << 5) | table_size; > + } > + last_process_table = cproc; > + fprintf(stderr, "calling config mmu flags=%lx proctbl=%lx\n", > + cflags, cproc); > + if (!kvmppc_configure_v3_mmu(cpu, cflags, cproc)) { > + return H_HARDWARE; > + } > + return H_SUCCESS; > +} > + > static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1]; > static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - > KVMPPC_HCALL_BASE + 1]; > > @@ -1136,6 +1180,10 @@ static void hypercall_register_types(void) > > /* ibm,client-architecture-support support */ > spapr_register_hypercall(KVMPPC_H_CAS, h_client_architecture_support); > + > + /* Power9 MMU support */ > + spapr_register_hypercall(H_REGISTER_PROCESS_TABLE, > + h_register_process_table); > } > > type_init(hypercall_register_types) > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h > index bd5bcf70de..92bda0f36d 100644 > --- a/include/hw/ppc/spapr.h > +++ b/include/hw/ppc/spapr.h > @@ -347,7 +347,8 @@ struct sPAPRMachineState { > #define H_XIRR_X 0x2FC > #define H_RANDOM 0x300 > #define H_SET_MODE 0x31C > -#define MAX_HCALL_OPCODE H_SET_MODE > +#define H_REGISTER_PROCESS_TABLE 0x37C > +#define MAX_HCALL_OPCODE H_REGISTER_PROCESS_TABLE > > /* The hcalls above are standardized in PAPR and implemented by pHyp > * as well. > diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c > index 8d6fd1b067..0d1443616c 100644 > --- a/target/ppc/kvm.c > +++ b/target/ppc/kvm.c > @@ -344,6 +344,18 @@ static bool kvm_get_rmmu_info(PowerPCCPU *cpu, struct > kvm_ppc_rmmu_info *info) > return false; > } > > +bool kvmppc_configure_v3_mmu(PowerPCCPU *cpu, uint64_t flags, uint64_t > proc_tbl) > +{ > + CPUState *cs = CPU(cpu); > + int ret; > + struct kvm_ppc_mmuv3_cfg cfg; > + > + cfg.flags = flags; > + cfg.process_table = proc_tbl; > + ret = kvm_vm_ioctl(cs->kvm_state, KVM_PPC_CONFIGURE_V3_MMU, &cfg); > + return ret == 0; > +} > + > static long gethugepagesize(const char *mem_path) > { > struct statfs fs; > diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h > index 1c1b94847c..0b8b77583a 100644 > --- a/target/ppc/kvm_ppc.h > +++ b/target/ppc/kvm_ppc.h > @@ -33,6 +33,7 @@ int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t > tsr_bits); > int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits); > int kvmppc_set_tcr(PowerPCCPU *cpu); > int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu); > +bool kvmppc_configure_v3_mmu(PowerPCCPU *cpu, uint64_t flags, uint64_t > proctbl); > #ifndef CONFIG_USER_ONLY > off_t kvmppc_alloc_rma(void **rma); > bool kvmppc_spapr_use_multitce(void); -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
signature.asc
Description: PGP signature