x86/shadow: adjust TLB flushing in sh_unshadow_for_p2m_change()
authorJan Beulich <jbeulich@suse.com>
Fri, 8 Jan 2021 15:51:19 +0000 (16:51 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 8 Jan 2021 15:51:19 +0000 (16:51 +0100)
Accumulating transient state of d->dirty_cpumask in a local variable is
unnecessary here: The flush is fine to make with the dirty set at the
time of the call. With this, move the invocation to a central place at
the end of the function.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Tim Deegan <tim@xen.org>
xen/arch/x86/mm/shadow/common.c

index d09c9405855cafcd2241a9e882aed53f152d37cd..df95c4db11d61607110a6e87a9cdd07aaa73f64b 100644 (file)
@@ -3092,6 +3092,7 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn,
     mfn_t omfn = l1e_get_mfn(old);
     unsigned int oflags = l1e_get_flags(old);
     p2m_type_t p2mt = p2m_flags_to_type(oflags);
+    bool flush = false;
 
     /*
      * If there are any shadows, update them.  But if shadow_teardown()
@@ -3116,7 +3117,7 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn,
         {
             sh_remove_all_shadows_and_parents(d, omfn);
             if ( sh_remove_all_mappings(d, omfn, _gfn(gfn)) )
-                guest_flush_tlb_mask(d, d->dirty_cpumask);
+                flush = true;
         }
         break;
 
@@ -3132,12 +3133,9 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn,
         if ( p2m_is_valid(p2mt) && mfn_valid(omfn) )
         {
             unsigned int i;
-            cpumask_t flushmask;
             mfn_t nmfn = l1e_get_mfn(new);
             l1_pgentry_t *npte = NULL;
 
-            cpumask_clear(&flushmask);
-
             /* If we're replacing a superpage with a normal L1 page, map it */
             if ( (l1e_get_flags(new) & _PAGE_PRESENT) &&
                  !(l1e_get_flags(new) & _PAGE_PSE) &&
@@ -3155,11 +3153,10 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn,
                     /* This GFN->MFN mapping has gone away */
                     sh_remove_all_shadows_and_parents(d, omfn);
                     if ( sh_remove_all_mappings(d, omfn, _gfn(gfn + i)) )
-                        cpumask_or(&flushmask, &flushmask, d->dirty_cpumask);
+                        flush = true;
                 }
                 omfn = mfn_add(omfn, 1);
             }
-            guest_flush_tlb_mask(d, &flushmask);
 
             if ( npte )
                 unmap_domain_page(npte);
@@ -3167,6 +3164,9 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn,
 
         break;
     }
+
+    if ( flush )
+        guest_flush_tlb_mask(d, d->dirty_cpumask);
 }
 
 #if (SHADOW_OPTIMIZATIONS & SHOPT_FAST_FAULT_PATH)