From 1fabb79515172d32b25fdcfdd36b7f1a15761f26 Mon Sep 17 00:00:00 2001 From: technowhizz <7688823+technowhizz@users.noreply.github.com> Date: Wed, 27 Mar 2024 12:50:27 +0000 Subject: [PATCH 1/2] Change conditional to search for 'Intel' Changes the conditional to search for 'Intel' in the ansible_facts.processor variable as the first item in the list is not always consistent. --- roles/iommu/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/iommu/tasks/main.yml b/roles/iommu/tasks/main.yml index 4ca9872..075a964 100644 --- a/roles/iommu/tasks/main.yml +++ b/roles/iommu/tasks/main.yml @@ -7,7 +7,7 @@ - intel_iommu=on kernel_cmdline_remove: # noqa: var-naming[no-role-prefix] - ^intel_iommu= - when: "'Intel' in ansible_facts.processor.0" + when: ansible_facts.processor | select('search', 'Intel') | list | length > 0 - name: Set iommu=pt ansible.builtin.include_role: From 20708e906159bc837940f59f830d6f8d0d09b8d0 Mon Sep 17 00:00:00 2001 From: technowhizz <7688823+technowhizz@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:37:08 +0000 Subject: [PATCH 2/2] Add support for specfying vfio id's --- roles/iommu/README.md | 16 ++++++++++++++++ roles/iommu/handlers/main.yml | 8 ++++++++ roles/iommu/tasks/main.yml | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 roles/iommu/handlers/main.yml diff --git a/roles/iommu/README.md b/roles/iommu/README.md index cb9882b..8efce83 100644 --- a/roles/iommu/README.md +++ b/roles/iommu/README.md @@ -20,3 +20,19 @@ become: true ``` + +Or if you want the node to reboot automatically + +``` +--- +- name: Enable IOMMU + hosts: iommu + tasks: + - import_role: + name: stackhpc.linux.iommu + handlers: + - name: reboot + reboot: + become: true + +``` diff --git a/roles/iommu/handlers/main.yml b/roles/iommu/handlers/main.yml new file mode 100644 index 0000000..ce03b6e --- /dev/null +++ b/roles/iommu/handlers/main.yml @@ -0,0 +1,8 @@ +--- +- 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 diff --git a/roles/iommu/tasks/main.yml b/roles/iommu/tasks/main.yml index 075a964..23f4c75 100644 --- a/roles/iommu/tasks/main.yml +++ b/roles/iommu/tasks/main.yml @@ -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