From nobody Fri Dec 19 13:31:36 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 D5594326938 for ; Mon, 8 Dec 2025 06:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765175728; cv=none; b=m2aTmUPoauGErlvu6Mi7a8LBKZ43GZ1QQmMxM0Kdmd8jq9Zruiw+56RsXU0do4OTBVXVYk2i8Iy9qisIs71q/CyspB9OMntkpPUc4TMeeN4jFCXq9eNqV3xx28rZt7zNDD/ANjvHzEq73KVuRhRo8ZcznNS4SGY41EEEJAS7X7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765175728; c=relaxed/simple; bh=OG0xacH2PVJh1zLtJQQNMpSxfUki1wfZSTbiD0b7Ml0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ezXISwqi7kx+nj2Rqk+kFJB4uE13LhsT3ptOOUyvTftQ4k2ddXep84dUxcmxuB0MlA2Hz5g9s/xT1oPrGCFTxx87ZYeDlMvb9QE/9bp1X4rj+jrEqKEYpH0SbGFuGC1A2S6k80wCKIGIsOdxwl2DIO4jO3AGzFPTTM1/eP5dEpI= 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=PI2ucp9V; arc=none smtp.client-ip=209.85.215.202 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="PI2ucp9V" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-bf06c3426b7so7392809a12.3 for ; Sun, 07 Dec 2025 22:35:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765175726; x=1765780526; 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=7YniVUU6/+lQD/EVhfTXqpFE+9KZzpnPEHhqtMsCQi8=; b=PI2ucp9VzvexeqJP5XBosG0BIOXlViCkD1Xr6TuHhRGonOn+JCB4xStlU+F1/zB1SI 8rtH4dX9pN+MXslQcq9raYcH7W9ir3Txqppe9SnS0taymE+22IOCupbtyaRN8ADsOgHg B0Icxz08jgFAE7/pfAWdMBjjNlCKU4eg+o49UBSMHIYzNdYFr2pKdKvIUG4YqObMoFWL ERsQGK4JPi79g+z6J5qmQOXi2dqzVa7JwhkUHdLUllCa4DD6qwnmOTxzStc2Iq0wrqd8 5xN4lJQD5JC5zEP74KUJ6qLg1v6SfH5J8cEo4Z8nrZmJXISP9GeWpRWR5pFvicAItfDb 94rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765175726; x=1765780526; 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=7YniVUU6/+lQD/EVhfTXqpFE+9KZzpnPEHhqtMsCQi8=; b=vdBv8aq03QLEE6cZk2SxXBSOYnZyQ24XE/S4DuavrvrpTtwULLjiRxVbMIJd5zSUiN WUK1bIGgTOapmweM6GqxjUAU7ENM4kacto2DzLvBdgqXHYgxTybUPkVQfRwzUeJkiJ3X XI4h/cFYrMKjyDaRPyLRVIXrnZ94B6xH0FWzEJZCdUKPb9c97tvEPXMaZsyycd9eWh7i ifwrGLaXR1TcbkwoaU+zErYKtaphLuIy2FmRc3zByDqwBxAjDvYXHRNqXl5974k0okzp An4s75WR9hKS4ciR0xlSb14gta3XzyNaUMa8QE6+3iqwSbsJvDyZ/auknEbDLkX+9lwt jJpg== X-Forwarded-Encrypted: i=1; AJvYcCWS1DjFVvu8Kr7pT4Lh22cayswQRUJ5kw5nVgJKDIHXFDgClkckEWdAxp5rfdm35rhFJ6oDbZpxfq3MIu0=@vger.kernel.org X-Gm-Message-State: AOJu0YzlB+hIHcBNFa/XJaTTXzx9tnFttjxWyW4hl+8aWDWZ00W934uX w1MRis6H3frEbqODVW+/+Lbk9JGpQF2OqxtY712vmVdyhHe5HOiRO4maNPzPEOtyqijImVcoDRi OjioOgyoHCOeEVg== X-Google-Smtp-Source: AGHT+IHU6+/mDElXpIos6i8CNSp+95UxIucCYl80yGbmgb7FYlxpfDXUEFziZxt82S/j1o9ILLaNDoE1BFGUog== X-Received: from dybhw4.prod.google.com ([2002:a05:7301:2b84:b0:2a4:559f:7c4e]) (user=jasonmiu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:fae:b0:2a4:3593:9698 with SMTP id 5a478bee46e88-2abc71f7ec6mr4262433eec.21.1765175726144; Sun, 07 Dec 2025 22:35:26 -0800 (PST) Date: Sun, 7 Dec 2025 22:35:11 -0800 In-Reply-To: <20251208063513.3633942-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: <20251208063513.3633942-1-jasonmiu@google.com> X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251208063513.3633942-3-jasonmiu@google.com> Subject: [PATCH 2/4] kho: Relocate vmalloc preservation structure to KHO ABI header 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" The `struct kho_vmalloc` defines the in-memory layout for preserving vmalloc regions across kexec. This layout is a contract between kernels and part of the KHO ABI. To reflect this relationship, the related structs and helper macros are relocated to the ABI header, `include/linux/kho/abi/kexec_handover.h`. This move places the structure's definition under the protection of the KHO_FDT_COMPATIBLE version string. The structure and its components are now also documented within the ABI header to describe the contract and prevent ABI breaks. Signed-off-by: Jason Miu --- Documentation/core-api/kho/fdt.rst | 6 ++ include/linux/kexec_handover.h | 27 +-------- include/linux/kho/abi/kexec_handover.h | 78 ++++++++++++++++++++++++++ include/linux/kho/abi/memfd.h | 2 +- kernel/liveupdate/kexec_handover.c | 15 ----- lib/test_kho.c | 1 + 6 files changed, 88 insertions(+), 41 deletions(-) diff --git a/Documentation/core-api/kho/fdt.rst b/Documentation/core-api/kh= o/fdt.rst index 4e080ccc420e..4202b67fcdf9 100644 --- a/Documentation/core-api/kho/fdt.rst +++ b/Documentation/core-api/kho/fdt.rst @@ -14,6 +14,12 @@ directly in the ABI header file. .. kernel-doc:: include/linux/kho/abi/kexec_handover.h :doc: Kexec Handover ABI =20 +Kexec Handover ABI for vmalloc Preservation +=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=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. kernel-doc:: include/linux/kho/abi/kexec_handover.h + :doc: Kexec Handover ABI for vmalloc Preservation + See Also =3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 5f7b9de97e8d..a56ff3ffaf17 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -11,34 +11,11 @@ struct kho_scratch { phys_addr_t size; }; =20 +struct kho_vmalloc; + struct folio; struct page; =20 -#define DECLARE_KHOSER_PTR(name, type) \ - union { \ - phys_addr_t phys; \ - type ptr; \ - } name -#define KHOSER_STORE_PTR(dest, val) \ - ({ \ - typeof(val) v =3D val; \ - typecheck(typeof((dest).ptr), v); \ - (dest).phys =3D virt_to_phys(v); \ - }) -#define KHOSER_LOAD_PTR(src) = \ - ({ \ - typeof(src) s =3D src; \ - (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \ - }) - -struct kho_vmalloc_chunk; -struct kho_vmalloc { - DECLARE_KHOSER_PTR(first, struct kho_vmalloc_chunk *); - unsigned int total_pages; - unsigned short flags; - unsigned short order; -}; - #ifdef CONFIG_KEXEC_HANDOVER bool kho_is_enabled(void); bool is_kho_boot(void); diff --git a/include/linux/kho/abi/kexec_handover.h b/include/linux/kho/abi= /kexec_handover.h index d78df2d44cb6..74f4fa67e458 100644 --- a/include/linux/kho/abi/kexec_handover.h +++ b/include/linux/kho/abi/kexec_handover.h @@ -10,6 +10,8 @@ #ifndef _LINUX_KHO_ABI_KEXEC_HANDOVER_H #define _LINUX_KHO_ABI_KEXEC_HANDOVER_H =20 +#include + /** * DOC: Kexec Handover ABI * @@ -81,4 +83,80 @@ /* The FDT property for sub-FDTs. */ #define KHO_FDT_SUB_TREE_PROP_NAME "fdt" =20 +/** + * DOC: Kexec Handover ABI for vmalloc Preservation + * + * The Kexec Handover ABI for preserving vmalloc'ed memory is defined by + * a set of structures and helper macros. The layout of these structures i= s a + * stable contract between kernels and is versioned by the KHO_FDT_COMPATI= BLE + * string. + * + * The preservation is managed through a main descriptor struct (`kho_vmal= loc`), + * which points to a linked list of `kho_vmalloc_chunk` structures. These + * chunks contain the physical addresses of the preserved pages, allowing = the + * next kernel to reconstruct the vmalloc area with the same content and l= ayout. + * Helper macros are also defined for storing and loading pointers within + * these structures. + */ + +/* Helper macro to define a union for a serializable pointer. */ +#define DECLARE_KHOSER_PTR(name, type) \ + union { \ + u64 phys; \ + type ptr; \ + } name + +/* Stores the physical address of a serializable pointer. */ +#define KHOSER_STORE_PTR(dest, val) \ + ({ \ + typeof(val) v =3D val; \ + typecheck(typeof((dest).ptr), v); \ + (dest).phys =3D virt_to_phys(v); \ + }) + +/* Loads the stored physical address back to a pointer. */ +#define KHOSER_LOAD_PTR(src) \ + ({ \ + typeof(src) s =3D src; \ + (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \ + }) + +/* + * This header is embedded at the beginning of each `kho_vmalloc_chunk` + * and contains a pointer to the next chunk in the linked list, + * stored as a physical address for handover. + */ +struct kho_vmalloc_hdr { + DECLARE_KHOSER_PTR(next, struct kho_vmalloc_chunk *); +}; + +#define KHO_VMALLOC_SIZE \ + ((PAGE_SIZE - sizeof(struct kho_vmalloc_hdr)) / \ + sizeof(u64)) + +/* + * Each chunk is a single page and is part of a linked list that describes + * a preserved vmalloc area. It contains the header with the link to the n= ext + * chunk and an array of physical addresses of the pages that make up the + * preserved vmalloc area. + */ +struct kho_vmalloc_chunk { + struct kho_vmalloc_hdr hdr; + u64 phys[KHO_VMALLOC_SIZE]; +}; + +static_assert(sizeof(struct kho_vmalloc_chunk) =3D=3D PAGE_SIZE); + +/* + * Describes a preserved vmalloc memory area, including the + * total number of pages, allocation flags, page order, and a pointer to t= he + * first chunk of physical page addresses. + */ +struct kho_vmalloc { + DECLARE_KHOSER_PTR(first, struct kho_vmalloc_chunk *); + unsigned int total_pages; + unsigned short flags; + unsigned short order; +}; + #endif /* _LINUX_KHO_ABI_KEXEC_HANDOVER_H */ diff --git a/include/linux/kho/abi/memfd.h b/include/linux/kho/abi/memfd.h index da7d063474a1..1af4c9dc5a06 100644 --- a/include/linux/kho/abi/memfd.h +++ b/include/linux/kho/abi/memfd.h @@ -12,7 +12,7 @@ #define _LINUX_KHO_ABI_MEMFD_H =20 #include -#include +#include =20 /** * DOC: memfd Live Update ABI diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index d3d02a9ea391..a180b3367e8f 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -882,21 +882,6 @@ void kho_unpreserve_pages(struct page *page, unsigned = int nr_pages) } EXPORT_SYMBOL_GPL(kho_unpreserve_pages); =20 -struct kho_vmalloc_hdr { - DECLARE_KHOSER_PTR(next, struct kho_vmalloc_chunk *); -}; - -#define KHO_VMALLOC_SIZE \ - ((PAGE_SIZE - sizeof(struct kho_vmalloc_hdr)) / \ - sizeof(phys_addr_t)) - -struct kho_vmalloc_chunk { - struct kho_vmalloc_hdr hdr; - phys_addr_t phys[KHO_VMALLOC_SIZE]; -}; - -static_assert(sizeof(struct kho_vmalloc_chunk) =3D=3D PAGE_SIZE); - /* vmalloc flags KHO supports */ #define KHO_VMALLOC_SUPPORTED_FLAGS (VM_ALLOC | VM_ALLOW_HUGE_VMAP) =20 diff --git a/lib/test_kho.c b/lib/test_kho.c index 47de56280795..3431daca6968 100644 --- a/lib/test_kho.c +++ b/lib/test_kho.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include =20 --=20 2.52.0.223.gf5cc29aaa4-goog