How "get_user_pages" works (for linux driver)

While working on the PCI PCI driver, now I'm trying to write DMA codes using scatter / build.

Currently, I have learned that to access DMA data directly from user space, we need to bind user space pages to kernel space.

And for this we have get_user_pages, its full definition:

int get_user_pages (struct task_struct * tsk,
struct mm_struct * mm,
unsigned long start,
int nr_pages,
int write,
int force,
struct page ** pages,
struct vm_area_struct ** vmas);

My first question concerns struct page ** pages. Here we need to allocate memory (using kcallocfor ex.) For pagesbefore calling get_user_pages?

My second question concerns unsigned long start, on the manual page, it says “user start address”, does this mean that if I declare a pointer in user space, for example int *p, “user start address”, should I go to kernel space p?

My third question also concerns unsigned long start, if I understood correctly in the second question, then how can we make sure that this address starts at the top of the page?

So, three questions, thanks for the promotion.

+4
1

**. ( kcalloc ex.) get_user_pages?

, , ( nr_pages)

4 , struct page *pages[4]; .

unsigned, man, " ", , int * p, " ", p?

, (, malloc).

, , , ?

, getpagesize.

, : get_user_pages example .

+3

All Articles