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

[PATCH v2 07/10] granter: Introduce GranterD0ToD3/D3ToD0


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

XenBus requires all gnttab references to be dropped before hibernation;
otherwise, FdoS3ToS4 will crash. Since the granter cache can now outlive
a disconnect if there are outstanding grants, release it on D0->D3 at
the latest.

Nothing defers grant revocation yet, so Current is always zero there for
now.

Assisted-by: LLM
Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/xenvbd/frontend.c | 11 +++++++++--
 src/xenvbd/frontend.h |  4 ++--
 src/xenvbd/granter.c  | 41 +++++++++++++++++++++++++++++++++--------
 src/xenvbd/granter.h  | 12 ++++++++++++
 4 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/src/xenvbd/frontend.c b/src/xenvbd/frontend.c
index 8bf4f96..442e188 100644
--- a/src/xenvbd/frontend.c
+++ b/src/xenvbd/frontend.c
@@ -1669,7 +1669,7 @@ FrontendDebugCallback(
 }
 
 _Check_return_
-_IRQL_requires_max_(DISPATCH_LEVEL)
+_IRQL_requires_(PASSIVE_LEVEL)
 NTSTATUS
 FrontendD3ToD0(
     _Inout_ PXENVBD_FRONTEND    Frontend
@@ -1679,6 +1679,8 @@ FrontendD3ToD0(
     KIRQL                       Irql;
     NTSTATUS                    status;
 
+    GranterD3ToD0(Frontend->Granter);
+
     KeAcquireSpinLock(&Frontend->StateLock, &Irql);
 
     AdapterGetStoreInterface(Adapter, &Frontend->StoreInterface);
@@ -1746,10 +1748,13 @@ fail1:
                   sizeof(XENBUS_STORE_INTERFACE));
 
     KeReleaseSpinLock(&Frontend->StateLock, Irql);
+
+    GranterD0ToD3(Frontend->Granter);
+
     return status;
 }
 
-_IRQL_requires_max_(DISPATCH_LEVEL)
+_IRQL_requires_(PASSIVE_LEVEL)
 VOID
 FrontendD0ToD3(
     _Inout_ PXENVBD_FRONTEND    Frontend
@@ -1787,6 +1792,8 @@ FrontendD0ToD3(
                   sizeof(XENBUS_STORE_INTERFACE));
 
     KeReleaseSpinLock(&Frontend->StateLock, Irql);
+
+    GranterD0ToD3(Frontend->Granter);
 }
 
 _Check_return_
diff --git a/src/xenvbd/frontend.h b/src/xenvbd/frontend.h
index 8b0ad8c..3b43950 100644
--- a/src/xenvbd/frontend.h
+++ b/src/xenvbd/frontend.h
@@ -116,13 +116,13 @@ FrontendSetDeviceUsage(
     );
 
 _Check_return_
-_IRQL_requires_max_(DISPATCH_LEVEL)
+_IRQL_requires_(PASSIVE_LEVEL)
 extern NTSTATUS
 FrontendD3ToD0(
     _Inout_ PXENVBD_FRONTEND    Frontend
     );
 
-_IRQL_requires_max_(DISPATCH_LEVEL)
+_IRQL_requires_(PASSIVE_LEVEL)
 extern VOID
 FrontendD0ToD3(
     _Inout_ PXENVBD_FRONTEND    Frontend
diff --git a/src/xenvbd/granter.c b/src/xenvbd/granter.c
index 6adc578..7b7a7c8 100644
--- a/src/xenvbd/granter.c
+++ b/src/xenvbd/granter.c
@@ -111,14 +111,7 @@ GranterDestroy(
     )
 {
     BUG_ON(Granter->Current != 0);
-
-    if (Granter->Cache != NULL) {
-        KIRQL   Irql;
-
-        KeRaiseIrql(DISPATCH_LEVEL, &Irql);
-        __GranterDestroyCache(Granter);
-        KeLowerIrql(Irql);
-    }
+    ASSERT3P(Granter->Cache, ==, NULL);
 
     Granter->Frontend = NULL;
     RtlZeroMemory(&Granter->Lock, sizeof(KSPIN_LOCK));
@@ -367,6 +360,38 @@ GranterDisconnect(
     __GranterDestroyCache(Granter);
 }
 
+_IRQL_requires_(PASSIVE_LEVEL)
+VOID
+GranterD3ToD0(
+    _Inout_ PXENVBD_GRANTER Granter
+    )
+{
+    ASSERT3P(Granter->Cache, ==, NULL);
+    ASSERT3S(Granter->Current, ==, 0);
+}
+
+_IRQL_requires_(PASSIVE_LEVEL)
+VOID
+GranterD0ToD3(
+    _Inout_ PXENVBD_GRANTER Granter
+    )
+{
+    KIRQL                   Irql;
+
+    ASSERT(!Granter->Connected);
+
+    // All grants must be revoked before transitioning to S3.
+
+    BUG_ON(Granter->Current != 0);
+
+    if (Granter->Cache == NULL)
+        return;
+
+    KeRaiseIrql(DISPATCH_LEVEL, &Irql);
+    __GranterDestroyCache(Granter);
+    KeLowerIrql(Irql);
+}
+
 NTSTATUS
 GranterGet(
     _Inout_ PXENVBD_GRANTER Granter,
diff --git a/src/xenvbd/granter.h b/src/xenvbd/granter.h
index e609a8a..93b962c 100644
--- a/src/xenvbd/granter.h
+++ b/src/xenvbd/granter.h
@@ -50,6 +50,18 @@ GranterDestroy(
     _Inout_ PXENVBD_GRANTER Granter
     );
 
+_IRQL_requires_(PASSIVE_LEVEL)
+extern VOID
+GranterD3ToD0(
+    _Inout_ PXENVBD_GRANTER Granter
+    );
+
+_IRQL_requires_(PASSIVE_LEVEL)
+extern VOID
+GranterD0ToD3(
+    _Inout_ PXENVBD_GRANTER Granter
+    );
+
 extern NTSTATUS
 GranterConnect(
     _Inout_ PXENVBD_GRANTER Granter
-- 
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®.