xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: Sergej Proskurin <proskurin@sec.in.tum.de>,
	xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH v6 12/14] arm/mem_access: Add long-descriptor based gpt
Date: Mon, 17 Jul 2017 17:18:04 +0100	[thread overview]
Message-ID: <c77ab1d7-6c4c-cfdb-be3d-888d530a794e@arm.com> (raw)
In-Reply-To: <20170706115017.23072-13-proskurin@sec.in.tum.de>

Hi Sergej,

On 06/07/17 12:50, Sergej Proskurin wrote:
> +/*
> + * Get the MSB number of the GVA, according to "AddrTop" pseudocode
> + * implementation in ARM DDI 0487B.a J1-6066.
> + */
> +static unsigned int get_top_bit(struct domain *d, vaddr_t gva, register_t tcr)
> +{
> +    unsigned int topbit;
> +
> +    /*
> +     * IF EL1 is using AArch64 then addresses from EL0 using AArch32 are

NIT: s/IF/If/

> +     * zero-extended to 64 bits (ARM DDI 0487B.a J1-6066).
> +     */
> +    if ( is_32bit_domain(d) )
> +        topbit = 31;
> +    else if ( is_64bit_domain(d) )
> +    {
> +        if ( ((gva & BIT_ULL(55)) && (tcr & TCR_EL1_TBI1)) ||
> +             (!(gva & BIT_ULL(55)) && (tcr & TCR_EL1_TBI0)) )
> +            topbit = 55;
> +        else
> +            topbit = 63;
> +    }
> +
> +    return topbit;
> +}
> +
> +/* Make sure the base address does not exceed its configured size. */
> +static int check_base_size(unsigned int output_size, uint64_t base)
> +{
> +    paddr_t mask = GENMASK_ULL((TCR_EL1_IPS_48_BIT_VAL - 1), output_size);
> +
> +    if ( (output_size < TCR_EL1_IPS_48_BIT_VAL) && (base & mask) )
> +        return -EFAULT;
> +
> +    return 0;

This function only return 0 or -EFAULT and the caller doesn't care of 
the exact value. I would prefer if you return a boolean here.

[...]

> +    /*
> +     * According to to ARM DDI 0487B.a J1-5927, we return an error if the found
> +     * PTE is invalid or holds a reserved entry (PTE<1:0> == x0)) or if the PTE
> +     * maps a memory block at level 3 (PTE<1:0> == 01).
> +     */
> +    if ( !lpae_is_page(pte, level) && !lpae_is_superpage(pte, level) )
> +        return -EFAULT;
> +
> +    *ipa = pfn_to_paddr(pte.walk.base) | (gva & masks[gran][level]);

I haven't noticed it until now. When using 16KB and 64KB, you rely on 
the bottom bits to be zeroed. Although, the guest could purposefully put 
wrong value here. So you want to mask it as you do just above.

Furthermore, as other part of the Xen ARM you rely on the page size of 
Xen to always be 4KB. This is not really true and this code will break 
as soon as we introduce 16KB/64KB page granularity support in Xen. I 
will have a look on what to do here. No need to worry about that for now.

> +
> +    /*
> +     * Set permissions so that the caller can check the flags by herself. Note
> +     * that stage 1 translations also inherit attributes from the tables
> +     * (ARM DDI 0487B.a J1-5928).
> +     */
> +    if ( !pte.pt.ro && !ro_table )
> +        *perms |= GV2M_WRITE;
> +    if ( !pte.pt.xn && !xn_table )
> +        *perms |= GV2M_EXEC;
> +
> +    return 0;
>  }
>
>  int guest_walk_tables(const struct vcpu *v, vaddr_t gva,
>

Cheers,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-07-17 16:18 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-06 11:50 [PATCH v6 00/14] arm/mem_access: Walk guest page tables in SW if mem_access is active Sergej Proskurin
2017-07-06 11:50 ` [PATCH v6 01/14] arm/mem_access: Add and cleanup (TCR_|TTBCR_)* defines Sergej Proskurin
2017-07-06 11:50 ` [PATCH v6 02/14] arm/mem_access: Move PAGE_*_* macros to xen/page-defs.h Sergej Proskurin
2017-07-06 12:10   ` Jan Beulich
2017-07-06 14:53     ` Sergej Proskurin
2017-07-06 15:24       ` Jan Beulich
2017-07-06 15:34         ` Sergej Proskurin
2017-07-06 16:20           ` Jan Beulich
2017-07-07  8:27             ` Sergej Proskurin
2017-07-06 11:50 ` [PATCH v6 03/14] arm/mem_access: Add defines supporting PTs with varying page sizes Sergej Proskurin
2017-07-17 14:12   ` Julien Grall
2017-07-06 11:50 ` [PATCH v6 04/14] arm/lpae: Introduce lpae_is_page helper Sergej Proskurin
2017-07-06 11:50 ` [PATCH v6 05/14] arm/mem_access: Add short-descriptor pte typedefs and macros Sergej Proskurin
2017-07-06 11:50 ` [PATCH v6 06/14] arm/mem_access: Introduce GV2M_EXEC permission Sergej Proskurin
2017-07-06 11:50 ` [PATCH v6 07/14] arm/mem_access: Introduce BIT_ULL bit operation Sergej Proskurin
2017-07-06 11:50 ` [PATCH v6 08/14] arm/mem_access: Introduce GENMASK_ULL " Sergej Proskurin
2017-07-06 12:18   ` Jan Beulich
2017-07-06 14:38     ` Sergej Proskurin
2017-07-06 15:22       ` Jan Beulich
2017-07-06 15:34         ` Sergej Proskurin
2017-07-06 11:50 ` [PATCH v6 09/14] arm/guest_access: Move vgic_access_guest_memory to guest_access.h Sergej Proskurin
2017-07-17 15:38   ` Julien Grall
2017-07-18  9:49     ` Sergej Proskurin
2017-07-18 10:43       ` Julien Grall
2017-07-18 11:59         ` Sergej Proskurin
2017-07-18 12:12           ` Julien Grall
2017-07-18 12:20             ` Sergej Proskurin
2017-07-06 11:50 ` [PATCH v6 10/14] arm/guest_access: Rename vgic_access_guest_memory Sergej Proskurin
2017-07-17 15:43   ` Julien Grall
2017-07-18  8:42     ` Sergej Proskurin
2017-07-18 10:28       ` Julien Grall
2017-07-06 11:50 ` [PATCH v6 11/14] arm/mem_access: Add software guest-page-table walk Sergej Proskurin
2017-07-17 15:47   ` Julien Grall
2017-07-06 11:50 ` [PATCH v6 12/14] arm/mem_access: Add long-descriptor based gpt Sergej Proskurin
2017-07-17 16:18   ` Julien Grall [this message]
2017-07-06 11:50 ` [PATCH v6 13/14] arm/mem_access: Add short-descriptor " Sergej Proskurin
2017-07-17 16:26   ` Julien Grall
2017-07-06 11:50 ` [PATCH v6 14/14] arm/mem_access: Walk the guest's pt in software Sergej Proskurin

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=c77ab1d7-6c4c-cfdb-be3d-888d530a794e@arm.com \
    --to=julien.grall@arm.com \
    --cc=proskurin@sec.in.tum.de \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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).