From nobody Thu Apr 2 22:05:40 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 D01F1390C86 for ; Mon, 23 Mar 2026 23:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310351; cv=none; b=b+pq4AZfdgv1D2/eOb1qqMdtGeysywICZbRTLBecSo+wEoODbRtRetyahnF43gJ9J0yPLAFl7EvLrL1lwrf5nN+jxtDWc+xCyWvZsEuwEYfCuQvJMRA7uJr0pVv1oL7TjnuJD9EiBGoltStCPB13b1O7MdrFCqLbAjvL7XjX7HA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310351; c=relaxed/simple; bh=Pal8NLhSzj5NFCdkK3kSKC8PcLcfaBEm4Hex4yzxfHQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LQ2MfDDR0SsnSKZmw94NadP5Lxar/URY1bCOnkplxSdwppTYvOVVBGDJf2E14JlW6WU05cPWg7FREYqau+1LIKsPLzAwyTx+nEEOL2GYphTkTZFlWRQdpbKMcJTiW2Td65FPk1pI6NGH9rdol7GvdDbfLhpZSpJ/VfDOjFM+uBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Z2t4gcwi; arc=none smtp.client-ip=209.85.214.202 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--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z2t4gcwi" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2b05a3c2421so8471915ad.1 for ; Mon, 23 Mar 2026 16:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774310344; x=1774915144; 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=d5dX1H4XkIVUdogReT0P+xEIybXWqypp015VM5/RpRc=; b=Z2t4gcwiYdiRpMKelEM5gq77MCDju8RQIdsyXTs2OzZCyqLxRg7gT1yeIU5DlOKpR4 yY+RKvGB+tdPDY33SuRwansSOKKKNrcZmF1pXDfKjK62tuwUFitbvm7sKACE+qXmkcAU AmMhWNFv4ZL2ONeOg7ceMa59EGtNu23uTZXelEqdsDPr3XM/Lvdk+glOkq7wUxTbON5C m1zVxMqHK8zZEz8Vp80w5wDmZ5Zmx9HHdtrsT3C1SoaXgAJIgbnJoyID0UkCgGgXCcHz bZ2lob6kHuPGGzUQkdZbXgGiijYLOyet3PpHGUEQwue4/F3+Y2V2ccc8DOf2mqfM9Q4n jCjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774310344; x=1774915144; 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=d5dX1H4XkIVUdogReT0P+xEIybXWqypp015VM5/RpRc=; b=GaIIpldVAtFlhpKNIij53LsVTTCoWxQbI6M50++VpS4im4VzI8PqMSX0FswxnEZlPQ 2t00hTE38/6pkSgc4erGVc0TAKlmIXZI7p074T0i+iNoetA0NyyxncPlfCyoyTO5PiG3 N9yF7Tj+kUdHU/XBv7Gt7WXAkdG7jwmTWLIFMp/0DnLAraLSttk9WkInl9aOiO6+qr/8 vBnumWOLot7Lr4V0iQVJVuytJrgDRrjZJphVkeJr7ktHU7hPtAIQXaqXxiTiUfa3+hYR YhXzuOEdeKD8BHCIT1pEtvNEUNRpjlCXP6DyLeuZ+Wo/JvCbIagTwJHO/XQTKZ6vAMLn +FRQ== X-Forwarded-Encrypted: i=1; AJvYcCW1tcp+oMi7tj2/HXDuEgNuNWB1RJLJGFegeH4NO9nSsZRuy95nKEH5eO4p9JOamjNGXJI0vRWoq++k/9E=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7/AylUCdENhsgGjGZlq5jHA9O0uiamL1/vbXWONUWIbgjM/xn yEMnO4GpQq8Z2Vfnbynlv4F+OkQId0HI3+w+tZG+Vsb4fZYmr7pUUYOZG7Mks5+IFYNxDZ7Y02i DRZyb/WqGaA4e5A== X-Received: from plpn15.prod.google.com ([2002:a17:902:968f:b0:2ae:c5aa:fcd7]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:124f:b0:2b0:54dc:62c with SMTP id d9443c01a7336-2b0827c9a7cmr151447295ad.48.1774310343811; Mon, 23 Mar 2026 16:59:03 -0700 (PDT) Date: Mon, 23 Mar 2026 23:58:07 +0000 In-Reply-To: <20260323235817.1960573-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260323235817.1960573-1-dmatlack@google.com> X-Mailer: git-send-email 2.53.0.983.g0bb29b3bc5-goog Message-ID: <20260323235817.1960573-16-dmatlack@google.com> Subject: [PATCH v3 15/24] selftests/liveupdate: Add helpers to preserve/retrieve FDs From: David Matlack To: Alex Williamson , Bjorn Helgaas Cc: Adithya Jayachandran , Alexander Graf , Alex Mastro , Andrew Morton , Ankit Agrawal , Arnd Bergmann , Askar Safin , "Borislav Petkov (AMD)" , Chris Li , Dapeng Mi , David Matlack , David Rientjes , Feng Tang , Jacob Pan , Jason Gunthorpe , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Kees Cook , Kevin Tian , kexec@lists.infradead.org, kvm@vger.kernel.org, Leon Romanovsky , Leon Romanovsky , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, Li RongQing , Lukas Wunner , Marco Elver , "=?UTF-8?q?Micha=C5=82=20Winiarski?=" , Mike Rapoport , Parav Pandit , Pasha Tatashin , "Paul E. McKenney" , Pawan Gupta , "Peter Zijlstra (Intel)" , Pranjal Shrivastava , Pratyush Yadav , Raghavendra Rao Ananta , Randy Dunlap , Rodrigo Vivi , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , Vivek Kasireddy , William Tu , Yi Liu , Zhu Yanjun Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vipin Sharma Add helper functions to preserve and retrieve file descriptors from an LUO session. These will be used be used in subsequent commits to preserve FDs other than memfd. No functional change intended. Signed-off-by: Vipin Sharma Co-developed-by: David Matlack Signed-off-by: David Matlack --- .../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); =20 +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 *expect= ed_data); =20 diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate.c b/tools/te= sting/selftests/liveupdate/lib/liveupdate.c index 60121873f685..3e070975a3ec 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; } =20 +int luo_session_preserve_fd(int session_fd, int fd, __u64 token) +{ + struct liveupdate_session_preserve_fd arg =3D { + .size =3D sizeof(arg), + .fd =3D fd, + .token =3D token, + }; + + if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg)) + return -errno; + + return 0; +} + +int luo_session_retrieve_fd(int session_fd, __u64 token) +{ + struct liveupdate_session_retrieve_fd arg =3D { + .size =3D sizeof(arg), + .token =3D token, + }; + + if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg)) + return -errno; + + return arg.fd; +} + int create_and_preserve_memfd(int session_fd, int token, const char *data) { - struct liveupdate_session_preserve_fd arg =3D { .size =3D sizeof(arg) }; long page_size =3D sysconf(_SC_PAGE_SIZE); void *map =3D MAP_FAILED; int mfd =3D -1, ret =3D -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); =20 - arg.fd =3D mfd; - arg.token =3D token; - if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0) + ret =3D luo_session_preserve_fd(session_fd, mfd, token); + if (ret) goto out; =20 ret =3D 0; @@ -92,15 +117,13 @@ int create_and_preserve_memfd(int session_fd, int toke= n, const char *data) int restore_and_verify_memfd(int session_fd, int token, const char *expected_data) { - struct liveupdate_session_retrieve_fd arg =3D { .size =3D sizeof(arg) }; long page_size =3D sysconf(_SC_PAGE_SIZE); void *map =3D MAP_FAILED; int mfd =3D -1, ret =3D -1; =20 - arg.token =3D token; - if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0) - return -errno; - mfd =3D arg.fd; + mfd =3D luo_session_retrieve_fd(session_fd, token); + if (mfd < 0) + return mfd; =20 map =3D mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0); if (map =3D=3D MAP_FAILED) --=20 2.53.0.983.g0bb29b3bc5-goog