[CRIU] [PATCH 2/5] kdat: Relax uffd checks (v2)
Pavel Emelyanov
xemul at virtuozzo.com
Wed Apr 26 12:46:52 PDT 2017
v2: When uffd is present, the reported features may still be 0,
so we need one more bool for uffd syscall itself.
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
criu/cr-check.c | 7 ++++++-
criu/cr-service.c | 4 ++--
criu/include/kerndat.h | 3 ++-
criu/kerndat.c | 10 ++++++----
criu/uffd.c | 2 +-
5 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/criu/cr-check.c b/criu/cr-check.c
index 8d13504..0fcb285 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -1075,9 +1075,14 @@ static int check_uffd(void)
UFFD_FEATURE_EVENT_UNMAP |
UFFD_FEATURE_EVENT_REMOVE;
- if (kerndat_uffd(true))
+ if (kerndat_uffd())
return -1;
+ if (!kdat.has_uffd) {
+ pr_err("UFFD is not supported\n");
+ return -1;
+ }
+
if ((kdat.uffd_features & features) != features) {
pr_err("Userfaultfd missing essential features\n");
return -1;
diff --git a/criu/cr-service.c b/criu/cr-service.c
index d59ab8b..8cf76dd 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -893,7 +893,7 @@ static int handle_feature_check(int sk, CriuReq * msg)
if ((msg->features->has_lazy_pages == 1) &&
(msg->features->lazy_pages == true)) {
- ret = kerndat_uffd(true);
+ ret = kerndat_uffd();
/*
* Not checking for specific UFFD features yet.
@@ -902,7 +902,7 @@ static int handle_feature_check(int sk, CriuReq * msg)
* be extended in the future for a more detailed
* UFFD feature check.
*/
- if (ret)
+ if (ret || !kdat.has_uffd)
feat.lazy_pages = false;
else
feat.lazy_pages = true;
diff --git a/criu/include/kerndat.h b/criu/include/kerndat.h
index b8508ff..e6eb395 100644
--- a/criu/include/kerndat.h
+++ b/criu/include/kerndat.h
@@ -45,6 +45,7 @@ struct kerndat_s {
unsigned int has_xtlocks;
unsigned long mmap_min_addr;
bool has_tcp_half_closed;
+ bool has_uffd;
unsigned long uffd_features;
bool has_nsid;
bool has_link_nsid;
@@ -70,7 +71,7 @@ enum {
extern int kerndat_fs_virtualized(unsigned int which, u32 kdev);
extern int kerndat_tcp_repair();
-extern int kerndat_uffd(bool need_uffd);
+extern int kerndat_uffd(void);
extern int kerndat_has_nspid(void);
#endif /* __CR_KERNDAT_H__ */
diff --git a/criu/kerndat.c b/criu/kerndat.c
index 9c47b13..96c969a 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -586,7 +586,7 @@ static int kerndat_compat_restore(void)
return 0;
}
-int kerndat_uffd(bool need_uffd)
+int kerndat_uffd(void)
{
struct uffdio_api uffdio_api;
int uffd;
@@ -598,14 +598,16 @@ int kerndat_uffd(bool need_uffd)
* on this system. Additionally checking for ENOSYS
* makes sure it is actually not implemented.
*/
- if (uffd == -1 && errno == ENOSYS) {
- if (!need_uffd)
+ if (uffd == -1) {
+ if (errno == ENOSYS)
return 0;
pr_err("Lazy pages are not available\n");
return -1;
}
+ kdat.has_uffd = true;
+
uffdio_api.api = UFFD_API;
uffdio_api.features = 0;
if (ioctl(uffd, UFFDIO_API, &uffdio_api)) {
@@ -718,7 +720,7 @@ int kerndat_init_rst(void)
if (!ret)
ret = kerndat_compat_restore();
if (!ret)
- ret = kerndat_uffd(opts.lazy_pages);
+ ret = kerndat_uffd();
if (!ret)
ret = kerndat_socket_netns();
if (!ret)
diff --git a/criu/uffd.c b/criu/uffd.c
index b2cf102..205045e 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -1115,7 +1115,7 @@ int cr_lazy_pages(bool daemon)
int lazy_sk;
int ret;
- if (kerndat_uffd(true))
+ if (kerndat_uffd() || !kdat.has_uffd)
return -1;
if (prepare_dummy_pstree())
--
2.5.5
More information about the CRIU
mailing list