From nobody Mon Feb 9 00:55:01 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 DDE6135FF7D for ; Thu, 29 Jan 2026 21:25:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769721961; cv=none; b=RHWv5u8zVSgkc20PMiW3NiD8ans/k93D31quILttKUnBQhr3pxLWEYd79HRr/qkpqL9Cq56BWNvYfz+TjmMd6ajaTiQwThkZx3OeLtwkd1OlMvRxWgRd8HOlgUjP0BoOsCA07dHxjsouffUksMLxU5T3XEELEZeadbbTeglY4h0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769721961; c=relaxed/simple; bh=FPm4HNnNzdGsASTEmXYmmsAPSB4aul9GWDReAyxeCCY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R1h8MWs0ZkMFOKY3mVm67BiqhwGv+At9oNanuA0N6V5ZUeqi3VjRpwHCg8vwTXzpQGPUB54+YZMnn7S3+zXtEhqtMWgRzh2o2wQeXBpaCJ0jcnbjGCC7IZFT8/LKtY+oO3I9tOFSeCij/yEPAYzxucaOrMVf0YXxnlIbgJ5j08E= 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=jeUpRM1U; arc=none smtp.client-ip=209.85.215.201 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="jeUpRM1U" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c634b862fcfso895216a12.2 for ; Thu, 29 Jan 2026 13:25:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769721959; x=1770326759; 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=idHpW3SDccKJdv6+7GcWw8jBEpKmDKEMPgP0EwwfxqU=; b=jeUpRM1UNmTsBxYdioDrYyaaBwCFGiaoczwyCBJZM67st2YYKUK208OKLs7RYsr+D1 BJBExVhnR5YILu3UlQ3Ik9nU/V3io0yTjFysavSShZS6Zi83Moo6S/iiOg9okaftHKTG /OCM7VqwrAJ1caIGChnC1gcg4HOBFTLLhphWpuY3BACjk3dqIz/7O6mFsy/A6PPjLunC ObFwNqzIUX+EtQiMLStK0f3Zvp+ugXw9XHCOG10iSBdzrs/04Mf0Pl994mDUK0jvpWBt kA1Dh67dlTNA3ioHsoQdQlnsjWivaZ3NzH7oihtDOml5t+98mMjV8eXnd9FeNtdw6B7p xneA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769721959; x=1770326759; 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=idHpW3SDccKJdv6+7GcWw8jBEpKmDKEMPgP0EwwfxqU=; b=ahsTzD1fJXy8uLXQc47qxw+ErDcpRcNCNUP1+BmThZN5MittnhQpiDexCNO2Rwtddf omNOmxYPSKCzrUk+cv1usFo8+mgQVaRH0YbP0kwRsZ6/eeA3jvmO+lqyuwK26onJEW3l 720yxyHCb1aiHrC69RaBaALxCkC39IugT3E7E0tFIo0uote2vP3n3oC4CcByntXV7Oe4 c1AuDe47YUCpAFFQ4/rfwmR1m9yfjqUss3cDllxrIbr2/gr/hzwpzwPqgidcqk2jpo0I lqm7FVhOYuAvas/iVbhF+zwtRd0l8ejxUt+UMta+oVZ5Gs8GWFRsj8CJRwJ1h38osNF7 /3Cg== X-Forwarded-Encrypted: i=1; AJvYcCUW4l/5zqYxS1JhWa/t85DtU4PdjcXSbGM2ifhf7U0jP3MBIO1UNdiEAU86+msygm6kzAcZAYrtvkBaXtE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3ywnpUq9aUfUV1AvjpsDh9Cg6Ni6ZxcsQpXxYnUzsaXfxYSpz Wl1DluckxhbgZl3CbMVaAGFc+qKzv0YfOw9F5oOQjm6aoJ5dfpb1uCJfEqImPkxz90Mu7Euv4a6 kLOys2fN9Q53UkA== X-Received: from pgdj29.prod.google.com ([2002:a05:6a02:521d:b0:c5e:d16c:917e]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3392:b0:366:581e:1a11 with SMTP id adf61e73a8af0-392e0148145mr472290637.57.1769721958852; Thu, 29 Jan 2026 13:25:58 -0800 (PST) Date: Thu, 29 Jan 2026 21:25:00 +0000 In-Reply-To: <20260129212510.967611-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: <20260129212510.967611-1-dmatlack@google.com> X-Mailer: git-send-email 2.53.0.rc1.225.gd81095ad13-goog Message-ID: <20260129212510.967611-14-dmatlack@google.com> Subject: [PATCH v2 13/22] selftests/liveupdate: Add helpers to preserve/retrieve FDs From: David Matlack To: Alex Williamson Cc: Adithya Jayachandran , Alexander Graf , Alex Mastro , Alistair Popple , Andrew Morton , Ankit Agrawal , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , 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, Lukas Wunner , "=?UTF-8?q?Micha=C5=82=20Winiarski?=" , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Raghavendra Rao Ananta , Rodrigo Vivi , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , "=?UTF-8?q?Thomas=20Hellstr=C3=B6m?=" , Tomita Moeko , 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..4c93d043d2b3 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, int token); +int luo_session_retrieve_fd(int session_fd, int 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..9bf4f16ca0a4 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, int 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, int 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.rc1.225.gd81095ad13-goog