[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] xen/arm: p2m: split level 1 foreign superpages for preemption



Static shared memory can create 1GB foreign mappings, as
p2m_set_entry() picks the mapping size based only on alignment.
p2m_put_page() doesn't have a put for level 1, so the references of
such a mapping are never dropped, the pages are never freed and
destroying the owner never completes.

Putting the references of a 1GB block at once would take too long
without being able to preempt, since relinquish_p2m_mapping() can only
be preempted between entries. By changing the order to 2MB,
__p2m_set_entry() can split the superpage and therefore put 2MB
blocks, allowing the preemption check in relinquish_p2m_mapping() to
work properly. For that, the check also needs ">=" instead of ">".

Signed-off-by: Gabriel Quintáns Souto <gabi.qs.mail@xxxxxxxxx>
---
 xen/arch/arm/mmu/p2m.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/mmu/p2m.c b/xen/arch/arm/mmu/p2m.c
index bc6d196..e7a27db 100644
--- a/xen/arch/arm/mmu/p2m.c
+++ b/xen/arch/arm/mmu/p2m.c
@@ -1595,6 +1595,13 @@ int relinquish_p2m_mapping(struct domain *d)
           start = gfn_next_boundary(start, order) )
     {
         mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, NULL);
+        bool split = false;
+
+        if ( p2m_is_foreign(t) && order == XEN_PT_LEVEL_ORDER(1) )
+        {
+            order = XEN_PT_LEVEL_ORDER(2);
+            split = true;
+        }
 
         count++;
         /*
@@ -1602,7 +1609,7 @@ int relinquish_p2m_mapping(struct domain *d)
          * foreign mapping.
          */
         if ( (!(count % 512) ||
-              (p2m_is_foreign(t) && (order > XEN_PT_LEVEL_ORDER(2)))) &&
+              (p2m_is_foreign(t) && (order >= XEN_PT_LEVEL_ORDER(2)))) &&
              hypercall_preempt_check() )
         {
             rc = -ERESTART;
@@ -1621,6 +1628,16 @@ int relinquish_p2m_mapping(struct domain *d)
              */
             rc = __p2m_set_entry(p2m, start, order, INVALID_MFN,
                                  p2m_invalid, p2m_access_rwx);
+            if ( unlikely(rc == -ENOMEM && split) )
+            {
+                /*
+                 * Shattering the foreign superpage needs a page from the P2M
+                 * pool. If none is left, remove the whole superpage at once.
+                 */
+                order = XEN_PT_LEVEL_ORDER(1);
+                rc = __p2m_set_entry(p2m, start, order, INVALID_MFN,
+                                     p2m_invalid, p2m_access_rwx);
+            }
             if ( unlikely(rc) )
             {
                 printk(XENLOG_G_ERR "Unable to remove mapping gfn=%#"PRI_gfn" 
order=%u from the p2m of domain %d\n", gfn_x(start), order, d->domain_id);
-- 
2.56.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.