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

[PATCH] stream: Guard against failure to acquire ConsoleInterface


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Date: Mon, 2 Nov 2026 12:23:27 +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:Feedback-ID"
  • Cc: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Delivery-date: Mon, 02 Nov 2026 11:23:34 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

If console access is not enabled in XenBus (e.g. via UseConsole or
similar), console IRPs will block forever during reads and writes until
canceled. We should rather explicitly signal instead that the console is
not available.

Add a Stream->Failed flag that denies all incoming IRPs if
ConsoleAcquire failed. This must be done in StreamCsqInsertIrpEx to
avoid racing with the worker setting Failed = TRUE.

Because this flag deals with new IRPs, already-queued IRPs at the time
the worker fails need to be completed manually with an error code.

Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/xencons/stream.c | 52 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 46 insertions(+), 6 deletions(-)

diff --git a/src/xencons/stream.c b/src/xencons/stream.c
index 8760e7e..421fc42 100644
--- a/src/xencons/stream.c
+++ b/src/xencons/stream.c
@@ -43,12 +43,13 @@
 #define STREAM_POOL 'ETRS'
 
 struct _XENCONS_STREAM {
-    PXENCONS_FDO               Fdo;
-    PXENCONS_THREAD            Thread;
-    IO_CSQ                     Csq;
-    LIST_ENTRY                 List;
-    KSPIN_LOCK                 Lock;
-    XENBUS_CONSOLE_INTERFACE   ConsoleInterface;
+    PXENCONS_FDO                Fdo;
+    PXENCONS_THREAD             Thread;
+    IO_CSQ                      Csq;
+    LIST_ENTRY                  List;
+    KSPIN_LOCK                  Lock;
+    XENBUS_CONSOLE_INTERFACE    ConsoleInterface;
+    BOOLEAN                     Failed;
 };
 
 static FORCEINLINE PVOID
@@ -78,9 +79,14 @@ StreamCsqInsertIrpEx(
 {
     BOOLEAN             ReInsert = (BOOLEAN)(ULONG_PTR)InsertContext;
     PXENCONS_STREAM     Stream;
+    NTSTATUS            status;
 
     Stream = CONTAINING_RECORD(Csq, XENCONS_STREAM, Csq);
 
+    status = STATUS_UNSUCCESSFUL;
+    if (Stream->Failed)
+        goto fail1;
+
     if (ReInsert) {
         // This only occurs if the worker thread de-queued the IRP but
         // then found the console to be blocked.
@@ -91,6 +97,11 @@ StreamCsqInsertIrpEx(
     }
 
     return STATUS_SUCCESS;
+
+fail1:
+    Trace("fail1 (%08x)\n", status);
+
+    return status;
 }
 
 IO_CSQ_REMOVE_IRP StreamCsqRemoveIrp;
@@ -206,6 +217,7 @@ StreamWorker(
     PXENCONS_STREAM         Stream = Context;
     PKEVENT                 Event;
     PXENBUS_CONSOLE_WAKEUP  Wakeup;
+    KIRQL                   Irql;
     NTSTATUS                status;
 
     Trace("====>\n");
@@ -344,6 +356,32 @@ fail2:
 fail1:
     Error("fail1 (%08x)\n", status);
 
+    KeAcquireSpinLock(&Stream->Lock, &Irql);
+    Stream->Failed = TRUE;
+    KeReleaseSpinLock(&Stream->Lock, Irql);
+
+    for (;;) {
+        PIRP                Irp;
+        PIO_STACK_LOCATION  StackLocation;
+        UCHAR               MajorFunction;
+
+        Irp = IoCsqRemoveNextIrp(&Stream->Csq, NULL);
+        if (Irp == NULL)
+            break;
+
+        StackLocation = IoGetCurrentIrpStackLocation(Irp);
+        MajorFunction = StackLocation->MajorFunction;
+
+        Irp->IoStatus.Information = 0;
+        Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
+
+        Trace("FAILED (%02x:%s)\n",
+              MajorFunction,
+              MajorFunctionName(MajorFunction));
+
+        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    }
+
     return status;
 }
 
@@ -432,6 +470,8 @@ StreamDestroy(
     }
     ASSERT(IsListEmpty(&Stream->List));
 
+    Stream->Failed = FALSE;
+
     RtlZeroMemory(&Stream->Csq, sizeof (IO_CSQ));
 
     RtlZeroMemory(&Stream->List, sizeof (LIST_ENTRY));
-- 
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®.