Re: [PATCH 4/8] mm/memory_hotplug: export mhp_get_default_online_type

David Hildenbrand (Arm)
2026-04-13T15:18:29Z

On 3/21/26 16:04, Gregory Price wrote:
> Drivers which may pass hotplug policy down to DAX need MMOP_ symbols
> and the mhp_get_default_online_type function for hotplug use cases.
>
> Some drivers (cxl) co-mingle their hotplug and devdax use-cases into
> the same driver code, and chose the dax_kmem path as the default driver
> path - making it difficult to require hotplug as a predicate to building
> the overall driver (it may break other non-hotplug use-cases).
>
> Export mhp_get_default_online_type function to allow these drivers to
> build when hotplug is disabled and still use the DAX use case.
>
> In the built-out case we simply return MMOP_OFFLINE as it's
> non-destructive. The internal function can never return -1 either,
> so we choose this to allow for defining the function with 'enum mmop'.
>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> ---
> include/linux/memory_hotplug.h | 29 +++++++++++++++++++++++++++++
> mm/memory_hotplug.c | 1 +
> 2 files changed, 30 insertions(+)
>
> diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
> index e77ef3d7ff73..a8bcb36f93b8 100644
> --- a/include/linux/memory_hotplug.h
> +++ b/include/linux/memory_hotplug.h
> @@ -6,6 +6,7 @@
> #include <linux/spinlock.h>
> #include <linux/notifier.h>
> #include <linux/bug.h>
> +#include <linux/errno.h>
>
> struct page;
> struct zone;
> @@ -28,6 +29,27 @@ enum mmop {
> MMOP_ONLINE_MOVABLE,
> };
>
> +/**
> + * mmop_to_str - convert memory online type to string
> + * @online_type: the MMOP_* value to convert
> + *
> + * Returns a string representation of the memory online type,
> + * suitable for sysfs output (includes trailing newline).
> + */
> +static inline const char *mmop_to_str(enum mmop online_type)
> +{
> + switch (online_type) {
> + case MMOP_ONLINE:
> + return "online\n";
> + case MMOP_ONLINE_KERNEL:
> + return "online_kernel\n";
> + case MMOP_ONLINE_MOVABLE:
> + return "online_movable\n";
> + default:
> + return "offline\n";
> + }
> +}

In drivers/base/memory.c we have online_type_to_str[]. Likely you should
build upon that, and locate the code in there as well (or move all of
that to the same header). And call the function something matching like
mhp_online_type_to_str().

But, the patch description only spells out exporting
mhp_get_default_online_type(), so something is missing here why these
changes are even included in this patch.

--
Cheers,

David