[SRU][canonical-kernel-snap/main][PATCH v5 1/1] nvidia-hooks: add hooks for nvidia kernel components
Juerg Haefliger
juerg.haefliger at canonical.com
Thu Feb 13 08:36:37 UTC 2025
On Thu, 30 Jan 2025 12:05:35 +1100
Aaron Jauregui <aaron.jauregui at canonical.com> wrote:
> BugLink: https://bugs.launchpad.net/bugs/2088970
>
> Add required hooks for kernel components. module install and remove
> hooks should be generic with a special case for nouveau to be compatible
> with nvidia drivers. Also adding kernel-gpu-2404 mangler script, meant
> to set nvidia library paths for nvidia-550-user.
>
> Signed-off-by: Aaron Jauregui <aaron.jauregui at canonical.com>
> ---
> hooks/module/install.module | 21 ++++++++++++++++
> hooks/module/post-refresh.module | 21 ++++++++++++++++
> hooks/module/remove.module | 13 ++++++++++
> hooks/nvidia-ko/install.nvidia-ko | 25 +++++++++++++++++++
> hooks/nvidia-ko/post-refresh.nvidia-ko | 25 +++++++++++++++++++
> hooks/nvidia-ko/remove.nvidia-ko | 6 +++++
> hooks/nvidia-user/install.nvidia-user | 18 +++++++++++++
> .../kernel-gpu-2404-provider-mangler | 12 +++++++++
> hooks/nvidia-user/remove.nvidia-user | 10 ++++++++
> hooks/pc-kernel/install.pc-kernel | 6 +++++
> hooks/pc-kernel/post-refresh.pc-kernel | 6 +++++
> 11 files changed, 163 insertions(+)
> create mode 100644 hooks/module/install.module
> create mode 100644 hooks/module/post-refresh.module
> create mode 100644 hooks/module/remove.module
> create mode 100644 hooks/nvidia-ko/install.nvidia-ko
> create mode 100644 hooks/nvidia-ko/post-refresh.nvidia-ko
> create mode 100644 hooks/nvidia-ko/remove.nvidia-ko
> create mode 100644 hooks/nvidia-user/install.nvidia-user
> create mode 100644 hooks/nvidia-user/kernel-gpu-2404-provider-mangler
> create mode 100644 hooks/nvidia-user/remove.nvidia-user
> create mode 100644 hooks/pc-kernel/install.pc-kernel
> create mode 100644 hooks/pc-kernel/post-refresh.pc-kernel
>
> diff --git a/hooks/module/install.module b/hooks/module/install.module
> new file mode 100644
All your hook scripts are 644, don't they need to be executable?
> index 0000000..44e4394
> --- /dev/null
> +++ b/hooks/module/install.module
> @@ -0,0 +1,21 @@
> +#!/bin/bash
> +# Generic install hook for kernel modules
> +
> +set -eux
> +
> +name=$(echo "$SNAP_COMPONENT_NAME" | cut -d+ -f2)
> +
> +# nouveau needs a special case to override nvidia modules
> +if [ "$name" = "nouveau" ] ; then
Shouldn't this be "nouveau-ko" now?
> + dest="$SNAP_DATA/modules/$(uname -r)/graphics"
> +else
> + dest="$SNAP_DATA/modules/$(uname -r)/$name"
> +fi
> +
> +
> +#clean up existing modules
> +rm -rf "$dest"
> +mkdir -p "$dest"
> +
> +find "$SNAP_COMPONENT" -name '*.ko' -exec cp '{}' "$dest" \;
> +find "$SNAP_COMPONENT" -name '*.ko.zst' -exec cp '{}' "$dest" \;
> diff --git a/hooks/module/post-refresh.module b/hooks/module/post-refresh.module
> new file mode 100644
> index 0000000..44e4394
> --- /dev/null
> +++ b/hooks/module/post-refresh.module
> @@ -0,0 +1,21 @@
> +#!/bin/bash
> +# Generic install hook for kernel modules
> +
> +set -eux
> +
> +name=$(echo "$SNAP_COMPONENT_NAME" | cut -d+ -f2)
> +
> +# nouveau needs a special case to override nvidia modules
> +if [ "$name" = "nouveau" ] ; then
> + dest="$SNAP_DATA/modules/$(uname -r)/graphics"
> +else
> + dest="$SNAP_DATA/modules/$(uname -r)/$name"
> +fi
> +
> +
> +#clean up existing modules
> +rm -rf "$dest"
> +mkdir -p "$dest"
> +
> +find "$SNAP_COMPONENT" -name '*.ko' -exec cp '{}' "$dest" \;
> +find "$SNAP_COMPONENT" -name '*.ko.zst' -exec cp '{}' "$dest" \;
> diff --git a/hooks/module/remove.module b/hooks/module/remove.module
> new file mode 100644
> index 0000000..e326e7d
> --- /dev/null
> +++ b/hooks/module/remove.module
> @@ -0,0 +1,13 @@
> +#!/bin/bash
> +# Generic remove hook for kernel modules
> +
> +set -eux
> +
> +name=$(echo "$SNAP_COMPONENT_NAME" | cut -d+ -f2)
> +if [ "$name" = "nouveau" ] ; then
> + dest="$SNAP_DATA/modules/$(uname -r)/graphics"
> +else
> + dest="$SNAP_DATA/modules/$(uname -r)/$name"
> +fi
> +
> +rm -rf "$dest"
> diff --git a/hooks/nvidia-ko/install.nvidia-ko b/hooks/nvidia-ko/install.nvidia-ko
> new file mode 100644
> index 0000000..c4b5285
> --- /dev/null
> +++ b/hooks/nvidia-ko/install.nvidia-ko
> @@ -0,0 +1,25 @@
> +#!/bin/bash
> +# install hook for nvidia drivers that require assembling
> +
> +set -eux
> +
> +# First setup the kernel modules
> +tmp_dir="/tmp/nvidia-ko"
> +rm -rf $tmp_dir
Although shellcheck is smart and doesn't complain, I like to quote variables
just to be on the safe side.
> +mkdir $tmp_dir
And here and in a few other places...
> +cp -r "$SNAP_COMPONENT"/bits $tmp_dir/bits
> +
> +cd $tmp_dir/bits
> +
> +sed -i "s|/usr/bin/ld.bfd|$SNAP_COMPONENT/bin/ld.bfd|" BUILD
> +sed -i "s|make|$SNAP_COMPONENT/bin/make|" BUILD
> +
> +LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP_COMPONENT/lib/$(uname -m)-linux-gnu sh BUILD
> +
> +# Clean up directory before copying modules
> +rm -rf "$SNAP_DATA/modules/$(uname -r)/graphics"
> +mkdir -p "$SNAP_DATA/modules/$(uname -r)/graphics"
> +
> +mv ../*.ko "$SNAP_DATA/modules/$(uname -r)/graphics/"
> +
> +rm -rf $tmp_dir
> diff --git a/hooks/nvidia-ko/post-refresh.nvidia-ko b/hooks/nvidia-ko/post-refresh.nvidia-ko
> new file mode 100644
> index 0000000..c4b5285
> --- /dev/null
> +++ b/hooks/nvidia-ko/post-refresh.nvidia-ko
> @@ -0,0 +1,25 @@
> +#!/bin/bash
> +# install hook for nvidia drivers that require assembling
> +
> +set -eux
> +
> +# First setup the kernel modules
> +tmp_dir="/tmp/nvidia-ko"
> +rm -rf $tmp_dir
> +mkdir $tmp_dir
> +cp -r "$SNAP_COMPONENT"/bits $tmp_dir/bits
> +
> +cd $tmp_dir/bits
> +
> +sed -i "s|/usr/bin/ld.bfd|$SNAP_COMPONENT/bin/ld.bfd|" BUILD
> +sed -i "s|make|$SNAP_COMPONENT/bin/make|" BUILD
> +
> +LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP_COMPONENT/lib/$(uname -m)-linux-gnu sh BUILD
> +
> +# Clean up directory before copying modules
> +rm -rf "$SNAP_DATA/modules/$(uname -r)/graphics"
> +mkdir -p "$SNAP_DATA/modules/$(uname -r)/graphics"
> +
> +mv ../*.ko "$SNAP_DATA/modules/$(uname -r)/graphics/"
> +
> +rm -rf $tmp_dir
> diff --git a/hooks/nvidia-ko/remove.nvidia-ko b/hooks/nvidia-ko/remove.nvidia-ko
> new file mode 100644
> index 0000000..5e2831d
> --- /dev/null
> +++ b/hooks/nvidia-ko/remove.nvidia-ko
> @@ -0,0 +1,6 @@
> +#!/bin/bash
> +# Generic remove hook for kernel modules
> +
> +set -eux
> +
> +rm -rf "$SNAP_DATA/modules/$(uname -r)/graphics"
> diff --git a/hooks/nvidia-user/install.nvidia-user b/hooks/nvidia-user/install.nvidia-user
> new file mode 100644
> index 0000000..fab93e5
> --- /dev/null
> +++ b/hooks/nvidia-user/install.nvidia-user
> @@ -0,0 +1,18 @@
> +#!/bin/bash
> +# install hook for nvidia userspace drivers
> +
> +set -eux
> +
> +# Now setup the userspace libraries via kernel-gpu-2404 interface
> +SENTINEL_FILE="$SNAP_COMMON"/kernel-gpu-2404/kernel-gpu-2404-sentinel
> +
> +mkdir -p "$SNAP_COMMON"/kernel-gpu-2404
> +
> +# Clean up existing installs
> +rm -rf "$SNAP_COMMON"/kernel-gpu-2404/*
Nit, these feels the wrong way around (rm after mkdir).
> +
> +cp -r "$SNAP_COMPONENT"/usr "$SNAP_COMMON"/kernel-gpu-2404
> +cp "$SNAP_COMPONENT"/kernel-gpu-2404-provider-mangler "$SNAP_COMMON"/kernel-gpu-2404
> +
> +# put version information into sentinel file
> +echo "$SNAP_COMPONENT_REVISION" > "$SENTINEL_FILE"
> diff --git a/hooks/nvidia-user/kernel-gpu-2404-provider-mangler b/hooks/nvidia-user/kernel-gpu-2404-provider-mangler
> new file mode 100644
> index 0000000..ea032fd
> --- /dev/null
> +++ b/hooks/nvidia-user/kernel-gpu-2404-provider-mangler
> @@ -0,0 +1,12 @@
> +#!/bin/bash
> +
> +
> +ARCH_TRIPLET="$(arch)-linux-gnu"
Nit, maybe use $(uname -m) to be consistent with the other hook scripts that
use it.
> +
> +export OCL_ICD_VENDORS=${OCL_ICD_VENDORS:+$OCL_ICD_VENDORS:}${COMPONENT_PATH}/etc/OpenCL/vendors
> +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${COMPONENT_PATH}/usr/lib/${ARCH_TRIPLET}
> +export __EGL_VENDOR_LIBRARY_DIRS=${__EGL_VENDOR_LIBRARY_DIRS:+$__EGL_VENDOR_LIBRARY_DIRS:}${COMPONENT_PATH}/usr/share/glvnd/egl_vendor.d
> +export __EGL_EXTERNAL_PLATFORM_CONFIG_DIRS=${__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:+$__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:}${COMPONENT_PATH}/usr/share/egl/egl_external_platform.d
> +export VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${COMPONENT_PATH}/usr/share/vulkan/implicit_layer.d/
> +export XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${COMPONENT_PATH}/usr/share
> +export NVIDIA_DRIVER_ROOT=${COMPONENT_PATH}
> diff --git a/hooks/nvidia-user/remove.nvidia-user b/hooks/nvidia-user/remove.nvidia-user
> new file mode 100644
> index 0000000..19d6b22
> --- /dev/null
> +++ b/hooks/nvidia-user/remove.nvidia-user
> @@ -0,0 +1,10 @@
> +#!/bin/bash
> +# Remove hook for nvidia drivers
> +
> +set -eux
> +
> +SENTINEL_FILE="$SNAP_COMMON"/kernel-gpu-2404/kernel-gpu-2404-sentinel
> +
> +rm "$SENTINEL_FILE"
That seems redundant given you're cleaning out the whole directory content in
the next step.
> +
> +rm -rf "$SNAP_COMMON"/kernel-gpu-2404/*
Do you need to keep the (empty) directory?
> diff --git a/hooks/pc-kernel/install.pc-kernel b/hooks/pc-kernel/install.pc-kernel
> new file mode 100644
> index 0000000..0523662
> --- /dev/null
> +++ b/hooks/pc-kernel/install.pc-kernel
> @@ -0,0 +1,6 @@
> +#!/bin/bash
> +
> +#install nouveau graphics as default if not already installed
> +if [ ! -d "/snap/${SNAP_NAME}/components/mnt/nouveau" ]; then
> + snapctl install +nouveau
> +fi
> diff --git a/hooks/pc-kernel/post-refresh.pc-kernel b/hooks/pc-kernel/post-refresh.pc-kernel
> new file mode 100644
> index 0000000..0523662
> --- /dev/null
> +++ b/hooks/pc-kernel/post-refresh.pc-kernel
> @@ -0,0 +1,6 @@
> +#!/bin/bash
> +
> +#install nouveau graphics as default if not already installed
> +if [ ! -d "/snap/${SNAP_NAME}/components/mnt/nouveau" ]; then
> + snapctl install +nouveau
> +fi
nouveau-ko?
...Juerg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/kernel-team/attachments/20250213/49626f72/attachment.sig>
More information about the kernel-team
mailing list