Skip to content

Commit

Permalink
Add GPU Passthrough role
Browse files Browse the repository at this point in the history
  • Loading branch information
technowhizz committed Apr 4, 2024
1 parent 8a81227 commit 79259ec
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
34 changes: 34 additions & 0 deletions roles/gpu_passthrough/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# stackhpc.linux.iommu

## Example playbook

```
---
- name: Enable GPU Passthrough
hosts: gpu_passthrough
tasks:
- import_role:
name: stackhpc.linux.gpu_passthrough
handlers:
- name: reboot
fail:
msg: "Please reboot your hypervisor and re-run your host configure to continue"
become: true
```

Or if you want the machine to reboot automatically:

```
---
- name: Enable GPU Passthrough
hosts: gpu_passthrough
tasks:
- import_role:
name: stackhpc.linux.gpu_passthrough
handlers:
- name: reboot
reboot:
become: true
```
1 change: 1 addition & 0 deletions roles/gpu_passthrough/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
8 changes: 8 additions & 0 deletions roles/gpu_passthrough/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions roles/gpu_passthrough/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- name: Blacklist nouveau
ansible.builtin.blockinfile:
path: /etc/modprobe.d/blacklist-nouveau.conf
block: |
blacklist nouveau
options nouveau modeset=0
mode: "0664"
owner: root
group: root
create: true
become: true
notify:
- Regenerate initramfs
- reboot # no-qa

- name: Ignore unsupported model specific registers
# Occasionally, applications running in the VM may crash unexpectedly,
# whereas they would run normally on a physical machine. If, while
# running dmesg -wH, you encounter an error mentioning MSR, the reason
# for those crashes is that KVM injects a General protection fault (GPF)
# when the guest tries to access unsupported Model-specific registers
# (MSRs) - this often results in guest applications/OS crashing. A
# number of those issues can be solved by passing the ignore_msrs=1
# option to the KVM module, which will ignore unimplemented MSRs.
# source: https://wiki.archlinux.org/index.php/QEMU
ansible.builtin.blockinfile:
path: /etc/modprobe.d/kvm.conf
block: |
options kvm ignore_msrs=Y
# This option is not available in centos 7 as the kernel is too old,
# but it can help with dmesg spam in newer kernels (centos8?). Sample
# dmesg log message:
# [ +0.000002] kvm [8348]: vcpu0, guest rIP: 0xffffffffb0a767fa ignored rdmsr: 0x619
# options kvm report_ignored_msrs=N
mode: "0664"
owner: root
group: root
create: true
become: true
notify: reboot # no-qa

- name: Add IOMMU config to kernel command line
ansible.builtin.include_role:
name: stackhpc.linux.iommu

0 comments on commit 79259ec

Please sign in to comment.