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

criu: Add support for pidfds #2449

Merged
merged 8 commits into from
Oct 3, 2024

Commits on Sep 27, 2024

  1. images: Add protobuf definition for pidfd

    We only use the last pid from the list in NSpid entry (from
    /proc/<pid>/fdinfo/<pidfd>) while restoring pidfds.
    The last pid refers to the pid of the process in the most deeply nested
    pid namespace. Since CRIU does not currently support nested pid
    namespaces, this entry is the one we want.
    
    After Linux 6.9, inode numbers can be used to compare pidfds. pidfds
    referring to the same process will have the same inode numbers. We use
    inode numbers to restore pidfds that point to dead processes.
    
    Signed-off-by: Bhavik Sachdev <[email protected]>
    bsach64 committed Sep 27, 2024
    Configuration menu
    Copy the full SHA
    d22b9bd View commit details
    Browse the repository at this point in the history

Commits on Oct 3, 2024

  1. criu: Support C/R of pidfds

    Process file descriptors (pidfds) were introduced to provide a stable
    handle on a process. They solve the problem of pid recycling.
    
    For a detailed explanation, see https://lwn.net/Articles/801319/ and
    http://www.corsix.org/content/what-is-a-pidfd
    
    Before Linux 6.9, anonymous inodes were used for the implementation of
    pidfds. So, we detect them in a fashion similiar to other fd types that
    use anonymous inodes by calling `readlink()`.
    After 6.9, pidfs (a file system for pidfds) was introduced.
    In 6.9 `S_ISREG()` returned true for pidfds, but this again changed with
    6.10.
    (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/pidfs.c?h=v6.11-rc2#n285)
    After this change, pidfs inodes have no file type in st_mode in
    userspace.
    We use `PID_FS_MAGIC` to detect pidfds for kernel >= 6.9
    Hence, check for pidfds occurs before the check for regular files.
    
    For pidfds that refer to dead processes, we lose the pid of the process
    as the Pid and NSpid fields in /proc/<pid>/fdinfo/<pidfd> change to -1.
    So, we create a temporary process for each unique inode and open pidfds
    that refer to this process. After all pidfds have been opened we kill
    this temporary process.
    
    This commit does not include support for pidfds that point to a specific
    thread, i.e pidfds opened with `PIDFD_THREAD` flag.
    
    Fixes: checkpoint-restore#2258
    
    Signed-off-by: Bhavik Sachdev <[email protected]>
    bsach64 committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    e6e9b3b View commit details
    Browse the repository at this point in the history
  2. zdtm: Check pidfd fdinfo entry is consistent

    Ensures that entries in /proc/<pid>/fdinfo/<pidfd> are same.
    
    Signed-off-by: Bhavik Sachdev <[email protected]>
    bsach64 committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    d2099fe View commit details
    Browse the repository at this point in the history
  3. zdtm: Check pidfd can send signal after C/R

    Ensure `pidfd_send_signal()` syscall works as expected after C/R.
    
    Signed-off-by: Bhavik Sachdev <[email protected]>
    bsach64 committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    e13ed2f View commit details
    Browse the repository at this point in the history
  4. zdtm: Check pidfd can kill descendant processes

    Validate that pidfds can been used to send signals to different
    processes after C/R using the `pidfd_send_signal()` syscall.
    
    Signed-off-by: Bhavik Sachdev <[email protected]>
    bsach64 committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    f64e4c6 View commit details
    Browse the repository at this point in the history
  5. zdtm: Check dead pidfd is restored correctly

    After, C/R of pidfds that point to dead processes their inodes might
    change. But if two pidfds point to same dead process they should
    continue to do so after C/R.
    
    This test ensures that this happens by calling `statx()` on pidfds after
    C/R and then comparing their inode numbers.
    
    Support for comparing pidfds by using `statx()` and inode numbers was
    introduced alongside pidfs. So if `f_type` of pidfd is not equal to
    `PID_FS_MAGIC` then we skip this test.
    
    signed-off-by: Bhavik Sachdev <[email protected]>
    bsach64 committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    dc9ce75 View commit details
    Browse the repository at this point in the history
  6. zdtm: Check fd from pidfd_getfd is C/Red correctly

    We get the read end of a pipe using `pidfd_getfd` and check if we can
    read from it after C/R.
    
    signed-off-by: Bhavik Sachdev <[email protected]>
    bsach64 committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    f78a7f4 View commit details
    Browse the repository at this point in the history
  7. zdtm: Check pidfd for thread is valid after C/R

    We open a pidfd to a thread using `PIDFD_THREAD` flag and after C/R
    ensure that we can send signals using it with `PIDFD_SIGNAL_THREAD`.
    
    signed-off-by: Bhavik Sachdev <[email protected]>
    bsach64 committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    875be05 View commit details
    Browse the repository at this point in the history