Control: tags -1 + patch

The attached patch makes the open kernel modules from
nvidia-graphics-drivers 550.163.01-4 (550.163.01) -- binary package
nvidia-open-kernel-dkms, DKMS module nvidia-current-open -- build and
run on Linux 7.1.3+deb14-amd64 (current sid).All behavioural
changes are conftest-guarded or rely on interfaces available throughout
the package's supported kernel range, so the tree remains buildable on
pre-7.x kernels (verified, see below).

The patch incorporates Damir Islamov's earlier VMA-locking fix from
this bug, with two adjustments:

 * the nv_is_vma_write_locked() helper is defined in nvidia/nv-mmap.c
   rather than common/inc/nv-mm.h, as the original hunk does not apply
   against the 550 tree's nv-mm.h;
 * the is_vma_write_locked_has_mm_lock_seq_arg conftest is registered
   in nvidia.Kbuild -- without registration the test never runs, the
   NV_IS_VMA_WRITE_LOCKED_HAS_MM_LOCK_SEQ_ARG macro is never defined,
   and the single-argument path is unconditionally selected, which
   would break the build on older kernels.

Additional Linux 7.x API changes addressed (new conftest tests
pci_resize_resource_has_exclude_bars_arg, dma_map_ops_has_map_resource,
dev_pagemap_ops_has_folio_free, zone_device_page_init_has_pgmap_arg;
registered in nvidia.Kbuild and nvidia-uvm.Kbuild respectively):

 * in_irq() removed: call sites use in_hardirq() (present since 5.11)
   with a preprocessor fallback in nv-time.h for older kernels
   (common/inc/nv-time.h, nvidia/os-interface.c);
 * __vm_flags removed from vm_area_struct: use __vm_flags_mod(), which
   is present on all kernels that can reach the affected
   !NV_CAN_CALL_VMA_START_WRITE branch and does not re-acquire the VMA
   write lock already taken by nv_vma_start_write()
   (common/inc/nv-mm.h);
 * pci_resize_resource() gained an exclude_bars argument: pass 0,
   conftest-guarded (nvidia/nv-pci.c);
 * dma_map_ops lost its .map_resource member: report resource mapping
   as usable when the member is absent, since the 7.x DMA core handles
   dma_map_resource() generically (nvidia/nv-dma.c);
 * ZONE_DEVICE folio conversion: .folio_free callback wrapper and
   3-argument zone_device_page_init(), both conftest-guarded
   (nvidia-uvm/uvm_pmm_gpu.c, nvidia-uvm/uvm_hmm.c);
 * legacy DRM_ERROR/DRM_WARN/DRM_INFO/DRM_DEBUG/DRM_DEBUG_DRIVER
   macros removed: #ifndef-guarded pr_* shims, no-ops where the
   macros still exist (nvidia-drm/nvidia-drm-priv.h);
 * atomic-state iterator fallbacks read the removed .state member:
   switched to .new_state, present since 4.12 and semantically
   identical at the pre-commit atomic_check call sites
   (nvidia-drm/nvidia-drm-helper.h);
 * struct drm_mode_create_dumb no longer visible transitively in
   nvidia-drm-gem-nvkms-memory.h, causing a prototype-scoped struct
   and a conflicting-types error: forward declaration added;
 * dma_fence_signal()/dma_fence_signal_locked() now return void: the
   nv_dma_fence_* wrappers discard the return and report success,
   which compiles on all supported kernels.

Tested with NVIDIA GeForce RTX 4060 Laptop GPU:
 * Runtime-tested (modules load, nvidia-smi, desktop session) on
   7.1.3+deb14-amd64, 6.12.17-amd64, 6.17.13+deb14-amd64.
 * Build-tested on: 6.12.17-amd64,6.17.12+deb14-amd64
6.17.13+deb14-amd64,6.17.7+deb14+1-amd64
6.18.10+deb14-amd64,6.18.15+deb14-amd64 6.18.8+deb14-amd64,7.1.3+deb14-amd64.
   The legacy conftest branches are selected on the pre-7.x kernels
   and the new branches on 7.1.3, as intended.

All building and testing was done with the open flavor
(nvidia-open-kernel-dkms / nvidia-current-open). The patch only touches
kernel-interface files shared between flavors (conftest.sh, common/inc,
nvidia/, nvidia-drm/, nvidia-uvm/), so it should equally fix the
proprietary nvidia-kernel-dkms build against 7.x, but I have not built
that flavor and cannot confirm. The issue matches #1135362, which was
filed against nvidia-kernel-dkms.

One further note: on 7.1.3 the final module link initially fails in
linux-kbuild's scripts/gen-btf.sh (7.1.3-1), where the awk-wrapper
PAHOLE variable is expanded without eval, so its embedded quoting
reaches awk verbatim. That affects all out-of-tree modules and is
reported separately with a patch as #1141979.


-- System Information:
Debian Release: forky/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 7.1.3+deb14-amd64 (SMP w/32 CPU threads; PREEMPT)
Kernel taint flags: TAINT_OOT_MODULE
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
--- a/common/inc/nv-mm.h        2025-11-20 01:08:25.000000000 +0200
+++ b/common/inc/nv-mm.h        2026-07-13 09:50:45.946894840 +0300
@@ -312,7 +312,7 @@
 {
 #if !NV_CAN_CALL_VMA_START_WRITE
     nv_vma_start_write(vma);
-    ACCESS_PRIVATE(vma, __vm_flags) |= flags;
+    __vm_flags_mod(vma, flags, 0);
 #elif defined(NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS)
     vm_flags_set(vma, flags);
 #else
@@ -324,7 +324,7 @@
 {
 #if !NV_CAN_CALL_VMA_START_WRITE
     nv_vma_start_write(vma);
-    ACCESS_PRIVATE(vma, __vm_flags) &= ~flags;
+    __vm_flags_mod(vma, 0, flags);
 #elif defined(NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS)
     vm_flags_clear(vma, flags);
 #else
--- a/common/inc/nv-time.h      2025-04-08 15:25:44.000000000 +0300
+++ b/common/inc/nv-time.h      2026-07-13 09:50:45.947036304 +0300
@@ -32,6 +32,16 @@
 
 #include <nvstatus.h>
 
+#include <linux/preempt.h>
+
+/*
+ * in_irq() was removed in Linux 7.x; its replacement in_hardirq() has
+ * been available since Linux 5.11. Fall back for older kernels.
+ */
+#if !defined(in_hardirq)
+#define in_hardirq() in_irq()
+#endif
+
 #define NV_MAX_ISR_DELAY_US           20000
 #define NV_MAX_ISR_DELAY_MS           (NV_MAX_ISR_DELAY_US / 1000)
 #define NV_NSECS_TO_JIFFIES(nsec)     ((nsec) * HZ / 1000000000)
@@ -142,7 +152,7 @@
     ktime_get_raw_ts64(&tm1);
 #endif
 
-    if (in_irq() && (us > NV_MAX_ISR_DELAY_US))
+    if (in_hardirq() && (us > NV_MAX_ISR_DELAY_US))
         return NV_ERR_GENERIC;
 
     mdelay_safe_msec = us / 1000;
@@ -187,7 +197,7 @@
     tm_start = tm_aux;
 #endif
 
-    if (in_irq() && (ms > NV_MAX_ISR_DELAY_MS))
+    if (in_hardirq() && (ms > NV_MAX_ISR_DELAY_MS))
     {
         return NV_ERR_GENERIC;
     }
--- a/conftest.sh       2025-11-20 01:08:25.000000000 +0200
+++ b/conftest.sh       2026-07-13 09:50:45.947427653 +0300
@@ -7195,6 +7195,87 @@
             compile_check_conftest "$CODE" 
"NV_DRM_CONNECTOR_HELPER_FUNCS_MODE_VALID_HAS_CONST_MODE_ARG" "" "types"
         ;;
 
+        is_vma_write_locked_has_mm_lock_seq_arg)
+            #
+            # Determine if __is_vma_write_locked() takes only a single
+            # 'struct vm_area_struct *' argument.
+            #
+            # Commit 22f7639f2f03 ("mm/vma: improve and document
+            # __is_vma_write_locked()") removed the 'unsigned int *mm_lock_seq'
+            # parameter in v7.0-rc1.
+            #
+            CODE="
+            #include <linux/mm.h>
+            #include <linux/mmap_lock.h>
+            int conftest_is_vma_write_locked_has_mm_lock_seq_arg(struct 
vm_area_struct *vma) {
+                unsigned int mm_lock_seq;
+                return __is_vma_write_locked(vma, &mm_lock_seq);
+            }"
+
+            compile_check_conftest "$CODE" 
"NV_IS_VMA_WRITE_LOCKED_HAS_MM_LOCK_SEQ_ARG" "" "types"
+        ;;
+
+        pci_resize_resource_has_exclude_bars_arg)
+            #
+            # Determine if pci_resize_resource() takes the 'exclude_bars'
+            # argument, added in Linux v7.0.
+            #
+            CODE="
+            #include <linux/pci.h>
+            int conftest_pci_resize_resource_has_exclude_bars_arg(struct 
pci_dev *dev) {
+                return pci_resize_resource(dev, 0, 0, 0);
+            }"
+
+            compile_check_conftest "$CODE" 
"NV_PCI_RESIZE_RESOURCE_HAS_EXCLUDE_BARS_ARG" "" "types"
+        ;;
+
+        dma_map_ops_has_map_resource)
+            #
+            # Determine if struct dma_map_ops has the 'map_resource'
+            # member, removed in Linux v7.x when resource mapping moved
+            # into the DMA core.
+            #
+            CODE="
+            #include <linux/dma-mapping.h>
+            #if defined(NV_LINUX_DMA_MAP_OPS_H_PRESENT)
+            #include <linux/dma-map-ops.h>
+            #endif
+            int conftest_dma_map_ops_has_map_resource(void) {
+                return offsetof(struct dma_map_ops, map_resource);
+            }"
+
+            compile_check_conftest "$CODE" "NV_DMA_MAP_OPS_HAS_MAP_RESOURCE" 
"" "types"
+        ;;
+
+        dev_pagemap_ops_has_folio_free)
+            #
+            # Determine if struct dev_pagemap_ops has the 'folio_free'
+            # callback, which replaced 'page_free' in Linux v7.x as part
+            # of the ZONE_DEVICE folio conversion.
+            #
+            CODE="
+            #include <linux/memremap.h>
+            int conftest_dev_pagemap_ops_has_folio_free(void) {
+                return offsetof(struct dev_pagemap_ops, folio_free);
+            }"
+
+            compile_check_conftest "$CODE" "NV_DEV_PAGEMAP_OPS_HAS_FOLIO_FREE" 
"" "types"
+        ;;
+
+        zone_device_page_init_has_pgmap_arg)
+            #
+            # Determine if zone_device_page_init() takes the pgmap and
+            # order arguments (Linux v7.x).
+            #
+            CODE="
+            #include <linux/memremap.h>
+            void conftest_zone_device_page_init_has_pgmap_arg(struct page 
*page, struct dev_pagemap *pgmap) {
+                zone_device_page_init(page, pgmap, 0);
+            }"
+
+            compile_check_conftest "$CODE" 
"NV_ZONE_DEVICE_PAGE_INIT_HAS_PGMAP_ARG" "" "types"
+        ;;
+
         # When adding a new conftest entry, please use the correct format for
         # specifying the relevant upstream Linux kernel commit.  Please
         # avoid specifying -rc kernels, and only use SHAs that actually exist
--- a/nvidia/nv-dma.c   2025-04-08 15:25:36.000000000 +0300
+++ b/nvidia/nv-dma.c   2026-07-13 09:50:45.947993210 +0300
@@ -796,8 +796,15 @@
 #endif
     }
 
+#if defined(NV_DMA_MAP_OPS_HAS_MAP_RESOURCE)
     return (ops->map_resource != NULL);
 #else
+    /* Linux 7.x removed .map_resource from dma_map_ops; the DMA core
+     * handles dma_map_resource() generically for all ops. Unsupported
+     * devices report DMA_MAPPING_ERROR at map time. */
+    return NV_TRUE;
+#endif
+#else
     return NV_FALSE;
 #endif
 }
--- a/nvidia/nvidia.Kbuild      2025-11-20 01:08:25.000000000 +0200
+++ b/nvidia/nvidia.Kbuild      2026-07-13 09:50:45.948139736 +0300
@@ -241,6 +241,9 @@
 NV_CONFTEST_SYMBOL_COMPILE_TESTS += 
is_export_symbol_gpl_iommu_dev_enable_feature
 NV_CONFTEST_SYMBOL_COMPILE_TESTS += 
is_export_symbol_gpl_iommu_dev_disable_feature
 
+NV_CONFTEST_TYPE_COMPILE_TESTS += is_vma_write_locked_has_mm_lock_seq_arg
+NV_CONFTEST_TYPE_COMPILE_TESTS += pci_resize_resource_has_exclude_bars_arg
+NV_CONFTEST_TYPE_COMPILE_TESTS += dma_map_ops_has_map_resource
 NV_CONFTEST_TYPE_COMPILE_TESTS += dma_ops
 NV_CONFTEST_TYPE_COMPILE_TESTS += swiotlb_dma_ops
 NV_CONFTEST_TYPE_COMPILE_TESTS += noncoherent_swiotlb_dma_ops
--- a/nvidia/nv-mmap.c  2025-11-20 01:08:25.000000000 +0200
+++ b/nvidia/nv-mmap.c  2026-07-13 09:50:45.948251620 +0300
@@ -839,15 +839,32 @@
 }
 
 #if !NV_CAN_CALL_VMA_START_WRITE
+
+#if defined(VM_REFCNT_EXCLUDE_READERS_FLAG)
+#define NV_VMA_LOCK_OFFSET VM_REFCNT_EXCLUDE_READERS_FLAG
+#else
+#define NV_VMA_LOCK_OFFSET VMA_LOCK_OFFSET
+#endif
+
+static inline int nv_is_vma_write_locked(struct vm_area_struct *vma, unsigned 
int *mm_lock_seq)
+{
+#if defined(NV_IS_VMA_WRITE_LOCKED_HAS_MM_LOCK_SEQ_ARG)
+    return __is_vma_write_locked(vma, mm_lock_seq);
+#else
+    *mm_lock_seq = __vma_raw_mm_seqnum(vma);
+    return __is_vma_write_locked(vma);
+#endif
+}
+
 static NvBool nv_vma_enter_locked(struct vm_area_struct *vma, NvBool detaching)
 {
-    NvU32 tgt_refcnt = VMA_LOCK_OFFSET;
+    NvU32 tgt_refcnt = NV_VMA_LOCK_OFFSET;
     NvBool interrupted = NV_FALSE;
     if (!detaching)
     {
         tgt_refcnt++;
     }
-    if (!refcount_add_not_zero(VMA_LOCK_OFFSET, &vma->vm_refcnt))
+    if (!refcount_add_not_zero(NV_VMA_LOCK_OFFSET, &vma->vm_refcnt))
     {
         return NV_FALSE;
     }
@@ -877,7 +894,7 @@
     if (interrupted)
     {
         // Clean up on error: release refcount and dep_map
-        refcount_sub_and_test(VMA_LOCK_OFFSET, &vma->vm_refcnt);
+        refcount_sub_and_test(NV_VMA_LOCK_OFFSET, &vma->vm_refcnt);
         rwsem_release(&vma->vmlock_dep_map, _RET_IP_);
         return NV_FALSE;
     }
@@ -893,7 +910,7 @@
 {
     NvU32 mm_lock_seq;
     NvBool locked;
-    if (__is_vma_write_locked(vma, &mm_lock_seq))
+    if (nv_is_vma_write_locked(vma, &mm_lock_seq))
         return;
 
     locked = nv_vma_enter_locked(vma, NV_FALSE);
@@ -902,7 +919,7 @@
     if (locked)
     {
         NvBool detached;
-        detached = refcount_sub_and_test(VMA_LOCK_OFFSET, &vma->vm_refcnt);
+        detached = refcount_sub_and_test(NV_VMA_LOCK_OFFSET, &vma->vm_refcnt);
         rwsem_release(&vma->vmlock_dep_map, _RET_IP_);
         WARN_ON_ONCE(detached);
     }
--- a/nvidia/nv-pci.c   2025-04-08 15:25:36.000000000 +0300
+++ b/nvidia/nv-pci.c   2026-07-13 09:50:45.948394382 +0300
@@ -234,8 +234,13 @@
 
 resize:
     /* Attempt to resize BAR1 to the largest supported size */
+#if defined(NV_PCI_RESIZE_RESOURCE_HAS_EXCLUDE_BARS_ARG)
+    /* Linux 7.x: exclude_bars=0 preserves prior behavior; this driver
+     * already releases and relocates BAR3 manually. */
+    r = pci_resize_resource(pci_dev, NV_GPU_BAR1, requested_size, 0);
+#else
     r = pci_resize_resource(pci_dev, NV_GPU_BAR1, requested_size);
-
+#endif
     if (r) {
         if (r == -ENOSPC)
         {
--- a/nvidia/os-interface.c     2025-04-08 15:25:37.000000000 +0300
+++ b/nvidia/os-interface.c     2026-07-13 09:50:45.948573909 +0300
@@ -363,7 +363,7 @@
 
 NvBool NV_API_CALL os_is_isr(void)
 {
-    return (in_irq());
+    return (in_hardirq());
 }
 
 // return TRUE if the caller is the super-user
--- a/nvidia-drm/nvidia-dma-fence-helper.h      2025-04-08 15:08:41.000000000 
+0300
+++ b/nvidia-drm/nvidia-dma-fence-helper.h      2026-07-13 09:50:45.949046784 
+0300
@@ -97,7 +97,8 @@
 #if defined(NV_LINUX_FENCE_H_PRESENT)
     return fence_signal(fence);
 #else
-    return dma_fence_signal(fence);
+    dma_fence_signal(fence);
+    return 0;
 #endif
 }
 
@@ -105,7 +106,8 @@
 #if defined(NV_LINUX_FENCE_H_PRESENT)
     return fence_signal_locked(fence);
 #else
-    return dma_fence_signal_locked(fence);
+    dma_fence_signal_locked(fence);
+    return 0;
 #endif
 }
 
--- a/nvidia-drm/nvidia-drm-gem-nvkms-memory.h  2025-04-08 15:08:42.000000000 
+0300
+++ b/nvidia-drm/nvidia-drm-gem-nvkms-memory.h  2026-07-13 09:50:45.949144058 
+0300
@@ -80,6 +80,8 @@
     return to_nv_nvkms_memory(nv_gem);
 }
 
+struct drm_mode_create_dumb;
+
 int nv_drm_dumb_create(
     struct drm_file *file_priv,
     struct drm_device *dev, struct drm_mode_create_dumb *args);
--- a/nvidia-drm/nvidia-drm-helper.h    2025-04-08 15:08:41.000000000 +0300
+++ b/nvidia-drm/nvidia-drm-helper.h    2026-07-13 09:50:45.949237669 +0300
@@ -246,7 +246,7 @@
        for ((__i) = 0;                                                      \
             (__i) < (__state)->num_connector &&                             \
             ((connector) = (__state)->connectors[__i].ptr,                  \
-            (connector_state) = (__state)->connectors[__i].state, 1);       \
+            (connector_state) = (__state)->connectors[__i].new_state, 1);   \
             (__i)++)                                                        \
                for_each_if (connector)
 #else
@@ -273,7 +273,7 @@
        for ((__i) = 0;                                                \
             (__i) < (__state)->dev->mode_config.num_crtc &&           \
             ((crtc) = (__state)->crtcs[__i].ptr,                      \
-            (crtc_state) = (__state)->crtcs[__i].state, 1);           \
+            (crtc_state) = (__state)->crtcs[__i].new_state, 1);       \
             (__i)++)                                                  \
                for_each_if (crtc_state)
 #else
@@ -298,7 +298,7 @@
        for ((__i) = 0;                                                   \
             (__i) < (__state)->dev->mode_config.num_total_plane &&       \
             ((plane) = (__state)->planes[__i].ptr,                       \
-            (plane_state) = (__state)->planes[__i].state, 1);            \
+            (plane_state) = (__state)->planes[__i].new_state, 1);        \
             (__i)++)                                                     \
                for_each_if (plane_state)
 #else
--- a/nvidia-drm/nvidia-drm-priv.h      2025-04-08 15:08:41.000000000 +0300
+++ b/nvidia-drm/nvidia-drm-priv.h      2026-07-13 09:50:45.949342327 +0300
@@ -43,6 +43,22 @@
 
 #include "nvkms-kapi.h"
 
+#ifndef DRM_ERROR
+#define DRM_ERROR(fmt, ...) pr_err("[drm] *ERROR* " fmt, ##__VA_ARGS__)
+#endif
+#ifndef DRM_WARN
+#define DRM_WARN(fmt, ...)  pr_warn("[drm] " fmt, ##__VA_ARGS__)
+#endif
+#ifndef DRM_INFO
+#define DRM_INFO(fmt, ...)  pr_info("[drm] " fmt, ##__VA_ARGS__)
+#endif
+#ifndef DRM_DEBUG
+#define DRM_DEBUG(fmt, ...) pr_debug("[drm] " fmt, ##__VA_ARGS__)
+#endif
+#ifndef DRM_DEBUG_DRIVER
+#define DRM_DEBUG_DRIVER(fmt, ...) pr_debug("[drm:driver] " fmt, ##__VA_ARGS__)
+#endif
+
 #define NV_DRM_LOG_ERR(__fmt, ...) \
     DRM_ERROR("[nvidia-drm] " __fmt "\n", ##__VA_ARGS__)
 
--- a/nvidia-uvm/nvidia-uvm.Kbuild      2025-11-20 01:08:25.000000000 +0200
+++ b/nvidia-uvm/nvidia-uvm.Kbuild      2026-07-13 09:50:45.949853486 +0300
@@ -72,6 +72,8 @@
 NV_CONFTEST_FUNCTION_COMPILE_TESTS += folio_test_swapcache
 NV_CONFTEST_FUNCTION_COMPILE_TESTS += page_pgmap
 
+NV_CONFTEST_TYPE_COMPILE_TESTS += dev_pagemap_ops_has_folio_free
+NV_CONFTEST_TYPE_COMPILE_TESTS += zone_device_page_init_has_pgmap_arg
 NV_CONFTEST_TYPE_COMPILE_TESTS += backing_dev_info
 NV_CONFTEST_TYPE_COMPILE_TESTS += mm_context_t
 NV_CONFTEST_TYPE_COMPILE_TESTS += get_user_pages_remote
--- a/nvidia-uvm/uvm_hmm.c      2025-11-20 01:08:25.000000000 +0200
+++ b/nvidia-uvm/uvm_hmm.c      2026-07-13 09:50:45.950067037 +0300
@@ -1990,7 +1990,11 @@
 
     hmm_mark_gpu_chunk_referenced(va_block, gpu, gpu_chunk);
     UVM_ASSERT(!page_count(dpage));
+#if defined(NV_ZONE_DEVICE_PAGE_INIT_HAS_PGMAP_ARG)
+    zone_device_page_init(dpage, page_pgmap(dpage), 0);
+#else
     zone_device_page_init(dpage);
+#endif
     dpage->zone_device_data = va_block->hmm.va_space;
 
     dst_pfns[page_index] = migrate_pfn(pfn);
--- a/nvidia-uvm/uvm_pmm_gpu.c  2025-11-20 01:08:25.000000000 +0200
+++ b/nvidia-uvm/uvm_pmm_gpu.c  2026-07-13 09:50:45.950828156 +0300
@@ -3456,9 +3456,20 @@
     UVM_ENTRY_RET(devmem_fault(vmf));
 }
 
+#if defined(NV_DEV_PAGEMAP_OPS_HAS_FOLIO_FREE)
+static void devmem_folio_free(struct folio *folio)
+{
+    devmem_page_free(&folio->page);
+}
+#endif
+
 static const struct dev_pagemap_ops uvm_pmm_devmem_ops =
 {
+#if defined(NV_DEV_PAGEMAP_OPS_HAS_FOLIO_FREE)
+    .folio_free = devmem_folio_free,
+#else
     .page_free = devmem_page_free,
+#endif
     .migrate_to_ram = devmem_fault_entry,
 };
 

Reply via email to