[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260114085201.3222597-5-gourry@gourry.net>
Date: Wed, 14 Jan 2026 03:51:56 -0500
From: Gregory Price <gourry@...rry.net>
To: linux-mm@...ck.org
Cc: linux-cxl@...r.kernel.org,
nvdimm@...ts.linux.dev,
linux-kernel@...r.kernel.org,
virtualization@...ts.linux.dev,
kernel-team@...a.com,
dan.j.williams@...el.com,
vishal.l.verma@...el.com,
dave.jiang@...el.com,
david@...nel.org,
mst@...hat.com,
jasowang@...hat.com,
xuanzhuo@...ux.alibaba.com,
eperezma@...hat.com,
osalvador@...e.de,
akpm@...ux-foundation.org
Subject: [PATCH 4/8] mm/memory_hotplug: return online type from add_memory_driver_managed()
Change add_memory_driver_managed() to return the online type (MMOP_*)
on success instead of 0. This allows callers to determine the actual
online state of the memory after addition, which is important when
MMOP_SYSTEM_DEFAULT is used and the actual online type depends on the
system default policy.
Update virtio_mem to handle the new return value semantics by checking
for rc < 0 to detect errors.
Signed-off-by: Gregory Price <gourry@...rry.net>
---
drivers/dax/kmem.c | 2 +-
drivers/virtio/virtio_mem.c | 5 +++--
mm/memory_hotplug.c | 4 +++-
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c
index 5e0cf94a9620..d0dd36c536a0 100644
--- a/drivers/dax/kmem.c
+++ b/drivers/dax/kmem.c
@@ -178,7 +178,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
range_len(&range), kmem_name, mhp_flags,
MMOP_SYSTEM_DEFAULT);
- if (rc) {
+ if (rc < 0) {
dev_warn(dev, "mapping%d: %#llx-%#llx memory add failed\n",
i, range.start, range.end);
remove_resource(res);
diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
index b1ec8f2b9e31..4decb44f5a43 100644
--- a/drivers/virtio/virtio_mem.c
+++ b/drivers/virtio/virtio_mem.c
@@ -656,15 +656,16 @@ static int virtio_mem_add_memory(struct virtio_mem *vm, uint64_t addr,
rc = add_memory_driver_managed(vm->mgid, addr, size, vm->resource_name,
MHP_MERGE_RESOURCE | MHP_NID_IS_MGID,
MMOP_SYSTEM_DEFAULT);
- if (rc) {
+ if (rc < 0) {
atomic64_sub(size, &vm->offline_size);
dev_warn(&vm->vdev->dev, "adding memory failed: %d\n", rc);
/*
* TODO: Linux MM does not properly clean up yet in all cases
* where adding of memory failed - especially on -ENOMEM.
*/
+ return rc;
}
- return rc;
+ return 0;
}
/*
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 515ff9d18039..41974a1ccb91 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1689,7 +1689,7 @@ EXPORT_SYMBOL_GPL(add_memory);
* MMOP_ONLINE_MOVABLE to online with that type, MMOP_OFFLINE to leave offline,
* or MMOP_SYSTEM_DEFAULT to use the system default policy.
*
- * Returns 0 on success, negative error code on failure.
+ * Returns the online type (MMOP_*) on success, negative error code on failure.
*/
int add_memory_driver_managed(int nid, u64 start, u64 size,
const char *resource_name, mhp_t mhp_flags,
@@ -1721,6 +1721,8 @@ int add_memory_driver_managed(int nid, u64 start, u64 size,
rc = __add_memory_resource(nid, res, mhp_flags, online_type);
if (rc < 0)
release_memory_resource(res);
+ else
+ rc = online_type;
out_unlock:
unlock_device_hotplug();
--
2.52.0
Powered by blists - more mailing lists