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

"'Anders Blomdell' via Comedi: Linux Control and Measurement Device Interface" <[email protected]> Tue, 29 Aug 2023 20:45:25 +0200
Newsgroups gmane.linux.comedi
Message-ID <[email protected]>
Thanks a lot!

On 2023-08-29 13:28, Ian Abbott wrote:
> On 25/08/2023 16:10, 'Anders Blomdell' via Comedi: Linux Control and Meas=
urement 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 fai=
led' in dmesg but earlier kernels (6.0.15) works.
>>
>> The problem is that the call to 'dma_alloc_coherent' (called from 'comed=
i_buf_alloc' fails to allocate
>> the needed buffer.
>=20
> It seems to be the use of `| __GFP_COMP` bit in `flags` parameter of `dma=
_alloc_coherent()` that results in the allocation failure.=C2=A0 This chang=
ed in Linux commit ffcb75458460 ("dma-mapping: reject __GFP_COMP in dma_all=
oc_attrs") from Linux kernel v6.2:
>=20
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit=
/?id=3Dffcb754584603adf7039d7972564fbf6febdc542
>=20
> (Note: dma_alloc_coherent() calls dma_alloc_attrs().)
>=20
> For now, I'll just avoid setting the `__GFP_COMP` flag.=C2=A0 I'm not ent=
irely sure why it was set in the first place!
That's what stopped me from proposing that change directly (but got to refr=
esh my knowledge about linux DMA, long time since
I looked at at last time...)

>> Looking at the source in the kernel tree shows very different code in 'c=
omedi_buf_alloc', than in the standalone comedi.
>=20
> The Linux source version allocates the DMA buffer in a single lump so tha=
t `dma_mmap_coherent()` can be used to mmap it.=C2=A0 There still does not =
seem to be an official way to mmap a buffer consisting of individually allo=
cated DMA coherent pages, so I was stuck with allocating it as one big lump=
 to keep it official.
>=20
> Hopefully, we can still get away with using `remap_pfn_range()` on DMA co=
herent pages in the standalone comedi, but it might not work on all archite=
ctures.=C2=A0 Feedback welcome!
>=20
>> Should I take this as a discouragement to use the out of tree version of=
 comedi, and instead rebuild the kernel with
>> comedi support?
>=20
> Some distro kernels include comedi support, e.g. Debian and Ubuntu.
Will have to nag Fedora about this (and get comedilib back in again)


--=20
Anders Blomdell                  Email: [email protected]
Department of Automatic Control
Lund University                  Phone:    +46 46 222 8793
P.O. Box 118
SE-221 00 Lund, Sweden

--=20
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 e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
comedi_list/a5ded568-ccbb-7495-37be-e6f3dd1b1600%40control.lth.se.