Dell XPS 9560 で dGPU Passthrough に成功

読了まで:約3分


したので、ザックリと作業した内容をまとめたいと思います。

作業環境

  • NixOS 19.03 (nixpkgs の git master)
  • Dell XPS 9560 4k 16GB Memory Model (JP)
  • QEMU 3.0.0 + libvirtd + virt-manager

前提となる条件

  • virt-manager で qemu:///system へユーザー権限で接続出来ること
  • OVMF による GPU Passthrough が出来る様になっていること
  • 最後まで諦めない気合いや根性・気力を持っていること

参考にしたページ

具体的な作業について

1. 前提の準備

  1. NixOS (か、もしくは任意の Linux) で KVM を利用できるようにする
  2. KVM で PCI Passthrough が可能な諸条件を整える
  3. Windows 10 を利用する場合にはライセンスを用意する

2. 下準備

Dell XPS 9560 の BIOS を dump して vbios を抽出する

これの手順としては、

  1. USB 起動できる Bootable な FreeDOS のイメージ作成する
  2. 次に EXMBROM を FreeDOS の USB に突っ込む
  3. そして FreeDOS を Legacy mode で起動した後 EXMBROM.EXE を使って BIOS を dump
  4. 最後に VBiosFinder を利用し vbios の ROM を抽出

と言う感じです。

なお (3) の作業をする際には、

  • FreeDOS のインストールを選択しない(重要
  • EXMBROM.EXE の Prompt では 16384 をタイプする

という点には注意する必要があるかと思います。

抽出した vbios を Tianocore に組込む

これについては、

うページ上で解説されている内容をを再現する、という形になります。

準備として、

  • dump した vbios のデータを xxd -i vbios.rom > vbios.h という形で C のコードに変換
  • 変換した情報を元に ssdt.asl を修正してコンパイル
  • コンパイルした Ssdt.amlbuildable.txt にしたがって C のコードに変換

という作業を行なった後、

  • TianoCore の OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c

fwcfg_patch.txt と上記 2 つの C のコードを組込んでビルドします。

注意点としては、バイナリから生成した C ファイルやパッチ・ssdt.asl は適宜修正する必要があるので、それを忘れないようにしてください。

3. Windows 10 Pro の VM を作成する

これについては virt-manager でとりあえず Windows 10 Pro の UEFI VM を作成した後、次の作業を行います:

  1. vbios を組み込んだ TianoCore を利用する様にパスを修正する
  2. kvm である事を NVIDIA のドライバに悟られないように設定を追加する
  3. <hostdev> で dGPU を Passthrough をする設定を行う
  4. pcie-root-portslot の位置を Laptop の実機に合わせる

なお、これらの作業について私は Terminal から virsh を経由で該当 VM の編集を行いました。 また、実際に利用した Win10Pro.xml については記事下部に丸ごと転載したので、よかったら参考にしてください。

4. Windows 10 Pro VM でインストールなどを完了させる

ここまでの作業が上手く出来ていれば、

KVM 上の Windows 10 Pro で Passthrough した dGPU が Windows から利用できる

と言う状態になっているかと思います。

ただこれらの作業を一発で問題なく完了させるのはなかなか難しいので、その際には、

において参照されているリンク先(英語)を熟読して問題点のチェックを行いましょう。

最後に証拠

Dell XPS 9560 で dGPU Pssthrough に成功したスクリーンショット

ちなみに

上記の VM 、色々考えた末にストレージ容量などの関係でインストールし直すつもりなので、 ライセンス認証とかは未だ通してなかったりします。とは言え、 Windows 10 Pro のライセンスはいくつか所持しているので、その辺りは誤解なきよう ;-)

また今回は NixOS を使っていますが、別に NixOS でなければ出来ない事柄ではないため、 他の Linux でも同じ様な作業を行えば他の Linux Distro でも可能だと思います。

附属

Win10Pro.xml

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>Win10Pro</name>
  <uuid>a1f8be58-9c73-4bc4-ad1d-e7b2b79a5e82</uuid>
  <title>Windows 10 Pro</title>
  <metadata>
    <libosinfo:libosinfo
      xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0"
    >
      <libosinfo:os id="http://microsoft.com/win/10" />
    </libosinfo:libosinfo>
  </metadata>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static' current='4'>8</vcpu>
  <os>
    <type arch='x86_64' machine='pc-q35-3.0'>hvm</type>
    <loader
      readonly='yes'
      type='pflash'
    >/home/nyarla/VM/Win10Pro_CODE.fd</loader>
    <nvram>/home/nyarla/VM/Win10Pro_VARS.fd</nvram>
  </os>
  <features>
    <acpi />
    <apic />
    <hyperv>
      <relaxed state='on' />
      <vapic state='on' />
      <spinlocks state='on' retries='8191' />
      <vendor_id state='on' value='NYXPS9560KVM' />
    </hyperv>
    <kvm>
      <hidden state='on' />
    </kvm>
    <vmport state='off' />
  </features>
  <cpu mode='host-passthrough' check='none'>
    <topology sockets='1' cores='2' threads='4' />
  </cpu>
  <clock offset='localtime'>
    <timer name='rtc' tickpolicy='catchup' />
    <timer name='pit' tickpolicy='delay' />
    <timer name='hpet' present='no' />
    <timer name='hypervclock' present='yes' />
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no' />
    <suspend-to-disk enabled='no' />
  </pm>
  <devices>
    <emulator>/run/libvirt/nix-emulators/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='writethrough' />
      <source file='/home/nyarla/VM/Win10Pro.qcow2' />
      <target dev='vda' bus='virtio' />
      <boot order='1' />
      <address
        type='pci'
        domain='0x0000'
        bus='0x03'
        slot='0x00'
        function='0x0'
      />
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw' />
      <source file='/home/nyarla/Downloads/Win10_1803_Japanese_x64.iso' />
      <target dev='sdb' bus='sata' />
      <readonly />
      <boot order='2' />
      <address type='drive' controller='0' bus='0' target='0' unit='1' />
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw' />
      <source file='/home/nyarla/Downloads/virtio-win-0.1.160.iso' />
      <target dev='sdc' bus='sata' />
      <readonly />
      <address type='drive' controller='0' bus='0' target='0' unit='2' />
    </disk>
    <controller type='usb' index='0' model='qemu-xhci' ports='15'>
      <address
        type='pci'
        domain='0x0000'
        bus='0x02'
        slot='0x00'
        function='0x0'
      />
    </controller>
    <controller type='sata' index='0'>
      <address
        type='pci'
        domain='0x0000'
        bus='0x00'
        slot='0x1f'
        function='0x2'
      />
    </controller>
    <controller type='pci' index='0' model='pcie-root' />
    <controller type='pci' index='1' model='pcie-root-port'>
      <model name='pcie-root-port' />
      <target chassis='1' port='0x10' />
      <address
        type='pci'
        domain='0x0000'
        bus='0x00'
        slot='0x01'
        function='0x0'
        multifunction='on'
      />
    </controller>
    <controller type='pci' index='2' model='pcie-root-port'>
      <model name='pcie-root-port' />
      <target chassis='2' port='0x11' />
      <address
        type='pci'
        domain='0x0000'
        bus='0x00'
        slot='0x02'
        function='0x1'
      />
    </controller>
    <controller type='pci' index='3' model='pcie-root-port'>
      <model name='pcie-root-port' />
      <target chassis='3' port='0x12' />
      <address
        type='pci'
        domain='0x0000'
        bus='0x00'
        slot='0x02'
        function='0x2'
      />
    </controller>
    <controller type='pci' index='4' model='pcie-root-port'>
      <model name='pcie-root-port' />
      <target chassis='4' port='0x13' />
      <address
        type='pci'
        domain='0x0000'
        bus='0x00'
        slot='0x02'
        function='0x3'
      />
    </controller>
    <controller type='pci' index='5' model='pcie-root-port'>
      <model name='pcie-root-port' />
      <target chassis='5' port='0x14' />
      <address
        type='pci'
        domain='0x0000'
        bus='0x00'
        slot='0x02'
        function='0x4'
      />
    </controller>
    <controller type='pci' index='6' model='pcie-root-port'>
      <model name='pcie-root-port' />
      <target chassis='6' port='0x15' />
      <address
        type='pci'
        domain='0x0000'
        bus='0x00'
        slot='0x02'
        function='0x5'
      />
    </controller>
    <interface type='network'>
      <mac address='52:54:00:cc:3e:cf' />
      <source network='default' />
      <model type='virtio' />
      <address
        type='pci'
        domain='0x0000'
        bus='0x06'
        slot='0x00'
        function='0x0'
      />
    </interface>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial' />
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0' />
    </console>
    <input type='tablet' bus='usb'>
      <address type='usb' bus='0' port='1' />
    </input>
    <input type='mouse' bus='ps2' />
    <input type='keyboard' bus='ps2' />
    <graphics type='spice' autoport='yes'>
      <listen type='address' />
      <image compression='off' />
    </graphics>
    <sound model='ich9'>
      <address
        type='pci'
        domain='0x0000'
        bus='0x00'
        slot='0x1b'
        function='0x0'
      />
    </sound>
    <video>
      <model
        type='qxl'
        ram='131072'
        vram='131072'
        vgamem='65536'
        heads='1'
        primary='yes'
      />
      <address
        type='pci'
        domain='0x0000'
        bus='0x00'
        slot='0x02'
        function='0x0'
        multifunction='on'
      />
    </video>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x01' slot='0x00' function='0x0' />
      </source>
      <rom bar='off' />
      <address
        type='pci'
        domain='0x0000'
        bus='0x01'
        slot='0x00'
        function='0x0'
      />
    </hostdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='2' />
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='3' />
    </redirdev>
    <memballoon model='virtio'>
      <address
        type='pci'
        domain='0x0000'
        bus='0x04'
        slot='0x00'
        function='0x0'
      />
    </memballoon>
  </devices>
  <qemu:commandline>
    <qemu:arg value='-set' />
    <qemu:arg value='device.hostdev0.x-pci-sub-vendor-id=0x1028' />
    <qemu:arg value='-set' />
    <qemu:arg value='device.hostdev0.x-pci-sub-device-id=0x07be' />
  </qemu:commandline>
</domain>

にゃるら(カラクリスタ)

『輝かしい青春』なんて失かった人。
次に備えて待機中。

今は趣味でプログラミングをして
生活しています。