[CRIU] [PATCH 1/2] vma: Unify private VMAs testing
Cyrill Gorcunov
gorcunov at openvz.org
Sun Mar 29 12:17:08 PDT 2015
We have two helpers for VMA type testing: privately_dump_vma() and vma_priv(). They
work with different types but basically do the same: check if we should dump VMA into
the image and restore it back then.
Lets unify they both into common vma_entry_is_private() helper and vma_area_is_private()
for working with vma_area type.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
cr-dump.c | 36 ------------------------------------
cr-restore.c | 10 +++++-----
include/restorer.h | 4 ----
include/vma.h | 17 ++++++++++++++++-
mem.c | 6 +++---
pie/restorer.c | 6 +++---
proc_parse.c | 2 +-
7 files changed, 28 insertions(+), 53 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index cc524558989a..ac418650807c 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -81,42 +81,6 @@
static char loc_buf[PAGE_SIZE];
-bool privately_dump_vma(struct vma_area *vma)
-{
- /*
- * The special areas are not dumped.
- */
- if (!(vma->e->status & VMA_AREA_REGULAR))
- return false;
-
- /* No dumps for file-shared mappings */
- if (vma->e->status & VMA_FILE_SHARED)
- return false;
-
- /* No dumps for SYSV IPC mappings */
- if (vma->e->status & VMA_AREA_SYSVIPC)
- return false;
-
-#ifdef CONFIG_VDSO
- /* No dumps for vDSO VVAR data */
- if (vma->e->status & VMA_AREA_VVAR)
- return false;
-#endif
- if (vma_area_is(vma, VMA_ANON_SHARED))
- return false;
-
- if (!vma_area_is(vma, VMA_ANON_PRIVATE) &&
- !vma_area_is(vma, VMA_FILE_PRIVATE)) {
- pr_warn("Unexpected VMA area found\n");
- return false;
- }
-
- if (vma->e->end > TASK_SIZE)
- return false;
-
- return true;
-}
-
static void close_vma_file(struct vma_area *vma)
{
if (vma->vm_file_fd < 0)
diff --git a/cr-restore.c b/cr-restore.c
index 823bf156546b..9947c0ae7f10 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -252,7 +252,7 @@ static int map_private_vma(pid_t pid, struct vma_area *vma, void **tgt_addr,
if (p->e->start > vma->e->start)
break;
- if (!vma_priv(p->e))
+ if (!vma_area_is_private(p))
continue;
if (p->e->end != vma->e->end ||
@@ -364,7 +364,7 @@ static int premap_priv_vmas(pid_t pid, struct vm_area_list *vmas, void *at)
}
pstart = vma->e->start;
- if (!vma_priv(vma->e))
+ if (!vma_area_is_private(vma))
continue;
ret = map_private_vma(pid, vma, &at, &pvma, parent_vmas);
@@ -430,7 +430,7 @@ static int restore_priv_vma_content(pid_t pid)
*/
if (va < vma->e->start)
goto err_addr;
- else if (unlikely(!vma_priv(vma->e))) {
+ else if (unlikely(!vma_area_is_private(vma))) {
pr_err("Trying to restore page for non-private VMA\n");
goto err_addr;
}
@@ -573,7 +573,7 @@ static int unmap_guard_pages()
struct list_head *vmas = &rsti(current)->vmas.h;
list_for_each_entry(vma, vmas, list) {
- if (!vma_priv(vma->e))
+ if (!vma_area_is_private(vma))
continue;
if (vma->e->flags & MAP_GROWSDOWN) {
@@ -2646,7 +2646,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
*vme = *vma->e;
- if (vma_priv(vma->e))
+ if (vma_area_is_private(vma))
vma_premmaped_start(vme) = vma->premmaped_addr;
}
diff --git a/include/restorer.h b/include/restorer.h
index 746810583477..ded084a522df 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -197,8 +197,4 @@ enum {
/* the restorer_blob_offset__ prefix is added by gen_offsets.sh */
#define restorer_sym(rblob, name) ((void *)(rblob) + restorer_blob_offset__##name)
-#define vma_priv(vma) ((vma_entry_is(vma, VMA_AREA_REGULAR)) && \
- (vma_entry_is(vma, VMA_ANON_PRIVATE) || \
- vma_entry_is(vma, VMA_FILE_PRIVATE)))
-
#endif /* __CR_RESTORER_H__ */
diff --git a/include/vma.h b/include/vma.h
index 878658cae342..8b7a06cd800d 100644
--- a/include/vma.h
+++ b/include/vma.h
@@ -1,7 +1,10 @@
#ifndef __CR_VMA_H__
#define __CR_VMA_H__
+#include "asm/types.h"
+#include "image.h"
#include "list.h"
+
#include "protobuf/vma.pb-c.h"
struct vm_area_list {
@@ -69,7 +72,6 @@ struct vma_area {
extern struct vma_area *alloc_vma_area(void);
extern int collect_mappings(pid_t pid, struct vm_area_list *vma_area_list);
extern void free_mappings(struct vm_area_list *vma_area_list);
-extern bool privately_dump_vma(struct vma_area *vma);
#define vma_area_is(vma_area, s) vma_entry_is((vma_area)->e, s)
#define vma_area_len(vma_area) vma_entry_len((vma_area)->e)
@@ -90,4 +92,17 @@ static inline int in_vma_area(struct vma_area *vma, unsigned long addr)
addr < (unsigned long)vma->e->end;
}
+static inline bool vma_entry_is_private(VmaEntry *entry)
+{
+ return vma_entry_is(entry, VMA_AREA_REGULAR) &&
+ (vma_entry_is(entry, VMA_ANON_PRIVATE) ||
+ vma_entry_is(entry, VMA_FILE_PRIVATE)) &&
+ (entry->end <= TASK_SIZE);
+}
+
+static inline bool vma_area_is_private(struct vma_area *vma)
+{
+ return vma_entry_is_private(vma->e);
+}
+
#endif /* __CR_VMA_H__ */
diff --git a/mem.c b/mem.c
index 9164f97732ca..1821874c884d 100644
--- a/mem.c
+++ b/mem.c
@@ -178,7 +178,7 @@ static struct parasite_dump_pages_args *prep_dump_pages_args(struct parasite_ctl
args->nr_vmas = 0;
list_for_each_entry(vma, &vma_area_list->h, list) {
- if (!privately_dump_vma(vma))
+ if (!vma_area_is_private(vma))
continue;
if (vma->e->prot & PROT_READ)
continue;
@@ -293,7 +293,7 @@ static int __parasite_dump_pages_seized(struct parasite_ctl *ctl,
u64 off = 0;
u64 *map;
- if (!privately_dump_vma(vma_area))
+ if (!vma_area_is_private(vma_area))
continue;
map = pmc_get_map(&pmc, vma_area);
@@ -441,7 +441,7 @@ int prepare_mm_pid(struct pstree_item *i)
}
list_add_tail(&vma->list, &ri->vmas.h);
- if (vma_priv(vma->e)) {
+ if (vma_area_is_private(vma)) {
ri->vmas.priv_size += vma_area_len(vma);
if (vma->e->flags & MAP_GROWSDOWN)
ri->vmas.priv_size += PAGE_SIZE;
diff --git a/pie/restorer.c b/pie/restorer.c
index c890360af564..c5e44a524c25 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -802,7 +802,7 @@ long __export_restore_task(struct task_restore_args *args)
if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR))
continue;
- if (!vma_priv(vma_entry))
+ if (!vma_entry_is_private(vma_entry))
continue;
if (vma_entry->end >= TASK_SIZE)
@@ -823,7 +823,7 @@ long __export_restore_task(struct task_restore_args *args)
if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR))
continue;
- if (!vma_priv(vma_entry))
+ if (!vma_entry_is_private(vma_entry))
continue;
if (vma_entry->start > TASK_SIZE)
@@ -846,7 +846,7 @@ long __export_restore_task(struct task_restore_args *args)
if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR))
continue;
- if (vma_priv(vma_entry))
+ if (vma_entry_is_private(vma_entry))
continue;
va = restore_mapping(vma_entry);
diff --git a/proc_parse.c b/proc_parse.c
index 2354561fa446..88af28bd8753 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -483,7 +483,7 @@ static int vma_list_add(struct vma_area *vma_area,
list_add_tail(&vma_area->list, &vma_area_list->h);
vma_area_list->nr++;
- if (privately_dump_vma(vma_area)) {
+ if (vma_area_is_private(vma_area)) {
unsigned long pages;
pages = vma_area_len(vma_area) / PAGE_SIZE;
--
1.9.3
More information about the CRIU
mailing list