From d4edd9bf566b5e90d848667e64f0863d6c978bd4 Mon Sep 17 00:00:00 2001 From: Mike Rapoport Date: Tue, 15 Nov 2016 18:57:25 +0200 Subject: [PATCH] lazy-pages: introduce uffd_seek_or_zero_pages 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. travis-ci: success for uffd: A new set of improvements Signed-off-by: Mike Rapoport Signed-off-by: Pavel Emelyanov --- criu/uffd.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/criu/uffd.c b/criu/uffd.c index cec4c214d..e4d2a780a 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; @@ -582,6 +592,17 @@ static int uffd_handle_pages(struct lazy_pages_info *lpi, __u64 address, int nr) if (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);