From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: Mike Rapoport <rppt@kernel.org>
Cc: David Matlack <dmatlack@google.com>,
Pratyush Yadav <pratyush@kernel.org>,
linux-kselftest@vger.kernel.org, shuah@kernel.org,
akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, skhawaja@google.com
Subject: Re: [PATCH v3 1/2] liveupdate: prevent double management of files
Date: Thu, 26 Mar 2026 11:16:18 -0400 [thread overview]
Message-ID: <CA+CK2bA7=XBFVy1iS6y50v_TUxQPFbL182DgprkxeAh4JHZRoQ@mail.gmail.com> (raw)
In-Reply-To: <acT2lYJKdyXXzNPZ@kernel.org>
On Thu, Mar 26, 2026 at 5:04 AM Mike Rapoport <rppt@kernel.org> wrote:
>
> On Wed, Mar 25, 2026 at 05:08:57PM -0400, Pasha Tatashin wrote:
> > On Wed, Mar 25, 2026 at 4:34 PM David Matlack <dmatlack@google.com> wrote:
> > >
> > > On Wed, Mar 25, 2026 at 1:20 PM Pratyush Yadav <pratyush@kernel.org> wrote:
> > >
> > > > For memfd and hugetlb at least, we serialize the _inode_ not the file.
> > > > The inode has the contents that we care to preserve.
> > > >
> > > > So if two FDs point to the same inode, this will break. You can do this
> > > > by first creating a memfd and then by opening "/proc/self/fd/<fd>". Then
> > > > you would be able to trigger the preservation twice, causing all sorts
> > > > of problems. Same on the retrieve side.
> >
> > Hm.
> >
> > >
> > > > So unless I am missing something, I don't think this approach will work.
> > > > As much as I hate to suggest it, I think we need to move this check to
> > > > each caller so they can find out the object they need to serialize and
> > > > check if it already is.
> > >
> > > I think LUO can still enforce that the file is not preserved twice.
> > > HugeTLB and memfd's preserve() functions just need to also check that
> > > the associated inode has not already been preserved?
> >
> > For memfd/hugetlbs the true state is in inode
> > For vfio/kvm the shared anonymous inode is just a dummy wrapper, and
> > the true state is in file->private_data.
> >
> > I wonder if we could use the XArray to track inodes for standard
> > files, but track the struct file itself for anonymous files (we would
> > need a new function from FS that allows us to determine if "struct
> > file" has anonymous inode or not).
>
> Don't all files we preserve use anon inodes?
No for memfd_create(), the inode allocation path depends on the
presence of the MFD_HUGETLB flag:
1. Regular memfd (shmem):
memfd_alloc_file() calls shmem_file_setup(), which leads to:
shmem_get_inode() -> __shmem_get_inode() -> new_inode().
The allocated inode is a struct shmem_inode_info.
2. HugeTLB memfd (hugetlbfs):
memfd_alloc_file() calls hugetlb_file_setup(), which leads to:
hugetlbfs_get_inode() -> new_inode().
The allocated inode is a struct hugetlbfs_inode_info.
> How about we extend the fh->ops with a method that will return "unique"
> object?
Yeap, this is exactly what I am proposing. Adding an optional
get_id(struct file *file) to fh->ops allows each handler to define
what constitutes a "unique" identity for its supported file types.
luo_file.c will have a helper like this:
static inline unsigned long luo_get_id(struct liveupdate_file_handler
*fh, struct file *file)
{
return (fh->ops->get_id) ? fh->ops->get_id(file) : (unsigned long)file;
}
For memfd, the get_id implementation will return the inode pointer.
Pasha
>
> list_private_for_each_entry(fh, &luo_file_handler_list, list) {
> if (fh->ops->can_preserve(fh, file)) {
> unique_handle = fh->ops->unique_handle(fh, file);
> err = 0;
> break;
> }
> }
>
> xa_insert(&luo_preserved_objects, unique_handle,
> (unsigned long)unique_handle, GFP_KERNEL);
>
> > Pasha
>
> --
> Sincerely yours,
> Mike.
>
next prev parent reply other threads:[~2026-03-26 15:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 18:20 [PATCH v3 0/2] liveupdate: prevent double preservation Pasha Tatashin
2026-03-25 18:20 ` [PATCH v3 1/2] liveupdate: prevent double management of files Pasha Tatashin
2026-03-25 18:56 ` Mike Rapoport
2026-03-25 20:20 ` Pratyush Yadav
2026-03-25 20:33 ` David Matlack
2026-03-25 21:08 ` Pasha Tatashin
2026-03-25 21:35 ` Pasha Tatashin
2026-03-26 9:04 ` Mike Rapoport
2026-03-26 15:16 ` Pasha Tatashin [this message]
2026-03-25 18:20 ` [PATCH v3 2/2] selftests: liveupdate: add test for double preservation Pasha Tatashin
2026-03-25 23:14 ` [PATCH v3 0/2] liveupdate: prevent " Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CA+CK2bA7=XBFVy1iS6y50v_TUxQPFbL182DgprkxeAh4JHZRoQ@mail.gmail.com' \
--to=pasha.tatashin@soleen.com \
--cc=akpm@linux-foundation.org \
--cc=dmatlack@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pratyush@kernel.org \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=skhawaja@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox