Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download, patch, compile and install the newest stable Linux kernel with the ACS override patch (Ubuntu / Debian)
#!/bin/bash
function install_dependencies() {
echo "Installing dependencies..."
sudo apt -qq update
sudo apt -qq install -y curl git wget
sudo apt -qq install -y bison flex kernel-package libelf-dev libssl-dev
}
function init() {
echo "Initializing..."
kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)
grub_config="/etc/default/grub"
current_dir=$(pwd)
working_dir=$(mktemp -d)
cd "${working_dir}" || exit
install_dependencies
}
function get_newest_versions() {
echo "Retrieving newest version information..."
stable_releases_3x_url="https://mirrors.edge.kernel.org/pub/linux/kernel/v3.x/"
stable_releases_4x_url="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
stable_releases_5x_url="https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/"
stable_releases_3x_html=$(curl -s "${stable_releases_3x_url}")
stable_releases_4x_html=$(curl -s "${stable_releases_4x_url}")
stable_releases_5x_html=$(curl -s "${stable_releases_5x_url}")
stable_releases_combined_html="${stable_releases_3x_html}${stable_releases_4x_html}${stable_releases_5x_html}"
stable_version=$(echo "${stable_releases_combined_html}" | grep -E -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vru | head -n 1 | cut -d '-' -f 2)
mainline_link=$(curl -s https://www.kernel.org/ | grep https://git.kernel.org/torvalds/t/linux- | grep -Po '(?<=href=")[^"]*')
if ! [ -z "${mainline_link}" ]
then
mainline_version=$(echo "${mainline_link}" | cut -d '-' -f 2,3 | cut -d '.' -f 1,2)
else
mainline_version="unavailable"
fi
repo_pkg=$(apt search 'linux-source-' | grep 'linux-source' | cut -d '/' -f 1 | awk -F- 'NF<=3' | sort -Vr | head -n 1)
#repo_version=$(echo "${repo_pkg}" | cut -d '-' -f 3)
repo_version=$(apt search 'linux-source-' | grep 'linux-source' | sort -Vr | head -n 1 | cut -d ' ' -f 2)
}
function stable_or_mainline_or_repo() {
get_newest_versions
echo "Newest stable version is: ${stable_version}"
echo "Mainline version is: ${mainline_version}"
echo "Repository version is: ${repo_version}"
echo -n "Do you want to get a [s]table, the newest [m]ainline release candidate or the newest kernel from your [r]epositories? [S/m/r] "
read -r s_or_m_or_r
echo -n "Do you want to apply the acs override patch? Kernels below 4.10 are not supported. [Y/n] "
read -r acso
echo -n "Do you want to apply the experimental AMD AGESA patch to fix VFIO setups on AGESA 0.0.7.2 and newer? [y/N] "
read -r agesa
echo -n "Do you want to apply the experimental AMD Vega PCI reset patch? [y/N] "
read -r vega
echo -n "Do you want to install the kernel and its headers after compilation? [Y/n] "
read -r install
if [ -z "${install}" ] || [ "${install}" == "y" ]
then
echo -n "Do you want to make this kernel the new default? [Y/n] "
read -r default
fi
if [ -z "${s_or_m_or_r}" ] || [ "${s_or_m_or_r}" == "s" ]
then
stable_preparations
else
if [ "${s_or_m_or_r}" == "m" ]
then
if [ "${mainline_version}" == "unavailable" ]
then
echo "Mainline version currently unavailable. Exiting."
exit
else
mainline_preparations
fi
else
if [ "${s_or_m_or_r}" == "r" ]
then
repo_preparations
else
echo "Not a valid option. Exiting."
exit
fi
fi
fi
}
function try_acso_patch() {
acso_patch_5_4="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/5.4/acso.patch"
acso_patch_4_18="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.18/acso.patch"
acso_patch_4_17="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.17/acso.patch"
acso_patch_4_14="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.14/acso.patch"
acso_patch_4_10="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/4.10/acso.patch"
acso_patch_4_18_ubuntu="https://gist.github.com/mdPlusPlus/bb3df6248ffc7c6b3772ae0901659966/raw/acso_4_18_ubuntu.patch"
echo "Trying to apply acs override patch for 5.4+."
wget -O ../acso_5_4.patch "${acso_patch_5_4}"
if $(git apply --check ../acso_5_4.patch)
then
echo "Applying acs override patch for 5.4+."
git apply ../acso_5_4.patch
else
echo "Trying to apply acs override patch for 4.18+."
wget -O ../acso_4_18.patch "${acso_patch_4_18}"
if $(git apply --check ../acso_4_18.patch)
then
echo "Applying acs override patch for 4.18+."
git apply ../acso_4_18.patch
else
echo "Trying to apply acs override patch for 4.17+."
wget -O ../acso_4_17.patch "${acso_patch_4_17}"
if $(git apply --check ../acso_4_17.patch)
then
echo "Applying acs override patch for 4.17+."
git apply ../acso_4_17.patch
else
echo "Trying to apply acs override patch for 4.14+."
wget -O ../acso_4_14.patch "${acso_patch_4_14}"
if $(git apply --check ../acso_4_14.patch)
then
echo "Applying acs override patch for 4.14+."
git apply ../acso_4_14.patch
else
echo "Trying to apply acs override patch for 4.10+."
wget -O ../acso_4_10.patch "${acso_patch_4_10}"
if $(git apply --check ../acso_4_10.patch)
then
echo "Applying acs override patch for 4.10+."
git apply ../acso_4_10.patch
else
echo "Last resort: Trying to apply acs override patch for Ubuntu repository kernel source."
wget -O ../acso_4_18_ubuntu.patch "${acso_patch_4_18_ubuntu}"
if $(git apply --check ../acso_4_18_ubuntu.patch)
then
echo "Applying acs override patch for Ubuntu repository kernel source."
git apply ../acso_4_18_ubuntu.patch
else
echo "[ERROR]: Failed to apply acs override patch. Exiting."
exit
fi
rm -f ../acso_4_18_ubuntu.patch
fi
rm -f ../acso_4_10.patch
fi
rm -f ../acso_4_14.patch
fi
rm -f ../acso_4_17.patch
fi
rm -f ../acso_4_18.patch
fi
rm -f ../acso_5_4.patch
kernel_localversion+="-acso"
}
function try_agesa_patch() {
##by reddit user https://www.reddit.com/user/hansmoman/
##https://www.reddit.com/r/VFIO/comments/bqeixd/apparently_the_latest_bios_on_asrockmsi_boards/eo4neta
agesa_patch="https://clbin.com/VCiYJ"
agesa_patch_filename="agesa.patch"
echo "Trying to apply AMD AGESA patch."
wget -O ../${agesa_patch_filename} "${agesa_patch}"
if $(git apply --check ../${agesa_patch_filename})
then
echo "Applying AMD AGESA patch."
git apply ../${agesa_patch_filename}
else
echo "[ERROR]: Failed to apply AMD AGESA patch. Exiting."
exit
fi
rm -f ../${agesa_patch_filename}
kernel_localversion+="-agesa"
}
function try_vega_patch() {
##Original by github user https://gist.github.com/numinit
vega_patch_new="https://gist.github.com/mdPlusPlus/1754d82b53269ead770133829874fbfd/raw/"
vega_patch="https://gist.github.com/numinit/1bbabff521e0451e5470d740e0eb82fd/raw"
vega_patch_filename="fix-vega-reset.patch"
echo "Trying to apply AMD Vega reset patch."
wget -O ../${vega_patch_filename} "${vega_patch_new}"
if $(git apply --check ../${vega_patch_filename})
then
echo "Applying AMD Vega reset patch."
git apply ../${vega_patch_filename}
else
rm -f ../${vega_patch_filename}
wget -O ../${vega_patch_filename} "${vega_patch}"
if $(git apply --check ../${vega_patch_filename})
then
echo "Applying AMD Vega reset patch."
git apply ../${vega_patch_filename}
else
echo "[ERROR]: Failed to apply AMD Vega reset patch. Exiting."
exit
fi
fi
rm -f ../${vega_patch_filename}
kernel_localversion+="-vega"
}
function stable_preparations() {
echo "The newest available stable kernel version is ${stable_version}. Kernels below 4.10 are not supported."
echo -n "Which version do you want to download? [${stable_version}] "
read -r user_version
if ! [ -z "${user_version}" ]
then
stable_version="${user_version}"
fi
kernel_version="${stable_version}"
kernel_name="linux-${kernel_version}"
##Test whether the version string starts with 3, 4, or 5 and sets the URL accordingly
if [[ $stable_version == 5* ]]
then
stable_link="${stable_releases_5x_url}linux-${stable_version}.tar.xz"
else
if [[ $stable_version == 4* ]]
then
stable_link="${stable_releases_4x_url}linux-${stable_version}.tar.xz"
else
if [[ $stable_version == 3* ]]
then
stable_link="${stable_releases_3x_url}linux-${stable_version}.tar.xz"
else
echo "${stable_version} is not a vaild version number. Exiting."
exit
fi
fi
fi
wget "${stable_link}"
tar xf "${kernel_name}.tar.xz"
cd "${kernel_name}" || exit
independent_code
}
function mainline_preparations() {
kernel_version="${mainline_version}"
kernel_name="linux-${kernel_version}"
wget "${mainline_link}"
tar xf "${kernel_name}.tar.gz"
cd "${kernel_name}" || exit
independent_code
}
function repo_preparations() {
kernel_name="${repo_pkg}"
sudo apt install "${repo_pkg}"
tar xf "/usr/src/${kernel_name}.tar.bz2"
cd "${kernel_name}" || exit
makefile_version=$(grep "^VERSION" Makefile | tr -d '[:space:]' | cut -d '=' -f 2)
makefile_patchlevel=$(grep "^PATCHLEVEL" Makefile| tr -d '[:space:]' | cut -d '=' -f 2)
makefile_sublevel=$(grep "^SUBLEVEL" Makefile | tr -d '[:space:]' | cut -d '=' -f 2)
#makefile_extraversion=$(grep "^EXTRAVERSION" Makefile| tr -d '[:space:]' | cut -d '=' -f 2)
if ! [ -z "${makefile_version}" ]
then
kernel_version="${makefile_version}"
if ! [ -z "${makefile_patchlevel}" ]
then
kernel_version="${makefile_version}.${makefile_patchlevel}"
if ! [ -z "${makefile_sublevel}" ]
then
kernel_version="${makefile_version}.${makefile_patchlevel}.${makefile_sublevel}"
fi
fi
fi
##linux-hwe (5.0.0-25.26~18.04.1) bionic; urgency=medium
##->
##5.0.0-25.26~18.04.1
#kernel_version=$(head -n 1 debian/changelog | cut -d '(' -f 2 | cut -d ')' -f 1)
##This somehow comes out empty when run in the script, but is successful when issued manually
independent_code
}
function independent_code() {
kernel_localversion=""
if [ -z "${acso}" ] || [ "${acso}" != "n" ]
then
try_acso_patch
fi
if [ "${agesa}" == "y" ]
then
try_agesa_patch
fi
if [ "${vega}" == "y" ]
then
try_vega_patch
fi
##temporary
#fix_steam
cp "${kernel_config}" .config
yes '' | make oldconfig
##set xhci_hcd to load as a module instead of including it directly into the kernel
##results in vfio_pci being able to grab usb controllers before xhci_hcd is able to
sed -i -e 's/^CONFIG_USB_XHCI_HCD=y/CONFIG_USB_XHCI_HCD=m/g' .config
##Enable AMD's HSA driver for ROCm support. Thanks at https://github.com/jfturcot
sed -i -e 's/^#\ CONFIG_HSA_AMD\ is\ not\ set/CONFIG_HSA_AMD=y/g' .config
##Disable debug builds
sed -i -e 's/^CONFIG_DEBUG_INFO=y/CONFIG_DEBUG_INFO=n/g' .config
sed -i -e 's/^CONFIG_DEBUG_KERNEL=y/CONFIG_DEBUG_KERNEL=n/g' .config
##check for versions containing only a single dot instead of two
##but only when not choosing the repo source
if [ "${s_or_m_or_r}" != "r" ]
then
dots=$(echo "${kernel_version}" | awk -F "." '{print NF-1}')
dashes=$(echo "${kernel_version}" | awk -F "-" '{print NF-1}')
if [ "${dots}" -lt 2 ]
then
if [ "${dashes}" -lt 1 ]
then
##5.1 -> 5.1.0
kernel_version="${kernel_version}.0"
else
##5.1-rc1 -> 5.1.0-rc1
kernel_version="$(echo "${kernel_version}" | sed 's/-/.0-/')"
fi
kernel_name="linux-${kernel_version}"
fi
fi
make clean
make -j "$(nproc)" bindeb-pkg LOCALVERSION="${kernel_localversion}" || exit
if [ -z "${install}" ] || [ "${install}" == "y" ]
then
sudo dpkg -i ../linux-image-${kernel_version}${kernel_localversion}*.deb ../linux-headers-${kernel_version}${kernel_localversion}*.deb
if [ -z "${default}" ] || [ "${default}" == "y" ]
then
if [ "$(lsb_release -s -d | cut -d ' ' -f 1)" == "Ubuntu" ]
then
##removing previous commented line
sudo sed -i -e 's/^#GRUB_DEFAULT=.*//g' "${grub_config}"
##commenting current line
sudo sed -i 's/^GRUB_DEFAULT=/#GRUB_DEFAULT=/' "${grub_config}"
##adding line
## TODO multilanguage! only works for en-US (and other en-*) right now!
grub_line="GRUB_DEFAULT=\"Advanced options for Ubuntu>Ubuntu, with Linux ${kernel_version}${kernel_localversion}\""
sudo sed -i -e "s/^#GRUB_DEFAULT=.*/\0\n${grub_line}/" "${grub_config}"
sudo update-grub
fi
fi
fi
cd "${current_dir}" || exit
rm -rf "${working_dir}"
}
##actual logic
init
stable_or_mainline_or_repo
@maltere

This comment has been minimized.

Copy link

maltere commented Oct 25, 2018

Not working for me with Ubuntu 18.04

Stable: 4.19
Mainline: unavailable
Repositories: 4.15.***

all 3 are not working.
Mainline because its unavailable, while Stable and Repositories crash in die end with lines:

make[3]: dpkg-architecture: Command not found
make[3]: dpkg-architecture: Command not found
./compile_newest_stable_kernel_with_acso_path.sh: line 231: fakeroot: command not found
dpkg: error: cannot access archive '../*.deb': No such file or directory

Can you help me, please?

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Oct 27, 2018

I've just updated the script. Apparently apt -qq build-dep linux-image-generic does not install all required packages, so I replaced it with apt -qq install build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache. Please let me know if it works for you now.

@jfturcot

This comment has been minimized.

Copy link

jfturcot commented Oct 30, 2018

Thank you SOOOOO much, I have been struggling patching up ACS support and keep the Nvidia driver working, your script just works perfectly! I wasted so many hours and would have wasted so much more, I seriously couldn't thank you enough.

@yar05

This comment has been minimized.

Copy link

yar05 commented Oct 31, 2018

Could you please update script with libelf-dev boson flex - Ubuntu 18.10

@interprogs

This comment has been minimized.

Copy link

interprogs commented Dec 4, 2018

work good on 18.10 but dkms cannot find the kernel header when installed ? do i miss something ?

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Dec 16, 2018

@yar05:
I will test this on a fresh installation of 18.10 in a VM soon. I'm going to add the missing packages then.

@interprogs:
Sadly I'm running into the same problem. I tried to add the installation of the source package, but it didn't change anything. Even playing around with the symlinks in /usr/src/* didn't result in success.
I wasn't able to find anything helpful on the web either. My only guess is that certain dkms packages are not compatible with 4.19 yet.
So far I'm running into problems with rocm-dkms and virtualbox-dkms.

@jfturcot

This comment has been minimized.

Copy link

jfturcot commented Jan 9, 2019

@mdPlusPlus
Have you figured out why dkms doesn't find the headers? I am also running into a problem with rocm-dkms here. Thanks!

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Jan 15, 2019

I haven't been able to find out what the exact problem is, however, ROCm does no longer need the DKMS module for newer kernels, so in theory, given that you chose the right packages it should work with this kernel now. However, I have not tested this myself, yet.

You can read more on that in the ROCm documentation: https://github.com/RadeonOpenCompute/ROCm#rocm-support-in-upstream-linux-kernels

For instance, a user that wants to use the upstream kernel drivers (rather than those supplied by AMD) may want to skip the rocm-dkms and rock-dkms packages, and instead directly install rocm-dev.

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Jan 15, 2019

Note: Newest version compiles on Ubuntu 18.10 without having to manually install any additional packages. (I only tested 4.20 though.)

@jfturcot

This comment has been minimized.

Copy link

jfturcot commented Feb 7, 2019

@mdPlusPlus
I just finally managed to make ROCm work (with upstream kernel drivers) using your build script. What is missing was the kernel driver for HSA_AMD which isn't set by default. Adding the following after your USB_XHCI_HCD config line sets it.

sed -i -e 's/^#\ CONFIG_HSA_AMD\ is\ not\ set/CONFIG_HSA_AMD=y/g' .config
@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Feb 15, 2019

Thanks for the tip! There are still issues with the /lib/modules/*-acso folder. Currently I need to provide the full kernel source (~20GB) to be able to build kernel modules. So there's definitely still something wrong.

Could you please test whether it is enough to include HSA_AMD as a module (CONFIG_HSA_AMD=m instead of CONFIG_HSA_AMD=y)? Then I'm going to incorporate it into the next version of the script.

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Apr 9, 2019

Newest version includes CONFIG_HSA_AMD=y now. Also, I was able to fix the whole DKMS module installation mess.

@jfturcot

This comment has been minimized.

Copy link

jfturcot commented Apr 20, 2019

@mdPlusPlus that's awesome thanks, I will update my script right now. Sorry I never got to try it again as a module, I did once before but I never got it to work when compiled as a module.

@jfturcot

This comment has been minimized.

Copy link

jfturcot commented Apr 21, 2019

I don't know if it only happens to me, but since 5.08 the config file enabled SELinux at boot. I had to add the following lines to go back to the config of 5.07 where SELinux was compiled, but disabled at boot. I also realized that AppArmor was enabled 5.07, but wasn't anymore in favor of SELinux in 5.08 and up, so I re-enabled AppArmor also:

sed -i -e 's/^CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=1/CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=0/g' .config
sed -i -e 's/^CONFIG_DEFAULT_SECURITY_SELINUX=y/#\ CONFIG_DEFAULT_SECURITY_SELINUX\ is\ not\ set/g' .config
sed -i -e 's/^#\ CONFIG_DEFAULT_SECURITY_APPARMOR\ is\ not\ set/CONFIG_DEFAULT_SECURITY_APPARMOR=y/g' .config
sed -i -e 's/^CONFIG_DEFAULT_SECURITY="selinux"/CONFIG_DEFAULT_SECURITY="apparmor"/g' .config

So security wise, this above will return it to the same state it was in 5.07 which worked fine for me, SELinux was throwing a few errors on Ubuntu for me.

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented May 6, 2019

This is how my 5.1.0 config looks regarding apparmor and selinux under cosmic:

$ grep -i -e "APPARMOR" -e "SELINUX" /boot/config-5.1.0-acso 
CONFIG_SECURITY_SELINUX=y
CONFIG_SECURITY_SELINUX_BOOTPARAM=y
# CONFIG_SECURITY_SELINUX_DISABLE is not set
CONFIG_SECURITY_SELINUX_DEVELOP=y
CONFIG_SECURITY_SELINUX_AVC_STATS=y
CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=1
CONFIG_SECURITY_APPARMOR=y
CONFIG_SECURITY_APPARMOR_HASH=y
CONFIG_SECURITY_APPARMOR_HASH_DEFAULT=y
# CONFIG_SECURITY_APPARMOR_DEBUG is not set
# CONFIG_DEFAULT_SECURITY_SELINUX is not set
CONFIG_DEFAULT_SECURITY_APPARMOR=y
CONFIG_LSM="yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo"
@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Jun 22, 2019

Added a temporary workaround to fix Steam on the Linux host. Will be removed once the patch has been merged upstream.
More info here: ValveSoftware/steam-for-linux#6326 (comment)

Edit: Fixed as of 5.1.14, see changelog: https://cdn.kernel.org/pub/linux/kernel/v5.x/ChangeLog-5.1.14

@jessequinn

This comment has been minimized.

Copy link

jessequinn commented Jun 23, 2019

i ran this script recently and if you select the repo, which is now 5.0.0, the try_acso_patch fails. Obviously, this will occur because the patches that are included are for 4.* kernels. However, after adding the 5.0 acso patch from https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/5.0/acso.patch repo it actually still fails to patch!

function try_acso_patch() {
	acso_patch_5_0="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/5.0/acso.patch"

	echo "Trying to apply acs override patch for 5.0+."
	wget -O ../acso_5_0.patch "${acso_patch_5_0}"
	if $(git apply --check ../acso_5_0.patch)
	then
		echo "Applying acs override patch for 4.18+."
		git apply ../acso_5_0.patch
	else
        echo "[ERROR]: Failed to apply acs override patch. Exiting."
        exit
    fi
    rm -f ../acso_5_0.patch

	kernel_localversion="-acso"
}

this will fail with ERROR

Trying to apply acs override patch for 4.18+.
--2019-06-23 07:44:31--  https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/5.0/acso.patch
Resolving gitlab.com (gitlab.com)... 35.231.145.151
Connecting to gitlab.com (gitlab.com)|35.231.145.151|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3959 (3,9K) [text/plain]
Saving to: ‘../acso_5_0.patch’

../acso_5_0.patch                                               100%[======================================================================================================================================================>]   3,87K  --.-KB/s    in 0s      

2019-06-23 07:44:31 (217 MB/s) - ‘../acso_5_0.patch’ saved [3959/3959]

error: patch failed: Documentation/admin-guide/kernel-parameters.txt:3028
error: Documentation/admin-guide/kernel-parameters.txt: patch does not apply
[ERROR]: Failed to apply acs override patch. Exiting.
@jessequinn

This comment has been minimized.

Copy link

jessequinn commented Jun 23, 2019

The following command produces:

[linux-source-5.0.0] git apply --reject ../acso_5_0.patch                                                                                                                                                                                                     
Checking patch Documentation/admin-guide/kernel-parameters.txt...
error: while searching for:
                nomsi           [MSI] If the PCI_MSI kernel config parameter is
                                enabled, this kernel boot option can be used to
                                disable the use of MSI interrupts system-wide.
                noioapicquirk   [APIC] Disable all boot interrupt quirks.
                                Safety option to keep boot IRQs enabled. This
                                should never be necessary.

error: patch failed: Documentation/admin-guide/kernel-parameters.txt:3028
Checking patch drivers/pci/quirks.c...
error: while searching for:
        dev->dev_flags |= PCI_DEV_FLAGS_NO_BUS_RESET;
}

/*
 * Some Atheros AR9xxx and QCA988x chips do not behave after a bus reset.
 * The device will throw a Link Down error on AER-capable systems and

error: patch failed: drivers/pci/quirks.c:3355
error: while searching for:
        { PCI_VENDOR_ID_AMPERE, 0xE00A, pci_quirk_xgene_acs },
        { PCI_VENDOR_ID_AMPERE, 0xE00B, pci_quirk_xgene_acs },
        { PCI_VENDOR_ID_AMPERE, 0xE00C, pci_quirk_xgene_acs },
        { 0 }
};


error: patch failed: drivers/pci/quirks.c:4395
Applying patch Documentation/admin-guide/kernel-parameters.txt with 1 reject...
Rejected hunk #1.
Applying patch drivers/pci/quirks.c with 2 rejects...
Rejected hunk #1.
Rejected hunk #2.
@jessequinn

This comment has been minimized.

Copy link

jessequinn commented Jun 23, 2019

If, i stick to 5.1.14 (stable) and forget the EOL 5.0 series that ubuntu 19 is using, how can i rebuild the nvidia dkms? As we speak it breaks under this linux kernel for me.

@jessequinn

This comment has been minimized.

Copy link

jessequinn commented Jun 23, 2019

Using this method solved my problems with the 5.1.14 kernel and nvidia. Thanks for the script!

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Jun 23, 2019

I'm using the 4.18 patch file, because the contents of the patch actually haven't changed since then. You can test this by diffing the two versions.
Also, I've patched a lot of different (non-repo) kernel versions with this patch and it would always apply. I know Ubuntu at some point had an incompatible change in their kernel repo, but AFAIK it hasn't been merged into any stable branch. I'd need to check whether this still holds true. Use stable or mainline kernels if the patch fails for the time being.

As for Nvidia drivers, I can't really test it, since I don't have access to a Nvidia graphics card. However, I'm sure I've read something about an updated driver and firmware repo (I think PopOS! is using this). So you could try to get a hold of that repo.

I will make sure to test the patch against different repo versions and will modify it if necessary. Thanks for the hint.

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Jun 24, 2019

I've released a modified ACS override patch for the Ubuntu repository kernel source here and changed the script to use this patch if everything else fails.

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Jul 5, 2019

Newest version contains the AMD AGESA patch and the AMD Vega reset patch.

@ccodesharp

This comment has been minimized.

Copy link

ccodesharp commented Jul 20, 2019

Just for anyone else researching: I did use this script to compile an 4.18.20 kernel on Ubuntu 18.10 successfully.

My research system is an Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz on a Gigabyte GA-Z170X-UD5 TH. With this I now can pass through two graphic cards (GTX 1050 TI and RX 480) to two different virtual machines while the Intel integrated graphic stays with the host.

Thx @mdPlusPlus for this effort! Makes compiling kernel with ACS patch on Ubuntu so much easier!

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Jul 25, 2019

Thanks @ccodesharp!

Just a heads-up for everyone: Apparently Linux 5.2.x has introduced a KVM regression.
https://old.reddit.com/r/VFIO/comments/cgqk6p/kernel_52_kvm_bug/

@tchuyev

This comment has been minimized.

Copy link

tchuyev commented Aug 13, 2019

Thank you for this script.
A few things that don't work (for me):

  • Explicitly choosing Y in Do you want to install the kernel and its headers [...] would result in NOT asking to make this kernel the new default
  • Using Ubuntu 18.04.3 (5.0.0-23 or 25) using the newest kernel from your (r)epositories option installs the incorrect kernel 5.0.0-15
  • Can't find the corresponding .deb files after compilation even when selecting to install the kernel and its headers
@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Aug 15, 2019

Thanks for the feedback. I'm going to check item one and three tomorrow.
For item two it's installing the right kernel, but getting the wrong version info out of the provided Makefile. I'm probably going to change it to extract the version info from debian/control instead.

Edit:

Can't find the corresponding .deb files after compilation even when selecting to install the kernel and its headers

Could you please tell me what exactly your inputs were?
A quick test with the repository-provided kernel source inside an ubuntu:disco docker container results in success:

dpkg-deb: building package 'linux-headers-5.0.18-acso' in '../linux-headers-5.0.18-acso_5.0.18-acso-1_amd64.deb'.
dpkg-deb: building package 'linux-libc-dev' in '../linux-libc-dev_5.0.18-acso-1_amd64.deb'.
dpkg-deb: building package 'linux-image-5.0.18-acso' in '../linux-image-5.0.18-acso_5.0.18-acso-1_amd64.deb'.
 dpkg-genbuildinfo --build=binary
 dpkg-genchanges --build=binary >../linux-5.0.18-acso_5.0.18-acso-1_amd64.changes
dpkg-genchanges: warning: package linux-image-5.0.18-acso-dbg in control file but not in files list
dpkg-genchanges: info: binary-only upload (no source code included)
 dpkg-source --after-build .
dpkg-buildpackage: info: binary-only upload (no source included)
Selecting previously unselected package linux-image-5.0.18-acso.
(Reading database ... 68529 files and directories currently installed.)
Preparing to unpack .../linux-image-5.0.18-acso_5.0.18-acso-1_amd64.deb ...
Unpacking linux-image-5.0.18-acso (5.0.18-acso-1) ...
Selecting previously unselected package linux-headers-5.0.18-acso.
Preparing to unpack .../linux-headers-5.0.18-acso_5.0.18-acso-1_amd64.deb ...
Unpacking linux-headers-5.0.18-acso (5.0.18-acso-1) ...
Setting up linux-image-5.0.18-acso (5.0.18-acso-1) ...
Setting up linux-headers-5.0.18-acso (5.0.18-acso-1) ...
@tchuyev

This comment has been minimized.

Copy link

tchuyev commented Aug 16, 2019

I'm using the latest Ubuntu 18.04.3 with HWE kernel installed by default (fresh install), starting with 5.0.0-23.

Also noticed the kernel-package asks to use a specific version of a configuration file (already installed or the one from the maintainer) which prevents the unattended execution of the script.

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Aug 20, 2019

Sorry, it took me a bit longer to look into this.

  • Explicitly choosing Y in Do you want to install the kernel and its headers [...] would result in NOT asking to make this kernel the new default

The script currently only supports lowercase letters as answers. This seems to be the source of your issue from what I can tell. I will consider enabling uppercase letters in the future, but I won't implement this currently.

  • Using Ubuntu 18.04.3 (5.0.0-23 or 25) using the newest kernel from your (r)epositories option installs the incorrect kernel 5.0.0-15

As mentioned before, this is a discrepancy between what is shown on the screen and what can be found in the actual provided Makefile.
Changing this, however, is a lot more complex than it seems. I need to take a look at this again when I have more time.
The solution probably is to switch from the linux-source-* to the linux-image-*-generic package and issue dpkg-buildpackage instead of calling make directly.

  • Can't find the corresponding .deb files after compilation even when selecting to install the kernel and its headers

I wasn't able to reproduce this, but I think the issue was introduced by adding ".0" to the version string. I changed it to only add this when choosing mainline or stable versions.
Please let me know if this fixed the issue.

@tchuyev

This comment has been minimized.

Copy link

tchuyev commented Aug 20, 2019

Thank you for the updated script: I'll give it try for sure!

I actually had the same problem regarding missing .deb files when trying to compile the kernel manually (outside of your script).
Had to install gawk which solved the problem: maybe that's the same issue here and should be added as a dependency.

Not related to your script but when I:
$ git clone -b hwe git://kernel.ubuntu.com/ubuntu/ubuntu-bionic.git $HOME/Git/ubuntu-bionic-hwe
$ fakeroot debian/rules binary-headers binary-generic
It generates a non-signed kernel e.g. linux-image-unsigned-5.0.0-26-generic_5.0.0-26.27~18.04.1_amd64.deb
Any ideas why and how to avoid this? Thanks

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Aug 20, 2019

Can't really help you there but maybe try the signed repository? https://kernel.ubuntu.com/git/ubuntu/ubuntu-bionic-signed.git/
Also, I think dpkg-buildpackage -b is preferred over debian/rules binary-headers binary-generic, so maybe try that too.

Why do you need the image to be signed, though? Are you running into secure boot issues?

@tchuyev

This comment has been minimized.

Copy link

tchuyev commented Aug 25, 2019

Tried your updated script, here's my feedback:

  • It is now working, great... while still showing 5.0.18 (instead of 5.0.0-25)
  • grub2 shows a non critical error on boot: 'error: can't find command hwmatch'
  • kernel-package still prompts the user during install (default should be replace if at all possible)
  • Still can't get hold of the resulting kernel .deb files e.g. for reuse on other machines

I hope it is helpful to you.

@tchuyev

This comment has been minimized.

Copy link

tchuyev commented Aug 25, 2019

Regarding my previous question, I'll finally stick with unsigned as the tree branch for the signed kernel doesn't apply for compilation.

Trying kernel compilation the manual way, still using Ubuntu 18.04.3, I'm facing the following issue:
$ git clone -b hwe git://kernel.ubuntu.com/ubuntu/ubuntu-bionic.git $HOME/Git/ubuntu-bionic-hwe
$ wget https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/5.0.8/acso.patch

When running "git apply --check acso.patch", I get the following:
error: patch failed: Documentation/admin-guide/kernel-parameters.txt:3028
error: Documentation/admin-guide/kernel-parameters.txt: patch does not apply

Another attempt with "patch -p1 <acso.patch" would result in:
patching file Documentation/admin-guide/kernel-parameters.txt
Hunk #1 FAILED at 3028.
1 out of 1 hunk FAILED -- saving rejects to file Documentation/admin-guide/kernel-parameters.txt.rej
patching file drivers/pci/quirks.c
Hunk #1 succeeded at 3412 (offset 57 lines).
Hunk #2 succeeded at 4655 (offset 160 lines).

$ cat Documentation/admin-guide/kernel-parameters.txt.rej
--- Documentation/admin-guide/kernel-parameters.txt
+++ Documentation/admin-guide/kernel-parameters.txt
@@ -3028,6 +3028,15 @@
nomsi [MSI] If the PCI_MSI kernel config parameter is
enabled, this kernel boot option can be used to
disable the use of MSI interrupts system-wide.
+ pcie_acs_override =
+ [PCIE] Override missing PCIe ACS support for:
+ downstream
+ All downstream ports - full ACS capabilities
+ multfunction
+ All multifunction devices - multifunction ACS subset
+ id:nnnn:nnnn
+ Specfic device - full ACS capabilities
+ Specified as vid:did (vendor/device ID) in hex
noioapicquirk [APIC] Disable all boot interrupt quirks.
Safety option to keep boot IRQs enabled. This
should never be necessary.

You may already have encountered this issue.
Any ideas? Thanks.

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Aug 26, 2019

It's only a change in a documentation file, but I'm using this to work around the error: https://gist.github.com/mdPlusPlus/bb3df6248ffc7c6b3772ae0901659966

You could force the application of the patch though, as the incompatible lines are only documentation.

EDIT:

  • It is now working, great... while still showing 5.0.18 (instead of 5.0.0-25)

I'm still thinking about how to solve this the most elegant way.

  • grub2 shows a non critical error on boot: 'error: can't find command hwmatch'

We don't really do anything to GRUB, so I guess this error was there before. At least I don't have any errors showing at boot. Does this get logged somewhere so I could check my system?

  • kernel-package still prompts the user during install (default should be replace if at all possible)

I assume this is up to the package maintainer. Since this is only a one time issue on the first run and the script isn't meant do run unattended anyways, I guess this is again a WONTFIX. I'm going to look into it, though.

  • Stlll can't get hold of the resulting kernel .deb files e.g. for reuse on other machines

So this was the issue you mentioned before? I thought it couldn't find the files for installation due to a filename mismatch. I was looking for the wrong issue then.
The files aren't found on the filesystem, since they're created in a temporary directory, which gets deleted after the installation.
I should probably ask the user whether those should be moved somewhere before deletion. Good suggestion.

@delocker

This comment has been minimized.

Copy link

delocker commented Dec 5, 2019

Ubuntu 19.10 + 5.3.10 kernel - everything works! Thank you, buddy! I love you!

@jessequinn

This comment has been minimized.

Copy link

jessequinn commented Dec 13, 2019

new patch is needed for 5.4+

  acso_patch_5_4="https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/5.4/acso.patch"
@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Dec 16, 2019

Thanks for letting me know. I've just updated the script.

@leftjs

This comment has been minimized.

Copy link

leftjs commented Dec 26, 2019

hi, @mdPlusPlus .I run this script, but got this:
image

@mdPlusPlus

This comment has been minimized.

Copy link
Owner Author

mdPlusPlus commented Dec 26, 2019

What system are you trying this on? flex should get installed from the Ubuntu/Debian repositories automatically. You're also using /bin/sh instead of /bin/bash which makes me think that you're probably running this on an unsupported system.

What are the outputs of echo ${PATH}, which flex and ls /boot/config-* | grep generic | sort -Vr | head -n 1?

@jessequinn

This comment has been minimized.

Copy link

jessequinn commented Feb 7, 2020

acso patch for 5.4 will work for 5.5 series?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.