Add memory paging support for MMU updates (mapping a domain's memory).
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 17 Dec 2009 06:27:55 +0000 (06:27 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 17 Dec 2009 06:27:55 +0000 (06:27 +0000)
If Domain-0 tries to map a page that has been paged out, then propagate an
error so that it knows to try again. If the page is paged out, request that
it be paged back in. If the page is in the process of being paged in, then
just keeping returning the error until it is paged back in.

This requires the co-operation of the Domain-0 kernel's privcmd mmap
functions. The kernel can't simply spin waiting for the page, as this will
cause a dead-lock (since the paging tool lives in Domain-0 user-space and if
it's spinning in kernel space, it will never return to user-space to allow the
page to be paged back in). There is a complimentary Linux patch which sees
ENOENT, which is not returned by any other part of this code, and marks the
PFN of that paged specially to indicate it was paged out (much like what it
does with PFNs that are within the range of a domain's memory but are not
presently mapped).

Signed-off-by: Patrick Colp <Patrick.Colp@citrix.com>
xen/arch/x86/mm.c

index 948fabb54b74390cce2802e9c15e2766fcc43a7d..4944b2376eb6116142db6c222d05ea51ffdf55c2 100644 (file)
@@ -3083,13 +3083,24 @@ int do_mmu_update(
              */
         case MMU_NORMAL_PT_UPDATE:
         case MMU_PT_UPDATE_PRESERVE_AD:
+        {
+            p2m_type_t p2mt;
+
             rc = xsm_mmu_normal_update(d, pg_owner, req.val);
             if ( rc )
                 break;
 
             req.ptr -= cmd;
             gmfn = req.ptr >> PAGE_SHIFT;
-            mfn = gmfn_to_mfn(pt_owner, gmfn);
+            mfn = mfn_x(gfn_to_mfn(pt_owner, gmfn, &p2mt));
+
+            if ( p2m_is_paged(p2mt) )
+            {
+                p2m_mem_paging_populate(pg_owner, gmfn);
+
+                rc = -ENOENT;
+                break;
+            }
 
             if ( unlikely(!get_page_from_pagenr(mfn, pt_owner)) )
             {
@@ -3109,6 +3120,22 @@ int do_mmu_update(
                 case PGT_l1_page_table:
                 {
                     l1_pgentry_t l1e = l1e_from_intpte(req.val);
+                    p2m_type_t l1e_p2mt;
+                    gfn_to_mfn(pg_owner, l1e_get_pfn(l1e), &l1e_p2mt);
+
+                    if ( p2m_is_paged(l1e_p2mt) )
+                    {
+                        p2m_mem_paging_populate(pg_owner, l1e_get_pfn(l1e));
+
+                        rc = -ENOENT;
+                        break;
+                    }
+                    else if ( p2m_ram_paging_in_start == l1e_p2mt )
+                    {
+                        rc = -ENOENT;
+                        break;
+                    }
+
                     okay = mod_l1_entry(va, l1e, mfn,
                                         cmd == MMU_PT_UPDATE_PRESERVE_AD, v,
                                         pg_owner);
@@ -3117,6 +3144,22 @@ int do_mmu_update(
                 case PGT_l2_page_table:
                 {
                     l2_pgentry_t l2e = l2e_from_intpte(req.val);
+                    p2m_type_t l2e_p2mt;
+                    gfn_to_mfn(pg_owner, l2e_get_pfn(l2e), &l2e_p2mt);
+
+                    if ( p2m_is_paged(l2e_p2mt) )
+                    {
+                        p2m_mem_paging_populate(pg_owner, l2e_get_pfn(l2e));
+
+                        rc = -ENOENT;
+                        break;
+                    }
+                    else if ( p2m_ram_paging_in_start == l2e_p2mt )
+                    {
+                        rc = -ENOENT;
+                        break;
+                    }
+
                     okay = mod_l2_entry(va, l2e, mfn,
                                         cmd == MMU_PT_UPDATE_PRESERVE_AD, v);
                 }
@@ -3124,6 +3167,22 @@ int do_mmu_update(
                 case PGT_l3_page_table:
                 {
                     l3_pgentry_t l3e = l3e_from_intpte(req.val);
+                    p2m_type_t l3e_p2mt;
+                    gfn_to_mfn(pg_owner, l3e_get_pfn(l3e), &l3e_p2mt);
+
+                    if ( p2m_is_paged(l3e_p2mt) )
+                    {
+                        p2m_mem_paging_populate(pg_owner, l3e_get_pfn(l3e));
+
+                        rc = -ENOENT;
+                        break;
+                    }
+                    else if ( p2m_ram_paging_in_start == l3e_p2mt )
+                    {
+                        rc = -ENOENT;
+                        break;
+                    }
+
                     rc = mod_l3_entry(va, l3e, mfn,
                                       cmd == MMU_PT_UPDATE_PRESERVE_AD, 1, v);
                     okay = !rc;
@@ -3133,6 +3192,22 @@ int do_mmu_update(
                 case PGT_l4_page_table:
                 {
                     l4_pgentry_t l4e = l4e_from_intpte(req.val);
+                    p2m_type_t l4e_p2mt;
+                    gfn_to_mfn(pg_owner, l4e_get_pfn(l4e), &l4e_p2mt);
+
+                    if ( p2m_is_paged(l4e_p2mt) )
+                    {
+                        p2m_mem_paging_populate(pg_owner, l4e_get_pfn(l4e));
+
+                        rc = -ENOENT;
+                        break;
+                    }
+                    else if ( p2m_ram_paging_in_start == l4e_p2mt )
+                    {
+                        rc = -ENOENT;
+                        break;
+                    }
+
                     rc = mod_l4_entry(va, l4e, mfn,
                                       cmd == MMU_PT_UPDATE_PRESERVE_AD, 1, v);
                     okay = !rc;
@@ -3159,7 +3234,8 @@ int do_mmu_update(
 
             unmap_domain_page_with_cache(va, &mapcache);
             put_page(page);
-            break;
+        }
+        break;
 
         case MMU_MACHPHYS_UPDATE: