Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: linux-kselftest@vger.kernel.org, rppt@kernel.org,
	shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org,
	vipinsh@google.com, linux-kernel@vger.kernel.org,
	kexec@lists.infradead.org, pratyush@kernel.org, graf@amazon.com
Subject: Re: [PATCH v1 0/7] liveupdate: tmpfs preservation and early freeze
Date: Thu, 15 Oct 2026 17:48:51 +0000	[thread overview]
Message-ID: <atESAwf17pJ11S9U@google.com> (raw)
In-Reply-To: <20261015093816.2438942-1-pasha.tatashin@soleen.com>

On 2026-10-15 05:38 AM, Pasha Tatashin wrote:
> This series allows preserving files in tmpfs via LUO to survive across a
> live update, and allows userspace to decide when to freeze a session
> instead of delaying until auto-freeze at kexec time. Once userspace is
> done with a session, it can freeze the session immediately (and across
> multiple sessions in parallel), reducing blackout time by not postponing
> this operation to kexec shutdown where all sessions are frozen serially:
> 
> 1. Early session freeze (LIVEUPDATE_SESSION_FREEZE):
>    Currently, LUO sessions are frozen automatically only inside the
>    reboot(LINUX_REBOOT_CMD_KEXEC) path, where luo_session_serialize()
>    iterates through all outgoing sessions under global write locks and
>    freezes them serially during shutdown.
> 
>    Add the LIVEUPDATE_SESSION_FREEZE ioctl on session file descriptors so
>    userspace can freeze a session as soon as it is done with it (and freeze
>    multiple sessions concurrently, since luo_session_freeze() only acquires
>    the per-session mutex). During kexec, already-frozen sessions skip the
>    late auto-freeze step; if an early-frozen session is closed before
>    kexec, its files are rolled back via .unfreeze() before being
>    unpreserved.

Thanks for putting this together. I'm on board with driving
retrieve-into through a per-handler argument instead of a LUO-level
flag. It's what Pratyush suggested on the RFC too (sorry Pratyush, I
never replied to that). I still need to review the actual patch but
I think the idea is fine.

However, nothing ties the arg struct to a handler, it's interpreted by
whichever handler owns the token. At LPC we discussed letting userspace
pick the handler in PRESERVE_FD/RETRIEVE_FD, so that it controls which
one is used when more than one can take a file. If we do that, the
handler name would also be the natural key for which arg struct is
expected.

> 3. Tmpfs file preservation and retrieval:
>    Using the file handler retrieve argument, extend mm/memfd_luo to allow
>    preserving generic shmem-backed tmpfs files (not just unlinked memfd
>    pseudofiles), recording MEMFD_LUO_FLAG_TMPFS in
>    struct memfd_luo_ser.flags so that preserved tmpfs files must be
>    retrieved as tmpfs files and preserved memfd files must be retrieved as
>    memfd files.

I've been working on a v1 of the tmpfs preservation since LPC. v1 fixes
a number of problems in the RFC that I think this series still has
(sorry for the wall of text, it is LLM-generated):

 - Failures that userspace can fix lose the file. The folios are
   restored, charged and added one at a time, so if the target's mount
   is too small (ENOSPC/quota) or the caller hits its memcg limit
   partway through, the target is truncated, the folios are freed, and
   the failure is permanent. Only bad-argument errors are retryable.
   v1 restores all the folios first, charges all the blocks and memcg
   up front, and adds all the folios to the page cache or none of them.
   It keeps the restored folios in private_data between attempts (LUO
   needs to pass private_data to .retrieve() and keep it on failure),
   so the only permanent failure left is losing the KHO state itself.

 - memfd_pin_folios() doesn't require the inode lock, so iommufd can
   pin folios of the target while they're being added or truncated
   away. v1 starts with two patches that make iommufd take the lock
   and make memfd_pin_folios() assert it.

 - The target has to be opened for writing (FMODE_WRITE). Since LUO
   holds a reference to it until finish, that means a restored binary
   can't be executed until the session is finished (-ETXTBSY). v1
   instead requires mnt_want_write_file() and file_permission(MAY_WRITE)
   under the inode lock, like FS_IOC_ENABLE_VERITY. That also rejects
   immutable files, which a fd opened for writing before chattr +i
   doesn't.

 - There's no file_modified() or fsnotify_modify(), so setuid/setgid
   bits aren't cleared and timestamps aren't updated. The normal write
   path does both.

 - f_pos is set through fget() + vfs_setpos() without f_pos_lock, which
   races with read()/lseek() on the same open file. v1 uses
   fdget_pos(). (Sashiko called this an ABBA deadlock. I don't think it
   is one, since vfs_setpos() doesn't take the lock, but the race is
   real.)

 - Early failures leak the preserved folios. The seals/flags check
   frees ser and records a permanent error, so .finish() skips the file
   and the folios are never freed. Sashiko flagged this as well. The
   new MEMFD_LUO_ALL_FLAGS check adds another way to get there. In v1,
   early failures don't consume anything and aren't permanent, so
   .finish() cleans up.

 - If a token was already retrieved, luo_retrieve_file() returns the
   existing file and ignores arg. Userspace that asks to retrieve into
   X gets success and an fd for a different file. I think LUO should
   fail with -EBUSY if an arg is passed for a token that was already
   retrieved.

 - Sashiko's WARN_ON(liveupdate_claim_file()) report on 3/7 is valid:
   xa_insert() can fail with -ENOMEM there, and userspace can trigger
   that.

One place our series are not aligned is MEMFD_LUO_FLAG_TMPFS. My
thinking has been that RETRIEVE_FD should support retrieving into any
shmem file (including linked files, memfds, and O_TMPFILE). It is
userspace's choice at retrieve time. The only thing the kernel enforces
are the fundamental requirements such as exceeding the file's mount's
limit.  When I think about it that way there is nothing special about
retrieving into a memfd and MEMFD_LUO_FLAG_TMPFS is just artificially
limiting how a shmem file can be retrieved. WDYT?

One last thing is my v1 also comes with a dedicated tmpfs selftest with
much broader positive and negative test coverage that I would like to
land (things link O_TMPFILE and read-only targets, executing restored
binaries, exact block accounting with statfs() and st_blocks, including
large folios that extend past EOF, etc.).

Maybe what we can do is keep your 1-5/7 patches and I'll rebase my v1 on
top and send that as a replacement for 6-7/7?

Thanks,
David


      parent reply	other threads:[~2026-10-15 17:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  9:38 [PATCH v1 0/7] liveupdate: tmpfs preservation and early freeze Pasha Tatashin
2026-10-15  9:38 ` [PATCH v1 1/7] liveupdate: Add LIVEUPDATE_SESSION_FREEZE ioctl to freeze sessions early Pasha Tatashin
2026-10-15  9:38 ` [PATCH v1 2/7] selftests: liveupdate: Add tests for LIVEUPDATE_SESSION_FREEZE Pasha Tatashin
2026-10-15  9:38 ` [PATCH v1 3/7] liveupdate: Pass user argument to file preserve and retrieve Pasha Tatashin
2026-10-15  9:38 ` [PATCH v1 4/7] selftests: liveupdate: Add tests for preserve and retrieve user argument Pasha Tatashin
2026-10-15  9:38 ` [PATCH v1 5/7] liveupdate: Allow file handlers to mark retrieve failures as retryable Pasha Tatashin
2026-10-15  9:38 ` [PATCH v1 6/7] mm/memfd_luo: Support tmpfs preservation and retrieval Pasha Tatashin
2026-10-15  9:38 ` [PATCH v1 7/7] selftests: liveupdate: Add test coverage for " Pasha Tatashin
2026-10-15 17:48 ` David Matlack [this message]

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=atESAwf17pJ11S9U@google.com \
    --to=dmatlack@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=graf@amazon.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=vipinsh@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