qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org,
	qemu-ppc@nongnu.org, bharata.rao@gmail.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [Qemu-ppc] [PULL 02/12] ppc: Use split I/D mmu modes to avoid flushes on interrupts
Date: Thu, 2 Jun 2016 13:15:09 +1000	[thread overview]
Message-ID: <20160602031509.GI15455@voom.fritz.box> (raw)
In-Reply-To: <574F388A.3020201@ilande.co.uk>

[-- Attachment #1: Type: text/plain, Size: 10463 bytes --]

On Wed, Jun 01, 2016 at 08:33:30PM +0100, Mark Cave-Ayland wrote:
> On 31/05/16 01:41, David Gibson wrote:
> 
> > From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > 
> > We rework the way the MMU indices are calculated, providing separate
> > indices for I and D side based on MSR:IR and MSR:DR respectively,
> > and thus no longer need to flush the TLB on context changes. This also
> > adds correct support for HV as a separate address space.
> > 
> > Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  target-ppc/cpu.h         | 11 +++++++---
> >  target-ppc/excp_helper.c | 11 ----------
> >  target-ppc/helper_regs.h | 54 +++++++++++++++++++++++++++++++++++++++++-------
> >  target-ppc/machine.c     |  5 ++++-
> >  target-ppc/translate.c   |  7 ++++---
> >  5 files changed, 63 insertions(+), 25 deletions(-)
> > 
> > diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
> > index 02e71ea..2c8c8c0 100644
> > --- a/target-ppc/cpu.h
> > +++ b/target-ppc/cpu.h
> > @@ -359,6 +359,8 @@ struct ppc_slb_t {
> >  #define MSR_EP   6  /* Exception prefix on 601                               */
> >  #define MSR_IR   5  /* Instruction relocate                                  */
> >  #define MSR_DR   4  /* Data relocate                                         */
> > +#define MSR_IS   5  /* Instruction address space (BookE)                     */
> > +#define MSR_DS   4  /* Data address space (BookE)                            */
> >  #define MSR_PE   3  /* Protection enable on 403                              */
> >  #define MSR_PX   2  /* Protection exclusive on 403                  x        */
> >  #define MSR_PMM  2  /* Performance monitor mark on POWER            x        */
> > @@ -410,6 +412,8 @@ struct ppc_slb_t {
> >  #define msr_ep   ((env->msr >> MSR_EP)   & 1)
> >  #define msr_ir   ((env->msr >> MSR_IR)   & 1)
> >  #define msr_dr   ((env->msr >> MSR_DR)   & 1)
> > +#define msr_is   ((env->msr >> MSR_IS)   & 1)
> > +#define msr_ds   ((env->msr >> MSR_DS)   & 1)
> >  #define msr_pe   ((env->msr >> MSR_PE)   & 1)
> >  #define msr_px   ((env->msr >> MSR_PX)   & 1)
> >  #define msr_pmm  ((env->msr >> MSR_PMM)  & 1)
> > @@ -889,7 +893,7 @@ struct ppc_segment_page_sizes {
> >  
> >  /*****************************************************************************/
> >  /* The whole PowerPC CPU context */
> > -#define NB_MMU_MODES 3
> > +#define NB_MMU_MODES    8
> >  
> >  #define PPC_CPU_OPCODES_LEN          0x40
> >  #define PPC_CPU_INDIRECT_OPCODES_LEN 0x20
> > @@ -1053,7 +1057,8 @@ struct CPUPPCState {
> >      /* Those resources are used only in QEMU core */
> >      target_ulong hflags;      /* hflags is a MSR & HFLAGS_MASK         */
> >      target_ulong hflags_nmsr; /* specific hflags, not coming from MSR */
> > -    int mmu_idx;         /* precomputed MMU index to speed up mem accesses */
> > +    int immu_idx;         /* precomputed MMU index to speed up insn access */
> > +    int dmmu_idx;         /* precomputed MMU index to speed up data accesses */
> >  
> >      /* Power management */
> >      int (*check_pow)(CPUPPCState *env);
> > @@ -1245,7 +1250,7 @@ int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val);
> >  #define MMU_USER_IDX 0
> >  static inline int cpu_mmu_index (CPUPPCState *env, bool ifetch)
> >  {
> > -    return env->mmu_idx;
> > +    return ifetch ? env->immu_idx : env->dmmu_idx;
> >  }
> >  
> >  #include "exec/cpu-all.h"
> > diff --git a/target-ppc/excp_helper.c b/target-ppc/excp_helper.c
> > index 288903e..ba3caec 100644
> > --- a/target-ppc/excp_helper.c
> > +++ b/target-ppc/excp_helper.c
> > @@ -646,9 +646,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
> >  
> >      if (env->spr[SPR_LPCR] & LPCR_AIL) {
> >          new_msr |= (1 << MSR_IR) | (1 << MSR_DR);
> > -    } else if (msr & ((1 << MSR_IR) | (1 << MSR_DR))) {
> > -        /* If we disactivated any translation, flush TLBs */
> > -        tlb_flush(cs, 1);
> >      }
> >  
> >  #ifdef TARGET_PPC64
> > @@ -721,14 +718,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
> >      /* Reset exception state */
> >      cs->exception_index = POWERPC_EXCP_NONE;
> >      env->error_code = 0;
> > -
> > -    if ((env->mmu_model == POWERPC_MMU_BOOKE) ||
> > -        (env->mmu_model == POWERPC_MMU_BOOKE206)) {
> > -        /* XXX: The BookE changes address space when switching modes,
> > -                we should probably implement that as different MMU indexes,
> > -                but for the moment we do it the slow way and flush all.  */
> > -        tlb_flush(cs, 1);
> > -    }
> >  }
> >  
> >  void ppc_cpu_do_interrupt(CPUState *cs)
> > diff --git a/target-ppc/helper_regs.h b/target-ppc/helper_regs.h
> > index 271fddf..f7edd5b 100644
> > --- a/target-ppc/helper_regs.h
> > +++ b/target-ppc/helper_regs.h
> > @@ -41,11 +41,50 @@ static inline void hreg_swap_gpr_tgpr(CPUPPCState *env)
> >  
> >  static inline void hreg_compute_mem_idx(CPUPPCState *env)
> >  {
> > -    /* Precompute MMU index */
> > -    if (msr_pr == 0 && msr_hv != 0) {
> > -        env->mmu_idx = 2;
> > +    /* This is our encoding for server processors
> > +     *
> > +     *   0 = Guest User space virtual mode
> > +     *   1 = Guest Kernel space virtual mode
> > +     *   2 = Guest Kernel space real mode
> > +     *   3 = HV User space virtual mode
> > +     *   4 = HV Kernel space virtual mode
> > +     *   5 = HV Kernel space real mode
> > +     *
> > +     * The combination PR=1 IR&DR=0 is invalid, we will treat
> > +     * it as IR=DR=1
> > +     *
> > +     * For BookE, we need 8 MMU modes as follow:
> > +     *
> > +     *  0 = AS 0 HV User space
> > +     *  1 = AS 0 HV Kernel space
> > +     *  2 = AS 1 HV User space
> > +     *  3 = AS 1 HV Kernel space
> > +     *  4 = AS 0 Guest User space
> > +     *  5 = AS 0 Guest Kernel space
> > +     *  6 = AS 1 Guest User space
> > +     *  7 = AS 1 Guest Kernel space
> > +     */
> > +    if (env->mmu_model & POWERPC_MMU_BOOKE) {
> > +        env->immu_idx = env->dmmu_idx = msr_pr ? 0 : 1;
> > +        env->immu_idx += msr_is ? 2 : 0;
> > +        env->dmmu_idx += msr_ds ? 2 : 0;
> > +        env->immu_idx += msr_gs ? 4 : 0;
> > +        env->dmmu_idx += msr_gs ? 4 : 0;
> >      } else {
> > -        env->mmu_idx = 1 - msr_pr;
> > +        /* First calucalte a base value independent of HV */
> > +        if (msr_pr != 0) {
> > +            /* User space, ignore IR and DR */
> > +            env->immu_idx = env->dmmu_idx = 0;
> > +        } else {
> > +            /* Kernel, setup a base I/D value */
> > +            env->immu_idx = msr_ir ? 1 : 2;
> > +            env->dmmu_idx = msr_dr ? 1 : 2;
> > +        }
> > +        /* Then offset it for HV */
> > +        if (msr_hv) {
> > +            env->immu_idx += 3;
> > +            env->dmmu_idx += 3;
> > +        }
> >      }
> >  }
> >  
> > @@ -82,9 +121,10 @@ static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,
> >      }
> >      if (((value >> MSR_IR) & 1) != msr_ir ||
> >          ((value >> MSR_DR) & 1) != msr_dr) {
> > -        /* Flush all tlb when changing translation mode */
> > -        tlb_flush(cs, 1);
> > -        excp = POWERPC_EXCP_NONE;
> > +        cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
> > +    }
> > +    if ((env->mmu_model & POWERPC_MMU_BOOKE) &&
> > +        ((value >> MSR_GS) & 1) != msr_gs) {
> >          cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
> >      }
> >      if (unlikely((env->flags & POWERPC_FLAG_TGPR) &&
> > diff --git a/target-ppc/machine.c b/target-ppc/machine.c
> > index f6c7256..4820f22 100644
> > --- a/target-ppc/machine.c
> > +++ b/target-ppc/machine.c
> > @@ -97,9 +97,12 @@ static int cpu_load_old(QEMUFile *f, void *opaque, int version_id)
> >      qemu_get_betls(f, &env->nip);
> >      qemu_get_betls(f, &env->hflags);
> >      qemu_get_betls(f, &env->hflags_nmsr);
> > -    qemu_get_sbe32s(f, &env->mmu_idx);
> > +    qemu_get_sbe32(f); /* Discard unused mmu_idx */
> >      qemu_get_sbe32(f); /* Discard unused power_mode */
> >  
> > +    /* Recompute mmu indices */
> > +    hreg_compute_mem_idx(env);
> > +
> >      return 0;
> >  }
> >  
> > diff --git a/target-ppc/translate.c b/target-ppc/translate.c
> > index f5ceae5..b757634 100644
> > --- a/target-ppc/translate.c
> > +++ b/target-ppc/translate.c
> > @@ -11220,8 +11220,9 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
> >                  env->nip, env->lr, env->ctr, cpu_read_xer(env),
> >                  cs->cpu_index);
> >      cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx "  HF "
> > -                TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
> > -                env->hflags, env->mmu_idx);
> > +                TARGET_FMT_lx " iidx %d didx %d\n",
> > +                env->msr, env->spr[SPR_HID0],
> > +                env->hflags, env->immu_idx, env->dmmu_idx);
> >  #if !defined(NO_TIMER_DUMP)
> >      cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
> >  #if !defined(CONFIG_USER_ONLY)
> > @@ -11428,7 +11429,7 @@ void gen_intermediate_code(CPUPPCState *env, struct TranslationBlock *tb)
> >      ctx.spr_cb = env->spr_cb;
> >      ctx.pr = msr_pr;
> >      ctx.hv = !msr_pr && msr_hv;
> > -    ctx.mem_idx = env->mmu_idx;
> > +    ctx.mem_idx = env->dmmu_idx;
> >      ctx.insns_flags = env->insns_flags;
> >      ctx.insns_flags2 = env->insns_flags2;
> >      ctx.access_type = -1;
> 
> Apologies to have to report another regression, however this patch
> causes a kernel panic in Darwin PPC under TCG:
> 
> ./qemu-system-ppc -cdrom darwinppc-602.iso -boot d
> 
> The panic backtrace on-screen points towards one of the SCSI modules, so
> perhaps this patch doesn't handle DMA correctly when trying to access
> the CDROM?

Bother.  It's a lot less obvious to me how this one would cause
trouble.  Possibly a bug in the CD-ROM device which was masked by the
pervious mem access stuff.

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-06-02  3:16 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-31  0:41 [Qemu-devel] [PULL 00/12] ppc-for-2.7 queue 20160531 David Gibson
2016-05-31  0:41 ` [Qemu-devel] [PULL 01/12] ppc: Remove MMU_MODEn_SUFFIX definitions David Gibson
2016-05-31  0:41 ` [Qemu-devel] [PULL 02/12] ppc: Use split I/D mmu modes to avoid flushes on interrupts David Gibson
2016-06-01 19:33   ` [Qemu-devel] [Qemu-ppc] " Mark Cave-Ayland
2016-06-02  3:15     ` David Gibson [this message]
2016-06-02  5:32       ` Mark Cave-Ayland
2016-05-31  0:41 ` [Qemu-devel] [PULL 03/12] ppc: Do some batching of TCG tlb flushes David Gibson
2016-05-31  0:41 ` [Qemu-devel] [PULL 04/12] ppc: tlbie, tlbia and tlbisync are HV only David Gibson
2016-05-31 22:28   ` [Qemu-devel] [Qemu-ppc] " Mark Cave-Ayland
2016-06-01  2:15     ` David Gibson
2016-06-01  7:03       ` Mark Cave-Ayland
2016-06-02  3:17         ` David Gibson
2016-06-02  7:37           ` Cédric Le Goater
2016-06-02  7:45             ` Mark Cave-Ayland
2016-06-02  8:23               ` Cédric Le Goater
2016-06-02  8:47                 ` Mark Cave-Ayland
2016-06-02 18:09                   ` Mark Cave-Ayland
2016-06-02 18:19                     ` Cédric Le Goater
2016-06-03  7:12                   ` David Gibson
2016-06-14  7:37           ` Thomas Huth
2016-05-31  0:41 ` [Qemu-devel] [PULL 05/12] ppc: Change 'invalid' bit mask of tlbiel and tlbie David Gibson
2016-05-31  0:41 ` [Qemu-devel] [PULL 06/12] ppc: Fix sign extension issue in mtmsr(d) emulation David Gibson
2016-05-31  0:41 ` [Qemu-devel] [PULL 07/12] ppc: Get out of emulation on SMT "OR" ops David Gibson
2025-08-27 14:07   ` Philippe Mathieu-Daudé
2025-09-24 17:19     ` Philippe Mathieu-Daudé
2016-05-31  0:41 ` [Qemu-devel] [PULL 08/12] ppc: Add PPC_64H instruction flag to POWER7 and POWER8 David Gibson
2016-05-31  0:41 ` [Qemu-devel] [PULL 09/12] exec: Remove cpu from cpus list during cpu_exec_exit() David Gibson
2016-05-31  0:41 ` [Qemu-devel] [PULL 10/12] exec: Do vmstate unregistration from cpu_exec_exit() David Gibson
2016-05-31  0:41 ` [Qemu-devel] [PULL 11/12] cpu: Reclaim vCPU objects David Gibson
2016-05-31  0:41 ` [Qemu-devel] [PULL 12/12] cpu: Add a sync version of cpu_remove() David Gibson
2016-06-02 12:42 ` [Qemu-devel] [PULL 00/12] ppc-for-2.7 queue 20160531 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160602031509.GI15455@voom.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=bharata.rao@gmail.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).