Skip to content

Commit

Permalink
Merge branch 'checkpoint-restore:criu-dev' into assorted-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
osctobe authored Jun 15, 2023
2 parents 1ba14e4 + c75c017 commit b00fb0f
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 26 deletions.
4 changes: 2 additions & 2 deletions criu/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ static int open_cgroupfs(struct cg_ctl *cc)
return -1;
}

if (mount("none", prefix, fstype, 0, mopts) < 0) {
pr_perror("Unable to mount %s", mopts);
if (mount("none", prefix, fstype, 0, mopts[0] ? mopts : NULL) < 0) {
pr_perror("Unable to mount %s %s", fstype, mopts);
rmdir(prefix);
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion criu/cr-restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -2971,7 +2971,7 @@ static int prepare_mm(pid_t pid, struct task_restore_args *args)

args->fd_exe_link = exe_fd;

args->has_thp_enabled = rsti(current)->has_thp_enabled;
args->thp_disabled = mm->has_thp_disabled && mm->thp_disabled;

ret = 0;
out:
Expand Down
2 changes: 1 addition & 1 deletion criu/include/restorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct task_restore_args {
struct timeval logstart;

int uffd;
bool has_thp_enabled;
bool thp_disabled;

/* threads restoration */
int nr_threads; /* number of threads */
Expand Down
2 changes: 0 additions & 2 deletions criu/include/rst_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ struct rst_info {
*/
bool has_old_seccomp_filter;

bool has_thp_enabled;

struct rst_rseq *rseqe;

void *breakpoint;
Expand Down
2 changes: 2 additions & 0 deletions criu/kerndat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,8 @@ int kerndat_has_thp_disable(void)

parse_vmflags(str, &flags, &madv, &io_pf);
kdat.has_thp_disable = !(madv & (1 << MADV_NOHUGEPAGE));
if (!kdat.has_thp_disable)
pr_warn("prctl PR_SET_THP_DISABLE sets MADV_NOHUGEPAGE");
break;
}
}
Expand Down
4 changes: 0 additions & 4 deletions criu/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,6 @@ static int restore_priv_vma_content(struct pstree_item *t, struct page_read *pr)

static int maybe_disable_thp(struct pstree_item *t, struct page_read *pr)
{
MmEntry *mm = rsti(t)->mm;

/*
* There is no need to disable it if the page read doesn't
* have parent. In this case VMA will be empty until
Expand All @@ -1241,8 +1239,6 @@ static int maybe_disable_thp(struct pstree_item *t, struct page_read *pr)
pr_perror("Cannot disable THP");
return -1;
}
if (!(mm->has_thp_disabled && mm->thp_disabled))
rsti(t)->has_thp_enabled = true;

return 0;
}
Expand Down
13 changes: 11 additions & 2 deletions criu/memfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,17 @@ static int dump_memfd_inode(int fd, struct memfd_dump_inode *inode, const char *
}

mie.seals = fcntl(fd, F_GET_SEALS);
if (mie.seals == -1)
goto out;
if (mie.seals == -1) {
if (errno != EINVAL || ~mie.hugetlb_flag & MFD_HUGETLB) {
pr_perror("fcntl(F_GET_SEALS)");
goto out;
}
/* Kernels before 4.16 don't allow MFD_HUGETLB |
* MFD_ALLOW_SEALING and return EINVAL for
* fcntl(MFD_HUGETLB-enabled fd).
*/
mie.seals = F_SEAL_SEAL;
}

if (pb_write_one(img_from_set(glob_imgset, CR_FD_MEMFD_INODE), &mie, PB_MEMFD_INODE))
goto out;
Expand Down
16 changes: 6 additions & 10 deletions criu/pie/restorer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1635,17 +1635,13 @@ long __export_restore_task(struct task_restore_args *args)
goto core_restore_end;
}

if (args->uffd > -1) {
/* re-enable THP if we disabled it previously */
if (args->has_thp_enabled) {
int ret;
ret = sys_prctl(PR_SET_THP_DISABLE, 0, 0, 0, 0);
if (ret) {
pr_err("Cannot re-enable THP: %d\n", ret);
goto core_restore_end;
}
}
ret = sys_prctl(PR_SET_THP_DISABLE, args->thp_disabled, 0, 0, 0);
if (ret) {
pr_err("Cannot restore THP_DISABLE=%d flag: %ld\n", args->thp_disabled, ret);
goto core_restore_end;
}

if (args->uffd > -1) {
pr_debug("lazy-pages: closing uffd %d\n", args->uffd);
/*
* All userfaultfd configuration has finished at this point.
Expand Down
45 changes: 41 additions & 4 deletions test/zdtm/static/thp_disable.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ int main(int argc, char **argv)
unsigned long orig_flags = 0, new_flags = 0;
unsigned long orig_madv = 0, new_madv = 0;
void *area;
int ret;

test_init(argc, argv);

Expand All @@ -35,9 +36,46 @@ int main(int argc, char **argv)
return -1;
}

ret = prctl(PR_GET_THP_DISABLE, 0, 0, 0, 0);
if (ret < 0) {
pr_perror("Getting THP-disabled flag failed");
return -1;
}
if (ret != 1) {
errno = 0;
fail("prctl(GET_THP_DISABLE) returned unexpected value: %d != 1\n", ret);
return -1;
}

test_msg("Fetch pre-migration flags/adv\n");
if (get_smaps_bits((unsigned long)area, &new_flags, &new_madv))
return -1;

errno = 0;
if (orig_flags != new_flags) {
fail("Flags changed %lx -> %lx\n", orig_flags, new_flags);
return -1;
}

if (orig_madv != new_madv) {
fail("Madvs changed %lx -> %lx\n", orig_madv, new_madv);
return -1;
}

test_daemon();
test_waitsig();

ret = prctl(PR_GET_THP_DISABLE, 0, 0, 0, 0);
if (ret < 0) {
pr_perror("Getting post-migration THP-disabled flag failed");
return -1;
}
if (ret != 1) {
errno = 0;
fail("post-migration prctl(GET_THP_DISABLE) returned unexpected value: %d != 1\n", ret);
return -1;
}

if (prctl(PR_SET_THP_DISABLE, 0, 0, 0, 0)) {
pr_perror("Enabling THP failed");
return -1;
Expand All @@ -47,15 +85,14 @@ int main(int argc, char **argv)
if (get_smaps_bits((unsigned long)area, &new_flags, &new_madv))
return -1;

errno = 0;
if (orig_flags != new_flags) {
pr_err("Flags are changed %lx -> %lx\n", orig_flags, new_flags);
fail();
fail("Flags changed %lx -> %lx\n", orig_flags, new_flags);
return -1;
}

if (orig_madv != new_madv) {
pr_err("Madvs are changed %lx -> %lx\n", orig_madv, new_madv);
fail();
fail("Madvs changed %lx -> %lx\n", orig_madv, new_madv);
return -1;
}

Expand Down

0 comments on commit b00fb0f

Please sign in to comment.