criu: uffd runtime detection

Submitted by Adrian Reber on May 4, 2016, 8:22 a.m.

Details

Message ID 1462350145-6904-1-git-send-email-adrian@lisas.de
State Accepted
Series "criu: uffd runtime detection"
Commit bbd910f4d062af5019343557cde06807f58adb5e
Headers show

Commit Message

Adrian Reber May 4, 2016, 8:22 a.m.
From: Adrian Reber <areber@redhat.com>

Now that userfaultfd/lazy-pages support is enable all the time, this
adds runtime detection of userfaultfd. On a system without the
userfaultfd syscall following is printed:

uffd daemon:

(00.000004) Error (uffd.c:176): lazy-pages: Runtime detection of userfaultfd failed on this system.
(00.000024) Error (uffd.c:177): lazy-pages: Processes cannot be lazy-restored on this system.

or criu restore

(00.457047)   6858: Error (uffd.c:176): lazy-pages: Runtime detection of userfaultfd failed on this system.
(00.457049)   6858: Error (uffd.c:177): lazy-pages: Processes cannot be lazy-restored on this system.

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 criu/uffd.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/uffd.c b/criu/uffd.c
index c17f003..fb0cab1 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -160,10 +160,33 @@  out:
 	return ret;
 }
 
+/* Runtime detection if userfaultfd can be used */
+
+static int check_for_uffd()
+{
+	int uffd;
+
+	uffd = syscall(SYS_userfaultfd, 0);
+	/*
+	 * uffd == -1 is probably enough to not use lazy-restore
+	 * on this system. Additionally checking for ENOSYS
+	 * makes sure it is actually not implemented.
+	 */
+	if ((uffd == -1) && (errno == ENOSYS)) {
+		pr_err("Runtime detection of userfaultfd failed on this system.\n");
+		pr_err("Processes cannot be lazy-restored on this system.\n");
+		return -1;
+	}
+	close(uffd);
+	return 0;
+}
+
 /* This function is used by 'criu restore --lazy-pages' */
 int setup_uffd(struct task_restore_args *task_args, int pid)
 {
 	struct uffdio_api uffdio_api;
+	if (check_for_uffd())
+		return -1;
 	/*
 	 * Open userfaulfd FD which is passed to the restorer blob and
 	 * to a second process handling the userfaultfd page faults.
@@ -810,6 +833,9 @@  int cr_lazy_pages()
 	int epollfd;
 	int ret;
 
+	if (check_for_uffd())
+		return -1;
+
 	if (!opts.addr) {
 		pr_info("Please specify a file name for the unix domain socket\n");
 		pr_info("used to communicate between the lazy-pages server\n");

Comments

Dmitry Safonov May 4, 2016, 11:36 a.m.
On 05/04/2016 12:42 PM, Patchwork wrote:
> == Series Details ==
>
> Series: criu: uffd runtime detection
> URL   : https://zdtm.openvz.org/series/77/
> State : failure
>
> == Logs ==
>
> For more details see: https://travis-ci.org/criupatchwork/criu/builds/127744081

Ok, that's on me - will investigate now.
Mike Rapoport May 4, 2016, 2:57 p.m.
On Wed, May 04, 2016 at 08:22:25AM +0000, Adrian Reber wrote:
> From: Adrian Reber <areber@redhat.com>
> 
> Now that userfaultfd/lazy-pages support is enable all the time, this
> adds runtime detection of userfaultfd. On a system without the
> userfaultfd syscall following is printed:
> 
> uffd daemon:
> 
> (00.000004) Error (uffd.c:176): lazy-pages: Runtime detection of userfaultfd failed on this system.
> (00.000024) Error (uffd.c:177): lazy-pages: Processes cannot be lazy-restored on this system.
> 
> or criu restore
> 
> (00.457047)   6858: Error (uffd.c:176): lazy-pages: Runtime detection of userfaultfd failed on this system.
> (00.457049)   6858: Error (uffd.c:177): lazy-pages: Processes cannot be lazy-restored on this system.
> 
> Signed-off-by: Adrian Reber <areber@redhat.com>
> ---
>  criu/uffd.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)

Acked-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
 
> diff --git a/criu/uffd.c b/criu/uffd.c
> index c17f003..fb0cab1 100644
> --- a/criu/uffd.c
> +++ b/criu/uffd.c
> @@ -160,10 +160,33 @@ out:
>  	return ret;
>  }
> 
> +/* Runtime detection if userfaultfd can be used */
> +
> +static int check_for_uffd()
> +{
> +	int uffd;
> +
> +	uffd = syscall(SYS_userfaultfd, 0);
> +	/*
> +	 * uffd == -1 is probably enough to not use lazy-restore
> +	 * on this system. Additionally checking for ENOSYS
> +	 * makes sure it is actually not implemented.
> +	 */
> +	if ((uffd == -1) && (errno == ENOSYS)) {
> +		pr_err("Runtime detection of userfaultfd failed on this system.\n");
> +		pr_err("Processes cannot be lazy-restored on this system.\n");
> +		return -1;
> +	}
> +	close(uffd);
> +	return 0;
> +}
> +
>  /* This function is used by 'criu restore --lazy-pages' */
>  int setup_uffd(struct task_restore_args *task_args, int pid)
>  {
>  	struct uffdio_api uffdio_api;
> +	if (check_for_uffd())
> +		return -1;
>  	/*
>  	 * Open userfaulfd FD which is passed to the restorer blob and
>  	 * to a second process handling the userfaultfd page faults.
> @@ -810,6 +833,9 @@ int cr_lazy_pages()
>  	int epollfd;
>  	int ret;
> 
> +	if (check_for_uffd())
> +		return -1;
> +
>  	if (!opts.addr) {
>  		pr_info("Please specify a file name for the unix domain socket\n");
>  		pr_info("used to communicate between the lazy-pages server\n");
> -- 
> 1.8.3.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
>
Pavel Emelianov May 5, 2016, 12:22 p.m.
Applied, thanks