Skip to contentSkip to conversation

kho: ABI headers and Documentation updates

PATCH In review Mike Rapoport 3 participants 25 messages Jan 5 – Jan 22

Subsystems (7)
lore
Share & tools
lore

Mike Rapoport

author maintainer
#0 lore raw

cover kho: ABI headers and Documentation updates

From: "Mike Rapoport (Microsoft)" <[email protected]>

Hi,

LUO started adding KHO ABI headers to include/linux/kho/abi, but the core parts of KHO and memblock are still using the old way for descriptions on their ABIs.

Let's consolidate all things KHO in include/linux/kho/abi.

And while on that, make some documentation updates to have more coherent KHO docs.

Jason Miu (2):
kho: Introduce KHO FDT ABI header
kho: Relocate vmalloc preservation structure to KHO ABI header

Mike Rapoport (Microsoft) (4):
kho/abi: luo: make generated documentation more coherent kho/abi: memfd: make generated documentation more coherent
kho: docs: combine concepts and FDT documentation kho/abi: add memblock ABI header

 Documentation/core-api/kho/abi.rst            |  28 +++
 Documentation/core-api/kho/bindings/kho.yaml  |  43 -----
 .../kho/bindings/memblock/memblock.yaml       |  39 -----
 .../kho/bindings/memblock/reserve-mem.yaml    |  40 -----
 .../core-api/kho/bindings/sub-fdt.yaml        |  27 ---
 Documentation/core-api/kho/concepts.rst       |  74 --------
 Documentation/core-api/kho/fdt.rst            |  80 ---------
 Documentation/core-api/kho/index.rst          |  78 ++++++++-
 Documentation/core-api/liveupdate.rst         |   2 +-
 Documentation/mm/memfd_preservation.rst       |   2 +-
 MAINTAINERS                                   |   1 +
 include/linux/kexec_handover.h                |  27 +--
 include/linux/kho/abi/kexec_handover.h        | 163 ++++++++++++++++++
 include/linux/kho/abi/luo.h                   |   8 +-
 include/linux/kho/abi/memblock.h              |  72 ++++++++
 include/linux/kho/abi/memfd.h                 |   6 +-
 kernel/liveupdate/kexec_handover.c            |  34 +---
 lib/test_kho.c                                |   1 +
 mm/memblock.c                                 |   4 +-
 19 files changed, 361 insertions(+), 368 deletions(-)
 create mode 100644 Documentation/core-api/kho/abi.rst
 delete mode 100644 Documentation/core-api/kho/bindings/kho.yaml
 delete mode 100644 Documentation/core-api/kho/bindings/memblock/memblock.yaml
 delete mode 100644 Documentation/core-api/kho/bindings/memblock/reserve-mem.yaml
 delete mode 100644 Documentation/core-api/kho/bindings/sub-fdt.yaml
 delete mode 100644 Documentation/core-api/kho/concepts.rst
 delete mode 100644 Documentation/core-api/kho/fdt.rst
 create mode 100644 include/linux/kho/abi/kexec_handover.h
 create mode 100644 include/linux/kho/abi/memblock.h

base-commit: f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da

Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH 1/6 kho/abi: luo: make generated documentation more coherent

From: "Mike Rapoport (Microsoft)" <[email protected]>

LUO ABI description starts with "This header defines" which is fine in the header but reads weird in the generated html documentation.

Update it to make the generated documentation coherent.

---
 include/linux/kho/abi/luo.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/kho/abi/luo.h +4 -4
index bb099c92e469..beb86847b544 100644
@@ -8,10 +8,10 @@
 /**
  * DOC: Live Update Orchestrator ABI
  *
- * This header defines the stable Application Binary Interface used by the
- * Live Update Orchestrator to pass state from a pre-update kernel to a
- * post-update kernel. The ABI is built upon the Kexec HandOver framework
- * and uses a Flattened Device Tree to describe the preserved data.
+ * Live Update Orchestrator uses the stable Application Binary Interface
+ * defined below to pass state from a pre-update kernel to a post-update
+ * kernel. The ABI is built upon the Kexec HandOver framework and uses a
+ * Flattened Device Tree to describe the preserved data.
  *
  * This interface is a contract. Any modification to the FDT structure, node
  * properties, compatible strings, or the layout of the `__packed` serialization
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] kho/abi: luo: make generated documentation more coherent

Quoted 8 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

LUO ABI description starts with "This header defines" which is fine in the header but reads weird in the generated html documentation.

Update it to make the generated documentation coherent.

[...]

Signature · 2 lines
Regards,
Pratyush Yadav
maintainer Reviewed-by on v1 1/6
#3 lore raw

Re: [PATCH 1/6] kho/abi: luo: make generated documentation more coherent

In reply to Mike Rapoport
Quoted 33 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

LUO ABI description starts with "This header defines" which is fine in the header but reads weird in the generated html documentation.

Update it to make the generated documentation coherent.

---
 include/linux/kho/abi/luo.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/kho/abi/luo.h +4 -5
index bb099c92e469..beb86847b544 100644
@@ -8,10 +8,10 @@
 /**
  * DOC: Live Update Orchestrator ABI
  *
- * This header defines the stable Application Binary Interface used by the
- * Live Update Orchestrator to pass state from a pre-update kernel to a
- * post-update kernel. The ABI is built upon the Kexec HandOver framework
- * and uses a Flattened Device Tree to describe the preserved data.
+ * Live Update Orchestrator uses the stable Application Binary Interface
+ * defined below to pass state from a pre-update kernel to a post-update
+ * kernel. The ABI is built upon the Kexec HandOver framework and uses a
+ * Flattened Device Tree to describe the preserved data.
  *
  * This interface is a contract. Any modification to the FDT structure, node
  * properties, compatible strings, or the layout of the `__packed` serialization
--
Quoted 2 lines

2.51.0

author maintainer
#4 lore raw

PATCH 2/6 kho/abi: memfd: make generated documentation more coherent

In reply to Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

memfd preservation ABI description starts with "This header defines" which is fine in the header but reads weird in the generated html documentation.

Update it to make the generated documentation coherent.

---
 include/linux/kho/abi/memfd.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/kho/abi/memfd.h +2 -2
index da7d063474a1..c211c31334a3 100644
@@ -17,8 +17,8 @@
 /**
  * DOC: memfd Live Update ABI
  *
- * This header defines the ABI for preserving the state of a memfd across a
- * kexec reboot using the LUO.
+ * memfd uses the ABI defined below for preserving its state across a kexec
+ * reboot using the LUO.
  *
  * The state is serialized into a packed structure `struct memfd_luo_ser`
  * which is handed over to the next kernel via the KHO mechanism.
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 2/6
#5 lore raw

Re: [PATCH 2/6] kho/abi: memfd: make generated documentation more coherent

Quoted 9 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

memfd preservation ABI description starts with "This header defines" which is fine in the header but reads weird in the generated html documentation.

Update it to make the generated documentation coherent.

[...]

Signature · 2 lines
Regards,
Pratyush Yadav
maintainer Reviewed-by on v1 2/6
#6 lore raw

Re: [PATCH 2/6] kho/abi: memfd: make generated documentation more coherent

In reply to Mike Rapoport
Quoted 30 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

memfd preservation ABI description starts with "This header defines" which is fine in the header but reads weird in the generated html documentation.

Update it to make the generated documentation coherent.

---
 include/linux/kho/abi/memfd.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/kho/abi/memfd.h +2 -3
index da7d063474a1..c211c31334a3 100644
@@ -17,8 +17,8 @@
 /**
  * DOC: memfd Live Update ABI
  *
- * This header defines the ABI for preserving the state of a memfd across a
- * kexec reboot using the LUO.
+ * memfd uses the ABI defined below for preserving its state across a kexec
+ * reboot using the LUO.
  *
  * The state is serialized into a packed structure `struct memfd_luo_ser`
  * which is handed over to the next kernel via the KHO mechanism.
--
Quoted 2 lines

2.51.0

author maintainer
#7 lore raw

PATCH 3/6 kho: docs: combine concepts and FDT documentation

In reply to Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

Currently index.rst in KHO documentation looks empty and sad as it only contains links to "Kexec Handover Concepts" and "KHO FDT" chapters.

Inline contents of these chapters into index.rst to provide a single coherent chapter describing KHO.

While on it, drop parts of the KHO FDT description that will be superseded by addition of KHO ABI documentation.

---
 Documentation/core-api/kho/concepts.rst | 74 -----------------------
 Documentation/core-api/kho/fdt.rst      | 80 -------------------------
 Documentation/core-api/kho/index.rst    | 73 ++++++++++++++++++++--
 Documentation/core-api/liveupdate.rst   |  2 +-
 Documentation/mm/memfd_preservation.rst |  2 +-
 5 files changed, 70 insertions(+), 161 deletions(-)
 delete mode 100644 Documentation/core-api/kho/concepts.rst
 delete mode 100644 Documentation/core-api/kho/fdt.rst
Documentation/core-api/kho/concepts.rst deleted +0 -74
deleted file mode 100644
index d626d1dbd678..000000000000
@@ -1,74 +0,0 @@
-.. SPDX-License-Identifier: GPL-2.0-or-later
-.. _kho-concepts:
-
-=======================
-Kexec Handover Concepts
-=======================
-
-Kexec HandOver (KHO) is a mechanism that allows Linux to preserve memory
-regions, which could contain serialized system states, across kexec.
-
-It introduces multiple concepts:
-
-KHO FDT
-=======
-
-Every KHO kexec carries a KHO specific flattened device tree (FDT) blob
-that describes preserved memory regions. These regions contain either
-serialized subsystem states, or in-memory data that shall not be touched
-across kexec. After KHO, subsystems can retrieve and restore preserved
-memory regions from KHO FDT.
-
-KHO only uses the FDT container format and libfdt library, but does not
-adhere to the same property semantics that normal device trees do: Properties
-are passed in native endianness and standardized properties like ``regs`` and
-``ranges`` do not exist, hence there are no ``#...-cells`` properties.
-
-KHO is still under development. The FDT schema is unstable and would change
-in the future.
-
-Scratch Regions
-===============
-
-To boot into kexec, we need to have a physically contiguous memory range that
-contains no handed over memory. Kexec then places the target kernel and initrd
-into that region. The new kernel exclusively uses this region for memory
-allocations before during boot up to the initialization of the page allocator.
-
-We guarantee that we always have such regions through the scratch regions: On
-first boot KHO allocates several physically contiguous memory regions. Since
-after kexec these regions will be used by early memory allocations, there is a
-scratch region per NUMA node plus a scratch region to satisfy allocations
-requests that do not require particular NUMA node assignment.
-By default, size of the scratch region is calculated based on amount of memory
-allocated during boot. The ``kho_scratch`` kernel command line option may be
-used to explicitly define size of the scratch regions.
-The scratch regions are declared as CMA when page allocator is initialized so
-that their memory can be used during system lifetime. CMA gives us the
-guarantee that no handover pages land in that region, because handover pages
-must be at a static physical memory location and CMA enforces that only
-movable pages can be located inside.
-
-After KHO kexec, we ignore the ``kho_scratch`` kernel command line option and
-instead reuse the exact same region that was originally allocated. This allows
-us to recursively execute any amount of KHO kexecs. Because we used this region
-for boot memory allocations and as target memory for kexec blobs, some parts
-of that memory region may be reserved. These reservations are irrelevant for
-the next KHO, because kexec can overwrite even the original kernel.
-
-.. _kho-finalization-phase:
-
-KHO finalization phase
-======================
-
-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.
-
-Public API
-==========
-.. kernel-doc:: kernel/liveupdate/kexec_handover.c
-   :export:
Documentation/core-api/kho/fdt.rst deleted +0 -80

80 lines not on this page · raw message

Documentation/core-api/kho/index.rst +68 -5

78 lines not on this page · raw message

Documentation/core-api/liveupdate.rst +1 -1
index 7960eb15a81f..e2aba13494cf 100644
@@ -58,4 +58,4 @@ See Also
 ========
 
 - :doc:`Live Update uAPI </userspace-api/liveupdate>`
-- :doc:`/core-api/kho/concepts`
+- :doc:`/core-api/kho/index`
Documentation/mm/memfd_preservation.rst +1 -1
index 66e0fb6d5ef0..a8a5b476afd3 100644
@@ -20,4 +20,4 @@ See Also
 ========
 
 - :doc:`/core-api/liveupdate`
-- :doc:`/core-api/kho/concepts`
+- :doc:`/core-api/kho/index`
Signature · 1 line
2.51.0
maintainer
#8 lore raw

Re: [PATCH 3/6] kho: docs: combine concepts and FDT documentation

Quoted 12 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

Currently index.rst in KHO documentation looks empty and sad as it only contains links to "Kexec Handover Concepts" and "KHO FDT" chapters.

Inline contents of these chapters into index.rst to provide a single coherent chapter describing KHO.

While on it, drop parts of the KHO FDT description that will be superseded by addition of KHO ABI documentation.

[...]

Documentation/core-api/kho/index.rst line 8

Quoted 12 lines
Documentation/core-api/kho/index.rst +2 -2
index 0c63b0c5c143..03cd9afbdb2e 100644
@@ -4,10 +4,73 @@
 Kexec Handover Subsystem
 ========================
 
-.. toctree::
-   :maxdepth: 1
+Overview
+========

I ran a test build and Sphinx complains about:

Documentation/admin-guide/mm/kho.rst:10: WARNING: undefined label: 'kho-concepts' [ref.ref] Documentation/admin-guide/mm/kho.rst:31: WARNING: undefined label: 'kho-finalization-phase' [ref.ref]

I suppose you should add these labels here.

Otherwise LGTM.

Quoted 94 lines
Documentation/core-api/kho/index.rst +66 -3
-   concepts
-   fdt
+Kexec HandOver (KHO) is a mechanism that allows Linux to preserve memory
+regions, which could contain serialized system states, across kexec.
 
-.. only::  subproject and html
+KHO uses :ref:`flattened device tree (FDT) <kho_fdt>` to pass information about
+the preserved state from pre-exec kernel to post-kexec kernel and :ref:`scratch
+memory regions <kho_scratch>` to ensure integrity of the preserved memory.
+
+.. _kho_fdt:
+
+KHO FDT
+=======
+Every KHO kexec carries a KHO specific flattened device tree (FDT) blob that
+describes the preserved state. The FDT includes properties describing preserved
+memory regions and nodes that hold subsystem specific state.
+
+The preserved memory regions contain either serialized subsystem states, or
+in-memory data that shall not be touched across kexec. After KHO, subsystems
+can retrieve and restore the preserved state from KHO FDT.
+
+Subsystems participating in KHO can define their own format for state
+serialization and preservation.
+
+.. _kho_scratch:
+
+Scratch Regions
+===============
+
+To boot into kexec, we need to have a physically contiguous memory range that
+contains no handed over memory. Kexec then places the target kernel and initrd
+into that region. The new kernel exclusively uses this region for memory
+allocations before during boot up to the initialization of the page allocator.
+
+We guarantee that we always have such regions through the scratch regions: On
+first boot KHO allocates several physically contiguous memory regions. Since
+after kexec these regions will be used by early memory allocations, there is a
+scratch region per NUMA node plus a scratch region to satisfy allocations
+requests that do not require particular NUMA node assignment.
+By default, size of the scratch region is calculated based on amount of memory
+allocated during boot. The ``kho_scratch`` kernel command line option may be
+used to explicitly define size of the scratch regions.
+The scratch regions are declared as CMA when page allocator is initialized so
+that their memory can be used during system lifetime. CMA gives us the
+guarantee that no handover pages land in that region, because handover pages
+must be at a static physical memory location and CMA enforces that only
+movable pages can be located inside.
+
+After KHO kexec, we ignore the ``kho_scratch`` kernel command line option and
+instead reuse the exact same region that was originally allocated. This allows
+us to recursively execute any amount of KHO kexecs. Because we used this region
+for boot memory allocations and as target memory for kexec blobs, some parts
+of that memory region may be reserved. These reservations are irrelevant for
+the next KHO, because kexec can overwrite even the original kernel.
+
+KHO finalization phase
+======================
+
+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.
+
+See Also
+========
+
+- :doc:`/admin-guide/mm/kho`
Documentation/core-api/liveupdate.rst +1 -1
index 7960eb15a81f..e2aba13494cf 100644
@@ -58,4 +58,4 @@ See Also
 ========
 
 - :doc:`Live Update uAPI </userspace-api/liveupdate>`
-- :doc:`/core-api/kho/concepts`
 
+- :doc:`/core-api/kho/index`
Documentation/mm/memfd_preservation.rst +1 -1
index 66e0fb6d5ef0..a8a5b476afd3 100644
@@ -20,4 +20,4 @@ See Also
 ========
 
 - :doc:`/core-api/liveupdate`
-- :doc:`/core-api/kho/concepts`
 
+- :doc:`/core-api/kho/index`
Signature · 2 lines
Regards,
Pratyush Yadav
author maintainer
#9 lore raw

Re: [PATCH 3/6] kho: docs: combine concepts and FDT documentation

Quoted 30 lines · Pratyush Yadav
Quoted 12 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

Currently index.rst in KHO documentation looks empty and sad as it only contains links to "Kexec Handover Concepts" and "KHO FDT" chapters.

Inline contents of these chapters into index.rst to provide a single coherent chapter describing KHO.

While on it, drop parts of the KHO FDT description that will be superseded by addition of KHO ABI documentation.

[...]

Documentation/core-api/kho/index.rst line 8

Quoted 12 lines
Documentation/core-api/kho/index.rst +2 -2
index 0c63b0c5c143..03cd9afbdb2e 100644
@@ -4,10 +4,73 @@
 Kexec Handover Subsystem
 ========================
 
-.. toctree::
-   :maxdepth: 1
+Overview
+========

I ran a test build and Sphinx complains about:

Quoted 4 lines

Documentation/admin-guide/mm/kho.rst:10: WARNING: undefined label: 'kho-concepts' [ref.ref] Documentation/admin-guide/mm/kho.rst:31: WARNING: undefined label: 'kho-finalization-phase' [ref.ref]

I suppose you should add these labels here.

It's already in Andrew's tree:
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?h=mm-nonmm-unstable&id=bc1a060da2a76161ba65f1badc551de15056e398

Quoted 100 lines

Otherwise LGTM.

Quoted 94 lines
Documentation/core-api/kho/index.rst +66 -3
-   concepts
-   fdt
+Kexec HandOver (KHO) is a mechanism that allows Linux to preserve memory
+regions, which could contain serialized system states, across kexec.
 
-.. only::  subproject and html
+KHO uses :ref:`flattened device tree (FDT) <kho_fdt>` to pass information about
+the preserved state from pre-exec kernel to post-kexec kernel and :ref:`scratch
+memory regions <kho_scratch>` to ensure integrity of the preserved memory.
+
+.. _kho_fdt:
+
+KHO FDT
+=======
+Every KHO kexec carries a KHO specific flattened device tree (FDT) blob that
+describes the preserved state. The FDT includes properties describing preserved
+memory regions and nodes that hold subsystem specific state.
+
+The preserved memory regions contain either serialized subsystem states, or
+in-memory data that shall not be touched across kexec. After KHO, subsystems
+can retrieve and restore the preserved state from KHO FDT.
+
+Subsystems participating in KHO can define their own format for state
+serialization and preservation.
+
+.. _kho_scratch:
+
+Scratch Regions
+===============
+
+To boot into kexec, we need to have a physically contiguous memory range that
+contains no handed over memory. Kexec then places the target kernel and initrd
+into that region. The new kernel exclusively uses this region for memory
+allocations before during boot up to the initialization of the page allocator.
+
+We guarantee that we always have such regions through the scratch regions: On
+first boot KHO allocates several physically contiguous memory regions. Since
+after kexec these regions will be used by early memory allocations, there is a
+scratch region per NUMA node plus a scratch region to satisfy allocations
+requests that do not require particular NUMA node assignment.
+By default, size of the scratch region is calculated based on amount of memory
+allocated during boot. The ``kho_scratch`` kernel command line option may be
+used to explicitly define size of the scratch regions.
+The scratch regions are declared as CMA when page allocator is initialized so
+that their memory can be used during system lifetime. CMA gives us the
+guarantee that no handover pages land in that region, because handover pages
+must be at a static physical memory location and CMA enforces that only
+movable pages can be located inside.
+
+After KHO kexec, we ignore the ``kho_scratch`` kernel command line option and
+instead reuse the exact same region that was originally allocated. This allows
+us to recursively execute any amount of KHO kexecs. Because we used this region
+for boot memory allocations and as target memory for kexec blobs, some parts
+of that memory region may be reserved. These reservations are irrelevant for
+the next KHO, because kexec can overwrite even the original kernel.
+
+KHO finalization phase
+======================
+
+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.
+
+See Also
+========
+
+- :doc:`/admin-guide/mm/kho`
Documentation/core-api/liveupdate.rst +1 -1
index 7960eb15a81f..e2aba13494cf 100644
@@ -58,4 +58,4 @@ See Also
 ========
 
 - :doc:`Live Update uAPI </userspace-api/liveupdate>`
-- :doc:`/core-api/kho/concepts`
 
+- :doc:`/core-api/kho/index`
Documentation/mm/memfd_preservation.rst +1 -1
index 66e0fb6d5ef0..a8a5b476afd3 100644
@@ -20,4 +20,4 @@ See Also
 ========
 
 - :doc:`/core-api/liveupdate`
-- :doc:`/core-api/kho/concepts`
 
+- :doc:`/core-api/kho/index`
Signature · 2 lines
Regards,
Pratyush Yadav
Signature · 2 lines
Sincerely yours,
Mike.
maintainer Reviewed-by
#10 lore raw

Re: [PATCH 3/6] kho: docs: combine concepts and FDT documentation

Quoted 31 lines · Mike Rapoport
Quoted 30 lines · Pratyush Yadav
Quoted 12 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

Currently index.rst in KHO documentation looks empty and sad as it only contains links to "Kexec Handover Concepts" and "KHO FDT" chapters.

Inline contents of these chapters into index.rst to provide a single coherent chapter describing KHO.

While on it, drop parts of the KHO FDT description that will be superseded by addition of KHO ABI documentation.

[...]

Documentation/core-api/kho/index.rst line 8

Quoted 12 lines
Documentation/core-api/kho/index.rst +2 -2
index 0c63b0c5c143..03cd9afbdb2e 100644
@@ -4,10 +4,73 @@
 Kexec Handover Subsystem
 ========================
 
-.. toctree::
-   :maxdepth: 1
+Overview
+========

I ran a test build and Sphinx complains about:

Quoted 7 lines
Quoted 4 lines

Documentation/admin-guide/mm/kho.rst:10: WARNING: undefined label: 'kho-concepts' [ref.ref] Documentation/admin-guide/mm/kho.rst:31: WARNING: undefined label: 'kho-finalization-phase' [ref.ref]

I suppose you should add these labels here.

It's already in Andrew's tree:
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?h=mm-nonmm-unstable&id=bc1a060da2a76161ba65f1badc551de15056e398

Okay, nice. Then with that,

Quoted 3 lines
Quoted 3 lines

Otherwise LGTM.

[...]

Signature · 2 lines
Regards,
Pratyush Yadav
maintainer Reviewed-by on v1 3/6
#11 lore raw

Re: [PATCH 3/6] kho: docs: combine concepts and FDT documentation

In reply to Mike Rapoport
Quoted 6 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

Currently index.rst in KHO documentation looks empty and sad as it only contains links to "Kexec Handover Concepts" and "KHO FDT" chapters.

Quoted 7 lines

Inline contents of these chapters into index.rst to provide a single coherent chapter describing KHO.

While on it, drop parts of the KHO FDT description that will be superseded by addition of KHO ABI documentation.

author maintainer
#12 lore raw

PATCH 4/6 kho: Introduce KHO FDT ABI header

In reply to Mike Rapoport

From: Jason Miu <[email protected]>

Introduce the include/linux/kho/abi/kexec_handover.h header file, which defines the stable ABI for the KHO mechanism. This header specifies how preserved data is passed between kernels using an FDT.

The ABI contract includes the FDT structure, node properties, and the "kho-v1" compatible string. By centralizing these definitions, this header serves as the foundational agreement for inter-kernel communication of preserved states, ensuring forward compatibility and preventing misinterpretation of data across kexec transitions.

Since the ABI definitions are now centralized in the header files, the YAML files that previously described the FDT interfaces are redundant. These redundant files have therefore been removed.

---
 Documentation/core-api/kho/abi.rst            | 16 ++++
 Documentation/core-api/kho/bindings/kho.yaml  | 43 ----------
 .../core-api/kho/bindings/sub-fdt.yaml        | 27 ------
 Documentation/core-api/kho/index.rst          |  9 ++
 MAINTAINERS                                   |  1 +
 include/linux/kho/abi/kexec_handover.h        | 85 +++++++++++++++++++
 kernel/liveupdate/kexec_handover.c            | 19 ++---
 7 files changed, 120 insertions(+), 80 deletions(-)
 create mode 100644 Documentation/core-api/kho/abi.rst
 delete mode 100644 Documentation/core-api/kho/bindings/kho.yaml
 delete mode 100644 Documentation/core-api/kho/bindings/sub-fdt.yaml
 create mode 100644 include/linux/kho/abi/kexec_handover.h
Documentation/core-api/kho/abi.rst new file +16 -0
new file mode 100644
index 000000000000..a1ee0f481727
@@ -0,0 +1,16 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+==================
+Kexec Handover ABI
+==================
+
+Core Kexec Handover ABI
+========================
+
+.. kernel-doc:: include/linux/kho/abi/kexec_handover.h
+   :doc: Kexec Handover ABI
+
+See Also
+========
+
+- :doc:`/admin-guide/mm/kho`
Documentation/core-api/kho/bindings/kho.yaml deleted +0 -43

43 lines not on this page · raw message

Documentation/core-api/kho/bindings/sub-fdt.yaml deleted +0 -27
deleted file mode 100644
index b9a3d2d24850..000000000000
@@ -1,27 +0,0 @@
-# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
-%YAML 1.2
----
-title: KHO users' FDT address
-
-maintainers:
-  - Mike Rapoport <[email protected]>
-  - Changyuan Lyu <[email protected]>
-
-description: |
-  Physical address of an FDT blob registered by a KHO user.
-
-properties:
-  fdt:
-    description: |
-      physical address (u64) of an FDT blob.
-
-required:
-  - fdt
-
-additionalProperties: false
-
-examples:
-  - |
-    memblock {
-            fdt = <0x80cc16 0x1000000>;
-    };
Documentation/core-api/kho/index.rst +9 -0
index 03cd9afbdb2e..f56579b5c351 100644
@@ -29,6 +29,15 @@ can retrieve and restore the preserved state from KHO FDT.
 Subsystems participating in KHO can define their own format for state
 serialization and preservation.
 
+KHO FDT and structures defined by the subsystems form an ABI between pre-kexec
+and post-kexec kernels. This ABI is defined by header files in
+``include/linux/kho/abi`` directory.
+
+.. toctree::
+   :maxdepth: 1
+
+   abi.rst
+
 .. _kho_scratch:
 
 Scratch Regions
MAINTAINERS +1 -0
index 12f49de7fe03..cadaa9270346 100644
@@ -13959,6 +13959,7 @@ S:	Maintained
 F:	Documentation/admin-guide/mm/kho.rst
 F:	Documentation/core-api/kho/*
 F:	include/linux/kexec_handover.h
+F:	include/linux/kho/abi/
 F:	kernel/liveupdate/kexec_handover*
 F:	lib/test_kho.c
 F:	tools/testing/selftests/kho/
include/linux/kho/abi/kexec_handover.h new file +85 -0

85 lines not on this page · raw message

kernel/liveupdate/kexec_handover.c +9 -10
index 9dc51fab604f..d3d02a9ea391 100644
@@ -15,6 +15,7 @@
 #include <linux/count_zeros.h>
 #include <linux/kexec.h>
 #include <linux/kexec_handover.h>
+#include <linux/kho/abi/kexec_handover.h>
 #include <linux/libfdt.h>
 #include <linux/list.h>
 #include <linux/memblock.h>
@@ -33,10 +34,7 @@
 #include "../kexec_internal.h"
 #include "kexec_handover_internal.h"
 
-#define KHO_FDT_COMPATIBLE "kho-v1"
-#define PROP_PRESERVED_MEMORY_MAP "preserved-memory-map"
-#define PROP_SUB_FDT "fdt"
-
+/* The magic token for preserved pages */
 #define KHO_PAGE_MAGIC 0x4b484f50U /* ASCII for 'KHOP' */
 
 /*
@@ -378,7 +376,7 @@ static void kho_update_memory_map(struct khoser_mem_chunk *first_chunk)
 	void *ptr;
 	u64 phys;
 
-	ptr = fdt_getprop_w(kho_out.fdt, 0, PROP_PRESERVED_MEMORY_MAP, NULL);
+	ptr = fdt_getprop_w(kho_out.fdt, 0, KHO_FDT_MEMORY_MAP_PROP_NAME, NULL);
 
 	/* Check and discard previous memory map */
 	phys = get_unaligned((u64 *)ptr);
@@ -468,7 +466,7 @@ static bool __init kho_mem_deserialize(const void *fdt)
 	u64 mem;
 	int len;
 
-	mem_ptr = fdt_getprop(fdt, 0, PROP_PRESERVED_MEMORY_MAP, &len);
+	mem_ptr = fdt_getprop(fdt, 0, KHO_FDT_MEMORY_MAP_PROP_NAME, &len);
 	if (!mem_ptr || len != sizeof(u64)) {
 		pr_err("failed to get preserved memory bitmaps\n");
 		return false;
@@ -733,7 +731,8 @@ int kho_add_subtree(const char *name, void *fdt)
 		goto out_pack;
 	}
 
-	err = fdt_setprop(root_fdt, off, PROP_SUB_FDT, &phys, sizeof(phys));
+	err = fdt_setprop(root_fdt, off, KHO_FDT_SUB_TREE_PROP_NAME,
+			  &phys, sizeof(phys));
 	if (err < 0)
 		goto out_pack;
 
@@ -764,7 +763,7 @@ void kho_remove_subtree(void *fdt)
 		const u64 *val;
 		int len;
 
-		val = fdt_getprop(root_fdt, off, PROP_SUB_FDT, &len);
+		val = fdt_getprop(root_fdt, off, KHO_FDT_SUB_TREE_PROP_NAME, &len);
 		if (!val || len != sizeof(phys_addr_t))
 			continue;
 
@@ -1310,7 +1309,7 @@ int kho_retrieve_subtree(const char *name, phys_addr_t *phys)
 	if (offset < 0)
 		return -ENOENT;
 
-	val = fdt_getprop(fdt, offset, PROP_SUB_FDT, &len);
+	val = fdt_getprop(fdt, offset, KHO_FDT_SUB_TREE_PROP_NAME, &len);
 	if (!val || len != sizeof(*val))
 		return -EINVAL;
 
@@ -1330,7 +1329,7 @@ static __init int kho_out_fdt_setup(void)
 	err |= fdt_finish_reservemap(root);
 	err |= fdt_begin_node(root, "");
 	err |= fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE);
-	err |= fdt_property(root, PROP_PRESERVED_MEMORY_MAP, &empty_mem_map,
+	err |= fdt_property(root, KHO_FDT_MEMORY_MAP_PROP_NAME, &empty_mem_map,
 			    sizeof(empty_mem_map));
 	err |= fdt_end_node(root);
 	err |= fdt_finish(root);
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 4/6
#13 lore raw

Re: [PATCH 4/6] kho: Introduce KHO FDT ABI header

Quoted 12 lines · Mike Rapoport

From: Jason Miu <[email protected]>

Introduce the include/linux/kho/abi/kexec_handover.h header file, which defines the stable ABI for the KHO mechanism. This header specifies how preserved data is passed between kernels using an FDT.

The ABI contract includes the FDT structure, node properties, and the "kho-v1" compatible string. By centralizing these definitions, this header serves as the foundational agreement for inter-kernel communication of preserved states, ensuring forward compatibility and preventing misinterpretation of data across kexec transitions.

Quoted 7 lines

Since the ABI definitions are now centralized in the header files, the YAML files that previously described the FDT interfaces are redundant. These redundant files have therefore been removed.

[...]

Signature · 2 lines
Regards,
Pratyush Yadav
maintainer Reviewed-by on v1 4/6
#14 lore raw

Re: [PATCH 4/6] kho: Introduce KHO FDT ABI header

In reply to Mike Rapoport
Quoted 13 lines · Mike Rapoport

From: Jason Miu <[email protected]>

Introduce the include/linux/kho/abi/kexec_handover.h header file, which defines the stable ABI for the KHO mechanism. This header specifies how preserved data is passed between kernels using an FDT.

The ABI contract includes the FDT structure, node properties, and the "kho-v1" compatible string. By centralizing these definitions, this header serves as the foundational agreement for inter-kernel communication of preserved states, ensuring forward compatibility and preventing misinterpretation of data across kexec transitions.

Quoted 7 lines

Since the ABI definitions are now centralized in the header files, the YAML files that previously described the FDT interfaces are redundant. These redundant files have therefore been removed.

author maintainer
#15 lore raw

PATCH 5/6 kho: Relocate vmalloc preservation structure to KHO ABI header

In reply to Mike Rapoport

From: Jason Miu <[email protected]>

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.

---
 Documentation/core-api/kho/abi.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(-)
Documentation/core-api/kho/abi.rst +6 -0
index a1ee0f481727..1d9916adee23 100644
@@ -10,6 +10,12 @@ Core Kexec Handover ABI
 .. kernel-doc:: include/linux/kho/abi/kexec_handover.h
    :doc: Kexec Handover ABI
 
+vmalloc preservation ABI
+========================
+
+.. kernel-doc:: include/linux/kho/abi/kexec_handover.h
+   :doc: Kexec Handover ABI for vmalloc Preservation
+
 See Also
 ========
 
include/linux/kexec_handover.h +2 -25
index 5f7b9de97e8d..a56ff3ffaf17 100644
@@ -11,34 +11,11 @@ struct kho_scratch {
 	phys_addr_t size;
 };
 
+struct kho_vmalloc;
+
 struct folio;
 struct page;
 
-#define DECLARE_KHOSER_PTR(name, type) \
-	union {                        \
-		phys_addr_t phys;      \
-		type ptr;              \
-	} name
-#define KHOSER_STORE_PTR(dest, val)               \
-	({                                        \
-		typeof(val) v = val;              \
-		typecheck(typeof((dest).ptr), v); \
-		(dest).phys = virt_to_phys(v);    \
-	})
-#define KHOSER_LOAD_PTR(src)                                                 \
-	({                                                                   \
-		typeof(src) s = 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);
include/linux/kho/abi/kexec_handover.h +78 -0

88 lines not on this page · raw message

include/linux/kho/abi/memfd.h +1 -1
index c211c31334a3..68cb6303b846 100644
@@ -12,7 +12,7 @@
 #define _LINUX_KHO_ABI_MEMFD_H
 
 #include <linux/types.h>
-#include <linux/kexec_handover.h>
+#include <linux/kho/abi/kexec_handover.h>
 
 /**
  * DOC: memfd Live Update ABI
kernel/liveupdate/kexec_handover.c +0 -15
index d3d02a9ea391..a180b3367e8f 100644
@@ -882,21 +882,6 @@ void kho_unpreserve_pages(struct page *page, unsigned int nr_pages)
 }
 EXPORT_SYMBOL_GPL(kho_unpreserve_pages);
 
-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) == PAGE_SIZE);
-
 /* vmalloc flags KHO supports */
 #define KHO_VMALLOC_SUPPORTED_FLAGS	(VM_ALLOC | VM_ALLOW_HUGE_VMAP)
 
lib/test_kho.c +1 -0
index 47de56280795..3431daca6968 100644
@@ -19,6 +19,7 @@
 #include <linux/printk.h>
 #include <linux/vmalloc.h>
 #include <linux/kexec_handover.h>
+#include <linux/kho/abi/kexec_handover.h>
 
 #include <net/checksum.h>
 
Signature · 1 line
2.51.0
maintainer
#16 lore raw

Re: [PATCH 5/6] kho: Relocate vmalloc preservation structure to KHO ABI header

Quoted 17 lines · Mike Rapoport

From: Jason Miu <[email protected]>

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.

[...]

Quoted 11 lines
include/linux/kho/abi/kexec_handover.h +11 -0
+/* 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 = val;              \

include/linux/kho/abi/kexec_handover.h line 123

Quoted 10 lines
include/linux/kho/abi/kexec_handover.h +10 -0
+		typecheck(typeof((dest).ptr), v); \
+		(dest).phys = virt_to_phys(v);    \
+	})
+
+/* Loads the stored physical address back to a pointer. */
+#define KHOSER_LOAD_PTR(src)						\
+	({                                                                   \
+		typeof(src) s = src;                                         \
+		(typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \
+	})

Nit: not a fan of exposing code internals to the ABI header. But without this the definition of kho_vmalloc_hdr won't make any sense to someone reading the doc without looking at the code. Dunno if we can do anything better though...

Quoted 9 lines
include/linux/kho/abi/kexec_handover.h +9 -0
+
+/*
+ * 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 *);
+};

include/linux/kho/abi/kexec_handover.h line 142

Quoted 10 lines
include/linux/kho/abi/kexec_handover.h +10 -0
+
+#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 next
+ * chunk and an array of physical addresses of the pages that make up the
+ * preserved vmalloc area.

Perhaps also mention that the array is 0-terminated?

Looks good otherwise.

[...]

Signature · 2 lines
Regards,
Pratyush Yadav
author maintainer
#17 lore raw

Re: [PATCH 5/6] kho: Relocate vmalloc preservation structure to KHO ABI header

Quoted 38 lines · Pratyush Yadav
Quoted 17 lines · Mike Rapoport

From: Jason Miu <[email protected]>

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.

[...]

Quoted 18 lines
(quoted diff) +18 -0
+/* 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 = val;              \
+		typecheck(typeof((dest).ptr), v); \
+		(dest).phys = virt_to_phys(v);    \
+	})
+
+/* Loads the stored physical address back to a pointer. */
+#define KHOSER_LOAD_PTR(src)						\
+	({                                                                   \
Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+		typeof(src) s = src;                                         \
+		(typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \
+	})

Nit: not a fan of exposing code internals to the ABI header. But without this the definition of kho_vmalloc_hdr won't make any sense to someone reading the doc without looking at the code. Dunno if we can do anything better though...

These might be actually useful for other KHO users.

Quoted 12 lines
Quoted 12 lines
(quoted diff) +12 -0
+/*
+ * 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))
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+
+/*
+ * 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 next
+ * chunk and an array of physical addresses of the pages that make up the
+ * preserved vmalloc area.

Perhaps also mention that the array is 0-terminated?

Yeah, sure.

@Andrew, can you please add this as a fixup:

include/linux/kho/abi/kexec_handover.h +2 -2
index 285eda8a36e4..2201a0d2c159 100644
@@ -138,8 +138,8 @@ struct kho_vmalloc_hdr {
 /*
  * 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 next
- * chunk and an array of physical addresses of the pages that make up the
- * preserved vmalloc area.
+ * chunk and a zero terminated array of physical addresses of the pages that
+ * make up the preserved vmalloc area.
  */
 struct kho_vmalloc_chunk {
 	struct kho_vmalloc_hdr hdr;
Quoted 4 lines

Looks good otherwise.

Signature · 2 lines
Regards,
Pratyush Yadav
Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#18 lore raw

Re: [PATCH 5/6] kho: Relocate vmalloc preservation structure to KHO ABI header

Quoted 48 lines · Mike Rapoport
Quoted 38 lines · Pratyush Yadav
Quoted 17 lines · Mike Rapoport

From: Jason Miu <[email protected]>

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.

[...]

Quoted 18 lines
(quoted diff) +18 -0
+/* 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 = val;              \
+		typecheck(typeof((dest).ptr), v); \
+		(dest).phys = virt_to_phys(v);    \
+	})
+
+/* Loads the stored physical address back to a pointer. */
+#define KHOSER_LOAD_PTR(src)						\
+	({                                                                   \
Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+		typeof(src) s = src;                                         \
+		(typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \
+	})

Nit: not a fan of exposing code internals to the ABI header. But without this the definition of kho_vmalloc_hdr won't make any sense to someone reading the doc without looking at the code. Dunno if we can do anything better though...

Quoted 1 line

These might be actually useful for other KHO users.

Hmm, okay. Let's keep them here then.

[...]

Signature · 2 lines
Regards,
Pratyush Yadav
maintainer Reviewed-by
#19 lore raw

Re: [PATCH 5/6] kho: Relocate vmalloc preservation structure to KHO ABI header

Quoted 51 lines · Pratyush Yadav
Quoted 48 lines · Mike Rapoport
Quoted 46 lines · Pratyush Yadav
Quoted 17 lines · Mike Rapoport

From: Jason Miu <[email protected]>

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.

[...]

Quoted 11 lines
(quoted diff) +11 -0
+/* 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 = val;              \

Review

Quoted 10 lines
(quoted diff) +10 -0
+          typecheck(typeof((dest).ptr), v); \
+          (dest).phys = virt_to_phys(v);    \
+  })
+
+/* Loads the stored physical address back to a pointer. */
+#define KHOSER_LOAD_PTR(src)                                              \
+  ({                                                                   \
+          typeof(src) s = src;                                         \
+          (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \
+  })

Nit: not a fan of exposing code internals to the ABI header. But without this the definition of kho_vmalloc_hdr won't make any sense to someone reading the doc without looking at the code. Dunno if we can do anything better though...

Quoted 1 line
Quoted 1 line

These might be actually useful for other KHO users.

In my view, khoser definition belongs in the kernel implementation rather than the cross-kernel ABI. The ABI describes the preserved data format and should be independent of C types. However, this is a minor complaint compared to the overall effort of moving the preserved format into the ABI and making KHO stateless. For that reason, let's merge it.

author maintainer
#20 lore raw

PATCH 6/6 kho/abi: add memblock ABI header

In reply to Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

Introduce KHO ABI header describing preservation ABI for memblock's reserve_mem regions and link the relevant documentation to KHO docs.

---
 Documentation/core-api/kho/abi.rst            |  6 ++
 .../kho/bindings/memblock/memblock.yaml       | 39 ----------
 .../kho/bindings/memblock/reserve-mem.yaml    | 40 -----------
 include/linux/kho/abi/memblock.h              | 72 +++++++++++++++++++
 mm/memblock.c                                 |  4 +-
 5 files changed, 79 insertions(+), 82 deletions(-)
 delete mode 100644 Documentation/core-api/kho/bindings/memblock/memblock.yaml
 delete mode 100644 Documentation/core-api/kho/bindings/memblock/reserve-mem.yaml
 create mode 100644 include/linux/kho/abi/memblock.h
Documentation/core-api/kho/abi.rst +6 -0
index 1d9916adee23..2e63be3486cf 100644
@@ -16,6 +16,12 @@ vmalloc preservation ABI
 .. kernel-doc:: include/linux/kho/abi/kexec_handover.h
    :doc: Kexec Handover ABI for vmalloc Preservation
 
+memblock preservation ABI
+=========================
+
+.. kernel-doc:: include/linux/kho/abi/memblock.h
+   :doc: memblock kexec handover ABI
+
 See Also
 ========
 
Documentation/core-api/kho/bindings/memblock/memblock.yaml deleted +0 -39
deleted file mode 100644
index d388c28eb91d..000000000000
@@ -1,39 +0,0 @@
-# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
-%YAML 1.2
----
-title: Memblock reserved memory
-
-maintainers:
-  - Mike Rapoport <[email protected]>
-
-description: |
-  Memblock can serialize its current memory reservations created with
-  reserve_mem command line option across kexec through KHO.
-  The post-KHO kernel can then consume these reservations and they are
-  guaranteed to have the same physical address.
-
-properties:
-  compatible:
-    enum:
-      - reserve-mem-v1
-
-patternProperties:
-  "$[0-9a-f_]+^":
-    $ref: reserve-mem.yaml#
-    description: reserved memory regions
-
-required:
-  - compatible
-
-additionalProperties: false
-
-examples:
-  - |
-    memblock {
-      compatible = "memblock-v1";
-      n1 {
-        compatible = "reserve-mem-v1";
-        start = <0xc06b 0x4000000>;
-        size = <0x04 0x00>;
-      };
-    };
Documentation/core-api/kho/bindings/memblock/reserve-mem.yaml deleted +0 -40
deleted file mode 100644
index 10282d3d1bcd..000000000000
@@ -1,40 +0,0 @@
-# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
-%YAML 1.2
----
-title: Memblock reserved memory regions
-
-maintainers:
-  - Mike Rapoport <[email protected]>
-
-description: |
-  Memblock can serialize its current memory reservations created with
-  reserve_mem command line option across kexec through KHO.
-  This object describes each such region.
-
-properties:
-  compatible:
-    enum:
-      - reserve-mem-v1
-
-  start:
-    description: |
-      physical address (u64) of the reserved memory region.
-
-  size:
-    description: |
-      size (u64) of the reserved memory region.
-
-required:
-  - compatible
-  - start
-  - size
-
-additionalProperties: false
-
-examples:
-  - |
-    n1 {
-      compatible = "reserve-mem-v1";
-      start = <0xc06b 0x4000000>;
-      size = <0x04 0x00>;
-    };
include/linux/kho/abi/memblock.h new file +72 -0

72 lines not on this page · raw message

mm/memblock.c +1 -3
index 905d06b16348..6cff515d82f4 100644
@@ -21,6 +21,7 @@
 #ifdef CONFIG_KEXEC_HANDOVER
 #include <linux/libfdt.h>
 #include <linux/kexec_handover.h>
+#include <linux/kho/abi/memblock.h>
 #endif /* CONFIG_KEXEC_HANDOVER */
 
 #include <asm/sections.h>
@@ -2442,9 +2443,6 @@ int reserve_mem_release_by_name(const char *name)
 }
 
 #ifdef CONFIG_KEXEC_HANDOVER
-#define MEMBLOCK_KHO_FDT "memblock"
-#define MEMBLOCK_KHO_NODE_COMPATIBLE "memblock-v1"
-#define RESERVE_MEM_KHO_NODE_COMPATIBLE "reserve-mem-v1"
 
 static int __init reserved_mem_preserve(void)
 {
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 6/6
#21 lore raw

Re: [PATCH 6/6] kho/abi: add memblock ABI header

Quoted 7 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

Introduce KHO ABI header describing preservation ABI for memblock's reserve_mem regions and link the relevant documentation to KHO docs.

---

[...]

Quoted 22 lines

+ * / {
+ * compatible = "memblock-v1";
+ *
+ * n1 {
+ * compatible = "reserve-mem-v1";
+ * start = <0xc06b 0x4000000>;
+ * size = <0x04 0x00>;
+ * };
+ * };
+ *
+ * Main memblock node (/):
+ *
+ * - compatible: "memblock-v1"
+
+ * Identifies the overall memblock ABI version.
+ *
+ * reserved_mem node:
+ * These nodes describe all reserve_mem regions.
+ *
+ * - compatible: "reserve-mem-v1"
+ *
+ * Identifies the ABI version of reserve_mem descriptions

Quoted 8 lines

+ *
+ * - start: u64
+ *
+ * Physical address of the reserved memory region.
+ *
+ * - size: u64
+ *
+ * size in bytes of the reserved memory region.

I think you should also mention that the name of the node is the name of the map.

Other than this,

Quoted 12 lines

+ */

include/linux/kho/abi/memblock.h new file +11 -0
+
+/* Top level memblock FDT node name. */
+#define MEMBLOCK_KHO_FDT "memblock"
+
+/* The compatible string for the memblock FDT root node. */
+#define MEMBLOCK_KHO_NODE_COMPATIBLE "memblock-v1"
+
+/* The compatible string for the reserve_mem FDT nodes. */
+#define RESERVE_MEM_KHO_NODE_COMPATIBLE "reserve-mem-v1"
+
+#endif /* _LINUX_KHO_ABI_MEMBLOCK_H */

[...]

Signature · 2 lines
Regards,
Pratyush Yadav
author maintainer
#22 lore raw

Re: [PATCH 6/6] kho/abi: add memblock ABI header

Quoted 8 lines · Pratyush Yadav
Quoted 3 lines · Mike Rapoport

+ * reserved_mem node:
+ * These nodes describe all reserve_mem regions.
+ *

I think you should also mention that the name of the node is the name of the map.

@Andrew, can you please add this as a fixup:

include/linux/kho/abi/memblock.h +2 -1
index fbfb2eb1b1cf..27b042f470e1 100644
@@ -45,7 +45,8 @@
  *     Identifies the overall memblock ABI version.
  *
  * reserved_mem node:
- *   These nodes describe all reserve_mem regions.
+ *   These nodes describe all reserve_mem regions. The node name is the name
+ *   defined by the user for a reserve_mem region.
  *
  *   - compatible: "reserve-mem-v1"
  *
Quoted 3 lines

Other than this,

Thanks!

Quoted 3 lines
Signature · 2 lines
Regards,
Pratyush Yadav
Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#24 lore raw
In reply to Mike Rapoport
Quoted 4 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

Hi,

Quoted 8 lines

LUO started adding KHO ABI headers to include/linux/kho/abi, but the core parts of KHO and memblock are still using the old way for descriptions on their ABIs.

Let's consolidate all things KHO in include/linux/kho/abi.

And while on that, make some documentation updates to have more coherent KHO docs.

Thanks for working on this! It is nice to have the ABI consolidated and cleaned.

[...]

Signature · 2 lines
Regards,
Pratyush Yadav