From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.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 5A3FD25B682 for ; Thu, 15 May 2025 18:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333411; cv=none; b=fiCHe/h5wUqfzCcqvCtpdNb2d0oZPl0mfv7PawPj0CQmNXu4zvWGdOlFWwqksUT99wLqZa1YYdaWBvpYdpiqEBUweKnFm88tlk7uXMpd2kgRunLGU6uHQgWx5OpXjcEwTpQRltYZQOGjzF5yMIjCfoQfDO1iqtgJ5N6FtOn2qow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333411; c=relaxed/simple; bh=ShMOScZ+Sqlf+fpOMRmaC+ihKQQUAlg+2zwLS0ko2/4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UeHoceoDlDHVo9a9BG1OV97/CkkLW2KMWg25Up+G1rITJd9GhjIj92CepiNy6bU3BPhcqswXT7XMsKaJa+Ajo6qAU95ExwN5ckDVLxwGCe5hBEwDRpYLwdDh2/WpkFWnJaqaTR94BFE1iR6vji3MLSvlDchpouNGeJ5yOOK46CI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=2tQtI3Y0; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="2tQtI3Y0" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7c5e1b40f68so144824085a.1 for ; Thu, 15 May 2025 11:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333408; x=1747938208; 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=OA6MgJ6M49mplY2qbuxPQY2uALRjdw04ISOceScmNg8=; b=2tQtI3Y0XAPd11xYLA4zFRndQdAiJkZjpdxj8fopK/FI5qlMZHzxw3U0U24pNUeqWG FA3tCukbpHzK4fnVuWzlx7mozUviitcX7TGuE9lMqulWVjlgt6EHWiaLYGcy2tRYzRdg uK88yjMtEnQ10vTTZbk7v+kca4Us2iUDcwPtQf1FaGFDFRLUys0YCV24Q6Pg/PFP+lFk rHQGYdPERAWTPiL06ZB6+QKLJ79pszMdnL2H6t9tmJkf9fTU7Tsfkf2QvaaXvyH0gZAO eZ4PtbmoDZ12Q3u7ILuTW/MJS62gFE9d/eWmCo6dM3w6uyMfHvYUJrwRwRV78fU9Ll47 OF6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333408; x=1747938208; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OA6MgJ6M49mplY2qbuxPQY2uALRjdw04ISOceScmNg8=; b=XBm6hVxL2tNSDtTU1IsbRQV753XwTsrkTAtSFY4oSkEo/3t/4/hzDxKwr0mK5REU+Q R9T8jTEg1Aje7L9H0RkOP16Y95wPnbcvdVNaw6F1UIlx9Gj61vQXvRze4Sw0HtMVzkS6 14S0LwqKUKT9jOAWboS2krhrIAojMPpVE9os9U4UuSQibAOF2/Q/5lUbBLc6ctFqSez2 Kj6XynGTYiojzCLAl00JRF76CuMo4GW2t3rja7HsSlgHlkxqmTOnkAvJBzDA0dA8X+WU PkP7IV8U66/pFM5b29fD1DnFH1hNQyxj5pqLCfHyqrWLdKFtd5IM2B5VVdekFkvUHIXs BJqw== X-Forwarded-Encrypted: i=1; AJvYcCX+myiBSlLfnav8dc5Zsrm1mCjrNJnpRwfz5xuCW+XmYIFOOB6OLmOTFgAjq6hzI3d7BWdlhyceXqYUW4g=@vger.kernel.org X-Gm-Message-State: AOJu0YxJckvfYLmzgBvlNBP96SgLWXQS0sc2vDPl0GecglF7WcX0U3ap +eiuDGaLjMTyqbeAFCrg+63F6C2qyn9cukwkW7spqwbkPrLEXklz0B/Ma5STavEUO7M= X-Gm-Gg: ASbGncv7k48EhjUxvDwAroEAYLSV3iJmPciYA4HcRcEst5Y/wEiSgGeVtCb60Gl9r1m OOFbactIXGEWB0S1Bj0YmyrDCteDdJ0udXtfs03AiUMyM5421AO7X4Tp2rNtNe+kbCnjMxWL7kN Yh0iydNVDC9LoNHKqiIjIpLBDVD2MOc59aREpyPDObwjU1tcxIKJ9rzT3kayhOyBUWIEkCOyBaC BBIwVnI/w1pTSrsSe/ZKEvqkU3PoIAUZQHqLrITBWidFYzNyaxyj53WWeoD3HnVEV4/5dI+YSEE x5JNNgcJlqOUUxQE3K3ufXBmDWbTIgyba0RYWaLHwYcGauXHkBvplCywKr0RgaDevnySaY3UuIE 1C7JsjR+yx7V6Y0enLzqSDQQ+8QlK1hK9yAnAMlJmT93y7d7k8rBehBc= X-Google-Smtp-Source: AGHT+IFwPiSy57KtfJPs+U7xuV9rBNdEF5m1qAdIOcGOHbCQUN56mz0k2pGRILRAf8vp0yD020I1uw== X-Received: by 2002:a05:620a:2847:b0:7ca:f04b:3fa2 with SMTP id af79cd13be357-7cd4679cf74mr76951285a.38.1747333407852; Thu, 15 May 2025 11:23:27 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:27 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 01/16] kho: make debugfs interface optional Date: Thu, 15 May 2025 18:23:05 +0000 Message-ID: <20250515182322.117840-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" Currently, KHO is controlled via debugfs interface, but once LUO is introduced, it can control KHO, and the debug interface becomes optional. Add a separate config CONFIG_KEXEC_HANDOVER_DEBUG that enables the debugfs interface, and allows to inspect the tree. Move all debufs related code to a new file to keep the .c files clear of ifdefs. Signed-off-by: Pasha Tatashin --- MAINTAINERS | 3 +- kernel/Kconfig.kexec | 10 ++ kernel/Makefile | 1 + kernel/kexec_handover.c | 271 ++----------------------------- kernel/kexec_handover_debug.c | 237 +++++++++++++++++++++++++++ kernel/kexec_handover_internal.h | 72 ++++++++ 6 files changed, 336 insertions(+), 258 deletions(-) create mode 100644 kernel/kexec_handover_debug.c create mode 100644 kernel/kexec_handover_internal.h diff --git a/MAINTAINERS b/MAINTAINERS index bdea634d63a9..4fc28b6674bd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13143,12 +13143,13 @@ KEXEC HANDOVER (KHO) M: Alexander Graf M: Mike Rapoport M: Changyuan Lyu +M: Pasha Tatashin L: kexec@lists.infradead.org S: Maintained F: Documentation/admin-guide/mm/kho.rst F: Documentation/core-api/kho/* F: include/linux/kexec_handover.h -F: kernel/kexec_handover.c +F: kernel/kexec_handover* =20 KEYS-ENCRYPTED M: Mimi Zohar diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec index 4fa212909d69..44f9ac67ecbc 100644 --- a/kernel/Kconfig.kexec +++ b/kernel/Kconfig.kexec @@ -109,6 +109,16 @@ config KEXEC_HANDOVER to keep data or state alive across the kexec. For this to work, both source and target kernels need to have this option enabled. =20 +config KEXEC_HANDOVER_DEBUG + bool "kexec handover debug interface" + depends on KEXEC_HANDOVER + select DEBUG_FS + help + Allow to control kexec handover device tree via debugfs + interface, i.e. finalize the state or aborting the finalization. + Also, enables inspecting the KHO fdt trees with the debugfs binary + blobs. + config CRASH_DUMP bool "kernel crash dumps" default ARCH_DEFAULT_CRASH_DUMP diff --git a/kernel/Makefile b/kernel/Makefile index 97c09847db42..ae44877c0300 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -81,6 +81,7 @@ obj-$(CONFIG_KEXEC) +=3D kexec.o obj-$(CONFIG_KEXEC_FILE) +=3D kexec_file.o obj-$(CONFIG_KEXEC_ELF) +=3D kexec_elf.o obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o +obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o obj-$(CONFIG_BACKTRACE_SELF_TEST) +=3D backtracetest.o obj-$(CONFIG_COMPAT) +=3D compat.o obj-$(CONFIG_CGROUPS) +=3D cgroup/ diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index 69b953551677..5b65970e9746 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -10,7 +10,6 @@ =20 #include #include -#include #include #include #include @@ -27,6 +26,7 @@ */ #include "../mm/internal.h" #include "kexec_internal.h" +#include "kexec_handover_internal.h" =20 #define KHO_FDT_COMPATIBLE "kho-v1" #define PROP_PRESERVED_MEMORY_MAP "preserved-memory-map" @@ -75,22 +75,8 @@ struct kho_mem_phys { struct xarray phys_bits; }; =20 -struct kho_mem_track { - /* Points to kho_mem_phys, each order gets its own bitmap tree */ - struct xarray orders; -}; - struct khoser_mem_chunk; =20 -struct kho_serialization { - struct page *fdt; - struct list_head fdt_list; - struct dentry *sub_fdt_dir; - struct kho_mem_track track; - /* First chunk of serialized preserved memory map */ - struct khoser_mem_chunk *preserved_mem_map; -}; - static void *xa_load_or_alloc(struct xarray *xa, unsigned long index, size= _t sz) { void *elm, *res; @@ -355,8 +341,8 @@ static void __init kho_mem_deserialize(const void *fdt) * area for early allocations that happen before page allocator is * initialized. */ -static struct kho_scratch *kho_scratch; -static unsigned int kho_scratch_cnt; +struct kho_scratch *kho_scratch; +unsigned int kho_scratch_cnt; =20 /* * The scratch areas are scaled by default as percent of memory allocated = from @@ -542,37 +528,6 @@ static void __init kho_reserve_scratch(void) kho_enable =3D false; } =20 -struct fdt_debugfs { - struct list_head list; - struct debugfs_blob_wrapper wrapper; - struct dentry *file; -}; - -static int kho_debugfs_fdt_add(struct list_head *list, struct dentry *dir, - const char *name, const void *fdt) -{ - struct fdt_debugfs *f; - struct dentry *file; - - f =3D kmalloc(sizeof(*f), GFP_KERNEL); - if (!f) - return -ENOMEM; - - f->wrapper.data =3D (void *)fdt; - f->wrapper.size =3D fdt_totalsize(fdt); - - file =3D debugfs_create_blob(name, 0400, dir, &f->wrapper); - if (IS_ERR(file)) { - kfree(f); - return PTR_ERR(file); - } - - f->file =3D file; - list_add(&f->list, list); - - return 0; -} - /** * kho_add_subtree - record the physical address of a sub FDT in KHO root = tree. * @ser: serialization control object passed by KHO notifiers. @@ -584,7 +539,8 @@ static int kho_debugfs_fdt_add(struct list_head *list, = struct dentry *dir, * by KHO for the new kernel to retrieve it after kexec. * * A debugfs blob entry is also created at - * ``/sys/kernel/debug/kho/out/sub_fdts/@name``. + * ``/sys/kernel/debug/kho/out/sub_fdts/@name`` when kernel is configured = with + * CONFIG_KEXEC_HANDOVER_DEBUG * * Return: 0 on success, error code on failure */ @@ -601,22 +557,11 @@ int kho_add_subtree(struct kho_serialization *ser, co= nst char *name, void *fdt) if (err) return err; =20 - return kho_debugfs_fdt_add(&ser->fdt_list, ser->sub_fdt_dir, name, fdt); + return kho_debugfs_fdt_add(ser, name, fdt); } EXPORT_SYMBOL_GPL(kho_add_subtree); =20 -struct kho_out { - struct blocking_notifier_head chain_head; - - struct dentry *dir; - - struct mutex lock; /* protects KHO FDT finalization */ - - struct kho_serialization ser; - bool finalized; -}; - -static struct kho_out kho_out =3D { +struct kho_out kho_out =3D { .chain_head =3D BLOCKING_NOTIFIER_INIT(kho_out.chain_head), .lock =3D __MUTEX_INITIALIZER(kho_out.lock), .ser =3D { @@ -707,30 +652,7 @@ int kho_preserve_phys(phys_addr_t phys, size_t size) } EXPORT_SYMBOL_GPL(kho_preserve_phys); =20 -/* Handling for debug/kho/out */ - -static struct dentry *debugfs_root; - -static int kho_out_update_debugfs_fdt(void) -{ - int err =3D 0; - struct fdt_debugfs *ff, *tmp; - - if (kho_out.finalized) { - err =3D kho_debugfs_fdt_add(&kho_out.ser.fdt_list, kho_out.dir, - "fdt", page_to_virt(kho_out.ser.fdt)); - } else { - list_for_each_entry_safe(ff, tmp, &kho_out.ser.fdt_list, list) { - debugfs_remove(ff->file); - list_del(&ff->list); - kfree(ff); - } - } - - return err; -} - -static int kho_abort(void) +int __kho_abort(void) { int err; unsigned long order; @@ -763,7 +685,7 @@ static int kho_abort(void) return err; } =20 -static int kho_finalize(void) +int __kho_finalize(void) { int err =3D 0; u64 *preserved_mem_map; @@ -806,117 +728,13 @@ static int kho_finalize(void) abort: if (err) { pr_err("Failed to convert KHO state tree: %d\n", err); - kho_abort(); + __kho_abort(); } =20 return err; } =20 -static int kho_out_finalize_get(void *data, u64 *val) -{ - mutex_lock(&kho_out.lock); - *val =3D kho_out.finalized; - mutex_unlock(&kho_out.lock); - - return 0; -} - -static int kho_out_finalize_set(void *data, u64 _val) -{ - int ret =3D 0; - bool val =3D !!_val; - - mutex_lock(&kho_out.lock); - - if (val =3D=3D kho_out.finalized) { - if (kho_out.finalized) - ret =3D -EEXIST; - else - ret =3D -ENOENT; - goto unlock; - } - - if (val) - ret =3D kho_finalize(); - else - ret =3D kho_abort(); - - if (ret) - goto unlock; - - kho_out.finalized =3D val; - ret =3D kho_out_update_debugfs_fdt(); - -unlock: - mutex_unlock(&kho_out.lock); - return ret; -} - -DEFINE_DEBUGFS_ATTRIBUTE(fops_kho_out_finalize, kho_out_finalize_get, - kho_out_finalize_set, "%llu\n"); - -static int scratch_phys_show(struct seq_file *m, void *v) -{ - for (int i =3D 0; i < kho_scratch_cnt; i++) - seq_printf(m, "0x%llx\n", kho_scratch[i].addr); - - return 0; -} -DEFINE_SHOW_ATTRIBUTE(scratch_phys); - -static int scratch_len_show(struct seq_file *m, void *v) -{ - for (int i =3D 0; i < kho_scratch_cnt; i++) - seq_printf(m, "0x%llx\n", kho_scratch[i].size); - - return 0; -} -DEFINE_SHOW_ATTRIBUTE(scratch_len); - -static __init int kho_out_debugfs_init(void) -{ - struct dentry *dir, *f, *sub_fdt_dir; - - dir =3D debugfs_create_dir("out", debugfs_root); - if (IS_ERR(dir)) - return -ENOMEM; - - sub_fdt_dir =3D debugfs_create_dir("sub_fdts", dir); - if (IS_ERR(sub_fdt_dir)) - goto err_rmdir; - - f =3D debugfs_create_file("scratch_phys", 0400, dir, NULL, - &scratch_phys_fops); - if (IS_ERR(f)) - goto err_rmdir; - - f =3D debugfs_create_file("scratch_len", 0400, dir, NULL, - &scratch_len_fops); - if (IS_ERR(f)) - goto err_rmdir; - - f =3D debugfs_create_file("finalize", 0600, dir, NULL, - &fops_kho_out_finalize); - if (IS_ERR(f)) - goto err_rmdir; - - kho_out.dir =3D dir; - kho_out.ser.sub_fdt_dir =3D sub_fdt_dir; - return 0; - -err_rmdir: - debugfs_remove_recursive(dir); - return -ENOENT; -} - -struct kho_in { - struct dentry *dir; - phys_addr_t fdt_phys; - phys_addr_t scratch_phys; - struct list_head fdt_list; -}; - -static struct kho_in kho_in =3D { +struct kho_in kho_in =3D { .fdt_list =3D LIST_HEAD_INIT(kho_in.fdt_list), }; =20 @@ -961,56 +779,6 @@ int kho_retrieve_subtree(const char *name, phys_addr_t= *phys) } EXPORT_SYMBOL_GPL(kho_retrieve_subtree); =20 -/* Handling for debugfs/kho/in */ - -static __init int kho_in_debugfs_init(const void *fdt) -{ - struct dentry *sub_fdt_dir; - int err, child; - - kho_in.dir =3D debugfs_create_dir("in", debugfs_root); - if (IS_ERR(kho_in.dir)) - return PTR_ERR(kho_in.dir); - - sub_fdt_dir =3D debugfs_create_dir("sub_fdts", kho_in.dir); - if (IS_ERR(sub_fdt_dir)) { - err =3D PTR_ERR(sub_fdt_dir); - goto err_rmdir; - } - - err =3D kho_debugfs_fdt_add(&kho_in.fdt_list, kho_in.dir, "fdt", fdt); - if (err) - goto err_rmdir; - - fdt_for_each_subnode(child, fdt, 0) { - int len =3D 0; - const char *name =3D fdt_get_name(fdt, child, NULL); - const u64 *fdt_phys; - - fdt_phys =3D fdt_getprop(fdt, child, "fdt", &len); - if (!fdt_phys) - continue; - if (len !=3D sizeof(*fdt_phys)) { - pr_warn("node `%s`'s prop `fdt` has invalid length: %d\n", - name, len); - continue; - } - err =3D kho_debugfs_fdt_add(&kho_in.fdt_list, sub_fdt_dir, name, - phys_to_virt(*fdt_phys)); - if (err) { - pr_warn("failed to add fdt `%s` to debugfs: %d\n", name, - err); - continue; - } - } - - return 0; - -err_rmdir: - debugfs_remove_recursive(kho_in.dir); - return err; -} - static __init int kho_init(void) { int err =3D 0; @@ -1025,27 +793,16 @@ static __init int kho_init(void) goto err_free_scratch; } =20 - debugfs_root =3D debugfs_create_dir("kho", NULL); - if (IS_ERR(debugfs_root)) { - err =3D -ENOENT; + err =3D kho_debugfs_init(); + if (err) goto err_free_fdt; - } =20 err =3D kho_out_debugfs_init(); if (err) goto err_free_fdt; =20 if (fdt) { - err =3D kho_in_debugfs_init(fdt); - /* - * Failure to create /sys/kernel/debug/kho/in does not prevent - * reviving state from KHO and setting up KHO for the next - * kexec. - */ - if (err) - pr_err("failed exposing handover FDT in debugfs: %d\n", - err); - + kho_in_debugfs_init(fdt); return 0; } =20 diff --git a/kernel/kexec_handover_debug.c b/kernel/kexec_handover_debug.c new file mode 100644 index 000000000000..696131a3480f --- /dev/null +++ b/kernel/kexec_handover_debug.c @@ -0,0 +1,237 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * kexec_handover.c - kexec handover metadata processing + * Copyright (C) 2023 Alexander Graf + * Copyright (C) 2025 Microsoft Corporation, Mike Rapoport + * Copyright (C) 2025 Google LLC, Changyuan Lyu + * Copyright (C) 2025 Google LLC, Pasha Tatashin + */ + +#define pr_fmt(fmt) "KHO: " fmt + +#include +#include +#include +#include +#include "kexec_handover_internal.h" + +static struct dentry *debugfs_root; + +struct fdt_debugfs { + struct list_head list; + struct debugfs_blob_wrapper wrapper; + struct dentry *file; +}; + +static int __kho_debugfs_fdt_add(struct list_head *list, struct dentry *di= r, + const char *name, const void *fdt) +{ + struct fdt_debugfs *f; + struct dentry *file; + + f =3D kmalloc(sizeof(*f), GFP_KERNEL); + if (!f) + return -ENOMEM; + + f->wrapper.data =3D (void *)fdt; + f->wrapper.size =3D fdt_totalsize(fdt); + + file =3D debugfs_create_blob(name, 0400, dir, &f->wrapper); + if (IS_ERR(file)) { + kfree(f); + return PTR_ERR(file); + } + + f->file =3D file; + list_add(&f->list, list); + + return 0; +} + +int kho_debugfs_fdt_add(struct kho_serialization *ser, const char *name, + const void *fdt) +{ + return __kho_debugfs_fdt_add(&ser->fdt_list, ser->sub_fdt_dir, name, + fdt); +} + +static int kho_out_update_debugfs_fdt(void) +{ + int err =3D 0; + struct fdt_debugfs *ff, *tmp; + + if (kho_out.finalized) { + err =3D __kho_debugfs_fdt_add(&kho_out.ser.fdt_list, kho_out.dir, + "fdt", + page_to_virt(kho_out.ser.fdt)); + } else { + list_for_each_entry_safe(ff, tmp, &kho_out.ser.fdt_list, list) { + debugfs_remove(ff->file); + list_del(&ff->list); + kfree(ff); + } + } + + return err; +} + +static int kho_out_finalize_get(void *data, u64 *val) +{ + mutex_lock(&kho_out.lock); + *val =3D kho_out.finalized; + mutex_unlock(&kho_out.lock); + + return 0; +} + +static int kho_out_finalize_set(void *data, u64 _val) +{ + int ret =3D 0; + bool val =3D !!_val; + + mutex_lock(&kho_out.lock); + + if (val =3D=3D kho_out.finalized) { + if (kho_out.finalized) + ret =3D -EEXIST; + else + ret =3D -ENOENT; + goto unlock; + } + + if (val) + ret =3D __kho_finalize(); + else + ret =3D __kho_abort(); + + if (ret) + goto unlock; + + kho_out.finalized =3D val; + ret =3D kho_out_update_debugfs_fdt(); + +unlock: + mutex_unlock(&kho_out.lock); + return ret; +} + +DEFINE_DEBUGFS_ATTRIBUTE(fops_kho_out_finalize, kho_out_finalize_get, + kho_out_finalize_set, "%llu\n"); + +static int scratch_phys_show(struct seq_file *m, void *v) +{ + for (int i =3D 0; i < kho_scratch_cnt; i++) + seq_printf(m, "0x%llx\n", kho_scratch[i].addr); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(scratch_phys); + +static int scratch_len_show(struct seq_file *m, void *v) +{ + for (int i =3D 0; i < kho_scratch_cnt; i++) + seq_printf(m, "0x%llx\n", kho_scratch[i].size); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(scratch_len); + +__init void kho_in_debugfs_init(const void *fdt) +{ + struct dentry *sub_fdt_dir; + int err, child; + + kho_in.dir =3D debugfs_create_dir("in", debugfs_root); + if (IS_ERR(kho_in.dir)) { + err =3D PTR_ERR(kho_in.dir); + goto err_out; + } + + sub_fdt_dir =3D debugfs_create_dir("sub_fdts", kho_in.dir); + if (IS_ERR(sub_fdt_dir)) { + err =3D PTR_ERR(sub_fdt_dir); + goto err_rmdir; + } + + err =3D __kho_debugfs_fdt_add(&kho_in.fdt_list, kho_in.dir, "fdt", fdt); + if (err) + goto err_rmdir; + + fdt_for_each_subnode(child, fdt, 0) { + int len =3D 0; + const char *name =3D fdt_get_name(fdt, child, NULL); + const u64 *fdt_phys; + + fdt_phys =3D fdt_getprop(fdt, child, "fdt", &len); + if (!fdt_phys) + continue; + if (len !=3D sizeof(*fdt_phys)) { + pr_warn("node `%s`'s prop `fdt` has invalid length: %d\n", + name, len); + continue; + } + err =3D __kho_debugfs_fdt_add(&kho_in.fdt_list, sub_fdt_dir, name, + phys_to_virt(*fdt_phys)); + if (err) { + pr_warn("failed to add fdt `%s` to debugfs: %d\n", name, + err); + continue; + } + } + + return; +err_rmdir: + debugfs_remove_recursive(kho_in.dir); +err_out: + /* + * Failure to create /sys/kernel/debug/kho/in does not prevent + * reviving state from KHO and setting up KHO for the next + * kexec. + */ + if (err) + pr_err("failed exposing handover FDT in debugfs: %d\n", err); +} + +__init int kho_out_debugfs_init(void) +{ + struct dentry *dir, *f, *sub_fdt_dir; + + dir =3D debugfs_create_dir("out", debugfs_root); + if (IS_ERR(dir)) + return -ENOMEM; + + sub_fdt_dir =3D debugfs_create_dir("sub_fdts", dir); + if (IS_ERR(sub_fdt_dir)) + goto err_rmdir; + + f =3D debugfs_create_file("scratch_phys", 0400, dir, NULL, + &scratch_phys_fops); + if (IS_ERR(f)) + goto err_rmdir; + + f =3D debugfs_create_file("scratch_len", 0400, dir, NULL, + &scratch_len_fops); + if (IS_ERR(f)) + goto err_rmdir; + + f =3D debugfs_create_file("finalize", 0600, dir, NULL, + &fops_kho_out_finalize); + if (IS_ERR(f)) + goto err_rmdir; + + kho_out.dir =3D dir; + kho_out.ser.sub_fdt_dir =3D sub_fdt_dir; + return 0; + +err_rmdir: + debugfs_remove_recursive(dir); + return -ENOENT; +} + +__init int kho_debugfs_init(void) +{ + debugfs_root =3D debugfs_create_dir("kho", NULL); + if (IS_ERR(debugfs_root)) + return -ENOENT; + return 0; +} diff --git a/kernel/kexec_handover_internal.h b/kernel/kexec_handover_inter= nal.h new file mode 100644 index 000000000000..65ff0f651192 --- /dev/null +++ b/kernel/kexec_handover_internal.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef LINUX_KEXEC_HANDOVER_INTERNAL_H +#define LINUX_KEXEC_HANDOVER_INTERNAL_H + +#include +#include +#include + +#ifdef CONFIG_KEXEC_HANDOVER_DEBUG +#include +#endif + +struct kho_mem_track { + /* Points to kho_mem_phys, each order gets its own bitmap tree */ + struct xarray orders; +}; + +struct kho_serialization { + struct page *fdt; + struct list_head fdt_list; + struct kho_mem_track track; + /* First chunk of serialized preserved memory map */ + struct khoser_mem_chunk *preserved_mem_map; +#ifdef CONFIG_KEXEC_HANDOVER_DEBUG + struct dentry *sub_fdt_dir; +#endif +}; + +struct kho_in { + phys_addr_t fdt_phys; + phys_addr_t scratch_phys; + struct list_head fdt_list; +#ifdef CONFIG_KEXEC_HANDOVER_DEBUG + struct dentry *dir; +#endif +}; + +struct kho_out { + struct blocking_notifier_head chain_head; + struct mutex lock; /* protects KHO FDT finalization */ + struct kho_serialization ser; + bool finalized; +#ifdef CONFIG_KEXEC_HANDOVER_DEBUG + struct dentry *dir; +#endif +}; + +extern struct kho_in kho_in; +extern struct kho_out kho_out; + +extern struct kho_scratch *kho_scratch; +extern unsigned int kho_scratch_cnt; + +int __kho_finalize(void); +int __kho_abort(void); + +#ifdef CONFIG_KEXEC_HANDOVER_DEBUG +int kho_debugfs_init(void); +void kho_in_debugfs_init(const void *fdt); +int kho_out_debugfs_init(void); +int kho_debugfs_fdt_add(struct kho_serialization *ser, const char *name, + const void *fdt); +#else +static inline int kho_debugfs_init(void) { return 0; } +static inline void kho_in_debugfs_init(const void *fdt) { } +static inline int kho_out_debugfs_init(void) { return 0; } +static inline int kho_debugfs_fdt_add(struct kho_serialization *ser, + const char *name, + const void *fdt) { return 0; } +#endif /* CONFIG_KEXEC_HANDOVER_DEBUG */ + +#endif /* LINUX_KEXEC_HANDOVER_INTERNAL_H */ --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (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 B287B25D20D for ; Thu, 15 May 2025 18:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333412; cv=none; b=suRq5AnuxmKyNPUhgCGoecJFeCH2QYPl7esYkTpwzcnFNvRhOb4v2HDeBL4OnYdGA+XyL4sHn4UpMlV7LWUY0Ps00iNvYef2LFAyS1Mbf2deLVFxzekVTa3OZxqDSuHQmLIkQA9HKwKrgDI92gbR/Lpkbb4pSXSTMeD0yD8I3/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333412; c=relaxed/simple; bh=1rYzlB4jt+NgzrmG5MLloEzusBe5IEirmGPBVFDNYcI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M3evkC27OsBDi7Cr9T0fDLiNOdL7exGvMKzce6dYQ2dmCA8OKHpmesLeBVd4pcZUfOMnqgV8LPIstQFCtWM2xgnwBAmC/1z7GynnKiMAzhf+Vs739dlpvM23uWitYaVOj5S3TffHGmB+m8qCreXxlz8vu3mgcE4d3FjYpGsyWp0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=u9AQ1qIa; arc=none smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="u9AQ1qIa" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-476f4e9cf92so10049241cf.3 for ; Thu, 15 May 2025 11:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333409; x=1747938209; 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=/1cQld6s+fHhsQGRDIn5qKXAP1aMOMnCGujzp2H2Sb8=; b=u9AQ1qIapwgr8HRYKUxb2EmTswFXhzvguFJGm3MZfOmRXRFWYIEU0KMHJcvMGj4S8j Ixj9TQjQfElegZuG1vbLDlA/T5cVuJzs8ajiibWPo/RDiLN+D6JD8s7l1azqXwKOyeGR 29ZiCWHCGzLyUOh5V0+WmMWXTCE7A0PBcGibfHS2hN3pn1cFrMqNV11UmjDQMjRGZr1c Kp3d3JdAe038R3M9QsGqeMganAGGN5POuPGJNHmT66nxA3Tx5tMIPlK47T50M+IXdRWN iQZCamTKWedAyBVHcmR5+5a+uhuhkAsgQodpaJH5hPXigx+FoimPa4rTZ1l3GWiczZpU iNgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333409; x=1747938209; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/1cQld6s+fHhsQGRDIn5qKXAP1aMOMnCGujzp2H2Sb8=; b=QRHDKQYoBx4dLk+UOfssFcW8EThmuaCMff/YycsizLIpbo0QaBTdNeiH2ziU5ZFVOZ SOvyRsytoqVSzKaYkIsylvvYzJJclZuH8zFhGXql0bZxiAMw4t9i8VzqULvXSCL+jw7L vA+bcelE5q33fd0dcLUn//qYz0Q7X7BCuzk8CXPddKfoXomvyrCqQlxn3oOy5x4Y/E+x 8hJ+js0QvKfzgpY5ZTKxsJkWnalqNhzTcS782X3Lf+ymP8xojc+dQLMog8ZrEijjFs7d 56m5qL2ZWqxYe2vBYkygEq9RXBGa08qaddoo0eHxZsB9sAoDeUZvVpOMC8I1TyOlM4NL Pxnw== X-Forwarded-Encrypted: i=1; AJvYcCU3f72Dx6fEjoLiiZgW0TQPBX2pvbvb76j21FUY2ielRhtm4Lyenh6U9G77faN513Sf96fKV68HgX/fl8w=@vger.kernel.org X-Gm-Message-State: AOJu0YyT0ftAX61uFh9exi4DhQqZYF/mNf3u0HKijvtCynoIDrDuxsvl CD9cVcBS3a01VXIsh8KYIPWAfRpGyUJxjLz8XXYZXklwoE+N9Gpy+/wLkl8n2tyjTY0= X-Gm-Gg: ASbGncsXkVLA35r9Izs1HN22pqnfRHDsYTSn+Mgy2/J6VMddQq8KzJ8llYcVgCR/mL9 vDAbhPwhXNCtj6U4/82CcmUhNKFeY98BQRVtEwiwkQgQqd5ksXc0gNuBQ8hK3u8uDb3nqPXB+Ay v/fp7MyO7jAkJmPxUa10D5k9YT5PjrAnt/0nM3VL8sNV1MHgzSyv5BseVrcVRszeVrt9WHtrKAH qKxdvCpIJX3uftHPw8sHcEKTyc7cVAble0xgR1cad+lFT1AWwqfJ0v/tOwsswxh+r2lLGLjlZfY DMFeUSdMKoWE1yp4ygQcMn73I51adfhdAwR6aq21lG4MHIk7rjmHUfSJyfINHwVqm5v8e038SV/ AzyXmG/u7cKk8NR3E+l9zb4AJbR3cvnrp80Hzsofg/rwQ X-Google-Smtp-Source: AGHT+IHMdR7jltadwLx3md1mkyCXtwpjmFH9FzZ/ZTOjwdYm/5D6IYoCeXD8qKkrvwmgbOc0uZ2I7w== X-Received: by 2002:a05:622a:4ccc:b0:491:18c2:2d1 with SMTP id d75a77b69052e-494ae34b351mr5878641cf.7.1747333409292; Thu, 15 May 2025 11:23:29 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:28 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 02/16] kho: allow to drive kho from within kernel Date: Thu, 15 May 2025 18:23:06 +0000 Message-ID: <20250515182322.117840-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" Allow to do finalize and abort from kernel modules, so LUO could drive the KHO sequence via its own state machine. Signed-off-by: Pasha Tatashin --- include/linux/kexec_handover.h | 15 +++++++++ kernel/kexec_handover.c | 54 ++++++++++++++++++++++++++++++++ kernel/kexec_handover_debug.c | 2 +- kernel/kexec_handover_internal.h | 2 ++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 348844cffb13..f98565def593 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -54,6 +54,10 @@ void kho_memory_init(void); =20 void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_p= hys, u64 scratch_len); + +int kho_finalize(void); +int kho_abort(void); + #else static inline bool kho_is_enabled(void) { @@ -104,6 +108,17 @@ static inline void kho_populate(phys_addr_t fdt_phys, = u64 fdt_len, phys_addr_t scratch_phys, u64 scratch_len) { } + +static inline int kho_finalize(void) +{ + return -EOPNOTSUPP; +} + +static inline int kho_abort(void) +{ + return -EOPNOTSUPP; +} + #endif /* CONFIG_KEXEC_HANDOVER */ =20 #endif /* LINUX_KEXEC_HANDOVER_H */ diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index 5b65970e9746..8ff561e36a87 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -734,6 +734,60 @@ int __kho_finalize(void) return err; } =20 +int kho_finalize(void) +{ + int ret =3D 0; + + if (!kho_enable) + return -EOPNOTSUPP; + + mutex_lock(&kho_out.lock); + + if (kho_out.finalized) { + ret =3D -EEXIST; + goto unlock; + } + + ret =3D __kho_finalize(); + if (ret) + goto unlock; + + kho_out.finalized =3D true; + ret =3D kho_out_update_debugfs_fdt(); + +unlock: + mutex_unlock(&kho_out.lock); + return ret; +} +EXPORT_SYMBOL_GPL(kho_finalize); + +int kho_abort(void) +{ + int ret =3D 0; + + if (!kho_enable) + return -EOPNOTSUPP; + + mutex_lock(&kho_out.lock); + + if (!kho_out.finalized) { + ret =3D -ENOENT; + goto unlock; + } + + ret =3D __kho_abort(); + if (ret) + goto unlock; + + kho_out.finalized =3D false; + ret =3D kho_out_update_debugfs_fdt(); + +unlock: + mutex_unlock(&kho_out.lock); + return ret; +} +EXPORT_SYMBOL_GPL(kho_abort); + struct kho_in kho_in =3D { .fdt_list =3D LIST_HEAD_INIT(kho_in.fdt_list), }; diff --git a/kernel/kexec_handover_debug.c b/kernel/kexec_handover_debug.c index 696131a3480f..a15c238ec98e 100644 --- a/kernel/kexec_handover_debug.c +++ b/kernel/kexec_handover_debug.c @@ -55,7 +55,7 @@ int kho_debugfs_fdt_add(struct kho_serialization *ser, co= nst char *name, fdt); } =20 -static int kho_out_update_debugfs_fdt(void) +int kho_out_update_debugfs_fdt(void) { int err =3D 0; struct fdt_debugfs *ff, *tmp; diff --git a/kernel/kexec_handover_internal.h b/kernel/kexec_handover_inter= nal.h index 65ff0f651192..0b534758d39d 100644 --- a/kernel/kexec_handover_internal.h +++ b/kernel/kexec_handover_internal.h @@ -60,6 +60,7 @@ void kho_in_debugfs_init(const void *fdt); int kho_out_debugfs_init(void); int kho_debugfs_fdt_add(struct kho_serialization *ser, const char *name, const void *fdt); +int kho_out_update_debugfs_fdt(void); #else static inline int kho_debugfs_init(void) { return 0; } static inline void kho_in_debugfs_init(const void *fdt) { } @@ -67,6 +68,7 @@ static inline int kho_out_debugfs_init(void) { return 0; } static inline int kho_debugfs_fdt_add(struct kho_serialization *ser, const char *name, const void *fdt) { return 0; } +static inline int kho_out_update_debugfs_fdt(void) { return 0; } #endif /* CONFIG_KEXEC_HANDOVER_DEBUG */ =20 #endif /* LINUX_KEXEC_HANDOVER_INTERNAL_H */ --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.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 0385625D91D for ; Thu, 15 May 2025 18:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333413; cv=none; b=XwgVz+B+mtChJUwfTBYpTXzOM659ehzFSGFIktj8klmCmQl6wG0bPx4GPeDSATzKauWzrbul91GAL2kJZXEk3Ynzme6DyRxsfJLu3aqRbykg1nTA9PB5WWj1e04rCniMK+Myn4cbrzvPasKmzFAbad41jJKTnWP34UP7Nyc2bJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333413; c=relaxed/simple; bh=34PU7KMU+N2wXJE1/J7frHbhOQwrIo8aVZDlebHSbbY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hKUwIqB1MOaZWbyJSF8fBlOTSMPVlnBc11INYAXdXgjRL+FNb+meDwp4uEUHb2XGgiX6cm+q6dKKM1k9xpoPY6xjp2X4ZXjDs9ON86QSkiLHnFTdslZqGrzIyoQfSurdW46YnSYni6o6BHTpju7FzJIHkm/W2lwsADHro8j5f3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=iD4iya/d; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="iD4iya/d" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-4775ccf3e56so27930131cf.0 for ; Thu, 15 May 2025 11:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333411; x=1747938211; 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=FLBg4PWpdjUgYuKX869tnqzLKlnuTQmJAhNrRi7i9EE=; b=iD4iya/d8DW52JB58NspQjkEx3yY1vOyuqnOseOy4BE8MkdMNShW3j2FOyqlD+TeV0 Suf+St61GwxZuh1Zw0w/wZtXdd54dsHda3RRJDWHyuAGsNogC5tAnmchFHLmpF9x8KSs yTbgrpyBrSyiZfKR3dh2I0ldG6jyMBEchGSVxgzaUij2lb8zgP/3/RSj4HAscb4u/t0j NSY9lc6KoRjJn4f6jHN1bP4LWEUmJzL31kcie8HwuG8suBWLGei+c//KE5+SHu6e1k8H bAt9wUfbyVFvoU30uLTwMRto6TXTn/SqTTqkODkUuEFfMuGPSQauLqPKT4YgRoAc1HcS 7M3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333411; x=1747938211; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FLBg4PWpdjUgYuKX869tnqzLKlnuTQmJAhNrRi7i9EE=; b=ZkqQfvhD+qrrJdWoR2oTIEgyUF/Q6/mvt/QOzl8wj9Lrnd4ZoKliz5ImxYmtfpgtiX Q05vFJucErn8QLIzlHRHdga2WcQKkrcpcEgDz7GFYMOwsidtbyupmAbVTkEQLB7cjUA9 clo8rGaASolkNfE+oVDGD85cgTBBct16dqYxXK3ZyECIJB1dZq7+FT3dVKQrJIKB3zjv qshnD2a/aX5VK/LUZzuhvEhfP0RJEadg7cqmFNEwu/EFqza2zD/b+xvsoWOGGH5hsZP/ veMMXy5rGqSRp8Cu3upRbq09mqB+Smg9L9wkoDAM2Mz39TLN+t/rq6KjzrkJvGHvBP5E 3JxQ== X-Forwarded-Encrypted: i=1; AJvYcCXqDkATJWJzTq3L+JdcAK2RIVRq43kugGAJwWwGEJdMxfr5EXrV252lx/yR5tSBArfRBFPcKal5h9TCdOY=@vger.kernel.org X-Gm-Message-State: AOJu0YyU0ju968/sQUjL8BWODmaVGoAQjdxUN+IjKSej9O1tnkFD17tC cOB9yduHqCovyhLPMqaItR9Au/X3oNIdsf+kXPu/KknT35Ti+wdgw3XTYEUeo2rzjPw= X-Gm-Gg: ASbGncvl6CXj9SXXDvwrTqodmfwfUiUl9B3jxTylsMn9S1TfPKv69ao0xr8H8w2oCzp j+JtuMM299T+V3ieK6NnMu3UFbylM5mQ1U0NJKCBHdgR5/1escav8kpcZtrWvTRwVGxlKNgROug rAJW4Y5c4JtA/InhRq7M/+F7YPAqiVaqEA59Gjw6+ZSRemfVW/WWBFwavUR8n6g9lsuaymQvUwS sI+5Rsi4YTEUS0GEAcbMCdVs+nrnkKtxG9khGuL0UEVKpa3+OJ9GA6+9bEUxEojllWdokyK2B2j eh1aDtgrLCO2UBato7ZWj6MWaxHvwZtTQOud16MFq7G9wJc/LaX9yx97RwgFJR8yGBbz+toxwYK AFdswfgizodQtSx05Oq//9RQd5r702Ni1SK/btl1Xx8Bf X-Google-Smtp-Source: AGHT+IHdVpoXFzO5vpvPCK/fe5GtMM9oE80sh2/xmjSmGwo/5647bcIutgv4NbFJWhbe73WlciRiuA== X-Received: by 2002:a05:622a:1999:b0:48d:4887:9850 with SMTP id d75a77b69052e-494a0e2b131mr70141661cf.19.1747333410606; Thu, 15 May 2025 11:23:30 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:30 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 03/16] kho: add kho_unpreserve_folio/phys Date: Thu, 15 May 2025 18:23:07 +0000 Message-ID: <20250515182322.117840-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" From: Changyuan Lyu Allow users of KHO to cancel the previous preservation by adding the necessary interfaces to unpreserve folio. Signed-off-by: Changyuan Lyu Co-developed-by: Pasha Tatashin Signed-off-by: Pasha Tatashin --- include/linux/kexec_handover.h | 12 +++++ kernel/kexec_handover.c | 84 ++++++++++++++++++++++++++++------ 2 files changed, 83 insertions(+), 13 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index f98565def593..3d209f9e9d3a 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -42,7 +42,9 @@ struct kho_serialization; bool kho_is_enabled(void); =20 int kho_preserve_folio(struct folio *folio); +int kho_unpreserve_folio(struct folio *folio); int kho_preserve_phys(phys_addr_t phys, size_t size); +int kho_unpreserve_phys(phys_addr_t phys, size_t size); struct folio *kho_restore_folio(phys_addr_t phys); int kho_add_subtree(struct kho_serialization *ser, const char *name, void = *fdt); int kho_retrieve_subtree(const char *name, phys_addr_t *phys); @@ -69,11 +71,21 @@ static inline int kho_preserve_folio(struct folio *foli= o) return -EOPNOTSUPP; } =20 +static inline int kho_unpreserve_folio(struct folio *folio) +{ + return -EOPNOTSUPP; +} + static inline int kho_preserve_phys(phys_addr_t phys, size_t size) { return -EOPNOTSUPP; } =20 +static inline int kho_unpreserve_phys(phys_addr_t phys, size_t size) +{ + return -EOPNOTSUPP; +} + static inline struct folio *kho_restore_folio(phys_addr_t phys) { return NULL; diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index 8ff561e36a87..eb305e7e6129 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -101,26 +101,33 @@ static void *xa_load_or_alloc(struct xarray *xa, unsi= gned long index, size_t sz) return elm; } =20 -static void __kho_unpreserve(struct kho_mem_track *track, unsigned long pf= n, - unsigned long end_pfn) +static void __kho_unpreserve_order(struct kho_mem_track *track, unsigned l= ong pfn, + unsigned int order) { struct kho_mem_phys_bits *bits; struct kho_mem_phys *physxa; + const unsigned long pfn_high =3D pfn >> order; =20 - while (pfn < end_pfn) { - const unsigned int order =3D - min(count_trailing_zeros(pfn), ilog2(end_pfn - pfn)); - const unsigned long pfn_high =3D pfn >> order; + physxa =3D xa_load(&track->orders, order); + if (!physxa) + return; =20 - physxa =3D xa_load(&track->orders, order); - if (!physxa) - continue; + bits =3D xa_load(&physxa->phys_bits, pfn_high / PRESERVE_BITS); + if (!bits) + return; =20 - bits =3D xa_load(&physxa->phys_bits, pfn_high / PRESERVE_BITS); - if (!bits) - continue; + clear_bit(pfn_high % PRESERVE_BITS, bits->preserve); +} =20 - clear_bit(pfn_high % PRESERVE_BITS, bits->preserve); +static void __kho_unpreserve(struct kho_mem_track *track, unsigned long pf= n, + unsigned long end_pfn) +{ + unsigned int order; + + while (pfn < end_pfn) { + order =3D min(count_trailing_zeros(pfn), ilog2(end_pfn - pfn)); + + __kho_unpreserve_order(track, pfn, order); =20 pfn +=3D 1 << order; } @@ -607,6 +614,29 @@ int kho_preserve_folio(struct folio *folio) } EXPORT_SYMBOL_GPL(kho_preserve_folio); =20 +/** + * kho_unpreserve_folio - unpreserve a folio. + * @folio: folio to unpreserve. + * + * Instructs KHO to unpreserve a folio that was preserved by + * kho_preserve_folio() before. + * + * Return: 0 on success, error code on failure + */ +int kho_unpreserve_folio(struct folio *folio) +{ + const unsigned long pfn =3D folio_pfn(folio); + const unsigned int order =3D folio_order(folio); + struct kho_mem_track *track =3D &kho_out.ser.track; + + if (kho_out.finalized) + return -EBUSY; + + __kho_unpreserve_order(track, pfn, order); + return 0; +} +EXPORT_SYMBOL_GPL(kho_unpreserve_folio); + /** * kho_preserve_phys - preserve a physically contiguous range across kexec. * @phys: physical address of the range. @@ -652,6 +682,34 @@ int kho_preserve_phys(phys_addr_t phys, size_t size) } EXPORT_SYMBOL_GPL(kho_preserve_phys); =20 +/** + * kho_unpreserve_phys - unpreserve a physically contiguous range across k= exec. + * @phys: physical address of the range. + * @size: size of the range. + * + * Instructs KHO to unpreserve the memory range from @phys to @phys + @size + * across kexec. + * + * Return: 0 on success, error code on failure + */ +int kho_unpreserve_phys(phys_addr_t phys, size_t size) +{ + struct kho_mem_track *track =3D &kho_out.ser.track; + unsigned long pfn =3D PHYS_PFN(phys); + unsigned long end_pfn =3D PHYS_PFN(phys + size); + + if (kho_out.finalized) + return -EBUSY; + + if (!PAGE_ALIGNED(phys) || !PAGE_ALIGNED(size)) + return -EINVAL; + + __kho_unpreserve(track, pfn, end_pfn); + + return 0; +} +EXPORT_SYMBOL_GPL(kho_unpreserve_phys); + int __kho_abort(void) { int err; --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 B947525D90C for ; Thu, 15 May 2025 18:23:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333416; cv=none; b=qv6v0yFZ2cw1QMZsDEMoPtA4pUhaF9aFL0KGqFe8EVYLO2hJNHD/EyZU11bR3RhGQ9S5C0/YxbmzmtATUb9B5uqC5S9nFM4JnTACwhF5MI2dHHbu946F4Cze9lzC0OaIUvR9UukH2zW2XXcKuV2u6ZV3Q0ipvLf/xk7P7IhxR3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333416; c=relaxed/simple; bh=/0h1DAgvNS7gOWJbGR62D2WLgSr3BUoj0MaCWYY3rNk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JAHgooJjZVae5DPgrS226sHlexdN3+Gpsl3HzlndklO2XlkbefXcHONPQt7pzUZL8R/HNP2MzU72sJlAb2+p4XJgGI71iPvi1nGxybZ9eIoonDr+7TZXdJ3tXT2nXYYYxFG02N0pxLUd9i99o4ds/+b8yatlawDIKLLo43+qksI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=DAVBCold; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="DAVBCold" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7c5b2472969so126951085a.1 for ; Thu, 15 May 2025 11:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333412; x=1747938212; 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=oGF8/MZyPeKti2q6s3S+pfY6W5r5tibJELV0vgQCiJw=; b=DAVBColdbe2W+tHR30dMjhw7RqwpzAtrjbuR4KnJaaaTBWzrjX302x+O09d72iavfj qamSCRrjgzHDYBjcIhh6SAJJMzVid3J0Yyw85kEyFHRm9u5V/n0OtafvoqfR8vlEEOr2 7cvFmtDn7sC/GYmoQxxYBLT21qSZEyb/KHyzYZVFiNy5fhvALRrplXs8jywOyaluwdhy fiUqwMp9u/+ljdrbkLmqVEPRf7fvCt5KJXql42YJwbrQgqsFjtf3kBN5KyNYbdOP0wwa 9ssjF5CYG14Wt/63FIT7xElRM8UaKXWLRD/gX1GbOwdU6jMBrF3NPgH01RkmG3ulsqS8 IKtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333412; x=1747938212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oGF8/MZyPeKti2q6s3S+pfY6W5r5tibJELV0vgQCiJw=; b=espqSToWvuJMgU6wvFcTc6JTrpGNu/d7hIoPrzS4XLN8Itc2DXM8XHCyMDyQmIub9d 0tkzaAocRel+a9F9nft6FSZvFykz/Ixdpym4DNn57zJ2E7JuwFkzBNpe5UqRrp3TmohK 0jsaTQbsbScftkS0J3wBIb70WIbtpWyrtjIy9FMrME+I92IV/xZa6vFAKa+jS5LhUzKv ns+njnIop8nmtvDdgwIvGUMb+AZU9aZT6UDV/ZeUcJUv3VgoSqhlZo3qUc6bSW+eDZWt Z/FMztNmRIk0hIiGr5YW/zv8tU/+nvy+bdu6wE580giJ2k2BXlwEPs+RAAAGgUCnjS0v ZFIA== X-Forwarded-Encrypted: i=1; AJvYcCUN7oCVLuMUqFVupqYRQZfglFUCgphWYi/iG3h33OUs/1Jn9P1cdrKT0JQlct7vR4Eqk90+KOHhudBgQ8I=@vger.kernel.org X-Gm-Message-State: AOJu0YyOFbMfK6ez0HUZn6AXMvZ9XQd9eoaO/Zd389NJE2NY6xeX2C0Z HePXVJHjfkDbMX6AcIgMrsrXTFe4FaV1iLUSFKdWh/S7w2ccQZxISVrREIS6j6/F6q4= X-Gm-Gg: ASbGnctbqcE9Cg5B4aREAauq86DELA0fpvTcJ2uuxltE1HhFc+WtIDTzMwjDE2pixoU uepHzWjaQJix3MdDfgHQYiztkj2QUe4I/zF0sbkYyojlMXY+Z1Xr490kGWhPz51kJpuYJqJBsHt Xwcsv4jI3jZvItVoiyoyTeB44M0zoUows4e3bwgUSt7pBK9Fuv1FS+LvfCj1M3nV7/Ee69LGIfK DYfIb7kr9PDX/+43nnDukquYy3BRs8zGcH3OfJf/bhtknM3DpCANKkGxn6g2Bm1cOSIy7irSruq bghlXjDS5su2R+d4klxxcrXnpemwqQVQHep6EOe8IjqVNmE9jDMJPhRqt7eeH4/xu00OLx/GQK6 X9OjZSa3d6oEQyon8ta7oyBAGafXzc3vsv3FLbpL9K9gQ X-Google-Smtp-Source: AGHT+IGJZWVHZL0uOCsIdspadw7iSpqNWmFKAA4D6+zc22RZ4SvW71jxKclCUhsuNFBb4cm0e/GNGA== X-Received: by 2002:a05:620a:4114:b0:7c8:c9c:2a8a with SMTP id af79cd13be357-7cd467aa193mr75698585a.49.1747333412061; Thu, 15 May 2025 11:23:32 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:31 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 04/16] luo: luo_core: Live Update Orchestrator Date: Thu, 15 May 2025 18:23:08 +0000 Message-ID: <20250515182322.117840-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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 LUO, a mechanism intended to facilitate kernel updates while keeping designated devices operational across the transition (e.g., via kexec). The primary use case is updating hypervisors with minimal disruption to running virtual machines. For userspace side of hypervisor update we have copyless migration. LUO is for updating the kernel. This initial patch lays the groundwork for the LUO subsystem. Further functionality, including the implementation of state transition logic, integration with KHO, and hooks for subsystems and file descriptors, will be added in subsequent patches. Signed-off-by: Pasha Tatashin --- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/liveupdate/Kconfig | 27 +++ drivers/misc/liveupdate/Makefile | 2 + drivers/misc/liveupdate/luo_core.c | 296 +++++++++++++++++++++++++ drivers/misc/liveupdate/luo_internal.h | 26 +++ include/linux/liveupdate.h | 131 +++++++++++ 7 files changed, 484 insertions(+) create mode 100644 drivers/misc/liveupdate/Kconfig create mode 100644 drivers/misc/liveupdate/Makefile create mode 100644 drivers/misc/liveupdate/luo_core.c create mode 100644 drivers/misc/liveupdate/luo_internal.h create mode 100644 include/linux/liveupdate.h diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 6b37d61150ee..851fd9c33b36 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -636,6 +636,7 @@ source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" source "drivers/misc/lis3lv02d/Kconfig" +source "drivers/misc/liveupdate/Kconfig" source "drivers/misc/altera-stapl/Kconfig" source "drivers/misc/mei/Kconfig" source "drivers/misc/vmw_vmci/Kconfig" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index d6c917229c45..ed5b5bc71b85 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -41,6 +41,7 @@ obj-y +=3D eeprom/ obj-y +=3D cb710/ obj-$(CONFIG_VMWARE_BALLOON) +=3D vmw_balloon.o obj-$(CONFIG_PCH_PHUB) +=3D pch_phub.o +obj-$(CONFIG_LIVEUPDATE) +=3D liveupdate/ obj-y +=3D lis3lv02d/ obj-$(CONFIG_ALTERA_STAPL) +=3Daltera-stapl/ obj-$(CONFIG_INTEL_MEI) +=3D mei/ diff --git a/drivers/misc/liveupdate/Kconfig b/drivers/misc/liveupdate/Kcon= fig new file mode 100644 index 000000000000..a7424ceeba0b --- /dev/null +++ b/drivers/misc/liveupdate/Kconfig @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (c) 2025, Google LLC. +# Pasha Tatashin +# +# Live Update Orchestrator +# + +config LIVEUPDATE + bool "Live Update Orchestrator" + depends on KEXEC_HANDOVER + help + Enable the Live Update Orchestrator. Live Update is a mechanism, + typically based on kexec, that allows the kernel to be updated + while keeping selected devices operational across the transition. + These devices are intended to be reclaimed by the new kernel and + re-attached to their original workload without requiring a device + reset. + + This functionality depends on specific support within device drivers + and related kernel subsystems. + + This feature is primarily used in cloud environments to quickly + update the kernel hypervisor with minimal disruption to the + running virtual machines. + + If unsure, say N. diff --git a/drivers/misc/liveupdate/Makefile b/drivers/misc/liveupdate/Mak= efile new file mode 100644 index 000000000000..3bfb4b9fed11 --- /dev/null +++ b/drivers/misc/liveupdate/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-y +=3D luo_core.o diff --git a/drivers/misc/liveupdate/luo_core.c b/drivers/misc/liveupdate/l= uo_core.c new file mode 100644 index 000000000000..919c37b0b4d1 --- /dev/null +++ b/drivers/misc/liveupdate/luo_core.c @@ -0,0 +1,296 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: Live Update Orchestrator (LUO) + * + * Live Update is a specialized reboot process where selected devices are + * kept operational across a kernel transition. For these devices, DMA act= ivity + * may continue during the kernel reboot. + * + * The primary use case is in cloud environments, allowing hypervisor upda= tes + * without disrupting running virtual machines. During a live update, VMs = can be + * suspended (with their state preserved in memory), while the hypervisor = kernel + * reboots. Devices attached to these VMs (e.g., NICs, block devices) are = kept + * operational by the LUO during the hypervisor reboot, allowing the VMs t= o be + * quickly resumed on the new kernel. + * + * The core of LUO is a state machine that tracks the progress of a live u= pdate, + * along with a callback API that allows other kernel subsystems to partic= ipate + * in the process. Example subsystems that can hook into LUO include: kvm, + * iommu, interrupts, vfio, participating filesystems, and mm. + * + * LUO uses KHO to transfer memory state from the current Kernel to the ne= xt + * Kernel. + * + * The LUO state machine ensures that operations are performed in the corr= ect + * sequence and provides a mechanism to track and recover from potential + * failures, and select devices and subsystems that should participate in + * live update sequence. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include "luo_internal.h" + +static DECLARE_RWSEM(luo_state_rwsem); + +enum liveupdate_state luo_state; + +const char *const luo_state_str[] =3D { + [LIVEUPDATE_STATE_NORMAL] =3D "normal", + [LIVEUPDATE_STATE_PREPARED] =3D "prepared", + [LIVEUPDATE_STATE_FROZEN] =3D "frozen", + [LIVEUPDATE_STATE_UPDATED] =3D "updated", +}; + +bool luo_enabled; + +static int __init early_liveupdate_param(char *buf) +{ + return kstrtobool(buf, &luo_enabled); +} +early_param("liveupdate", early_liveupdate_param); + +/* Return true if the current state is equal to the provided state */ +static inline bool is_current_luo_state(enum liveupdate_state expected_sta= te) +{ + return READ_ONCE(luo_state) =3D=3D expected_state; +} + +static void __luo_set_state(enum liveupdate_state state) +{ + WRITE_ONCE(luo_state, state); +} + +static inline void luo_set_state(enum liveupdate_state state) +{ + pr_info("Switched from [%s] to [%s] state\n", + LUO_STATE_STR, luo_state_str[state]); + __luo_set_state(state); +} + +static int luo_do_freeze_calls(void) +{ + return 0; +} + +static void luo_do_finish_calls(void) +{ +} + +int luo_prepare(void) +{ + return 0; +} + +/** + * luo_freeze() - Initiate the final freeze notification phase for live up= date. + * + * Attempts to transition the live update orchestrator state from + * %LIVEUPDATE_STATE_PREPARED to %LIVEUPDATE_STATE_FROZEN. This function is + * typically called just before the actual reboot system call (e.g., kexec) + * is invoked, either directly by the orchestration tool or potentially fr= om + * within the reboot syscall path itself. + * + * Based on the outcome of the notification process: + * - If luo_do_freeze_calls() returns 0 (all callbacks succeeded), the sta= te + * is set to %LIVEUPDATE_STATE_FROZEN using luo_set_state(), indicating + * readiness for the imminent kexec. + * - If luo_do_freeze_calls() returns a negative error code (a callback + * failed), the state is reverted to %LIVEUPDATE_STATE_NORMAL using + * luo_set_state() to cancel the live update attempt. + * + * @return 0: Success. Negative error otherwise. State is reverted to + * %LIVEUPDATE_STATE_NORMAL in case of an error during callbacks. + */ +int luo_freeze(void) +{ + int ret; + + if (down_write_killable(&luo_state_rwsem)) { + pr_warn("[freeze] event canceled by user\n"); + return -EAGAIN; + } + + if (!is_current_luo_state(LIVEUPDATE_STATE_PREPARED)) { + pr_warn("Can't switch to [%s] from [%s] state\n", + luo_state_str[LIVEUPDATE_STATE_FROZEN], + LUO_STATE_STR); + up_write(&luo_state_rwsem); + + return -EINVAL; + } + + ret =3D luo_do_freeze_calls(); + if (!ret) + luo_set_state(LIVEUPDATE_STATE_FROZEN); + else + luo_set_state(LIVEUPDATE_STATE_NORMAL); + + up_write(&luo_state_rwsem); + + return ret; +} + +/** + * luo_finish - Finalize the live update process in the new kernel. + * + * This function is called after a successful live update reboot into a n= ew + * kernel, once the new kernel is ready to transition to the normal operat= ional + * state. It signals the completion of the live update sequence to subsyst= ems. + * + * It first attempts to acquire the write lock for the orchestrator state. + * + * Then, it checks if the system is in the ``LIVEUPDATE_STATE_UPDATED`` st= ate. + * If not, it logs a warning and returns ``-EINVAL``. + * + * If the state is correct, it triggers the ``LIVEUPDATE_FINISH`` notifier + * chain. Note that the return value of the notifier is intentionally igno= red as + * finish callbacks must not fail. Finally, the orchestrator state is + * transitioned back to ``LIVEUPDATE_STATE_NORMAL``, indicating the end of= the + * live update process. + * + * @return 0 on success, ``-EAGAIN`` if the state change was cancelled by = the + * user while waiting for the lock, or ``-EINVAL`` if the orchestrator is = not in + * the updated state. + */ +int luo_finish(void) +{ + if (down_write_killable(&luo_state_rwsem)) { + pr_warn("[finish] event canceled by user\n"); + return -EAGAIN; + } + + if (!is_current_luo_state(LIVEUPDATE_STATE_UPDATED)) { + pr_warn("Can't switch to [%s] from [%s] state\n", + luo_state_str[LIVEUPDATE_STATE_NORMAL], + LUO_STATE_STR); + up_write(&luo_state_rwsem); + + return -EINVAL; + } + + luo_do_finish_calls(); + luo_set_state(LIVEUPDATE_STATE_NORMAL); + + up_write(&luo_state_rwsem); + + return 0; +} + +int luo_cancel(void) +{ + return 0; +} + +void luo_state_read_enter(void) +{ + down_read(&luo_state_rwsem); +} + +void luo_state_read_exit(void) +{ + up_read(&luo_state_rwsem); +} + +static int __init luo_startup(void) +{ + __luo_set_state(LIVEUPDATE_STATE_NORMAL); + + return 0; +} +early_initcall(luo_startup); + +/* Public Functions */ + +/** + * liveupdate_reboot() - Kernel reboot notifier for live update final + * serialization. + * + * This function is invoked directly from the reboot() syscall pathway if a + * reboot is initiated while the live update state is %LIVEUPDATE_STATE_PR= EPARED + * (i.e., if the user did not explicitly trigger the frozen state). It han= dles + * the implicit transition into the final frozen state. + * + * It triggers the %LIVEUPDATE_REBOOT event callbacks for participating + * subsystems. These callbacks must perform final state saving very quickl= y as + * they execute during the blackout period just before kexec. + * + * If any %LIVEUPDATE_FREEZE callback fails, this function triggers the + * %LIVEUPDATE_CANCEL event for all participants to revert their state, ab= orts + * the live update, and returns an error. + */ +int liveupdate_reboot(void) +{ + if (!is_current_luo_state(LIVEUPDATE_STATE_PREPARED)) + return 0; + + return luo_freeze(); +} +EXPORT_SYMBOL_GPL(liveupdate_reboot); + +/** + * liveupdate_state_updated - Check if the system is in the live update + * 'updated' state. + * + * This function checks if the live update orchestrator is in the + * ``LIVEUPDATE_STATE_UPDATED`` state. This state indicates that the syste= m has + * successfully rebooted into a new kernel as part of a live update, and t= he + * preserved devices are expected to be in the process of being reclaimed. + * + * This is typically used by subsystems during early boot of the new kernel + * to determine if they need to attempt to restore state from a previous + * live update. + * + * @return true if the system is in the ``LIVEUPDATE_STATE_UPDATED`` state, + * false otherwise. + */ +bool liveupdate_state_updated(void) +{ + return is_current_luo_state(LIVEUPDATE_STATE_UPDATED); +} +EXPORT_SYMBOL_GPL(liveupdate_state_updated); + +/** + * liveupdate_state_normal - Check if the system is in the live update 'no= rmal' + * state. + * + * This function checks if the live update orchestrator is in the + * ``LIVEUPDATE_STATE_NORMAL`` state. This state indicates that no live up= date + * is in progress. It represents the default operational state of the syst= em. + * + * This can be used to gate actions that should only be performed when no + * live update activity is occurring. + * + * @return true if the system is in the ``LIVEUPDATE_STATE_NORMAL`` state, + * false otherwise. + */ +bool liveupdate_state_normal(void) +{ + return is_current_luo_state(LIVEUPDATE_STATE_NORMAL); +} +EXPORT_SYMBOL_GPL(liveupdate_state_normal); + +/** + * liveupdate_enabled - Check if the live update feature is enabled. + * + * This function returns the state of the live update feature flag, which + * can be controlled via the ``liveupdate`` kernel command-line parameter. + * + * @return true if live update is enabled, false otherwise. + */ +bool liveupdate_enabled(void) +{ + return luo_enabled; +} +EXPORT_SYMBOL_GPL(liveupdate_enabled); diff --git a/drivers/misc/liveupdate/luo_internal.h b/drivers/misc/liveupda= te/luo_internal.h new file mode 100644 index 000000000000..34e73fb0318c --- /dev/null +++ b/drivers/misc/liveupdate/luo_internal.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#ifndef _LINUX_LUO_INTERNAL_H +#define _LINUX_LUO_INTERNAL_H + +int luo_cancel(void); +int luo_prepare(void); +int luo_freeze(void); +int luo_finish(void); + +void luo_state_read_enter(void); +void luo_state_read_exit(void); + +extern const char *const luo_state_str[]; + +/* Get the current state as a string */ +#define LUO_STATE_STR luo_state_str[READ_ONCE(luo_state)] + +extern enum liveupdate_state luo_state; + +#endif /* _LINUX_LUO_INTERNAL_H */ diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h new file mode 100644 index 000000000000..c2740da70958 --- /dev/null +++ b/include/linux/liveupdate.h @@ -0,0 +1,131 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ +#ifndef _LINUX_LIVEUPDATE_H +#define _LINUX_LIVEUPDATE_H + +#include +#include +#include + +/** + * enum liveupdate_event - Events that trigger live update callbacks. + * @LIVEUPDATE_PREPARE: PREPARE should happens *before* the blackout windo= w. + * Subsystems should prepare for an upcoming reboot by + * serializing their states. However, it must be cons= idered + * that user applications, e.g. virtual machines are = still + * running during this phase. + * @LIVEUPDATE_FREEZE: FREEZE sent from the reboot() syscall, when the cu= rrent + * kernel is on its way out. This is the final opport= unity + * for subsystems to save any state that must persist + * across the reboot. Callbacks for this event should= be as + * fast as possible since they are on the critical pa= th of + * rebooting into the next kernel. + * @LIVEUPDATE_FINISH: FINISH is sent in the newly booted kernel after a + * successful live update and normally *after* the bl= ackout + * window. Subsystems should perform any final cleanup + * during this phase. This phase also provides an + * opportunity to clean up devices that were preserve= d but + * never explicitly reclaimed during the live update + * process. State restoration should have already occ= urred + * before this event. Callbacks for this event must n= ot + * fail. The completion of this call transitions the + * machine from ``updated`` to ``normal`` state. + * @LIVEUPDATE_CANCEL: CANCEL the live update and go back to normal state= . This + * event is user initiated, or is done automatically = when + * LIVEUPDATE_PREPARE or LIVEUPDATE_FREEZE stage fail= s. + * Subsystems should revert any actions taken during = the + * corresponding prepare event. Callbacks for this ev= ent + * must not fail. + * + * These events represent the different stages and actions within the live + * update process that subsystems (like device drivers and bus drivers) + * need to be aware of to correctly serialize and restore their state. + * + */ +enum liveupdate_event { + LIVEUPDATE_PREPARE, + LIVEUPDATE_FREEZE, + LIVEUPDATE_FINISH, + LIVEUPDATE_CANCEL, +}; + +/** + * enum liveupdate_state - Defines the possible states of the live update + * orchestrator. + * @LIVEUPDATE_STATE_NORMAL: Default state, no live update in prog= ress. + * @LIVEUPDATE_STATE_PREPARED: Live update is prepared for reboot; t= he + * LIVEUPDATE_PREPARE callbacks have com= pleted + * successfully. + * Devices might operate in a limited st= ate + * for example the participating devices= might + * not be allowed to unbind, and also the + * setting up of new DMA mappings might = be + * disabled in this state. + * @LIVEUPDATE_STATE_FROZEN: The final reboot event + * (%LIVEUPDATE_FREEZE) has been sent, a= nd the + * system is performing its final state = saving + * within the "blackout window". User + * workloads must be suspended. The actu= al + * reboot (kexec) into the next kernel is + * imminent. + * @LIVEUPDATE_STATE_UPDATED: The system has rebooted into the next + * kernel via live update the system is = now + * running the next kernel, awaiting the + * finish event. + * + * These states track the progress and outcome of a live update operation. + */ +enum liveupdate_state { + LIVEUPDATE_STATE_NORMAL =3D 0, + LIVEUPDATE_STATE_PREPARED =3D 1, + LIVEUPDATE_STATE_FROZEN =3D 2, + LIVEUPDATE_STATE_UPDATED =3D 3, +}; + +#ifdef CONFIG_LIVEUPDATE + +/* Return true if live update orchestrator is enabled */ +bool liveupdate_enabled(void); + +/* Called during reboot to tell participants to complete serialization */ +int liveupdate_reboot(void); + +/* + * Return true if machine is in updated state (i.e. live update boot in + * progress) + */ +bool liveupdate_state_updated(void); + +/* + * Return true if machine is in normal state (i.e. no live update in progr= ess). + */ +bool liveupdate_state_normal(void); + +#else /* CONFIG_LIVEUPDATE */ + +static inline int liveupdate_reboot(void) +{ + return 0; +} + +static inline bool liveupdate_enabled(void) +{ + return false; +} + +static inline bool liveupdate_state_updated(void) +{ + return false; +} + +static inline bool liveupdate_state_normal(void) +{ + return true; +} + +#endif /* CONFIG_LIVEUPDATE */ +#endif /* _LINUX_LIVEUPDATE_H */ --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 66593264619 for ; Thu, 15 May 2025 18:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333417; cv=none; b=c7Hr2+Lv4tSKPLQ/MD1XfiJYR/Apek1F1j1Ajxe21YmpM8ewp4vHDO4nVCZqV7Ue9ySF3sLsBbUytO0y/IfmlF3ovC3N86BT2vV0e6LmzthNL2m1ktBlZpQgDho+Pak9+mDyHUgK4YOYOV8f8YzWp4tvL3WGZqyOd7orPmcw+dA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333417; c=relaxed/simple; bh=yAO+FqUyXW7TfElH7NH7lyIDYXIQ35zp42uQgPAFqsQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DCdzSJkVHoCmkwdJrYRQs18v45lrRotwszTytEA0ySBM+DBzWsVLCJKcFtXYOvCZqnOk5+O/wGvf/GImM+goTjGAKntEAV2aqBM75UmzeXAyIy3/oCLsj+gw3VJ0VIdN0/PMOfOm8Ww6VXOwk0bjfnaTawnscoKeySUvzpu04Os= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=TrH07SJN; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="TrH07SJN" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7c5f720c717so289341085a.0 for ; Thu, 15 May 2025 11:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333414; x=1747938214; 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=eCL7Dl0fUJFgtoGMLDnQRSnzltXuASvUYx206SfRPVk=; b=TrH07SJNhzLdVUVOGu4NklRcvKaqoBTDkKextkucNU18kK0wOO8sIAqGmIgE3a1Y9J 2vm87tHhL+XSJfaRh/wDN/FDd4c2P9u/N4cq3HC4A/NPcL+QOi6ygttFW1DqUuT9npqF BxudGjquI0JMxyCclkN7LObaVLDwK8r/l+CAg0osdwZJGsyBeXgrEpQBGUfIiTri6olE /WS4jiUe3NHPlGk2KA25RI2Mj4q+uwGotTYrcnp/2vtzlV3ShhcKaMv7AnFajfLvGTAZ 6TorKoLonZ7w9D720Vw2TVyQP+KysTLe18W0H3QDD/rWL9lGg21uVzX7b1xpONCTRwA6 Wwlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333414; x=1747938214; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eCL7Dl0fUJFgtoGMLDnQRSnzltXuASvUYx206SfRPVk=; b=h2gSIPC+YoTF0vzbAfMc+SR4BXRAIpQ5UKxnHcVxNEdYXKDEmSTCrbl0kiIEGXWe2p I/B2l4qDezaSw33S5nbaCzvhvHfyaHer/13RxNY4gCCCFFtsdQYvGqHk4GyErQuq5+BR s9OGp8SGGD+mh4TEYwj5V2QnPrqEO0UwEhHpWIgnTC8Yg/0vjiZGeUp8g4Tz7CKNF4BQ 1mYaWMl4XqBgKEEAYzvNRxBrIjeUeZgC/PiZEX/g4Fy0f0yVWocKwunLG1ZhyShYVlFp /hL4UE8W2bWYzFzmkoyKZQ+KAWstacKkOz70GtvrAQLq12Fq3hU7T07G3x7rTZ7OdtOT GBEg== X-Forwarded-Encrypted: i=1; AJvYcCVppVTyLjJDFW7dpRl0KDxg6FzXKYuhHypzsF6tCuDUfyG99Wx424pS/4PVjmHSWhsXimOu7jG2JF5bS7g=@vger.kernel.org X-Gm-Message-State: AOJu0YwBiLi46rFwD3TcOlvTn+K7SXBHQcHULYeEjivK1eQJtjj4CeMD QAIacY1sEVlxt2HBkLYvj+hBAVGphp0oba+/PMJX74+podgJTRAzZDagIrk+5qrg/1w= X-Gm-Gg: ASbGncuKid3sWD/ETJvEUKXUm5sOeb/t45CReGAAFSK4jfNedBHUE865send2vO3WsN JXH++1h4dtc3fVTlcwHLFTKF/X+BP7OF/2KlDg6mYCCj1FxkDh8pqCt4DSHkkzMj9v/B1GF42bu y6IZvwfQPTXdiSD5MGRaTS6CE8iee6TKvpe7E2tx9jecrgcw6FBVbxNhlxJH7y23YhalSWl1NAV ME3KGIf0W6MetCXUq1teWkcDc7jZtBBLFRZlt9clESx6wTE+/EhZDvI2WXCLwWGo7nZdF3XnC3c 5yWP3gVU6u73gCuLRE5v0+ckB7vwz6LcpXjs0rZZQSx6YjnCPW0Y6C2M0MyY+PEuoaar/Q6iyWP sX9DP863pbWmMMnaup610bCVsDBgbUHAputFAOC+Epfjo X-Google-Smtp-Source: AGHT+IGyVx7YT2wET1Kp1qNiBNOANi4Vf79w65s/UaK8dJtraKWXto4zccTg9syrNS2nds1eQAId/g== X-Received: by 2002:a05:620a:2890:b0:7c9:65cb:6214 with SMTP id af79cd13be357-7cd46b14da4mr55322585a.17.1747333414011; Thu, 15 May 2025 11:23:34 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:32 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 05/16] luo: luo_core: integrate with KHO Date: Thu, 15 May 2025 18:23:09 +0000 Message-ID: <20250515182322.117840-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" Integrate the LUO with the KHO framework to enable passing LUO state across a kexec reboot. This patch introduces the following changes: - During the KHO finalization phase allocate FDT blob. - Populate this FDT with a LUO compatibility string ("luo-v1") and the current LUO state (`luo_state`). - Implement a KHO notifier LUO now depends on `CONFIG_KEXEC_HANDOVER`. The core state transition logic (`luo_do_*_calls`) remains unimplemented in this patch. Signed-off-by: Pasha Tatashin --- drivers/misc/liveupdate/luo_core.c | 222 ++++++++++++++++++++++++++++- 1 file changed, 219 insertions(+), 3 deletions(-) diff --git a/drivers/misc/liveupdate/luo_core.c b/drivers/misc/liveupdate/l= uo_core.c index 919c37b0b4d1..a76e886bc3b1 100644 --- a/drivers/misc/liveupdate/luo_core.c +++ b/drivers/misc/liveupdate/luo_core.c @@ -36,9 +36,12 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 #include +#include #include +#include #include #include +#include #include #include "luo_internal.h" =20 @@ -55,6 +58,12 @@ const char *const luo_state_str[] =3D { =20 bool luo_enabled; =20 +static void *luo_fdt_out; +static void *luo_fdt_in; +#define LUO_FDT_SIZE SZ_1M +#define LUO_KHO_ENTRY_NAME "LUO" +#define LUO_COMPATIBLE "luo-v1" + static int __init early_liveupdate_param(char *buf) { return kstrtobool(buf, &luo_enabled); @@ -79,6 +88,60 @@ static inline void luo_set_state(enum liveupdate_state s= tate) __luo_set_state(state); } =20 +/* Called during the prepare phase, to create LUO fdt tree */ +static int luo_fdt_setup(struct kho_serialization *ser) +{ + void *fdt_out; + int ret; + + fdt_out =3D (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(LUO_FDT_SIZE)); + if (!fdt_out) { + pr_err("failed to allocate FDT memory\n"); + return -ENOMEM; + } + + ret =3D fdt_create_empty_tree(fdt_out, LUO_FDT_SIZE); + if (ret) + goto exit_free; + + ret =3D fdt_setprop(fdt_out, 0, "compatible", LUO_COMPATIBLE, + strlen(LUO_COMPATIBLE) + 1); + if (ret) + goto exit_free; + + ret =3D kho_preserve_phys(__pa(fdt_out), LUO_FDT_SIZE); + if (ret) + goto exit_free; + + ret =3D kho_add_subtree(ser, LUO_KHO_ENTRY_NAME, fdt_out); + if (ret) + goto exit_unpreserve; + luo_fdt_out =3D fdt_out; + + return 0; + +exit_unpreserve: + kho_unpreserve_phys(__pa(fdt_out), LUO_FDT_SIZE); +exit_free: + free_pages((unsigned long)fdt_out, get_order(LUO_FDT_SIZE)); + pr_err("failed to prepare LUO FDT: %d\n", ret); + + return ret; +} + +static void luo_fdt_destroy(void) +{ + kho_unpreserve_phys(__pa(luo_fdt_out), LUO_FDT_SIZE); + free_pages((unsigned long)luo_fdt_out, get_order(LUO_FDT_SIZE)); + luo_fdt_out =3D NULL; +} + +static int luo_do_prepare_calls(void) +{ + return 0; +} + static int luo_do_freeze_calls(void) { return 0; @@ -88,11 +151,111 @@ static void luo_do_finish_calls(void) { } =20 -int luo_prepare(void) +static void luo_do_cancel_calls(void) +{ +} + +static int __luo_prepare(struct kho_serialization *ser) { + int ret; + + if (down_write_killable(&luo_state_rwsem)) { + pr_warn("[prepare] event canceled by user\n"); + return -EAGAIN; + } + + if (!is_current_luo_state(LIVEUPDATE_STATE_NORMAL)) { + pr_warn("Can't switch to [%s] from [%s] state\n", + luo_state_str[LIVEUPDATE_STATE_PREPARED], + LUO_STATE_STR); + ret =3D -EINVAL; + goto exit_unlock; + } + + ret =3D luo_fdt_setup(ser); + if (ret) + goto exit_unlock; + + ret =3D luo_do_prepare_calls(); + if (ret) + goto exit_unlock; + + luo_set_state(LIVEUPDATE_STATE_PREPARED); + +exit_unlock: + up_write(&luo_state_rwsem); + + return ret; +} + +static int __luo_cancel(void) +{ + if (down_write_killable(&luo_state_rwsem)) { + pr_warn("[cancel] event canceled by user\n"); + return -EAGAIN; + } + + if (!is_current_luo_state(LIVEUPDATE_STATE_PREPARED) && + !is_current_luo_state(LIVEUPDATE_STATE_FROZEN)) { + pr_warn("Can't switch to [%s] from [%s] state\n", + luo_state_str[LIVEUPDATE_STATE_NORMAL], + LUO_STATE_STR); + up_write(&luo_state_rwsem); + + return -EINVAL; + } + + luo_do_cancel_calls(); + luo_fdt_destroy(); + luo_set_state(LIVEUPDATE_STATE_NORMAL); + + up_write(&luo_state_rwsem); + return 0; } =20 +static int luo_kho_notifier(struct notifier_block *self, + unsigned long cmd, void *v) +{ + int ret; + + switch (cmd) { + case KEXEC_KHO_FINALIZE: + ret =3D __luo_prepare((struct kho_serialization *)v); + break; + case KEXEC_KHO_ABORT: + ret =3D __luo_cancel(); + break; + default: + return NOTIFY_BAD; + } + + return notifier_from_errno(ret); +} + +static struct notifier_block luo_kho_notifier_nb =3D { + .notifier_call =3D luo_kho_notifier, +}; + +/** + * luo_prepare - Initiate the live update preparation phase. + * + * This function is called to begin the live update process. It attempts to + * transition the luo to the ``LIVEUPDATE_STATE_PREPARED`` state. + * + * If the calls complete successfully, the orchestrator state is set + * to ``LIVEUPDATE_STATE_PREPARED``. If any call fails a + * ``LIVEUPDATE_CANCEL`` is sent to roll back any actions. + * + * @return 0 on success, ``-EAGAIN`` if the state change was cancelled by = the + * user while waiting for the lock, ``-EINVAL`` if the orchestrator is not= in + * the normal state, or a negative error code returned by the calls. + */ +int luo_prepare(void) +{ + return kho_finalize(); +} + /** * luo_freeze() - Initiate the final freeze notification phase for live up= date. * @@ -188,9 +351,23 @@ int luo_finish(void) return 0; } =20 +/** + * luo_cancel - Cancel the ongoing live update from prepared or frozen sta= tes. + * + * This function is called to abort a live update that is currently in the + * ``LIVEUPDATE_STATE_PREPARED`` state. + * + * If the state is correct, it triggers the ``LIVEUPDATE_CANCEL`` notifier= chain + * to allow subsystems to undo any actions performed during the prepare or + * freeze events. Finally, the orchestrator state is transitioned back to + * ``LIVEUPDATE_STATE_NORMAL``. + * + * @return 0 on success, or ``-EAGAIN`` if the state change was cancelled = by the + * user while waiting for the lock. + */ int luo_cancel(void) { - return 0; + return kho_abort(); } =20 void luo_state_read_enter(void) @@ -205,7 +382,46 @@ void luo_state_read_exit(void) =20 static int __init luo_startup(void) { - __luo_set_state(LIVEUPDATE_STATE_NORMAL); + phys_addr_t fdt_phys; + int ret; + + if (!kho_is_enabled()) { + if (luo_enabled) + pr_warn("Disabling liveupdate because KHO is disabled\n"); + luo_enabled =3D false; + return 0; + } + + ret =3D register_kho_notifier(&luo_kho_notifier_nb); + if (ret) { + luo_enabled =3D false; + pr_warn("Failed to register with KHO [%d]\n", ret); + } + + /* + * Retrieve LUO subtree, and verify its format. Panic in case of + * exceptions, since machine devices and memory is in unpredictable + * state. + */ + ret =3D kho_retrieve_subtree(LUO_KHO_ENTRY_NAME, &fdt_phys); + if (ret) { + if (ret !=3D -ENOENT) { + panic("failed to retrieve FDT '%s' from KHO: %d\n", + LUO_KHO_ENTRY_NAME, ret); + } + __luo_set_state(LIVEUPDATE_STATE_NORMAL); + + return 0; + } + + luo_fdt_in =3D __va(fdt_phys); + ret =3D fdt_node_check_compatible(luo_fdt_in, 0, LUO_COMPATIBLE); + if (ret) { + panic("FDT '%s' is incompatible with '%s' [%d]\n", + LUO_KHO_ENTRY_NAME, LUO_COMPATIBLE, ret); + } + + __luo_set_state(LIVEUPDATE_STATE_UPDATED); =20 return 0; } --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 E908E264F96 for ; Thu, 15 May 2025 18:23:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333419; cv=none; b=F5nh80EFNMN4iWf8zzSr5DIkGiVl9BzrDQwmsLObvvKoP3n7/cmDAy3PuBtPywDv93nL4wD4WoD36HCro3PeLuYbShwmgdSARdM/oPjGtOuT5rgzFl9ho8i8W0PeBfrs/Lb1z20cfg17VDn3IdpLaX5F953gVPKCXa9Jcnahsuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333419; c=relaxed/simple; bh=BoLj1Ak1vQggmph+8uK4dV+pjb1sx6KyTa/pSg/IZEU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gtif8GxDBvkj842aQA8blrlPHihtSOxqPVH+aiVlJV0rqcDgSBdyXiWiQouWeKUskvFK40/8BpHSfrqblt83XIsQ9baRH4rzNDWloFSi9PsA3+BREEPe9K3KMN3WuqCwrAIoQfcw1faZoBSOm60q7kwrQXWHsZnDbsw/Cni4kV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=nJekHMD1; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="nJekHMD1" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7c59e7039eeso176796585a.2 for ; Thu, 15 May 2025 11:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333416; x=1747938216; 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=36BQafovF1Ac1o8l66KKhJYbiIRxHdYx4gFtUfBj6co=; b=nJekHMD16tyWs1ffW41eSjbKSlKniY9+40Cv939H24YdSE6PfNb+DiJwmOOkZM/WYQ +yOVa+06mgYb1IPghszJvcAntpme1l6kM/BWTL3CdTcLFXkzkMfTGJfHPyxTXsdCRkwW tA9msQXdKFxAIsLdX9F20E3FJsPjgghffpJECv1CMAPkCrdVhtHYLnZ5Dm2tlyHcVg9K DoSSRj6RQ+QPUS8OGsDLVgWlijq9OM+6FDEq270aIFxah1BkkEkZguAqU+kLhAaeVni+ d8+gSeJi/23tI+KyAqnUZzqyKYEBBHAS0Oas3CpP0GvszXAOoZL/gUl/zke/tjxKJIga j+GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333416; x=1747938216; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=36BQafovF1Ac1o8l66KKhJYbiIRxHdYx4gFtUfBj6co=; b=ohpmvrNvB6CIqoxx+/F822UvvIR7R79n6KMpZdDHfKr5qqNMyIUvA/WrBlBBItaKsn PorEVWjXknoDBAECRZ8wRwofpEKbsjjqYTdwtEd/76Wj5PYDymRdOND28gPR453ztcQv 0ovt5Uv364GnzIBqPH7OWZx2+2NU/3as32T8ssVhqfMvjlKuUG1Pv1w1XcdP1oy2waAu H/qz7cq7TXvJAotgaXNoqE4Bg+UtEX6vmsnCvfDEqp1QLGVGcTZlsmdYYWYm5pw9ZQ9t AIPYjK8J6wYi7YKFAuisC/IwWy3vyAx/eFJtgOdzPQj2vRa26UY4PvbnTNUfy7DoO1uD os7g== X-Forwarded-Encrypted: i=1; AJvYcCWFhWi+TqR8sjNzvTKTu7nAFuOTrlHd26m5E6IrpIvM4VxHOEDAlgjJ5/CVDFZc7slSAaxNCwuJlDnRdNo=@vger.kernel.org X-Gm-Message-State: AOJu0YzF2NnHrlqmgAdNuOrgeHUHUc7DWxconHWRlMvHex3Hujgx4Eug m3+H8uGE0Y9ZSGAX63J2dnurUsYvLQe9WF/UspoB3ZB0uIhADQsR6pITyB4vccJK8TU= X-Gm-Gg: ASbGncsQKMSw3mpBMhCeCmNg1UmcaIT2ghBTG6Am1WyjggIrzTYiPvG6qBr4/gd8viF NN/A255NZcCHY6LkiAed2iYNtfNvyr3XJ2GCqoeubyj5ORD1rPqKNMjqGcqv/Ervs1vpWkorG1F DqPs7kpL7Vb3MrpNnFZuns9H7RvtmqxaAoPjIM+2lLlMEyO8JblYSZHf0pruBaBvo8vQfeoOBBx K1sXUGcUVcMKhhDL4dk008DrxQbU9C+UzW64mOlsHgjryNRqCDWSKy07y1G5T2ubySfQK8cZQZh 8ptF6Xb6wz3SpNyqc96OiJcHBaOH02dK7yT4wd1Zd01D5TtJlERi9H7Eu86TFo/YWXYDb7HZXka le359OyVPf9sz90J1Hbwemn+tq2y3SmHgsx3P9Lr3ZdgX X-Google-Smtp-Source: AGHT+IHZNr27zFQP0NtQYhUod6TNi4DfrQJByS+jzjJRT8QrvEWlLHAp4pGsYYNOuKcOvMxot8QTuA== X-Received: by 2002:a05:620a:bcb:b0:7ca:f3e2:92b0 with SMTP id af79cd13be357-7cd4670b0c5mr66666785a.3.1747333415512; Thu, 15 May 2025 11:23:35 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:34 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 06/16] luo: luo_subsystems: add subsystem registration Date: Thu, 15 May 2025 18:23:10 +0000 Message-ID: <20250515182322.117840-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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 the framework for kernel subsystems (e.g., KVM, IOMMU, device drivers) to register with LUO and participate in the live update process via callbacks. Subsystem Registration: - Defines struct liveupdate_subsystem in linux/liveupdate.h, which subsystems use to provide their name and optional callbacks (prepare, freeze, cancel, finish). The callbacks accept a u64 *data intended for passing state/handles. - Exports liveupdate_register_subsystem() and liveupdate_unregister_subsystem() API functions. - Adds drivers/misc/liveupdate/luo_subsystems.c to manage a list of registered subsystems. Registration/unregistration is restricted to specific LUO states (NORMAL/UPDATED). Callback Framework: - The main luo_core.c state transition functions now delegate to new luo_do_subsystems_*_calls() functions defined in luo_subsystems.c. - These new functions are intended to iterate through the registered subsystems and invoke their corresponding callbacks. FDT Integration: - Adds a /subsystems subnode within the main LUO FDT created in luo_core.c. This node has its own compatibility string (subsystems-v1). - luo_subsystems_fdt_setup() populates this node by adding a property for each registered subsystem, using the subsystem's name. Currently, these properties are initialized with a placeholder u64 value (0). - luo_subsystems_startup() is called from luo_core.c on boot to find and validate the /subsystems node in the FDT received via KHO. It panics if the node is missing or incompatible. - Adds a stub API function liveupdate_get_subsystem_data() intended for subsystems to retrieve their persisted u64 data from the FDT in the new kernel. Signed-off-by: Pasha Tatashin --- drivers/misc/liveupdate/Makefile | 1 + drivers/misc/liveupdate/luo_core.c | 19 +- drivers/misc/liveupdate/luo_internal.h | 7 + drivers/misc/liveupdate/luo_subsystems.c | 284 +++++++++++++++++++++++ include/linux/liveupdate.h | 53 +++++ 5 files changed, 362 insertions(+), 2 deletions(-) create mode 100644 drivers/misc/liveupdate/luo_subsystems.c diff --git a/drivers/misc/liveupdate/Makefile b/drivers/misc/liveupdate/Mak= efile index 3bfb4b9fed11..df1c9709ba4f 100644 --- a/drivers/misc/liveupdate/Makefile +++ b/drivers/misc/liveupdate/Makefile @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-y +=3D luo_core.o +obj-y +=3D luo_subsystems.o diff --git a/drivers/misc/liveupdate/luo_core.c b/drivers/misc/liveupdate/l= uo_core.c index a76e886bc3b1..417e7f6bf36c 100644 --- a/drivers/misc/liveupdate/luo_core.c +++ b/drivers/misc/liveupdate/luo_core.c @@ -110,6 +110,10 @@ static int luo_fdt_setup(struct kho_serialization *ser) if (ret) goto exit_free; =20 + ret =3D luo_subsystems_fdt_setup(fdt_out); + if (ret) + goto exit_free; + ret =3D kho_preserve_phys(__pa(fdt_out), LUO_FDT_SIZE); if (ret) goto exit_free; @@ -139,20 +143,30 @@ static void luo_fdt_destroy(void) =20 static int luo_do_prepare_calls(void) { - return 0; + int ret; + + ret =3D luo_do_subsystems_prepare_calls(); + + return ret; } =20 static int luo_do_freeze_calls(void) { - return 0; + int ret; + + ret =3D luo_do_subsystems_freeze_calls(); + + return ret; } =20 static void luo_do_finish_calls(void) { + luo_do_subsystems_finish_calls(); } =20 static void luo_do_cancel_calls(void) { + luo_do_subsystems_cancel_calls(); } =20 static int __luo_prepare(struct kho_serialization *ser) @@ -422,6 +436,7 @@ static int __init luo_startup(void) } =20 __luo_set_state(LIVEUPDATE_STATE_UPDATED); + luo_subsystems_startup(luo_fdt_in); =20 return 0; } diff --git a/drivers/misc/liveupdate/luo_internal.h b/drivers/misc/liveupda= te/luo_internal.h index 34e73fb0318c..63a8b93254a6 100644 --- a/drivers/misc/liveupdate/luo_internal.h +++ b/drivers/misc/liveupdate/luo_internal.h @@ -16,6 +16,13 @@ int luo_finish(void); void luo_state_read_enter(void); void luo_state_read_exit(void); =20 +void luo_subsystems_startup(void *fdt); +int luo_subsystems_fdt_setup(void *fdt); +int luo_do_subsystems_prepare_calls(void); +int luo_do_subsystems_freeze_calls(void); +void luo_do_subsystems_finish_calls(void); +void luo_do_subsystems_cancel_calls(void); + extern const char *const luo_state_str[]; =20 /* Get the current state as a string */ diff --git a/drivers/misc/liveupdate/luo_subsystems.c b/drivers/misc/liveup= date/luo_subsystems.c new file mode 100644 index 000000000000..436929a17de0 --- /dev/null +++ b/drivers/misc/liveupdate/luo_subsystems.c @@ -0,0 +1,284 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO Subsystems support + * + * Various kernel subsystems register with the Live Update Orchestrator to + * participate in the live update process. These subsystems are notified at + * different stages of the live update sequence, allowing them to serialize + * device state before the reboot and restore it afterwards. Examples incl= ude + * the device layer, interrupt controllers, KVM, IOMMU, and specific device + * drivers. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include "luo_internal.h" + +#define LUO_SUBSYSTEMS_NODE_NAME "subsystems" +#define LUO_SUBSYSTEMS_COMPATIBLE "subsystems-v1" + +static DEFINE_MUTEX(luo_subsystem_list_mutex); +static LIST_HEAD(luo_subsystems_list); +static void *luo_fdt_out; +static void *luo_fdt_in; + +/** + * luo_subsystems_fdt_setup - Adds and populates the 'subsystems' node in = the + * FDT. + * @fdt: Pointer to the LUO FDT blob. + * + * Add subsystems node and each subsystem to the LUO FDT blob. + * + * Returns: 0 on success, negative errno on failure. + */ +int luo_subsystems_fdt_setup(void *fdt) +{ + struct liveupdate_subsystem *subsystem; + const u64 zero_data =3D 0; + int ret, node_offset; + + ret =3D fdt_add_subnode(fdt, 0, LUO_SUBSYSTEMS_NODE_NAME); + if (ret < 0) + goto exit_error; + + node_offset =3D ret; + ret =3D fdt_setprop_string(fdt, node_offset, "compatible", + LUO_SUBSYSTEMS_COMPATIBLE); + if (ret < 0) + goto exit_error; + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + ret =3D fdt_setprop(fdt, node_offset, subsystem->name, + &zero_data, sizeof(zero_data)); + if (ret < 0) + goto exit_error; + } + + luo_fdt_out =3D fdt; + return 0; +exit_error: + pr_err("Failed to setup 'subsystems' node to FDT: %s\n", + fdt_strerror(ret)); + return -ENOSPC; +} + +/** + * luo_subsystems_startup - Validates the LUO subsystems FDT node at start= up. + * @fdt: Pointer to the LUO FDT blob passed from the previous kernel. + * + * This __init function checks the existence and validity of the '/subsyst= ems' + * node in the FDT. This node is considered mandatory. It calls panic() if + * the node is missing, inaccessible, or invalid (e.g., missing compatible, + * wrong compatible string), indicating a critical configuration error for= LUO. + */ +void __init luo_subsystems_startup(void *fdt) +{ + int ret, node_offset; + + node_offset =3D fdt_subnode_offset(fdt, 0, LUO_SUBSYSTEMS_NODE_NAME); + if (node_offset < 0) + panic("Failed to find /subsystems node\n"); + + ret =3D fdt_node_check_compatible(fdt, node_offset, + LUO_SUBSYSTEMS_COMPATIBLE); + if (ret) { + panic("FDT '%s' is incompatible with '%s' [%d]\n", + LUO_SUBSYSTEMS_NODE_NAME, LUO_SUBSYSTEMS_COMPATIBLE, ret); + } + luo_fdt_in =3D fdt; +} + +/** + * luo_do_subsystems_prepare_calls - Calls prepare callbacks and updates F= DT + * if all prepares succeed. Handles cancellation on failure. + * + * Phase 1: Calls 'prepare' for all subsystems and stores results temporar= ily. + * If any 'prepare' fails, calls 'cancel' on previously prepared subsystems + * and returns the error. + * Phase 2: If all 'prepare' calls succeeded, writes the stored data to th= e FDT. + * If any FDT write fails, calls 'cancel' on *all* prepared subsystems and + * returns the FDT error. + * + * Returns: 0 on success. Negative errno on failure. + */ +int luo_do_subsystems_prepare_calls(void) +{ + return 0; +} + +/** + * luo_do_subsystems_freeze_calls - Calls freeze callbacks and updates FDT + * if all freezes succeed. Handles cancellation on failure. + * + * Phase 1: Calls 'freeze' for all subsystems and stores results temporari= ly. + * If any 'freeze' fails, calls 'cancel' on previously called subsystems + * and returns the error. + * Phase 2: If all 'freeze' calls succeeded, writes the stored data to the= FDT. + * If any FDT write fails, calls 'cancel' on *all* subsystems and + * returns the FDT error. + * + * Returns: 0 on success. Negative errno on failure. + */ +int luo_do_subsystems_freeze_calls(void) +{ + return 0; +} + +/** + * luo_do_subsystems_finish_calls- Calls finish callbacks for all subsyste= ms. + * + * This function is called at the end of live update cycle to do the final + * clean-up or housekeeping of the post-live update states. + */ +void luo_do_subsystems_finish_calls(void) +{ +} + +/** + * luo_do_subsystems_cancel_calls - Calls cancel callbacks for all subsyst= ems. + * + * This function is typically called when the live update process needs to= be + * aborted externally, for example, after the prepare phase may have run b= ut + * before actual reboot. It iterates through all registered subsystems and= calls + * the 'cancel' callback for those that implement it and likely completed + * prepare. + */ +void luo_do_subsystems_cancel_calls(void) +{ +} + +/** + * liveupdate_register_subsystem - Register a kernel subsystem handler wit= h LUO + * @h: Pointer to the liveupdate_subsystem structure allocated and populat= ed + * by the calling subsystem. + * + * Registers a subsystem handler that provides callbacks for different eve= nts + * of the live update cycle. Registration is typically done during the + * subsystem's module init or core initialization. + * + * Can only be called when LUO is in the NORMAL or UPDATED states. + * The provided name (@h->name) must be unique among registered subsystems. + * + * Return: 0 on success, negative error code otherwise. + */ +int liveupdate_register_subsystem(struct liveupdate_subsystem *h) +{ + struct liveupdate_subsystem *iter; + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + luo_state_read_exit(); + return -EBUSY; + } + + mutex_lock(&luo_subsystem_list_mutex); + list_for_each_entry(iter, &luo_subsystems_list, list) { + if (iter =3D=3D h) { + pr_warn("Subsystem '%s' (%p) already registered.\n", + h->name, h); + ret =3D -EEXIST; + goto out_unlock; + } + + if (!strcmp(iter->name, h->name)) { + pr_err("Subsystem with name '%s' already registered.\n", + h->name); + ret =3D -EEXIST; + goto out_unlock; + } + } + + INIT_LIST_HEAD(&h->list); + list_add_tail(&h->list, &luo_subsystems_list); + +out_unlock: + mutex_unlock(&luo_subsystem_list_mutex); + luo_state_read_exit(); + + return ret; +} +EXPORT_SYMBOL_GPL(liveupdate_register_subsystem); + +/** + * liveupdate_unregister_subsystem - Unregister a kernel subsystem handler= from + * LUO + * @h: Pointer to the same liveupdate_subsystem structure that was used du= ring + * registration. + * + * Unregisters a previously registered subsystem handler. Typically called + * during module exit or subsystem teardown. LUO removes the structure fro= m its + * internal list; the caller is responsible for any necessary memory clean= up + * of the structure itself. + * + * Return: 0 on success, negative error code otherwise. + * -EINVAL if h is NULL. + * -ENOENT if the specified handler @h is not found in the registration li= st. + * -EBUSY if LUO is not in the NORMAL state. + */ +int liveupdate_unregister_subsystem(struct liveupdate_subsystem *h) +{ + struct liveupdate_subsystem *iter; + bool found =3D false; + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + luo_state_read_exit(); + return -EBUSY; + } + + mutex_lock(&luo_subsystem_list_mutex); + list_for_each_entry(iter, &luo_subsystems_list, list) { + if (iter =3D=3D h) { + found =3D true; + break; + } + } + + if (found) { + list_del_init(&h->list); + } else { + pr_warn("Subsystem handler '%s' not found for unregistration.\n", + h->name); + ret =3D -ENOENT; + } + + mutex_unlock(&luo_subsystem_list_mutex); + luo_state_read_exit(); + + return ret; +} +EXPORT_SYMBOL_GPL(liveupdate_unregister_subsystem); + +/** + * liveupdate_get_subsystem_data - Retrieve raw private data for a subsyst= em + * from FDT. + * @h: Pointer to the liveupdate_subsystem structure representing the + * subsystem instance. The 'name' field is used to find the property. + * @data: Output pointer where the subsystem's raw private u64 data will= be + * stored via memcpy. + * + * Reads the 8-byte data property associated with the subsystem @h->name + * directly from the '/subsystems' node within the globally accessible + * 'luo_fdt_in' blob. Returns appropriate error codes if inputs are invali= d, or + * nodes/properties are missing or invalid. + * + * Return: 0 on success. -ENOENT on error. + */ +int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, u64 *dat= a) +{ + return 0; +} +EXPORT_SYMBOL_GPL(liveupdate_get_subsystem_data); diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index c2740da70958..7a130680b5f2 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -86,6 +86,39 @@ enum liveupdate_state { LIVEUPDATE_STATE_UPDATED =3D 3, }; =20 +/** + * struct liveupdate_subsystem - Represents a subsystem participating in L= UO + * @prepare: Optional. Called during LUO prepare phase. Should perform + * preparatory actions and can store a u64 handle/state + * via the 'data' pointer for use in later callbacks. + * Return 0 on success, negative error code on failure. + * @freeze: Optional. Called during LUO freeze event (before actual = jump + * to new kernel). Should perform final state saving action= s and + * can update the u64 handle/state via the 'data' pointer. = Retur: + * 0 on success, negative error code on failure. + * @cancel: Optional. Called if the live update process is canceled = after + * prepare (or freeze) was called. Receives the u64 data + * set by prepare/freeze. Used for cleanup. + * @finish: Optional. Called after the live update is finished in th= e new + * kernel. + * Receives the u64 data set by prepare/freeze. Used for cl= eanup. + * @name: Mandatory. Unique name identifying the subsystem. + * @arg: Add this argument to callback functions. + * @list: List head used internally by LUO. Should not be modified= by + * caller after registration. + * @private_data: For LUO internal use, cached value of data field. + */ +struct liveupdate_subsystem { + int (*prepare)(void *arg, u64 *data); + int (*freeze)(void *arg, u64 *data); + void (*cancel)(void *arg, u64 data); + void (*finish)(void *arg, u64 data); + const char *name; + void *arg; + struct list_head list; + u64 private_data; +}; + #ifdef CONFIG_LIVEUPDATE =20 /* Return true if live update orchestrator is enabled */ @@ -105,6 +138,10 @@ bool liveupdate_state_updated(void); */ bool liveupdate_state_normal(void); =20 +int liveupdate_register_subsystem(struct liveupdate_subsystem *h); +int liveupdate_unregister_subsystem(struct liveupdate_subsystem *h); +int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, u64 *dat= a); + #else /* CONFIG_LIVEUPDATE */ =20 static inline int liveupdate_reboot(void) @@ -127,5 +164,21 @@ static inline bool liveupdate_state_normal(void) return true; } =20 +static inline int liveupdate_register_subsystem(struct liveupdate_subsyste= m *h) +{ + return 0; +} + +static inline int liveupdate_unregister_subsystem(struct liveupdate_subsys= tem *h) +{ + return 0; +} + +static inline int liveupdate_get_subsystem_data(struct liveupdate_subsyste= m *h, + u64 *data) +{ + return -ENODATA; +} + #endif /* CONFIG_LIVEUPDATE */ #endif /* _LINUX_LIVEUPDATE_H */ --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.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 71C8F25CC6C for ; Thu, 15 May 2025 18:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333420; cv=none; b=q3SHgdPZsg10WsPUymo/FAGc1bgamxRd9GJEFYp5QxcGfYAWCzOYGU793/89KfUtl+oOToace6GKzC10sjgTK6EmAh0XDfewfWtbzekOvGl49Wq2tFEkFdzJVxfNfZTQhQ4aAiODkwNmf8/ZqHHevp/XyAEEkUfyTTsDDXoSgVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333420; c=relaxed/simple; bh=YFtHT+k/XEwn8s8NbYSX++JEXBQzRYvhNkOkYu9LKk0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=glG+NVv46dlCTf2NzaM0gJNrYyVj+ey4p1OMh4IzBUTB/Endrive1pzbU40sDSa+ntYfsZU92D+P2Q8xxKn72j/NyEXehKmvOFfadJPwWcqFzgg6a/AP405ojTDwME4H+95mcwnqVX4VlD2FuvWOgrcMSdMpv6mBpQ6x3sDYvSc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=K1u6OD1t; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="K1u6OD1t" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-476977848c4so14431281cf.1 for ; Thu, 15 May 2025 11:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333417; x=1747938217; 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=AvA/5mmwvlyXjjShgPRe3HUQDr1iF9RhOznOEeKkVGs=; b=K1u6OD1tC/z948PdhYLTwJXf3WaC9biqAgscwCPwvRqg8tLWz+61Jpajcc+DlHFmWt F+S9b4r4+d4oMiYdu/BUyIW7J9C2SXdw1XhJtbAstx+Q5P0TOb7bILlNX17MzHuwtUJQ T+x1XFY8Kvpgf9ggijgQ6+uU0XPwJcJK8R9Giz07FAIhXxCAE7xbWADrj1AmTsCCN0wt vd5G2eoEpA/Bxza2yvgppvlvm7V9PlqoPIUgZnw9Gmmr1Ddo62cdLqbb5dA9gQSC2Zfk S6A6gM8dSNo3s53mY/Wr5N0vmijABCC5GZQ7rb6FS8gA3VcpG080nFKvnKIHdBZz/Obf UUWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333417; x=1747938217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AvA/5mmwvlyXjjShgPRe3HUQDr1iF9RhOznOEeKkVGs=; b=wyG0fS6Iqm7OQzq5AZGMpMq7oNZsF1vQEo3xIrYje9GpVAS2a6iTZa03dTtlhPlj3J PpbnCqij77efV4qwgsPL6dVzAlv3N7YZlC4QMVnpFWT7rgWdifKw08grqCAw6NRFKtHC iOa7mcXJMnaDk45CqWHN3+5kGbb+r7kWwmx0X1eWw7kci51KeTrQrc9c1Io96YNgW54w Pg7j+gRy8sHG2a8ekQ/Dl7YKKCC1QLup9k+X1eW+rvpuGynwy/L/sLiFYAL4cwN+y7js c1V/Quup4ezw7djHBp0qCWV66l0UNNAsyGw2Y2ZQ9+YNXietKtVLTRyWY//kfsrYOMes Hdng== X-Forwarded-Encrypted: i=1; AJvYcCXhrnlMBOx0GHabJ8RLVpC5ZNrCaU1cOCrRVI4M2IFVZ1ZCpJtiz4qjZ65QmI4X/ttsWdsdPqqf+4MlF0c=@vger.kernel.org X-Gm-Message-State: AOJu0YzCruGUStnAxdBvkxZw1MwJMeYXXVSCoF8uvsYTyt3V0hMTj6JW +dxoPTDAnv9ysY+jrrl9J3rnRJZ2pEf3YO9LEn4ZEUV6TUnu8hUJvBFsIkWLoQhvQVA= X-Gm-Gg: ASbGncu7ctBZLkXW7iVhtiTsCFYC3i6s0MJ54FaOYL6zUwhvWSJIFrRWfWhdLZ/G0GF oJufWWxXLXSbKK6btI4A656fWF5NVnsfwZbHps2Im71li6OKb5JSsT9uU1UBFlFSIDeMPnopkZq 7VYYfOMMsejeh0iS2nvy6QAkLg4qAWFpjpFE2gjNhQ0DnhMfRiFv5DS230kL76si1nkAkIno5Ny 1qzYItkRJB3vGKXxHxLvccokFa/bjzVzhpoY0oAVzph9yLz8x3+wuG/f9IwaQhT+Dk+ZfdFQDfF 8CxZtvJT8f2JjRx87hdByuCQQUlE9Fmtorxt9pXW4B/rKVqM4l2txt5YAeZQWdOB/lW/FDbvJ3g UHiJUWN651V9QdPtaztoYkJ+Q1b5L1MrsAjlooIf/HLhH X-Google-Smtp-Source: AGHT+IGwGfafVEqszpzHfVyT1n75QQOkLMjmW8/M2osA6KUoeC67c8MFcYHqA49j/QOV7cBeHjhLpQ== X-Received: by 2002:a05:622a:4113:b0:477:e7c:a4c with SMTP id d75a77b69052e-494ae47d27fmr6871581cf.39.1747333417029; Thu, 15 May 2025 11:23:37 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:36 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 07/16] luo: luo_subsystems: implement subsystem callbacks Date: Thu, 15 May 2025 18:23:11 +0000 Message-ID: <20250515182322.117840-8-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" Implement the core logic within luo_subsystems.c to handle the invocation of registered subsystem callbacks and manage the persistence of their state via the LUO FDT. This replaces the stub implementations from the previous patch. This completes the core mechanism enabling subsystems to actively participate in the LUO state machine, execute phase-specific logic, and persist/restore a u64 state across the live update transition using the FDT. Signed-off-by: Pasha Tatashin --- drivers/misc/liveupdate/luo_subsystems.c | 133 ++++++++++++++++++++++- 1 file changed, 131 insertions(+), 2 deletions(-) diff --git a/drivers/misc/liveupdate/luo_subsystems.c b/drivers/misc/liveup= date/luo_subsystems.c index 436929a17de0..71f5f0468b0d 100644 --- a/drivers/misc/liveupdate/luo_subsystems.c +++ b/drivers/misc/liveupdate/luo_subsystems.c @@ -99,6 +99,66 @@ void __init luo_subsystems_startup(void *fdt) luo_fdt_in =3D fdt; } =20 +static void __luo_do_subsystems_cancel_calls(struct liveupdate_subsystem *= boundary_subsystem) +{ + struct liveupdate_subsystem *subsystem; + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + if (subsystem =3D=3D boundary_subsystem) + break; + + if (subsystem->cancel) { + subsystem->cancel(subsystem->arg, + subsystem->private_data); + } + subsystem->private_data =3D 0; + } +} + +static void luo_subsystems_retrieve_data_from_fdt(void) +{ + struct liveupdate_subsystem *subsystem; + int node_offset, prop_len; + const void *prop; + + if (!luo_fdt_in) + return; + + node_offset =3D fdt_subnode_offset(luo_fdt_in, 0, + LUO_SUBSYSTEMS_NODE_NAME); + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + prop =3D fdt_getprop(luo_fdt_in, node_offset, + subsystem->name, &prop_len); + + if (!prop || prop_len !=3D sizeof(u64)) { + panic("In FDt node '/%s' can't find property '%s': %s\n", + LUO_SUBSYSTEMS_NODE_NAME, subsystem->name, + fdt_strerror(node_offset)); + } + memcpy(&subsystem->private_data, prop, sizeof(u64)); + } +} + +static int luo_subsystems_commit_data_to_fdt(void) +{ + struct liveupdate_subsystem *subsystem; + int ret, node_offset; + + node_offset =3D fdt_subnode_offset(luo_fdt_out, 0, + LUO_SUBSYSTEMS_NODE_NAME); + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + ret =3D fdt_setprop(luo_fdt_out, node_offset, subsystem->name, + &subsystem->private_data, sizeof(u64)); + if (ret < 0) { + pr_err("Failed to set FDT property for subsystem '%s' %s\n", + subsystem->name, fdt_strerror(ret)); + return -ENOENT; + } + } + + return 0; +} + /** * luo_do_subsystems_prepare_calls - Calls prepare callbacks and updates F= DT * if all prepares succeed. Handles cancellation on failure. @@ -114,7 +174,29 @@ void __init luo_subsystems_startup(void *fdt) */ int luo_do_subsystems_prepare_calls(void) { - return 0; + struct liveupdate_subsystem *subsystem; + int ret; + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + if (!subsystem->prepare) + continue; + + ret =3D subsystem->prepare(subsystem->arg, + &subsystem->private_data); + if (ret < 0) { + pr_err("Subsystem '%s' prepare callback failed [%d]\n", + subsystem->name, ret); + __luo_do_subsystems_cancel_calls(subsystem); + + return ret; + } + } + + ret =3D luo_subsystems_commit_data_to_fdt(); + if (ret) + __luo_do_subsystems_cancel_calls(NULL); + + return ret; } =20 /** @@ -132,7 +214,29 @@ int luo_do_subsystems_prepare_calls(void) */ int luo_do_subsystems_freeze_calls(void) { - return 0; + struct liveupdate_subsystem *subsystem; + int ret; + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + if (!subsystem->freeze) + continue; + + ret =3D subsystem->freeze(subsystem->arg, + &subsystem->private_data); + if (ret < 0) { + pr_err("Subsystem '%s' freeze callback failed [%d]\n", + subsystem->name, ret); + __luo_do_subsystems_cancel_calls(subsystem); + + return ret; + } + } + + ret =3D luo_subsystems_commit_data_to_fdt(); + if (ret) + __luo_do_subsystems_cancel_calls(NULL); + + return ret; } =20 /** @@ -143,6 +247,16 @@ int luo_do_subsystems_freeze_calls(void) */ void luo_do_subsystems_finish_calls(void) { + struct liveupdate_subsystem *subsystem; + + luo_subsystems_retrieve_data_from_fdt(); + + list_for_each_entry(subsystem, &luo_subsystems_list, list) { + if (subsystem->finish) { + subsystem->finish(subsystem->arg, + subsystem->private_data); + } + } } =20 /** @@ -156,6 +270,8 @@ void luo_do_subsystems_finish_calls(void) */ void luo_do_subsystems_cancel_calls(void) { + __luo_do_subsystems_cancel_calls(NULL); + luo_subsystems_commit_data_to_fdt(); } =20 /** @@ -279,6 +395,19 @@ EXPORT_SYMBOL_GPL(liveupdate_unregister_subsystem); */ int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, u64 *dat= a) { + int node_offset, prop_len; + const void *prop; + + if (!luo_fdt_in || !liveupdate_state_updated()) + return -ENOENT; + + node_offset =3D fdt_subnode_offset(luo_fdt_in, 0, + LUO_SUBSYSTEMS_NODE_NAME); + prop =3D fdt_getprop(luo_fdt_in, node_offset, h->name, &prop_len); + if (!prop || prop_len !=3D sizeof(u64)) + return -ENOENT; + memcpy(data, prop, sizeof(u64)); + return 0; } EXPORT_SYMBOL_GPL(liveupdate_get_subsystem_data); --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (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 B025C265CC5 for ; Thu, 15 May 2025 18:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333423; cv=none; b=l4ULq89kZ2wyJMPBu3Sfx4lzTNhLLEAkK1dSIMDuj8qpo9NhRn2/t5RKe0edsQCp2au7MVs+hQ0UGrPBXu78ggQ3KjVXzSjgWb/C+7aRBu4UTSynoevCwA9uBtdzLXKxKIqmUGEq6DbAp+Z3goV1/fm+lbxDk+Ab+cnrKAbQLT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333423; c=relaxed/simple; bh=LNJ7Yn25BV+W1LC7/VlfM1LG6ohTFEm6NdrbazXB0S0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W0gCT7D5aWU3jufmGs0PxtJwaisrJDd0Rv5ggx/qXqInr55TsY33LlzgGLWklOk1urymkJSSr9iAPCS7N09pweA8d0+fEtTH/K1hYFGbegeD6H/k+T3z7b2+xKOuBpjnW+O/DyvvlcF9VDWDbma0BuDKAaFxqigdX5SPiM/UFDs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=yfKrWokI; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="yfKrWokI" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7c5b2472969so126964085a.1 for ; Thu, 15 May 2025 11:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333418; x=1747938218; 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=n9X5I0ERJIQ3sR+dONy6m+vwr4x0n0wOEhUsfS8F8y4=; b=yfKrWokIELvJKsaB94A729Qpw8DkOPO6B7vGDmpsNwRzGz5P1SpqK0MCne7OhRERM3 +URkADbiSGCEFdX3XpmT3sB9IzDPAxpYKOUWsPQJqrF+Wi2v0RDssjtEISzILEe8Xikk hcyDBBXe900+5VV04iBx4QMMr5/iHJVQFyfBhi7TqoohkDxdfFE23+jdKXTJ7iOgTwl2 wx7EgNLjyhgfHNUoTKdvAamvoJXyyOkVa1fL/exFeNt9e/35gXo8+f/iIbS5G8SR8mGe wBxxmRWW2XmH5tQvwmi0XWvO8fpODz3SQBaSsWaJZH3G1guJWJ05SNZDKZhDD7lrd/Ep HXFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333418; x=1747938218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n9X5I0ERJIQ3sR+dONy6m+vwr4x0n0wOEhUsfS8F8y4=; b=GKR6u3Td6oRiMhoqcxvuvyKcqSHwETj3b94a/AWVjYGJ6YFYCEh0ljy+3IvxX/rdy2 vWmtz1JGxSwPkzKNEKoGuTfmPc0y2sIjQf4BkgXsDB3yoTfFPYO8J43gV/tJlqxW0q0T rduwyE2g7lnR1VFjtC/z/iGGP/R+B5U6+NWu8ofJqtRn2JomKMLwygZxQKNt1asrJrle 1/ZqFgY6SWuYepsm0McdfxVcuqMCKhifxFwaZGnXLdmriSFC01eWXjFxUn+w5F1SZPQT EBv9cOgTd0/3H9S9PEEgDGp/GKG2aMldxawLrvRLhzBAKNMTSsfAiw2rZ5pXCF/eUMme ullQ== X-Forwarded-Encrypted: i=1; AJvYcCWCKvLKO6nKexnR0WnS0lvWHAblMzZ5/7pWwCilabZuAmHJW5wI/mo+S/yzvoikHDXgllrtvF9asAnwj4E=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3ZBFdECiXxozvV6BfT+YEF2wkNyYmZ5OTuvHkxXDzVFfNI8BY WNOReW/2GHbJ9fDCXi8ZFJv92ahdABWg/IAglSXmgubmYUFNES/+0dEChuxWE4SLQrQ= X-Gm-Gg: ASbGnctoghHFph9Z5bQ8MyfHyVu1+H6K2SMNoDwItGL8VUGTonAiKK3czOW0/ws6pdu tsMEwwD7H/98IATvvbKf881cKK0tCBrgsJ6YiU0g5G/JSKRrt0caXZPtAwag6sGQGehVFbVZa11 ZMk3jjx0W1oAGOycYhQUQxL4S+9hr04WdCh5/ptZuNQipLJ/f7+pxvhG+vr4UZFW0MfRz+5oQE0 IZBjNjL60YfuTfWd8xcjDgeRVAfwovvNhrzWLiy2dulitPL2jlmV93S5hWtYnDMqlCgKOT+t4Em +mMgZQVOujc3Pn0UjNi/5u4gcJKopCewxQtPbWgY6m3aKfA3gbVa1G78X1cEfKSsr50sbzgdCRW BtRqQkVTMdcrJeWTgKpS42c9V/Lv6AuaW+th9npA5dV52 X-Google-Smtp-Source: AGHT+IHjVBt8H6HfJ0JCB/KGKK5fDmLxLCaQwGuXFQZwwfyBbHpU4K4wMmeetHkz+S+qBh3MPxccnw== X-Received: by 2002:a05:620a:261b:b0:7ca:e8cc:5f08 with SMTP id af79cd13be357-7cd467241fbmr93206085a.23.1747333418244; Thu, 15 May 2025 11:23:38 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:37 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 08/16] luo: luo_files: add infrastructure for FDs Date: Thu, 15 May 2025 18:23:12 +0000 Message-ID: <20250515182322.117840-9-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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 the framework within LUO to support preserving specific types of file descriptors across a live update transition. This allows stateful FDs (like memfds or vfio FDs used by VMs) to be recreated in the new kernel. Note: The core logic for iterating through the luo_files_list and invoking the handler callbacks (prepare, freeze, cancel, finish) within luo_do_files_*_calls, as well as managing the u64 data persistence via the FDT for individual files, is currently implemented as stubs in this patch. This patch sets up the registration, FDT layout, and retrieval framework. Signed-off-by: Pasha Tatashin --- drivers/misc/liveupdate/Makefile | 1 + drivers/misc/liveupdate/luo_core.c | 19 + drivers/misc/liveupdate/luo_files.c | 563 +++++++++++++++++++++++++ drivers/misc/liveupdate/luo_internal.h | 11 + include/linux/liveupdate.h | 62 +++ 5 files changed, 656 insertions(+) create mode 100644 drivers/misc/liveupdate/luo_files.c diff --git a/drivers/misc/liveupdate/Makefile b/drivers/misc/liveupdate/Mak= efile index df1c9709ba4f..b4cdd162574f 100644 --- a/drivers/misc/liveupdate/Makefile +++ b/drivers/misc/liveupdate/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-y +=3D luo_core.o +obj-y +=3D luo_files.o obj-y +=3D luo_subsystems.o diff --git a/drivers/misc/liveupdate/luo_core.c b/drivers/misc/liveupdate/l= uo_core.c index 417e7f6bf36c..ab1d76221fe2 100644 --- a/drivers/misc/liveupdate/luo_core.c +++ b/drivers/misc/liveupdate/luo_core.c @@ -110,6 +110,10 @@ static int luo_fdt_setup(struct kho_serialization *ser) if (ret) goto exit_free; =20 + ret =3D luo_files_fdt_setup(fdt_out); + if (ret) + goto exit_free; + ret =3D luo_subsystems_fdt_setup(fdt_out); if (ret) goto exit_free; @@ -145,7 +149,13 @@ static int luo_do_prepare_calls(void) { int ret; =20 + ret =3D luo_do_files_prepare_calls(); + if (ret) + return ret; + ret =3D luo_do_subsystems_prepare_calls(); + if (ret) + luo_do_files_cancel_calls(); =20 return ret; } @@ -154,18 +164,26 @@ static int luo_do_freeze_calls(void) { int ret; =20 + ret =3D luo_do_files_freeze_calls(); + if (ret) + return ret; + ret =3D luo_do_subsystems_freeze_calls(); + if (ret) + luo_do_files_cancel_calls(); =20 return ret; } =20 static void luo_do_finish_calls(void) { + luo_do_files_finish_calls(); luo_do_subsystems_finish_calls(); } =20 static void luo_do_cancel_calls(void) { + luo_do_files_cancel_calls(); luo_do_subsystems_cancel_calls(); } =20 @@ -436,6 +454,7 @@ static int __init luo_startup(void) } =20 __luo_set_state(LIVEUPDATE_STATE_UPDATED); + luo_files_startup(luo_fdt_in); luo_subsystems_startup(luo_fdt_in); =20 return 0; diff --git a/drivers/misc/liveupdate/luo_files.c b/drivers/misc/liveupdate/= luo_files.c new file mode 100644 index 000000000000..953fc40db3d7 --- /dev/null +++ b/drivers/misc/liveupdate/luo_files.c @@ -0,0 +1,563 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO file descriptors + * + * LUO provides the infrastructure necessary to preserve + * specific types of stateful file descriptors across a kernel live + * update transition. The primary goal is to allow workloads, such as virt= ual + * machines using vfio, memfd, or iommufd to retain access to their essent= ial + * resources without interruption after the underlying kernel is updated. + * + * The framework operates based on handler registration and instance track= ing: + * + * 1. Handler Registration: Kernel modules responsible for specific file + * types (e.g., memfd, vfio) register a &struct liveupdate_filesystem + * handler. This handler contains callbacks (&liveupdate_filesystem.prepar= e, + * &liveupdate_filesystem.freeze, &liveupdate_filesystem.finish, etc.) + * and a unique 'compatible' string identifying the file type. + * Registration occurs via liveupdate_register_filesystem(). + * + * 2. File Instance Tracking: When a potentially preservable file needs to= be + * managed for live update, the core LUO logic (luo_register_file()) finds= a + * compatible registered handler using its &liveupdate_filesystem.can_pres= erve + * callback. If found, an internal &struct luo_file instance is created, + * assigned a unique u64 'token', and added to a list. + * + * 3. State Persistence (FDT): During the LUO prepare/freeze phases, the + * registered handler callbacks are invoked for each tracked file instance. + * These callbacks can generate a u64 data payload representing the minimal + * state needed for restoration. This payload, along with the handler's + * compatible string and the unique token, is stored in a dedicated + * '/file-descriptors' node within the main LUO FDT blob passed via + * Kexec Handover (KHO). + * + * 4. Restoration: In the new kernel, the LUO framework parses the incoming + * FDT to reconstruct the list of &struct luo_file instances. When the + * original owner requests the file, luo_retrieve_file() uses the correspo= nding + * handler's &liveupdate_filesystem.retrieve callback, passing the persist= ed + * u64 data, to recreate or find the appropriate &struct file object. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include "luo_internal.h" + +#define LUO_FILES_NODE_NAME "file-descriptors" +#define LUO_FILES_COMPATIBLE "file-descriptors-v1" + +static DEFINE_XARRAY(luo_files_xa_in); +static DEFINE_XARRAY(luo_files_xa_out); +static bool luo_files_xa_in_recreated; + +/* Regestred filesystems. */ +static DECLARE_RWSEM(luo_filesystems_list_rwsem); +static LIST_HEAD(luo_filesystems_list); + +static void *luo_fdt_out; +static void *luo_fdt_in; + +static u64 luo_next_file_token; + +/** + * struct luo_file - Represents a file descriptor instance preserved + * across live update. + * @fs: Pointer to the &struct liveupdate_filesystems containing + * the implementation of prepare, freeze, cancel, and fini= sh + * operations specific to this file's type. + * @file: A pointer to the kernel's &struct file object represent= ing + * the open file descriptor that is being preserved. + * @private_data: Internal storage used by the live update core framework + * between phases. + * @reclaimed: Flag indicating whether this preserved file descriptor = has + * been successfully 'reclaimed' (e.g., requested via an i= octl) + * by user-space or the owning kernel subsystem in the new + * kernel after the live update. + * @state: The current state of file descriptor, it is allowed to + * prepare, freeze, and finish FDs before the global state + * switch. + * @mutex: Lock to protect FD state, and allow independently to c= hange + * the FD state compared to global state. + * + * This structure holds the necessary callbacks and context for managing a + * specific open file descriptor throughout the different phases of a live + * update process. Instances of this structure are typically allocated, + * populated with file-specific details (&file, &arg, callbacks, compatibi= lity + * string, token), and linked into a central list managed by the LUO. The + * private_data field is used internally by the core logic to store state + * between phases. + */ +struct luo_file { + struct liveupdate_filesystem *fs; + struct file *file; + u64 private_data; + bool reclaimed; + enum liveupdate_state state; + struct mutex mutex; +}; + +/** + * luo_files_startup - Validates the LUO file-descriptors FDT node at star= tup. + * @fdt: Pointer to the LUO FDT blob passed from the previous kernel. + * + * This __init function checks the existence and validity of the + * '/file-descriptors' node in the FDT. This node is considered mandatory.= It + * calls panic() if the node is missing, inaccessible, or invalid (e.g., m= issing + * compatible, wrong compatible string), indicating a critical configurati= on + * error for LUO. + */ +void __init luo_files_startup(void *fdt) +{ + int ret, node_offset; + + node_offset =3D fdt_subnode_offset(fdt, 0, LUO_FILES_NODE_NAME); + if (node_offset < 0) + panic("Failed to find /file-descriptors node\n"); + + ret =3D fdt_node_check_compatible(fdt, node_offset, + LUO_FILES_COMPATIBLE); + if (ret) { + panic("FDT '%s' is incompatible with '%s' [%d]\n", + LUO_FILES_NODE_NAME, LUO_FILES_COMPATIBLE, ret); + } + luo_fdt_in =3D fdt; +} + +static void luo_files_recreate_luo_files_xa_in(void) +{ + int parent_node_offset, file_node_offset; + const char *node_name, *fdt_compat_str; + struct liveupdate_filesystem *fs; + struct luo_file *luo_file; + const void *data_ptr; + int ret =3D 0; + + if (luo_files_xa_in_recreated || !luo_fdt_in) + return; + + /* Take write in order to gurantee that we re-create list once */ + down_write(&luo_filesystems_list_rwsem); + if (luo_files_xa_in_recreated) + goto exit_unlock; + + parent_node_offset =3D fdt_subnode_offset(luo_fdt_in, 0, + LUO_FILES_NODE_NAME); + + fdt_for_each_subnode(file_node_offset, luo_fdt_in, parent_node_offset) { + bool handler_found =3D false; + u64 token; + + node_name =3D fdt_get_name(luo_fdt_in, file_node_offset, NULL); + if (!node_name) { + panic("Skipping FDT subnode at offset %d: Cannot get name\n", + file_node_offset); + } + + ret =3D kstrtou64(node_name, 0, &token); + if (ret < 0) { + panic("Skipping FDT node '%s': Failed to parse token\n", + node_name); + } + + fdt_compat_str =3D fdt_getprop(luo_fdt_in, file_node_offset, + "compatible", NULL); + if (!fdt_compat_str) { + panic("Skipping FDT node '%s': Missing 'compatible' property\n", + node_name); + } + + data_ptr =3D fdt_getprop(luo_fdt_in, file_node_offset, "data", + NULL); + if (!data_ptr) { + panic("Can't recover property 'data' for FDT node '%s'\n", + node_name); + } + + list_for_each_entry(fs, &luo_filesystems_list, list) { + if (!strcmp(fs->compatible, fdt_compat_str)) { + handler_found =3D true; + break; + } + } + + if (!handler_found) { + panic("Skipping FDT node '%s': No registered handler for compatible '%s= '\n", + node_name, fdt_compat_str); + } + + luo_file =3D kmalloc(sizeof(*luo_file), + GFP_KERNEL | __GFP_NOFAIL); + luo_file->fs =3D fs; + luo_file->file =3D NULL; + memcpy(&luo_file->private_data, data_ptr, sizeof(u64)); + luo_file->reclaimed =3D false; + mutex_init(&luo_file->mutex); + luo_file->state =3D LIVEUPDATE_STATE_UPDATED; + ret =3D xa_err(xa_store(&luo_files_xa_in, token, luo_file, + GFP_KERNEL | __GFP_NOFAIL)); + if (ret < 0) { + panic("Failed to store luo_file for token %llu in XArray: %d\n", + token, ret); + } + } + luo_files_xa_in_recreated =3D true; + +exit_unlock: + up_write(&luo_filesystems_list_rwsem); +} + +/** + * luo_files_fdt_setup - Adds and populates the 'file-descriptors' node in= the + * FDT. + * @fdt: Pointer to the LUO FDT blob. + * + * Add file-descriptors node and each FD node to the LUO FDT blob. + * + * Returns: 0 on success, negative errno on failure. + */ +int luo_files_fdt_setup(void *fdt) +{ + int ret, files_node_offset, node_offset; + const u64 zero_data =3D 0; + unsigned long token; + struct luo_file *h; + char token_str[19]; + + ret =3D fdt_add_subnode(fdt, 0, LUO_FILES_NODE_NAME); + if (ret < 0) + goto exit_error; + + files_node_offset =3D ret; + ret =3D fdt_setprop_string(fdt, files_node_offset, "compatible", + LUO_FILES_COMPATIBLE); + if (ret < 0) + goto exit_error; + + xa_for_each(&luo_files_xa_out, token, h) { + snprintf(token_str, sizeof(token_str), "%#0llx", (u64)token); + + ret =3D fdt_add_subnode(fdt, files_node_offset, token_str); + if (ret < 0) + goto exit_error; + + node_offset =3D ret; + ret =3D fdt_setprop_string(fdt, node_offset, "compatible", + h->fs->compatible); + if (ret < 0) + goto exit_error; + + ret =3D fdt_setprop(fdt, node_offset, "data", + &zero_data, sizeof(zero_data)); + } + + luo_fdt_out =3D fdt; + + return 0; +exit_error: + pr_err("Failed to setup 'file-descriptors' node to FDT: %s\n", + fdt_strerror(ret)); + return -ENOSPC; +} + +/** + * luo_do_files_prepare_calls - Calls prepare callbacks and updates FDT + * if all prepares succeed. Handles cancellation on failure. + * + * Phase 1: Calls 'prepare' for all files and stores results temporarily. + * If any 'prepare' fails, calls 'cancel' on previously prepared files + * and returns the error. + * Phase 2: If all 'prepare' calls succeeded, writes the stored data to th= e FDT. + * If any FDT write fails, calls 'cancel' on *all* prepared files and + * returns the FDT error. + * + * Returns: 0 on success. Negative errno on failure. + */ +int luo_do_files_prepare_calls(void) +{ + return 0; +} + +/** + * luo_do_files_freeze_calls - Calls freeze callbacks and updates FDT + * if all calls succeed. Handles cancellation on failure. + * + * Phase 1: Calls 'freeze' for all files and stores results temporarily. + * If any 'freeze' fails, calls 'cancel' on previously called files. + * and returns the error. + * Phase 2: If all 'freeze' calls succeeded, writes the stored data to the= FDT. + * If any FDT write fails, calls 'cancel' on *all* files and returns the F= DT + * error. + * + * Returns: 0 on success. Negative errno on failure. + */ +int luo_do_files_freeze_calls(void) +{ + return 0; +} + +/** + * luo_do_files_finish_calls - Calls finish callbacks for all file descrip= tors. + * + * This function is called at the end of live update cycle to do the final + * clean-up or housekeeping of the post-live update states. + */ +void luo_do_files_finish_calls(void) +{ + luo_files_recreate_luo_files_xa_in(); +} + +/** + * luo_do_files_cancel_calls - Calls cancel callbacks for all file descrip= tors. + * + * This function is typically called when the live update process needs to= be + * aborted externally, for example, after the prepare phase may have run b= ut + * before actual reboot. It iterates through all registered files and calls + * the 'cancel' callback for those that implement it and likely completed + * prepare. + */ +void luo_do_files_cancel_calls(void) +{ +} + +/** + * luo_register_file - Register a file descriptor for live update manageme= nt. + * @tokenp: Return argument for the token value. + * @file: Pointer to the struct file to be preserved. + * + * Context: Must be called when LUO is in 'normal' state. + * + * Return: 0 on success. Negative errno on failure. + */ +int luo_register_file(u64 *tokenp, struct file *file) +{ + struct liveupdate_filesystem *fs; + bool found =3D false; + int ret =3D -ENOENT; + u64 token; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + pr_warn("File can be registered only in normal or prepared state\n"); + luo_state_read_exit(); + return -EBUSY; + } + + down_read(&luo_filesystems_list_rwsem); + list_for_each_entry(fs, &luo_filesystems_list, list) { + if (fs->can_preserve(file, fs->arg)) { + found =3D true; + break; + } + } + + if (found) { + struct luo_file *luo_file =3D kmalloc(sizeof(*luo_file), + GFP_KERNEL); + + if (!luo_file) { + ret =3D -ENOMEM; + goto exit_unlock; + } + + token =3D luo_next_file_token; + luo_next_file_token++; + + luo_file->private_data =3D 0; + luo_file->reclaimed =3D false; + + luo_file->file =3D file; + luo_file->fs =3D fs; + mutex_init(&luo_file->mutex); + luo_file->state =3D LIVEUPDATE_STATE_NORMAL; + ret =3D xa_err(xa_store(&luo_files_xa_out, token, luo_file, + GFP_KERNEL)); + if (ret < 0) { + pr_warn("Failed to store file for token %llu in XArray: %d\n", + token, ret); + kfree(luo_file); + goto exit_unlock; + } + *tokenp =3D token; + } + +exit_unlock: + up_read(&luo_filesystems_list_rwsem); + luo_state_read_exit(); + + return ret; +} + +/** + * luo_unregister_file - Unregister a file instance using its token. + * @token: The unique token of the file instance to unregister. + * + * Finds the &struct luo_file associated with the @token in the + * global list and removes it. This function *only* removes the entry from= the + * list; it does *not* free the memory allocated for the &struct luo_file + * itself. The caller is responsible for freeing the structure after this + * function returns successfully. + * + * Context: Can be called when a preserved file descriptor is closed or + * no longer needs live update management. Uses down_write_killable + * for list modification. + * + * Return: 0 on success. Negative errno on failure. + */ +int luo_unregister_file(u64 token) +{ + struct luo_file *luo_file; + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + pr_warn("File can be unregistered only in normal or updates state\n"); + luo_state_read_exit(); + return -EBUSY; + } + + luo_file =3D xa_erase(&luo_files_xa_out, token); + if (luo_file) { + kfree(luo_file); + } else { + pr_warn("Failed to unregister: token %llu not found.\n", + token); + ret =3D -ENOENT; + } + luo_state_read_exit(); + + return ret; +} + +/** + * luo_retrieve_file - Find a registered file instance by its token. + * @token: The unique token of the file instance to retrieve. + * @file: Output parameter. On success (return value 0), this will point + * to the retrieved "struct file". + * + * Searches the global list for a &struct luo_file matching the @token. Us= es a + * read lock, allowing concurrent retrievals. + * + * Return: 0 on success. Negative errno on failure. + */ +int luo_retrieve_file(u64 token, struct file **file) +{ + struct luo_file *luo_file; + int ret =3D 0; + + luo_files_recreate_luo_files_xa_in(); + luo_state_read_enter(); + if (!liveupdate_state_updated()) { + pr_warn("File can be retrieved only in updated state\n"); + luo_state_read_exit(); + return -EBUSY; + } + + luo_file =3D xa_load(&luo_files_xa_in, token); + if (luo_file && !luo_file->reclaimed) { + luo_file->reclaimed =3D true; + ret =3D luo_file->fs->retrieve(luo_file->fs->arg, + luo_file->private_data, + file); + if (!ret) + luo_file->file =3D *file; + } else if (luo_file && luo_file->reclaimed) { + pr_err("The file descriptor for token %lld has already been retrieved\n", + token); + ret =3D -EINVAL; + } else { + ret =3D -ENOENT; + } + + luo_state_read_exit(); + + return ret; +} + +/** + * liveupdate_register_filesystem - Register a filesystem handler with LUO. + * @fs: Pointer to a caller-allocated &struct liveupdate_filesystem. + * The caller must initialize this structure, including a unique + * 'compatible' string and a valid 'fs' callbacks. This function adds the + * handler to the global list of supported filesystem handlers. + * + * Context: Typically called during module initialization for filesystems = or + * file types that support live update preservation. + * + * Return: 0 on success. Negative errno on failure. + */ +int liveupdate_register_filesystem(struct liveupdate_filesystem *fs) +{ + struct liveupdate_filesystem *fs_iter; + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + luo_state_read_exit(); + return -EBUSY; + } + + down_write(&luo_filesystems_list_rwsem); + list_for_each_entry(fs_iter, &luo_filesystems_list, list) { + if (!strcmp(fs_iter->compatible, fs->compatible)) { + pr_err("Filesystem handler registration failed: Compatible string '%s' = already registered.\n", + fs->compatible); + ret =3D -EEXIST; + goto exit_unlock; + } + } + + INIT_LIST_HEAD(&fs->list); + list_add_tail(&fs->list, &luo_filesystems_list); + +exit_unlock: + up_write(&luo_filesystems_list_rwsem); + luo_state_read_exit(); + + return ret; +} +EXPORT_SYMBOL_GPL(liveupdate_register_filesystem); + +/** + * liveupdate_unregister_filesystem - Unregister a filesystem handler. + * @fs: Pointer to the specific &struct liveupdate_filesystem instance + * that was previously returned by or passed to liveupdate_register_filesy= stem. + * + * Removes the specified handler instance @fs from the global list of + * registered filesystem handlers. This function only removes the entry fr= om the + * list; it does not free the memory associated with @fs itself. The caller + * is responsible for freeing the structure memory after this function ret= urns + * successfully. + * + * Return: 0 on success. Negative errno on failure. + */ +int liveupdate_unregister_filesystem(struct liveupdate_filesystem *fs) +{ + int ret =3D 0; + + luo_state_read_enter(); + if (!liveupdate_state_normal() && !liveupdate_state_updated()) { + luo_state_read_exit(); + return -EBUSY; + } + + down_write(&luo_filesystems_list_rwsem); + list_del_init(&fs->list); + up_write(&luo_filesystems_list_rwsem); + luo_state_read_exit(); + + return ret; +} +EXPORT_SYMBOL_GPL(liveupdate_unregister_filesystem); diff --git a/drivers/misc/liveupdate/luo_internal.h b/drivers/misc/liveupda= te/luo_internal.h index 63a8b93254a6..b7a0f31ddc99 100644 --- a/drivers/misc/liveupdate/luo_internal.h +++ b/drivers/misc/liveupdate/luo_internal.h @@ -23,6 +23,17 @@ int luo_do_subsystems_freeze_calls(void); void luo_do_subsystems_finish_calls(void); void luo_do_subsystems_cancel_calls(void); =20 +void luo_files_startup(void *fdt); +int luo_files_fdt_setup(void *fdt); +int luo_do_files_prepare_calls(void); +int luo_do_files_freeze_calls(void); +void luo_do_files_finish_calls(void); +void luo_do_files_cancel_calls(void); + +int luo_retrieve_file(u64 token, struct file **file); +int luo_register_file(u64 *token, struct file *file); +int luo_unregister_file(u64 token); + extern const char *const luo_state_str[]; =20 /* Get the current state as a string */ diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index 7a130680b5f2..7afe0aac5ce4 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -86,6 +86,55 @@ enum liveupdate_state { LIVEUPDATE_STATE_UPDATED =3D 3, }; =20 +/* Forward declaration needed if definition isn't included */ +struct file; + +/** + * struct liveupdate_filesystem - Represents a handler for a live-updatable + * filesystem/file type. + * @prepare: Optional. Saves state for a specific file instance (@fi= le, + * @arg) before update, potentially returning value via @d= ata. + * Returns 0 on success, negative errno on failure. + * @freeze: Optional. Performs final actions just before kernel + * transition, potentially reading/updating the handle via + * @data. + * Returns 0 on success, negative errno on failure. + * @cancel: Optional. Cleans up state/resources if update is aborted + * after prepare/freeze succeeded, using the @data handle = (by + * value) from the successful prepare. Returns void. + * @finish: Optional. Performs final cleanup in the new kernel usin= g the + * preserved @data handle (by value). Returns void. + * @retrieve: Retrieve the preserved file. Must be called before fini= sh. + * @can_preserve: callback to determine if @file with associated context = (@arg) + * can be preserved by this handler. + * Return bool (true if preservable, false otherwise). + * @compatible: The compatibility string (e.g., "memfd-v1", "vfiofd-v1") + * that uniquely identifies the filesystem or file type th= is + * handler supports. This is matched against the compatible + * string associated with individual &struct liveupdate_fi= le + * instances. + * @arg: An opaque pointer to implementation-specific context da= ta + * associated with this filesystem handler registration. + * @list: used for linking this handler instance into a global li= st of + * registered filesystem handlers. + * + * Modules that want to support live update for specific file types should + * register an instance of this structure. LUO uses this registration to + * determine if a given file can be preserved and to find the appropriate + * operations to manage its state across the update. + */ +struct liveupdate_filesystem { + int (*prepare)(struct file *file, void *arg, u64 *data); + int (*freeze)(struct file *file, void *arg, u64 *data); + void (*cancel)(struct file *file, void *arg, u64 data); + void (*finish)(struct file *file, void *arg, u64 data, bool reclaimed); + int (*retrieve)(void *arg, u64 data, struct file **file); + bool (*can_preserve)(struct file *file, void *arg); + const char *compatible; + void *arg; + struct list_head list; +}; + /** * struct liveupdate_subsystem - Represents a subsystem participating in L= UO * @prepare: Optional. Called during LUO prepare phase. Should perform @@ -142,6 +191,9 @@ int liveupdate_register_subsystem(struct liveupdate_sub= system *h); int liveupdate_unregister_subsystem(struct liveupdate_subsystem *h); int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, u64 *dat= a); =20 +int liveupdate_register_filesystem(struct liveupdate_filesystem *h); +int liveupdate_unregister_filesystem(struct liveupdate_filesystem *h); + #else /* CONFIG_LIVEUPDATE */ =20 static inline int liveupdate_reboot(void) @@ -180,5 +232,15 @@ static inline int liveupdate_get_subsystem_data(struct= liveupdate_subsystem *h, return -ENODATA; } =20 +static inline int liveupdate_register_filesystem(struct liveupdate_filesys= tem *h) +{ + return 0; +} + +static inline int liveupdate_unregister_filesystem(struct liveupdate_files= ystem *h) +{ + return 0; +} + #endif /* CONFIG_LIVEUPDATE */ #endif /* _LINUX_LIVEUPDATE_H */ --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 EB54E266577 for ; Thu, 15 May 2025 18:23:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333422; cv=none; b=bMJK1Vd+apO/pGMICqKXkHygXfAKOdXWsSMtLUnUw2iRIAZwI/DwGLDNrTeNQDRRC+wOBhnx+f0mLSmqzVhx63jA9OmNZ2bc0B/s8/x6xovCFrnTYBV4ny14rStum604STWab2mGjlqBpjHtcVgGdzKvhy5jXO70FvUDqlKeo8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333422; c=relaxed/simple; bh=ZYEq4Qh4meJf6SEZCS3Xk5gBfGj3zxwgCJBcjhweYoU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=naF1yOnzA+3QbaOjvhwISB+i5IvB37EuMG/BHn5MdGmc8ccgjXLon+52OHVp8dZFbs6aMDA7y4EEvwSVHoXDpZPPr15chN1QHgB/r9V/KtdTicqXRqc+XnsThaI1FgZgvU364GbSnv0huaTSb0IrGzvg8KEo+pcgs40z/2TULnY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=TQLytnyf; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="TQLytnyf" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7c53b9d66fdso164122085a.3 for ; Thu, 15 May 2025 11:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333420; x=1747938220; 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=fncEWK+MZKkah5dMCpMCDEnPbBrReOK9LaFvpIbRDZQ=; b=TQLytnyfACZ56nAAqaoOX78fcOuFFDmiGBvnbS0FKD3oubWur/q/pjixqE76OSVC6N z1ZsrpqmTWWUKJpKUC8g7fBXP4mmfx29UBp9S+S3rnriSaakHljr/skqBoUcHNf2TYv1 NzV5IUHmtftA/KMxB81fFVpnCRBz+hMXm5u+0pSpUm6STcaU06epA6HhEPDvf5nOpsbp 7XGmml+7T8wH2EX49yJEwTzyPdS0+5Y80Z2KQ5Vt1uOf00e8aFB43NnUZsKPVucxupMs CpnnuwhtAfx98nFbPxMcgEMrKPAEclpEk+I/8bu7a9eWinwDVRkQCsg5yTxOJBLJvTTU CnWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333420; x=1747938220; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fncEWK+MZKkah5dMCpMCDEnPbBrReOK9LaFvpIbRDZQ=; b=a2jht05Wv9152FC+5a77fLYH00toq48asHYbz/0Rg2sMYXTfKTjQlLgJzHP1qoh4Vf GG3C9Uv/DmzeiQ2w2Lz1+B4FITw0zuKbVVTsFh+zginwV3kIsbyxR4uOTB9qAE4tumG/ p/oHfxVAUzvnaXpQElT5UBKUfx6lru6Q13Z/BbfF21vfTYQPdwBFSGmrdJk0JZeIGPjL a+pSBzTp7pP6rNAOK1qda9FhgmnOZXmaDYEzBMA3CluKgzMLYSCo5ViDJN9TGhJPsV2w 3J3iZI4BjSPIJI6kP5A9uSA3qCUR9Dd2zqDszLVLDc3J57R8kp1Fs+s/WSM1+nbqXAMe FbQA== X-Forwarded-Encrypted: i=1; AJvYcCVV0WeW4pOp36N6DpGyFEmC83SFZZMgTtMuonEo6cTjVl4Aqaly5cyd1wwI5C4s1RdaZBBpFtHiRRMnz2M=@vger.kernel.org X-Gm-Message-State: AOJu0Yxfxv77xXzjbecgXdl/l5Xwpiz84EM2DK/CCrHZsW4gGHThRG/6 rZopIrfBzXtr33pYrTqADrmpTCQdqbMvQgUdpOruAhGpd1a/fSCLgeoVKUJAAgfYrpU= X-Gm-Gg: ASbGncth6akzPy8T249s2/4olrK+BkLgQON70DOce4+XL4/BkZtf8N1UKBlUx4GKYmW y41VdTvWQiFoNEoYslA+1qOA15pPGji1wjFKwBbWGZ2dWRuHxKw/LwPVfU3aQiWsgqfhAod2vNz iJbWyBbEcj5wDrf/7e7iGDsOZlXdIOa7EN1GQPsn1sHXrbZUII+X5T0HAwYm1nL+ngvRVqh9IIg ENmwh1OhYh1Fj9yIialKWZEyUinmOvSU05gKbNv0oSsXdleBtoNj9OGItyfc9WMxWjjidmDArlR Gi4LQY9CPONnpMLzwjoS2CBBWAnRcwZiQU+jZ9RoAwWZdoWCok6JdADeZxgvrkp9oPiVawEx4z7 SxL7htFFdrgA9Q5Ko3Ymi9GK8URTVglyDCDP7i8BBTuo0qMh5wo0iwqw= X-Google-Smtp-Source: AGHT+IF6BdiwFI8/g0r4fDQt5wq8NzbRLR+StKi364/jhbEBEOuKAsf85B0QaQPF6JgbzPbIYHnMjA== X-Received: by 2002:a05:620a:24d6:b0:7c5:562d:ccfa with SMTP id af79cd13be357-7cd46792d1dmr78474085a.36.1747333419419; Thu, 15 May 2025 11:23:39 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:39 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 09/16] luo: luo_files: implement file systems callbacks Date: Thu, 15 May 2025 18:23:13 +0000 Message-ID: <20250515182322.117840-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" Implements the core logic within luo_files.c to invoke the prepare, reboot, finish, and cancel callbacks for preserved file instances, replacing the previous stub implementations. It also handles the persistence and retrieval of the u64 data payload associated with each file via the LUO FDT. This completes the core mechanism enabling registered filesystem handlers to actively manage file state across the live update transition using the LUO framework. Signed-off-by: Pasha Tatashin --- drivers/misc/liveupdate/luo_files.c | 105 +++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 2 deletions(-) diff --git a/drivers/misc/liveupdate/luo_files.c b/drivers/misc/liveupdate/= luo_files.c index 953fc40db3d7..091bf07e051a 100644 --- a/drivers/misc/liveupdate/luo_files.c +++ b/drivers/misc/liveupdate/luo_files.c @@ -272,6 +272,48 @@ int luo_files_fdt_setup(void *fdt) return -ENOSPC; } =20 +static void __luo_do_files_cancel_calls(struct luo_file *boundary_file) +{ + unsigned long token; + struct luo_file *h; + + xa_for_each(&luo_files_xa_out, token, h) { + if (h =3D=3D boundary_file) + break; + + if (h->fs->cancel) { + h->fs->cancel(h->file, h->fs->arg, h->private_data); + h->private_data =3D 0; + } + } +} + +static int luo_files_commit_data_to_fdt(void) +{ + int files_node_offset, node_offset, ret; + unsigned long token; + char token_str[19]; + struct luo_file *h; + + files_node_offset =3D fdt_subnode_offset(luo_fdt_out, 0, + LUO_FILES_NODE_NAME); + xa_for_each(&luo_files_xa_out, token, h) { + snprintf(token_str, sizeof(token_str), "%#0llx", (u64)token); + node_offset =3D fdt_subnode_offset(luo_fdt_out, + files_node_offset, + token_str); + ret =3D fdt_setprop(luo_fdt_out, node_offset, "data", + &h->private_data, sizeof(h->private_data)); + if (ret < 0) { + pr_err("Failed to set data property for token %s: %s\n", + token_str, fdt_strerror(ret)); + return -ENOSPC; + } + } + + return 0; +} + /** * luo_do_files_prepare_calls - Calls prepare callbacks and updates FDT * if all prepares succeed. Handles cancellation on failure. @@ -287,7 +329,29 @@ int luo_files_fdt_setup(void *fdt) */ int luo_do_files_prepare_calls(void) { - return 0; + unsigned long token; + struct luo_file *h; + int ret; + + xa_for_each(&luo_files_xa_out, token, h) { + if (h->fs->prepare) { + ret =3D h->fs->prepare(h->file, h->fs->arg, + &h->private_data); + if (ret < 0) { + pr_err("Prepare failed for file token %#0llx handler '%s' [%d]\n", + (u64)token, h->fs->compatible, ret); + __luo_do_files_cancel_calls(h); + + return ret; + } + } + } + + ret =3D luo_files_commit_data_to_fdt(); + if (ret) + __luo_do_files_cancel_calls(NULL); + + return ret; } =20 /** @@ -305,7 +369,29 @@ int luo_do_files_prepare_calls(void) */ int luo_do_files_freeze_calls(void) { - return 0; + unsigned long token; + struct luo_file *h; + int ret; + + xa_for_each(&luo_files_xa_out, token, h) { + if (h->fs->freeze) { + ret =3D h->fs->freeze(h->file, h->fs->arg, + &h->private_data); + if (ret < 0) { + pr_err("Freeze callback failed for file token %#0llx handler '%s' [%d]= \n", + (u64)token, h->fs->compatible, ret); + __luo_do_files_cancel_calls(h); + + return ret; + } + } + } + + ret =3D luo_files_commit_data_to_fdt(); + if (ret) + __luo_do_files_cancel_calls(NULL); + + return ret; } =20 /** @@ -316,7 +402,20 @@ int luo_do_files_freeze_calls(void) */ void luo_do_files_finish_calls(void) { + unsigned long token; + struct luo_file *h; + luo_files_recreate_luo_files_xa_in(); + xa_for_each(&luo_files_xa_in, token, h) { + mutex_lock(&h->mutex); + if (h->state =3D=3D LIVEUPDATE_STATE_UPDATED && h->fs->finish) { + h->fs->finish(h->file, h->fs->arg, + h->private_data, + h->reclaimed); + h->state =3D LIVEUPDATE_STATE_NORMAL; + } + mutex_unlock(&h->mutex); + } } =20 /** @@ -330,6 +429,8 @@ void luo_do_files_finish_calls(void) */ void luo_do_files_cancel_calls(void) { + __luo_do_files_cancel_calls(NULL); + luo_files_commit_data_to_fdt(); } =20 /** --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (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 75D6E266B66 for ; Thu, 15 May 2025 18:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333425; cv=none; b=OSpV21vRD7JFK3PbOBkN80+k/TWUd5ISKzat5/Sx4Yfm59q0U7II56ARPvJHooJcgf6E/gFDeqRQ/vJSN0+Mmib1ckdBAVprqmmYLkx3O9+it0OaUf5qjiKpCfBzFwj46GxAnaTHaprcMXKc4cgXOHW1MidbBlZfTpKim0qq4wU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333425; c=relaxed/simple; bh=tFxT665V5hUDbhIWRElPYRYvVhS6iYWIrOgZou05mwI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fFQ1Rr399BMlONFUgUlIsxkh1n7FLmNe2vbu6cQGRfe+YPSULNdoiXOUP9mnHhRweoIBM7HGIFtVg1gkxQ8YM0SgFc1mwpxefSDIbljqfHe1XgeJjo/XPK75sth3BKAqF237jH1dsqCkkLQS5PZpEFELq6OuN5Wq6lvnhI1RAJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=ts4wLMsA; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="ts4wLMsA" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7c5b2472969so126970385a.1 for ; Thu, 15 May 2025 11:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333421; x=1747938221; 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=cWCx6GGcEP/Bhmxu59BlBlBS7y0637Vw+qLeLaDOFgQ=; b=ts4wLMsAB93fVBZ7Zxr41MgE5x0bXHqxEaKCtCa5huK4B35/CPB0z9lfuy3SAXUs+1 X65Qv5Ntj0uioi9r2iqps/gtKUYsSuB4O2prZaGnJirD4p9h25iQZm1xC+zrD2JHqhIq c+SGfGHhYW5/PfUUYlHpNo5RNR8bJ+b8OQI4hFTf/1VgsyQ6NBLyuBYlYKSgVQcLm4qJ EE1HkCcJzMpLAVppWCl/pfI1RY25kqRu3yNIrlC6htO6LC6mIKfHKtkb0Q1HnaC98Vdu n4Ibzt0t28moS1sdPg9zyfMPdbCN3S6hnIuuop2DFDV6dOni+j8VflZxMLxf1OcNK7R+ R4tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333421; x=1747938221; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cWCx6GGcEP/Bhmxu59BlBlBS7y0637Vw+qLeLaDOFgQ=; b=HFSfo+5RBNURCX59hln534F1x3A0HwxJxA+GI+ZB7bwNnCt0oThMMKkYVLhfkK91md qAlmqjjOSIarO1B2YPg+FKoP9cyDZtCcw8HWQAFI9JKNYsScKTiu6s9FQlyrHvH+PnqD vMuwEYSYl9O/sTTlSMLPStcByykfy8qRxu8SslVB66Z3nDx924nOj8xRzOUN5CuCr2sA grIYdYqFMQ09ztkkpWFQG6tJTaJlSSeCIO29lPI4h7H4T5kujdfBqqj9dnd4HAz5fuPa 0SeePZaNYJvUeDfmSVOpuZG0jUqxvqN3f0vLb6ZXkimHwxgIk6yQRaq9pspLr9+aCHFR K2kw== X-Forwarded-Encrypted: i=1; AJvYcCWys/NTXWd6Ky4kONDUImllqp0RPehbG8YjBYSbJIERMWlpm9yx1U6Z8I0GDnce4fHFHpvOhqFHe4Dxh48=@vger.kernel.org X-Gm-Message-State: AOJu0YyQ/eoXtoymFGV2WONvQ7tFAadA9xb1J5NjjUrgs2gV2FElJ0eg B4a1IzsrPutEyMb9VPlNZ9D5AIIXd3le9UORddnjXGwp8OTYrdTu15j2oHXB1k1/jCo= X-Gm-Gg: ASbGncv7kWLKv/0xh9YSGui9pauxaScuDnBLpuGHLNyuEIqAUdBkyacKOqZElGvUMLl cg3ZkUCi1WWmXE8vXu76Z1sHQVtzrL3YxvEQzKKAMsFxqGEeiNnuYvevzm8gkc6ySwCO6GaYzzU L6ksjyW0PZ70Kz2rI93upP29cJAYrz/zcHQN8l9yTPEe9sInWz6z6/4kQU4qzsbtaBVSWQfB3v/ m2o6LdsVlngvVgOXxfnj+2zzAtuQWYZ7ioU2YxxTqeSFa6wnWlquOsTBBgwa+skxlDLSGx5Nqxz LUyiOAcIKGxQ3YVWBISygewYcgARgQ2VUuX1cdicsad+29AfwZotaK2uU587B/56Ep89eJ9Ht54 0Ma0p06+d1AXHLAAp2E4MOI6MEDAH/0ctgiLgDw/3vDZ7 X-Google-Smtp-Source: AGHT+IEWhdlfPNILwzbLIqumfGzpcWA+Jmu5BcE2C+Ogk2n1GuY+lHsyTfj1P93f5W7qlh3TnbUPDA== X-Received: by 2002:a05:620a:2592:b0:7cd:3b02:b6e4 with SMTP id af79cd13be357-7cd46707fcfmr70839885a.1.1747333420931; Thu, 15 May 2025 11:23:40 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:40 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 10/16] luo: luo_ioctl: add ioctl interface Date: Thu, 15 May 2025 18:23:14 +0000 Message-ID: <20250515182322.117840-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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 the user-space interface for the Live Update Orchestrator via ioctl commands, enabling external control over the live update process and management of preserved resources. Create a misc character device at /dev/liveupdate. Access to this device requires the CAP_SYS_ADMIN capability. A new UAPI header, , defines the necessary structures. The magic number is registered in Documentation/userspace-api/ioctl/ioctl-number.rst. Signed-off-by: Pasha Tatashin --- .../userspace-api/ioctl/ioctl-number.rst | 1 + drivers/misc/liveupdate/Makefile | 1 + drivers/misc/liveupdate/luo_ioctl.c | 199 ++++++++++++ include/linux/liveupdate.h | 34 +- include/uapi/linux/liveupdate.h | 300 ++++++++++++++++++ 5 files changed, 502 insertions(+), 33 deletions(-) create mode 100644 drivers/misc/liveupdate/luo_ioctl.c create mode 100644 include/uapi/linux/liveupdate.h diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documenta= tion/userspace-api/ioctl/ioctl-number.rst index 7a1409ecc238..279c124048f2 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -375,6 +375,7 @@ Code Seq# Include File = Comments 0xB8 01-02 uapi/misc/mrvl_cn10k_dpi.h Marve= ll CN10K DPI driver 0xB8 all uapi/linux/mshv.h Micro= soft Hyper-V /dev/mshv driver +0xBA all uapi/linux/liveupdate.h 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h Dead = since 6.15 0xCA 10-2F uapi/misc/ocxl.h diff --git a/drivers/misc/liveupdate/Makefile b/drivers/misc/liveupdate/Mak= efile index b4cdd162574f..7a0cd08919c9 100644 --- a/drivers/misc/liveupdate/Makefile +++ b/drivers/misc/liveupdate/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +obj-y +=3D luo_ioctl.o obj-y +=3D luo_core.o obj-y +=3D luo_files.o obj-y +=3D luo_subsystems.o diff --git a/drivers/misc/liveupdate/luo_ioctl.c b/drivers/misc/liveupdate/= luo_ioctl.c new file mode 100644 index 000000000000..76c687ff650b --- /dev/null +++ b/drivers/misc/liveupdate/luo_ioctl.c @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO ioctl Interface + * + * The IOCTL user-space control interface for the LUO subsystem. + * It registers a misc character device, typically found at ``/dev/liveupd= ate``, + * which allows privileged userspace applications (requiring %CAP_SYS_ADMI= N) to + * manage and monitor the LUO state machine and associated resources like + * preservable file descriptors. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "luo_internal.h" + +static int luo_ioctl_fd_preserve(struct liveupdate_fd *luo_fd) +{ + struct file *file; + int ret; + + file =3D fget(luo_fd->fd); + if (!file) { + pr_err("Bad file descriptor\n"); + return -EBADF; + } + + ret =3D luo_register_file(&luo_fd->token, file); + if (ret) + fput(file); + + return ret; +} + +static int luo_ioctl_fd_unpreserve(u64 token) +{ + return luo_unregister_file(token); +} + +static int luo_ioctl_fd_restore(struct liveupdate_fd *luo_fd) +{ + struct file *file; + int ret; + int fd; + + fd =3D get_unused_fd_flags(O_CLOEXEC); + if (fd < 0) { + pr_err("Failed to allocate new fd: %d\n", fd); + return fd; + } + + ret =3D luo_retrieve_file(luo_fd->token, &file); + if (ret < 0) { + put_unused_fd(fd); + + return ret; + } + + fd_install(fd, file); + luo_fd->fd =3D fd; + + return 0; +} + +static int luo_open(struct inode *inodep, struct file *filep) +{ + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (filep->f_flags & O_EXCL) + return -EINVAL; + + return 0; +} + +static long luo_ioctl(struct file *filep, unsigned int cmd, unsigned long = arg) +{ + void __user *argp =3D (void __user *)arg; + struct liveupdate_fd luo_fd; + enum liveupdate_state state; + int ret =3D 0; + u64 token; + + if (_IOC_TYPE(cmd) !=3D LIVEUPDATE_IOCTL_TYPE) + return -ENOTTY; + + switch (cmd) { + case LIVEUPDATE_IOCTL_GET_STATE: + state =3D READ_ONCE(luo_state); + if (copy_to_user(argp, &state, sizeof(luo_state))) + ret =3D -EFAULT; + break; + + case LIVEUPDATE_IOCTL_EVENT_PREPARE: + ret =3D luo_prepare(); + break; + + case LIVEUPDATE_IOCTL_EVENT_FREEZE: + ret =3D luo_freeze(); + break; + + case LIVEUPDATE_IOCTL_EVENT_FINISH: + ret =3D luo_finish(); + break; + + case LIVEUPDATE_IOCTL_EVENT_CANCEL: + ret =3D luo_cancel(); + break; + + case LIVEUPDATE_IOCTL_FD_PRESERVE: + if (copy_from_user(&luo_fd, argp, sizeof(luo_fd))) { + ret =3D -EFAULT; + break; + } + + ret =3D luo_ioctl_fd_preserve(&luo_fd); + if (!ret && copy_to_user(argp, &luo_fd, sizeof(luo_fd))) + ret =3D -EFAULT; + break; + + case LIVEUPDATE_IOCTL_FD_UNPRESERVE: + if (copy_from_user(&token, argp, sizeof(u64))) { + ret =3D -EFAULT; + break; + } + + ret =3D luo_ioctl_fd_unpreserve(token); + break; + + case LIVEUPDATE_IOCTL_FD_RESTORE: + if (copy_from_user(&luo_fd, argp, sizeof(luo_fd))) { + ret =3D -EFAULT; + break; + } + + ret =3D luo_ioctl_fd_restore(&luo_fd); + if (!ret && copy_to_user(argp, &luo_fd, sizeof(luo_fd))) + ret =3D -EFAULT; + break; + + default: + pr_warn("ioctl: unknown command nr: 0x%x\n", _IOC_NR(cmd)); + ret =3D -ENOTTY; + break; + } + + return ret; +} + +static const struct file_operations fops =3D { + .owner =3D THIS_MODULE, + .open =3D luo_open, + .unlocked_ioctl =3D luo_ioctl, +}; + +static struct miscdevice liveupdate_miscdev =3D { + .minor =3D MISC_DYNAMIC_MINOR, + .name =3D "liveupdate", + .fops =3D &fops, +}; + +static int __init liveupdate_init(void) +{ + int err; + + err =3D misc_register(&liveupdate_miscdev); + if (err < 0) { + pr_err("Failed to register misc device '%s': %d\n", + liveupdate_miscdev.name, err); + } + + return err; +} +module_init(liveupdate_init); + +static void __exit liveupdate_exit(void) +{ + misc_deregister(&liveupdate_miscdev); +} +module_exit(liveupdate_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Pasha Tatashin"); +MODULE_DESCRIPTION("Live Update Orchestrator"); +MODULE_VERSION("0.1"); diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index 7afe0aac5ce4..ff4f2ab5c673 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -10,6 +10,7 @@ #include #include #include +#include =20 /** * enum liveupdate_event - Events that trigger live update callbacks. @@ -53,39 +54,6 @@ enum liveupdate_event { LIVEUPDATE_CANCEL, }; =20 -/** - * enum liveupdate_state - Defines the possible states of the live update - * orchestrator. - * @LIVEUPDATE_STATE_NORMAL: Default state, no live update in prog= ress. - * @LIVEUPDATE_STATE_PREPARED: Live update is prepared for reboot; t= he - * LIVEUPDATE_PREPARE callbacks have com= pleted - * successfully. - * Devices might operate in a limited st= ate - * for example the participating devices= might - * not be allowed to unbind, and also the - * setting up of new DMA mappings might = be - * disabled in this state. - * @LIVEUPDATE_STATE_FROZEN: The final reboot event - * (%LIVEUPDATE_FREEZE) has been sent, a= nd the - * system is performing its final state = saving - * within the "blackout window". User - * workloads must be suspended. The actu= al - * reboot (kexec) into the next kernel is - * imminent. - * @LIVEUPDATE_STATE_UPDATED: The system has rebooted into the next - * kernel via live update the system is = now - * running the next kernel, awaiting the - * finish event. - * - * These states track the progress and outcome of a live update operation. - */ -enum liveupdate_state { - LIVEUPDATE_STATE_NORMAL =3D 0, - LIVEUPDATE_STATE_PREPARED =3D 1, - LIVEUPDATE_STATE_FROZEN =3D 2, - LIVEUPDATE_STATE_UPDATED =3D 3, -}; - /* Forward declaration needed if definition isn't included */ struct file; =20 diff --git a/include/uapi/linux/liveupdate.h b/include/uapi/linux/liveupdat= e.h new file mode 100644 index 000000000000..c673d08a29ea --- /dev/null +++ b/include/uapi/linux/liveupdate.h @@ -0,0 +1,300 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +/* + * Userspace interface for /dev/liveupdate + * Live Update Orchestrator + * + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#ifndef _UAPI_LIVEUPDATE_H +#define _UAPI_LIVEUPDATE_H + +#include +#include + +/** + * enum liveupdate_state - Defines the possible states of the live update + * orchestrator. + * @LIVEUPDATE_STATE_NORMAL: Default state, no live update in prog= ress. + * @LIVEUPDATE_STATE_PREPARED: Live update is prepared for reboot; t= he + * LIVEUPDATE_PREPARE callbacks have com= pleted + * successfully. + * Devices might operate in a limited st= ate + * for example the participating devices= might + * not be allowed to unbind, and also the + * setting up of new DMA mappings might = be + * disabled in this state. + * @LIVEUPDATE_STATE_FROZEN: The final reboot event + * (%LIVEUPDATE_FREEZE) has been sent, a= nd the + * system is performing its final state = saving + * within the "blackout window". User + * workloads must be suspended. The actu= al + * reboot (kexec) into the next kernel is + * imminent. + * @LIVEUPDATE_STATE_UPDATED: The system has rebooted into the next + * kernel via live update the system is = now + * running the next kernel, awaiting the + * finish event. + * + * These states track the progress and outcome of a live update operation. + */ +enum liveupdate_state { + LIVEUPDATE_STATE_NORMAL =3D 0, + LIVEUPDATE_STATE_PREPARED =3D 1, + LIVEUPDATE_STATE_FROZEN =3D 2, + LIVEUPDATE_STATE_UPDATED =3D 3, +}; + +/** + * struct liveupdate_fd - Holds parameters for preserving and restoring fi= le + * descriptors across live update. + * @fd: Input for %LIVEUPDATE_IOCTL_FD_PRESERVE: The user-space file + * descriptor to be preserved. + * Output for %LIVEUPDATE_IOCTL_FD_RESTORE: The new file descriptor + * representing the fully restored kernel resource. + * @flags: Unused, reserved for future expansion, must be set to 0. + * @token: Output for %LIVEUPDATE_IOCTL_FD_PRESERVE: An opaque, unique tok= en + * generated by the kernel representing the successfully preserved + * resource state. + * Input for %LIVEUPDATE_IOCTL_FD_RESTORE: The token previously + * returned by the preserve ioctl for the resource to be restored. + * + * This structure is used as the argument for the %LIVEUPDATE_IOCTL_FD_PRE= SERVE + * and %LIVEUPDATE_IOCTL_FD_RESTORE ioctls. These ioctls allow specific ty= pes + * of file descriptors (for example memfd, kvm, iommufd, and VFIO) to have= their + * underlying kernel state preserved across a live update cycle. + * + * To preserve an FD, user space passes this struct to + * %LIVEUPDATE_IOCTL_FD_PRESERVE with the @fd field set. On success, the + * kernel populates the @token field. + * + * After the live update transition, user space passes the struct populate= d with + * the *same* @token to %LIVEUPDATE_IOCTL_FD_RESTORE. The kernel uses the = @token + * to find the preserved state and, on success, populates the @fd field wi= th a + * new file descriptor referring to the fully restored resource. + */ +struct liveupdate_fd { + int fd; + __u32 flags; + __u64 token; +}; + +/* The ioctl type, documented in ioctl-number.rst */ +#define LIVEUPDATE_IOCTL_TYPE 0xBA + +/** + * LIVEUPDATE_IOCTL_FD_PRESERVE - Validate and initiate preservation for a= file + * descriptor. + * + * Argument: Pointer to &struct liveupdate_fd. + * + * User sets the @fd field identifying the file descriptor to preserve + * (e.g., memfd, kvm, iommufd, VFIO). The kernel validates if this FD type + * and its dependencies are supported for preservation. If validation pass= es, + * the kernel marks the FD internally and *initiates the process* of prepa= ring + * its state for saving. The actual snapshotting of the state typically oc= curs + * during the subsequent %LIVEUPDATE_IOCTL_EVENT_PREPARE execution phase, = though + * some finalization might occur during %LIVEUPDATE_IOCTL_EVENT_FREEZE. + * On successful validation and initiation, the kernel populates the @token + * field with an opaque identifier representing the resource being preserv= ed. + * This token confirms the FD is targeted for preservation and is required= for + * the subsequent %LIVEUPDATE_IOCTL_FD_RESTORE call after the live update.= This + * is an I/O read/write operation. + * + * Return: 0 on success (validation passed, preservation initiated), negat= ive + * error code on failure (e.g., unsupported FD type, dependency issue, + * validation failed). + */ +#define LIVEUPDATE_IOCTL_FD_PRESERVE \ + _IOWR(LIVEUPDATE_IOCTL_TYPE, 0x00, struct liveupdate_fd) + +/** + * LIVEUPDATE_IOCTL_FD_UNPRESERVE - Remove a file descriptor from the + * preservation list. + * + * Argument: Pointer to __u64 token. + * + * Allows user space to explicitly remove a file descriptor from the set of + * items marked as potentially preservable. User space provides a pointer = to the + * __u64 @token that was previously returned by a successful + * %LIVEUPDATE_IOCTL_FD_PRESERVE call (potentially from a prior, possibly + * cancelled, live update attempt). The kernel reads the token value from = the + * provided user-space address. + * + * On success, the kernel removes the corresponding entry (identified by t= he + * token value read from the user pointer) from its internal preservation = list. + * The provided @token (representing the now-removed entry) becomes invalid + * after this call. + * + * This operation can only be called when the live update orchestrator is = in the + * %LIVEUPDATE_STATE_NORMAL state.** + * + * This is an I/O write operation (_IOW), signifying the kernel reads data= (the + * token) from the user-provided pointer. + * + * Return: 0 on success, negative error code on failure (e.g., -EBUSY or -= EINVAL + * if not in %LIVEUPDATE_STATE_NORMAL, bad address provided, invalid token= value + * read, token not found). + */ +#define LIVEUPDATE_IOCTL_FD_UNPRESERVE \ + _IOW(LIVEUPDATE_IOCTL_TYPE, 0x01, __u64) + +/** + * LIVEUPDATE_IOCTL_FD_RESTORE - Restore a previously preserved file descr= iptor. + * + * Argument: Pointer to &struct liveupdate_fd. + * + * User sets the @token field to the value obtained from a successful + * %LIVEUPDATE_IOCTL_FD_PRESERVE call before the live update. On success, + * the kernel restores the state (saved during the PREPARE/FREEZE phases) + * associated with the token and populates the @fd field with a new file + * descriptor referencing the restored resource in the current (new) kerne= l. + * This operation must be performed *before* signaling completion via + * %LIVEUPDATE_IOCTL_EVENT_FINISH. This is an I/O read/write operation. + * + * Return: 0 on success, negative error code on failure (e.g., invalid tok= en). + */ +#define LIVEUPDATE_IOCTL_FD_RESTORE \ + _IOWR(LIVEUPDATE_IOCTL_TYPE, 0x02, struct liveupdate_fd) + +/** + * LIVEUPDATE_IOCTL_GET_STATE - Query the current state of the live update + * orchestrator. + * + * Argument: Pointer to &enum liveupdate_state. + * + * The kernel fills the enum value pointed to by the argument with the cur= rent + * state of the live update subsystem. Possible states are: + * + * - %LIVEUPDATE_STATE_NORMAL: Default state; no live update operation is + * currently in progress. + * - %LIVEUPDATE_STATE_PREPARED: The preparation phase (triggered by + * %LIVEUPDATE_IOCTL_EVENT_PREPARE) has comp= leted + * successfully. The system is ready for the + * reboot transition initiated by + * %LIVEUPDATE_IOCTL_EVENT_FREEZE. Note that= some + * device operations (e.g., unbinding, new D= MA + * mappings) might be restricted in this sta= te. + * - %LIVEUPDATE_STATE_UPDATED: The system has successfully rebooted into= the + * new kernel via live update. It is now run= ning + * the new kernel code and is awaiting the + * completion signal from user space via + * %LIVEUPDATE_IOCTL_EVENT_FINISH after + * restoration tasks are done. + * + * See the definition of &enum liveupdate_state for more details on each s= tate. + * This is an I/O read operation (kernel writes to the user-provided point= er). + * + * Return: 0 on success, negative error code on failure. + */ +#define LIVEUPDATE_IOCTL_GET_STATE \ + _IOR(LIVEUPDATE_IOCTL_TYPE, 0x03, enum liveupdate_state) + +/** + * LIVEUPDATE_IOCTL_EVENT_PREPARE - Initiate preparation phase and trigger= state + * saving. + * + * Argument: None. + * + * Initiates the live update preparation phase. This action corresponds to + * the internal %LIVEUPDATE_PREPARE kernel event and can also be triggered + * by writing '1' to ``/sys/kernel/liveupdate/prepare``. This typically + * triggers the main state saving process for items marked via the PRESERVE + * ioctls. This occurs *before* the main "blackout window", while user + * applications (e.g., VMs) may still be running. Kernel subsystems + * receiving the %LIVEUPDATE_PREPARE event should serialize necessary stat= e. + * This command does not transfer data. + * + * Return: 0 on success, negative error code on failure. Transitions state + * towards %LIVEUPDATE_STATE_PREPARED on success. + */ +#define LIVEUPDATE_IOCTL_EVENT_PREPARE \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x04) + +/** + * LIVEUPDATE_IOCTL_EVENT_FREEZE - Notify subsystems of imminent reboot + * transition. + * + * Argument: None. + * + * Notifies the live update subsystem and associated components that the k= ernel + * is about to execute the final reboot transition into the new kernel (e.= g., + * via kexec). This action triggers the internal %LIVEUPDATE_FREEZE kernel + * event. This event provides subsystems a final, brief opportunity (withi= n the + * "blackout window") to save critical state or perform last-moment quiesc= ing. + * Any remaining or deferred state saving for items marked via the PRESERVE + * ioctls typically occurs in response to the %LIVEUPDATE_FREEZE event. + * + * This ioctl should only be called when the system is in the + * %LIVEUPDATE_STATE_PREPARED state. This command does not transfer data. + * + * Return: 0 if the notification is successfully processed by the kernel (= but + * reboot follows). Returns a negative error code if the notification fails + * or if the system is not in the %LIVEUPDATE_STATE_PREPARED state. + */ +#define LIVEUPDATE_IOCTL_EVENT_FREEZE \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x05) + +/** + * LIVEUPDATE_IOCTL_EVENT_CANCEL - Cancel the live update preparation phas= e. + * + * Argument: None. + * + * Notifies the live update subsystem to abort the preparation sequence + * potentially initiated by %LIVEUPDATE_IOCTL_EVENT_PREPARE. This action + * typically corresponds to the internal %LIVEUPDATE_CANCEL kernel event, + * which might also be triggered automatically if the PREPARE stage fails + * internally. + * + * When triggered, subsystems receiving the %LIVEUPDATE_CANCEL event should + * revert any state changes or actions taken specifically for the aborted + * prepare phase (e.g., discard partially serialized state). The kernel + * releases resources allocated specifically for this *aborted preparation + * attempt*. + * + * This operation cancels the current *attempt* to prepare for a live upda= te + * but does **not** remove previously validated items from the internal li= st + * of potentially preservable resources. Consequently, preservation tokens + * previously generated by successful %LIVEUPDATE_IOCTL_FD_PRESERVE or cal= ls + * generally **remain valid** as identifiers for those potentially preserv= able + * resources. However, since the system state returns towards + * %LIVEUPDATE_STATE_NORMAL, user space must initiate a new live update se= quence + * (starting with %LIVEUPDATE_IOCTL_EVENT_PREPARE) to proceed with an upda= te + * using these (or other) tokens. + * + * This command does not transfer data. Kernel callbacks for the + * %LIVEUPDATE_CANCEL event must not fail. + * + * Return: 0 on success, negative error code on failure. Transitions state= back + * towards %LIVEUPDATE_STATE_NORMAL on success. + */ +#define LIVEUPDATE_IOCTL_EVENT_CANCEL \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x06) + +/** + * LIVEUPDATE_IOCTL_EVENT_FINISH - Signal restoration completion and trigg= er + * cleanup. + * + * Argument: None. + * + * Signals that user space has completed all necessary restoration actions= in + * the new kernel (after a live update reboot). This action corresponds to= the + * internal %LIVEUPDATE_FINISH kernel event and may also be triggerable via + * sysfs (e.g., writing '1' to ``/sys/kernel/liveupdate/finish``) + * Calling this ioctl triggers the cleanup phase: any resources that were + * successfully preserved but were *not* subsequently restored (reclaimed)= via + * the RESTORE ioctls will have their preserved state discarded and associ= ated + * kernel resources released. Involved devices may be reset. All desired + * restorations *must* be completed *before* this. Kernel callbacks for the + * %LIVEUPDATE_FINISH event must not fail. Successfully completing this ph= ase + * transitions the system state from %LIVEUPDATE_STATE_UPDATED back to + * %LIVEUPDATE_STATE_NORMAL. This command does not transfer data. + * + * Return: 0 on success, negative error code on failure. + */ +#define LIVEUPDATE_IOCTL_EVENT_FINISH \ + _IO(LIVEUPDATE_IOCTL_TYPE, 0x07) + +#endif /* _UAPI_LIVEUPDATE_H */ --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 DEA91267700 for ; Thu, 15 May 2025 18:23:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333426; cv=none; b=CEffVCQuf3fv4iU7G4IxjqnduejWhfnZgquXLCiPCuIdh0p6/dNO0UuJh4UNijZdGSpClyha+CBmUlhbxRSk5BDrkP7wgRrzoI7Btponyj78ingA5P5OUQBuT8SJxdJMVrvYBeR78PgXHYXiuQsYCLHUyYM0j91s6phSExqkJ5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333426; c=relaxed/simple; bh=IyCI45gm7LvyaR79piBMSG0ktcYZBhXIdzy96OlDz54=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b2/rosisSd1V1dBK+TDa8HAN8ZCcYZle7zOXTx/nkiyeeWL5hQSgsOb2o6QfGb6v7TN6z9gQHszcSpPKjGmKNhSqMZALVsY2VGTUsuA7wa5cI8oBVvO2LByHyidehTcFXn2z40sxsXfh3i/S2Gx32TtScF2E8Y/Q8ITDz2AUdfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=M1GslH8J; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="M1GslH8J" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7c9376c4dbaso153710885a.0 for ; Thu, 15 May 2025 11:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333423; x=1747938223; 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=ltL7NUHX20pXkC0VOJlR8mGY0Kaj9UtnVW/UYNskncc=; b=M1GslH8JrorVmR+H2/9OeorU98xcvezDrGCwrd9/70MxJFKlGVY/DntnGwfON721Tr wh5vpapv/14DR8f/Ygs/ssSQkOUXS76KASdDy4eKFtwBH+rIyWfrXYcoPT7GjeNfGGgs +5kMeslWFCLyPmW4JrCSCry4jT6wYhrdqffuC1Qq+RVk+EhldD/YXaB0XcvuCQmP17/q P/Dg664Tk6hszisxvKJHzZKWCT0fZBHq13Z7oYFOLU+nQkMYxfE3nWOur0Hh4ZX3h4Yq FEZRJi1wKKmXfqaMgS58TOruX87uSKpUIj3KHmPn64CeS5n6ykZO2B7BVSTd8DeW33rz 6h/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333423; x=1747938223; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ltL7NUHX20pXkC0VOJlR8mGY0Kaj9UtnVW/UYNskncc=; b=A4Mys3Gkamyq6SkhQZfBwjRabv+JjwgjINcUnPtGMMXBzPcA2o3ZU2wNIp1/BOnChx fixCqpsHbfWIlwbs7mRpwMPaPCok7tvvDC2GIQWryY45kWeCoKh9a/6aAQ2J2z9/JKyZ BeqgROTpnbJ+935x3ZzamV2MTLqH3DXAX41NF9nOMJECYgojMJAqm+14OKQas779kdn2 uOK7+2OdGjCQba/QfrRYpzj2OzAGZqLD6+IVO0bAq3YOQcJIChUsRRqGDYWBdx78KEnf muj/SrvQQ1Rnk0rqgdek3SZwn6U0m9yh5/CYaVmineiicpRzOPdkoGG0sqlRYPwaacT8 xo3w== X-Forwarded-Encrypted: i=1; AJvYcCUaKsgNbxY3KbswPy1/4HKeaRGIt46y9eWHX0NPyXd/XWQGjUqTO2aPwUoHCcBWlktpWs85dDX3qEpoce8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7tzTqA3aSNfdiSZlQieTvaBqwRqnCfRkRa39NPQ6XyMoUJdfc A60hmJXQROxci/oOMiV9WjysnYGK0hElwuZkorX/ff9SbmpalcsXvjUQS1nm8dxyWIE= X-Gm-Gg: ASbGncuf+4MpqS24YbbMD0Ev0WqW4rnIMEUGS60Y2KCbnpi8zaRSzqzEclQp9TWkgLg DpGdepcEVQeoFOGZrW8G8h6nz5g1T7V+XUogKnEXvX1Jh7aPJE8oapSomzvt4m5j6H3zZS4iaas yVpLGWuCDYLJX7Ae1q7mwaZ3cWlAaKm86pnMWo/FYXv7QVpwdMR0O8QW5aZCinqazLzzXTK1KlQ +qQpmJctyjAr6ODpwQo929J+aH93GbilpkPfchAP03BauphjenWXh0Aya/UTkf4GOCwTRBuf/C7 fhf440s+5tJ4b0qXkVTPzGPTi+iGJBaGpbGa/b8x5cw6vlaEhDGIbWxyFhvyhXG1obi9sG5pBAY aTmm5OR3bxO44P3HO/n5KMRrgC+MsNyCqXj9Njh2nBzZ1 X-Google-Smtp-Source: AGHT+IE+XvR/Oap8/b8tQ4cy4ncNNrPm3HTXrnPFPzaqq9DTCDamdPUIr8DrHH9ecT3KnE+qPIT/Rw== X-Received: by 2002:a05:620a:880b:b0:7c0:5b5d:c82b with SMTP id af79cd13be357-7cd39e37279mr705912185a.28.1747333422544; Thu, 15 May 2025 11:23:42 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:41 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 11/16] luo: luo_sysfs: add sysfs state monitoring Date: Thu, 15 May 2025 18:23:15 +0000 Message-ID: <20250515182322.117840-12-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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 a sysfs interface for the Live Update Orchestrator under /sys/kernel/liveupdate/. This interface provides a way for userspace tools and scripts to monitor the current state of the LUO state machine. The main feature is a read-only file, state, which displays the current LUO state as a string ("normal", "prepared", "frozen", "updated"). The interface uses sysfs_notify to allow userspace listeners (e.g., via poll) to be efficiently notified of state changes. ABI documentation for this new sysfs interface is added in Documentation/ABI/testing/sysfs-kernel-liveupdate. This read-only sysfs interface complements the main ioctl interface provided by /dev/liveupdate, which handles LUO control operations and resource management. Signed-off-by: Pasha Tatashin --- .../ABI/testing/sysfs-kernel-liveupdate | 51 ++++++++++ drivers/misc/liveupdate/Kconfig | 18 ++++ drivers/misc/liveupdate/Makefile | 1 + drivers/misc/liveupdate/luo_core.c | 1 + drivers/misc/liveupdate/luo_internal.h | 6 ++ drivers/misc/liveupdate/luo_sysfs.c | 92 +++++++++++++++++++ 6 files changed, 169 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-kernel-liveupdate create mode 100644 drivers/misc/liveupdate/luo_sysfs.c diff --git a/Documentation/ABI/testing/sysfs-kernel-liveupdate b/Documentat= ion/ABI/testing/sysfs-kernel-liveupdate new file mode 100644 index 000000000000..7631410a10c3 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-kernel-liveupdate @@ -0,0 +1,51 @@ +What: /sys/kernel/liveupdate/ +Date: May 2025 +KernelVersion: 6.16.0 +Contact: pasha.tatashin@soleen.com +Description: Directory containing interfaces to query the live + update orchestrator. Live update is the ability to reboot the + host kernel (e.g., via kexec, without a full power cycle) while + keeping specifically designated devices operational ("alive") + across the transition. After the new kernel boots, these devices + can be re-attached to their original workloads (e.g., virtual + machines) with their state preserved. This is particularly + useful, for example, for quick hypervisor updates without + terminating running virtual machines. + + +What: /sys/kernel/liveupdate/state +Date: May 2025 +KernelVersion: 6.16.0 +Contact: pasha.tatashin@soleen.com +Description: Read-only file that displays the current state of the live + update orchestrator as a string. Possible values are: + + "normal": No live update operation is in progress. This is + the default operational state. + + "prepared": The live update preparation phase has completed + successfully (e.g., triggered via the 'prepare' + file). Kernel subsystems have been notified via + the %LIVEUPDATE_PREPARE event/callback and + should have initiated state saving. User + workloads (e.g., VMs) are generally still + running, but some operations (like device + unbinding or new DMA mappings) might be + restricted. The system is ready for the reboot + trigger. + + "frozen": The final reboot notification has been sent + (e.g., triggered via the 'reboot' file), + corresponding to the %LIVEUPDATE_REBOOT kernel + event. Subsystems have had their final chance to + save state. User workloads must be suspended. + The system is about to execute the reboot into + the new kernel (imminent kexec). This state + corresponds to the "blackout window". + + "updated": The system has successfully rebooted into the + new kernel via live update. Restoration of + preserved resources can now occur (typically via + ioctl commands). The system is awaiting the + final 'finish' signal after user space completes + restoration tasks. diff --git a/drivers/misc/liveupdate/Kconfig b/drivers/misc/liveupdate/Kcon= fig index a7424ceeba0b..09940f9a724a 100644 --- a/drivers/misc/liveupdate/Kconfig +++ b/drivers/misc/liveupdate/Kconfig @@ -25,3 +25,21 @@ config LIVEUPDATE running virtual machines. =20 If unsure, say N. + +config LIVEUPDATE_SYSFS_API + bool "Live Update sysfs monitoring interface" + depends on SYSFS + depends on LIVEUPDATE + help + Enable a sysfs interface for the Live Update Orchestrator + at /sys/kernel/liveupdate/. + + This allows monitoring the LUO state ('normal', 'prepared', + 'frozen', 'updated') via the read-only 'state' file. + + This interface complements the primary /dev/liveupdate ioctl + interface, which handles the full update process. + This sysfs API may be useful for scripting, or userspace monitoring + needed to coordinate application restarts and minimize downtime. + + If unsure, say N. diff --git a/drivers/misc/liveupdate/Makefile b/drivers/misc/liveupdate/Mak= efile index 7a0cd08919c9..190323c10220 100644 --- a/drivers/misc/liveupdate/Makefile +++ b/drivers/misc/liveupdate/Makefile @@ -3,3 +3,4 @@ obj-y +=3D luo_ioctl.o obj-y +=3D luo_core.o obj-y +=3D luo_files.o obj-y +=3D luo_subsystems.o +obj-$(CONFIG_LIVEUPDATE_SYSFS_API) +=3D luo_sysfs.o diff --git a/drivers/misc/liveupdate/luo_core.c b/drivers/misc/liveupdate/l= uo_core.c index ab1d76221fe2..1a5163c116a4 100644 --- a/drivers/misc/liveupdate/luo_core.c +++ b/drivers/misc/liveupdate/luo_core.c @@ -79,6 +79,7 @@ static inline bool is_current_luo_state(enum liveupdate_s= tate expected_state) static void __luo_set_state(enum liveupdate_state state) { WRITE_ONCE(luo_state, state); + luo_sysfs_notify(); } =20 static inline void luo_set_state(enum liveupdate_state state) diff --git a/drivers/misc/liveupdate/luo_internal.h b/drivers/misc/liveupda= te/luo_internal.h index b7a0f31ddc99..bf1ba18722e2 100644 --- a/drivers/misc/liveupdate/luo_internal.h +++ b/drivers/misc/liveupdate/luo_internal.h @@ -34,6 +34,12 @@ int luo_retrieve_file(u64 token, struct file **file); int luo_register_file(u64 *token, struct file *file); int luo_unregister_file(u64 token); =20 +#ifdef CONFIG_LIVEUPDATE_SYSFS_API +void luo_sysfs_notify(void); +#else +static inline void luo_sysfs_notify(void) {} +#endif + extern const char *const luo_state_str[]; =20 /* Get the current state as a string */ diff --git a/drivers/misc/liveupdate/luo_sysfs.c b/drivers/misc/liveupdate/= luo_sysfs.c new file mode 100644 index 000000000000..756b341dd886 --- /dev/null +++ b/drivers/misc/liveupdate/luo_sysfs.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO sysfs interface + * + * Provides a sysfs interface at ``/sys/kernel/liveupdate/`` for monitorin= g LUO + * state. Live update allows rebooting the kernel (via kexec) while prese= rving + * designated device state for attached workloads (e.g., VMs), useful for + * minimizing downtime during hypervisor updates. + * + * /sys/kernel/liveupdate/state + * ---------------------------- + * - Permissions: Read-only + * - Description: Displays the current LUO state string. + * - Valid States: + * @normal + * Idle state. + * @prepared + * Preparation phase complete (triggered via 'prepare'). Resources + * checked, state saving initiated via %LIVEUPDATE_PREPARE event. + * Workloads mostly running but may be restricted. Ready forreboot + * trigger. + * @frozen + * Final reboot notification sent (triggered via 'reboot'). Correspo= nds to + * %LIVEUPDATE_REBOOT event. Final state saving. Workloads must be + * suspended. System about to kexec ("blackout window"). + * @updated + * New kernel booted via live update. Awaiting 'finish' signal. + * + * Userspace Interaction & Blackout Window Reduction + * ------------------------------------------------- + * Userspace monitors the ``state`` file to coordinate actions: + * - Suspend workloads before @frozen state is entered. + * - Initiate resource restoration upon entering @updated state. + * - Resume workloads after restoration, minimizing downtime. + */ + +#include +#include +#include +#include "luo_internal.h" + +static bool luo_sysfs_initialized; + +#define LUO_DIR_NAME "liveupdate" + +void luo_sysfs_notify(void) +{ + if (luo_sysfs_initialized) + sysfs_notify(kernel_kobj, LUO_DIR_NAME, "state"); +} + +/* Show the current live update state */ +static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *att= r, + char *buf) +{ + return sysfs_emit(buf, "%s\n", LUO_STATE_STR); +} + +static struct kobj_attribute state_attribute =3D __ATTR_RO(state); + +static struct attribute *luo_attrs[] =3D { + &state_attribute.attr, + NULL +}; + +static struct attribute_group luo_attr_group =3D { + .attrs =3D luo_attrs, + .name =3D LUO_DIR_NAME, +}; + +static int __init luo_init(void) +{ + int ret; + + ret =3D sysfs_create_group(kernel_kobj, &luo_attr_group); + if (ret) { + pr_err("Failed to create group\n"); + return ret; + } + + luo_sysfs_initialized =3D true; + pr_info("Initialized\n"); + + return 0; +} +subsys_initcall(luo_init); --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (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 796BE264619 for ; Thu, 15 May 2025 18:23:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333427; cv=none; b=KFeggH4/aDNX/uUkhz3AKmxpX4JdeQA96yE/SDzCjsJRx9d4FrAnTpM+CEQgFx8fevtKoFtKWRKN/ut16HaQBq2N9UWbMB+lC48D8f1lhLkTD7vs1uMU5nkKIE3MveRmLau5NfUY6VYmpNJRgdX42lm7Jtr/7glnTVBG0IdcxQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333427; c=relaxed/simple; bh=lWJrKH2ewgb0eX1vkGmRIsvKb0JKgD/qXbGK9GoZ+uo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=imnjCO6mRxU2iqNm5jDGf2/JCvDIECHlZwwJGfg9OAXljaO2Pejw/4KhZAD5rQeUoAacqPhy5quK/S5p+D0y88Vc93c9te5EYqQJQp4Rcw0N3qsNn1/teHFl41e4OTQMbSyQOIaDVR3mwci5d54WTIrjWewPG8fga/txM6OUOD4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=D0Eqp9zJ; arc=none smtp.client-ip=209.85.222.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="D0Eqp9zJ" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7c5c815f8efso113959785a.2 for ; Thu, 15 May 2025 11:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333424; x=1747938224; 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=mEniED4DkTfmCqxmyCGUmyvqBa7+e8K9WWMdUYmkBGg=; b=D0Eqp9zJZ7DicQmHcbwa5jPlUzbivYzyCqww5b+c3hGrh7TApxjAqYkqjrAcTeLyX0 XcNnSwNxcJSEMFLvUKGLjxz9j7G58e5eiiP07CoNeD6/wjCbg4fUn8Y876rxemK34YCI x2gZ8aCZ3MVJ5mzsbtKCd5IHYPeArjQDcJcVZZeCJa9Ti2sHp5abtwICdl3W/vm/HNQa VTbZKVTngt+9VHPC4COZWoreRiPZbBg/pq5xf/sKXUYu3/Kf9oF0WBx6SlBMq6IZLImY pA9gfAJ0TPYkhzzvp+bwxAUzY7Kt3/M6xCgzUfHhXaL5W5UOBTeif68NOHQ99jAVuuUW mYnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333424; x=1747938224; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mEniED4DkTfmCqxmyCGUmyvqBa7+e8K9WWMdUYmkBGg=; b=BZ1JujaaXJfzrtTpxWZYr1sP5vVV1LYdnL11YrNw7qXXD8+VRyAQLJGgRvnsgU2B4d yUcWePUVip6+s2oia7CyeoLR4Jk1+4jMMNIMtAqpeAmYvVu8pDWv2794a2X81nqgXZ7H X/27t3+7JzidHgaIgrjM9bNAc8cgkZ0IigcfIR4TniW+x7Yafi3+hIzEPflm+WwGxNzF ZOzzQBDdtGOgjiBT245/nlZmZt2leIb5tVtjshZGmauIgoelE8tx76EE4nHaF4gCZPqY UEHYVH3JzYBuAzBA7R+51CJfKB5a3YKeKRRp0A8CIHVQDGSIAC5n0vx9E68YVLlT+x2k aW8Q== X-Forwarded-Encrypted: i=1; AJvYcCUG7Gj3wxTVStpQMfX90TJ527uheGuNn1GXUejUTcQrC6j9RDSuofqL/Gg14/AMYg7L1XhgPCxc2arvdJM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8wlDi/GUKViCy4kBW5TCJJbWNmCiM3F7wEKXWwU3rMkyC7W+P dIV6NSStGLzoJ9DvKJOfgtyQwQKIFudV3/8c4VZfhL9Gi+ax9RLALH7h+KMy41ft0yU= X-Gm-Gg: ASbGncuy7FP5mSuN99/ReCK1knM01tT9mfpzR0tb1glCsLL3Xw9xw9CWMKwPl43xi3w ecG31wZs2WTkGEdm1xkGwQxIrPLHPNMWL9x/9awWoycWWy2mBU2IEnvrIfdZDVAt8F1ONIaqdZH EUZXQxiT+e0ERw0EQee1BNf+lX5gLfmlxX2mFAJ1dzQXvtSbMewFnZJzYU/iBlqpGN0PZoEXfcD EPedyDzao7dgc4hQ07fPwIumtApRDfIif5PkDJLak+LnNuoGMcIODymTorR8OtXibaw/78Ou5UY poLhentS41TreoB0W2z/hjaExr3DKy2+EgzZUNbUVRUIkz75Iut7ZETyRCnOfUVP6QbuhqatxMU Gst8KuhjQmMekcCVsbSJCD57wlZF/vGgMLMi/+gUHMDcWk+/R0VVmn1U= X-Google-Smtp-Source: AGHT+IEEvhDcK0rfSEs9ibsvsuoGoyD122Q4/XnrHONMAwVJ+f9mAQ9x06PYH/dTETAU7jGtExspCQ== X-Received: by 2002:a05:620a:240e:b0:7c5:4c49:76a5 with SMTP id af79cd13be357-7cd46718986mr65234785a.12.1747333424033; Thu, 15 May 2025 11:23:44 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:43 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 12/16] reboot: call liveupdate_reboot() before kexec Date: Thu, 15 May 2025 18:23:16 +0000 Message-ID: <20250515182322.117840-13-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" Modify the reboot() syscall handler in kernel/reboot.c to call liveupdate_reboot() when processing the LINUX_REBOOT_CMD_KEXEC command. This ensures that the Live Update Orchestrator is notified just before the kernel executes the kexec jump. The liveupdate_reboot() function triggers the final LIVEUPDATE_REBOOT event, allowing participating subsystems to perform last-minute state saving within the blackout window, and transitions the LUO state machine to FROZEN. The call is placed immediately before kernel_kexec() to ensure LUO finalization happens at the latest possible moment before the kernel transition. If liveupdate_reboot() returns an error (indicating a failure during LUO finalization), the kexec operation is aborted to prevent proceeding with an inconsistent state. Signed-off-by: Pasha Tatashin --- kernel/reboot.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/reboot.c b/kernel/reboot.c index ec087827c85c..bdeb04a773db 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -797,6 +798,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsig= ned int, cmd, =20 #ifdef CONFIG_KEXEC_CORE case LINUX_REBOOT_CMD_KEXEC: + ret =3D liveupdate_reboot(); + if (ret) + break; ret =3D kernel_kexec(); break; #endif --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 BC900267F70 for ; Thu, 15 May 2025 18:23:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333429; cv=none; b=uMYNlPg0KodfYXz/BY8WdLzhz2Pst9Ev5iipb2fa93LqKbY88/595H4cGeuuEJRCiXnX7xZ8+HVt/wye0Y8TpAHo3Jv0HGRzl+RPxKtaxEEcNyqrgFtS65UBt0MGRYEDyFLE+Ti2Mlfqt7ciVSBwA4o0jd7DG0uodqZURCgwYXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333429; c=relaxed/simple; bh=hgPuW5Ys7sC8BGWu94CgKexhMd9oEBDpOch4SttenXM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hS5jibR3giKOoAY6btOhaoceoDB73Rpfpmtk/DKRHT/nTulD6i/2LWS95xLu6duWyVfXCtQhMoiW3K1jXdqrxuLzyZ5hZdafLN+f0gN7FLc+vA9wNEzk/TdK/eA/mPLR4mmPHacXPXXBo5auWEwe5IWfD+cbAcffAaxq1LFCzck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=Zl0dQx4+; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="Zl0dQx4+" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7c54b651310so159297985a.0 for ; Thu, 15 May 2025 11:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333425; x=1747938225; 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=oENjR2vhI4RJwAs+G75r0Z5r6ExS3XdaJkL9pQx4Wu0=; b=Zl0dQx4+PboHfc3P9u7cnYFU522svQn14sfZFc+mGUYsmledY5OqFp6jr0qIZ/1nv/ 0ClBAKj6PtbiJLRf9QTzMURmSHGDG/0yWF03gZGK+NFp+Wv7+Ky2z2N9IUYL+1IK+h19 G0aXPjXsoTnrQffdlrwp/sGLcixe9jNmqpE7kOY0jFxaDgGWCoimQ4ygCGb+aw4RKXW7 2JL1oTQaw8ZWx8YQm19ZeR74RC3N51v8aAybjcazbCKNt4WTqEXTRdI28MmLausrZooo SdEC9iqCO234w9OCq/SbmDiz2oQfuYP7NVx2gW9feRoEewRJHFNT6Q2ZjwwkwxC8+Egm 2YcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333425; x=1747938225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oENjR2vhI4RJwAs+G75r0Z5r6ExS3XdaJkL9pQx4Wu0=; b=Tb85IxBVAV8JqU3eG+3wET3itbKxCesBdI0YOzTOOGstlVMZfMTe64B4Q8PSK6P3PU hG40+Qn1PHju9tncJibnFNaNsAGbTi8G5vH5qSClfMy+Ax+dzZGH2ff4RUSgo1rc6QO3 IqTgs5L9SX5ul5aA6ZRzsNtCm0qHak0uZsDMgquGTLOHOMvwFnfX1Kuzj1RkukLjV3wK CeECZYUmR9tvXUpeiJM1608rZgA92/B2ffQA6sxj8jrtwhY7zCa0LSUa4yGGHgorLsje H9O1PWYaTTN1hfY0iYhS59OcoY8JuU0hyVqFAiQQnhuMtxuQRfTQ7PI3DlPOiRIhDgXn Skrg== X-Forwarded-Encrypted: i=1; AJvYcCUwWu55SaAXPKWoRaM7jrkvXSd7U3PywDpmHYLEQf8uMZYqxWTKzHpFzaKTl8AUel1NzqQg+trU2X6nIUQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwfFVcqcEV9VGa0IQQ8n9VFurrDQ8o7R5HomlMbkp7yjSN393GF EiGD7Q4xjKedMyr82hcPaRUKes/JRHLGyEGlYgJJ92kWQw4worxgghIAKx4QgvRnioE= X-Gm-Gg: ASbGncvPhHI1xTcJTq7Yo7LJye+kFEaQyLmsiNsQSj5Hq0U28u9cGqqdFqoYTzH1D4k WuOqVazPfz930xxDEerRGpdKX3Jol2MpAVR+dPB+agemW9QQjZuVQdyyhjFxblIvkwtB9nxcCdG l+hmxAtgoCEbMyK2eBl8TSjh02IW8FNAEbNYV62xg8XmfvtveyAyVY9vPhV/4F5A2mBd6h1owuW hw2/9z8BfmLW6YLtM4hGPlgkAnS10uaLChwG7wY7U6RmHDKj75KXbq7Yy+T9ebzWje++XXL3iNl b/cRZ5S7s3qSNpP3DeKEFQT05bmqepF28eteUbuuU6oIWQ+VBl2QMT06ub25gtQKVd0Tfm/Qwhu 12F9fKmFFLshhWGFG2a3B5RA3V9x0kHrgdfEz2C9BAVns X-Google-Smtp-Source: AGHT+IHP1cJdLqVJKJ+0AFAF8cX8CxtBKtnuYkRWk6aLTFzY+RY4Wob1Ir0/sZcQQGuhUB+Whzp0DQ== X-Received: by 2002:a05:620a:4707:b0:7c5:d888:7098 with SMTP id af79cd13be357-7cd46779dc9mr86813885a.44.1747333425466; Thu, 15 May 2025 11:23:45 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:44 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 13/16] luo: add selftests for subsystems un/registration Date: Thu, 15 May 2025 18:23:17 +0000 Message-ID: <20250515182322.117840-14-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Introduce a self-test mechanism for the LUO to allow verification of core subsystem management functionality. This is primarily intended for developers and system integrators validating the live update feature. The tests are enabled via the new Kconfig option CONFIG_LIVEUPDATE_SELFTESTS (default 'n') and are triggered through a new ioctl command, LIVEUPDATE_IOCTL_SELFTESTS, added to the /dev/liveupdate device node. This ioctl accepts commands defined in luo_selftests.h to: - LUO_CMD_SUBSYSTEM_REGISTER: Creates and registers a dummy LUO subsystem using the liveupdate_register_subsystem() function. It allocates a data page and copies initial data from userspace. - LUO_CMD_SUBSYSTEM_UNREGISTER: Unregisters the specified dummy subsystem using the liveupdate_unregister_subsystem() function and cleans up associated test resources. - LUO_CMD_SUBSYSTEM_GETDATA: Copies the data page associated with a registered test subsystem back to userspace, allowing verification of data potentially modified or preserved by test callbacks. This provides a way to test the fundamental registration and unregistration flows within the LUO framework from userspace without requiring a full live update sequence. Signed-off-by: Pasha Tatashin --- drivers/misc/liveupdate/Kconfig | 15 ++ drivers/misc/liveupdate/Makefile | 1 + drivers/misc/liveupdate/luo_internal.h | 9 + drivers/misc/liveupdate/luo_ioctl.c | 4 + drivers/misc/liveupdate/luo_selftests.c | 283 ++++++++++++++++++++++++ drivers/misc/liveupdate/luo_selftests.h | 23 ++ include/uapi/linux/liveupdate.h | 24 ++ 7 files changed, 359 insertions(+) create mode 100644 drivers/misc/liveupdate/luo_selftests.c create mode 100644 drivers/misc/liveupdate/luo_selftests.h diff --git a/drivers/misc/liveupdate/Kconfig b/drivers/misc/liveupdate/Kcon= fig index 09940f9a724a..304217e2fe95 100644 --- a/drivers/misc/liveupdate/Kconfig +++ b/drivers/misc/liveupdate/Kconfig @@ -43,3 +43,18 @@ config LIVEUPDATE_SYSFS_API needed to coordinate application restarts and minimize downtime. =20 If unsure, say N. + +config LIVEUPDATE_SELFTESTS + bool "Live Update Orchestrator - self tests" + depends on LIVEUPDATE + help + =C2=A0 Say Y here to build self-tests for the LUO framework. When enabled, + these tests can be initiated via the ioctl interface to help verify + the core live update functionality. + + =C2=A0 This option is primarily intended for developers working on the + =C2=A0 live update feature or for validation purposes during system + =C2=A0 integration. + + =C2=A0 If you are unsure or are building a production kernel where size + =C2=A0 or attack surface is a concern, say N. diff --git a/drivers/misc/liveupdate/Makefile b/drivers/misc/liveupdate/Mak= efile index 190323c10220..1afa4059b99f 100644 --- a/drivers/misc/liveupdate/Makefile +++ b/drivers/misc/liveupdate/Makefile @@ -2,5 +2,6 @@ obj-y +=3D luo_ioctl.o obj-y +=3D luo_core.o obj-y +=3D luo_files.o +obj-$(CONFIG_LIVEUPDATE_SELFTESTS) +=3D luo_selftests.o obj-y +=3D luo_subsystems.o obj-$(CONFIG_LIVEUPDATE_SYSFS_API) +=3D luo_sysfs.o diff --git a/drivers/misc/liveupdate/luo_internal.h b/drivers/misc/liveupda= te/luo_internal.h index bf1ba18722e2..45bf8398ab6e 100644 --- a/drivers/misc/liveupdate/luo_internal.h +++ b/drivers/misc/liveupdate/luo_internal.h @@ -40,6 +40,15 @@ void luo_sysfs_notify(void); static inline void luo_sysfs_notify(void) {} #endif =20 +#ifdef CONFIG_LIVEUPDATE_SELFTESTS +int luo_ioctl_selftests(void __user *argp); +#else +static inline int luo_ioctl_selftests(void __user *argp) +{ + return -EOPNOTSUPP; +} +#endif + extern const char *const luo_state_str[]; =20 /* Get the current state as a string */ diff --git a/drivers/misc/liveupdate/luo_ioctl.c b/drivers/misc/liveupdate/= luo_ioctl.c index 76c687ff650b..f92cea7eff82 100644 --- a/drivers/misc/liveupdate/luo_ioctl.c +++ b/drivers/misc/liveupdate/luo_ioctl.c @@ -152,6 +152,10 @@ static long luo_ioctl(struct file *filep, unsigned int= cmd, unsigned long arg) ret =3D -EFAULT; break; =20 + case LIVEUPDATE_IOCTL_SELFTESTS: + ret =3D luo_ioctl_selftests((void __user *)arg); + break; + default: pr_warn("ioctl: unknown command nr: 0x%x\n", _IOC_NR(cmd)); ret =3D -ENOTTY; diff --git a/drivers/misc/liveupdate/luo_selftests.c b/drivers/misc/liveupd= ate/luo_selftests.c new file mode 100644 index 000000000000..7956e5c2371f --- /dev/null +++ b/drivers/misc/liveupdate/luo_selftests.c @@ -0,0 +1,283 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +/** + * DOC: LUO Selftests + * + * We provide ioctl-based selftest interface for the LUO. It provides a + * mechanism to test core LUO functionality, particularly the registration, + * unregistration, and data handling aspects of LUO subsystems, without + * requiring a full live update event sequence. + * + * The tests are intended primarily for developers working on the LUO fram= ework + * or for validation purposes during system integration. This functionalit= y is + * conditionally compiled based on the `CONFIG_LIVEUPDATE_SELFTESTS` Kconf= ig + * option and should typically be disabled in production kernels. + * + * Interface: + * The selftests are accessed via the `/dev/liveupdate` character device u= sing + * the `LIVEUPDATE_IOCTL_SELFTESTS` ioctl command. The argument to the ioc= tl + * is a pointer to a `struct liveupdate_selftest` structure (defined in + * `uapi/linux/liveupdate.h`), which contains: + * - `cmd`: The specific selftest command to execute (e.g., + * `LUO_CMD_SUBSYSTEM_REGISTER`). + * - `arg`: A pointer to a command-specific argument structure. For subsys= tem + * tests, this points to a `struct luo_arg_subsystem` (defined in + * `luo_selftests.h`). + * + * Commands: + * - `LUO_CMD_SUBSYSTEM_REGISTER`: + * Registers a new dummy LUO subsystem. It allocates kernel memory for test + * data, copies initial data from the user-provided `data_page`, sets up + * simple logging callbacks, and calls the core + * `liveupdate_register_subsystem()` + * function. Requires `arg` pointing to `struct luo_arg_subsystem`. + * - `LUO_CMD_SUBSYSTEM_UNREGISTER`: + * Unregisters a previously registered dummy subsystem identified by `name= `. + * It calls the core `liveupdate_unregister_subsystem()` function and then + * frees the associated kernel memory and internal tracking structures. + * Requires `arg` pointing to `struct luo_arg_subsystem` (only `name` used= ). + * - `LUO_CMD_SUBSYSTEM_GETDATA`: + * Copies the content of the kernel data page associated with the specified + * dummy subsystem (`name`) back to the user-provided `data_page`. This al= lows + * userspace to verify the state of the data after potential test operatio= ns. + * Requires `arg` pointing to `struct luo_arg_subsystem`. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include "luo_internal.h" +#include "luo_selftests.h" + +struct luo_subsystems { + struct liveupdate_subsystem handle; + char name[LUO_NAME_LENGTH]; + void *data; + bool in_use; +} luo_subsystems[LUO_MAX_SUBSYSTEMS]; + +/* Only allow one selftest ioctl operation at a time */ +static DEFINE_MUTEX(luo_ioctl_mutex); + +static int luo_subsystem_prepare(void *arg, u64 *data) +{ + unsigned long i =3D (unsigned long)arg; + unsigned long phys_addr =3D __pa(luo_subsystems[i].data); + int ret; + + ret =3D kho_preserve_phys(phys_addr, PAGE_SIZE); + if (ret) + return ret; + + *data =3D phys_addr; + pr_info("Subsystem '%s' prepare data[%lx]\n", + luo_subsystems[i].name, phys_addr); + + return 0; +} + +static int luo_subsystem_freeze(void *arg, u64 *data) +{ + unsigned long i =3D (unsigned long)arg; + + pr_info("Subsystem '%s' freeze data[%llx]\n", + luo_subsystems[i].name, *data); + + return 0; +} + +static void luo_subsystem_cancel(void *arg, u64 data) +{ + unsigned long i =3D (unsigned long)arg; + + pr_info("Subsystem '%s' canel data[%llx]\n", + luo_subsystems[i].name, data); +} + +static void luo_subsystem_finish(void *arg, u64 data) +{ + unsigned long i =3D (unsigned long)arg; + + pr_info("Subsystem '%s' finish data[%llx]\n", + luo_subsystems[i].name, data); +} + +static int luo_subsystem_idx(char *name) +{ + int i; + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + if (luo_subsystems[i].in_use && + !strcmp(luo_subsystems[i].name, name)) + break; + } + + if (i =3D=3D LUO_MAX_SUBSYSTEMS) { + pr_warn("Subsystem with name '%s' is not registred\n", name); + + return -EINVAL; + } + + return i; +} + +static void luo_put_and_free_subsystem(char *name) +{ + int i =3D luo_subsystem_idx(name); + + if (i < 0) + return; + + free_page((unsigned long)luo_subsystems[i].data); + luo_subsystems[i].in_use =3D false; +} + +static int luo_get_and_alloc_subsystem(char *name, void __user *data, + struct liveupdate_subsystem **hp) +{ + unsigned long page_addr, i; + + page_addr =3D get_zeroed_page(GFP_KERNEL); + if (!page_addr) { + pr_warn("Failed to allocate memory for subsystem data\n"); + return -ENOMEM; + } + + if (copy_from_user((void *)page_addr, data, PAGE_SIZE)) { + free_page(page_addr); + return -EFAULT; + } + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + if (!luo_subsystems[i].in_use) + break; + } + + if (i =3D=3D LUO_MAX_SUBSYSTEMS) { + pr_warn("Maximum number of subsystems registered\n"); + return -ENOMEM; + } + + luo_subsystems[i].in_use =3D true; + luo_subsystems[i].handle.prepare =3D luo_subsystem_prepare; + luo_subsystems[i].handle.freeze =3D luo_subsystem_freeze; + luo_subsystems[i].handle.cancel =3D luo_subsystem_cancel; + luo_subsystems[i].handle.finish =3D luo_subsystem_finish; + luo_subsystems[i].handle.name =3D luo_subsystems[i].name; + luo_subsystems[i].handle.arg =3D (void *)i; + strscpy(luo_subsystems[i].name, name, LUO_NAME_LENGTH); + luo_subsystems[i].data =3D (void *)page_addr; + + *hp =3D &luo_subsystems[i].handle; + + return 0; +} + +static int luo_cmd_subsystem_unregister(void __user *argp) +{ + struct luo_arg_subsystem arg; + int ret, i; + + if (copy_from_user(&arg, argp, sizeof(arg))) + return -EFAULT; + + i =3D luo_subsystem_idx(arg.name); + if (i < 0) + return i; + + ret =3D liveupdate_unregister_subsystem(&luo_subsystems[i].handle); + if (ret) + return ret; + + luo_put_and_free_subsystem(arg.name); + + return 0; +} + +static int luo_cmd_subsystem_register(void __user *argp) +{ + struct liveupdate_subsystem *h; + struct luo_arg_subsystem arg; + int ret; + + if (copy_from_user(&arg, argp, sizeof(arg))) + return -EFAULT; + + ret =3D luo_get_and_alloc_subsystem(arg.name, + (void __user *)arg.data_page, &h); + if (ret) + return ret; + + ret =3D liveupdate_register_subsystem(h); + if (ret) + luo_put_and_free_subsystem(arg.name); + + return ret; +} + +static int luo_cmd_subsystem_getdata(void __user *argp) +{ + struct luo_arg_subsystem arg; + int i; + + if (copy_from_user(&arg, argp, sizeof(arg))) + return -EFAULT; + + i =3D luo_subsystem_idx(arg.name); + if (i < 0) + return i; + + if (copy_to_user(arg.data_page, luo_subsystems[i].data, + PAGE_SIZE)) { + return -EFAULT; + } + + return 0; +} + +int luo_ioctl_selftests(void __user *argp) +{ + struct liveupdate_selftest luo_st; + void __user *cmd_argp; + int ret =3D 0; + + if (copy_from_user(&luo_st, argp, sizeof(luo_st))) + return -EFAULT; + + cmd_argp =3D (void __user *)luo_st.arg; + + mutex_lock(&luo_ioctl_mutex); + switch (luo_st.cmd) { + case LUO_CMD_SUBSYSTEM_REGISTER: + ret =3D luo_cmd_subsystem_register(cmd_argp); + break; + + case LUO_CMD_SUBSYSTEM_UNREGISTER: + ret =3D luo_cmd_subsystem_unregister(cmd_argp); + break; + + case LUO_CMD_SUBSYSTEM_GETDATA: + ret =3D luo_cmd_subsystem_getdata(cmd_argp); + break; + + default: + pr_warn("ioctl: unknown self-test command nr: 0x%llx\n", + luo_st.cmd); + ret =3D -ENOTTY; + break; + } + mutex_unlock(&luo_ioctl_mutex); + + return ret; +} diff --git a/drivers/misc/liveupdate/luo_selftests.h b/drivers/misc/liveupd= ate/luo_selftests.h new file mode 100644 index 000000000000..a30c6ce2273e --- /dev/null +++ b/drivers/misc/liveupdate/luo_selftests.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#ifndef _LINUX_LUO_SELFTESTS_H +#define _LINUX_LUO_SELFTESTS_H + +/* Maximum number of subsystem self-test can register */ +#define LUO_MAX_SUBSYSTEMS 16 +#define LUO_NAME_LENGTH 32 + +#define LUO_CMD_SUBSYSTEM_REGISTER 0 +#define LUO_CMD_SUBSYSTEM_UNREGISTER 1 +#define LUO_CMD_SUBSYSTEM_GETDATA 2 +struct luo_arg_subsystem { + char name[LUO_NAME_LENGTH]; + void *data_page; +}; + +#endif /* _LINUX_LUO_SELFTESTS_H */ diff --git a/include/uapi/linux/liveupdate.h b/include/uapi/linux/liveupdat= e.h index c673d08a29ea..e77a7b4e3448 100644 --- a/include/uapi/linux/liveupdate.h +++ b/include/uapi/linux/liveupdate.h @@ -81,6 +81,18 @@ struct liveupdate_fd { __u64 token; }; =20 +/** + * struct liveupdate_selftest - Holds directions for the self-test operati= ons. + * @cmd: Selftest comman defined in luo_selftests.h. + * @arg: Argument for the self test command. + * + * This structure is used only for the selftest purposes. + */ +struct liveupdate_selftest { + __u64 cmd; + __u64 arg; +}; + /* The ioctl type, documented in ioctl-number.rst */ #define LIVEUPDATE_IOCTL_TYPE 0xBA =20 @@ -297,4 +309,16 @@ struct liveupdate_fd { #define LIVEUPDATE_IOCTL_EVENT_FINISH \ _IO(LIVEUPDATE_IOCTL_TYPE, 0x07) =20 +/** + * LIVEUPDATE_IOCTL_SELFTESTS - Interface for the LUO selftests + * + * Argument: Pointer to &struct liveupdate_selftest. + * + * Use by LUO selftests, commands are declared in luo_selftests.h + * + * Return: 0 on success, negative error code on failure (e.g., invalid tok= en). + */ +#define LIVEUPDATE_IOCTL_SELFTESTS \ + _IOWR(LIVEUPDATE_IOCTL_TYPE, 0x08, struct liveupdate_selftest) + #endif /* _UAPI_LIVEUPDATE_H */ --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 3D7C9268C6B for ; Thu, 15 May 2025 18:23:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333430; cv=none; b=mtwu48aKTVs+5ai9w3/gmz3FaMVdf+qaqAp9aGXAvRzzjvmj9vPeWdPMbU+NFgNFGSXgMkGxndnk0bSCQ65bZnwPacTBAQaZXtaWXcrmu8Nq4LLetWpGP49ets0N9OCel933Hn2/tTB7hW3qFSnDU3WyXeq4f4NGaRV+u+QWIJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333430; c=relaxed/simple; bh=e4Bwg9sSIKzn/lkP2knt8ta1KGa8xV4kwB0HY1L9R14=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KOdCa+EolSDqBNtl/aYdGtOZGMqCGOWgvd4DFL2L5daClhR/kCHXGe71X/js8dxoOOWHvfBEz4QGKeSKb5L0FeMaefTmQy4RBHEuylQHEFILXmHYJW8yr5k5+VBndaqjMq9zSeadNaf+saMqYiLj9RK9A6hc+Xq32V1hKlOmfuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=je/w6cCD; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="je/w6cCD" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7c597760323so130476685a.3 for ; Thu, 15 May 2025 11:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333427; x=1747938227; 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=OgbqJ8uAFqaQzUPM6Yfuc1QdySf2ZJmkbP3YXxkM1A8=; b=je/w6cCDZnzaRU8t9hz7F5XPYe1b6Ponu/25FoV43HYxxgBIUH6e4cYr+/AcxDxita GXfFYDrIveinvrOYccHqxXWAWdneE+1h++jAADH2PTaXAK4INaIcGst14oAFaRBRqlco IXj+AhBgYVX3nN5YHMZ2DmL0O1rWOYq+kb1W230Tukq+6CeufVrtDWg+oBtR9zca3S54 5+X2besUdNh9bl7ANqQUNy3bqPve2pRrmOSSDSECAQNxoGEzqMXIiAGMGKChqWBWGiil n5d0feorzjlV0fgJ3C0qPDNtwWDUCyKM3Awwfu1qm4UE0EhPMHauxppONOBWFV1kLWG/ q4SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333427; x=1747938227; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OgbqJ8uAFqaQzUPM6Yfuc1QdySf2ZJmkbP3YXxkM1A8=; b=qhQXVPU0TJQUOixqo4WrT0oMOT6PM+jscLgyM2yIbABOUWojPeuk1cMp32s6Er/98E LCoZcP7bcbtEmuoUtHAwkCVviiIVm48l6vfH3WSuoPCuVPwvcL5Rc0jz80gOPoaUdh+0 PCYCZG6Qou156ATdUcMi963X/yJEZmIMyMBs7IG97Mmbd/Yb5GkwdesxBuTxf5kf5UT3 GT0s6MrEelTlBVsy2QB0ZIzwMn2TKtru54lE+VAfSGw+OPYX1btV99t2Vrdlp4R2AxEt C8i4qwB4edjr+kIPrQU7/B0BE2iVY3NFfMiNqPjTKJf53NXEiY7u+t0fkMNwPjji+aGJ YngA== X-Forwarded-Encrypted: i=1; AJvYcCWlbuv1zhJROyKllrJbx/VlNaF4kFbkhkmLRHF+JVW6W8oSIrKJDaOFzLMxYhIuMJIoPUJcDu1S6DFquDk=@vger.kernel.org X-Gm-Message-State: AOJu0YwZYXZ99MS1Zm3gb6RcAuC/H8NtVoIfmzSGmr2+1FSVMrKi2+zG peMgAXxtgevopEGZX2Yk1noLggdKg72sSU7js48E3UtB+uOWxIKBUd6z4OA9rJCWZ2g= X-Gm-Gg: ASbGncvVPiSmIU9EaJfJoDSWgsDrl101H+kDhKTPdNGrFTFkO1kWuN7wArLB7vogYBo tIr4bnIkEzAU+DNgxRQ8DhEesRm1TNh5k2R6YcaOtC3Vn7eBG7TkBRl8+GU5K2leBkgnVkaApRC xbxUr4DMzXBfx/bDrVoex0R4VS4HMQAfIPbyDlSku3vCHbTilcoD6yrDCa34bo4s8Lu5JDPDKmI qN3pOwmJ9FMBVF0JruKfWJROI1BjBdzR2UGo8XI0FzSfRsCGoAJUsUY/pRCqVyHcQAvaaOzVlam j5tF/two3pchuHJ0tqftZkuqbhVDW4oadaYX7s7QS6epaEc7c3KIJqZERtLVBa4V5pVL0g1xFdv Xh7F0tAwV+Ir/ASd5eQWrj1lMLphFVkxbH/m7GqdjLMRQ X-Google-Smtp-Source: AGHT+IHbo0BqjSV7553DLTOcjGLoeCOmefHo9uBHE4Z501wh+amUmwMVZNZST76DsyUEX0+3rFyCYg== X-Received: by 2002:a05:620a:2886:b0:7c5:562d:ccf8 with SMTP id af79cd13be357-7cd46707fe4mr91925285a.8.1747333426761; Thu, 15 May 2025 11:23:46 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:46 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 14/16] selftests/liveupdate: add subsystem/state tests Date: Thu, 15 May 2025 18:23:18 +0000 Message-ID: <20250515182322.117840-15-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" Introduces a new set of userspace selftests for the LUO. These tests verify the functionality LUO by using the kernel-side selftest ioctls provided by the LUO module, primarily focusing on subsystem management and basic LUO state transitions. Signed-off-by: Pasha Tatashin --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 7 + tools/testing/selftests/liveupdate/config | 6 + .../testing/selftests/liveupdate/liveupdate.c | 440 ++++++++++++++++++ 5 files changed, 455 insertions(+) create mode 100644 tools/testing/selftests/liveupdate/.gitignore create mode 100644 tools/testing/selftests/liveupdate/Makefile create mode 100644 tools/testing/selftests/liveupdate/config create mode 100644 tools/testing/selftests/liveupdate/liveupdate.c diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Mak= efile index 80fb84fa3cfc..1a96e806a5dd 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -52,6 +52,7 @@ TARGETS +=3D kvm TARGETS +=3D landlock TARGETS +=3D lib TARGETS +=3D livepatch +TARGETS +=3D liveupdate TARGETS +=3D lkdtm TARGETS +=3D lsm TARGETS +=3D membarrier diff --git a/tools/testing/selftests/liveupdate/.gitignore b/tools/testing/= selftests/liveupdate/.gitignore new file mode 100644 index 000000000000..af6e773cf98f --- /dev/null +++ b/tools/testing/selftests/liveupdate/.gitignore @@ -0,0 +1 @@ +/liveupdate diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/se= lftests/liveupdate/Makefile new file mode 100644 index 000000000000..2a573c36016e --- /dev/null +++ b/tools/testing/selftests/liveupdate/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +CFLAGS +=3D -Wall -O2 -Wno-unused-function +CFLAGS +=3D $(KHDR_INCLUDES) + +TEST_GEN_PROGS +=3D liveupdate + +include ../lib.mk diff --git a/tools/testing/selftests/liveupdate/config b/tools/testing/self= tests/liveupdate/config new file mode 100644 index 000000000000..382c85b89570 --- /dev/null +++ b/tools/testing/selftests/liveupdate/config @@ -0,0 +1,6 @@ +CONFIG_KEXEC_FILE=3Dy +CONFIG_KEXEC_HANDOVER=3Dy +CONFIG_KEXEC_HANDOVER_DEBUG=3Dy +CONFIG_LIVEUPDATE=3Dy +CONFIG_LIVEUPDATE_SYSFS_API=3Dy +CONFIG_LIVEUPDATE_SELFTESTS=3Dy diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testin= g/selftests/liveupdate/liveupdate.c new file mode 100644 index 000000000000..0007085e2b96 --- /dev/null +++ b/tools/testing/selftests/liveupdate/liveupdate.c @@ -0,0 +1,440 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (c) 2025, Google LLC. + * Pasha Tatashin + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "../kselftest.h" +#include "../kselftest_harness.h" +#include "../../../../drivers/misc/liveupdate/luo_selftests.h" + +struct subsystem_info { + void *data_page; + void *verify_page; + char test_name[LUO_NAME_LENGTH]; + bool registered; +}; + +FIXTURE(subsystem) { + enum liveupdate_state state; + int fd; + struct subsystem_info si[LUO_MAX_SUBSYSTEMS]; +}; + +FIXTURE(state) { + enum liveupdate_state state; + int fd; +}; + +#define LUO_DEVICE "/dev/liveupdate" +#define LUO_SYSFS_STATE "/sys/kernel/liveupdate/state" +static size_t page_size; + +const char *const luo_state_str[] =3D { + [LIVEUPDATE_STATE_NORMAL] =3D "normal", + [LIVEUPDATE_STATE_PREPARED] =3D "prepared", + [LIVEUPDATE_STATE_FROZEN] =3D "frozen", + [LIVEUPDATE_STATE_UPDATED] =3D "updated", +}; + +static int run_luo_selftest_cmd(int fd, __u64 cmd_code, + struct luo_arg_subsystem *subsys_arg) +{ + struct liveupdate_selftest k_arg; + + if (fd < 0) { + errno =3D EBADF; + return -1; + } + + k_arg.cmd =3D cmd_code; + k_arg.arg =3D (__u64)(unsigned long)subsys_arg; + + return ioctl(fd, LIVEUPDATE_IOCTL_SELFTESTS, &k_arg); +} + +static int __register_subsystem(int fd, char *name, void *data_page) +{ + struct luo_arg_subsystem subsys_arg; + + memset(&subsys_arg, 0, sizeof(subsys_arg)); + snprintf(subsys_arg.name, LUO_NAME_LENGTH, "%s", name); + subsys_arg.data_page =3D data_page; + + return run_luo_selftest_cmd(fd, LUO_CMD_SUBSYSTEM_REGISTER, + &subsys_arg); +} + +static int __unregister_subsystem(int fd, char *name) +{ + struct luo_arg_subsystem subsys_arg; + + memset(&subsys_arg, 0, sizeof(subsys_arg)); + snprintf(subsys_arg.name, LUO_NAME_LENGTH, "%s", name); + + return run_luo_selftest_cmd(fd, LUO_CMD_SUBSYSTEM_UNREGISTER, + &subsys_arg); +} + +static int get_sysfs_state(void) +{ + char buf[64]; + ssize_t len; + int fd, i; + + fd =3D open(LUO_SYSFS_STATE, O_RDONLY); + if (fd < 0) { + ksft_print_msg("Failed to open sysfs state file '%s': %s\n", + LUO_SYSFS_STATE, strerror(errno)); + return -errno; + } + + len =3D read(fd, buf, sizeof(buf) - 1); + close(fd); + + if (len <=3D 0) { + ksft_print_msg("Failed to read sysfs state file '%s': %s\n", + LUO_SYSFS_STATE, strerror(errno)); + return -errno; + } + if (buf[len - 1] =3D=3D '\n') + buf[len - 1] =3D '\0'; + else + buf[len] =3D '\0'; + + for (i =3D 0; i < ARRAY_SIZE(luo_state_str); i++) { + if (!strcmp(buf, luo_state_str[i])) + return i; + } + + return -EIO; +} + +FIXTURE_SETUP(state) +{ + page_size =3D sysconf(_SC_PAGE_SIZE); + self->fd =3D open(LUO_DEVICE, O_RDWR); + if (self->fd < 0) { + ksft_exit_skip("Setup: Cannot open %s (errno %d).\n", + LUO_DEVICE, errno); + } + self->state =3D LIVEUPDATE_STATE_NORMAL; +} + +FIXTURE_TEARDOWN(state) +{ + page_size =3D sysconf(_SC_PAGE_SIZE); + if (self->state !=3D LIVEUPDATE_STATE_NORMAL) + ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_CANCEL, NULL); + close(self->fd); +} + +FIXTURE_SETUP(subsystem) +{ + int i; + + page_size =3D sysconf(_SC_PAGE_SIZE); + memset(&self->si, 0, sizeof(self->si)); + self->fd =3D open(LUO_DEVICE, O_RDWR); + if (self->fd < 0) { + ksft_exit_skip("Setup: Cannot open %s (errno %d).\n", + LUO_DEVICE, errno); + } + self->state =3D LIVEUPDATE_STATE_NORMAL; + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + snprintf(self->si[i].test_name, LUO_NAME_LENGTH, + "ksft_luo_%d.%d", getpid(), i); + + self->si[i].data_page =3D mmap(NULL, page_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + + if (self->si[i].data_page =3D=3D MAP_FAILED) { + ksft_print_msg("Setup: mmap data_page failed\n"); + goto exit_fail; + } + memset(self->si[i].data_page, 'A' + i, page_size); + + self->si[i].verify_page =3D mmap(NULL, page_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if (self->si[i].verify_page =3D=3D MAP_FAILED) { + ksft_print_msg("Setup: mmap verify_page failed\n"); + goto exit_fail; + } + memset(self->si[i].verify_page, 0, page_size); + } + + return; +exit_fail: + close(self->fd); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + void *page; + + page =3D self->si[i].data_page; + if (page && page !=3D MAP_FAILED) + munmap(page, page_size); + + page =3D self->si[i].verify_page; + if (page && page !=3D MAP_FAILED) + munmap(page, page_size); + } + ksft_exit_fail(); +} + +FIXTURE_TEARDOWN(subsystem) +{ + int i; + + if (self->state !=3D LIVEUPDATE_STATE_NORMAL) + ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_CANCEL, NULL); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + if (self->si[i].registered) { + struct luo_arg_subsystem subsys_arg; + + memset(&subsys_arg, 0, sizeof(subsys_arg)); + snprintf(subsys_arg.name, LUO_NAME_LENGTH, "%s", + self->si[i].test_name); + subsys_arg.data_page =3D NULL; + run_luo_selftest_cmd(self->fd, LUO_CMD_SUBSYSTEM_UNREGISTER, + &subsys_arg); + } + munmap(self->si[i].data_page, page_size); + munmap(self->si[i].verify_page, page_size); + } + + close(self->fd); +} + +TEST_F(state, normal) +{ + enum liveupdate_state state; + int ret; + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state); + ASSERT_EQ(0, ret); + ASSERT_EQ(state, LIVEUPDATE_STATE_NORMAL); +} + +TEST_F(state, prepared) +{ + enum liveupdate_state state; + int ret; + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_PREPARE, NULL); + ASSERT_EQ(0, ret); + self->state =3D LIVEUPDATE_STATE_PREPARED; + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state); + ASSERT_EQ(0, ret); + ASSERT_EQ(state, LIVEUPDATE_STATE_PREPARED); + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_CANCEL, NULL); + ASSERT_EQ(0, ret); + self->state =3D LIVEUPDATE_STATE_NORMAL; + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state); + ASSERT_EQ(0, ret); + ASSERT_EQ(state, LIVEUPDATE_STATE_NORMAL); +} + +TEST_F(state, sysfs_normal) +{ + int state =3D get_sysfs_state(); + + if (state < 0) { + if (state =3D=3D -ENOENT || state =3D=3D -EACCES) { + ksft_test_result_skip("Sysfs state file not accessible (%d)\n", + state); + return; + } + } + + ASSERT_EQ(LIVEUPDATE_STATE_NORMAL, state); +} + +TEST_F(state, sysfs_prepared) +{ + int ret, state; + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_PREPARE, NULL); + ASSERT_EQ(0, ret); + self->state =3D LIVEUPDATE_STATE_PREPARED; + + state =3D get_sysfs_state(); + if (state < 0) { + if (state =3D=3D -ENOENT || state =3D=3D -EACCES) { + ksft_test_result_skip("Sysfs state file not accessible (%d)\n", + state); + ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_CANCEL, NULL); + self->state =3D LIVEUPDATE_STATE_NORMAL; + return; + } + } + ASSERT_EQ(LIVEUPDATE_STATE_PREPARED, state); + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_CANCEL, NULL); + ASSERT_EQ(0, ret); + self->state =3D LIVEUPDATE_STATE_NORMAL; + state =3D get_sysfs_state(); + ASSERT_EQ(LIVEUPDATE_STATE_NORMAL, state); +} + +TEST_F(state, sysfs_frozen) +{ + int ret, state; + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_PREPARE, NULL); + ASSERT_EQ(0, ret); + self->state =3D LIVEUPDATE_STATE_PREPARED; + + state =3D get_sysfs_state(); + if (state < 0) { + if (state =3D=3D -ENOENT || state =3D=3D -EACCES) { + ksft_test_result_skip("Sysfs state file not accessible (%d)\n", state); + ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_CANCEL, NULL); + self->state =3D LIVEUPDATE_STATE_NORMAL; + return; + } + } + ASSERT_EQ(LIVEUPDATE_STATE_PREPARED, state); + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_FREEZE, NULL); + ASSERT_EQ(0, ret); + self->state =3D LIVEUPDATE_STATE_FROZEN; + state =3D get_sysfs_state(); + ASSERT_EQ(LIVEUPDATE_STATE_FROZEN, state); + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_CANCEL, NULL); + ASSERT_EQ(0, ret); + self->state =3D LIVEUPDATE_STATE_NORMAL; + state =3D get_sysfs_state(); + ASSERT_EQ(LIVEUPDATE_STATE_NORMAL, state); +} + +TEST_F(subsystem, register_unregister) +{ + int ret; + + ret =3D __register_subsystem(self->fd, self->si[0].test_name, + self->si[0].data_page); + ASSERT_EQ(0, ret); + self->si[0].registered =3D true; + + ret =3D __unregister_subsystem(self->fd, self->si[0].test_name); + ASSERT_EQ(0, ret); + self->si[0].registered =3D false; +} + +TEST_F(subsystem, double_unregister) +{ + int ret; + + ret =3D __register_subsystem(self->fd, self->si[0].test_name, + self->si[0].data_page); + ASSERT_EQ(0, ret); + self->si[0].registered =3D true; + + ret =3D __unregister_subsystem(self->fd, self->si[0].test_name); + ASSERT_EQ(0, ret); + self->si[0].registered =3D false; + + ret =3D __unregister_subsystem(self->fd, self->si[0].test_name); + EXPECT_NE(0, ret); + EXPECT_TRUE(errno =3D=3D EINVAL || errno =3D=3D ENOENT); + self->si[0].registered =3D false; +} + +TEST_F(subsystem, register_unregister_many) +{ + int ret; + int i; + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + ret =3D __register_subsystem(self->fd, self->si[i].test_name, + self->si[i].data_page); + ASSERT_EQ(0, ret); + self->si[i].registered =3D true; + } + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + ret =3D __unregister_subsystem(self->fd, self->si[i].test_name); + ASSERT_EQ(0, ret); + self->si[i].registered =3D false; + } + +} + +TEST_F(subsystem, getdata_verify) +{ + enum liveupdate_state state; + int ret; + int i; + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + ret =3D __register_subsystem(self->fd, self->si[i].test_name, + self->si[i].data_page); + ASSERT_EQ(0, ret); + self->si[i].registered =3D true; + } + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_PREPARE, NULL); + ASSERT_EQ(0, ret); + self->state =3D LIVEUPDATE_STATE_PREPARED; + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state); + ASSERT_EQ(0, ret); + ASSERT_EQ(state, LIVEUPDATE_STATE_PREPARED); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + struct luo_arg_subsystem subsys_arg; + + memset(&subsys_arg, 0, sizeof(subsys_arg)); + snprintf(subsys_arg.name, LUO_NAME_LENGTH, "%s", + self->si[i].test_name); + subsys_arg.data_page =3D self->si[i].verify_page; + + ret =3D run_luo_selftest_cmd(self->fd, LUO_CMD_SUBSYSTEM_GETDATA, + &subsys_arg); + + ASSERT_EQ(0, ret); + ASSERT_EQ(0, memcmp(self->si[i].data_page, + self->si[i].verify_page, + page_size)); + } + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_EVENT_CANCEL, NULL); + ASSERT_EQ(0, ret); + self->state =3D LIVEUPDATE_STATE_NORMAL; + + ret =3D ioctl(self->fd, LIVEUPDATE_IOCTL_GET_STATE, &state); + ASSERT_EQ(0, ret); + ASSERT_EQ(state, LIVEUPDATE_STATE_NORMAL); + + for (i =3D 0; i < LUO_MAX_SUBSYSTEMS; i++) { + ret =3D __unregister_subsystem(self->fd, self->si[i].test_name); + ASSERT_EQ(0, ret); + self->si[i].registered =3D false; + } +} + +TEST_HARNESS_MAIN --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 51397268FFF for ; Thu, 15 May 2025 18:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333431; cv=none; b=Hh4nHmHgGazubyjxK+5i0Selcve8GnDOv89PtE5cEYLvgP1JX7Gn5pL2jCojguoy3solVKjQu//TVD8QhWQFr9nIllRMTpu1MqdVU42dzANvATAtoR1jIdfse/CWUy4Hl7wEVxsu0v6lNz6XwwghMlJ28SuOW8GICfXc8xZylt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333431; c=relaxed/simple; bh=VRCETR/ZNMscZ4PQziAJBi6EbuBypp6uz2gXjli2EYg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fqzTFuvnY/vdUKOMFAL54nle1ztYW+pT71ZSf9WKv4N7vdPaj19MKipdrq6tStYzxfIVs5CghqxEV1H7vsICllkU3lA22kMLcqoQHNbQt/fPZVvEY31e+4yfgTwM2nc/K5a2Nk1qBkPdGw6Vjg3JjftJaSnOc8lAAy+1ykxCiNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=piDK4RO+; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="piDK4RO+" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7c96759d9dfso175719985a.3 for ; Thu, 15 May 2025 11:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333428; x=1747938228; 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=P6KJXTjc0r76p8v9NLIxG+1plF/W6x+7amHEacWowEk=; b=piDK4RO+9tkwg4jUhMDgPVkkjIeDkrL4nwJsbE+YHnPeOJybDtb3y7k0a4xIPCj+L7 0LssXD3ewidk9RUsycKZWGycnqGbtF1aQFW3fzIrzhRGJhzcTauaTst3CtqPUKJhM+cn B32VJc1PBbpJlzgrVOi8z6HQV5MC+SVlI/B9oC574jayWmDzcNMj1n+NBvygsQn5UKMq 87Y+vUFE/+UgixTcN8XsE+1UgdYtyyZmhvzk8H1lu/PmwuVvwzRU778POKUdcGLS+Xzj fLZAtOGrh4zILl1SCRbdqy9xyTr7jdp3HHynCejX5VwT/M8e2yR1TxzGh6WissHUPoFP konQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333428; x=1747938228; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P6KJXTjc0r76p8v9NLIxG+1plF/W6x+7amHEacWowEk=; b=pj1ZviwKji5U6mrHA/sHjFWk1hXcuLVfEAEzmtQ4PRjJfTpZEMHuoXtDw8S29Bot/X SnWyjW5dLH3yMxPqf0PyscAvrpkJnlkrtHIG42EZZmP1TtapvTDjmzreUZ0JHW/fz4D9 f9vb1Xacmq9Fobf7Ac3q08ctx1pyLo7YxpsiVbNN0bhB6Oc9t/HyANEw4m1YbH5Sn//W w6QzhyqGkZCC0tX5T/kxx8hinUVmVnTUKstMPqIDAZrCh8xmnUa6W8gBShkMtyWObIl3 gvjgN5sekIhUwDXPAarxOc+xuzsZrrBHfuPQd+lE64TXps/DJxgfp2SgaLD1gU5F15Ei U8aw== X-Forwarded-Encrypted: i=1; AJvYcCV+sD1B5ianTJMB48HjPU75Xvc75Q4YuKiQ/8WG74YwP7raKOH4a0bPsc3zZZCrpk+NKgoVGQwDJrUL0zU=@vger.kernel.org X-Gm-Message-State: AOJu0YwkHBOnr01yIvTkgl40ShAYLhNthfsFOCwQsrX12ptzU70gdcS+ 36BperVR7s5iGuL/CUqMVclgReZPrMtdAcDDSRDlhypkwPE3CcaRKAQBwN31PmkbTvU= X-Gm-Gg: ASbGncsakAGNIsyUn9WofQJ/iEB5CWQ+W4AD5D/T9Da6gZ+dRvegtjsZNbrymLmDJux IihlVwFOa98/p41zZ3a9o5mJ3qIJookK5crKV8DnR1fqVPOBz7JNv+zh9AJ3k2YJaGImBV1cT5C j8ytEzYXTK4RREF1oaTYtLy9WA3WyOc7pQiCvtiBqZJdzidLtR9jbR7REthPwQQEhiDPQZAOCQU 7x8lsBFmsePUY7TL9EtvAwo+BHm39PSptbKZI+KrD5jdJwg9IlHKJIAQVT+pEhI06KBh7LLcQL8 HYdPUUvomwQrwl3MTm6FZ4hHU4YnzL6jyXtVGHyQ1u17HuD6eXGLyeS73vZzmDJozDwHCYBiy38 QqUNWr1g2+BhS41t+keHdhMkFMsme1tK7h/mnftjX9Yic X-Google-Smtp-Source: AGHT+IEG7RwmXqR/Tm2fInhaZBiu3WtaiEVf8X1895Z0lbevuSTfErYi54kRZ9n6luWpwWWeTV+CYQ== X-Received: by 2002:a05:620a:d89:b0:7c5:4b24:468d with SMTP id af79cd13be357-7cd46707195mr63632785a.2.1747333428187; Thu, 15 May 2025 11:23:48 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:47 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 15/16] docs: add luo documentation Date: Thu, 15 May 2025 18:23:19 +0000 Message-ID: <20250515182322.117840-16-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" Add the main documentation file for the Live Update Orchestrator subsystem at Documentation/admin-guide/liveupdate.rst. The new file is included in the main Documentation/admin-guide/index.rst table of contents. Signed-off-by: Pasha Tatashin --- Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/liveupdate.rst | 62 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Documentation/admin-guide/liveupdate.rst diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guid= e/index.rst index 259d79fbeb94..3f59ccf32760 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -95,6 +95,7 @@ likely to be of interest on almost any system. cgroup-v2 cgroup-v1/index cpu-load + liveupdate mm/index module-signing namespaces/index diff --git a/Documentation/admin-guide/liveupdate.rst b/Documentation/admin= -guide/liveupdate.rst new file mode 100644 index 000000000000..bff9475d2518 --- /dev/null +++ b/Documentation/admin-guide/liveupdate.rst @@ -0,0 +1,62 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D +Live Update Orchestrator (LUO) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D +:Author: Pasha Tatashin + +.. kernel-doc:: drivers/misc/liveupdate/luo_core.c + :doc: Live Update Orchestrator (LUO) + +LUO Subsystems Participation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D +.. kernel-doc:: drivers/misc/liveupdate/luo_subsystems.c + :doc: LUO Subsystems support + +LUO Preserving File Descriptors +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: drivers/misc/liveupdate/luo_files.c + :doc: LUO file descriptors + +LUO ioctl interface +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: drivers/misc/liveupdate/luo_ioctl.c + :doc: LUO ioctl Interface + +LUO sysfs interface +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: drivers/misc/liveupdate/luo_sysfs.c + :doc: LUO sysfs interface + +LUO selftests ioctl +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: drivers/misc/liveupdate/luo_selftests.c + :doc: LUO Selftests + +ioctl uAPI +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: include/uapi/linux/liveupdate.h + +Public API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: include/linux/liveupdate.h + +.. kernel-doc:: drivers/misc/liveupdate/luo_core.c + :export: + +.. kernel-doc:: drivers/misc/liveupdate/luo_subsystems.c + :export: + +.. kernel-doc:: drivers/misc/liveupdate/luo_files.c + :export: + +Internal API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: drivers/misc/liveupdate/luo_core.c + :internal: + +.. kernel-doc:: drivers/misc/liveupdate/luo_subsystems.c + :internal: + +.. kernel-doc:: drivers/misc/liveupdate/luo_files.c + :internal: --=20 2.49.0.1101.gccaa498523-goog From nobody Mon Feb 9 06:48:09 2026 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (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 D4B4B26980F for ; Thu, 15 May 2025 18:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333433; cv=none; b=KB6w8XlNb4jCxFfhU+TXEMj3VY3HkHjiWdsdnFiVLDysWhhQOpCdFmnX8jXnjH3uJHYqMyhwg0ds7BWbPyqO2gl+zTo3BE7DQAoRnKgIBplZtcsus4CCs5thDpPkPWbOBzN/LIU9cqQ1LoWRwQlj1Es3GZ7UafSpnxSmmgrO8fg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747333433; c=relaxed/simple; bh=YaE0d21aL4ypcSNyRnSQBH6nYjgCRfkHddqKY3G90JA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iSyOTPS/R4hIANq7JSz7wkFeWZJ+s5MDm8kGnwXYPviUT2WOyeRsfqu2MzaRBEju5xhDGz3BScR+9s4N8m1ricA8V0QRRMwAqWFu+hoE0cI8EkYN53v0St/ZVCsFhbypB3iA+QlryEClYaEEVsKRqPBrixlBL8696z99Sk4CqWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=FAoAOoLd; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="FAoAOoLd" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7c54b651310so159307785a.0 for ; Thu, 15 May 2025 11:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1747333429; x=1747938229; 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=/UkhatAda5pzqxG11ONXrnfa3++BT9kkRoGoO4mFl6c=; b=FAoAOoLd6QYmSjM6SUEUmnwyBnT2AdRAN6cfGWxnEEpuhJYfAdi00tbPkfnLHJMYnw NWz+dNniMpXPt4ee3XoPx1edtzkLlkQiV/ThsDEQees28704JfYMgV7M6xk3kYhGHr7Z ja0lX+F2xuNJxx+8OopdGGeWkD7xpxUTHyhRDiLUsgYCSB1AsmGrRuJeLIT9JF3eQ2yd FwsdNfQ399hycjca8F/hajfpNAElD3MoGZ6N5cwYBZIuvNPqQFbE+en/tPzuB+gbIrwe zlMaP+EffIQUCn+tuLLVmPgDDEsOKaTJ7NWrQ/BsvJhQ5WqApOTnI42L7+JUhMimTgBz w2xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747333429; x=1747938229; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/UkhatAda5pzqxG11ONXrnfa3++BT9kkRoGoO4mFl6c=; b=ZVhHbkkrY0RJ9ON7xItrAdED3qfHJpFXMXlYd6o7DAV08IKe7JHgBAW1QoM3DNG5sN GcX4/7Lcz6B/JG+VSau6EOwRaHxWsebsUmHFb2UNMaPuDz68+Krfwz9HTEVcU3AIaE1c Bi1IetPeAkDbkaOV53VXcbHwRN6dnj4Qreq+bdzX1N7UUezKiLJdhv+XdboBcwPBgSUP 57w76p/EqCiQvoja9qjicNyAsrKqs4snwEnolUVEyGI5tSwhxo0rAWG3iiXYvBxqNE8f +Jq8KeHfUa5OBJLEWZ6F+4XOK6VqLejuo7uEjDP1bqHwAos4Oehq5rU5S1Jq8ve3zNR6 6/2A== X-Forwarded-Encrypted: i=1; AJvYcCWHisuIbdVC8KDn6NeuY3t7u8wDZxctCbPcKD+4F9Op4swevOoTUbxQEcKqDtK28R0fUxnvedeMQPSvI3k=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2qXx1KYBAmvfP6+hVzRWOUD3O/Kb24eWdtfQwn42W/geNSxWD owrAKORPcjgxQMJXPsuYHusvs6F3lx0a6XWppwb1DlqonUretNSo1wEB4f5/XzTnWGs= X-Gm-Gg: ASbGncuXpOpklbe5RCNz4sLv6GW++3Vm6LpAnQHevjI62/74A60PHYydgAF6tP3hHuC szn/ZeSA1WBl1X9LaSnlcXuMJB6juw6QiyycnMWnvVuzpnZqLzbNRHzW/l7ih3s0DdrLj/k/DGu yQghU07aaf5P/pt5neKVUZLwJRUoBkdVqd3viuOBEP9SGcslcaOunTZMPyzF783xEgwolhcBKKi 39udwQgXYR2aT+zBrAZF3pUPltcFdzAVMi1YGD/7fkNiRopJQu57SDTpGsKzCfZYElHJ9cLBH7X 6VMEYZWhyq6C3wxkMfncka+VtOKxIwSAlXzJUmzpuYe1ZddV5HfzaikUbanXzz5u13i55fXsyRJ fUl/11CEhu2gx0fpSjo9aywCMBSivU9IiX59INFmxi1IlY2WqQ2rFYtE= X-Google-Smtp-Source: AGHT+IEMo9czCluXO4G1WUwXTZGTpWwBloBS5Kz3sFDyqt4FQLh+A2ENHLRTo8aoPbEVNVI7zemMmQ== X-Received: by 2002:a05:620a:4885:b0:7cc:fde8:81cd with SMTP id af79cd13be357-7cd46722312mr74875585a.24.1747333429367; Thu, 15 May 2025 11:23:49 -0700 (PDT) Received: from soleen.c.googlers.com.com (138.200.150.34.bc.googleusercontent.com. [34.150.200.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7cd466fc2afsm18218685a.0.2025.05.15.11.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 11:23:48 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de Subject: [RFC v2 16/16] MAINTAINERS: add liveupdate entry Date: Thu, 15 May 2025 18:23:20 +0000 Message-ID: <20250515182322.117840-17-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog In-Reply-To: <20250515182322.117840-1-pasha.tatashin@soleen.com> References: <20250515182322.117840-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" Add a MAINTAINERS file entry for the new Live Update Orchestrator introduced in previous patches. Signed-off-by: Pasha Tatashin --- MAINTAINERS | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 4fc28b6674bd..327b2084ab79 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13806,6 +13806,17 @@ F: kernel/module/livepatch.c F: samples/livepatch/ F: tools/testing/selftests/livepatch/ =20 +LIVE UPDATE +M: Pasha Tatashin +L: linux-kernel@vger.kernel.org +S: Maintained +F: Documentation/ABI/testing/sysfs-kernel-liveupdate +F: Documentation/admin-guide/liveupdate.rst +F: drivers/misc/liveupdate/ +F: include/linux/liveupdate.h +F: include/uapi/linux/liveupdate.h +F: tools/testing/selftests/liveupdate/ + LLC (802.2) L: netdev@vger.kernel.org S: Odd fixes --=20 2.49.0.1101.gccaa498523-goog