From nobody Wed Dec 17 15:53:10 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 6BB5F248886 for ; Tue, 9 Dec 2025 02:53:27 +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=1765248809; cv=none; b=jIggdpfxTPbg9lxErHouqwe/5xDTNe0CS1tia63Mnnv53ulYcxovIZC2XfcO1oQKW0V7P/ZkHb27xpRFePzScRBgpKm6/spJ3+DoBDxdGhted8LnXbPyUqwnUNvvQbz/4jzSkzRz6INRn+B9zR4YEKiwk++e07PhebDyY+7xGaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765248809; c=relaxed/simple; bh=OG0xacH2PVJh1zLtJQQNMpSxfUki1wfZSTbiD0b7Ml0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=k8MfPeYif6RVHFlUA59wriCB3YLsDw3WrzqY5RcLhhTBuZ9qyK5tdbwTG1rmwAo3LZEGIUK9/yga00wzB5YsAR4v4tKHzwnRvR2Dk8zMxWklcGbty/Y0sp2TVhb9s98pocvR5ATtGFTk+iGRhUGFv7tqr/u0VgxI4AaJ91xgHYQ= 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=M/7vaKWq; 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="M/7vaKWq" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b630753cc38so7449495a12.1 for ; Mon, 08 Dec 2025 18:53:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765248806; x=1765853606; 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=M/7vaKWqdZ+PWolXExRG1ieJEnREC9V2xCZYFLtaExD3GslmHSkw7gJ+q1EHkJu4Uz 6PruMz2hWwqLXi1FilazKhW0MwtMX2Wk9SexgMqgvOoow0QdYx4HMCutFxhxpSnUw3J9 qwpaHX3HujXAPOb/iLtisxwBbtJH/RUQZt0P67nPRc/nF+4nrzUF/blRebHfE65Cvzmm SSjZAtuNyk6mnSY6x3hLANivz3uIqPd2cegbtF8rT3Kpp3ql8Fvjx/pepEFF/YpUmpO2 n4beDLABVap9AoycXUjj299+o9FPUeaEPPlpGl/70If8jV+hLJ1O1yOtnyDPSBF85wTJ bJ0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765248806; x=1765853606; 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=iqNGkgDxbTWemt3Qfw+PG+K1T1MFu9PF1KpJ9zeESQA0j5VZzGjtcehvzg7XqBzotL Wj7AUpcGZAkwnKXmzJhwHwZ7/1bKQmDKaOHU5NErPSwSM/+kvAZIut/tGOWerYkB0BJc PytNBGhTGDWRFDJ1MkjdmaP3x1VeGFpbcuSVtjeQ4x3z0H7+UmufmLxKmKx+cU0WRKlN xHvKQ4vbx4db7Q0CfZoAPDC+cP7u5EtNVt62eObE0pfN8JjsznbcR/PHLvIXDiEb6ssZ LqMkCR5duvcJpORm9WIC2l/QmdS5/qLJ0GUVhn581rpdxAp6g4gkWVK6ACG6UWRu7wSH w9fw== X-Forwarded-Encrypted: i=1; AJvYcCU0u3dmotkFQtW2wCMvJWc2JH+TxesoidNZ2iMMttYIBIEXBwQb/gSXKaL+QG2RW5zFhAn+KNWR03ZrPFQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyysB3E5y77eI+N68j/oM6GOsGC5Umg6NcQxTxxmcK5z4NIq/R6 WGy/xMI3o7soMgW6BputojWzCsEXEL6wvaovJMWJqFrR3nYcAHK8WGu1cCJVuMbmWkblQjgJHR1 s5/uObWZnQ5iUIQ== X-Google-Smtp-Source: AGHT+IEE2+RzFDmhYi3sZJMC5POuF7uEYIA0RYOQQ5LbZQGlmWpKy+l52MCfZMJi+695a5er1FB0tS6NzuXitg== X-Received: from dychz10.prod.google.com ([2002:a05:7301:860a:b0:2a4:7a56:1730]) (user=jasonmiu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:6589:b0:2a4:3594:72d7 with SMTP id 5a478bee46e88-2abc710d8f1mr7325213eec.6.1765248806192; Mon, 08 Dec 2025 18:53:26 -0800 (PST) Date: Mon, 8 Dec 2025 18:53:14 -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-3-jasonmiu@google.com> Subject: [PATCH v3 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