From nobody Tue Feb 10 14:49:43 2026 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (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 B510F35CBDA for ; Thu, 18 Dec 2025 15:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766073486; cv=none; b=GkapkjxXoYc0VVS1kVAikyWDLnYJiUc6fIguBWj7ia8RsXiglTTZ+giLF+AshYXTfNWBACH0t6rxLilJxA3M5zdutMdhiYoI+jVNkoPhUbRh1Ez0fYnrcGZ3yRTDmXNW5wrQFmQqOhcPeOLFPmENUGOKkhiIwU1sP//AXabCl4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766073486; c=relaxed/simple; bh=FMjdBmMGwwhHssNMW8N3x0mp46UX3zaLEfgfZTx3lzU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=obPu6SEUnh6hOVazCdbcMTbCr97wST+eEDvv6ftXpRf1E6eTs1ND0mvw+905AkdW32/FLsuKxyC+PKu6d++b6U5ECsfWGFfpIINqXeoyg1c4wT9rzjurY+taHEPVJhGOA7wgcvYeDs0WVu5uKKpVGh0Sc4qdxcd9EKbSgIX9hDs= 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=hM7hkEe4; arc=none smtp.client-ip=209.85.128.181 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="hM7hkEe4" Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-78ab03c30ceso6183447b3.2 for ; Thu, 18 Dec 2025 07:58:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1766073482; x=1766678282; 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=Y2GvxvWgw+C5A6znHXWAufIHkp3YvrzYE+ZzMWkjVVs=; b=hM7hkEe4ihM7iu1VXXFA425y7KzdfJRbUFpGM9A5qxEfR0yb3058W7T+44M8YBRom/ ew84rRu3b+JQg2Iidyru8mRY/uQBilX3UpHNWkFW6z6615FBI0zIbaQKMpST7LTeUkos jyl00un7XWek948CuOPqcZNP3j3t1cf3YjiHv/rVATgxRziKIksgJcvVbeOT+5WZ1Ffl uLhJxf4ZPYV3Itf6oySriB4ucx5QPH8lP/qrJEWF+ejgky7M9jN0U1LWgTYgz9tFV6eG dYadHHl6PZnQ1Md1wdQq3/zeQBMzE5zusozH1Uo69S8n5v+8di/oE/3IVoew+9TA/Z/z TasA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766073482; x=1766678282; 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=Y2GvxvWgw+C5A6znHXWAufIHkp3YvrzYE+ZzMWkjVVs=; b=NnAdHmYQCXTvm104y0abF36i7rxbJdG40pXwWhNH9e4QPk4+4Hv+Ma/j3vyHK1yiQv +xH9qZnGQYSfaYbz3s20eh4YwLqeJ9bjmaIrQAlqQKy/Ztoa7mqJIL3dhdlgGjB/v5XG NChB+mwgTM/4zpP7Qyjhh01j8b0yJjwJqZAwz6pczEII5UXCMihTgw3yqjeOAt6Wh3j6 YbDwMY6+QgZ42bFwaROSzNT8mmvAYt0BqZXtVDYaOBNY69x8pyPqtVK6YoBAu+YWOwKl JneJmX/4FCidEGi9ZYolIfZMKDmNtnKQWAFOtigi4a+n0saNpDGsh0FI90AIYgx2zZjR oCWA== X-Forwarded-Encrypted: i=1; AJvYcCXBc1QG/l9/6mTEQOwziLatXcldXppctHmqbGoUylaL61DWhvXp4EvsBFYg/XICCxmkqFgy0CCWWzenYFA=@vger.kernel.org X-Gm-Message-State: AOJu0YyK7Wd72sDJW0Pmcc4N64dGIECA9y4qxcps0BB5mYEwSgcOHQKL Vl3ttmWesFsx3upBtZ+ahIL8kQct662bPe/DllDRK9nYR86/O/2Qi4XIA6QwB1I3k9E= X-Gm-Gg: AY/fxX640SrXkfkBr5CJ1UIELdZLqMmZCqkmvfpCRqd770xo5pF9K7Fz+0Z7sJxMobx SwLGSpyrdXeRIbzV/HAgwOQl3fk+8nX3jU2RF+flxt2kc5gh6IWL81eXnSyzjgSbKH+P3EgL1g+ LVQaIONSR3VAvMs/TCju+Ok6gI7knED0NrodEuqMxOyUcxr09zru8ED3uKABNLLXFCVY0J6G51t mFJqaqW/jjd6gygVQiqCusEbL6BlT2it9R/FfS6Gb0RCRB4vN0FDmoGRB3LMpHs2H5fuT3ZXry5 hpWN7wlpPDm2RBSJFW2WHixCfQN4ZzRenc/gukR88eErBwISf/sd+tXIU/RDrDUiymVN6oMbUS0 NEZmyP+JHOr2LQlg6GFknQT1+z+gzoEmwbeW4wxXHw4BUGCoZfl72e1+zgjLrnCPp/L5kazXpVu GpMBB2ePm15LH1v3zcJU3U/tDKLGftHU6ewd+qRD2UtEesYDJ9L/X5wYmxdzz58jgFCvKt57AI8 acspCnVELxhXgoxHUAa8Lvd8mKj7xdQM47jaA== X-Google-Smtp-Source: AGHT+IFmbIoqILeKHhuczXPRMgfqJxIXux1ceJzUQG9pkHU0LZvckHem2z07ZnG7v2PKrT/gLLGB4Q== X-Received: by 2002:a53:c082:0:b0:63f:c487:17ab with SMTP id 956f58d0204a3-64555651309mr19343654d50.47.1766073482595; Thu, 18 Dec 2025 07:58:02 -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-78fa6f52bb2sm9348467b3.16.2025.12.18.07.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Dec 2025 07:58:02 -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, nicolas.frattaroli@collabora.com, linux-doc@vger.kernel.org, tamird@gmail.com, raemoar63@gmail.com, graf@amazon.com Subject: [PATCH v9 5/5] tests/liveupdate: Add in-kernel liveupdate test Date: Thu, 18 Dec 2025 10:57:52 -0500 Message-ID: <20251218155752.3045808-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.313.g674ac2bdf7-goog In-Reply-To: <20251218155752.3045808-1-pasha.tatashin@soleen.com> References: <20251218155752.3045808-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 5b11839cba9d..dac0f87eba5b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14641,6 +14641,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 cade273c50c9..35d2a8b1a0df 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -864,6 +864,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: @@ -895,8 +897,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; @@ -909,5 +913,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 99db13d99530..8083d8739b09 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -107,4 +107,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 0760b24f7cd6..7c94961bf49d 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2819,6 +2819,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 62a7f115f622..439a99c8d32c 100644 --- a/lib/tests/Makefile +++ b/lib/tests/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_LIST_PRIVATE_KUNIT_TEST) +=3D list-private-t= est.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.313.g674ac2bdf7-goog