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 B9C98C7EE2A for ; Wed, 25 Jun 2025 23:19:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 520BA6B00D7; Wed, 25 Jun 2025 19:19:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D89A6B00D8; Wed, 25 Jun 2025 19:19:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3252E6B00D9; Wed, 25 Jun 2025 19:19:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1847C6B00D7 for ; Wed, 25 Jun 2025 19:19:07 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D9F3F1D75C4 for ; Wed, 25 Jun 2025 23:19:06 +0000 (UTC) X-FDA: 83595490692.22.5501DFF Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) by imf21.hostedemail.com (Postfix) with ESMTP id 052331C0004 for ; Wed, 25 Jun 2025 23:19:04 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=D2J9ADzP; spf=pass (imf21.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.128.170 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=1750893545; a=rsa-sha256; cv=none; b=yAipsfyeUeKgiafuxyBHnQ3bYvr5Fwu4Yge0a3ugP8zhf8DQYdU9M85u0NKZe8jnwhl1ON ER06jJbRAByAWOkSJCMsCT59iuHLO11Zj2TgishvMFpgItoUHDCFCIW/KcqzTeinemC+jn OwMIFJotp3TIw1UAver0VZIqkzAGL54= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=D2J9ADzP; spf=pass (imf21.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.128.170 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=1750893545; 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=PZSlqdnTxC2Wjx/Crjm0HF+UsFjTh+cAEzYLoPE8XGM=; b=UCK9xoQjaSFsGi2ijLrPQ03ndQwEInTImREfT5DrVIOBawgAYk0+3VSULhCCCTbHJ3M4nA WjrWjHhsGGASqCrut/PTx2a5CsPt8x+fkWLExjJxCSA1qpa/mPZ6/xIGRWQWYCZDZ2lWAi OH7ufPQnJq9dsOAIKcgXV9M4TKyoMwU= Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-70e1d8c2dc2so4469907b3.3 for ; Wed, 25 Jun 2025 16:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893544; x=1751498344; 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=PZSlqdnTxC2Wjx/Crjm0HF+UsFjTh+cAEzYLoPE8XGM=; b=D2J9ADzPDb8epR263YMAGLrsJ5Z6XGKVqfeOe+rD4CGSMsOV8OwonvwnzueBP0/+KS MmUXFwxqnsLUcvE4IHRKCy8z2Zt53QgcUB9tMEm8wNvrrGLHsFyksbZvjQq35x22iIl0 phiijs/suCFw/7T9jwMXS0Ds2nnRDjOSIObCsX7TBsVZjM7Z31MPDyXa7KK4l1cuCvWQ Ze6DEybvh1ZsI6eRU1tK2yQDL8Kqj+hq0HDWa3zIEWMFO5wmeI7k7hIc63/6pNOve3SF +0qVhKmdvSw7NCi+2OXyeOXjsSR6C513lqMyZCAIUWnJBs6uqP19koNadXKClq5NYDiY bz2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893544; x=1751498344; 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=PZSlqdnTxC2Wjx/Crjm0HF+UsFjTh+cAEzYLoPE8XGM=; b=QiFUaM62YFkDHrh+WOfubRwuc1GJiVejyLN3OaMjJrCQ19OeM/BxwK5FQf2yLosY4j 23DIi+UWErWzsetiO20c9d+KnzioeC6A9PrSsiMYapeFHqZnjt5R9hxtHk0JtWpCRbkG mtsAqvhKL1ktKvimScEVnw9Rvz6ulli22Pi6N4kx1oQq5QXdyuiKUoLZd2R0ZqmXZ96h i9eNARPhTCFAyQcpLMAy3vW9ySjaMRRHbgpJrLGe1v+frmvnhm0feIfjwL8Rj1Baf7V0 KSPBIGkL0gfbjJgIokznUz9vdwxPLajGqOsn5a3dKo+Vk7/FmafaqQIW28kUeQmwDyTT 8BsQ== X-Forwarded-Encrypted: i=1; AJvYcCXEvOODypjjbjK6JKRhfg7RfPkkWceOHswn26NVit7H5b39waO43WH5o4/FJFCE3iUCuXj9TFVa+g==@kvack.org X-Gm-Message-State: AOJu0YyXqMSLZcC3jGLZRN1sn0ezmeGAZgYkF4UeIFiAAgGXU4ZSG8Jx rOqV+YXRiYXX2nd1QuQ4sVu8SWlA7MJV/soCl0XzOwqzacU4yfx+x8teEVAx9+UK2PY= X-Gm-Gg: ASbGncu1gxnVduJct2/kJ3gHlG/LhUmGb+8dL3ZXtkLBupu05J6UsI4PxBIhoCnZnYX E/JkNH7sm4tvVYpVQ7O2QuFyUntFGxypvUTVmgd8DUIGBUe4o8FjqyOz4Ht4qZbecGX+YkVQ+vx uvHYa0zCdT6oL1iSB8yZyYb/9SIvFDzeymk07PTIF4LZ2avVxm3m1kwNHXv4dmUivrxpiqvzJYU fSc0dTNccGK8oAQ0PVyYwem+e+UbmdBCoAWlDoJ7jF6iYKULBHkjzIvHPeU1h5mWKLx8Xdde0Qt wIYC+RqZ+mXcaZ3wXZCzjhARsyYnT5LYx6OhRz0LtWiM4CkZLlHxA/32gmJ4Oq6fEMbBWD7QkTx bYzsTrfxBlQIBm/uuSemAYymhmcZvLubN6LyKKZ0z7GG45JuQGdVx X-Google-Smtp-Source: AGHT+IFUBGWR2vgXdeu6WMqjmysPRfKH2b0g+Y1BY72xIGjHQryfk9+9u7i490nYs2DPXKqM9VEAwA== X-Received: by 2002:a05:690c:6ac4:b0:70e:7663:8bb4 with SMTP id 00721157ae682-71406e064cbmr72906017b3.25.1750893543841; Wed, 25 Jun 2025 16:19:03 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:03 -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, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 12/32] liveupdate: luo_subsystems: add subsystem registration Date: Wed, 25 Jun 2025 23:17:59 +0000 Message-ID: <20250625231838.1897085-13-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: crxyjsyw5r4gjrbmhtu4j48j8zkpumtt X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 052331C0004 X-Rspam-User: X-HE-Tag: 1750893544-691239 X-HE-Meta: U2FsdGVkX1/xwxP5M8dcdvVZVK3WScXewGcuDTxSBzi5PH9SGRG+VvniIbEISapbu31fc1SufbDJadBV2OqbW4ScYPa8BwPKJMG1Bq9ZX/VVhcj4tuictkYeYI5wQbymyrgEejT1vUDxvPv9J783r7WwihVjvQd3mTgi+wcvXJjtiqFRYNXYqRT0YJvqOKzqGUA6pJWbn6jf0Vij/RmAyiwsUoNCMVgvo+TaXT+Xtp/yRez19gU8LxV4znkbKfNoZ6bPaRDjOKr3FKChrhyYRUfgQufo3azM4IlbbBU7WuGX8I5ArCovlWkLv6ygD2h0a19sngc2V0ZtC+irpBo0L/ZUZzXUfpFGCGhP69Ox6luZyP5y8qlTXr24gCLNPypfm70Ck+57dbrz8c2iLd7Zf0G/s+pILG9JN65gtabeCZL1LIYPAVxOuWHQQy94I9ZVh1DxQEa6ZkVUdthQP4psHFdeA5iEBS0tTc11FyOJVCUj14K8F1AWL+cTLEe/BGzFZQPX1qvnFvCcs1DhxAFJQ5DMaS7wp8hgI56i7QGdAotCDe1EXz2UVL/dD2rYUb5jeIZuxvy6bT0JroSp/AxGhH5GKXGbCSAVawWj6+0+KVVZsukNfrmFMVheV0KbdgMSLzhjldFFs3vTuS7qJ3Ck10TKUiHdPA3+18seL3o/4pakxsiS0U8+Ws2HKjaz/ggckpzk5Ba7rSCt4cYTmGr9d7SJSMLCnHIkVZHORnyYk52tYzs1I8f2hXx1t9RcCpfbRj+E604cccTo+WDGbb6x3E0m5NfkBV5Jm4o3jDVjRBjNnOLkXhNA141DMozoPAAj2pIBnLKYlPNmL1sNz/F6XwFvsn/j0BSGuDsi81XmuvDy9AeacaLbS+hyqbv8IXBKrnP5wqSao0wkly0IjrC4QaOfZgrM/xLBIuVHCAdofdgJErpb/DPqIUkUQ/G71rpuUBAGYynA54u6j0UJ0r2 TIuV5SN4 ytGzRtkD3cDZ5nimmBWIu4zL+iNuZufuBUt9bXxrF3dhhOxbKz8+Xhuyw3AEih8UHgsaV9rfGvIViTzXJELM2gkJd6Tq2rluLVPkpGzvzeNxjlSlun5XUtJ85bWfnc/yw9fVl566PZ7Otgs0LV2lobTynlejtT9OTAoS7SRMbAauo2tOG3pztR3Ue8AlPaU9snSoywn8/T4zedTcI7he7E9g/RpfUrCU0uJ1P4uJcf1jhi+Az3dzIFtxryAvvBknpfEUPtIL3fvERQiJKi0v+tUfMWDMKl8gPlsK6OF3QZZ32mkSF7RhsCqDh8DBNgt3/t/MaQ90izH5ScD/XIR2xuXggpt+JELDtui9vV19Bc25Q/oHjiLHr0DjdgDIdxPp2UXSojf5aqr2if2/lr4SxNA56NrjmNEOrMetOlNcB9aopdCoWm8B9fnCtyk0X1v1qWDmW06VUwfMkB35gvEbbV0rb9BabJGmrUu69RzDq/JO/W9lZ04Y1L+6GLYIWXgW5Bsih 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 --- include/linux/liveupdate.h | 61 +++++++ kernel/liveupdate/Makefile | 1 + kernel/liveupdate/luo_core.c | 19 +- kernel/liveupdate/luo_internal.h | 7 + kernel/liveupdate/luo_subsystems.c | 284 +++++++++++++++++++++++++++++ 5 files changed, 370 insertions(+), 2 deletions(-) create mode 100644 kernel/liveupdate/luo_subsystems.c diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index da8f05c81e51..fed68b9ab32b 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -88,6 +88,47 @@ enum liveupdate_state { LIVEUPDATE_STATE_UPDATED = 4, }; +/** + * struct liveupdate_subsystem_ops - LUO events callback functions + * @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. + */ +struct liveupdate_subsystem_ops { + int (*prepare)(void *arg, u64 *data); + int (*freeze)(void *arg, u64 *data); + void (*cancel)(void *arg, u64 data); + void (*finish)(void *arg, u64 data); +}; + +/** + * struct liveupdate_subsystem - Represents a subsystem participating in LUO + * @ops: Callback functions + * @name: 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 { + const struct liveupdate_subsystem_ops *ops; + const char *name; + void *arg; + struct list_head list; + u64 private_data; +}; + #ifdef CONFIG_LIVEUPDATE /* Return true if live update orchestrator is enabled */ @@ -109,6 +150,10 @@ bool liveupdate_state_normal(void); enum liveupdate_state liveupdate_get_state(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) @@ -136,5 +181,21 @@ static inline enum liveupdate_state liveupdate_get_state(void) return LIVEUPDATE_STATE_NORMAL; } +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 */ diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile index b3c72c405780..999208a1fdbb 100644 --- a/kernel/liveupdate/Makefile +++ b/kernel/liveupdate/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_KEXEC_HANDOVER) += kexec_handover.o obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) += kexec_handover_debug.o obj-$(CONFIG_LIVEUPDATE) += luo_core.o +obj-$(CONFIG_LIVEUPDATE) += luo_subsystems.o diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index c80a1f188359..fff84c51d986 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -130,6 +130,10 @@ static int luo_fdt_setup(void) 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; @@ -160,20 +164,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(void) @@ -419,6 +433,7 @@ static int __init luo_startup(void) } __luo_set_state(LIVEUPDATE_STATE_UPDATED); + luo_subsystems_startup(luo_fdt_in); return 0; } diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h index 3d10f3eb20a7..98bf799adb61 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -18,4 +18,11 @@ void luo_state_read_exit(void); const char *luo_current_state_str(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); + #endif /* _LINUX_LUO_INTERNAL_H */ diff --git a/kernel/liveupdate/luo_subsystems.c b/kernel/liveupdate/luo_subsystems.c new file mode 100644 index 000000000000..436929a17de0 --- /dev/null +++ b/kernel/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); -- 2.50.0.727.gbf7dc18ff4-goog