|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * virt/virtual_machines/advanced_vm_management/virt-configuring-pci-passthrough.adoc |
| 4 | + |
| 5 | +[id="virt-binding-devices-vfio-driver_{context}"] |
| 6 | += Binding PCI devices to the VFIO driver |
| 7 | +To bind PCI devices to the VFIO (Virtual Function I/O) driver, obtain the values for `vendor-ID` and `device-ID` from each device and create a list with the values. Add this list to the `MachineConfig` object. The `MachineConfig` Operator generates the `/etc/modprobe.d/vfio.conf` on the nodes with the PCI devices, and binds the PCI devices to the VFIO driver. |
| 8 | + |
| 9 | +.Prerequisites |
| 10 | +* You added kernel arguments to enable IOMMU for the CPU. |
| 11 | + |
| 12 | +.Procedure |
| 13 | +. Create the `MachineConfig` object to enable the binding of PCI devices to the VFIO driver. |
| 14 | ++ |
| 15 | +.Example |
| 16 | +[source,yaml] |
| 17 | +---- |
| 18 | +apiVersion: machineconfiguration.openshift.io/v1 |
| 19 | +kind: MachineConfig <1> |
| 20 | +metadata: |
| 21 | + labels: |
| 22 | + machineconfiguration.openshift.io/role: worker <2> |
| 23 | + name: 100-worker-vfiopci-configuration <3> |
| 24 | +spec: |
| 25 | + config: |
| 26 | + ignition: |
| 27 | + version: 3.2.0 |
| 28 | + storage: |
| 29 | + files: |
| 30 | + - contents: |
| 31 | + source: data:text/plain;charset=utf-8;base64,b3B0aW9ucyB2ZmlvLXBjaSBpZHM9MTBkZToxZWI4Cg== <4> |
| 32 | + mode: 420 <5> |
| 33 | + overwrite: true |
| 34 | + path: /etc/modprobe.d/vfio.conf <6> |
| 35 | + - contents: |
| 36 | + source: data:text/plain;charset=utf-8;base64,dmZpby1wY2kK <7> |
| 37 | + mode: 420 |
| 38 | + overwrite: true |
| 39 | + path: /etc/modules-load.d/vfio-pci.conf <8> |
| 40 | +---- |
| 41 | +<1> The type of object being configured is `MachineConfig`. |
| 42 | +<2> Applies the new kernel argument only to worker nodes. |
| 43 | +<3> Named to identify where this `MachineConfig` object fits among the other `MachineConfig` objects. |
| 44 | +<4> The `echo "options vfio-pci ids=10de:1eb8" | base64` command creates the encoded text. The `vendor-ID` value (10de) and the `device-ID` value (1eb8) applies to a single device that binds to the VFIO driver. You can add a list of multiple devices for `source` with their vendor and device information. |
| 45 | +<5> The values specified for `mode` determine the permissions for the file. |
| 46 | +<6> The `/etc/modprobe.d/vfio.conf` was created by the `echo "options vfio-pci ids=10de:1eb8 > /etc/modprobe.d/vfio/conf"` command. |
| 47 | +<7> The `echo "dmZpby1wY2kK" | base64 -d` command and the `vfio-pci` commands create the encoded text for `source` as `dmZpby1wY2kK`. The encoded text translates to `vfio-pci`. |
| 48 | +<8> The file that loads the vfio-pci kernel module on the worker nodes. |
| 49 | + |
| 50 | +. Create a `MachineConfig` object that identifies the kernel argument for the IOMMU configuration: |
| 51 | ++ |
| 52 | +[source,terminal] |
| 53 | +---- |
| 54 | +$ oc create -f 100-worker-kernel-arg-iommu.yaml |
| 55 | +---- |
| 56 | + |
| 57 | +. Verify that the `MachineConfig` object was added. |
| 58 | ++ |
| 59 | +[source,terminal] |
| 60 | +---- |
| 61 | +$ oc get MachineConfig |
| 62 | +---- |
| 63 | ++ |
| 64 | +.Example output |
| 65 | +[source, terminal] |
| 66 | +---- |
| 67 | +NAME GENERATEDBYCONTROLLER IGNITIONVERSION AGE |
| 68 | +00-master d3da910bfa9f4b599af4ed7f5ac270d55950a3a1 3.2.0 25h |
| 69 | +00-worker d3da910bfa9f4b599af4ed7f5ac270d55950a3a1 3.2.0 25h |
| 70 | +01-master-container-runtime d3da910bfa9f4b599af4ed7f5ac270d55950a3a1 3.2.0 25h |
| 71 | +01-master-kubelet d3da910bfa9f4b599af4ed7f5ac270d55950a3a1 3.2.0 25h |
| 72 | +01-worker-container-runtime d3da910bfa9f4b599af4ed7f5ac270d55950a3a1 3.2.0 25h |
| 73 | +01-worker-kubelet d3da910bfa9f4b599af4ed7f5ac270d55950a3a1 3.2.0 25h |
| 74 | +100-worker-iommu 3.2.0 30s |
| 75 | +100-worker-vfiopci-configuration 3.2.0 30s |
| 76 | +---- |
| 77 | + |
| 78 | +. Run the `lspci` command to obtain the `vendor-ID` and the `device-ID` for the PCI device. |
| 79 | ++ |
| 80 | +[source, terminal] |
| 81 | +---- |
| 82 | +$ lspci -nnv | grep -i nvidia |
| 83 | +---- |
| 84 | ++ |
| 85 | +.Example output |
| 86 | +[source, terminal] |
| 87 | +---- |
| 88 | +02:01.0 3D controller [0302]: NVIDIA Corporation GV100GL [Tesla V100 PCIe 32GB] [10de:1eb8] (rev a1) |
| 89 | +---- |
| 90 | + |
| 91 | +. Specify the values for `vendor-ID` and `device-ID` and convert the `/etc/modprobe.d/vfio.conf` file to base64 format: |
| 92 | ++ |
| 93 | +[source,terminal] |
| 94 | +---- |
| 95 | +$ echo "options vfio-pci ids=10de:1eb8" | base64 |
| 96 | +---- |
| 97 | +These values are converted into the `base64 format` and the output is encoded. |
| 98 | ++ |
| 99 | +.Example output |
| 100 | +[source,terminal] |
| 101 | +---- |
| 102 | +b3B0aW9ucyB2ZmlvLXBjaSBpZHM9MTBkZToxZWI4Cg== |
| 103 | +---- |
| 104 | + |
| 105 | +. Add the encoded text to `source` in the `MachineConfig` object. |
| 106 | + |
| 107 | +. Convert `vfio-pci` into base64 format and encode the text: |
| 108 | ++ |
| 109 | +[source,terminal] |
| 110 | +---- |
| 111 | +$ echo vfio-pci | base64 |
| 112 | +---- |
| 113 | +These values are converted into the `base64 format` and the output is encoded. |
| 114 | ++ |
| 115 | +.Example output |
| 116 | +[source,terminal] |
| 117 | +---- |
| 118 | +dmZpby1wY2kK |
| 119 | +---- |
| 120 | + |
| 121 | +. Add the encoded text to `source` in the `MachineConfig` object. |
| 122 | + |
| 123 | +.Verification |
| 124 | +* Verify that the VFIO driver is loaded. |
| 125 | ++ |
| 126 | +[source,terminal] |
| 127 | +---- |
| 128 | +$ lspci -nnk -d 10de: |
| 129 | +---- |
| 130 | +The output confirms that the VFIO driver is being used. |
| 131 | ++ |
| 132 | +.Example output |
| 133 | +---- |
| 134 | +04:00.0 3D controller [0302]: NVIDIA Corporation GP102GL [Tesla P40] [10de:1eb8] (rev a1) |
| 135 | + Subsystem: NVIDIA Corporation Device [10de:1eb8] |
| 136 | + Kernel driver in use: vfio-pci |
| 137 | + Kernel modules: nouveau |
| 138 | +---- |
0 commit comments