[5/7] uffd: Helper to complete the #PF

Submitted by Pavel Emelianov on Nov. 16, 2016, 9:39 a.m.

Details

Message ID 582C2957.7080504@virtuozzo.com
State Superseded
Commit 213fbcdc96b8a0aa866a25f473854f653d4801eb
Headers show

Commit Message

Pavel Emelianov Nov. 16, 2016, 9:39 a.m.
The _copy and _update_lazy_iovecs are both called by hands
once the data is ready.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/uffd.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/uffd.c b/criu/uffd.c
index 46ac9f2..93cdee7 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -82,6 +82,7 @@  struct lazy_pages_info {
 	struct list_head l;
 
 	void *buf;
+	bool remaining;
 };
 
 static LIST_HEAD(lpis);
@@ -575,6 +576,17 @@  static int uffd_copy(struct lazy_pages_info *lpi, __u64 address, int nr_pages)
 	return 0;
 }
 
+static int complete_page_fault(struct lazy_pages_info *lpi, unsigned long vaddr, int nr)
+{
+	if (uffd_copy(lpi, vaddr, nr))
+		return -1;
+
+	if (lpi->remaining)
+		return 0;
+
+	return update_lazy_iovecs(lpi, vaddr, nr * PAGE_SIZE);
+}
+
 static int uffd_zero(struct lazy_pages_info *lpi, __u64 address, int nr_pages)
 {
 	struct uffdio_zeropage uffdio_zeropage;
@@ -643,7 +655,7 @@  static int uffd_handle_pages(struct lazy_pages_info *lpi, __u64 address, int nr)
 		return ret;
 	}
 
-	return uffd_copy(lpi, address, nr);
+	return complete_page_fault(lpi, address, nr);
 }
 
 static int handle_remaining_pages(struct lazy_pages_info *lpi)
@@ -651,6 +663,8 @@  static int handle_remaining_pages(struct lazy_pages_info *lpi)
 	struct lazy_iovec *lazy_iov;
 	int nr_pages, err;
 
+	lpi->remaining = true;
+
 	lpi->pr.reset(&lpi->pr);
 
 	list_for_each_entry(lazy_iov, &lpi->iovs, l) {
@@ -689,13 +703,7 @@  static int page_fault_local(struct lazy_pages_info *lpi, __u64 address, int nr)
 	if (page_fault_common(lpi, address, nr, PR_ASYNC | PR_ASAP))
 		return -1;
 
-	if (uffd_copy(lpi, address, nr))
-		return -1;
-
-	if (update_lazy_iovecs(lpi, address, PAGE_SIZE * nr))
-		return -1;
-
-	return 0;
+	return complete_page_fault(lpi, address, nr);
 }
 
 static int page_fault_remote(struct lazy_pages_info *lpi, __u64 address, int nr)
@@ -963,13 +971,7 @@  static int page_server_event(struct lazy_pages_fd *lpfd)
 		if (receive_remote_pages(nr_pages * PAGE_SIZE, lpi->buf))
 			return -1;
 
-		if (uffd_copy(lpi, addr, nr_pages))
-			return -1;
-
-		if (update_lazy_iovecs(lpi, addr, PAGE_SIZE * nr_pages))
-			return -1;
-
-		return 0;
+		return complete_page_fault(lpi, addr, nr_pages);
 	}
 }
 

Comments

Mike Rapoport Nov. 16, 2016, 10:56 a.m.
On Wed, Nov 16, 2016 at 11:39 AM, Pavel Emelyanov <xemul@virtuozzo.com> wrote:
> The _copy and _update_lazy_iovecs are both called by hands
> once the data is ready.
>
> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
> ---

Acked-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

>  criu/uffd.c | 32 +++++++++++++++++---------------
>  1 file changed, 17 insertions(+), 15 deletions(-)
>
> diff --git a/criu/uffd.c b/criu/uffd.c
> index 46ac9f2..93cdee7 100644
> --- a/criu/uffd.c
> +++ b/criu/uffd.c
> @@ -82,6 +82,7 @@ struct lazy_pages_info {
>         struct list_head l;
>
>         void *buf;
> +       bool remaining;
>  };
>
>  static LIST_HEAD(lpis);
> @@ -575,6 +576,17 @@ static int uffd_copy(struct lazy_pages_info *lpi, __u64 address, int nr_pages)
>         return 0;
>  }
>
> +static int complete_page_fault(struct lazy_pages_info *lpi, unsigned long vaddr, int nr)
> +{
> +       if (uffd_copy(lpi, vaddr, nr))
> +               return -1;
> +
> +       if (lpi->remaining)
> +               return 0;
> +
> +       return update_lazy_iovecs(lpi, vaddr, nr * PAGE_SIZE);
> +}
> +
>  static int uffd_zero(struct lazy_pages_info *lpi, __u64 address, int nr_pages)
>  {
>         struct uffdio_zeropage uffdio_zeropage;
> @@ -643,7 +655,7 @@ static int uffd_handle_pages(struct lazy_pages_info *lpi, __u64 address, int nr)
>                 return ret;
>         }
>
> -       return uffd_copy(lpi, address, nr);
> +       return complete_page_fault(lpi, address, nr);
>  }
>
>  static int handle_remaining_pages(struct lazy_pages_info *lpi)
> @@ -651,6 +663,8 @@ static int handle_remaining_pages(struct lazy_pages_info *lpi)
>         struct lazy_iovec *lazy_iov;
>         int nr_pages, err;
>
> +       lpi->remaining = true;
> +
>         lpi->pr.reset(&lpi->pr);
>
>         list_for_each_entry(lazy_iov, &lpi->iovs, l) {
> @@ -689,13 +703,7 @@ static int page_fault_local(struct lazy_pages_info *lpi, __u64 address, int nr)
>         if (page_fault_common(lpi, address, nr, PR_ASYNC | PR_ASAP))
>                 return -1;
>
> -       if (uffd_copy(lpi, address, nr))
> -               return -1;
> -
> -       if (update_lazy_iovecs(lpi, address, PAGE_SIZE * nr))
> -               return -1;
> -
> -       return 0;
> +       return complete_page_fault(lpi, address, nr);
>  }
>
>  static int page_fault_remote(struct lazy_pages_info *lpi, __u64 address, int nr)
> @@ -963,13 +971,7 @@ static int page_server_event(struct lazy_pages_fd *lpfd)
>                 if (receive_remote_pages(nr_pages * PAGE_SIZE, lpi->buf))
>                         return -1;
>
> -               if (uffd_copy(lpi, addr, nr_pages))
> -                       return -1;
> -
> -               if (update_lazy_iovecs(lpi, addr, PAGE_SIZE * nr_pages))
> -                       return -1;
> -
> -               return 0;
> +               return complete_page_fault(lpi, addr, nr_pages);
>         }
>  }
>
> --
> 2.5.0
>