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

[win-pv-devel] [PATCH] Don't veto everything on InitSafeModeMode



In safe mode we want to fall back to using emulated devices (which have
in-box drivers) just in case there is a problem using PV devices. However,
the current scheme of bailing very early in DriverEntry() hence not
supplying an AddDevice() entry point, hence not creating any FDOs and hence
no PDOs is problematic. This is because, when no child FDOs are created,
un-installing a child driver does not invoke the child driver co-installer
and thus cleanup, such as removing unplug registry keys, does not occur.
This then leads to a potential 0x7B BSOD on reboot if XENVBD was removed in
safe mode.

This patch gets rid of the global veto and instead simply vetoes unplug of
emulated devices. This should be sufficient for other PV drivers to
deactivate and let Windows use the emulated devices, but won't get in the
way of normal driver un-install behaviour.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xen/driver.c     | 23 +++++++++++++----------
 src/xenbus/driver.c  |  9 ---------
 src/xenfilt/driver.c | 22 ++++++++++++----------
 3 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/src/xen/driver.c b/src/xen/driver.c
index adc1a00..6119c7c 100644
--- a/src/xen/driver.c
+++ b/src/xen/driver.c
@@ -49,8 +49,6 @@
 #include "assert.h"
 #include "version.h"
 
-extern PULONG   InitSafeBootMode;
-
 typedef struct _XEN_DRIVER {
     PLOG_DISPOSITION    TraceDisposition;
     PLOG_DISPOSITION    InfoDisposition;
@@ -60,6 +58,16 @@ typedef struct _XEN_DRIVER {
 
 static XEN_DRIVER   Driver;
 
+extern PULONG   InitSafeBootMode;
+
+static FORCEINLINE BOOLEAN
+__DriverSafeMode(
+    VOID
+    )
+{
+    return (*InitSafeBootMode > 0) ? TRUE : FALSE;
+}
+
 static FORCEINLINE VOID
 __DriverSetUnplugKey(
     IN  HANDLE  Key
@@ -202,9 +210,6 @@ DllInitialize(
 
     Trace("====>\n");
 
-    if (*InitSafeBootMode > 0)
-        goto done;
-
     status = LogInitialize();
     if (!NT_SUCCESS(status))
         goto fail1;
@@ -234,6 +239,9 @@ DllInitialize(
          MONTH,
          YEAR);
 
+    if (__DriverSafeMode())
+        Info("SAFE MODE\n");
+
     status = RegistryInitialize(RegistryPath);
     if (!NT_SUCCESS(status))
         goto fail2;
@@ -290,7 +298,6 @@ DllInitialize(
 
     RegistryCloseKey(ServiceKey);
 
-done:
     Trace("<====\n");
 
     return STATUS_SUCCESS;
@@ -376,9 +383,6 @@ DllUnload(
 
     Trace("====>\n");
 
-    if (*InitSafeBootMode > 0)
-        goto done;
-
     UnplugTeardown();
 
     ProcessTeardown();
@@ -420,7 +424,6 @@ DllUnload(
 
     LogTeardown();
 
-done:
     ASSERT(IsZeroMemory(&Driver, sizeof (XEN_DRIVER)));
 
     Trace("<====\n");
diff --git a/src/xenbus/driver.c b/src/xenbus/driver.c
index cd22a72..24f06f5 100644
--- a/src/xenbus/driver.c
+++ b/src/xenbus/driver.c
@@ -45,8 +45,6 @@
 #include "util.h"
 #include "version.h"
 
-extern PULONG       InitSafeBootMode;
-
 typedef struct _XENBUS_DRIVER {
     PDRIVER_OBJECT      DriverObject;
     HANDLE              ParametersKey;
@@ -518,9 +516,6 @@ DriverUnload(
 
     Trace("====>\n");
 
-    if (*InitSafeBootMode > 0)
-        goto done;
-
     ASSERT(IsListEmpty(&Driver.List));
     ASSERT3U(Driver.References, ==, 1);
     --Driver.References;
@@ -549,7 +544,6 @@ DriverUnload(
          MONTH,
          YEAR);
 
-done:
     __DriverSetDriverObject(NULL);
 
     ASSERT(IsZeroMemory(&Driver, sizeof (XENBUS_DRIVER)));
@@ -662,9 +656,6 @@ DriverEntry(
 
     Driver.DriverObject->DriverUnload = DriverUnload;
 
-    if (*InitSafeBootMode > 0)
-        goto done;
-
     Info("%d.%d.%d (%d) (%02d.%02d.%04d)\n",
          MAJOR_VERSION,
          MINOR_VERSION,
diff --git a/src/xenfilt/driver.c b/src/xenfilt/driver.c
index d46630f..c96f406 100644
--- a/src/xenfilt/driver.c
+++ b/src/xenfilt/driver.c
@@ -45,8 +45,6 @@
 #include "util.h"
 #include "version.h"
 
-extern PULONG       InitSafeBootMode;
-
 typedef struct _XENFILT_DRIVER {
     PDRIVER_OBJECT              DriverObject;
     HANDLE                      ParametersKey;
@@ -81,6 +79,16 @@ __DriverFree(
     __FreePoolWithTag(Buffer, XENFILT_DRIVER_TAG);
 }
 
+extern PULONG   InitSafeBootMode;
+
+static FORCEINLINE BOOLEAN
+__DriverSafeMode(
+    VOID
+    )
+{
+    return (*InitSafeBootMode > 0) ? TRUE : FALSE;
+}
+
 static FORCEINLINE VOID
 __DriverSetDriverObject(
     IN  PDRIVER_OBJECT  DriverObject
@@ -355,7 +363,8 @@ DriverSetFilterState(
         if (DriverIsActivePresent()) {
             Info("ACTIVE DEVICE %sPRESENT\n", (!Present) ? "NOT " : "");
 
-            UnplugDevices();
+            if (!__DriverSafeMode())
+                UnplugDevices();
         }
 
         Info("PENDING\n");
@@ -405,9 +414,6 @@ DriverUnload(
 
     Trace("====>\n");
 
-    if (*InitSafeBootMode > 0)
-        goto done;
-
     ASSERT(IsListEmpty(&Driver.List));
     ASSERT3U(Driver.References, ==, 1);
     --Driver.References;
@@ -436,7 +442,6 @@ DriverUnload(
          MONTH,
          YEAR);
 
-done:
     __DriverSetDriverObject(NULL);
 
     ASSERT(IsZeroMemory(&Driver, sizeof (XENFILT_DRIVER)));
@@ -694,9 +699,6 @@ DriverEntry(
 
     DriverObject->DriverUnload = DriverUnload;
 
-    if (*InitSafeBootMode > 0)
-        goto done;
-
     Info("%d.%d.%d (%d) (%02d.%02d.%04d)\n",
          MAJOR_VERSION,
          MINOR_VERSION,
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://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®.