From c6cb9aba90351adcd6e93f4d6614d2015efb666b Mon Sep 17 00:00:00 2001 From: thojohns <41297926+thojohns@users.noreply.github.com> Date: Mon, 4 Sep 2023 11:48:24 -0400 Subject: [PATCH] Patch 525xx and 530xx for kernel 6.5 (#186) * Add Linux 6.5 patch for 525 and 530 driver branches * fix link to original patch --- PKGBUILD | 27 +++++++++-- patches/kernel-6.5.patch | 99 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 patches/kernel-6.5.patch diff --git a/PKGBUILD b/PKGBUILD index 5277c4d..4f4e880 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -356,6 +356,7 @@ source=($_source_name 'kernel-6.2.patch' 'kernel-6.3.patch' 'kernel-6.4.patch' + 'kernel-6.5.patch' ) msg2 "Selected driver integrity check behavior (md5sum or SKIP): $_md5sum" # If the driver is "known", return md5sum. If it isn't, return SKIP @@ -401,7 +402,8 @@ md5sums=("$_md5sum" '0b9b855d9be313153a5903e46e774a30' '5d573b1aa0712b9bd2000c9fefdf84c2' 'a6acbba08173769399658914eb86a212' - '4f855bb0e0b84e8e5d072c687256767a') + '4f855bb0e0b84e8e5d072c687256767a' + 'b81cac7573842ebd7af30fdf851c63f9') if [ "$_open_source_modules" = "true" ]; then source+=("$pkgname-$pkgver.tar.gz::https://github.com/NVIDIA/open-gpu-kernel-modules/archive/refs/tags/${pkgver}.tar.gz") @@ -812,6 +814,11 @@ DEST_MODULE_LOCATION[3]="/kernel/drivers/video"' dkms.conf _kernel64="1" _whitelist64=( 470.4* 470.5* 470.6* 470.7* 470.8* 470.9* 470.10* 470.12* 470.14* 470.16* 470.18* 530* ) fi + # 6.5 + if (( $(vercmp "$_kernel" "6.5") >= 0 )); then + _kernel65="1" + _whitelist65=(525* 530* 535.5* 535.43.02) + fi # Loop patches (linux-4.15.patch, lol.patch, ...) for _p in $(printf -- '%s\n' ${source[@]} | grep .patch); do # https://stackoverflow.com/a/21058239/1821548 @@ -887,7 +894,9 @@ DEST_MODULE_LOCATION[3]="/kernel/drivers/video"' dkms.conf if [ "$_patch" = "6.4" ]; then _whitelist=(${_whitelist64[@]}) fi - + if [ "$_patch" = "6.5" ]; then + _whitelist=(${_whitelist65[@]}) + fi patchy=0 if (( $(vercmp "$_kernel" "$_patch") >= 0 )); then for yup in "${_whitelist[@]}"; do @@ -1280,7 +1289,19 @@ DEST_MODULE_LOCATION[3]="/kernel/drivers/video"' dkms.conf msg2 "Skipping kernel-6.4.patch as it doesn't apply to this driver version..." fi fi - + # 6.5 + if [ "$_kernel65" = "1" ]; then + patchy=0 + for yup in "${_whitelist65[@]}"; do + [[ $pkgver = $yup ]] && patchy=1 + done + if [ "$patchy" = "1" ]; then + msg2 "Applying kernel-6.5.patch for dkms..." + patch -Np1 -i "$srcdir"/kernel-6.5.patch + else + msg2 "Skipping kernel-6.5.patch as it doesn't apply to this driver version..." + fi + fi # Legacy quirks if [ "$_oldstuff" = "1" ]; then msg2 "Applying 01-ipmi-vm.diff for dkms..." diff --git a/patches/kernel-6.5.patch b/patches/kernel-6.5.patch new file mode 100644 index 0000000..0032702 --- /dev/null +++ b/patches/kernel-6.5.patch @@ -0,0 +1,99 @@ +Works around get_user_pages argument error when compiling for kernel 6.5 or newer +Should work with 525xx, 530xx 535xx prior to 535.86(?), potentially some older versions? +Original patch by Fjodor42 - this just changes some driver-specific lines +See: https://gist.github.com/Fjodor42/cfd29b3ffd1d1957894469f2def8f4f6 +Original original patch for 470xx by Joan Bruguera at https://gist.github.com/joanbm/dfe8dc59af1c83e2530a1376b77be8ba + +--- a/kernel-dkms/common/inc/nv-mm.h ++++ b/kernel-dkms/common/inc/nv-mm.h + +@@ -23,6 +23,7 @@ + #ifndef __NV_MM_H__ + #define __NV_MM_H__ + ++#include + #include "conftest.h" + + #if !defined(NV_VM_FAULT_T_IS_PRESENT) +@@ -41,7 +42,16 @@ typedef int vm_fault_t; + #include + #include + #if defined(NV_PIN_USER_PAGES_PRESENT) +- #define NV_PIN_USER_PAGES pin_user_pages ++ #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0) ++ static inline long NV_PIN_USER_PAGES(unsigned long start, unsigned long nr_pages, ++ unsigned int gup_flags, struct page **pages, ++ struct vm_area_struct **vmas) { ++ return pin_user_pages(start, nr_pages, gup_flags, pages); ++ } ++ #else ++ #define NV_PIN_USER_PAGES pin_user_pages ++ #endif ++ + #define NV_UNPIN_USER_PAGE unpin_user_page + #else + #define NV_PIN_USER_PAGES NV_GET_USER_PAGES +@@ -66,7 +76,25 @@ typedef int vm_fault_t; + * + */ + +-#if defined(NV_GET_USER_PAGES_HAS_ARGS_FLAGS) ++// Rel. commit. "mm/gup: remove unused vmas parameter from get_user_pages()" (Lorenzo Stoakes, 14 May 2023) ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0) ++static inline long NV_GET_USER_PAGES(unsigned long start, ++ unsigned long nr_pages, ++ int write, ++ int force, ++ struct page **pages, ++ struct vm_area_struct **vmas) ++{ ++ unsigned int flags = 0; ++ ++ if (write) ++ flags |= FOLL_WRITE; ++ if (force) ++ flags |= FOLL_FORCE; ++ ++ return get_user_pages(start, nr_pages, flags, pages); ++} ++#elif defined(NV_GET_USER_PAGES_HAS_ARGS_FLAGS) + #define NV_GET_USER_PAGES get_user_pages + #elif defined(NV_GET_USER_PAGES_HAS_ARGS_TSK_FLAGS) + #define NV_GET_USER_PAGES(start, nr_pages, flags, pages, vmas) \ +@@ -103,7 +131,14 @@ typedef int vm_fault_t; + */ + + #if defined(NV_PIN_USER_PAGES_REMOTE_PRESENT) +- #if defined (NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK) ++ #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0) ++ static inline long NV_PIN_USER_PAGES_REMOTE(struct mm_struct *mm, ++ unsigned long start, unsigned long nr_pages, ++ unsigned int gup_flags, struct page **pages, ++ struct vm_area_struct **vmas, int *locked) { ++ return pin_user_pages_remote(mm, start, nr_pages, gup_flags, pages, locked); ++ } ++ #elif defined (NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK) + #define NV_PIN_USER_PAGES_REMOTE(mm, start, nr_pages, flags, pages, vmas, locked) \ + pin_user_pages_remote(NULL, mm, start, nr_pages, flags, pages, vmas, locked) + #else +@@ -137,7 +172,20 @@ typedef int vm_fault_t; + * + */ + +-#if defined(NV_GET_USER_PAGES_REMOTE_PRESENT) ++//#if defined(NV_GET_USER_PAGES_REMOTE_PRESENT) ++// Rel. commit. "mm/gup: remove unused vmas parameter from get_user_pages_remote()" (Lorenzo Stoakes, 14 May 2023) ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0) ++static inline long NV_GET_USER_PAGES_REMOTE( struct mm_struct *mm, ++ unsigned long start, ++ unsigned long nr_pages, ++ unsigned int gup_flags, ++ struct page **pages, ++ struct vm_area_struct **vmas, ++ int *locked) ++{ ++ return get_user_pages_remote(mm, start, nr_pages, gup_flags, pages, locked); ++} ++#elif defined(NV_GET_USER_PAGES_REMOTE_PRESENT) + #if defined(NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED) + #define NV_GET_USER_PAGES_REMOTE get_user_pages_remote