From nobody Sat Sep 26 11:46:50 2026 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 A10EE494834 for ; Tue, 1 Sep 2026 18:07:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286046; cv=none; b=RhyeuVhWs7b0yh4xEc21tUdAvJSo7vWXrUiYIi3Pl1qssHIPfpAM7YRW3tErplS2nDQlXCgOYuE/5ly+zMmKxqZ3PJsSQpSFBlp1NsC0xR4DeDjCLR8YkD6R0wmZc7kv4XykBzWk/hONnbPGY8xEr2s88z32aE+E874PWYaRLm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286046; c=relaxed/simple; bh=XOoPuVLt9dfHQzyitxIiDLxWCT1LNGdaieF2sHtluzo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BBLWXccbgCf9oiLkhqD8m63kUFgjerW2YlL0sL9h50m3/MY1Ionb7vRKrHnNZdWMoftB+OKP1NqcHH3RJRpsoHJdnxec2hUE2MlgDfBOXXDRkKN0lrJbDHVhWGjTaz9ehKi6Hr64lLdgveHRf9dTWEx25i5D7RkKSqDRQGWgXp0= 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=DpdgKFjN; arc=none smtp.client-ip=209.85.215.198 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="DpdgKFjN" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cc1cdfb337eso216960a12.0 for ; Tue, 01 Sep 2026 11:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788286045; x=1788890845; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=j3UHjUhSHEFs3BDPKTwtfBJ57unvd2KtLqU4zpNQnvE=; b=DpdgKFjNRLihw6sTldhn+GUTyzKoBYEhWDaeC8k/8Nvmj/CRn94BSsWxZ91NDJXqzq 66DaDhO/jl2XXSED3dG1jCWLDSwVFsNFq1Z4LW+xbs0OrszMqFpxQGwOfZ62p8zD+nmK fr+WRWM/y+IiVDRqJNiWN6TUwq0+bdD3o6HmLODW7ZHAK8uVn0B2ZWKt5QYzedFptgB3 H/km0RrgN4fxxjIYuea8fqeYlPvovA7uV7B2r0eQNlSM7W7L5LfR5iYVYE2HdKgfRVpX t4Bdytr+kW0CGjsbYVnadSs41qeCLADhg97zLXJ5Z3vqDK/LwvCNIMsoJ+vLMevFAMoe D80A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788286045; x=1788890845; h=content-type: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:content-type; bh=j3UHjUhSHEFs3BDPKTwtfBJ57unvd2KtLqU4zpNQnvE=; b=jhvE+ofix5Q4PaPQKxRhpquY2GDuZNVMlGQ9fQNT7PiAE2x4/MCxyyUwoWiJcDJjO4 fxb/10zdok5GnalAAtnFwxbbZ4w3LZOqF2rVfte1ovHari2GlK84QR5HdENepA/ONCJK +GbUUs8x8LD/ryftZ5DONDENHO8mh1+LUShKSM0GmCI95mLEflpN7I5ldmIJN4Wm9Jqo D84V+2e25EfZ/riGOxdbBnrjfhGbeDf4mAsJ329qCglPpUi161/gdCXsvkT1yKxSnr+q Vjj/NouZfpOsUVtLXscY23eWmXStYcDXhLtl0awIt/PUkRvyW00e0D83R3hx1bjv/Op7 93TA== X-Forwarded-Encrypted: i=1; AHgh+RrGCPS6/rhr4JuJSw8mBU5cggNFzmoC0kUo1hrczR6DTGqlTWALwXZJp23pwKLcJl87o/070HADnTuPfJQ=@vger.kernel.org X-Gm-Message-State: AFuF++k5w1FjroPeOnnNAYb+VGae15BPu2KDAD2GOH8HhYCgLlBNH/ek wM95IhqpZEDSUxVzQQ9HX7uXMLIfOeYtYaZXYKCqyBODQQ4X7g4/CoIM8Bmqfy068aj2zSb/8cj DpKMiOQzjWbVCwQ== X-Received: from pgp10-n2.prod.google.com ([2002:a05:6a02:62ca:20b0:cc2:2955:6540]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7a97:b0:3d0:cc29:ff64 with SMTP id adf61e73a8af0-3d7af8303a1mr17251598637.15.1788286044618; Tue, 01 Sep 2026 11:07:24 -0700 (PDT) Date: Tue, 1 Sep 2026 18:07:09 +0000 In-Reply-To: <20260901180713.4185641-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: <20260901180713.4185641-1-dmatlack@google.com> X-Mailer: git-send-email 2.55.0.966.g6673acef38-goog Message-ID: <20260901180713.4185641-2-dmatlack@google.com> Subject: [RFC PATCH 1/5] liveupdate: Extract luo_file token lookup logic into helper function From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Samiullah Khawaja , Shuah Khan , David Matlack Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extract the token-based list iteration inside luo_retrieve_file() into a standalone private helper luo_find_file_by_token(). This eliminates code duplication by paving the way for additional file retrieval modalities (like retrieving into an existing file descriptor) which also need to safely lookup file tracking structures from the token list before bridging payloads. No functional change intended. Signed-off-by: David Matlack --- kernel/liveupdate/luo_file.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index c39f96961a85..5e160836a165 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -549,26 +549,32 @@ void luo_file_unfreeze(struct luo_file_set *file_set, * -ENOENT if no file with the matching token is found. * Any error code returned by the handler's .retrieve() op. */ -int luo_retrieve_file(struct luo_file_set *file_set, u64 token, - struct file **filep) + +static struct luo_file *luo_find_file_by_token(struct luo_file_set *file_s= et, u64 token) { - struct liveupdate_file_op_args args =3D {0}; struct luo_file *luo_file; - bool found =3D false; - int err; =20 if (list_empty(&file_set->files_list)) - return -ENOENT; + return ERR_PTR(-ENOENT); =20 list_for_each_entry(luo_file, &file_set->files_list, list) { - if (luo_file->token =3D=3D token) { - found =3D true; - break; - } + if (luo_file->token =3D=3D token) + return luo_file; } =20 - if (!found) - return -ENOENT; + return ERR_PTR(-ENOENT); +} + +int luo_retrieve_file(struct luo_file_set *file_set, u64 token, + struct file **filep) +{ + struct liveupdate_file_op_args args =3D {0}; + struct luo_file *luo_file; + int err; + + luo_file =3D luo_find_file_by_token(file_set, token); + if (IS_ERR(luo_file)) + return PTR_ERR(luo_file); =20 guard(mutex)(&luo_file->mutex); if (luo_file->retrieve_status < 0) { --=20 2.55.0.966.g6673acef38-goog From nobody Sat Sep 26 11:46:50 2026 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 B49F849483C for ; Tue, 1 Sep 2026 18:07:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286048; cv=none; b=KDl2t2tp1z3UrZsBxIIyCJE21STJmTCR81CpDbiFeGHkL4WPYa7nMK4C/f/o/m9Dni6T3Y/q1bdbXxlnkys5WG2hfX6qwqkz5iE8zG2I0wGqioxzr+gshcRuLE52+Ha25rPHRE5yV3wvBk8IKcjTZcPZosTvV0wUqR8LoZyUdAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286048; c=relaxed/simple; bh=vtYIoVwj2gUjnAUPtl0S6WmTLHlYLBq4sxXTimWNe+0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sL88aypW6sIEib3dDfg1VAlY9pxj/NobUneCsWHLThmv+RjtOCl6yJZynIBfCt3bQ/yAx6HTSh5RGLsklyeh9A+dmZSAcQmaPp0WFm43PTVslWkJcxKcDTG6AVhprIojMbONZ3yFxh7ZrnepClwNHWslJ5ip55Hb3Xh6MKcLJhU= 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=tc8EYzPv; arc=none smtp.client-ip=209.85.214.197 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="tc8EYzPv" Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2d9336581a2so1228485ad.3 for ; Tue, 01 Sep 2026 11:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788286046; x=1788890846; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=falXxVt1CqmyncILPaUG22UQuDMsfEGdQdvwDGt8XFI=; b=tc8EYzPvzjJJOK667C6ZooyWzoXbtgyGaxZzxGmF3XcuQevItsEkT4BZe1CF7BiAO3 P9RMCqO5ua4LnpSZ4Ie3rcXwhMzd/7C5HiHNg6Z/BRefmz/zS2Rsk+WV7CwdhacYw3ZE FY1UZcHuQ6w6r5KaCoziSBTQEb0lUtUSL3tkdGIgjPqF+CpwIwd0KHwc4X3Y9hjkozJ1 D23a8DfHHQzQnOZWXXVemCVp6r+eNduOgvkR/Jaq1xYA3sD4mimmhWzXEaZYi4LEaKNO h6fEiRS9IQRMuSRIBwVmPGNooi6XDl6eoJQCBJ1BHwb9alFpQ6BVW2CCJmEPFsKwneIq mgxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788286046; x=1788890846; h=content-type: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:content-type; bh=falXxVt1CqmyncILPaUG22UQuDMsfEGdQdvwDGt8XFI=; b=GwbDqpFKsoWi5uHAC/TmeySLF1nFv7QAol8QOf1+xrpKK+aynt2PwWMHmhpYhFEk1b hL3byPMiH8uwQ8bIwEpu004+kCoDt7ybUffXwNqK0RApCsRa85/DnHQimXxbd/PgSdf3 U9R4N3PaqCzuLfipUiKL7rru6yA1kC/6UN8aDf5UyaurEYEtZUmpoM6Cu09vkizqvumJ MgnJkYvE2/W9anwX/7FmjvQ7kNeDwfvrnhMp0dbaWyYaqRRi4Tj/4h1ygCKZhKmqCaOs fwJ0jczpN4zZH/Zu+B3RdGggAm4oPrkBby/PbzNMc2Z8jKcoVaHGRa9h6VOn9u5NBWn7 JRLA== X-Forwarded-Encrypted: i=1; AKwUvBz5Ecr6l0lU6AH/37vDeiEMjvobfOGv336SqMXz5hjH3KMtg3YYCg3epBLVMX+Otnf73h4Dr/m9/1aUbR8=@vger.kernel.org X-Gm-Message-State: AFuF++l9te2PMZCHLf9+G988SS2Bnyvy4zWt85OQiS5JxsfQz+zJr1mG FxjVX8phMyxJNISvKeiD7Ix6olraZDOaDihmf/81VADAJuiHexpYdrCLSBlGwV+nDmn9iXGfxkT SBPKmER2kH25FWA== X-Received: from pjyv9.prod.google.com ([2002:a17:90a:e989:b0:396:5ba1:a6dc]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3c44:b0:398:dcef:c040 with SMTP id 98e67ed59e1d1-398dcefc24amr26801689a91.19.1788286045592; Tue, 01 Sep 2026 11:07:25 -0700 (PDT) Date: Tue, 1 Sep 2026 18:07:10 +0000 In-Reply-To: <20260901180713.4185641-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: <20260901180713.4185641-1-dmatlack@google.com> X-Mailer: git-send-email 2.55.0.966.g6673acef38-goog Message-ID: <20260901180713.4185641-3-dmatlack@google.com> Subject: [RFC PATCH 2/5] liveupdate: Introduce SESSION_RETRIEVE_INTO_FD API and core support From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Samiullah Khawaja , Shuah Khan , David Matlack Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define the LIVEUPDATE_CMD_SESSION_RETRIEVE_INTO_FD ioctl in the UAPI and implement the core support into LUO sessions. Add a new .retrieve_into() callback definition to struct liveupdate_file_handler but do not yet implement it for any file types. Delegating VFS topology recreation to userspace across Live Updates requires an interface where userspace can provide an empty target file descriptor, and the kernel can inject preserved memory into it. This API supplies that missing routing. It uses the new luo_retrieve_into_file() helper to safely look up tracking structures without duplicating backend locks. Signed-off-by: David Matlack --- include/linux/liveupdate.h | 1 + include/uapi/linux/liveupdate.h | 21 +++++++++++++++++++ kernel/liveupdate/luo_file.c | 36 ++++++++++++++++++++++++++++++++ kernel/liveupdate/luo_internal.h | 2 ++ kernel/liveupdate/luo_session.c | 30 ++++++++++++++++++++++++++ 5 files changed, 90 insertions(+) diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index 63ea5417de84..7b595e0f53bc 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -79,6 +79,7 @@ struct liveupdate_file_ops { int (*freeze)(struct liveupdate_file_op_args *args); void (*unfreeze)(struct liveupdate_file_op_args *args); int (*retrieve)(struct liveupdate_file_op_args *args); + int (*retrieve_into)(struct liveupdate_file_op_args *args, struct file *t= arget_file); bool (*can_finish)(struct liveupdate_file_op_args *args); void (*finish)(struct liveupdate_file_op_args *args); unsigned long (*get_id)(struct file *file); diff --git a/include/uapi/linux/liveupdate.h b/include/uapi/linux/liveupdat= e.h index 4043d4038712..ed2049529cc0 100644 --- a/include/uapi/linux/liveupdate.h +++ b/include/uapi/linux/liveupdate.h @@ -59,7 +59,11 @@ enum { LIVEUPDATE_CMD_SESSION_PRESERVE_FD =3D LIVEUPDATE_CMD_SESSION_BASE, LIVEUPDATE_CMD_SESSION_RETRIEVE_FD =3D 0x41, LIVEUPDATE_CMD_SESSION_FINISH =3D 0x42, + LIVEUPDATE_CMD_SESSION_GET_NAME =3D 0x43, + + LIVEUPDATE_CMD_SESSION_RETRIEVE_INTO_FD =3D 0x44, + }; =20 /** @@ -184,6 +188,23 @@ struct liveupdate_session_retrieve_fd { #define LIVEUPDATE_SESSION_RETRIEVE_FD \ _IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_RETRIEVE_FD) =20 +/** + * struct liveupdate_session_retrieve_into_fd - ioctl(LIVEUPDATE_SESSION_R= ETRIEVE_INTO_FD) + * @size: Input; sizeof(struct liveupdate_session_retrieve_into_fd) + * @fd: Input; The open file descriptor (e.g. empty tmpfs file) to inje= ct the resource into. + * @token: Input; An opaque, token that was used to preserve the resource. + * + * Retrieve a previously preserved file descriptor into an existing file d= escriptor. + */ +struct liveupdate_session_retrieve_into_fd { + __u32 size; + __s32 fd; + __aligned_u64 token; +}; + +#define LIVEUPDATE_SESSION_RETRIEVE_INTO_FD \ + _IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_RETRIEVE_INTO_FD) + /** * struct liveupdate_session_finish - ioctl(LIVEUPDATE_SESSION_FINISH) * @size: Input; sizeof(struct liveupdate_session_finish) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index 5e160836a165..c4abfd25e149 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -932,3 +932,39 @@ void liveupdate_unregister_file_handler(struct liveupd= ate_file_handler *fh) luo_flb_unregister_all(fh); list_del(&ACCESS_PRIVATE(fh, list)); } + +int luo_retrieve_into_file(struct luo_file_set *file_set, u64 token, + struct file *target_file) +{ + struct liveupdate_file_op_args args =3D {0}; + struct luo_file *luo_file; + int err; + + luo_file =3D luo_find_file_by_token(file_set, token); + if (IS_ERR(luo_file)) + return PTR_ERR(luo_file); + + guard(mutex)(&luo_file->mutex); + if (luo_file->retrieve_status < 0) + return luo_file->retrieve_status; + + if (luo_file->retrieve_status > 0) + return -EBUSY; /* Already retrieved */ + + if (!luo_file->fh->ops->retrieve_into) + return -EOPNOTSUPP; + + args.handler =3D luo_file->fh; + args.serialized_data =3D luo_file->serialized_data; + err =3D luo_file->fh->ops->retrieve_into(&args, target_file); + if (err) { + luo_file->retrieve_status =3D err; + return err; + } + + luo_file->file =3D target_file; + get_file(luo_file->file); + luo_file->retrieve_status =3D 1; + + return 0; +} diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 64879ffe7378..1af9aebe6623 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -92,6 +92,8 @@ void luo_file_unfreeze(struct luo_file_set *file_set, struct luo_file_set_ser *file_set_ser); int luo_retrieve_file(struct luo_file_set *file_set, u64 token, struct file **filep); +int luo_retrieve_into_file(struct luo_file_set *file_set, u64 token, + struct file *target_file); int luo_file_finish(struct luo_file_set *file_set); int luo_file_deserialize(struct luo_file_set *file_set, struct luo_file_set_ser *file_set_ser); diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_sessio= n.c index f48e9a4185f9..2b967f720ef5 100644 --- a/kernel/liveupdate/luo_session.c +++ b/kernel/liveupdate/luo_session.c @@ -278,6 +278,34 @@ static int luo_session_preserve_fd(struct luo_session = *session, return err; } =20 +static int luo_session_retrieve_into_fd(struct luo_session *session, + struct luo_ucmd *ucmd) +{ + struct liveupdate_session_retrieve_into_fd *argp =3D ucmd->cmd; + struct fd target_fd; + int err; + + target_fd =3D fdget(argp->fd); + if (fd_empty(target_fd)) + return -EBADF; + + guard(mutex)(&session->mutex); + err =3D luo_retrieve_into_file(&session->file_set, argp->token, fd_file(t= arget_fd)); + if (err < 0) + goto err_put_fd; + + err =3D luo_ucmd_respond(ucmd, sizeof(*argp)); + /* + * If we fail to respond, we cannot easily undo the retrieval. Let the + * normal session cleanup logic handle the file reference eventually. + */ + +err_put_fd: + fdput(target_fd); + + return err; +} + static int luo_session_retrieve_fd(struct luo_session *session, struct luo_ucmd *ucmd) { @@ -382,6 +410,8 @@ static const struct luo_ioctl_op luo_session_ioctl_ops[= ] =3D { struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING), IOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name, struct liveupdate_session_get_name, name, LUO_IOCTL_ALL), + IOCTL_OP(LIVEUPDATE_SESSION_RETRIEVE_INTO_FD, luo_session_retrieve_into_f= d, + struct liveupdate_session_retrieve_into_fd, token, LUO_IOCTL_INCOMING), }; =20 static bool luo_ioctl_type_valid(struct luo_session *session, --=20 2.55.0.966.g6673acef38-goog From nobody Sat Sep 26 11:46:50 2026 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 3CADD4949FA for ; Tue, 1 Sep 2026 18:07:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286048; cv=none; b=VQJt0UoCy6NI6XPLDe/rRDV4n0DY/kNLqVLcZ7nzF93wRGWCZsy6rxma/P0mNzGRPfibb/Vzp8WxgZLvqIgA2XAHq3aOq6pONriDwLVhYVWwou5eXAPdo51sfQxLxtKpWklhgzF6066Jd1hPYQIJLiFZqQ9p+qgPxQOUWt7UI1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286048; c=relaxed/simple; bh=1rC3XR2fF2fywHIrzahWsEG6/t6CZ5/hmiLajevTnlM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tfiRtSQ0yv1dWuWSyGHRcPgC5QasJqO0PNYZZqaKLMPDPtgv2Yy6iOjBZGRK1dfrSSUQ6PAdBvtcyZrwgEpTE5QK254ivILLnTLwEwf0JfyRju0gAWSyIWlZuskPeeBcB/oO5k9rGDmj9IcINkOskT2Qu2e2E3ZVAA7etBCX/t0= 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=Nlb4bEn5; arc=none smtp.client-ip=209.85.215.198 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="Nlb4bEn5" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cbb467e56aaso142592a12.1 for ; Tue, 01 Sep 2026 11:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788286047; x=1788890847; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=P31f4AxefLaMEsH/zGccMYrThdu9slSJRJY7f7YnBMU=; b=Nlb4bEn5Z3tUak1LXT7AMqJe8AyvClqEQLWJbJulA1OS3NWt1RY9mmheVpMfRbOk2b YxRdrnPUOQMVErLGff53RdWnx1Mgvl4fmKnxgdYx79k4JcZUuaah3f4C81WCFHs6LUuj nIokspRtnkp1YBeutz6mGPFAbbCxa0ELffd09ZS+vJO6GGgL786FTPFNGh/ifZr+JoS6 yBl5rIj0Vz0ab4xTYkZSiTmDHulp22adMIaMMOIg0IUoVh0J1KTNgp+egzcsrFdb79vG biZR/YeycQgHsTy6kIeXSGUBgRcLKAPYpoCLJtUDtnhH/SC9mfqeDmdKut6sH5HgTay1 P8Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788286047; x=1788890847; h=content-type: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:content-type; bh=P31f4AxefLaMEsH/zGccMYrThdu9slSJRJY7f7YnBMU=; b=hPq6wS90cc+mgBQacnEi6tJyMQ3sBecdITFJsjsgaZUpPph74oKodWN4gof6Z7sL84 XgE3Hqr9oiD+hG4vE2fRUkhOlwupTQbU/koJafC2+PMjr7Lonaiu4zBG1DzW7c/FxePP boItnhnjcGsVF9w7H0sjAnFdVSf7aX3ytrJDn+/lYbSGRoZ2pEt+Sd969+BGUZ+dMKii djqV5Sicw/InbReGo0sxcwevWX4zozkQPDwqK7TR9N226HZlpVlvSvW3BXnkLKPhi4OP RXO3JqTZV4dIOHHR5PbrA7cgL174MNZBj2kiXyHdpdFQ41l0De76Gx66jirw8z61RjHW 2hFQ== X-Forwarded-Encrypted: i=1; AHgh+Rrjp4gN7A0vOvPTvdK1nA7de/ETuSuyMwfbMzxaEkZNulb2IvGT/OfgusBaM/G1ZjRH6OmlbWIJjUnJrjo=@vger.kernel.org X-Gm-Message-State: AFuF++k38g26UxKWchu0ld368uNSo18VMK/XGJNu9Oh7FNQn9W3wCPX8 7URu2Bj9kfvLaVTCgyRXN2dMxqlpZnNyqOGRoG8uXm3v7B7XSbXDlGFUhdyJTGBgL/88DVL6eJx YvGrqy2PW5/MzUA== X-Received: from pgea25.prod.google.com ([2002:a05:6a02:5399:b0:c88:b675:3609]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:31c7:b0:3d3:adbf:777e with SMTP id adf61e73a8af0-3d7afe35cddmr15820173637.19.1788286046490; Tue, 01 Sep 2026 11:07:26 -0700 (PDT) Date: Tue, 1 Sep 2026 18:07:11 +0000 In-Reply-To: <20260901180713.4185641-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: <20260901180713.4185641-1-dmatlack@google.com> X-Mailer: git-send-email 2.55.0.966.g6673acef38-goog Message-ID: <20260901180713.4185641-4-dmatlack@google.com> Subject: [RFC PATCH 3/5] mm/memfd_luo: Implement retrieve_into callback for shmem folios From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Samiullah Khawaja , Shuah Khan , David Matlack Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement the .retrieve_into() file handler API for memfd/shmem files. This implementation uses the standalone logic extracted previously to securely drop physical memory into an empty target inode. Userspace topology delegation requires injecting folios into existing file descriptors. This implementation verifies the target descriptor is a shmem file and strictly guarantees it is empty before locking the inode and bridging the KHO folios into its address space. Signed-off-by: David Matlack --- mm/memfd_luo.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c index 59de210bee5f..dcda5bf98646 100644 --- a/mm/memfd_luo.c +++ b/mm/memfd_luo.c @@ -590,10 +590,58 @@ static unsigned long memfd_luo_get_id(struct file *fi= le) return (unsigned long)file_inode(file); } =20 +static int memfd_luo_retrieve_into(struct liveupdate_file_op_args *args, s= truct file *target_file) +{ + struct inode *inode =3D file_inode(target_file); + struct memfd_luo_folio_ser *folios_ser; + struct memfd_luo_ser *ser; + int err; + + /* Security/Safety checks: Ensure it's a shmem file and is completely emp= ty */ + if (!shmem_mapping(target_file->f_mapping)) + return -EINVAL; + + inode_lock(inode); + if (i_size_read(inode) !=3D 0) { + inode_unlock(inode); + return -EBUSY; + } + + ser =3D phys_to_virt(args->serialized_data); + if (!ser) { + inode_unlock(inode); + return -EINVAL; + } + + if (ser->nr_folios) { + folios_ser =3D kho_restore_vmalloc(&ser->folios); + if (!folios_ser) { + inode_unlock(inode); + return -EINVAL; + } + + /* Inject the physical pages from KHO using the extracted helper */ + err =3D memfd_luo_retrieve_folios(target_file, folios_ser, ser->nr_folio= s); + kho_restore_free(folios_ser); + if (err) { + inode_unlock(inode); + return err; + } + } + + /* Fast-forward the kernel inode size to match the injected data */ + vfs_setpos(target_file, ser->pos, MAX_LFS_FILESIZE); + i_size_write(inode, ser->size); + + inode_unlock(inode); + return 0; +} + static const struct liveupdate_file_ops memfd_luo_file_ops =3D { .freeze =3D memfd_luo_freeze, .finish =3D memfd_luo_finish, .retrieve =3D memfd_luo_retrieve, + .retrieve_into =3D memfd_luo_retrieve_into, .preserve =3D memfd_luo_preserve, .unpreserve =3D memfd_luo_unpreserve, .can_preserve =3D memfd_luo_can_preserve, --=20 2.55.0.966.g6673acef38-goog From nobody Sat Sep 26 11:46:50 2026 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (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 5337449502C for ; Tue, 1 Sep 2026 18:07:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286049; cv=none; b=g/sECd/zug12jvMOLUaXOoKGR+PTAPMckkuAdnyldtj9LWPtCQWnKYoyLKFshirDYROP9GpXWNjss6Cq8zP/wgzEbtvVV59dpPzO0rfSh34bW/OK+6DFiJ50LGvQEe/X0dZVH/3WZ96IkrDP/OFOocXt0QXAs6K3ivjLHVCwK8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286049; c=relaxed/simple; bh=uFV6QdZgs53Cc//57Ww0okrOM7FWgj7HZIJ7HnfB/tI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lAnbFTISpsbf//serh7etn5KKc/4+1lTw+dWcQMmGA6J7ELHzEDAPyjTaHz/utoU+f+T4M1py8BgAEJzM1WFSpd5t5Smr3vCWdb9S1mkJa9I6XTK/66Mlm0T/5QnmQsGVxkBIa+vE1BsvB77xyFpW9I6R3Ffct/4+DEh8xZPhjQ= 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=NdxWsNN7; arc=none smtp.client-ip=209.85.215.197 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="NdxWsNN7" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cc1b6f65dacso207136a12.1 for ; Tue, 01 Sep 2026 11:07:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788286048; x=1788890848; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=abQNPJxLdJSbNwggArhdklh2mCXd2+hz+eKc3bSV4GE=; b=NdxWsNN7eDscQRVtniyJcrdp3jT5UfT7moWS2ymVPhgLtkt5eDAiZwvyFI7X1kIB07 au1hOVocwh0+C94HUCEkNg3zr75dDzIGNRFLpAnCz4WmKQbl3LPtpKlw07zEfJAnirfi E0QP//ZsgNjeeIfNl3rt7oy/cCNGOwnACnPJINML5TtSMSj/lOZjnnYd13ota7eeMT6y rcLuLkNKQtE7D5V4qX1PmwflX8EpPZjYEvZs7mPmfRMb3cw8pykWgk/HNUwCMCkbjbuJ i22VbET8c7juTwyad7JDy+c3HyNUj8rYieEhEdsYUr8eg84G9MReAUUXWn90khRpw2ZW vnKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788286048; x=1788890848; h=content-type: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:content-type; bh=abQNPJxLdJSbNwggArhdklh2mCXd2+hz+eKc3bSV4GE=; b=Btupn41MJC9r0O3ZcRowMfuXbY2MsVIEEjEz2cVLZBXmpeKR2LhK+7l74BfC/WLWOl oLIF0lOjg+0mDGKs85IO6j+vNmGsxUBZvhrHUSuLo6A4ny5Dxjh2FT37ZBJZ9Dk7+D48 jNMGLecxGVDNXtSDp39UsDVx0rCGpF5uCEqJ2AOarxlHjjFxZetiqOwlb0amAYlPDdgC wp5vyULogwTud59fH642ropff6L4UZgula2f61WE1EAX3+uRv+j0SB71q1d56hc+q7EO l2DT8yCHHw65OzwOyANMzQEi1ONFh/CIBPlosqxexktfXYVgd6nW++qENKigGWHlyu/c hQ3g== X-Forwarded-Encrypted: i=1; AHgh+RpIqqVvWAeTQZlw2JZN+ieStAjaq1lDXcquamR4Jc+Y0nN+eQGFU+fy8wL0HLWs5yc/j95RVilFg/X0Jho=@vger.kernel.org X-Gm-Message-State: AFuF++mF4murL+Fwp+EGoDyxrRsYrl0Z+iHBtCnSz1dQ8Nh/q1Anyfxi ygX7eMcJsFvXni31KgrhU+YkiwBqCiApkH/tMcfZRVuNmz11BPMEGB+UTNICWuj6a4rp7xkdZR9 m7KCtjL5+76grbQ== X-Received: from pfux35.prod.google.com ([2002:a05:6a00:be3:b0:848:7bbd:284b]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3309:b0:835:6388:655d with SMTP id d2e1a72fcca58-8562ba7dae0mr58420543b3a.14.1788286047461; Tue, 01 Sep 2026 11:07:27 -0700 (PDT) Date: Tue, 1 Sep 2026 18:07:12 +0000 In-Reply-To: <20260901180713.4185641-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: <20260901180713.4185641-1-dmatlack@google.com> X-Mailer: git-send-email 2.55.0.966.g6673acef38-goog Message-ID: <20260901180713.4185641-5-dmatlack@google.com> Subject: [RFC PATCH 4/5] mm/memfd_luo: Expand support beyond memfd to all generic shmem inodes From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Samiullah Khawaja , Shuah Khan , David Matlack Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Relax the early validation checks in the Live Update preservation path to allow general shmem-backed files, completely dropping the requirement that the file be unlinked (!inode->i_nlink). This officially enables userspace to push standard, path-backed tmpfs file descriptors through the LUO session ioctl instead of being artificially restricted strictly to anonymous memfd pseudofiles. Signed-off-by: David Matlack --- mm/memfd_luo.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c index dcda5bf98646..107115c97bd8 100644 --- a/mm/memfd_luo.c +++ b/mm/memfd_luo.c @@ -9,14 +9,15 @@ */ =20 /** - * DOC: Memfd Preservation via LUO + * DOC: Memfd and Tmpfs Preservation via LUO * * Overview * =3D=3D=3D=3D=3D=3D=3D=3D * - * Memory file descriptors (memfd) can be preserved over a kexec using the= Live - * Update Orchestrator (LUO) file preservation. This allows userspace to - * transfer its memory contents to the next kernel after a kexec. + * Memory file descriptors (memfd) and generic tmpfs files can be preserved + * over a kexec using the Live Update Orchestrator (LUO) file preservation. + * This allows userspace to transfer its memory contents to the next kernel + * after a kexec. * * The preservation is not intended to be transparent. Only select propert= ies of * the file are preserved. All others are reset to default. The preserved @@ -24,16 +25,17 @@ * * .. note:: * The LUO API is not stabilized yet, so the preserved properties of a = memfd - * are also not stable and are subject to backwards incompatible change= s. + * or tmpfs file are also not stable and are subject to backwards + * incompatible changes. * * .. note:: - * Currently a memfd backed by Hugetlb is not supported. Memfds created + * Currently a file backed by Hugetlb is not supported. Memfds created * with ``MFD_HUGETLB`` will be rejected. * * Preserved Properties * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * - * The following properties of the memfd are preserved across kexec: + * The following properties of the memfd/tmpfs file are preserved across k= exec: * * File Contents * All data stored in the file is preserved. @@ -580,9 +582,7 @@ static int memfd_luo_retrieve(struct liveupdate_file_op= _args *args) static bool memfd_luo_can_preserve(struct liveupdate_file_handler *handler, struct file *file) { - struct inode *inode =3D file_inode(file); - - return shmem_file(file) && !inode->i_nlink; + return shmem_file(file) || shmem_mapping(file->f_mapping); } =20 static unsigned long memfd_luo_get_id(struct file *file) --=20 2.55.0.966.g6673acef38-goog From nobody Sat Sep 26 11:46:50 2026 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 285F3495045 for ; Tue, 1 Sep 2026 18:07:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286050; cv=none; b=a75I5kq3yfy9md0qBbpv8YNYsiKNQ6bjbXUVZuqloIB9nwEFDqLIgMXH8Y/VAdLmcjRKUhQOkXBstJCb2a6Owq0Wvq5U5lKut3AxgZjpqESsW7BXjrrKq2fuSemLieBV8MGxdky/Wuo8H49Ur72Ys4pk5ElTgicPKciIsZw1jyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788286050; c=relaxed/simple; bh=OMBn7uiudnSSq54gX2RVyNKqmRP8wdhdzksmUcad6So=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LJChjXmUJcex/v2phARghZ6VZ9Bjz3sjbE6aYtK2KFPdzk0ob87lxbqtg9UJf+qSxRxL1Q/zeAJGfo9bbPv00hfZ3ZnHT20hyhJGMlBO8CKWUWIto1EtFmQNPeWactFTIYbRlnw7qSQ6ZW+m2iAMLW6dSsjIN0cY0TTO02drT4E= 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=OqhXS1Zt; arc=none smtp.client-ip=209.85.216.71 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="OqhXS1Zt" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38dbf293831so247205a91.3 for ; Tue, 01 Sep 2026 11:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788286048; x=1788890848; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=EEIZgCOB2hl947kqAMQSV91Zoox41yoYUfb/qDb9/EY=; b=OqhXS1Zt/cKsJMBefL6SAk9JugUcqqHOeg5bXHkAdSI68clOpYhCeIouauQcZJuljH gdX1jvxOaDisTk2IgegBQGH9eyWJR+JizNcMStPBdk/3Mb/doyqaCYAUdBjbO+gw7lCm ifaBTQ0FGDZHUQrNadbLJyxNQ7swOUTzE6Bh5G8mQXYTMLxwRY2EXtM1+u5Zkbet1mvZ TiXnHd2d/dFT/B+hx8qWer96kx67KVrrcsQDPcCfsIZ40VDbNz6IN52c9M3wir9GrKLZ gaPC5RRBXcbo+GNubysKzQ+EICpEnOnFLjU2ZKCv+VB0yVc2JYEmbDD++/snikIBKZwC Q9+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788286048; x=1788890848; h=content-type: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:content-type; bh=EEIZgCOB2hl947kqAMQSV91Zoox41yoYUfb/qDb9/EY=; b=QazyViBQYnbDMbxmfQOEa2A5T+hBA3WRei6VPrfGvh0pSyINRG8ynVeq5JdK5YZ8AM o1SM8WYQUPzvWpRkgCzwUr3LcBvPMshpYVlUU5fTXo9K14d6wp3Ah6sELX/cflp5iYzr wXpyzxQvA3o9GJ1WN8V6HKLcrtPJDIWvva4wJskXPVIbT2QyBe5G4zwpkOgt1pOXyYX3 7cYebUbKUHGe0jcvQ7u6sXDu627KF9kVc9SPhcBvNxGoMi/4xyfYviLd3PSsLI/Mj9y1 GwOVzLkeddUC9Xscbv75yZVtVMl/v4mNfbFX2c0CeJ2MTZ5ymZOv+jH8Wd1SD+E4WgH6 f8+w== X-Forwarded-Encrypted: i=1; AKwUvBzjQ2jH1C75tKYm1e+N3is/JHxs5kULuXw63FUgSFbqEfxA9UneMeuHs8ZBGKFrIMnFQy9YaRhvT5RWvwg=@vger.kernel.org X-Gm-Message-State: AFuF++kXIgy+OaVdp0NQsEcnIUzIZr1PBcpUwhHb4X0li7CUShHggpAt QLgMvWwl8KgI66zmWwbciLfGufcF8yqTDLVW8u5xYrcZWlVakU6JXuIuFj2Co0TndFiIZXfhqzE JnIdKTWhH+J+HLg== X-Received: from pjbiy13.prod.google.com ([2002:a17:90b:16cd:b0:38e:b470:e6db]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3fcf:b0:398:9be5:b419 with SMTP id 98e67ed59e1d1-3989be5b4camr43204014a91.20.1788286048322; Tue, 01 Sep 2026 11:07:28 -0700 (PDT) Date: Tue, 1 Sep 2026 18:07:13 +0000 In-Reply-To: <20260901180713.4185641-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: <20260901180713.4185641-1-dmatlack@google.com> X-Mailer: git-send-email 2.55.0.966.g6673acef38-goog Message-ID: <20260901180713.4185641-6-dmatlack@google.com> Subject: [RFC PATCH 5/5] selftests: liveupdate: Add multi-session test coverage for session_retrieve_into From: David Matlack To: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Samiullah Khawaja , Shuah Khan , David Matlack Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extend the multi-session Live Update test to specifically verify the new LIVEUPDATE_SESSION_RETRIEVE_INTO_FD ioctl path. In Stage 2 of the kexec workflow, the test explicitly delegates topology by allocating a clean tmpfs target and driving the folios into it through the new API, verifying that the data preserves identically to the native KHO mapping. Signed-off-by: David Matlack --- .../liveupdate/lib/include/libliveupdate.h | 1 + .../selftests/liveupdate/lib/lu_utils.c | 33 +++++++++++ .../selftests/liveupdate/luo_multi_session.c | 56 ++++++++++++++++--- 3 files changed, 83 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h= b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h index fa07fed08364..8ab1e662eeaa 100644 --- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h +++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h @@ -33,6 +33,7 @@ int luo_session_retrieve_fd(int session_fd, __u64 token); =20 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); +int luo_verify_retrieve_into_memfd(int session_fd, int token, int mfd, con= st char *expected_data); =20 void create_state_file(int luo_fd, const char *session_name, int token, int next_stage); diff --git a/tools/testing/selftests/liveupdate/lib/lu_utils.c b/tools/test= ing/selftests/liveupdate/lib/lu_utils.c index 74d41115c281..8ed9c367f92e 100644 --- a/tools/testing/selftests/liveupdate/lib/lu_utils.c +++ b/tools/testing/selftests/liveupdate/lib/lu_utils.c @@ -324,3 +324,36 @@ int luo_test(int argc, char *argv[], =20 return 0; } + +int luo_verify_retrieve_into_memfd(int session_fd, int token, int mfd, + const char *expected_data) +{ + struct liveupdate_session_retrieve_into_fd retrieve_args =3D { + .size =3D sizeof(retrieve_args), + .token =3D token, + .fd =3D mfd, + }; + long page_size =3D getpagesize(); + void *map =3D MAP_FAILED; + int ret =3D -1; + + ret =3D ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_INTO_FD, &retrieve_= args); + if (ret < 0) { + ksft_print_msg("ioctl LIVEUPDATE_SESSION_RETRIEVE_INTO_FD failed\n"); + return -errno; + } + + map =3D mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0); + if (map =3D=3D MAP_FAILED) + return -errno; + + if (expected_data && strcmp(expected_data, map) !=3D 0) { + ksft_print_msg("Data mismatch! Expected '%s', Got '%s'\n", + expected_data, (char *)map); + munmap(map, page_size); + return -EINVAL; + } + + munmap(map, page_size); + return 0; +} diff --git a/tools/testing/selftests/liveupdate/luo_multi_session.c b/tools= /testing/selftests/liveupdate/luo_multi_session.c index aac24a5f5ce3..7882f49aadaf 100644 --- a/tools/testing/selftests/liveupdate/luo_multi_session.c +++ b/tools/testing/selftests/liveupdate/luo_multi_session.c @@ -1,4 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include =20 /* * Copyright (c) 2025, Google LLC. @@ -31,6 +36,8 @@ static void run_stage_1(int luo_fd) { int s_empty1_fd, s_empty2_fd, s_files1_fd, s_files2_fd; + int tmpfs_fd; + void *map; =20 ksft_print_msg("[STAGE 1] Starting pre-kexec setup for multi-session test= ...\n"); =20 @@ -53,25 +60,50 @@ static void run_stage_1(int luo_fd) s_files1_fd =3D luo_create_session(luo_fd, SESSION_FILES_1); if (s_files1_fd < 0) fail_exit("luo_create_session for '%s'", SESSION_FILES_1); + ksft_print_msg(" -> Preserving memfd (token %#x, content: \"%s\")\n", + MFD1_TOKEN, MFD1_DATA); if (create_and_preserve_memfd(s_files1_fd, MFD1_TOKEN, MFD1_DATA) < 0) { fail_exit("create_and_preserve_memfd for token %#x", MFD1_TOKEN); } =20 - ksft_print_msg("[STAGE 1] Creating session '%s' with two memfds...\n", + ksft_print_msg("[STAGE 1] Creating session '%s' with memfd and tmpfs file= ...\n", SESSION_FILES_2); =20 s_files2_fd =3D luo_create_session(luo_fd, SESSION_FILES_2); if (s_files2_fd < 0) fail_exit("luo_create_session for '%s'", SESSION_FILES_2); + ksft_print_msg(" -> Preserving memfd (token %#x, content: \"%s\")\n", + MFD2_TOKEN, MFD2_DATA); if (create_and_preserve_memfd(s_files2_fd, MFD2_TOKEN, MFD2_DATA) < 0) { fail_exit("create_and_preserve_memfd for token %#x", MFD2_TOKEN); } - if (create_and_preserve_memfd(s_files2_fd, MFD3_TOKEN, MFD3_DATA) < 0) { - fail_exit("create_and_preserve_memfd for token %#x", - MFD3_TOKEN); - } + ksft_print_msg(" -> Populating custom tmpfs file at /mnt/mfd3_source...\= n"); + mkdir("/mnt", 0777); + mount("tmpfs", "/mnt", "tmpfs", 0, NULL); + tmpfs_fd =3D open("/mnt/mfd3_source", O_CREAT | O_RDWR, 0666); + if (tmpfs_fd < 0) + fail_exit("failed to open tmpfs_fd"); + ksft_print_msg(" -> Preserving generic tmpfs file (token %#x, content: \= "%s\")\n", + MFD3_TOKEN, MFD3_DATA); + if (ftruncate(tmpfs_fd, getpagesize()) < 0) + fail_exit("ftruncate tmpfs_fd"); + map =3D mmap(NULL, getpagesize(), PROT_WRITE, MAP_SHARED, tmpfs_fd, 0); + if (map =3D=3D MAP_FAILED) + fail_exit("mmap tmpfs_fd"); + strcpy(map, MFD3_DATA); + munmap(map, getpagesize()); + + struct liveupdate_session_preserve_fd preserve_args =3D { + .size =3D sizeof(preserve_args), + .token =3D MFD3_TOKEN, + .fd =3D tmpfs_fd, + }; + if (ioctl(s_files2_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &preserve_args) < = 0) + fail_exit("preserve tmpfs fd"); + + close(tmpfs_fd); =20 close(luo_fd); daemonize_and_wait(); @@ -110,6 +142,7 @@ static void run_stage_2(int luo_fd, int state_session_f= d) =20 ksft_print_msg("[STAGE 2] Verifying contents of session '%s'...\n", SESSION_FILES_1); + ksft_print_msg(" -> Retrieving memfd (token %#x) from session...\n", MFD= 1_TOKEN); mfd1 =3D restore_and_verify_memfd(s_files1_fd, MFD1_TOKEN, MFD1_DATA); if (mfd1 < 0) fail_exit("restore_and_verify_memfd for token %#x", MFD1_TOKEN); @@ -118,14 +151,23 @@ static void run_stage_2(int luo_fd, int state_session= _fd) ksft_print_msg("[STAGE 2] Verifying contents of session '%s'...\n", SESSION_FILES_2); =20 + ksft_print_msg(" -> Retrieving memfd (token %#x) from session...\n", MFD= 2_TOKEN); mfd2 =3D restore_and_verify_memfd(s_files2_fd, MFD2_TOKEN, MFD2_DATA); if (mfd2 < 0) fail_exit("restore_and_verify_memfd for token %#x", MFD2_TOKEN); close(mfd2); =20 - mfd3 =3D restore_and_verify_memfd(s_files2_fd, MFD3_TOKEN, MFD3_DATA); + ksft_print_msg(" -> Creating empty tmpfs file at /mnt/mfd3_target...\n"); + mkdir("/mnt", 0777); + mount("tmpfs", "/mnt", "tmpfs", 0, NULL); + mfd3 =3D open("/mnt/mfd3_target", O_CREAT | O_RDWR, 0666); if (mfd3 < 0) - fail_exit("restore_and_verify_memfd for token %#x", MFD3_TOKEN); + fail_exit("open tmpfs target for retrieve_into"); + + ksft_print_msg(" -> Validating LIVEUPDATE_SESSION_RETRIEVE_INTO_FD (toke= n %#x)...\n", + MFD3_TOKEN); + if (luo_verify_retrieve_into_memfd(s_files2_fd, MFD3_TOKEN, mfd3, MFD3_DA= TA) < 0) + fail_exit("luo_verify_retrieve_into_memfd for token %#x", MFD3_TOKEN); close(mfd3); =20 ksft_print_msg("[STAGE 2] Test data verified successfully.\n"); --=20 2.55.0.966.g6673acef38-goog