Re: [PATCH v3 6/7] mm/memblock: Use KSTATE instead of kho to preserve preserved_mem_table

Jason Gunthorpe
2025-09-15T11:47:12Z

On Tue, Sep 09, 2025 at 10:14:41PM +0200, Andrey Ryabinin wrote:
> +static int kstate_preserve_phys(struct kstate_stream *stream, void *obj,
> + const struct kstate_field *field)
> +{
> + struct reserve_mem_table *map = obj;
> +
> + return kho_preserve_phys(map->start, map->size);
> +}
> +
> +struct kstate_description kstate_reserve_mem = {
> + .name = "reserved_mem",
> + .id = KSTATE_RESERVED_MEM_ID,
> + .fields = (const struct kstate_field[]) {
> + KSTATE_BASE_TYPE(name, struct reserve_mem_table,
> + char[RESERVE_MEM_NAME_SIZE]),
> + KSTATE_BASE_TYPE(start, struct reserve_mem_table, phys_addr_t),
> + KSTATE_BASE_TYPE(size, struct reserve_mem_table, phys_addr_t),
> + {
> + .name = "phys_range",
> + .flags = KS_CUSTOM,
> + .save = kstate_preserve_phys,
> + },
> + KSTATE_END_OF_LIST(),
> + },
> +};
>
> static int __init reserve_mem_init(void)
> {
> int err;
> + int i;
>
> if (!kho_is_enabled() || !reserved_mem_count)
> return 0;
>
> + for (i = 0; i < reserved_mem_count; i++) {
> + struct reserve_mem_table *map = &reserved_mem_table[i];
>
> + err = kstate_register(&kstate_reserve_mem,
> + map, crc32(~0, map->name, RESERVE_MEM_NAME_SIZE));
> + if (err)
> + goto out;
> }

As I've said to the other proposals, this doesn't seem to be bringing
that much value compared to just using a normal struct:

for (i = 0; i < reserved_mem_count; i++) {
struct reserve_mem_table *map = &reserved_mem_table[i];
struct khoser_reserve_mem_table abi_map = {.name = map->name. .start = map->start, .size = map->size};

err = kho_preserve_phys(map->start, map->size);
if (err)
return err; // Should unwind the other preservations!

luo_preserve_key(luo_obj, map->name, &abi_map, sizeof(abi_map), VERSION_0);
}

Jason