From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FC6EC2D0CD for ; Thu, 15 May 2025 18:23:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C565D8D0002; Thu, 15 May 2025 14:23:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BFF0F8D0001; Thu, 15 May 2025 14:23:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B9BF8D0002; Thu, 15 May 2025 14:23:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 716A68D0001 for ; Thu, 15 May 2025 14:23:37 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6F50FC046B for ; Thu, 15 May 2025 18:23:38 +0000 (UTC) X-FDA: 83445965316.02.3E54001 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf07.hostedemail.com (Postfix) with ESMTP id 8E04340005 for ; Thu, 15 May 2025 18:23:36 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=JgMfNQKc; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747333416; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=36BQafovF1Ac1o8l66KKhJYbiIRxHdYx4gFtUfBj6co=; b=pAbp2t+PhDLla26zBgjjiIMEHJ1+3B17eHHDPBsxke14swpwR0/mf4mSNof8Td75xp9or/ sS/GJM4Pm5hs948sX6JaZLyEBX2SiX5DDWO4fUjlN0C6IZJ9OTglljFEMkyOkzlhg/lort jymLroMc2mCEbLvmp9qAPAL3f4Xf3wc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=JgMfNQKc; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747333416; a=rsa-sha256; cv=none; b=UHI2VMZH1Z/grCf+2GdRTQ6k1aIIWNaiGoMyX+yNjljR49PqUj5g2rzfNCuiQWu7Y1FZ/j pcGpLvar8si3LUOW0/mQFIx6eWBN97pdk0Ea8oe6FZ9LKg6K2NY2bij2NTBxp1A0ysQRJI h6HLluxygg0uwAyO0GGzwvOzNkMNxUg= Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7c53b9d66fdso164111885a.3 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=kvack.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=JgMfNQKcLUO1YCMTNEJyivYhWPKKi5m8WiQOXA6Eg4VRRMePAh+TSOZb2tIa5b5UNJ gwYiX/3DyIeeg59wmdWC8rbg8Th/OwMWnEg+pYYA/pTovF0XspwzhU1yM15adrfQmD2u lB08McV22uGFGom24eY3R/Kf1jpl4d8CvMD9nJQ9nnqWvHDF8awaSe0O/uU4QZ4udzAy Ge5NRwA2Rl9qX2JcAOqb5mqiweyza7n/ofQHkpiBG1domdjvFwT095oBInk8d9LONVmM NGvEYFo+tgyCfJo+w663IAwju8qvpYb0ALXDwNhw+TRo4q7fpQcrM2m/TJHcSWfKOhfb Wr+A== 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=jDFOqNYIGqtdja4C8970LNToN/9oO7i2VbahnauC8urIGlvx642uypLCjVDm68JC4e XsqSppNngsFtHojqSJn3QymkXAykYQsL+6kS8tRIgeAjeUBfJo9Njd84XebzCMeUHKlz QLxp/IvR1jhqNw9yDWVQaEHYAOcmT+WfRoeJgS3y2QLsGmh4DYcuoHdO50AtWfmteLec SdKDbUX/AM+HNANIqS8Tp7ayQF8Ec9E7G6f5kO7lOfzwIDtyCSAp8myW6wJhXlxAjtYo L1aqo+EZrkSX1/+r6H5f4nRJ0ZNZjKgg3O6IQX+uvKr79iy9lvDqsxA2DfDkKokfXxhi E0bw== X-Forwarded-Encrypted: i=1; AJvYcCVHTFPlCNnzKo5/UHHnRuCTotRrTWrUx8FjvW5DXX5+Fj9p7aqa0jn1lpI+ck+nAOGm3J03onF7XQ==@kvack.org X-Gm-Message-State: AOJu0YxnQkSMbHJk7w0jMShrq4sPCeDjgQmHH3KdSV9GbglEC/MYEnw6 /86dcRhnvfdJzHjj3Vc8tacsm94J/7ZQCesrGinbE9PkWb42sW26c4G5yFUOkPPNvOE= X-Gm-Gg: ASbGnct6WhdvEaPVZcfhEmKae3BmiH4QaJ4LMhBjyL+PEXWZWrV2lh+KxAwdwM1CECS wjU48u9aai9idtaTqejNAG63dBp2gpyHrZe7budRQaflw1mXHZ0KIChDZm1Zh8Cb/emhK+a7oUm 1mrs6f2fLvfgOVAVC7hfjWRkECDaAerqfd7r4Bubz/t7lEGnlDycWAgTRzPKqSD5ARkw+5c8sri yYnv6s3F0ERTUh90iH2CuDNgfbnvgXXmro5dQhiINvil1uPj7ePR29wJGrAnzK+0hHMMA3NuQq4 JVTCP1qrUG/dGrKoD2AYLoGxb2/YC6bJv+ujtlRANcScmONHZd+spHJCKn20ksMTWHsiyByiSoe DEB5BcAGJoyXcIz8p8NM2YHQIZg/42CgXag1W565YMiV+ 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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: 8E04340005 X-Rspamd-Server: rspam09 X-Stat-Signature: pw5t9u6mu1ftddohcxguf65ermr1agks X-HE-Tag: 1747333416-172552 X-HE-Meta: U2FsdGVkX1+1c8R8CW019CX73sQanLD/EIRv2883v4if0E+d838iHQGlPgw+v2BquFG/Fc1qK0NniifXQ5+k/0WlCbKOjezbh1VtVL/6VBnn8dyVouNJ01TBv2vjwdHr71aHRkUdTtwPtO+aozVKZ8SgmpdREhB1DE7ojWttcgCkKXnWNMp1XO5KCfkZTSxLczUveW2vwJd5XNJDl7qYB+jbWFO6S8cuLbikO/kPpjJmaMVxURw/WATTyRjP3amB5eXkNJ4H7bVtT9s3+YqVxBXRwi60gKK0ff6ibMwuHdBkL5OUclBsetsKbYo6QGS/AFJjoNSaQlnZ9B1akGaiD612wYOeJYGXeVB6YgL/JmVjsfx1YnxGjNovyJaJJx7sOu/B2sCeEE0QPzh9qzyqc2GzHDRUuwtJPyHCv9iY0mAp8R1O3wguVJcFtMUCtyKzuXkWYwWrKh6m9IMROb56vqM5LkR39dtnDO03SHvZSWBo9HfTZ0Qnz2ptqItcHUxFrBKlmQoocguA+N7lDPGBiYpM71ptw8nz62Rqso/z1rjVe13HXZKc0G5pPt3Nmkc3wX2ot6Tx63n+h5fuq74l/mhZ66s9kETB3CAVlU732Rc975vqz4dISpBowNBKQd3HoiMnqOyM/JZ8pIMLAKFYPqos6fSq4Wsaoun7Nc0Z7GcHjFvDTL+4NjqzmWGAtYPDvNCriNbx4QrOJliX+7Yog6L3ddjPuNl2yrGFzk3D5mtA/jhLsq4Tdpqdbim4cCSD8/1RXCyd6rckPiNh598DWwIzaGAAQ2qZTORiFKQbmChcPB7mxFXAlnejVARf+f+1esILaJ5lE9ER6bRzKRI4ldIxUX9YRclifPKEGctXX/TWXtmiNSFcR5R+ntc15yI5xk8ZmIv2hRZ2GQIILJEXRFY/6+kfB0ze698+B2xxooQmML6FnYxRDe+8OSg8hl6D/auJ6mlECQmTMQOzUJ7 7TCIDeGB lqxomETF7GtMp8HaWFdHn/6f/Ra7isz94Gb7kVfgr+dq1wkgAAp8IHIlm0ZVPy538zGgx9gw/7m+ik5s7CLvZ6Wn7x8glTMr44ephvNzoJvo83XDDs0DhmETaVo8lfcdcQ3VIGV+sZqTp8viR3jHepSQqDHCNSf9hCE38YPmPSzgCmCGwq+bH7h1YK9xvajrvhkI+KP2zV9cgWPenROnK+XhzPG4sjDMsqcxRY3X7Xw7l8vnbtzMrLLQNaKw10+7bfxfCct75N7S2oIMJ1AP4/mO3t8RkgRx3ug9wjkR9uMMVqxOXYc3JhFdvFt58XVnsHv3SJlHWMP1dWgEkMzKqYlj0BvorztFj0IIjJOHJmdpsjRufR+Ilu29mOoSEM8lMkZGKheOaJDeOIc/CRcsrvkz1c1QkronpyOTjFZuvezBo/j52nIJ/+5Ttt3p9BNpWj2R7Ij0MVEnX6SbfISSPW9syYpdtYus4i+5G+/7Ez8wH1+z6QzI7NeZhVFXpYrSpV/zM X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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/Makefile 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 += luo_core.o +obj-y += luo_subsystems.o diff --git a/drivers/misc/liveupdate/luo_core.c b/drivers/misc/liveupdate/luo_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; + ret = luo_subsystems_fdt_setup(fdt_out); + if (ret) + goto exit_free; + ret = kho_preserve_phys(__pa(fdt_out), LUO_FDT_SIZE); if (ret) goto exit_free; @@ -139,20 +143,30 @@ static void luo_fdt_destroy(void) static int luo_do_prepare_calls(void) { - return 0; + int ret; + + ret = luo_do_subsystems_prepare_calls(); + + return ret; } static int luo_do_freeze_calls(void) { - return 0; + int ret; + + ret = luo_do_subsystems_freeze_calls(); + + return ret; } static void luo_do_finish_calls(void) { + luo_do_subsystems_finish_calls(); } static void luo_do_cancel_calls(void) { + luo_do_subsystems_cancel_calls(); } static int __luo_prepare(struct kho_serialization *ser) @@ -422,6 +436,7 @@ static int __init luo_startup(void) } __luo_set_state(LIVEUPDATE_STATE_UPDATED); + luo_subsystems_startup(luo_fdt_in); return 0; } diff --git a/drivers/misc/liveupdate/luo_internal.h b/drivers/misc/liveupdate/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); +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[]; /* Get the current state as a string */ diff --git a/drivers/misc/liveupdate/luo_subsystems.c b/drivers/misc/liveupdate/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 include + * 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 = 0; + int ret, node_offset; + + ret = fdt_add_subnode(fdt, 0, LUO_SUBSYSTEMS_NODE_NAME); + if (ret < 0) + goto exit_error; + + node_offset = ret; + ret = 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 = fdt_setprop(fdt, node_offset, subsystem->name, + &zero_data, sizeof(zero_data)); + if (ret < 0) + goto exit_error; + } + + luo_fdt_out = 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 startup. + * @fdt: Pointer to the LUO FDT blob passed from the previous kernel. + * + * This __init function checks the existence and validity of the '/subsystems' + * 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 = fdt_subnode_offset(fdt, 0, LUO_SUBSYSTEMS_NODE_NAME); + if (node_offset < 0) + panic("Failed to find /subsystems node\n"); + + ret = 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 = fdt; +} + +/** + * luo_do_subsystems_prepare_calls - Calls prepare callbacks and updates FDT + * if all prepares succeed. Handles cancellation on failure. + * + * Phase 1: Calls 'prepare' for all subsystems and stores results temporarily. + * 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 the 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 temporarily. + * 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 subsystems. + * + * 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 subsystems. + * + * This function is typically called when the live update process needs to be + * aborted externally, for example, after the prepare phase may have run but + * 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 with LUO + * @h: Pointer to the liveupdate_subsystem structure allocated and populated + * by the calling subsystem. + * + * Registers a subsystem handler that provides callbacks for different events + * 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 = 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 == h) { + pr_warn("Subsystem '%s' (%p) already registered.\n", + h->name, h); + ret = -EEXIST; + goto out_unlock; + } + + if (!strcmp(iter->name, h->name)) { + pr_err("Subsystem with name '%s' already registered.\n", + h->name); + ret = -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 during + * registration. + * + * Unregisters a previously registered subsystem handler. Typically called + * during module exit or subsystem teardown. LUO removes the structure from its + * internal list; the caller is responsible for any necessary memory cleanup + * 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 list. + * -EBUSY if LUO is not in the NORMAL state. + */ +int liveupdate_unregister_subsystem(struct liveupdate_subsystem *h) +{ + struct liveupdate_subsystem *iter; + bool found = false; + int ret = 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 == h) { + found = true; + break; + } + } + + if (found) { + list_del_init(&h->list); + } else { + pr_warn("Subsystem handler '%s' not found for unregistration.\n", + h->name); + ret = -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 subsystem + * 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 invalid, or + * nodes/properties are missing or invalid. + * + * Return: 0 on success. -ENOENT on error. + */ +int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, u64 *data) +{ + 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 = 3, }; +/** + * struct liveupdate_subsystem - Represents a subsystem participating in LUO + * @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 actions 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 the new + * kernel. + * Receives the u64 data set by prepare/freeze. Used for cleanup. + * @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 /* Return true if live update orchestrator is enabled */ @@ -105,6 +138,10 @@ bool liveupdate_state_updated(void); */ bool liveupdate_state_normal(void); +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 *data); + #else /* CONFIG_LIVEUPDATE */ static inline int liveupdate_reboot(void) @@ -127,5 +164,21 @@ static inline bool liveupdate_state_normal(void) return true; } +static inline int liveupdate_register_subsystem(struct liveupdate_subsystem *h) +{ + return 0; +} + +static inline int liveupdate_unregister_subsystem(struct liveupdate_subsystem *h) +{ + return 0; +} + +static inline int liveupdate_get_subsystem_data(struct liveupdate_subsystem *h, + u64 *data) +{ + return -ENODATA; +} + #endif /* CONFIG_LIVEUPDATE */ #endif /* _LINUX_LIVEUPDATE_H */ -- 2.49.0.1101.gccaa498523-goog