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

Re: [PATCH v2 1/3] Capture Context->Request once per SyncWorker iteration


  • To: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>, "win-pv-devel@xxxxxxxxxxxxxxxxxxxx" <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Thu, 17 Sep 2026 13:36:11 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=o9lDiJ045fd0Odc43Y+mt+5EtI6b1+FCbkUUci9xDHE=; b=n33BgLlojiqky2n4x9Dl5vPOAQ5srXuib2MKV2gQyQaoagtGWnIJn68MzFZrSWQZwhh+Cm6eGmR4xlRnyUZL83/XTpAWo+bwvYk04wSVnSiZT1LJhQFJPaH+HCfsSDqQIiKBKbJKZ9r6LMSwlbnU5coraL/w11WwFe7tZOnr6JnAw7M7HY8006wDM/WMMCDznNYqg1HxV6+i+u81mi/9LL49kC5vtOFYZsVOtvfHIxoCb2oEJJAKoqja+TDI36j5sGlNjEdJa0SCQrv9FN2xOBF7c26NtBnLx8XVdnhKXuf8JnKDqZ76NX61toAfTo3ekeMcJK9E67LW46eoR9gBWA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=THFEWmA01z1eLC1e5y15lnJEvdK/aIYcQVcbPNZwaEebcYVAIvJeuamqzL7hLQ7wsGklqVrDo5fJwtcyz/YjBedcwHTC5V0OnnE47zxiARwjcfpulR9tUYxiHSBQDZi50hxwHwG25sWOk4xxGphpgoldqqHdXEaRs64ni6xL84lS+GTyz2LxbGZcpSwMPrzIFlkvClvFCBvsZf7vHIr3ecOuKrg86VRCfVKV/Ee1znyYIaMnjMHdJUz7vefialgbcufpBpjjl2nSr44S/ETRV9D04FcGNhFqmDLWyaBwzwWxKQh2uYAUChXSdCcZNm1BvlFavsIwN5hJqi96Ok8Cbw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Delivery-date: Thu, 17 Sep 2026 13:36:20 +0000
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>
  • Msip_labels:
  • Thread-index: AQHdRdfUJKgtfp96s0ycQZH053rW57bSx0HZ
  • Thread-topic: [PATCH v2 1/3] Capture Context->Request once per SyncWorker iteration

Reviewed-by: Owen Smith <owen.smith@xxxxxxxxxx>

________________________________________
From: win-pv-devel <win-pv-devel-bounces@xxxxxxxxxxxxxxxxxxxx> on behalf of Tu 
Dinh <ngoc-tu.dinh@xxxxxxxxxx>
Sent: 16 September 2026 1:34 PM
To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
Cc: Tu Dinh
Subject: [PATCH v2 1/3] Capture Context->Request once per SyncWorker iteration

Context->Request is a shared variable and so we must capture it instead
of rereading every time. Otherwise, this sequence will be possible:
* A synchronized action (e.g. __SyncProcessorDisableInterrupts)
  completes from the owner's viewpoint, but its worker has not finished
  updating Request = Context->Request yet;
* The owner sets Context->Request to something else;
* Request = Context->Request executes and sets Request to the wrong
  value.

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

diff --git a/src/xenbus/sync.c b/src/xenbus/sync.c
index eefa2fe..b416dbb 100644
--- a/src/xenbus/sync.c
+++ b/src/xenbus/sync.c
@@ -284,21 +284,22 @@ SyncWorker(

     Request = SYNC_REQUEST_NONE;
     for (;;) {
-        NTSTATUS status;
+        SYNC_REQUEST    Next;
+        NTSTATUS        status;

-        KeMemoryBarrier();
+        Next = ReadAcquire((LONG *)&Context->Request);

-        if (Context->Request == SYNC_REQUEST_EXIT)
+        if (Next == SYNC_REQUEST_EXIT)
             break;

-        if (Context->Request == Request) {
+        if (Next == Request) {
             _mm_pause();
             continue;
         }

         status = STATUS_SUCCESS;

-        switch (Context->Request) {
+        switch (Next) {
         case SYNC_REQUEST_DISABLE_INTERRUPTS:
             status = __SyncProcessorDisableInterrupts(&Irql);
             break;
@@ -321,7 +322,7 @@ SyncWorker(
         }

         if (NT_SUCCESS(status))
-            Request = Context->Request;
+            Request = Next;
     }

     ASSERT3U(KeGetCurrentIrql(), ==, DISPATCH_LEVEL);
--
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®.