From patchwork Fri Dec 13 04:02:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Jauregui X-Patchwork-Id: 2022612 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y8bKF4xz2z1yRW for ; Fri, 13 Dec 2024 15:02:57 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1tLwtA-0004Rg-9O; Fri, 13 Dec 2024 04:02:52 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1tLwt9-0004RB-2W for kernel-team@lists.ubuntu.com; Fri, 13 Dec 2024 04:02:51 +0000 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id CC09D40CE5 for ; Fri, 13 Dec 2024 04:02:50 +0000 (UTC) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-21638389f63so11311625ad.1 for ; Thu, 12 Dec 2024 20:02:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734062569; x=1734667369; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FmKcOjm4sfT3TrZAQiKTT+qPZo9a6Nkx4iUaBL+GkMk=; b=b1RMyP5x776ud8T8+fmLqPzBWzd7zP/kHegk+OsoVanPgE/n/XtcgSYFBzCw8xfrD2 WNxqXV66at3Urdh0Jg5GmLKfUnJ8OZh0NjGQi7iaq/W0Qd5cHfThvq2PSq7zo1p2YqEr /c282COIb+fwfQCZSv1wP+hXI7DOLkN4OhUwdoXK1bIgX2YS1IqTZpqn+wmrXlti+l8K gSUzzXLHB7cfyvkVpuCidH4esQfpE0eXeL8S0w89L9yrw4KLhnCREIa6kbuA+lNzoVnM iMg9UvnSlW7N1IOQ+Dg6HM6D4oyzU+NxCZa1aoatoKR60Cg2s/ONTC3GVom4maE19DW/ RPbA== X-Gm-Message-State: AOJu0YzHauF4ahebjTQBJh/z5IgKTPc4HesGCgRkogZ8M9YWxzl+UqNh yXNgo37UC2mZFuHoJW1GJc8BnsfoAUbkNghTS5wi+RZQO1Mm6PEIbRdLUpZvAcPoDFIQddv4WSk P273O+05Q6e/+QY7BZ5QJLU1LnWZ6MHlVOKOM5j3gJ4IikC89+PwJmi0sKILOw4/hPBgrOAqszD 92LwSao5ezaA== X-Gm-Gg: ASbGncv3/N9uGsiDmzFZkc65kbODVM0a0Hbpgf5hTqgkRLwQl+IqBmBZkm6IZ3U6Lp4 HinFlMQV8SjPTJfiwFTdWane3SwjyVY9Ek8qphJh5y9/Kxd9oS/RsBaXEw1dcmAv7GbIu78n6QL ab3HUBJtOr1JDLY2+x9HKIL3ev1Y731vh+rMefXqXF96NdcWat+wxmkVyxJbNP4y1ODlCjqvcdY QD/oq4x1rBb1drjhXSHemxCG0VXq3L2EiX4ywW7djh8JcnZtx4zL8+0k0uOfkNz X-Received: by 2002:a17:902:c44c:b0:216:2abc:194f with SMTP id d9443c01a7336-21892a54781mr16204895ad.40.1734062568852; Thu, 12 Dec 2024 20:02:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IET/vz4J5q9fy3eCRqD8wijmpbjkRj/Kf4vloqrv0tJq1vUTcUnZbiZny/WXlUohyyc/Mp6Gw== X-Received: by 2002:a17:902:c44c:b0:216:2abc:194f with SMTP id d9443c01a7336-21892a54781mr16204465ad.40.1734062568308; Thu, 12 Dec 2024 20:02:48 -0800 (PST) Received: from localhost ([58.84.136.157]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-216637467aasm68038625ad.49.2024.12.12.20.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 20:02:48 -0800 (PST) From: Aaron Jauregui To: kernel-team@lists.ubuntu.com Subject: [SRU][canonical-kernel-snap/main][RFC PATCH v3 1/1] nvidia-hooks: add hooks for nvidia kernel components Date: Fri, 13 Dec 2024 15:02:04 +1100 Message-ID: <20241213040237.3465338-3-aaron.jauregui@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241213040237.3465338-1-aaron.jauregui@canonical.com> References: <20241213040237.3465338-1-aaron.jauregui@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" 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 --- 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 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 + 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 +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/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/* + +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" + +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" + +rm -rf "$SNAP_COMMON"/kernel-gpu-2404/* 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