aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Brucker <jean-philippe@linaro.org>2023-06-06 14:04:12 +0100
committerWill Deacon <will@kernel.org>2023-06-08 22:39:03 +0100
commit676c0c8ad95bff2f1aa77f2899aa9ee13f66c7a1 (patch)
treebf52bd5b35eaedca787ab2ed1bf3e1d053242076
parent745221e582f7c81ff2911599d2620ac541d0f671 (diff)
downloadkvmtool-676c0c8ad95bff2f1aa77f2899aa9ee13f66c7a1.tar.gz
virtio/vhost: Factor notify_vq_eventfd()
All vhost devices perform the same operation when setting up the ioeventfd. Move it to virtio/vhost.c Reviewed-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Link: https://lore.kernel.org/r/20230606130426.978945-4-jean-philippe@linaro.org Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r--include/kvm/virtio.h2
-rw-r--r--virtio/net.c9
-rw-r--r--virtio/scsi.c9
-rw-r--r--virtio/vhost.c14
-rw-r--r--virtio/vsock.c14
5 files changed, 20 insertions, 28 deletions
diff --git a/include/kvm/virtio.h b/include/kvm/virtio.h
index daea8554..6912875e 100644
--- a/include/kvm/virtio.h
+++ b/include/kvm/virtio.h
@@ -261,6 +261,8 @@ void virtio_notify_status(struct kvm *kvm, struct virtio_device *vdev,
void virtio_vhost_init(struct kvm *kvm, int vhost_fd);
void virtio_vhost_set_vring(struct kvm *kvm, int vhost_fd, u32 index,
struct virt_queue *queue);
+void virtio_vhost_set_vring_kick(struct kvm *kvm, int vhost_fd,
+ u32 index, int event_fd);
int virtio_transport_parser(const struct option *opt, const char *arg, int unset);
diff --git a/virtio/net.c b/virtio/net.c
index b7c64a08..c0871163 100644
--- a/virtio/net.c
+++ b/virtio/net.c
@@ -701,18 +701,11 @@ static void notify_vq_gsi(struct kvm *kvm, void *dev, u32 vq, u32 gsi)
static void notify_vq_eventfd(struct kvm *kvm, void *dev, u32 vq, u32 efd)
{
struct net_dev *ndev = dev;
- struct vhost_vring_file file = {
- .index = vq,
- .fd = efd,
- };
- int r;
if (ndev->vhost_fd == 0 || is_ctrl_vq(ndev, vq))
return;
- r = ioctl(ndev->vhost_fd, VHOST_SET_VRING_KICK, &file);
- if (r < 0)
- die_perror("VHOST_SET_VRING_KICK failed");
+ virtio_vhost_set_vring_kick(kvm, ndev->vhost_fd, vq, efd);
}
static int notify_vq(struct kvm *kvm, void *dev, u32 vq)
diff --git a/virtio/scsi.c b/virtio/scsi.c
index 6aa0909f..ebddec36 100644
--- a/virtio/scsi.c
+++ b/virtio/scsi.c
@@ -121,18 +121,11 @@ static void notify_vq_gsi(struct kvm *kvm, void *dev, u32 vq, u32 gsi)
static void notify_vq_eventfd(struct kvm *kvm, void *dev, u32 vq, u32 efd)
{
struct scsi_dev *sdev = dev;
- struct vhost_vring_file file = {
- .index = vq,
- .fd = efd,
- };
- int r;
if (sdev->vhost_fd == 0)
return;
- r = ioctl(sdev->vhost_fd, VHOST_SET_VRING_KICK, &file);
- if (r < 0)
- die_perror("VHOST_SET_VRING_KICK failed");
+ virtio_vhost_set_vring_kick(kvm, sdev->vhost_fd, vq, efd);
}
static int notify_vq(struct kvm *kvm, void *dev, u32 vq)
diff --git a/virtio/vhost.c b/virtio/vhost.c
index afe37465..3acfd30a 100644
--- a/virtio/vhost.c
+++ b/virtio/vhost.c
@@ -65,3 +65,17 @@ void virtio_vhost_set_vring(struct kvm *kvm, int vhost_fd, u32 index,
if (r < 0)
die_perror("VHOST_SET_VRING_ADDR failed");
}
+
+void virtio_vhost_set_vring_kick(struct kvm *kvm, int vhost_fd,
+ u32 index, int event_fd)
+{
+ int r;
+ struct vhost_vring_file file = {
+ .index = index,
+ .fd = event_fd,
+ };
+
+ r = ioctl(vhost_fd, VHOST_SET_VRING_KICK, &file);
+ if (r < 0)
+ die_perror("VHOST_SET_VRING_KICK failed");
+}
diff --git a/virtio/vsock.c b/virtio/vsock.c
index 2f7906f2..0ada9e09 100644
--- a/virtio/vsock.c
+++ b/virtio/vsock.c
@@ -80,21 +80,11 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq)
static void notify_vq_eventfd(struct kvm *kvm, void *dev, u32 vq, u32 efd)
{
struct vsock_dev *vdev = dev;
- struct vhost_vring_file file = {
- .index = vq,
- .fd = efd,
- };
- int r;
- if (is_event_vq(vq))
- return;
-
- if (vdev->vhost_fd == -1)
+ if (vdev->vhost_fd == -1 || is_event_vq(vq))
return;
- r = ioctl(vdev->vhost_fd, VHOST_SET_VRING_KICK, &file);
- if (r < 0)
- die_perror("VHOST_SET_VRING_KICK failed");
+ virtio_vhost_set_vring_kick(kvm, vdev->vhost_fd, vq, efd);
}
static void notify_status(struct kvm *kvm, void *dev, u32 status)