All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Sergey Fedorov" <serge.fdrv@gmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Alexander Graf" <agraf@suse.de>
Subject: Re: [Qemu-devel] [PATCH RFC 3/8] target-arm: Add support for S2 page-table protection bits
Date: Thu, 1 Oct 2015 11:44:51 -0700	[thread overview]
Message-ID: <20151001184451.GB29416@toto> (raw)
In-Reply-To: <CAFEAcA_thbqKpZMt7EPPe570RQ5c+Si_KNt1-T8UVeP17Y95iw@mail.gmail.com>

On Wed, Sep 23, 2015 at 09:55:05AM -0700, Peter Maydell wrote:
> On 19 September 2015 at 07:15, Edgar E. Iglesias
> <edgar.iglesias@gmail.com> wrote:
> > From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
> >
> > Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
> > ---
> >  target-arm/helper.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
> >  1 file changed, 45 insertions(+), 3 deletions(-)
> >
> > diff --git a/target-arm/helper.c b/target-arm/helper.c
> > index 33be8c2..6f0ed51 100644
> > --- a/target-arm/helper.c
> > +++ b/target-arm/helper.c
> > @@ -6008,6 +6008,38 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap)
> >      return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx));
> >  }
> >
> > +/* Translate S2 section/page access permissions to protection flags
> > + *
> > + * @env:     CPUARMState
> > + * @ap:      The 2-bit simple AP (AP[2:1])
> 
> I think this should read "The 2-bit stage2 access permissions (S2AP)".
> The interpretation of the field differs from the simple-AP bits.
> You could helpfully call the argument "s2ap" as well.
> 
> > + * @xn:      XN (execute-never) bit
> > + */
> > +static int get_S2prot(CPUARMState *env, int ap, int xn)
> > +{
> > +    int prot_rw;
> > +
> > +    switch (ap) {
> > +    default:
> > +    case 0:
> > +        prot_rw = 0;
> > +        break;
> > +    case 1:
> > +        prot_rw = PAGE_READ | PAGE_EXEC;
> > +        break;
> > +    case 2:
> > +        prot_rw = PAGE_WRITE;
> > +        break;
> > +    case 3:
> > +        prot_rw = PAGE_READ | PAGE_EXEC | PAGE_WRITE;
> > +        break;
> > +    }
> > +
> > +    if (xn) {
> > +        prot_rw &= ~PAGE_EXEC;
> > +    }
> 
> This isn't right -- the XN bit controls executability and the
> S2AP bits don't affect it at all. I think you want:
> 
>     int prot_rw = 0;
>     if (s2ap & 1) {
>         prot_rw |= PAGE_READ;
>     }
>     if (s2ap & 2) {
>         prot_rw |= PAGE_WRITE;
>     }
>     if (!xn) {
>         prot_rw |= PAGE_EXEC;
>     }


Thanks, this was the stuff I was worried about when we talked about it
last time. I've got the following now which seems to be the same as
you suggest:

static int get_S2prot(CPUARMState *env, int s2ap, int xn)
{
    int prot;

    prot = s2ap & 1 ? PAGE_READ : 0;
    prot |= s2ap & 2 ? PAGE_WRITE : 0;
    if (!xn) {
        prot |= PAGE_EXEC;
    }
    return prot;
}


I've also fixed up your other comments on this.

Thanks,
Edgar


> 
> 
> > +    return prot_rw;
> > +}
> > +
> >  /* Translate section/page access permissions to protection flags
> >   *
> >   * @env:     CPUARMState
> > @@ -6617,6 +6649,11 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,
> >          /* Extract attributes from the descriptor and merge with table attrs */
> >          attrs = extract64(descriptor, 2, 10)
> >              | (extract64(descriptor, 52, 12) << 10);
> > +
> > +        if (mmu_idx == ARMMMUIdx_S2NS) {
> > +            /* The following extractions do not apply to S2.  */
> 
> I think it would be clearer to say
>   /* Stage 2 table descriptors do not include any attribute fields. */
> 
> > +            break;
> > +        }
> 
> and then here put
>       /* Merge in attributes from table descriptors */
> 
> and delete the now-redundant "and merge with table attrs" part from the
> comment at the start of this hunk.
> 
> >          attrs |= extract32(tableattrs, 0, 2) << 11; /* XN, PXN */
> >          attrs |= extract32(tableattrs, 3, 1) << 5; /* APTable[1] => AP[2] */
> >          /* The sense of AP[1] vs APTable[0] is reversed, as APTable[0] == 1
> > @@ -6638,11 +6675,16 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,
> >      }
> >
> >      ap = extract32(attrs, 4, 2);
> > -    ns = extract32(attrs, 3, 1);
> >      xn = extract32(attrs, 12, 1);
> > -    pxn = extract32(attrs, 11, 1);
> >
> > -    *prot = get_S1prot(env, mmu_idx, va_size == 64, ap, ns, xn, pxn);
> > +    if (mmu_idx == ARMMMUIdx_S2NS) {
> > +        ns = true;
> > +        *prot = get_S2prot(env, ap, xn);
> > +    } else {
> > +        ns = extract32(attrs, 3, 1);
> > +        pxn = extract32(attrs, 11, 1);
> > +        *prot = get_S1prot(env, mmu_idx, va_size == 64, ap, ns, xn, pxn);
> > +    }
> >
> >      fault_type = permission_fault;
> >      if (!(*prot & (1 << access_type))) {
> > --
> > 1.9.1
> >
> 
> thanks
> -- PMM

  reply	other threads:[~2015-10-01 18:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-19 14:15 [Qemu-devel] [PATCH RFC 0/8] arm: Steps towards EL2 support round 5 Edgar E. Iglesias
2015-09-19 14:15 ` [Qemu-devel] [PATCH RFC 1/8] target-arm: Add HPFAR_EL2 Edgar E. Iglesias
2015-09-23 16:23   ` Peter Maydell
2015-09-19 14:15 ` [Qemu-devel] [PATCH RFC 2/8] target-arm: Add computation of starting level for S2 PTW Edgar E. Iglesias
2015-09-23 16:36   ` Peter Maydell
2015-09-19 14:15 ` [Qemu-devel] [PATCH RFC 3/8] target-arm: Add support for S2 page-table protection bits Edgar E. Iglesias
2015-09-23 16:55   ` Peter Maydell
2015-10-01 18:44     ` Edgar E. Iglesias [this message]
2015-10-01 19:48       ` Peter Maydell
2015-10-01 19:52         ` Edgar E. Iglesias
2015-09-19 14:15 ` [Qemu-devel] [PATCH RFC 4/8] target-arm: Avoid inline for get_phys_addr Edgar E. Iglesias
2015-09-23 16:58   ` Peter Maydell
2015-10-01 18:35     ` Edgar E. Iglesias
2015-09-19 14:15 ` [Qemu-devel] [PATCH RFC 5/8] target-arm: Add ARMMMUFaultInfo Edgar E. Iglesias
2015-09-23 17:00   ` Peter Maydell
2015-09-19 14:15 ` [Qemu-devel] [PATCH RFC 6/8] target-arm: Add S2 translation support for S1 PTW Edgar E. Iglesias
2015-09-19 14:15 ` [Qemu-devel] [PATCH RFC 7/8] target-arm: Route S2 MMU faults to EL2 Edgar E. Iglesias
2015-09-19 14:15 ` [Qemu-devel] [PATCH RFC 8/8] target-arm: Add support for S1 + S2 MMU translations Edgar E. Iglesias
2015-09-19 14:39 ` [Qemu-devel] [PATCH RFC 0/8] arm: Steps towards EL2 support round 5 Edgar E. Iglesias
2015-09-23 17:11 ` Peter Maydell
2015-09-24 13:47   ` Edgar E. Iglesias

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=20151001184451.GB29416@toto \
    --to=edgar.iglesias@xilinx.com \
    --cc=agraf@suse.de \
    --cc=alex.bennee@linaro.org \
    --cc=edgar.iglesias@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=serge.fdrv@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.