mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
vma: Unify private VMAs testing
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@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
204c0771ff
commit
9ce0254c04
7 changed files with 28 additions and 53 deletions
36
cr-dump.c
36
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)
|
||||
|
|
|
|||
10
cr-restore.c
10
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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__ */
|
||||
|
|
|
|||
|
|
@ -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__ */
|
||||
|
|
|
|||
6
mem.c
6
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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue