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

uffd: Disable image deduplication after fork #2492

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

liusdu
Copy link

@liusdu liusdu commented Oct 12, 2024

After a fork, both the child and parent processes may trigger a page fault (#PF) at the same virtual address, referencing the same position in the page image. If deduplication is enabled, the last process to trigger the page fault will fail.

Therefore, deduplication should be disabled after a fork to prevent this issue.

@rst0git
Copy link
Member

rst0git commented Oct 13, 2024

If deduplication is enabled, the last process to trigger the page fault will fail.

Would it be possible to add a ZDTM test for this use-case?

After a fork, both the child and parent processes may trigger a page fault (#PF)
at the same virtual address, referencing the same position in the page image.
If deduplication is enabled, the last process to trigger the page fault will fail.

Therefore, deduplication should be disabled after a fork to prevent this issue.

Signed-off-by: Liu Hua <[email protected]>
@liusdu
Copy link
Author

liusdu commented Oct 14, 2024

If deduplication is enabled, the last process to trigger the page fault will fail.

Would it be possible to add a ZDTM test for this use-case?

I will add a ZDTM testcase later. The follow test case can reproduce this issue.

  • source code
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <signal.h>
#include <sched.h>


#define VALUE 0x1001
#define STACK_SIZE (1024 * 1024)

int validate_memory(void *arg)
{
    if  (*(int *)arg != VALUE) {
        printf("memory is corrupted\n");
        return -1;
    }
    printf("memory: %x\n", *(int *)arg);
    return 0;
}

int main() {
    int pid = 0;
    char *stack;
    int *buffer;;
     int flags = CLONE_VFORK;
    stack = malloc(STACK_SIZE + 4096);
    if (stack == NULL) {
        perror("malloc");
        exit(EXIT_FAILURE);
    }
    buffer = (int *)(stack + STACK_SIZE);
    buffer[0] = VALUE;

    kill(getpid(), 19);
    if (clone(validate_memory, buffer, flags, (void *)buffer) == -1) {
        perror("clone");
        free(stack);
        exit(EXIT_FAILURE);
    }
    validate_memory(buffer);

    return 0;
}
  • steps
  gcc -o clone clone.c 
  setsid ./clone
  criu dump --shell-job  -vvvv --tree `pidof ./clone` -o dumo.log  --images-dir ./ckp 
  criu lazy-pages -vvvv -o lp.log  --auto-dedup --images-dir ckp/ &
  criu  restore -vvvv -o restore.log  --images-dir  ./ckp/ --lazy-pages -j --no-background-fetch  &
  kill -s SIGCONT `ps aux | grep '\[clone\]' | awk '{print $2}'`
 

criu/config.c Outdated Show resolved Hide resolved
@duguhaotian
Copy link
Contributor

can you show some error message of this issuse?

criu/cr-restore.c Outdated Show resolved Hide resolved
criu/config.c Outdated Show resolved Hide resolved
@liusdu
Copy link
Author

liusdu commented Oct 24, 2024

@rst0git @rppt I found it very difficult to disable background fetch. I cannot reliably reproduce this issue in the tests because the memory may be fetched by the background process before deduplication. However, I can reliably reproduce this issue with a large-memory process, which is not suitable for testing. Could you please consider merging this patch without the test?

@liusdu
Copy link
Author

liusdu commented Oct 24, 2024

can you show some error message of this issuse?

Please refer to the above testcase.

Copy link
Member

@rst0git rst0git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@liusdu Thank you for working on this!

@avagin avagin merged commit 266f150 into checkpoint-restore:criu-dev Oct 27, 2024
36 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants