diff mbox series

[11/12] x86/mm: pull a sanity check earlier in xenmem_add_to_physmap_one()

Message ID e0819038-98b0-2c4c-9176-70d68be39130@suse.com (mailing list archive)
State Superseded
Headers show
Series x86: more or less log-dirty related improvements | expand

Commit Message

Jan Beulich June 25, 2021, 1:22 p.m. UTC
We should try to limit the failure reasons after we've started making
changes.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

Comments

Andrew Cooper June 25, 2021, 7:10 p.m. UTC | #1
On 25/06/2021 14:22, Jan Beulich wrote:
> We should try to limit the failure reasons after we've started making
> changes.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
diff mbox series

Patch

--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -2763,6 +2763,15 @@  int xenmem_add_to_physmap_one(
         goto put_both;
     }
 
+    /* XENMAPSPACE_gmfn: Check if the MFN is associated with another GFN. */
+    old_gpfn = get_gpfn_from_mfn(mfn_x(mfn));
+    ASSERT(!SHARED_M2P(old_gpfn));
+    if ( space == XENMAPSPACE_gmfn && old_gpfn != gfn )
+    {
+        rc = -EXDEV;
+        goto put_both;
+    }
+
     /* Remove previously mapped page if it was present. */
     prev_mfn = get_gfn(d, gfn_x(gpfn), &p2mt);
     if ( mfn_valid(prev_mfn) )
@@ -2781,13 +2790,6 @@  int xenmem_add_to_physmap_one(
         goto put_both;
 
     /* Unmap from old location, if any. */
-    old_gpfn = get_gpfn_from_mfn(mfn_x(mfn));
-    ASSERT(!SHARED_M2P(old_gpfn));
-    if ( space == XENMAPSPACE_gmfn && old_gpfn != gfn )
-    {
-        rc = -EXDEV;
-        goto put_both;
-    }
     if ( old_gpfn != INVALID_M2P_ENTRY )
         rc = guest_physmap_remove_page(d, _gfn(old_gpfn), mfn, PAGE_ORDER_4K);