[CRIU] [PATCH v3 16/19] lazy-pages: introduce uffd_seek_or_zero_pages

Mike Rapoport rppt at linux.vnet.ibm.com
Tue Nov 15 08:57:25 PST 2016


This part of code is responsible for reseting pagemap to proper locatation,
and mapping requested address to zero pfn if needed. The upcoming addtions
to uffd.c will reuse this code.

Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 criu/uffd.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/criu/uffd.c b/criu/uffd.c
index 3750f5b..1ab4df2 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -569,7 +569,17 @@ static int uffd_zero(struct lazy_pages_info *lpi, __u64 address, int nr_pages)
 	return 0;
 }
 
-static int uffd_handle_pages(struct lazy_pages_info *lpi, __u64 address, int nr)
+/*
+ * Seek for the requested address in the pagemap. If it is found, the
+ * subsequent call to pr->page_read will bring us the data. If the
+ * address is not found in the pagemap, but no error occured, the
+ * address should be mapped to zero pfn.
+ *
+ * Returns 0 for zero pages, 1 for "real" pages and negative value on
+ * error
+ */
+static int uffd_seek_or_zero_pages(struct lazy_pages_info *lpi, __u64 address,
+				   int nr)
 {
 	int ret;
 
@@ -588,6 +598,17 @@ static int uffd_handle_pages(struct lazy_pages_info *lpi, __u64 address, int nr)
 	if (ret == 0 || pagemap_zero(lpi->pr.pe))
 		return uffd_zero(lpi, address, nr);
 
+	return 1;
+}
+
+static int uffd_handle_pages(struct lazy_pages_info *lpi, __u64 address, int nr)
+{
+	int ret;
+
+	ret = uffd_seek_or_zero_pages(lpi, address, nr);
+	if (ret <= 0)
+		return ret;
+
 	ret = lpi->pr.read_pages(&lpi->pr, address, nr, lpi->buf, 0);
 	if (ret <= 0) {
 		pr_err("%d: failed reading pages at %llx\n", lpi->pid, address);
-- 
1.9.1



More information about the CRIU mailing list