📜 ⬆️ ⬇️

Forwarding a video card to a guest OS from the Xen hypervisor

Prehistory


After reading this article , my girlfriend suggested trying to insert a second video card into my systemic and get two cars on the same hardware. We have come a long way together of trial and error, faced with interesting problems, the solution of which I would like to describe.

Hardware



Start


Initially, the XPC 1.5 beta virtualization platform (Xen Cloud Platform), which is based on the Xen hypervisor, was selected for the experiment. This platform is completely free, in addition, installation and launch into operation takes a few minutes. During the work, it turned out that it was impossible to start Skype on a virtual machine under XCP, it immediately ends with an error. The problem is described here and here . To fix it, you need to add one line to the sources and rebuild the Xen, on which XPC is based. Therefore, I switched to the free edition of Citrix Xen Server 6.0.2 in which this problem has already been fixed.

Another danger lurked when installing video card drivers. The fact is that the Catalyst Control Center calls the BSOD on the guest system (tested on both XCP and Xen Server). Therefore, you will have to install the driver through the task manager, the native installer can also cause BSOD when checking the video card.

As a result, the guest system received a full-fledged HD7770 at its disposal and passed all the tests. After the guest OS was fully configured, I created a linked copy (this allowed me to save some space on the SSD) and forwarded the second video card there.
Unfortunately, separate USB ports XCP and Xen Server are not able to forward, so I forwarded one USB controller to one machine (all rear ports), the second to another (all ports connected to the case). The built-in USB controllers hang on PCI and are therefore forwarded just like a video card.
')
For the sake of justice, it is worth noting that there is a separate USB probing in Xen, but in my opinion it is more difficult to manage it (you need some experience in Linux)

All this allowed us to fully use one system unit for work and games for two people and simultaneously run additional virtual machines on it, if necessary. The performance of the video card or processor was not noticed. There were no interruptions, freezes, or any problems other than those described above!

System performance evaluation (virtual machine with a wired video card)

image

Disk performance CrystalDiskMark (virtual machine with a wired video card)

image

Alternatives



Hyper-V 3.0 - MS Hypervisor

There is a free option with limited functionality. It does not suit us, because it does not yet have support for device passthrough. However, he has a very attractive RemoteFX technology, which allows you to get 3d acceleration through an RDP session. As I understand it, some modern games work with him, some do not. In addition, it is likely that there will be some emulation costs, which will reduce performance. I will definitely try this interesting technology and write a separate article.

ESXi - VMware hypervisor

Perhaps the most popular and powerful. During testing, he was a favorite because in almost everything, in my opinion, is superior to XenServer. Firstly, when creating virtual machines, it is possible to specify the fine settings of iron, which is undoubtedly useful in preparing images for casting on real hardware. XenServer, on the contrary, has only pre-prepared templates and does everything at its discretion. Secondly, it has three types of memory balancing at once, as well as allows to “give” to the guest machine a strictly defined amount of processor time. There is a free edition with a 32 GB memory limit. Passing (passthrough) PCI devices is the easiest thing to do here: ticking the required devices and adding them to the guest machine. However, only some video cards are successfully forwarded. Success does not depend on the manufacturer, both AMD and nVidia are being forwarded, but only a few. I was not lucky, the Radeon 7770 failed to transfer to the virtual machine. During the installation of the drivers we get BSOD.
During the skipping I was faced with a very interesting bug that can stump. The fact is that if the guest machine is allocated more than 2 GB of memory, then after forwarding the video card, the machine will not start! I found the solution to the problem here .
This hypervisor has another problem: You can’t just take it and put it on regular hardware. Only for certified! At the initial stage of the installation, he did not find a suitable network card and refused to continue. Oddly enough, because built into my mate. The network adapter card is Intel 82579, not the worst option, you must agree. Next, I found D-link DGE 528T in the bins, but it does not support this board either. Googling a bit, found the following solution . Having patched the image, we still managed to install ESXi 5.1.

Xen - a hypervisor under the GPL license

Many commercial products have been made based on it, for example, the very popular now Citrix XenServer, or the little-known Oracle VM. I see three options for using this hypervisor:
  1. Use Xen itself (the longest way). In this case, we will need to install some Linux distribution, then install Xen on it and configure it. In this case, the configuration and launch of virtual machines and the hypervisor itself will be done by creating and editing configuration files. All management through the command line.
  2. Use open XCP (Xen Cloud Platform). In this case, we are able to manage the hypervisor, as well as guest OS using third-party applications (conveniently and quickly). The best combination: XCP + Citrix XenCenter (free program to manage Citrix XenServer). XCP 1.5 beta is almost an exact copy of commercial Citrix XenServer 6.0, while the functionality of the free XCP is equal to the enterprise version of XenServer!
  3. Use commercial Citrix XenServer. There is a free edition with limited functionality: memory balancing is disabled, the video card is forwarded using XenCenter (the card is still forwarded through the command line). XenServer is based on XCP and is not much different from it, however Citrix releases frequent patches for XenServer, which is a key factor influencing the choice.


KVM

a little-studied hypervisor, I can hardly say anything about it. It seems that he can forward PCI devices, including video cards. As I understand it, it is not a separate platform, but is installed on Linux, after which it is configured. I am not a fan of picking on the command line and do not have enough experience in Linux, so I decided to consider it last.

Installing and configuring XenServer (or XCP) and forwarding a video card


I combined two different products, because one is actually a clone of the other, there are few differences in configuration (I will note them).

  1. We download from the official site XCP and XenServer (click try it Free from above). Even if you plan on using XPC, I recommend also downloading XenServer, since On the installation disk in the folder client_install is XenCenter, which will not be superfluous.
  2. Install the hypervisor on the iron. The installation is equipped with a master and will not cause difficulties. However, it is at the time of installation that you should choose the HDD for storing virtual machines, if you plan to use local disks, and not iSCSI. After installation, this can cause difficulties, because done only from the command line.
  3. We install Citrix XenCenter from a Citrix XenServer image on any PC on the same local network (we downloaded it in the first step). Launch XenCenter and connect to our server.
  4. (Only for XPC !!!) To complete the work of XenCenter with XCP 1.5 beta, you need to run the following commands in the hypervisor console:
    cd /opt/xensource/bin /etc/init.d/xapi stop cp -vp xapi xapi.original sed -i 's/1\.4\.90/6.0.99/g' xapi /etc/init.d/xapi start 

    After that, tabs will appear in XenCenter, allowing you to enable memory balancing, as well as perform forwarding of the video card to the guest machines.
  5. Create a new virtual machine by selecting the template we need - Windows 7 (64-bit)
  6. Go to the Console tab of the virtual machine that appeared in XenCenter and install Windows 7 x64.
  7. Install the para-virtual drivers by mounting the xs-tools.iso image in the Console tab.
  8. We set a password for the user (needed for connecting through the terminal) and enable terminal access (Control Panel -> System -> Remote Access Setup). This is needed to access the guest OS after forwarding the video card, since the image will no longer be displayed in the console.
  9. Go to the console hypervisor. recruit
      lspci 

    and see a list of pci devices with ids. We remember the codes of the devices we need. For example, the video card in the first pci-e slot will have the identifier 01: 00.0, and the sound card embedded in it 01: 00.1.
  10. Typing
      xe vm-list 

    and see a list of virtual machines. We remember uuid identifiers of the machines we need. For example, d103a91d-5c38-844f-14d5-64b3c495eb08.
  11. For forwarding the video card we type
      xe vm-param-set other-config:pci=0/0000:01:00.0,0/0000:01:00.1 uuid=d103a91d-5c38-844f-14d5-64b3c495eb08 

    replacing the values ​​in the example with your own. Comma-separated all pci devices that we want to forward.
  12. Attention bug! Forwarding devices does not work normally if memory balancing is enabled for the guest.
    Balancing allows you to change the amount of memory on the fly. For example, there are two cars with a maximum memory limit of 8 GiB. Suppose a hypervisor has only 8 GiB of free memory available. Then, if one machine is turned on, the hypervisor allocates to it all 8 GiB of free memory, but it is worth running the second one, as the hypervisor changes the amount of memory for the first machine (on the fly, without stopping it). Thus, each will receive 4 GiB and use up all free memory.
    The essence of the bug is that if the amount of free memory of the hypervisor is less than the maximum amount of memory for the virtual machine, then when you start this machine, some of the forwarded PCI devices will fall off of it.
  13. We start guest OS and we see that there were new devices. We download the last Catalyst, unpack it into a folder without installing it, then go to the device manager and from there we update the video card driver, specifying the desired folder.
    The fact is that the Catalyst Control Center causes a BSOD, even if it succeeds in installing it, the video card will not work stably - image artifacts will pop up periodically.
  14. After the reboot, the virtual machine console in XenCenter will freeze during the Windows boot phase. So the video card is thrown, you can connect the monitor to its connector!


Links (short)


General Information : Wiki ( Wiki )
Xen : Forwarding a video card in Xen, from under Ubuntu ( Habr )
Forwarding a video card to a virtual machine (Habr)
Xen : XenVGAPassthrough (legacy) ( Wiki.xen.org )
Xen : Xen VGA Passthrough (new) ( Wiki.xen.org )
XenServer and XCP : XenServer 5.6 Multi-GPU Passthrough for XenDesktop HDX 3D Pro Graphics ( support.citrix.com )
XenServer and XCP : PCI passthrough for paravirtualized guests on Citrix XenServer without an IOMMU ( ogris.de/howtos )
XCP : Fixing a bug with XenCenter for XCP ( gossamer-threads.com )

Finally, I will add that at the time of writing this article from under one machine, my girlfriend sat side by side, playing Skyrim on the other without any lags and brakes at high (partially ultra) graphics settings. Under the table there is one sistemnik, which saves space and money, there are two monitors on the table.

Source: https://habr.com/ru/post/151661/


All Articles