Re: [comedi] On later kernels 'comedi_config /dev/comedi0 ni_pcimio' does not work

Ian Abbott <[email protected]> Tue, 29 Aug 2023 12:28:55 +0100
Newsgroups gmane.linux.comedi
Organization MEV Ltd.
Message-ID <[email protected]>
On 25/08/2023 16:10, 'Anders Blomdell' via Comedi: Linux Control and 
Measurement Device Interface wrote:
> With comedi from https://github.com/Linux-Comedi/comedi (git tag 
> 9792ce4) 'comedi_config /dev/comedi0 ni_pcimio'
> later kernels (6.2.9, 6.3.7 and 6.4.6) fails with 'Buffer allocation 
> failed' in dmesg but earlier kernels (6.0.15) works.
> 
> The problem is that the call to 'dma_alloc_coherent' (called from 
> 'comedi_buf_alloc' fails to allocate
> the needed buffer.

It seems to be the use of `| __GFP_COMP` bit in `flags` parameter of 
`dma_alloc_coherent()` that results in the allocation failure.  This 
changed in Linux commit ffcb75458460 ("dma-mapping: reject __GFP_COMP in 
dma_alloc_attrs") from Linux kernel v6.2:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ffcb754584603adf7039d7972564fbf6febdc542

(Note: dma_alloc_coherent() calls dma_alloc_attrs().)

For now, I'll just avoid setting the `__GFP_COMP` flag.  I'm not 
entirely sure why it was set in the first place!

> Looking at the source in the kernel tree shows very different code in 
> 'comedi_buf_alloc', than in the standalone comedi.

The Linux source version allocates the DMA buffer in a single lump so 
that `dma_mmap_coherent()` can be used to mmap it.  There still does not 
seem to be an official way to mmap a buffer consisting of individually 
allocated DMA coherent pages, so I was stuck with allocating it as one 
big lump to keep it official.

Hopefully, we can still get away with using `remap_pfn_range()` on DMA 
coherent pages in the standalone comedi, but it might not work on all 
architectures.  Feedback welcome!

> Should I take this as a discouragement to use the out of tree version of 
> comedi, and instead rebuild the kernel with
> comedi support?

Some distro kernels include comedi support, e.g. Debian and Ubuntu.

-- 
-=( Ian Abbott <[email protected]> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

-- 
You received this message because you are subscribed to the Google Groups "Comedi: Linux Control and Measurement Device Interface" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/comedi_list/cf43c6a5-009d-4c18-977f-ecf37e0aa805%40mev.co.uk.