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

[win-pv-devel] [PATCH 1/4] Ackowledge that tracked emulated objects are strictly...


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Paul Durrant <paul.durrant@xxxxxxxxxx>
  • Date: Wed, 2 Oct 2019 12:24:47 +0100
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@xxxxxxxxxx; spf=Pass smtp.mailfrom=Paul.Durrant@xxxxxxxxxx; spf=None smtp.helo=postmaster@xxxxxxxxxxxxxxx
  • Cc: Paul Durrant <paul.durrant@xxxxxxxxxx>
  • Delivery-date: Wed, 02 Oct 2019 11:25:14 +0000
  • Ironport-sdr: LkSZFhXfr8IdZlQhMRiSSAXrA7gbmjHJnmDSmWdZMS6eq7oXoCm/rrdBmRU55sxcH9tH9ZmPdU BMxm+51mfYL4WzZG5FvpvT13gOLRJn7KQhYho4FaJpq/EBXgWfqsCc627tZ7YSdNJ+E1NkmAtm pxe1UDLgSOG2xZHSwAXtqh8Qxwzug6J7h7oIO3sIZKIpBq1/BGq3FQcHeFNnegceatX+244eIj TDTcip8fkTXSQOc+o1UEdjEE2BNh1gzIffWLu5/c8wL/sEpDbwRrngwRimnCAGec0xy3bNQ1fX gTE=
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

...PCI devices or IDE disks.

Do this by renaming the type values both internally and in the registry.
The parsing code in emulated.c doesn't need to change but the type is now
passed into EmulatedSetObjectDeviceData() and EmulatedSetObjectDiskData()
so that they may cope with non-PCI devices or non-IDE disks in future.

Also, re-name XENFILT_EMULATED_OBJECT_TYPE_INVALID to
XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN to more accurately reflect its
meaning.

NOTE: This patch also re-works DriverGetEmulatedType() slightly to do
      the registry look-up of the DeviceID itself. This allows the fail
      labels to be removed from DriverAddDevice().

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenbus.inf         |  4 +--
 src/xenfilt/driver.c   | 72 +++++++++++++++++++++++---------------------------
 src/xenfilt/emulated.c | 58 +++++++++++++++++++++++++++-------------
 src/xenfilt/emulated.h |  6 ++---
 src/xenfilt/fdo.c      |  6 +++--
 src/xenfilt/pdo.c      |  6 +++--
 6 files changed, 85 insertions(+), 67 deletions(-)

diff --git a/src/xenbus.inf b/src/xenbus.inf
index 7c523d1..356e40b 100644
--- a/src/xenbus.inf
+++ b/src/xenbus.inf
@@ -117,8 +117,8 @@ AddReg = XenFilt_Parameters
 
 [XenFilt_Parameters]
 HKR,"Parameters",,0x00000010
-HKR,"Parameters","ACPI\PNP0A03",0x00000000,"DEVICE"
-HKR,"Parameters","PCIIDE\IDEChannel",0x00000000,"DISK"
+HKR,"Parameters","ACPI\PNP0A03",0x00000000,"PCI"
+HKR,"Parameters","PCIIDE\IDEChannel",0x00000000,"IDE"
 
 [Monitor_Service]
 DisplayName=%MonitorName%
diff --git a/src/xenfilt/driver.c b/src/xenfilt/driver.c
index 1b9ca98..18ffeaa 100644
--- a/src/xenfilt/driver.c
+++ b/src/xenfilt/driver.c
@@ -651,17 +651,30 @@ fail1:
 
 static XENFILT_EMULATED_OBJECT_TYPE
 DriverGetEmulatedType(
-    IN  PANSI_STRING                Ansi
+    IN  PCHAR                       DeviceID
     )
 {
+    HANDLE                          ParametersKey;
     XENFILT_EMULATED_OBJECT_TYPE    Type;
+    PANSI_STRING                    Ansi;
+    NTSTATUS                        status;
 
-    if (_strnicmp(Ansi->Buffer, "DEVICE", Ansi->Length) == 0)
-        Type = XENFILT_EMULATED_OBJECT_TYPE_DEVICE;
-    else if (_strnicmp(Ansi->Buffer, "DISK", Ansi->Length) == 0)
-        Type = XENFILT_EMULATED_OBJECT_TYPE_DISK;
-    else
-        Type = XENFILT_EMULATED_OBJECT_TYPE_INVALID;
+    ParametersKey = __DriverGetParametersKey();
+
+    Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
+
+    status = RegistryQuerySzValue(ParametersKey,
+                                  DeviceID,
+                                  NULL,
+                                  &Ansi);
+    if (NT_SUCCESS(status)) {
+        if (_strnicmp(Ansi->Buffer, "PCI", Ansi->Length) == 0)
+            Type = XENFILT_EMULATED_OBJECT_TYPE_PCI;
+        else if (_strnicmp(Ansi->Buffer, "IDE", Ansi->Length) == 0)
+            Type = XENFILT_EMULATED_OBJECT_TYPE_IDE;
+
+        RegistryFreeSzValue(Ansi);
+    }
 
     return Type;
 }
@@ -671,14 +684,13 @@ DRIVER_ADD_DEVICE   DriverAddDevice;
 NTSTATUS
 #pragma prefast(suppress:28152) // Does not clear DO_DEVICE_INITIALIZING
 DriverAddDevice(
-    IN  PDRIVER_OBJECT  DriverObject,
-    IN  PDEVICE_OBJECT  PhysicalDeviceObject
+    IN  PDRIVER_OBJECT              DriverObject,
+    IN  PDEVICE_OBJECT              PhysicalDeviceObject
     )
 {
-    HANDLE              ParametersKey;
-    PCHAR               DeviceID;
-    PANSI_STRING        Type;
-    NTSTATUS            status;
+    PCHAR                           DeviceID;
+    XENFILT_EMULATED_OBJECT_TYPE    Type;
+    NTSTATUS                        status;
 
     ASSERT3P(DriverObject, ==, __DriverGetDriverObject());
 
@@ -686,38 +698,20 @@ DriverAddDevice(
                            BusQueryDeviceID,
                            &DeviceID);
     if (!NT_SUCCESS(status))
-        goto fail1;
-
-    ParametersKey = __DriverGetParametersKey();
-
-    status = RegistryQuerySzValue(ParametersKey,
-                                  DeviceID,
-                                  NULL,
-                                  &Type);
-    if (NT_SUCCESS(status)) {
-        __DriverAcquireMutex();
-
-        status = FdoCreate(PhysicalDeviceObject,
-                           DriverGetEmulatedType(Type));
-
-        if (!NT_SUCCESS(status))
-            goto fail2;
-
-        __DriverReleaseMutex();
-
-        RegistryFreeSzValue(Type);
-    }
+        goto done;
 
+    Type = DriverGetEmulatedType(DeviceID);
     ExFreePool(DeviceID);
 
-    return STATUS_SUCCESS;
+    status = STATUS_SUCCESS;
+    if (Type == XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN)
+        goto done;
 
-fail2:
+    __DriverAcquireMutex();
+    status = FdoCreate(PhysicalDeviceObject, Type);
     __DriverReleaseMutex();
 
-fail1:
-    ExFreePool(DeviceID);
-
+done:
     return status;
 }
 
diff --git a/src/xenfilt/emulated.c b/src/xenfilt/emulated.c
index 7eb4054..7491afd 100644
--- a/src/xenfilt/emulated.c
+++ b/src/xenfilt/emulated.c
@@ -91,12 +91,17 @@ __EmulatedFree(
 
 static NTSTATUS
 EmulatedSetObjectDeviceData(
-    IN  PXENFILT_EMULATED_OBJECT    EmulatedObject,
-    IN  PCHAR                       DeviceID,
-    IN  PCHAR                       InstanceID
+    IN  PXENFILT_EMULATED_OBJECT        EmulatedObject,
+    IN  XENFILT_EMULATED_OBJECT_TYPE    Type,
+    IN  PCHAR                           DeviceID,
+    IN  PCHAR                           InstanceID
     )
 {
-    NTSTATUS                        status;
+    NTSTATUS                            status;
+
+    status = STATUS_INVALID_PARAMETER;
+    if (Type != XENFILT_EMULATED_OBJECT_TYPE_PCI)
+        goto fail1;
 
     status = RtlStringCbPrintfA(EmulatedObject->Data.Device.DeviceID,
                                 MAXNAMELEN,
@@ -111,28 +116,38 @@ EmulatedSetObjectDeviceData(
     ASSERT(NT_SUCCESS(status));
 
     return STATUS_SUCCESS;
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
 }
 
 static NTSTATUS
 EmulatedSetObjectDiskData(
-    IN  PXENFILT_EMULATED_OBJECT    EmulatedObject,
-    IN  PCHAR                       DeviceID,
-    IN  PCHAR                       InstanceID
+    IN  PXENFILT_EMULATED_OBJECT        EmulatedObject,
+    IN  XENFILT_EMULATED_OBJECT_TYPE    Type,
+    IN  PCHAR                           DeviceID,
+    IN  PCHAR                           InstanceID
     )
 {
-    PCHAR                           End;
-    ULONG                           Controller;
-    ULONG                           Target;
-    ULONG                           Lun;
-    NTSTATUS                        status;
+    PCHAR                               End;
+    ULONG                               Controller;
+    ULONG                               Target;
+    ULONG                               Lun;
+    NTSTATUS                            status;
 
     UNREFERENCED_PARAMETER(DeviceID);
 
+    status = STATUS_INVALID_PARAMETER;
+    if (Type != XENFILT_EMULATED_OBJECT_TYPE_IDE)
+        goto fail1;
+
     Controller = strtol(InstanceID, &End, 10);
 
     status = STATUS_INVALID_PARAMETER;
     if (*End != '.')
-        goto fail1;
+        goto fail2;
 
     End++;
 
@@ -140,7 +155,7 @@ EmulatedSetObjectDiskData(
 
     status = STATUS_INVALID_PARAMETER;
     if (*End != '.')
-        goto fail2;
+        goto fail3;
 
     End++;
 
@@ -148,7 +163,7 @@ EmulatedSetObjectDiskData(
 
     status = STATUS_INVALID_PARAMETER;
     if (*End != '\0')
-        goto fail3;
+        goto fail4;
 
     EmulatedObject->Data.Disk.Controller = Controller;
     EmulatedObject->Data.Disk.Target = Target;
@@ -156,6 +171,9 @@ EmulatedSetObjectDiskData(
 
     return STATUS_SUCCESS;
 
+fail4:
+    Error("fail4\n");
+
 fail3:
     Error("fail3\n");
 
@@ -189,14 +207,16 @@ EmulatedAddObject(
         goto fail1;
 
     switch (Type) {
-    case XENFILT_EMULATED_OBJECT_TYPE_DEVICE:
+    case XENFILT_EMULATED_OBJECT_TYPE_PCI:
         status = EmulatedSetObjectDeviceData(*EmulatedObject,
+                                             Type,
                                              DeviceID,
                                              InstanceID);
         break;
 
-    case XENFILT_EMULATED_OBJECT_TYPE_DISK:
+    case XENFILT_EMULATED_OBJECT_TYPE_IDE:
         status = EmulatedSetObjectDiskData(*EmulatedObject,
+                                           Type,
                                            DeviceID,
                                            InstanceID);
         break;
@@ -270,7 +290,7 @@ EmulatedIsDevicePresent(
                                            XENFILT_EMULATED_OBJECT,
                                            ListEntry);
 
-        if (EmulatedObject->Type == XENFILT_EMULATED_OBJECT_TYPE_DEVICE &&
+        if (EmulatedObject->Type == XENFILT_EMULATED_OBJECT_TYPE_PCI &&
             _stricmp(DeviceID, EmulatedObject->Data.Device.DeviceID) == 0 &&
             (InstanceID == NULL ||
              _stricmp(InstanceID, EmulatedObject->Data.Device.InstanceID) == 
0)) {
@@ -312,7 +332,7 @@ EmulatedIsDiskPresent(
                                            XENFILT_EMULATED_OBJECT,
                                            ListEntry);
 
-        if (EmulatedObject->Type == XENFILT_EMULATED_OBJECT_TYPE_DISK &&
+        if (EmulatedObject->Type == XENFILT_EMULATED_OBJECT_TYPE_IDE &&
             Controller == EmulatedObject->Data.Disk.Controller &&
             Target == EmulatedObject->Data.Disk.Target &&
             Lun == EmulatedObject->Data.Disk.Lun) {
diff --git a/src/xenfilt/emulated.h b/src/xenfilt/emulated.h
index 778c784..57edee2 100644
--- a/src/xenfilt/emulated.h
+++ b/src/xenfilt/emulated.h
@@ -39,9 +39,9 @@
 typedef struct _XENFILT_EMULATED_CONTEXT XENFILT_EMULATED_CONTEXT, 
*PXENFILT_EMULATED_CONTEXT;
 
 typedef enum _XENFILT_EMULATED_OBJECT_TYPE {
-    XENFILT_EMULATED_OBJECT_TYPE_INVALID = 0,
-    XENFILT_EMULATED_OBJECT_TYPE_DEVICE,
-    XENFILT_EMULATED_OBJECT_TYPE_DISK
+    XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN = 0,
+    XENFILT_EMULATED_OBJECT_TYPE_PCI,
+    XENFILT_EMULATED_OBJECT_TYPE_IDE
 } XENFILT_EMULATED_OBJECT_TYPE, *PXENFILT_EMULATED_OBJECT_TYPE;
 
 typedef struct _XENFILT_EMULATED_OBJECT XENFILT_EMULATED_OBJECT, 
*PXENFILT_EMULATED_OBJECT;
diff --git a/src/xenfilt/fdo.c b/src/xenfilt/fdo.c
index 3e87911..b8cf424 100644
--- a/src/xenfilt/fdo.c
+++ b/src/xenfilt/fdo.c
@@ -1964,6 +1964,8 @@ FdoCreate(
     PXENFILT_FDO                        Fdo;
     NTSTATUS                            status;
 
+    ASSERT(Type != XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN);
+
     LowerDeviceObject = IoGetAttachedDeviceReference(PhysicalDeviceObject);
     DeviceType = LowerDeviceObject->DeviceType;
     ObDereferenceObject(LowerDeviceObject);
@@ -2069,7 +2071,7 @@ fail5:
 fail4:
     Error("fail4\n");
 
-    Fdo->Type = XENFILT_EMULATED_OBJECT_TYPE_INVALID;
+    Fdo->Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
     Fdo->PhysicalDeviceObject = NULL;
     Fdo->LowerDeviceObject = NULL;
     Fdo->Dx = NULL;
@@ -2132,7 +2134,7 @@ FdoDestroy(
     ThreadJoin(Fdo->SystemPowerThread);
     Fdo->SystemPowerThread = NULL;
 
-    Fdo->Type = XENFILT_EMULATED_OBJECT_TYPE_INVALID;
+    Fdo->Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
     Fdo->LowerDeviceObject = NULL;
     Fdo->PhysicalDeviceObject = NULL;
     Fdo->Dx = NULL;
diff --git a/src/xenfilt/pdo.c b/src/xenfilt/pdo.c
index 37b4a45..0f6e6ce 100644
--- a/src/xenfilt/pdo.c
+++ b/src/xenfilt/pdo.c
@@ -2114,6 +2114,8 @@ PdoCreate(
     PXENFILT_PDO                    Pdo;
     NTSTATUS                        status;
 
+    ASSERT(Type != XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN);
+
     LowerDeviceObject = IoGetAttachedDeviceReference(PhysicalDeviceObject);
     DeviceType = LowerDeviceObject->DeviceType;
     ObDereferenceObject(LowerDeviceObject);
@@ -2221,7 +2223,7 @@ fail5:
 fail4:
     Error("fail4\n");
 
-    Pdo->Type = XENFILT_EMULATED_OBJECT_TYPE_INVALID;
+    Pdo->Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
     Pdo->PhysicalDeviceObject = NULL;
     Pdo->LowerDeviceObject = NULL;
     Pdo->Fdo = NULL;
@@ -2287,7 +2289,7 @@ PdoDestroy(
     ThreadJoin(Pdo->SystemPowerThread);
     Pdo->SystemPowerThread = NULL;
 
-    Pdo->Type = XENFILT_EMULATED_OBJECT_TYPE_INVALID;
+    Pdo->Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
     Pdo->PhysicalDeviceObject = NULL;
     Pdo->LowerDeviceObject = NULL;
     Pdo->Fdo = NULL;
-- 
2.5.3


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

 


Rackspace

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