vhost-user: fix duplicated notifier MR init

In case of device resume after suspend, VQ notifier MR still valid.
Duplicated registrations explode memory block list and slow down device
resume.

Fixes: 44866521bd ("vhost-user: support registering external host notifiers")
Cc: tiwei.bie@intel.com
Cc: qemu-stable@nongnu.org
Cc: Yuwei Zhang <zhangyuwei.9149@bytedance.com>

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
Message-Id: <20211008080215.590292-1-xuemingl@nvidia.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Xueming Li 2021-10-08 16:02:15 +08:00 committed by Michael S. Tsirkin
parent c47d4fa0c8
commit a1ed9ef1de

View File

@ -1526,8 +1526,9 @@ static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev,
name = g_strdup_printf("vhost-user/host-notifier@%p mmaps[%d]", name = g_strdup_printf("vhost-user/host-notifier@%p mmaps[%d]",
user, queue_idx); user, queue_idx);
memory_region_init_ram_device_ptr(&n->mr, OBJECT(vdev), name, if (!n->mr.ram) /* Don't init again after suspend. */
page_size, addr); memory_region_init_ram_device_ptr(&n->mr, OBJECT(vdev), name,
page_size, addr);
g_free(name); g_free(name);
if (virtio_queue_set_host_notifier_mr(vdev, queue_idx, &n->mr, true)) { if (virtio_queue_set_host_notifier_mr(vdev, queue_idx, &n->mr, true)) {