All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>,
	patches@linaro.org,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	qemu-devel@nongnu.org, Greg Bellows <greg.bellows@linaro.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH v2 11/14] target-arm: Use correct memory attributes for page table walks
Date: Tue, 21 Apr 2015 10:36:01 +0100	[thread overview]
Message-ID: <87zj61vn5q.fsf@linaro.org> (raw)
In-Reply-To: <1428931324-4973-12-git-send-email-peter.maydell@linaro.org>


Peter Maydell <peter.maydell@linaro.org> writes:

> Factor out the page table walk memory accesses into their own function,
> so that we can specify the correct S/NS memory attributes for them.
> This will also provide a place to use the correct endianness and
> handle the need for a stage-2 translation when virtualization is
> supported.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
> ---
>  target-arm/helper.c | 49 ++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 40 insertions(+), 9 deletions(-)
>
> diff --git a/target-arm/helper.c b/target-arm/helper.c
> index a568299..a01ff7f 100644
> --- a/target-arm/helper.c
> +++ b/target-arm/helper.c
> @@ -5129,6 +5129,29 @@ static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx,
>      return true;
>  }
>  
> +/* All loads done in the course of a page table walk go through here.
> + * TODO: rather than ignoring errors from physical memory reads (which
> + * are external aborts in ARM terminology) we should propagate this
> + * error out so that we can turn it into a Data Abort if this walk
> + * was being done for a CPU load/store or an address translation instruction
> + * (but not if it was for a debug access).
> + */
> +static uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure)
> +{
> +    MemTxAttrs attrs = {};
> +
> +    attrs.secure = is_secure;
> +    return address_space_ldl(cs->as, addr, attrs, NULL);
> +}
> +
> +static uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure)
> +{
> +    MemTxAttrs attrs = {};
> +
> +    attrs.secure = is_secure;
> +    return address_space_ldq(cs->as, addr, attrs, NULL);
> +}
> +
>  static int get_phys_addr_v5(CPUARMState *env, uint32_t address, int access_type,
>                              ARMMMUIdx mmu_idx, hwaddr *phys_ptr,
>                              int *prot, target_ulong *page_size)
> @@ -5151,7 +5174,7 @@ static int get_phys_addr_v5(CPUARMState *env, uint32_t address, int access_type,
>          code = 5;
>          goto do_fault;
>      }
> -    desc = ldl_phys(cs->as, table);
> +    desc = arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx));
>      type = (desc & 3);
>      domain = (desc >> 5) & 0x0f;
>      if (regime_el(env, mmu_idx) == 1) {
> @@ -5187,7 +5210,7 @@ static int get_phys_addr_v5(CPUARMState *env, uint32_t address, int access_type,
>              /* Fine pagetable.  */
>              table = (desc & 0xfffff000) | ((address >> 8) & 0xffc);
>          }
> -        desc = ldl_phys(cs->as, table);
> +        desc = arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx));
>          switch (desc & 3) {
>          case 0: /* Page translation fault.  */
>              code = 7;
> @@ -5261,7 +5284,7 @@ static int get_phys_addr_v6(CPUARMState *env, uint32_t address, int access_type,
>          code = 5;
>          goto do_fault;
>      }
> -    desc = ldl_phys(cs->as, table);
> +    desc = arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx));
>      type = (desc & 3);
>      if (type == 0 || (type == 3 && !arm_feature(env, ARM_FEATURE_PXN))) {
>          /* Section translation fault, or attempt to use the encoding
> @@ -5310,7 +5333,7 @@ static int get_phys_addr_v6(CPUARMState *env, uint32_t address, int access_type,
>          ns = extract32(desc, 3, 1);
>          /* Lookup l2 entry.  */
>          table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc);
> -        desc = ldl_phys(cs->as, table);
> +        desc = arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx));
>          ap = ((desc >> 4) & 3) | ((desc >> 7) & 4);
>          switch (desc & 3) {
>          case 0: /* Page translation fault.  */
> @@ -5525,13 +5548,20 @@ static int get_phys_addr_lpae(CPUARMState *env, target_ulong address,
>      descaddr = extract64(ttbr, 0, 48);
>      descaddr &= ~((1ULL << (va_size - tsz - (granule_sz * (4 - level)))) - 1);
>  
> -    tableattrs = 0;
> +    /* Secure accesses start with the page table in secure memory and
> +     * can be downgraded to non-secure at any step. Non-secure accesses
> +     * remain non-secure. We implement this by just ORing in the NSTable/NS
> +     * bits at each step.
> +     */
> +    tableattrs = regime_is_secure(env, mmu_idx) ? 0 : (1 << 4);
<snip>

Again some new magic numbers added to the function but anyway:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

>      /* Here descaddr is the final physical address, and attributes
> @@ -5705,8 +5735,9 @@ static inline int get_phys_addr(CPUARMState *env, target_ulong address,
>  {
>      if (mmu_idx == ARMMMUIdx_S12NSE0 || mmu_idx == ARMMMUIdx_S12NSE1) {
>          /* TODO: when we support EL2 we should here call ourselves recursively
> -         * to do the stage 1 and then stage 2 translations. The ldl_phys
> -         * calls for stage 1 will also need changing.
> +         * to do the stage 1 and then stage 2 translations. The arm_ld*_ptw
> +         * functions will also need changing to perform ARMMMUIdx_S2NS loads
> +         * rather than direct physical memory loads when appropriate.
>           * For non-EL2 CPUs a stage1+stage2 translation is just stage 1.
>           */
>          assert(!arm_feature(env, ARM_FEATURE_EL2));

-- 
Alex Bennée

  reply	other threads:[~2015-04-21  9:35 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 13:21 [Qemu-devel] [PATCH v2 00/14] Add memory attributes and use them in ARM Peter Maydell
2015-04-13 13:21 ` [Qemu-devel] [PATCH v2 01/14] memory: Define API for MemoryRegionOps to take attrs and return status Peter Maydell
2015-04-15  1:35   ` Edgar E. Iglesias
2015-04-17 16:00   ` Alex Bennée
2015-04-13 13:21 ` [Qemu-devel] [PATCH v2 02/14] memory: Replace io_mem_read/write with memory_region_dispatch_read/write Peter Maydell
2015-04-17 16:01   ` Alex Bennée
2015-04-13 13:21 ` [Qemu-devel] [PATCH v2 03/14] Make CPU iotlb a structure rather than a plain hwaddr Peter Maydell
2015-04-17 16:08   ` Alex Bennée
2015-04-13 13:21 ` [Qemu-devel] [PATCH v2 04/14] Add MemTxAttrs to the IOTLB Peter Maydell
2015-04-17 16:09   ` Alex Bennée
2015-04-13 13:21 ` [Qemu-devel] [PATCH v2 05/14] exec.c: Convert subpage memory ops to _with_attrs Peter Maydell
2015-04-17 16:15   ` Alex Bennée
2015-04-17 16:18     ` Peter Maydell
2015-04-17 16:25       ` Alex Bennée
2015-04-13 13:21 ` [Qemu-devel] [PATCH v2 06/14] exec.c: Make address_space_rw take transaction attributes Peter Maydell
2015-04-21  7:39   ` Alex Bennée
2015-04-21 13:27     ` Peter Maydell
2015-04-13 13:21 ` [Qemu-devel] [PATCH v2 07/14] exec.c: Add new address_space_ld*/st* functions Peter Maydell
2015-04-21  8:36   ` Alex Bennée
2015-04-13 13:21 ` [Qemu-devel] [PATCH v2 08/14] exec.c: Capture the memory attributes for a watchpoint hit Peter Maydell
2015-04-21  8:42   ` Alex Bennée
2015-04-13 13:21 ` [Qemu-devel] [PATCH v2 09/14] Switch non-CPU callers from ld/st*_phys to address_space_ld/st* Peter Maydell
2015-04-21  8:44   ` Alex Bennée
2015-04-13 13:22 ` [Qemu-devel] [PATCH v2 10/14] target-arm: Honour NS bits in page tables Peter Maydell
2015-04-21  9:24   ` Alex Bennée
2015-04-21 13:28     ` Peter Maydell
2015-04-13 13:22 ` [Qemu-devel] [PATCH v2 11/14] target-arm: Use correct memory attributes for page table walks Peter Maydell
2015-04-21  9:36   ` Alex Bennée [this message]
2015-04-13 13:22 ` [Qemu-devel] [PATCH v2 12/14] target-arm: Add user-mode transaction attribute Peter Maydell
2015-04-21  9:36   ` Alex Bennée
2015-04-13 13:22 ` [Qemu-devel] [PATCH v2 13/14] target-arm: Use attribute info to handle user-only watchpoints Peter Maydell
2015-04-21  9:37   ` Alex Bennée
2015-04-13 13:22 ` [Qemu-devel] [PATCH v2 14/14] target-arm: Check watchpoints against CPU security state Peter Maydell
2015-04-21  9:37   ` Alex Bennée
2015-04-21 13:35 ` [Qemu-devel] [PATCH v2 00/14] Add memory attributes and use them in ARM 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=87zj61vn5q.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=edgar.iglesias@gmail.com \
    --cc=greg.bellows@linaro.org \
    --cc=patches@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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.