get_user_pages and pinning
sadanandwarrier at gmail.com
Sun Jan 3 12:54:39 EST 2021
> I don't have an answer to your question because your sentences are too long and I couldn't understand the thing you are asking.
A clearer picture below.
1) There is a user program that allocates memory using malloc. It does
not initialize the memory.
2) It uses an ioctl to pass a pointer to different areas of this
allocated memory to a driver controlling a device.
3) The device is supposed to fill the buffer that this pointer points
to with requested data.
4) The driver pins the pages that the pointer points to in memory
5) The driver gets the physical (bus) address of this buffer using
kernel apis such as dma_map_sg and queues up the DMA.
6) Inspecting the bus address returned by kernel apis shows that the
same address is returned for different locations in the buffer.
7) So the DMA fails (rather the device sends the data but it is over
writing the same location)
8) It looks like the memory isn't actually allocated by malloc. Not a surprise.
9) It will ideally allocate memory when a write to the memory location occurs.
10) But the write is happening not from user space but by DMA from a device.
So the question is what should happen if the memory isn't actually
allocated. Should get_user_pages check?
It doesn't seem to be doing so. Can it?
More information about the Kernelnewbies