Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save msnoigrs/da2e34e63ecc27de8be3d75f55f033b5 to your computer and use it in GitHub Desktop.

Select an option

Save msnoigrs/da2e34e63ecc27de8be3d75f55f033b5 to your computer and use it in GitHub Desktop.

Revisions

  1. @Misairu-G Misairu-G revised this gist Nov 12, 2018. 1 changed file with 10 additions and 9 deletions.
    19 changes: 10 additions & 9 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,8 @@
    - [Hardware](#hardware)
    - [System & Software](#system--software)
    - [Update: Attention for MUXless laptop](#update-attention-for-muxless-laptop)
    - [Some success report](#some-success-report)
    - [Some success report](#some-success-reports)
    - [Some fail report](#some-fail-reports)
    - [Bumblebee setup guide](#bumblebee-setup-guide)
    - [dGPU passthrough guide](#dgpu-passthrough-guide)
    - [System & Environment setup](#system--environment-setup)
    @@ -38,6 +39,8 @@ Sorry but currently I don't know how to check if your dGPU load its firmware thr

    **Update**: Use qemu 2.11.2 with pulse audio patch and vcpupin, add some caveats for 18.04

    **Update**: Outdated link to VirtIO windows-guest drivers, thanks to @pascalav, who also attach [a link of how to embed an ACPI table for VBIOS](https://gist.github.com/Misairu-G/616f7b2756c488148b7309addc940b28#gistcomment-2573646)

    # What to expect?

    Depends on your hardware, you can have a laptop that:
    @@ -77,7 +80,7 @@ Some might be heard of [gnif's phenomenal work](https://forum.level1techs.com/t/

    # Prerequisites

    Please noted that this tutorial does not support every Optimus laptop. Generally, a good laptop with some specific hardware capability is required. If you have a laptop that have a swappable MXM form factor graphics card, its highly possible that you'll success.
    Please noted that this tutorial does not support every Optimus laptop. Generally, a good laptop with some specific hardware capability is required. If you have a laptop that come with a swappable MXM form factor graphics card, its highly possible that you'll success.

    Also, due to the nature that laptop varies so much from manufacture to manufacture, there is no way you can tell if it is MUXed, or MUXless, or how a MUXless laptop load its firmware before you get your hands on it. However, the firmware loading mechanism of your GPU is crucial for resolving the infamous Code 43 problem. So please do enough homework (find some success report in particular) before you plan to purchase a laptop for this purpose.

    @@ -161,13 +164,11 @@ For people who encounter Code 43 with a MUXless scheme, that is to say, you can
    - Please refer to [u/jscinoz](https://www.reddit.com/u/jscinoz) 's [optimus-vfio-docs](https://github.com/jscinoz/optimus-vfio-docs) if you encounter such problem
    ### Some success report
    [Perdouille got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dqo6jxf/), with MSI GS60-040XFR with an i7-4720HQ and a 970m.
    [qgnox got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/drq3ewm/), with MSI GS60 2PC with GTX860M.
    ### Some success reports
    ASUS G751JM (i7-4710HQ, NVIDIA gtx 860m), thanks to @d0ku
    - [Perdouille got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dqo6jxf/), with MSI GS60-040XFR with an i7-4720HQ and a 970m.
    - [qgnox got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/drq3ewm/), with MSI GS60 2PC with GTX860M.
    - ASUS G751JM (i7-4710HQ, NVIDIA gtx 860m), thanks to @d0ku
    # Bumblebee setup guide
    @@ -476,7 +477,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - This will solve the SSID/SVID all zero problem inside the VM.
    - Don't forget to get a copy of [VirtIO Driver](https://launchpad.net/kvm-guest-drivers-windows/+download)
    - Don't forget to get a copy of [VirtIO Driver](https://www.linux-kvm.org/page/WindowsGuestDrivers/Download_Drivers)
    - ```shell
    #!/bin/bash
  2. @Misairu-G Misairu-G revised this gist Aug 20, 2018. 1 changed file with 51 additions and 40 deletions.
    91 changes: 51 additions & 40 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -71,15 +71,15 @@ Steam in-home streaming between Windows VM and host:

    As you might read after, this tutorial is pretty much the same as most passthrough guide. The keypoint, however, is to assign Subsystem ID for the dGPU using some vfio-pci options. My dGPU appears to have a Subsystem ID 00000000 inside the VM by default.

    About one display setup, frames are rendered in GPU memory as we all know, and display ports apparently is not the only way we can get those frames. Nvidia itself provides API to capture things happen in GPU memory, this is why we can have technology like Steam in-home streaming and Geforce experience. I have RemoteFX working and that is the only reason why I put that in this tutorial. Despite I use a quadro, this mobile version does not support NvFBC capture API (the same as other consumer card), so you should be able to get RemoteFX working with GPU even its Geforce.
    About one display setup, although frames are rendered in GPU memory, display ports is not the only way to get those frames. Nvidia itself provides API to capture things in GPU memory, this is why we can have technology like Steam in-home streaming and Geforce experience. For me, I have RemoteFX working, and that is the only reason why I put that in this tutorial. Despite I use a Quadro, this mobile version GPU does not support NvFBC capture API (the same as other consumer card), which means it's capability is no more than a GeForce, so you should be able to get RemoteFX working with Geforce.

    Some might be heard of [gnif's phenomenal work](https://forum.level1techs.com/t/a-little-teaser-of-what-is-to-come/121641), which made a huge step forward for one-display setup. Unfortunately, a dummy device is still required for that setup, which is a no go for laptop. Even if you are using MUXed laptop, having a dummy device plug-in still mean that you need to have DisplayPortDirectOutput mode enabled, which largely limit the capability of extending the host's display.
    Some might be heard of [gnif's phenomenal work](https://forum.level1techs.com/t/a-little-teaser-of-what-is-to-come/121641), which made a huge step forward for one-display setup. Unfortunately, a dummy device is still required for that setup, which is a no go for laptop. Even with a MUXed laptop, having a dummy device plug-in still means that your GPU needs to expose some form of display output signal physically, but most Laptop don't support this. As far as I know, Dell precision 7000 line-up can enable DisplayPortDirectOutput mode in BIOS, which would route GPU signal directly to video output port, while keeping iGPU rendering the built-in display.

    # Prerequisites

    This tutorial does not mean any laptop with a Optimus setup will be able to passthrough their dGPU. Generally, a good laptop is still required, and it is highly possible you will success if you have a laptop that use a swappable MXM form factor graphics card.
    Please noted that this tutorial does not support every Optimus laptop. Generally, a good laptop with some specific hardware capability is required. If you have a laptop that have a swappable MXM form factor graphics card, its highly possible that you'll success.

    Generally, due to the nature that laptop varies so much from manufacture to manufacture, there is no way you can tell if it is MUXed or MUXless or how a MUXless laptop load its firmware before you get your hands on it. So please do enough homework (find some success report in particular) before you plan to purchase a laptop for this purpose.
    Also, due to the nature that laptop varies so much from manufacture to manufacture, there is no way you can tell if it is MUXed, or MUXless, or how a MUXless laptop load its firmware before you get your hands on it. However, the firmware loading mechanism of your GPU is crucial for resolving the infamous Code 43 problem. So please do enough homework (find some success report in particular) before you plan to purchase a laptop for this purpose.

    ## Hardware

    @@ -89,7 +89,7 @@ Generally, due to the nature that laptop varies so much from manufacture to manu

    - A motherboard that support IOMMU with decent IOMMU layout e.g. your dGPU is in its own IOMMU group aside from other devices.

    - For the reason that there is no ACS support for laptop (maybe some bare-bone does) so far, a decent IOMMU layout is crucial since the ACS override patch is not applicable.
    - For the reason that there is no ACS support for laptop (maybe some bare-bone does), so far, a decent IOMMU layout is crucial since the ACS override patch is not applicable.

    - Verification:

    @@ -98,11 +98,11 @@ Generally, due to the nature that laptop varies so much from manufacture to manu
    - Example:

    - ```
    # output from lspci:
    # From "lspci":
    # 00:01.0 PCI bridge: Intel Corporation Sky Lake PCIe Controller (x16) (rev 05)
    # 01:00.0 VGA compatible controller: NVIDIA Corporation Device 1bb6 (rev a1)
    # output from dmesg
    # From "dmesg | grep iommu"
    [ 0.000000] DMAR: IOMMU enabled
    [ 0.086383] DMAR-IR: IOAPIC id 2 under DRHD base 0xfed91000 IOMMU 1
    [ 1.271222] iommu: Adding device 0000:00:00.0 to group 0
    @@ -132,17 +132,17 @@ Generally, due to the nature that laptop varies so much from manufacture to manu
    ## System & Software
    - Host:
    - I'm currently running Ubuntu 18.04 (with 4.15 kernel), but it should also work on other distribution.
    - I'm currently running Ubuntu 16.04 (with 4.15 kernel), but it should also work on other distribution.
    - System should be installed in UEFI mode, and boot via UEFI.
    - Guest:
    - A Windows that support RemoteFX (If you don't want an external display). The latest Windows 10 Pro for example.
    - Windows that support RemoteFX. Windows 10 Pro for example.
    - QEMU:
    - Currently running QEMU 2.11.1 with pulse audio and vcpupin patch
    - Currently running QEMU 2.11.2 with pulse audio and vcpupin patch
    - If you you use QEMU 2.10 or higher and encounter a boot hang (dots spinning forever), check your OVMF version, it might need an upgrade. Refer [here](https://bugs.launchpad.net/qemu/+bug/1715700) for further detail.
    - RDP Client:
    - Freerdp 2.0 or above for RDP 8 with RemoteFX connection.
    **Note**: Keep your dual-boot Windows if you want to use software like XTU.
    **Note**: Keep your dual-boot Windows if you still want to run software like XTU.
    ## Update: Attention for MUXless laptop
    @@ -152,26 +152,28 @@ Now for switchable graphics, there are three different solutions: MUXed(Old), MU
    ![Circuits diagram](https://i.imgur.com/GI7v8Gk.jpg)
    Most modern Optimus laptop use MUXless scheme, while some others, HP/Thinkpad/Dell mobile workstation, Clevo P650, some Alienware, etc. use MUXed scheme. At the dark age before Optimus solution came out, there is an old MUXed scheme which require reboot to switch graphics card and can only use one at a time, while the modern MUXed allow switch between Optimus and dGPU only, and can even have display output port hooked directly to the dGPU when using Optimus. The only thing unchanged is you need to get in BIOS to switch between these modes.
    Most modern Optimus laptop use MUXless scheme, while some others, HP/Thinkpad/Dell mobile workstation, Clevo P650, some Alienware, etc. use MUXed scheme. At the dark age before Optimus solution came out, there is an old MUXed scheme which require reboot to switch graphics card and can only use one at a time, while the modern MUXed allow switch between Optimus and dGPU only, and can even have display output port hooked directly to the dGPU when using Optimus (only applicable for some laptop).
    For people who encounter Code 43 with a MUXless scheme, that is to say, you can see your dGPU in guest, can even have nvidia driver installed without any problem, but still have this error code. This is because [ACPI call failed for firmware loading](https://www.reddit.com/r/VFIO/comments/6q7bf5/short_report_wip_got_the_nvidia_gpu_to/), in short:
    - Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM).
    - Please refer to [u/jscinoz](https://www.reddit.com/u/jscinoz) 's [optimus-vfio-docs](https://github.com/jscinoz/optimus-vfio-docs) if you encounter such problem.
    - Please refer to [u/jscinoz](https://www.reddit.com/u/jscinoz) 's [optimus-vfio-docs](https://github.com/jscinoz/optimus-vfio-docs) if you encounter such problem
    ### Some success report with MUXless laptop
    ### Some success report
    [Perdouille got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dqo6jxf/), with MSI GS60-040XFR with an i7-4720HQ and a 970m.
    [qgnox got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/drq3ewm/), with MSI GS60 2PC with GTX860M.
    ASUS G751JM (i7-4710HQ, NVIDIA gtx 860m), thanks to @d0ku
    # Bumblebee setup guide
    **Note**: For people who don't want to setup bumblebee, follow [this](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dpvwka6/) to get your GPU's ACPI address, and power it on/off by refering script [here](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dpvubpd/). (Credit to Verequies from reddit)
    **Note**: You might need to disable secure boot before following this guide.
    **Note**: You might need to disable secure boot before following continue on this part.
    We will first go through my bumblebee setup process. I did install bumblebee first and setup passthrough the second. But it should work the other way around.
    @@ -186,7 +188,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    3. (Trouble shooting) Solving the library linking problem in Nvidia driver.
    - If you are having error message with `sudo prime-select intel` or `sudo prime-select nvidia`, follow instructions below.
    - If error messages show up after executing `sudo prime-select intel` or `sudo prime-select nvidia`, follow instructions below.
    - ```bash
    # Replace 'xxx' to the velrsion of nvidia driver you installed
    @@ -197,9 +199,9 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    sudo ln -s /usr/lib32/nvidia-xxx/libEGL.so.375.66 /usr/lib32/nvidia-xxx/libEGL.so.1
    ```
    - If everything work correctly, `sudo prime-select nvidia` and then logout will give you a login loop. Execute `sudo prime-select intel` in other tty (Ctrl+Alt+F1) will solve the login loop problem.
    - If everything work correctly, `sudo prime-select nvidia` and then logout will give you a login loop. While `sudo prime-select intel` (do this in other tty with Ctrl+Alt+F2) will solve the login loop problem.
    - It is recommended to switch back and forth once if you run into some problem after a nvidia driver update.
    - It is recommended to switch back and forth for once, if you run into some problem after a nvidia driver update.
    4. Blocking nouveau
    @@ -212,13 +214,13 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - `sudo update-initramfs -u` when finish.
    - If you are using Ubuntu 18.04 (or some other case that your display manager is not running on X11), some extra work might be needed to prevent nouveau loading. Refer [here](https://askubuntu.com/questions/1031511/cant-disable-nouveau-drivers-in-ubuntu-18-04) for details.
    - If you have a DM running under wayland (such as Ubuntu 18.04, it runs GDM in wayland mode, despite GNOME is running under X11), some extra work might be needed to prevent nouveau from loading. Refer [here](https://askubuntu.com/questions/1031511/cant-disable-nouveau-drivers-in-ubuntu-18-04) for details.
    5. (Optional) Install CUDA, since the CUDA installation process is [well guided by Nvidia](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html), I will skip this part.
    - For CUDA, I personally recommend runfile installation. It is far more easy to maintain compare to other installation method. Just make sure neither the display driver (self-contain in the runfile) nor the OpenGL libraries is check during the runfile installation process. ONLY install the CUDA Toolkit and don't run `nvidia-xconfig`.
    - For CUDA, I personally recommend runfile installation. It is far more easy to maintain compare to other installation method. Just make sure neither the display driver (self-contain in the runfile) nor the OpenGL libraries is checked during the runfile installation process. ONLY install the CUDA Toolkit and don't run `nvidia-xconfig`.
    6. Solve some ACPI problem before bumblebee installation:
    6. Solve some ACPI problem before bumblebee install:
    - Add `nogpumanager acpi_osi=! acpi_osi=Linux acpi_osi=\"Windows 2015\" pcie_port_pm=off` for `GRUB_CMDLINE_LINUX_DEFAULT` in `/etc/default/grub`
    - `nogpumanager` is actually part of the CUDA installation guide.
    @@ -228,14 +230,15 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - https://github.com/Bumblebee-Project/Bumblebee/issues/764
    - https://github.com/Bumblebee-Project/Bumblebee/issues/810
    - `sudo update-grub` when finish.
    - (Trouble shooting) If your `prime-select` command updates grub, be sure to check your grub file again, as it does not handle escape character correctly, `\"` would become `\`
    - (Trouble shooting) If `prime-select` command updates grub, be sure to check your grub file again, as it does not handle escape character correctly, `\"` would become `\`
    7. Install bumblebee
    - ```shell
    # For Ubuntu 18.04, the official ppa should work
    sudo add-apt-repository ppa:bumblebee/testing
    sudo apt update
    sudo apt install bumblebee bumblebee-nvidia
    ```
    @@ -269,9 +272,9 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - `sudo update-initramfs -u` when finish.
    9. Create a group for bumblebee so that you won't need to `sudo` every time:
    9. (Optional) Create a group for bumblebee so that you don't need to `sudo` every time:
    - If `cat /etc/group | grep $(whoami)` already gives your user name in bumblebee group, skip this part.
    - If `cat /etc/group | grep $(whoami)` already gives your user name under bumblebee group, skip this part.
    - `groupadd bumblebee && gpasswd -a $(whoami) bumblebee`
    @@ -288,11 +291,18 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    11. Verification:
    - `cat /proc/acpi/bbswitch` should output something like `Ouput:0000:01:00.0 OFF`
    - `cat /proc/acpi/bbswitch` should gives you `Ouput:0000:01:00.0 OFF`
    - `optirun cat /proc/acpi/bbswitch` should gives you `Ouput:0000:01:00.0 ON`
    - `optirun cat /proc/acpi/bbswitch` should output something like `Ouput:0000:01:00.0 ON`
    - `nvidia-smi` should give you something like:
    - ```
    NVIDIA-SMI couldn't find libnvidia-ml.so library in your system. Please make sure that the NVIDIA Display Driver is properly installed and present in your system.
    Please also try adding directory that contains libnvidia-ml.so to your system PATH.
    ```
    - `optirun nvidia-smi` should give your something like:
    - `optirun nvidia-smi` should gives you something like:
    - ```
    Wed Nov 15 00:36:53 2017
    @@ -314,7 +324,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    +-----------------------------------------------------------------------------+
    ```
    12. Congratulations, stay and enjoy this moment a little bit before run into the next part.
    12. Congratulations, stay and enjoy this moment a little bit before running into the next part.
    # dGPU passthrough guide
    @@ -324,7 +334,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - QEMU from Ubuntu official PPA should work, just `sudo apt install qemu-kvm qemu-utils qemu-efi ovmf`.
    - Please note that QEMU 2.10 or above require a higher version of OVMF (say if you use UEFI for your VM), otherwise will have boot hang. Refer [here](https://bugs.launchpad.net/qemu/+bug/1715700) for details about which version. Simplest solution is to use [ovmf package from 18.04 ppa](https://launchpad.net/ubuntu/bionic/+package/ovmf) directly.
    - Please note that QEMU 2.10 or above require a higher version of OVMF (say if you use UEFI for your VM), otherwise will cause boot hang. Refer [here](https://bugs.launchpad.net/qemu/+bug/1715700) for details about which version. Simplest solution is to use [ovmf package from 18.04 ppa](https://launchpad.net/ubuntu/bionic/+package/ovmf) directly.
    - Here I use QEMU 2.11.2 with pulse audio patch from [spheenik](https://www.reddit.com/user/spheenik) to provide better audio quality and resolve the crackling issue, and vcpupin patch from [saveriomiroddi](https://github.com/saveriomiroddi) for better performance.
    @@ -348,6 +358,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    # Apply pulseaudio from spheenik's git, we're applying the v1 version.
    wget -O - https://gist.github.com/spheenik/8140a4405f819c5cd2465a65c8bb6d09/raw/9735bcfaaaef45cf47e1b5d92c5006adf6ecd737/v1.patch | patch -p0
    # (Optional)
    # You might need to set your git email or name before commiting changes
    git commit -am "Apply pulse audio patch"
    @@ -420,7 +431,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    1. Get your Subsystem ID (SSID) and Subsystem Vendor ID (SVID):
    - Run `optirun lspci -nnk -s 01:00.0`, you will get an output like this:
    - Run `optirun lspci -nnk -s 01:00.0`, which will gives you an output like this:
    - ```
    01:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [10de:1bb6] (rev a1)
    @@ -438,24 +449,24 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    3. Setup VM:
    - **Note**: Command here just serve as a reference, check QEMU documentation for more detail.
    - **Note**: Command here only serve as a reference, checkout QEMU documentation for more detail.
    - **Note**: I personally don't prefer libvirt as editing xml is annoying for me. Use libvirt if you like it, and use `virsh domxml-from-native qemu-argv xxx.sh` to convert a QEMU launching script to libvirt XML if needed. Refer [here](https://libvirt.org/drvqemu.html#imex) for more information.
    - **Note**: I personally don't prefer libvirt as editing xml is annoying for me. Use libvirt if you like. `virsh domxml-from-native qemu-argv xxx.sh` can help you converting a QEMU startup script to libvirt XML. Refer [here](https://libvirt.org/drvqemu.html#imex) for more information.
    - **Note**: If you would like to put you GPU at some other address, refer [here](https://www.redhat.com/archives/libvir-list/2013-February/msg00440.html) for details about ICH9 and GMCH (Graphics & Memory Controller Hub) defines
    - **Note**: If you would like to put you GPU at some other address, refer [here](https://www.redhat.com/archives/libvir-list/2013-February/msg00440.html) for details about ICH9 and GMCH (Graphics & Memory Controller Hub) defines. Layout of PCIe devices of your guest machines should follow these guidelines, as to prevent potential problem.
    - **Note**: The `romfile` option in the script below is not required if there is a stand alone GPU ROM chip bundled with your GPU (must have for MXM, not sure for soldered). However, if you decide to use the `romfile` option, please extract it yourself instead of download a copy from the Internet.
    - **Note**: The `romfile` option in the script below is not required if there is a stand alone GPU ROM chip bundled with your GPU (the case for MXM, not sure for soldered). However, if you decide to use the `romfile` option, please extract it yourself instead of download a copy from the Internet.
    - Create a disk for your VM:
    - Create a disk image for your VM:
    - `qemu-img create -f raw WindowsVM.img 75G`
    - Install `iptables` and `tunctl` if you don't have it.
    - Create two script for tap networking:
    - `tap_ifup` (check file below in this gist)
    - `tap_ifdown` (check file below in this gist)
    - `tap_ifup` (check files below in this gist)
    - `tap_ifdown` (check files below in this gist)
    - Use `dpkg -L ovmf` to locate your `OVMF_VARS.fd` file, copy that to the directory where you store your VM image, then rename it to `WIN_VARS.fd`(or other names you like).
    @@ -532,15 +543,15 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    2. Run the script to launch your VM
    - Install your Windows system through host side VNC (`remote-viewer spice://127.0.0.1:5930`).
    - `-device qxl,bus=pcie.0,addr=1c.4,id=video.2` need to be comment out, change `-vga none` to `-vga qxl` so that QXL would become the first GPU and can see POST screen from spice client.
    - Change back once you have everything .
    - **IMPORTANT**: Driver could be a cause for Code 43, please try both the driver you manufacture provided, and the driver from Nvidia website.
    - Change back once you have everything working.
    - **IMPORTANT**: Driver could be a cause for Code 43, please try both the driver your manufacture provided, and the driver from Nvidia website.
    - Add `192.168.99.0/24` to your Windows VM firewall exception:
    - In `Control Panel\System and Security\Windows Defender Firewall`, click `Advance settings` in the right panel, and `Inbound Rules` -> `New rules`.
    - Make sure you can `ping` to your VM from host.
    - Some details about setting up VirtIO driver not included here.
    - Enable remote desktop in Windows VM:
    - Right click `This PC`, click `Remote settings` in the right panel.
    - Verify that your GPU have correct the hardware ID. `Device manager` -> double click your dGPU -> `Detail`tab -> `Hardware Ids`
    - Verify that your GPU (in guest) have the correct hardware ID. `Device manager` -> double click your dGPU -> `Detail`tab -> `Hardware Ids`
    - For me, its `PCI\VEN_10DE&DEV_1BB6&SUBSYS_07B11028`. I'll get `PCI\VEN_10DE&DEV_1BB6&SUBSYS_00000000` if I did't have it masqueraded.
    - In some cases, you will find your dGPU as a `Video controller(VGA compatible)` under `Unknown Device` before your install nvidia driver.
    - Install the official nvidia driver.
  3. @Misairu-G Misairu-G revised this gist Jul 14, 2018. 1 changed file with 28 additions and 21 deletions.
    49 changes: 28 additions & 21 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -32,9 +32,11 @@ This is a guide for passing through you dGPU on your laptop for your VM. This gu

    Sorry but currently I don't know how to check if your dGPU load its firmware through acpi call.

    **Update**: Use hexadecimal id directly instead of convert it to decimal, add some note for romfile option

    **Update**: Forget that `-vga none` would cause `Guest has not initialized the display (yet)` problem if you don't have a system installed

    **Update**: Use qemu 2.11.1 with pulse audio patch and vcpupin, add some caveats for 18.04
    **Update**: Use qemu 2.11.2 with pulse audio patch and vcpupin, add some caveats for 18.04

    # What to expect?

    @@ -275,14 +277,14 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    10. (Trouble shooting) Try `optirun nvidia-smi`, if encounter `[ERROR][XORG] (EE) Failed to load module "mouse" (module does not exist, 0)`, add lines below to `/etc/bumblebee/xorg.conf.nvidia`
    - ```
    Section "Screen"
    Identifier "Default Screen"
    Device "DiscreteNvidia"
    EndSection
    ```
    - ```
    Section "Screen"
    Identifier "Default Screen"
    Device "DiscreteNvidia"
    EndSection
    ```
    - Check [here](https://github.com/Bumblebee-Project/Bumblebee/issues/867) for more information about this problem.
    - Check [here](https://github.com/Bumblebee-Project/Bumblebee/issues/867) for more information about this problem.
    11. Verification:
    @@ -342,20 +344,20 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    git clone https://github.com/saveriomiroddi/qemu-pinning.git qemu
    cd qemu
    git checkout v2.11.2-pinning
    # Apply pulseaudio from spheenik's git, we're applying the v1 version.
    wget -O - https://gist.github.com/spheenik/8140a4405f819c5cd2465a65c8bb6d09/raw/9735bcfaaaef45cf47e1b5d92c5006adf6ecd737/v1.patch | patch -p0
    # You might need to set your git email or name before commiting changes
    git commit -am "Apply pulse audio patch"
    # Install dependencies
    sudo apt install libjpeg-turbo8-dev libepoxy-dev libdrm-dev libgbm-dev libegl1-mesa-dev libboost-thread1.58-dev libboost-random1.58-dev libiscsi-dev libnfs-dev libfdt-dev libpixman-1-dev libssl-dev socat libsdl1.2-dev libspice-server-dev autoconf libtool xtightvncviewer tightvncserver x11vnc libsdl1.2-dev uuid-runtime uuid uml-utilities bridge-utils python-dev liblzma-dev libc6-dev libusb-1.0-0-dev checkinstall virt-viewer cpu-checker nettle-dev libaio-dev
    # Prepare to build
    mkdir build
    cd build
    # QEMU does not support python3
    ../configure --prefix=/usr \
    --audio-drv-list=alsa,pa,oss \
    @@ -370,9 +372,9 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    --enable-spice \
    --target-list=x86_64-softmmu \
    --python=/usr/bin/python2
    make -j8
    # QEMU does not provide 'make uninstall'
    # Use checkinstall here so that you can remove it by 'dpkg -r'
    # Assign a version number start with numeric number is mandatory when using checkinstall
    @@ -433,7 +435,6 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - Please refer to [Archwiki/PCI passthrough/Passing VM audio to host via PulseAudio](https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF#Passing_VM_audio_to_host_via_PulseAudio) and [Archwiki/pulseaudio/Allowing multiple users to use PulseAudio at the same time](https://wiki.archlinux.org/index.php/PulseAudio/Examples#Allowing_multiple_users_to_use_PulseAudio_at_the_same_time)
    3. Setup VM:
    @@ -443,6 +444,8 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - **Note**: If you would like to put you GPU at some other address, refer [here](https://www.redhat.com/archives/libvir-list/2013-February/msg00440.html) for details about ICH9 and GMCH (Graphics & Memory Controller Hub) defines
    - **Note**: The `romfile` option in the script below is not required if there is a stand alone GPU ROM chip bundled with your GPU (must have for MXM, not sure for soldered). However, if you decide to use the `romfile` option, please extract it yourself instead of download a copy from the Internet.
    - Create a disk for your VM:
    - `qemu-img create -f raw WindowsVM.img 75G`
    @@ -458,23 +461,23 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - Create a script for starting your VM:
    - Recall that our GPU have a SVID `1028`, and a SSID `07b1`. Convert these two hexadecimal value to decimal. Which is `4136` for SVID, and `1969` for SSID. Use these two value to set the corresponding vfio-pci options (see script below).
    - Recall that our GPU have a SVID `1028`, and a SSID `07b1`, use these two value to set the corresponding vfio-pci options (see script below).
    - This will solve the SSID/SVID all zero problem inside the VM.
    - Don't forget to get a copy of [VirtIO Driver](https://launchpad.net/kvm-guest-drivers-windows/+download)
    - ```shell
    #!/bin/bash
    # Set audio output options
    export QEMU_AUDIO_DRV=pa
    export QEMU_PA_SERVER="<your-pulse-socket>"
    export QEMU_AUDIO_TIMER_PERIOD=500
    # Use command below to generate a MAC address
    # printf '52:54:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))
    # Refer https://github.com/saveriomiroddi/qemu-pinning for how to set your cpu affinity properly
    qemu-system-x86_64 \
    -name "Windows10-QEMU" \
    @@ -502,7 +505,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    -spice port=5901,addr=127.0.0.1,disable-ticketing \
    -usb \
    -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
    -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=1969,x-pci-sub-vendor-id=4136,multifunction=on,romfile=MyGPU.rom \
    -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=0x07b1,x-pci-sub-vendor-id=0x1028,multifunction=on,romfile=MyGPU.rom \
    -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd \
    -drive if=pflash,format=raw,file=WIN_VARS.fd \
    -boot menu=on \
    @@ -514,6 +517,10 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    -device virtio-net-pci,netdev=net0,addr=19.0,mac=<address your generate>
    -device pci-bridge,addr=12.0,chassis_nr=2,id=head.2 \
    -device usb-tablet
    # The -device usb-tablet will not be accurate regarding the pointer in some cases, another option is to use
    # -device virtio-keyboard-pci,bus=head.2,addr=03.0,display=video.2 \
    # -device virtio-mouse-pci,bus=head.2,addr=04.0,display=video.2 \
    ```
    - For libvirt, refer [here](https://gist.github.com/anonymous/500f1edf89d6f22c40bd2cbbdec6490b) for an example of how to masquerade your Subsystem ID. (Credit to jscinoz)
  4. @Misairu-G Misairu-G revised this gist Jul 2, 2018. 1 changed file with 5 additions and 9 deletions.
    14 changes: 5 additions & 9 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -324,7 +324,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - Please note that QEMU 2.10 or above require a higher version of OVMF (say if you use UEFI for your VM), otherwise will have boot hang. Refer [here](https://bugs.launchpad.net/qemu/+bug/1715700) for details about which version. Simplest solution is to use [ovmf package from 18.04 ppa](https://launchpad.net/ubuntu/bionic/+package/ovmf) directly.
    - Here I use QEMU 2.11.1 with pulse audio patch from [spheenik](https://www.reddit.com/user/spheenik) to provide better audio quality and resolve the crackling issue, and vcpupin patch from [saveriomiroddi](https://github.com/saveriomiroddi) for better performance.
    - Here I use QEMU 2.11.2 with pulse audio patch from [spheenik](https://www.reddit.com/user/spheenik) to provide better audio quality and resolve the crackling issue, and vcpupin patch from [saveriomiroddi](https://github.com/saveriomiroddi) for better performance.
    - Details about pulse audio patch:
    - [Improved Pulse Audio Driver for QEMU - Testers/coders needed! (archived)](https://www.reddit.com/r/VFIO/comments/74vokw/improved_pulse_audio_driver_for_qemu/)
    @@ -341,17 +341,14 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    # Clone saveriomiroddi's vcpupin version of QEMU
    git clone https://github.com/saveriomiroddi/qemu-pinning.git qemu
    cd qemu
    git checkout v2.11.1-pinning
    git checkout v2.11.2-pinning
    # Apply pulseaudio from spheenik's git, we're applying the v1 version.
    wget -O - https://gist.github.com/spheenik/8140a4405f819c5cd2465a65c8bb6d09/raw/9735bcfaaaef45cf47e1b5d92c5006adf6ecd737/v1.patch | patch -p0
    # You might need to set your git email or name before commiting changes
    git commit -am "Apply pulse audio patch"
    # Fix some configure problem due to recent change in glibc
    git cherry-pick -x 75e5b70e6b5dcc4f2219992d7cffa462aa406af0
    # Install dependencies
    sudo apt install libjpeg-turbo8-dev libepoxy-dev libdrm-dev libgbm-dev libegl1-mesa-dev libboost-thread1.58-dev libboost-random1.58-dev libiscsi-dev libnfs-dev libfdt-dev libpixman-1-dev libssl-dev socat libsdl1.2-dev libspice-server-dev autoconf libtool xtightvncviewer tightvncserver x11vnc libsdl1.2-dev uuid-runtime uuid uml-utilities bridge-utils python-dev liblzma-dev libc6-dev libusb-1.0-0-dev checkinstall virt-viewer cpu-checker nettle-dev libaio-dev
    @@ -516,8 +513,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    -netdev type=tap,id=net0,ifname=tap0,script=tap_ifup,downscript=tap_ifdown,vhost=on \
    -device virtio-net-pci,netdev=net0,addr=19.0,mac=<address your generate>
    -device pci-bridge,addr=12.0,chassis_nr=2,id=head.2 \
    -device virtio-keyboard-pci,bus=head.2,addr=03.0,display=video.2 \
    -device virtio-mouse-pci,bus=head.2,addr=04.0,display=video.2 \
    -device usb-tablet
    ```
    - For libvirt, refer [here](https://gist.github.com/anonymous/500f1edf89d6f22c40bd2cbbdec6490b) for an example of how to masquerade your Subsystem ID. (Credit to jscinoz)
    @@ -528,8 +524,8 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - `echo "10de 1bb6" > "/sys/bus/pci/drivers/vfio-pci/new_id"`
    2. Run the script to launch your VM
    - Install your Windows system through host side VNC (`remote-viewer spice://127.0.0.1:5930`).
    - `-device qxl,bus=pcie.0,addr=1c.4,id=video.2` need to comment out, change `-vga none` to `-vga qxl` so that QXL would become the first GPU and can see POST screen from spice client.
    - Change back once you have everything working.
    - `-device qxl,bus=pcie.0,addr=1c.4,id=video.2` need to be comment out, change `-vga none` to `-vga qxl` so that QXL would become the first GPU and can see POST screen from spice client.
    - Change back once you have everything .
    - **IMPORTANT**: Driver could be a cause for Code 43, please try both the driver you manufacture provided, and the driver from Nvidia website.
    - Add `192.168.99.0/24` to your Windows VM firewall exception:
    - In `Control Panel\System and Security\Windows Defender Firewall`, click `Advance settings` in the right panel, and `Inbound Rules` -> `New rules`.
  5. @Misairu-G Misairu-G revised this gist Jun 28, 2018. 1 changed file with 11 additions and 9 deletions.
    20 changes: 11 additions & 9 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@

    This is a guide for passing through you dGPU on your laptop for your VM. This guide only apply to laptops that does not load dGPU firmware through acpi call, which include all MUXed laptop and some MUXless laptop. For laptops that use acpi call to load dGPU firmware, please refer to to [u/jscinoz](https://www.reddit.com/u/jscinoz) 's [optimus-vfio-docs](https://github.com/jscinoz/optimus-vfio-docs).

    Also, currently I don't know how to check if your dGPU load its firmware through acpi call.
    Sorry but currently I don't know how to check if your dGPU load its firmware through acpi call.

    **Update**: Forget that `-vga none` would cause `Guest has not initialized the display (yet)` problem if you don't have a system installed

    @@ -173,9 +173,11 @@ For people who encounter Code 43 with a MUXless scheme, that is to say, you can
    We will first go through my bumblebee setup process. I did install bumblebee first and setup passthrough the second. But it should work the other way around.
    1. Solving the known interference between TLP and Bumblebee
    1. (Optional) Solving the known interference between TLP and Bumblebee
    - TLP is a must have for a Linux laptop since it provide extra policy to save your battery. Install TLP by `sudo apt install tlp` if you haven't install it.
    - If you don't want to use tlp, please skip this part.
    - TLP is a must have for a Linux laptop since it provides extra policies to save your battery. Install TLP by `sudo apt install tlp`
    - Add the output of `lspci | grep "NVIDIA" | cut -b -8` to `RUNTIME_PM_BLACKLIST` in `/etc/default/tlp`, uncomment it if necessary. This will solve the interference.
    2. Install Nvidia proprietary driver through Ubuntu system settings (Or other install method you prefer).
    @@ -212,7 +214,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    5. (Optional) Install CUDA, since the CUDA installation process is [well guided by Nvidia](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html), I will skip this part.
    - With all that said, I personally recommend runfile installation. It is far more easy to maintain compare to other install method. Just make sure neither the display driver (self-contain in the runfile) nor the OpenGL libraries is check during the runfile installation process. ONLY install the CUDA Toolkit and don't run `nvidia-xconfig`.
    - For CUDA, I personally recommend runfile installation. It is far more easy to maintain compare to other installation method. Just make sure neither the display driver (self-contain in the runfile) nor the OpenGL libraries is check during the runfile installation process. ONLY install the CUDA Toolkit and don't run `nvidia-xconfig`.
    6. Solve some ACPI problem before bumblebee installation:
    @@ -224,12 +226,12 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - https://github.com/Bumblebee-Project/Bumblebee/issues/764
    - https://github.com/Bumblebee-Project/Bumblebee/issues/810
    - `sudo update-grub` when finish.
    - (Trouble shooting) If your `prime-select` updates grub, be sure to check your grub file again, as it does not handle escape character correctly, `\"` would become `\`
    - (Trouble shooting) If your `prime-select` command updates grub, be sure to check your grub file again, as it does not handle escape character correctly, `\"` would become `\`
    7. Install bumblebee
    - ```shell
    # If you use Ubuntu 18.04, the official ppa should work
    # For Ubuntu 18.04, the official ppa should work
    sudo add-apt-repository ppa:bumblebee/testing
    sudo apt update
    sudo apt install bumblebee bumblebee-nvidia
    @@ -263,11 +265,11 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    bbswitch
    ```
    - `sudo update-initramfs -u` when finish.
    - `sudo update-initramfs -u` when finish.
    9. Create a group for bumblebee so that you won't need to `sudo` every time:
    - If `cat /etc/group | grep $(whoami)` already gives your user name, pass this part.
    - If `cat /etc/group | grep $(whoami)` already gives your user name in bumblebee group, skip this part.
    - `groupadd bumblebee && gpasswd -a $(whoami) bumblebee`
    @@ -320,7 +322,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - QEMU from Ubuntu official PPA should work, just `sudo apt install qemu-kvm qemu-utils qemu-efi ovmf`.
    - Please note that QEMU 2.10 or above should use a higher version of OVMF (say if you use UEFI for your VM), otherwise will have boot hang. Refer [here](https://bugs.launchpad.net/qemu/+bug/1715700) for details about which version. Simplest solution is to use [ovmf package from 18.04 ppa](https://launchpad.net/ubuntu/bionic/+package/ovmf) directly.
    - Please note that QEMU 2.10 or above require a higher version of OVMF (say if you use UEFI for your VM), otherwise will have boot hang. Refer [here](https://bugs.launchpad.net/qemu/+bug/1715700) for details about which version. Simplest solution is to use [ovmf package from 18.04 ppa](https://launchpad.net/ubuntu/bionic/+package/ovmf) directly.
    - Here I use QEMU 2.11.1 with pulse audio patch from [spheenik](https://www.reddit.com/user/spheenik) to provide better audio quality and resolve the crackling issue, and vcpupin patch from [saveriomiroddi](https://github.com/saveriomiroddi) for better performance.
  6. @Misairu-G Misairu-G revised this gist Jun 25, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -528,6 +528,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - Install your Windows system through host side VNC (`remote-viewer spice://127.0.0.1:5930`).
    - `-device qxl,bus=pcie.0,addr=1c.4,id=video.2` need to comment out, change `-vga none` to `-vga qxl` so that QXL would become the first GPU and can see POST screen from spice client.
    - Change back once you have everything working.
    - **IMPORTANT**: Driver could be a cause for Code 43, please try both the driver you manufacture provided, and the driver from Nvidia website.
    - Add `192.168.99.0/24` to your Windows VM firewall exception:
    - In `Control Panel\System and Security\Windows Defender Firewall`, click `Advance settings` in the right panel, and `Inbound Rules` -> `New rules`.
    - Make sure you can `ping` to your VM from host.
  7. @Misairu-G Misairu-G revised this gist Jun 20, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -500,7 +500,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    -serial none \
    -parallel none \
    -k en-us \
    -spice port=5930,addr=127.0.0.1,disable-ticketing \
    -spice port=5901,addr=127.0.0.1,disable-ticketing \
    -usb \
    -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
    -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=1969,x-pci-sub-vendor-id=4136,multifunction=on,romfile=MyGPU.rom \
    @@ -525,7 +525,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    1. Binding your dGPU to vfio-pci driver:
    - `echo "10de 1bb6" > "/sys/bus/pci/drivers/vfio-pci/new_id"`
    2. Run the script to launch your VM
    - Install your Windows system through host side VNC (`127.0.0.1:5901`).
    - Install your Windows system through host side VNC (`remote-viewer spice://127.0.0.1:5930`).
    - `-device qxl,bus=pcie.0,addr=1c.4,id=video.2` need to comment out, change `-vga none` to `-vga qxl` so that QXL would become the first GPU and can see POST screen from spice client.
    - Change back once you have everything working.
    - Add `192.168.99.0/24` to your Windows VM firewall exception:
  8. @Misairu-G Misairu-G revised this gist Jun 20, 2018. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -17,21 +17,22 @@
    - [RemoteFX configure and fine tuning](#remotefx-configure-and-fine-tuning)
    - [Steam in-home Streaming](#steam-in-home-streaming)
    - [External display setup](#external-display-setup)
    - [Looking glass](#looking-glass)
    - [FAQ](#faq)
    - [How did you extract you vBIOS?](#how-did-you-extract-you-vbios)
    - [Did you success with AMD CPU?](#did-you-success-with-amd-cpu)
    - [What about AMD dGPU?](#what-about-amd-dgpu)
    - [Regarding AMD CPU/GPU?](#regarding-amd-cpugpu)
    - [What about GVT-g? Can I replicate a Optimus system inside a VM?](#what-about-gvt-g-can-i-replicate-a-optimus-system-inside-a-vm)
    - [What about those bare-bone laptop?](#what-about-those-bare-bone-laptop)
    - [Options other than RemoteFX?](#options-other-than-remotefx)
    - [Known issue](#known-issue)
    - [Reference](#reference)

    This is a guide for passing through you dGPU on your laptop for your VM. This guide only apply to laptops that does not load dGPU firmware through acpi call, which include all MUXed laptop and some MUXless laptop. For laptops that use acpi call to load the dGPU firmware, please refer to to [u/jscinoz](https://www.reddit.com/u/jscinoz) 's [optimus-vfio-docs](https://github.com/jscinoz/optimus-vfio-docs).
    This is a guide for passing through you dGPU on your laptop for your VM. This guide only apply to laptops that does not load dGPU firmware through acpi call, which include all MUXed laptop and some MUXless laptop. For laptops that use acpi call to load dGPU firmware, please refer to to [u/jscinoz](https://www.reddit.com/u/jscinoz) 's [optimus-vfio-docs](https://github.com/jscinoz/optimus-vfio-docs).

    Also, currently I don't know how to detect if your dGPU load its firmware through acpi call.
    Also, currently I don't know how to check if your dGPU load its firmware through acpi call.

    **Update**: Forget that `-vga none` would cause `Guest has not initialized the display (yet)` problem if you don't have a system running
    **Update**: Forget that `-vga none` would cause `Guest has not initialized the display (yet)` problem if you don't have a system installed

    **Update**: Use qemu 2.11.1 with pulse audio patch and vcpupin, add some caveats for 18.04

    @@ -462,6 +463,8 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - This will solve the SSID/SVID all zero problem inside the VM.
    - Don't forget to get a copy of [VirtIO Driver](https://launchpad.net/kvm-guest-drivers-windows/+download)
    - ```shell
    #!/bin/bash
    @@ -528,6 +531,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - Add `192.168.99.0/24` to your Windows VM firewall exception:
    - In `Control Panel\System and Security\Windows Defender Firewall`, click `Advance settings` in the right panel, and `Inbound Rules` -> `New rules`.
    - Make sure you can `ping` to your VM from host.
    - Some details about setting up VirtIO driver not included here.
    - Enable remote desktop in Windows VM:
    - Right click `This PC`, click `Remote settings` in the right panel.
    - Verify that your GPU have correct the hardware ID. `Device manager` -> double click your dGPU -> `Detail`tab -> `Hardware Ids`
  9. @Misairu-G Misairu-G revised this gist Jun 20, 2018. 1 changed file with 143 additions and 84 deletions.
    227 changes: 143 additions & 84 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    [Reddit post](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/)
    [Reddit post (Archived)](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/)

    #### Table of Content

    @@ -27,7 +27,13 @@
    - [Known issue](#known-issue)
    - [Reference](#reference)

    Just like most of you, and partially because of the lack of success report, I once thought that this is a mission impossible for a laptop. But here we are, with the lack of words to express my excitement, I am now sharing my success and this tutorial to help you achieve the goal you might have been striving for so long.
    This is a guide for passing through you dGPU on your laptop for your VM. This guide only apply to laptops that does not load dGPU firmware through acpi call, which include all MUXed laptop and some MUXless laptop. For laptops that use acpi call to load the dGPU firmware, please refer to to [u/jscinoz](https://www.reddit.com/u/jscinoz) 's [optimus-vfio-docs](https://github.com/jscinoz/optimus-vfio-docs).

    Also, currently I don't know how to detect if your dGPU load its firmware through acpi call.

    **Update**: Forget that `-vga none` would cause `Guest has not initialized the display (yet)` problem if you don't have a system running

    **Update**: Use qemu 2.11.1 with pulse audio patch and vcpupin, add some caveats for 18.04

    # What to expect?

    @@ -68,7 +74,9 @@ Some might be heard of [gnif's phenomenal work](https://forum.level1techs.com/t/

    # Prerequisites

    With all that said, this tutorial does not mean any laptop with a Optimus setup will be able to passthrough their dGPU. Generally, a pretty high end laptop is still required, and it is highly possible you will success if you have a laptop that use a swappable MXM form factor graphics card.
    This tutorial does not mean any laptop with a Optimus setup will be able to passthrough their dGPU. Generally, a good laptop is still required, and it is highly possible you will success if you have a laptop that use a swappable MXM form factor graphics card.

    Generally, due to the nature that laptop varies so much from manufacture to manufacture, there is no way you can tell if it is MUXed or MUXless or how a MUXless laptop load its firmware before you get your hands on it. So please do enough homework (find some success report in particular) before you plan to purchase a laptop for this purpose.

    ## Hardware

    @@ -121,66 +129,59 @@ With all that said, this tutorial does not mean any laptop with a Optimus setup
    ## System & Software
    - Host:
    - I'm currently running Ubuntu 16.04 (with 4.10 kernel), but it should also work on other distribution.
    - I'm currently running Ubuntu 18.04 (with 4.15 kernel), but it should also work on other distribution.
    - System should be installed in UEFI mode, and boot via UEFI.
    - Guest:
    - A Windows that support RemoteFX (If you don't want an external display). The latest Windows 10 Pro for example.
    - QEMU:
    - Currently running a Intel GVT-g version QEMU (2.9.0, for testing iGPU virtualization), other main stream QEMU should also work.
    - Currently running QEMU 2.11.1 with pulse audio and vcpupin patch
    - If you you use QEMU 2.10 or higher and encounter a boot hang (dots spinning forever), check your OVMF version, it might need an upgrade. Refer [here](https://bugs.launchpad.net/qemu/+bug/1715700) for further detail.
    - RDP Client:
    - Freerdp 2.0 or above for RDP 8 with RemoteFX connection.
    **Note**: Keep your dual-boot Windows if you want to use software like XTU.
    ## Update: Attention for MUXless laptop
    ~~Not sure anyone succeseded with a MUXless laptop yet (Or failed with a MUXed laptop)~~. If you do, please leave a comment with your setup (laptop model, what ROM for your GPU and what SSID/SVID are you using). Consider this as a request.
    ~~Not sure anyone succeseded with a MUXless laptop yet (Or failed with a MUXed laptop)~~. If you do success, please consider leave a comment with your setup (laptop model, year of production/purchase, etc.), so that other people can have some reference.
    Now for switchable graphics, there are three different solutions: MUXed(Old), MUXless and MUXed(New)
    ![Circuits diagram](https://i.imgur.com/GI7v8Gk.jpg)
    Most modern Optimus laptop use MUXless scheme, while some others, HP/Thinkpad/Dell mobile workstation, Clevo P650, some Alienware, etc. use MUXed scheme. At the dark age before Optimus solution came out, there is an old MUXed scheme which require reboot to switch graphics card and can only use one at a time, while the modern MUXed allow switch between Optimus and dGPU only, and can even have display output port hooked directly to the dGPU when using Optimus. The only thing unchanged is you need to get in BIOS to switch between these modes.
    For people who encounter Code 43 with a MUXless scheme, that is to say, you can see your dGPU in guest, can even have nvidia driver installed without any problem, but still have this error code. Here are some **speculations** (read the [dGPU passthrough guide](#dgpu-passthrough-guide) first if you cannot understand things below):
    For people who encounter Code 43 with a MUXless scheme, that is to say, you can see your dGPU in guest, can even have nvidia driver installed without any problem, but still have this error code. This is because [ACPI call failed for firmware loading](https://www.reddit.com/r/VFIO/comments/6q7bf5/short_report_wip_got_the_nvidia_gpu_to/), in short:
    - Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM).
    1. Your ROM don't support UEFI.
    2. Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM). Maybe some patch for OVMF will make it work.
    - If [ACPI call failed for firmware loading](https://www.reddit.com/r/VFIO/comments/6q7bf5/short_report_wip_got_the_nvidia_gpu_to/) is the only problem, then MUXless laptop with a MXM GPU should be fine. Please at least give that a try.
    3. ROM for MUXless dGPU don't support running independently. Maybe a ROM from dGPU who support MUXed will fix this.
    - As all MXM GPU can be install in a MUXed laptop, ROM from MXM GPU should work.
    4. Nvidia driver don't allow MUXless dGPU running independently by checking SSID/SVID. Maybe a proper masqueraded SSID/SVID can fool the Nvidia driver and make it work. (SSID/SVID can be found inside Nvidia driver, by extracting it with WinRAR or some other tools. Follow [this guide](http://null-bin.blogspot.com/2015/08/how-to-modify-nvidia-notebook-driver.html))
    5. You need both a MUXed dGPU ROM and its corresponding SSID/SVID.
    6. ~~MUXless non-MXM dGPU don't support running independently due to hardware limitation. No fix.~~ Should not be a problem. Clevo P650RG is a MUXed laptop with soldered dGPU. This laptop also support G-Sync (with appropriate display panel and GPU of casue) when using Discrete mode, and its MSHybrid mode stands for Optimus).
    ### Some success report
    - Please refer to [u/jscinoz](https://www.reddit.com/u/jscinoz) 's [optimus-vfio-docs](https://github.com/jscinoz/optimus-vfio-docs) if you encounter such problem.
    [Perdouille got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dqo6jxf/). He/She use MSI GS60-040XFR with an i7-4720HQ and a 970m.
    ### Some success report with MUXless laptop
    [qgnox got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/drq3ewm/). He/She use MSI GS60 2PC with GTX860M.
    [Perdouille got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dqo6jxf/), with MSI GS60-040XFR with an i7-4720HQ and a 970m.
    [qgnox got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/drq3ewm/), with MSI GS60 2PC with GTX860M.
    # Bumblebee setup guide
    **Note**: For people who don't want to setup bumblebee, follow [this](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dpvwka6/) to get your GPU's ACPI address, and power it on/off by refering script [here](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dpvubpd/). (Credit to Verequies from reddit)
    **Note**: You might need to disable secure boot before following this guide.
    **Note**: This bumblebee setup is based on [this guide](https://gist.github.com/whizzzkid/37c0d365f1c7aa555885d102ec61c048). Thank you whizzzkid.
    We will first go through my bumblebee setup process. I did install bumblebee first and setup passthrough the second. But it should work the other way around.
    1. Install Intel Graphics Patch Firmwares
    - Refer to https://01.org/linuxgraphics/downloads/firmware, select your platform and download corresponding GuC, DMC and HuC firmware. Installation instructions are self-contained within those tar file.
    2. Solving the known interference between TLP and Bumblebee
    1. Solving the known interference between TLP and Bumblebee
    - TLP is a must have for a Linux laptop since it provide extra policy to save your battery. Install TLP by `sudo apt install tlp` if you haven't install it.
    - Add the output of `lspci | grep "NVIDIA" | cut -b -8` to `RUNTIME_PM_BLACKLIST` in `/etc/default/tlp`, uncomment it if necessary. This will solve the interference.
    3. Install Nvidia proprietary driver through Ubuntu system settings (Or other install method you prefer).
    2. Install Nvidia proprietary driver through Ubuntu system settings (Or other install method you prefer).
    4. Solving the library linking problem in Nvidia driver.
    3. (Trouble shooting) Solving the library linking problem in Nvidia driver.
    - If you are having error message with `sudo prime-select intel` or `sudo prime-select nvidia`, follow instructions below.
    - ```bash
    # Replace 'xxx' to the velrsion of nvidia driver you installed
    @@ -195,7 +196,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - It is recommended to switch back and forth once if you run into some problem after a nvidia driver update.
    5. Blocking nouveau
    4. Blocking nouveau
    - Adding content below to `/etc/modprobe.d/blacklist-nouveau.conf`:
    @@ -206,13 +207,13 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - `sudo update-initramfs -u` when finish.
    - Reboot.
    - If you are using Ubuntu 18.04 (or some other case that your display manager is not running on X11), some extra work might be needed to prevent nouveau loading. Refer [here](https://askubuntu.com/questions/1031511/cant-disable-nouveau-drivers-in-ubuntu-18-04) for details.
    6. (Optional) Install CUDA, since the CUDA installation process is [well guided by Nvidia](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html), I will skip this part.
    5. (Optional) Install CUDA, since the CUDA installation process is [well guided by Nvidia](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html), I will skip this part.
    - With all that said, I personally recommend runfile installation. It is far more easy to maintain compare to other install method. Just make sure neither the display driver (self-contain in the runfile) nor the OpenGL libraries is check during the runfile installation process. ONLY install the CUDA Toolkit and don't run `nvidia-xconfig`.
    7. Solve some ACPI problem before bumblebee installation:
    6. Solve some ACPI problem before bumblebee installation:
    - Add `nogpumanager acpi_osi=! acpi_osi=Linux acpi_osi=\"Windows 2015\" pcie_port_pm=off` for `GRUB_CMDLINE_LINUX_DEFAULT` in `/etc/default/grub`
    - `nogpumanager` is actually part of the CUDA installation guide.
    @@ -222,11 +223,12 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - https://github.com/Bumblebee-Project/Bumblebee/issues/764
    - https://github.com/Bumblebee-Project/Bumblebee/issues/810
    - `sudo update-grub` when finish.
    - Reboot.
    - (Trouble shooting) If your `prime-select` updates grub, be sure to check your grub file again, as it does not handle escape character correctly, `\"` would become `\`
    8. Install bumblebee
    7. Install bumblebee
    - ```shell
    # If you use Ubuntu 18.04, the official ppa should work
    sudo add-apt-repository ppa:bumblebee/testing
    sudo apt update
    sudo apt install bumblebee bumblebee-nvidia
    @@ -237,10 +239,11 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - Change `Driver=` to `Driver=nvidia`
    - Change all occurrences of `nvidia-current` to `nvidia-xxx` (`xxx` is your nvidia driver version)
    - `KernelDriver=nvidia-xxx`
    - It appears that nvidia driver change its location in Ubuntu 18.04, refer [here](https://github.com/Bumblebee-Project/Bumblebee/issues/951) for details and solutions.
    - Save the file and `sudo service bumblebeed restart`
    9. Kernel module loading modification:
    8. Kernel module loading modification:
    - Make sure corresponding section in `/etc/modprobe.d/bumblebee.conf` look like below
    @@ -261,28 +264,28 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - `sudo update-initramfs -u` when finish.
    - Reboot.
    9. Create a group for bumblebee so that you won't need to `sudo` every time:
    10. Create a group for bumblebee so that you won't need to `sudo` every time:
    - If `cat /etc/group | grep $(whoami)` already gives your user name, pass this part.
    - `groupadd bumblebee && gpasswd -a $(whoami) bumblebee`
    11. Verification:
    10. (Trouble shooting) Try `optirun nvidia-smi`, if encounter `[ERROR][XORG] (EE) Failed to load module "mouse" (module does not exist, 0)`, add lines below to `/etc/bumblebee/xorg.conf.nvidia`
    - `cat /proc/acpi/bbswitch` should output something like `Ouput:0000:01:00.0 OFF`
    - ```
    Section "Screen"
    Identifier "Default Screen"
    Device "DiscreteNvidia"
    EndSection
    ```
    - `optirun cat /proc/acpi/bbswitch` should output something like `Ouput:0000:01:00.0 ON`
    - Check [here](https://github.com/Bumblebee-Project/Bumblebee/issues/867) for more information about this problem.
    - You might highly possible run into the `[ERROR][XORG] (EE) Failed to load module "mouse" (module does not exist, 0)` problem, append content below to `/etc/bumblebee/xorg.conf.nvidia` to solve this:
    11. Verification:
    - ```
    Section "Screen"
    Identifier "Default Screen"
    Device "DiscreteNvidia"
    EndSection
    ```
    - `cat /proc/acpi/bbswitch` should output something like `Ouput:0000:01:00.0 OFF`
    - Check [here](https://github.com/Bumblebee-Project/Bumblebee/issues/867) for more information about this problem.
    - `optirun cat /proc/acpi/bbswitch` should output something like `Ouput:0000:01:00.0 ON`
    - `optirun nvidia-smi` should give your something like:
    @@ -316,33 +319,63 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - QEMU from Ubuntu official PPA should work, just `sudo apt install qemu-kvm qemu-utils qemu-efi ovmf`.
    - For those who want to use GVT-g QEMU as I did:
    - Please note that QEMU 2.10 or above should use a higher version of OVMF (say if you use UEFI for your VM), otherwise will have boot hang. Refer [here](https://bugs.launchpad.net/qemu/+bug/1715700) for details about which version. Simplest solution is to use [ovmf package from 18.04 ppa](https://launchpad.net/ubuntu/bionic/+package/ovmf) directly.
    - ```shell
    sudo apt-get install git libfdt-dev libpixman-1-dev libssl-dev vim socat libsdl1.2-dev libspice-server-dev autoconf libtool xtightvncviewer tightvncserver x11vnc libsdl1.2-dev uuid-runtime uuid uml-utilities bridge-utils python-dev liblzma-dev libc6-dev libusb-1.0-0-dev ovmf checkinstall
    - Here I use QEMU 2.11.1 with pulse audio patch from [spheenik](https://www.reddit.com/user/spheenik) to provide better audio quality and resolve the crackling issue, and vcpupin patch from [saveriomiroddi](https://github.com/saveriomiroddi) for better performance.
    - Details about pulse audio patch:
    - [Improved Pulse Audio Driver for QEMU - Testers/coders needed! (archived)](https://www.reddit.com/r/VFIO/comments/74vokw/improved_pulse_audio_driver_for_qemu/)
    - [Heads up: QEMU audio patch rebased onto 2.12 ](https://www.reddit.com/r/VFIO/comments/8ptqbd/heads_up_qemu_audio_patch_rebased_onto_212/)
    - [Github Gist](https://gist.github.com/spheenik/8140a4405f819c5cd2465a65c8bb6d09/9735bcfaaaef45cf47e1b5d92c5006adf6ecd737)
    - [Github](https://github.com/spheenik/qemu)
    - Details about vcpupin patch
    - [QEMU fork with pinning (with hyper threading support) (archived)](https://www.reddit.com/r/VFIO/comments/79z4q2/qemu_fork_with_pinning_with_hyper_threading/)
    - [Github](https://github.com/saveriomiroddi/qemu-pinning)
    git clone https://github.com/01org/igvtg-qemu
    cd igvtg-qemu
    git checkout stable-2.9.0
    - Follow instructions below to build the QEMU I use (only if you prefer):
    - ```shell
    # Clone saveriomiroddi's vcpupin version of QEMU
    git clone https://github.com/saveriomiroddi/qemu-pinning.git qemu
    cd qemu
    git checkout v2.11.1-pinning
    # Apply pulseaudio from spheenik's git, we're applying the v1 version.
    wget -O - https://gist.github.com/spheenik/8140a4405f819c5cd2465a65c8bb6d09/raw/9735bcfaaaef45cf47e1b5d92c5006adf6ecd737/v1.patch | patch -p0
    # You might need to set your git email or name before commiting changes
    git commit -am "Apply pulse audio patch"
    # Fix some configure problem due to recent change in glibc
    git cherry-pick -x 75e5b70e6b5dcc4f2219992d7cffa462aa406af0
    # Install dependencies
    sudo apt install libjpeg-turbo8-dev libepoxy-dev libdrm-dev libgbm-dev libegl1-mesa-dev libboost-thread1.58-dev libboost-random1.58-dev libiscsi-dev libnfs-dev libfdt-dev libpixman-1-dev libssl-dev socat libsdl1.2-dev libspice-server-dev autoconf libtool xtightvncviewer tightvncserver x11vnc libsdl1.2-dev uuid-runtime uuid uml-utilities bridge-utils python-dev liblzma-dev libc6-dev libusb-1.0-0-dev checkinstall virt-viewer cpu-checker nettle-dev libaio-dev
    # Prepare to build
    mkdir build
    cd build
    # QEMU does not support python3
    ./configure --prefix=/usr \
    ../configure --prefix=/usr \
    --audio-drv-list=alsa,pa,oss \
    --enable-kvm \
    --disable-xen \
    --enable-debug-info \
    --enable-debug \
    --enable-sdl \
    --enable-vnc \
    --enable-vnc-jpeg \
    --enable-opengl \
    --enable-libusb \
    --enable-vhost-net \
    --enable-spice \
    --disable-debug-tcg \
    --target-list=x86_64-softmmu \
    --python=/usr/bin/python2
    make -j8
    # QEMU does not provide 'make uninstall'
    # Use checkinstall here so that you can remove it by 'dpkg -r'
    # Assign a version number start with number is mandatory when using checkinstall
    # Assign a version number start with numeric number is mandatory when using checkinstall
    sudo checkinstall
    ```
    @@ -370,6 +403,8 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    3. (Optional) Setup hugepages
    - [Reasons to use hugepages](https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF#Static_huge_pages)
    - Check `cat /proc/cpuinfo` see if it has the `pse` flag (for 2MB pages) or the `pdpe1gb` flag (for 1GB pages)
    - For `pdpe1gb`:
    - Add `default_hugepagesz=1G hugepagesz=1G hugepages=8 transparent_hugepage=never` to `GRUB_CMDLINE_LINUX_DEFAULT` in `/etc/default/grub`, this will assign a 8GB huge page.
    @@ -394,11 +429,19 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - Here, `1028` is the SVID and `07b1` is the SSID. We will use them later.
    2. Setup VM:
    2. Setup audio:
    - Please refer to [Archwiki/PCI passthrough/Passing VM audio to host via PulseAudio](https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF#Passing_VM_audio_to_host_via_PulseAudio) and [Archwiki/pulseaudio/Allowing multiple users to use PulseAudio at the same time](https://wiki.archlinux.org/index.php/PulseAudio/Examples#Allowing_multiple_users_to_use_PulseAudio_at_the_same_time)
    3. Setup VM:
    - **Note**: Command here just serve as a reference, check QEMU documentation for more detail.
    - **Note**: I personally don't prefer libvirt as editing xml is annoying for me. Use libvirt if you like it, and use `virsh domxml-from-native qemu-argv xxx.sh` to convert a QEMU launching script to libvirt XML. Refer [here](https://libvirt.org/drvqemu.html#imex) for more information.
    - **Note**: I personally don't prefer libvirt as editing xml is annoying for me. Use libvirt if you like it, and use `virsh domxml-from-native qemu-argv xxx.sh` to convert a QEMU launching script to libvirt XML if needed. Refer [here](https://libvirt.org/drvqemu.html#imex) for more information.
    - **Note**: If you would like to put you GPU at some other address, refer [here](https://www.redhat.com/archives/libvir-list/2013-February/msg00440.html) for details about ICH9 and GMCH (Graphics & Memory Controller Hub) defines
    - Create a disk for your VM:
    @@ -408,42 +451,54 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    - Create two script for tap networking:
    - tap_ifup (check file below in this gist)
    - tap_ifdown (check file below in this gist)
    - `tap_ifup` (check file below in this gist)
    - `tap_ifdown` (check file below in this gist)
    - Use `dpkg -L ovmf` to locate your `OVMF_VARS.fd` file, copy that to the directory where you store your VM image, then rename it to `WIN_VARS.fd`(or other names you like).
    - Create a QEMU launching script:
    - Create a script for starting your VM:
    - Recall that our GPU have a SVID `1028`, and a SSID `07b1`. Convert these two hexadecimal value to decimal. Which is `4136` for SVID, and `1969` for SSID. Use these two value to set the corresponding vfio-pci options (see script below).
    - This will solve the SSID/SVID all zero problem inside the VM.
    - ```shell
    #!/bin/bash
    # Set audio output options
    export QEMU_AUDIO_DRV=pa
    export QEMU_PA_SERVER="<your-pulse-socket>"
    export QEMU_AUDIO_TIMER_PERIOD=500
    # Use command below to generate a MAC address
    # printf '52:54:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))
    # Refer https://github.com/saveriomiroddi/qemu-pinning for how to set your cpu affinity properly
    qemu-system-x86_64 \
    -name "Windows10-QEMU" \
    -machine type=q35,accel=kvm \
    -global ICH9-LPC.disable_s3=1 \
    -global ICH9-LPC.disable_s4=1 \
    -enable-kvm \
    -cpu host,kvm=off,hv_vapic,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vendor_id=12alphanum \
    -smp 8,sockets=1,cores=4,threads=2 \
    -smp 6,sockets=1,cores=3,threads=2 \
    -vcpu vcpunum=0,affinity=1 -vcpu vcpunum=1,affinity=5 \
    -vcpu vcpunum=2,affinity=2 -vcpu vcpunum=3,affinity=6 \
    -vcpu vcpunum=4,affinity=3 -vcpu vcpunum=5,affinity=7 \
    -m 8G \
    -mem-path /dev/hugepages \
    -mem-prealloc \
    -balloon none \
    -rtc clock=host,base=localtime \
    -vnc 127.0.0.1:1 \
    -device qxl,bus=pcie.0,addr=1c.2 \
    -device ich9-intel-hda -device hda-output \
    -device qxl,bus=pcie.0,addr=1c.4,id=video.2 \
    -vga none \
    -nographic \
    -serial none \
    -parallel none \
    -k en-us \
    -usb -usbdevice tablet \
    -spice port=5930,addr=127.0.0.1,disable-ticketing \
    -usb \
    -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
    -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,x-pci-sub-device-id=1969,x-pci-sub-vendor-id=4136,multifunction=on,romfile=MyGPU.rom \
    -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd \
    @@ -455,6 +510,9 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    -drive file=virtio-win-0.1.141.iso,index=2,media=cdrom \
    -netdev type=tap,id=net0,ifname=tap0,script=tap_ifup,downscript=tap_ifdown,vhost=on \
    -device virtio-net-pci,netdev=net0,addr=19.0,mac=<address your generate>
    -device pci-bridge,addr=12.0,chassis_nr=2,id=head.2 \
    -device virtio-keyboard-pci,bus=head.2,addr=03.0,display=video.2 \
    -device virtio-mouse-pci,bus=head.2,addr=04.0,display=video.2 \
    ```
    - For libvirt, refer [here](https://gist.github.com/anonymous/500f1edf89d6f22c40bd2cbbdec6490b) for an example of how to masquerade your Subsystem ID. (Credit to jscinoz)
    @@ -463,8 +521,10 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    1. Binding your dGPU to vfio-pci driver:
    - `echo "10de 1bb6" > "/sys/bus/pci/drivers/vfio-pci/new_id"`
    2. Run the QEMU launching script
    2. Run the script to launch your VM
    - Install your Windows system through host side VNC (`127.0.0.1:5901`).
    - `-device qxl,bus=pcie.0,addr=1c.4,id=video.2` need to comment out, change `-vga none` to `-vga qxl` so that QXL would become the first GPU and can see POST screen from spice client.
    - Change back once you have everything working.
    - Add `192.168.99.0/24` to your Windows VM firewall exception:
    - In `Control Panel\System and Security\Windows Defender Firewall`, click `Advance settings` in the right panel, and `Inbound Rules` -> `New rules`.
    - Make sure you can `ping` to your VM from host.
    @@ -541,7 +601,6 @@ Extra precautions should be taken for Steam in-home Streaming:
    - Use [this method](https://steamcommunity.com/groups/homestream/discussions/0/617335934139051123/) to unlock the remote screen, note that current RDP session will be terminated once unlock success.
    - Pro or higher version of Windows is required.
    - Do not launch the script until the game appears in taskbar, otherwise it won't use your dGPU.
    -
    ## External display setup
    @@ -552,6 +611,12 @@ External display require a BIOS setting that can rarely be seen on Optimus lapto
    - However, you will lose your capability to extend your host machine display. As there is no display output port connect to the iGPU, e.g. your host.
    - While RemoteFX will compress the image in exchange for performance (which is not good if you required extreme image quality for professional use), such problem don't exist for external display setup, as it hook the dGPU directly.
    ### Looking glass
    - If your machine can expose video output port to dGPU, then using Looking Glass is possible.
    - Moreover, if you have a Quadro card, you can load EDID directly from file in Nvidia Control Panel, and don't need to plug anything. Can even run without physical video output port expost to dGPU.
    - Though you still need to plug something for the first time setup otherwise Nvidia Control Panel won't show.
    # FAQ
    ## How did you extract you vBIOS?
    @@ -569,25 +634,21 @@ Well, except for laptop that use MXM graphics card, vBIOS of onboard graphics ca
    - Manufactures tend to include several vBIOS for generic purpose. Be sure you find the correct vBIOS that have the same device ID as the one shown in device manager.
    - **Disclaimer**: I just know that you can use this method to extract the vBIOS of onboard graphics in the old days. However laptop BIOS may vary and I am not sure either the extraction process can go smoothly or the extracted and identified vBIOS rom can be used in QEMU without any problem.
    ## Did you success with AMD CPU?
    Never own a laptop with AMD CPU myself, worth trying though. Don't forget to share you experience.
    ## Regarding AMD CPU/GPU?
    ## What about AMD dGPU?
    I Know nothing about dGPU from the red team.
    Never own a laptop with AMD CPU/GPU myself, worth trying though.
    ## What about GVT-g? Can I replicate a Optimus system inside a VM?
    As for now, No. GVT-g can run on Q35 or PC machine but only with SeaBIOS. Won't boot with ovmf.
    Recently GVT project successful expose guest screen with dmabuf, might be some hope?
    Though passing dGPU to a GVT-g VM is possible, but the dGPU will report Code 12 with "no enough resources" inside the VM. Don't know why.
    Last time I try this, passing dGPU to a GVT-g VM is possible, but the dGPU will report Code 12 with "no enough resources" inside the VM. No idea why.
    ## What about those bare-bone laptop?
    Bare-bone laptop with desktop CPU already have their iGPU disabled in a way you cannot revert (as far as I know), and can only use their dGPU to render the display. Thus there will be no display if you pass it to your VM.
    For those bare-bone laptops who have two dGPUs, passing one to your VM sounds pretty possible. Though, be sure to take extra care if you have two identical dGPU. Check [here](https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF#Using_identical_guest_and_host_GPUs) for more detail.
    For those bare-bone laptops who have two dGPUs, passing one to your VM sounds possible? Not sure. Just take extra care if you have two identical dGPU. Check [here](https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF#Using_identical_guest_and_host_GPUs) for more detail.
    ## Options other than RemoteFX?
    @@ -599,10 +660,10 @@ For RemoteFX connection with xfreerdp:
    - Only windowed game can work, full screen will triger d3d11 0x087A0001 cannot set resolution blablabla problem. Media player does not affect by this.
    - As a solution, use [borderless gaming](https://github.com/Codeusa/Borderless-Gaming) or other equivalence.
    - Windows client doesn't seems to have this problem.
    - Windowed client doesn't seems to have this problem.
    - Mouse will go wild due to relative mouse is unsupported in RDSH/RDVH connection.
    - Redirect a XBOX controller or USB joystick might solve this?
    - [Using Hyper-V for a high-end desktop computer](https://blogs.msdn.microsoft.com/virtual_pc_guy/2011/01/17/using-hyper-v-for-a-high-end-desktop-computer/)
    - Use Synergy (v1) with relative mouse mode enabled
    - [RemoteFX Question](https://social.technet.microsoft.com/Forums/windowsserver/en-US/28373bb0-d9a6-4876-bf0b-02f2ba6ea6b3/remotefx-question?forum=winserverhyperv)
    - [Erratic mouse movement in 3D games over RDP with RemoteFX](https://superuser.com/questions/849918/erratic-mouse-movement-in-3d-games-over-rdp-with-remotefx)
    @@ -616,8 +677,6 @@ For RemoteFX connection with xfreerdp:
    [PCI passthrough via OVMF - Arch Wiki](https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF)
    [GVTg_Setup_Guide](https://github.com/intel/gvt-linux/wiki/GVTg_Setup_Guide)
    [CUDA installation guide](http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html)
    [Frame rate is limited to 30 FPS in Windows 8 and Windows Server 2012 remote sessions](https://support.microsoft.com/en-us/help/2885213/frame-rate-is-limited-to-30-fps-in-windows-8-and-windows-server-2012-r)
  10. @Misairu-G Misairu-G revised this gist Dec 25, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -157,6 +157,8 @@ For people who encounter Code 43 with a MUXless scheme, that is to say, you can
    [Perdouille got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dqo6jxf/). He/She use MSI GS60-040XFR with an i7-4720HQ and a 970m.
    [qgnox got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/drq3ewm/). He/She use MSI GS60 2PC with GTX860M.
    # Bumblebee setup guide
    **Note**: For people who don't want to setup bumblebee, follow [this](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dpvwka6/) to get your GPU's ACPI address, and power it on/off by refering script [here](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dpvubpd/). (Credit to Verequies from reddit)
  11. @Misairu-G Misairu-G revised this gist Dec 14, 2017. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    #### Table of Content

    - [What to expect?](#what-to-expect)
    - [The idea behind](#some-tldr-about-the-idea-behind)
    - [Some TLDR about the idea behind](#some-tldr-about-the-idea-behind)
    - [Prerequisites](#prerequisites)
    - [Hardware](#hardware)
    - [System & Software](#system--software)
    @@ -62,7 +62,9 @@ Steam in-home streaming between Windows VM and host:

    As you might read after, this tutorial is pretty much the same as most passthrough guide. The keypoint, however, is to assign Subsystem ID for the dGPU using some vfio-pci options. My dGPU appears to have a Subsystem ID 00000000 inside the VM by default.

    About one display setup, frames are rendered in GPU memory as we all know, and display ports apparently is not the only way we can get those frames. Nvidia itself provides API to capture things happen in GPU memory, this is why we can have technology like Steam in-home streaming and Geforce experience. I have RemoteFX working and that is the only reason why I put that in this tutorial, but since I use a Quadro card, and Nvidia limit the API usage in Geforce and I don't have a Geforce laptop to test this, things might be vary in different machine. The good news is [gnif's phenomenal work](https://forum.level1techs.com/t/a-little-teaser-of-what-is-to-come/121641) have made a huge step forward for one-display setup, and we can ditch things like Steam streaming and RemoteFX in a very near future.
    About one display setup, frames are rendered in GPU memory as we all know, and display ports apparently is not the only way we can get those frames. Nvidia itself provides API to capture things happen in GPU memory, this is why we can have technology like Steam in-home streaming and Geforce experience. I have RemoteFX working and that is the only reason why I put that in this tutorial. Despite I use a quadro, this mobile version does not support NvFBC capture API (the same as other consumer card), so you should be able to get RemoteFX working with GPU even its Geforce.

    Some might be heard of [gnif's phenomenal work](https://forum.level1techs.com/t/a-little-teaser-of-what-is-to-come/121641), which made a huge step forward for one-display setup. Unfortunately, a dummy device is still required for that setup, which is a no go for laptop. Even if you are using MUXed laptop, having a dummy device plug-in still mean that you need to have DisplayPortDirectOutput mode enabled, which largely limit the capability of extending the host's display.

    # Prerequisites

    @@ -537,6 +539,7 @@ Extra precautions should be taken for Steam in-home Streaming:
    - Use [this method](https://steamcommunity.com/groups/homestream/discussions/0/617335934139051123/) to unlock the remote screen, note that current RDP session will be terminated once unlock success.
    - Pro or higher version of Windows is required.
    - Do not launch the script until the game appears in taskbar, otherwise it won't use your dGPU.
    -
    ## External display setup
  12. @Misairu-G Misairu-G revised this gist Dec 11, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    #### Table of Content

    - [What to expect?](#what-to-expect)
    - [The idea behind](#the-idea-behind)
    - [The idea behind](#some-tldr-about-the-idea-behind)
    - [Prerequisites](#prerequisites)
    - [Hardware](#hardware)
    - [System & Software](#system--software)
  13. @Misairu-G Misairu-G revised this gist Dec 11, 2017. 1 changed file with 17 additions and 10 deletions.
    27 changes: 17 additions & 10 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@
    #### Table of Content

    - [What to expect?](#what-to-expect)
    - [The idea behind](#the-idea-behind)
    - [Prerequisites](#prerequisites)
    - [Hardware](#hardware)
    - [System & Software](#system--software)
    @@ -45,7 +46,7 @@ Depends on your hardware, you can have a laptop that:

    ![Unigine Heaven 4.0 Basic test](https://i.imgur.com/YVTTyfN.jpg)

    Steam in-home steaming between Windows VM and host:
    Steam in-home streaming between Windows VM and host:

    - Both game use high preset with V-Sync enabled.
    - Max fps of Witcher 3 has set to 60.
    @@ -57,9 +58,15 @@ Steam in-home steaming between Windows VM and host:

    \*This is my laptop running in Optimus mode with a 1080p@120Hz panel (I swapped the original 1080p@60Hz myself) and a MXM form factor Quadro P5000(QS). This laptop is MUXed.

    ## Some TLDR about the idea behind

    As you might read after, this tutorial is pretty much the same as most passthrough guide. The keypoint, however, is to assign Subsystem ID for the dGPU using some vfio-pci options. My dGPU appears to have a Subsystem ID 00000000 inside the VM by default.

    About one display setup, frames are rendered in GPU memory as we all know, and display ports apparently is not the only way we can get those frames. Nvidia itself provides API to capture things happen in GPU memory, this is why we can have technology like Steam in-home streaming and Geforce experience. I have RemoteFX working and that is the only reason why I put that in this tutorial, but since I use a Quadro card, and Nvidia limit the API usage in Geforce and I don't have a Geforce laptop to test this, things might be vary in different machine. The good news is [gnif's phenomenal work](https://forum.level1techs.com/t/a-little-teaser-of-what-is-to-come/121641) have made a huge step forward for one-display setup, and we can ditch things like Steam streaming and RemoteFX in a very near future.

    # Prerequisites

    With all that said, this tutorial does not mean any laptop with a Optimus setup will be able to passthrough their dGPU. Generally, a pretty high end laptop is still required, and it is highly possible you will success if you have a laptop that use a swappable MXM form factor graphics card.
    With all that said, this tutorial does not mean any laptop with a Optimus setup will be able to passthrough their dGPU. Generally, a pretty high end laptop is still required, and it is highly possible you will success if you have a laptop that use a swappable MXM form factor graphics card.

    ## Hardware

    @@ -81,7 +88,7 @@ With all that said, this tutorial does not mean any laptop with a Optimus setup
    # output from lspci:
    # 00:01.0 PCI bridge: Intel Corporation Sky Lake PCIe Controller (x16) (rev 05)
    # 01:00.0 VGA compatible controller: NVIDIA Corporation Device 1bb6 (rev a1)
    # output from dmesg
    [ 0.000000] DMAR: IOMMU enabled
    [ 0.086383] DMAR-IR: IOAPIC id 2 under DRHD base 0xfed91000 IOMMU 1
    @@ -120,9 +127,9 @@ With all that said, this tutorial does not mean any laptop with a Optimus setup
    - Currently running a Intel GVT-g version QEMU (2.9.0, for testing iGPU virtualization), other main stream QEMU should also work.
    - RDP Client:
    - Freerdp 2.0 or above for RDP 8 with RemoteFX connection.
    **Note**: Keep your dual-boot Windows if you want to use software like XTU.
    ## Update: Attention for MUXless laptop
    ~~Not sure anyone succeseded with a MUXless laptop yet (Or failed with a MUXed laptop)~~. If you do, please leave a comment with your setup (laptop model, what ROM for your GPU and what SSID/SVID are you using). Consider this as a request.
    @@ -254,7 +261,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    10. Create a group for bumblebee so that you won't need to `sudo` every time:
    - `groupadd bumblebee && gpasswd -a $(whoami) bumblebee`
    - `groupadd bumblebee && gpasswd -a $(whoami) bumblebee`
    11. Verification:
    @@ -426,7 +433,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    -balloon none \
    -rtc clock=host,base=localtime \
    -vnc 127.0.0.1:1 \
    -device qxl-vga,bus=pcie.0,addr=1c.2 \
    -device qxl,bus=pcie.0,addr=1c.2 \
    -vga none \
    -nographic \
    -serial none \
    @@ -445,7 +452,7 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    -netdev type=tap,id=net0,ifname=tap0,script=tap_ifup,downscript=tap_ifdown,vhost=on \
    -device virtio-net-pci,netdev=net0,addr=19.0,mac=<address your generate>
    ```
    - For libvirt, refer [here](https://gist.github.com/anonymous/500f1edf89d6f22c40bd2cbbdec6490b) for an example of how to masquerade your Subsystem ID. (Credit to jscinoz)
    ## Run your VM and configure guest side
    @@ -519,9 +526,9 @@ For other task:
    ## Steam in-home Streaming
    For the [limitations of RemoteFX](#known-issue), service like Steam in-home steaming or Geforce Experience is more recommended for gaming scenario.
    For the [limitations of RemoteFX](#known-issue), service like Steam in-home streaming or Geforce Experience is more recommended for gaming scenario.
    Extra precautions should be taken for Steam in-home Steaming:
    Extra precautions should be taken for Steam in-home Streaming:
    - A Remote desktop connection that use dGPU inside the VM to render its display is still required, or the game will literally not running on the dGPU you just passed.
    - Not 100 percent about this. Maybe manually tell the game to use which GPU is possible?
  14. @Misairu-G Misairu-G revised this gist Dec 10, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -445,6 +445,8 @@ We will first go through my bumblebee setup process. I did install bumblebee fir
    -netdev type=tap,id=net0,ifname=tap0,script=tap_ifup,downscript=tap_ifdown,vhost=on \
    -device virtio-net-pci,netdev=net0,addr=19.0,mac=<address your generate>
    ```
    - For libvirt, refer [here](https://gist.github.com/anonymous/500f1edf89d6f22c40bd2cbbdec6490b) for an example of how to masquerade your Subsystem ID. (Credit to jscinoz)
    ## Run your VM and configure guest side
  15. @Misairu-G Misairu-G revised this gist Dec 5, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@
    - [Hardware](#hardware)
    - [System & Software](#system--software)
    - [Update: Attention for MUXless laptop](#update-attention-for-muxless-laptop)
    - [Some success report](#some-success-report)
    - [Bumblebee setup guide](#bumblebee-setup-guide)
    - [dGPU passthrough guide](#dgpu-passthrough-guide)
    - [System & Environment setup](#system--environment-setup)
  16. @Misairu-G Misairu-G revised this gist Dec 5, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -124,7 +124,7 @@ With all that said, this tutorial does not mean any laptop with a Optimus setup
    ## Update: Attention for MUXless laptop
    Not sure anyone succeseded with a MUXless laptop yet (Or failed with a MUXed laptop). If you do, please leave a comment with your setup (laptop model, what ROM for your GPU and what SSID/SVID are you using). Consider this as a request.
    ~~Not sure anyone succeseded with a MUXless laptop yet (Or failed with a MUXed laptop)~~. If you do, please leave a comment with your setup (laptop model, what ROM for your GPU and what SSID/SVID are you using). Consider this as a request.
    Now for switchable graphics, there are three different solutions: MUXed(Old), MUXless and MUXed(New)
    @@ -143,6 +143,10 @@ For people who encounter Code 43 with a MUXless scheme, that is to say, you can
    5. You need both a MUXed dGPU ROM and its corresponding SSID/SVID.
    6. ~~MUXless non-MXM dGPU don't support running independently due to hardware limitation. No fix.~~ Should not be a problem. Clevo P650RG is a MUXed laptop with soldered dGPU. This laptop also support G-Sync (with appropriate display panel and GPU of casue) when using Discrete mode, and its MSHybrid mode stands for Optimus).
    ### Some success report
    [Perdouille got a MUXless laptop working](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dqo6jxf/). He/She use MSI GS60-040XFR with an i7-4720HQ and a 970m.
    # Bumblebee setup guide
    **Note**: For people who don't want to setup bumblebee, follow [this](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dpvwka6/) to get your GPU's ACPI address, and power it on/off by refering script [here](https://www.reddit.com/r/VFIO/comments/7d27sz/you_can_now_passthrough_your_dgpu_as_you_wish/dpvubpd/). (Credit to Verequies from reddit)
  17. @Misairu-G Misairu-G revised this gist Nov 28, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -576,10 +576,11 @@ Try nvidia gamestream with moonlight client, or Parsec. Or just pick whatever ha
    # Known issue
    For RemoteFX connection:
    For RemoteFX connection with xfreerdp:
    - Only windowed game can work, full screen will triger d3d11 0x087A0001 cannot set resolution blablabla problem. Media player does not affect by this.
    - As a solution, use [borderless gaming](https://github.com/Codeusa/Borderless-Gaming) or other equivalence.
    - Windows client doesn't seems to have this problem.
    - Mouse will go wild due to relative mouse is unsupported in RDSH/RDVH connection.
    - Redirect a XBOX controller or USB joystick might solve this?
    - [Using Hyper-V for a high-end desktop computer](https://blogs.msdn.microsoft.com/virtual_pc_guy/2011/01/17/using-hyper-v-for-a-high-end-desktop-computer/)
  18. @Misairu-G Misairu-G revised this gist Nov 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -135,7 +135,7 @@ Most modern Optimus laptop use MUXless scheme, while some others, HP/Thinkpad/De
    For people who encounter Code 43 with a MUXless scheme, that is to say, you can see your dGPU in guest, can even have nvidia driver installed without any problem, but still have this error code. Here are some **speculations** (read the [dGPU passthrough guide](#dgpu-passthrough-guide) first if you cannot understand things below):
    1. Your ROM don't support UEFI.
    2. Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM). Maybe some patch for OVMF will make it work. (Credit to jscinoz from reddit)
    2. Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM). Maybe some patch for OVMF will make it work.
    - If [ACPI call failed for firmware loading](https://www.reddit.com/r/VFIO/comments/6q7bf5/short_report_wip_got_the_nvidia_gpu_to/) is the only problem, then MUXless laptop with a MXM GPU should be fine. Please at least give that a try.
    3. ROM for MUXless dGPU don't support running independently. Maybe a ROM from dGPU who support MUXed will fix this.
    - As all MXM GPU can be install in a MUXed laptop, ROM from MXM GPU should work.
  19. @Misairu-G Misairu-G revised this gist Nov 26, 2017. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -65,7 +65,6 @@ With all that said, this tutorial does not mean any laptop with a Optimus setup
    - A CPU that support hardware virtualization (Intel VT-x) and IOMMU (Intel VT-d).

    - Check [here](https://ark.intel.com/Search/FeatureFilter?productType=processors&VTD=true&MarketSegment=Mobile) for a full list of qualified CPU
    - To achieve the "no external display" purpose, we will use RemoteFX. With proper configuration, gaming in 1600x900 with fps higher that 60 should not be a problem for most passthrough qualified laptop (RemoteFX codec is CPU intensive). For those who want to gaming in 1920x1080 60 fps+ through RemoteFX, a overclockable CPU like 6820HK or 7820HK, or 6920HQ and 7920HQ (which can actually overclock to +600Mhz using XTU) is recommended.

    - A motherboard that support IOMMU with decent IOMMU layout e.g. your dGPU is in its own IOMMU group aside from other devices.

    @@ -133,14 +132,15 @@ Now for switchable graphics, there are three different solutions: MUXed(Old), MU
    Most modern Optimus laptop use MUXless scheme, while some others, HP/Thinkpad/Dell mobile workstation, Clevo P650, some Alienware, etc. use MUXed scheme. At the dark age before Optimus solution came out, there is an old MUXed scheme which require reboot to switch graphics card and can only use one at a time, while the modern MUXed allow switch between Optimus and dGPU only, and can even have display output port hooked directly to the dGPU when using Optimus. The only thing unchanged is you need to get in BIOS to switch between these modes.
    For people who encounter Code 43 with a MUXless scheme. Here are some **speculations** (read the [dGPU passthrough guide](#dgpu-passthrough-guide) first if you cannot understand things below):
    For people who encounter Code 43 with a MUXless scheme, that is to say, you can see your dGPU in guest, can even have nvidia driver installed without any problem, but still have this error code. Here are some **speculations** (read the [dGPU passthrough guide](#dgpu-passthrough-guide) first if you cannot understand things below):
    1. Your ROM don't support UEFI.
    2. ROM for MUXless dGPU don't support running independently. Maybe a ROM from dGPU who support MUXed will fix this.
    2. Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM). Maybe some patch for OVMF will make it work. (Credit to jscinoz from reddit)
    - If [ACPI call failed for firmware loading](https://www.reddit.com/r/VFIO/comments/6q7bf5/short_report_wip_got_the_nvidia_gpu_to/) is the only problem, then MUXless laptop with a MXM GPU should be fine. Please at least give that a try.
    3. ROM for MUXless dGPU don't support running independently. Maybe a ROM from dGPU who support MUXed will fix this.
    - As all MXM GPU can be install in a MUXed laptop, ROM from MXM GPU should work.
    3. Nvidia driver don't allow MUXless dGPU running independently by checking SSID/SVID. Maybe a proper masqueraded SSID/SVID can fool the Nvidia driver and make it work. (SSID/SVID can be found inside Nvidia driver, by extracting it with WinRAR or some other tools. Follow [this guide](http://null-bin.blogspot.com/2015/08/how-to-modify-nvidia-notebook-driver.html))
    4. You need both a MUXed dGPU ROM and its corresponding SSID/SVID.
    5. Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM). Maybe some patch for OVMF will make it work. (Credit to jscinoz from reddit)
    4. Nvidia driver don't allow MUXless dGPU running independently by checking SSID/SVID. Maybe a proper masqueraded SSID/SVID can fool the Nvidia driver and make it work. (SSID/SVID can be found inside Nvidia driver, by extracting it with WinRAR or some other tools. Follow [this guide](http://null-bin.blogspot.com/2015/08/how-to-modify-nvidia-notebook-driver.html))
    5. You need both a MUXed dGPU ROM and its corresponding SSID/SVID.
    6. ~~MUXless non-MXM dGPU don't support running independently due to hardware limitation. No fix.~~ Should not be a problem. Clevo P650RG is a MUXed laptop with soldered dGPU. This laptop also support G-Sync (with appropriate display panel and GPU of casue) when using Discrete mode, and its MSHybrid mode stands for Optimus).
    # Bumblebee setup guide
  20. @Misairu-G Misairu-G revised this gist Nov 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -133,7 +133,7 @@ Now for switchable graphics, there are three different solutions: MUXed(Old), MU
    Most modern Optimus laptop use MUXless scheme, while some others, HP/Thinkpad/Dell mobile workstation, Clevo P650, some Alienware, etc. use MUXed scheme. At the dark age before Optimus solution came out, there is an old MUXed scheme which require reboot to switch graphics card and can only use one at a time, while the modern MUXed allow switch between Optimus and dGPU only, and can even have display output port hooked directly to the dGPU when using Optimus. The only thing unchanged is you need to get in BIOS to switch between these modes.
    For people who encounter Code 43 with a MUXless scheme. Here are some speculations (read the [dGPU passthrough guide](#dgpu-passthrough-guide) first if you cannot understand things below):
    For people who encounter Code 43 with a MUXless scheme. Here are some **speculations** (read the [dGPU passthrough guide](#dgpu-passthrough-guide) first if you cannot understand things below):
    1. Your ROM don't support UEFI.
    2. ROM for MUXless dGPU don't support running independently. Maybe a ROM from dGPU who support MUXed will fix this.
  21. @Misairu-G Misairu-G revised this gist Nov 26, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -48,6 +48,7 @@ Steam in-home steaming between Windows VM and host:

    - Both game use high preset with V-Sync enabled.
    - Max fps of Witcher 3 has set to 60.
    - No extra monitor what so ever.

    ![DOOM](https://i.imgur.com/c86OGKF.png)

    @@ -517,8 +518,8 @@ Extra precautions should be taken for Steam in-home Steaming:
    - A Remote desktop connection that use dGPU inside the VM to render its display is still required, or the game will literally not running on the dGPU you just passed.
    - Not 100 percent about this. Maybe manually tell the game to use which GPU is possible?
    - One more thing, Nvidia control panel is not accessible through RDP. Nothing will pop-up no matter how hard you click it.
    - Make sure only your dGPU is the only display adapter enabled inside the VM.
    - One more thing, Nvidia control panel is not accessible within a RDP session. Nothing will pop-up no matter how hard you click it.
    - Make sure your dGPU is the ONLY display adapter enabled inside the VM.
    - Use [this method](https://steamcommunity.com/groups/homestream/discussions/0/617335934139051123/) to unlock the remote screen, note that current RDP session will be terminated once unlock success.
    - Pro or higher version of Windows is required.
    - Do not launch the script until the game appears in taskbar, otherwise it won't use your dGPU.
  22. @Misairu-G Misairu-G revised this gist Nov 26, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,9 @@ Depends on your hardware, you can have a laptop that:

    Steam in-home steaming between Windows VM and host:

    - Both game use high preset with V-Sync enabled.
    - Max fps of Witcher 3 has set to 60.

    ![DOOM](https://i.imgur.com/c86OGKF.png)

    ![Witcher 3](https://i.imgur.com/HCXzaX7.png)
  23. @Misairu-G Misairu-G revised this gist Nov 26, 2017. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -511,6 +511,10 @@ For other task:
    For the [limitations of RemoteFX](#known-issue), service like Steam in-home steaming or Geforce Experience is more recommended for gaming scenario.
    Extra precautions should be taken for Steam in-home Steaming:
    - A Remote desktop connection that use dGPU inside the VM to render its display is still required, or the game will literally not running on the dGPU you just passed.
    - Not 100 percent about this. Maybe manually tell the game to use which GPU is possible?
    - One more thing, Nvidia control panel is not accessible through RDP. Nothing will pop-up no matter how hard you click it.
    - Make sure only your dGPU is the only display adapter enabled inside the VM.
    - Use [this method](https://steamcommunity.com/groups/homestream/discussions/0/617335934139051123/) to unlock the remote screen, note that current RDP session will be terminated once unlock success.
    - Pro or higher version of Windows is required.
  24. @Misairu-G Misairu-G revised this gist Nov 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    - [Prepare your script](#prepare-your-script)
    - [Run your VM and configure guest side](#run-your-vm-and-configure-guest-side)
    - [RemoteFX configure and fine tuning](#remotefx-configure-and-fine-tuning)
    - [Steam in-home Streaming](#steam-inhome-streaming)
    - [Steam in-home Streaming](#steam-in-home-streaming)
    - [External display setup](#external-display-setup)
    - [FAQ](#faq)
    - [How did you extract you vBIOS?](#how-did-you-extract-you-vbios)
  25. @Misairu-G Misairu-G revised this gist Nov 26, 2017. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@
    - [Prepare your script](#prepare-your-script)
    - [Run your VM and configure guest side](#run-your-vm-and-configure-guest-side)
    - [RemoteFX configure and fine tuning](#remotefx-configure-and-fine-tuning)
    - [Steam in-home Streaming](#steam-inhome-streaming)
    - [External display setup](#external-display-setup)
    - [FAQ](#faq)
    - [How did you extract you vBIOS?](#how-did-you-extract-you-vbios)
    @@ -43,6 +44,12 @@ Depends on your hardware, you can have a laptop that:

    ![Unigine Heaven 4.0 Basic test](https://i.imgur.com/YVTTyfN.jpg)

    Steam in-home steaming between Windows VM and host:

    ![DOOM](https://i.imgur.com/c86OGKF.png)

    ![Witcher 3](https://i.imgur.com/HCXzaX7.png)

    \*This is my laptop running in Optimus mode with a 1080p@120Hz panel (I swapped the original 1080p@60Hz myself) and a MXM form factor Quadro P5000(QS). This laptop is MUXed.

    # Prerequisites
    @@ -499,6 +506,16 @@ For other task:
    - Tasks that are more GPU compute intensive (which does its operation asynchronously from display update) will not be bottlenecked by CPU, thus you can choose a higher resolution like 1080p.
    ## Steam in-home Streaming
    For the [limitations of RemoteFX](#known-issue), service like Steam in-home steaming or Geforce Experience is more recommended for gaming scenario.
    Extra precautions should be taken for Steam in-home Steaming:
    - Make sure only your dGPU is the only display adapter enabled inside the VM.
    - Use [this method](https://steamcommunity.com/groups/homestream/discussions/0/617335934139051123/) to unlock the remote screen, note that current RDP session will be terminated once unlock success.
    - Pro or higher version of Windows is required.
    - Do not launch the script until the game appears in taskbar, otherwise it won't use your dGPU.
    ## External display setup
    External display require a BIOS setting that can rarely be seen on Optimus laptop.
  26. @Misairu-G Misairu-G revised this gist Nov 25, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -556,11 +556,10 @@ For RemoteFX connection:
    - Only windowed game can work, full screen will triger d3d11 0x087A0001 cannot set resolution blablabla problem. Media player does not affect by this.
    - As a solution, use [borderless gaming](https://github.com/Codeusa/Borderless-Gaming) or other equivalence.
    - Mouse will go wild due to relative mouse is unsupported in RDSH/RDVH connection.
    - Redirect a XBOX controller might solve this?
    - Redirect a XBOX controller or USB joystick might solve this?
    - [Using Hyper-V for a high-end desktop computer](https://blogs.msdn.microsoft.com/virtual_pc_guy/2011/01/17/using-hyper-v-for-a-high-end-desktop-computer/)
    - [RemoteFX Question](https://social.technet.microsoft.com/Forums/windowsserver/en-US/28373bb0-d9a6-4876-bf0b-02f2ba6ea6b3/remotefx-question?forum=winserverhyperv)
    - [Erratic mouse movement in 3D games over RDP with RemoteFX](https://superuser.com/questions/849918/erratic-mouse-movement-in-3d-games-over-rdp-with-remotefx)
    -
    # Reference
  27. @Misairu-G Misairu-G revised this gist Nov 25, 2017. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -551,9 +551,16 @@ Try nvidia gamestream with moonlight client, or Parsec. Or just pick whatever ha
    # Known issue
    For RemoteFX connection, only windowed game can work, full screen will triger d3d11 0x087A0001 cannot set resolution blablabla problem. Media player does not affect by this.
    As a solution, use [borderless gaming](https://github.com/Codeusa/Borderless-Gaming) or other equivalence.
    For RemoteFX connection:
    - Only windowed game can work, full screen will triger d3d11 0x087A0001 cannot set resolution blablabla problem. Media player does not affect by this.
    - As a solution, use [borderless gaming](https://github.com/Codeusa/Borderless-Gaming) or other equivalence.
    - Mouse will go wild due to relative mouse is unsupported in RDSH/RDVH connection.
    - Redirect a XBOX controller might solve this?
    - [Using Hyper-V for a high-end desktop computer](https://blogs.msdn.microsoft.com/virtual_pc_guy/2011/01/17/using-hyper-v-for-a-high-end-desktop-computer/)
    - [RemoteFX Question](https://social.technet.microsoft.com/Forums/windowsserver/en-US/28373bb0-d9a6-4876-bf0b-02f2ba6ea6b3/remotefx-question?forum=winserverhyperv)
    - [Erratic mouse movement in 3D games over RDP with RemoteFX](https://superuser.com/questions/849918/erratic-mouse-movement-in-3d-games-over-rdp-with-remotefx)
    -
    # Reference
  28. @Misairu-G Misairu-G revised this gist Nov 23, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -130,8 +130,7 @@ For people who encounter Code 43 with a MUXless scheme. Here are some speculatio
    3. Nvidia driver don't allow MUXless dGPU running independently by checking SSID/SVID. Maybe a proper masqueraded SSID/SVID can fool the Nvidia driver and make it work. (SSID/SVID can be found inside Nvidia driver, by extracting it with WinRAR or some other tools. Follow [this guide](http://null-bin.blogspot.com/2015/08/how-to-modify-nvidia-notebook-driver.html))
    4. You need both a MUXed dGPU ROM and its corresponding SSID/SVID.
    5. Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM). Maybe some patch for OVMF will make it work. (Credit to jscinoz from reddit)
    6. ~~MUXless non-MXM dGPU don't support running independently due to hardware limitation. No fix.~~
      - Should not be a problem. Clevo P650RG is a MUXed laptop with soldered dGPU. This laptop also support G-Sync when using Discrete mode (and MSHybrid mode stands for Optimus).
    6. ~~MUXless non-MXM dGPU don't support running independently due to hardware limitation. No fix.~~ Should not be a problem. Clevo P650RG is a MUXed laptop with soldered dGPU. This laptop also support G-Sync (with appropriate display panel and GPU of casue) when using Discrete mode, and its MSHybrid mode stands for Optimus).
    # Bumblebee setup guide
  29. @Misairu-G Misairu-G revised this gist Nov 23, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -131,7 +131,7 @@ For people who encounter Code 43 with a MUXless scheme. Here are some speculatio
    4. You need both a MUXed dGPU ROM and its corresponding SSID/SVID.
    5. Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM). Maybe some patch for OVMF will make it work. (Credit to jscinoz from reddit)
    6. ~~MUXless non-MXM dGPU don't support running independently due to hardware limitation. No fix.~~
      - Should not be a problem. Clevo P650RG is a MUXed laptop with soldered dGPU. This laptop also support G-Sync when using Discrete mode (and MSHybrid mode stands for Optimus).
      - Should not be a problem. Clevo P650RG is a MUXed laptop with soldered dGPU. This laptop also support G-Sync when using Discrete mode (and MSHybrid mode stands for Optimus).
    # Bumblebee setup guide
  30. @Misairu-G Misairu-G revised this gist Nov 23, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion [GUIDE] Optimus laptop dGPU passthrough.md
    Original file line number Diff line number Diff line change
    @@ -130,7 +130,8 @@ For people who encounter Code 43 with a MUXless scheme. Here are some speculatio
    3. Nvidia driver don't allow MUXless dGPU running independently by checking SSID/SVID. Maybe a proper masqueraded SSID/SVID can fool the Nvidia driver and make it work. (SSID/SVID can be found inside Nvidia driver, by extracting it with WinRAR or some other tools. Follow [this guide](http://null-bin.blogspot.com/2015/08/how-to-modify-nvidia-notebook-driver.html))
    4. You need both a MUXed dGPU ROM and its corresponding SSID/SVID.
    5. Nvidia driver try to read your dGPU ROM from system BIOS instead of using the ROM you provided through vfio-pci (this is actually how a real MUXless dGPU get its ROM). Maybe some patch for OVMF will make it work. (Credit to jscinoz from reddit)
    6. MUXless non-MXM dGPU don't support running independently due to hardware limitation. No fix.
    6. ~~MUXless non-MXM dGPU don't support running independently due to hardware limitation. No fix.~~
      - Should not be a problem. Clevo P650RG is a MUXed laptop with soldered dGPU. This laptop also support G-Sync when using Discrete mode (and MSHybrid mode stands for Optimus).
    # Bumblebee setup guide