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

[win-pv-devel] [PATCH 1/2] Make sure AdapterInitialize is called at PASSIVE_LEVEL



AdapterHwFindAdapter() can be called at DISPATCH_LEVEL and therefore it
is not safe to call AdapterInitialize() directly from there.

This patch, instead, calls StorPortEnablePassiveInitialization() from
AdapterHwInitialize() to request a PASSIVE_LEVEL initialization routine
is called immediately after AdapterHwFindAdapter() so that
AdapterInitialize() can be called from there.

Suggested-by: Owen Smith <owen.smith@xxxxxxxxxx>
Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenvbd/adapter.c | 57 ++++++++++++++++++++++++++++++++++------------------
 src/xenvbd/driver.c  |  1 +
 src/xenvbd/driver.h  |  1 +
 3 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/src/xenvbd/adapter.c b/src/xenvbd/adapter.c
index 577bfdf..a4220d1 100644
--- a/src/xenvbd/adapter.c
+++ b/src/xenvbd/adapter.c
@@ -1095,6 +1095,7 @@ AdapterDevicePowerThread(
     return STATUS_SUCCESS;
 }
 
+__drv_requiresIRQL(PASSIVE_LEVEL)
 static NTSTATUS
 __AdapterQueryInterface(
     IN  PXENVBD_ADAPTER Adapter,
@@ -1174,6 +1175,8 @@ fail1:
                             (PINTERFACE)(_itf),                 \
                             sizeof( ## _name ## _INTERFACE),    \
                             (_opt))
+
+__drv_requiresIRQL(PASSIVE_LEVEL)
 static NTSTATUS
 AdapterInitialize(
     IN  PXENVBD_ADAPTER Adapter,
@@ -1916,12 +1919,7 @@ AdapterHwFindAdapter(
     OUT PBOOLEAN                            Again
     )
 {
-    PXENVBD_ADAPTER                         Adapter = DevExt;
-    PDEVICE_OBJECT                          DeviceObject;
-    PDEVICE_OBJECT                          PhysicalDeviceObject;
-    PDEVICE_OBJECT                          LowerDeviceObject;
-    NTSTATUS                                status;
-
+    UNREFERENCED_PARAMETER(DevExt);
     UNREFERENCED_PARAMETER(Context);
     UNREFERENCED_PARAMETER(BusInformation);
     UNREFERENCED_PARAMETER(ArgumentString);
@@ -1948,36 +1946,57 @@ AdapterHwFindAdapter(
     // We need to do this to avoid an assertion in a checked kernel
     (VOID) StorPortGetUncachedExtension(DevExt, ConfigInfo, PAGE_SIZE);
 
-    (VOID) StorPortGetDeviceObjects(DevExt,
-                                    &DeviceObject,
-                                    &PhysicalDeviceObject,
-                                    &LowerDeviceObject);
-    if (Adapter->DeviceObject == DeviceObject)
-        return SP_RETURN_FOUND;
+    return SP_RETURN_FOUND;
+}
+
+HW_PASSIVE_INITIALIZE_ROUTINE AdapterHwPassiveInitialize;
+
+BOOLEAN
+AdapterHwPassiveInitialize(
+    IN  PVOID   DevExt
+    )
+{
+    PXENVBD_ADAPTER Adapter = DevExt;
+    PDEVICE_OBJECT  DeviceObject;
+    PDEVICE_OBJECT  PhysicalDeviceObject;
+    PDEVICE_OBJECT  LowerDeviceObject;
+    NTSTATUS        status;
+
+    if (StorPortGetDeviceObjects(DevExt,
+                                 &DeviceObject,
+                                 &PhysicalDeviceObject,
+                                 &LowerDeviceObject) != STOR_STATUS_SUCCESS)
+        goto fail1;
 
     status = AdapterInitialize(Adapter,
                                DeviceObject,
                                PhysicalDeviceObject,
                                LowerDeviceObject);
     if (!NT_SUCCESS(status))
-        goto fail1;
+        goto fail2;
 
     AdapterUnplugRequest(Adapter, TRUE);
 
     status = AdapterD3ToD0(Adapter);
     if (!NT_SUCCESS(status))
-        goto fail2;
+        goto fail3;
 
     DriverSetAdapter(Adapter);
-    return SP_RETURN_FOUND;
+    return TRUE;
 
-fail2:
+fail3:
     Error("fail2\n");
+
     AdapterUnplugRequest(Adapter, FALSE);
     AdapterTeardown(Adapter);
+
+fail2:
+    Error("fail2\n");
+
 fail1:
     Error("fail1\n");
-    return SP_RETURN_ERROR;
+
+    return FALSE;
 }
 
 HW_INITIALIZE   AdapterHwInitialize;
@@ -1987,8 +2006,8 @@ AdapterHwInitialize(
     IN  PVOID   DevExt
     )
 {
-    UNREFERENCED_PARAMETER(DevExt);
-    return TRUE;
+    return StorPortEnablePassiveInitialization(DevExt,
+                                               AdapterHwPassiveInitialize);
 }
 
 HW_INTERRUPT    AdapterHwInterrupt;
diff --git a/src/xenvbd/driver.c b/src/xenvbd/driver.c
index 6ed865e..62c3cbb 100644
--- a/src/xenvbd/driver.c
+++ b/src/xenvbd/driver.c
@@ -105,6 +105,7 @@ DriverDispatchPower(
 
 #define MAXNAMELEN  256
 
+__drv_requiresIRQL(PASSIVE_LEVEL)
 VOID
 DriverRequestReboot(
     VOID
diff --git a/src/xenvbd/driver.h b/src/xenvbd/driver.h
index 343a7fe..386cd84 100644
--- a/src/xenvbd/driver.h
+++ b/src/xenvbd/driver.h
@@ -61,6 +61,7 @@ DriverDispatchPower(
     IN  PIRP            Irp
     );
 
+__drv_requiresIRQL(PASSIVE_LEVEL)
 extern VOID
 DriverRequestReboot(
     VOID
-- 
2.5.3


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

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