Similarly to the previous commit, this commit moves altp2m_p2m to the
common domain struct. The representation of altp2m views as an array of
p2m_domain pointers is the same on x86 and ARM, and it seems that this
would be the case for other architectures as well.
This commit is a refactor, and no change in functionality is intended.
This is commit 3/8 of the preparation phase.
Signed-off-by: Rose Spangler <Rose.Spangler@elektrobit.com>
---
v6: Introduced this patch.
---
xen/arch/x86/hvm/vmx/vmx.c | 2 +-
xen/arch/x86/include/asm/domain.h | 1 -
xen/arch/x86/include/asm/p2m.h | 4 ++--
xen/arch/x86/mm/altp2m.c | 28 ++++++++++++++--------------
xen/arch/x86/mm/hap/hap.c | 6 +++---
xen/arch/x86/mm/mem_access.c | 8 ++++----
xen/arch/x86/mm/mem_sharing.c | 2 +-
xen/arch/x86/mm/p2m-ept.c | 6 +++---
xen/arch/x86/mm/p2m.c | 8 ++++----
xen/include/xen/sched.h | 1 +
10 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index ff895f7f9437..0909929c00e0 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -5004,7 +5004,7 @@ bool asmlinkage vmx_vmenter_helper(const struct cpu_user_regs *regs)
if ( currd->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
continue;
- ept = &currd->arch.altp2m_p2m[i]->ept;
+ ept = &currd->altp2m_p2m[i]->ept;
if ( cpumask_test_cpu(cpu, ept->invalidate) )
{
cpumask_clear_cpu(cpu, ept->invalidate);
diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h
index 0cf0c0d92087..f8038087e612 100644
--- a/xen/arch/x86/include/asm/domain.h
+++ b/xen/arch/x86/include/asm/domain.h
@@ -368,7 +368,6 @@ struct arch_domain
mm_lock_t nested_p2m_lock;
#ifdef CONFIG_ALTP2M
- struct p2m_domain **altp2m_p2m;
mm_lock_t altp2m_list_lock;
uint64_t *altp2m_eptp;
uint64_t *altp2m_visible_eptp;
diff --git a/xen/arch/x86/include/asm/p2m.h b/xen/arch/x86/include/asm/p2m.h
index 3a5a5fd43c2a..ec871717a9e4 100644
--- a/xen/arch/x86/include/asm/p2m.h
+++ b/xen/arch/x86/include/asm/p2m.h
@@ -901,7 +901,7 @@ static inline struct p2m_domain *p2m_get_altp2m(struct vcpu *v)
BUG_ON(index >= v->domain->nr_altp2m);
- return v->domain->arch.altp2m_p2m[index];
+ return v->domain->altp2m_p2m[index];
}
/* set current alternate p2m table */
@@ -919,7 +919,7 @@ static inline bool p2m_set_altp2m(struct vcpu *v, unsigned int idx)
atomic_dec(&orig->active_vcpus);
vcpu_altp2m(v).p2midx = idx;
- atomic_inc(&v->domain->arch.altp2m_p2m[idx]->active_vcpus);
+ atomic_inc(&v->domain->altp2m_p2m[idx]->active_vcpus);
return true;
}
diff --git a/xen/arch/x86/mm/altp2m.c b/xen/arch/x86/mm/altp2m.c
index 08db8f37c1b1..8dd3c0f96be0 100644
--- a/xen/arch/x86/mm/altp2m.c
+++ b/xen/arch/x86/mm/altp2m.c
@@ -130,14 +130,14 @@ int p2m_init_altp2m(struct domain *d)
struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
mm_lock_init(&d->arch.altp2m_list_lock);
- d->arch.altp2m_p2m = xvzalloc_array(struct p2m_domain *, d->nr_altp2m);
+ d->altp2m_p2m = xvzalloc_array(struct p2m_domain *, d->nr_altp2m);
- if ( !d->arch.altp2m_p2m )
+ if ( !d->altp2m_p2m )
return -ENOMEM;
for ( i = 0; i < d->nr_altp2m; i++ )
{
- d->arch.altp2m_p2m[i] = p2m = p2m_init_one(d);
+ d->altp2m_p2m[i] = p2m = p2m_init_one(d);
if ( p2m == NULL )
{
p2m_teardown_altp2m(d);
@@ -158,14 +158,14 @@ void p2m_teardown_altp2m(struct domain *d)
for ( i = 0; i < d->nr_altp2m; i++ )
{
- if ( !d->arch.altp2m_p2m[i] )
+ if ( !d->altp2m_p2m[i] )
continue;
- p2m = d->arch.altp2m_p2m[i];
- d->arch.altp2m_p2m[i] = NULL;
+ p2m = d->altp2m_p2m[i];
+ d->altp2m_p2m[i] = NULL;
p2m_free_one(p2m);
}
- XVFREE(d->arch.altp2m_p2m);
+ XVFREE(d->altp2m_p2m);
}
int altp2m_get_effective_entry(struct p2m_domain *ap2m, gfn_t gfn, mfn_t *mfn,
@@ -325,7 +325,7 @@ static void p2m_reset_altp2m(struct domain *d, unsigned int idx,
struct p2m_domain *p2m;
ASSERT(idx < d->nr_altp2m);
- p2m = d->arch.altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
+ p2m = d->altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
p2m_lock(p2m);
@@ -368,7 +368,7 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx,
ASSERT(idx < d->nr_altp2m);
- p2m = d->arch.altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
+ p2m = d->altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
hostp2m = p2m_get_hostp2m(d);
p2m_lock(p2m);
@@ -468,7 +468,7 @@ int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int idx)
if ( d->arch.altp2m_eptp[array_index_nospec(idx, MAX_EPTP)] !=
mfn_x(INVALID_MFN) )
{
- p2m = d->arch.altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
+ p2m = d->altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
if ( !_atomic_read(p2m->active_vcpus) )
{
@@ -532,7 +532,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
return rc;
hp2m = p2m_get_hostp2m(d);
- ap2m = d->arch.altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
+ ap2m = d->altp2m_p2m[array_index_nospec(idx, d->nr_altp2m)];
p2m_lock(hp2m);
p2m_lock(ap2m);
@@ -596,7 +596,7 @@ int p2m_altp2m_propagate_change(struct domain *d, gfn_t gfn,
if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
continue;
- p2m = d->arch.altp2m_p2m[i];
+ p2m = d->altp2m_p2m[i];
/* Check for a dropped page that may impact this altp2m */
if ( mfn_eq(mfn, INVALID_MFN) &&
@@ -679,7 +679,7 @@ int p2m_set_suppress_ve_multi(struct domain *d,
return -EINVAL;
p2m = ap2m =
- d->arch.altp2m_p2m[array_index_nospec(sve->view, d->nr_altp2m)];
+ d->altp2m_p2m[array_index_nospec(sve->view, d->nr_altp2m)];
}
p2m_lock(host_p2m);
@@ -746,7 +746,7 @@ int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool *suppress_ve,
return -EINVAL;
p2m = ap2m =
- d->arch.altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
+ d->altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
}
else
p2m = host_p2m;
diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
index 3d563b3bc2d1..6918a00a2a25 100644
--- a/xen/arch/x86/mm/hap/hap.c
+++ b/xen/arch/x86/mm/hap/hap.c
@@ -524,7 +524,7 @@ int hap_enable(struct domain *d, u32 mode)
for ( i = 0; i < d->nr_altp2m; i++ )
{
- rv = p2m_alloc_table(d->arch.altp2m_p2m[i]);
+ rv = p2m_alloc_table(d->altp2m_p2m[i]);
if ( rv != 0 )
goto out;
}
@@ -548,7 +548,7 @@ void hap_final_teardown(struct domain *d)
#ifdef CONFIG_ALTP2M
if ( hvm_altp2m_supported() )
for ( i = 0; i < d->nr_altp2m; i++ )
- p2m_teardown(d->arch.altp2m_p2m[i], true, NULL);
+ p2m_teardown(d->altp2m_p2m[i], true, NULL);
#endif
/* Destroy nestedp2m's first */
@@ -603,7 +603,7 @@ void hap_teardown(struct domain *d, bool *preempted)
for ( i = 0; i < d->nr_altp2m; i++ )
{
- p2m_teardown(d->arch.altp2m_p2m[i], false, preempted);
+ p2m_teardown(d->altp2m_p2m[i], false, preempted);
if ( preempted && *preempted )
return;
}
diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c
index a9d6b081a523..e5548e64d8d0 100644
--- a/xen/arch/x86/mm/mem_access.c
+++ b/xen/arch/x86/mm/mem_access.c
@@ -319,7 +319,7 @@ long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
if ( !altp2m_is_eptp_valid(d, altp2m_idx) )
return -EINVAL;
- ap2m = d->arch.altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
+ ap2m = d->altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
}
#endif
@@ -375,7 +375,7 @@ long p2m_set_mem_access_multi(struct domain *d,
if ( !altp2m_is_eptp_valid(d, altp2m_idx) )
return -EINVAL;
- ap2m = d->arch.altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
+ ap2m = d->altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
}
#endif
@@ -438,7 +438,7 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access,
if ( !altp2m_is_eptp_valid(d, altp2m_idx) )
return -EINVAL;
- p2m = d->arch.altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
+ p2m = d->altp2m_p2m[array_index_nospec(altp2m_idx, d->nr_altp2m)];
}
#endif
@@ -457,7 +457,7 @@ void arch_p2m_set_access_required(struct domain *d, bool access_required)
unsigned int i;
for ( i = 0; i < d->nr_altp2m; i++ )
{
- struct p2m_domain *p2m = d->arch.altp2m_p2m[i];
+ struct p2m_domain *p2m = d->altp2m_p2m[i];
if ( p2m )
p2m->access_required = access_required;
diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
index 8319733b1bb6..b7d8fb9ad1aa 100644
--- a/xen/arch/x86/mm/mem_sharing.c
+++ b/xen/arch/x86/mm/mem_sharing.c
@@ -919,7 +919,7 @@ static int nominate_page(struct domain *d, gfn_t gfn,
for ( i = 0; i < d->nr_altp2m; i++ )
{
- ap2m = d->arch.altp2m_p2m[i];
+ ap2m = d->altp2m_p2m[i];
if ( !ap2m )
continue;
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index ed850723f5fd..ddb4c7606be1 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -1311,7 +1311,7 @@ static void ept_set_ad_sync(struct domain *d, bool value)
if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
continue;
- p2m = d->arch.altp2m_p2m[i];
+ p2m = d->altp2m_p2m[i];
p2m_lock(p2m);
p2m->ept.ad = value;
@@ -1579,7 +1579,7 @@ void __init setup_ept_dump(void)
void p2m_init_altp2m_ept(struct domain *d, unsigned int i)
{
struct p2m_domain *p2m =
- d->arch.altp2m_p2m[array_index_nospec(i, d->nr_altp2m)];
+ d->altp2m_p2m[array_index_nospec(i, d->nr_altp2m)];
struct p2m_domain *hostp2m = p2m_get_hostp2m(d);
struct ept_data *ept;
@@ -1603,7 +1603,7 @@ unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp)
if ( d->arch.altp2m_eptp[i] == mfn_x(INVALID_MFN) )
continue;
- p2m = d->arch.altp2m_p2m[i];
+ p2m = d->altp2m_p2m[i];
ept = &p2m->ept;
if ( eptp == ept->eptp )
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index 41517765c5ec..5bd426296f20 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -111,7 +111,7 @@ void p2m_change_entry_type_global(struct domain *d,
{
if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
{
- struct p2m_domain *altp2m = d->arch.altp2m_p2m[i];
+ struct p2m_domain *altp2m = d->altp2m_p2m[i];
p2m_lock(altp2m);
change_entry_type_global(altp2m, ot, nt);
@@ -157,7 +157,7 @@ bool p2m_memory_type_changed(struct domain *d)
{
if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
{
- struct p2m_domain *altp2m = d->arch.altp2m_p2m[i];
+ struct p2m_domain *altp2m = d->altp2m_p2m[i];
p2m_lock(altp2m);
_memory_type_changed(altp2m);
@@ -955,7 +955,7 @@ void p2m_change_type_range(struct domain *d,
{
if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
{
- struct p2m_domain *altp2m = d->arch.altp2m_p2m[i];
+ struct p2m_domain *altp2m = d->altp2m_p2m[i];
p2m_lock(altp2m);
change_type_range(altp2m, start, end, ot, nt);
@@ -1031,7 +1031,7 @@ int p2m_finish_type_change(struct domain *d,
{
if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) )
{
- struct p2m_domain *altp2m = d->arch.altp2m_p2m[i];
+ struct p2m_domain *altp2m = d->altp2m_p2m[i];
p2m_lock(altp2m);
rc = finish_type_change(altp2m, first_gfn, max_nr);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 458f2f260dd7..5d8ba2d2ab19 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -626,6 +626,7 @@ struct domain
/* altp2m: allow multiple copies of host p2m */
bool altp2m_active;
unsigned int nr_altp2m; /* Number of altp2m tables. */
+ struct p2m_domain **altp2m_p2m;
#endif
#ifdef CONFIG_VMTRACE
--
2.34.1
Using a generic name for altp2m_supported makes it possible to indicate
whether altp2m is supported on other architectures as well. Even if other
architectures always support altp2m at a hardware level (like ARM), altp2m
might not be supported due to CONFIG_ALTP2M being disabled. Therefore, the
altp2m_supported function can be implemented on all architectures to
indicate if the hardware supports altp2m *and* if CONFIG_ALTP2M is enabled.
This is commit 4/8 of the preparation phase.
Signed-off-by: Rose Spangler <Rose.Spangler@elektrobit.com>
---
v6: Introduced this patch.
---
xen/arch/x86/domain.c | 2 +-
xen/arch/x86/hvm/hvm.c | 6 +++---
xen/arch/x86/include/asm/hvm/hvm.h | 4 ++--
xen/arch/x86/mm/hap/hap.c | 6 +++---
xen/arch/x86/mm/p2m-basic.c | 4 ++--
xen/arch/x86/mm/p2m-ept.c | 2 +-
6 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 1d458f1372e5..512b18d4010f 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -698,7 +698,7 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
if ( altp2m_mode )
{
- if ( !hvm_altp2m_supported() )
+ if ( !altp2m_supported() )
{
dprintk(XENLOG_INFO, "altp2m is not supported\n");
return -EINVAL;
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 86c12c0d1ef4..bc35efdf2c02 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -1692,7 +1692,7 @@ void hvm_vcpu_destroy(struct vcpu *v)
ioreq_server_remove_vcpu_all(v->domain, v);
- if ( hvm_altp2m_supported() )
+ if ( altp2m_supported() )
altp2m_vcpu_destroy(v);
nestedhvm_vcpu_destroy(v);
@@ -4566,7 +4566,7 @@ static int do_altp2m_op(
int rc = 0;
uint64_t mode;
- if ( !hvm_altp2m_supported() )
+ if ( !altp2m_supported() )
return -EOPNOTSUPP;
if ( copy_from_guest(&a, arg, 1) )
@@ -4965,7 +4965,7 @@ static int compat_altp2m_op(
struct xen_hvm_altp2m_op *altp2m_op;
} nat;
- if ( !hvm_altp2m_supported() )
+ if ( !altp2m_supported() )
return -EOPNOTSUPP;
if ( copy_from_guest(&a, arg, 1) )
diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h
index e7c1364802f8..6406bb687718 100644
--- a/xen/arch/x86/include/asm/hvm/hvm.h
+++ b/xen/arch/x86/include/asm/hvm/hvm.h
@@ -702,7 +702,7 @@ static inline bool hvm_hap_supported(void)
}
/* returns true if hardware supports alternate p2m's */
-static inline bool hvm_altp2m_supported(void)
+static inline bool altp2m_supported(void)
{
return IS_ENABLED(CONFIG_ALTP2M) && hvm_funcs.caps.altp2m;
}
@@ -876,7 +876,7 @@ static inline bool hvm_hap_supported(void)
return false;
}
-static inline bool hvm_altp2m_supported(void)
+static inline bool altp2m_supported(void)
{
return false;
}
diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
index 6918a00a2a25..563eba3c0d36 100644
--- a/xen/arch/x86/mm/hap/hap.c
+++ b/xen/arch/x86/mm/hap/hap.c
@@ -501,7 +501,7 @@ int hap_enable(struct domain *d, u32 mode)
}
#ifdef CONFIG_ALTP2M
- if ( hvm_altp2m_supported() )
+ if ( altp2m_supported() )
{
/* Init alternate p2m data */
if ( (d->arch.altp2m_eptp = alloc_xenheap_page()) == NULL )
@@ -546,7 +546,7 @@ void hap_final_teardown(struct domain *d)
unsigned int i;
#ifdef CONFIG_ALTP2M
- if ( hvm_altp2m_supported() )
+ if ( altp2m_supported() )
for ( i = 0; i < d->nr_altp2m; i++ )
p2m_teardown(d->altp2m_p2m[i], true, NULL);
#endif
@@ -590,7 +590,7 @@ void hap_teardown(struct domain *d, bool *preempted)
#ifdef CONFIG_ALTP2M
/* Leave the root pt in case we get further attempts to modify the p2m. */
- if ( hvm_altp2m_supported() )
+ if ( altp2m_supported() )
{
if ( altp2m_active(d) )
for_each_vcpu ( d, v )
diff --git a/xen/arch/x86/mm/p2m-basic.c b/xen/arch/x86/mm/p2m-basic.c
index e126fda26760..ce14066fedaf 100644
--- a/xen/arch/x86/mm/p2m-basic.c
+++ b/xen/arch/x86/mm/p2m-basic.c
@@ -128,7 +128,7 @@ int p2m_init(struct domain *d)
return rc;
}
- rc = hvm_altp2m_supported() ? p2m_init_altp2m(d) : 0;
+ rc = altp2m_supported() ? p2m_init_altp2m(d) : 0;
if ( rc )
{
p2m_teardown_hostp2m(d);
@@ -197,7 +197,7 @@ void p2m_final_teardown(struct domain *d)
{
if ( is_hvm_domain(d) )
{
- if ( hvm_altp2m_supported() )
+ if ( altp2m_supported() )
p2m_teardown_altp2m(d);
/*
* We must tear down nestedp2m unconditionally because
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index ddb4c7606be1..84159198f3a0 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -995,7 +995,7 @@ out:
if ( is_epte_present(&old_entry) )
ept_free_entry(p2m, &old_entry, target);
- if ( hvm_altp2m_supported() && entry_written && p2m_is_hostp2m(p2m) )
+ if ( altp2m_supported() && entry_written && p2m_is_hostp2m(p2m) )
{
ret = p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, p2ma);
if ( !rc )
--
2.34.1
Following from the previous commit, this commit makes altp2m_supported
available through the asm/altp2m.h header.
This is commit 5/8 of the preparation phase.
Signed-off-by: Rose Spangler <Rose.Spangler@elektrobit.com>
---
v6: Introduced this patch.
---
xen/arch/x86/domain.c | 1 +
xen/arch/x86/include/asm/altp2m.h | 11 +++++++++++
xen/arch/x86/include/asm/hvm/hvm.h | 11 -----------
xen/include/asm-generic/altp2m.h | 7 +++++++
4 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 512b18d4010f..e4f1cbf3b51e 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -39,6 +39,7 @@
#include <xen/softirq.h>
#include <xen/wait.h>
+#include <asm/altp2m.h>
#include <asm/amd.h>
#include <asm/cpu-policy.h>
#include <asm/cpuidle.h>
diff --git a/xen/arch/x86/include/asm/altp2m.h b/xen/arch/x86/include/asm/altp2m.h
index ad5ded833a75..07e760f60659 100644
--- a/xen/arch/x86/include/asm/altp2m.h
+++ b/xen/arch/x86/include/asm/altp2m.h
@@ -28,6 +28,12 @@ static inline bool altp2m_is_eptp_valid(const struct domain *d,
mfn_x(INVALID_MFN);
}
+/* returns true if hardware supports alternate p2m's */
+static inline bool altp2m_supported(void)
+{
+ return hvm_funcs.caps.altp2m;
+}
+
static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
{
return vcpu_altp2m(v).p2midx;
@@ -58,6 +64,11 @@ static inline bool altp2m_is_eptp_valid(const struct domain *d,
return false;
}
+static inline bool altp2m_supported(void)
+{
+ return false;
+}
+
/* Only declaration is needed. DCE will optimise it out when linking. */
uint16_t altp2m_vcpu_idx(const struct vcpu *v);
void altp2m_vcpu_initialise(struct vcpu *v);
diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h
index 6406bb687718..e6d8042831dc 100644
--- a/xen/arch/x86/include/asm/hvm/hvm.h
+++ b/xen/arch/x86/include/asm/hvm/hvm.h
@@ -701,12 +701,6 @@ static inline bool hvm_hap_supported(void)
return hvm_funcs.caps.hap;
}
-/* returns true if hardware supports alternate p2m's */
-static inline bool altp2m_supported(void)
-{
- return IS_ENABLED(CONFIG_ALTP2M) && hvm_funcs.caps.altp2m;
-}
-
/* Returns true if we have the minimum hardware requirements for nested virt */
static inline bool hvm_nested_virt_supported(void)
{
@@ -876,11 +870,6 @@ static inline bool hvm_hap_supported(void)
return false;
}
-static inline bool altp2m_supported(void)
-{
- return false;
-}
-
static inline bool hvm_nested_virt_supported(void)
{
return false;
diff --git a/xen/include/asm-generic/altp2m.h b/xen/include/asm-generic/altp2m.h
index ecee6942f4e8..a3cdbdae9953 100644
--- a/xen/include/asm-generic/altp2m.h
+++ b/xen/include/asm-generic/altp2m.h
@@ -6,6 +6,13 @@
struct vcpu;
+/* returns true if hardware supports alternate p2m's */
+static inline bool altp2m_supported(void)
+{
+ /* Not implemented on GENERIC. */
+ return false;
+}
+
/* Alternate p2m VCPU */
static inline unsigned int altp2m_vcpu_idx(const struct vcpu *v)
{
--
2.34.1
Similarly to the earlier common altp2m.c/altp2m.h commit, this commit adds
a template altp2m.c and altp2m.h file for ARM to be added to in later
commits. Creating a commit with just the template file additions makes it
easier to reorder later commits which add to these files.
This commit can be squashed into the first commit which actually adds
something to altp2m.c/altp2m.h for the actual submission if that would be
preferred.
This is commit 6/8 of the preparation phase.
Signed-off-by: Rose Spangler <Rose.Spangler@elektrobit.com>
Signed-off-by: Aqib Javaid <Aqib.Javaid@elektrobit.com>
---
v6: Introduced this patch.
---
xen/arch/arm/Makefile | 1 +
xen/arch/arm/altp2m.c | 16 +++++++++++++
xen/arch/arm/include/asm/Makefile | 1 -
xen/arch/arm/include/asm/altp2m.h | 37 +++++++++++++++++++++++++++++++
4 files changed, 54 insertions(+), 1 deletion(-)
create mode 100644 xen/arch/arm/altp2m.c
create mode 100644 xen/arch/arm/include/asm/altp2m.h
diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 69200b27280d..d995d4ff7aa1 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_TEE) += tee/
obj-$(CONFIG_HAS_VPCI) += vpci.o
obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o
+obj-$(CONFIG_ALTP2M) += altp2m.o
obj-y += cpuerrata.o
obj-y += cpufeature.o
obj-y += decode.o
diff --git a/xen/arch/arm/altp2m.c b/xen/arch/arm/altp2m.c
new file mode 100644
index 000000000000..2bd1ff4df223
--- /dev/null
+++ b/xen/arch/arm/altp2m.c
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * altp2m.c: Alternate p2m
+ *
+ * Copyright (c) 2016 Sergej Proskurin <proskurin@sec.in.tum.de>
+ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/include/asm/Makefile b/xen/arch/arm/include/asm/Makefile
index 4565baca6a4d..fef4dd42b6cb 100644
--- a/xen/arch/arm/include/asm/Makefile
+++ b/xen/arch/arm/include/asm/Makefile
@@ -1,5 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only
-generic-y += altp2m.h
generic-y += device.h
generic-y += hardirq.h
generic-y += iocap.h
diff --git a/xen/arch/arm/include/asm/altp2m.h b/xen/arch/arm/include/asm/altp2m.h
new file mode 100644
index 000000000000..ca836bae7330
--- /dev/null
+++ b/xen/arch/arm/include/asm/altp2m.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * altp2m.h: Alternate p2m
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ * Copyright (c) 2016, Sergej Proskurin <proskurin@sec.in.tum.de>.
+ */
+
+#ifndef __ASM_ARM_ALTP2M_H
+#define __ASM_ARM_ALTP2M_H
+
+#include <xen/sched.h>
+
+static inline bool altp2m_supported(void)
+{
+ /* Not implemented yet */
+ return false;
+}
+
+/* Alternate p2m VCPU */
+static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
+{
+ /* Not implemented yet */
+ BUG();
+ return 0;
+}
+
+#endif /* __ASM_ARM_ALTP2M_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
2.34.1
Following the x86 implementation in commit e96831ece819, this commit adds
the CONFIG_ALTP2M Kconfig option for ARM. This makes it possible to build
Xen without building altp2m code.
This commit also implements a stub for p2m_altp2m_check, as some
implementation is needed when CONFIG_ALTP2M is enabled. This is due to a
call to p2m_altp2m_check in vm_event.c which is gated by CONFIG_ALTP2M.
This is commit 7/8 of the preparation phase.
Signed-off-by: Rose Spangler <Rose.Spangler@elektrobit.com>
Signed-off-by: Aqib Javaid <Aqib.Javaid@elektrobit.com>
---
v6: Introduced this patch.
---
xen/arch/arm/Kconfig | 11 +++++++++++
xen/arch/arm/altp2m.c | 9 +++++++++
xen/arch/arm/include/asm/altp2m.h | 18 ++++++++++++++++--
3 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index 2f2b501fdac4..fdf0721c3c03 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -98,6 +98,17 @@ config MPU
systems supporting EL2. (UNSUPPORTED)
endchoice
+config ALTP2M
+ bool "Alternate P2M support" if EXPERT
+ depends on MMU
+ default y
+ help
+ Alternate-p2m allows a guest to manage multiple p2m guest physical
+ "memory views" (as opposed to a single p2m).
+ Useful for memory introspection.
+
+ If unsure, stay with defaults.
+
source "arch/Kconfig"
config ACPI
diff --git a/xen/arch/arm/altp2m.c b/xen/arch/arm/altp2m.c
index 2bd1ff4df223..8bd174ea8f37 100644
--- a/xen/arch/arm/altp2m.c
+++ b/xen/arch/arm/altp2m.c
@@ -5,6 +5,15 @@
* Copyright (c) 2016 Sergej Proskurin <proskurin@sec.in.tum.de>
*/
+#include <asm/p2m.h>
+
+/* Check to see if vcpu should be switched to a different p2m. */
+void p2m_altp2m_check(struct vcpu *v, uint16_t idx)
+{
+ /* Not yet implemented */
+ BUG();
+}
+
/*
* Local variables:
* mode: C
diff --git a/xen/arch/arm/include/asm/altp2m.h b/xen/arch/arm/include/asm/altp2m.h
index ca836bae7330..698c35427e75 100644
--- a/xen/arch/arm/include/asm/altp2m.h
+++ b/xen/arch/arm/include/asm/altp2m.h
@@ -11,10 +11,12 @@
#include <xen/sched.h>
+#ifdef CONFIG_ALTP2M
+
+/* Hardware always supports altp2m on ARM */
static inline bool altp2m_supported(void)
{
- /* Not implemented yet */
- return false;
+ return true;
}
/* Alternate p2m VCPU */
@@ -25,6 +27,18 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
return 0;
}
+#else /* CONFIG_ALTP2M */
+
+static inline bool altp2m_supported(void)
+{
+ return false;
+}
+
+/* Only declaration is needed. DCE will optimise it out when linking. */
+uint16_t altp2m_vcpu_idx(const struct vcpu *v);
+
+#endif /* CONFIG_ALTP2M */
+
#endif /* __ASM_ARM_ALTP2M_H */
/*
--
2.34.1
© 2016 - 2026 Red Hat, Inc.