From: Julien Grall <julien.grall@linaro.org>
To: xen-devel@lists.xenproject.org
Cc: Julien Grall <julien.grall@linaro.org>,
ian.jackson@eu.citrix.com, ian.campbell@citrix.com,
patches@linaro.org
Subject: [PATCH v6 09/10] xen/arm: Set foreign page type to p2m_map_foreign
Date: Tue, 17 Dec 2013 16:27:57 +0000 [thread overview]
Message-ID: <1387297678-17762-10-git-send-email-julien.grall@linaro.org> (raw)
In-Reply-To: <1387297678-17762-1-git-send-email-julien.grall@linaro.org>
Xen needs to know that the current page belongs to another domain. Also take
a reference to this page.
The current process to add a foreign page is:
1) get the page from the foreign p2m
2) take a reference on the page with the foreign domain in parameters
3) add the page to the current domain p2m
If the foreign domain drops the page:
- before 2), get_page will return NULL because the page doesn't
belong anymore to the domain
- after 2), the current domain already have a reference. Write will
occur to an old page which is not yet released. It can corrupt the foreign
domain.
Signed-off-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
Changes in v5:
- Missing rcu_unlock_domain in one path
- Check if the foreign page is RAM
Changes in v4:
- Typo s/release/released/
- Improve commit message
Changes in v3:
- Typoes
- Check if the foreign domain is different from the current domain
Changes in v2:
- Even if gcc is buggy (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501)
define p2m type per mapspace to let the compiler warns about unitialized
values.
---
xen/arch/arm/mm.c | 38 ++++++++++++++++++++++++++++++--------
xen/include/asm-arm/p2m.h | 1 +
2 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index b1222be..6829822 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -977,6 +977,7 @@ static int xenmem_add_to_physmap_one(
{
unsigned long mfn = 0;
int rc;
+ p2m_type_t t;
switch ( space )
{
@@ -1009,22 +1010,33 @@ static int xenmem_add_to_physmap_one(
d->arch.grant_table_gpfn[idx] = gpfn;
+ t = p2m_ram_rw;
+
spin_unlock(&d->grant_table->lock);
break;
case XENMAPSPACE_shared_info:
- if ( idx == 0 )
- mfn = virt_to_mfn(d->shared_info);
- else
+ if ( idx != 0 )
return -EINVAL;
+
+ mfn = virt_to_mfn(d->shared_info);
+ t = p2m_ram_rw;
+
break;
case XENMAPSPACE_gmfn_foreign:
{
- paddr_t maddr;
struct domain *od;
+ struct page_info *page;
+ p2m_type_t p2mt;
od = rcu_lock_domain_by_any_id(foreign_domid);
if ( od == NULL )
return -ESRCH;
+ if ( od == d )
+ {
+ rcu_unlock_domain(od);
+ return -EINVAL;
+ }
+
rc = xsm_map_gmfn_foreign(XSM_TARGET, d, od);
if ( rc )
{
@@ -1032,15 +1044,25 @@ static int xenmem_add_to_physmap_one(
return rc;
}
- maddr = p2m_lookup(od, pfn_to_paddr(idx), NULL);
- if ( maddr == INVALID_PADDR )
+ /* Take reference to the foreign domain page.
+ * Reference will be released in XENMEM_remove_from_physmap */
+ page = get_page_from_gfn(od, idx, &p2mt, P2M_ALLOC);
+ if ( !page )
{
dump_p2m_lookup(od, pfn_to_paddr(idx));
rcu_unlock_domain(od);
return -EINVAL;
}
- mfn = maddr >> PAGE_SHIFT;
+ if ( !p2m_is_ram(p2mt) )
+ {
+ put_page(page);
+ rcu_unlock_domain(od);
+ return -EINVAL;
+ }
+
+ mfn = page_to_mfn(page);
+ t = p2m_map_foreign;
rcu_unlock_domain(od);
break;
@@ -1051,7 +1073,7 @@ static int xenmem_add_to_physmap_one(
}
/* Map at new location. */
- rc = guest_physmap_add_page(d, gpfn, mfn, 0);
+ rc = guest_physmap_add_entry(d, gpfn, mfn, 0, t);
return rc;
}
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index 8b7b6d0..53b3266 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -47,6 +47,7 @@ typedef enum {
} p2m_type_t;
#define p2m_is_foreign(_t) ((_t) == p2m_map_foreign)
+#define p2m_is_ram(_t) ((_t) == p2m_ram_rw || (_t) == p2m_ram_ro)
/* Initialise vmid allocator */
void p2m_vmid_allocator_init(void);
--
1.7.10.4
next prev parent reply other threads:[~2013-12-17 16:28 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-17 16:27 [PATCH v6 00/10] xen/arm: Handle correctly foreign mapping Julien Grall
2013-12-17 16:27 ` [PATCH v6 01/10] xen/arm: Introduce steps in domain_relinquish_resource Julien Grall
2013-12-17 16:27 ` [PATCH v6 02/10] xen/arm: move mfn_to_p2m_entry in arch/arm/p2m.c Julien Grall
2013-12-17 16:27 ` [PATCH v6 03/10] xen/arm: Implement p2m_type_t as an enum Julien Grall
2013-12-17 16:27 ` [PATCH v6 04/10] xen/arm: Store p2m type in each page of the guest Julien Grall
2013-12-18 14:18 ` Ian Campbell
2013-12-17 16:27 ` [PATCH v6 05/10] xen/arm: p2m: Extend p2m_lookup parameters to retrieve the p2m type Julien Grall
2013-12-17 16:27 ` [PATCH v6 06/10] xen/arm: Retrieve p2m type in get_page_from_gfn Julien Grall
2013-12-17 16:27 ` [PATCH v6 07/10] xen/arm: Handle remove foreign mapping Julien Grall
2013-12-17 16:27 ` [PATCH v6 08/10] xen/arm: Add relinquish_p2m_mapping to remove reference on every mapped page Julien Grall
2013-12-17 16:36 ` Ian Campbell
2013-12-17 16:58 ` Julien Grall
2013-12-17 17:02 ` Ian Campbell
2013-12-18 13:21 ` Ian Campbell
2013-12-18 13:30 ` Julien Grall
2013-12-18 14:06 ` Julien Grall
2013-12-18 14:12 ` Ian Campbell
2013-12-18 14:20 ` Ian Campbell
2013-12-18 16:48 ` Julien Grall
2013-12-18 16:50 ` Ian Campbell
2013-12-17 16:27 ` Julien Grall [this message]
2013-12-17 16:27 ` [PATCH v6 10/10] xen/arm: grant-table: Support read-only mapping Julien Grall
2013-12-18 14:41 ` [PATCH v6 00/10] xen/arm: Handle correctly foreign mapping Ian Campbell
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=1387297678-17762-10-git-send-email-julien.grall@linaro.org \
--to=julien.grall@linaro.org \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=patches@linaro.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).