diff mbox series

x86/PV: fold exit paths of ptwr_do_page_fault()

Message ID 839f005e-e36a-14be-c2bb-83cb999e783b@suse.com
State New
Headers show
Series x86/PV: fold exit paths of ptwr_do_page_fault() | expand

Commit Message

Jan Beulich Sept. 11, 2020, 10:35 a.m. UTC
One less aspect to keep an eye on for things to stay in sync.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
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.

Comments

Andrew Cooper Sept. 11, 2020, 11:35 a.m. UTC | #1
On 11/09/2020 11:35, Jan Beulich wrote:
> One less aspect to keep an eye on for things to stay in sync.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

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

Patch

--- a/xen/arch/x86/pv/ro-page-fault.c
+++ b/xen/arch/x86/pv/ro-page-fault.c
@@ -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;