[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-ppc] [PATCH v3 09/12] target/ppc: Implement H_REGISTER_PROCESS
From: |
Sam Bobroff |
Subject: |
Re: [Qemu-ppc] [PATCH v3 09/12] target/ppc: Implement H_REGISTER_PROCESS_TABLE H_CALL |
Date: |
Wed, 15 Mar 2017 11:23:38 +1100 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Fri, Mar 03, 2017 at 03:09:05PM +1100, David Gibson wrote:
> On Thu, Mar 02, 2017 at 04:39:04PM +1100, Sam Bobroff wrote:
> > From: Suraj Jitindar Singh <address@hidden>
> >
> > The H_REGISTER_PROCESS_TABLE H_CALL is used by a guest to indicate to the
> > hypervisor where in memory its process table is and how translation should
> > be performed using this process table.
> >
> > Provide the implementation of this H_CALL for a guest.
> >
> > We first check for invalid flags, then parse the flags to determine the
> > operation, and then check the other parameters for valid values based on
> > the operation (register new table/deregister table/maintain registration).
> > The process table is then stored in the appropriate location and registered
> > with the hypervisor (if running under KVM), and the LPCR_[UPRT/GTSE] bits
> > are updated as required.
> >
> > Signed-off-by: Suraj Jitindar Singh <address@hidden>
> > Signed-off-by: Sam Bobroff <address@hidden>
> > ---
> > Changes in v3:
> > * KVM-only implementation of h_register_process_table() integrated into the
> > TCG version.
> >
> > hw/ppc/spapr.c | 11 ++++-
> > hw/ppc/spapr_hcall.c | 114
> > +++++++++++++++++++++++++++++++++++++++++++++++--
> > include/hw/ppc/spapr.h | 1 +
> > target/ppc/kvm.c | 18 ++++++++
> > target/ppc/kvm_ppc.h | 2 +
> > 5 files changed, 141 insertions(+), 5 deletions(-)
> >
> > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > index 0b266e96f1..8cbab04101 100644
> > --- a/hw/ppc/spapr.c
> > +++ b/hw/ppc/spapr.c
> > @@ -40,6 +40,7 @@
> > #include "kvm_ppc.h"
> > #include "migration/migration.h"
> > #include "mmu-hash64.h"
> > +#include "mmu-book3s-v3.h"
> > #include "qom/cpu.h"
> >
> > #include "hw/boards.h"
> > @@ -1080,7 +1081,7 @@ static int get_htab_fd(sPAPRMachineState *spapr)
> > return spapr->htab_fd;
> > }
> >
> > -static void close_htab_fd(sPAPRMachineState *spapr)
> > +void close_htab_fd(sPAPRMachineState *spapr)
> > {
> > if (spapr->htab_fd >= 0) {
> > close(spapr->htab_fd);
> > @@ -1216,6 +1217,8 @@ void spapr_setup_hpt_and_vrma(sPAPRMachineState
> > *spapr)
> > spapr->rma_size = kvmppc_rma_size(spapr_node0_size(),
> > spapr->htab_shift);
> > }
> > + /* We're setting up a hash table, so that means we're not radix */
> > + spapr->patb_entry = 0;
> > }
> >
> > static void find_unknown_sysbus_device(SysBusDevice *sbdev, void *opaque)
> > @@ -1246,7 +1249,11 @@ static void ppc_spapr_reset(void)
> > /* Check for unknown sysbus devices */
> > foreach_dynamic_sysbus_device(find_unknown_sysbus_device, NULL);
> >
> > - spapr->patb_entry = 0;
> > + if (kvm_enabled()) { /* We assume Radix under KVM */
> > + spapr->patb_entry = PATBE1_GR;
> > + } else {
> > + spapr->patb_entry = 0;
> > + }
> >
> > /* If using KVM with radix mode available, VCPUs can be started
> > * without a HPT because KVM will start them in radix mode. */
> > diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
> > index cd0d8b068c..2bf794d9cd 100644
> > --- a/hw/ppc/spapr_hcall.c
> > +++ b/hw/ppc/spapr_hcall.c
> > @@ -12,6 +12,8 @@
> > #include "trace.h"
> > #include "kvm_ppc.h"
> > #include "hw/ppc/spapr_ovec.h"
> > +#include "qemu/error-report.h"
> > +#include "mmu-book3s-v3.h"
> >
> > struct SPRSyncState {
> > int spr;
> > @@ -894,14 +896,120 @@ static target_ulong h_invalidate_pid(PowerPCCPU
> > *cpu, sPAPRMachineState *spapr,
> > return H_FUNCTION;
> > }
> >
> > +static void spapr_check_setup_free_hpt(sPAPRMachineState *spapr,
> > + uint64_t patbe_old, uint64_t
> > patbe_new)
> > +{
> > + /*
> > + * We have 4 Options:
> > + * HASH->HASH || RADIX->RADIX || NOTHING->RADIX : Do Nothing
> > + * HASH->RADIX : Free HPT
> > + * RADIX->HASH : Allocate HPT
> > + * NOTHING->HASH : Allocate HPT
> > + * Note: NOTHING implies the case where we said the guest could choose
> > + * later and so assumed radix and now it's called H_REG_PROC_TBL
> > + */
> > +
> > + if ((patbe_old & PATBE1_GR) == (patbe_new & PATBE1_GR)) {
> > + /* We assume RADIX, so this catches all the "Do Nothing" cases */
> > + } else if (!(patbe_old & PATBE1_GR)) {
> > + /* HASH->RADIX : Free HPT */
> > + g_free(spapr->htab);
> > + spapr->htab = NULL;
> > + spapr->htab_shift = 0;
> > + close_htab_fd(spapr);
> > + } else if (!(patbe_new & PATBE1_GR)) {
> > + /* RADIX->HASH || NOTHING->HASH : Allocate HPT */
> > + spapr_setup_hpt_and_vrma(spapr);
> > + }
> > + return;
> > +}
> > +
> > +#define FLAGS_MASK 0x01FULL
> > +#define FLAGS_MAINTAIN(flags) (!(flags & 0x10))
> > +#define FLAGS_DEREG(flags) ((flags & 0x10) && !(flags & 0x08))
> > +#define FLAGS_NEW_RADIX(flags) ((flags & 0x18) && (flags & 0x04))
> > +#define FLAGS_NEW_HASH(flags) ((flags & 0x18) && !(flags & 0x04))
> > +#define FLAGS_RADIX(flags) (flags & 0x04)
> > +#define FLAGS_HASH_SLB(flags) (!(flags & 0x06))
> > +#define FLAGS_HASH_SEG(flags) (!(flags & 0x04) && (flags & 0x02))
> > +#define FLAGS_GTSE(flags) (flags & 0x01)
>
> It's a bit more normal for simple bit tests like this to just #define
> the bitmask values and do the bitwise-& in the code, rather than
> hiding it in the macro.
OK. Will change. In order to keep the "if" statements tidy I've
reordered the clauses as well (to avoid "if (!x) else ...").
> > +
> > static target_ulong h_register_process_table(PowerPCCPU *cpu,
> > sPAPRMachineState *spapr,
> > target_ulong opcode,
> > target_ulong *args)
> > {
> > - qemu_log_mask(LOG_UNIMP, "Unimplemented SPAPR hcall 0x" TARGET_FMT_lx
> > "%s\n",
> > - opcode, " (H_REGISTER_PROC_TBL)");
> > - return H_FUNCTION;
> > + CPUPPCState *env = &cpu->env;
> > + 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 cproc;
> > +
> > + if (flags & ~FLAGS_MASK) { /* Check no reserved bits are set */
> > + return H_PARAMETER;
> > + } else if (FLAGS_MAINTAIN(flags)) { /* Maintain current registration */
> > + if (!!(flags & 0x4) ^ !!(spapr->patb_entry & PATBE1_GR)) {
> > + return H_PARAMETER; /* Existing Process Table Mismatch */
> > + }
> > + cproc = spapr->patb_entry;
> > + } else if (FLAGS_DEREG(flags)) { /* Deregister current process table */
> > + /* Set to benign value: (current GR) | 0. This allows
> > + * deregistration in KVM to succeed even if the radix bit in flags
> > + * doesn't match the radix bit in the old PATB. */
> > + cproc = spapr->patb_entry & PATBE1_GR;
> > + } else if (FLAGS_NEW_RADIX(flags)) { /* Register new RADIX process
> > table */
> > + if (proc_tbl & 0xfff || proc_tbl >> 60) {
> > + return H_P2;
> > + } else if (page_size) {
> > + return H_P3;
> > + } else if (table_size > 24) {
> > + return H_P4;
> > + }
> > + cproc = PATBE1_GR | proc_tbl | table_size;
> > + } else { /* Register new HPT process table */
> > + if (FLAGS_HASH_SLB(flags)) { /* SLB */
> > + if (proc_tbl >> 38) {
> > + return H_P2;
> > + } else if (page_size & ~0x7) {
> > + return H_P3;
> > + } else if (table_size > 24) {
> > + return H_P4;
> > + }
> > + } else if (FLAGS_HASH_SEG(flags)) { /* Segment Tables */
> > + /* TODO - Not Supported */
> > + return H_PARAMETER;
>
> Is H_PARAMETER correct? Usually that indicates the guest has supplied
> an invalid parameter rather than merely one the hypervisor doesn't
> support. I'd expect H_NOT_AVAILABLE or maybe H_HARDWARE here.
The documentation says to return H_PARAMETER if any bits in "flags"
aren't supported, so I think this is correct (if a bit odd). Does that
seem OK?
> > + }
> > + cproc = (proc_tbl << 25) | page_size << 5 | table_size;
> > + }
> > +
> > + /* Check if we need to setup OR free the hpt */
> > + spapr_check_setup_free_hpt(spapr, spapr->patb_entry, cproc);
> > +
> > + spapr->patb_entry = cproc; /* Save new process table */
> > + if (FLAGS_RADIX(flags) || FLAGS_HASH_SEG(flags)) { /* Use Process TBL
> > */
> > + env->spr[SPR_LPCR] |= LPCR_UPRT;
> > + } else {
> > + env->spr[SPR_LPCR] &= ~LPCR_UPRT;
> > + }
> > + if (FLAGS_GTSE(flags)) { /* Partition Uses Guest Translation Shootdwn
> > */
> > + env->spr[SPR_LPCR] |= LPCR_GTSE;
> > + } else {
> > + env->spr[SPR_LPCR] &= ~LPCR_GTSE;
> > + }
> > +
> > + if (kvm_enabled()) {
> > + uint64_t cflags = 0;
> > +
> > + if (FLAGS_RADIX(flags)) {
> > + cflags |= KVM_PPC_MMUV3_RADIX;
> > + }
> > + if (FLAGS_GTSE(flags)) {
> > + cflags |= KVM_PPC_MMUV3_GTSE;
> > + }
> > + return kvmppc_configure_v3_mmu(cpu, cflags, cproc);
> > + }
> > + return H_SUCCESS;
> > }
> >
> > #define H_SIGNAL_SYS_RESET_ALL -1
> > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> > index 08cdb83953..a964a50693 100644
> > --- a/include/hw/ppc/spapr.h
> > +++ b/include/hw/ppc/spapr.h
> > @@ -594,6 +594,7 @@ void spapr_dt_events(sPAPRMachineState *sm, void *fdt);
> > int spapr_h_cas_compose_response(sPAPRMachineState *sm,
> > target_ulong addr, target_ulong size,
> > sPAPROptionVector *ov5_updates);
> > +void close_htab_fd(sPAPRMachineState *spapr);
> > void spapr_setup_hpt_and_vrma(sPAPRMachineState *spapr);
> > sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn);
> > void spapr_tce_table_enable(sPAPRTCETable *tcet,
> > diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> > index adf12da1aa..a264eeacdb 100644
> > --- a/target/ppc/kvm.c
> > +++ b/target/ppc/kvm.c
> > @@ -358,6 +358,24 @@ struct ppc_radix_page_info
> > *kvm_get_radix_page_info(void)
> > return radix_page_info;
> > }
> >
> > +target_ulong 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;
>
> You can use a C99 structure initializer for this.
OK.
> > + ret = kvm_vm_ioctl(cs->kvm_state, KVM_PPC_CONFIGURE_V3_MMU, &cfg);
> > + switch (ret) {
> > + case 0: return H_SUCCESS;
> > + case -EINVAL: return H_PARAMETER;
> > + case -ENODEV: return H_FUNCTION;
>
> Should probably be H_NOT_AVAILABLE, AIUI PAPR only uses H_FUNCTION
> when it doesn't know about the hypercall at all.
Ah thanks, I wasn't sure of this. I'll change it to H_NOT_AVAILABLE (the
return value doesn't matter to Linux guests but I think it's good to
differentiate these cases for debugging).
> > + default: return H_HARDWARE;
> > + }
> > +}
> > +
> > 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 0cdbe9ea0b..d1462913e3 100644
> > --- a/target/ppc/kvm_ppc.h
> > +++ b/target/ppc/kvm_ppc.h
> > @@ -33,6 +33,8 @@ 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);
> > +target_ulong 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