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

[PATCH v2 02/10] granter: Correct the accounting of Current


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Date: Wed, 28 Oct 2026 18:18:32 +0100
  • 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, 28 Oct 2026 17:19:00 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Current serves as an upper bound on the number of taken grants and must
be 0 on GranterDisconnect. We must increment Current before calling
PermitForeignAccess, and decrement it again on failure.

Assisted-by: LLM
Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/xenvbd/granter.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/xenvbd/granter.c b/src/xenvbd/granter.c
index fd90965..eddcdcf 100644
--- a/src/xenvbd/granter.c
+++ b/src/xenvbd/granter.c
@@ -319,7 +319,9 @@ GranterGet(
     if (Granter->Connected == FALSE)
         goto fail1;
 
-    status = XENBUS_GNTTAB(PermitForeignAccess, 
+    Value = InterlockedIncrement(&Granter->Current);
+
+    status = XENBUS_GNTTAB(PermitForeignAccess,
                            &Granter->GnttabInterface,
                            Granter->Cache,
                            FALSE,
@@ -329,8 +331,7 @@ GranterGet(
                            &Entry);
     if (!NT_SUCCESS(status))
         goto fail2;
-    
-    Value = InterlockedIncrement(&Granter->Current);
+
     if (Value > Granter->Maximum)
         Granter->Maximum = Value;
 
@@ -339,6 +340,7 @@ GranterGet(
 
 fail2:
     Error("fail2\n");
+    InterlockedDecrement(&Granter->Current);
 fail1:
     Error("fail1 %08x\n", status);
     return status;
-- 
2.56.0.windows.4



--
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®.