kvm tools: Fix VHOST_SET_MEM_TABLE failure
PATCH 1/2 kvm tools: Fix VHOST_SET_MEM_TABLE failure
VHOST_SET_MEM_TABLE failed: Operation not supported
In vhost_set_memory(), We have
if (mem.padding)
return -EOPNOTSUPP;So, we need to zero struct vhost_memory.
Signed-off-by Asias He <[email protected]>
--- tools/kvm/virtio/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/kvm/virtio/net.c +1 -1
@@ -471,7 +471,7 @@ static void virtio_net__vhost_init(struct kvm *kvm, struct net_dev *ndev)if (ndev->vhost_fd <0 )die_perror ("Failed openning vhost-net device" ); - mem =malloc (sizeof (*mem) +sizeof (struct vhost_memory_region )); + mem =calloc (1 ,sizeof (*mem) +sizeof (struct vhost_memory_region ));if (mem ==NULL )die ("Failed allocating memory for vhost memory map" );
Signature · 1 line
1.7.10.4
PATCH 2/2 kvm tools: Do not poll ioeventfd if vhost is enabled
If vhost is enabled for a virtio device, vhost will poll the ioeventfd in kernel side and there is no need to poll it in userspace. Otherwise, both vhost kernel and userspace will race to poll.
Signed-off-by Asias He <[email protected]>
--- tools/kvm/include/kvm/ioeventfd.h | 2 +- tools/kvm/ioeventfd.c | 5 ++++- tools/kvm/virtio/mmio.c | 10 +++++++++- tools/kvm/virtio/pci.c | 10 +++++++++- 4 files changed, 23 insertions(+), 4 deletions(-)
tools/kvm/include/kvm/ioeventfd.h +1 -1
@@ -22,7 +22,7 @@ struct ioevent {int ioeventfd__init (struct kvm *kvm);int ioeventfd__exit (struct kvm *kvm); -int ioeventfd__add_event (struct ioevent *ioevent,bool is_pio); +int ioeventfd__add_event (struct ioevent *ioevent,bool is_pio,bool poll_in_userspace);int ioeventfd__del_event (u64 addr,u64 datamatch);#endif
tools/kvm/ioeventfd.c +4 -1
@@ -117,7 +117,7 @@ int ioeventfd__exit(struct kvm *kvm)return 0 ; } -int ioeventfd__add_event (struct ioevent *ioevent,bool is_pio) +int ioeventfd__add_event (struct ioevent *ioevent,bool is_pio,bool poll_in_userspace) {struct kvm_ioeventfd kvm_ioevent;struct epoll_event epoll_event;
@@ -151,6 +151,9 @@ int ioeventfd__add_event(struct ioevent *ioevent, bool is_pio) goto cleanup; } +if (!poll_in_userspace) +return 0 ; + epoll_event = (struct epoll_event ) { .events =EPOLLIN , .data.ptr = new_ioevent,
tools/kvm/virtio/mmio.c +9 -1
@@ -48,7 +48,15 @@ static int virtio_mmio_init_ioeventfd(struct kvm *kvm, .fd = eventfd(0, 0), }; - err =ioeventfd__add_event (&ioevent, false); +if (vdev->ops->notify_vq_eventfd) +/* +* Vhost will poll the eventfd in host kernel side, +* no need to poll in userspace. +*/ + err =ioeventfd__add_event (&ioevent, true, false); +else +/* Need to poll in userspace. */ + err =ioeventfd__add_event (&ioevent, true, true);if (err)return err;
tools/kvm/virtio/pci.c +9 -1
@@ -40,7 +40,15 @@ static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_device *vde .fd = eventfd(0, 0), }; - r =ioeventfd__add_event (&ioevent, true); +if (vdev->ops->notify_vq_eventfd) +/* +* Vhost will poll the eventfd in host kernel side, +* no need to poll in userspace. +*/ + r =ioeventfd__add_event (&ioevent, true, false); +else +/* Need to poll in userspace. */ + r =ioeventfd__add_event (&ioevent, true, true);if (r)return r;
Signature · 1 line
1.7.10.4