Question: how to copy to user space from a tasklet
[Sorry to have to ask this here - I can't find any driver-specific newsgroup or mailing lists - are there any??]
I have a driver which needs to copy device data direct to user space from a tasklet. I need to do this because the device is continuously DMA'ing into user space, with no user intervention, so the user isn't waiting for data. In other words, I don't have any user-associated process to wake up.
This means that I have to somehow copy the data directly to the user from the tasklet, without sleeping, and without direct access to user context. Can someone tell me how to do this?
Thanks
Tom
Quoted 9 lines · Tom Brown
[Sorry to have to ask this here - I can't find any driver-specific newsgroup or mailing lists - are there any??]
I have a driver which needs to copy device data direct to user space from a tasklet. I need to do this because the device is continuously DMA'ing into user space, with no user intervention, so the user isn't waiting for data. In other words, I don't have any user-associated process to wake up.
Quoted 3 lines
This means that I have to somehow copy the data directly to the user from the tasklet, without sleeping, and without direct access to user context. Can someone tell me how to do this?
Are you seeking for probe_kernel_read/write(include/linux/uaccess.h)?
Thanks,
Yong
Quoted 9 lines
Thanks
Tom
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 2 lines · Tom Brown
[Sorry to have to ask this here - I can't find any driver-specific newsgroup or mailing lists - are there any??]
linux-newbie perhaps.
Quoted 2 lines
I have a driver which needs to copy device data direct to user space from a tasklet.
One way would be to use mmap() to allocate the DMA buffer and insert it into the user address space before DMA commences. An additional poll/read/write based protocol or so can be used for buffer management during DMA.
Signature · 3 lines
Stefan Richter -=====-==-=- =-=- -==== http://arcgraph.de/sr/
Quoted 4 lines · On Friday 15 October 2010 07:57:59 Stefan Richter wrote:
Quoted 2 lines · Tom Brown
[Sorry to have to ask this here - I can't find any driver-specific newsgroup or mailing lists - are there any??]
Quoted 8 lines
linux-newbie perhaps.
Quoted 2 lines
I have a driver which needs to copy device data direct to user space from a tasklet.
One way would be to use
mmap()to allocate the DMA buffer and insert it into the user address space before DMA commences. An additional poll/read/write based protocol or so can be used for buffer management during DMA.
Agreed, that would be best, it's a lot easier than the way Tom describes the driver to work today.
Just for completeness: doing DMA to random user address would require the process to register the area using some home grown interface, so that the driver can do get_user_pages/kmap on all of them and subsequently pass around an array of pages, while keeping track of ulimits and coherency with the existing kernel mappings. Don't do that.
Arnd
Quoted 3 lines · Stefan Richter
One way would be to use
mmap()to allocate the DMA buffer and insert it into the user address space before DMA commences. An additional poll/read/write based protocol or so can be used for buffer management during DMA.
Thanks, think I'm there:
1 - The user calls mmap() with a specific offset to flag that he wants a DMA buffer
2 - I then 'vmalloc' the buffer, and call 'setPageReserved' for each page
I then step over each page, and:
3 - call 'vmalloc_to_pfn' to get a PFN for each page, and then
4 - call 'remap_page_range' for that page (I instead call 'remap_pfn_range' for kernels >= 2.6.10, but I'm on 2.6.9)
This gives me the buffer, and the interrupt handler then just uses 'memcpy' to copy data to the user.
I've got to say, this was incredibly hard work. I can't find any useful documentation and it can take a couple of hours on Google to write a few lines of code. LDD is next to useless. There's no 'vmalloc_to_pfn' on 2.6.9, so I copied an old deprecated one from 2.6.10 (which was also in a kernel prior to 2.6.9, I think). I'm not yet convinced that all this is working; I think I've seen one instance when the 'memcpy' to the buffer didn't work, so I think there might potentially be a problem with setting the reserved bit (and isn't the reserved bit deprecated in 2.6.15??)
On the other stuff, thanks Yong for the 'probe_kernel_' suggestion, but I can't find any documentation on it.
linux-newbie only had one thread on it for the entire month when I checked a couple of days ago, apart from a couple of 419 scams.
Thanks -
Tom
Quoted 9 lines · Tom Brown
Thanks, think I'm there:
1 - The user calls
mmap()with a specific offset to flag that he wants a DMA buffer2 - I then 'vmalloc' the buffer, and call 'setPageReserved' for each page
I then step over each page, and:
Quoted 7 lines
3 - call '
vmalloc_to_pfn' to get a PFN for each page, and then4 - call '
remap_page_range' for that page (I instead call 'remap_pfn_range' for kernels >= 2.6.10, but I'm on 2.6.9)This gives me the buffer, and the interrupt handler then just uses 'memcpy' to copy data to the user.
I would have thought of a bunch of alloc_page() and vm_insert_page() but I don't know if vm_insert_page exists in 2.6.9 and if it honors user limits.
Plus dma_map_page() to get zero-copy operation with a DMA capable device.
Signature · 3 lines
Stefan Richter -=====-==-=- =-=- =--=- http://arcgraph.de/sr/
Quoted 12 lines · Stefan Richter
Quoted 11 lines · Tom Brown
Thanks, think I'm there:
1 - The user calls
mmap()with a specific offset to flag that he wants a DMA buffer2 - I then 'vmalloc' the buffer, and call 'setPageReserved' for each page
I then step over each page, and:
3 - call '
vmalloc_to_pfn' to get a PFN for each page, and then
Quoted 8 lines
Quoted 5 lines
4 - call '
remap_page_range' for that page (I instead call 'remap_pfn_range' for kernels>= 2.6.10, but I'm on 2.6.9)This gives me the buffer, and the interrupt handler then just uses 'memcpy' to copy data to the user.
I would have thought of a bunch of
alloc_page()andvm_insert_page()but I don't know ifvm_insert_pageexists in 2.6.9 and if it honors user limits.
It turns out that I'm getting occasional
"BUG: unable to handle kernel paging request at virtual address ...[buffer address]"
oops when the driver attempts to 'memcpy' to the buffer, so I think 'setPageReserved' is probably not the right thing to do. This is strange - it's almost as if 'setPageReserved' stops the page being swapped out, but the kernel doesn't know this.
I'll look into alloc_page/vm_insert_page instead.
Thanks -
Tom