2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-29 13:28:27 +00:00

lazy-pages: add handling of UFFD_EVENT_REMOVE

When the restored process calls madvise(MADV_DONTNEED) or
madvise(MADV_REMOVE) the memory range specified by the madvise() call
should be remapped to zero pfn and we should stop monitoring this range in
order to avoid its pollution with data the process does not expect.
All we need to do here, is to unregister the memory range from userfaultfd
and the kernel will take care of the rest.

travis-ci: success for lazy-pages: add non-#PF events handling (rev2)
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
Mike Rapoport 2017-02-06 13:44:06 +02:00 committed by Andrei Vagin
parent 7df4f14be6
commit ba3d099b74

View File

@ -671,6 +671,24 @@ static int handle_remaining_pages(struct lazy_pages_info *lpi)
return 0; return 0;
} }
static int handle_remove(struct lazy_pages_info *lpi, struct uffd_msg *msg)
{
struct uffdio_range unreg;
unreg.start = msg->arg.remove.start;
unreg.len = msg->arg.remove.end - msg->arg.remove.start;
lp_debug(lpi, "REMOVE: %Lx(%Lx)\n", unreg.start, unreg.len);
if (ioctl(lpi->lpfd.fd, UFFDIO_UNREGISTER, &unreg)) {
pr_perror("Failed to unregister (%llx - %llx)", unreg.start,
unreg.start + unreg.len);
return -1;
}
return drop_lazy_iovs(lpi, unreg.start, unreg.len);
}
static int handle_page_fault(struct lazy_pages_info *lpi, struct uffd_msg *msg) static int handle_page_fault(struct lazy_pages_info *lpi, struct uffd_msg *msg)
{ {
struct lp_req *req; struct lp_req *req;
@ -731,6 +749,8 @@ static int handle_uffd_event(struct epoll_rfd *lpfd)
switch (msg.event) { switch (msg.event) {
case UFFD_EVENT_PAGEFAULT: case UFFD_EVENT_PAGEFAULT:
return handle_page_fault(lpi, &msg); return handle_page_fault(lpi, &msg);
case UFFD_EVENT_REMOVE:
return handle_remove(lpi, &msg);
default: default:
lp_err(lpi, "unexpected uffd event %u\n", msg.event); lp_err(lpi, "unexpected uffd event %u\n", msg.event);
return -1; return -1;