Control: tags -1 + patch

Hi,

Attached is a patch against nvidia-graphics-drivers 550.163.01-5.1 that
makes
nvidia-kernel-dkms build and work on Linux 7.2.6+deb14-amd64. It addresses
the
two issues Jonas described in his follow-up to this bug.

1. strncpy() removed in Linux 7.2

   - nvidia/os-interface.c and nvidia-uvm/uvm_pmm_gpu.c: switched to
strscpy(),
     same as NVIDIA's upstream fix (open-gpu-kernel-modules PR #1227,
shipped
     in 610.57.04).
   - nvidia/linux_nvswitch.c (registry key parsing): switched to memcpy(),
also
     as upstream does. The following line already NUL-terminates.
   - nvkms_strncpy() and nvswitch_os_strncpy(): these are called from the
     closed-source binary objects, so, following the concern raised in this
     bug, I kept their names and exact strncpy() semantics (copy, then
     zero-pad the rest of the buffer), implemented locally instead of
changing
     them to strscpy().

2. struct drm_atomic_state renamed to struct drm_atomic_commit
   (commit 5164f7e7ff8e)

   - New conftest drm_atomic_commit_present (types), registered in
     nvidia-drm-sources.mk. It uses sizeof(struct drm_atomic_commit), so it
     cannot give a false positive on older kernels.
   - When it is defined, nvidia-drm-conftest.h maps the old names to the new
     API (drm_atomic_state_alloc/clear/get/put/init/default_clear/
     default_release -> drm_atomic_commit_*). I checked these names against
     the 7.2.6 headers.
   - Several existing conftests probe using the old struct name and silently
     report false negatives on 7.2. That made the driver pick the pre-4.10
     code paths (drm_atomic_state_free, and the old signatures of the crtc
and
     plane atomic_check callbacks). When NV_DRM_ATOMIC_COMMIT_PRESENT is
set,
     the patch forces ATOMIC_STATE_REF_COUNTING_PRESENT,
     CRTC/PLANE_ATOMIC_CHECK_HAS_ATOMIC_STATE_ARG and the two
     ATOMIC_HELPER_SWAP_STATE conftests.

   Everything new is guarded by NV_DRM_ATOMIC_COMMIT_PRESENT, so builds on
   older kernels are unchanged.

Testing:

- Built with DKMS against 7.2.6+deb14-amd64 and 7.1.13+deb14-amd64. Both
  succeed with no errors and no implicit-declaration or modpost warnings.
  On 7.1.13 the new conftest correctly reports #undef.
- Hardware: HP laptop with GeForce RTX 2050 (GA107, 10de:25ad) plus Radeon
  680M, KDE Plasma on Wayland, forky.
- Booted 7.2.6: nvidia, nvidia_modeset, nvidia_drm and nvidia_uvm load,
  nvidia-smi reports the GPU with driver 550.163.01, and the desktop works.

This is a local fix and I have only tested it on one machine, so please
review
it before using it. I hope it helps get a 7.2-compatible upload out.

Thanks,
Kevin Cuevas
diff -ruN orig/conftest.sh patched/conftest.sh
--- orig/conftest.sh	2026-06-11 06:33:08.000000000 -0600
+++ patched/conftest.sh	2026-09-24 11:40:21.371928925 -0600
@@ -3528,6 +3528,25 @@
             fi
         ;;
 
+        drm_atomic_commit_present)
+            #
+            # Local patch for Linux 7.2: determine if struct drm_atomic_state was renamed to
+            # struct drm_atomic_commit, by Linux kernel commit 5164f7e7ff8e
+            # ("drm: Rename struct drm_atomic_state to drm_atomic_commit") in v7.2.
+            # sizeof() requires the complete type, so this cannot give a false
+            # positive on older kernels.
+            #
+            CODE="
+            #if defined(NV_DRM_DRM_ATOMIC_H_PRESENT)
+            #include <drm/drm_atomic.h>
+            #endif
+            int conftest_drm_atomic_commit_present(void) {
+                return sizeof(struct drm_atomic_commit);
+            }"
+
+            compile_check_conftest "$CODE" "NV_DRM_ATOMIC_COMMIT_PRESENT" "" "types"
+        ;;
+
         drm_atomic_state_ref_counting)
             #
             # Determine if functions drm_atomic_state_get/put() are
diff -ruN orig/nvidia/linux_nvswitch.c patched/nvidia/linux_nvswitch.c
--- orig/nvidia/linux_nvswitch.c	2025-04-08 07:05:00.000000000 -0600
+++ patched/nvidia/linux_nvswitch.c	2026-09-24 11:40:21.371479365 -0600
@@ -2026,7 +2026,7 @@
         return -NVL_ERR_GENERIC;
     }
 
-    strncpy(regkey_val, regkey_val_start, regkey_val_len);
+    memcpy(regkey_val, regkey_val_start, regkey_val_len); /* Local patch for Linux 7.2 */
     regkey_val[regkey_val_len] = '\0';
 
     if (nvswitch_os_strtouint(regkey_val, data) != 0)
@@ -2381,7 +2381,17 @@
     NvLength length
 )
 {
-    return strncpy(dest, src, length);
+    /*
+     * Local patch for Linux 7.2: strncpy() was removed from the kernel. This wrapper is
+     * called from closed-source code, so keep the exact strncpy()
+     * semantics (copy, then zero-pad the remainder).
+     */
+    NvLength i;
+    for (i = 0; i < length && src[i] != '\0'; i++)
+        dest[i] = src[i];
+    for (; i < length; i++)
+        dest[i] = '\0';
+    return dest;
 }
 
 int
diff -ruN orig/nvidia/os-interface.c patched/nvidia/os-interface.c
--- orig/nvidia/os-interface.c	2026-06-11 06:33:08.000000000 -0600
+++ patched/nvidia/os-interface.c	2026-09-24 11:40:21.371194436 -0600
@@ -750,8 +750,7 @@
 void NV_API_CALL os_get_current_process_name(char *buf, NvU32 len)
 {
     task_lock(current);
-    strncpy(buf, current->comm, len - 1);
-    buf[len - 1] = '\0';
+    strscpy(buf, current->comm, len); /* Local patch for Linux 7.2 */
     task_unlock(current);
 }
 
diff -ruN orig/nvidia-drm/nvidia-drm-conftest.h patched/nvidia-drm/nvidia-drm-conftest.h
--- orig/nvidia-drm/nvidia-drm-conftest.h	2026-06-11 06:33:08.000000000 -0600
+++ patched/nvidia-drm/nvidia-drm-conftest.h	2026-09-24 11:40:21.376668766 -0600
@@ -215,4 +215,41 @@
 
 #endif /* defined(NV_BSD) */
 
+/*
+ * Local patch for Linux 7.2: Linux kernel commit 5164f7e7ff8e ("drm: Rename struct
+ * drm_atomic_state to drm_atomic_commit") renamed the struct and its helpers.
+ */
+#if defined(NV_DRM_ATOMIC_COMMIT_PRESENT)
+#define drm_atomic_state                 drm_atomic_commit
+#define drm_atomic_state_alloc           drm_atomic_commit_alloc
+#define drm_atomic_state_clear           drm_atomic_commit_clear
+#define drm_atomic_state_get             drm_atomic_commit_get
+#define drm_atomic_state_put             drm_atomic_commit_put
+#define drm_atomic_state_free            drm_atomic_commit_put
+#define drm_atomic_state_init            drm_atomic_commit_init
+#define drm_atomic_state_default_clear   drm_atomic_commit_default_clear
+#define drm_atomic_state_default_release drm_atomic_commit_default_release
+
+/*
+ * These conftests probe using the old 'struct drm_atomic_state' name, so they
+ * report false negatives on 7.2+. All of these features exist on any kernel
+ * that has struct drm_atomic_commit.
+ */
+#ifndef NV_DRM_ATOMIC_STATE_REF_COUNTING_PRESENT
+#define NV_DRM_ATOMIC_STATE_REF_COUNTING_PRESENT
+#endif
+#ifndef NV_DRM_CRTC_ATOMIC_CHECK_HAS_ATOMIC_STATE_ARG
+#define NV_DRM_CRTC_ATOMIC_CHECK_HAS_ATOMIC_STATE_ARG
+#endif
+#ifndef NV_DRM_PLANE_ATOMIC_CHECK_HAS_ATOMIC_STATE_ARG
+#define NV_DRM_PLANE_ATOMIC_CHECK_HAS_ATOMIC_STATE_ARG
+#endif
+#ifndef NV_DRM_ATOMIC_HELPER_SWAP_STATE_HAS_STALL_ARG
+#define NV_DRM_ATOMIC_HELPER_SWAP_STATE_HAS_STALL_ARG
+#endif
+#ifndef NV_DRM_ATOMIC_HELPER_SWAP_STATE_RETURN_INT
+#define NV_DRM_ATOMIC_HELPER_SWAP_STATE_RETURN_INT
+#endif
+#endif /* NV_DRM_ATOMIC_COMMIT_PRESENT */
+
 #endif /* defined(__NVIDIA_DRM_CONFTEST_H__) */
diff -ruN orig/nvidia-drm/nvidia-drm-sources.mk patched/nvidia-drm/nvidia-drm-sources.mk
--- orig/nvidia-drm/nvidia-drm-sources.mk	2026-06-11 06:33:08.000000000 -0600
+++ patched/nvidia-drm/nvidia-drm-sources.mk	2026-09-24 11:40:21.375196662 -0600
@@ -117,6 +117,7 @@
 NV_CONFTEST_TYPE_COMPILE_TESTS += drm_crtc_atomic_check_has_atomic_state_arg
 NV_CONFTEST_TYPE_COMPILE_TESTS += drm_gem_object_vmap_has_map_arg
 NV_CONFTEST_TYPE_COMPILE_TESTS += drm_plane_atomic_check_has_atomic_state_arg
+NV_CONFTEST_TYPE_COMPILE_TESTS += drm_atomic_commit_present
 NV_CONFTEST_TYPE_COMPILE_TESTS += drm_device_has_pdev
 NV_CONFTEST_TYPE_COMPILE_TESTS += drm_crtc_state_has_no_vblank
 NV_CONFTEST_TYPE_COMPILE_TESTS += drm_mode_config_has_allow_fb_modifiers
diff -ruN orig/nvidia-modeset/nvidia-modeset-linux.c patched/nvidia-modeset/nvidia-modeset-linux.c
--- orig/nvidia-modeset/nvidia-modeset-linux.c	2026-06-11 06:33:08.000000000 -0600
+++ patched/nvidia-modeset/nvidia-modeset-linux.c	2026-09-24 11:40:21.371588341 -0600
@@ -351,7 +351,17 @@
 
 char* nvkms_strncpy(char *dest, const char *src, size_t n)
 {
-    return strncpy(dest, src, n);
+    /*
+     * Local patch for Linux 7.2: strncpy() was removed from the kernel. This wrapper is
+     * called from closed-source code, so keep the exact strncpy()
+     * semantics (copy, then zero-pad the remainder).
+     */
+    size_t i;
+    for (i = 0; i < n && src[i] != '\0'; i++)
+        dest[i] = src[i];
+    for (; i < n; i++)
+        dest[i] = '\0';
+    return dest;
 }
 
 void nvkms_usleep(NvU64 usec)
diff -ruN orig/nvidia-uvm/uvm_pmm_gpu.c patched/nvidia-uvm/uvm_pmm_gpu.c
--- orig/nvidia-uvm/uvm_pmm_gpu.c	2025-04-08 07:05:14.000000000 -0600
+++ patched/nvidia-uvm/uvm_pmm_gpu.c	2026-09-24 11:40:21.371337056 -0600
@@ -3038,7 +3038,7 @@
             size_t size;
             size_t align;
             if (level == 0) {
-                strncpy(chunk_split_cache[level].name, "uvm_gpu_chunk_t", sizeof(chunk_split_cache[level].name) - 1);
+                strscpy(chunk_split_cache[level].name, "uvm_gpu_chunk_t", sizeof(chunk_split_cache[level].name)); /* Local patch for Linux 7.2 */
                 size = sizeof(uvm_gpu_chunk_t);
                 align = __alignof__(uvm_gpu_chunk_t);
             } else {

Reply via email to