Giter VIP home page Giter VIP logo

linux-acs-override's Introduction

ACS Override Patch

A common use case in virtualization is the need to passthrough a PCI or VGA device to a guest VM. However, because all devices within a single IOMMU group must be passed through at once, it can pose challenges to passthrough if there are multiple devices in the same IOMMU group.

To address the issue, Alex Williamson created a kernel patch that allows each device to be placed into its own IOMMU group, easing passthrough:

https://lkml.org/lkml/2013/5/30/513

This repository provides patch files for various kernel versions from 4.10 and updates when a new kernel release breaks patch compatibility.

Note: The ACS override patch is typically considered a 'last resort' for PCIe passthrough if other methods don't work. It's not meant for production systems (and neither are custom kernels), but may be useful for dev environments or homelabs.

References and ACS Override Alternatives:

https://heiko-sieger.info/iommu-groups-what-you-need-to-consider/ https://forum.level1techs.com/t/the-pragmatic-neckbeard-3-vfio-iommu-and-pcie/111251 https://bugzilla.redhat.com/show_bug.cgi?id=1113399 https://bugzilla.redhat.com/attachment.cgi?id=913028&action=diff

Installation

Confirm Current IOMMU Groups

Run the iommu-groups.sh helper script to view the current IOMMU groups:

# ./iommu-groups.sh
...
IOMMU Group 2:
	00:08.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge [1022:1632]
	00:08.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus [1022:1635]
	00:08.2 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus [1022:1635]
	05:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Renoir [1002:1636] (rev d8)
	05:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Device [1002:1637]
	05:00.2 Encryption controller [1080]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 10h-1fh) Platform Security Processor [1022:15df]
	05:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Renoir USB 3.1 [1022:1639]
	05:00.4 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Renoir USB 3.1 [1022:1639]
	05:00.6 Audio device [0403]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 10h-1fh) HD Audio Controller [1022:15e3]
	06:00.0 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] [1022:7901] (rev 81)
...

In the above example, two USB controllers and two PCI bridges are in the same group.

Build the Kernel Source

In this example we'll build the Kernel into the Debian .deb file format for installation.

# ./build-debian.sh

Install the Kernel

# ls *.deb
linux-headers-6.3.0-acso_6.3.0-1_amd64.deb  linux-image-6.3.0-acso-dbg_6.3.0-1_amd64.deb
linux-image-6.3.0-acso_6.3.0-1_amd64.deb    linux-libc-dev_6.3.0-1_amd64.deb
# dpkg -i *.deb
# reboot

Boot System Using the New Custom Kernel

# vi /etc/default/grub

Add pcie_acs_override=downstream,multifunction to the GRUB_CMDLINE_LINUX_DEFAULT entry like so:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash pcie_acs_override=downstream,multifunction"

Update GRUB

# update-grub
# reboot

Confirm the grub config updates are applied:

# cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-6.3.0-acso root=UUID=0706649e-a7c1-4631-973f-cd650f863f00 ro quiet splash systemd.unified_cgroup_hierarchy=0 amd-pstate=active pcie_acs_override=downstream,multifunction vt.handoff=7

Confirm Devices Separated

Run the iommu-groups.sh script again to confirm devices are now separated as expected:

# ./iommu-groups.sh
IOMMU Group 0:
	00:01.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge [1022:1632]
IOMMU Group 1:
	00:01.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe GPP Bridge [1022:1633]
IOMMU Group 2:
	00:02.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge [1022:1632]
IOMMU Group 3:
	00:02.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe GPP Bridge [1022:1634]
IOMMU Group 4:
	00:02.3 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe GPP Bridge [1022:1634]
IOMMU Group 5:
	00:02.4 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe GPP Bridge [1022:1634]
IOMMU Group 6:
	00:08.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge [1022:1632]
IOMMU Group 7:
	00:08.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus [1022:1635]
IOMMU Group 8:
	00:08.2 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus [1022:1635]
IOMMU Group 9:
	00:14.0 SMBus [0c05]: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller [1022:790b] (rev 51)
	00:14.3 ISA bridge [0601]: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge [1022:790e] (rev 51)
IOMMU Group 10:
	00:18.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 0 [1022:1448]
	00:18.1 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 1 [1022:1449]
	00:18.2 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 2 [1022:144a]
	00:18.3 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 3 [1022:144b]
	00:18.4 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 4 [1022:144c]
	00:18.5 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 5 [1022:144d]
	00:18.6 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 6 [1022:144e]
	00:18.7 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Renoir Device 24: Function 7 [1022:144f]
IOMMU Group 11:
	01:00.0 Non-Volatile memory controller [0108]: Samsung Electronics Co Ltd NVMe SSD Controller SM981/PM981/PM983 [144d:a808]
IOMMU Group 12:
	02:00.0 Non-Volatile memory controller [0108]: Samsung Electronics Co Ltd NVMe SSD Controller SM981/PM981/PM983 [144d:a808]
IOMMU Group 13:
	03:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [10ec:8168] (rev 15)
IOMMU Group 14:
	04:00.0 Network controller [0280]: Intel Corporation Wi-Fi 6 AX200 [8086:2723] (rev 1a)
IOMMU Group 15:
	05:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Renoir [1002:1636] (rev d8)
IOMMU Group 16:
	05:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Device [1002:1637]
IOMMU Group 17:
	05:00.2 Encryption controller [1080]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 10h-1fh) Platform Security Processor [1022:15df]
IOMMU Group 18:
	05:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Renoir USB 3.1 [1022:1639]
IOMMU Group 19:
	05:00.4 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Renoir USB 3.1 [1022:1639]
IOMMU Group 20:
	05:00.6 Audio device [0403]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 10h-1fh) HD Audio Controller [1022:15e3]
IOMMU Group 21:
	06:00.0 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] [1022:7901] (rev 81)

PCI passthrough

Now the patch has been applied to the kernel and the USB controller, for example, is in its own group we can pass it through to the virtual machine.

IOMMU Group 18:
	05:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Renoir USB 3.1 [1022:1639]
# vi /etc/modprobe.d/vfio.conf
install xhci-pci echo vfio-pci >/sys/bus/pci/devices/0000:05:00.3/driver_override; echo 0000:05:00.3 >/sys/bus/pci/drivers/vfio-pci/bind; modprobe -i xhci-pci
# update-initramfs -u
# reboot

Links

linux-acs-override's People

Contributors

benbaker76 avatar flotwig avatar labrat97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

linux-acs-override's Issues

dpkg-deb: building package doesn't finish

Hi @benbaker76, thank you for the suggestion at #4 (comment)

I can run commands in build-debian.sh file

sudo make olddefconfig -j $(nproc) bindeb-pkg LOCALVERSION=-acso KDEB_PKGVERSION=$(make kernelversion)-1

it runs but it stuck at dpkg-deb: building package for a long time

Screenshot 2023-12-11 at 21 50 36
  SIGN    debian/linux-image/lib/modules/6.3.0-acso/kernel/net/qrtr/qrtr-tun.ko
  SIGN    debian/linux-image/lib/modules/6.3.0-acso/kernel/net/qrtr/qrtr-mhi.ko
  SIGN    debian/linux-image/lib/modules/6.3.0-acso/kernel/virt/lib/irqbypass.ko
  DEPMOD  debian/linux-image/lib/modules/6.3.0-acso
dpkg-deb: building package 'linux-image-6.3.0-acso' in '../linux-image-6.3.0-acso_6.3.0-1_amd64.deb'.
dpkg-deb: building package 'linux-libc-dev' in '../linux-libc-dev_6.3.0-1_amd64.deb'.
dpkg-deb: building package 'linux-headers-6.3.0-acso' in '../linux-headers-6.3.0-acso_6.3.0-1_amd64.deb'.
dpkg-deb: building package 'linux-image-6.3.0-acso-dbg' in '../linux-image-6.3.0-acso-dbg_6.3.0-1_amd64.deb'.

Then I open another window to see file list:

image

Then I can not install *.deb files and get the error:

# dpkg -i *.deb
(Reading database ... 228471 files and directories currently installed.)
Preparing to unpack linux-headers-6.3.0-acso_6.3.0-1_amd64.deb ...
Unpacking linux-headers-6.3.0-acso (6.3.0-1) over (6.3.0-1) ...
Preparing to unpack linux-image-6.3.0-acso-dbg_6.3.0-1_amd64.deb ...
Unpacking linux-image-6.3.0-acso-dbg (6.3.0-1) ...
dpkg-deb: error: unexpected end of file in archive member header in linux-image-6.3.0-acso-dbg_6.3.0-1_amd64.deb
dpkg: error processing archive linux-image-6.3.0-acso-dbg_6.3.0-1_amd64.deb (--install):
 dpkg-deb --fsys-tarfile subprocess returned error exit status 2
Preparing to unpack linux-image-6.3.0-acso_6.3.0-1_amd64.deb ...
Unpacking linux-image-6.3.0-acso (6.3.0-1) over (6.3.0-1) ...
Preparing to unpack linux-libc-dev_6.3.0-1_amd64.deb ...
Unpacking linux-libc-dev:amd64 (6.3.0-1) over (6.3.0-1) ...
Setting up linux-headers-6.3.0-acso (6.3.0-1) ...
Setting up linux-image-6.3.0-acso (6.3.0-1) ...
 * dkms: running auto installation service for kernel 6.3.0-acso                            [ OK ] 
update-initramfs: Generating /boot/initrd.img-6.3.0-acso
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/40-force-partuuid.cfg'
Sourcing file `/etc/default/grub.d/50-cloudimg-settings.cfg'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
GRUB_FORCE_PARTUUID is set, will attempt initrdless boot
Found linux image: /boot/vmlinuz-6.3.0-060300-generic
Found initrd image: /boot/initrd.img-6.3.0-060300-generic
Found linux image: /boot/vmlinuz-6.3.0-acso
Found initrd image: /boot/initrd.img-6.3.0-acso
....
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Adding boot menu entry for UEFI Firmware Settings ...
done
Setting up linux-libc-dev:amd64 (6.3.0-1) ...
Errors were encountered while processing:
 linux-image-6.3.0-acso-dbg_6.3.0-1_amd64.deb

my ubuntu info:

# uname -a
Linux kvm1 6.3.0-060300-generic #202304232030 SMP PREEMPT_DYNAMIC Sun Apr 23 20:37:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

# lsb_release -a
LSB Version:	core-11.1.0ubuntu4-noarch:security-11.1.0ubuntu4-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.3 LTS
Release:	22.04
Codename:	jammy

I don't know what to do next

4.18 Kernel Patch failed

[root@MiWiFi-RB04-srv linux-4.18.0-305.3.1.el8_4]# patch -p1 < ../acso.patch
patching file Documentation/admin-guide/kernel-parameters.txt
Hunk #1 succeeded at 3460 (offset 432 lines).
patching file drivers/pci/quirks.c
Hunk #1 succeeded at 3551 (offset 196 lines).
Hunk #2 FAILED at 4495.
1 out of 2 hunks FAILED -- saving rejects to file drivers/pci/quirks.c.rej
[root@MiWiFi-RB04-srv linux-4.18.0-305.3.1.el8_4]#

构建错误

image

make[6]: *** [Makefile:2032:.] 错误 2
make[5]: *** [Makefile:359:__build_one_by_one] 错误 2
make[4]: *** [debian/rules:10:build-arch] 错误 2
dpkg-buildpackage: 错误: debian/rules binary subprocess returned exit status 2
make[3]: *** [scripts/Makefile.package:139:bindeb-pkg] 错误 2
make[2]: *** [Makefile:1659:bindeb-pkg] 错误 2
make[1]: *** [/opt/git/linux-6.5/Makefile:359:__build_one_by_one] 错误 2
make: *** [Makefile:234:__sub-make] 错误 2

I have installed dwarves and also deleted 'debian/certs/debian-uefi-certs.pem' but this error persists
Tried kernel builds for 6.3 and 6.5 both failed

`dpkg-buildpackage` fails when building kernel packages

When running build-debian.sh, I get this error at the end of kernel compilation:

make[4]: *** [Makefile:357: __build_one_by_one] Error 2
make[3]: *** [debian/rules:8: build-arch] Error 2
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
make[2]: *** [scripts/Makefile.package:114: bindeb-pkg] Error 2
make[1]: *** [Makefile:1656: bindeb-pkg] Error 2
make: *** [Makefile:357: __build_one_by_one] Error 2

How does one fix this issue?

facing issues on build

I'm running ubuntu 22.04 and currently on 5.15.0

I've cloned the repo and run ./build_debian.sh

I left defaults for 6.3 and it failed.

Attempted the fix of removing the certificate and building again with failure at:

LD [M] fs/btrfs/btrfs.o
make[5]: *** [Makefile:2025: .] Error 2
make[4]: *** [Makefile:357: __build_one_by_one] Error 2
make[3]: *** [debian/rules:8: build-arch] Error 2
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
make[2]: *** [scripts/Makefile.package:114: bindeb-pkg] Error 2
make[1]: *** [Makefile:1656: bindeb-pkg] Error 2
make: *** [Makefile:357: __build_one_by_one] Error 2

Attempted build of 6.5 and got an error at:

LD [M] fs/ocfs2/ocfs2.o
make[6]: *** [Makefile:2032: .] Error 2
make[5]: *** [Makefile:359: __build_one_by_one] Error 2
make[4]: *** [debian/rules:10: build-arch] Error 2
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
make[3]: *** [scripts/Makefile.package:139: bindeb-pkg] Error 2
make[2]: *** [Makefile:1659: bindeb-pkg] Error 2
make[1]: *** [/root/linux-acs-override/linux-6.5/Makefile:359: __build_one_by_one] Error 2
make: *** [Makefile:234: __sub-make] Error 2

Newer kernels break `dpkg-buildpackage`

If you are running a newer kernel than the one you are trying to patch, you will get:

dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2

Please use make oldconfig

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.