Linux 6.8.4 and blackmagic-io-12.8.1a1 module

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

coppice

  • Posts: 5
  • Joined: Sat Jun 25, 2022 12:38 pm
  • Real Name: Steve Underwood

Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostSat Apr 06, 2024 7:49 pm

Hi,
Fedora 39 just updated to Linux kernel 6.8.4. The blackmagic 12.8.1a1 module builds OK, but the related blackmagic-io module fails, with the compiler complaining that:
mutex_init(mutex)
mutex_lock(mutex)
mutex_trylock(mutex) and
mutex_unlock(mutex)
cannot be resolved. With Linux kernel 6.7.11 things were still OK.
Offline

NVieville

  • Posts: 14
  • Joined: Tue Mar 12, 2019 9:29 am
  • Real Name: Nicolas Viéville

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostMon Apr 08, 2024 9:00 am

hello,

Here is an attempt to fix this issue.

Code and patch file (as a zip file) provided for ease of use.

Code: Select all
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_locks.c ./blackmagic-io-12.8.1a1/bm_locks.c
--- ./blackmagic-io-12.8.1a1.orig/bm_locks.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_locks.c   2024-04-08 10:31:15.502799014 +0200
@@ -31,6 +31,9 @@
 #if KERNEL_VERSION_OR_LATER(4, 11, 0)
    #include <linux/sched/debug.h>
 #endif
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   #include <linux/mutex.h>
+#endif
 #include "bm_locks.h"
 #include "bm_util.h"
 
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_mm.c ./blackmagic-io-12.8.1a1/bm_mm.c
--- ./blackmagic-io-12.8.1a1.orig/bm_mm.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_mm.c   2024-04-08 10:42:57.193768026 +0200
@@ -237,7 +237,11 @@
 
 int bm_dma_sg_bus_map(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    if (unlikely(nents <= 0))
    {
       sg_free_table(sgTable);
@@ -254,7 +258,11 @@
 
 void bm_dma_sg_bus_unmap(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    bm_atomic_sub(&statistics.pages_mapped, sgTable->orig_nents);
    sg_free_table(sgTable);
    kfree(sgTable);
@@ -341,7 +349,11 @@
    bm_dma_subpage_t* subpage = kzalloc(sizeof(*subpage), GFP_KERNEL);
    if (! subpage)
       return NULL;
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, (enum dma_data_direction) dir);
+#else
    subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, dir);
+#endif
    if (dma_mapping_error(&pci->pdev->dev, subpage->busAddr))
    {
       kfree(subpage);
@@ -354,7 +366,11 @@
 
 void bm_dma_bus_unmap_kernel_subpage(bm_pci_device_t* pci, bm_dma_subpage_t* subpage, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, (enum dma_data_direction) dir);
+#else
    dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, dir);
+#endif
    bm_atomic_sub(&statistics.memory_mapped, subpage->size);
    kfree(subpage);
 }
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_util.c ./blackmagic-io-12.8.1a1/bm_util.c
--- ./blackmagic-io-12.8.1a1.orig/bm_util.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_util.c   2024-04-08 10:37:57.007781283 +0200
@@ -137,7 +137,11 @@
       alloc_size += align - 1;
    }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   if (get_order(alloc_size) < MAX_PAGE_ORDER)
+#else
    if (get_order(alloc_size) < MAX_ORDER)
+#endif
       mem = (vm_address_t)kmalloc(alloc_size, GFP_KERNEL);
 
    if (mem == 0 && (flags & BM_ALLOC_CONTIGUOUS) == 0)
@@ -532,7 +536,11 @@
       INIT_HLIST_HEAD(&event_table.events[i]);
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static bm_event_t* get_event(void* event, bool create)
+#else
 bm_event_t* get_event(void* event, bool create)
+#endif
 {
    bm_event_t* ev;
    unsigned idx = hash_ptr(event, EVENT_TABLE_BITS);
@@ -572,7 +580,11 @@
    return ev;
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static void put_event(bm_event_t* ev)
+#else
 void put_event(bm_event_t* ev)
+#endif
 {
    unsigned long flags;
    spin_lock_irqsave(&event_table.lock, flags);


Hope this will help.

Cordially,


--
NVieville
Attachments
blackmagic-io-12.8.1a1-001-fix_for_kernel_6.8.zip
patch file for kernel 6.8
(1.31 KiB) Downloaded 92 times
Offline

goldyfruit

  • Posts: 31
  • Joined: Mon Apr 26, 2021 6:47 pm
  • Real Name: Gaëtan Trellu

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostFri Apr 12, 2024 2:05 pm

NVieville wrote:hello,

Here is an attempt to fix this issue.

Code and patch file (as a zip file) provided for ease of use.

Code: Select all
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_locks.c ./blackmagic-io-12.8.1a1/bm_locks.c
--- ./blackmagic-io-12.8.1a1.orig/bm_locks.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_locks.c   2024-04-08 10:31:15.502799014 +0200
@@ -31,6 +31,9 @@
 #if KERNEL_VERSION_OR_LATER(4, 11, 0)
    #include <linux/sched/debug.h>
 #endif
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   #include <linux/mutex.h>
+#endif
 #include "bm_locks.h"
 #include "bm_util.h"
 
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_mm.c ./blackmagic-io-12.8.1a1/bm_mm.c
--- ./blackmagic-io-12.8.1a1.orig/bm_mm.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_mm.c   2024-04-08 10:42:57.193768026 +0200
@@ -237,7 +237,11 @@
 
 int bm_dma_sg_bus_map(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    if (unlikely(nents <= 0))
    {
       sg_free_table(sgTable);
@@ -254,7 +258,11 @@
 
 void bm_dma_sg_bus_unmap(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    bm_atomic_sub(&statistics.pages_mapped, sgTable->orig_nents);
    sg_free_table(sgTable);
    kfree(sgTable);
@@ -341,7 +349,11 @@
    bm_dma_subpage_t* subpage = kzalloc(sizeof(*subpage), GFP_KERNEL);
    if (! subpage)
       return NULL;
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, (enum dma_data_direction) dir);
+#else
    subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, dir);
+#endif
    if (dma_mapping_error(&pci->pdev->dev, subpage->busAddr))
    {
       kfree(subpage);
@@ -354,7 +366,11 @@
 
 void bm_dma_bus_unmap_kernel_subpage(bm_pci_device_t* pci, bm_dma_subpage_t* subpage, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, (enum dma_data_direction) dir);
+#else
    dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, dir);
+#endif
    bm_atomic_sub(&statistics.memory_mapped, subpage->size);
    kfree(subpage);
 }
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_util.c ./blackmagic-io-12.8.1a1/bm_util.c
--- ./blackmagic-io-12.8.1a1.orig/bm_util.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_util.c   2024-04-08 10:37:57.007781283 +0200
@@ -137,7 +137,11 @@
       alloc_size += align - 1;
    }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   if (get_order(alloc_size) < MAX_PAGE_ORDER)
+#else
    if (get_order(alloc_size) < MAX_ORDER)
+#endif
       mem = (vm_address_t)kmalloc(alloc_size, GFP_KERNEL);
 
    if (mem == 0 && (flags & BM_ALLOC_CONTIGUOUS) == 0)
@@ -532,7 +536,11 @@
       INIT_HLIST_HEAD(&event_table.events[i]);
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static bm_event_t* get_event(void* event, bool create)
+#else
 bm_event_t* get_event(void* event, bool create)
+#endif
 {
    bm_event_t* ev;
    unsigned idx = hash_ptr(event, EVENT_TABLE_BITS);
@@ -572,7 +580,11 @@
    return ev;
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static void put_event(bm_event_t* ev)
+#else
 void put_event(bm_event_t* ev)
+#endif
 {
    unsigned long flags;
    spin_lock_irqsave(&event_table.lock, flags);


Hope this will help.

Cordially,


--
NVieville

Your patch works well with kernel 6.8.5-301.fc40, thanks as usual!
Offline

mrtooler

  • Posts: 1
  • Joined: Sat Apr 13, 2024 3:01 am
  • Location: Charlotte, NC
  • Real Name: Mark Mellon

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostSat Apr 13, 2024 3:04 am

NVieville wrote:hello,

Here is an attempt to fix this issue.

Code and patch file (as a zip file) provided for ease of use.

Code: Select all
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_locks.c ./blackmagic-io-12.8.1a1/bm_locks.c
--- ./blackmagic-io-12.8.1a1.orig/bm_locks.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_locks.c   2024-04-08 10:31:15.502799014 +0200
@@ -31,6 +31,9 @@
 #if KERNEL_VERSION_OR_LATER(4, 11, 0)
    #include <linux/sched/debug.h>
 #endif
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   #include <linux/mutex.h>
+#endif
 #include "bm_locks.h"
 #include "bm_util.h"
 
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_mm.c ./blackmagic-io-12.8.1a1/bm_mm.c
--- ./blackmagic-io-12.8.1a1.orig/bm_mm.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_mm.c   2024-04-08 10:42:57.193768026 +0200
@@ -237,7 +237,11 @@
 
 int bm_dma_sg_bus_map(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    int nents = dma_map_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    if (unlikely(nents <= 0))
    {
       sg_free_table(sgTable);
@@ -254,7 +258,11 @@
 
 void bm_dma_sg_bus_unmap(bm_pci_device_t* pci, bm_sg_table_t* sgTable, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, (enum dma_data_direction) dir);
+#else
    dma_unmap_sg(&pci->pdev->dev, sgTable->sgl, sgTable->orig_nents, dir);
+#endif
    bm_atomic_sub(&statistics.pages_mapped, sgTable->orig_nents);
    sg_free_table(sgTable);
    kfree(sgTable);
@@ -341,7 +349,11 @@
    bm_dma_subpage_t* subpage = kzalloc(sizeof(*subpage), GFP_KERNEL);
    if (! subpage)
       return NULL;
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, (enum dma_data_direction) dir);
+#else
    subpage->busAddr = dma_map_single(&pci->pdev->dev, addr, size, dir);
+#endif
    if (dma_mapping_error(&pci->pdev->dev, subpage->busAddr))
    {
       kfree(subpage);
@@ -354,7 +366,11 @@
 
 void bm_dma_bus_unmap_kernel_subpage(bm_pci_device_t* pci, bm_dma_subpage_t* subpage, bm_dma_direction_t dir)
 {
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, (enum dma_data_direction) dir);
+#else
    dma_unmap_single(&pci->pdev->dev, subpage->busAddr, subpage->size, dir);
+#endif
    bm_atomic_sub(&statistics.memory_mapped, subpage->size);
    kfree(subpage);
 }
diff -Naur ./blackmagic-io-12.8.1a1.orig/bm_util.c ./blackmagic-io-12.8.1a1/bm_util.c
--- ./blackmagic-io-12.8.1a1.orig/bm_util.c   2024-02-09 02:02:38.000000000 +0100
+++ ./blackmagic-io-12.8.1a1/bm_util.c   2024-04-08 10:37:57.007781283 +0200
@@ -137,7 +137,11 @@
       alloc_size += align - 1;
    }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+   if (get_order(alloc_size) < MAX_PAGE_ORDER)
+#else
    if (get_order(alloc_size) < MAX_ORDER)
+#endif
       mem = (vm_address_t)kmalloc(alloc_size, GFP_KERNEL);
 
    if (mem == 0 && (flags & BM_ALLOC_CONTIGUOUS) == 0)
@@ -532,7 +536,11 @@
       INIT_HLIST_HEAD(&event_table.events[i]);
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static bm_event_t* get_event(void* event, bool create)
+#else
 bm_event_t* get_event(void* event, bool create)
+#endif
 {
    bm_event_t* ev;
    unsigned idx = hash_ptr(event, EVENT_TABLE_BITS);
@@ -572,7 +580,11 @@
    return ev;
 }
 
+#if KERNEL_VERSION_OR_LATER(6, 8, 0)
+static void put_event(bm_event_t* ev)
+#else
 void put_event(bm_event_t* ev)
+#endif
 {
    unsigned long flags;
    spin_lock_irqsave(&event_table.lock, flags);


Hope this will help.

Cordially,


--
NVieville


Can confirm this is also required and works for desktopvideo 12.9a3 on kernel 6.8+ (Tested on Pop_OS 22.04 running 6.8.0)
~mrt
Offline

coppice

  • Posts: 5
  • Joined: Sat Jun 25, 2022 12:38 pm
  • Real Name: Steve Underwood

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostSun Apr 14, 2024 7:47 pm

blackmagic-io-12.9a3 still has the same problem, but the posted patch seems to work OK for that as well as version 12.8.1a1.
Offline

NVieville

  • Posts: 14
  • Joined: Tue Mar 12, 2019 9:29 am
  • Real Name: Nicolas Viéville

Re: Linux 6.8.4 and blackmagic-io-12.8.1a1 module

PostMon Apr 15, 2024 8:49 am

coppice wrote:blackmagic-io-12.9a3 still has the same problem, but the posted patch seems to work OK for that as well as version 12.8.1a1.


Thanks for this information.

In order to make it smoother, one can modify the downloaded patch to correspond to the 12.9a3 version, making a copy before.

Code: Select all
cp /path_to_your_patch_directory/blackmagic-io-12.8.1a1-001-fix_for_kernel_6.8.patch /path_to_your_patch_directory/blackmagic-io-12.9a3-001-fix_for_kernel_6.8.patch

sed -i -e 's%12\.8\.1a1%12\.9a3%g' /path_to_your_patch_directory/blackmagic-io-12.9a3-001-fix_for_kernel_6.8.patch


Then proceed as usual, in the right directory, first dry run, then patch:

Code: Select all
cd /usr/src/

patch -p1 --dry-run </path_to_your_patch_directory/blackmagic-io-12.9a3-001-fix_for_kernel_6.8.patch

patch -p1 </path_to_your_patch_directory/blackmagic-io-12.9a3-001-fix_for_kernel_6.8.patch


Cordially,


--
NVieville

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 6 guests