KVM PCI Passthrough and Omni-Path » History » Version 2
Brian Smith, 04/07/2018 01:56 AM
1 | 1 | Brian Smith | # KVM PCI Passthrough and OPA |
---|---|---|---|
2 | |||
3 | A KVM guest can use OPA hardware when configured for PCI passthrough. |
||
4 | |||
5 | |||
6 | ## BIOS Settings |
||
7 | |||
8 | 1. Intel VT must be enabled. |
||
9 | 2. Integrated IO / Enable IntelVT must be enabled. |
||
10 | |||
11 | ## Kernel Command Line |
||
12 | |||
13 | ```intel_iommu=on iommu=pt``` |
||
14 | |||
15 | ## Install KVM |
||
16 | |||
17 | ``` |
||
18 | $ sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system virtinst libosinfo-bin virt-viewer virsh |
||
19 | $ sudo adduser YOU libvirt |
||
20 | $ sudo adduser YOU libvirt-qemu |
||
21 | $ sudo adduser YOU kvm |
||
22 | ``` |
||
23 | |||
24 | ## Disable hfi1 on host |
||
25 | |||
26 | The hfi1 driver must not be loaded on the host machine, in order to use PCI passthrough. In /etc/modprobe.d/hfi1.conf: |
||
27 | |||
28 | ``` |
||
29 | blacklist hfi1 |
||
30 | ``` |
||
31 | |||
32 | Also, there is no reason to have IFS installed on the host. The host machine should have no OPA functionality enabled. |
||
33 | |||
34 | ## Configure PCI Passthrough |
||
35 | |||
36 | The hfi1 device must be setup for PCI passthrough. Find the device's port in the output of lspci: |
||
37 | |||
38 | ``` |
||
39 | $ lspci | grep Omni | cut -f1 '-d ' |
||
40 | ``` |
||
41 | |||
42 | For the scripts below, prepend the port with 0000:, like "0000:80:02.0". |
||
43 | |||
44 | |||
45 | Use the following script, replace PCI_PORT with the port of the hfi1: |
||
46 | |||
47 | ``` |
||
48 | #!/bin/bash |
||
49 | |||
50 | PCI_PORT=0000:80:02.0 |
||
51 | DEV_VENDOR=8086 |
||
52 | DEV_MODEL=24f0 |
||
53 | |||
54 | rmmod vfio |
||
55 | rmmod vfio_pci |
||
56 | echo "$PCI_PORT" > /sys/bus/pci/devices/$PCI_PORT/driver/unbind |
||
57 | modprobe vfio |
||
58 | modprobe vfio_pci |
||
59 | echo $DEV_VENDOR $DEV_MODEL > /sys/bus/pci/drivers/vfio-pci/new_id |
||
60 | ``` |
||
61 | |||
62 | 2 | Brian Smith | ## Configure Default Network for DNS Forwarding |
63 | |||
64 | ``` |
||
65 | $ sudo virsh net-edit default |
||
66 | ``` |
||
67 | |||
68 | Add this tag: |
||
69 | |||
70 | ``` |
||
71 | <domain name='sfw.int' localOnly='no'/> |
||
72 | ``` |
||
73 | |||
74 | 1 | Brian Smith | ## Create Guest |
75 | |||
76 | While it is possible to manage guests for an unprivileged user, they get a non-functional network setup in the default config. TBD to to figure this out. Use virsh as root. |
||
77 | |||
78 | ``` |
||
79 | $ systemctl start libvirtd |
||
80 | $ virt-install --virt-type kvm --name gozer-deb8 \ |
||
81 | --vcpus=4 --virt-type kvm --cdrom $HOME/kvm-guest/debian-8.7.0-amd64-DVD-1.iso \ |
||
82 | -v --os-variant debian8 \ |
||
83 | --disk path=$HOME/kvm-guest/gozer-deb8-d1.disk,size=16 --memory 4096 --graphics vnc |
||
84 | ``` |
||
85 | |||
86 | Connect a VNC client to a tunneled connection to the host. |
||
87 | |||
88 | From the workstation: |
||
89 | |||
90 | ``` |
||
91 | $ ssh -L5910:host:5900 YOU@host |
||
92 | ``` |
||
93 | |||
94 | Now connect a VNC client to localhost:5910 and complete the install. |
||
95 | |||
96 | ## Import Existing Disk to New Guest |
||
97 | |||
98 | To import an existing guest disk image, use the following command: |
||
99 | |||
100 | ``` |
||
101 | 2 | Brian Smith | $ sudo virt-install --virt-type kvm --name gozer-deb8 \ |
102 | 1 | Brian Smith | --vcpus=4 --virt-type kvm --import \ |
103 | -v --os-variant debian8 \ |
||
104 | --disk PATH_TO_DISK_IMAGE,device=disk,bus=virtio --memory 4096 --graphics vnc |
||
105 | ``` |
||
106 | 2 | Brian Smith | |
107 | ## Connect to Guest, Configure DNS |
||
108 | |||
109 | TBD: figure out bridged network |
||
110 | |||
111 | The default network for KVM is 192.168.122.0/24 and the guest should be assigned a DHCP address when it boots. Use the VNC connection to execute ```$ ip addr``. ssh should be able to connect to the guest from the host. |
||
112 | |||
113 | Unfortunately, dnsmasq doesn't appear to set the search domain properly. For Debian, configure a search domain in the guest's ```/etc/network/interfaces```. |
||
114 | |||
115 | ``` |
||
116 | allow-hotplug eth0 |
||
117 | iface eth0 inet dhcp |
||
118 | dns-search sfw.int |
||
119 | ``` |
||
120 | |||
121 | 1 | Brian Smith | |
122 | ## Configure Guest for PCI Passthrough |
||
123 | |||
124 | Shutdown the guest if it is running. |
||
125 | |||
126 | ``` |
||
127 | $ virsh shutdown GUEST |
||
128 | ``` |
||
129 | |||
130 | Look for the PCI device in virsh. Look for a pci device that matches the port found via lspci. |
||
131 | |||
132 | ``` |
||
133 | $ virsh nodedev-list --tree |
||
134 | ``` |
||
135 | |||
136 | Detach the device. Use the child device of the one that matches the device you found via lspci. |
||
137 | |||
138 | ``` |
||
139 | $ virsh nodedev-detach pci_0000_81_00_0 |
||
140 | ``` |
||
141 | |||
142 | Dump the device info. |
||
143 | |||
144 | ``` |
||
145 | $ virsh nodedev-dumpxml pci_0000_81_00_0 |
||
146 | ``` |
||
147 | |||
148 | Convert bus, slot and function to hex. ```$ printf %x VALUE``` can be used for the hex-challenged. |
||
149 | |||
150 | Edit the guest and add a hostdev section: |
||
151 | |||
152 | ``` |
||
153 | <hostdev mode='subsystem' type='pci' managed='yes'> |
||
154 | <source> |
||
155 | <address domain='0x0000' bus='0x81' slot='0x0' function='0x0'/> |
||
156 | </source> |
||
157 | </hostdev> |
||
158 | ``` |
||
159 | |||
160 | Upon booting the guest, the passthrough device should be present in the guest's lspci output. |
||
161 | |||
162 | |||
163 | ## References |
||
164 | |||
165 | 1. https://wiki.debian.org/KVM |
||
166 | 2. https://jamielinux.com/docs/libvirt-networking-handbook/nat-based-network.html |
||
167 | 3. https://www.linux-kvm.org/page/How_to_assign_devices_with_VT-d_in_KVM |
||
168 | 4. https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF |
||
169 | 5. https://wiki.debian.org/VGAPassthrough |
||
170 | |||
171 | ---- |
||
172 | |||
173 | {{lastupdated_by}} {{lastupdated_at}} |
||
174 | |||
175 | {{comment_form}} |
||
176 | {{comments}} |