From nobody Wed Dec 17 15:53:09 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 E80AB2EC569 for ; Tue, 9 Dec 2025 02:53:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765248812; cv=none; b=CpI1BxnbvZ85GDk0bDc1nhtIgFhGu86B83Ho5XWEHE2hDBTuh0XQLVDt67vu9H074/snKoHqU7dRvunIpjceIPRuDUmnVeIs/7R5s2iJtlun0G/RDC1TCvPKcbkbhVrxG+gg7qvwLhioXDvxvrjUFVUIYPYkBSOHj/u4BARznNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765248812; c=relaxed/simple; bh=uqIkBNQ+rPWDnKpw20LE20cM7Ix95qr6b1GQK0k7UOg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=uQz0WvlnQKZUia30Swl1VH5dJW41fUzvm/EVo/PnYGMhYu6e2A2zwqivLowCrCm9teuRrtGd5uFiZ0LqzlT8R+/pdi6ytRCgPsLWUffMRRl0Z7lZomiPdslYA3RSshksaqewkmtvASydzJv6VxX3YTjHPxCedTyMGFK3KSFjYjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jasonmiu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sQGliVZm; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jasonmiu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sQGliVZm" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b630b4d8d52so5343036a12.3 for ; Mon, 08 Dec 2025 18:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765248810; x=1765853610; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=KshiYXV7msSpU9cl75Ojt3IGhY+gwGaRSdjYRirqx3s=; b=sQGliVZmPVszReZfItRIj21dT5J9CKzUw9/v2eq3A00TY9hIrBqSqPTtnx6gyXpQl6 w7juhQt2WIUQP0i6FYvZ4kWjhHPoQl7sz1BJpl5QbFTuIjwX3oO0TtSV+52v/FxKHMeX AVKPeYtDBD84mqD3PYUaXhYDBRSGkuRIjBi7pkUl0owMatencrV42XsBJBOIdjMJRfr6 e3eusMuIbjOQgjWuw3xabSnTMbaQ4B5yeF4eBOaFi9Fkmauv87nU9SWKDK+lKGGVLihI n6N66TMkUnEDkTzDFuK7MWLU5fE21wnHc8TU/t9Q4TbgQnxC+Qd92ynT99gN/zqnqpa6 yDAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765248810; x=1765853610; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KshiYXV7msSpU9cl75Ojt3IGhY+gwGaRSdjYRirqx3s=; b=HT/Y8l/Y0SexeFnFj/iH6xSbW+Ce23EBMQ354EDOzw2/hUkETtByYsu4EQri8rCi2D yi3XkT+b9tgDIXvt93tkZS0ouuRdxEVBJsUe+YHyuvwVUSxrzhJRBba2t50BrN6Tcb3Q LO8c5v+/9MWsrGuZCn8M5QmDJX8pNDmRaN6neMAkNGQTCA3FFIc3uouzPkpw0WY7KM/T fV+hl/8kATshbBEj/uu/Kqe3G7o9V9iBut4vnKmOYUKStyGSIhJYbgFLa6OYnU31ZdIm 8tr0yEtGcmSxH7PWChSB4pXw5ig+dRQYtkx/zQolz85MBTrz0+5rsGVRIyoCe44wiI1/ zalw== X-Forwarded-Encrypted: i=1; AJvYcCXt5cYX/II1NXcsHF3Cly5n0XN8bJ1tIw+rP8gQEz8Q8+HBfeF1WeIHIBj3FUMy/tXt+sDmR2MWvjyOtF4=@vger.kernel.org X-Gm-Message-State: AOJu0YzGT6aPeNpeUCPMhQdLQjkdgQ1hnAcd4rqO5URDg+1GTr3Y0bVc H39SYKm5OgLyuloVeeGFapxXpqnTIFavRyl3RYicUMin9Ne98xCbxIZjUhSR4fYDN2bqTaFkA4D HPkiL2zErfDkrGA== X-Google-Smtp-Source: AGHT+IFClP5phTsaQmpFtJ4A14CfMylc4B7SYp/2612GMMu8hUh6AsMjFy4WJ9S94iPvuBTuGOQmw234CmrEmA== X-Received: from dybno7.prod.google.com ([2002:a05:7300:e607:b0:2a4:7587:4d39]) (user=jasonmiu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:4312:b0:2a4:3593:ddd9 with SMTP id 5a478bee46e88-2abc70f79c7mr7581649eec.6.1765248810012; Mon, 08 Dec 2025 18:53:30 -0800 (PST) Date: Mon, 8 Dec 2025 18:53:16 -0800 In-Reply-To: <20251209025317.3846938-1-jasonmiu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251209025317.3846938-1-jasonmiu@google.com> X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251209025317.3846938-5-jasonmiu@google.com> Subject: [PATCH v3 4/4] kho: Remove finalize state and clients From: Jason Miu To: Alexander Graf , Andrew Morton , Baoquan He , Changyuan Lyu , David Matlack , David Rientjes , Jason Gunthorpe , Jason Miu , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Eliminate the `kho_finalize()` function and its associated state from the KHO subsystem. The transition to a radix tree for memory tracking makes the explicit "finalize" state and its serialization step obsolete. Remove the `kho_finalize()` and `kho_finalized()` APIs and their stub implementations. Update KHO client code and the debugfs interface to no longer call or depend on the `kho_finalize()` mechanism. Complete the move towards a stateless KHO, simplifying the overall design by removing unnecessary state management. Signed-off-by: Jason Miu --- Documentation/admin-guide/mm/kho.rst | 46 ++++----------------- Documentation/core-api/kho/concepts.rst | 13 +----- kernel/liveupdate/kexec_handover.c | 10 ----- kernel/liveupdate/kexec_handover_debugfs.c | 20 --------- kernel/liveupdate/kexec_handover_internal.h | 3 -- kernel/liveupdate/luo_core.c | 12 +----- kernel/liveupdate/luo_flb.c | 2 +- tools/testing/selftests/kho/init.c | 20 --------- 8 files changed, 10 insertions(+), 116 deletions(-) diff --git a/Documentation/admin-guide/mm/kho.rst b/Documentation/admin-gui= de/mm/kho.rst index 6dc18ed4b886..13910bc68efe 100644 --- a/Documentation/admin-guide/mm/kho.rst +++ b/Documentation/admin-guide/mm/kho.rst @@ -28,17 +28,7 @@ per NUMA node scratch regions on boot. Perform a KHO kexec =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -First, before you perform a KHO kexec, you need to move the system into -the :ref:`KHO finalization phase ` :: - - $ echo 1 > /sys/kernel/debug/kho/out/finalize - -After this command, the KHO FDT is available in -``/sys/kernel/debug/kho/out/fdt``. Other subsystems may also register -their own preserved sub FDTs under -``/sys/kernel/debug/kho/out/sub_fdts/``. - -Next, load the target payload and kexec into it. It is important that you +To perform a KHO kexec, load the target payload and kexec into it. It is i= mportant that you use the ``-s`` parameter to use the in-kernel kexec file loader, as user space kexec tooling currently has no support for KHO with the user space based file loader :: @@ -52,40 +42,19 @@ For example, if you used ``reserve_mem`` command line p= arameter to create an early memory reservation, the new kernel will have that memory at the same physical address as the old kernel. =20 -Abort a KHO exec -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -You can move the system out of KHO finalization phase again by calling :: - - $ echo 0 > /sys/kernel/debug/kho/out/active - -After this command, the KHO FDT is no longer available in -``/sys/kernel/debug/kho/out/fdt``. - debugfs Interfaces =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 +These debugfs interfaces are available when the kernel is compiled with +``CONFIG_KEXEC_HANDOVER_DEBUGFS`` set to y. + Currently KHO creates the following debugfs interfaces. Notice that these interfaces may change in the future. They will be moved to sysfs once KHO = is stabilized. =20 -``/sys/kernel/debug/kho/out/finalize`` - Kexec HandOver (KHO) allows Linux to transition the state of - compatible drivers into the next kexec'ed kernel. To do so, - device drivers will instruct KHO to preserve memory regions, - which could contain serialized kernel state. - While the state is serialized, they are unable to perform - any modifications to state that was serialized, such as - handed over memory allocations. - - When this file contains "1", the system is in the transition - state. When contains "0", it is not. To switch between the - two states, echo the respective number into this file. - ``/sys/kernel/debug/kho/out/fdt`` - When KHO state tree is finalized, the kernel exposes the - flattened device tree blob that carries its current KHO - state in this file. Kexec user space tooling can use this + The kernel exposes the flattened device tree blob that carries its + current KHO state in this file. Kexec user space tooling can use this as input file for the KHO payload image. =20 ``/sys/kernel/debug/kho/out/scratch_len`` @@ -100,8 +69,7 @@ stabilized. it should place its payload images. =20 ``/sys/kernel/debug/kho/out/sub_fdts/`` - In the KHO finalization phase, KHO producers register their own - FDT blob under this directory. + KHO producers can register their own FDT blob under this directory. =20 ``/sys/kernel/debug/kho/in/fdt`` When the kernel was booted with Kexec HandOver (KHO), diff --git a/Documentation/core-api/kho/concepts.rst b/Documentation/core-a= pi/kho/concepts.rst index d38bcaa951e4..0ac01760db18 100644 --- a/Documentation/core-api/kho/concepts.rst +++ b/Documentation/core-api/kho/concepts.rst @@ -6,7 +6,7 @@ Kexec Handover Concepts =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Kexec HandOver (KHO) is a mechanism that allows Linux to preserve memory -regions, which could contain serialized system states, across kexec. +regions, containing kernel data structures in their live, in-memory format= , across kexec. =20 It introduces multiple concepts: =20 @@ -56,17 +56,6 @@ for boot memory allocations and as target memory for kex= ec blobs, some parts of that memory region may be reserved. These reservations are irrelevant f= or the next KHO, because kexec can overwrite even the original kernel. =20 -.. _kho-finalization-phase: - -KHO finalization phase -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -To enable user space based kexec file loader, the kernel needs to be able = to -provide the FDT that describes the current kernel's state before -performing the actual kexec. The process of generating that FDT is -called serialization. When the FDT is generated, some properties -of the system may become immutable because they are already written down -in the FDT. That state is called the KHO finalization phase. =20 Public API =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 81bac82c8672..92b052450ce4 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1212,16 +1212,6 @@ void kho_restore_free(void *mem) } EXPORT_SYMBOL_GPL(kho_restore_free); =20 -int kho_finalize(void) -{ - return 0; -} - -bool kho_finalized(void) -{ - return false; -} - struct kho_in { phys_addr_t fdt_phys; phys_addr_t scratch_phys; diff --git a/kernel/liveupdate/kexec_handover_debugfs.c b/kernel/liveupdate= /kexec_handover_debugfs.c index 2abbf62ba942..2f70d9c41831 100644 --- a/kernel/liveupdate/kexec_handover_debugfs.c +++ b/kernel/liveupdate/kexec_handover_debugfs.c @@ -75,24 +75,6 @@ void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, voi= d *fdt) } } =20 -static int kho_out_finalize_get(void *data, u64 *val) -{ - *val =3D kho_finalized(); - - return 0; -} - -static int kho_out_finalize_set(void *data, u64 val) -{ - if (val) - return kho_finalize(); - else - return -EINVAL; -} - -DEFINE_DEBUGFS_ATTRIBUTE(kho_out_finalize_fops, 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++) @@ -198,8 +180,6 @@ __init int kho_out_debugfs_init(struct kho_debugfs *dbg) if (IS_ERR(f)) goto err_rmdir; =20 - f =3D debugfs_create_file("finalize", 0600, dir, NULL, - &kho_out_finalize_fops); if (IS_ERR(f)) goto err_rmdir; =20 diff --git a/kernel/liveupdate/kexec_handover_internal.h b/kernel/liveupdat= e/kexec_handover_internal.h index 0202c85ad14f..9a832a35254c 100644 --- a/kernel/liveupdate/kexec_handover_internal.h +++ b/kernel/liveupdate/kexec_handover_internal.h @@ -22,9 +22,6 @@ struct kho_debugfs {}; extern struct kho_scratch *kho_scratch; extern unsigned int kho_scratch_cnt; =20 -bool kho_finalized(void); -int kho_finalize(void); - #ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS int kho_debugfs_init(void); void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt); diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index 69298d82f404..e4db15d81f89 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -231,17 +231,7 @@ int liveupdate_reboot(void) =20 luo_flb_serialize(); =20 - err =3D kho_finalize(); - if (err) { - pr_err("kho_finalize failed %d\n", err); - /* - * kho_finalize() may return libfdt errors, to aboid passing to - * userspace unknown errors, change this to EAGAIN. - */ - err =3D -EAGAIN; - } - - return err; + return 0; } =20 /** diff --git a/kernel/liveupdate/luo_flb.c b/kernel/liveupdate/luo_flb.c index e80ac5b575ec..92d35eb5e6ee 100644 --- a/kernel/liveupdate/luo_flb.c +++ b/kernel/liveupdate/luo_flb.c @@ -632,7 +632,7 @@ int __init luo_flb_setup_incoming(void *fdt_in) * data handle, and the final reference count. This allows the new kernel = to * find the appropriate handler and reconstruct the FLB's state. * - * Context: Called from liveupdate_reboot() just before kho_finalize(). + * Context: Called from liveupdate_reboot() just before return. */ void luo_flb_serialize(void) { diff --git a/tools/testing/selftests/kho/init.c b/tools/testing/selftests/k= ho/init.c index 6d9e91d55d68..88a41b6eba95 100644 --- a/tools/testing/selftests/kho/init.c +++ b/tools/testing/selftests/kho/init.c @@ -11,7 +11,6 @@ /* from arch/x86/include/asm/setup.h */ #define COMMAND_LINE_SIZE 2048 =20 -#define KHO_FINALIZE "/debugfs/kho/out/finalize" #define KERNEL_IMAGE "/kernel" =20 static int mount_filesystems(void) @@ -22,22 +21,6 @@ static int mount_filesystems(void) return mount("proc", "/proc", "proc", 0, NULL); } =20 -static int kho_enable(void) -{ - const char enable[] =3D "1"; - int fd; - - fd =3D open(KHO_FINALIZE, O_RDWR); - if (fd < 0) - return -1; - - if (write(fd, enable, sizeof(enable)) !=3D sizeof(enable)) - return 1; - - close(fd); - return 0; -} - static long kexec_file_load(int kernel_fd, int initrd_fd, unsigned long cmdline_len, const char *cmdline, unsigned long flags) @@ -78,9 +61,6 @@ int main(int argc, char *argv[]) if (mount_filesystems()) goto err_reboot; =20 - if (kho_enable()) - goto err_reboot; - if (kexec_load()) goto err_reboot; =20 --=20 2.52.0.223.gf5cc29aaa4-goog