liveupdate: Move to feature flags for LUO and memfd ABI compatibility
Subsystems (7)
cover liveupdate: Move to feature flags for LUO and memfd ABI compatibility
We're including maintainers from all subsystems that currently is or will be expected to participate in live update to ensure alignment on the path forward for compatibility.
Currently, Live Update Orchestrator (LUO) and its file handlers rely on monolithic compatibility strings (such as "luo-v5" and "memfd-v1") to validate ABI compatibility across kexec live updates. Any modification to serialized structures requires bumping the version string, which strictly breaks compatibility between adjacent kernels even when changes are additive, backwards-compatible, or optional.
This RFC series transitions LUO and subsystem file handlers to use granular feature bitmasks instead of compatibility strings. We replace the compatibility string with a header structure that includes some reserved space to define the features that are included after the feature.
We include 3 bits of data for each feature: supported, active, and required. When the supported bit is set in the next kernel, the previous kernel can serialize the feature and pass it to the next kernel. When the active bit is set, it means the previous occurred and the data for that feature is valid. When the required bit is set, it means that the next kernel must have the associated supported bit in order to be compatible.
If a feature is required in that it cannot live update to a kernel that does not support the feature, it is expected that the feature not be active or required initially. This allows for an intermediate upgrade path.
Overview of Changes:
1. Define feature header and migrate luo_ser (Patch 1):
- Introudce the feature header with the supported, active, and required bits.
- Replace the luo compatibility string with this new header.
- Validate the preserved size is at least the size of the header. This breaks compatibility with the old way.
2. Export feature header information to vmlinux (Patch 2):
- Adds a .liveupdate_features section in vmlinux containing
- Adds helper macros to export feature information for a given subsystem
- Export luo's feature information
3. Memfd Handler Migration (Patch 3):
- Migrate memfd to use the feature header instead of compatibility strings
Logan Odell (3):
luo: Move to feature flags instead of compatibility strings
luo: Export feature support to vmlinux section
luo: memfd: Move to feature flags instead of compatibility strings
include/asm-generic/vmlinux.lds.h | 12 ++++ include/linux/kho/abi/luo.h | 114 +++++++++++++++++++++++++----- include/linux/kho/abi/memfd.h | 41 +++++++---- include/linux/liveupdate.h | 22 ++++-- kernel/liveupdate/luo_core.c | 60 ++++++++++++---- kernel/liveupdate/luo_file.c | 28 ++++---- kernel/liveupdate/luo_flb.c | 2 +- lib/tests/liveupdate.c | 2 +- mm/memfd_luo.c | 40 ++++++++--- 9 files changed, 246 insertions(+), 75 deletions(-)
Signature · 1 line
2.55.0.979.g7e5102b832-goog
RFC PATCH 1/3 luo: Move to feature flags instead of compatibility strings
Define a 128 byte header that can be used by all live update serialized structures. In this header, we reserve room for 64 features with supported, active, and required bits. Update the top level luo struct to use this instead of compatibility strings. Previous versions of the struct had smaller sizes, so add a minimum size check to avoid collisions with older kernels.
--- include/linux/kho/abi/luo.h | 74 +++++++++++++++++++++++++++++------- kernel/liveupdate/luo_core.c | 44 +++++++++++++-------- 2 files changed, 90 insertions(+), 28 deletions(-)
include/linux/kho/abi/luo.h +61 -13
@@ -13,15 +13,17 @@* kernel. The ABI is built upon the Kexec HandOver framework and registers * the central `struct luo_ser` via the KHO raw subtree API. * -* This interface is a contract. Any modification to the structure fields, -* compatible strings, or the layout of the `__packed` serialization -* structures defined here constitutes a breaking change. Such changes require -* incrementing the version number in the relevant `_COMPATIBLE` string to -* prevent a new kernel from misinterpreting data from an old kernel. +* This interface is a contract. To ensure the stability of moving between +* kernel versions, any changes to the structures should only be additive +* and should utilize the feature flags to denote the supported, active, and +* required status of the feature. +* +* Features that are entirely optional can be added with the supported and +* active flags both asserted, and the required flag cleared. Features that +* require that the next kernel supports the feature should only be added as +* supported to allow compatible transition kernels. At a later time, the +* active and required flag should be asserted. * -* Changes are allowed provided the compatibility version is incremented; -* however, backward/forward compatibility is only guaranteed for kernels -* supporting the same ABI version. * * KHO Structure Overview: * The entire LUO state is encapsulated within a single KHO entry named "LUO".
@@ -30,7 +32,7 @@* Serialization Structures: * - struct luo_ser: * The central ABI structure that contains the overall state of the LUO. -* It includes the compatibility string, the liveupdate-number, and pointers +* It includes the feature flags, the liveupdate-number, and pointers * to sessions and FLBs. * * - struct luo_session_ser:
@@ -58,19 +60,65 @@#define _LINUX_KHO_ABI_LUO_H#include <linux/align.h> +#include <linux/bits.h> #include <linux/kho/abi/block.h> #include <uapi/linux/liveupdate.h> +/** +* struct luo_feature_hdr - Feature negotiation and versioning header. +* @supp: Bitmask of features supported by the producing subsystem. +* @req: Bitmask of features required for safe deserialization by the +* receiving subsystem. +* @active: Bitmask of features actually active/used in the serialized payload. +* @reserved: Reserved for future use. +* +* This header can be embedded at the beginning of any serialized structure to +* provide forward and backward compatibility via feature negotiation across +* live update. +*/ +struct luo_feature_hdr { +u64 supp; +u64 req; +u64 active; +u64 reserved[13 ]; +} __packed; + +#define LUO_FEATURE_ACTIVE (s, f) \ + do { \ + (s)->features.supp |= (u64)(f); \ + (s)->features.active |= (u64)(f); \ + } while (0) +#define LUO_FEATURE_SUPPORTED (s, f) ((s)->features.supp |= (u64)(f)) +#define LUO_FEATURE_REQUIRED (s, f) ((s)->features.req |= (u64)(f)) +#define LUO_FEATURE_IS_ACTIVE (s, f) (!!((s)->features.active & (u64)(f))) +#define LUO_FEATURE_IS_SUPPORTED (s, f) (!!((s)->features.supp & (u64)(f))) +#define LUO_FEATURE_IS_REQUIRED (s, f) (!!((s)->features.req & (u64)(f))) +/* * The LUO state is registered under this KHO entry name. */ #define LUO_KHO_ENTRY_NAME "LUO" -#define LUO_ABI_COMPATIBLE "luo-v5" -#define LUO_ABI_COMPAT_LEN ALIGN(sizeof(LUO_ABI_COMPATIBLE), 8) + +/* +* Bits associated with the luo_feature_hdr values. +*/ +#define LUO_FEATURE_NUMBER BIT_ULL(0) +#define LUO_FEATURE_SESSIONS BIT_ULL(1) +#define LUO_FEATURE_FLBS BIT_ULL(2) + +#define LUO_CORE_FEATURES_SUPP (LUO_FEATURE_NUMBER | \ + LUO_FEATURE_SESSIONS | \ + LUO_FEATURE_FLBS) +#define LUO_CORE_FEATURES_REQ (LUO_FEATURE_NUMBER | \ + LUO_FEATURE_SESSIONS | \ + LUO_FEATURE_FLBS) +#define LUO_CORE_FEATURES_ACTIVE (LUO_FEATURE_NUMBER | \ + LUO_FEATURE_SESSIONS | \ + LUO_FEATURE_FLBS)/** * struct luo_ser - Centralized LUO ABI header. -* @compatible: Compatibility string identifying the LUO ABI version. +* @features: Bit mask of supported and active features. * @liveupdate_num: A counter tracking the number of successful live updates. * @sessions_pa: Physical address of the first session block header. * @flbs_pa: Physical address of the FLB header.
@@ -78,7 +126,7 @@* This structure is the root of all preserved LUO state. */ struct luo_ser { -char compatible[LUO_ABI_COMPAT_LEN ]; +struct luo_feature_hdr features;u64 liveupdate_num;u64 sessions_pa;u64 flbs_pa;
kernel/liveupdate/luo_core.c +29 -15
62 lines not on this page · raw message
Signature · 1 line
2.55.0.979.g7e5102b832-goog
[email protected]
AI reviewRe: [RFC PATCH 1/3] luo: Move to feature flags instead of compatibility strings
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing payload length validation before accessing feature-dependent fields in `luo_ser`, leading…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing payload length validation before accessing feature-dependent fields in luo_ser, leading to out-of-bounds reads. --
commit 8e63def24ae09c6e2674a2bd48e32ef12916dd48
Author: Logan Odell <[email protected]>
luo: Move to feature flags instead of compatibility strings
This commit replaces the compatibility string check with a 128-byte feature header in the live update serialization structure. It introduces flags for supported, required, and active features to allow for more flexible structure evolution.
kernel/liveupdate/luo_core.c static int __init luo_early_startup(void) · line 112
Quoted 13 lines
kernel/liveupdate/luo_core.c +3
-3@@ -107,26 +107,37 @@ static int __init luo_early_startup(void)return 0 ; } -if (len <sizeof (*luo_ser)) { -pr_err ("LUO state is too small (%zu < %zu)\n" , len,sizeof (*luo_ser)); -return -EINVAL ; + luo_ser =phys_to_virt (luo_ser_phys); + +if (len <sizeof (struct luo_feature_hdr )) {
[Severity: High]
In luo_early_startup() in kernel/liveupdate/luo_core.c, does this code sufficiently validate the payload length?
Since len is only checked against the size of struct luo_feature_hdr, it seems the check for the full struct luo_ser size has been removed.
Quoted 5 lines
kernel/liveupdate/luo_core.c +4
-0+pr_err ("LUO state is too small (%zu < %zu)\n" , + len,sizeof (struct luo_feature_hdr )); + err = -EINVAL ; + goto out_free_ser; }
[ ... ]
kernel/liveupdate/luo_core.c static int __init luo_early_startup(void) · line 127
Quoted 2 lines
kernel/liveupdate/luo_core.c +2
-0+if (LUO_FEATURE_IS_ACTIVE (luo_ser,LUO_FEATURE_NUMBER )) { + luo_global.liveupdate_num = luo_ser->liveupdate_num;
[Severity: High]
Can this access memory out of bounds?
If the payload length from KHO is large enough to pass the header check but smaller than the full structure size, this will read luo_ser->liveupdate_num beyond the validated length.
kernel/liveupdate/luo_core.c static int __init luo_early_startup(void) · line 134
Quoted 11 lines
kernel/liveupdate/luo_core.c +5
-4+pr_info ("Retrieved live update data, liveupdate number: %lld\n" , + luo_global.liveupdate_num); + } - err =luo_session_setup_incoming (luo_ser->sessions_pa); -if (err) - goto out_free_ser; -luo_flb_setup_incoming (luo_ser->flbs_pa); +if (LUO_FEATURE_IS_ACTIVE (luo_ser,LUO_FEATURE_SESSIONS )) { + err =luo_session_setup_incoming (luo_ser->sessions_pa);
[Severity: High]
Can this result in the use of uninitialized or garbage data?
If len does not cover the sessions_pa field, reading it could yield a garbage physical address that luo_session_setup_incoming() might then dereference, leading to a panic or state corruption during boot.
kernel/liveupdate/luo_core.c static int __init luo_early_startup(void) · line 140
Quoted 6 lines
kernel/liveupdate/luo_core.c +6
-0+if (err) + goto out_free_ser; + } + +if (LUO_FEATURE_IS_ACTIVE (luo_ser,LUO_FEATURE_FLBS )) +luo_flb_setup_incoming (luo_ser->flbs_pa);
[Severity: High]
Does this code pass a garbage address to luo_flb_setup_incoming()?
Accessing luo_ser->flbs_pa could read beyond the payload if len is smaller than the full struct luo_ser size.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Pratyush Yadav
maintainerRe: [RFC PATCH 1/3] luo: Move to feature flags instead of compatibility strings
In reply to Logan OdellHi Logan,
Quoted 55 lines · Logan Odell
Define a 128 byte header that can be used by all live update serialized structures. In this header, we reserve room for 64 features with supported, active, and required bits. Update the top level luo struct to use this instead of compatibility strings. Previous versions of the struct had smaller sizes, so add a minimum size check to avoid collisions with older kernels.
Signed-off-by Logan Odell <[email protected]>--- include/linux/kho/abi/luo.h | 74 +++++++++++++++++++++++++++++------- kernel/liveupdate/luo_core.c | 44 +++++++++++++-------- 2 files changed, 90 insertions(+), 28 deletions(-)include/linux/kho/abi/luo.h +11
-9@@ -13,15 +13,17 @@* kernel. The ABI is built upon the Kexec HandOver framework and registers * the central `struct luo_ser` via the KHO raw subtree API. * -* This interface is a contract. Any modification to the structure fields, -* compatible strings, or the layout of the `__packed` serialization -* structures defined here constitutes a breaking change. Such changes require -* incrementing the version number in the relevant `_COMPATIBLE` string to -* prevent a new kernel from misinterpreting data from an old kernel. +* This interface is a contract. To ensure the stability of moving between +* kernel versions, any changes to the structures should only be additive +* and should utilize the feature flags to denote the supported, active, and +* required status of the feature. +* +* Features that are entirely optional can be added with the supported and +* active flags both asserted, and the required flag cleared. Features that +* require that the next kernel supports the feature should only be added as +* supported to allow compatible transition kernels. At a later time, the +* active and required flag should be asserted. * -* Changes are allowed provided the compatibility version is incremented; -* however, backward/forward compatibility is only guaranteed for kernels -* supporting the same ABI version. * * KHO Structure Overview: * The entire LUO state is encapsulated within a single KHO entry named "LUO". @@ -30,7 +32,7 @@* Serialization Structures: * - struct luo_ser: * The central ABI structure that contains the overall state of the LUO. -* It includes the compatibility string, the liveupdate-number, and pointers +* It includes the feature flags, the liveupdate-number, and pointers * to sessions and FLBs. * * - struct luo_session_ser: @@ -58,19 +60,65 @@#define _LINUX_KHO_ABI_LUO_H
include/linux/kho/abi/luo.h line 71
Quoted 10 lines
include/linux/kho/abi/luo.h +6
-0#include <linux/align.h> +#include <linux/bits.h> #include <linux/kho/abi/block.h> #include <uapi/linux/liveupdate.h> +/** +* struct luo_feature_hdr - Feature negotiation and versioning header. +* @supp: Bitmask of features supported by the producing subsystem. +* @req: Bitmask of features required for safe deserialization by the +* receiving subsystem.
I think you are mixing two things here: description of the payload and description of the file handler capability.
The payload that is handed over via KHO should have the active and required bitmasks only. It doesn't need the supported bitmask, because it doesn't matter what the handler that produced the payload supports. It only matters what fields it populated and which ones are mandatory to understand.
Similarly, the description of the file handler can't really describe "active". Because the capabilities are static and the active bits will depend on a specific file.
So I reckon we should separate these two. These should be the same bits of course, but expressed in two ways in two different places.
include/linux/kho/abi/luo.h line 83
Quoted 12 lines
include/linux/kho/abi/luo.h +12
-0+* @active: Bitmask of features actually active/used in the serialized payload. +* @reserved: Reserved for future use. +* +* This header can be embedded at the beginning of any serialized structure to +* provide forward and backward compatibility via feature negotiation across +* live update. +*/ +struct luo_feature_hdr { +u64 supp; +u64 req; +u64 active; +u64 reserved[13 ];
How do you plan to ever use this? Say I want to extend my bitmaps so I do:
struct luo_feature_hdr {
u64 supp;
u64 req;
u64 active;
u64 supp2;
u64 req2;
u64 active2;
u64 reserved[10];But when I go back to a kernel that doesn't know about supp2, req2, etc., how does it know how to interpret these? How does it know what the values mean?
Is your goal only to be able to extend the three types of flags we have? If so, perhaps something like "if bit 63 is set, the flags continue to the next u64"? It is certainly harder for the parser, but seems to at least be extensible. What do you think?
Quoted 16 lines
include/linux/kho/abi/luo.h +13
-0+} __packed; + +#define LUO_FEATURE_ACTIVE (s, f) \ + do { \ + (s)->features.supp |= (u64)(f); \ + (s)->features.active |= (u64)(f); \ + } while (0) +#define LUO_FEATURE_SUPPORTED (s, f) ((s)->features.supp |= (u64)(f)) +#define LUO_FEATURE_REQUIRED (s, f) ((s)->features.req |= (u64)(f)) +#define LUO_FEATURE_IS_ACTIVE (s, f) (!!((s)->features.active & (u64)(f))) +#define LUO_FEATURE_IS_SUPPORTED (s, f) (!!((s)->features.supp & (u64)(f))) +#define LUO_FEATURE_IS_REQUIRED (s, f) (!!((s)->features.req & (u64)(f))) +/* * The LUO state is registered under this KHO entry name. */
include/linux/kho/abi/luo.h line 107
Quoted 10 lines
include/linux/kho/abi/luo.h +7
-2#define LUO_KHO_ENTRY_NAME "LUO" -#define LUO_ABI_COMPATIBLE "luo-v5" -#define LUO_ABI_COMPAT_LEN ALIGN(sizeof(LUO_ABI_COMPATIBLE), 8) + +/* +* Bits associated with the luo_feature_hdr values. +*/ +#define LUO_FEATURE_NUMBER BIT_ULL(0) +#define LUO_FEATURE_SESSIONS BIT_ULL(1) +#define LUO_FEATURE_FLBS BIT_ULL(2)
Nit: please give the flags full documentation on their semantics.
Quoted 19 lines
include/linux/kho/abi/luo.h +11
-1+ +#define LUO_CORE_FEATURES_SUPP (LUO_FEATURE_NUMBER | \ + LUO_FEATURE_SESSIONS | \ + LUO_FEATURE_FLBS) +#define LUO_CORE_FEATURES_REQ (LUO_FEATURE_NUMBER | \ + LUO_FEATURE_SESSIONS | \ + LUO_FEATURE_FLBS) +#define LUO_CORE_FEATURES_ACTIVE (LUO_FEATURE_NUMBER | \ + LUO_FEATURE_SESSIONS | \ + LUO_FEATURE_FLBS)/** * struct luo_ser - Centralized LUO ABI header. -* @compatible: Compatibility string identifying the LUO ABI version. +* @features: Bit mask of supported and active features. * @liveupdate_num: A counter tracking the number of successful live updates. * @sessions_pa: Physical address of the first session block header. * @flbs_pa: Physical address of the FLB header.
include/linux/kho/abi/luo.h line 129
Quoted 5 lines
include/linux/kho/abi/luo.h +1
-1@@ -78,7 +126,7 @@* This structure is the root of all preserved LUO state. */ struct luo_ser { -char compatible[LUO_ABI_COMPAT_LEN ]; +struct luo_feature_hdr features;
Do we still need compatible here? How will we ever do breaking changes if we really need to?
Quoted 71 lines
include/linux/kho/abi/luo.h +0
-0u64 liveupdate_num;u64 sessions_pa;u64 flbs_pa;kernel/liveupdate/luo_core.c +29
-15@@ -107,26 +107,37 @@ static int __init luo_early_startup(void)return 0 ; } -if (len <sizeof (*luo_ser)) { -pr_err ("LUO state is too small (%zu < %zu)\n" , len,sizeof (*luo_ser)); -return -EINVAL ; + luo_ser =phys_to_virt (luo_ser_phys); + +if (len <sizeof (struct luo_feature_hdr )) { +pr_err ("LUO state is too small (%zu < %zu)\n" , + len,sizeof (struct luo_feature_hdr )); + err = -EINVAL ; + goto out_free_ser; } - luo_ser =phys_to_virt (luo_ser_phys); -if (strncmp (luo_ser->compatible,LUO_ABI_COMPATIBLE ,LUO_ABI_COMPAT_LEN )) { -pr_err ("LUO state is incompatible with '%s'\n" ,LUO_ABI_COMPATIBLE ); -return -EINVAL ; +if (luo_ser->features.req & ~LUO_CORE_FEATURES_SUPP ) { +pr_err ("Unsupported required LUO feature (req: 0x%llx, supp: 0x%llx)\n" , + luo_ser->features.req, (u64 )LUO_CORE_FEATURES_SUPP ); + err = -EOPNOTSUPP ; + goto out_free_ser; } - luo_global.liveupdate_num = luo_ser->liveupdate_num; -pr_info ("Retrieved live update data, liveupdate number: %lld\n" , - luo_global.liveupdate_num); +if (LUO_FEATURE_IS_ACTIVE (luo_ser,LUO_FEATURE_NUMBER )) { + luo_global.liveupdate_num = luo_ser->liveupdate_num; +pr_info ("Retrieved live update data, liveupdate number: %lld\n" , + luo_global.liveupdate_num); + } - err =luo_session_setup_incoming (luo_ser->sessions_pa); -if (err) - goto out_free_ser; -luo_flb_setup_incoming (luo_ser->flbs_pa); +if (LUO_FEATURE_IS_ACTIVE (luo_ser,LUO_FEATURE_SESSIONS )) { + err =luo_session_setup_incoming (luo_ser->sessions_pa); +if (err) + goto out_free_ser; + } + +if (LUO_FEATURE_IS_ACTIVE (luo_ser,LUO_FEATURE_FLBS )) +luo_flb_setup_incoming (luo_ser->flbs_pa); err =0 ;@@ -162,7 +173,10 @@ static int __init luo_state_setup(void)return PTR_ERR (luo_ser); } -strscpy (luo_ser->compatible,LUO_ABI_COMPATIBLE ,sizeof (luo_ser->compatible)); + luo_ser->features.supp =LUO_CORE_FEATURES_SUPP ; + luo_ser->features.req =LUO_CORE_FEATURES_REQ ; + luo_ser->features.active =LUO_CORE_FEATURES_ACTIVE ; + luo_ser->liveupdate_num = luo_global.liveupdate_num +1 ;luo_session_setup_outgoing (&luo_ser->sessions_pa);
Signature · 2 lines
Regards, Pratyush Yadav
Re: [RFC PATCH 1/3] luo: Move to feature flags instead of compatibility strings
Quoted 101 lines · Pratyush Yadav
Hi Logan,
Quoted 55 lines · Logan Odell
Define a 128 byte header that can be used by all live update serialized structures. In this header, we reserve room for 64 features with supported, active, and required bits. Update the top level luo struct to use this instead of compatibility strings. Previous versions of the struct had smaller sizes, so add a minimum size check to avoid collisions with older kernels.
Signed-off-by Logan Odell <[email protected]>--- include/linux/kho/abi/luo.h | 74 +++++++++++++++++++++++++++++------- kernel/liveupdate/luo_core.c | 44 +++++++++++++-------- 2 files changed, 90 insertions(+), 28 deletions(-)include/linux/kho/abi/luo.h +11
-9@@ -13,15 +13,17 @@* kernel. The ABI is built upon the Kexec HandOver framework and registers * the central `struct luo_ser` via the KHO raw subtree API. * -* This interface is a contract. Any modification to the structure fields, -* compatible strings, or the layout of the `__packed` serialization -* structures defined here constitutes a breaking change. Such changes require -* incrementing the version number in the relevant `_COMPATIBLE` string to -* prevent a new kernel from misinterpreting data from an old kernel. +* This interface is a contract. To ensure the stability of moving between +* kernel versions, any changes to the structures should only be additive +* and should utilize the feature flags to denote the supported, active, and +* required status of the feature. +* +* Features that are entirely optional can be added with the supported and +* active flags both asserted, and the required flag cleared. Features that +* require that the next kernel supports the feature should only be added as +* supported to allow compatible transition kernels. At a later time, the +* active and required flag should be asserted. * -* Changes are allowed provided the compatibility version is incremented; -* however, backward/forward compatibility is only guaranteed for kernels -* supporting the same ABI version. * * KHO Structure Overview: * The entire LUO state is encapsulated within a single KHO entry named "LUO". @@ -30,7 +32,7 @@* Serialization Structures: * - struct luo_ser: * The central ABI structure that contains the overall state of the LUO. -* It includes the compatibility string, the liveupdate-number, and pointers +* It includes the feature flags, the liveupdate-number, and pointers * to sessions and FLBs. * * - struct luo_session_ser: @@ -58,19 +60,65 @@#define _LINUX_KHO_ABI_LUO_Hinclude/linux/kho/abi/luo.h line 71
Quoted 10 lines
include/linux/kho/abi/luo.h +6
-0#include <linux/align.h> +#include <linux/bits.h> #include <linux/kho/abi/block.h> #include <uapi/linux/liveupdate.h> +/** +* struct luo_feature_hdr - Feature negotiation and versioning header. +* @supp: Bitmask of features supported by the producing subsystem. +* @req: Bitmask of features required for safe deserialization by the +* receiving subsystem. I think you are mixing two things here: description of the payload and description of the file handler capability.
The payload that is handed over via KHO should have the active and required bitmasks only. It doesn't need the supported bitmask, because it doesn't matter what the handler that produced the payload supports. It only matters what fields it populated and which ones are mandatory to understand.
Similarly, the description of the file handler can't really describe "active". Because the capabilities are static and the active bits will depend on a specific file.
So I reckon we should separate these two. These should be the same bits of course, but expressed in two ways in two different places.
include/linux/kho/abi/luo.h line 83
Quoted 12 lines
include/linux/kho/abi/luo.h +12
-0+* @active: Bitmask of features actually active/used in the serialized payload. +* @reserved: Reserved for future use. +* +* This header can be embedded at the beginning of any serialized structure to +* provide forward and backward compatibility via feature negotiation across +* live update. +*/ +struct luo_feature_hdr { +u64 supp; +u64 req; +u64 active; +u64 reserved[13 ];How do you plan to ever use this? Say I want to extend my bitmaps so I do:
Quoted 8 lines
struct luo_feature_hdr {
u64 supp;
u64 req;
u64 active;
u64 supp2;
u64 req2;
u64 active2;
u64 reserved[10];I thinking this is too spreaded.
We can do somthing like:
struct ABI {
u64 size;
u64 flags;
u64 flags2;
}where flags is extended to flags2 if flags MSB bits is 11.
and each flags is formatted like 0b 00 01 11 00 11 10 11 11 00 00 11 ...
each pair represents 0b 1 (required) 1 (active)
Getting the details of the feature is just bit manipulation, so proper macro definition similar to the one this patch has implemented.
~Tarun
Quoted 142 lines
But when I go back to a kernel that doesn't know about supp2, req2, etc., how does it know how to interpret these? How does it know what the values mean?
Is your goal only to be able to extend the three types of flags we have? If so, perhaps something like "if bit 63 is set, the flags continue to the next u64"? It is certainly harder for the parser, but seems to at least be extensible. What do you think?
Quoted 16 lines
include/linux/kho/abi/luo.h +13
-0+} __packed; + +#define LUO_FEATURE_ACTIVE (s, f) \ + do { \ + (s)->features.supp |= (u64)(f); \ + (s)->features.active |= (u64)(f); \ + } while (0) +#define LUO_FEATURE_SUPPORTED (s, f) ((s)->features.supp |= (u64)(f)) +#define LUO_FEATURE_REQUIRED (s, f) ((s)->features.req |= (u64)(f)) +#define LUO_FEATURE_IS_ACTIVE (s, f) (!!((s)->features.active & (u64)(f))) +#define LUO_FEATURE_IS_SUPPORTED (s, f) (!!((s)->features.supp & (u64)(f))) +#define LUO_FEATURE_IS_REQUIRED (s, f) (!!((s)->features.req & (u64)(f))) +/* * The LUO state is registered under this KHO entry name. */ include/linux/kho/abi/luo.h line 107
Quoted 10 lines
include/linux/kho/abi/luo.h +7
-2#define LUO_KHO_ENTRY_NAME "LUO" -#define LUO_ABI_COMPATIBLE "luo-v5" -#define LUO_ABI_COMPAT_LEN ALIGN(sizeof(LUO_ABI_COMPATIBLE), 8) + +/* +* Bits associated with the luo_feature_hdr values. +*/ +#define LUO_FEATURE_NUMBER BIT_ULL(0) +#define LUO_FEATURE_SESSIONS BIT_ULL(1) +#define LUO_FEATURE_FLBS BIT_ULL(2)Nit: please give the flags full documentation on their semantics.
Quoted 19 lines
include/linux/kho/abi/luo.h +11
-1+ +#define LUO_CORE_FEATURES_SUPP (LUO_FEATURE_NUMBER | \ + LUO_FEATURE_SESSIONS | \ + LUO_FEATURE_FLBS) +#define LUO_CORE_FEATURES_REQ (LUO_FEATURE_NUMBER | \ + LUO_FEATURE_SESSIONS | \ + LUO_FEATURE_FLBS) +#define LUO_CORE_FEATURES_ACTIVE (LUO_FEATURE_NUMBER | \ + LUO_FEATURE_SESSIONS | \ + LUO_FEATURE_FLBS)/** * struct luo_ser - Centralized LUO ABI header. -* @compatible: Compatibility string identifying the LUO ABI version. +* @features: Bit mask of supported and active features. * @liveupdate_num: A counter tracking the number of successful live updates. * @sessions_pa: Physical address of the first session block header. * @flbs_pa: Physical address of the FLB header. include/linux/kho/abi/luo.h line 129
Quoted 5 lines
include/linux/kho/abi/luo.h +1
-1@@ -78,7 +126,7 @@* This structure is the root of all preserved LUO state. */ struct luo_ser { -char compatible[LUO_ABI_COMPAT_LEN ]; +struct luo_feature_hdr features;Do we still need compatible here? How will we ever do breaking changes if we really need to?
Quoted 71 lines
include/linux/kho/abi/luo.h +0
-0u64 liveupdate_num;u64 sessions_pa;u64 flbs_pa;kernel/liveupdate/luo_core.c +29
-15@@ -107,26 +107,37 @@ static int __init luo_early_startup(void)return 0 ; } -if (len <sizeof (*luo_ser)) { -pr_err ("LUO state is too small (%zu < %zu)\n" , len,sizeof (*luo_ser)); -return -EINVAL ; + luo_ser =phys_to_virt (luo_ser_phys); + +if (len <sizeof (struct luo_feature_hdr )) { +pr_err ("LUO state is too small (%zu < %zu)\n" , + len,sizeof (struct luo_feature_hdr )); + err = -EINVAL ; + goto out_free_ser; } - luo_ser =phys_to_virt (luo_ser_phys); -if (strncmp (luo_ser->compatible,LUO_ABI_COMPATIBLE ,LUO_ABI_COMPAT_LEN )) { -pr_err ("LUO state is incompatible with '%s'\n" ,LUO_ABI_COMPATIBLE ); -return -EINVAL ; +if (luo_ser->features.req & ~LUO_CORE_FEATURES_SUPP ) { +pr_err ("Unsupported required LUO feature (req: 0x%llx, supp: 0x%llx)\n" , + luo_ser->features.req, (u64 )LUO_CORE_FEATURES_SUPP ); + err = -EOPNOTSUPP ; + goto out_free_ser; } - luo_global.liveupdate_num = luo_ser->liveupdate_num; -pr_info ("Retrieved live update data, liveupdate number: %lld\n" , - luo_global.liveupdate_num); +if (LUO_FEATURE_IS_ACTIVE (luo_ser,LUO_FEATURE_NUMBER )) { + luo_global.liveupdate_num = luo_ser->liveupdate_num; +pr_info ("Retrieved live update data, liveupdate number: %lld\n" , + luo_global.liveupdate_num); + } - err =luo_session_setup_incoming (luo_ser->sessions_pa); -if (err) - goto out_free_ser; -luo_flb_setup_incoming (luo_ser->flbs_pa); +if (LUO_FEATURE_IS_ACTIVE (luo_ser,LUO_FEATURE_SESSIONS )) { + err =luo_session_setup_incoming (luo_ser->sessions_pa); +if (err) + goto out_free_ser; + } + +if (LUO_FEATURE_IS_ACTIVE (luo_ser,LUO_FEATURE_FLBS )) +luo_flb_setup_incoming (luo_ser->flbs_pa); err =0 ;@@ -162,7 +173,10 @@ static int __init luo_state_setup(void)return PTR_ERR (luo_ser); } -strscpy (luo_ser->compatible,LUO_ABI_COMPATIBLE ,sizeof (luo_ser->compatible)); + luo_ser->features.supp =LUO_CORE_FEATURES_SUPP ; + luo_ser->features.req =LUO_CORE_FEATURES_REQ ; + luo_ser->features.active =LUO_CORE_FEATURES_ACTIVE ; + luo_ser->liveupdate_num = luo_global.liveupdate_num +1 ;luo_session_setup_outgoing (&luo_ser->sessions_pa);Signature · 2 lines
Regards, Pratyush Yadav
RFC PATCH 2/3 luo: Export feature support to vmlinux section
In reply to Logan OdellCreate a liveupdate_features section that contains the feature information for a given liveupdate component. Add the LUO component first. These can be compared between two kernels to determine live update compatibility. Features marked as required in the running kernel will need to have that feature marked as supported in the next kernel to be eligible for compatibility.
--- include/asm-generic/vmlinux.lds.h | 12 +++++++++++ include/linux/kho/abi/luo.h | 34 +++++++++++++++++++++++++++++++ include/linux/liveupdate.h | 12 +++++++++++ kernel/liveupdate/luo_core.c | 16 +++++++++++++++ 4 files changed, 74 insertions(+)
include/asm-generic/vmlinux.lds.h +12 -0
@@ -359,6 +359,17 @@#define THERMAL_TABLE (name)#endif +#ifdef CONFIG_LIVEUPDATE +#define LIVEUPDATE_FEATURES \ + . = ALIGN(8); \ + .liveupdate_features : AT(ADDR(.liveupdate_features) - LOAD_OFFSET) { \ + KEEP(*(.liveupdate_sec_hdr)) \ + KEEP(*(.liveupdate_features)) \ + } +#else +#define LIVEUPDATE_FEATURES +#endif +#define KERNEL_DTB () \ STRUCT_ALIGN(); \ __dtb_start = .; \
@@ -554,6 +565,7 @@RO_EXCEPTION_TABLE \ NOTES \BTF \ +LIVEUPDATE_FEATURES \ \ . = ALIGN((align)); \ __end_rodata = .;
include/linux/kho/abi/luo.h +34 -0
@@ -230,4 +230,38 @@ struct luo_flb_ser {#define LIVEUPDATE_TEST_FLB_COMPATIBLE (i) "liveupdate-test-flb-v" #i#endif +#define LIVEUPDATE_VER_HDR_MAGIC 0x4c565550/* 'LVUP' */ +#define LIVEUPDATE_VER_HDR_VER 1 + +/** +* struct liveupdate_ver_hdr - Header of vmlinux section with version lists +* @magic: Magic number ('LVUP'). +* @version: Version of the header format. +* +* This struct is the header for the vmlinux section ".liveupdate_features". The +* section contains the list of feature/version entries that the kernel supports. +*/ +struct liveupdate_ver_hdr { +u32 magic; +u32 version; +} __packed; + +/** +* struct liveupdate_feature_entry - Live update feature/version entry +* @name: Name of the subsystem or feature ("luo" for core). +* @feat_bytes: Number of bytes covered by supp, req, and active bitmaps (e.g. 8). +* @reserved: Reserved / padding for alignment. +* @supp: Bitmask of supported features. +* @req: Bitmask of required features. +* @active: Bitmask of active features. +*/ +struct liveupdate_feature_entry { +char name[LIVEUPDATE_HNDL_COMPAT_LENGTH ]; +u32 feat_bytes; +u32 reserved; +u64 supp; +u64 req; +u64 active; +} __packed; +#endif /* _LINUX_KHO_ABI_LUO_H */
include/linux/liveupdate.h +12 -0
@@ -229,6 +229,16 @@ struct liveupdate_flb {#ifdef CONFIG_LIVEUPDATE +#define LIVEUPDATE_FEATURE_ENTRY (_id, _name, _supp, _req, _active) \ + static const struct liveupdate_feature_entry __lu_feat_##_id \ + __used __section(".liveupdate_features") __aligned(8) = { \ + .name = _name, \ + .feat_bytes = sizeof(u64), \ + .supp = (_supp), \ + .req = (_req), \ + .active = (_active), \ + } +/* Return true if live update orchestrator is enabled */ bool liveupdate_enabled (void );
@@ -259,6 +269,8 @@ int liveupdate_get_token_outgoing(struct liveupdate_session *s,#else /* CONFIG_LIVEUPDATE */ +#define LIVEUPDATE_FEATURE_ENTRY (_id, _name, _supp, _req, _active) +static inline bool liveupdate_enabled (void ) {return false;
kernel/liveupdate/luo_core.c +16 -0
@@ -64,6 +64,22 @@#include "kexec_handover_internal.h" #include "luo_internal.h" +/* +* This is the header for the ".liveupdate_features" section in vmlinux. +* The linker makes sure that this header precedes the entries. +*/ +static const struct liveupdate_ver_hdr ver_hdr + __used __section(".liveupdate_sec_hdr") __aligned(8) = { + .magic = LIVEUPDATE_VER_HDR_MAGIC, + .version =LIVEUPDATE_VER_HDR_VER , +}; + +/* Core LUO features */ +LIVEUPDATE_FEATURE_ENTRY (luo_core,"luo" , +LUO_CORE_FEATURES_SUPP , +LUO_CORE_FEATURES_REQ , +LUO_CORE_FEATURES_ACTIVE ); + static struct { bool enabled; struct luo_ser *luo_ser_out;
Signature · 1 line
2.55.0.979.g7e5102b832-goog
[email protected]
AI reviewRe: [RFC PATCH 2/3] luo: Export feature support to vmlinux section
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
Create a
liveupdate_featuressection that contains the feature information for a given liveupdate component. Add the LUO component first. These can be compared between two kernels to determine live update compatibility. Features marked as required in the running kernel will need to have that feature marked as supported in the next kernel to be eligible for compatibility.Suggested-by Pratyush Yadav <[email protected]>Signed-off-by Logan Odell <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Pratyush Yadav
maintainerRe: [RFC PATCH 2/3] luo: Export feature support to vmlinux section
In reply to Logan OdellHi Logan,
Quoted 9 lines · Logan Odell
Create a
liveupdate_featuressection that contains the feature information for a given liveupdate component. Add the LUO component first. These can be compared between two kernels to determine live update compatibility. Features marked as required in the running kernel will need to have that feature marked as supported in the next kernel to be eligible for compatibility.Suggested-by Pratyush Yadav <[email protected]>Signed-off-by Logan Odell <[email protected]>
I was thinking about this a bit more. We don't really ship the vmlinux directly. On x86 it is a PE/COFF image, on arm64 the Image format strips ELF information and is a raw binary file.
So this information would not be accessible to the kexec loader/luod. So perhaps as part of the build we parse the section and output a file with the versions? And then it can be packaged with the likes of System.map for example?
Quoted 49 lines
--- include/asm-generic/vmlinux.lds.h | 12 +++++++++++ include/linux/kho/abi/luo.h | 34 +++++++++++++++++++++++++++++++ include/linux/liveupdate.h | 12 +++++++++++ kernel/liveupdate/luo_core.c | 16 +++++++++++++++ 4 files changed, 74 insertions(+)include/asm-generic/vmlinux.lds.h +12
-0@@ -359,6 +359,17 @@#define THERMAL_TABLE (name)#endif +#ifdef CONFIG_LIVEUPDATE +#define LIVEUPDATE_FEATURES \ + . = ALIGN(8); \ + .liveupdate_features : AT(ADDR(.liveupdate_features) - LOAD_OFFSET) { \ + KEEP(*(.liveupdate_sec_hdr)) \ + KEEP(*(.liveupdate_features)) \ + } +#else +#define LIVEUPDATE_FEATURES +#endif +#define KERNEL_DTB () \ STRUCT_ALIGN(); \ __dtb_start = .; \@@ -554,6 +565,7 @@RO_EXCEPTION_TABLE \ NOTES \BTF \ +LIVEUPDATE_FEATURES \ \ . = ALIGN((align)); \ __end_rodata = .;include/linux/kho/abi/luo.h +4
-0@@ -230,4 +230,38 @@ struct luo_flb_ser {#define LIVEUPDATE_TEST_FLB_COMPATIBLE (i) "liveupdate-test-flb-v" #i#endif +#define LIVEUPDATE_VER_HDR_MAGIC 0x4c565550/* 'LVUP' */ +#define LIVEUPDATE_VER_HDR_VER 1 + +/**
include/linux/kho/abi/luo.h struct luo_flb_ser { · line 246
Quoted 10 lines
include/linux/kho/abi/luo.h +10
-0+* struct liveupdate_ver_hdr - Header of vmlinux section with version lists +* @magic: Magic number ('LVUP'). +* @version: Version of the header format. +* +* This struct is the header for the vmlinux section ".liveupdate_features". The +* section contains the list of feature/version entries that the kernel supports. +*/ +struct liveupdate_ver_hdr { +u32 magic; +u32 version;
Should we do feature flags along with the version to extend in backwards-compatible way?
include/linux/kho/abi/luo.h struct luo_flb_ser { · line 257
Quoted 11 lines
include/linux/kho/abi/luo.h +11
-0+} __packed; + +/** +* struct liveupdate_feature_entry - Live update feature/version entry +* @name: Name of the subsystem or feature ("luo" for core). +* @feat_bytes: Number of bytes covered by supp, req, and active bitmaps (e.g. 8). +* @reserved: Reserved / padding for alignment. +* @supp: Bitmask of supported features. +* @req: Bitmask of required features. +* @active: Bitmask of active features. +*/
How should we model FLB dependencies here? And how do we export FLB capabilities?
Quoted 67 lines
include/linux/kho/abi/luo.h +9
-0+struct liveupdate_feature_entry { +char name[LIVEUPDATE_HNDL_COMPAT_LENGTH ]; +u32 feat_bytes; +u32 reserved; +u64 supp; +u64 req; +u64 active; +} __packed; +#endif /* _LINUX_KHO_ABI_LUO_H */ include/linux/liveupdate.h +12
-0@@ -229,6 +229,16 @@ struct liveupdate_flb {#ifdef CONFIG_LIVEUPDATE +#define LIVEUPDATE_FEATURE_ENTRY (_id, _name, _supp, _req, _active) \ + static const struct liveupdate_feature_entry __lu_feat_##_id \ + __used __section(".liveupdate_features") __aligned(8) = { \ + .name = _name, \ + .feat_bytes = sizeof(u64), \ + .supp = (_supp), \ + .req = (_req), \ + .active = (_active), \ + } +/* Return true if live update orchestrator is enabled */ bool liveupdate_enabled (void );@@ -259,6 +269,8 @@ int liveupdate_get_token_outgoing(struct liveupdate_session *s,#else /* CONFIG_LIVEUPDATE */ +#define LIVEUPDATE_FEATURE_ENTRY (_id, _name, _supp, _req, _active) +static inline bool liveupdate_enabled (void ) {return false;kernel/liveupdate/luo_core.c +16
-0@@ -64,6 +64,22 @@#include "kexec_handover_internal.h" #include "luo_internal.h" +/* +* This is the header for the ".liveupdate_features" section in vmlinux. +* The linker makes sure that this header precedes the entries. +*/ +static const struct liveupdate_ver_hdr ver_hdr + __used __section(".liveupdate_sec_hdr") __aligned(8) = { + .magic = LIVEUPDATE_VER_HDR_MAGIC, + .version =LIVEUPDATE_VER_HDR_VER , +}; + +/* Core LUO features */ +LIVEUPDATE_FEATURE_ENTRY (luo_core,"luo" , +LUO_CORE_FEATURES_SUPP , +LUO_CORE_FEATURES_REQ , +LUO_CORE_FEATURES_ACTIVE ); + static struct { bool enabled; struct luo_ser *luo_ser_out;
Signature · 2 lines
Regards, Pratyush Yadav
RFC PATCH 3/3 luo: memfd: Move to feature flags instead of compatibility strings
In reply to Logan OdellUpdate struct memfd_luo_ser to embed struct luo_feature_hdr features. Define feature flags for memfd (MEMFD_LUO_FEATURE_SEALS and MEMFD_LUO_FEATURE_FOLIOS), emit the liveupdate feature entry for memfd, and validate required features and active flags during deserialization. Also replace the version bump requirement for seals with MEMFD_LUO_BASE_SEALS to allow new seals to be introduced granularly as feature bits.
--- include/linux/kho/abi/luo.h | 8 +++--- include/linux/kho/abi/memfd.h | 41 ++++++++++++++++++++---------- include/linux/liveupdate.h | 10 ++++---- kernel/liveupdate/luo_file.c | 28 ++++++++++----------- kernel/liveupdate/luo_flb.c | 2 +- lib/tests/liveupdate.c | 2 +- mm/memfd_luo.c | 47 +++++++++++++++++++++++++---------- 7 files changed, 87 insertions(+), 51 deletions(-)
include/linux/kho/abi/luo.h +4 -4
@@ -132,18 +132,18 @@ struct luo_ser {u64 flbs_pa; } __packed; -#define LIVEUPDATE_HNDL_COMPAT_LENGTH 48 +#define LIVEUPDATE_HNDL_NAME_LENGTH 48/** * struct luo_file_ser - Represents the serialized preserves files. -* @compatible: File handler compatible string. +* @name: File handler name. * @data: Private data * @token: User provided token for this file * * If this structure is modified, `LUO_ABI_COMPATIBLE` must be updated. */ struct luo_file_ser { -char compatible[LIVEUPDATE_HNDL_COMPAT_LENGTH ]; +char name[LIVEUPDATE_HNDL_NAME_LENGTH ];u64 data;u64 token; } __packed;
@@ -256,7 +256,7 @@ struct liveupdate_ver_hdr {* @active: Bitmask of active features. */ struct liveupdate_feature_entry { -char name[LIVEUPDATE_HNDL_COMPAT_LENGTH ]; +char name[LIVEUPDATE_HNDL_NAME_LENGTH ];u32 feat_bytes;u32 reserved;u64 supp;
include/linux/kho/abi/memfd.h +28 -13
76 lines not on this page · raw message
include/linux/liveupdate.h +5 -5
@@ -90,10 +90,10 @@ struct liveupdate_file_ops {/** * struct liveupdate_file_handler - Represents a handler for a live-updatable file type. * @ops: Callback functions -* @compatible: The compatibility string (e.g., "memfd-v1", "vfiofd-v1") -* that uniquely identifies the file type this handler -* supports. This is matched against the compatible string -* associated with individual &struct file instances. +* @name: The name (e.g., "memfd", "vfiofd") that uniquely +* identifies the file type this handler supports. This +* is matched against the name associated with individual +* &struct file instances. * * Modules that want to support live update for specific file types should * register an instance of this structure. LUO uses this registration to
@@ -102,7 +102,7 @@ struct liveupdate_file_ops {*/ struct liveupdate_file_handler {const struct liveupdate_file_ops *ops; -const char compatible[LIVEUPDATE_HNDL_COMPAT_LENGTH ]; +const char name[LIVEUPDATE_HNDL_NAME_LENGTH ];/* private: */
kernel/liveupdate/luo_file.c +14 -14
@@ -480,13 +480,13 @@ int luo_file_freeze(struct luo_file_set *file_set, err =luo_file_freeze_one (file_set, luo_file);if (err <0 ) {pr_warn ("Freeze failed for token[%#0llx] handler[%s] err[%pe]\n" , - luo_file->token, luo_file->fh->compatible, + luo_file->token, luo_file->fh->name,ERR_PTR (err)); goto err_unfreeze; } -strscpy (file_ser->compatible, luo_file->fh->compatible, -sizeof (file_ser->compatible)); +strscpy (file_ser->name, luo_file->fh->name, +sizeof (file_ser->name)); file_ser->data = luo_file->serialized_data; file_ser->token = luo_file->token; }
@@ -732,7 +732,7 @@ static int luo_file_deserialize_one(struct luo_file_set *file_set,down_read (&luo_register_rwlock);list_private_for_each_entry (fh, &luo_file_handler_list, list) { -if (!strcmp (fh->compatible, ser->compatible)) { +if (!strcmp (fh->name, ser->name)) {if (try_module_get (fh->ops->owner)) handler_found = true;break ;
@@ -741,9 +741,9 @@ static int luo_file_deserialize_one(struct luo_file_set *file_set,up_read (&luo_register_rwlock);if (!handler_found) { -pr_warn ("No registered handler for compatible '%.*s'\n" , - (int )sizeof (ser->compatible), - ser->compatible); +pr_warn ("No registered handler for name '%.*s'\n" , + (int )sizeof (ser->name), + ser->name);return -ENOENT ; }
@@ -774,9 +774,9 @@ static int luo_file_deserialize_one(struct luo_file_set *file_set,* in-memory linked list of 'struct luo_file' instances. * * For each serialized entry, it performs the following steps: -* 1. Reads the 'compatible' string. +* 1. Reads the 'name' string. * 2. Searches the global list of registered file handlers for one that -* matches the compatible string. +* matches the name. * 3. Allocates a new 'struct luo_file'. * 4. Populates the new structure with the deserialized data (token, private * data handle) and links it to the found handler. The 'file' pointer is
@@ -870,7 +870,7 @@ void luo_file_set_destroy(struct luo_file_set *file_set)* liveupdate_register_file_handler - Register a file handler with LUO. * @fh: Pointer to a caller-allocated &struct liveupdate_file_handler. * The caller must initialize this structure, including a unique -* 'compatible' string and a valid 'fh' callbacks. This function adds the +* 'name' string and valid 'fh' callbacks. This function adds the * handler to the global list of supported file handlers. * * Context: Typically called during module initialization for file types that
@@ -893,11 +893,11 @@ int liveupdate_register_file_handler(struct liveupdate_file_handler *fh) }down_write (&luo_register_rwlock); -/* Check for duplicate compatible strings */ +/* Check for duplicate handler names */ list_private_for_each_entry (fh_iter, &luo_file_handler_list, list) { -if (!strcmp (fh_iter->compatible, fh->compatible)) { -pr_err ("File handler registration failed: Compatible string '%s' already registered.\n" , - fh->compatible); +if (!strcmp (fh_iter->name, fh->name)) { +pr_err ("File handler registration failed: Handler name '%s' already registered.\n" , + fh->name); err = -EEXIST ; goto err_unlock; }
kernel/liveupdate/luo_flb.c +1 -1
@@ -337,7 +337,7 @@ static void luo_flb_unregister_one(struct liveupdate_file_handler *fh,if (!found) {pr_warn ("Failed to unregister FLB '%s': not found in file handler '%s'\n" , - flb->compatible, fh->compatible); + flb->compatible, fh->name);return ; }
lib/tests/liveupdate.c +1 -1
@@ -135,7 +135,7 @@ void liveupdate_test_register(struct liveupdate_file_handler *fh) }pr_info ("Registered %d FLBs with file handler: [%s]\n" , -TEST_NFLBS , fh->compatible); +TEST_NFLBS , fh->name); }MODULE_LICENSE ("GPL" );
mm/memfd_luo.c +34 -13
100 lines not on this page · raw message
Signature · 1 line
2.55.0.979.g7e5102b832-goog
[email protected]
AI reviewRe: [RFC PATCH 3/3] luo: memfd: Move to feature flags instead of compatibility strings
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Permanent memory leak of preserved KHO vmalloc block and physical folios when memfd_luo_retrieve() fails on early error paths. --
commit 5ce2719ae4caecc0b1ca1429438f4dfe06609564
Author: Logan Odell <[email protected]>
luo: memfd: Move to feature flags instead of compatibility strings
This commit updates the memfd liveupdate serialization structure to use feature flags instead of compatibility strings. It introduces granular compatibility checking by validating required features and active flags during deserialization to prevent unsupported states from being restored.
Quoted 4 lines
mm/memfd_luo.c +0
-0
[ ... ]
Quoted 11 lines
mm/memfd_luo.c +3
-2@@ -526,12 +531,21 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)if (!ser)return -EINVAL ; -/* Make sure the file only has seals supported by this version. */ -if (ser->seals & ~MEMFD_LUO_ALL_SEALS ) { +if (ser->features.req & ~MEMFD_LUO_FEATURES_SUPP ) { +pr_err ("Unsupported required memfd feature (req: 0x%llx, supp: 0x%llx)\n" , + ser->features.req, (u64 )MEMFD_LUO_FEATURES_SUPP ); err = -EOPNOTSUPP ; goto free_ser;
mm/memfd_luo.c static int memfd_luo_retrieve(struct liveupdate_file_op_args *args) · line 548
Quoted 10 lines
mm/memfd_luo.c +8
-0} +if (LUO_FEATURE_IS_ACTIVE (ser,MEMFD_LUO_FEATURE_SEALS )) { +/* Make sure the file only has seals supported by this version. */ +if (ser->seals & ~MEMFD_LUO_ALL_SEALS ) { + err = -EOPNOTSUPP ; + goto free_ser; + } + } +
[Severity: High]
This is a pre-existing issue, but does this early error path permanently leak the preserved KHO vmalloc block and physical folios?
When memfd_luo_retrieve() in mm/memfd_luo.c fails here and jumps to the free_ser label:
free_ser:
kho_restore_free(ser); return err;
It abruptly frees the serialization struct. Bypassing the restoration of the vmalloc array and physical folios leaves them locked in memblock indefinitely.
Furthermore, any fallback cleanup is skipped because the finalizer memfd_luo_finish() returns immediately if args->retrieve_status is set:
mm/memfd_luo.c:memfd_luo_finish() {
...
if (args->retrieve_status)
return;
...
}Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Quoted 10 lines · Logan Odell
We're including maintainers from all subsystems that currently is or will be expected to participate in live update to ensure alignment on the path forward for compatibility.
Currently, Live Update Orchestrator (LUO) and its file handlers rely on monolithic compatibility strings (such as "luo-v5" and "memfd-v1") to validate ABI compatibility across kexec live updates. Any modification to serialized structures requires bumping the version string, which strictly breaks compatibility between adjacent kernels even when changes are additive, backwards-compatible, or optional.
That was the intention, I aruged strongly that upstream does not want to maintain a CSP matrix of endless kernel version combinations. That is far too much work to push on maintainers. Upstream would do much less, maybe only same-version, depending.
Quoted 5 lines
This RFC series transitions LUO and subsystem file handlers to use granular feature bitmasks instead of compatibility strings. We replace the compatibility string with a header structure that includes some reserved space to define the features that are included after the feature.
The compatability string is only a small part of it, you also need a serializing ABI that can handle some random mixmash of these features. Ie the various TLV schemes that were all proposed. What is the plan here?
Jason
Quoted 12 lines · Jason Gunthorpe
Quoted 10 lines · Logan Odell
We're including maintainers from all subsystems that currently is or will be expected to participate in live update to ensure alignment on the path forward for compatibility.
Currently, Live Update Orchestrator (LUO) and its file handlers rely on monolithic compatibility strings (such as "luo-v5" and "memfd-v1") to validate ABI compatibility across kexec live updates. Any modification to serialized structures requires bumping the version string, which strictly breaks compatibility between adjacent kernels even when changes are additive, backwards-compatible, or optional.
Quoted 4 lines
That was the intention, I aruged strongly that upstream does not want to maintain a CSP matrix of endless kernel version combinations. That is far too much work to push on maintainers. Upstream would do much less, maybe only same-version, depending.
We received basically the opposite stance from Sean regarding the KVM LUO ABI:
https://lore.kernel.org/kvm/[email protected]/
So we're trying to use this series to get some alignment across LUO ABIs.
Quoted 10 lines
Quoted 5 lines
This RFC series transitions LUO and subsystem file handlers to use granular feature bitmasks instead of compatibility strings. We replace the compatibility string with a header structure that includes some reserved space to define the features that are included after the feature.
The compatability string is only a small part of it, you also need a serializing ABI that can handle some random mixmash of these features. Ie the various TLV schemes that were all proposed. What is the plan here?
The proposal here (which is inspired by the KVM UAPI) is to ensure every LUO ABI struct has 2 properties:
1. A field to encode options/features (e.g. u64 flags).
2. A way way to grow without breaking backward compatibility (e.g. so we can add new fields).
Each flag can mean whatever it needs to. e.g. It can indicate the precence of one or more fields (i.e. new fields in the struct), or it can mean a field now has a different meaning (i.e. union in the struct).
This would enable adding support for new features without breaking backward compatibility. Downstream users would have to ensure their kernel does not start using a new feature while it can still rollback to a version that does not support the new feature.
Quoted 7 lines · David Matlack
The proposal here (which is inspired by the KVM UAPI) is to ensure every LUO ABI struct has 2 properties:
1. A field to encode options/features (e.g. u64 flags).
2. A way way to grow without breaking backward compatibility (e.g. so we can add new fields).
Quoted 8 lines
Each flag can mean whatever it needs to. e.g. It can indicate the precence of one or more fields (i.e. new fields in the struct), or it can mean a field now has a different meaning (i.e. union in the struct).
This would enable adding support for new features without breaking backward compatibility. Downstream users would have to ensure their kernel does not start using a new feature while it can still rollback to a version that does not support the new feature.
This was never the biggest problem. The main issue was the functional behaviors of the kernel that cannot be represented simply as data in a struct with some flag bits.
Like for instance kernel A supports memfd folio sizes far larger than kernel B because we fixed MAX_ORDER. You can't fix that just with simplistic flags.
Jason
Sean Christopherson
reviewerQuoted 18 lines · Jason Gunthorpe
Quoted 7 lines · David Matlack
The proposal here (which is inspired by the KVM UAPI) is to ensure every LUO ABI struct has 2 properties:
1. A field to encode options/features (e.g. u64 flags).
2. A way way to grow without breaking backward compatibility (e.g. so we can add new fields).Quoted 8 lines
Each flag can mean whatever it needs to. e.g. It can indicate the precence of one or more fields (i.e. new fields in the struct), or it can mean a field now has a different meaning (i.e. union in the struct).
This would enable adding support for new features without breaking backward compatibility. Downstream users would have to ensure their kernel does not start using a new feature while it can still rollback to a version that does not support the new feature.
Quoted 7 lines
This was never the biggest problem. The main issue was the functional behaviors of the kernel that cannot be represented simply as data in a struct with some flag bits.
Like for instance kernel A supports memfd folio sizes far larger than kernel B because we fixed
MAX_ORDER. You can't fix that just with simplistic flags.
Can you elaborate on why the folio sizes matter? Honest question, because I don't understand why the serialization format wouldn't express things as "N contiguous pages starting at PFN X". Then the implementation would rebuild its folios as appropriate.
I could see things like HugeTLB not working if someone booted the kernel with support for only 1GiB pages and then tried to feed it payload with sub-1GiB ranges. But to me, those sorts of things fall into the "well yeah, don't do that" category.
Quoted 23 lines · Sean Christopherson
Quoted 22 lines · Jason Gunthorpe
Quoted 7 lines · David Matlack
The proposal here (which is inspired by the KVM UAPI) is to ensure every LUO ABI struct has 2 properties:
1. A field to encode options/features (e.g. u64 flags).
2. A way way to grow without breaking backward compatibility (e.g. so we can add new fields).Quoted 8 lines
Each flag can mean whatever it needs to. e.g. It can indicate the precence of one or more fields (i.e. new fields in the struct), or it can mean a field now has a different meaning (i.e. union in the struct).
This would enable adding support for new features without breaking backward compatibility. Downstream users would have to ensure their kernel does not start using a new feature while it can still rollback to a version that does not support the new feature.
This was never the biggest problem. The main issue was the functional behaviors of the kernel that cannot be represented simply as data in a struct with some flag bits.
Quoted 8 lines
Quoted 3 lines
Like for instance kernel A supports memfd folio sizes far larger than kernel B because we fixed
MAX_ORDER. You can't fix that just with simplistic flags.Can you elaborate on why the folio sizes matter? Honest question, because I don't understand why the serialization format wouldn't express things as "N contiguous pages starting at PFN X". Then the implementation would rebuild its folios as appropriate.
That's an idyllic view, yes, but my point is (IIRC) we didn't do exactly that for memfd.
Sometimes you can do more and more work to try and be more and more general but this is *alot* of work and even then eventually hits problematic limits. Like what do you do with the sealing flags? That's ABI breaking if the successor does not support them, and downgrades make exactly that possible.
A CSPish user can do things like patch the new sealing flag into their current kernel (while preventing userspace from using it), ensure everything is updated to that, then jump ahead to a newer kernel and enjoy the new flag with full downgrade support. There is so much more control on their part that makes the problem far more managably simple that upstream does not get to have.
This is why I think the very idea we can support any version pair is too much to ask for. We should focus on supporting a small set of version pairs and not making it too invasive or hard in the kernel or on the maintainers.
Thus live update within a stable branch only is my proposal for upstream support.
If it really succeeds at that and it becomes very popular, then let's discuss upstreaming doing additional version combinations.
Quoted 3 lines
I could see things like HugeTLB not working if someone booted the kernel with support for only 1GiB pages and then tried to feed it payload with sub-1GiB ranges. But to me, those sorts of things fall into the "well yeah, don't do that" category.
Okay, how about worse, todays kernel has hugetlbfs and there are patches around to luo serialize that. Lots and lots of talks about a post-hugetlbfs world out there.
Do we want to constrain what is possible to ensure we accomodate this hugetlbfs serialization? I vote no.
Do we want to reject the hugetlbfs serialization until we have a year of debate outlining every possible ABI scenario? I also vote no.
Should we make a downgrade round trip a downstream problem? I think so!
Jason
Sean Christopherson
reviewerQuoted 28 lines · Jason Gunthorpe
Quoted 27 lines · Sean Christopherson
Quoted 25 lines · Jason Gunthorpe
Quoted 7 lines · David Matlack
The proposal here (which is inspired by the KVM UAPI) is to ensure every LUO ABI struct has 2 properties:
1. A field to encode options/features (e.g. u64 flags).
2. A way way to grow without breaking backward compatibility (e.g. so we can add new fields).Quoted 8 lines
Each flag can mean whatever it needs to. e.g. It can indicate the precence of one or more fields (i.e. new fields in the struct), or it can mean a field now has a different meaning (i.e. union in the struct).
This would enable adding support for new features without breaking backward compatibility. Downstream users would have to ensure their kernel does not start using a new feature while it can still rollback to a version that does not support the new feature.
This was never the biggest problem. The main issue was the functional behaviors of the kernel that cannot be represented simply as data in a struct with some flag bits.
Like for instance kernel A supports memfd folio sizes far larger than kernel B because we fixed
MAX_ORDER. You can't fix that just with simplistic flags.
Quoted 7 lines
Quoted 4 lines
Can you elaborate on why the folio sizes matter? Honest question, because I don't understand why the serialization format wouldn't express things as "N contiguous pages starting at PFN X". Then the implementation would rebuild its folios as appropriate.
That's an idyllic view, yes, but my point is (IIRC) we didn't do exactly that for memfd.
Well, y'all screwed up then. I don't see why past mistakes should force other subsystems to support a flawed implementation. Learn from the mistakes, add v2 of serialization for memfd, and move on.
Quoted 6 lines
Sometimes you can do more and more work to try and be more and more general but this is *alot* of work and even then eventually hits problematic limits. Like what do you do with the sealing flags? That's ABI breaking if the successor does not support them, and downgrades make exactly that possible.
Quoted 6 lines
A CSPish user can do things like patch the new sealing flag into their current kernel (while preventing userspace from using it), ensure everything is updated to that, then jump ahead to a newer kernel and enjoy the new flag with full downgrade support. There is so much more control on their part that makes the problem far more managably simple that upstream does not get to have.
I guess maybe we have a different definition of ABI?
I'm not saying that upstream has to be 100% forwards and backwards compatible. I'm saying the serialization payload itself should communicate what features are effectively required. I.e. *if* there are incompatibilities, they should be naturally expressed in the serialization format, not communicated out-of-band through magic numbers.
The scenario you describe fits exactly with what I am proposing. Until something actually starts using the new sealing flag, the CSP can downgrade to older kernels at will. And if the user cares about downgrading, then they need to prevent the flag from being used until the new kernel is rollback-safe and deployed to enough hosts to prevent stockout.
Quoted 10 lines
This is why I think the very idea we can support any version pair is too much to ask for. We should focus on supporting a small set of version pairs and not making it too invasive or hard in the kernel or on the maintainers.
Thus live update within a stable branch only is my proposal for upstream support.
If it really succeeds at that and it becomes very popular, then let's discuss upstreaming doing additional version combinations.
Why on earth would we have version numbers in the first place? IMO, monotically increasing version numbers are flat out the worst way to communicate features.
I am completely against supporting any scheme that relies on magic version numbers. It creates problems where none need exist, and checking for compatibility can't be sanely done in a programmatic way, because by definition it relies on magic numbers.
E.g. if the ABI for a given component hasn't changed, why should anyone care if the overall "version" of the kernel is ahead or behind by N kernels?
Quoted 7 lines
Quoted 3 lines
I could see things like HugeTLB not working if someone booted the kernel with support for only 1GiB pages and then tried to feed it payload with sub-1GiB ranges. But to me, those sorts of things fall into the "well yeah, don't do that" category.
Okay, how about worse, todays kernel has hugetlbfs and there are patches around to luo serialize that. Lots and lots of talks about a post-hugetlbfs world out there.
And? Adding a compatibility layer to a future kernel so that it understands an incoming HugeTLBFS payload should be trivial. I can totally see not wanting to support serializing a post-HugeTBLFS kernel's memory representation into the "old" format, though even that probably wouldn't be all that difficult.
Quoted 2 lines
Do we want to constrain what is possible to ensure we accomodate this hugetlbfs serialization? I vote no.
In what way is providing strong ABI guarantees for individual components constraining HugeTBLFS serialization?
Quoted 2 lines
Do we want to reject the hugetlbfs serialization until we have a year of debate outlining every possible ABI scenario? I also vote no.
That's a bit of a strawman argument. Is designing a forward-looking ABI easy? No, but IMO "a year" is a massive exaggeration of the effort required to come up with a scheme that can survive a variety of plausible upgrade/downgrade scenarios.
And again, I'm not saying we have to support infinite compatibility. If some future kernel drops HugeTLBFS, and we decide not to provide a shim to support downgrading (which IMO is totally reasonable), then it's on the user to understand that moving to that new kernel is a one-way street. Given that dropping something like HugeTLBFS would require significant changes in the software stack, I think it's perfectly fine to put the burden of understanding the implications on the end user (though realistically, there would be a copious amount of documentation and deprecation warnings).
Quoted 2 lines
Should we make a downgrade round trip a downstream problem? I think so!
Hard NAK. There will inevitably be boundaries that cannot be crossed, but I am not at all ok punting on downgrades. To me, that's basically saying "we want to add just enough support upstream so that it's not too painful to carry full support out-of-tree". That completely goes against the spirit of open source and upstream Linux, and I want no part of it.
Quoted 7 lines · Sean Christopherson
I guess maybe we have a different definition of ABI?
I'm not saying that upstream has to be 100% forwards and backwards compatible. I'm saying the serialization payload itself should communicate what features are effectively required. I.e. *if* there are incompatibilities, they should be naturally expressed in the serialization format, not communicated out-of-band through magic numbers.
The ABI strings were introduced specifically because extension makes the actual compatibility indeterminate by userspace.
Keep in mind the actual goal here. Someone has kernel A and they need to blind kexec into kernel B and NOT have the machine explode, or all the VMs sitting on it lost.
Meaning you must have a way to determine before the kexec if kernel A is producing something B will *accept*. Accept is not "parse and fail with EOPNOTSUPP" like most uapi schems. Aceept means bring in and actually fully support and use.
So how do you solve this problem? You MUST declare in some kind of manifest exactly what ABIs are supported, in some way.
Quoted 1 line
The scenario you describe fits exactly with what I am proposing.
It does not. What is really wanted here is to tell kernel A to only support ABI 1 for memfd and so kernel A will fail to serialize if it cannot do it because a newer seal flag was used.
We do not want to succeed to serialize then fail to accept after kexec and have a dead machine.
This is not anything like a normal uapi compatability problem.
Quoted 5 lines
actually starts using the new sealing flag, the CSP can downgrade to older kernels at will. And if the user cares about downgrading, then they need to prevent the flag from being used until the new kernel is rollback-safe and deployed to enough hosts to prevent stockout.
Yeah, CSP broadly has to do exactly this across a wide range of topics. It is a further reason why this feature is not exactly usable by a "mainstream" user :\
Quoted 8 lines
Quoted 8 lines
This is why I think the very idea we can support any version pair is too much to ask for. We should focus on supporting a small set of version pairs and not making it too invasive or hard in the kernel or on the maintainers.
Thus live update within a stable branch only is my proposal for upstream support.
Quoted 6 lines
Quoted 2 lines
If it really succeeds at that and it becomes very popular, then let's discuss upstreaming doing additional version combinations.
Why on earth would we have version numbers in the first place? IMO, monotically increasing version numbers are flat out the worst way to communicate features.
As above, discoverablility is a key requirement.
Each version number is a very specific upstream defined ABI, in the sense if kernel A emits version X and kernel B accepts version X then kexec *must* work.
You can make some manifest in other more complicated ways, but I'm deeply skeptical that is really going to bring any value. It feels like it is just increasing the testing matrix :\
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
I could see things like HugeTLB not working if someone booted the kernel with support for only 1GiB pages and then tried to feed it payload with sub-1GiB ranges. But to me, those sorts of things fall into the "well yeah, don't do that" category.
Okay, how about worse, todays kernel has hugetlbfs and there are patches around to luo serialize that. Lots and lots of talks about a post-hugetlbfs world out there.
And? Adding a compatibility layer to a future kernel so that it understands an incoming HugeTLBFS payload should be trivial.
From my experience that's optimistic :(
Quoted 5 lines
Quoted 2 lines
Do we want to constrain what is possible to ensure we accomodate this hugetlbfs serialization? I vote no.
In what way is providing strong ABI guarantees for individual components constraining HugeTBLFS serialization?
I bet it will. Other things we've looked at seemed to be like that. Even the above about "yall screwed up" with memfd has the problem already. I don't believe we can ever do this so right that it won't be constraining to the kernel internals.
Quoted 6 lines
Quoted 2 lines
Do we want to reject the hugetlbfs serialization until we have a year of debate outlining every possible ABI scenario? I also vote no.
That's a bit of a strawman argument. Is designing a forward-looking ABI easy? No, but IMO "a year" is a massive exaggeration of the effort required to come up with a scheme that can survive a variety of plausible upgrade/downgrade scenarios.
Have you tried to get anything merged into the kernel lately? I've got lots of uncontroversial stuff pushed out past 4 months already. Some luo patches are close to a year already and don't even have any controversy.
Quoted 1 line
And again, I'm not saying we have to support infinite compatibility.
Okay, I said same stable branch only, do you have some wider limitation in mind?
Quoted 8 lines
Quoted 2 lines
Should we make a downgrade round trip a downstream problem? I think so!
Hard NAK. There will inevitably be boundaries that cannot be crossed, but I am not at all ok punting on downgrades. To me, that's basically saying "we want to add just enough support upstream so that it's not too painful to carry full support out-of-tree". That completely goes against the spirit of open source and upstream Linux, and I want no part of it.
I generally agree with you sentiment, but I think this is a unique case. I've asked around a fair bit, this is sufficiently complicated, requires alot of userspace that the CSPs are not open sourcing so has a very minimal usage foot print out side their world. I found one other possible user that might be more open source oriented..
So, if I was feeling unreasonable I'd say stay out of the upstream kernel entirely.
Though, I think this could grow and maybe some open source ecosystem will develop around it. I don't know. I'm willing to give it a chance.
HOWEVER upstream is not some kind of free outsourcing for the CSP's proprietary forks! Do not ask maintainers to do significant and burdensome work that only a CSP is ever going to consume and can only really work in a closed proprietary environment. There is no "spirit of open source" in that kind of demand. I will be NAKing anything like that in my subsystems, I am not signing up to do live update stable ABI so the CSPs alone can have a better proprietary product.
This is how I come to my conclusion that upstream should support same stable branch only at this point. It minimizes the burden, it is a decent trail of the technology, and if things go well with a quality open ecosystem then sure, upstream can change its mind.
Jason
Quoted 17 lines · Jason Gunthorpe
Quoted 7 lines · Sean Christopherson
I guess maybe we have a different definition of ABI?
I'm not saying that upstream has to be 100% forwards and backwards compatible. I'm saying the serialization payload itself should communicate what features are effectively required. I.e. *if* there are incompatibilities, they should be naturally expressed in the serialization format, not communicated out-of-band through magic numbers.
The ABI strings were introduced specifically because extension makes the actual compatibility indeterminate by userspace.
Keep in mind the actual goal here. Someone has kernel A and they need to blind kexec into kernel B and NOT have the machine explode, or all the VMs sitting on it lost.
Quoted 7 lines
Meaning you must have a way to determine before the kexec if kernel A is producing something B will *accept*. Accept is not "parse and fail with EOPNOTSUPP" like most uapi schems. Aceept means bring in and actually fully support and use.
So how do you solve this problem? You MUST declare in some kind of manifest exactly what ABIs are supported, in some way.
I think this series solves this problem in a fairly clean way without relying on version numbers.
Each ABI is now extensible with a set of structured featured flags that are exposed to userspace. Userspace can inspect the flags that the kernel supports and confirm the next kernel also supports them.
I think there is still room for improvement, like determining what features are used at runtime rather than statically at compile time, or allowing userspace to disable use of certain features to control compatability, but I think these things can be built into this type of model.
Quoted 38 lines
Quoted 1 line
The scenario you describe fits exactly with what I am proposing.
It does not. What is really wanted here is to tell kernel A to only support ABI 1 for memfd and so kernel A will fail to serialize if it cannot do it because a newer seal flag was used.
We do not want to succeed to serialize then fail to accept after kexec and have a dead machine.
This is not anything like a normal uapi compatability problem.
Quoted 5 lines
actually starts using the new sealing flag, the CSP can downgrade to older kernels at will. And if the user cares about downgrading, then they need to prevent the flag from being used until the new kernel is rollback-safe and deployed to enough hosts to prevent stockout.
Yeah, CSP broadly has to do exactly this across a wide range of topics. It is a further reason why this feature is not exactly usable by a "mainstream" user :\
Quoted 8 lines
Quoted 8 lines
This is why I think the very idea we can support any version pair is too much to ask for. We should focus on supporting a small set of version pairs and not making it too invasive or hard in the kernel or on the maintainers.
Thus live update within a stable branch only is my proposal for upstream support.
Quoted 6 lines
Quoted 2 lines
If it really succeeds at that and it becomes very popular, then let's discuss upstreaming doing additional version combinations.
Why on earth would we have version numbers in the first place? IMO, monotically increasing version numbers are flat out the worst way to communicate features.
As above, discoverablility is a key requirement.
Quoted 7 lines
Each version number is a very specific upstream defined ABI, in the sense if kernel A emits version X and kernel B accepts version X then kexec *must* work.
You can make some manifest in other more complicated ways, but I'm deeply skeptical that is really going to bring any value. It feels like it is just increasing the testing matrix :\
The value I see of the flag-based approach over the version-based approach is:
- Each component can have one ABI struct that extends over time and one serialization/deserialization routines, rather than N for the N supported current versions. Supporting multiple versions within a single kernel would be required for upgrade/downgrade. Maybe there is a way to make the multi-versioning support maintainable but it seems like it will be messy to me.
- Features can be managed individually. Let's say a downstream user wants to use a new upstream feature. If we had a versioning model they would have to backport the entire version delta from their current kernel to that feature upstream. With flags they can backport and use an individual feature.
I agree testing matrix becomes more complex but maybe that can be mitigated with your suggestion that upstream only "officially" supports (i.e. tests) some constrained version sets like within a stable branch?
Quoted 78 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
I could see things like HugeTLB not working if someone booted the kernel with support for only 1GiB pages and then tried to feed it payload with sub-1GiB ranges. But to me, those sorts of things fall into the "well yeah, don't do that" category.
Okay, how about worse, todays kernel has hugetlbfs and there are patches around to luo serialize that. Lots and lots of talks about a post-hugetlbfs world out there.
And? Adding a compatibility layer to a future kernel so that it understands an incoming HugeTLBFS payload should be trivial.
From my experience that's optimistic :(
Quoted 5 lines
Quoted 2 lines
Do we want to constrain what is possible to ensure we accomodate this hugetlbfs serialization? I vote no.
In what way is providing strong ABI guarantees for individual components constraining HugeTBLFS serialization?
I bet it will. Other things we've looked at seemed to be like that. Even the above about "yall screwed up" with memfd has the problem already. I don't believe we can ever do this so right that it won't be constraining to the kernel internals.
Quoted 6 lines
Quoted 2 lines
Do we want to reject the hugetlbfs serialization until we have a year of debate outlining every possible ABI scenario? I also vote no.
That's a bit of a strawman argument. Is designing a forward-looking ABI easy? No, but IMO "a year" is a massive exaggeration of the effort required to come up with a scheme that can survive a variety of plausible upgrade/downgrade scenarios.
Have you tried to get anything merged into the kernel lately? I've got lots of uncontroversial stuff pushed out past 4 months already. Some luo patches are close to a year already and don't even have any controversy.
Quoted 1 line
And again, I'm not saying we have to support infinite compatibility.
Okay, I said same stable branch only, do you have some wider limitation in mind?
Quoted 8 lines
Quoted 2 lines
Should we make a downgrade round trip a downstream problem? I think so!
Hard NAK. There will inevitably be boundaries that cannot be crossed, but I am not at all ok punting on downgrades. To me, that's basically saying "we want to add just enough support upstream so that it's not too painful to carry full support out-of-tree". That completely goes against the spirit of open source and upstream Linux, and I want no part of it.
I generally agree with you sentiment, but I think this is a unique case. I've asked around a fair bit, this is sufficiently complicated, requires alot of userspace that the CSPs are not open sourcing so has a very minimal usage foot print out side their world. I found one other possible user that might be more open source oriented..
So, if I was feeling unreasonable I'd say stay out of the upstream kernel entirely.
Though, I think this could grow and maybe some open source ecosystem will develop around it. I don't know. I'm willing to give it a chance.
HOWEVER upstream is not some kind of free outsourcing for the CSP's proprietary forks! Do not ask maintainers to do significant and burdensome work that only a CSP is ever going to consume and can only really work in a closed proprietary environment. There is no "spirit of open source" in that kind of demand. I will be NAKing anything like that in my subsystems, I am not signing up to do live update stable ABI so the CSPs alone can have a better proprietary product.
This is how I come to my conclusion that upstream should support same stable branch only at this point. It minimizes the burden, it is a decent trail of the technology, and if things go well with a quality open ecosystem then sure, upstream can change its mind.
Jason
Quoted 3 lines · David Matlack
Each ABI is now extensible with a set of structured featured flags that are exposed to userspace. Userspace can inspect the flags that the kernel supports and confirm the next kernel also supports them.
I'm fine with that bit, it is really just a different way to encode an ABI ID #. If ABI 5 is spelled b11111 instead it doesn't materially change how things work.
It was always the case you can use the same struct extension techinque with a version number. A version can't handle 'holes' in the feature mask, but I haven't thought that was a meaningful use case.
"if (id > 10)" instead "if (id & FEAT)" isn't a big coding difference.
My concern is the implied position that the kernel must make full use of this to maximize compatability or bust. That's what has always concerned me about all these proposals since the start.
I do not want to have arguments upstream about not changing things because we didn't do a perfect job preserving luo compatability with upgrade and downgrade for arbitary kernel versions. That has always been my position and worry.
So, change the simple version to a u64 features[] tuple (be sure to use an array, we will need alot of them!!) and I'm fine. But I'm not going to promise that every upstream kernel will strictly only have an increasing string of 1's. You are going to get some that look like b1110000 and still wont work with old kernels.
Sean's initial email was asking for strict never-break ABI compatability rules on top, and that is what I've been reacting to.
Jason
Sean Christopherson
reviewerQuoted 2 lines · Jason Gunthorpe
Sean's initial email was asking for strict never-break ABI compatability rules on top, and that is what I've been reacting to.
No, I was never asking for that. I think we just have a different interpretation of ABI, or rather are talking about different pieces of ABI.
I am still asking for never-break serialization format compatibility, i.e. the more literal save/restore ABI. I'm not asking for full backwards/forwards compatibility across all kernels version, i.e. the higher level "kernel" ABI.
To phrase things differently: I am a-ok if kernels are inherently incompatible because they fundamentally operate differently and/or support different features. I am not ok if we end up with incompatible kernels because the save/restore interfaces and payloads are poorly designed, lack abstraction, etc.
Quoted 7 lines · Sean Christopherson
Quoted 2 lines · Jason Gunthorpe
Sean's initial email was asking for strict never-break ABI compatability rules on top, and that is what I've been reacting to.
No, I was never asking for that. I think we just have a different interpretation of ABI, or rather are talking about different pieces of ABI.
Quoted 8 lines
I am still asking for never-break serialization format compatibility, i.e. the more literal save/restore ABI. I'm not asking for full backwards/forwards compatibility across all kernels version, i.e. the higher level "kernel" ABI.
To phrase things differently: I am a-ok if kernels are inherently incompatible because they fundamentally operate differently and/or support different features. I am not ok if we end up with incompatible kernels because the save/restore interfaces and payloads are poorly designed, lack abstraction, etc.
I can more agree with this, it is mostly what I thought we'd end up doing anyhow with version numbers and growing the structs not replacing them.
So you still end up with a version label (string I guess?) because we can break it from time to time, just the version should have the feature mechanism layered under it? I'm fine with that
Jason
Quoted 17 lines · Jason Gunthorpe
Quoted 7 lines · Sean Christopherson
Quoted 2 lines · Jason Gunthorpe
Sean's initial email was asking for strict never-break ABI compatability rules on top, and that is what I've been reacting to.
No, I was never asking for that. I think we just have a different interpretation of ABI, or rather are talking about different pieces of ABI.
Quoted 8 lines
I am still asking for never-break serialization format compatibility, i.e. the more literal save/restore ABI. I'm not asking for full backwards/forwards compatibility across all kernels version, i.e. the higher level "kernel" ABI.
To phrase things differently: I am a-ok if kernels are inherently incompatible because they fundamentally operate differently and/or support different features. I am not ok if we end up with incompatible kernels because the save/restore interfaces and payloads are poorly designed, lack abstraction, etc.
Quoted 7 lines
I can more agree with this, it is mostly what I thought we'd end up doing anyhow with version numbers and growing the structs not replacing them.
So you still end up with a version label (string I guess?) because we can break it from time to time, just the version should have the feature mechanism layered under it? I'm fine with that
Seems reasonable. I'd note that downgrade support *is* important though.
So where possible, those new features which are inherently incompatible should be opt-out. That way the admin can disable them when first upgrading to a new kernel version, and enable them only in a *subsequent* update, once that new kernel version has actually rolled out successfully.
Again, it's OK if we sometimes can't manage that, but not if it happens just because of poor design, as Sean said above.
The thing that *really* concerns me here though, is latency. When we pause guests and kexec underneath them, every *millisecond* is perceived as steal time. I worry that we're designing handover protocols to look *pretty*, and not necessarily go *fast* enough.
I'd really love to see these patch series come in with benchmarks.
Sean Christopherson
reviewerQuoted 17 lines · Jason Gunthorpe
Quoted 7 lines · Sean Christopherson
Quoted 2 lines · Jason Gunthorpe
Sean's initial email was asking for strict never-break ABI compatability rules on top, and that is what I've been reacting to.
No, I was never asking for that. I think we just have a different interpretation of ABI, or rather are talking about different pieces of ABI.
Quoted 8 lines
I am still asking for never-break serialization format compatibility, i.e. the more literal save/restore ABI. I'm not asking for full backwards/forwards compatibility across all kernels version, i.e. the higher level "kernel" ABI.
To phrase things differently: I am a-ok if kernels are inherently incompatible because they fundamentally operate differently and/or support different features. I am not ok if we end up with incompatible kernels because the save/restore interfaces and payloads are poorly designed, lack abstraction, etc.
Quoted 6 lines
I can more agree with this, it is mostly what I thought we'd end up doing anyhow with version numbers and growing the structs not replacing them.
So you still end up with a version label (string I guess?) because we can break it from time to time,
Why bother with a label/string? I don't understand what it buys us; I see only pain. Make the features discoverable and punt on all of the "is this pile of insanity my company has created compatible with this other pile of insanity?" to layers above the kernel.
IMO, trying to capture compatibility in a version string is doomed to fail. To be useful, the version would have to be extremely sensitive to changes, otherwise userspace will have to do its own compatibility analysis/checks anyways. And at that point, a verson string will be too restrictive, e.g. will mismatch due to changes in features the deployment isn't using.
Quoted 4 lines
just the version should have the feature mechanism layered under it? I'm fine with that
Jason
Quoted 22 lines · Sean Christopherson
Quoted 21 lines · Jason Gunthorpe
Quoted 7 lines · Sean Christopherson
Quoted 2 lines · Jason Gunthorpe
Sean's initial email was asking for strict never-break ABI compatability rules on top, and that is what I've been reacting to.
No, I was never asking for that. I think we just have a different interpretation of ABI, or rather are talking about different pieces of ABI.
Quoted 8 lines
I am still asking for never-break serialization format compatibility, i.e. the more literal save/restore ABI. I'm not asking for full backwards/forwards compatibility across all kernels version, i.e. the higher level "kernel" ABI.
To phrase things differently: I am a-ok if kernels are inherently incompatible because they fundamentally operate differently and/or support different features. I am not ok if we end up with incompatible kernels because the save/restore interfaces and payloads are poorly designed, lack abstraction, etc.
I can more agree with this, it is mostly what I thought we'd end up doing anyhow with version numbers and growing the structs not replacing them.
Quoted 7 lines
Quoted 2 lines
So you still end up with a version label (string I guess?) because we can break it from time to time,
Why bother with a label/string? I don't understand what it buys us; I see only pain. Make the features discoverable and punt on all of the "is this pile of insanity my company has created compatible with this other pile of insanity?" to layers above the kernel.
It is one layer above, the serialization ends up with 10 memfds a couple iommus, kvm, pci device, etc, etch. Each one starts with a string label saying what it even is - to dispatch it to the proper de-serialization code, then some detail about where it is (eg a handle to recover a FD later) and then the actual object serialization data itself.
So the features are fine to handle the ABI within the object and a memfd-v1, memfd-v2 is fine to handle labeling the object within the stream and gives us an option to reboot the ABI if some reason comes up someday.
If features are a perfect success then we will never need to go beyond memfd-v1. I'm just saying we should have the option and plan for it.
Jason
Paolo Bonzini
maintainerQuoted 11 lines · Jason Gunthorpe
Keep in mind the actual goal here. Someone has kernel A and they need to blind kexec into kernel B and NOT have the machine explode, or all the VMs sitting on it lost.
Meaning you must have a way to determine before the kexec if kernel A is producing something B will *accept*. Accept is not "parse and fail with EOPNOTSUPP" like most uapi schems. Aceept means bring in and actually fully support and use.
So how do you solve this problem? You MUST declare in some kind of manifest exactly what ABIs are supported, in some way.
You still have to pass out of band what B will accept. Passing a string or a bitvector doesn't change much.
The problem, again is that memfd is the easy case. KVM would bump the version number on every other release, as even a new serialized MSR will be an incompatibility.
Rather, forwards kexec *must* work (again, that's nothing but a variant of "we don't break userspace") and for backwards kexec, well, you must know what you're doing. QEMU has been doing backwards live migration forever, and QEMU is a gnarly C program that has grown by accretion as we were learning all this stuff, so it's not impossible at all.
Quoted 3 lines
Yeah, CSP broadly has to do exactly this across a wide range of topics. It is a further reason why this feature is not exactly usable by a "mainstream" user :\
It's not easy, but you aren't even trying to do it right in the kernel. You are starting from *a* solution and saying that it makes the feature hard to use.
And I'm not saying to dismiss your work or ability, quite the contrary in fact! It's just that you're solving for the wrong complexity, and only partially so because (if I'm not wrong) there's still the question of how to bring the manifest of kernel B into kernel A.
Paolo
Quoted 3 lines · Paolo Bonzini
Rather, forwards kexec *must* work (again, that's nothing but a variant of "we don't break userspace") and for backwards kexec, well, you must know what you're doing.
Again, I strongly disagree with this MUST. This is not a variant of "we don't break userspace". It is internal kabi and the kernel gets to decide which versions it supports. There are no promises here. It is not a breaking change to say we won't support A->B.
Community needs to agree on what these parameters are. I've been clear my stake in the ground is same stable version only as a starting point.
This is typical in the industry, nobody does live update where you can jump ahead multiple years of versions. Sequential releases only is very normal.
Quoted 3 lines
QEMU has been doing backwards live migration forever, and QEMU is a gnarly C program that has grown by accretion as we were learning all this stuff, so it's not impossible at all.
I agree it is not impossible, you can always make things harder and more complicated to keep it working. I don't want the kernel to turn into a "gnarly C program" because we over engineered this.
Quoted 1 line
It's not easy, but you aren't even trying to do it right in the kernel. You
Right, I've been pretty clear about this, I want to start with same-stable-version only and if that works out then consider if we want to do more.
I am not doing this for any sort of technical reason. Not because it is impossible, but because it is HARD. I do not want to force anyone to take on hard and difficult projects like this for a niche feature only a few CSPs are likely to use. If we take this approach LUO will fail because maintainers will be scared to take on this extra work and simply won't merge LUO patches.
There needs to be some balance that we can try this out and see if a broader use case develops before we commit to doing the hardest possible version of it.
A niche feature only for CSPs like live update must not become a boat anchor on kernel progress!
Quoted 3 lines
fact! It's just that you're solving for the wrong complexity, and only partially so because (if I'm not wrong) there's still the question of how to bring the manifest of kernel B into kernel A.
There is a proposal to encode information into ELF sections. Feature flags should flow through there just fine, I think.
I have not seen a proposal to re-inject this information back into the A kernel as a 'restriction' so it fails luo instead of producing something unsupported.
Jason
Paolo Bonzini
maintainerQuoted 14 lines · Sean Christopherson
Quoted 6 lines · Jason Gunthorpe
Sometimes you can do more and more work to try and be more and more general but this is *alot* of work and even then eventually hits problematic limits. Like what do you do with the sealing flags? That's ABI breaking if the successor does not support them, and downgrades make exactly that possible.
Quoted 6 lines
A CSPish user can do things like patch the new sealing flag into their current kernel (while preventing userspace from using it), ensure everything is updated to that, then jump ahead to a newer kernel and enjoy the new flag with full downgrade support. There is so much more control on their part that makes the problem far more managably simple that upstream does not get to have.
Quoted 4 lines
I guess maybe we have a different definition of ABI? I'm not saying that upstream has to be 100% forwards and backwards compatible. I'm saying the serialization payload itself should communicate what features are effectively required.
I strongly agree with Sean on this, like really really agree.
All you need is serializing *actions*. Make the destination a small interpreter not something that read structs. memfd/guest_memfd is already created by a bunch of actions, which are syscalls, so it shouldn't be hard to either come up with the actions or parse them in the destination.
An example matching (going by memory) what is now in place for memfd:
- memfd_create(name[], flags)
- memfd_map(folios[], index)
- memfd_finish(seals, pos, size, mode)
So:
#define MEMFD_LUO_CREATE 0
#define MEMFD_LUO_MAP 1
#define MEMFD_LUO_FINISH 2
struct memfd_luo_op {
/* 0 = end */
u32 size;
u32 op;
union {
struct {
u32 flags;
char name[];
} memfd_luo_create;
struct {
u32 flags;
} memfd_luo_secret;
struct {
u64 i_size;
u64 f_pos;
u32 f_seals;
u32 i_mode;
} memfd_luo_finish;
struct {
u64 index;
struct memfd_luo_folio src_folios[]; // whatever
} memfd_luo_map;
};
} __aligned(8);You write almost everything at prepare, just ensure there is room for finish and write that on freeze.
Want to move secret memfds? Sure they're different in underlying implementation but they can share LUO serialization format almost entirely. Make it a new op instead of create.. you have 4 billion possible ops, adding them isn't quite free but not too expensive either.
In fact memfd is the easy case, almost always you'll have a more complicated initialization sequence and a huge explosion of possibilities, but the good thing is that the kernel *already* has to initialize its data structures from actions. We're not quite serializing syscalls but pretty close, in fact for KVM a lot of code could be shared between ioctls and LUO receiving side.
It doesn't have to match exactly userspace, for example you wouldn't really need to transmit MFD_ALLOW_SEALING because it's implicit in the seals you transmit. That said, taking inspiration doesn't hurt; just remember to *always* validate unknown flags.
Quoted 5 lines
Quoted 2 lines
If it really succeeds at that and it becomes very popular, then let's discuss upstreaming doing additional version combinations.
Why on earth would we have version numbers in the first place? IMO, monotically increasing version numbers are flat out the worst way to communicate features.
This, too. KVM has been at API version 12 since 2007. It is not userspace compatible with 2007 vintage QEMU, because a couple misfeatures were removed after 10 years or so of waiting, so I guess technically it would be 15 or 16, but it doesn't matter because no one checks KVM_API_VERSION. If a ioctl works it works, if it doesn't you get a much better message than "KVM API version mismatch".
Quoted 8 lines
Quoted 3 lines
Okay, how about worse, todays kernel has hugetlbfs and there are patches around to luo serialize that. Lots and lots of talks about a post-hugetlbfs world out there.
And? Adding a compatibility layer to a future kernel so that it understands an incoming HugeTLBFS payload should be trivial. I can totally see not wanting to support serializing a post-HugeTBLFS kernel's memory representation into the "old" format, though even that probably wouldn't be all that difficult.
Yeah, hugetlbfs is an implementation detail *of the destination* not the source. The destination somehow needs to take the 1GB area and donate it to hugetlbfs. That's not the source's problem. All the source->destination ABI contains is MFD_HUGETLB and MFD_HUGE_*, which promise to the destination a certain alignment of all map requests.
Quoted 4 lines
Quoted 2 lines
Do we want to reject the hugetlbfs serialization until we have a year of debate outlining every possible ABI scenario? I also vote no.
That's a bit of a strawman argument. Is designing a forward-looking ABI easy?
No, but it's also not *that* hard if you have a half-decent userspace ABI.
Quoted 5 lines
Hard NAK. There will inevitably be boundaries that cannot be crossed, but I am not at all ok punting on downgrades. To me, that's basically saying "we want to add just enough support upstream so that it's not too painful to carry full support out-of-tree". That completely goes against the spirit of open source and upstream Linux, and I want no part of it.
100%. And I'll add, what happened to "we don't break userspace"? This does the intentional opposite in the hope that no one cares about using this feature upstream. Which in the long term hurts downstream forks as much as upstream.
Paolo