kerndat: initialize zero_page_pfn to -1

Submitted by Andrei Vagin on April 29, 2016, 6:17 p.m.

Details

Message ID 1461953869-8161-1-git-send-email-avagin@openvz.org
State Rejected
Series "kerndat: initialize zero_page_pfn to -1"
Headers show

Commit Message

Andrei Vagin April 29, 2016, 6:17 p.m.
From: Andrew Vagin <avagin@virtuozzo.com>

zero_page_pfn should be invalid if it isn't set to a real value.

zero is bad, because pagemap returns zero pfn-s for non-root users.

$ python test/zdtm.py run -t zdtm/static/env00 -k always -f h --user --norst

Patch hide | download patch | download mbox

========================== Run zdtm/static/env00 in h ==========================
Start test
./env00 --pidfile=env00.pid --outfile=env00.out --envname=ENV_00_TEST
Run criu dump
Wait for zdtm/static/env00 to die for 0.100000
========================= Test zdtm/static/env00 PASS ==========================

$ ./crit/crit show test/dump/zdtm/static/env00/24/1/pagemap-24.img
{
    "magic": "PAGEMAP",
    "entries": [
        {
            "pages_id": 1
        },
        {
            "vaddr": "0x7ffcfd5ed000",
            "nr_pages": 2
        }
    ]
}

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
---
 criu/kerndat.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/criu/kerndat.c b/criu/kerndat.c
index 8636b07..8127b6e 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -292,7 +292,13 @@  no_dt:
 static int init_zero_page_pfn()
 {
 	void *addr;
-	int ret;
+	int ret = 0;
+
+	kdat.zero_page_pfn = -1;
+	if (kdat.pmap != PM_FULL) {
+		pr_info("Zero page detection failed, optimization turns off.\n");
+		return 0;
+	}
 
 	addr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 	if (addr == MAP_FAILED) {
@@ -305,11 +311,6 @@  static int init_zero_page_pfn()
 		return -1;
 	}
 
-	if (kdat.pmap != PM_FULL) {
-		pr_info("Zero page detection failed, optimization turns off.\n");
-		return 0;
-	}
-
 	ret = vaddr_to_pfn((unsigned long)addr, &kdat.zero_page_pfn);
 	munmap(addr, PAGE_SIZE);
 

Comments

Cyrill Gorcunov April 29, 2016, 6:47 p.m.
On Fri, Apr 29, 2016 at 09:17:49PM +0300, Andrey Vagin wrote:
> From: Andrew Vagin <avagin@virtuozzo.com>
> 
> zero_page_pfn should be invalid if it isn't set to a real value.
> 
> zero is bad, because pagemap returns zero pfn-s for non-root users.
> 
> $ python test/zdtm.py run -t zdtm/static/env00 -k always -f h --user --norst
> ========================== Run zdtm/static/env00 in h ==========================
> Start test
> ./env00 --pidfile=env00.pid --outfile=env00.out --envname=ENV_00_TEST
> Run criu dump
> Wait for zdtm/static/env00 to die for 0.100000
> ========================= Test zdtm/static/env00 PASS ==========================
> 
> $ ./crit/crit show test/dump/zdtm/static/env00/24/1/pagemap-24.img
> {
>     "magic": "PAGEMAP",
>     "entries": [
>         {
>             "pages_id": 1
>         },
>         {
>             "vaddr": "0x7ffcfd5ed000",
>             "nr_pages": 2
>         }
>     ]
> }
> 
> Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Pavel Emelianov May 5, 2016, 12:17 p.m.
Applied, thanks