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 46547f7
Show file tree
Hide file tree
Showing 3 changed files with 48 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
11 changes: 11 additions & 0 deletions roles/iommu/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Regenerate initramfs

Check failure on line 2 in roles/iommu/handlers/main.yml

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

fqcn[action-core]

Use FQCN for builtin module actions (shell).

Check failure on line 2 in roles/iommu/handlers/main.yml

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

no-changed-when

Commands should not change things if nothing needs doing.
shell: |-
#!/bin/bash
set -eux
dracut -v -f /boot/initramfs-$(uname -r).img $(uname -r)
become: true
- name: reboot

Check failure on line 8 in roles/iommu/handlers/main.yml

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

fqcn[action-core]

Use FQCN for builtin module actions (reboot).

Check failure on line 8 in roles/iommu/handlers/main.yml

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

name[casing]

All names should start with an uppercase letter.
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

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

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

fqcn[action-core]

Use FQCN for builtin module actions (blockinfile).
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

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

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

yaml[octal-values]

Forbidden implicit octal value "0660"
create: true
become: true
when: iommu_vfio_pci_ids is defined
notify:
- Regenerate initramfs
- reboot

- name: Add vfio to modules-load.d

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

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

fqcn[action-core]

Use FQCN for builtin module actions (blockinfile).
blockinfile:
path: /etc/modules-load.d/vfio.conf
block: |
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
owner: root
group: root
mode: 0664

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

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

yaml[octal-values]

Forbidden implicit octal value "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 46547f7

Please sign in to comment.