-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GPU Passthrough role #28
Open
technowhizz
wants to merge
10
commits into
main
Choose a base branch
from
gpu-passthrough
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1fabb79
Change conditional to search for 'Intel'
technowhizz 20708e9
Add support for specfying vfio id's
technowhizz 08d611f
Add GPU Passthrough role
technowhizz bdcc85a
Set vfio pci ids for AMD cards
jovial ed1e207
Add debian handler
jovial 0a5dc50
Update handlers for Ubuntu support
jovial 33ec084
Only configure dracut on RedHat
jovial c776773
Merge branch 'main' into gpu-passthrough
jovial b11018f
whitespace fix
jovial 555da33
Apply suggestions from code review
jovial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
- name: Regenerate initramfs (RedHat) | ||
listen: Regenerate initramfs | ||
ansible.builtin.shell: |- | ||
#!/bin/bash | ||
set -eux | ||
dracut -v -f /boot/initramfs-$(uname -r).img $(uname -r) | ||
become: true | ||
changed_when: true | ||
when: ansible_facts.os_family == 'RedHat' | ||
|
||
- name: Regenerate initramfs (Debian) | ||
listen: Regenerate initramfs | ||
ansible.builtin.shell: |- | ||
#!/bin/bash | ||
set -eux | ||
update-initramfs -u -k $(uname -r) | ||
become: true | ||
changed_when: true | ||
when: ansible_facts.os_family == 'Debian' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe should uncomment by default |
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
- name: Regenerate initramfs (RedHat) | ||
listen: Regenerate initramfs | ||
ansible.builtin.shell: |- | ||
#!/bin/bash | ||
set -eux | ||
dracut -v -f /boot/initramfs-$(uname -r).img $(uname -r) | ||
become: true | ||
changed_when: true | ||
when: ansible_facts.os_family == 'RedHat' | ||
|
||
- name: Regenerate initramfs (Debian) | ||
listen: Regenerate initramfs | ||
ansible.builtin.shell: |- | ||
#!/bin/bash | ||
set -eux | ||
update-initramfs -u -k $(uname -r) | ||
become: true | ||
changed_when: true | ||
when: ansible_facts.os_family == 'Debian' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,55 @@ | ||
--- | ||
- 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw warnings about this configuration:
Please fix the syntax. |
||
owner: root | ||
group: root | ||
mode: "0660" | ||
create: true | ||
become: true | ||
when: | ||
- iommu_vfio_pci_ids is defined | ||
- ansible_facts.os_family == 'Debian' | ||
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'] }}" # noqa: var-naming[no-role-prefix] | ||
kernel_cmdline_remove: # noqa: var-naming[no-role-prefix] | ||
- ^intel_iommu= | ||
when: ansible_facts.processor | select('search','Intel') | ||
|
||
- name: Add vfio pci ids to kernel command line | ||
ansible.builtin.include_role: | ||
name: stackhpc.linux.grubcmdline | ||
vars: | ||
kernel_cmdline: "{{ ['vfio-pci.ids=' + iommu_vfio_pci_ids] }}" # noqa: var-naming[no-role-prefix] | ||
kernel_cmdline_remove: # noqa: var-naming[no-role-prefix] | ||
- ^vfio-pci\.ids= | ||
when: iommu_vfio_pci_ids is defined | ||
|
||
jovial marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- name: Set iommu=pt | ||
ansible.builtin.include_role: | ||
name: stackhpc.linux.grubcmdline | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed to run after the reboot handler