xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Mukesh Rathor <mukesh.rathor@oracle.com>
To: "Xen-devel@lists.xensource.com" <Xen-devel@lists.xensource.com>
Cc: Tim Deegan <tim@xen.org>, Jan Beulich <JBeulich@suse.com>
Subject: [RFC PATCH] PVH: cleanup of p2m upon p2m destroy
Date: Mon, 16 Dec 2013 17:47:28 -0800	[thread overview]
Message-ID: <20131216174728.2ba3ad9a@mantra.us.oracle.com> (raw)


When a controlling domain is destroyed, any p2m_is_foreign pages must
release the refcnt gotten when the page was added to the p2m.

Signed-off-by: Mukesh Rathor <mukesh.rathor@oracle.com>
---
 xen/arch/x86/domain.c     |    3 +++
 xen/arch/x86/mm/p2m.c     |   30 ++++++++++++++++++++++++++++++
 xen/include/asm-x86/p2m.h |    4 +++-
 3 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index c0ac5d6..7f15cdd 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1872,6 +1872,9 @@ int domain_relinquish_resources(struct domain *d)
     case RELMEM_not_started:
         pci_release_devices(d);
 
+        if ( (ret = p2m_cleanup(d)) )
+            return ret;
+
         /* Tear down paging-assistance stuff. */
         paging_teardown(d);
 
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index 441d151..a91deb2 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -499,6 +499,36 @@ void p2m_final_teardown(struct domain *d)
     p2m_teardown_hostp2m(d);
 }
 
+/* This function to do any cleanup while walking the entire p2m */
+int p2m_cleanup(struct domain *d)
+{
+    int rc = 0;
+    unsigned long gfn, count = 0;
+    struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+    if ( !is_pvh_domain(d) )
+        return 0;
+
+    for ( gfn = p2m->next_foreign_gfn_to_check;
+          gfn <= p2m->max_mapped_pfn; gfn++, count++ )
+    {
+        p2m_type_t p2mt;
+        mfn_t mfn = get_gfn_query(d, gfn, &p2mt);
+
+        if ( unlikely(p2m_is_foreign(p2mt)) )
+            put_page(mfn_to_page(mfn));
+        put_gfn(d, gfn);
+        
+        /* Preempt every 10k pages, arbritary */
+        if ( count == 10000 && hypercall_preempt_check() )
+        {
+            p2m->next_foreign_gfn_to_check = gfn + 1;
+            rc = -EAGAIN;
+            break;
+        }
+    }
+    return rc;
+}
 
 static void
 p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn,
diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h
index 6371705..d32d103 100644
--- a/xen/include/asm-x86/p2m.h
+++ b/xen/include/asm-x86/p2m.h
@@ -254,9 +254,10 @@ struct p2m_domain {
     /* Highest guest frame that's ever been mapped in the p2m */
     unsigned long max_mapped_pfn;
 
-    /* When releasing shared gfn's in a preemptible manner, recall where
+    /* When releasing gfn's in a preemptible manner, recall where
      * to resume the search */
     unsigned long next_shared_gfn_to_relinquish;
+    unsigned long next_foreign_gfn_to_check;
 
     /* Populate-on-demand variables
      * All variables are protected with the pod lock. We cannot rely on
@@ -471,6 +472,7 @@ int p2m_alloc_table(struct p2m_domain *p2m);
 /* Return all the p2m resources to Xen. */
 void p2m_teardown(struct p2m_domain *p2m);
 void p2m_final_teardown(struct domain *d);
+int p2m_cleanup(struct domain *d);
 
 /* Add a page to a domain's p2m table */
 int guest_physmap_add_entry(struct domain *d, unsigned long gfn,
-- 
1.7.2.3

             reply	other threads:[~2013-12-17  1:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17  1:47 Mukesh Rathor [this message]
2013-12-17  8:42 ` [RFC PATCH] PVH: cleanup of p2m upon p2m destroy Jan Beulich
2013-12-17 10:19   ` Tim Deegan
2013-12-18  2:44     ` Mukesh Rathor
2013-12-18 10:03       ` Jan Beulich
2013-12-18 11:32         ` Dietmar Hahn
2013-12-18 10:09       ` Tim Deegan
2013-12-18 16:51         ` Tim Deegan
2013-12-19  2:01           ` Mukesh Rathor
2013-12-19 10:50             ` Tim Deegan
2013-12-20  2:00               ` Mukesh Rathor
2013-12-20  9:22                 ` Tim Deegan
2014-02-01  2:38           ` Mukesh Rathor
2014-02-03 10:12             ` Tim Deegan
2013-12-20 13:58         ` George Dunlap
2013-12-20 14:29           ` Tim Deegan
2013-12-18  1:01   ` Mukesh Rathor
2013-12-18  8:12     ` Jan Beulich

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=20131216174728.2ba3ad9a@mantra.us.oracle.com \
    --to=mukesh.rathor@oracle.com \
    --cc=JBeulich@suse.com \
    --cc=Xen-devel@lists.xensource.com \
    --cc=tim@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).