xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andres Lagar-Cavilla <andres@lagarcavilla.org>
To: xen-devel@lists.xensource.com
Cc: george.dunlap@eu.citrix.com, andres@gridcentric.ca,
	keir.xen@gmail.com, tim@xen.org, adin@gridcentric.ca
Subject: [PATCH 7 of 7] x86/mm: When removing/adding a page from/to the physmap, keep in mind it could be shared
Date: Thu, 09 Feb 2012 00:45:52 -0500	[thread overview]
Message-ID: <667191f054c34b6c1e72.1328766352@xdev.gridcentric.ca> (raw)
In-Reply-To: <patchbomb.1328766345@xdev.gridcentric.ca>

 xen/arch/x86/mm/p2m.c |  26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)


When removing the m2p mapping it is unconditionally set to invalid, which
breaks sharing.

When adding to the physmap, if the previous holder of that entry is a shared
page, we unshare to default to normal case handling.

And, we cannot add a shared page directly to the physmap. Proper interfaces
must be employed, otherwise book-keeping goes awry.

Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>

diff -r 7fe1bb9208df -r 667191f054c3 xen/arch/x86/mm/p2m.c
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -438,7 +438,7 @@ p2m_remove_page(struct p2m_domain *p2m, 
         for ( i = 0; i < (1UL << page_order); i++ )
         {
             mfn_return = p2m->get_entry(p2m, gfn + i, &t, &a, p2m_query, NULL);
-            if ( !p2m_is_grant(t) )
+            if ( !p2m_is_grant(t) && !p2m_is_shared(t) )
                 set_gpfn_from_mfn(mfn+i, INVALID_M2P_ENTRY);
             ASSERT( !p2m_is_valid(t) || mfn + i == mfn_x(mfn_return) );
         }
@@ -500,6 +500,22 @@ guest_physmap_add_entry(struct domain *d
     for ( i = 0; i < (1UL << page_order); i++ )
     {
         omfn = p2m->get_entry(p2m, gfn + i, &ot, &a, p2m_query, NULL);
+#ifdef __x86_64__
+        if ( p2m_is_shared(ot) )
+        {
+            /* Do an unshare to cleanly take care of all corner 
+             * cases. */
+            int rc;
+            rc = mem_sharing_unshare_page(p2m->domain, gfn + i, 0);
+            if ( rc )
+            {
+                p2m_unlock(p2m);
+                return rc;
+            }
+            omfn = p2m->get_entry(p2m, gfn + i, &ot, &a, p2m_query, NULL);
+            ASSERT(!p2m_is_shared(ot));
+        }
+#endif /* __x86_64__ */
         if ( p2m_is_grant(ot) )
         {
             /* Really shouldn't be unmapping grant maps this way */
@@ -528,6 +544,14 @@ guest_physmap_add_entry(struct domain *d
     /* Then, look for m->p mappings for this range and deal with them */
     for ( i = 0; i < (1UL << page_order); i++ )
     {
+        if ( page_get_owner(mfn_to_page(_mfn(mfn + i))) == dom_cow )
+        {
+            /* This is no way to add a shared page to your physmap! */
+            gdprintk(XENLOG_ERR, "Adding shared mfn %lx directly to dom %hu "
+                        "physmap not allowed.\n", mfn+i, d->domain_id);
+            p2m_unlock(p2m);
+            return -EINVAL;
+        }
         if ( page_get_owner(mfn_to_page(_mfn(mfn + i))) != d )
             continue;
         ogfn = mfn_to_gfn(d, _mfn(mfn+i));

  parent reply	other threads:[~2012-02-09  5:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-09  5:45 [PATCH 0 of 7] Synchronized p2m lookups v2 Andres Lagar-Cavilla
2012-02-09  5:45 ` [PATCH 1 of 7] Make p2m lookups fully synchronized wrt modifications Andres Lagar-Cavilla
2012-02-10 15:33   ` Tim Deegan
2012-02-09  5:45 ` [PATCH 2 of 7] Clean up locking now that p2m lockups are fully synchronized Andres Lagar-Cavilla
2012-02-09  5:45 ` [PATCH 3 of 7] Rework locking in the PoD layer Andres Lagar-Cavilla
2012-02-09 12:07   ` George Dunlap
2012-02-09 14:45     ` Andres Lagar-Cavilla
2012-02-10 15:36       ` Tim Deegan
2012-02-10 15:43         ` Tim Deegan
2012-02-10 15:47           ` Andres Lagar-Cavilla
2012-02-10 15:59       ` George Dunlap
2012-02-09  5:45 ` [PATCH 4 of 7] Re-order calls to put_gfn() around wait queue invocations Andres Lagar-Cavilla
2012-02-09  5:45 ` [PATCH 5 of 7] x86/mm: Revert changeset 24582:f6c33cfe7333 Andres Lagar-Cavilla
2012-02-09  5:45 ` [PATCH 6 of 7] x86/mm: Refactor possibly deadlocking get_gfn calls Andres Lagar-Cavilla
2012-02-09  5:45 ` Andres Lagar-Cavilla [this message]
2012-02-10 15:38   ` [PATCH 7 of 7] x86/mm: When removing/adding a page from/to the physmap, keep in mind it could be shared Tim Deegan
2012-02-10 16:10 ` [PATCH 0 of 7] Synchronized p2m lookups v2 Tim Deegan

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=667191f054c34b6c1e72.1328766352@xdev.gridcentric.ca \
    --to=andres@lagarcavilla.org \
    --cc=adin@gridcentric.ca \
    --cc=andres@gridcentric.ca \
    --cc=george.dunlap@eu.citrix.com \
    --cc=keir.xen@gmail.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xensource.com \
    /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).