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 v3 24/38] arm/p2m: Make p2m_mem_access_check ready for altp2m
Date: Mon, 12 Sep 2016 10:02:25 +0100	[thread overview]
Message-ID: <cbbb8582-af91-31a1-acb1-ee458dde2bc4@arm.com> (raw)
In-Reply-To: <20160816221714.22041-25-proskurin@sec.in.tum.de>

Hello Sergej,

On 16/08/2016 23:17, Sergej Proskurin wrote:
> This commit extends the function "p2m_mem_access_check" and
> "p2m_mem_access_check_and_get_page" to consider altp2m. The function
> "p2m_mem_access_check_and_get_page" needs to translate the gva upon the
> hostp2m's vttbr, as it contains all valid mappings while the currently
> active altp2m view might not have the required gva mapping yet.
>
> Also, the new implementation fills the request buffer to hold
> altp2m-related information.
>
> Signed-off-by: Sergej Proskurin <proskurin@sec.in.tum.de>
> ---
> Cc: Stefano Stabellini <sstabellini@kernel.org>
> Cc: Julien Grall <julien.grall@arm.com>
> ---
> v3: Extended the function "p2m_mem_access_check_and_get_page" to
>     consider altp2m. Similar to "get_page_from_gva", the function
>     "p2m_mem_access_check_and_get_page" needs to translate the gva upon
>     the hostp2m's vttbr. Although, the function "gva_to_ipa" (called in
>     "p2m_mem_access_check_and_get_page") performs a stage 1 table walk,
>     it will access page tables residing in memory. Accesses to this
>     memory are controlled by the underlying 2nd stage translation table
>     and hence require the original mappings of the hostp2m.
> ---
>  xen/arch/arm/p2m.c | 43 +++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 39 insertions(+), 4 deletions(-)
>
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index 5819ae0..ed9e0f0 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -14,6 +14,7 @@
>  #include <asm/hardirq.h>
>  #include <asm/page.h>
>
> +#include <asm/vm_event.h>
>  #include <asm/altp2m.h>
>
>  #ifdef CONFIG_ARM_64
> @@ -1479,9 +1480,32 @@ p2m_mem_access_check_and_get_page(struct vcpu *v, vaddr_t gva, unsigned long fla
>      xenmem_access_t xma;
>      p2m_type_t t;
>      struct page_info *page = NULL;
> -    struct p2m_domain *p2m = p2m_get_hostp2m(v->domain);
> +    struct domain *d = v->domain;
> +    struct p2m_domain *p2m = p2m_get_hostp2m(d);
> +
> +    /*
> +     * If altp2m is active, we need to translate the gva upon the hostp2m's
> +     * vttbr, as it contains all valid mappings while the currently active
> +     * altp2m view might not have the required gva mapping yet. Although, the
> +     * function gva_to_ipa performs a stage 1 table walk, it will access page
> +     * tables residing in memory. Accesses to this memory are controlled by the
> +     * underlying 2nd stage translation table and hence require the original
> +     * mappings of the hostp2m.

As I already mentioned a few times now, this function is broken and 
needs to be fixed before anymore change in it.

The underlying memory of stage-1 page table may have been restricted and 
therefore hardware page table walk (gva_to_ipa) may fail.

> +     */
> +    if ( unlikely(altp2m_active(d)) )
> +    {
> +        unsigned long flags = 0;
> +        uint64_t ovttbr = READ_SYSREG64(VTTBR_EL2);
> +
> +        p2m_switch_vttbr_and_get_flags(ovttbr, p2m->vttbr, flags);
> +
> +        rc = gva_to_ipa(gva, &ipa, flag);
> +
> +        p2m_restore_vttbr_and_set_flags(ovttbr, flags);
> +    }
> +    else
> +        rc = gva_to_ipa(gva, &ipa, flag);
>
> -    rc = gva_to_ipa(gva, &ipa, flag);
>      if ( rc < 0 )
>          goto err;
>
> @@ -1698,13 +1722,16 @@ bool_t p2m_mem_access_check(paddr_t gpa, vaddr_t gla, const struct npfec npfec)
>      xenmem_access_t xma;
>      vm_event_request_t *req;
>      struct vcpu *v = current;
> -    struct p2m_domain *p2m = p2m_get_hostp2m(v->domain);
> +    struct domain *d = v->domain;
> +    struct p2m_domain *p2m = p2m_get_active_p2m(v);
>
>      /* Mem_access is not in use. */
>      if ( !p2m->mem_access_enabled )
>          return true;
>
> -    rc = p2m_get_mem_access(v->domain, _gfn(paddr_to_pfn(gpa)), &xma);
> +    p2m_read_lock(p2m);
> +    rc = __p2m_get_mem_access(p2m, _gfn(paddr_to_pfn(gpa)), &xma);
> +    p2m_read_unlock(p2m);
>      if ( rc )
>          return true;
>
> @@ -1810,6 +1837,14 @@ bool_t p2m_mem_access_check(paddr_t gpa, vaddr_t gla, const struct npfec npfec)
>          req->u.mem_access.flags |= npfec.insn_fetch     ? MEM_ACCESS_X : 0;
>          req->vcpu_id = v->vcpu_id;
>
> +        vm_event_fill_regs(req);

I don't think this change belongs to this patch.

> +
> +        if ( unlikely(altp2m_active(d)) )
> +        {
> +            req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M;
> +            req->altp2m_idx = altp2m_vcpu(v).p2midx;
> +        }
> +
>          mem_access_send_req(v->domain, req);
>          xfree(req);
>      }
>

Regards,

-- 
Julien Grall

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

  reply	other threads:[~2016-09-12  9:02 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-16 22:16 [PATCH v3 00/38] arm/altp2m: Introducing altp2m to ARM Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 01/38] arm/p2m: Cosmetic fixes - apply p2m_get_hostp2m Sergej Proskurin
2016-09-01 15:46   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 02/38] arm/p2m: Expose p2m_*lock helpers Sergej Proskurin
2016-09-01 15:48   ` Julien Grall
2016-09-02 10:12     ` Sergej Proskurin
2016-09-02 10:15       ` Julien Grall
2016-09-02 10:29         ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 03/38] arm/p2m: Introduce p2m_(switch|restore)_vttbr_and_(g|s)et_flags Sergej Proskurin
2016-09-01 15:51   ` Julien Grall
2016-09-02  8:40     ` Sergej Proskurin
2016-09-02  9:57       ` Julien Grall
2016-09-02 10:15         ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 04/38] arm/p2m: Add first altp2m HVMOP stubs Sergej Proskurin
2016-09-01 16:09   ` Julien Grall
2016-09-02  9:26     ` Sergej Proskurin
2016-09-02 10:12       ` Julien Grall
2016-09-02 10:24         ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 05/38] arm/p2m: Add hvm_allow_(set|get)_param Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 06/38] arm/p2m: Add HVMOP_altp2m_get_domain_state Sergej Proskurin
2016-09-01 17:06   ` Julien Grall
2016-09-02  8:45     ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 07/38] arm/p2m: Introduce p2m_is_(hostp2m|altp2m) Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 08/38] arm/p2m: Free p2m entries only in the hostp2m Sergej Proskurin
2016-09-01 17:08   ` Julien Grall
2016-09-02  9:38     ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 09/38] arm/p2m: Add backpointer to the domain in p2m_domain Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 10/38] arm/p2m: Move hostp2m init/teardown to individual functions Sergej Proskurin
2016-09-01 17:36   ` Julien Grall
2016-09-02  9:09     ` Sergej Proskurin
2016-09-02 10:51       ` Julien Grall
2016-09-05 10:23         ` Sergej Proskurin
2016-09-09 16:44           ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 11/38] arm/p2m: Cosmetic fix - function prototype of p2m_alloc_table Sergej Proskurin
2016-09-09 16:45   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 12/38] arm/p2m: Rename parameter in p2m_alloc_vmid Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 13/38] arm/p2m: Change func prototype and impl of p2m_(alloc|free)_vmid Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 14/38] arm/p2m: Add altp2m init/teardown routines Sergej Proskurin
2016-09-09 16:56   ` Julien Grall
2016-09-13 19:35     ` Sergej Proskurin
2016-09-14  6:28       ` Sergej Proskurin
2016-09-14 10:53         ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 15/38] arm/p2m: Add altp2m table flushing routine Sergej Proskurin
2016-09-09 17:02   ` Julien Grall
2016-09-13  9:13     ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 16/38] arm/p2m: Add HVMOP_altp2m_set_domain_state Sergej Proskurin
2016-09-09 17:14   ` Julien Grall
2016-09-13  9:22     ` Sergej Proskurin
2016-09-14 11:07   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 17/38] arm/p2m: Add HVMOP_altp2m_create_p2m Sergej Proskurin
2016-09-12  8:38   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 18/38] arm/p2m: Add HVMOP_altp2m_destroy_p2m Sergej Proskurin
2016-09-12  8:41   ` Julien Grall
2016-09-13 12:43     ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 19/38] arm/p2m: Add HVMOP_altp2m_switch_p2m Sergej Proskurin
2016-09-12  8:47   ` Julien Grall
2016-09-13 13:00     ` Sergej Proskurin
2016-09-14 10:57       ` Julien Grall
2016-09-14 15:28         ` Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 20/38] arm/p2m: Add p2m_get_active_p2m macro Sergej Proskurin
2016-09-12  8:50   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 21/38] arm/p2m: Make p2m_restore_state ready for altp2m Sergej Proskurin
2016-09-12  8:51   ` Julien Grall
2016-08-16 22:16 ` [PATCH v3 22/38] arm/p2m: Make get_page_from_gva " Sergej Proskurin
2016-08-16 22:16 ` [PATCH v3 23/38] arm/p2m: Cosmetic fixes -- __p2m_get_mem_access Sergej Proskurin
2016-09-12  8:53   ` Julien Grall
2016-09-13 13:27     ` Sergej Proskurin
2016-09-13 13:30       ` Julien Grall
2016-09-13 13:42         ` Sergej Proskurin
2016-09-13 13:45           ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 24/38] arm/p2m: Make p2m_mem_access_check ready for altp2m Sergej Proskurin
2016-09-12  9:02   ` Julien Grall [this message]
2016-09-13 14:00     ` Sergej Proskurin
2016-09-13 14:20       ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 25/38] arm/p2m: Cosmetic fixes - function prototypes Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 26/38] arm/p2m: Introduce helpers managing altp2m entries Sergej Proskurin
2016-09-12  9:04   ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 27/38] arm/p2m: Introduce p2m_lookup_attr Sergej Proskurin
2016-09-12  9:15   ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 28/38] arm/p2m: Modify reference count only if hostp2m active Sergej Proskurin
2016-09-12  9:17   ` Julien Grall
2016-09-13 14:16     ` Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 29/38] arm/p2m: Add HVMOP_altp2m_set_mem_access Sergej Proskurin
2016-09-12 12:08   ` Julien Grall
2016-09-14 15:20     ` Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 30/38] arm/p2m: Add altp2m_propagate_change Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 31/38] altp2m: Introduce altp2m_switch_vcpu_altp2m_by_id Sergej Proskurin
2016-08-17 10:05   ` Jan Beulich
2016-08-17 12:37     ` Sergej Proskurin
2016-08-17 12:48       ` Julien Grall
2016-08-17 12:08   ` Razvan Cojocaru
2016-08-18 10:35   ` George Dunlap
2016-08-16 22:17 ` [PATCH v3 32/38] arm/p2m: Code movement in instr/data abort handlers Sergej Proskurin
2016-09-12 13:54   ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 33/38] arm/p2m: Add altp2m paging mechanism Sergej Proskurin
2016-09-12 14:18   ` Julien Grall
2016-09-13 15:06     ` Sergej Proskurin
2016-09-13 15:08       ` Julien Grall
2016-09-13 15:53         ` Sergej Proskurin
2016-09-14  7:53       ` Sergej Proskurin
2016-09-14 11:15         ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 34/38] arm/p2m: Add HVMOP_altp2m_change_gfn Sergej Proskurin
2016-09-12 14:27   ` Julien Grall
2016-08-16 22:17 ` [PATCH v3 35/38] arm/p2m: Adjust debug information to altp2m Sergej Proskurin
2016-09-12 14:29   ` Julien Grall
2016-09-13 15:13     ` Sergej Proskurin
2016-08-16 22:17 ` [PATCH v3 36/38] altp2m: Allow specifying external-only use-case Sergej Proskurin
2016-08-17 10:08   ` Jan Beulich
2016-08-17 14:47   ` Daniel De Graaf
2016-08-24 12:18   ` Wei Liu
2016-08-16 22:17 ` [PATCH v3 37/38] arm/p2m: Extend xen-access for altp2m on ARM Sergej Proskurin
2016-08-17 11:26   ` Razvan Cojocaru
2016-08-16 22:17 ` [PATCH v3 38/38] arm/p2m: Add test of xc_altp2m_change_gfn Sergej Proskurin
2016-08-17 12:06   ` Razvan Cojocaru
2016-08-24 12:27   ` Wei Liu
2016-09-13 15:45     ` 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=cbbb8582-af91-31a1-acb1-ee458dde2bc4@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).