Commit 39f1388b authored by Mike Rapoport's avatar Mike Rapoport Committed by Andrei Vagin

lazy-pages: prepare for non-#PF events handling

Rename handle_user_fault to handle_uffd_event and split actual page fault
handling to a helper function

travis-ci: success for lazy-pages: add non-#PF events handling
Signed-off-by: 's avatarMike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent fcfdc196
...@@ -73,7 +73,7 @@ struct lazy_pages_info { ...@@ -73,7 +73,7 @@ struct lazy_pages_info {
}; };
static LIST_HEAD(lpis); static LIST_HEAD(lpis);
static int handle_user_fault(struct epoll_rfd *lpfd); static int handle_uffd_event(struct epoll_rfd *lpfd);
static struct lazy_pages_info *lpi_init(void) static struct lazy_pages_info *lpi_init(void)
{ {
...@@ -86,7 +86,7 @@ static struct lazy_pages_info *lpi_init(void) ...@@ -86,7 +86,7 @@ static struct lazy_pages_info *lpi_init(void)
memset(lpi, 0, sizeof(*lpi)); memset(lpi, 0, sizeof(*lpi));
INIT_LIST_HEAD(&lpi->iovs); INIT_LIST_HEAD(&lpi->iovs);
INIT_LIST_HEAD(&lpi->l); INIT_LIST_HEAD(&lpi->l);
lpi->lpfd.revent = handle_user_fault; lpi->lpfd.revent = handle_uffd_event;
return lpi; return lpi;
} }
...@@ -633,34 +633,13 @@ static int handle_remaining_pages(struct lazy_pages_info *lpi) ...@@ -633,34 +633,13 @@ static int handle_remaining_pages(struct lazy_pages_info *lpi)
return 0; return 0;
} }
static int handle_user_fault(struct epoll_rfd *lpfd) static int handle_page_fault(struct lazy_pages_info *lpi, struct uffd_msg *msg)
{ {
struct lazy_pages_info *lpi;
struct uffd_msg msg;
__u64 address; __u64 address;
int ret; int ret;
lpi = container_of(lpfd, struct lazy_pages_info, lpfd);
ret = read(lpfd->fd, &msg, sizeof(msg));
if (!ret)
return 1;
if (ret != sizeof(msg)) {
if (ret < 0)
pr_perror("Can't read userfaultfd message");
else
pr_err("Can't read userfaultfd message: short read");
return -1;
}
if (msg.event != UFFD_EVENT_PAGEFAULT) {
pr_err("unexpected msg event %u\n", msg.event);
return -1;
}
/* Align requested address to the next page boundary */ /* Align requested address to the next page boundary */
address = msg.arg.pagefault.address & ~(page_size() - 1); address = msg->arg.pagefault.address & ~(page_size() - 1);
pr_debug("%d: #PF at 0x%llx\n", lpi->pid, address); pr_debug("%d: #PF at 0x%llx\n", lpi->pid, address);
#if 0 #if 0
...@@ -687,6 +666,37 @@ static int handle_user_fault(struct epoll_rfd *lpfd) ...@@ -687,6 +666,37 @@ static int handle_user_fault(struct epoll_rfd *lpfd)
return 0; return 0;
} }
static int handle_uffd_event(struct epoll_rfd *lpfd)
{
struct lazy_pages_info *lpi;
struct uffd_msg msg;
int ret;
lpi = container_of(lpfd, struct lazy_pages_info, lpfd);
ret = read(lpfd->fd, &msg, sizeof(msg));
if (!ret)
return 1;
if (ret != sizeof(msg)) {
if (ret < 0)
pr_perror("Can't read userfaultfd message");
else
pr_err("Can't read userfaultfd message: short read");
return -1;
}
switch (msg.event) {
case UFFD_EVENT_PAGEFAULT:
return handle_page_fault(lpi, &msg);
default:
pr_err("unexpected uffd event %u\n", msg.event);
return -1;
}
return 0;
}
static int lazy_pages_summary(struct lazy_pages_info *lpi) static int lazy_pages_summary(struct lazy_pages_info *lpi)
{ {
pr_debug("Process %d: with UFFD transferred pages: (%ld/%ld)\n", pr_debug("Process %d: with UFFD transferred pages: (%ld/%ld)\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment