Skip to contentSkip to conversation

x86/PV: fold exit paths of ptwr_do_page_fault()

PATCH In review Jan Beulich 2 participants 2 messages Sep 11, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/PV: fold exit paths of ptwr_do_page_fault()

One less aspect to keep an eye on for things to stay in sync.

---
FAOD I did consider (and even try) reducing the scope of ptwr_ctxt at the same occasion - this results in worse code with gcc 10 at least, as the compiler then indeed defers populating of the struct, and hence needs to retain the respective function arguments across prior calls.

xen/arch/x86/pv/ro-page-fault.c +7 -13
@@ -262,29 +262,23 @@ static int ptwr_do_page_fault(struct x86
         .pte = pte,
     };
     struct page_info *page;
-    int rc;
+    int rc = X86EMUL_UNHANDLEABLE;
 
     page = get_page_from_mfn(l1e_get_mfn(pte), current->domain);
     if ( !page )
         return X86EMUL_UNHANDLEABLE;
 
-    if ( !page_lock(page) )
+    if ( page_lock(page) )
     {
-        put_page(page);
-        return X86EMUL_UNHANDLEABLE;
-    }
+        if ( (page->u.inuse.type_info & PGT_type_mask) == PGT_l1_page_table )
+        {
+            ctxt->data = &ptwr_ctxt;
+            rc = x86_emulate(ctxt, &ptwr_emulate_ops);
+        }
 
-    if ( (page->u.inuse.type_info & PGT_type_mask) != PGT_l1_page_table )
-    {
         page_unlock(page);
-        put_page(page);
-        return X86EMUL_UNHANDLEABLE;
     }
 
-    ctxt->data = &ptwr_ctxt;
-    rc = x86_emulate(ctxt, &ptwr_emulate_ops);
-
-    page_unlock(page);
     put_page(page);
 
     return rc;