From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27E822FB969 for ; Mon, 18 May 2026 11:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779103797; cv=none; b=E2/KFjwWXk7JY5vfoTCgtUUO811BUHkUDcTik2XAF65X/G8cv2tcDkRr3PGt4pdSxAmq/5BwcMYDpSjFvGa+ltR31N9eB2phVuj+wtZBDK+2qJSJ/cuG8HLV4AfKfGB2G9D6mMla6YlyntdYo2J90hFDnBnssnLlUQ2/HndyKf4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779103797; c=relaxed/simple; bh=5h+JaZk/JM+pD3tioviir/zaPCZBDLs4hcSQ6YmKTnY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EKzv02wFH1B73fyCNfwaB1mL/CXyd51dPtsMQ5sAbshID+iexb84vQGqQCQR91e86vyGpv8DTQmcVZTQEZlkx7+Q7WsxzCRZbzhn6QOqhlnjfIAuJzw7APTK+7HEd8THS/+Hg1EtnRASU0AEk0Qtc98E32W3otUJir/uYA7s7io= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZptN1vmA; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZptN1vmA" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b8f848ebcbbso156946666b.0 for ; Mon, 18 May 2026 04:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779103790; x=1779708590; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eVDqRPZa7dBLYBPk4B/6HSFC2D7QwgtADBC0sCxOKu8=; b=ZptN1vmAWF8ZKJ5BKFQQ7wfEnPxMHq3rM4jRZ0Ek2fSD9lXFrO2ShH1cR5pDNvQ4pk fh9Z4wD7vc0Z7ESh1c7SVJ2+5CQWbY7mR/yI4DBFQkrd6E/cWq3r4Oy9IhdPh4gQyl2z n2iz/qkEGIMgQA+m49ZFAoC7MLDsMS8qCQDjeniQ4RqXia88vr1ECoNRS/frJB220dA6 euOa2QEG980wh+AbrAgJbNWbpwLX9Sawi3/XSWkVyEAhLaF4i8l2VPaarnckByH6MIqu Is3lY4JaHaSMXDWmle1aBIPDB9vIPTjklSp+N1WcXelZ18wmgPP7iG1ulgYD4O6WYc62 YsxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779103790; x=1779708590; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eVDqRPZa7dBLYBPk4B/6HSFC2D7QwgtADBC0sCxOKu8=; b=aS3sx3XCgbX7h87JWlO/p1cg91uHC5Zt8vCtZfrC9fFhG60h0VyxO0EX9lkosVkHfo 9oPM5Lw6LCdVCywMIkm6JekgbND+DaiDhB0/F/40sljzpTgYFKCkxuirhGPDQL2+iF6Y IVzPa0RU/rCD/WdqhoP9Zs6dJ53Nq+C9r7o8ZplqOXOtyjjqO7hGn1K/n+qFijYSdb4b qf4dqhxdGX9Hjk3ekkZHx7/9P0rMWbyzngnhAgeK+JbWT0H7L5yByjoGEnys9NhDSlOx Vxe6bv9WekJvhH3Pcquo6o63B6+0FXZ/bGTWqJC3n0jTqUcm2OHJK3CL3oxeCVgEYLdl Dnbw== X-Forwarded-Encrypted: i=1; AFNElJ/+5YmGitl2aXTuF92a9wBAT1ASZQb+vY2wHmGraqyHqKk6RtGp9CwZB7oX9TY6IC+5WsiGJIDePxZoeJ4=@vger.kernel.org X-Gm-Message-State: AOJu0YyCmVNotAAEmnsg6PUSmlTsBChrjzYKRsn1LxqTZ4KZXC7Kqe4y JYBqkuLT1x9FPaiKaHFaqNnB37yV6YgiFag/AIasxxi+fxJoIkYSifmbeercYaZ0e2TDtmESs9S odzjggpZlwQkd3Q5NYw== X-Received: from ejchr5.prod.google.com ([2002:a17:907:3f85:b0:b99:5efe:10b2]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:6e86:b0:bd5:2cc7:d845 with SMTP id a640c23a62f3a-bd52cc7de89mr574085666b.30.1779103790274; Mon, 18 May 2026 04:29:50 -0700 (PDT) Date: Mon, 18 May 2026 11:29:49 +0000 In-Reply-To: <20260511201155.1488670-3-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260511201155.1488670-1-vipinsh@google.com> <20260511201155.1488670-3-vipinsh@google.com> Message-ID: <9huzy0hh3qhe.fsf@tarunix.c.googlers.com> Subject: Re: [PATCH 2/2] selftests/liveupdate: Add helpers to preserve/retrieve FDs From: tarunsahu@google.com To: Vipin Sharma , pasha.tatashin@soleen.com, rppt@kernel.org, pratyush@kernel.org Cc: shuah@kernel.org, dmatlack@google.com, skhawaja@google.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Type: text/plain; charset="UTF-8" Vipin Sharma 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 > Co-developed-by: David Matlack > Signed-off-by: David Matlack > Signed-off-by: Vipin Sharma > --- > .../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. > +{ > + 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