[v3,1/1] virt2phys: virtual to physical address translator for Windows

Message ID 20200414194426.1640704-2-dmitry.kozliuk@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series Windows basic memory management |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Performance-Testing fail build patch failure
ci/Intel-compilation fail Compilation issues

Commit Message

Dmitry Kozlyuk April 14, 2020, 7:44 p.m. UTC
  This driver supports Windows EAL memory management by translating
current process virtual addresses to physical addresses (IOVA).
Standalone virt2phys allows using DPDK without PMD and provides a
reference implementation.

Suggested-by: Ranjit Menon <ranjit.menon@intel.com>
Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 windows/README.rst                          | 103 +++++++++
 windows/virt2phys/virt2phys.c               | 129 +++++++++++
 windows/virt2phys/virt2phys.h               |  34 +++
 windows/virt2phys/virt2phys.inf             |  64 ++++++
 windows/virt2phys/virt2phys.sln             |  27 +++
 windows/virt2phys/virt2phys.vcxproj         | 228 ++++++++++++++++++++
 windows/virt2phys/virt2phys.vcxproj.filters |  36 ++++
 7 files changed, 621 insertions(+)
 create mode 100644 windows/README.rst
 create mode 100644 windows/virt2phys/virt2phys.c
 create mode 100644 windows/virt2phys/virt2phys.h
 create mode 100644 windows/virt2phys/virt2phys.inf
 create mode 100644 windows/virt2phys/virt2phys.sln
 create mode 100644 windows/virt2phys/virt2phys.vcxproj
 create mode 100644 windows/virt2phys/virt2phys.vcxproj.filters
  

Comments

Menon, Ranjit April 14, 2020, 11:35 p.m. UTC | #1
On 4/14/2020 12:44 PM, Dmitry Kozlyuk wrote:
> This driver supports Windows EAL memory management by translating
> current process virtual addresses to physical addresses (IOVA).
> Standalone virt2phys allows using DPDK without PMD and provides a
> reference implementation.
> 
> Suggested-by: Ranjit Menon <ranjit.menon@intel.com>
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
>   windows/README.rst                          | 103 +++++++++
>   windows/virt2phys/virt2phys.c               | 129 +++++++++++
>   windows/virt2phys/virt2phys.h               |  34 +++
>   windows/virt2phys/virt2phys.inf             |  64 ++++++
>   windows/virt2phys/virt2phys.sln             |  27 +++
>   windows/virt2phys/virt2phys.vcxproj         | 228 ++++++++++++++++++++
>   windows/virt2phys/virt2phys.vcxproj.filters |  36 ++++
>   7 files changed, 621 insertions(+)
>   create mode 100644 windows/README.rst
>   create mode 100644 windows/virt2phys/virt2phys.c
>   create mode 100644 windows/virt2phys/virt2phys.h
>   create mode 100644 windows/virt2phys/virt2phys.inf
>   create mode 100644 windows/virt2phys/virt2phys.sln
>   create mode 100644 windows/virt2phys/virt2phys.vcxproj
>   create mode 100644 windows/virt2phys/virt2phys.vcxproj.filters
> 

Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>
  
Thomas Monjalon April 15, 2020, 3:19 p.m. UTC | #2
15/04/2020 01:35, Ranjit Menon:
> On 4/14/2020 12:44 PM, Dmitry Kozlyuk wrote:
> > This driver supports Windows EAL memory management by translating
> > current process virtual addresses to physical addresses (IOVA).
> > Standalone virt2phys allows using DPDK without PMD and provides a
> > reference implementation.
> > 
> > Suggested-by: Ranjit Menon <ranjit.menon@intel.com>
> > Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> 
> Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
> Acked-by: Ranjit Menon <ranjit.menon@intel.com>

Applied in dpdk-kmods, thanks.

This is the very first kernel module in this repository:
	http://git.dpdk.org/dpdk-kmods/
  
Ophir Munk April 21, 2020, 6:23 a.m. UTC | #3
Hi Dmitry,
When trying to test the series under Linux (RedHat 7.4, x86_64-native-linuxapp-gcc) I get compilation errors. I am using make.
It seems that there are calls from common which are not compiled under linux.

x86_64-native-linuxapp-gcc/lib/librte_eal.a(eal_common_memory.o): In function `eal_get_virtual_area':
eal_common_memory.c:(.text+0x27e): undefined reference to `eal_mem_reserve'

[dpdk-branches]$  find lib -name '*.c' | xargs grep eal_mem_reserve
lib/librte_eal/common/eal_common_memory.c:              mapped_addr = eal_mem_reserve(
lib/librte_eal/windows/eal_memory.c:eal_mem_reserve(void *requested_addr, size_t size,
lib/librte_eal/unix/eal_memory.c:eal_mem_reserve(void *requested_addr, size_t size,

Does it succeed for you?
If not - can you please resend the series such that it compiles under Linux with Makefile?

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Dmitry Kozlyuk
> Sent: Tuesday, April 14, 2020 10:44 PM
> To: dev@dpdk.org
> Cc: Dmitry Malloy (MESHCHANINOV) <dmitrym@microsoft.com>; Narcisa
> Ana Maria Vasile <Narcisa.Vasile@microsoft.com>; Fady Bader
> <fady@mellanox.com>; Tal Shnaiderman <talshn@mellanox.com>; Dmitry
> Kozlyuk <dmitry.kozliuk@gmail.com>; Ranjit Menon
> <ranjit.menon@intel.com>
> Subject: [dpdk-dev] [PATCH v3 1/1] virt2phys: virtual to physical address
> translator for Windows
> 
> This driver supports Windows EAL memory management by translating
> current process virtual addresses to physical addresses (IOVA).
> Standalone virt2phys allows using DPDK without PMD and provides a
> reference implementation.
> 
> Suggested-by: Ranjit Menon <ranjit.menon@intel.com>
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
>  windows/README.rst                          | 103 +++++++++
>  windows/virt2phys/virt2phys.c               | 129 +++++++++++
>  windows/virt2phys/virt2phys.h               |  34 +++
>  windows/virt2phys/virt2phys.inf             |  64 ++++++
>  windows/virt2phys/virt2phys.sln             |  27 +++
>  windows/virt2phys/virt2phys.vcxproj         | 228 ++++++++++++++++++++
>  windows/virt2phys/virt2phys.vcxproj.filters |  36 ++++
>  7 files changed, 621 insertions(+)
>  create mode 100644 windows/README.rst
>  create mode 100644 windows/virt2phys/virt2phys.c  create mode 100644
> windows/virt2phys/virt2phys.h  create mode 100644
> windows/virt2phys/virt2phys.inf  create mode 100644
> windows/virt2phys/virt2phys.sln  create mode 100644
> windows/virt2phys/virt2phys.vcxproj
>  create mode 100644 windows/virt2phys/virt2phys.vcxproj.filters
> 
> diff --git a/windows/README.rst b/windows/README.rst new file mode
> 100644 index 0000000..45a1d80
> --- /dev/null
> +++ b/windows/README.rst
> @@ -0,0 +1,103 @@
> +Developing Windows Drivers
> +==========================
> +
> +Prerequisites
> +-------------
> +
> +Building Windows Drivers is only possible on Windows.
> +
> +1. Visual Studio 2019 Community or Professional Edition 2. Windows
> +Driver Kit (WDK) for Windows 10, version 1903
> +
> +Follow the official instructions to obtain all of the above:
> +https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs
> .
> +microsoft.com%2Fen-us%2Fwindows-hardware%2Fdrivers%2Fdownload-
> the-wdk&a
> +mp;data=02%7C01%7Cophirmu%40mellanox.com%7C86da431f2b904dca3
> d8208d7e0ac
> +4cd0%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C637224902
> 939680479&am
> +p;sdata=RSZXmo%2FewOpl9VCCg4BIgYUFvpreZzqX1X%2Bcl9vNRjU%3D&a
> mp;reserved
> +=0
> +
> +
> +Build the Drivers
> +-----------------
> +
> +Build from Visual Studio
> +~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +Open a solution (``*.sln``) with Visual Studio and build it (Ctrl+Shift+B).
> +
> +
> +Build from Command-Line
> +~~~~~~~~~~~~~~~~~~~~~~~
> +
> +Run *Developer Command Prompt for VS 2019* from the Start menu.
> +
> +Navigate to the solution directory (with ``*.sln``), then run:
> +
> +.. code-block:: console
> +
> +    msbuild
> +
> +To build a particular combination of configuration and platform:
> +
> +.. code-block:: console
> +
> +    msbuild -p:Configuration=Debug;Platform=x64
> +
> +
> +Install the Drivers
> +-------------------
> +
> +Disable Driver Signature Enforcement
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +By default Windows prohibits installing and loading drivers without
> +`digital signature`_ obtained from Microsoft. For development signature
> +enforcement may be disabled as follows.
> +
> +In Elevated Command Prompt (from this point, sufficient privileges are
> +assumed):
> +
> +.. code-block:: console
> +
> +    bcdedit -set loadoptions DISABLE_INTEGRITY_CHECKS
> +    bcdedit -set TESTSIGNING ON
> +    shutdown -r -t 0
> +
> +Upon reboot, an overlay message should appear on the desktop informing
> +that Windows is in test mode, which means it allows loading unsigned
> drivers.
> +
> +.. _digital signature:
> +https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs
> .
> +microsoft.com%2Fen-us%2Fwindows-
> hardware%2Fdrivers%2Finstall%2Fdriver-s
> +igning&amp;data=02%7C01%7Cophirmu%40mellanox.com%7C86da431f2b
> 904dca3d82
> +08d7e0ac4cd0%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C63
> 72249029396
> +85478&amp;sdata=tLVdijiQ56xwSDW0zVsVE3TnIpuMPTLd9DBtS3Bnf4Q%3
> D&amp;rese
> +rved=0
> +
> +Install, List, and Remove Drivers
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +Driver package is by default located in a subdirectory of its source
> +tree, e.g. ``x64\Debug\virt2phys\virt2phys`` (note two levels of
> ``virt2phys``).
> +
> +To install the driver and bind associated devices to it:
> +
> +.. code-block:: console
> +
> +    pnputil /add-driver x64\Debug\virt2phys\virt2phys\virt2phys.inf
> + /install
> +
> +A graphical confirmation to load an unsigned driver will still appear.
> +
> +On Windows Server additional steps are required if the driver uses a
> +custom setup class:
> +
> +1. From "Device Manager", "Action" menu, select "Add legacy hardware".
> +2. It will launch the "Add Hardware Wizard". Click "Next".
> +3. Select second option "Install the hardware that I manually select
> +   from a list (Advanced)".
> +4. On the next screen, locate the driver device class.
> +5. Select it, and click "Next".
> +6. The previously installed drivers will now be installed for
> +   the appropriate devices (software devices will be created).
> +
> +To list installed drivers:
> +
> +.. code-block:: console
> +
> +    pnputil /enum-drivers
> +
> +To remove the driver package and to uninstall its devices:
> +
> +.. code-block:: console
> +
> +    pnputil /delete-driver oem2.inf /uninstall
> diff --git a/windows/virt2phys/virt2phys.c b/windows/virt2phys/virt2phys.c
> new file mode 100644 index 0000000..e157e9c
> --- /dev/null
> +++ b/windows/virt2phys/virt2phys.c
> @@ -0,0 +1,129 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2020 Dmitry Kozlyuk
> + */
> +
> +#include <ntddk.h>
> +#include <wdf.h>
> +#include <wdmsec.h>
> +#include <initguid.h>
> +
> +#include "virt2phys.h"
> +
> +DRIVER_INITIALIZE DriverEntry;
> +EVT_WDF_DRIVER_DEVICE_ADD virt2phys_driver_EvtDeviceAdd;
> +EVT_WDF_IO_IN_CALLER_CONTEXT
> virt2phys_device_EvtIoInCallerContext;
> +
> +NTSTATUS
> +DriverEntry(
> +	IN PDRIVER_OBJECT driver_object, IN PUNICODE_STRING
> registry_path) {
> +	WDF_DRIVER_CONFIG config;
> +	WDF_OBJECT_ATTRIBUTES attributes;
> +	NTSTATUS status;
> +
> +	PAGED_CODE();
> +
> +	WDF_DRIVER_CONFIG_INIT(&config,
> virt2phys_driver_EvtDeviceAdd);
> +	WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
> +	status = WdfDriverCreate(
> +			driver_object, registry_path,
> +			&attributes, &config, WDF_NO_HANDLE);
> +	if (!NT_SUCCESS(status)) {
> +		KdPrint(("WdfDriverCreate() failed, status=%08x\n", status));
> +	}
> +
> +	return status;
> +}
> +
> +_Use_decl_annotations_
> +NTSTATUS
> +virt2phys_driver_EvtDeviceAdd(
> +	WDFDRIVER driver, PWDFDEVICE_INIT init) {
> +	WDF_OBJECT_ATTRIBUTES attributes;
> +	WDFDEVICE device;
> +	NTSTATUS status;
> +
> +	UNREFERENCED_PARAMETER(driver);
> +
> +	PAGED_CODE();
> +
> +	WdfDeviceInitSetIoType(
> +		init, WdfDeviceIoNeither);
> +	WdfDeviceInitSetIoInCallerContextCallback(
> +		init, virt2phys_device_EvtIoInCallerContext);
> +
> +	WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
> +
> +	status = WdfDeviceCreate(&init, &attributes, &device);
> +	if (!NT_SUCCESS(status)) {
> +		KdPrint(("WdfDeviceCreate() failed, status=%08x\n", status));
> +		return status;
> +	}
> +
> +	status = WdfDeviceCreateDeviceInterface(
> +			device, &GUID_DEVINTERFACE_VIRT2PHYS, NULL);
> +	if (!NT_SUCCESS(status)) {
> +		KdPrint(("WdfDeviceCreateDeviceInterface() failed, "
> +			"status=%08x\n", status));
> +		return status;
> +	}
> +
> +	return STATUS_SUCCESS;
> +}
> +
> +_Use_decl_annotations_
> +VOID
> +virt2phys_device_EvtIoInCallerContext(
> +	IN WDFDEVICE device, IN WDFREQUEST request) {
> +	WDF_REQUEST_PARAMETERS params;
> +	ULONG code;
> +	PVOID *virt;
> +	PHYSICAL_ADDRESS *phys;
> +	size_t size;
> +	NTSTATUS status;
> +
> +	UNREFERENCED_PARAMETER(device);
> +
> +	PAGED_CODE();
> +
> +	WDF_REQUEST_PARAMETERS_INIT(&params);
> +	WdfRequestGetParameters(request, &params);
> +
> +	if (params.Type != WdfRequestTypeDeviceControl) {
> +		KdPrint(("bogus request type=%u\n", params.Type));
> +		WdfRequestComplete(request, STATUS_NOT_SUPPORTED);
> +		return;
> +	}
> +
> +	code = params.Parameters.DeviceIoControl.IoControlCode;
> +	if (code != IOCTL_VIRT2PHYS_TRANSLATE) {
> +		KdPrint(("bogus IO control code=%lu\n", code));
> +		WdfRequestComplete(request, STATUS_NOT_SUPPORTED);
> +		return;
> +	}
> +
> +	status = WdfRequestRetrieveInputBuffer(
> +			request, sizeof(*virt), (PVOID *)&virt, &size);
> +	if (!NT_SUCCESS(status)) {
> +		KdPrint(("WdfRequestRetrieveInputBuffer() failed, "
> +			"status=%08x\n", status));
> +		WdfRequestComplete(request, status);
> +		return;
> +	}
> +
> +	status = WdfRequestRetrieveOutputBuffer(
> +		request, sizeof(*phys), (PVOID *)&phys, &size);
> +	if (!NT_SUCCESS(status)) {
> +		KdPrint(("WdfRequestRetrieveOutputBuffer() failed, "
> +			"status=%08x\n", status));
> +		WdfRequestComplete(request, status);
> +		return;
> +	}
> +
> +	*phys = MmGetPhysicalAddress(*virt);
> +
> +	WdfRequestCompleteWithInformation(
> +		request, STATUS_SUCCESS, sizeof(*phys)); }
> diff --git a/windows/virt2phys/virt2phys.h b/windows/virt2phys/virt2phys.h
> new file mode 100644 index 0000000..4bb2b4a
> --- /dev/null
> +++ b/windows/virt2phys/virt2phys.h
> @@ -0,0 +1,34 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright (c) 2020 Dmitry Kozlyuk
> + */
> +
> +/**
> + * @file virt2phys driver interface
> + */
> +
> +/**
> + * Driver device interface GUID {539c2135-793a-4926-afec-d3a1b61bbc8a}.
> + */
> +DEFINE_GUID(GUID_DEVINTERFACE_VIRT2PHYS,
> +	0x539c2135, 0x793a, 0x4926,
> +	0xaf, 0xec, 0xd3, 0xa1, 0xb6, 0x1b, 0xbc, 0x8a);
> +
> +/**
> + * Driver device type for IO control codes.
> + */
> +#define VIRT2PHYS_DEVTYPE 0x8000
> +
> +/**
> + * Translate a valid non-paged virtual address to a physical address.
> + *
> + * Note: A physical address zero (0) is reported if input address
> + * is paged out or not mapped. However, if input is a valid mapping
> + * of I/O port 0x0000, output is also zero. There is no way
> + * to distinguish between these cases by return value only.
> + *
> + * Input: a non-paged virtual address (PVOID).
> + *
> + * Output: the corresponding physical address (LARGE_INTEGER).
> + */
> +#define IOCTL_VIRT2PHYS_TRANSLATE CTL_CODE( \
> +	VIRT2PHYS_DEVTYPE, 0x800, METHOD_BUFFERED,
> FILE_ANY_ACCESS)
> diff --git a/windows/virt2phys/virt2phys.inf
> b/windows/virt2phys/virt2phys.inf new file mode 100644 index
> 0000000..e35765e
> --- /dev/null
> +++ b/windows/virt2phys/virt2phys.inf
> @@ -0,0 +1,64 @@
> +; SPDX-License-Identifier: BSD-3-Clause ; Copyright (c) 2020 Dmitry
> +Kozlyuk
> +
> +[Version]
> +Signature = "$WINDOWS NT$"
> +Class = %ClassName%
> +ClassGuid = {78A1C341-4539-11d3-B88D-00C04FAD5171}
> +Provider = %ManufacturerName%
> +CatalogFile = virt2phys.cat
> +DriverVer =
> +
> +[DestinationDirs]
> +DefaultDestDir = 12
> +
> +; ================= Class section =====================
> +
> +[ClassInstall32]
> +Addreg = virt2phys_ClassReg
> +
> +[virt2phys_ClassReg]
> +HKR,,,0,%ClassName%
> +HKR,,Icon,,-5
> +
> +[SourceDisksNames]
> +1 = %DiskName%,,,""
> +
> +[SourceDisksFiles]
> +virt2phys.sys  = 1,,
> +
> +;*****************************************
> +; Install Section
> +;*****************************************
> +
> +[Manufacturer]
> +%ManufacturerName%=Standard,NT$ARCH$
> +
> +[Standard.NT$ARCH$]
> +%virt2phys.DeviceDesc%=virt2phys_Device, Root\virt2phys
> +
> +[virt2phys_Device.NT]
> +CopyFiles = Drivers_Dir
> +
> +[Drivers_Dir]
> +virt2phys.sys
> +
> +;-------------- Service installation
> +[virt2phys_Device.NT.Services]
> +AddService = virt2phys,%SPSVCINST_ASSOCSERVICE%,
> virt2phys_Service_Inst
> +
> +; -------------- virt2phys driver install sections
> +[virt2phys_Service_Inst]
> +DisplayName    = %virt2phys.SVCDESC%
> +ServiceType    = 1 ; SERVICE_KERNEL_DRIVER
> +StartType      = 3 ; SERVICE_DEMAND_START
> +ErrorControl   = 1 ; SERVICE_ERROR_NORMAL
> +ServiceBinary  = %12%\virt2phys.sys
> +
> +[Strings]
> +SPSVCINST_ASSOCSERVICE = 0x00000002
> +ManufacturerName = "Dmitry Kozlyuk"
> +ClassName = "Kernel bypass"
> +DiskName = "virt2phys Installation Disk"
> +virt2phys.DeviceDesc = "Virtual to physical address translator"
> +virt2phys.SVCDESC = "virt2phys Service"
> diff --git a/windows/virt2phys/virt2phys.sln
> b/windows/virt2phys/virt2phys.sln new file mode 100644 index
> 0000000..0f5ecdc
> --- /dev/null
> +++ b/windows/virt2phys/virt2phys.sln
> @@ -0,0 +1,27 @@
> ++Microsoft Visual Studio Solution File, Format Version 12.00+# Visual Studio
> Version 16+VisualStudioVersion =
> 16.0.29613.14+MinimumVisualStudioVersion =
> 10.0.40219.1+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") =
> "virt2phys", "virt2phys.vcxproj", "{0EEF826B-9391-43A8-A722-
> BDD6F6115137}"+EndProject+Global+
> 	GlobalSection(SolutionConfigurationPlatforms) = preSolution+
> 	Debug|x64 = Debug|x64+		Release|x64 = Release|x64+
> 	EndGlobalSection+
> 	GlobalSection(ProjectConfigurationPlatforms) = postSolution+
> 	{0EEF826B-9391-43A8-A722-BDD6F6115137}.Debug|x64.ActiveCfg =
> Debug|x64+		{0EEF826B-9391-43A8-A722-
> BDD6F6115137}.Debug|x64.Build.0 = Debug|x64+		{0EEF826B-
> 9391-43A8-A722-BDD6F6115137}.Debug|x64.Deploy.0 = Debug|x64+
> 	{0EEF826B-9391-43A8-A722-BDD6F6115137}.Release|x64.ActiveCfg
> = Release|x64+		{0EEF826B-9391-43A8-A722-
> BDD6F6115137}.Release|x64.Build.0 = Release|x64+		{0EEF826B-
> 9391-43A8-A722-BDD6F6115137}.Release|x64.Deploy.0 = Release|x64+
> 	EndGlobalSection+	GlobalSection(SolutionProperties) =
> preSolution+		HideSolutionNode = FALSE+	EndGlobalSection+
> 	GlobalSection(ExtensibilityGlobals) = postSolution+
> 	SolutionGuid = {845012FB-4471-4A12-A1C4-FF7E05C40E8E}+
> 	EndGlobalSection+EndGlobaldiff --git
> a/windows/virt2phys/virt2phys.vcxproj
> b/windows/virt2phys/virt2phys.vcxproj
> new file mode 100644
> index 0000000..fa51916
> --- /dev/null
> +++ b/windows/virt2phys/virt2phys.vcxproj
> @@ -0,0 +1,228 @@
> +<?xml version="1.0" encoding="utf-8"?>+<Project DefaultTargets="Build"
> ToolsVersion="12.0"
> xmlns="https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2
> Fschemas.microsoft.com%2Fdeveloper%2Fmsbuild%2F2003&amp;data=02%
> 7C01%7Cophirmu%40mellanox.com%7C86da431f2b904dca3d8208d7e0ac4c
> d0%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C637224902939
> 685478&amp;sdata=N7HPDma1qrXV6sobOS0tblhsgaEUePD8lXqhnyXD1sU%
> 3D&amp;reserved=0">+  <ItemGroup Label="ProjectConfigurations">+
> <ProjectConfiguration Include="Debug|Win32">+
> <Configuration>Debug</Configuration>+      <Platform>Win32</Platform>+
> </ProjectConfiguration>+    <ProjectConfiguration
> Include="Release|Win32">+      <Configuration>Release</Configuration>+
> <Platform>Win32</Platform>+    </ProjectConfiguration>+
> <ProjectConfiguration Include="Debug|x64">+
> <Configuration>Debug</Configuration>+      <Platform>x64</Platform>+
> </ProjectConfiguration>+    <ProjectConfiguration Include="Release|x64">+
> <Configuration>Release</Configuration>+      <Platform>x64</Platform>+
> </ProjectConfiguration>+    <ProjectConfiguration Include="Debug|ARM">+
> <Configuration>Debug</Configuration>+      <Platform>ARM</Platform>+
> </ProjectConfiguration>+    <ProjectConfiguration Include="Release|ARM">+
> <Configuration>Release</Configuration>+      <Platform>ARM</Platform>+
> </ProjectConfiguration>+    <ProjectConfiguration
> Include="Debug|ARM64">+      <Configuration>Debug</Configuration>+
> <Platform>ARM64</Platform>+    </ProjectConfiguration>+
> <ProjectConfiguration Include="Release|ARM64">+
> <Configuration>Release</Configuration>+
> <Platform>ARM64</Platform>+    </ProjectConfiguration>+  </ItemGroup>+
> <ItemGroup>+    <ClCompile Include="virt2phys.c" />+  </ItemGroup>+
> <ItemGroup>+    <ClInclude Include="virt2phys.h" />+  </ItemGroup>+
> <ItemGroup>+    <Inf Include="virt2phys.inf" />+  </ItemGroup>+
> <PropertyGroup Label="Globals">+    <ProjectGuid>{0EEF826B-9391-43A8-
> A722-BDD6F6115137}</ProjectGuid>+    <TemplateGuid>{497e31cb-056b-
> 4f31-abb8-447fd55ee5a5}</TemplateGuid>+
> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>+
> <MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>+
> <Configuration>Debug</Configuration>+    <Platform
> Condition="'$(Platform)' == ''">Win32</Platform>+
> <RootNamespace>virt2phys</RootNamespace>+  </PropertyGroup>+
> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />+
> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"
> Label="Configuration">+    <TargetVersion>Windows10</TargetVersion>+
> <UseDebugLibraries>true</UseDebugLibraries>+
> <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>+
> <ConfigurationType>Driver</ConfigurationType>+
> <DriverType>KMDF</DriverType>+
> <DriverTargetPlatform>Universal</DriverTargetPlatform>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"
> Label="Configuration">+    <TargetVersion>Windows10</TargetVersion>+
> <UseDebugLibraries>false</UseDebugLibraries>+
> <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>+
> <ConfigurationType>Driver</ConfigurationType>+
> <DriverType>KMDF</DriverType>+
> <DriverTargetPlatform>Universal</DriverTargetPlatform>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"
> Label="Configuration">+    <TargetVersion>Windows10</TargetVersion>+
> <UseDebugLibraries>true</UseDebugLibraries>+
> <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>+
> <ConfigurationType>Driver</ConfigurationType>+
> <DriverType>KMDF</DriverType>+
> <DriverTargetPlatform>Universal</DriverTargetPlatform>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|x64'"
> Label="Configuration">+    <TargetVersion>Windows10</TargetVersion>+
> <UseDebugLibraries>false</UseDebugLibraries>+
> <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>+
> <ConfigurationType>Driver</ConfigurationType>+
> <DriverType>KMDF</DriverType>+
> <DriverTargetPlatform>Universal</DriverTargetPlatform>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'"
> Label="Configuration">+    <TargetVersion>Windows10</TargetVersion>+
> <UseDebugLibraries>true</UseDebugLibraries>+
> <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>+
> <ConfigurationType>Driver</ConfigurationType>+
> <DriverType>KMDF</DriverType>+
> <DriverTargetPlatform>Universal</DriverTargetPlatform>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|ARM'"
> Label="Configuration">+    <TargetVersion>Windows10</TargetVersion>+
> <UseDebugLibraries>false</UseDebugLibraries>+
> <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>+
> <ConfigurationType>Driver</ConfigurationType>+
> <DriverType>KMDF</DriverType>+
> <DriverTargetPlatform>Universal</DriverTargetPlatform>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'"
> Label="Configuration">+    <TargetVersion>Windows10</TargetVersion>+
> <UseDebugLibraries>true</UseDebugLibraries>+
> <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>+
> <ConfigurationType>Driver</ConfigurationType>+
> <DriverType>KMDF</DriverType>+
> <DriverTargetPlatform>Universal</DriverTargetPlatform>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'"
> Label="Configuration">+    <TargetVersion>Windows10</TargetVersion>+
> <UseDebugLibraries>false</UseDebugLibraries>+
> <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>+
> <ConfigurationType>Driver</ConfigurationType>+
> <DriverType>KMDF</DriverType>+
> <DriverTargetPlatform>Universal</DriverTargetPlatform>+
> </PropertyGroup>+  <Import
> Project="$(VCTargetsPath)\Microsoft.Cpp.props" />+  <ImportGroup
> Label="ExtensionSettings">+  </ImportGroup>+  <ImportGroup
> Label="PropertySheets">+    <Import
> Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
> Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
> Label="LocalAppDataPlatform" />+  </ImportGroup>+  <PropertyGroup
> Label="UserMacros" />+  <PropertyGroup />+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">+
> <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">+
> <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">+
> <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|x64'">+
> <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">+
> <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">+
> <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">+
> <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>+
> </PropertyGroup>+  <PropertyGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">+
> <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>+
> </PropertyGroup>+  <ItemDefinitionGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">+
> <ClCompile>+      <WppEnabled>true</WppEnabled>+
> <WppRecorderEnabled>true</WppRecorderEnabled>+
> <WppScanConfigurationData
> Condition="'%(ClCompile.ScanConfigurationData)' ==
> ''">trace.h</WppScanConfigurationData>+
> <WppKernelMode>true</WppKernelMode>+    </ClCompile>+
> </ItemDefinitionGroup>+  <ItemDefinitionGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">+
> <ClCompile>+      <WppEnabled>true</WppEnabled>+
> <WppRecorderEnabled>true</WppRecorderEnabled>+
> <WppScanConfigurationData
> Condition="'%(ClCompile.ScanConfigurationData)' ==
> ''">trace.h</WppScanConfigurationData>+
> <WppKernelMode>true</WppKernelMode>+    </ClCompile>+
> </ItemDefinitionGroup>+  <ItemDefinitionGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">+    <ClCompile>+
> <WppEnabled>false</WppEnabled>+
> <WppRecorderEnabled>true</WppRecorderEnabled>+
> <WppScanConfigurationData
> Condition="'%(ClCompile.ScanConfigurationData)' ==
> ''">trace.h</WppScanConfigurationData>+
> <WppKernelMode>true</WppKernelMode>+    </ClCompile>+    <Link>+
> <AdditionalDependencies>$(DDK_LIB_PATH)wdmsec.lib;%(AdditionalDepend
> encies)</AdditionalDependencies>+    </Link>+    <Inf>+
> <TimeStamp>0.1</TimeStamp>+    </Inf>+  </ItemDefinitionGroup>+
> <ItemDefinitionGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|x64'">+
> <ClCompile>+      <WppEnabled>true</WppEnabled>+
> <WppRecorderEnabled>true</WppRecorderEnabled>+
> <WppScanConfigurationData
> Condition="'%(ClCompile.ScanConfigurationData)' ==
> ''">trace.h</WppScanConfigurationData>+
> <WppKernelMode>true</WppKernelMode>+    </ClCompile>+
> </ItemDefinitionGroup>+  <ItemDefinitionGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">+
> <ClCompile>+      <WppEnabled>true</WppEnabled>+
> <WppRecorderEnabled>true</WppRecorderEnabled>+
> <WppScanConfigurationData
> Condition="'%(ClCompile.ScanConfigurationData)' ==
> ''">trace.h</WppScanConfigurationData>+
> <WppKernelMode>true</WppKernelMode>+    </ClCompile>+
> </ItemDefinitionGroup>+  <ItemDefinitionGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">+
> <ClCompile>+      <WppEnabled>true</WppEnabled>+
> <WppRecorderEnabled>true</WppRecorderEnabled>+
> <WppScanConfigurationData
> Condition="'%(ClCompile.ScanConfigurationData)' ==
> ''">trace.h</WppScanConfigurationData>+
> <WppKernelMode>true</WppKernelMode>+    </ClCompile>+
> </ItemDefinitionGroup>+  <ItemDefinitionGroup
> Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">+
> <ClCompile>+      <WppEnabled>true</WppEnabled>+
> <WppRecorderEnabled>true</WppRecorderEnabled>+
> <WppScanConfigurationData
> Condition="'%(ClCompile.ScanConfigurationData)' ==
> ''">trace.h</WppScanConfigurationData>+
> <WppKernelMode>true</WppKernelMode>+    </ClCompile>+
> </ItemDefinitionGroup>+  <ItemDefinitionGroup
> Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">+
> <ClCompile>+      <WppEnabled>true</WppEnabled>+
> <WppRecorderEnabled>true</WppRecorderEnabled>+
> <WppScanConfigurationData
> Condition="'%(ClCompile.ScanConfigurationData)' ==
> ''">trace.h</WppScanConfigurationData>+
> <WppKernelMode>true</WppKernelMode>+    </ClCompile>+
> </ItemDefinitionGroup>+  <ItemGroup>+    <FilesToPackage
> Include="$(TargetPath)" />+  </ItemGroup>+  <Import
> Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />+  <ImportGroup
> Label="ExtensionTargets">+  </ImportGroup>+</Project>
> \ No newline at end of file
> diff --git a/windows/virt2phys/virt2phys.vcxproj.filters
> b/windows/virt2phys/virt2phys.vcxproj.filters
> new file mode 100644
> index 0000000..0fe65fc
> --- /dev/null
> +++ b/windows/virt2phys/virt2phys.vcxproj.filters
> @@ -0,0 +1,36 @@
> +<?xml version="1.0" encoding="utf-8"?>+<Project ToolsVersion="4.0"
> xmlns="https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2
> Fschemas.microsoft.com%2Fdeveloper%2Fmsbuild%2F2003&amp;data=02%
> 7C01%7Cophirmu%40mellanox.com%7C86da431f2b904dca3d8208d7e0ac4c
> d0%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C637224902939
> 685478&amp;sdata=N7HPDma1qrXV6sobOS0tblhsgaEUePD8lXqhnyXD1sU%
> 3D&amp;reserved=0">+  <ItemGroup>+    <Filter Include="Source Files">+
> <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-
> 2A32D752A2FF}</UniqueIdentifier>+
> <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>+
> </Filter>+    <Filter Include="Header Files">+
> <UniqueIdentifier>{93995380-89BD-4b04-88EB-
> 625FBE52EBFB}</UniqueIdentifier>+
> <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>+    </Filter>+    <Filter
> Include="Resource Files">+      <UniqueIdentifier>{67DA6AB6-F800-4c08-
> 8B7A-83BB121AAD01}</UniqueIdentifier>+
> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;pn
> g;wav;mfcribbon-ms</Extensions>+    </Filter>+    <Filter Include="Driver
> Files">+      <UniqueIdentifier>{8E41214B-6785-4CFE-B992-
> 037D68949A14}</UniqueIdentifier>+
> <Extensions>inf;inv;inx;mof;mc;</Extensions>+    </Filter>+  </ItemGroup>+
> <ItemGroup>+    <Inf Include="virt2phys.inf">+      <Filter>Driver
> Files</Filter>+    </Inf>+  </ItemGroup>+  <ItemGroup>+    <ClInclude
> Include="virt2phys.h">+      <Filter>Header Files</Filter>+    </ClInclude>+
> </ItemGroup>+  <ItemGroup>+    <ClCompile Include="virt2phys.c">+
> <Filter>Source Files</Filter>+    </ClCompile>+  </ItemGroup>+</Project>--
> 2.25.1
  

Patch

diff --git a/windows/README.rst b/windows/README.rst
new file mode 100644
index 0000000..45a1d80
--- /dev/null
+++ b/windows/README.rst
@@ -0,0 +1,103 @@ 
+Developing Windows Drivers
+==========================
+
+Prerequisites
+-------------
+
+Building Windows Drivers is only possible on Windows.
+
+1. Visual Studio 2019 Community or Professional Edition
+2. Windows Driver Kit (WDK) for Windows 10, version 1903
+
+Follow the official instructions to obtain all of the above:
+https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk
+
+
+Build the Drivers
+-----------------
+
+Build from Visual Studio
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Open a solution (``*.sln``) with Visual Studio and build it (Ctrl+Shift+B).
+
+
+Build from Command-Line
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Run *Developer Command Prompt for VS 2019* from the Start menu.
+
+Navigate to the solution directory (with ``*.sln``), then run:
+
+.. code-block:: console
+
+    msbuild
+
+To build a particular combination of configuration and platform:
+
+.. code-block:: console
+
+    msbuild -p:Configuration=Debug;Platform=x64
+
+
+Install the Drivers
+-------------------
+
+Disable Driver Signature Enforcement
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+By default Windows prohibits installing and loading drivers without `digital
+signature`_ obtained from Microsoft. For development signature enforcement may
+be disabled as follows.
+
+In Elevated Command Prompt (from this point, sufficient privileges are
+assumed):
+
+.. code-block:: console
+
+    bcdedit -set loadoptions DISABLE_INTEGRITY_CHECKS
+    bcdedit -set TESTSIGNING ON
+    shutdown -r -t 0
+
+Upon reboot, an overlay message should appear on the desktop informing
+that Windows is in test mode, which means it allows loading unsigned drivers.
+
+.. _digital signature: https://docs.microsoft.com/en-us/windows-hardware/drivers/install/driver-signing
+
+Install, List, and Remove Drivers
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Driver package is by default located in a subdirectory of its source tree,
+e.g. ``x64\Debug\virt2phys\virt2phys`` (note two levels of ``virt2phys``).
+
+To install the driver and bind associated devices to it:
+
+.. code-block:: console
+
+    pnputil /add-driver x64\Debug\virt2phys\virt2phys\virt2phys.inf /install
+
+A graphical confirmation to load an unsigned driver will still appear.
+
+On Windows Server additional steps are required if the driver uses a custom
+setup class:
+
+1. From "Device Manager", "Action" menu, select "Add legacy hardware".
+2. It will launch the "Add Hardware Wizard". Click "Next".
+3. Select second option "Install the hardware that I manually select
+   from a list (Advanced)".
+4. On the next screen, locate the driver device class.
+5. Select it, and click "Next".
+6. The previously installed drivers will now be installed for
+   the appropriate devices (software devices will be created).
+
+To list installed drivers:
+
+.. code-block:: console
+
+    pnputil /enum-drivers
+
+To remove the driver package and to uninstall its devices:
+
+.. code-block:: console
+
+    pnputil /delete-driver oem2.inf /uninstall
diff --git a/windows/virt2phys/virt2phys.c b/windows/virt2phys/virt2phys.c
new file mode 100644
index 0000000..e157e9c
--- /dev/null
+++ b/windows/virt2phys/virt2phys.c
@@ -0,0 +1,129 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2020 Dmitry Kozlyuk
+ */
+
+#include <ntddk.h>
+#include <wdf.h>
+#include <wdmsec.h>
+#include <initguid.h>
+
+#include "virt2phys.h"
+
+DRIVER_INITIALIZE DriverEntry;
+EVT_WDF_DRIVER_DEVICE_ADD virt2phys_driver_EvtDeviceAdd;
+EVT_WDF_IO_IN_CALLER_CONTEXT virt2phys_device_EvtIoInCallerContext;
+
+NTSTATUS
+DriverEntry(
+	IN PDRIVER_OBJECT driver_object, IN PUNICODE_STRING registry_path)
+{
+	WDF_DRIVER_CONFIG config;
+	WDF_OBJECT_ATTRIBUTES attributes;
+	NTSTATUS status;
+
+	PAGED_CODE();
+
+	WDF_DRIVER_CONFIG_INIT(&config, virt2phys_driver_EvtDeviceAdd);
+	WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
+	status = WdfDriverCreate(
+			driver_object, registry_path,
+			&attributes, &config, WDF_NO_HANDLE);
+	if (!NT_SUCCESS(status)) {
+		KdPrint(("WdfDriverCreate() failed, status=%08x\n", status));
+	}
+
+	return status;
+}
+
+_Use_decl_annotations_
+NTSTATUS
+virt2phys_driver_EvtDeviceAdd(
+	WDFDRIVER driver, PWDFDEVICE_INIT init)
+{
+	WDF_OBJECT_ATTRIBUTES attributes;
+	WDFDEVICE device;
+	NTSTATUS status;
+
+	UNREFERENCED_PARAMETER(driver);
+
+	PAGED_CODE();
+
+	WdfDeviceInitSetIoType(
+		init, WdfDeviceIoNeither);
+	WdfDeviceInitSetIoInCallerContextCallback(
+		init, virt2phys_device_EvtIoInCallerContext);
+
+	WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
+
+	status = WdfDeviceCreate(&init, &attributes, &device);
+	if (!NT_SUCCESS(status)) {
+		KdPrint(("WdfDeviceCreate() failed, status=%08x\n", status));
+		return status;
+	}
+
+	status = WdfDeviceCreateDeviceInterface(
+			device, &GUID_DEVINTERFACE_VIRT2PHYS, NULL);
+	if (!NT_SUCCESS(status)) {
+		KdPrint(("WdfDeviceCreateDeviceInterface() failed, "
+			"status=%08x\n", status));
+		return status;
+	}
+
+	return STATUS_SUCCESS;
+}
+
+_Use_decl_annotations_
+VOID
+virt2phys_device_EvtIoInCallerContext(
+	IN WDFDEVICE device, IN WDFREQUEST request)
+{
+	WDF_REQUEST_PARAMETERS params;
+	ULONG code;
+	PVOID *virt;
+	PHYSICAL_ADDRESS *phys;
+	size_t size;
+	NTSTATUS status;
+
+	UNREFERENCED_PARAMETER(device);
+
+	PAGED_CODE();
+
+	WDF_REQUEST_PARAMETERS_INIT(&params);
+	WdfRequestGetParameters(request, &params);
+
+	if (params.Type != WdfRequestTypeDeviceControl) {
+		KdPrint(("bogus request type=%u\n", params.Type));
+		WdfRequestComplete(request, STATUS_NOT_SUPPORTED);
+		return;
+	}
+
+	code = params.Parameters.DeviceIoControl.IoControlCode;
+	if (code != IOCTL_VIRT2PHYS_TRANSLATE) {
+		KdPrint(("bogus IO control code=%lu\n", code));
+		WdfRequestComplete(request, STATUS_NOT_SUPPORTED);
+		return;
+	}
+
+	status = WdfRequestRetrieveInputBuffer(
+			request, sizeof(*virt), (PVOID *)&virt, &size);
+	if (!NT_SUCCESS(status)) {
+		KdPrint(("WdfRequestRetrieveInputBuffer() failed, "
+			"status=%08x\n", status));
+		WdfRequestComplete(request, status);
+		return;
+	}
+
+	status = WdfRequestRetrieveOutputBuffer(
+		request, sizeof(*phys), (PVOID *)&phys, &size);
+	if (!NT_SUCCESS(status)) {
+		KdPrint(("WdfRequestRetrieveOutputBuffer() failed, "
+			"status=%08x\n", status));
+		WdfRequestComplete(request, status);
+		return;
+	}
+
+	*phys = MmGetPhysicalAddress(*virt);
+
+	WdfRequestCompleteWithInformation(
+		request, STATUS_SUCCESS, sizeof(*phys));
+}
diff --git a/windows/virt2phys/virt2phys.h b/windows/virt2phys/virt2phys.h
new file mode 100644
index 0000000..4bb2b4a
--- /dev/null
+++ b/windows/virt2phys/virt2phys.h
@@ -0,0 +1,34 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2020 Dmitry Kozlyuk
+ */
+
+/**
+ * @file virt2phys driver interface
+ */
+
+/**
+ * Driver device interface GUID {539c2135-793a-4926-afec-d3a1b61bbc8a}.
+ */
+DEFINE_GUID(GUID_DEVINTERFACE_VIRT2PHYS,
+	0x539c2135, 0x793a, 0x4926,
+	0xaf, 0xec, 0xd3, 0xa1, 0xb6, 0x1b, 0xbc, 0x8a);
+
+/**
+ * Driver device type for IO control codes.
+ */
+#define VIRT2PHYS_DEVTYPE 0x8000
+
+/**
+ * Translate a valid non-paged virtual address to a physical address.
+ *
+ * Note: A physical address zero (0) is reported if input address
+ * is paged out or not mapped. However, if input is a valid mapping
+ * of I/O port 0x0000, output is also zero. There is no way
+ * to distinguish between these cases by return value only.
+ *
+ * Input: a non-paged virtual address (PVOID).
+ *
+ * Output: the corresponding physical address (LARGE_INTEGER).
+ */
+#define IOCTL_VIRT2PHYS_TRANSLATE CTL_CODE( \
+	VIRT2PHYS_DEVTYPE, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
diff --git a/windows/virt2phys/virt2phys.inf b/windows/virt2phys/virt2phys.inf
new file mode 100644
index 0000000..e35765e
--- /dev/null
+++ b/windows/virt2phys/virt2phys.inf
@@ -0,0 +1,64 @@ 
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright (c) 2020 Dmitry Kozlyuk
+
+[Version]
+Signature = "$WINDOWS NT$"
+Class = %ClassName%
+ClassGuid = {78A1C341-4539-11d3-B88D-00C04FAD5171}
+Provider = %ManufacturerName%
+CatalogFile = virt2phys.cat
+DriverVer =
+
+[DestinationDirs]
+DefaultDestDir = 12
+
+; ================= Class section =====================
+
+[ClassInstall32]
+Addreg = virt2phys_ClassReg
+
+[virt2phys_ClassReg]
+HKR,,,0,%ClassName%
+HKR,,Icon,,-5
+
+[SourceDisksNames]
+1 = %DiskName%,,,""
+
+[SourceDisksFiles]
+virt2phys.sys  = 1,,
+
+;*****************************************
+; Install Section
+;*****************************************
+
+[Manufacturer]
+%ManufacturerName%=Standard,NT$ARCH$
+
+[Standard.NT$ARCH$]
+%virt2phys.DeviceDesc%=virt2phys_Device, Root\virt2phys
+
+[virt2phys_Device.NT]
+CopyFiles = Drivers_Dir
+
+[Drivers_Dir]
+virt2phys.sys
+
+;-------------- Service installation
+[virt2phys_Device.NT.Services]
+AddService = virt2phys,%SPSVCINST_ASSOCSERVICE%, virt2phys_Service_Inst
+
+; -------------- virt2phys driver install sections
+[virt2phys_Service_Inst]
+DisplayName    = %virt2phys.SVCDESC%
+ServiceType    = 1 ; SERVICE_KERNEL_DRIVER
+StartType      = 3 ; SERVICE_DEMAND_START
+ErrorControl   = 1 ; SERVICE_ERROR_NORMAL
+ServiceBinary  = %12%\virt2phys.sys
+
+[Strings]
+SPSVCINST_ASSOCSERVICE = 0x00000002
+ManufacturerName = "Dmitry Kozlyuk"
+ClassName = "Kernel bypass"
+DiskName = "virt2phys Installation Disk"
+virt2phys.DeviceDesc = "Virtual to physical address translator"
+virt2phys.SVCDESC = "virt2phys Service"
diff --git a/windows/virt2phys/virt2phys.sln b/windows/virt2phys/virt2phys.sln
new file mode 100644
index 0000000..0f5ecdc
--- /dev/null
+++ b/windows/virt2phys/virt2phys.sln
@@ -0,0 +1,27 @@ 
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29613.14
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "virt2phys", "virt2phys.vcxproj", "{0EEF826B-9391-43A8-A722-BDD6F6115137}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x64 = Debug|x64
+		Release|x64 = Release|x64
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{0EEF826B-9391-43A8-A722-BDD6F6115137}.Debug|x64.ActiveCfg = Debug|x64
+		{0EEF826B-9391-43A8-A722-BDD6F6115137}.Debug|x64.Build.0 = Debug|x64
+		{0EEF826B-9391-43A8-A722-BDD6F6115137}.Debug|x64.Deploy.0 = Debug|x64
+		{0EEF826B-9391-43A8-A722-BDD6F6115137}.Release|x64.ActiveCfg = Release|x64
+		{0EEF826B-9391-43A8-A722-BDD6F6115137}.Release|x64.Build.0 = Release|x64
+		{0EEF826B-9391-43A8-A722-BDD6F6115137}.Release|x64.Deploy.0 = Release|x64
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {845012FB-4471-4A12-A1C4-FF7E05C40E8E}
+	EndGlobalSection
+EndGlobal
diff --git a/windows/virt2phys/virt2phys.vcxproj b/windows/virt2phys/virt2phys.vcxproj
new file mode 100644
index 0000000..fa51916
--- /dev/null
+++ b/windows/virt2phys/virt2phys.vcxproj
@@ -0,0 +1,228 @@ 
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|ARM">
+      <Configuration>Debug</Configuration>
+      <Platform>ARM</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|ARM">
+      <Configuration>Release</Configuration>
+      <Platform>ARM</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|ARM64">
+      <Configuration>Debug</Configuration>
+      <Platform>ARM64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|ARM64">
+      <Configuration>Release</Configuration>
+      <Platform>ARM64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="virt2phys.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="virt2phys.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <Inf Include="virt2phys.inf" />
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{0EEF826B-9391-43A8-A722-BDD6F6115137}</ProjectGuid>
+    <TemplateGuid>{497e31cb-056b-4f31-abb8-447fd55ee5a5}</TemplateGuid>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
+    <Configuration>Debug</Configuration>
+    <Platform Condition="'$(Platform)' == ''">Win32</Platform>
+    <RootNamespace>virt2phys</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <TargetVersion>Windows10</TargetVersion>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
+    <ConfigurationType>Driver</ConfigurationType>
+    <DriverType>KMDF</DriverType>
+    <DriverTargetPlatform>Universal</DriverTargetPlatform>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <TargetVersion>Windows10</TargetVersion>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
+    <ConfigurationType>Driver</ConfigurationType>
+    <DriverType>KMDF</DriverType>
+    <DriverTargetPlatform>Universal</DriverTargetPlatform>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <TargetVersion>Windows10</TargetVersion>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
+    <ConfigurationType>Driver</ConfigurationType>
+    <DriverType>KMDF</DriverType>
+    <DriverTargetPlatform>Universal</DriverTargetPlatform>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <TargetVersion>Windows10</TargetVersion>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
+    <ConfigurationType>Driver</ConfigurationType>
+    <DriverType>KMDF</DriverType>
+    <DriverTargetPlatform>Universal</DriverTargetPlatform>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
+    <TargetVersion>Windows10</TargetVersion>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
+    <ConfigurationType>Driver</ConfigurationType>
+    <DriverType>KMDF</DriverType>
+    <DriverTargetPlatform>Universal</DriverTargetPlatform>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
+    <TargetVersion>Windows10</TargetVersion>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
+    <ConfigurationType>Driver</ConfigurationType>
+    <DriverType>KMDF</DriverType>
+    <DriverTargetPlatform>Universal</DriverTargetPlatform>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
+    <TargetVersion>Windows10</TargetVersion>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
+    <ConfigurationType>Driver</ConfigurationType>
+    <DriverType>KMDF</DriverType>
+    <DriverTargetPlatform>Universal</DriverTargetPlatform>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
+    <TargetVersion>Windows10</TargetVersion>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
+    <ConfigurationType>Driver</ConfigurationType>
+    <DriverType>KMDF</DriverType>
+    <DriverTargetPlatform>Universal</DriverTargetPlatform>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
+    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
+    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
+    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
+    <DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WppEnabled>true</WppEnabled>
+      <WppRecorderEnabled>true</WppRecorderEnabled>
+      <WppScanConfigurationData Condition="'%(ClCompile.ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
+      <WppKernelMode>true</WppKernelMode>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WppEnabled>true</WppEnabled>
+      <WppRecorderEnabled>true</WppRecorderEnabled>
+      <WppScanConfigurationData Condition="'%(ClCompile.ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
+      <WppKernelMode>true</WppKernelMode>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WppEnabled>false</WppEnabled>
+      <WppRecorderEnabled>true</WppRecorderEnabled>
+      <WppScanConfigurationData Condition="'%(ClCompile.ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
+      <WppKernelMode>true</WppKernelMode>
+    </ClCompile>
+    <Link>
+      <AdditionalDependencies>$(DDK_LIB_PATH)wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+    <Inf>
+      <TimeStamp>0.1</TimeStamp>
+    </Inf>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WppEnabled>true</WppEnabled>
+      <WppRecorderEnabled>true</WppRecorderEnabled>
+      <WppScanConfigurationData Condition="'%(ClCompile.ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
+      <WppKernelMode>true</WppKernelMode>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
+    <ClCompile>
+      <WppEnabled>true</WppEnabled>
+      <WppRecorderEnabled>true</WppRecorderEnabled>
+      <WppScanConfigurationData Condition="'%(ClCompile.ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
+      <WppKernelMode>true</WppKernelMode>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
+    <ClCompile>
+      <WppEnabled>true</WppEnabled>
+      <WppRecorderEnabled>true</WppRecorderEnabled>
+      <WppScanConfigurationData Condition="'%(ClCompile.ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
+      <WppKernelMode>true</WppKernelMode>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
+    <ClCompile>
+      <WppEnabled>true</WppEnabled>
+      <WppRecorderEnabled>true</WppRecorderEnabled>
+      <WppScanConfigurationData Condition="'%(ClCompile.ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
+      <WppKernelMode>true</WppKernelMode>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
+    <ClCompile>
+      <WppEnabled>true</WppEnabled>
+      <WppRecorderEnabled>true</WppRecorderEnabled>
+      <WppScanConfigurationData Condition="'%(ClCompile.ScanConfigurationData)' == ''">trace.h</WppScanConfigurationData>
+      <WppKernelMode>true</WppKernelMode>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <FilesToPackage Include="$(TargetPath)" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/windows/virt2phys/virt2phys.vcxproj.filters b/windows/virt2phys/virt2phys.vcxproj.filters
new file mode 100644
index 0000000..0fe65fc
--- /dev/null
+++ b/windows/virt2phys/virt2phys.vcxproj.filters
@@ -0,0 +1,36 @@ 
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+    <Filter Include="Driver Files">
+      <UniqueIdentifier>{8E41214B-6785-4CFE-B992-037D68949A14}</UniqueIdentifier>
+      <Extensions>inf;inv;inx;mof;mc;</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <Inf Include="virt2phys.inf">
+      <Filter>Driver Files</Filter>
+    </Inf>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="virt2phys.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="virt2phys.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>