get_user_pages and pinning

Sadanand Warrier sadanandwarrier at gmail.com
Sat Jan 2 10:11:46 EST 2021


Thanks Greg

> You should get an error of -EFAULT when you try to do this when the
> kernel tries to access memory you don't have.
>
> But the best way to be sure is to actually try it yourself and see!
> There's nothing preventing you from doing that, right?  :)

Ah yes that is of course true.:-)  I did try it on Centos 4.18 and
sadly I do not get an -EFAULT.
Even access_ok blithely passes it off to the depths in the driver. But
I suppose unless the kernel actually tries to access the memory in the
midst of get_user_pages I would not see an error.
Since I do not see such an error I am supposing it doesn't (actually
touch the pages I mean), I haven't yet delved into the bowels of the
code yet. I thought I would ask here.
Now after get_user_pages and  after suitable calls to sg_dma_map etc
to get the bus address associated with the buffer, this area is passed
to a device.

If the buffer has been allocated and initialized in user space all is
good. This has been tried several times, by using memset, calloc,
actually initializing every element of the allocated buffer etc.

If not then I notice for various offsets in the buffer at page
boundaries the physical(bus) address points to the same page.
The device does the DMA and we end up with segmentation faults in
unrelated areas . systemd seems to be a frequent victim, I guess our
device has a bone to pick.

I know 5,0 onwards has the pin_user_pages family which may have some
solutions but for the moment I am stuck with 4.18.

Perhaps some other adventurous soul has tried this?  Again an IOMMU is
not present in bit of hardware though that may be neither here nor
there.

S



More information about the Kernelnewbies mailing list