Commit ffaa6ce8 authored by David Hildenbrand's avatar David Hildenbrand Committed by Linus Torvalds

virtio-mem: use a single dynamic memory group for a single virtio-mem device

Let's use a single dynamic memory group.

Link: https://lkml.kernel.org/r/20210806124715.17090-8-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hui Zhu <teawater@gmail.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Len Brown <lenb@kernel.org>
Cc: Marek Kedzierski <mkedzier@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent eedf634a
...@@ -143,6 +143,8 @@ struct virtio_mem { ...@@ -143,6 +143,8 @@ struct virtio_mem {
* add_memory_driver_managed(). * add_memory_driver_managed().
*/ */
const char *resource_name; const char *resource_name;
/* Memory group identification. */
int mgid;
/* /*
* We don't want to add too much memory if it's not getting onlined, * We don't want to add too much memory if it's not getting onlined,
...@@ -626,8 +628,8 @@ static int virtio_mem_add_memory(struct virtio_mem *vm, uint64_t addr, ...@@ -626,8 +628,8 @@ static int virtio_mem_add_memory(struct virtio_mem *vm, uint64_t addr,
addr + size - 1); addr + size - 1);
/* Memory might get onlined immediately. */ /* Memory might get onlined immediately. */
atomic64_add(size, &vm->offline_size); atomic64_add(size, &vm->offline_size);
rc = add_memory_driver_managed(vm->nid, addr, size, vm->resource_name, rc = add_memory_driver_managed(vm->mgid, addr, size, vm->resource_name,
MHP_MERGE_RESOURCE); MHP_MERGE_RESOURCE | MHP_NID_IS_MGID);
if (rc) { if (rc) {
atomic64_sub(size, &vm->offline_size); atomic64_sub(size, &vm->offline_size);
dev_warn(&vm->vdev->dev, "adding memory failed: %d\n", rc); dev_warn(&vm->vdev->dev, "adding memory failed: %d\n", rc);
...@@ -2569,6 +2571,7 @@ static bool virtio_mem_has_memory_added(struct virtio_mem *vm) ...@@ -2569,6 +2571,7 @@ static bool virtio_mem_has_memory_added(struct virtio_mem *vm)
static int virtio_mem_probe(struct virtio_device *vdev) static int virtio_mem_probe(struct virtio_device *vdev)
{ {
struct virtio_mem *vm; struct virtio_mem *vm;
uint64_t unit_pages;
int rc; int rc;
BUILD_BUG_ON(sizeof(struct virtio_mem_req) != 24); BUILD_BUG_ON(sizeof(struct virtio_mem_req) != 24);
...@@ -2603,6 +2606,16 @@ static int virtio_mem_probe(struct virtio_device *vdev) ...@@ -2603,6 +2606,16 @@ static int virtio_mem_probe(struct virtio_device *vdev)
if (rc) if (rc)
goto out_del_vq; goto out_del_vq;
/* use a single dynamic memory group to cover the whole memory device */
if (vm->in_sbm)
unit_pages = PHYS_PFN(memory_block_size_bytes());
else
unit_pages = PHYS_PFN(vm->bbm.bb_size);
rc = memory_group_register_dynamic(vm->nid, unit_pages);
if (rc < 0)
goto out_del_resource;
vm->mgid = rc;
/* /*
* If we still have memory plugged, we have to unplug all memory first. * If we still have memory plugged, we have to unplug all memory first.
* Registering our parent resource makes sure that this memory isn't * Registering our parent resource makes sure that this memory isn't
...@@ -2617,7 +2630,7 @@ static int virtio_mem_probe(struct virtio_device *vdev) ...@@ -2617,7 +2630,7 @@ static int virtio_mem_probe(struct virtio_device *vdev)
vm->memory_notifier.notifier_call = virtio_mem_memory_notifier_cb; vm->memory_notifier.notifier_call = virtio_mem_memory_notifier_cb;
rc = register_memory_notifier(&vm->memory_notifier); rc = register_memory_notifier(&vm->memory_notifier);
if (rc) if (rc)
goto out_del_resource; goto out_unreg_group;
rc = register_virtio_mem_device(vm); rc = register_virtio_mem_device(vm);
if (rc) if (rc)
goto out_unreg_mem; goto out_unreg_mem;
...@@ -2631,6 +2644,8 @@ static int virtio_mem_probe(struct virtio_device *vdev) ...@@ -2631,6 +2644,8 @@ static int virtio_mem_probe(struct virtio_device *vdev)
return 0; return 0;
out_unreg_mem: out_unreg_mem:
unregister_memory_notifier(&vm->memory_notifier); unregister_memory_notifier(&vm->memory_notifier);
out_unreg_group:
memory_group_unregister(vm->mgid);
out_del_resource: out_del_resource:
virtio_mem_delete_resource(vm); virtio_mem_delete_resource(vm);
out_del_vq: out_del_vq:
...@@ -2695,6 +2710,7 @@ static void virtio_mem_remove(struct virtio_device *vdev) ...@@ -2695,6 +2710,7 @@ static void virtio_mem_remove(struct virtio_device *vdev)
} else { } else {
virtio_mem_delete_resource(vm); virtio_mem_delete_resource(vm);
kfree_const(vm->resource_name); kfree_const(vm->resource_name);
memory_group_unregister(vm->mgid);
} }
/* remove all tracking data - no locking needed */ /* remove all tracking data - no locking needed */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment