mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vipin Sharma <vipinsh@google.com>
To: tarunsahu@google.com
Cc: pasha.tatashin@soleen.com, rppt@kernel.org, pratyush@kernel.org,
	 shuah@kernel.org, dmatlack@google.com, skhawaja@google.com,
	 linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs
Date: Mon, 18 May 2026 10:14:21 -0700	[thread overview]
Message-ID: <20260518170124.GA3352871.vipinsh@google.com> (raw)
In-Reply-To: <9huzy0hh3qhe.fsf@tarunix.c.googlers.com>

On Mon, May 18, 2026 at 11:29:49AM +0000, tarunsahu@google.com wrote:
> Vipin Sharma <vipinsh@google.com> writes:
> 
> > Add helper functions to preserve and retrieve file descriptors from an
> > LUO session. This allows library users to work with FD preservation.
> >
> > No functional change intended.
> >
> > Signed-off-by: Vipin Sharma <vipinsh@google.com>
> > Co-developed-by: David Matlack <dmatlack@google.com>
> > Signed-off-by: David Matlack <dmatlack@google.com>
> > Signed-off-by: Vipin Sharma <vipinsh@google.com>
> > ---
> >  .../liveupdate/lib/include/libliveupdate.h    |  3 ++
> >  .../selftests/liveupdate/lib/liveupdate.c     | 41 +++++++++++++++----
> >  2 files changed, 35 insertions(+), 9 deletions(-)
> >
> > diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> > index 4390a2737930..2b04b3256382 100644
> > --- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> > +++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
> > @@ -26,6 +26,9 @@ int luo_create_session(int luo_fd, const char *name);
> >  int luo_retrieve_session(int luo_fd, const char *name);
> >  int luo_session_finish(int session_fd);
> >  
> > +int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
> > +int luo_session_retrieve_fd(int session_fd, __u64 token);
> > +
> >  int create_and_preserve_memfd(int session_fd, int token, const char *data);
> >  int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
> >  
> > diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate.c b/tools/testing/selftests/liveupdate/lib/liveupdate.c
> > index 60121873f685..7bc6707d8bb7 100644
> > --- a/tools/testing/selftests/liveupdate/lib/liveupdate.c
> > +++ b/tools/testing/selftests/liveupdate/lib/liveupdate.c
> > @@ -54,9 +54,35 @@ int luo_retrieve_session(int luo_fd, const char *name)
> >  	return arg.fd;
> >  }
> >  
> > +int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
> > +{
> > +	struct liveupdate_session_preserve_fd arg = {
> > +		.size = sizeof(arg),
> > +		.fd = fd,
> > +		.token = token,
> > +	};
> > +
> > +	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
> > +		return -errno;
> > +
> > +	return 0;
> > +}
> > +
> > +int luo_session_retrieve_fd(int session_fd, __u64 token)
> nit: Can add a comment that, once it is failed, retrieved status is saved,
> So it is permanent failure.

I think appropriate place will be the official documentation which is
here include/uapi/linux/liveupdate.h

I don't see it is mentioned in the documentation (yes, code does what
you have said), I will refrain from adding that comment here.

> > +{
> > +	struct liveupdate_session_retrieve_fd arg = {
> > +		.size = sizeof(arg),
> > +		.token = token,
> > +	};
> > +
> > +	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
> > +		return -errno;
> > +
> > +	return arg.fd;
> > +}
> > +
> >  int create_and_preserve_memfd(int session_fd, int token, const char *data)
> >  {
> > -	struct liveupdate_session_preserve_fd arg = { .size = sizeof(arg) };
> >  	long page_size = sysconf(_SC_PAGE_SIZE);
> >  	void *map = MAP_FAILED;
> >  	int mfd = -1, ret = -1;
> > @@ -75,9 +101,8 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
> >  	snprintf(map, page_size, "%s", data);
> >  	munmap(map, page_size);
> >  
> > -	arg.fd = mfd;
> > -	arg.token = token;
> > -	if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0)
> > +	ret = luo_session_preserve_fd(session_fd, mfd, token);
> > +	if (ret)
> >  		goto out;
> >  
> >  	ret = 0;
> > @@ -92,15 +117,13 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data)
> >  int restore_and_verify_memfd(int session_fd, int token,
> >  			     const char *expected_data)
> >  {
> > -	struct liveupdate_session_retrieve_fd arg = { .size = sizeof(arg) };
> >  	long page_size = sysconf(_SC_PAGE_SIZE);
> >  	void *map = MAP_FAILED;
> >  	int mfd = -1, ret = -1;
> >  
> > -	arg.token = token;
> > -	if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0)
> > -		return -errno;
> > -	mfd = arg.fd;
> > +	mfd = luo_session_retrieve_fd(session_fd, token);
> > +	if (mfd < 0)
> > +		return mfd;
> >  
> >  	map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0);
> >  	if (map == MAP_FAILED)
> > -- 
> > 2.54.0.563.g4f69b47b94-goog

  reply	other threads:[~2026-05-18 17:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 20:11 [PATCH 0/2] Make liveupdate selftests util as a library Vipin Sharma
2026-05-11 20:11 ` [PATCH 1/2] selftests/liveupdate: Move luo_test_utils.* into a reusable library Vipin Sharma
2026-06-08 14:31   ` Pratyush Yadav
2026-06-10 18:06     ` Vipin Sharma
2026-05-11 20:11 ` [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs Vipin Sharma
2026-05-18 11:29   ` tarunsahu
2026-05-18 17:14     ` Vipin Sharma [this message]
2026-06-08 14:32       ` Pratyush Yadav
2026-06-08 18:44         ` tarunsahu
2026-06-08 14:38   ` Pratyush Yadav

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=20260518170124.GA3352871.vipinsh@google.com \
    --to=vipinsh@google.com \
    --cc=dmatlack@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=skhawaja@google.com \
    --cc=tarunsahu@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

Powered by JetHome