Skip to content

Commit

Permalink
Add support for specfying vfio id's
Browse files Browse the repository at this point in the history
  • Loading branch information
technowhizz committed Mar 27, 2024
1 parent 960abbe commit 5d6e3d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 4 additions & 0 deletions roles/iommu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- `iommu_pt`: Default true, Configure passthrough mode, which doesn't require DMA translation.

## Host Vars

- `iommu_vfio_pci_ids`: Can optionally be set with the pci id of the device to pass-through.

## Example playbook

```
Expand Down
12 changes: 12 additions & 0 deletions roles/iommu/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Regenerate initramfs
ansible.builtin.shell: |-
#!/bin/bash
set -eux
dracut -v -f /boot/initramfs-$(uname -r).img $(uname -r)
become: true
changed_when: true
- name: Reboot
ansible.builtin.reboot:
msg: "Rebooting the hypervisor"
become: true
35 changes: 33 additions & 2 deletions roles/iommu/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
---
- name: Template dracut config for vfio
ansible.builtin.blockinfile:
path: /etc/dracut.conf.d/gpu-vfio.conf
block: |
add_drivers+="vfio vfio_iommu_type1 vfio_pci vfio_virqfd"
owner: root
group: root
mode: "0660"
create: true
become: true
when: iommu_vfio_pci_ids is defined
notify:
- Regenerate initramfs
- reboot

- name: Add vfio to modules-load.d
ansible.builtin.blockinfile:
path: /etc/modules-load.d/vfio.conf
block: |
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
owner: root
group: root
mode: "0664"
create: true
become: true
when: iommu_vfio_pci_ids is defined
notify: reboot

- name: Add iommu to kernel command line (Intel)
ansible.builtin.include_role:
name: stackhpc.linux.grubcmdline
vars:
kernel_cmdline: # noqa: var-naming[no-role-prefix]
- intel_iommu=on
kernel_cmdline: "{{ ['intel_iommu=on'] + (['vfio-pci.ids=' + iommu_vfio_pci_ids] if iommu_vfio_pci_ids is defined else []) }}" # noqa: var-naming[no-role-prefix]
kernel_cmdline_remove: # noqa: var-naming[no-role-prefix]
- ^intel_iommu=
- ^vfio-pci\.ids=
when: ansible_facts.processor | select('search', 'Intel') | list | length > 0

- name: Set iommu=pt
Expand Down

0 comments on commit 5d6e3d9

Please sign in to comment.