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 04/18] arm/altp2m: Add altp2m init/teardown routines.
Date: Mon, 4 Jul 2016 16:17:17 +0100 [thread overview]
Message-ID: <577A7DFD.2070600@arm.com> (raw)
In-Reply-To: <20160704114605.10086-5-proskurin@sec.in.tum.de>
Hello Sergej,
On 04/07/16 12:45, Sergej Proskurin wrote:
> The p2m intialization now invokes intialization routines responsible for
s/intialization/initialization/
> the allocation and intitialization of altp2m structures. The same
Ditto
> applies to teardown routines. The functionality has been adopted from
> the x86 altp2m implementation.
This patch would benefit to be split in 2:
1) Moving p2m init/teardown in a separate function
2) Introducing altp2m init/teardown
It will ease the review.
> Signed-off-by: Sergej Proskurin <proskurin@sec.in.tum.de>
> ---
> Cc: Stefano Stabellini <sstabellini@kernel.org>
> Cc: Julien Grall <julien.grall@arm.com>
> ---
> xen/arch/arm/p2m.c | 166 ++++++++++++++++++++++++++++++++++++++++--
> xen/include/asm-arm/domain.h | 6 ++
> xen/include/asm-arm/hvm/hvm.h | 12 +++
> xen/include/asm-arm/p2m.h | 20 +++++
> 4 files changed, 198 insertions(+), 6 deletions(-)
>
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index aa4e774..e72ca7a 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -1400,19 +1400,103 @@ static void p2m_free_vmid(struct domain *d)
> spin_unlock(&vmid_alloc_lock);
> }
>
> -void p2m_teardown(struct domain *d)
> +static int p2m_initialise(struct domain *d, struct p2m_domain *p2m)
AFAICT, this function is only used by p2m_initialise_one. So I would
prefer if you fold the code in the latter.
> {
> - struct p2m_domain *p2m = &d->arch.p2m;
> + int ret = 0;
> +
> + spin_lock_init(&p2m->lock);
> + INIT_PAGE_LIST_HEAD(&p2m->pages);
> +
> + spin_lock(&p2m->lock);
> +
> + p2m->domain = d;
> + p2m->access_required = false;
> + p2m->mem_access_enabled = false;
> + p2m->default_access = p2m_access_rwx;
> + p2m->p2m_class = p2m_host;
> + p2m->root = NULL;
> +
> + /* Adopt VMID of the associated domain */
> + p2m->vmid = d->arch.p2m.vmid;
It looks like to me that re-using the same VMID will require more TLB
flush (such as when a VCPU is migrated to another physical CPU). So
could you explain why you decided to re-use the same VMID?
> + p2m->vttbr.vttbr = 0;
> + p2m->vttbr.vttbr_vmid = p2m->vmid;
> +
> + p2m->max_mapped_gfn = 0;
> + p2m->lowest_mapped_gfn = ULONG_MAX;
> + radix_tree_init(&p2m->mem_access_settings);
> +
> + spin_unlock(&p2m->lock);
> +
> + return ret;
> +}
> +
> +static void p2m_free_one(struct p2m_domain *p2m)
> +{
> + mfn_t mfn;
> + unsigned int i;
> struct page_info *pg;
>
> spin_lock(&p2m->lock);
>
> while ( (pg = page_list_remove_head(&p2m->pages)) )
> - free_domheap_page(pg);
> + if ( pg != p2m->root )
> + free_domheap_page(pg);
> +
> + for ( i = 0; i < P2M_ROOT_PAGES; i++ )
> + {
> + mfn = _mfn(page_to_mfn(p2m->root) + i);
> + clear_domain_page(mfn);
> + }
> + free_domheap_pages(p2m->root, P2M_ROOT_ORDER);
> + p2m->root = NULL;
> +
> + radix_tree_destroy(&p2m->mem_access_settings, NULL);
> +
> + spin_unlock(&p2m->lock);
> +
> + xfree(p2m);
> +}
> +
> +static struct p2m_domain *p2m_init_one(struct domain *d)
> +{
> + struct p2m_domain *p2m = xzalloc(struct p2m_domain);
> +
> + if ( !p2m )
> + return NULL;
> +
> + if ( p2m_initialise(d, p2m) )
> + goto free_p2m;
> +
> + return p2m;
> +
> +free_p2m:
> + xfree(p2m);
> + return NULL;
> +}
> +
> +static void p2m_teardown_hostp2m(struct domain *d)
Why does p2m_teardown_hostp2m not use p2m_teardown_one to teardown the
p2m? Assuming xfree(p2m) is move out of the function.
> +{
> + struct p2m_domain *p2m = p2m_get_hostp2m(d);
> + struct page_info *pg = NULL;
> + mfn_t mfn;
> + unsigned int i;
> +
> + spin_lock(&p2m->lock);
>
> - if ( p2m->root )
Why did you remove this check? The p2m->root could be NULL if the an
error occurred before create the root page table.
> - free_domheap_pages(p2m->root, P2M_ROOT_ORDER);
> + while ( (pg = page_list_remove_head(&p2m->pages)) )
> + if ( pg != p2m->root )
Why this check? p2m->root will never be part of p2m->pages.
> + {
> + mfn = _mfn(page_to_mfn(pg));
> + clear_domain_page(mfn);
> + free_domheap_page(pg);
> + }
>
> + for ( i = 0; i < P2M_ROOT_PAGES; i++ )
> + {
> + mfn = _mfn(page_to_mfn(p2m->root) + i);
> + clear_domain_page(mfn);
> + }
> + free_domheap_pages(p2m->root, P2M_ROOT_ORDER);
> p2m->root = NULL;
>
> p2m_free_vmid(d);
> @@ -1422,7 +1506,7 @@ void p2m_teardown(struct domain *d)
> spin_unlock(&p2m->lock);
> }
>
> -int p2m_init(struct domain *d)
> +static int p2m_init_hostp2m(struct domain *d)
Why does p2m_init_hostp2m not use p2m_init_one to initialize the p2m?
> {
> struct p2m_domain *p2m = &d->arch.p2m;
> int rc = 0;
> @@ -1437,6 +1521,8 @@ int p2m_init(struct domain *d)
> if ( rc != 0 )
> goto err;
>
> + p2m->vttbr.vttbr_vmid = p2m->vmid;
> +
> d->arch.vttbr = 0;
>
> p2m->root = NULL;
> @@ -1454,6 +1540,74 @@ err:
> return rc;
> }
>
> +static void p2m_teardown_altp2m(struct domain *d)
> +{
> + unsigned int i;
> + struct p2m_domain *p2m;
> +
> + for ( i = 0; i < MAX_ALTP2M; i++ )
> + {
> + if ( !d->arch.altp2m_p2m[i] )
> + continue;
> +
> + p2m = d->arch.altp2m_p2m[i];
> + p2m_free_one(p2m);
> + d->arch.altp2m_vttbr[i] = INVALID_MFN;
> + d->arch.altp2m_p2m[i] = NULL;
These 2 lines are not necessary because the domain is destroyed and the
memory associated will be free very soon.
> + }
> +
> + d->arch.altp2m_active = false;
> +}
> +
> +static int p2m_init_altp2m(struct domain *d)
> +{
> + unsigned int i;
> + struct p2m_domain *p2m;
> +
> + spin_lock_init(&d->arch.altp2m_lock);
> + for ( i = 0; i < MAX_ALTP2M; i++ )
> + {
> + d->arch.altp2m_vttbr[i] = INVALID_MFN;
The VTTBR will be stored in altp2m_p2m[i].vttbr. So why do you need to
store in a different way?
Also, please don't mix value that have different meaning. MFN_INVALID
indicates that a MFN is invalid not the VTTBR.
> + d->arch.altp2m_p2m[i] = p2m = p2m_init_one(d);
> + if ( p2m == NULL )
> + {
> + p2m_teardown_altp2m(d);
This call is not necessary. p2m_teardown_altp2m will be called by
p2m_teardown as part of arch_domain_destroy.
> + return -ENOMEM;
> + }
> + p2m->p2m_class = p2m_alternate;
> + p2m->access_required = 1;
> + _atomic_set(&p2m->active_vcpus, 0);
> + }
> +
> + return 0;
> +}
> +
> +void p2m_teardown(struct domain *d)
> +{
> + /*
> + * We must teardown altp2m unconditionally because
> + * we initialise it unconditionally.
Why do we need to initialize altp2m unconditionally? When altp2m is not
used we will allocate memory that is never used.
I would prefer to see the allocation of the memory only if the domain
will make use of altp2m.
> + */
> + p2m_teardown_altp2m(d);
> +
> + p2m_teardown_hostp2m(d);
> +}
> +
> +int p2m_init(struct domain *d)
> +{
> + int rc = 0;
> +
> + rc = p2m_init_hostp2m(d);
> + if ( rc )
> + return rc;
> +
> + rc = p2m_init_altp2m(d);
> + if ( rc )
> + p2m_teardown_hostp2m(d);
This call is not necessary.
> +
> + return rc;
> +}
> +
> int relinquish_p2m_mapping(struct domain *d)
> {
> struct p2m_domain *p2m = &d->arch.p2m;
> diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h
> index 2039f16..6b9770f 100644
> --- a/xen/include/asm-arm/domain.h
> +++ b/xen/include/asm-arm/domain.h
> @@ -29,6 +29,9 @@ enum domain_type {
> #define is_64bit_domain(d) (0)
> #endif
>
> +#define MAX_ALTP2M 10 /* arbitrary */
> +#define INVALID_ALTP2M 0xffff
IMHO, this should either be part of p2m.h or altp2m.h
> +
> extern int dom0_11_mapping;
> #define is_domain_direct_mapped(d) ((d) == hardware_domain && dom0_11_mapping)
>
> @@ -130,6 +133,9 @@ struct arch_domain
>
> /* altp2m: allow multiple copies of host p2m */
> bool_t altp2m_active;
> + struct p2m_domain *altp2m_p2m[MAX_ALTP2M];
> + spinlock_t altp2m_lock;
Please document was the lock is protecting.
> + uint64_t altp2m_vttbr[MAX_ALTP2M];
> } __cacheline_aligned;
>
> struct arch_vcpu
> diff --git a/xen/include/asm-arm/hvm/hvm.h b/xen/include/asm-arm/hvm/hvm.h
> index 96c455c..28d5298 100644
> --- a/xen/include/asm-arm/hvm/hvm.h
> +++ b/xen/include/asm-arm/hvm/hvm.h
> @@ -19,6 +19,18 @@
> #ifndef __ASM_ARM_HVM_HVM_H__
> #define __ASM_ARM_HVM_HVM_H__
>
> +struct vttbr_data {
This structure should not be part of hvm.h but processor.h. Also, I
would rename it to simply vttbr.
> + union {
> + struct {
> + u64 vttbr_baddr :40, /* variable res0: from 0-(x-1) bit */
Please drop vttbr_. Also, this field is 48 bits for ARMv8 (see ARM
D7.2.102 in DDI 0487A.j).
> + res1 :8,
> + vttbr_vmid :8,
Please drop vttbr_.
> + res2 :8;
> + };
> + u64 vttbr;
> + };
> +};
> +
> struct hvm_function_table {
> char *name;
>
> diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
> index 0d1e61e..a78d547 100644
> --- a/xen/include/asm-arm/p2m.h
> +++ b/xen/include/asm-arm/p2m.h
> @@ -8,6 +8,9 @@
> #include <xen/p2m-common.h>
> #include <public/memory.h>
>
> +#include <asm/atomic.h>
> +#include <asm/hvm/hvm.h>
ARM has not concept of HVM nor PV. So I would prefer to see a very
limited usage of hvm.h
> +
> #define paddr_bits PADDR_BITS
>
> /* Holds the bit size of IPAs in p2m tables. */
> @@ -17,6 +20,11 @@ struct domain;
>
> extern void memory_type_changed(struct domain *);
>
> +typedef enum {
> + p2m_host,
> + p2m_alternate,
> +} p2m_class_t;
> +
> /* Per-p2m-table state */
> struct p2m_domain {
> /* Lock that protects updates to the p2m */
> @@ -66,6 +74,18 @@ struct p2m_domain {
> /* Radix tree to store the p2m_access_t settings as the pte's don't have
> * enough available bits to store this information. */
> struct radix_tree_root mem_access_settings;
> +
> + /* Alternate p2m: count of vcpu's currently using this p2m. */
> + atomic_t active_vcpus;
> +
> + /* Choose between: host/alternate */
> + p2m_class_t p2m_class;
Is there any reason to have this field? It is set but never used.
> +
> + /* Back pointer to domain */
> + struct domain *domain;
AFAICT, the only usage of this field is in p2m_altp2m_lazy_copy where
you have direct access to the domain. So this could be dropped.
> +
> + /* VTTBR information */
> + struct vttbr_data vttbr;
> };
>
> /* List of possible type for each page in the p2m entry.
>
Regards,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-07-04 15:17 UTC|newest]
Thread overview: 126+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-04 11:45 [PATCH 00/18] arm/altp2m: Introducing altp2m to ARM Sergej Proskurin
2016-07-04 11:45 ` [PATCH 01/18] arm/altp2m: Add cmd-line support for altp2m on ARM Sergej Proskurin
2016-07-04 12:15 ` Andrew Cooper
2016-07-04 13:02 ` Sergej Proskurin
2016-07-04 13:25 ` Julien Grall
2016-07-04 13:43 ` Sergej Proskurin
2016-07-04 17:42 ` Julien Grall
2016-07-04 17:56 ` Tamas K Lengyel
2016-07-04 21:08 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 02/18] arm/altp2m: Add first altp2m HVMOP stubs Sergej Proskurin
2016-07-04 13:36 ` Julien Grall
2016-07-04 13:51 ` Sergej Proskurin
2016-07-05 10:19 ` Julien Grall
2016-07-06 9:14 ` Sergej Proskurin
2016-07-06 13:43 ` Julien Grall
2016-07-06 15:23 ` Tamas K Lengyel
2016-07-06 15:54 ` Julien Grall
2016-07-06 16:05 ` Tamas K Lengyel
2016-07-06 16:29 ` Julien Grall
2016-07-06 16:35 ` Tamas K Lengyel
2016-07-06 18:35 ` Julien Grall
2016-07-07 9:14 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 03/18] arm/altp2m: Add HVMOP_altp2m_get_domain_state Sergej Proskurin
2016-07-04 11:45 ` [PATCH 04/18] arm/altp2m: Add altp2m init/teardown routines Sergej Proskurin
2016-07-04 15:17 ` Julien Grall [this message]
2016-07-04 16:40 ` Sergej Proskurin
2016-07-04 16:43 ` Andrew Cooper
2016-07-04 16:56 ` Sergej Proskurin
2016-07-04 17:44 ` Julien Grall
2016-07-04 21:19 ` Sergej Proskurin
2016-07-04 21:35 ` Julien Grall
2016-07-04 21:46 ` Sergej Proskurin
2016-07-04 18:18 ` Julien Grall
2016-07-04 21:37 ` Sergej Proskurin
2016-07-04 18:30 ` Julien Grall
2016-07-04 21:56 ` Sergej Proskurin
2016-07-04 16:15 ` Julien Grall
2016-07-04 16:51 ` Sergej Proskurin
2016-07-04 18:34 ` Julien Grall
2016-07-05 7:45 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 05/18] arm/altp2m: Add HVMOP_altp2m_set_domain_state Sergej Proskurin
2016-07-04 15:39 ` Julien Grall
2016-07-05 8:45 ` Sergej Proskurin
2016-07-05 10:11 ` Julien Grall
2016-07-05 12:05 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 06/18] arm/altp2m: Add a(p2m) table flushing routines Sergej Proskurin
2016-07-04 12:12 ` Sergej Proskurin
2016-07-04 15:42 ` Julien Grall
2016-07-05 8:52 ` Sergej Proskurin
2016-07-04 15:55 ` Julien Grall
2016-07-05 9:51 ` Sergej Proskurin
2016-07-04 16:20 ` Julien Grall
2016-07-05 9:57 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 07/18] arm/altp2m: Add HVMOP_altp2m_create_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 08/18] arm/altp2m: Add HVMOP_altp2m_destroy_p2m Sergej Proskurin
2016-07-04 16:32 ` Julien Grall
2016-07-05 11:37 ` Sergej Proskurin
2016-07-05 11:48 ` Julien Grall
2016-07-05 12:18 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 09/18] arm/altp2m: Add HVMOP_altp2m_switch_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 10/18] arm/altp2m: Renamed and extended p2m_alloc_table Sergej Proskurin
2016-07-04 18:43 ` Julien Grall
2016-07-05 13:56 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 11/18] arm/altp2m: Make flush_tlb_domain ready for altp2m Sergej Proskurin
2016-07-04 12:30 ` Sergej Proskurin
2016-07-04 20:32 ` Julien Grall
2016-07-05 14:48 ` Sergej Proskurin
2016-07-05 15:37 ` Julien Grall
2016-07-05 20:21 ` Sergej Proskurin
2016-07-06 14:28 ` Julien Grall
2016-07-06 14:39 ` Sergej Proskurin
2016-07-07 17:24 ` Julien Grall
2016-07-04 11:45 ` [PATCH 12/18] arm/altp2m: Cosmetic fixes - function prototypes Sergej Proskurin
2016-07-15 13:45 ` Julien Grall
2016-07-16 15:18 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 13/18] arm/altp2m: Make get_page_from_gva ready for altp2m Sergej Proskurin
2016-07-04 20:34 ` Julien Grall
2016-07-05 20:31 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 14/18] arm/altp2m: Add HVMOP_altp2m_set_mem_access Sergej Proskurin
2016-07-05 12:49 ` Julien Grall
2016-07-05 21:55 ` Sergej Proskurin
2016-07-06 14:32 ` Julien Grall
2016-07-06 16:12 ` Tamas K Lengyel
2016-07-06 16:59 ` Julien Grall
2016-07-06 17:03 ` Sergej Proskurin
2016-07-06 17:08 ` Julien Grall
2016-07-07 9:16 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 15/18] arm/altp2m: Add altp2m paging mechanism Sergej Proskurin
2016-07-04 20:53 ` Julien Grall
2016-07-06 8:33 ` Sergej Proskurin
2016-07-06 14:26 ` Julien Grall
2016-07-04 11:45 ` [PATCH 16/18] arm/altp2m: Extended libxl to activate altp2m on ARM Sergej Proskurin
2016-07-07 16:27 ` Wei Liu
2016-07-24 16:06 ` Sergej Proskurin
2016-07-25 8:32 ` Wei Liu
2016-07-25 9:04 ` Sergej Proskurin
2016-07-25 9:49 ` Julien Grall
2016-07-25 10:08 ` Wei Liu
2016-07-25 11:26 ` Sergej Proskurin
2016-07-25 11:37 ` Wei Liu
2016-07-04 11:45 ` [PATCH 17/18] arm/altp2m: Adjust debug information to altp2m Sergej Proskurin
2016-07-04 20:58 ` Julien Grall
2016-07-06 8:41 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 18/18] arm/altp2m: Extend xen-access for altp2m on ARM Sergej Proskurin
2016-07-04 13:38 ` Razvan Cojocaru
2016-07-06 8:44 ` Sergej Proskurin
2016-07-04 11:45 ` [PATCH 01/18] arm/altp2m: Add cmd-line support " Sergej Proskurin
2016-07-04 11:45 ` [PATCH 02/18] arm/altp2m: Add first altp2m HVMOP stubs Sergej Proskurin
2016-07-04 11:45 ` [PATCH 03/18] arm/altp2m: Add HVMOP_altp2m_get_domain_state Sergej Proskurin
2016-07-04 11:45 ` [PATCH 04/18] arm/altp2m: Add altp2m init/teardown routines Sergej Proskurin
2016-07-04 11:45 ` [PATCH 05/18] arm/altp2m: Add HVMOP_altp2m_set_domain_state Sergej Proskurin
2016-07-04 11:45 ` [PATCH 06/18] arm/altp2m: Add a(p2m) table flushing routines Sergej Proskurin
2016-07-04 11:45 ` [PATCH 07/18] arm/altp2m: Add HVMOP_altp2m_create_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 08/18] arm/altp2m: Add HVMOP_altp2m_destroy_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 09/18] arm/altp2m: Add HVMOP_altp2m_switch_p2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 10/18] arm/altp2m: Renamed and extended p2m_alloc_table Sergej Proskurin
2016-07-04 11:45 ` [PATCH 11/18] arm/altp2m: Make flush_tlb_domain ready for altp2m Sergej Proskurin
2016-07-04 11:45 ` [PATCH 12/18] arm/altp2m: Cosmetic fixes - function prototypes Sergej Proskurin
2016-07-04 11:46 ` [PATCH 13/18] arm/altp2m: Make get_page_from_gva ready for altp2m Sergej Proskurin
2016-07-04 11:46 ` [PATCH 14/18] arm/altp2m: Add HVMOP_altp2m_set_mem_access Sergej Proskurin
2016-07-04 11:46 ` [PATCH 15/18] arm/altp2m: Add altp2m paging mechanism Sergej Proskurin
2016-07-04 11:46 ` [PATCH 16/18] arm/altp2m: Extended libxl to activate altp2m on ARM Sergej Proskurin
2016-07-04 11:46 ` [PATCH 17/18] arm/altp2m: Adjust debug information to altp2m Sergej Proskurin
2016-07-04 11:46 ` [PATCH 18/18] arm/altp2m: Extend xen-access for altp2m on ARM Sergej Proskurin
2016-07-04 12:52 ` [PATCH 00/18] arm/altp2m: Introducing altp2m to ARM Andrew Cooper
2016-07-04 13:05 ` 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=577A7DFD.2070600@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).