myriadrf / xtrx_linux_pcie_drv

XTRX PCI driver for linux
Apache License 2.0
16 stars 22 forks source link

DKMS build fails on a Linux 6.3.3-surface based system due to a read-only vm_area_struct member. #16

Closed phibbs7 closed 9 months ago

phibbs7 commented 1 year ago

Hello,

I was trying to install another package which pulled in your DKMS module. The build attempt failed on 6.3.3-surface but succeeded on 6.2.10-surface. So I assume the issue is caused by a change in the upstream kernel sources between 6.2.10 and 6.3.3.

dkms console output: Building for 6.3.3-surface Building initial module for 6.3.3-surface Error! Bad return status for module build on kernel: 6.3.3-surface (x86_64) Consult /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/make.log for more information.

dkms make.log output: DKMS make.log for xtrx-0.0.1+git20190320.5ae3a3e-3.2 for kernel 6.3.3-surface (x86_64) Tue May 30 12:15:07 PM EDT 2023 make: Entering directory '/usr/src/linux-headers-6.3.3-surface' warning: the compiler differs from the one used to build the kernel The kernel was built by: gcc (Ubuntu 9.4.0-1ubuntu1\~20.04.1) 9.4.0 You are using: gcc (Debian 12.2.0-14) 12.2.0 CC [M] /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.o /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c: In function ‘xtrxfd_mmap’: /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:1075:31: error: assignment of read-only member ‘vm_flags’ 1075 | vma->vm_flags |= VM_LOCKED; | ^~ /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:1090:31: error: assignment of read-only member ‘vm_flags’ 1090 | vma->vm_flags |= VM_IO; | ^~ /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:1115:31: error: assignment of read-only member ‘vm_flags’ 1115 | vma->vm_flags |= VM_LOCKED; | ^~ make[1]: [scripts/Makefile.build:252: /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.o] Error 1 make: [Makefile:2031: /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build] Error 2 make: Leaving directory '/usr/src/linux-headers-6.3.3-surface'

svavassori commented 1 year ago

+1

hax0rbana-adam commented 1 year ago

Below is the patch to fix this issue. For reference, here's the thread about this change on the Linux Kernel mailing list: https://lore.kernel.org/lkml/ZA7x9y60sfGOanHl@kroah.com/T/

--- /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c  2023-08-02 23:31:16.843423689 -0500
+++ /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c       2023-08-02 23:32:22.432850822 -0500
@@ -1072,7 +1072,7 @@
                        return -EINVAL;
                }
                //vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
-               vma->vm_flags |= VM_LOCKED;
+               vm_flags_set(vma, VM_LOCKED);

                if (remap_pfn_range(vma, vma->vm_start,
                                                        virt_to_phys((void*)((unsigned long)xtrxdev->shared_mmap)) >> PAGE_SHIFT,
@@ -1087,7 +1087,7 @@
                unsigned long pfn;
                int bar = (region == REGION_CTRL) ? 0 : 1;
                vma->vm_page_prot = pgprot_device(vma->vm_page_prot);
-               vma->vm_flags |= VM_IO;
+               vm_flags_set(vma, VM_IO);
                pfn = pci_resource_start(xtrxdev->pdev, bar) >> PAGE_SHIFT;

                if (io_remap_pfn_range(vma, vma->vm_start, pfn,
@@ -1112,7 +1112,7 @@
                }

                //vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
-               vma->vm_flags |= VM_LOCKED;
+               vm_flags_set(vma, VM_LOCKED);

                for (i = 0, off = 0; i < BUFS; ++i, off += bufsize) {
 #ifdef VA_DMA_ADDR_FIXUP
hax0rbana-adam commented 1 year ago

I submitted a pull request for this. https://github.com/myriadrf/xtrx_linux_pcie_drv/pull/18

There's a superior pull request that was already submitted by @myriadrf but I failed to check before submitting my fix (oops).

If this repo is still being maintained, please merge in https://github.com/myriadrf/xtrx_linux_pcie_drv/pull/17 so Linux Surface users can upgrade to the latest kernel.

hax0rbana-adam commented 1 year ago

And I can also confirm that downgrading Linux to 6.2.10-surface works around this issue.

When linux-image-surface is installed, it currently uses linux-image-6.4.7-surface, which is why this happens to everyone running Linux on their surface by default.