[PATCH v15 02/10] x86/shadow: blow away tables first when tearing down

Jan Beulich <[email protected]> Tue, 28 Jul 2026 16:20:51 +0200
Newsgroups gmane.comp.emulators.xen.devel
Message-ID <[email protected]>
With shadow_blow_tables() but not sh_detach_old_tables() (called by
shadow_vcpu_teardown()) being preemptable, move the invocation of the
former ahead. This way future finer grained preemption checks applied
to shadow_blow_tables() will further benefit teardown behavior.

Signed-off-by: Jan Beulich <[email protected]>
Acked-by: Roger Pau MonnĂ© <[email protected]>
---
v13: New.

--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -2279,6 +2279,17 @@ void shadow_teardown(struct domain *d, b
     ASSERT(d->is_dying);
     ASSERT(d != current->domain);
 
+    /*
+     * Reclaim all shadow memory so that shadow_set_allocation() doesn't find
+     * in-use pages, as _shadow_prealloc() will no longer try to reclaim pages
+     * because the domain is dying.
+     */
+    paging_lock(d);
+    shadow_blow_tables(d, preempted);
+    paging_unlock(d);
+    if ( preempted && *preempted )
+        return;
+
     /* TODO - Remove when the teardown path is better structured. */
     for_each_vcpu ( d, v )
         shadow_vcpu_teardown(v);
@@ -2289,15 +2300,6 @@ void shadow_teardown(struct domain *d, b
 
     paging_lock(d);
 
-    /*
-     * Reclaim all shadow memory so that shadow_set_allocation() doesn't find
-     * in-use pages, as _shadow_prealloc() will no longer try to reclaim pages
-     * because the domain is dying.
-     */
-    shadow_blow_tables(d, preempted);
-    if ( preempted && *preempted )
-        goto out;
-
 #if (SHADOW_OPTIMIZATIONS & (SHOPT_VIRTUAL_TLB|SHOPT_OUT_OF_SYNC))
     /* Free the virtual-TLB array attached to each vcpu */
     for_each_vcpu(d, v)