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 D2142C3ABDD for ; Thu, 15 May 2025 18:24:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24D376B00A3; Thu, 15 May 2025 14:23:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18AAF6B000A; Thu, 15 May 2025 14:23:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBA288D0008; Thu, 15 May 2025 14:23:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B16458D0001 for ; Thu, 15 May 2025 14:23:44 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A711E59188 for ; Thu, 15 May 2025 18:23:45 +0000 (UTC) X-FDA: 83445965610.26.7C1D6C2 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf12.hostedemail.com (Postfix) with ESMTP id CA1CC4000E for ; Thu, 15 May 2025 18:23:43 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=R7YcZmTG; spf=pass (imf12.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.179 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=1747333423; 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=ltL7NUHX20pXkC0VOJlR8mGY0Kaj9UtnVW/UYNskncc=; b=HmL/ea61SMR1neVE1LtAM/hEKkKhCh7thtJWoIgiT4V4UT+Fuz3iqcTVtE/gyF0WYhghVT EGTBy6BgkJcpZO8fSuDpWYSIyACOEECUZ4GdzJ3i3WH/lo+vp1m+muQ3eSHvkAaHj+9fxp hJo3oLXjoMxhh+mt7U2Dyim2PTpLhzE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747333423; a=rsa-sha256; cv=none; b=ToH29fEHl3B8Ofhps9WVskFGGkIonTFWLxB/Q90ATjuevNGGNIiKQo58wtKD35ccz1lb06 7TCXS/RCuR3b36tl1PhPpgTuFbGc63xjTBZl4fFfw59n8NubR34IlZ62ex+g9drm7/XLBX MVU7BHy+a0YNxArDXK7ifcSEX/Ds2UI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=R7YcZmTG; spf=pass (imf12.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.179 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7c922734cc2so153139685a.1 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=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=ltL7NUHX20pXkC0VOJlR8mGY0Kaj9UtnVW/UYNskncc=; b=R7YcZmTGPlz49L2opCRc8qpbP2j1F1hWYd1gIeEZOd4BAu9VZmIvURBiePHRUWs4jf O7uPpDS4KXymSpyK7WAjNKPywkI1Kjf66GRYQ4dOzHqsJ8je585EDKbyMrH9biGO7HKI RehcJMrKnGLu56NYup93DDeRCCsyT+eXkq0IFH+jwTLm0tV3AMwnM5uGFRiv1YXdgFZr 4PPjoidV1wVnh6Yegjyzuqf6T3JP4fI3zg26KH4y1y/eY9I7I4H+3ODNwwUDzW5M5K8v /lXIaO5nMG2GpaOZEqbVDb6SGZ5Y5ATSkp0YGY+bosLS+NwYuBmDBNzzMnvIGFqUqg1S iFXA== 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=Ow2csZodOAlQCM5p6HyOGSPaGpNofoF5pLsZtqHhS0ExZKY41Xkfd0IBXDejFMPc5r wEEHffKrikb40hHEhkkGbsnI7ZWhBoOG7WBnfRn1Tl67sEaz7VmDkPt3FOO2v6Eh8l4g iGpmTA1MnU+oKUtcopIHqAbqxgsZQoE5oPCLZ0/+2/PCnTnwo0jNBJgSWGsprWF4tioA gaiEtGBmwCHd8UyintZ6XWtXzd8gt/Ebhhh5HPjCI9/1VDMuln1YvpPiGMNzNHxEDbXb eKUTj16Avw0xiv8HPJFb+QH88KbV9cSgOs+PRZgze7WqLXL/tKSOl6YfH0Rxa94Q5MAV g+vQ== X-Forwarded-Encrypted: i=1; AJvYcCV5Az/K2iW9bnRWpFalVZm3T7MXv2bhNmTv6QmF4hjyEGFKacxJUrPMblbO1WP9nku5jOKUH/4vWw==@kvack.org X-Gm-Message-State: AOJu0Yz812eWiSfD2lDalif4v4kRb+qEGAWryEHlsJwip7po3TOVa/uQ As7tQuhIuqlCEsDlqhMPfZwVN2Oo9zlthZyLorrk1mQiWaTTSXu89dm3lweYHP0fgVY= X-Gm-Gg: ASbGncsCYE/QZWSvYE0XleRTIpmtop68DATg8fBKO/Cm++5cihLHFR5bd2UfpHtBIF1 PfRVLFVtsMc15GmSnD9mP71qkUR8Y306Doic6x51jaj5P2IcSj0FeZTbG9InjckvlzVPP4EUy0z l3sxxNDA3lj+FTCocebU22zIlscO/SjG8EWgp52OgEFyMabjo7jKMtMx3oiGaZOZTgcHD3koxMp wTSid/FCb7Ihe7eHeT1alCOLlUuGptvWEglNgVLdoM6/w0+Cr5tldA7y6Hw0aXs47h5wEPoABJg 60TywXudkITQeA4RO5hfh/Kk7W55zhg90hCr8WoY7euSQ3NDOoId9c7Erlf4oJwwfyNZ0oMMAmN AmSxlsz4MUtyibI40D0KYF2VDHREfT8CIMyCNfgL+03GW 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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CA1CC4000E X-Stat-Signature: 44p11s9kguefpgrt1yj1ogs94scy6qej X-Rspam-User: X-HE-Tag: 1747333423-834735 X-HE-Meta: U2FsdGVkX18f0nBPrE++a6AdyMmHPf4KVnSxZZDngmiWkRUOLOWq9gipk0i+MhJIGNd/QGNlJw0T1GqEN2jTO0gLsFdyhs6v0ivuqufZ8PUdn9wk2hOsS404XB/cyDk1EHTU6k2M/gSV3VPOcrWXU3gIB+XaEi48MwMAeYMhNQIfEhV7w7s7gD9la9rpuNIuDBBtgcoB9pTNZym01tLdYJu1WxCfaIaK0yDfGqT929dYX/UiaKKzzS9Uo3BCs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oQ21Cym7i6twObrrb6vLHEupeSiYJR8XGtNTwbxh8PEdr4yTfKQz4LN7tKy5gur2Cero0/CG3pBqmKxQKORIZ7wCZa1yreW3vNAk4TzFMz36hC05FXNFzvxlmw8I1ayfC0cyVYbCPlov8d6ZU8bDbxbY+K/NRNHCyNCejR4B1gc 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 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/Documentation/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/Kconfig index a7424ceeba0b..09940f9a724a 100644 --- a/drivers/misc/liveupdate/Kconfig +++ b/drivers/misc/liveupdate/Kconfig @@ -25,3 +25,21 @@ config LIVEUPDATE running virtual machines. 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/Makefile index 7a0cd08919c9..190323c10220 100644 --- a/drivers/misc/liveupdate/Makefile +++ b/drivers/misc/liveupdate/Makefile @@ -3,3 +3,4 @@ obj-y += luo_ioctl.o obj-y += luo_core.o obj-y += luo_files.o obj-y += luo_subsystems.o +obj-$(CONFIG_LIVEUPDATE_SYSFS_API) += luo_sysfs.o diff --git a/drivers/misc/liveupdate/luo_core.c b/drivers/misc/liveupdate/luo_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_state expected_state) static void __luo_set_state(enum liveupdate_state state) { WRITE_ONCE(luo_state, state); + luo_sysfs_notify(); } static inline void luo_set_state(enum liveupdate_state state) diff --git a/drivers/misc/liveupdate/luo_internal.h b/drivers/misc/liveupdate/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); +#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[]; /* 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 monitoring LUO + * state. Live update allows rebooting the kernel (via kexec) while preserving + * 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'). Corresponds 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 *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", LUO_STATE_STR); +} + +static struct kobj_attribute state_attribute = __ATTR_RO(state); + +static struct attribute *luo_attrs[] = { + &state_attribute.attr, + NULL +}; + +static struct attribute_group luo_attr_group = { + .attrs = luo_attrs, + .name = LUO_DIR_NAME, +}; + +static int __init luo_init(void) +{ + int ret; + + ret = sysfs_create_group(kernel_kobj, &luo_attr_group); + if (ret) { + pr_err("Failed to create group\n"); + return ret; + } + + luo_sysfs_initialized = true; + pr_info("Initialized\n"); + + return 0; +} +subsys_initcall(luo_init); -- 2.49.0.1101.gccaa498523-goog