|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [RFC PATCH v6 15/43] arm/p2m: Allocate hostp2m with xzalloc
This commit replaces the concrete p2m_domain member in arch_domain with a
pointer to p2m_domain, which is allocated with xzalloc during p2m
initialization.
In the following commits, the altp2m_init and altp2m_teardown routines from
x86 are be moved to common code. These routines (respectively) allocate and
free the p2m_domain structs for altp2m views.
While it would be possible to have special code paths for
allocating/freeing altp2m views while keeping the hostp2m as an concrete
member, this results in code duplication and increases complexity without
any clear benefit. Therefore, switching the hostp2m to be allocated
separately from arch_domain (similarly to x86) makes it possible to use the
same functions for both allocation/teardown/freeing of the hostp2m and
altp2m views.
This is commit 4/12 of the altp2m_init/altp2m_teardown routines phase.
Signed-off-by: Rose Spangler <Rose.Spangler@xxxxxxxxxxxxxx>
---
v6: Introduced this patch.
---
xen/arch/arm/domain.c | 2 +-
xen/arch/arm/include/asm/domain.h | 2 +-
xen/arch/arm/include/asm/p2m.h | 2 +-
xen/arch/arm/mm.c | 2 +-
xen/arch/arm/mmu/p2m.c | 27 +++++++++++++++++++++---
xen/arch/arm/traps.c | 2 +-
xen/drivers/passthrough/arm/ipmmu-vmsa.c | 2 +-
xen/drivers/passthrough/arm/smmu-v3.c | 2 +-
xen/drivers/passthrough/arm/smmu.c | 2 +-
9 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 26380a807cad..be824a5ba18d 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -1099,7 +1099,7 @@ int domain_relinquish_resources(struct domain *d)
* We are about to free the intermediate page-tables, so clear the
* root to prevent any walk to use them.
*/
- p2m_clear_root_pages(&d->arch.p2m);
+ p2m_clear_root_pages(d->arch.p2m);
PROGRESS(p2m):
ret = p2m_teardown(d);
diff --git a/xen/arch/arm/include/asm/domain.h
b/xen/arch/arm/include/asm/domain.h
index ffe5d0d9f0a6..576dbdec20af 100644
--- a/xen/arch/arm/include/asm/domain.h
+++ b/xen/arch/arm/include/asm/domain.h
@@ -72,7 +72,7 @@ struct arch_domain
#endif
/* Virtual MMU */
- struct p2m_domain p2m;
+ struct p2m_domain *p2m;
struct hvm_domain hvm;
diff --git a/xen/arch/arm/include/asm/p2m.h b/xen/arch/arm/include/asm/p2m.h
index 010ce8c9ebbd..23df91ea13e9 100644
--- a/xen/arch/arm/include/asm/p2m.h
+++ b/xen/arch/arm/include/asm/p2m.h
@@ -410,7 +410,7 @@ static inline int get_page_and_type(struct page_info *page,
}
/* get host p2m table */
-#define p2m_get_hostp2m(d) (&(d)->arch.p2m)
+#define p2m_get_hostp2m(d) ((d)->arch.p2m)
static inline bool p2m_vm_event_sanity_check(struct domain *d)
{
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 6df8b616e464..46f9363ea851 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -116,7 +116,7 @@ bool page_is_offlinable(mfn_t mfn)
unsigned long domain_get_maximum_gpfn(struct domain *d)
{
- return gfn_x(d->arch.p2m.max_mapped_gfn);
+ return gfn_x(d->arch.p2m->max_mapped_gfn);
}
void share_xen_page_with_guest(struct page_info *page, struct domain *d,
diff --git a/xen/arch/arm/mmu/p2m.c b/xen/arch/arm/mmu/p2m.c
index 51abf3504fcf..3ecb969a0369 100644
--- a/xen/arch/arm/mmu/p2m.c
+++ b/xen/arch/arm/mmu/p2m.c
@@ -5,6 +5,7 @@
#include <xen/lib.h>
#include <xen/sched.h>
#include <xen/softirq.h>
+#include <xen/xmalloc.h>
#include <asm/alternative.h>
#include <asm/event.h>
@@ -1475,7 +1476,7 @@ void p2m_final_teardown(struct domain *d)
/* p2m not actually initialized */
if ( !p2m->domain )
- return;
+ goto free_p2m;
/*
* No need to call relinquish_p2m_mapping() here because
@@ -1499,11 +1500,13 @@ void p2m_final_teardown(struct domain *d)
radix_tree_destroy(&p2m->mem_access_settings, NULL);
p2m->domain = NULL;
+
+free_p2m:
+ xfree(p2m);
}
-int p2m_init(struct domain *d)
+static int p2m_initialise(struct domain *d, struct p2m_domain *p2m)
{
- struct p2m_domain *p2m = p2m_get_hostp2m(d);
int rc;
unsigned int cpu;
@@ -1556,6 +1559,24 @@ int p2m_init(struct domain *d)
return 0;
}
+int p2m_init(struct domain *d)
+{
+ struct p2m_domain *p2m = xzalloc(struct p2m_domain);
+ int rc;
+
+ if ( !p2m )
+ return -ENOMEM;
+
+ rc = p2m_initialise(d, p2m);
+
+ if ( !rc )
+ d->arch.p2m = p2m;
+ else
+ xfree(p2m);
+
+ return rc;
+}
+
/*
* The function will go through the p2m and remove page reference when it
* is required. The mapping will be removed from the p2m.
diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
index 0c01f37ad6b4..637d27659b20 100644
--- a/xen/arch/arm/traps.c
+++ b/xen/arch/arm/traps.c
@@ -984,7 +984,7 @@ void vcpu_show_registers(struct vcpu *v)
#endif
#ifdef CONFIG_MMU
- ctxt.vttbr_el2 = v->domain->arch.p2m.vttbr;
+ ctxt.vttbr_el2 = v->domain->arch.p2m->vttbr;
#endif
_show_registers(&v->arch.cpu_info->guest_cpu_user_regs, &ctxt, 1, v);
diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c
b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
index fa9ab9cb1330..d246c5e59005 100644
--- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c
+++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
@@ -565,7 +565,7 @@ static int ipmmu_domain_init_context(struct
ipmmu_vmsa_domain *domain)
* Use P2M table for this Xen domain.
*/
ASSERT(domain->d != NULL);
- ttbr = page_to_maddr(domain->d->arch.p2m.root);
+ ttbr = page_to_maddr(domain->d->arch.p2m->root);
dev_info(domain->mmu->root->dev, "%pd: Set IPMMU context %u (pgd
0x%"PRIx64")\n",
domain->d, domain->context_id, ttbr);
diff --git a/xen/drivers/passthrough/arm/smmu-v3.c
b/xen/drivers/passthrough/arm/smmu-v3.c
index bf153227dbd9..a7fbe58cba77 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -1205,7 +1205,7 @@ static int arm_smmu_domain_finalise_s2(struct
arm_smmu_domain *smmu_domain,
vtcr->tsz = 64 - p2m_ipa_bits;
vtcr->sl = 2 - P2M_ROOT_LEVEL;
- arm_lpae_s2_cfg.vttbr = page_to_maddr(smmu_domain->d->arch.p2m.root);
+ arm_lpae_s2_cfg.vttbr = page_to_maddr(smmu_domain->d->arch.p2m->root);
vmid = arm_smmu_bitmap_alloc(smmu->vmid_map, smmu->vmid_bits);
if (vmid < 0)
diff --git a/xen/drivers/passthrough/arm/smmu.c
b/xen/drivers/passthrough/arm/smmu.c
index d63c9015510e..0975be2562bb 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -1247,7 +1247,7 @@ static void arm_smmu_init_context_bank(struct
arm_smmu_domain *smmu_domain)
/* TTBR0 */
/* Xen: The page table is shared with the P2M code */
ASSERT(smmu_domain->cfg.domain != NULL);
- p2maddr = page_to_maddr(smmu_domain->cfg.domain->arch.p2m.root);
+ p2maddr = page_to_maddr(smmu_domain->cfg.domain->arch.p2m->root);
dev_notice(smmu->dev, "d%u: p2maddr 0x%"PRIpaddr"\n",
smmu_domain->cfg.domain->domain_id, p2maddr);
--
2.34.1
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |