[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/3] sync: Wait for interrupts to be disabled


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Date: Wed, 16 Sep 2026 14:35:19 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Cc: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Delivery-date: Wed, 16 Sep 2026 12:35:28 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Currently, SyncDisableInterrupts doesn't wait for _disable() to be
issued. So SuspendTrigger can issue a suspend before all CPUs have
actually reached a quiescent state.

In each worker, increment CompletionCount again after _disable(). Wait
for all sync workers to actually issue _disable() in
SyncDisableInterrupts by making sure that CompletionCount reaches 2x the
CPU count.

Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/xenbus/sync.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/xenbus/sync.c b/src/xenbus/sync.c
index b416dbb..5111310 100644
--- a/src/xenbus/sync.c
+++ b/src/xenbus/sync.c
@@ -170,7 +170,7 @@ __SyncProcessorDisableInterrupts(
     while (++Attempts <= 1000) {
         KeMemoryBarrier();
 
-        if (Context->CompletionCount == Context->ProcessorCount)
+        if (Context->CompletionCount >= Context->ProcessorCount)
             break;
 
         _mm_pause();
@@ -180,7 +180,7 @@ __SyncProcessorDisableInterrupts(
         Old = Context->CompletionCount;
         New = Old - 1;
 
-        if (Old == Context->ProcessorCount)
+        if (Old >= Context->ProcessorCount)
             break;
     } while (InterlockedCompareExchange(&Context->CompletionCount, New, Old) 
!= Old);
 
@@ -189,8 +189,10 @@ __SyncProcessorDisableInterrupts(
         status = STATUS_UNSUCCESSFUL;
     }
 
-    if (NT_SUCCESS(status))
+    if (NT_SUCCESS(status)) {
         _disable();
+        InterlockedIncrement(&Context->CompletionCount);
+    }
 
     return status;
 }
@@ -237,8 +239,8 @@ __SyncProcessorRunLate(
 }
 
 static FORCEINLINE VOID
-__SyncWait(
-    VOID
+__SyncWaitTarget(
+    LONG            Target
     )
 {
     PSYNC_CONTEXT   Context = &SyncContext;
@@ -246,13 +248,23 @@ __SyncWait(
     for (;;) {
         KeMemoryBarrier();
 
-        if (Context->CompletionCount == Context->ProcessorCount)
+        if (Context->CompletionCount == Target)
             break;
 
         _mm_pause();
     }
 }
 
+static FORCEINLINE VOID
+__SyncWait(
+    VOID
+    )
+{
+    PSYNC_CONTEXT   Context = &SyncContext;
+
+    __SyncWaitTarget(Context->ProcessorCount);
+}
+
 _Use_decl_annotations_
 VOID
 SyncWorker(
@@ -418,8 +430,10 @@ SyncDisableInterrupts(
     for (;;) {
         status = __SyncProcessorDisableInterrupts(Irql);
         _Analysis_assume_(NT_SUCCESS(status));
-        if (NT_SUCCESS(status))
+        if (NT_SUCCESS(status)) {
+            __SyncWaitTarget(2 * Context->ProcessorCount);
             return status;
+        }
 
         LogPrintf(LOG_LEVEL_WARNING, "SYNC: RE-TRY\n");
     }
-- 
2.55.0.windows.3



--
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.