* Question: how to copy to user space from a tasklet
@ 2010-10-14 10:43 Tom Brown
2010-10-15 2:15 ` Yong Zhang
2010-10-15 5:57 ` Stefan Richter
0 siblings, 2 replies; 7+ messages in thread
From: Tom Brown @ 2010-10-14 10:43 UTC (permalink / raw)
To: LKML
[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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Question: how to copy to user space from a tasklet
2010-10-14 10:43 Question: how to copy to user space from a tasklet Tom Brown
@ 2010-10-15 2:15 ` Yong Zhang
2010-10-15 5:57 ` Stefan Richter
1 sibling, 0 replies; 7+ messages in thread
From: Yong Zhang @ 2010-10-15 2:15 UTC (permalink / raw)
To: Tom Brown; +Cc: LKML
On Thu, Oct 14, 2010 at 11:43:16AM +0100, Tom Brown wrote:
> [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?
Are you seeking for probe_kernel_read/write(include/linux/uaccess.h)?
Thanks,
Yong
>
> Thanks
>
> Tom
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Question: how to copy to user space from a tasklet
2010-10-14 10:43 Question: how to copy to user space from a tasklet Tom Brown
2010-10-15 2:15 ` Yong Zhang
@ 2010-10-15 5:57 ` Stefan Richter
2010-10-15 8:59 ` Arnd Bergmann
2010-10-18 15:45 ` Tom Brown
1 sibling, 2 replies; 7+ messages in thread
From: Stefan Richter @ 2010-10-15 5:57 UTC (permalink / raw)
To: Tom Brown; +Cc: LKML, Yong Zhang
Tom Brown wrote:
> [Sorry to have to ask this here - I can't find any driver-specific
> newsgroup or mailing lists - are there any??]
linux-newbie perhaps.
> 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.
--
Stefan Richter
-=====-==-=- =-=- -====
http://arcgraph.de/sr/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Question: how to copy to user space from a tasklet
2010-10-15 5:57 ` Stefan Richter
@ 2010-10-15 8:59 ` Arnd Bergmann
2010-10-18 15:45 ` Tom Brown
1 sibling, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2010-10-15 8:59 UTC (permalink / raw)
To: Stefan Richter; +Cc: Tom Brown, LKML, Yong Zhang
On Friday 15 October 2010 07:57:59 Stefan Richter wrote:
> Tom Brown wrote:
> > [Sorry to have to ask this here - I can't find any driver-specific
> > newsgroup or mailing lists - are there any??]
>
> linux-newbie perhaps.
>
> > 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Question: how to copy to user space from a tasklet
2010-10-15 5:57 ` Stefan Richter
2010-10-15 8:59 ` Arnd Bergmann
@ 2010-10-18 15:45 ` Tom Brown
2010-10-18 17:01 ` Stefan Richter
1 sibling, 1 reply; 7+ messages in thread
From: Tom Brown @ 2010-10-18 15:45 UTC (permalink / raw)
To: LKML; +Cc: Stefan Richter, Yong Zhang, Arnd Bergmann
On 15/10/2010 06:57, Stefan Richter wrote:
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Question: how to copy to user space from a tasklet
2010-10-18 15:45 ` Tom Brown
@ 2010-10-18 17:01 ` Stefan Richter
2010-10-18 18:02 ` Tom Brown
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Richter @ 2010-10-18 17:01 UTC (permalink / raw)
To: Tom Brown; +Cc: LKML, Yong Zhang, Arnd Bergmann
Tom Brown wrote:
> 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 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.
--
Stefan Richter
-=====-==-=- =-=- =--=-
http://arcgraph.de/sr/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Question: how to copy to user space from a tasklet
2010-10-18 17:01 ` Stefan Richter
@ 2010-10-18 18:02 ` Tom Brown
0 siblings, 0 replies; 7+ messages in thread
From: Tom Brown @ 2010-10-18 18:02 UTC (permalink / raw)
To: LKML; +Cc: Stefan Richter, Yong Zhang, Arnd Bergmann
On 18/10/2010 18:01, Stefan Richter wrote:
> Tom Brown wrote:
>> 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 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.
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-10-18 18:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-14 10:43 Question: how to copy to user space from a tasklet Tom Brown
2010-10-15 2:15 ` Yong Zhang
2010-10-15 5:57 ` Stefan Richter
2010-10-15 8:59 ` Arnd Bergmann
2010-10-18 15:45 ` Tom Brown
2010-10-18 17:01 ` Stefan Richter
2010-10-18 18:02 ` Tom Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox