Subject: Re: memory questions
To: None <tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 04/12/2006 05:49:34
> 1) is it correct to access memory allocated in user space within my
> driver?
Yes, provided you do it properly.
> 2) when accessing memory mapped for DMA access, I sometimes get an
> "uvm_fault: page fault error". It seems that pointer is valid
> (points into allocated buffer), what can be an other reason for it?
> Page fault seems strange to me in such situation ...
Most likely, it points to a page which is not in RAM at the time. This
could be because it's a demand-zero page (one which has never been
accessed and is to be filled with zeros on its first reference), it
could be because it's been paged out to swap...there might even be
other reasons, though I'd say those two are the most likely ones.
This sort of thing is part of the "properly" I mentioned in response to
question 1. copyin and copyout take care to handle page faults
correctly; they are usually the right thing to use if you're copying
small amounts of data. If you want to DMA directly into user memory,
you have to (a) make sure the relevant pages are locked in memory for
the duration and (b) do the correct dance to make sure caches and such
are properly handled - this is part of why bus_dma exists, so the
driver code can be insulated from the (heavily machine-specific)
details of this dance..
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B