From: Randy Dunlap <rdunlap@infradead.org>
To: Andrey Ryabinin <arbn@yandex-team.com>, linux-kernel@vger.kernel.org
Cc: Alexander Graf <graf@amazon.com>, Mike Rapoport <rppt@kernel.org>,
James Gowans <jgowans@amazon.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Baoquan He <bhe@redhat.com>,
kexec@lists.infradead.org, Pratyush Yadav <ptyadav@amazon.de>,
Jason Gunthorpe <jgg@nvidia.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
David Rientjes <rientjes@google.com>,
Pratyush Yadav <pratyush@kernel.org>,
Changyuan Lyu <changyuanl@google.com>,
Jonathan Corbet <corbet@lwn.net>,
linux-doc@vger.kernel.org,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Chris Li <chrisl@kernel.org>,
Ashish.Kalra@amd.com, William Tu <witu@nvidia.com>,
David Matlack <dmatlack@google.com>
Subject: Re: [PATCH v3 7/7] Documentation, kstate: Add KSTATE documentation
Date: Tue, 9 Sep 2025 18:00:49 -0700 [thread overview]
Message-ID: <4e230009-ed70-4260-ba61-170ddab17a80@infradead.org> (raw)
In-Reply-To: <20250909201446.13138-8-arbn@yandex-team.com>
On 9/9/25 1:14 PM, Andrey Ryabinin wrote:
> Add KSTATE doc. Describe 'struct kstate_description' and information
> about versioning fields.
>
> Signed-off-by: Andrey Ryabinin <arbn@yandex-team.com>
> ---
> Documentation/core-api/index.rst | 1 +
> Documentation/core-api/kstate.rst | 117 ++++++++++++++++++++++++++++++
> MAINTAINERS | 1 +
> 3 files changed, 119 insertions(+)
> create mode 100644 Documentation/core-api/kstate.rst
>
> diff --git a/Documentation/core-api/kstate.rst b/Documentation/core-api/kstate.rst
> new file mode 100644
> index 000000000000..981ba162109c
> --- /dev/null
> +++ b/Documentation/core-api/kstate.rst
> @@ -0,0 +1,117 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +KSTATE: Kernel state preservation framework
> +===========================================
> +
> +KSTATE (kernel state) is framework to migrate some part of the internal
> +kernel state (device driver, memory, etc) from one kernel to another across
> +kexec reboot.
> +
> +kstate_description
> +------------------
> +
> +Most kernel's state is in structs and structs could be described by
Most kernel state
> +kstate_description. E.g. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> +
> +struct kstate_test_data {
> + int i;
> + unsigned long *p_ulong;
> + char s[10];
> + struct folio *folio;
> +};
> +
> +struct kstate_description test_state = {
> + .name = "test",
> + .version_id = 1,
> + .id = KSTATE_TEST_ID,
> + .fields = (const struct kstate_field[]) {
> + KSTATE_BASE_TYPE(s, struct kstate_test_data, char [10]),
> + KSTATE_POINTER(p_ulong, struct kstate_test_data),
> + KSTATE_FOLIO(folio, struct kstate_test_data),
> + KSTATE_END_OF_LIST()
> + },
> +};
> +
> +Changing data structures
> +------------------------
> +
> +KSTATE saves/restores structs as a series of fields. When the kernel structs
> +are changed we may need to change the state to store more/different information.
> +
> +Versions
> +--------
> +
> +Version numbers are intended for major incompatible changes, that are not
no comma
Drop "incompatible" since that is implied in the rest of the sentence.
> +backward compatible.
> +
> +Each version is associated with a series of fields saved. The state is always
> +saved as the newest version specified by ->version_id.
> +But loading state sometimes is able to load state from an older version.
> +
> +There are two version fields:
> +
> + - version_id: the maximum version_id supported by kstate_description.
> + - min_version_id: the minimum version_id that given kstate_description is able to understand.
> +
> +KSTATE is able to read versions from minimum_version_id to version_id.
> +
> +There are _V forms of many KSTATE_ macros to load fields for version dependent fields, e.g.
> +
> + KSTATE_BASE_TYPE_V(i, struct kstate_test_data, int, 2),
> +
> +only loads that field for versions 2 and newer.
> +
> +Saving state will always create a section with the ‘version_id’ value and thus can’t
> +be loaded by any older kernel.
> +
> +Removing field
> +--------------
> +If field is no longer needed it could be marked deprecated using
If a field
> +KSTATE_*_DEPRECATED macro and bumping ->version_id of kstate_description:
> +
> + KSTATE_BASE_TYPE_DEPRECATED(k, u16, 1),
> +
> +The last parameter of the macro is the last version number that have this field.
has
> +Old kernel will save such field, but new kernel will skip it on load. Also
An old kernel a new kernel
> +the new kernel will not save such field (as there is nothing to save).
> +Such change is not backward compatible.
> +
> +Adding new field
> +----------------
> +
> +Addition of new field can be done as version dependent field by using _V form of
of a new field as a version-dependent field by using the _V form of
> +KSTATE_ macro:
> + KSTATE_BASE_TYPE_V(i, struct kstate_test_data, int, 2),
> +
> +This indicates that 'test_state' only from version 2 and above have field '->i'.
> +If new kernel sees incoming 'test_state' of version 1 it will skip restoring '->i'
If a new kernel
or
If the new kernel
> +as nothing was saved. This is not backward compatible, as old kernel doesn't
as an old kernel doesn't
> +understand the new V2 'test_state'.
> +
> +Subsections
> +-----------
> +Another option is adding subsection to kstate_description. A subsection is
adding a subsection
> +additional kstate_description which linked to the main one:
an additional which is linked to the main one:
> +
> +struct kstate_description test_state_v2 = {
> + .name = "test_v2",
> + .id = KSTATE_TEST_ID_V2,
> + .fields = (const struct kstate_field[]) {
> + KSTATE_BASE_TYPE(i, struct kstate_test_data, int),
> + KSTATE_END_OF_LIST()
> + },
> +};
> +
> +struct kstate_description test_state = {
> + ......
> + .subsections = (const struct kstate_description *[]){
> + &test_state_v2,
> + NULL
> + },
> +};
> +
> +
> +Subsection must have a unique ->id. If the receiving side finds a subsection
A subsection
> +with unknown id it will be ignored. This make subsections suitable for backward
> +compatible changes (migrate from N+1 to N kernel) assuming old kernel is ok without
assuming the old kernel
> +information in subsection.
in the subsection.
--
~Randy
prev parent reply other threads:[~2025-09-10 1:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 20:14 [PATCH v3 0/7] KSTATE: [de]serialization framework for KHO Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 1/7] kho: move fdt setup in separate helper Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 2/7] kho: move scratch memory " Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 3/7] kstate: Add KSTATE - [de]serialization framework for KHO Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 4/7] kho: replace KHO FDT with kstate metadata Andrey Ryabinin
2025-09-10 16:50 ` Rob Herring
2025-09-11 16:54 ` Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 5/7] kstate, test: add test module for testing kstate subsystem Andrey Ryabinin
2025-09-10 0:33 ` Randy Dunlap
2025-09-11 17:00 ` Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 6/7] mm/memblock: Use KSTATE instead of kho to preserve preserved_mem_table Andrey Ryabinin
2025-09-15 11:47 ` Jason Gunthorpe
2025-09-18 19:00 ` Andrey Ryabinin
2025-09-18 23:14 ` Jason Gunthorpe
2025-09-09 20:14 ` [PATCH v3 7/7] Documentation, kstate: Add KSTATE documentation Andrey Ryabinin
2025-09-10 0:53 ` Bagas Sanjaya
2025-09-11 17:07 ` Andrey Ryabinin
2025-09-10 1:00 ` Randy Dunlap [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4e230009-ed70-4260-ba61-170ddab17a80@infradead.org \
--to=rdunlap@infradead.org \
--cc=Ashish.Kalra@amd.com \
--cc=akpm@linux-foundation.org \
--cc=arbn@yandex-team.com \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=changyuanl@google.com \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=dmatlack@google.com \
--cc=graf@amazon.com \
--cc=hpa@zytor.com \
--cc=jgg@nvidia.com \
--cc=jgowans@amazon.com \
--cc=kexec@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=ptyadav@amazon.de \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=tglx@linutronix.de \
--cc=witu@nvidia.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox