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

Re: [PATCH] Add XENFILT_EMULATED_OBJECT_TYPE override


  • To: "win-pv-devel@xxxxxxxxxxxxxxxxxxxx" <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>, "paul@xxxxxxx" <paul@xxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Fri, 26 Mar 2021 08:58:57 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qxwxhtB6L7Jmphmap0pyZxpLOjNIBPevM7FsqWV2UQs=; b=XpNevKZUCBb84AcPkVoxUw+DdjKpzr7T6JIeQsMfbyGm3k9E7e6kJwq0jmiySK2LdWh/zRheo7GPt/D8nuAfILdYXXG01/cuiRzrqoxlM/4209j39bMfwtlbu+QMioCOxOdy1gck3sy2hrrhkro9A9hk49P+6Z5kSfd6WpF75dp0O5dhcEislb74BerCLNFosKTvQZmea3T4qrfvGk04RUV0qVsflIm4eUxHyTEfXJcpReCKUgNO9ea5oLufVbeWcQ6qTSim3TQaFfhFteWl8LiuAKdv0x9DMCZJdY3+b6lW6zZXayTJuFy+kygTvKGQgjkTV5GEWyEj6swmwQ04NA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iaiRKle2CTG5YZv+E6Mo5Lj97bC05/9pt1kYWBrrN/502A6HtXoUdyfjqksXYnjO/C6Sx4l2WbiI5AxIVGuN1/+cTOW3OxFVI1RlBU1Kd8Bfqmn0d8i4cFm3+6AoVT8z3xjsf5oOXpYIBFv0azS2o0uFp0/vgjzAjykq+eCJxvrUJDSkvK0cEgTj7v0jkLrSVpN/yh/MGVoJY7h/JqHux2Pp0kmRIiNUbPkHYV0Dl37f2Prgk6VKDt0eJKCjwWdEDIwQULA6yNBk9vAgfqAlNcihsZzS7/nt4/8HXb27sxisi0kTNRzt19nwwwJalqpD57ZpeDpWE8ce87I2NBoMVQ==
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Delivery-date: Fri, 26 Mar 2021 08:59:07 +0000
  • Ironport-hdrordr: A9a23:BJg4taEjrPhPNN30pLqFTZTXdLJzesId70hD6mlYcjYQWtCEls yogfQQ3QL1jjFUY307hdWcIsC7Lk/03aVepa0cJ62rUgWjgmunK4l+8ZDvqgeNJwTXzcQY76 tpdsFFZeHYJVJxgd/mpCyxFNg9yNeKmZrY/9v25XFrUA1sduVE5wB2Fg6UHiRNNXR7LLA+E4 eR4dcCmiGpfm4ZYt/+Kn4OWeXCoNOjruOrXTctARk75A6SyQ658bKSKWnU4j4ycRNqhY0j/2 /MjhDj6syY3c2T5xfA2wbonvJrsfT7zN8rPr3utuE0LXHWhh+sdMBdXdS5zUsIicWOzHpvr9 XWuRcnOK1ImjzsV0W4uwHk1QWl8BtG0Q6a9XaijXHuodP0SVsBYqIr7+M4TjLj50Utp9162q 5Qtljpz6Z/Nh/cgD/7o+HBShACrDvsnVMZjeURg3ZDOLFuDYN5kI0F8EtZVLcGES7qgbpXd9 VGMcDG6P5aNW6ddnDS11MfpOCEY3JbJGblfmEy/uiulxRGlnFwyEUVgOYFmG0byZ47Q55Yo8 zZL6VBjth1P4ErRJM4IN1Ebdq8C2TLTx6JGnmVO07bGKYOPG+Ig4Lr4Y8y+PqhdPUzvdoPsa WEdGkdmX85ekroB8HL9oZM6ArxTGK0Wimo7c1C+Z5juPnZSKDwOSOODHAi+vHQ48k3M4n+Yb KeKZhWC/jsIS/FAoBSxTDzXJFUND0QS8sQttEnW0+fo87CJ4Hw39arMsr7Ff7IK3IJS2n/Cn wMUHzYP8Nb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MBxMXdR7BcrLEpHxDgNRtDgA7hJGcvIf TJcSdIG5VuehOs8z2HssUHGdag1MIZPS3WyRj09RElgQuvFs+KxOoEI4C4Scm/HZCwRNrfBgYy YF4OvzBg+XjWceAxLOc1zEw5Re5SNNDDKdGO2d8iwzBq6zvs+CGrQarrWSXxFGXyYzNTwMGsk7 XXE=
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>
  • Thread-index: AQHXGY38KqmEOTOVDEu7tbhlky6tiKqV+9EAgAAMJ7E=
  • Thread-topic: [PATCH] Add XENFILT_EMULATED_OBJECT_TYPE override

________________________________________
From: win-pv-devel <win-pv-devel-bounces@xxxxxxxxxxxxxxxxxxxx> on behalf of 
Paul Durrant <xadimgnik@xxxxxxxxx>
Sent: 26 March 2021 08:10
To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
Subject: Re: [PATCH] Add XENFILT_EMULATED_OBJECT_TYPE override

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments 
unless you have verified the sender and know the content is safe.

On 15/03/2021 11:25, Owen Smith wrote:
> EMULATED(IsDiskPresent) currently only reports if IDE disks are present.
> Add the option to override the emulated type of any given PDO to allow
> the emulated NVMe device to report its emulated device type as NVME.
> Adds the override for the QEMU emulated NVMe controller
> (PCI\VEN_8086&DEV_5845) to indicate it is a NVMe controller, and
> exposes disk 0.
> Also extends XENFILT_EMULATED_OBJECT_TYPE to include NVME
>
> This is to fix an issue where XenVbd can incorrectly identify that disk
> 0 is not present, when disk 0 is infact the present emulated NVMe
> device. This is problematic if the VM boots off the emulated device, not
> the PV device (due to the missing unplug) and then rebinds XENVBD which
> is unable to determine the presense of the emulated disk and attempts to
> connect to an in-use ring.
>
> Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
> ---
>   src/xenbus.inf         |  1 +
>   src/xenfilt/driver.c   | 24 +++++++++++++++---
>   src/xenfilt/driver.h   |  7 ++++++
>   src/xenfilt/emulated.c | 40 ++++++++++++++++++++++++++++++
>   src/xenfilt/emulated.h |  3 ++-
>   src/xenfilt/pdo.c      | 55 ++++++++++++++++++++++++++++++++++++++++++
>   6 files changed, 125 insertions(+), 5 deletions(-)
>
> diff --git a/src/xenbus.inf b/src/xenbus.inf
> index f9a5475..d2f2477 100644
> --- a/src/xenbus.inf
> +++ b/src/xenbus.inf
> @@ -119,6 +119,7 @@ AddReg = XenFilt_Parameters
>   HKR,"Parameters",,0x00000010
>   HKR,"Parameters","*PNP0A03",0x00000000,"PCI"
>   HKR,"Parameters","Internal_IDE_Channel",0x00000000,"IDE"
> +HKR,"Parameters\Override","PCI\VEN_8086&DEV_5845&SUBSYS_11001AF4&REV_02",0x00000000,"NVME"

That's a very strict match. How confident are we that the QEMU device
won't need to deal with e.g. multiple revisions of the QEMU device?
Perhaps it would be better to look at class code or is there something
else that may be a more stable identifier?

   Paul


My intention here was to make the match as specific as possible given the 
information immidiately available at the time the override is applied. By 
keeping it specific, its reducing the chances of wrongly overriding a device.

Using device class code may catch devices that are passed through, or are not 
otherwise the emulated device that corresponds to the PV device.

Owen

>
>   [Monitor_Service]
>   DisplayName=%MonitorName%
> diff --git a/src/xenfilt/driver.c b/src/xenfilt/driver.c
> index e9e6673..eb2ca42 100644
> --- a/src/xenfilt/driver.c
> +++ b/src/xenfilt/driver.c
> @@ -723,6 +723,25 @@ fail1:
>       return status;
>   }
>
> +XENFILT_EMULATED_OBJECT_TYPE
> +DriverParseEmulatedType(
> +    IN  PANSI_STRING                Ansi
> +    )
> +{
> +    XENFILT_EMULATED_OBJECT_TYPE    Type;
> +
> +    Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
> +
> +    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;
> +    else if (_strnicmp(Ansi->Buffer, "NVME", Ansi->Length) == 0)
> +        Type = XENFILT_EMULATED_OBJECT_TYPE_NVME;
> +
> +    return Type;
> +}
> +
>   static XENFILT_EMULATED_OBJECT_TYPE
>   DriverGetEmulatedType(
>       IN  PCHAR                       Id
> @@ -753,10 +772,7 @@ DriverGetEmulatedType(
>           if (NT_SUCCESS(status)) {
>               Info("MATCH: %s -> %Z\n", &Id[Index], Ansi);
>
> -            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;
> +            Type = DriverParseEmulatedType(Ansi);
>
>               RegistryFreeSzValue(Ansi);
>           } else {
> diff --git a/src/xenfilt/driver.h b/src/xenfilt/driver.h
> index 286580b..2129054 100644
> --- a/src/xenfilt/driver.h
> +++ b/src/xenfilt/driver.h
> @@ -32,6 +32,8 @@
>   #ifndef _XENFILT_DRIVER_H
>   #define _XENFILT_DRIVER_H
>
> +#include "emulated.h"
> +
>   extern PDRIVER_OBJECT
>   DriverGetDriverObject(
>       VOID
> @@ -58,6 +60,11 @@ DriverGetActive(
>       OUT PCHAR       *Value
>       );
>
> +extern XENFILT_EMULATED_OBJECT_TYPE
> +DriverParseEmulatedType(
> +    IN  PANSI_STRING                Ansi
> +    );
> +
>   typedef enum _XENFILT_FILTER_STATE {
>       XENFILT_FILTER_ENABLED = 0,
>       XENFILT_FILTER_PENDING,
> diff --git a/src/xenfilt/emulated.c b/src/xenfilt/emulated.c
> index 827c905..97da61b 100644
> --- a/src/xenfilt/emulated.c
> +++ b/src/xenfilt/emulated.c
> @@ -87,6 +87,33 @@ __EmulatedFree(
>       __FreePoolWithTag(Buffer, XENFILT_EMULATED_TAG);
>   }
>
> +static NTSTATUS
> +EmulatedSetObjectNvmeData(
> +    IN  PXENFILT_EMULATED_OBJECT        EmulatedObject,
> +    IN  XENFILT_EMULATED_OBJECT_TYPE    Type,
> +    IN  PCHAR                           DeviceID,
> +    IN  PCHAR                           InstanceID
> +    )
> +{
> +    NTSTATUS                            status;
> +
> +    UNREFERENCED_PARAMETER(DeviceID);
> +    UNREFERENCED_PARAMETER(InstanceID);
> +
> +    status = STATUS_INVALID_PARAMETER;
> +    if (Type != XENFILT_EMULATED_OBJECT_TYPE_NVME)
> +        goto fail1;
> +
> +    EmulatedObject->Data.Disk.Index = 0;
> +
> +    return STATUS_SUCCESS;
> +
> +fail1:
> +    Error("fail1 (%08x)\n", status);
> +
> +    return status;
> +}
> +
>   static NTSTATUS
>   EmulatedSetObjectDeviceData(
>       IN  PXENFILT_EMULATED_OBJECT        EmulatedObject,
> @@ -210,6 +237,13 @@ EmulatedAddObject(
>           goto fail1;
>
>       switch (Type) {
> +    case XENFILT_EMULATED_OBJECT_TYPE_NVME:
> +        status = EmulatedSetObjectNvmeData(*EmulatedObject,
> +                                           Type,
> +                                           DeviceID,
> +                                           InstanceID);
> +        break;
> +
>       case XENFILT_EMULATED_OBJECT_TYPE_PCI:
>           status = EmulatedSetObjectDeviceData(*EmulatedObject,
>                                                Type,
> @@ -338,6 +372,12 @@ EmulatedIsDiskPresent(
>               Trace("FOUND\n");
>               break;
>           }
> +        if (EmulatedObject->Type == XENFILT_EMULATED_OBJECT_TYPE_NVME &&
> +            Index == EmulatedObject->Data.Disk.Index) {
> +            Trace("FOUND\n");
> +            break;
> +        }
> +
>
>           ListEntry = ListEntry->Flink;
>       }
> diff --git a/src/xenfilt/emulated.h b/src/xenfilt/emulated.h
> index 57edee2..499e43c 100644
> --- a/src/xenfilt/emulated.h
> +++ b/src/xenfilt/emulated.h
> @@ -41,7 +41,8 @@ typedef struct _XENFILT_EMULATED_CONTEXT 
> XENFILT_EMULATED_CONTEXT, *PXENFILT_EMU
>   typedef enum _XENFILT_EMULATED_OBJECT_TYPE {
>       XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN = 0,
>       XENFILT_EMULATED_OBJECT_TYPE_PCI,
> -    XENFILT_EMULATED_OBJECT_TYPE_IDE
> +    XENFILT_EMULATED_OBJECT_TYPE_IDE,
> +    XENFILT_EMULATED_OBJECT_TYPE_NVME
>   } XENFILT_EMULATED_OBJECT_TYPE, *PXENFILT_EMULATED_OBJECT_TYPE;
>
>   typedef struct _XENFILT_EMULATED_OBJECT XENFILT_EMULATED_OBJECT, 
> *PXENFILT_EMULATED_OBJECT;
> diff --git a/src/xenfilt/pdo.c b/src/xenfilt/pdo.c
> index 0f6e6ce..41b0b10 100644
> --- a/src/xenfilt/pdo.c
> +++ b/src/xenfilt/pdo.c
> @@ -42,6 +42,7 @@
>   #include "pdo.h"
>   #include "thread.h"
>   #include "driver.h"
> +#include "registry.h"
>   #include "dbg_print.h"
>   #include "assert.h"
>   #include "util.h"
> @@ -251,6 +252,58 @@ __PdoGetFdo(
>       return Pdo->Fdo;
>   }
>
> +static VOID
> +__PdoGetEmulatedTypeOverride(
> +    IN  PXENFILT_PDO                Pdo,
> +    IN  PCHAR                       DeviceID
> +    )
> +{
> +    HANDLE                          ParametersKey;
> +    HANDLE                          OverrideKey;
> +    ULONG                           ValueType;
> +    PANSI_STRING                    Ansi;
> +    XENFILT_EMULATED_OBJECT_TYPE    Type;
> +    NTSTATUS                        status;
> +
> +    ParametersKey = DriverGetParametersKey();
> +
> +    status = RegistryOpenSubKey(ParametersKey,
> +                                "Override",
> +                                GENERIC_READ,
> +                                &OverrideKey);
> +    if (!NT_SUCCESS(status))
> +        goto fail1;
> +
> +    status = RegistryQuerySzValue(OverrideKey,
> +                                  DeviceID,
> +                                  &ValueType,
> +                                  &Ansi);
> +    if (!NT_SUCCESS(status))
> +        goto fail2;
> +
> +    if (ValueType != REG_SZ)
> +        goto fail3;
> +
> +    Type = DriverParseEmulatedType(Ansi);
> +    if (Type != XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN)
> +        Pdo->Type = Type;
> +
> +    RegistryFreeSzValue(Ansi);
> +
> +    RegistryCloseKey(OverrideKey);
> +
> +    return;
> +
> +fail3:
> +    RegistryFreeSzValue(Ansi);
> +
> +fail2:
> +    RegistryCloseKey(OverrideKey);
> +
> +fail1:
> +    return;
> +}
> +
>   static NTSTATUS
>   PdoSetDeviceInformation(
>       IN  PXENFILT_PDO    Pdo
> @@ -310,6 +363,8 @@ PdoSetDeviceInformation(
>               LocationInformation = NULL;
>       }
>
> +    __PdoGetEmulatedTypeOverride(Pdo, DeviceID);
> +
>       Dx->DeviceID = DeviceID;
>       Dx->InstanceID = InstanceID;
>       Dx->LocationInformation = LocationInformation;
>





 


Rackspace

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