xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andres Lagar-Cavilla <andres@lagarcavilla.org>
To: xen-devel@lists.xen.org
Cc: andres@gridcentric.ca, tim@xen.org
Subject: [PATCH] x86/mm: Clean up unshare path for foreign mappings
Date: Tue, 19 Jun 2012 10:48:20 -0400	[thread overview]
Message-ID: <b3a8ef4c556cc9a2d310.1340117300@xdev.gridcentric.ca> (raw)

 xen/arch/x86/mm.c |  34 +++++++++++-----------------------
 1 files changed, 11 insertions(+), 23 deletions(-)


In its current shape, if Xen unshares a foreign gfn successfully while building
a foreign writable map, it is left with a reference to the old shared page in
the "target" var.

Instead, push unsharing request down on the initial get_page_from_gfn call,
which will DTRT.

This allows for greatly simplifying the unshare related condition handling,
removing ugly comments and s86_64 ifdef-ery.

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

diff -r f0806cb74009 -r b3a8ef4c556c xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -3563,10 +3563,12 @@ int do_mmu_update(
                     l1_pgentry_t l1e = l1e_from_intpte(req.val);
                     p2m_type_t l1e_p2mt = p2m_ram_rw;
                     struct page_info *target = NULL;
+                    p2m_query_t q = (l1e_get_flags(l1e) & _PAGE_RW) ?
+                                        P2M_UNSHARE : P2M_ALLOC;
 
                     if ( paging_mode_translate(pg_owner) )
                         target = get_page_from_gfn(pg_owner, l1e_get_pfn(l1e),
-                                                   &l1e_p2mt, P2M_ALLOC);
+                                                   &l1e_p2mt, q);
 
                     if ( p2m_is_paged(l1e_p2mt) )
                     {
@@ -3581,29 +3583,15 @@ int do_mmu_update(
                         rc = -ENOENT;
                         break;
                     }
-#ifdef __x86_64__
-                    /* XXX: Ugly: pull all the checks into a separate function. 
-                     * Don't want to do it now, not to interfere with mem_paging
-                     * patches */
-                    else if ( p2m_ram_shared == l1e_p2mt )
+                    /* If we tried to unshare and failed */
+                    else if ( (q & P2M_UNSHARE) && p2m_is_shared(l1e_p2mt) )
                     {
-                        /* Unshare the page for RW foreign mappings */
-                        if ( l1e_get_flags(l1e) & _PAGE_RW )
-                        {
-                            unsigned long gfn = l1e_get_pfn(l1e);
-                            rc = mem_sharing_unshare_page(pg_owner, gfn, 0); 
-                            if ( rc )
-                            {
-                                if ( target )
-                                    put_page(target);
-                                /* Notify helper, don't care about errors, will not
-                                 * sleep on wq, since we're a foreign domain. */
-                                (void)mem_sharing_notify_enomem(pg_owner, gfn, 0);
-                                break; 
-                            }
-                        }
-                    } 
-#endif
+                        /* We could not have obtained a page ref. */
+                        ASSERT(target == NULL);
+                        /* And mem_sharing_notify has already been called. */
+                        rc = -ENOMEM;
+                        break;
+                    }
 
                     rc = mod_l1_entry(va, l1e, mfn,
                                       cmd == MMU_PT_UPDATE_PRESERVE_AD, v,

             reply	other threads:[~2012-06-19 14:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-19 14:48 Andres Lagar-Cavilla [this message]
2012-06-28 11:46 ` [PATCH] x86/mm: Clean up unshare path for foreign mappings 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=b3a8ef4c556cc9a2d310.1340117300@xdev.gridcentric.ca \
    --to=andres@lagarcavilla.org \
    --cc=andres@gridcentric.ca \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.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).