NVIDIA GPU Passthrough on an Optimus MUXed Laptop

A year ago, to simultaneously browse webpages and write codes on my Arch Linux installation and use Windows to run tasks infeasible on Linux (such as gaming), I tried GPU passthrough on my Lenovo R720 gaming laptop. But since that laptop has an Optimus MUXless architecture (as mentioned in that post), its dedicated GPU doesn't have output ports, and the integrated GPU is in charge of all the displays. Therefore, severe limitations exist for that setup, and I eventually gave up on it.But now, I've purchased a new laptop. The HDMI output port on this laptop is directly connected to its NVIDIA dedicated graphics card, or in other words, it has an Optimus MUXed architecture. Since there is a way to make the virtual machine aware of a "monitor on the dedicated GPU",...
Illustration

Intel and NVIDIA GPU Passthrough on a Optimus MUXless Laptop

Changelog2022-07-21: Add starting GVT-g on startup. Thanks to comment from Owsmyf (on Chinese version of this post).2022-01-22: Revisions on NVIDIA driver updates and comments.I successfully passed through an Optimus MUXed GPU on my new laptop.Abstract (Spoiler Alert!)I successfully passed through Intel's GVT-g virtual GPU, as well as the dedicated NVIDIA GPU itself, into a virtual machine on Lenovo R720 gaming laptop.However, due to the limitation of the architecture itself, this GPU passthrough scheme is severely limited. For example, the dGPU is unusable in many games, and the performance is still relatively worse despite the complicated setup it needs.Therefore, you may attempt the passthrough purely for the fun of tinkering, but I don't recommend using it for anything important....