[1/1] virt2phys: virtual to physical address translator for Windows
Checks
Commit Message
This patch is for dpdk-kmods tree.
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. UIO drivers might also implement virt2phys
interface, thus rendering this separate driver unneeded.
Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
windows/README.rst | 79 +++++++
windows/virt2phys/virt2phys.c | 129 +++++++++++
windows/virt2phys/virt2phys.h | 34 +++
windows/virt2phys/virt2phys.inf | 85 ++++++++
windows/virt2phys/virt2phys.sln | 27 +++
windows/virt2phys/virt2phys.vcxproj | 228 ++++++++++++++++++++
windows/virt2phys/virt2phys.vcxproj.filters | 36 ++++
7 files changed, 618 insertions(+)
create mode 100644 windows/README.rst
create mode 100755 windows/virt2phys/virt2phys.c
create mode 100755 windows/virt2phys/virt2phys.h
create mode 100755 windows/virt2phys/virt2phys.inf
create mode 100755 windows/virt2phys/virt2phys.sln
create mode 100755 windows/virt2phys/virt2phys.vcxproj
create mode 100755 windows/virt2phys/virt2phys.vcxproj.filters
Comments
On Mon, Mar 30, 2020 at 9:40 AM Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> wrote:
>
> This patch is for dpdk-kmods tree.
>
> 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. UIO drivers might also implement virt2phys
> interface, thus rendering this separate driver unneeded.
>
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
> windows/README.rst | 79 +++++++
> windows/virt2phys/virt2phys.c | 129 +++++++++++
> windows/virt2phys/virt2phys.h | 34 +++
> windows/virt2phys/virt2phys.inf | 85 ++++++++
> windows/virt2phys/virt2phys.sln | 27 +++
> windows/virt2phys/virt2phys.vcxproj | 228 ++++++++++++++++++++
> windows/virt2phys/virt2phys.vcxproj.filters | 36 ++++
> 7 files changed, 618 insertions(+)
> create mode 100644 windows/README.rst
> create mode 100755 windows/virt2phys/virt2phys.c
> create mode 100755 windows/virt2phys/virt2phys.h
> create mode 100755 windows/virt2phys/virt2phys.inf
> create mode 100755 windows/virt2phys/virt2phys.sln
> create mode 100755 windows/virt2phys/virt2phys.vcxproj
> create mode 100755 windows/virt2phys/virt2phys.vcxproj.filters
>
> diff --git a/windows/README.rst b/windows/README.rst
> new file mode 100644
> index 0000000..84506fa
> --- /dev/null
> +++ b/windows/README.rst
> @@ -0,0 +1,79 @@
> +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
Looks like WDK is licence is "Proprietary commercial software".
I am just wondering, Can we package this driver in binary form for
end-users to whose scope
is to not develop Windows DPDK but fixing any issues reported by build
CI for Window due
to generic EAL patches or so.
> +
> +Follow the official instructions to obtain all of the above:
> +https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk
> +
> > +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
>
> Looks like WDK is licence is "Proprietary commercial software".
>
> I am just wondering, Can we package this driver in binary form for
> end-users to whose scope
> is to not develop Windows DPDK but fixing any issues reported by build
> CI for Window due
> to generic EAL patches or so.
As cover letter says, this driver should not be required in the end. For
netUIO, Harini announced at Windows community call 2020-03-14 that it will be
freely available in binary form hosted by Microsoft. In general, publishing
driver binaries is OK, take virtio for example:
https://www.linux-kvm.org/page/WindowsGuestDrivers/Download_Drivers
Driver signing is a different matter, but CI probably doesn't require it.
On 3/29/2020 9:10 PM, Dmitry Kozlyuk wrote:
> This patch is for dpdk-kmods tree.
>
> 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. UIO drivers might also implement virt2phys
> interface, thus rendering this separate driver unneeded.
>
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
<Snip!>
> +
> +_Use_decl_annotations_
> +VOID
> +virt2phys_device_EvtIoInCallerContext(
> + IN WDFDEVICE device, IN WDFREQUEST request)
> +{
> + WDF_REQUEST_PARAMETERS params;
> + ULONG code;
> + PVOID *virt;
Should this be PVOID virt; (instead of PVOID *virt)?
If so, changes will be required to parameters passed in to
WdfRequestRetrieveInputBuffer() call.
> + PHYSICAL_ADDRESS *phys;
> + size_t size;
> + NTSTATUS status;
> +
> + UNREFERENCED_PARAMETER(device);
> +
> + PAGED_CODE();
> +
> + WDF_REQUEST_PARAMETERS_INIT(¶ms);
> + WdfRequestGetParameters(request, ¶ms);
> +
> + 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), &phys, &size);
Better to put a (PVOID *)typecast for &phys here:
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));
> +}
<Snip!>
Co-installers are no longer required (and discouraged) as per Microsoft.
So you can remove the lines indicated below from the .inf file.
> diff --git a/windows/virt2phys/virt2phys.inf b/windows/virt2phys/virt2phys.inf
> new file mode 100755
> index 0000000..e8adaac
> --- /dev/null
> +++ b/windows/virt2phys/virt2phys.inf
> @@ -0,0 +1,85 @@
> +; 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
> +virt2phys_Device_CoInstaller_CopyFiles = 11
Remove this line
> +
> +; ================= Class section =====================
> +
> +[ClassInstall32]
> +Addreg = virt2phys_ClassReg
> +
> +[virt2phys_ClassReg]
> +HKR,,,0,%ClassName%
> +HKR,,Icon,,-5
> +
> +[SourceDisksNames]
> +1 = %DiskName%,,,""
> +
> +[SourceDisksFiles]
> +virt2phys.sys = 1,,
> +WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll = 1
Remove this line
> +
> +;*****************************************
> +; 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
> +
Remove entire co-installer section below
> +;
> +;--- virt2phys_Device Coinstaller installation ------
> +;
> +
> +[virt2phys_Device.NT.CoInstallers]
> +AddReg = virt2phys_Device_CoInstaller_AddReg
> +CopyFiles = virt2phys_Device_CoInstaller_CopyFiles
> +
> +[virt2phys_Device_CoInstaller_AddReg]
> +HKR,,CoInstallers32,0x00010000, "WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller"
> +
> +[virt2phys_Device_CoInstaller_CopyFiles]
> +WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll
> +
Remove up to here
> +[virt2phys_Device.NT.Wdf]
> +KmdfService = virt2phys, virt2phys_wdfsect
> +[virt2phys_wdfsect]
> +KmdfLibraryVersion = $KMDFVERSION$
> +
> +[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"
<Snip!>
ranjit m.
> > +
> > +_Use_decl_annotations_
> > +VOID
> > +virt2phys_device_EvtIoInCallerContext(
> > + IN WDFDEVICE device, IN WDFREQUEST request)
> > +{
> > + WDF_REQUEST_PARAMETERS params;
> > + ULONG code;
> > + PVOID *virt;
>
> Should this be PVOID virt; (instead of PVOID *virt)?
> If so, changes will be required to parameters passed in to
> WdfRequestRetrieveInputBuffer() call.
This should be PVOID *virt (pointer to an untyped pointer). User-mode passes
a virtual address as a PVOID value, WdfRequestRetrieveInputBuffer() fills
virt with the address of that parameter, so that *virt is the virtual address
user-mode wants to translate into a physical one.
>
> > + PHYSICAL_ADDRESS *phys;
> > + size_t size;
> > + NTSTATUS status;
> > +
[snip]
> > +
> > + status = WdfRequestRetrieveOutputBuffer(
> > + request, sizeof(*phys), &phys, &size);
>
> Better to put a (PVOID *)typecast for &phys here:
> status = WdfRequestRetrieveOutputBuffer(
> request, sizeof(*phys), (PVOID *)&phys, &size);
What do you mean? Without a typecast the built-in static analyzer emits a
warning (and all warnings are treated as errors for a driver):
virt2phys.c(108,46): error C2220: the following warning is treated as an error
virt2phys.c(108,46): warning C4047: 'function': 'PVOID *' differs in levels of indirection from 'PVOID **'
virt2phys.c(108,46): warning C4022: 'WdfRequestRetrieveInputBuffer': pointer mismatch for actual parameter 3
> > + if (!NT_SUCCESS(status)) {
> > + KdPrint(("WdfRequestRetrieveOutputBuffer() failed, "
> > + "status=%08x\n", status));
> > + WdfRequestComplete(request, status);
> > + return;
> > + }
> > +
> > + *phys = MmGetPhysicalAddress(*virt);
> > +
> > + WdfRequestCompleteWithInformation(
> > + request, STATUS_SUCCESS, sizeof(*phys));
> > +}
>
> <Snip!>
>
> Co-installers are no longer required (and discouraged) as per Microsoft.
> So you can remove the lines indicated below from the .inf file.
Thanks, will remove in v2. They were generated by WDK solution template.
> >
> > > + PHYSICAL_ADDRESS *phys;
> > > + size_t size;
> > > + NTSTATUS status;
> > > +
> [snip]
> > > +
> > > + status = WdfRequestRetrieveOutputBuffer(
> > > + request, sizeof(*phys), &phys, &size);
> >
> > Better to put a (PVOID *)typecast for &phys here:
> > status = WdfRequestRetrieveOutputBuffer(
> > request, sizeof(*phys), (PVOID *)&phys, &size);
>
> What do you mean? Without a typecast the built-in static analyzer emits a
> warning (and all warnings are treated as errors for a driver):
>
> virt2phys.c(108,46): error C2220: the following warning is treated as an error
> virt2phys.c(108,46): warning C4047: 'function': 'PVOID *' differs in levels of indirection from 'PVOID **'
> virt2phys.c(108,46): warning C4022: 'WdfRequestRetrieveInputBuffer': pointer mismatch for actual parameter 3
>
Never mind, I thought you were referring to the existing typecast in
WdfRequestRetrieveInputBuffer(). Thanks for the suggestion, will add in v2.
On 4/9/2020 7:50 PM, Dmitry Kozlyuk wrote:
>>> +
>>> +_Use_decl_annotations_
>>> +VOID
>>> +virt2phys_device_EvtIoInCallerContext(
>>> + IN WDFDEVICE device, IN WDFREQUEST request)
>>> +{
>>> + WDF_REQUEST_PARAMETERS params;
>>> + ULONG code;
>>> + PVOID *virt;
>>
>> Should this be PVOID virt; (instead of PVOID *virt)?
>> If so, changes will be required to parameters passed in to
>> WdfRequestRetrieveInputBuffer() call.
>
> This should be PVOID *virt (pointer to an untyped pointer). User-mode passes
> a virtual address as a PVOID value, WdfRequestRetrieveInputBuffer() fills
> virt with the address of that parameter, so that *virt is the virtual address
> user-mode wants to translate into a physical one.
>
Makes sense. Thanks for the explanation, Dmitry.
>>
>>> + PHYSICAL_ADDRESS *phys;
>>> + size_t size;
>>> + NTSTATUS status;
>>> +
> [snip]
>>> +
>>> + status = WdfRequestRetrieveOutputBuffer(
>>> + request, sizeof(*phys), &phys, &size);
>>
>> Better to put a (PVOID *)typecast for &phys here:
>> status = WdfRequestRetrieveOutputBuffer(
>> request, sizeof(*phys), (PVOID *)&phys, &size);
>
> What do you mean? Without a typecast the built-in static analyzer emits a
> warning (and all warnings are treated as errors for a driver):
>
> virt2phys.c(108,46): error C2220: the following warning is treated as an error
> virt2phys.c(108,46): warning C4047: 'function': 'PVOID *' differs in levels of indirection from 'PVOID **'
> virt2phys.c(108,46): warning C4022: 'WdfRequestRetrieveInputBuffer': pointer mismatch for actual parameter 3
>
>>> + if (!NT_SUCCESS(status)) {
>>> + KdPrint(("WdfRequestRetrieveOutputBuffer() failed, "
>>> + "status=%08x\n", status));
>>> + WdfRequestComplete(request, status);
>>> + return;
>>> + }
>>> +
>>> + *phys = MmGetPhysicalAddress(*virt);
>>> +
>>> + WdfRequestCompleteWithInformation(
>>> + request, STATUS_SUCCESS, sizeof(*phys));
>>> +}
>>
>> <Snip!>
>>
>> Co-installers are no longer required (and discouraged) as per Microsoft.
>> So you can remove the lines indicated below from the .inf file.
>
> Thanks, will remove in v2. They were generated by WDK solution template.
>
I see the above changes in v2. Thanks!
ranjit m.
new file mode 100644
@@ -0,0 +1,79 @@
+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:
+
+ msbuild
+
+To build a particular combination of configuration and platform:
+
+ 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 (read more: `Driver Signing`_).
+For development signature enforcement may be disabled as follows.
+
+In Elevated Command Prompt:
+
+ 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.
+
+.. Driver Signing: https://docs.microsoft.com/en-us/windows-hardware/drivers/install/driver-signing
+
+
+Install, List, and Uninstall 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:
+
+ pnputil /add-driver x64\Debug\virt2phys\virt2phys\virt2phys.inf /install
+
+A graphical confirmation to load an unsigned driver will still appear.
+
+To list installed drivers:
+
+ pnputil /enum-drivers
+
+To remove the driver package and to uninstall its devices:
+
+ pnputil /delete-drive oem2.inf /install
new file mode 100755
@@ -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(¶ms);
+ WdfRequestGetParameters(request, ¶ms);
+
+ 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), &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));
+}
new file mode 100755
@@ -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)
new file mode 100755
@@ -0,0 +1,85 @@
+; 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
+virt2phys_Device_CoInstaller_CopyFiles = 11
+
+; ================= Class section =====================
+
+[ClassInstall32]
+Addreg = virt2phys_ClassReg
+
+[virt2phys_ClassReg]
+HKR,,,0,%ClassName%
+HKR,,Icon,,-5
+
+[SourceDisksNames]
+1 = %DiskName%,,,""
+
+[SourceDisksFiles]
+virt2phys.sys = 1,,
+WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll = 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
+
+;
+;--- virt2phys_Device Coinstaller installation ------
+;
+
+[virt2phys_Device.NT.CoInstallers]
+AddReg = virt2phys_Device_CoInstaller_AddReg
+CopyFiles = virt2phys_Device_CoInstaller_CopyFiles
+
+[virt2phys_Device_CoInstaller_AddReg]
+HKR,,CoInstallers32,0x00010000, "WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller"
+
+[virt2phys_Device_CoInstaller_CopyFiles]
+WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll
+
+[virt2phys_Device.NT.Wdf]
+KmdfService = virt2phys, virt2phys_wdfsect
+[virt2phys_wdfsect]
+KmdfLibraryVersion = $KMDFVERSION$
+
+[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"
new file mode 100755
@@ -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
new file mode 100755
@@ -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
new file mode 100755
@@ -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>