Short report (WIP): Got the NVIDIA GPU to passthrough on an optimus laptop
Since there haven't been any successful posts regarding this setup, I'm sharing this so that others can try and improve this. This should work on at least a few thinkpads.
Laptop: Thinkpad W530, Card: Quadro K2000M
What works (so far): Linux host, Linux guest with nouveau driver
Setup: Pretty standard. Luckily, the IOMMU group is isolated with only the GPU and a bridge in it. GPU can be passed through without too much trouble.
Main challenges:
- GPU vbios isn't easily accessible in this setup since it's not on the card. It's a part of the system bios, which the driver is supposed to read through ACPI calls.
- There are a few ways to extract it. I tried nouveau's debugfs interface first. It has the useful stuff that nouveau needs, but it is truncated. Eventually, a full bios with passing signatures will be needed. I've got the full rom too from a couple of other tools. PM me if you need the ROM.
- Since the guest cannot read the rom on its own, it needs to be passed as a file. This can be done as the romfile option, or by baking it into initramfs on the guest, and adding a kernel boot arg "nouveau.config=NvBios=path-to-file". This is all that is needed to make passthrough work.
- Next thing I tired was installing nvidia drivers on the guest. This fails even if you pass the pci rom because nvidia drivers know that this is an optimus card, and only try the acpi method to get the bios. They error out with a message like "Failed to load vbios into system memory" .
Next steps:
- The BIOS+ACPI need to be patched so that the nvidia drivers on the guest can load properly. Coreboot has some documentation and builds regarding this stuff. I think that should be helpful.
- Windows guest. I haven't tried this yet, but I highly doubt that it will work unless the linux guest with nvidia drivers works first.
Other quibbles:
- libvirt on Ubuntu 16.04 has a bug that doesn't allow the rom file option. It errors out with a permissions error no matter what the permissions of the file are. Calling qemu directly works.
- I haven't been able to get my mouse + keyboard to work in this setup. I'm pretty new to this stuff. What's the standard way of doing this ? I tried passing my external mouse and keyboard, but that didn't work. I was able to do some basic testing with synergy, which was crap. I'll probably never use that again.
Acknowledgements:
Thanks to imirkin_ on the nouveau irc for all the help.
Posted Jul 28, 2017, 10:38 PM UTC · edited
I got as far as GPU vbios, and didn't think it was worth gambling all the brain damage getting the rom on maybe having a system that probably wouldn't take drivers. Is this pretty repeatable if I were to get a laptop with a k200m? I tried on a Dell E6520, k200m sounds familiar. I don't see any thinkpad w30's on ebay.....
You could pass the usb devices individually, I'm used to doing this in xml & using libvirt.
If you were to install a new VM, booting from the install cd, do you see the output on the lcd, or is this only after you load drivers?
I'd be interested in the rom & a more detailed walkthrough.
This is very cool , good job!!
Sorry, there were a couple of typos. The laptop is W530 and the card is K2000M. Yes, Dell and HP also had a couple of models with the same card. This is an optimus setup with a hardware mux. So you can operate the laptop as integrated only, optimus, or discrete only. Modern laptops don't have the integrated only option. So I'm not sure if the GPU can be sufficiently detached that they can be passed through in newer laptops. This should be repeatable if you get a w530 with a k2000m. I would advise waiting though for more reports. I tried passing individual devices for keyboard and mouse in virt-manager, but that didn't work. However, my peripherals were connected to the dock. Maybe that plays a role. Since this was just proof of concept, I didn't spend too much time on it.
Those I saw on ebay. I think the dell had only 2 options in the bios. Does the vm play out of laptop lcd or do you need the monitor?
That's an old ass keyboard.
Yes, the keyboard is an IBM model M from the 80s. The vm needs the monitor. This laptop's wiring is a bit peculiar. The igpu is connected to the lcd. All the external ports are connected to the nvidia gpu. If you want to use the discrete gpu on the lcd, it writes to the igpu's framebuffer, which then shows it on the lcd. This has been a source of headache for years on linux. Things are getting a bit better now though. For the passthrough case, you completely decouple the igpu and the discrete gpu. So igpu only drives the lcd, and the discrete one only drives external ports.