Skip to content

Commit

Permalink
vdso: handle vvar_vclock vma-s
Browse files Browse the repository at this point in the history
The vvar_vclock was introduced by [1]. Basically, the old vvar vma has
been splited on two parts. In term of C/R, these two vma-s can be still
treated as one.

[1] e93d2521b27f ("x86/vdso: Split virtual clock pages into dedicated mapping")

Signed-off-by: Andrei Vagin <[email protected]>
  • Loading branch information
avagin authored and rst0git committed Dec 8, 2024
1 parent beff27e commit 058572e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
1 change: 1 addition & 0 deletions criu/include/util-vdso.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct vdso_symbol {
struct vdso_symtable {
unsigned long vdso_size;
unsigned long vvar_size;
unsigned long vvar_vclock_size;
struct vdso_symbol symbols[VDSO_SYMBOL_MAX];
bool vdso_before_vvar; /* order of vdso/vvar pair */
};
Expand Down
19 changes: 18 additions & 1 deletion criu/pie/parasite-vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static int remap_one(char *who, unsigned long *from, unsigned long to, size_t si
static int park_at(struct vdso_maps *rt, unsigned long vdso, unsigned long vvar)
{
unsigned long vvar_size = rt->sym.vvar_size;
unsigned long vvar_vclock_size = rt->sym.vvar_vclock_size;
unsigned long vdso_size = rt->sym.vdso_size;
int ret;

Expand All @@ -54,8 +55,24 @@ static int park_at(struct vdso_maps *rt, unsigned long vdso, unsigned long vvar)

std_log_set_gettimeofday(NULL); /* stop using vdso for timings */

if (vvar)
if (vvar) {
/*
* v6.13-rc1~172^2~9 splits the vvar vma in two parts vvar and
* vvar_clock. The last one is mapped right after the first
* one.
*/
if (vvar_vclock_size) {
unsigned long from;

vvar_size -= vvar_vclock_size;
from = rt->vvar_start + vvar_size;

ret = remap_one("rt-vvar", &from, vvar + vvar_size, vvar_vclock_size);
if (ret)
return ret;
}
ret = remap_one("rt-vvar", &rt->vvar_start, vvar, vvar_size);
}

if (!ret)
vdso_update_gtod_addr(rt);
Expand Down
23 changes: 19 additions & 4 deletions criu/proc_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ static int handle_vma(pid_t pid, struct vma_area *vma_area, const char *file_pat
} else if (!strcmp(file_path, "[vdso]")) {
if (handle_vdso_vma(vma_area))
goto err;
} else if (!strcmp(file_path, "[vvar]")) {
} else if (!strcmp(file_path, "[vvar]") ||
!strcmp(file_path, "[vvar_vclock]")) {
if (handle_vvar_vma(vma_area))
goto err;
} else if (!strcmp(file_path, "[heap]")) {
Expand Down Expand Up @@ -771,7 +772,7 @@ static int task_size_check(pid_t pid, VmaEntry *entry)

int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, dump_filemap_t dump_filemap)
{
struct vma_area *vma_area = NULL;
struct vma_area *vma_area = NULL, *prev_vma_area = NULL;
unsigned long start, end, pgoff, prev_end = 0;
char r, w, x, s;
int ret = -1, vm_file_fd = -1;
Expand Down Expand Up @@ -813,8 +814,22 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, dump_filemap_t du
continue;
}

if (vma_area && vma_list_add(vma_area, vma_area_list, &prev_end, &vfi, &prev_vfi))
goto err;
if (vma_area && vma_area_is(vma_area, VMA_AREA_VVAR) &&
prev_vma_area && vma_area_is(prev_vma_area, VMA_AREA_VVAR)) {
if (prev_vma_area->e->end != vma_area->e->start) {
pr_err("two nonconsecutive vvar vma-s: "
"%" PRIx64 "-%" PRIx64 " %" PRIx64 "-%" PRIx64 "\n",
prev_vma_area->e->start, prev_vma_area->e->end,
vma_area->e->start, vma_area->e->end);
goto err;
}
/* Merge all vvar vma-s into one. */
prev_vma_area->e->end = vma_area->e->end;
} else {
if (vma_area && vma_list_add(vma_area, vma_area_list, &prev_end, &vfi, &prev_vfi))
goto err;
prev_vma_area = vma_area;
}

if (eof)
break;
Expand Down
28 changes: 21 additions & 7 deletions criu/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,21 +310,27 @@ static int vdso_parse_maps(pid_t pid, struct vdso_maps *s)

while (1) {
unsigned long start, end;
char *has_vdso, *has_vvar;
char *has_vdso, *has_vvar, *has_vvar_vclock;

buf = breadline(&f);
if (buf == NULL)
break;
if (IS_ERR(buf))
goto err;

has_vdso = strstr(buf, "[vdso]");
if (!has_vdso)
has_vvar = NULL;
has_vvar_vclock = NULL;
do {
has_vdso = strstr(buf, "[vdso]");
if (has_vdso)
break;
has_vvar = strstr(buf, "[vvar]");
else
has_vvar = NULL;
if (has_vvar)
break;
has_vvar_vclock = strstr(buf, "[vvar_vclock]");
} while (0);

if (!has_vdso && !has_vvar)
if (!has_vdso && !has_vvar && !has_vvar_vclock)
continue;

if (sscanf(buf, "%lx-%lx", &start, &end) != 2) {
Expand All @@ -339,13 +345,21 @@ static int vdso_parse_maps(pid_t pid, struct vdso_maps *s)
}
s->vdso_start = start;
s->sym.vdso_size = end - start;
} else {
} else if (has_vvar) {
if (s->vvar_start != VVAR_BAD_ADDR) {
pr_err("Got second VVAR entry\n");
goto err;
}
s->vvar_start = start;
s->sym.vvar_size = end - start;
} else {
if (s->vvar_start == VDSO_BAD_ADDR ||
s->vvar_start + s->sym.vvar_size != start) {
pr_err("VVAR and VVAR_VCLOCK entries are not subsequent\n");
goto err;
}
s->sym.vvar_vclock_size = end - start;
s->sym.vvar_size += s->sym.vvar_vclock_size;
}
}

Expand Down

0 comments on commit 058572e

Please sign in to comment.