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 92edcff
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
10 changes: 4 additions & 6 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 All @@ -13,10 +17,4 @@
tasks:
- import_role:
name: stackhpc.linux.iommu
handlers:
- name: reboot
fail:
msg: "Please reboot your hypervisor and re-run your host configure to continue"
become: true
```
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
37 changes: 35 additions & 2 deletions roles/iommu/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
---
- 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)

Check failure on line 33 in roles/iommu/tasks/main.yml

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

syntax-check[specific]

'notify' is not a valid attribute for a IncludeRole
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
notify: reboot

- name: Set iommu=pt
ansible.builtin.include_role:
Expand All @@ -18,3 +50,4 @@
kernel_cmdline_remove: # noqa: var-naming[no-role-prefix]
- ^iommu=
when: iommu_pt
notify: reboot

0 comments on commit 92edcff

Please sign in to comment.