Deploy graphics devices using Discrete Device Assignment

In this article

Starting with Windows Server 2016, you can use Discrete Device Assignment, or DDA, to pass an entire PCIe Device into a VM. This will allow high performance access to devices like NVMe storage or Graphics Cards from within a VM while being able to leverage the devices native drivers. Please visit the Plan for Deploying Devices using Discrete Device Assignment for more details on which devices work, what are the possible security implications, etc.

There are three steps to using a device with Discrete Device Assignment:

Configure the VM for Discrete Device Assignment

Dismount the Device from the Host Partition

Assigning the Device to the Guest VM

All command can be executed on the Host on a Windows PowerShell console as an Administrator.

Configure the VM for DDA

Discrete Device Assignment imposes some restrictions to the VMs and the following step needs to be taken.

Configure greater than 32 bit MMIO space
Set-VM -HighMemoryMappedIoSpace 33280Mb -VMName VMName
Note, the MMIO space values above are reasonable values to set for experimenting with a single GPU. If after starting the VM, the device is reporting an error relating to not enough resources, you'll likely need to modify these values. Also, if you're assigning multiple GPUs, you'll need to increase these values as well.

Dismount the Device from the Host Partition

Optional - Install the Partitioning Driver

Discrete Device Assignment provide hardware venders the ability to provide a security mitigation driver with their devices. Note that this driver is not the same as the device driver that will be installed in the guest VM. It’s up to the hardware vendor’s discretion to provide this driver, however, if they do provide it, please install it prior to dismounting the device from the host partition. Please reach out to the hardware vendor for more information on if they have a mitigation driver

Locating the Device’s Location Path

The PCI Location path is required to dismount and mount the device from the Host. An example location path looks like the following: "PCIROOT(20)#PCI(0300)#PCI(0000)#PCI(0800)#PCI(0000)". More details on located the Location Path can be found here: Plan for Deploying Devices using Discrete Device Assignment.

Disable the Device

Using Device Manager or PowerShell, ensure the device is “disabled.”

Dismount the Device

Depending on if the vendor provided a mitigation driver, you’ll either need to use the “-force” option or not.

If a Mitigation Driver was installed
Dismount-VMHostAssignableDevice -LocationPath $locationPath

If a Mitigation Driver was not installed
Dismount-VMHostAssignableDevice -force -LocationPath $locationPath

Assigning the Device to the Guest VM

The final step is to tell Hyper-V that a VM should have access to the device. In addition to the location path found above, you'll need to know the name of the vm.

Add-VMAssignableDevice -LocationPath $locationPath -VMName VMName

What’s Next

After a device is successfully mounted in a VM, you’re now able to start that VM and interact with the device as you normally would if you were running on a bare metal system. This means that you’re now able to install the Hardware Vendor’s drivers in the VM and applications will be able to see that hardware present. You can verify this by opening device manager in the Guest VM and seeing that the hardware now shows up.

Removing a Device and Returning it to the Host

If you want to return he device back to its original state, you will need to stop the VM and issue the following:

#Remove the device from the VM
Remove-VMAssignableDevice -LocationPath $locationPath -VMName VMName
#Mount the device back in the host
Mount-VMHostAssignableDevice -LocationPath $locationPath

You can then re-enable the device in device manager and the host operating system will be able to interact with the device again.

Examples

Mounting a GPU to a VM

In this example we use PowerShell to configure a VM named “ddatest1” to take the first GPU available by the manufacturer NVIDIA and assign it into the VM.