How to map pages using a page error handler?

I want to use my pagefault handler struct vm_area_struct *to map a physical page to user space.

This is how I continue:

  • I globally highlight a page with alloc_page(GFP_USER)during module initialization (I tried various GFPs).
  • I create struct vm_area_struct, install my own page_file handler and attach vmato current->mm.

If a page error occurs:

  • I installed vmf->pageon the previously assigned page and returned 0.

As a result, each virtual page in vmashould be displayed on the same physical page after a page error.

But here is what I noticed:

  • When I write to a page from my kernel module, it is reflected in my user space program.
  • When I write to a page from my user space, I do not see it in my kernel module.
  • When I use get_user_pagesthe kernel in my module to get the page (instead of using my global variable), I get a different physical address than the global page variable. I type the address using page_to_phys(page). The entry on this page is reflected in my user program.

All this is done in the page error handler. By the way

How to explain this curious behavior?

To access the page from kernel space, I use kmap_atomicand kunmap_atomic.

+1
source share
1

. , vmf->page, . . , , , .

do_cow_fault mm/memory.c.

+1

Source: https://habr.com/ru/post/1670217/


All Articles