<div dir="ltr"><div>Hi, Christian!</div><div><br></div><div>Thanks for your attention to the patch!</div><div>This field is introduced with aufs (a3a49a17226f99a5e5dbdcbd328398cbf3c2959e) and it allows to have two struct files connected with</div><div>vma. One for memory management needs and seconds for things like proc/<pid>/map_files, numa_maps and so on.</div><div><br></div><div>Alex<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 27, 2021 at 12:47 PM Christian Brauner <<a href="mailto:christian.brauner@ubuntu.com">christian.brauner@ubuntu.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, Apr 26, 2021 at 11:11:21AM +0300, <a href="mailto:alexander@mihalicyn.com" target="_blank">alexander@mihalicyn.com</a> wrote:<br>
> From: Alexander Mikhalitsyn <<a href="mailto:alexander@mihalicyn.com" target="_blank">alexander@mihalicyn.com</a>><br>
> <br>
> BugLink: <a href="https://bugs.launchpad.net/bugs/1857257" rel="noreferrer" target="_blank">https://bugs.launchpad.net/bugs/1857257</a><br>
> <br>
> The hack was introduced in ("UBUNTU: SAUCE: overlayfs: allow with<br>
> shiftfs as underlay") and it broke checkpoint/restore of docker<br>
> contains:<br>
> <a href="https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1857257" rel="noreferrer" target="_blank">https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1857257</a><br>
> <br>
> The following script can be used to trigger the issue:<br>
> #!/bin/bash<br>
> <br>
> cat > test.py << EOF<br>
> import sys<br>
> <br>
> f = open("/proc/self/maps")<br>
> <br>
> for l in f.readlines():<br>
> if "python" not in l:<br>
> continue<br>
> print(l)<br>
> s = l.split()<br>
> start, end = s[0].split("-")<br>
> fname = s[-1]<br>
> print(start, end, fname)<br>
> break<br>
> else:<br>
> sys.exit(1)<br>
> <br>
> test_file1 = open(fname)<br>
> test_file2 = open("/proc/self/map_files/%s-%s" % (start, end))<br>
> <br>
> fdinfo1 = open("/proc/self/fdinfo/%d" % test_file1.fileno()).read()<br>
> fdinfo2 = open("/proc/self/fdinfo/%d" % test_file2.fileno()).read()<br>
> <br>
> if fdinfo1 != fdinfo2:<br>
> print("FAIL")<br>
> print(test_file1)<br>
> print(fdinfo1)<br>
> print(test_file2)<br>
> print(fdinfo2)<br>
> sys.exit(1)<br>
> print("PASS")<br>
> EOF<br>
> sudo docker run -it --privileged --rm -v `pwd`:/mnt python python /mnt/test.py<br>
> <br>
> Thanks to Andrei Vagin for the reproducer and investigation of this problem.<br>
> <br>
> Cc: Andrei Vagin <<a href="mailto:avagin@gmail.com" target="_blank">avagin@gmail.com</a>><br>
> Cc: Adrian Reber <<a href="mailto:areber@redhat.com" target="_blank">areber@redhat.com</a>><br>
> Cc: Christian Brauner <<a href="mailto:christian.brauner@ubuntu.com" target="_blank">christian.brauner@ubuntu.com</a>><br>
> Cc: Stefan Bader <<a href="mailto:stefan.bader@canonical.com" target="_blank">stefan.bader@canonical.com</a>><br>
> Cc: Kleber Sacilotto de Souza <<a href="mailto:kleber.souza@canonical.com" target="_blank">kleber.souza@canonical.com</a>><br>
> Cc: Krzysztof Kozlowski <<a href="mailto:krzysztof.kozlowski@canonical.com" target="_blank">krzysztof.kozlowski@canonical.com</a>><br>
> <br>
> Fixes: d24b8a5 ("UBUNTU: SAUCE: overlayfs: allow with shiftfs as underlay")<br>
> Signed-off-by: Alexander Mikhalitsyn <<a href="mailto:alexander@mihalicyn.com" target="_blank">alexander@mihalicyn.com</a>><br>
> ---<br>
<br>
Hey,<br>
<br>
Thanks for the patch!<br>
Fwiw, Andrei already tried to fix this a while ago but it caused another<br>
regression which forced us to revert the fix for this issue.<br>
<br>
> fs/overlayfs/file.c | 29 +++++++++++++++++++++++++++++<br>
> 1 file changed, 29 insertions(+)<br>
> <br>
> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c<br>
> index 0d3ea0cf3e98..5fa520d0798e 100644<br>
> --- a/fs/overlayfs/file.c<br>
> +++ b/fs/overlayfs/file.c<br>
> @@ -325,6 +325,18 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)<br>
> return ret;<br>
> }<br>
> <br>
> +/* handle vma->vm_prfile */<br>
> +static void ovl_vm_prfile_set(struct vm_area_struct *vma,<br>
> + struct file *file)<br>
> +{<br>
> + get_file(file);<br>
> + vma->vm_prfile = file;<br>
> +#ifndef CONFIG_MMU<br>
> + get_file(file);<br>
> + vma->vm_region->vm_prfile = file;<br>
> +#endif<br>
> +}<br>
<br>
I'm confused struct vm_area_struct doesn't have a vm_prfile entry. Can<br>
you explain, please?<br>
<br>
> +<br>
> static int ovl_mmap(struct file *file, struct vm_area_struct *vma)<br>
> {<br>
> struct file *realfile = file->private_data;<br>
> @@ -351,6 +363,23 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)<br>
> vma->vm_file = file;<br>
> fput(realfile);<br>
> } else {<br>
> + /*<br>
> + * In map_files_get_link() (fs/proc/base.c)<br>
> + * we need to determine correct path from overlayfs.<br>
> + * But real_mount(realfile->f_path.mnt) may be not<br>
> + * equal to real_mount(file->f_path.mnt). In such case<br>
> + * fdinfo of the same file which was opened from<br>
> + * /proc/<pid>/map_files/... and "usual" path<br>
> + * will show different mnt_id.<br>
> + *<br>
> + * We solve issue like in aufs by using additional<br>
> + * field on struct vm_area_struct called "vm_prfile"<br>
> + * which is used only for fdinfo/"printing" needs.<br>
> + *<br>
> + * See also mm/prfile.c<br>
> + */<br>
> + ovl_vm_prfile_set(vma, file);<br>
> +<br>
> /* Drop reference count from previous vm_file value */<br>
> fput(file);<br>
> }<br>
> -- <br>
> 2.30.2<br>
> <br>
</blockquote></div>