Commit 9ce0254c authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 204c0771
...@@ -81,42 +81,6 @@ ...@@ -81,42 +81,6 @@
static char loc_buf[PAGE_SIZE]; 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) static void close_vma_file(struct vma_area *vma)
{ {
if (vma->vm_file_fd < 0) if (vma->vm_file_fd < 0)
......
...@@ -252,7 +252,7 @@ static int map_private_vma(pid_t pid, struct vma_area *vma, void **tgt_addr, ...@@ -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) if (p->e->start > vma->e->start)
break; break;
if (!vma_priv(p->e)) if (!vma_area_is_private(p))
continue; continue;
if (p->e->end != vma->e->end || 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) ...@@ -364,7 +364,7 @@ static int premap_priv_vmas(pid_t pid, struct vm_area_list *vmas, void *at)
} }
pstart = vma->e->start; pstart = vma->e->start;
if (!vma_priv(vma->e)) if (!vma_area_is_private(vma))
continue; continue;
ret = map_private_vma(pid, vma, &at, &pvma, parent_vmas); ret = map_private_vma(pid, vma, &at, &pvma, parent_vmas);
...@@ -430,7 +430,7 @@ static int restore_priv_vma_content(pid_t pid) ...@@ -430,7 +430,7 @@ static int restore_priv_vma_content(pid_t pid)
*/ */
if (va < vma->e->start) if (va < vma->e->start)
goto err_addr; 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"); pr_err("Trying to restore page for non-private VMA\n");
goto err_addr; goto err_addr;
} }
...@@ -573,7 +573,7 @@ static int unmap_guard_pages() ...@@ -573,7 +573,7 @@ static int unmap_guard_pages()
struct list_head *vmas = &rsti(current)->vmas.h; struct list_head *vmas = &rsti(current)->vmas.h;
list_for_each_entry(vma, vmas, list) { list_for_each_entry(vma, vmas, list) {
if (!vma_priv(vma->e)) if (!vma_area_is_private(vma))
continue; continue;
if (vma->e->flags & MAP_GROWSDOWN) { if (vma->e->flags & MAP_GROWSDOWN) {
...@@ -2646,7 +2646,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core) ...@@ -2646,7 +2646,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
*vme = *vma->e; *vme = *vma->e;
if (vma_priv(vma->e)) if (vma_area_is_private(vma))
vma_premmaped_start(vme) = vma->premmaped_addr; vma_premmaped_start(vme) = vma->premmaped_addr;
} }
......
...@@ -197,8 +197,4 @@ enum { ...@@ -197,8 +197,4 @@ enum {
/* the restorer_blob_offset__ prefix is added by gen_offsets.sh */ /* the restorer_blob_offset__ prefix is added by gen_offsets.sh */
#define restorer_sym(rblob, name) ((void *)(rblob) + restorer_blob_offset__##name) #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__ */ #endif /* __CR_RESTORER_H__ */
#ifndef __CR_VMA_H__ #ifndef __CR_VMA_H__
#define __CR_VMA_H__ #define __CR_VMA_H__
#include "asm/types.h"
#include "image.h"
#include "list.h" #include "list.h"
#include "protobuf/vma.pb-c.h" #include "protobuf/vma.pb-c.h"
struct vm_area_list { struct vm_area_list {
...@@ -69,7 +72,6 @@ struct vma_area { ...@@ -69,7 +72,6 @@ struct vma_area {
extern struct vma_area *alloc_vma_area(void); extern struct vma_area *alloc_vma_area(void);
extern int collect_mappings(pid_t pid, struct vm_area_list *vma_area_list); 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 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_is(vma_area, s) vma_entry_is((vma_area)->e, s)
#define vma_area_len(vma_area) vma_entry_len((vma_area)->e) #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) ...@@ -90,4 +92,17 @@ static inline int in_vma_area(struct vma_area *vma, unsigned long addr)
addr < (unsigned long)vma->e->end; 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__ */ #endif /* __CR_VMA_H__ */
...@@ -178,7 +178,7 @@ static struct parasite_dump_pages_args *prep_dump_pages_args(struct parasite_ctl ...@@ -178,7 +178,7 @@ static struct parasite_dump_pages_args *prep_dump_pages_args(struct parasite_ctl
args->nr_vmas = 0; args->nr_vmas = 0;
list_for_each_entry(vma, &vma_area_list->h, list) { list_for_each_entry(vma, &vma_area_list->h, list) {
if (!privately_dump_vma(vma)) if (!vma_area_is_private(vma))
continue; continue;
if (vma->e->prot & PROT_READ) if (vma->e->prot & PROT_READ)
continue; continue;
...@@ -293,7 +293,7 @@ static int __parasite_dump_pages_seized(struct parasite_ctl *ctl, ...@@ -293,7 +293,7 @@ static int __parasite_dump_pages_seized(struct parasite_ctl *ctl,
u64 off = 0; u64 off = 0;
u64 *map; u64 *map;
if (!privately_dump_vma(vma_area)) if (!vma_area_is_private(vma_area))
continue; continue;
map = pmc_get_map(&pmc, vma_area); map = pmc_get_map(&pmc, vma_area);
...@@ -441,7 +441,7 @@ int prepare_mm_pid(struct pstree_item *i) ...@@ -441,7 +441,7 @@ int prepare_mm_pid(struct pstree_item *i)
} }
list_add_tail(&vma->list, &ri->vmas.h); 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); ri->vmas.priv_size += vma_area_len(vma);
if (vma->e->flags & MAP_GROWSDOWN) if (vma->e->flags & MAP_GROWSDOWN)
ri->vmas.priv_size += PAGE_SIZE; ri->vmas.priv_size += PAGE_SIZE;
......
...@@ -802,7 +802,7 @@ long __export_restore_task(struct task_restore_args *args) ...@@ -802,7 +802,7 @@ long __export_restore_task(struct task_restore_args *args)
if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR)) if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR))
continue; continue;
if (!vma_priv(vma_entry)) if (!vma_entry_is_private(vma_entry))
continue; continue;
if (vma_entry->end >= TASK_SIZE) if (vma_entry->end >= TASK_SIZE)
...@@ -823,7 +823,7 @@ long __export_restore_task(struct task_restore_args *args) ...@@ -823,7 +823,7 @@ long __export_restore_task(struct task_restore_args *args)
if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR)) if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR))
continue; continue;
if (!vma_priv(vma_entry)) if (!vma_entry_is_private(vma_entry))
continue; continue;
if (vma_entry->start > TASK_SIZE) if (vma_entry->start > TASK_SIZE)
...@@ -846,7 +846,7 @@ long __export_restore_task(struct task_restore_args *args) ...@@ -846,7 +846,7 @@ long __export_restore_task(struct task_restore_args *args)
if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR)) if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR))
continue; continue;
if (vma_priv(vma_entry)) if (vma_entry_is_private(vma_entry))
continue; continue;
va = restore_mapping(vma_entry); va = restore_mapping(vma_entry);
......
...@@ -483,7 +483,7 @@ static int vma_list_add(struct vma_area *vma_area, ...@@ -483,7 +483,7 @@ static int vma_list_add(struct vma_area *vma_area,
list_add_tail(&vma_area->list, &vma_area_list->h); list_add_tail(&vma_area->list, &vma_area_list->h);
vma_area_list->nr++; vma_area_list->nr++;
if (privately_dump_vma(vma_area)) { if (vma_area_is_private(vma_area)) {
unsigned long pages; unsigned long pages;
pages = vma_area_len(vma_area) / PAGE_SIZE; pages = vma_area_len(vma_area) / PAGE_SIZE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment