Skip to content

Commit

Permalink
vhost-user: don't merge regions with different fds
Browse files Browse the repository at this point in the history
vhost currently merges regions with contiguious virtual and physical
addresses.  This breaks for vhost-user since that also needs fds to
match.

Add a vhost_ops entry to compare the fds for vhost-user only.

Cc: qemu-stable@nongnu.org
Cc: Victor Kaplansky <victork@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit ffe42cc)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
mstsirkin authored and mdroth committed Mar 17, 2016
1 parent 3092979 commit 9ae0217
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hw/virtio/vhost-user.c
Expand Up @@ -612,6 +612,25 @@ static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr)
return -1;
}

static bool vhost_user_can_merge(struct vhost_dev *dev,
uint64_t start1, uint64_t size1,
uint64_t start2, uint64_t size2)
{
ram_addr_t ram_addr;
int mfd, rfd;
MemoryRegion *mr;

mr = qemu_ram_addr_from_host((void *)(uintptr_t)start1, &ram_addr);
assert(mr);
mfd = qemu_get_ram_fd(ram_addr);

mr = qemu_ram_addr_from_host((void *)(uintptr_t)start2, &ram_addr);
assert(mr);
rfd = qemu_get_ram_fd(ram_addr);

return mfd == rfd;
}

const VhostOps user_ops = {
.backend_type = VHOST_BACKEND_TYPE_USER,
.vhost_backend_init = vhost_user_init,
Expand All @@ -634,4 +653,5 @@ const VhostOps user_ops = {
.vhost_set_vring_enable = vhost_user_set_vring_enable,
.vhost_requires_shm_log = vhost_user_requires_shm_log,
.vhost_migration_done = vhost_user_migration_done,
.vhost_backend_can_merge = vhost_user_can_merge,
};
7 changes: 7 additions & 0 deletions hw/virtio/vhost.c
Expand Up @@ -259,6 +259,13 @@ static void vhost_dev_assign_memory(struct vhost_dev *dev,
continue;
}

if (dev->vhost_ops->vhost_backend_can_merge &&
!dev->vhost_ops->vhost_backend_can_merge(dev, uaddr, size,
reg->userspace_addr,
reg->memory_size)) {
continue;
}

if (merged) {
--to;
assert(to >= 0);
Expand Down
4 changes: 4 additions & 0 deletions include/hw/virtio/vhost-backend.h
Expand Up @@ -70,6 +70,9 @@ typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev,
typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
typedef int (*vhost_migration_done_op)(struct vhost_dev *dev,
char *mac_addr);
typedef bool (*vhost_backend_can_merge_op)(struct vhost_dev *dev,
uint64_t start1, uint64_t size1,
uint64_t start2, uint64_t size2);

typedef struct VhostOps {
VhostBackendType backend_type;
Expand Down Expand Up @@ -97,6 +100,7 @@ typedef struct VhostOps {
vhost_set_vring_enable_op vhost_set_vring_enable;
vhost_requires_shm_log_op vhost_requires_shm_log;
vhost_migration_done_op vhost_migration_done;
vhost_backend_can_merge_op vhost_backend_can_merge;
} VhostOps;

extern const VhostOps user_ops;
Expand Down

0 comments on commit 9ae0217

Please sign in to comment.