]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
x86/mm: Remove unnecessary mfn_valid() call from get_page_from_l1e()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 27 Apr 2022 13:43:28 +0000 (14:43 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 18 May 2022 14:05:18 +0000 (15:05 +0100)
mfn_valid() is not a trivially simple, and contains an evaluate_nospec() for
speculative defence.  Avoid calling it redundantly, and just store the result
of the first call.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/mm.c

index 67c04279632cd8014cb13525281b1d23fb4dc96a..796faca64103440aefe4ba617f378383f318a3c2 100644 (file)
@@ -887,7 +887,7 @@ get_page_from_l1e(
     uint32_t l1f = l1e_get_flags(l1e);
     struct vcpu *curr = current;
     struct domain *real_pg_owner;
-    bool write;
+    bool write, valid;
 
     if ( unlikely(!(l1f & _PAGE_PRESENT)) )
     {
@@ -902,13 +902,15 @@ get_page_from_l1e(
         return -EINVAL;
     }
 
-    if ( !mfn_valid(_mfn(mfn)) ||
+    valid = mfn_valid(_mfn(mfn));
+
+    if ( !valid ||
          (real_pg_owner = page_get_owner_and_reference(page)) == dom_io )
     {
         int flip = 0;
 
         /* Only needed the reference to confirm dom_io ownership. */
-        if ( mfn_valid(_mfn(mfn)) )
+        if ( valid )
             put_page(page);
 
         /* DOMID_IO reverts to caller for privilege checks. */