Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes needed to compile on newer kernel #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arunpersaud
Copy link

Hello

here are the changes I had to do to get the kernel to compile. I also had to sign the kernel. I should probably add some information on how this was done in the README or some other place. Do you have any preference on where to put this?

The code seems to work for me (at least it compiles), but I haven't used it yet to talk to the pixie card. I hope to be able to test this this coming week.

The code needs still cleanup, e.g. some #if statements around it that specifies the kernel version, but I'm not sure exactly how this should look like. For now, I also left the old code in there and that should then be removed. Happy to update the PR, just wanted to get this out, so that you can already have a look at it.

@rmathar
Copy link

rmathar commented Jun 19, 2024

Dropping of the last (5th) argument of the get_user_pages call is not correct for openSUSE 15.5 and Alma Linux 9.2 (both are linux kernels 5.14) but correct for openSUSE 15.6 (Linux kernel 6.4). So the patch relative to PLX SDK 8.23 is
supposedly happening around kernel 6.0

--- SuppFunc.c.orig     2020-11-17 20:37:52.000000000 +0100
+++ SuppFunc.c  2024-06-18 20:12:10.469087202 +0200
@@ -615,7 +615,12 @@
             &(pdx->pPciDevice->dev),
             pMemObject->Size,
             &BusAddress,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,14,0)
             GFP_KERNEL | __GFP_NOWARN         
+#else       
+           // this to avoid failure on Alma 9.x
+           GFP_ATOMIC
+#endif      
             );
             
     if (pMemObject->pKernelVa == NULL)
@@ -626,6 +631,25 @@
     // Store the bus address
     pMemObject->BusPhysical = (U64)BusAddress;
             
+#if 1       
+    // Check that the pages in the correct range (avoid kernel panic on Alma 9.x)
+    for (virt_addr = (PLX_UINT_PTR)pMemObject->pKernelVa;
+         virt_addr < ((PLX_UINT_PTR)pMemObject->pKernelVa + pMemObject->Size);
+         virt_addr += PAGE_SIZE)
+    {
+        if ( ! virt_addr_valid( PLX_INT_TO_PTR(virt_addr) ) )
+        {
+            dma_free_coherent(
+                &(pdx->pPciDevice->dev),
+                pMemObject->Size,
+                pMemObject->pKernelVa,
+                (dma_addr_t)pMemObject->BusPhysical
+                );
+           return NULL ;
+        }
+    }
+#endif
+
     // Tag all pages as reserved
     for (virt_addr = (PLX_UINT_PTR)pMemObject->pKernelVa;
          virt_addr < ((PLX_UINT_PTR)pMemObject->pKernelVa + pMemObject->Size);
@@ -958,11 +982,18 @@
     // Attempt to lock the user buffer into memory
     rc =
         Plx_get_user_pages(
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,0,0)
             UserVa & PAGE_MASK,                // Page-aligned user buffer start address
             TotalDescr,                        // Length of the buffer in pages
             (bDirLocalToPci ? FOLL_WRITE : 0), // Flags
             pdx->DmaInfo[channel].PageList,    // List of page pointers describing buffer
             NULL                               // List of associated VMAs
+#else
+            UserVa & PAGE_MASK,                // Page-aligned user buffer start address
+            TotalDescr,                        // Length of the buffer in pages
+            (bDirLocalToPci ? FOLL_WRITE : 0), // Flags
+            pdx->DmaInfo[channel].PageList    // List of page pointers describing buffer
+#endif
             );
 
     // Release mmap semaphore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants