From nobody Tue Dec 2 00:06:08 2025 Received: from mail-yx1-f50.google.com (mail-yx1-f50.google.com [74.125.224.50]) (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 4134E25A359 for ; Tue, 25 Nov 2025 22:50:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764111016; cv=none; b=GQnIIkHSiDfevJS7Lgs6SFws+BlXiuRejItisyDBJiQIi44fEO6rZBakbfwtaclZ8bdpsgq7BvXnpJebDA5bUt2UFv2cYEehNsT3r/NaKo0JFM5MIQOtrmYtFK3rH9SyR2Mp0cLsdNA9C78DiOrd+LqWN6d63F/ZnuQBB8yEQhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764111016; c=relaxed/simple; bh=Flw1HhgOTwsLYaqUsBzwcOnR3+UP2B1RKhE9nu7LuUo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZTzGbw9SaRt/oMfX2FXZXiS7K5xbZDYq03fbaj9tZZEk/BkeqtKBYArzg0kKkksplQdsxXc0QRkSVX2qqHNTPZM1+NOvNnOcog4whTXfEsxft67ISB3neeQnqp8JA6IYs5LRx3WX6vC0l6ZekNyz+4TjualszsJtPBjJ+2iqf5A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=MktIyMPu; arc=none smtp.client-ip=74.125.224.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="MktIyMPu" Received: by mail-yx1-f50.google.com with SMTP id 956f58d0204a3-63fc8c337f2so5867608d50.0 for ; Tue, 25 Nov 2025 14:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1764111013; x=1764715813; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=WhjNI5+EJ9ljnjKwa2s5cY5pXpLFdeBfNK5SlWfnyu0=; b=MktIyMPueKYGEL9t35cjC5FJvKMosqbSt4nI2f5cteVtAnHlZP5c30Vs9k6eW7rvru lC7LmB/t/16s2b23peN9+ADcMXA/DtOViVLgUIT8BDCPJbmfUohaw+rGoocrJo3rAcOL 7i4wsSdAFt7pEBACc1dYmQtpQE0/vgxTXhk2NAse0O8PqSQEnAi4R9oeW/V5l1qgrF5j BQ7fZbiYG2dHYaXiMW5Co7kpSse3622nrT1NKq9FpMGXvQAcJ26qm60lPGWJqmBUKy4p AmKJMzByUjIdguHumD2K+q/Wyzbx7lP2HsuAcU7jR3R56Qrt5CTlMiHTZWwciE2YFoHu 6lgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764111013; x=1764715813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=WhjNI5+EJ9ljnjKwa2s5cY5pXpLFdeBfNK5SlWfnyu0=; b=RBttj9GO0ecD318j7O2TyC2mGHZIcv426oNUsQWyT9cNpWSjVUdt1AVeatjjH/T/Ef bTDlYBSp7JQ20Y6RAmI5+p6D/mMIC7OVHRXPu4Deh2dZSG/yLD1NtEnCiyaeuYIfupXt kmW6lfs7a0+8qJWvhK1P2ynWDAnIT5VF8v+h00h1GN/pMxnqmrClpVzxp8oAZ3OHTYwB l2DzJPyWj+yfgQjvQd3lJC11iU/SJHODwZnW8BEFcVR6z/MZdJIAHtfhMDwWxQp47avE WA89IYMUf0W2B1BWk+AUJsQ0q7SJ71PTJQtzbpZsw2LquY6fqGW9jGl8JbFFwe8O9fMd JIbw== X-Forwarded-Encrypted: i=1; AJvYcCU05F6Ukc+9AJ6gN9pDFJVO4rEfuDf8ZeBBPC6oKspzpwVTIeL0yoVffF16lEJh7NEpdb3gq8lX+DeTDfM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3+NpRm6oiee7iFsrOvo43OwSTSj1oDlulF111toyajBUyv9gb mmQViinY7sX4JMbCdBGbZni6e1jt6Y452+h5W5Ob3TX+FUTqkSduZIAN4Iab1J4F9Yo= X-Gm-Gg: ASbGncuvc5St9rRi3rJcuph2tzAavE6O+8CGLlG3mIxqHFo8R4eXKYLxyPNZDsnlffx VlutR3erbRYGz7j3F6ctG1xu5eTrgyEEn5t+eSLgHQAujrJHUKCAFVlnryXnRGzdON1Q+sTytB1 vSwi+hz/1W67x1hsagkoHfeoqWd75B9ZV8fu7pdUbXLm5cZB6763RvyQulMlieS8tre3pXi7B51 bHNmJjVBeqVtFmZIUG7YurM+ZylW8sLYAi2Bve/IBxVUZncoBBZFMVytzWwP4tUKiE2u3SS7lcs vKAOJKFnsKsJa2T1ppaQz5Dv083EJQZxCOi5Vmh5O2YBN2vJyNqW7Le/ZO6C4o7hq/Lrqb86y6l r2D0kn+M3XWDOu1+jyI2pMaZmFie4uGMHaH3BmX3e/MX7IYdnLqjgKAGF1ee1rcJpMwO6yE3B4i pRm4MKPtkdmVxp0Sui6anvaLuXLpdrIVt6O4CeQz69mtWeBlcE3X76qU91aEut+yz57KmliwL9w exHzdQ= X-Google-Smtp-Source: AGHT+IHN1T8IjsJLPeQFfxJ0zE12+tdXYu3bnT6rjJ5iYU6llFZIq22ymrAKFvFStVURlAQL0Q1stQ== X-Received: by 2002:a05:690c:f83:b0:722:7a7f:537a with SMTP id 00721157ae682-78ab6f01706mr75241757b3.38.1764111013150; Tue, 25 Nov 2025 14:50:13 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 00721157ae682-78a79925ba4sm60138167b3.26.2025.11.25.14.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 14:50:12 -0800 (PST) From: Pasha Tatashin To: pratyush@kernel.org, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, skhawaja@google.com, rientjes@google.com, corbet@lwn.net, akpm@linux-foundation.org, kees@kernel.org, davidgow@google.com, pmladek@suse.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v8 2/2] tests/liveupdate: Add in-kernel liveupdate test Date: Tue, 25 Nov 2025 17:50:06 -0500 Message-ID: <20251125225006.3722394-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.487.g5c8c507ade-goog In-Reply-To: <20251125225006.3722394-1-pasha.tatashin@soleen.com> References: <20251125225006.3722394-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce an in-kernel test module to validate the core logic of the Live Update Orchestrator's File-Lifecycle-Bound feature. This provides a low-level, controlled environment to test FLB registration and callback invocation without requiring userspace interaction or actual kexec reboots. The test is enabled by the CONFIG_LIVEUPDATE_TEST Kconfig option. Signed-off-by: Pasha Tatashin --- MAINTAINERS | 1 + include/linux/kho/abi/luo.h | 5 + kernel/liveupdate/luo_file.c | 8 +- kernel/liveupdate/luo_internal.h | 8 ++ lib/Kconfig.debug | 23 +++++ lib/tests/Makefile | 1 + lib/tests/liveupdate.c | 158 +++++++++++++++++++++++++++++++ 7 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 lib/tests/liveupdate.c diff --git a/MAINTAINERS b/MAINTAINERS index ce2da2d39786..2722f98d0ed7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14479,6 +14479,7 @@ F: include/linux/liveupdate.h F: include/linux/liveupdate/ F: include/uapi/linux/liveupdate.h F: kernel/liveupdate/ +F: lib/tests/liveupdate.c F: mm/memfd_luo.c F: tools/testing/selftests/liveupdate/ =20 diff --git a/include/linux/kho/abi/luo.h b/include/linux/kho/abi/luo.h index 2734d1020dda..4a1cc6a5f3f8 100644 --- a/include/linux/kho/abi/luo.h +++ b/include/linux/kho/abi/luo.h @@ -239,4 +239,9 @@ struct luo_flb_ser { u64 count; } __packed; =20 +/* Kernel Live Update Test ABI */ +#ifdef CONFIG_LIVEUPDATE_TEST +#define LIVEUPDATE_TEST_FLB_COMPATIBLE(i) "liveupdate-test-flb-v" #i +#endif + #endif /* _LINUX_KHO_ABI_LUO_H */ diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index 6a29d20e9ed9..fca3806dae28 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -860,6 +860,8 @@ int liveupdate_register_file_handler(struct liveupdate_= file_handler *fh) list_add_tail(&ACCESS_PRIVATE(fh, list), &luo_file_handler_list); luo_session_resume(); =20 + liveupdate_test_register(fh); + return 0; =20 err_resume: @@ -891,8 +893,10 @@ int liveupdate_unregister_file_handler(struct liveupda= te_file_handler *fh) if (!liveupdate_enabled()) return -EOPNOTSUPP; =20 + liveupdate_test_unregister(fh); + if (!luo_session_quiesce()) - return -EBUSY; + goto err_register; =20 if (!list_empty(&ACCESS_PRIVATE(fh, flb_list))) goto err_resume; @@ -905,5 +909,7 @@ int liveupdate_unregister_file_handler(struct liveupdat= e_file_handler *fh) =20 err_resume: luo_session_resume(); +err_register: + liveupdate_test_register(fh); return err; } diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 9732a7ca3d5f..6115d6a4054d 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -114,4 +114,12 @@ int __init luo_flb_setup_outgoing(void *fdt); int __init luo_flb_setup_incoming(void *fdt); void luo_flb_serialize(void); =20 +#ifdef CONFIG_LIVEUPDATE_TEST +void liveupdate_test_register(struct liveupdate_file_handler *fh); +void liveupdate_test_unregister(struct liveupdate_file_handler *fh); +#else +static inline void liveupdate_test_register(struct liveupdate_file_handler= *fh) { } +static inline void liveupdate_test_unregister(struct liveupdate_file_handl= er *fh) { } +#endif + #endif /* _LINUX_LUO_INTERNAL_H */ diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index bd3bb7a0c801..59b5ce8f89cf 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2803,6 +2803,29 @@ config LINEAR_RANGES_TEST =20 If unsure, say N. =20 +config LIVEUPDATE_TEST + bool "Live Update Kernel Test" + default n + depends on LIVEUPDATE + help + Enable a built-in kernel test module for the Live Update + Orchestrator. + + This module validates the File-Lifecycle-Bound subsystem by + registering a set of mock FLB objects with any real file handlers + that support live update (such as the memfd handler). + + When live update operations are performed, this test module will + output messages to the kernel log (dmesg), confirming that its + registration and various callback functions (preserve, retrieve, + finish, etc.) are being invoked correctly. + + This is a debugging and regression testing tool for developers + working on the Live Update subsystem. It should not be enabled in + production kernels. + + If unsure, say N + config CMDLINE_KUNIT_TEST tristate "KUnit test for cmdline API" if !KUNIT_ALL_TESTS depends on KUNIT diff --git a/lib/tests/Makefile b/lib/tests/Makefile index 601dba4b7d96..ab0173e6e8b0 100644 --- a/lib/tests/Makefile +++ b/lib/tests/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_LIST_KUNIT_TEST) +=3D list-test.o obj-$(CONFIG_KFIFO_KUNIT_TEST) +=3D kfifo_kunit.o obj-$(CONFIG_TEST_LIST_SORT) +=3D test_list_sort.o obj-$(CONFIG_LINEAR_RANGES_TEST) +=3D test_linear_ranges.o +obj-$(CONFIG_LIVEUPDATE_TEST) +=3D liveupdate.o =20 CFLAGS_longest_symbol_kunit.o +=3D $(call cc-disable-warning, missing-prot= otypes) obj-$(CONFIG_LONGEST_SYM_KUNIT_TEST) +=3D longest_symbol_kunit.o diff --git a/lib/tests/liveupdate.c b/lib/tests/liveupdate.c new file mode 100644 index 000000000000..496d6ef91a30 --- /dev/null +++ b/lib/tests/liveupdate.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#define pr_fmt(fmt) KBUILD_MODNAME " test: " fmt + +#include +#include +#include +#include +#include +#include "../../kernel/liveupdate/luo_internal.h" + +static const struct liveupdate_flb_ops test_flb_ops; +#define DEFINE_TEST_FLB(i) { \ + .ops =3D &test_flb_ops, \ + .compatible =3D LIVEUPDATE_TEST_FLB_COMPATIBLE(i), \ +} + +/* Number of Test FLBs to register with every file handler */ +#define TEST_NFLBS 3 +static struct liveupdate_flb test_flbs[TEST_NFLBS] =3D { + DEFINE_TEST_FLB(0), + DEFINE_TEST_FLB(1), + DEFINE_TEST_FLB(2), +}; + +#define TEST_FLB_MAGIC_BASE 0xFEEDF00DCAFEBEE0ULL + +static int test_flb_preserve(struct liveupdate_flb_op_args *argp) +{ + ptrdiff_t index =3D argp->flb - test_flbs; + + pr_info("%s: preserve was triggered\n", argp->flb->compatible); + argp->data =3D TEST_FLB_MAGIC_BASE + index; + + return 0; +} + +static void test_flb_unpreserve(struct liveupdate_flb_op_args *argp) +{ + pr_info("%s: unpreserve was triggered\n", argp->flb->compatible); +} + +static int test_flb_retrieve(struct liveupdate_flb_op_args *argp) +{ + ptrdiff_t index =3D argp->flb - test_flbs; + u64 expected_data =3D TEST_FLB_MAGIC_BASE + index; + + if (argp->data =3D=3D expected_data) { + pr_info("%s: found flb data from the previous boot\n", + argp->flb->compatible); + argp->obj =3D (void *)argp->data; + } else { + pr_err("%s: ERROR - incorrect data handle: %llx, expected %llx\n", + argp->flb->compatible, argp->data, expected_data); + return -EINVAL; + } + + return 0; +} + +static void test_flb_finish(struct liveupdate_flb_op_args *argp) +{ + ptrdiff_t index =3D argp->flb - test_flbs; + void *expected_obj =3D (void *)(TEST_FLB_MAGIC_BASE + index); + + if (argp->obj =3D=3D expected_obj) { + pr_info("%s: finish was triggered\n", argp->flb->compatible); + } else { + pr_err("%s: ERROR - finish called with invalid object\n", + argp->flb->compatible); + } +} + +static const struct liveupdate_flb_ops test_flb_ops =3D { + .preserve =3D test_flb_preserve, + .unpreserve =3D test_flb_unpreserve, + .retrieve =3D test_flb_retrieve, + .finish =3D test_flb_finish, + .owner =3D THIS_MODULE, +}; + +static void liveupdate_test_init(void) +{ + static DEFINE_MUTEX(init_lock); + static bool initialized; + int i; + + guard(mutex)(&init_lock); + + if (initialized) + return; + + for (i =3D 0; i < TEST_NFLBS; i++) { + struct liveupdate_flb *flb =3D &test_flbs[i]; + void *obj; + int err; + + err =3D liveupdate_flb_get_incoming(flb, &obj); + if (err && err !=3D -ENODATA && err !=3D -ENOENT) { + pr_err("liveupdate_flb_get_incoming for %s failed: %pe\n", + flb->compatible, ERR_PTR(err)); + } + } + initialized =3D true; +} + +void liveupdate_test_register(struct liveupdate_file_handler *fh) +{ + int err, i; + + liveupdate_test_init(); + + for (i =3D 0; i < TEST_NFLBS; i++) { + struct liveupdate_flb *flb =3D &test_flbs[i]; + + err =3D liveupdate_register_flb(fh, flb); + if (err) { + pr_err("Failed to register %s %pe\n", + flb->compatible, ERR_PTR(err)); + } + } + + err =3D liveupdate_register_flb(fh, &test_flbs[0]); + if (!err || err !=3D -EEXIST) { + pr_err("Failed: %s should be already registered, but got err: %pe\n", + test_flbs[0].compatible, ERR_PTR(err)); + } + + pr_info("Registered %d FLBs with file handler: [%s]\n", + TEST_NFLBS, fh->compatible); +} + +void liveupdate_test_unregister(struct liveupdate_file_handler *fh) +{ + int err, i; + + for (i =3D 0; i < TEST_NFLBS; i++) { + struct liveupdate_flb *flb =3D &test_flbs[i]; + + err =3D liveupdate_unregister_flb(fh, flb); + if (err) { + pr_err("Failed to unregister %s %pe\n", + flb->compatible, ERR_PTR(err)); + } + } + + pr_info("Unregistered %d FLBs from file handler: [%s]\n", + TEST_NFLBS, fh->compatible); +} + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Pasha Tatashin "); +MODULE_DESCRIPTION("In-kernel test for LUO mechanism"); --=20 2.52.0.487.g5c8c507ade-goog