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