The current hook placement in domain_{,un}pause() calls arch_domain_pause()
unconditionally, regardless of whether the domain is already paused or not
unpaused (so no state change).  However the underlying Viridian unpause
function (time_ref_count_thaw()) expects the call to only be done once
there's a transition from paused to active.

Adjust the calling of arch_domain_{,un}pause() so it's only done for state
changes, to accommodate for the behavior expected by the Viridian hooks.
Note there are no other implementations of arch_domain_{,un}pause() apart
from the Viridian use cases, and hence the change is non-functional for all
other architectures (or for x86 if Viridian is disabled).

Fixes: f6a07643e1cc ('x86/viridian: freeze time reference counter when domain 
is paused')
Signed-off-by: Roger Pau MonnĂ© <[email protected]>
---
 xen/common/domain.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 3b6e9471c413..e0ca71a53bc1 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1547,8 +1547,7 @@ int vcpu_unpause_by_systemcontroller(struct vcpu *v)
 static void _domain_pause(struct domain *d, bool sync)
 {
     struct vcpu *v;
-
-    atomic_inc(&d->pause_count);
+    bool was_paused = atomic_inc_return(&d->pause_count) - 1;
 
     if ( sync )
         for_each_vcpu ( d, v )
@@ -1557,7 +1556,8 @@ static void _domain_pause(struct domain *d, bool sync)
         for_each_vcpu ( d, v )
             vcpu_sleep_nosync(v);
 
-    arch_domain_pause(d);
+    if ( !was_paused )
+        arch_domain_pause(d);
 }
 
 void domain_pause(struct domain *d)
@@ -1575,11 +1575,12 @@ void domain_unpause(struct domain *d)
 {
     struct vcpu *v;
 
-    arch_domain_unpause(d);
-
     if ( atomic_dec_and_test(&d->pause_count) )
+    {
+        arch_domain_unpause(d);
         for_each_vcpu( d, v )
             vcpu_wake(v);
+    }
 }
 
 static int _domain_pause_by_systemcontroller(struct domain *d, bool sync)
-- 
2.51.0


Reply via email to