Skip to contentSkip to conversation

Avoid premature update of M2P in set_typed_p2m_entry

PATCH In review Mukesh Rathor 3 participants 3 messages Jun 5, 2014 – Jun 6, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid premature update of M2P in set_typed_p2m_entry

Update M2P for ram type after p2m_set_entry call has been made and is successful.

---
 xen/arch/x86/mm/p2m.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
xen/arch/x86/mm/p2m.c +5 -5
index b50747a..20272dc 100644
@@ -818,11 +818,6 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
         domain_crash(d);
         return -ENOENT;
     }
-    else if ( p2m_is_ram(ot) )
-    {
-        ASSERT(mfn_valid(omfn));
-        set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
-    }
 
     P2M_DEBUG("set %d %lx %lx\n", gfn_p2mt, gfn, mfn_x(mfn));
     rc = p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, gfn_p2mt,
@@ -832,6 +827,11 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
         gdprintk(XENLOG_ERR,
                  "p2m_set_entry failed! mfn=%08lx rc:%d\n",
                  mfn_x(get_gfn_query_unlocked(p2m->domain, gfn, &ot)), rc);
+    else if ( p2m_is_ram(ot) )
+    {
+        ASSERT(mfn_valid(omfn));
+        set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
+    }
     return rc;
 }
 
Signature · 1 line
1.8.3.1
#1 lore raw

xen/arch/x86/mm/p2m.c static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn, · line 834

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 06.06.14 at 00:55, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +5 -0
@@ -832,6 +827,11 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
         gdprintk(XENLOG_ERR,
                  "p2m_set_entry failed! mfn=%08lx rc:%d\n",
                  mfn_x(get_gfn_query_unlocked(p2m->domain, gfn, &ot)), rc);
+    else if ( p2m_is_ram(ot) )
+    {
+        ASSERT(mfn_valid(omfn));
+        set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
+    }

The only possible concern here is that all other code paths in p2m.c do the M2P updates under lock. Tim - is that a requirement (formally the M2P isn't really considered serialized by P2M locking I think)? Yet then again, even if it isn't, the placement here might sooner or later result in a Coverity warning (recognizing that all other paths do the update with a lock held)...

Jan

#2 lore raw
Quoted 17 lines · Jan Beulich

xen/arch/x86/mm/p2m.c static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn, · line 834

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 06.06.14 at 00:55, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +5 -0
@@ -832,6 +827,11 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
         gdprintk(XENLOG_ERR,
                  "p2m_set_entry failed! mfn=%08lx rc:%d\n",
                  mfn_x(get_gfn_query_unlocked(p2m->domain, gfn, &ot)), rc);
+    else if ( p2m_is_ram(ot) )
+    {
+        ASSERT(mfn_valid(omfn));
+        set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
+    }

The only possible concern here is that all other code paths in p2m.c do the M2P updates under lock. Tim - is that a requirement (formally the M2P isn't really considered serialized by P2M locking I think)? Yet then again, even if it isn't, the placement here might sooner or later result in a Coverity warning (recognizing that all other paths do the update with a lock held)...

No, the m2p isn't covered by the p2m lock, but it might be as well to do so in this case anyway, to avoid worrying about race conditions between two invocations of this code.

Tim.