Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdso: handle vvar_vclock vma-s #2539

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
avagin marked this conversation as resolved.
Show resolved Hide resolved
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
Loading