diff --git a/graphics/nvidia-drm-515-kmod-580/Makefile b/graphics/nvidia-drm-515-kmod-580/Makefile index 5811c6c05558..6b237d7df0ca 100644 --- a/graphics/nvidia-drm-515-kmod-580/Makefile +++ b/graphics/nvidia-drm-515-kmod-580/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 580.159.04 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 2 +PORTREVISION= 3 MASTERDIR= ${.CURDIR}/../nvidia-drm-515-kmod PKGNAMESUFFIX= -580 .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-515-kmod-devel/Makefile b/graphics/nvidia-drm-515-kmod-devel/Makefile index a12d6ca6d511..3017edd24efc 100644 --- a/graphics/nvidia-drm-515-kmod-devel/Makefile +++ b/graphics/nvidia-drm-515-kmod-devel/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 610.43.02 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 1 +PORTREVISION= 2 MASTERDIR= ${.CURDIR}/../nvidia-drm-515-kmod PKGNAMESUFFIX= -devel .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-515-kmod/Makefile b/graphics/nvidia-drm-515-kmod/Makefile index 0766514f6d54..fc5f1f0fbdc2 100644 --- a/graphics/nvidia-drm-515-kmod/Makefile +++ b/graphics/nvidia-drm-515-kmod/Makefile @@ -1,11 +1,11 @@ PORTNAME= nvidia-drm-515-kmod -PORTREVISION= 0 +PORTREVISION= 1 CATEGORIES= graphics RUN_DEPENDS+= ${KMODDIR}/drm.ko:graphics/drm-515-kmod CONFLICTS_INSTALL= nvidia-drm-61-kmod* nvidia-drm-66-kmod* nvidia-drm-612-kmod* nvidia-drm-latest-kmod* .include "${.CURDIR}/../drm-515-kmod/Makefile.version" .include "${.CURDIR}/../nvidia-drm-kmod/Makefile.common" .include diff --git a/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c b/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c new file mode 100644 index 000000000000..4ca6b309249d --- /dev/null +++ b/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c @@ -0,0 +1,54 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-nvkms-memory.c.orig nvidia-drm-gem-nvkms-memory.c +index 60f490f89dca..6aa0e40bcb1a 100644 +--- nvidia-drm-gem-nvkms-memory.c.orig ++++ nvidia-drm-gem-nvkms-memory.c +@@ -124,22 +124,12 @@ static vm_fault_t __nv_drm_gem_nvkms_handle_vma_fault( + unsigned long page_offset, pfn; + vm_fault_t ret; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + + if (nv_nvkms_memory->pages_count == 0) { + pfn = (unsigned long)(uintptr_t)nv_nvkms_memory->pPhysicalAddress; + pfn >>= PAGE_SHIFT; +-#if defined(NV_LINUX) +- /* +- * FreeBSD doesn't set pgoff. We instead have pfn be the base physical +- * address, and we will calculate the index pidx from the virtual address. +- * +- * This only works because linux_cdev_pager_populate passes the pidx as +- * vmf->virtual_address. Then we turn the virtual address +- * into a physical page number. +- */ + pfn += page_offset; +-#endif + } else { + BUG_ON(page_offset >= nv_nvkms_memory->pages_count); + pfn = page_to_pfn(nv_nvkms_memory->pages[page_offset]); diff --git a/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-gem-user-memory.c b/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-gem-user-memory.c new file mode 100644 index 000000000000..2bd7c897a50e --- /dev/null +++ b/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-gem-user-memory.c @@ -0,0 +1,39 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-user-memory.c.orig nvidia-drm-gem-user-memory.c +index 5ce0ba890e52..0ca3a7e2e07d 100644 +--- nvidia-drm-gem-user-memory.c.orig ++++ nvidia-drm-gem-user-memory.c +@@ -144,7 +144,7 @@ static vm_fault_t __nv_drm_gem_user_memory_handle_vma_fault( + unsigned long page_offset; + unsigned long pfn; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + BUG_ON(page_offset >= nv_user_memory->pages_count); + pfn = page_to_pfn(nv_user_memory->pages[page_offset]); + diff --git a/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-gem.c b/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-gem.c deleted file mode 100644 index 5693b76d27c4..000000000000 --- a/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-gem.c +++ /dev/null @@ -1,18 +0,0 @@ ---- nvidia-drm-gem.c.orig 2023-12-29 19:08:23 UTC -+++ nvidia-drm-gem.c -@@ -68,15 +68,7 @@ void nv_drm_gem_free(struct drm_gem_object *gem) - #if !defined(NV_DRM_DRIVER_HAS_GEM_PRIME_CALLBACKS) && \ - defined(NV_DRM_GEM_OBJECT_VMAP_HAS_MAP_ARG) - --/* -- * The 'dma_buf_map' structure is renamed to 'iosys_map' by the commit -- * 7938f4218168 ("dma-buf-map: Rename to iosys-map"). -- */ --#if defined(NV_LINUX_IOSYS_MAP_H_PRESENT) --typedef struct iosys_map nv_sysio_map_t; --#else - typedef struct dma_buf_map nv_sysio_map_t; --#endif - - static int nv_drm_gem_vmap(struct drm_gem_object *gem, - nv_sysio_map_t *map) diff --git a/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-helper.h b/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-helper.h new file mode 100644 index 000000000000..6929f75cae28 --- /dev/null +++ b/graphics/nvidia-drm-515-kmod/files/patch-nvidia-drm-helper.h @@ -0,0 +1,60 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-helper.h.orig nvidia-drm-helper.h +index bc91858136b2..2ef27fced3c5 100644 +--- nvidia-drm-helper.h.orig ++++ nvidia-drm-helper.h +@@ -51,6 +51,29 @@ + #define NV_DRM_USE_EXTENDED_PROPERTIES (DRM_OBJECT_MAX_PROPERTY >= 64) + + #include ++#include ++#include ++ ++/* ++ * nv_drm_vma_fault_get_page_offset - compute GEM page offset from a vm_fault ++ * ++ * On Linux, vmf->pgoff carries the file-level page index set by the VM. ++ * On FreeBSD, linux_cdev_pager_populate() sets vmf->pgoff = 0 and instead ++ * passes the page index (pidx) via vmf->virtual_address as IDX_TO_OFF(pidx). ++ * Convert back with OFF_TO_IDX and subtract the GEM vma_node start to get ++ * the page offset within the GEM object. ++ */ ++static inline unsigned long ++nv_drm_vma_fault_get_page_offset(struct vm_fault *vmf, ++ struct drm_gem_object *gem) ++{ ++#if defined(NV_LINUX) ++ unsigned long offset = vmf->pgoff; ++#else ++ unsigned long offset = OFF_TO_IDX((uintptr_t)vmf->virtual_address); ++#endif ++ return offset - drm_vma_node_start(&gem->vma_node); ++} + + static inline struct sg_table* + nv_drm_prime_pages_to_sg(struct drm_device *dev, diff --git a/graphics/nvidia-drm-61-kmod-580/Makefile b/graphics/nvidia-drm-61-kmod-580/Makefile index 44e7a72a1f5e..18f21da3b96f 100644 --- a/graphics/nvidia-drm-61-kmod-580/Makefile +++ b/graphics/nvidia-drm-61-kmod-580/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 580.159.04 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 2 +PORTREVISION= 3 MASTERDIR= ${.CURDIR}/../nvidia-drm-61-kmod PKGNAMESUFFIX= -580 .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-61-kmod-devel/Makefile b/graphics/nvidia-drm-61-kmod-devel/Makefile index 39b3624484ef..8902aa09a1f5 100644 --- a/graphics/nvidia-drm-61-kmod-devel/Makefile +++ b/graphics/nvidia-drm-61-kmod-devel/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 610.43.02 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 1 +PORTREVISION= 2 MASTERDIR= ${.CURDIR}/../nvidia-drm-61-kmod PKGNAMESUFFIX= -devel .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-61-kmod/Makefile b/graphics/nvidia-drm-61-kmod/Makefile index 8f941b48148d..0ff6e9ca78d2 100644 --- a/graphics/nvidia-drm-61-kmod/Makefile +++ b/graphics/nvidia-drm-61-kmod/Makefile @@ -1,11 +1,11 @@ PORTNAME= nvidia-drm-61-kmod -PORTREVISION= 0 +PORTREVISION= 1 CATEGORIES= graphics RUN_DEPENDS+= ${KMODDIR}/drm.ko:graphics/drm-61-kmod CONFLICTS_INSTALL= nvidia-drm-515-kmod* nvidia-drm-66-kmod* nvidia-drm-612-kmod* nvidia-drm-latest-kmod* .include "${.CURDIR}/../drm-61-kmod/Makefile.version" .include "${.CURDIR}/../nvidia-drm-kmod/Makefile.common" .include diff --git a/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c b/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c new file mode 100644 index 000000000000..4ca6b309249d --- /dev/null +++ b/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c @@ -0,0 +1,54 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-nvkms-memory.c.orig nvidia-drm-gem-nvkms-memory.c +index 60f490f89dca..6aa0e40bcb1a 100644 +--- nvidia-drm-gem-nvkms-memory.c.orig ++++ nvidia-drm-gem-nvkms-memory.c +@@ -124,22 +124,12 @@ static vm_fault_t __nv_drm_gem_nvkms_handle_vma_fault( + unsigned long page_offset, pfn; + vm_fault_t ret; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + + if (nv_nvkms_memory->pages_count == 0) { + pfn = (unsigned long)(uintptr_t)nv_nvkms_memory->pPhysicalAddress; + pfn >>= PAGE_SHIFT; +-#if defined(NV_LINUX) +- /* +- * FreeBSD doesn't set pgoff. We instead have pfn be the base physical +- * address, and we will calculate the index pidx from the virtual address. +- * +- * This only works because linux_cdev_pager_populate passes the pidx as +- * vmf->virtual_address. Then we turn the virtual address +- * into a physical page number. +- */ + pfn += page_offset; +-#endif + } else { + BUG_ON(page_offset >= nv_nvkms_memory->pages_count); + pfn = page_to_pfn(nv_nvkms_memory->pages[page_offset]); diff --git a/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-gem-user-memory.c b/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-gem-user-memory.c new file mode 100644 index 000000000000..2bd7c897a50e --- /dev/null +++ b/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-gem-user-memory.c @@ -0,0 +1,39 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-user-memory.c.orig nvidia-drm-gem-user-memory.c +index 5ce0ba890e52..0ca3a7e2e07d 100644 +--- nvidia-drm-gem-user-memory.c.orig ++++ nvidia-drm-gem-user-memory.c +@@ -144,7 +144,7 @@ static vm_fault_t __nv_drm_gem_user_memory_handle_vma_fault( + unsigned long page_offset; + unsigned long pfn; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + BUG_ON(page_offset >= nv_user_memory->pages_count); + pfn = page_to_pfn(nv_user_memory->pages[page_offset]); + diff --git a/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-helper.h b/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-helper.h new file mode 100644 index 000000000000..6929f75cae28 --- /dev/null +++ b/graphics/nvidia-drm-61-kmod/files/patch-nvidia-drm-helper.h @@ -0,0 +1,60 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-helper.h.orig nvidia-drm-helper.h +index bc91858136b2..2ef27fced3c5 100644 +--- nvidia-drm-helper.h.orig ++++ nvidia-drm-helper.h +@@ -51,6 +51,29 @@ + #define NV_DRM_USE_EXTENDED_PROPERTIES (DRM_OBJECT_MAX_PROPERTY >= 64) + + #include ++#include ++#include ++ ++/* ++ * nv_drm_vma_fault_get_page_offset - compute GEM page offset from a vm_fault ++ * ++ * On Linux, vmf->pgoff carries the file-level page index set by the VM. ++ * On FreeBSD, linux_cdev_pager_populate() sets vmf->pgoff = 0 and instead ++ * passes the page index (pidx) via vmf->virtual_address as IDX_TO_OFF(pidx). ++ * Convert back with OFF_TO_IDX and subtract the GEM vma_node start to get ++ * the page offset within the GEM object. ++ */ ++static inline unsigned long ++nv_drm_vma_fault_get_page_offset(struct vm_fault *vmf, ++ struct drm_gem_object *gem) ++{ ++#if defined(NV_LINUX) ++ unsigned long offset = vmf->pgoff; ++#else ++ unsigned long offset = OFF_TO_IDX((uintptr_t)vmf->virtual_address); ++#endif ++ return offset - drm_vma_node_start(&gem->vma_node); ++} + + static inline struct sg_table* + nv_drm_prime_pages_to_sg(struct drm_device *dev, diff --git a/graphics/nvidia-drm-612-kmod-580/Makefile b/graphics/nvidia-drm-612-kmod-580/Makefile index 30f4499ebec1..9462932f1424 100644 --- a/graphics/nvidia-drm-612-kmod-580/Makefile +++ b/graphics/nvidia-drm-612-kmod-580/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 580.159.04 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 1 +PORTREVISION= 2 MASTERDIR= ${.CURDIR}/../nvidia-drm-612-kmod PKGNAMESUFFIX= -580 .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-612-kmod-devel/Makefile b/graphics/nvidia-drm-612-kmod-devel/Makefile index 0587df6f2cc2..57d0cb4b2c2b 100644 --- a/graphics/nvidia-drm-612-kmod-devel/Makefile +++ b/graphics/nvidia-drm-612-kmod-devel/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 610.43.02 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 1 +PORTREVISION= 2 MASTERDIR= ${.CURDIR}/../nvidia-drm-612-kmod PKGNAMESUFFIX= -devel .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-612-kmod/Makefile b/graphics/nvidia-drm-612-kmod/Makefile index 1467c5ad5ed4..daae7c7620d9 100644 --- a/graphics/nvidia-drm-612-kmod/Makefile +++ b/graphics/nvidia-drm-612-kmod/Makefile @@ -1,11 +1,11 @@ PORTNAME= nvidia-drm-612-kmod -PORTREVISION= 0 +PORTREVISION= 1 CATEGORIES= graphics RUN_DEPENDS+= ${KMODDIR}/drm.ko:graphics/drm-612-kmod CONFLICTS_INSTALL= nvidia-drm-515-kmod* nvidia-drm-61-kmod* nvidia-drm-66-kmod* nvidia-drm-latest-kmod* .include "${.CURDIR}/../drm-612-kmod/Makefile.version" .include "${.CURDIR}/../nvidia-drm-kmod/Makefile.common" .include diff --git a/graphics/nvidia-drm-612-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c b/graphics/nvidia-drm-612-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c new file mode 100644 index 000000000000..4ca6b309249d --- /dev/null +++ b/graphics/nvidia-drm-612-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c @@ -0,0 +1,54 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-nvkms-memory.c.orig nvidia-drm-gem-nvkms-memory.c +index 60f490f89dca..6aa0e40bcb1a 100644 +--- nvidia-drm-gem-nvkms-memory.c.orig ++++ nvidia-drm-gem-nvkms-memory.c +@@ -124,22 +124,12 @@ static vm_fault_t __nv_drm_gem_nvkms_handle_vma_fault( + unsigned long page_offset, pfn; + vm_fault_t ret; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + + if (nv_nvkms_memory->pages_count == 0) { + pfn = (unsigned long)(uintptr_t)nv_nvkms_memory->pPhysicalAddress; + pfn >>= PAGE_SHIFT; +-#if defined(NV_LINUX) +- /* +- * FreeBSD doesn't set pgoff. We instead have pfn be the base physical +- * address, and we will calculate the index pidx from the virtual address. +- * +- * This only works because linux_cdev_pager_populate passes the pidx as +- * vmf->virtual_address. Then we turn the virtual address +- * into a physical page number. +- */ + pfn += page_offset; +-#endif + } else { + BUG_ON(page_offset >= nv_nvkms_memory->pages_count); + pfn = page_to_pfn(nv_nvkms_memory->pages[page_offset]); diff --git a/graphics/nvidia-drm-612-kmod/files/patch-nvidia-drm-gem-user-memory.c b/graphics/nvidia-drm-612-kmod/files/patch-nvidia-drm-gem-user-memory.c new file mode 100644 index 000000000000..2bd7c897a50e --- /dev/null +++ b/graphics/nvidia-drm-612-kmod/files/patch-nvidia-drm-gem-user-memory.c @@ -0,0 +1,39 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-user-memory.c.orig nvidia-drm-gem-user-memory.c +index 5ce0ba890e52..0ca3a7e2e07d 100644 +--- nvidia-drm-gem-user-memory.c.orig ++++ nvidia-drm-gem-user-memory.c +@@ -144,7 +144,7 @@ static vm_fault_t __nv_drm_gem_user_memory_handle_vma_fault( + unsigned long page_offset; + unsigned long pfn; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + BUG_ON(page_offset >= nv_user_memory->pages_count); + pfn = page_to_pfn(nv_user_memory->pages[page_offset]); + diff --git a/graphics/nvidia-drm-612-kmod/files/patch-nvidia-drm-helper.h b/graphics/nvidia-drm-612-kmod/files/patch-nvidia-drm-helper.h new file mode 100644 index 000000000000..6929f75cae28 --- /dev/null +++ b/graphics/nvidia-drm-612-kmod/files/patch-nvidia-drm-helper.h @@ -0,0 +1,60 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-helper.h.orig nvidia-drm-helper.h +index bc91858136b2..2ef27fced3c5 100644 +--- nvidia-drm-helper.h.orig ++++ nvidia-drm-helper.h +@@ -51,6 +51,29 @@ + #define NV_DRM_USE_EXTENDED_PROPERTIES (DRM_OBJECT_MAX_PROPERTY >= 64) + + #include ++#include ++#include ++ ++/* ++ * nv_drm_vma_fault_get_page_offset - compute GEM page offset from a vm_fault ++ * ++ * On Linux, vmf->pgoff carries the file-level page index set by the VM. ++ * On FreeBSD, linux_cdev_pager_populate() sets vmf->pgoff = 0 and instead ++ * passes the page index (pidx) via vmf->virtual_address as IDX_TO_OFF(pidx). ++ * Convert back with OFF_TO_IDX and subtract the GEM vma_node start to get ++ * the page offset within the GEM object. ++ */ ++static inline unsigned long ++nv_drm_vma_fault_get_page_offset(struct vm_fault *vmf, ++ struct drm_gem_object *gem) ++{ ++#if defined(NV_LINUX) ++ unsigned long offset = vmf->pgoff; ++#else ++ unsigned long offset = OFF_TO_IDX((uintptr_t)vmf->virtual_address); ++#endif ++ return offset - drm_vma_node_start(&gem->vma_node); ++} + + static inline struct sg_table* + nv_drm_prime_pages_to_sg(struct drm_device *dev, diff --git a/graphics/nvidia-drm-66-kmod-580/Makefile b/graphics/nvidia-drm-66-kmod-580/Makefile index 66d7a907384a..fe4a66924879 100644 --- a/graphics/nvidia-drm-66-kmod-580/Makefile +++ b/graphics/nvidia-drm-66-kmod-580/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 580.159.04 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 2 +PORTREVISION= 3 MASTERDIR= ${.CURDIR}/../nvidia-drm-66-kmod PKGNAMESUFFIX= -580 .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-66-kmod-devel/Makefile b/graphics/nvidia-drm-66-kmod-devel/Makefile index 7c43544475f6..c2fed27edac2 100644 --- a/graphics/nvidia-drm-66-kmod-devel/Makefile +++ b/graphics/nvidia-drm-66-kmod-devel/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 610.43.02 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 1 +PORTREVISION= 2 MASTERDIR= ${.CURDIR}/../nvidia-drm-66-kmod PKGNAMESUFFIX= -devel .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-66-kmod/Makefile b/graphics/nvidia-drm-66-kmod/Makefile index f9149f513ad0..55a9e2aaef7a 100644 --- a/graphics/nvidia-drm-66-kmod/Makefile +++ b/graphics/nvidia-drm-66-kmod/Makefile @@ -1,11 +1,11 @@ PORTNAME= nvidia-drm-66-kmod -PORTREVISION= 0 +PORTREVISION= 1 CATEGORIES= graphics RUN_DEPENDS+= ${KMODDIR}/drm.ko:graphics/drm-66-kmod CONFLICTS_INSTALL= nvidia-drm-515-kmod* nvidia-drm-61-kmod* nvidia-drm-612-kmod* nvidia-drm-latest-kmod* .include "${.CURDIR}/../drm-66-kmod/Makefile.version" .include "${.CURDIR}/../nvidia-drm-kmod/Makefile.common" .include diff --git a/graphics/nvidia-drm-66-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c b/graphics/nvidia-drm-66-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c new file mode 100644 index 000000000000..4ca6b309249d --- /dev/null +++ b/graphics/nvidia-drm-66-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c @@ -0,0 +1,54 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-nvkms-memory.c.orig nvidia-drm-gem-nvkms-memory.c +index 60f490f89dca..6aa0e40bcb1a 100644 +--- nvidia-drm-gem-nvkms-memory.c.orig ++++ nvidia-drm-gem-nvkms-memory.c +@@ -124,22 +124,12 @@ static vm_fault_t __nv_drm_gem_nvkms_handle_vma_fault( + unsigned long page_offset, pfn; + vm_fault_t ret; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + + if (nv_nvkms_memory->pages_count == 0) { + pfn = (unsigned long)(uintptr_t)nv_nvkms_memory->pPhysicalAddress; + pfn >>= PAGE_SHIFT; +-#if defined(NV_LINUX) +- /* +- * FreeBSD doesn't set pgoff. We instead have pfn be the base physical +- * address, and we will calculate the index pidx from the virtual address. +- * +- * This only works because linux_cdev_pager_populate passes the pidx as +- * vmf->virtual_address. Then we turn the virtual address +- * into a physical page number. +- */ + pfn += page_offset; +-#endif + } else { + BUG_ON(page_offset >= nv_nvkms_memory->pages_count); + pfn = page_to_pfn(nv_nvkms_memory->pages[page_offset]); diff --git a/graphics/nvidia-drm-66-kmod/files/patch-nvidia-drm-gem-user-memory.c b/graphics/nvidia-drm-66-kmod/files/patch-nvidia-drm-gem-user-memory.c new file mode 100644 index 000000000000..2bd7c897a50e --- /dev/null +++ b/graphics/nvidia-drm-66-kmod/files/patch-nvidia-drm-gem-user-memory.c @@ -0,0 +1,39 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-user-memory.c.orig nvidia-drm-gem-user-memory.c +index 5ce0ba890e52..0ca3a7e2e07d 100644 +--- nvidia-drm-gem-user-memory.c.orig ++++ nvidia-drm-gem-user-memory.c +@@ -144,7 +144,7 @@ static vm_fault_t __nv_drm_gem_user_memory_handle_vma_fault( + unsigned long page_offset; + unsigned long pfn; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + BUG_ON(page_offset >= nv_user_memory->pages_count); + pfn = page_to_pfn(nv_user_memory->pages[page_offset]); + diff --git a/graphics/nvidia-drm-66-kmod/files/patch-nvidia-drm-helper.h b/graphics/nvidia-drm-66-kmod/files/patch-nvidia-drm-helper.h new file mode 100644 index 000000000000..6929f75cae28 --- /dev/null +++ b/graphics/nvidia-drm-66-kmod/files/patch-nvidia-drm-helper.h @@ -0,0 +1,60 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-helper.h.orig nvidia-drm-helper.h +index bc91858136b2..2ef27fced3c5 100644 +--- nvidia-drm-helper.h.orig ++++ nvidia-drm-helper.h +@@ -51,6 +51,29 @@ + #define NV_DRM_USE_EXTENDED_PROPERTIES (DRM_OBJECT_MAX_PROPERTY >= 64) + + #include ++#include ++#include ++ ++/* ++ * nv_drm_vma_fault_get_page_offset - compute GEM page offset from a vm_fault ++ * ++ * On Linux, vmf->pgoff carries the file-level page index set by the VM. ++ * On FreeBSD, linux_cdev_pager_populate() sets vmf->pgoff = 0 and instead ++ * passes the page index (pidx) via vmf->virtual_address as IDX_TO_OFF(pidx). ++ * Convert back with OFF_TO_IDX and subtract the GEM vma_node start to get ++ * the page offset within the GEM object. ++ */ ++static inline unsigned long ++nv_drm_vma_fault_get_page_offset(struct vm_fault *vmf, ++ struct drm_gem_object *gem) ++{ ++#if defined(NV_LINUX) ++ unsigned long offset = vmf->pgoff; ++#else ++ unsigned long offset = OFF_TO_IDX((uintptr_t)vmf->virtual_address); ++#endif ++ return offset - drm_vma_node_start(&gem->vma_node); ++} + + static inline struct sg_table* + nv_drm_prime_pages_to_sg(struct drm_device *dev, diff --git a/graphics/nvidia-drm-kmod/Makefile.common b/graphics/nvidia-drm-kmod/Makefile.common index d303d5331bab..ea6b633c2530 100644 --- a/graphics/nvidia-drm-kmod/Makefile.common +++ b/graphics/nvidia-drm-kmod/Makefile.common @@ -1,92 +1,97 @@ # Common rules for nvidia-drm-*-kmod ports MAINTAINER= x11@FreeBSD.org COMMENT= NVIDIA DRM Kernel Module WWW= https://www.nvidia.com/object/unix.html MASTER_SITES= NVIDIA/XFree86/FreeBSD-${ARCH_SUFX}/${NVIDIA_DISTVERSION}:nvidia \ https://codeload.github.com/freebsd/drm-kmod/tar.gz/${DRM_KMOD_GH_TAGNAME}?dummy=/:drm DISTVERSION?= ${NVIDIA_DISTVERSION} PORTREVISION?= 0 DISTFILES= NVIDIA-FreeBSD-${ARCH_SUFX}-${NVIDIA_DISTVERSION}${EXTRACT_SUFX}:nvidia \ freebsd-drm-kmod-${DRM_KMOD_GH_TAGNAME}_GH0.tar.gz:drm # Choose proper distinfo file using PKGNAMESUFFIX for slave ports. # Kept for switching to centralized distinfo with suffixes. .ifdef PKGNAMESUFFIX DISTINFO_FILE= ${.CURDIR}/distinfo .endif ONLY_FOR_ARCHS= amd64 USES= kmod uidfix tar:xz SUB_FILES= 20-nvidia-drm-outputclass.conf RUN_DEPENDS+= ${KMODDIR}/nvidia.ko:x11/nvidia-kmod${PKGNAMESUFFIX} .include "${.CURDIR}/../../x11/nvidia-driver/Makefile.version" .include "${.CURDIR}/../../x11/nvidia-driver/Makefile.common" LICENSE_FILE= ${WRKSRC}/../../doc/license.txt PLIST_FILES= ${KMODDIR}/nvidia-drm.ko \ share/X11/xorg.conf.d/20-nvidia-drm-outputclass.conf MAKE_ENV+= DEBUG_FLAGS=${DEBUG_FLAGS} \ DRMKMODDIR=${WRKDIR}/drm-kmod-${DRM_KMOD_GH_TAGNAME}/ WRKSRC= ${WRKDIR}/NVIDIA-FreeBSD-${ARCH_SUFX}-${NVIDIA_DISTVERSION}/ WRKSRC_SUBDIR= src/nvidia-drm/ .if ${NVVERSION} < 595.07105 && empty(.CURDIR:M*graphics/nvidia-drm-5*) EXTRA_PATCHES+= ${FILESDIR}/extra-patch-nvidia-drm-freebsd-lkpi.c-20250918-01 .endif .if ${NVVERSION} < 565.00000 EXTRA_PATCHES+= ${FILESDIR}/extra-patch-nvidia-drm-conftest.h .endif #565.00 .if ${NVVERSION} < 555.04202 EXTRA_PATCHES+= ${FILESDIR}/extra-patch-nvidia-drm-freebsd-lkpi.c .endif post-install: ${MKDIR} ${STAGEDIR}${PREFIX}/share/X11/xorg.conf.d/ ${INSTALL_DATA} ${WRKDIR}/20-nvidia-drm-outputclass.conf ${STAGEDIR}${PREFIX}/share/X11/xorg.conf.d/ post-patch: # Workaround for LLVM/Clang19 ${REINPLACE_CMD} -e '/DRMKMODDIR.*\/linuxkpi\/dummy\/include/d' \ ${WRKSRC}/Makefile # Workaround for the issue that X11 cannot acquire modesetting # permission by disabling hw.nvidiadrm.fbdev tunable which is # enabled on 570 series and later of the driver. # This is due to the issue lacking proper support for fbdev # (would be simpledrm) in graphics/drm-*-kmod and/or LinuxKPI. # Would be reverted once the issues are sorted and fixed. .if ${NVVERSION} >= 570.00000 ${REINPLACE_CMD} -e 's:\&nv_drm_fbdev_module_param\, 1\,:\&nv_drm_fbdev_module_param\, 0\,:' \ ${WRKSRC}/nvidia-drm-freebsd-lkpi.c ${REINPLACE_CMD} -e 's:bool nv_drm_fbdev_module_param = true;:bool nv_drm_fbdev_module_param = false;:' \ ${WRKSRC}/nvidia-drm-os-interface.c .endif # Workaround for build failure on 575.51.02. # --- nvidia-drm-drv.o --- # nvidia-drm-drv.c:386:80: error: cast from 'const void *' to 'struct nv_drm_mst_display_info *' drops const qualifier [-Werror,-Wcast-qual] # 386 | struct nv_drm_mst_display_info *l_info = (struct nv_drm_mst_display_info *)l; # | ^ # nvidia-drm-drv.c:387:80: error: cast from 'const void *' to 'struct nv_drm_mst_display_info *' drops const qualifier [-Werror,-Wcast-qual] # 387 | struct nv_drm_mst_display_info *r_info = (struct nv_drm_mst_display_info *)r; # | ^ .if ${NVVERSION} >= 575.00000 ${REINPLACE_CMD} -e 's:struct nv_drm_mst_display_info \*l_info = (struct nv_drm_mst_display_info:const struct nv_drm_mst_display_info \*l_info = (const struct nv_drm_mst_display_info:' \ ${WRKSRC}/nvidia-drm-drv.c ${REINPLACE_CMD} -e 's:struct nv_drm_mst_display_info \*r_info = (struct nv_drm_mst_display_info:const struct nv_drm_mst_display_info \*r_info = (const struct nv_drm_mst_display_info:' \ ${WRKSRC}/nvidia-drm-drv.c +.endif + # Workaround for build failure on graphics/nvidia-drm-515-kmod*, + # as struct dma_buf_map was renamed to struct iosys_map at Linux 5.18 (DRM5.18). +.if ${.CURDIR:M*nvidia-drm-515-kmod*} + ${REINPLACE_CMD} -e 's:defined(NV_LINUX_IOSYS_MAP_H_PRESENT):0:' ${WRKSRC}/nvidia-drm-gem.c .endif # We should support -CURRENT: kill the check (first #if __FreeBSD_version) linenum=$$(${SED} -ne '/^#if __FreeBSD_version/ { = ; q ; }' \ ${WRKSRC}/../nvidia/nv-freebsd.h) ; ${REINPLACE_CMD} \ -e "$$linenum,+2d" ${WRKSRC}/../nvidia/nv-freebsd.h # Workaround for build failure on any base without pm_vt_switch_required(). # 13.5, 14.3 and 15.0 doesn't have the stub (blank) function. ${REINPLACE_CMD} -e 's/.*pm_vt_switch_required(dev->dev, true);.*/#if __FreeBSD_version >= 1403507 \&\& __FreeBSD_version < 1500000 || __FreeBSD_version >= 1500504\n&\n#endif/' \ ${WRKSRC}/nvidia-drm-drv.c diff --git a/graphics/nvidia-drm-latest-kmod-580/Makefile b/graphics/nvidia-drm-latest-kmod-580/Makefile index 0ba4a3131682..9fa7548cfa5c 100644 --- a/graphics/nvidia-drm-latest-kmod-580/Makefile +++ b/graphics/nvidia-drm-latest-kmod-580/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 580.159.04 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 1 +PORTREVISION= 2 MASTERDIR= ${.CURDIR}/../nvidia-drm-latest-kmod PKGNAMESUFFIX= -580 .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-latest-kmod-devel/Makefile b/graphics/nvidia-drm-latest-kmod-devel/Makefile index ca2541b439ff..2a04afca2377 100644 --- a/graphics/nvidia-drm-latest-kmod-devel/Makefile +++ b/graphics/nvidia-drm-latest-kmod-devel/Makefile @@ -1,7 +1,7 @@ NVIDIA_DISTVERSION?= 610.43.02 # Explicitly set PORTREVISION as it can be overridden by the master port -PORTREVISION= 0 +PORTREVISION= 1 MASTERDIR= ${.CURDIR}/../nvidia-drm-latest-kmod PKGNAMESUFFIX= -devel .include "${MASTERDIR}/Makefile" diff --git a/graphics/nvidia-drm-latest-kmod/Makefile b/graphics/nvidia-drm-latest-kmod/Makefile index bff909dfdf6b..67bca41228f5 100644 --- a/graphics/nvidia-drm-latest-kmod/Makefile +++ b/graphics/nvidia-drm-latest-kmod/Makefile @@ -1,11 +1,11 @@ PORTNAME= nvidia-drm-latest-kmod -PORTREVISION= 0 +PORTREVISION= 1 CATEGORIES= graphics RUN_DEPENDS+= ${KMODDIR}/drm.ko:graphics/drm-latest-kmod CONFLICTS_INSTALL= nvidia-drm-515-kmod* nvidia-drm-61-kmod* nvidia-drm-66-kmod* nvidia-drm-612-kmod* .include "${.CURDIR}/../drm-latest-kmod/Makefile.version" .include "${.CURDIR}/../nvidia-drm-kmod/Makefile.common" .include diff --git a/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c b/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c new file mode 100644 index 000000000000..4ca6b309249d --- /dev/null +++ b/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-gem-nvkms-memory.c @@ -0,0 +1,54 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-nvkms-memory.c.orig nvidia-drm-gem-nvkms-memory.c +index 60f490f89dca..6aa0e40bcb1a 100644 +--- nvidia-drm-gem-nvkms-memory.c.orig ++++ nvidia-drm-gem-nvkms-memory.c +@@ -124,22 +124,12 @@ static vm_fault_t __nv_drm_gem_nvkms_handle_vma_fault( + unsigned long page_offset, pfn; + vm_fault_t ret; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + + if (nv_nvkms_memory->pages_count == 0) { + pfn = (unsigned long)(uintptr_t)nv_nvkms_memory->pPhysicalAddress; + pfn >>= PAGE_SHIFT; +-#if defined(NV_LINUX) +- /* +- * FreeBSD doesn't set pgoff. We instead have pfn be the base physical +- * address, and we will calculate the index pidx from the virtual address. +- * +- * This only works because linux_cdev_pager_populate passes the pidx as +- * vmf->virtual_address. Then we turn the virtual address +- * into a physical page number. +- */ + pfn += page_offset; +-#endif + } else { + BUG_ON(page_offset >= nv_nvkms_memory->pages_count); + pfn = page_to_pfn(nv_nvkms_memory->pages[page_offset]); diff --git a/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-gem-user-memory.c b/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-gem-user-memory.c new file mode 100644 index 000000000000..2bd7c897a50e --- /dev/null +++ b/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-gem-user-memory.c @@ -0,0 +1,39 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-gem-user-memory.c.orig nvidia-drm-gem-user-memory.c +index 5ce0ba890e52..0ca3a7e2e07d 100644 +--- nvidia-drm-gem-user-memory.c.orig ++++ nvidia-drm-gem-user-memory.c +@@ -144,7 +144,7 @@ static vm_fault_t __nv_drm_gem_user_memory_handle_vma_fault( + unsigned long page_offset; + unsigned long pfn; + +- page_offset = vmf->pgoff - drm_vma_node_start(&gem->vma_node); ++ page_offset = nv_drm_vma_fault_get_page_offset(vmf, gem); + BUG_ON(page_offset >= nv_user_memory->pages_count); + pfn = page_to_pfn(nv_user_memory->pages[page_offset]); + diff --git a/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-helper.h b/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-helper.h new file mode 100644 index 000000000000..6929f75cae28 --- /dev/null +++ b/graphics/nvidia-drm-latest-kmod/files/patch-nvidia-drm-helper.h @@ -0,0 +1,60 @@ +commit c81cb2d87591863cd1d37ccb6143981462f215b7 +Author: Austin Shafer +Date: Sun May 17 14:14:58 2026 -0400 + + nvidia-drm: fix freebsd page offset during nvkms/user memory faults + + This fixes the page offset calculation on freebsd with nvidia-drm + in our nvkms/user memory faults. With this we actually convert + virtual_address into a page index and use that to index into + our array of pages. + + I found this and ran with it a bit myself, it also recently came + up and appears to fix a panic that an end user was running into: + https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296195 + + Bug 317957: Clean up module branches + Reviewed by: rrameshbabu + Signed-off-for-open-source-by: ashafer + + DVS_BUILD_INCLUDE ALL + MVS_SET_TESTS all + SUBMIT_GVS_OF_CUSTOM_DVS + https://builds4u.nvidia.com/dvs/#/change/38366516102499930.6?showTab=DVS + +Splitted into per-target. + +diff --git nvidia-drm-helper.h.orig nvidia-drm-helper.h +index bc91858136b2..2ef27fced3c5 100644 +--- nvidia-drm-helper.h.orig ++++ nvidia-drm-helper.h +@@ -51,6 +51,29 @@ + #define NV_DRM_USE_EXTENDED_PROPERTIES (DRM_OBJECT_MAX_PROPERTY >= 64) + + #include ++#include ++#include ++ ++/* ++ * nv_drm_vma_fault_get_page_offset - compute GEM page offset from a vm_fault ++ * ++ * On Linux, vmf->pgoff carries the file-level page index set by the VM. ++ * On FreeBSD, linux_cdev_pager_populate() sets vmf->pgoff = 0 and instead ++ * passes the page index (pidx) via vmf->virtual_address as IDX_TO_OFF(pidx). ++ * Convert back with OFF_TO_IDX and subtract the GEM vma_node start to get ++ * the page offset within the GEM object. ++ */ ++static inline unsigned long ++nv_drm_vma_fault_get_page_offset(struct vm_fault *vmf, ++ struct drm_gem_object *gem) ++{ ++#if defined(NV_LINUX) ++ unsigned long offset = vmf->pgoff; ++#else ++ unsigned long offset = OFF_TO_IDX((uintptr_t)vmf->virtual_address); ++#endif ++ return offset - drm_vma_node_start(&gem->vma_node); ++} + + static inline struct sg_table* + nv_drm_prime_pages_to_sg(struct drm_device *dev,