All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] virtio: support extra per-buffer context
@ 2017-03-29 20:48 Michael S. Tsirkin
  2017-03-29 20:48   ` Michael S. Tsirkin
                   ` (5 more replies)
  0 siblings, 6 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Fastabend

virtio net is resorting to hacks in order to fit all per-buffer info in a
single 64 bit value. But in fact we have some unused memory there - normally
used for indirect descriptors - that we can utilize without slowing everyone
down.

Add APIs to do exactly that, and use them to simplify mergeable
buffer handling code.

This will also easily enable switching XDP mode on/off without doing device
resets (leading to packet drops), and more optimizations.

Michael S. Tsirkin (6):
  virtio: wrap find_vqs
  virtio: add context flag to find vqs
  virtio: allow extra context per descriptor
  virtio_net: allow specifying context for rx
  virtio_net: rework mergeable buffer handling
  virtio_net: reduce alignment for buffers

 drivers/block/virtio_blk.c                 |   3 +-
 drivers/char/virtio_console.c              |   6 +-
 drivers/crypto/virtio/virtio_crypto_core.c |   3 +-
 drivers/gpu/drm/virtio/virtgpu_kms.c       |   3 +-
 drivers/misc/mic/vop/vop_main.c            |   9 ++-
 drivers/net/caif/caif_virtio.c             |   3 +-
 drivers/net/virtio_net.c                   | 116 ++++++++++++++---------------
 drivers/rpmsg/virtio_rpmsg_bus.c           |   2 +-
 drivers/s390/virtio/kvm_virtio.c           |   6 +-
 drivers/s390/virtio/virtio_ccw.c           |   7 +-
 drivers/scsi/virtio_scsi.c                 |   3 +-
 drivers/virtio/virtio_balloon.c            |   3 +-
 drivers/virtio/virtio_input.c              |   3 +-
 drivers/virtio/virtio_mmio.c               |   8 +-
 drivers/virtio/virtio_pci_common.c         |  18 +++--
 drivers/virtio/virtio_pci_common.h         |   4 +-
 drivers/virtio/virtio_pci_legacy.c         |   4 +-
 drivers/virtio/virtio_pci_modern.c         |  12 ++-
 drivers/virtio/virtio_ring.c               |  77 +++++++++++++++----
 include/linux/virtio.h                     |   9 +++
 include/linux/virtio_config.h              |  25 ++++++-
 include/linux/virtio_ring.h                |   3 +
 net/vmw_vsock/virtio_transport.c           |   6 +-
 23 files changed, 212 insertions(+), 121 deletions(-)

-- 
MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* [PATCH 1/6] virtio: wrap find_vqs
  2017-03-29 20:48 [PATCH 0/6] virtio: support extra per-buffer context Michael S. Tsirkin
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  2017-03-29 20:48   ` Michael S. Tsirkin
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel
  Cc: John Fastabend, Jason Wang, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Gonglei, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev,
	linux-remoteproc, linux-scsi, kvm

We are going to add more parameters to find_vqs, let's wrap the call so
we don't need to tweak all drivers every time.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/block/virtio_blk.c                 | 3 +--
 drivers/char/virtio_console.c              | 6 +++---
 drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
 drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
 drivers/net/caif/caif_virtio.c             | 3 +--
 drivers/net/virtio_net.c                   | 3 +--
 drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
 drivers/scsi/virtio_scsi.c                 | 3 +--
 drivers/virtio/virtio_balloon.c            | 3 +--
 drivers/virtio/virtio_input.c              | 3 +--
 include/linux/virtio_config.h              | 9 +++++++++
 net/vmw_vsock/virtio_transport.c           | 6 +++---
 12 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 1d4c9f8..c08c30c 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -455,8 +455,7 @@ static int init_vq(struct virtio_blk *vblk)
 	}
 
 	/* Discover virtqueues and write information to configuration.  */
-	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
-			&desc);
+	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
 	if (err)
 		goto out;
 
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index e9b7e0b..5da4c8e 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1945,9 +1945,9 @@ static int init_vqs(struct ports_device *portdev)
 		}
 	}
 	/* Find the queues. */
-	err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
-					      io_callbacks,
-					      (const char **)io_names, NULL);
+	err = virtio_find_vqs(portdev->vdev, nr_queues, vqs,
+			      io_callbacks,
+			      (const char **)io_names, NULL);
 	if (err)
 		goto free;
 
diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
index 21472e4..a111cd72 100644
--- a/drivers/crypto/virtio/virtio_crypto_core.c
+++ b/drivers/crypto/virtio/virtio_crypto_core.c
@@ -119,8 +119,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
 		names[i] = vi->data_vq[i].name;
 	}
 
-	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
-					 names, NULL);
+	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
 	if (ret)
 		goto err_find;
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
index 4918668..1e1c90b 100644
--- a/drivers/gpu/drm/virtio/virtgpu_kms.c
+++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -175,8 +175,7 @@ int virtio_gpu_driver_load(struct drm_device *dev, unsigned long flags)
 	DRM_INFO("virgl 3d acceleration not supported by guest\n");
 #endif
 
-	ret = vgdev->vdev->config->find_vqs(vgdev->vdev, 2, vqs,
-					    callbacks, names, NULL);
+	ret = virtio_find_vqs(vgdev->vdev, 2, vqs, callbacks, names, NULL);
 	if (ret) {
 		DRM_ERROR("failed to find virt queues\n");
 		goto err_vqs;
diff --git a/drivers/net/caif/caif_virtio.c b/drivers/net/caif/caif_virtio.c
index bc0eb47..6122768 100644
--- a/drivers/net/caif/caif_virtio.c
+++ b/drivers/net/caif/caif_virtio.c
@@ -679,8 +679,7 @@ static int cfv_probe(struct virtio_device *vdev)
 		goto err;
 
 	/* Get the TX virtio ring. This is a "guest side vring". */
-	err = vdev->config->find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names,
-			NULL);
+	err = virtio_find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names, NULL);
 	if (err)
 		goto err;
 
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ea9890d..6802169 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2079,8 +2079,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 		names[txq2vq(i)] = vi->sq[i].name;
 	}
 
-	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
-					 names, NULL);
+	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
 	if (ret)
 		goto err_find;
 
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 5e66e08..f7cade0 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -869,7 +869,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
 	init_waitqueue_head(&vrp->sendq);
 
 	/* We expect two virtqueues, rx and tx (and in this order) */
-	err = vdev->config->find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
+	err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
 	if (err)
 		goto free_vrp;
 
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 939c47d..e9222dc 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -870,8 +870,7 @@ static int virtscsi_init(struct virtio_device *vdev,
 	}
 
 	/* Discover virtqueues and write information to configuration.  */
-	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
-			&desc);
+	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
 	if (err)
 		goto out;
 
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 34adf9b..408c174 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -418,8 +418,7 @@ static int init_vqs(struct virtio_balloon *vb)
 	 * optionally stat.
 	 */
 	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2;
-	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names,
-			NULL);
+	err = virtio_find_vqs(vb->vdev, nvqs, vqs, callbacks, names, NULL);
 	if (err)
 		return err;
 
diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
index 79f1293..3a0468f 100644
--- a/drivers/virtio/virtio_input.c
+++ b/drivers/virtio/virtio_input.c
@@ -173,8 +173,7 @@ static int virtinput_init_vqs(struct virtio_input *vi)
 	static const char * const names[] = { "events", "status" };
 	int err;
 
-	err = vi->vdev->config->find_vqs(vi->vdev, 2, vqs, cbs, names,
-			NULL);
+	err = virtio_find_vqs(vi->vdev, 2, vqs, cbs, names, NULL);
 	if (err)
 		return err;
 	vi->evt = vqs[0];
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 8355bab..47f3d80 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -179,6 +179,15 @@ struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,
 	return vq;
 }
 
+static inline
+int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
+			struct virtqueue *vqs[], vq_callback_t *callbacks[],
+			const char * const names[],
+			struct irq_affinity *desc)
+{
+	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
+}
+
 /**
  * virtio_device_ready - enable vq use in probe function
  * @vdev: the device
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 68675a1..97e26e2 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -573,9 +573,9 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 
 	vsock->vdev = vdev;
 
-	ret = vsock->vdev->config->find_vqs(vsock->vdev, VSOCK_VQ_MAX,
-					    vsock->vqs, callbacks, names,
-					    NULL);
+	ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX,
+			      vsock->vqs, callbacks, names,
+			      NULL);
 	if (ret < 0)
 		goto out;
 
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 1/6] virtio: wrap find_vqs
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel
  Cc: Dmitry Tarnyagin, kvm, David Airlie, linux-remoteproc, dri-devel,
	Bjorn Andersson, James E.J. Bottomley, Herbert Xu, linux-scsi,
	John Fastabend, Arnd Bergmann, Amit Shah, Stefan Hajnoczi,
	virtualization, Martin K. Petersen, Greg Kroah-Hartman,
	linux-crypto, netdev, David S. Miller

We are going to add more parameters to find_vqs, let's wrap the call so
we don't need to tweak all drivers every time.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/block/virtio_blk.c                 | 3 +--
 drivers/char/virtio_console.c              | 6 +++---
 drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
 drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
 drivers/net/caif/caif_virtio.c             | 3 +--
 drivers/net/virtio_net.c                   | 3 +--
 drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
 drivers/scsi/virtio_scsi.c                 | 3 +--
 drivers/virtio/virtio_balloon.c            | 3 +--
 drivers/virtio/virtio_input.c              | 3 +--
 include/linux/virtio_config.h              | 9 +++++++++
 net/vmw_vsock/virtio_transport.c           | 6 +++---
 12 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 1d4c9f8..c08c30c 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -455,8 +455,7 @@ static int init_vq(struct virtio_blk *vblk)
 	}
 
 	/* Discover virtqueues and write information to configuration.  */
-	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
-			&desc);
+	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
 	if (err)
 		goto out;
 
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index e9b7e0b..5da4c8e 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1945,9 +1945,9 @@ static int init_vqs(struct ports_device *portdev)
 		}
 	}
 	/* Find the queues. */
-	err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
-					      io_callbacks,
-					      (const char **)io_names, NULL);
+	err = virtio_find_vqs(portdev->vdev, nr_queues, vqs,
+			      io_callbacks,
+			      (const char **)io_names, NULL);
 	if (err)
 		goto free;
 
diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
index 21472e4..a111cd72 100644
--- a/drivers/crypto/virtio/virtio_crypto_core.c
+++ b/drivers/crypto/virtio/virtio_crypto_core.c
@@ -119,8 +119,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
 		names[i] = vi->data_vq[i].name;
 	}
 
-	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
-					 names, NULL);
+	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
 	if (ret)
 		goto err_find;
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
index 4918668..1e1c90b 100644
--- a/drivers/gpu/drm/virtio/virtgpu_kms.c
+++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -175,8 +175,7 @@ int virtio_gpu_driver_load(struct drm_device *dev, unsigned long flags)
 	DRM_INFO("virgl 3d acceleration not supported by guest\n");
 #endif
 
-	ret = vgdev->vdev->config->find_vqs(vgdev->vdev, 2, vqs,
-					    callbacks, names, NULL);
+	ret = virtio_find_vqs(vgdev->vdev, 2, vqs, callbacks, names, NULL);
 	if (ret) {
 		DRM_ERROR("failed to find virt queues\n");
 		goto err_vqs;
diff --git a/drivers/net/caif/caif_virtio.c b/drivers/net/caif/caif_virtio.c
index bc0eb47..6122768 100644
--- a/drivers/net/caif/caif_virtio.c
+++ b/drivers/net/caif/caif_virtio.c
@@ -679,8 +679,7 @@ static int cfv_probe(struct virtio_device *vdev)
 		goto err;
 
 	/* Get the TX virtio ring. This is a "guest side vring". */
-	err = vdev->config->find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names,
-			NULL);
+	err = virtio_find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names, NULL);
 	if (err)
 		goto err;
 
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ea9890d..6802169 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2079,8 +2079,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 		names[txq2vq(i)] = vi->sq[i].name;
 	}
 
-	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
-					 names, NULL);
+	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
 	if (ret)
 		goto err_find;
 
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 5e66e08..f7cade0 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -869,7 +869,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
 	init_waitqueue_head(&vrp->sendq);
 
 	/* We expect two virtqueues, rx and tx (and in this order) */
-	err = vdev->config->find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
+	err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
 	if (err)
 		goto free_vrp;
 
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 939c47d..e9222dc 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -870,8 +870,7 @@ static int virtscsi_init(struct virtio_device *vdev,
 	}
 
 	/* Discover virtqueues and write information to configuration.  */
-	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
-			&desc);
+	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
 	if (err)
 		goto out;
 
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 34adf9b..408c174 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -418,8 +418,7 @@ static int init_vqs(struct virtio_balloon *vb)
 	 * optionally stat.
 	 */
 	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2;
-	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names,
-			NULL);
+	err = virtio_find_vqs(vb->vdev, nvqs, vqs, callbacks, names, NULL);
 	if (err)
 		return err;
 
diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
index 79f1293..3a0468f 100644
--- a/drivers/virtio/virtio_input.c
+++ b/drivers/virtio/virtio_input.c
@@ -173,8 +173,7 @@ static int virtinput_init_vqs(struct virtio_input *vi)
 	static const char * const names[] = { "events", "status" };
 	int err;
 
-	err = vi->vdev->config->find_vqs(vi->vdev, 2, vqs, cbs, names,
-			NULL);
+	err = virtio_find_vqs(vi->vdev, 2, vqs, cbs, names, NULL);
 	if (err)
 		return err;
 	vi->evt = vqs[0];
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 8355bab..47f3d80 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -179,6 +179,15 @@ struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,
 	return vq;
 }
 
+static inline
+int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
+			struct virtqueue *vqs[], vq_callback_t *callbacks[],
+			const char * const names[],
+			struct irq_affinity *desc)
+{
+	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
+}
+
 /**
  * virtio_device_ready - enable vq use in probe function
  * @vdev: the device
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 68675a1..97e26e2 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -573,9 +573,9 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 
 	vsock->vdev = vdev;
 
-	ret = vsock->vdev->config->find_vqs(vsock->vdev, VSOCK_VQ_MAX,
-					    vsock->vqs, callbacks, names,
-					    NULL);
+	ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX,
+			      vsock->vqs, callbacks, names,
+			      NULL);
 	if (ret < 0)
 		goto out;
 
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 2/6] virtio: add context flag to find vqs
  2017-03-29 20:48 [PATCH 0/6] virtio: support extra per-buffer context Michael S. Tsirkin
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  2017-03-29 20:48   ` Michael S. Tsirkin
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel
  Cc: John Fastabend, Sudeep Dutt, Ashutosh Dixit,
	Christian Borntraeger, Cornelia Huck, Martin Schwidefsky,
	Heiko Carstens, Jason Wang, linux-s390, virtualization, kvm

Allows maintaining extra context per vq.  For ease of use, passing in
NULL is legal and disables the feature for all vqs.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/misc/mic/vop/vop_main.c    |  9 ++++++---
 drivers/s390/virtio/kvm_virtio.c   |  6 ++++--
 drivers/s390/virtio/virtio_ccw.c   |  7 ++++---
 drivers/virtio/virtio_mmio.c       |  8 +++++---
 drivers/virtio/virtio_pci_common.c | 18 +++++++++++-------
 drivers/virtio/virtio_pci_common.h |  4 +++-
 drivers/virtio/virtio_pci_legacy.c |  4 +++-
 drivers/virtio/virtio_pci_modern.c | 12 ++++++++----
 drivers/virtio/virtio_ring.c       |  7 +++++--
 include/linux/virtio_config.h      | 18 +++++++++++++++---
 include/linux/virtio_ring.h        |  3 +++
 11 files changed, 67 insertions(+), 29 deletions(-)

diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c
index c2e29d7..a341938 100644
--- a/drivers/misc/mic/vop/vop_main.c
+++ b/drivers/misc/mic/vop/vop_main.c
@@ -278,7 +278,7 @@ static void vop_del_vqs(struct virtio_device *dev)
 static struct virtqueue *vop_find_vq(struct virtio_device *dev,
 				     unsigned index,
 				     void (*callback)(struct virtqueue *vq),
-				     const char *name)
+				     const char *name, bool ctx)
 {
 	struct _vop_vdev *vdev = to_vopvdev(dev);
 	struct vop_device *vpdev = vdev->vpdev;
@@ -314,6 +314,7 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev,
 				le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN,
 				dev,
 				false,
+				ctx,
 				(void __force *)va, vop_notify, callback, name);
 	if (!vq) {
 		err = -ENOMEM;
@@ -374,7 +375,8 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev,
 static int vop_find_vqs(struct virtio_device *dev, unsigned nvqs,
 			struct virtqueue *vqs[],
 			vq_callback_t *callbacks[],
-			const char * const names[], struct irq_affinity *desc)
+			const char * const names[], const bool *ctx,
+			struct irq_affinity *desc)
 {
 	struct _vop_vdev *vdev = to_vopvdev(dev);
 	struct vop_device *vpdev = vdev->vpdev;
@@ -388,7 +390,8 @@ static int vop_find_vqs(struct virtio_device *dev, unsigned nvqs,
 	for (i = 0; i < nvqs; ++i) {
 		dev_dbg(_vop_dev(vdev), "%s: %d: %s\n",
 			__func__, i, names[i]);
-		vqs[i] = vop_find_vq(dev, i, callbacks[i], names[i]);
+		vqs[i] = vop_find_vq(dev, i, callbacks[i], names[i],
+				     ctx ? ctx[i] : false);
 		if (IS_ERR(vqs[i])) {
 			err = PTR_ERR(vqs[i]);
 			goto error;
diff --git a/drivers/s390/virtio/kvm_virtio.c b/drivers/s390/virtio/kvm_virtio.c
index 2ce0b3e..81b33aa 100644
--- a/drivers/s390/virtio/kvm_virtio.c
+++ b/drivers/s390/virtio/kvm_virtio.c
@@ -189,7 +189,7 @@ static bool kvm_notify(struct virtqueue *vq)
 static struct virtqueue *kvm_find_vq(struct virtio_device *vdev,
 				     unsigned index,
 				     void (*callback)(struct virtqueue *vq),
-				     const char *name)
+				     const char *name, bool ctx)
 {
 	struct kvm_device *kdev = to_kvmdev(vdev);
 	struct kvm_vqconfig *config;
@@ -256,6 +256,7 @@ static int kvm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 			struct virtqueue *vqs[],
 			vq_callback_t *callbacks[],
 			const char * const names[],
+			const bool *ctx,
 			struct irq_affinity *desc)
 {
 	struct kvm_device *kdev = to_kvmdev(vdev);
@@ -266,7 +267,8 @@ static int kvm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		return -ENOENT;
 
 	for (i = 0; i < nvqs; ++i) {
-		vqs[i] = kvm_find_vq(vdev, i, callbacks[i], names[i]);
+		vqs[i] = kvm_find_vq(vdev, i, callbacks[i], names[i],
+				     ctx ? ctx[i] : false);
 		if (IS_ERR(vqs[i]))
 			goto error;
 	}
diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c
index 0ed209f..2a76ea7 100644
--- a/drivers/s390/virtio/virtio_ccw.c
+++ b/drivers/s390/virtio/virtio_ccw.c
@@ -484,7 +484,7 @@ static void virtio_ccw_del_vqs(struct virtio_device *vdev)
 
 static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
 					     int i, vq_callback_t *callback,
-					     const char *name,
+					     const char *name, bool ctx,
 					     struct ccw1 *ccw)
 {
 	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
@@ -522,7 +522,7 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
 	}
 
 	vq = vring_new_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
-				 true, info->queue, virtio_ccw_kvm_notify,
+				 true, ctx, info->queue, virtio_ccw_kvm_notify,
 				 callback, name);
 	if (!vq) {
 		/* For now, we fail if we can't get the requested size. */
@@ -629,6 +629,7 @@ static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 			       struct virtqueue *vqs[],
 			       vq_callback_t *callbacks[],
 			       const char * const names[],
+			       const bool *ctx,
 			       struct irq_affinity *desc)
 {
 	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
@@ -642,7 +643,7 @@ static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 
 	for (i = 0; i < nvqs; ++i) {
 		vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i],
-					     ccw);
+					     ctx ? ctx[i] : false, ccw);
 		if (IS_ERR(vqs[i])) {
 			ret = PTR_ERR(vqs[i]);
 			vqs[i] = NULL;
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 78343b8..74dc717 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -351,7 +351,7 @@ static void vm_del_vqs(struct virtio_device *vdev)
 
 static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index,
 				  void (*callback)(struct virtqueue *vq),
-				  const char *name)
+				  const char *name, bool ctx)
 {
 	struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
 	struct virtio_mmio_vq_info *info;
@@ -388,7 +388,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index,
 
 	/* Create the vring */
 	vq = vring_create_virtqueue(index, num, VIRTIO_MMIO_VRING_ALIGN, vdev,
-				 true, true, vm_notify, callback, name);
+				 true, true, ctx, vm_notify, callback, name);
 	if (!vq) {
 		err = -ENOMEM;
 		goto error_new_virtqueue;
@@ -447,6 +447,7 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		       struct virtqueue *vqs[],
 		       vq_callback_t *callbacks[],
 		       const char * const names[],
+		       const bool *ctx,
 		       struct irq_affinity *desc)
 {
 	struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
@@ -459,7 +460,8 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		return err;
 
 	for (i = 0; i < nvqs; ++i) {
-		vqs[i] = vm_setup_vq(vdev, i, callbacks[i], names[i]);
+		vqs[i] = vm_setup_vq(vdev, i, callbacks[i], names[i],
+				     ctx ? ctx[i] : false);
 		if (IS_ERR(vqs[i])) {
 			vm_del_vqs(vdev);
 			return PTR_ERR(vqs[i]);
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 5905349..18e74c8 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -143,7 +143,8 @@ void vp_del_vqs(struct virtio_device *vdev)
 
 static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
 		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[], struct irq_affinity *desc)
+		const char * const names[], const bool *ctx,
+		struct irq_affinity *desc)
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 	const char *name = dev_name(&vp_dev->vdev.dev);
@@ -225,7 +226,8 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
 			msix_vec = VIRTIO_MSI_NO_VECTOR;
 
 		vqs[i] = vp_dev->setup_vq(vp_dev, i, callbacks[i], names[i],
-				msix_vec);
+					  ctx ? ctx[i] : false,
+					  msix_vec);
 		if (IS_ERR(vqs[i])) {
 			err = PTR_ERR(vqs[i]);
 			goto out_remove_vqs;
@@ -282,7 +284,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
 
 static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
 		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[])
+		const char * const names[], const bool *ctx)
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 	int i, err;
@@ -298,7 +300,8 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
 			continue;
 		}
 		vqs[i] = vp_dev->setup_vq(vp_dev, i, callbacks[i], names[i],
-				VIRTIO_MSI_NO_VECTOR);
+					  ctx ? ctx[i] : false,
+					  VIRTIO_MSI_NO_VECTOR);
 		if (IS_ERR(vqs[i])) {
 			err = PTR_ERR(vqs[i]);
 			goto out_remove_vqs;
@@ -316,14 +319,15 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
 /* the config->find_vqs() implementation */
 int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[], struct irq_affinity *desc)
+		const char * const names[], const bool *ctx,
+		struct irq_affinity *desc)
 {
 	int err;
 
-	err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, desc);
+	err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, ctx, desc);
 	if (!err)
 		return 0;
-	return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names);
+	return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names, ctx);
 }
 
 const char *vp_bus_name(struct virtio_device *vdev)
diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h
index ac8c9d7..8149dd3 100644
--- a/drivers/virtio/virtio_pci_common.h
+++ b/drivers/virtio/virtio_pci_common.h
@@ -77,6 +77,7 @@ struct virtio_pci_device {
 				      unsigned idx,
 				      void (*callback)(struct virtqueue *vq),
 				      const char *name,
+				      bool ctx,
 				      u16 msix_vec);
 	void (*del_vq)(struct virtqueue *vq);
 
@@ -98,7 +99,8 @@ void vp_del_vqs(struct virtio_device *vdev);
 /* the config->find_vqs() implementation */
 int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[], struct irq_affinity *desc);
+		const char * const names[], const bool *ctx,
+		struct irq_affinity *desc);
 const char *vp_bus_name(struct virtio_device *vdev);
 
 /* Setup the affinity for a virtqueue:
diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
index f7362c5..a976452 100644
--- a/drivers/virtio/virtio_pci_legacy.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -115,6 +115,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 				  unsigned index,
 				  void (*callback)(struct virtqueue *vq),
 				  const char *name,
+				  bool ctx,
 				  u16 msix_vec)
 {
 	struct virtqueue *vq;
@@ -132,7 +133,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 	/* create the vring */
 	vq = vring_create_virtqueue(index, num,
 				    VIRTIO_PCI_VRING_ALIGN, &vp_dev->vdev,
-				    true, false, vp_notify, callback, name);
+				    true, false, ctx,
+				    vp_notify, callback, name);
 	if (!vq)
 		return ERR_PTR(-ENOMEM);
 
diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index 7bc3004..709f7e2 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -296,6 +296,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 				  unsigned index,
 				  void (*callback)(struct virtqueue *vq),
 				  const char *name,
+				  bool ctx,
 				  u16 msix_vec)
 {
 	struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;
@@ -325,7 +326,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 	/* create the vring */
 	vq = vring_create_virtqueue(index, num,
 				    SMP_CACHE_BYTES, &vp_dev->vdev,
-				    true, true, vp_notify, callback, name);
+				    true, true, ctx,
+				    vp_notify, callback, name);
 	if (!vq)
 		return ERR_PTR(-ENOMEM);
 
@@ -384,12 +386,14 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 }
 
 static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned nvqs,
-		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[], struct irq_affinity *desc)
+			      struct virtqueue *vqs[],
+			      vq_callback_t *callbacks[],
+			      const char * const names[], const bool *ctx,
+			      struct irq_affinity *desc)
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 	struct virtqueue *vq;
-	int rc = vp_find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
+	int rc = vp_find_vqs(vdev, nvqs, vqs, callbacks, names, ctx, desc);
 
 	if (rc)
 		return rc;
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 409aeaa..b23b5fa 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -916,6 +916,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
 					struct vring vring,
 					struct virtio_device *vdev,
 					bool weak_barriers,
+					bool context,
 					bool (*notify)(struct virtqueue *),
 					void (*callback)(struct virtqueue *),
 					const char *name)
@@ -1019,6 +1020,7 @@ struct virtqueue *vring_create_virtqueue(
 	struct virtio_device *vdev,
 	bool weak_barriers,
 	bool may_reduce_num,
+	bool context,
 	bool (*notify)(struct virtqueue *),
 	void (*callback)(struct virtqueue *),
 	const char *name)
@@ -1058,7 +1060,7 @@ struct virtqueue *vring_create_virtqueue(
 	queue_size_in_bytes = vring_size(num, vring_align);
 	vring_init(&vring, num, queue, vring_align);
 
-	vq = __vring_new_virtqueue(index, vring, vdev, weak_barriers,
+	vq = __vring_new_virtqueue(index, vring, vdev, weak_barriers, context,
 				   notify, callback, name);
 	if (!vq) {
 		vring_free_queue(vdev, queue_size_in_bytes, queue,
@@ -1079,6 +1081,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
 				      unsigned int vring_align,
 				      struct virtio_device *vdev,
 				      bool weak_barriers,
+				      bool context,
 				      void *pages,
 				      bool (*notify)(struct virtqueue *vq),
 				      void (*callback)(struct virtqueue *vq),
@@ -1086,7 +1089,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
 {
 	struct vring vring;
 	vring_init(&vring, num, pages, vring_align);
-	return __vring_new_virtqueue(index, vring, vdev, weak_barriers,
+	return __vring_new_virtqueue(index, vring, vdev, weak_barriers, context,
 				     notify, callback, name);
 }
 EXPORT_SYMBOL_GPL(vring_new_virtqueue);
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 47f3d80..0133d8a 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -72,7 +72,8 @@ struct virtio_config_ops {
 	void (*reset)(struct virtio_device *vdev);
 	int (*find_vqs)(struct virtio_device *, unsigned nvqs,
 			struct virtqueue *vqs[], vq_callback_t *callbacks[],
-			const char * const names[], struct irq_affinity *desc);
+			const char * const names[], const bool *ctx,
+			struct irq_affinity *desc);
 	void (*del_vqs)(struct virtio_device *);
 	u64 (*get_features)(struct virtio_device *vdev);
 	int (*finalize_features)(struct virtio_device *vdev);
@@ -173,7 +174,8 @@ struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,
 	vq_callback_t *callbacks[] = { c };
 	const char *names[] = { n };
 	struct virtqueue *vq;
-	int err = vdev->config->find_vqs(vdev, 1, &vq, callbacks, names, NULL);
+	int err = vdev->config->find_vqs(vdev, 1, &vq, callbacks, names, NULL,
+					 NULL);
 	if (err < 0)
 		return ERR_PTR(err);
 	return vq;
@@ -185,7 +187,17 @@ int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 			const char * const names[],
 			struct irq_affinity *desc)
 {
-	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
+	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, desc);
+}
+
+static inline
+int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs,
+			struct virtqueue *vqs[], vq_callback_t *callbacks[],
+			const char * const names[], const bool *ctx,
+			struct irq_affinity *desc)
+{
+	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, ctx,
+				      desc);
 }
 
 /**
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
index e8d3693..270cfa8 100644
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -71,6 +71,7 @@ struct virtqueue *vring_create_virtqueue(unsigned int index,
 					 struct virtio_device *vdev,
 					 bool weak_barriers,
 					 bool may_reduce_num,
+					 bool ctx,
 					 bool (*notify)(struct virtqueue *vq),
 					 void (*callback)(struct virtqueue *vq),
 					 const char *name);
@@ -80,6 +81,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
 					struct vring vring,
 					struct virtio_device *vdev,
 					bool weak_barriers,
+					bool ctx,
 					bool (*notify)(struct virtqueue *),
 					void (*callback)(struct virtqueue *),
 					const char *name);
@@ -93,6 +95,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
 				      unsigned int vring_align,
 				      struct virtio_device *vdev,
 				      bool weak_barriers,
+				      bool ctx,
 				      void *pages,
 				      bool (*notify)(struct virtqueue *vq),
 				      void (*callback)(struct virtqueue *vq),
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 2/6] virtio: add context flag to find vqs
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-s390, kvm, Heiko Carstens, John Fastabend, Sudeep Dutt,
	virtualization, Ashutosh Dixit, Cornelia Huck,
	Martin Schwidefsky

Allows maintaining extra context per vq.  For ease of use, passing in
NULL is legal and disables the feature for all vqs.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/misc/mic/vop/vop_main.c    |  9 ++++++---
 drivers/s390/virtio/kvm_virtio.c   |  6 ++++--
 drivers/s390/virtio/virtio_ccw.c   |  7 ++++---
 drivers/virtio/virtio_mmio.c       |  8 +++++---
 drivers/virtio/virtio_pci_common.c | 18 +++++++++++-------
 drivers/virtio/virtio_pci_common.h |  4 +++-
 drivers/virtio/virtio_pci_legacy.c |  4 +++-
 drivers/virtio/virtio_pci_modern.c | 12 ++++++++----
 drivers/virtio/virtio_ring.c       |  7 +++++--
 include/linux/virtio_config.h      | 18 +++++++++++++++---
 include/linux/virtio_ring.h        |  3 +++
 11 files changed, 67 insertions(+), 29 deletions(-)

diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c
index c2e29d7..a341938 100644
--- a/drivers/misc/mic/vop/vop_main.c
+++ b/drivers/misc/mic/vop/vop_main.c
@@ -278,7 +278,7 @@ static void vop_del_vqs(struct virtio_device *dev)
 static struct virtqueue *vop_find_vq(struct virtio_device *dev,
 				     unsigned index,
 				     void (*callback)(struct virtqueue *vq),
-				     const char *name)
+				     const char *name, bool ctx)
 {
 	struct _vop_vdev *vdev = to_vopvdev(dev);
 	struct vop_device *vpdev = vdev->vpdev;
@@ -314,6 +314,7 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev,
 				le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN,
 				dev,
 				false,
+				ctx,
 				(void __force *)va, vop_notify, callback, name);
 	if (!vq) {
 		err = -ENOMEM;
@@ -374,7 +375,8 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev,
 static int vop_find_vqs(struct virtio_device *dev, unsigned nvqs,
 			struct virtqueue *vqs[],
 			vq_callback_t *callbacks[],
-			const char * const names[], struct irq_affinity *desc)
+			const char * const names[], const bool *ctx,
+			struct irq_affinity *desc)
 {
 	struct _vop_vdev *vdev = to_vopvdev(dev);
 	struct vop_device *vpdev = vdev->vpdev;
@@ -388,7 +390,8 @@ static int vop_find_vqs(struct virtio_device *dev, unsigned nvqs,
 	for (i = 0; i < nvqs; ++i) {
 		dev_dbg(_vop_dev(vdev), "%s: %d: %s\n",
 			__func__, i, names[i]);
-		vqs[i] = vop_find_vq(dev, i, callbacks[i], names[i]);
+		vqs[i] = vop_find_vq(dev, i, callbacks[i], names[i],
+				     ctx ? ctx[i] : false);
 		if (IS_ERR(vqs[i])) {
 			err = PTR_ERR(vqs[i]);
 			goto error;
diff --git a/drivers/s390/virtio/kvm_virtio.c b/drivers/s390/virtio/kvm_virtio.c
index 2ce0b3e..81b33aa 100644
--- a/drivers/s390/virtio/kvm_virtio.c
+++ b/drivers/s390/virtio/kvm_virtio.c
@@ -189,7 +189,7 @@ static bool kvm_notify(struct virtqueue *vq)
 static struct virtqueue *kvm_find_vq(struct virtio_device *vdev,
 				     unsigned index,
 				     void (*callback)(struct virtqueue *vq),
-				     const char *name)
+				     const char *name, bool ctx)
 {
 	struct kvm_device *kdev = to_kvmdev(vdev);
 	struct kvm_vqconfig *config;
@@ -256,6 +256,7 @@ static int kvm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 			struct virtqueue *vqs[],
 			vq_callback_t *callbacks[],
 			const char * const names[],
+			const bool *ctx,
 			struct irq_affinity *desc)
 {
 	struct kvm_device *kdev = to_kvmdev(vdev);
@@ -266,7 +267,8 @@ static int kvm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		return -ENOENT;
 
 	for (i = 0; i < nvqs; ++i) {
-		vqs[i] = kvm_find_vq(vdev, i, callbacks[i], names[i]);
+		vqs[i] = kvm_find_vq(vdev, i, callbacks[i], names[i],
+				     ctx ? ctx[i] : false);
 		if (IS_ERR(vqs[i]))
 			goto error;
 	}
diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c
index 0ed209f..2a76ea7 100644
--- a/drivers/s390/virtio/virtio_ccw.c
+++ b/drivers/s390/virtio/virtio_ccw.c
@@ -484,7 +484,7 @@ static void virtio_ccw_del_vqs(struct virtio_device *vdev)
 
 static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
 					     int i, vq_callback_t *callback,
-					     const char *name,
+					     const char *name, bool ctx,
 					     struct ccw1 *ccw)
 {
 	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
@@ -522,7 +522,7 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
 	}
 
 	vq = vring_new_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
-				 true, info->queue, virtio_ccw_kvm_notify,
+				 true, ctx, info->queue, virtio_ccw_kvm_notify,
 				 callback, name);
 	if (!vq) {
 		/* For now, we fail if we can't get the requested size. */
@@ -629,6 +629,7 @@ static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 			       struct virtqueue *vqs[],
 			       vq_callback_t *callbacks[],
 			       const char * const names[],
+			       const bool *ctx,
 			       struct irq_affinity *desc)
 {
 	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
@@ -642,7 +643,7 @@ static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 
 	for (i = 0; i < nvqs; ++i) {
 		vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i],
-					     ccw);
+					     ctx ? ctx[i] : false, ccw);
 		if (IS_ERR(vqs[i])) {
 			ret = PTR_ERR(vqs[i]);
 			vqs[i] = NULL;
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 78343b8..74dc717 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -351,7 +351,7 @@ static void vm_del_vqs(struct virtio_device *vdev)
 
 static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index,
 				  void (*callback)(struct virtqueue *vq),
-				  const char *name)
+				  const char *name, bool ctx)
 {
 	struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
 	struct virtio_mmio_vq_info *info;
@@ -388,7 +388,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index,
 
 	/* Create the vring */
 	vq = vring_create_virtqueue(index, num, VIRTIO_MMIO_VRING_ALIGN, vdev,
-				 true, true, vm_notify, callback, name);
+				 true, true, ctx, vm_notify, callback, name);
 	if (!vq) {
 		err = -ENOMEM;
 		goto error_new_virtqueue;
@@ -447,6 +447,7 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		       struct virtqueue *vqs[],
 		       vq_callback_t *callbacks[],
 		       const char * const names[],
+		       const bool *ctx,
 		       struct irq_affinity *desc)
 {
 	struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
@@ -459,7 +460,8 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		return err;
 
 	for (i = 0; i < nvqs; ++i) {
-		vqs[i] = vm_setup_vq(vdev, i, callbacks[i], names[i]);
+		vqs[i] = vm_setup_vq(vdev, i, callbacks[i], names[i],
+				     ctx ? ctx[i] : false);
 		if (IS_ERR(vqs[i])) {
 			vm_del_vqs(vdev);
 			return PTR_ERR(vqs[i]);
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 5905349..18e74c8 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -143,7 +143,8 @@ void vp_del_vqs(struct virtio_device *vdev)
 
 static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
 		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[], struct irq_affinity *desc)
+		const char * const names[], const bool *ctx,
+		struct irq_affinity *desc)
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 	const char *name = dev_name(&vp_dev->vdev.dev);
@@ -225,7 +226,8 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
 			msix_vec = VIRTIO_MSI_NO_VECTOR;
 
 		vqs[i] = vp_dev->setup_vq(vp_dev, i, callbacks[i], names[i],
-				msix_vec);
+					  ctx ? ctx[i] : false,
+					  msix_vec);
 		if (IS_ERR(vqs[i])) {
 			err = PTR_ERR(vqs[i]);
 			goto out_remove_vqs;
@@ -282,7 +284,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
 
 static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
 		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[])
+		const char * const names[], const bool *ctx)
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 	int i, err;
@@ -298,7 +300,8 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
 			continue;
 		}
 		vqs[i] = vp_dev->setup_vq(vp_dev, i, callbacks[i], names[i],
-				VIRTIO_MSI_NO_VECTOR);
+					  ctx ? ctx[i] : false,
+					  VIRTIO_MSI_NO_VECTOR);
 		if (IS_ERR(vqs[i])) {
 			err = PTR_ERR(vqs[i]);
 			goto out_remove_vqs;
@@ -316,14 +319,15 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
 /* the config->find_vqs() implementation */
 int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[], struct irq_affinity *desc)
+		const char * const names[], const bool *ctx,
+		struct irq_affinity *desc)
 {
 	int err;
 
-	err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, desc);
+	err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, ctx, desc);
 	if (!err)
 		return 0;
-	return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names);
+	return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names, ctx);
 }
 
 const char *vp_bus_name(struct virtio_device *vdev)
diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h
index ac8c9d7..8149dd3 100644
--- a/drivers/virtio/virtio_pci_common.h
+++ b/drivers/virtio/virtio_pci_common.h
@@ -77,6 +77,7 @@ struct virtio_pci_device {
 				      unsigned idx,
 				      void (*callback)(struct virtqueue *vq),
 				      const char *name,
+				      bool ctx,
 				      u16 msix_vec);
 	void (*del_vq)(struct virtqueue *vq);
 
@@ -98,7 +99,8 @@ void vp_del_vqs(struct virtio_device *vdev);
 /* the config->find_vqs() implementation */
 int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[], struct irq_affinity *desc);
+		const char * const names[], const bool *ctx,
+		struct irq_affinity *desc);
 const char *vp_bus_name(struct virtio_device *vdev);
 
 /* Setup the affinity for a virtqueue:
diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
index f7362c5..a976452 100644
--- a/drivers/virtio/virtio_pci_legacy.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -115,6 +115,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 				  unsigned index,
 				  void (*callback)(struct virtqueue *vq),
 				  const char *name,
+				  bool ctx,
 				  u16 msix_vec)
 {
 	struct virtqueue *vq;
@@ -132,7 +133,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 	/* create the vring */
 	vq = vring_create_virtqueue(index, num,
 				    VIRTIO_PCI_VRING_ALIGN, &vp_dev->vdev,
-				    true, false, vp_notify, callback, name);
+				    true, false, ctx,
+				    vp_notify, callback, name);
 	if (!vq)
 		return ERR_PTR(-ENOMEM);
 
diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index 7bc3004..709f7e2 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -296,6 +296,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 				  unsigned index,
 				  void (*callback)(struct virtqueue *vq),
 				  const char *name,
+				  bool ctx,
 				  u16 msix_vec)
 {
 	struct virtio_pci_common_cfg __iomem *cfg = vp_dev->common;
@@ -325,7 +326,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 	/* create the vring */
 	vq = vring_create_virtqueue(index, num,
 				    SMP_CACHE_BYTES, &vp_dev->vdev,
-				    true, true, vp_notify, callback, name);
+				    true, true, ctx,
+				    vp_notify, callback, name);
 	if (!vq)
 		return ERR_PTR(-ENOMEM);
 
@@ -384,12 +386,14 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 }
 
 static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned nvqs,
-		struct virtqueue *vqs[], vq_callback_t *callbacks[],
-		const char * const names[], struct irq_affinity *desc)
+			      struct virtqueue *vqs[],
+			      vq_callback_t *callbacks[],
+			      const char * const names[], const bool *ctx,
+			      struct irq_affinity *desc)
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 	struct virtqueue *vq;
-	int rc = vp_find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
+	int rc = vp_find_vqs(vdev, nvqs, vqs, callbacks, names, ctx, desc);
 
 	if (rc)
 		return rc;
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 409aeaa..b23b5fa 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -916,6 +916,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
 					struct vring vring,
 					struct virtio_device *vdev,
 					bool weak_barriers,
+					bool context,
 					bool (*notify)(struct virtqueue *),
 					void (*callback)(struct virtqueue *),
 					const char *name)
@@ -1019,6 +1020,7 @@ struct virtqueue *vring_create_virtqueue(
 	struct virtio_device *vdev,
 	bool weak_barriers,
 	bool may_reduce_num,
+	bool context,
 	bool (*notify)(struct virtqueue *),
 	void (*callback)(struct virtqueue *),
 	const char *name)
@@ -1058,7 +1060,7 @@ struct virtqueue *vring_create_virtqueue(
 	queue_size_in_bytes = vring_size(num, vring_align);
 	vring_init(&vring, num, queue, vring_align);
 
-	vq = __vring_new_virtqueue(index, vring, vdev, weak_barriers,
+	vq = __vring_new_virtqueue(index, vring, vdev, weak_barriers, context,
 				   notify, callback, name);
 	if (!vq) {
 		vring_free_queue(vdev, queue_size_in_bytes, queue,
@@ -1079,6 +1081,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
 				      unsigned int vring_align,
 				      struct virtio_device *vdev,
 				      bool weak_barriers,
+				      bool context,
 				      void *pages,
 				      bool (*notify)(struct virtqueue *vq),
 				      void (*callback)(struct virtqueue *vq),
@@ -1086,7 +1089,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
 {
 	struct vring vring;
 	vring_init(&vring, num, pages, vring_align);
-	return __vring_new_virtqueue(index, vring, vdev, weak_barriers,
+	return __vring_new_virtqueue(index, vring, vdev, weak_barriers, context,
 				     notify, callback, name);
 }
 EXPORT_SYMBOL_GPL(vring_new_virtqueue);
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 47f3d80..0133d8a 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -72,7 +72,8 @@ struct virtio_config_ops {
 	void (*reset)(struct virtio_device *vdev);
 	int (*find_vqs)(struct virtio_device *, unsigned nvqs,
 			struct virtqueue *vqs[], vq_callback_t *callbacks[],
-			const char * const names[], struct irq_affinity *desc);
+			const char * const names[], const bool *ctx,
+			struct irq_affinity *desc);
 	void (*del_vqs)(struct virtio_device *);
 	u64 (*get_features)(struct virtio_device *vdev);
 	int (*finalize_features)(struct virtio_device *vdev);
@@ -173,7 +174,8 @@ struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,
 	vq_callback_t *callbacks[] = { c };
 	const char *names[] = { n };
 	struct virtqueue *vq;
-	int err = vdev->config->find_vqs(vdev, 1, &vq, callbacks, names, NULL);
+	int err = vdev->config->find_vqs(vdev, 1, &vq, callbacks, names, NULL,
+					 NULL);
 	if (err < 0)
 		return ERR_PTR(err);
 	return vq;
@@ -185,7 +187,17 @@ int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 			const char * const names[],
 			struct irq_affinity *desc)
 {
-	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
+	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, desc);
+}
+
+static inline
+int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs,
+			struct virtqueue *vqs[], vq_callback_t *callbacks[],
+			const char * const names[], const bool *ctx,
+			struct irq_affinity *desc)
+{
+	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, ctx,
+				      desc);
 }
 
 /**
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
index e8d3693..270cfa8 100644
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -71,6 +71,7 @@ struct virtqueue *vring_create_virtqueue(unsigned int index,
 					 struct virtio_device *vdev,
 					 bool weak_barriers,
 					 bool may_reduce_num,
+					 bool ctx,
 					 bool (*notify)(struct virtqueue *vq),
 					 void (*callback)(struct virtqueue *vq),
 					 const char *name);
@@ -80,6 +81,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
 					struct vring vring,
 					struct virtio_device *vdev,
 					bool weak_barriers,
+					bool ctx,
 					bool (*notify)(struct virtqueue *),
 					void (*callback)(struct virtqueue *),
 					const char *name);
@@ -93,6 +95,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
 				      unsigned int vring_align,
 				      struct virtio_device *vdev,
 				      bool weak_barriers,
+				      bool ctx,
 				      void *pages,
 				      bool (*notify)(struct virtqueue *vq),
 				      void (*callback)(struct virtqueue *vq),
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 3/6] virtio: allow extra context per descriptor
  2017-03-29 20:48 [PATCH 0/6] virtio: support extra per-buffer context Michael S. Tsirkin
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  2017-03-29 20:48   ` Michael S. Tsirkin
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Fastabend, Jason Wang, virtualization

Allow extra context per descriptor. To avoid slow down for data path,
this disables use of indirect descriptors for this vq.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++++++++++--------
 include/linux/virtio.h       |  9 ++++++
 2 files changed, 66 insertions(+), 13 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index b23b5fa..5e1b548 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -263,6 +263,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 				unsigned int out_sgs,
 				unsigned int in_sgs,
 				void *data,
+				void *ctx,
 				gfp_t gfp)
 {
 	struct vring_virtqueue *vq = to_vvq(_vq);
@@ -275,6 +276,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 	START_USE(vq);
 
 	BUG_ON(data == NULL);
+	BUG_ON(ctx && vq->indirect);
 
 	if (unlikely(vq->broken)) {
 		END_USE(vq);
@@ -389,6 +391,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 	vq->desc_state[head].data = data;
 	if (indirect)
 		vq->desc_state[head].indir_desc = desc;
+	if (ctx)
+		vq->desc_state[head].indir_desc = ctx;
 
 	/* Put entry in available array (but don't update avail->idx until they
 	 * do sync). */
@@ -461,7 +465,8 @@ int virtqueue_add_sgs(struct virtqueue *_vq,
 		for (sg = sgs[i]; sg; sg = sg_next(sg))
 			total_sg++;
 	}
-	return virtqueue_add(_vq, sgs, total_sg, out_sgs, in_sgs, data, gfp);
+	return virtqueue_add(_vq, sgs, total_sg, out_sgs, in_sgs,
+			     data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_sgs);
 
@@ -483,7 +488,7 @@ int virtqueue_add_outbuf(struct virtqueue *vq,
 			 void *data,
 			 gfp_t gfp)
 {
-	return virtqueue_add(vq, &sg, num, 1, 0, data, gfp);
+	return virtqueue_add(vq, &sg, num, 1, 0, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_outbuf);
 
@@ -505,11 +510,35 @@ int virtqueue_add_inbuf(struct virtqueue *vq,
 			void *data,
 			gfp_t gfp)
 {
-	return virtqueue_add(vq, &sg, num, 0, 1, data, gfp);
+	return virtqueue_add(vq, &sg, num, 0, 1, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_inbuf);
 
 /**
+ * virtqueue_add_inbuf_ctx - expose input buffers to other end
+ * @vq: the struct virtqueue we're talking about.
+ * @sg: scatterlist (must be well-formed and terminated!)
+ * @num: the number of entries in @sg writable by other side
+ * @data: the token identifying the buffer.
+ * @ctx: extra context for the token
+ * @gfp: how to do memory allocations (if necessary).
+ *
+ * Caller must ensure we don't call this with other virtqueue operations
+ * at the same time (except where noted).
+ *
+ * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
+ */
+int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
+			struct scatterlist *sg, unsigned int num,
+			void *data,
+			void *ctx,
+			gfp_t gfp)
+{
+	return virtqueue_add(vq, &sg, num, 0, 1, data, ctx, gfp);
+}
+EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx);
+
+/**
  * virtqueue_kick_prepare - first half of split virtqueue_kick call.
  * @vq: the struct virtqueue
  *
@@ -598,7 +627,8 @@ bool virtqueue_kick(struct virtqueue *vq)
 }
 EXPORT_SYMBOL_GPL(virtqueue_kick);
 
-static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
+static void detach_buf(struct vring_virtqueue *vq, unsigned int head,
+		       void **ctx)
 {
 	unsigned int i, j;
 	__virtio16 nextflag = cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT);
@@ -622,10 +652,15 @@ static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
 	/* Plus final descriptor */
 	vq->vq.num_free++;
 
-	/* Free the indirect table, if any, now that it's unmapped. */
-	if (vq->desc_state[head].indir_desc) {
+	if (vq->indirect) {
 		struct vring_desc *indir_desc = vq->desc_state[head].indir_desc;
-		u32 len = virtio32_to_cpu(vq->vq.vdev, vq->vring.desc[head].len);
+		u32 len;
+
+		/* Free the indirect table, if any, now that it's unmapped. */
+		if (!indir_desc)
+			return;
+
+		len = virtio32_to_cpu(vq->vq.vdev, vq->vring.desc[head].len);
 
 		BUG_ON(!(vq->vring.desc[head].flags &
 			 cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_INDIRECT)));
@@ -634,8 +669,10 @@ static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
 		for (j = 0; j < len / sizeof(struct vring_desc); j++)
 			vring_unmap_one(vq, &indir_desc[j]);
 
-		kfree(vq->desc_state[head].indir_desc);
+		kfree(indir_desc);
 		vq->desc_state[head].indir_desc = NULL;
+	} else if (ctx) {
+		*ctx = vq->desc_state[head].indir_desc;
 	}
 }
 
@@ -660,7 +697,8 @@ static inline bool more_used(const struct vring_virtqueue *vq)
  * Returns NULL if there are no used buffers, or the "data" token
  * handed to virtqueue_add_*().
  */
-void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
+void *virtqueue_get_buf_ctx(struct virtqueue *_vq, unsigned int *len,
+			    void **ctx)
 {
 	struct vring_virtqueue *vq = to_vvq(_vq);
 	void *ret;
@@ -698,7 +736,7 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
 
 	/* detach_buf clears data, so grab it now. */
 	ret = vq->desc_state[i].data;
-	detach_buf(vq, i);
+	detach_buf(vq, i, ctx);
 	vq->last_used_idx++;
 	/* If we expect an interrupt for the next entry, tell host
 	 * by writing event index and flush out the write before
@@ -715,8 +753,13 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
 	END_USE(vq);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(virtqueue_get_buf);
+EXPORT_SYMBOL_GPL(virtqueue_get_buf_ctx);
 
+void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
+{
+	return virtqueue_get_buf_ctx(_vq, len, NULL);
+}
+EXPORT_SYMBOL_GPL(virtqueue_get_buf);
 /**
  * virtqueue_disable_cb - disable callbacks
  * @vq: the struct virtqueue we're talking about.
@@ -878,7 +921,7 @@ void *virtqueue_detach_unused_buf(struct virtqueue *_vq)
 			continue;
 		/* detach_buf clears data, so grab it now. */
 		buf = vq->desc_state[i].data;
-		detach_buf(vq, i);
+		detach_buf(vq, i, NULL);
 		vq->avail_idx_shadow--;
 		vq->vring.avail->idx = cpu_to_virtio16(_vq->vdev, vq->avail_idx_shadow);
 		END_USE(vq);
@@ -951,7 +994,8 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
 	vq->last_add_time_valid = false;
 #endif
 
-	vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC);
+	vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) &&
+		!context;
 	vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX);
 
 	/* No callback?  Tell other side not to bother us. */
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 04b0d3f9..193fea9 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -44,6 +44,12 @@ int virtqueue_add_inbuf(struct virtqueue *vq,
 			void *data,
 			gfp_t gfp);
 
+int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
+			    struct scatterlist sg[], unsigned int num,
+			    void *data,
+			    void *ctx,
+			    gfp_t gfp);
+
 int virtqueue_add_sgs(struct virtqueue *vq,
 		      struct scatterlist *sgs[],
 		      unsigned int out_sgs,
@@ -59,6 +65,9 @@ bool virtqueue_notify(struct virtqueue *vq);
 
 void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
 
+void *virtqueue_get_buf_ctx(struct virtqueue *vq, unsigned int *len,
+			    void **ctx);
+
 void virtqueue_disable_cb(struct virtqueue *vq);
 
 bool virtqueue_enable_cb(struct virtqueue *vq);
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 3/6] virtio: allow extra context per descriptor
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Fastabend, virtualization

Allow extra context per descriptor. To avoid slow down for data path,
this disables use of indirect descriptors for this vq.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++++++++++--------
 include/linux/virtio.h       |  9 ++++++
 2 files changed, 66 insertions(+), 13 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index b23b5fa..5e1b548 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -263,6 +263,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 				unsigned int out_sgs,
 				unsigned int in_sgs,
 				void *data,
+				void *ctx,
 				gfp_t gfp)
 {
 	struct vring_virtqueue *vq = to_vvq(_vq);
@@ -275,6 +276,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 	START_USE(vq);
 
 	BUG_ON(data == NULL);
+	BUG_ON(ctx && vq->indirect);
 
 	if (unlikely(vq->broken)) {
 		END_USE(vq);
@@ -389,6 +391,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 	vq->desc_state[head].data = data;
 	if (indirect)
 		vq->desc_state[head].indir_desc = desc;
+	if (ctx)
+		vq->desc_state[head].indir_desc = ctx;
 
 	/* Put entry in available array (but don't update avail->idx until they
 	 * do sync). */
@@ -461,7 +465,8 @@ int virtqueue_add_sgs(struct virtqueue *_vq,
 		for (sg = sgs[i]; sg; sg = sg_next(sg))
 			total_sg++;
 	}
-	return virtqueue_add(_vq, sgs, total_sg, out_sgs, in_sgs, data, gfp);
+	return virtqueue_add(_vq, sgs, total_sg, out_sgs, in_sgs,
+			     data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_sgs);
 
@@ -483,7 +488,7 @@ int virtqueue_add_outbuf(struct virtqueue *vq,
 			 void *data,
 			 gfp_t gfp)
 {
-	return virtqueue_add(vq, &sg, num, 1, 0, data, gfp);
+	return virtqueue_add(vq, &sg, num, 1, 0, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_outbuf);
 
@@ -505,11 +510,35 @@ int virtqueue_add_inbuf(struct virtqueue *vq,
 			void *data,
 			gfp_t gfp)
 {
-	return virtqueue_add(vq, &sg, num, 0, 1, data, gfp);
+	return virtqueue_add(vq, &sg, num, 0, 1, data, NULL, gfp);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_inbuf);
 
 /**
+ * virtqueue_add_inbuf_ctx - expose input buffers to other end
+ * @vq: the struct virtqueue we're talking about.
+ * @sg: scatterlist (must be well-formed and terminated!)
+ * @num: the number of entries in @sg writable by other side
+ * @data: the token identifying the buffer.
+ * @ctx: extra context for the token
+ * @gfp: how to do memory allocations (if necessary).
+ *
+ * Caller must ensure we don't call this with other virtqueue operations
+ * at the same time (except where noted).
+ *
+ * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
+ */
+int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
+			struct scatterlist *sg, unsigned int num,
+			void *data,
+			void *ctx,
+			gfp_t gfp)
+{
+	return virtqueue_add(vq, &sg, num, 0, 1, data, ctx, gfp);
+}
+EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx);
+
+/**
  * virtqueue_kick_prepare - first half of split virtqueue_kick call.
  * @vq: the struct virtqueue
  *
@@ -598,7 +627,8 @@ bool virtqueue_kick(struct virtqueue *vq)
 }
 EXPORT_SYMBOL_GPL(virtqueue_kick);
 
-static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
+static void detach_buf(struct vring_virtqueue *vq, unsigned int head,
+		       void **ctx)
 {
 	unsigned int i, j;
 	__virtio16 nextflag = cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_NEXT);
@@ -622,10 +652,15 @@ static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
 	/* Plus final descriptor */
 	vq->vq.num_free++;
 
-	/* Free the indirect table, if any, now that it's unmapped. */
-	if (vq->desc_state[head].indir_desc) {
+	if (vq->indirect) {
 		struct vring_desc *indir_desc = vq->desc_state[head].indir_desc;
-		u32 len = virtio32_to_cpu(vq->vq.vdev, vq->vring.desc[head].len);
+		u32 len;
+
+		/* Free the indirect table, if any, now that it's unmapped. */
+		if (!indir_desc)
+			return;
+
+		len = virtio32_to_cpu(vq->vq.vdev, vq->vring.desc[head].len);
 
 		BUG_ON(!(vq->vring.desc[head].flags &
 			 cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_INDIRECT)));
@@ -634,8 +669,10 @@ static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
 		for (j = 0; j < len / sizeof(struct vring_desc); j++)
 			vring_unmap_one(vq, &indir_desc[j]);
 
-		kfree(vq->desc_state[head].indir_desc);
+		kfree(indir_desc);
 		vq->desc_state[head].indir_desc = NULL;
+	} else if (ctx) {
+		*ctx = vq->desc_state[head].indir_desc;
 	}
 }
 
@@ -660,7 +697,8 @@ static inline bool more_used(const struct vring_virtqueue *vq)
  * Returns NULL if there are no used buffers, or the "data" token
  * handed to virtqueue_add_*().
  */
-void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
+void *virtqueue_get_buf_ctx(struct virtqueue *_vq, unsigned int *len,
+			    void **ctx)
 {
 	struct vring_virtqueue *vq = to_vvq(_vq);
 	void *ret;
@@ -698,7 +736,7 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
 
 	/* detach_buf clears data, so grab it now. */
 	ret = vq->desc_state[i].data;
-	detach_buf(vq, i);
+	detach_buf(vq, i, ctx);
 	vq->last_used_idx++;
 	/* If we expect an interrupt for the next entry, tell host
 	 * by writing event index and flush out the write before
@@ -715,8 +753,13 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
 	END_USE(vq);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(virtqueue_get_buf);
+EXPORT_SYMBOL_GPL(virtqueue_get_buf_ctx);
 
+void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
+{
+	return virtqueue_get_buf_ctx(_vq, len, NULL);
+}
+EXPORT_SYMBOL_GPL(virtqueue_get_buf);
 /**
  * virtqueue_disable_cb - disable callbacks
  * @vq: the struct virtqueue we're talking about.
@@ -878,7 +921,7 @@ void *virtqueue_detach_unused_buf(struct virtqueue *_vq)
 			continue;
 		/* detach_buf clears data, so grab it now. */
 		buf = vq->desc_state[i].data;
-		detach_buf(vq, i);
+		detach_buf(vq, i, NULL);
 		vq->avail_idx_shadow--;
 		vq->vring.avail->idx = cpu_to_virtio16(_vq->vdev, vq->avail_idx_shadow);
 		END_USE(vq);
@@ -951,7 +994,8 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
 	vq->last_add_time_valid = false;
 #endif
 
-	vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC);
+	vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) &&
+		!context;
 	vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX);
 
 	/* No callback?  Tell other side not to bother us. */
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 04b0d3f9..193fea9 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -44,6 +44,12 @@ int virtqueue_add_inbuf(struct virtqueue *vq,
 			void *data,
 			gfp_t gfp);
 
+int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
+			    struct scatterlist sg[], unsigned int num,
+			    void *data,
+			    void *ctx,
+			    gfp_t gfp);
+
 int virtqueue_add_sgs(struct virtqueue *vq,
 		      struct scatterlist *sgs[],
 		      unsigned int out_sgs,
@@ -59,6 +65,9 @@ bool virtqueue_notify(struct virtqueue *vq);
 
 void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
 
+void *virtqueue_get_buf_ctx(struct virtqueue *vq, unsigned int *len,
+			    void **ctx);
+
 void virtqueue_disable_cb(struct virtqueue *vq);
 
 bool virtqueue_enable_cb(struct virtqueue *vq);
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 4/6] virtio_net: allow specifying context for rx
  2017-03-29 20:48 [PATCH 0/6] virtio: support extra per-buffer context Michael S. Tsirkin
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  2017-03-29 20:48   ` Michael S. Tsirkin
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Fastabend, Jason Wang, virtualization, netdev

With mergeable buffers we never use s/g for rx,
so allow specifying context in that case.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/net/virtio_net.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 6802169..340f737 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2044,6 +2044,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 	int ret = -ENOMEM;
 	int i, total_vqs;
 	const char **names;
+	const bool *ctx;
 
 	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
 	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
@@ -2062,6 +2063,13 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
 	if (!names)
 		goto err_names;
+	if (vi->mergeable_rx_bufs) {
+		ctx = kzalloc(total_vqs * sizeof(*ctx), GFP_KERNEL);
+		if (!ctx)
+			goto err_ctx;
+	} else {
+		ctx = NULL;
+	}
 
 	/* Parameters for control virtqueue, if any */
 	if (vi->has_cvq) {
@@ -2077,9 +2085,12 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 		sprintf(vi->sq[i].name, "output.%d", i);
 		names[rxq2vq(i)] = vi->rq[i].name;
 		names[txq2vq(i)] = vi->sq[i].name;
+		if (ctx)
+			ctx[rxq2vq(i)] = true;
 	}
 
-	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
+	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
+					 names, ctx, NULL);
 	if (ret)
 		goto err_find;
 
@@ -2101,6 +2112,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 	return 0;
 
 err_find:
+	kfree(ctx);
+err_ctx:
 	kfree(names);
 err_names:
 	kfree(callbacks);
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 4/6] virtio_net: allow specifying context for rx
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: netdev, John Fastabend, virtualization

With mergeable buffers we never use s/g for rx,
so allow specifying context in that case.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/net/virtio_net.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 6802169..340f737 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2044,6 +2044,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 	int ret = -ENOMEM;
 	int i, total_vqs;
 	const char **names;
+	const bool *ctx;
 
 	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
 	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
@@ -2062,6 +2063,13 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
 	if (!names)
 		goto err_names;
+	if (vi->mergeable_rx_bufs) {
+		ctx = kzalloc(total_vqs * sizeof(*ctx), GFP_KERNEL);
+		if (!ctx)
+			goto err_ctx;
+	} else {
+		ctx = NULL;
+	}
 
 	/* Parameters for control virtqueue, if any */
 	if (vi->has_cvq) {
@@ -2077,9 +2085,12 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 		sprintf(vi->sq[i].name, "output.%d", i);
 		names[rxq2vq(i)] = vi->rq[i].name;
 		names[txq2vq(i)] = vi->sq[i].name;
+		if (ctx)
+			ctx[rxq2vq(i)] = true;
 	}
 
-	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
+	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
+					 names, ctx, NULL);
 	if (ret)
 		goto err_find;
 
@@ -2101,6 +2112,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 	return 0;
 
 err_find:
+	kfree(ctx);
+err_ctx:
 	kfree(names);
 err_names:
 	kfree(callbacks);
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 5/6] virtio_net: rework mergeable buffer handling
  2017-03-29 20:48 [PATCH 0/6] virtio: support extra per-buffer context Michael S. Tsirkin
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  2017-03-29 20:48   ` Michael S. Tsirkin
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Fastabend, Jason Wang, virtualization, netdev

Use the new _ctx virtio API to maintain true length for each buffer.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/net/virtio_net.c | 91 +++++++++++++++++++++++-------------------------
 1 file changed, 44 insertions(+), 47 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 340f737..94f94f3 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -250,24 +250,6 @@ static void skb_xmit_done(struct virtqueue *vq)
 	netif_wake_subqueue(vi->dev, vq2txq(vq));
 }
 
-static unsigned int mergeable_ctx_to_buf_truesize(unsigned long mrg_ctx)
-{
-	unsigned int truesize = mrg_ctx & (MERGEABLE_BUFFER_ALIGN - 1);
-	return (truesize + 1) * MERGEABLE_BUFFER_ALIGN;
-}
-
-static void *mergeable_ctx_to_buf_address(unsigned long mrg_ctx)
-{
-	return (void *)(mrg_ctx & -MERGEABLE_BUFFER_ALIGN);
-
-}
-
-static unsigned long mergeable_buf_to_ctx(void *buf, unsigned int truesize)
-{
-	unsigned int size = truesize / MERGEABLE_BUFFER_ALIGN;
-	return (unsigned long)buf | (size - 1);
-}
-
 /* Called from bottom half context */
 static struct sk_buff *page_to_skb(struct virtnet_info *vi,
 				   struct receive_queue *rq,
@@ -511,15 +493,13 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
 
 	while (--*num_buf) {
 		unsigned int buflen;
-		unsigned long ctx;
 		void *buf;
 		int off;
 
-		ctx = (unsigned long)virtqueue_get_buf(rq->vq, &buflen);
-		if (unlikely(!ctx))
+		buf = virtqueue_get_buf(rq->vq, &buflen);
+		if (unlikely(!buf))
 			goto err_buf;
 
-		buf = mergeable_ctx_to_buf_address(ctx);
 		p = virt_to_head_page(buf);
 		off = buf - page_address(p);
 
@@ -548,10 +528,10 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
 static struct sk_buff *receive_mergeable(struct net_device *dev,
 					 struct virtnet_info *vi,
 					 struct receive_queue *rq,
-					 unsigned long ctx,
+					 void *buf,
+					 void *ctx,
 					 unsigned int len)
 {
-	void *buf = mergeable_ctx_to_buf_address(ctx);
 	struct virtio_net_hdr_mrg_rxbuf *hdr = buf;
 	u16 num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers);
 	struct page *page = virt_to_head_page(buf);
@@ -639,7 +619,13 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 	}
 	rcu_read_unlock();
 
-	truesize = max(len, mergeable_ctx_to_buf_truesize(ctx));
+	if (unlikely(len > (unsigned long)ctx)) {
+		pr_debug("%s: rx error: len %u exceeds truesize 0x%lu\n",
+			 dev->name, len, (unsigned long)ctx);
+		dev->stats.rx_length_errors++;
+		goto err_skb;
+	}
+	truesize = (unsigned long)ctx;
 	head_skb = page_to_skb(vi, rq, page, offset, len, truesize);
 	curr_skb = head_skb;
 
@@ -648,7 +634,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 	while (--num_buf) {
 		int num_skb_frags;
 
-		ctx = (unsigned long)virtqueue_get_buf(rq->vq, &len);
+		buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx);
 		if (unlikely(!ctx)) {
 			pr_debug("%s: rx error: %d buffers out of %d missing\n",
 				 dev->name, num_buf,
@@ -658,8 +644,14 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			goto err_buf;
 		}
 
-		buf = mergeable_ctx_to_buf_address(ctx);
 		page = virt_to_head_page(buf);
+		if (unlikely(len > (unsigned long)ctx)) {
+			pr_debug("%s: rx error: len %u exceeds truesize 0x%lu\n",
+				 dev->name, len, (unsigned long)ctx);
+			dev->stats.rx_length_errors++;
+			goto err_skb;
+		}
+		truesize = (unsigned long)ctx;
 
 		num_skb_frags = skb_shinfo(curr_skb)->nr_frags;
 		if (unlikely(num_skb_frags == MAX_SKB_FRAGS)) {
@@ -675,7 +667,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			head_skb->truesize += nskb->truesize;
 			num_skb_frags = 0;
 		}
-		truesize = max(len, mergeable_ctx_to_buf_truesize(ctx));
 		if (curr_skb != head_skb) {
 			head_skb->data_len += len;
 			head_skb->len += len;
@@ -700,14 +691,14 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 err_skb:
 	put_page(page);
 	while (--num_buf) {
-		ctx = (unsigned long)virtqueue_get_buf(rq->vq, &len);
-		if (unlikely(!ctx)) {
+		buf = virtqueue_get_buf(rq->vq, &len);
+		if (unlikely(!buf)) {
 			pr_debug("%s: rx error: %d buffers missing\n",
 				 dev->name, num_buf);
 			dev->stats.rx_length_errors++;
 			break;
 		}
-		page = virt_to_head_page(mergeable_ctx_to_buf_address(ctx));
+		page = virt_to_head_page(buf);
 		put_page(page);
 	}
 err_buf:
@@ -718,7 +709,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 }
 
 static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
-		       void *buf, unsigned int len)
+		       void *buf, unsigned int len, void **ctx)
 {
 	struct net_device *dev = vi->dev;
 	struct sk_buff *skb;
@@ -729,9 +720,7 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
 		pr_debug("%s: short packet %i\n", dev->name, len);
 		dev->stats.rx_length_errors++;
 		if (vi->mergeable_rx_bufs) {
-			unsigned long ctx = (unsigned long)buf;
-			void *base = mergeable_ctx_to_buf_address(ctx);
-			put_page(virt_to_head_page(base));
+			put_page(virt_to_head_page(buf));
 		} else if (vi->big_packets) {
 			give_pages(rq, buf);
 		} else {
@@ -741,7 +730,7 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
 	}
 
 	if (vi->mergeable_rx_bufs)
-		skb = receive_mergeable(dev, vi, rq, (unsigned long)buf, len);
+		skb = receive_mergeable(dev, vi, rq, buf, ctx, len);
 	else if (vi->big_packets)
 		skb = receive_big(dev, vi, rq, buf, len);
 	else
@@ -869,7 +858,7 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
 	struct page_frag *alloc_frag = &rq->alloc_frag;
 	unsigned int headroom = virtnet_get_headroom(vi);
 	char *buf;
-	unsigned long ctx;
+	void *ctx;
 	int err;
 	unsigned int len, hole;
 
@@ -879,7 +868,7 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
 
 	buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset;
 	buf += headroom; /* advance address leaving hole at front of pkt */
-	ctx = mergeable_buf_to_ctx(buf, len);
+	ctx = (void *)(unsigned long)len;
 	get_page(alloc_frag->page);
 	alloc_frag->offset += len + headroom;
 	hole = alloc_frag->size - alloc_frag->offset;
@@ -894,7 +883,7 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
 	}
 
 	sg_init_one(rq->sg, buf, len);
-	err = virtqueue_add_inbuf(rq->vq, rq->sg, 1, (void *)ctx, gfp);
+	err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp);
 	if (err < 0)
 		put_page(virt_to_head_page(buf));
 
@@ -988,10 +977,20 @@ static int virtnet_receive(struct receive_queue *rq, int budget)
 	void *buf;
 	struct virtnet_stats *stats = this_cpu_ptr(vi->stats);
 
-	while (received < budget &&
-	       (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) {
-		bytes += receive_buf(vi, rq, buf, len);
-		received++;
+	if (vi->mergeable_rx_bufs) {
+		void *ctx;
+
+		while (received < budget &&
+		       (buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx))) {
+			bytes += receive_buf(vi, rq, buf, len, ctx);
+			received++;
+		}
+	} else {
+		while (received < budget &&
+		       (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) {
+			bytes += receive_buf(vi, rq, buf, len, NULL);
+			received++;
+		}
 	}
 
 	if (rq->vq->num_free > virtqueue_get_vring_size(rq->vq) / 2) {
@@ -2014,9 +2013,7 @@ static void free_unused_bufs(struct virtnet_info *vi)
 
 		while ((buf = virtqueue_detach_unused_buf(vq)) != NULL) {
 			if (vi->mergeable_rx_bufs) {
-				unsigned long ctx = (unsigned long)buf;
-				void *base = mergeable_ctx_to_buf_address(ctx);
-				put_page(virt_to_head_page(base));
+				put_page(virt_to_head_page(buf));
 			} else if (vi->big_packets) {
 				give_pages(&vi->rq[i], buf);
 			} else {
@@ -2044,7 +2041,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 	int ret = -ENOMEM;
 	int i, total_vqs;
 	const char **names;
-	const bool *ctx;
+	bool *ctx;
 
 	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
 	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 5/6] virtio_net: rework mergeable buffer handling
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: netdev, John Fastabend, virtualization

Use the new _ctx virtio API to maintain true length for each buffer.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/net/virtio_net.c | 91 +++++++++++++++++++++++-------------------------
 1 file changed, 44 insertions(+), 47 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 340f737..94f94f3 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -250,24 +250,6 @@ static void skb_xmit_done(struct virtqueue *vq)
 	netif_wake_subqueue(vi->dev, vq2txq(vq));
 }
 
-static unsigned int mergeable_ctx_to_buf_truesize(unsigned long mrg_ctx)
-{
-	unsigned int truesize = mrg_ctx & (MERGEABLE_BUFFER_ALIGN - 1);
-	return (truesize + 1) * MERGEABLE_BUFFER_ALIGN;
-}
-
-static void *mergeable_ctx_to_buf_address(unsigned long mrg_ctx)
-{
-	return (void *)(mrg_ctx & -MERGEABLE_BUFFER_ALIGN);
-
-}
-
-static unsigned long mergeable_buf_to_ctx(void *buf, unsigned int truesize)
-{
-	unsigned int size = truesize / MERGEABLE_BUFFER_ALIGN;
-	return (unsigned long)buf | (size - 1);
-}
-
 /* Called from bottom half context */
 static struct sk_buff *page_to_skb(struct virtnet_info *vi,
 				   struct receive_queue *rq,
@@ -511,15 +493,13 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
 
 	while (--*num_buf) {
 		unsigned int buflen;
-		unsigned long ctx;
 		void *buf;
 		int off;
 
-		ctx = (unsigned long)virtqueue_get_buf(rq->vq, &buflen);
-		if (unlikely(!ctx))
+		buf = virtqueue_get_buf(rq->vq, &buflen);
+		if (unlikely(!buf))
 			goto err_buf;
 
-		buf = mergeable_ctx_to_buf_address(ctx);
 		p = virt_to_head_page(buf);
 		off = buf - page_address(p);
 
@@ -548,10 +528,10 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
 static struct sk_buff *receive_mergeable(struct net_device *dev,
 					 struct virtnet_info *vi,
 					 struct receive_queue *rq,
-					 unsigned long ctx,
+					 void *buf,
+					 void *ctx,
 					 unsigned int len)
 {
-	void *buf = mergeable_ctx_to_buf_address(ctx);
 	struct virtio_net_hdr_mrg_rxbuf *hdr = buf;
 	u16 num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers);
 	struct page *page = virt_to_head_page(buf);
@@ -639,7 +619,13 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 	}
 	rcu_read_unlock();
 
-	truesize = max(len, mergeable_ctx_to_buf_truesize(ctx));
+	if (unlikely(len > (unsigned long)ctx)) {
+		pr_debug("%s: rx error: len %u exceeds truesize 0x%lu\n",
+			 dev->name, len, (unsigned long)ctx);
+		dev->stats.rx_length_errors++;
+		goto err_skb;
+	}
+	truesize = (unsigned long)ctx;
 	head_skb = page_to_skb(vi, rq, page, offset, len, truesize);
 	curr_skb = head_skb;
 
@@ -648,7 +634,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 	while (--num_buf) {
 		int num_skb_frags;
 
-		ctx = (unsigned long)virtqueue_get_buf(rq->vq, &len);
+		buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx);
 		if (unlikely(!ctx)) {
 			pr_debug("%s: rx error: %d buffers out of %d missing\n",
 				 dev->name, num_buf,
@@ -658,8 +644,14 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			goto err_buf;
 		}
 
-		buf = mergeable_ctx_to_buf_address(ctx);
 		page = virt_to_head_page(buf);
+		if (unlikely(len > (unsigned long)ctx)) {
+			pr_debug("%s: rx error: len %u exceeds truesize 0x%lu\n",
+				 dev->name, len, (unsigned long)ctx);
+			dev->stats.rx_length_errors++;
+			goto err_skb;
+		}
+		truesize = (unsigned long)ctx;
 
 		num_skb_frags = skb_shinfo(curr_skb)->nr_frags;
 		if (unlikely(num_skb_frags == MAX_SKB_FRAGS)) {
@@ -675,7 +667,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			head_skb->truesize += nskb->truesize;
 			num_skb_frags = 0;
 		}
-		truesize = max(len, mergeable_ctx_to_buf_truesize(ctx));
 		if (curr_skb != head_skb) {
 			head_skb->data_len += len;
 			head_skb->len += len;
@@ -700,14 +691,14 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 err_skb:
 	put_page(page);
 	while (--num_buf) {
-		ctx = (unsigned long)virtqueue_get_buf(rq->vq, &len);
-		if (unlikely(!ctx)) {
+		buf = virtqueue_get_buf(rq->vq, &len);
+		if (unlikely(!buf)) {
 			pr_debug("%s: rx error: %d buffers missing\n",
 				 dev->name, num_buf);
 			dev->stats.rx_length_errors++;
 			break;
 		}
-		page = virt_to_head_page(mergeable_ctx_to_buf_address(ctx));
+		page = virt_to_head_page(buf);
 		put_page(page);
 	}
 err_buf:
@@ -718,7 +709,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 }
 
 static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
-		       void *buf, unsigned int len)
+		       void *buf, unsigned int len, void **ctx)
 {
 	struct net_device *dev = vi->dev;
 	struct sk_buff *skb;
@@ -729,9 +720,7 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
 		pr_debug("%s: short packet %i\n", dev->name, len);
 		dev->stats.rx_length_errors++;
 		if (vi->mergeable_rx_bufs) {
-			unsigned long ctx = (unsigned long)buf;
-			void *base = mergeable_ctx_to_buf_address(ctx);
-			put_page(virt_to_head_page(base));
+			put_page(virt_to_head_page(buf));
 		} else if (vi->big_packets) {
 			give_pages(rq, buf);
 		} else {
@@ -741,7 +730,7 @@ static int receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
 	}
 
 	if (vi->mergeable_rx_bufs)
-		skb = receive_mergeable(dev, vi, rq, (unsigned long)buf, len);
+		skb = receive_mergeable(dev, vi, rq, buf, ctx, len);
 	else if (vi->big_packets)
 		skb = receive_big(dev, vi, rq, buf, len);
 	else
@@ -869,7 +858,7 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
 	struct page_frag *alloc_frag = &rq->alloc_frag;
 	unsigned int headroom = virtnet_get_headroom(vi);
 	char *buf;
-	unsigned long ctx;
+	void *ctx;
 	int err;
 	unsigned int len, hole;
 
@@ -879,7 +868,7 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
 
 	buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset;
 	buf += headroom; /* advance address leaving hole at front of pkt */
-	ctx = mergeable_buf_to_ctx(buf, len);
+	ctx = (void *)(unsigned long)len;
 	get_page(alloc_frag->page);
 	alloc_frag->offset += len + headroom;
 	hole = alloc_frag->size - alloc_frag->offset;
@@ -894,7 +883,7 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
 	}
 
 	sg_init_one(rq->sg, buf, len);
-	err = virtqueue_add_inbuf(rq->vq, rq->sg, 1, (void *)ctx, gfp);
+	err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp);
 	if (err < 0)
 		put_page(virt_to_head_page(buf));
 
@@ -988,10 +977,20 @@ static int virtnet_receive(struct receive_queue *rq, int budget)
 	void *buf;
 	struct virtnet_stats *stats = this_cpu_ptr(vi->stats);
 
-	while (received < budget &&
-	       (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) {
-		bytes += receive_buf(vi, rq, buf, len);
-		received++;
+	if (vi->mergeable_rx_bufs) {
+		void *ctx;
+
+		while (received < budget &&
+		       (buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx))) {
+			bytes += receive_buf(vi, rq, buf, len, ctx);
+			received++;
+		}
+	} else {
+		while (received < budget &&
+		       (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) {
+			bytes += receive_buf(vi, rq, buf, len, NULL);
+			received++;
+		}
 	}
 
 	if (rq->vq->num_free > virtqueue_get_vring_size(rq->vq) / 2) {
@@ -2014,9 +2013,7 @@ static void free_unused_bufs(struct virtnet_info *vi)
 
 		while ((buf = virtqueue_detach_unused_buf(vq)) != NULL) {
 			if (vi->mergeable_rx_bufs) {
-				unsigned long ctx = (unsigned long)buf;
-				void *base = mergeable_ctx_to_buf_address(ctx);
-				put_page(virt_to_head_page(base));
+				put_page(virt_to_head_page(buf));
 			} else if (vi->big_packets) {
 				give_pages(&vi->rq[i], buf);
 			} else {
@@ -2044,7 +2041,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
 	int ret = -ENOMEM;
 	int i, total_vqs;
 	const char **names;
-	const bool *ctx;
+	bool *ctx;
 
 	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
 	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 6/6] virtio_net: reduce alignment for buffers
  2017-03-29 20:48 [PATCH 0/6] virtio: support extra per-buffer context Michael S. Tsirkin
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  2017-03-29 20:48   ` Michael S. Tsirkin
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: John Fastabend, Jason Wang, virtualization, netdev

We don't need to align length to any particular
value anymore. Aligning to L1 cache size probably
sill makes sense to reduce false sharing.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/net/virtio_net.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 94f94f3..824dd95 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -53,17 +53,6 @@ module_param(gso, bool, 0444);
  */
 DECLARE_EWMA(pkt_len, 0, 64)
 
-/* With mergeable buffers we align buffer address and use the low bits to
- * encode its true size. Buffer size is up to 1 page so we need to align to
- * square root of page size to ensure we reserve enough bits to encode the true
- * size.
- */
-#define MERGEABLE_BUFFER_MIN_ALIGN_SHIFT ((PAGE_SHIFT + 1) / 2)
-
-/* Minimum alignment for mergeable packet buffers. */
-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, \
-				   1 << MERGEABLE_BUFFER_MIN_ALIGN_SHIFT)
-
 #define VIRTNET_DRIVER_VERSION "1.0.0"
 
 struct virtnet_stats {
@@ -849,7 +838,7 @@ static unsigned int get_mergeable_buf_len(struct ewma_pkt_len *avg_pkt_len)
 
 	len = hdr_len + clamp_t(unsigned int, ewma_pkt_len_read(avg_pkt_len),
 			GOOD_PACKET_LEN, PAGE_SIZE - hdr_len);
-	return ALIGN(len, MERGEABLE_BUFFER_ALIGN);
+	return ALIGN(len, L1_CACHE_BYTES);
 }
 
 static int add_recvbuf_mergeable(struct virtnet_info *vi,
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 6/6] virtio_net: reduce alignment for buffers
@ 2017-03-29 20:48   ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-29 20:48 UTC (permalink / raw)
  To: linux-kernel; +Cc: netdev, John Fastabend, virtualization

We don't need to align length to any particular
value anymore. Aligning to L1 cache size probably
sill makes sense to reduce false sharing.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/net/virtio_net.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 94f94f3..824dd95 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -53,17 +53,6 @@ module_param(gso, bool, 0444);
  */
 DECLARE_EWMA(pkt_len, 0, 64)
 
-/* With mergeable buffers we align buffer address and use the low bits to
- * encode its true size. Buffer size is up to 1 page so we need to align to
- * square root of page size to ensure we reserve enough bits to encode the true
- * size.
- */
-#define MERGEABLE_BUFFER_MIN_ALIGN_SHIFT ((PAGE_SHIFT + 1) / 2)
-
-/* Minimum alignment for mergeable packet buffers. */
-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, \
-				   1 << MERGEABLE_BUFFER_MIN_ALIGN_SHIFT)
-
 #define VIRTNET_DRIVER_VERSION "1.0.0"
 
 struct virtnet_stats {
@@ -849,7 +838,7 @@ static unsigned int get_mergeable_buf_len(struct ewma_pkt_len *avg_pkt_len)
 
 	len = hdr_len + clamp_t(unsigned int, ewma_pkt_len_read(avg_pkt_len),
 			GOOD_PACKET_LEN, PAGE_SIZE - hdr_len);
-	return ALIGN(len, MERGEABLE_BUFFER_ALIGN);
+	return ALIGN(len, L1_CACHE_BYTES);
 }
 
 static int add_recvbuf_mergeable(struct virtnet_info *vi,
-- 
MST

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* RE: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-29 20:48   ` Michael S. Tsirkin
  (?)
  (?)
@ 2017-03-30  0:50     ` Gonglei (Arei)
  -1 siblings, 0 replies; 50+ messages in thread
From: Gonglei (Arei) @ 2017-03-30  0:50 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: John Fastabend, Jason Wang, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev,
	linux-remoteproc, linux-scsi, kvm


> -----Original Message-----
> From: Michael S. Tsirkin [mailto:mst@redhat.com]
> Sent: Thursday, March 30, 2017 4:49 AM
> Subject: [PATCH 1/6] virtio: wrap find_vqs
> 
> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/block/virtio_blk.c                 | 3 +--
>  drivers/char/virtio_console.c              | 6 +++---
>  drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
>  drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
>  drivers/net/caif/caif_virtio.c             | 3 +--
>  drivers/net/virtio_net.c                   | 3 +--
>  drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
>  drivers/scsi/virtio_scsi.c                 | 3 +--
>  drivers/virtio/virtio_balloon.c            | 3 +--
>  drivers/virtio/virtio_input.c              | 3 +--
>  include/linux/virtio_config.h              | 9 +++++++++
>  net/vmw_vsock/virtio_transport.c           | 6 +++---
>  12 files changed, 24 insertions(+), 23 deletions(-)
> 

Acked-by: Gonglei <arei.gonglei@huawei.com>


> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 1d4c9f8..c08c30c 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -455,8 +455,7 @@ static int init_vq(struct virtio_blk *vblk)
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index e9b7e0b..5da4c8e 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -1945,9 +1945,9 @@ static int init_vqs(struct ports_device *portdev)
>  		}
>  	}
>  	/* Find the queues. */
> -	err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
> -					      io_callbacks,
> -					      (const char **)io_names, NULL);
> +	err = virtio_find_vqs(portdev->vdev, nr_queues, vqs,
> +			      io_callbacks,
> +			      (const char **)io_names, NULL);
>  	if (err)
>  		goto free;
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c
> b/drivers/crypto/virtio/virtio_crypto_core.c
> index 21472e4..a111cd72 100644
> --- a/drivers/crypto/virtio/virtio_crypto_core.c
> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> @@ -119,8 +119,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
>  		names[i] = vi->data_vq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c
> b/drivers/gpu/drm/virtio/virtgpu_kms.c
> index 4918668..1e1c90b 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
> @@ -175,8 +175,7 @@ int virtio_gpu_driver_load(struct drm_device *dev,
> unsigned long flags)
>  	DRM_INFO("virgl 3d acceleration not supported by guest\n");
>  #endif
> 
> -	ret = vgdev->vdev->config->find_vqs(vgdev->vdev, 2, vqs,
> -					    callbacks, names, NULL);
> +	ret = virtio_find_vqs(vgdev->vdev, 2, vqs, callbacks, names, NULL);
>  	if (ret) {
>  		DRM_ERROR("failed to find virt queues\n");
>  		goto err_vqs;
> diff --git a/drivers/net/caif/caif_virtio.c b/drivers/net/caif/caif_virtio.c
> index bc0eb47..6122768 100644
> --- a/drivers/net/caif/caif_virtio.c
> +++ b/drivers/net/caif/caif_virtio.c
> @@ -679,8 +679,7 @@ static int cfv_probe(struct virtio_device *vdev)
>  		goto err;
> 
>  	/* Get the TX virtio ring. This is a "guest side vring". */
> -	err = vdev->config->find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names,
> -			NULL);
> +	err = virtio_find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names, NULL);
>  	if (err)
>  		goto err;
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index ea9890d..6802169 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2079,8 +2079,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  		names[txq2vq(i)] = vi->sq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c
> b/drivers/rpmsg/virtio_rpmsg_bus.c
> index 5e66e08..f7cade0 100644
> --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> @@ -869,7 +869,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
>  	init_waitqueue_head(&vrp->sendq);
> 
>  	/* We expect two virtqueues, rx and tx (and in this order) */
> -	err = vdev->config->find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
> +	err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
>  	if (err)
>  		goto free_vrp;
> 
> diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
> index 939c47d..e9222dc 100644
> --- a/drivers/scsi/virtio_scsi.c
> +++ b/drivers/scsi/virtio_scsi.c
> @@ -870,8 +870,7 @@ static int virtscsi_init(struct virtio_device *vdev,
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 34adf9b..408c174 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -418,8 +418,7 @@ static int init_vqs(struct virtio_balloon *vb)
>  	 * optionally stat.
>  	 */
>  	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 :
> 2;
> -	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names,
> -			NULL);
> +	err = virtio_find_vqs(vb->vdev, nvqs, vqs, callbacks, names, NULL);
>  	if (err)
>  		return err;
> 
> diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
> index 79f1293..3a0468f 100644
> --- a/drivers/virtio/virtio_input.c
> +++ b/drivers/virtio/virtio_input.c
> @@ -173,8 +173,7 @@ static int virtinput_init_vqs(struct virtio_input *vi)
>  	static const char * const names[] = { "events", "status" };
>  	int err;
> 
> -	err = vi->vdev->config->find_vqs(vi->vdev, 2, vqs, cbs, names,
> -			NULL);
> +	err = virtio_find_vqs(vi->vdev, 2, vqs, cbs, names, NULL);
>  	if (err)
>  		return err;
>  	vi->evt = vqs[0];
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index 8355bab..47f3d80 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -179,6 +179,15 @@ struct virtqueue *virtio_find_single_vq(struct
> virtio_device *vdev,
>  	return vq;
>  }
> 
> +static inline
> +int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
> +			struct virtqueue *vqs[], vq_callback_t *callbacks[],
> +			const char * const names[],
> +			struct irq_affinity *desc)
> +{
> +	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
> +}
> +
>  /**
>   * virtio_device_ready - enable vq use in probe function
>   * @vdev: the device
> diff --git a/net/vmw_vsock/virtio_transport.c
> b/net/vmw_vsock/virtio_transport.c
> index 68675a1..97e26e2 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -573,9 +573,9 @@ static int virtio_vsock_probe(struct virtio_device
> *vdev)
> 
>  	vsock->vdev = vdev;
> 
> -	ret = vsock->vdev->config->find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> -					    vsock->vqs, callbacks, names,
> -					    NULL);
> +	ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> +			      vsock->vqs, callbacks, names,
> +			      NULL);
>  	if (ret < 0)
>  		goto out;
> 
> --
> MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [PATCH 1/6] virtio: wrap find_vqs
@ 2017-03-30  0:50     ` Gonglei (Arei)
  0 siblings, 0 replies; 50+ messages in thread
From: Gonglei (Arei) @ 2017-03-30  0:50 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: John Fastabend, Jason Wang, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto


> -----Original Message-----
> From: Michael S. Tsirkin [mailto:mst@redhat.com]
> Sent: Thursday, March 30, 2017 4:49 AM
> Subject: [PATCH 1/6] virtio: wrap find_vqs
> 
> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/block/virtio_blk.c                 | 3 +--
>  drivers/char/virtio_console.c              | 6 +++---
>  drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
>  drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
>  drivers/net/caif/caif_virtio.c             | 3 +--
>  drivers/net/virtio_net.c                   | 3 +--
>  drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
>  drivers/scsi/virtio_scsi.c                 | 3 +--
>  drivers/virtio/virtio_balloon.c            | 3 +--
>  drivers/virtio/virtio_input.c              | 3 +--
>  include/linux/virtio_config.h              | 9 +++++++++
>  net/vmw_vsock/virtio_transport.c           | 6 +++---
>  12 files changed, 24 insertions(+), 23 deletions(-)
> 

Acked-by: Gonglei <arei.gonglei@huawei.com>


> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 1d4c9f8..c08c30c 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -455,8 +455,7 @@ static int init_vq(struct virtio_blk *vblk)
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index e9b7e0b..5da4c8e 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -1945,9 +1945,9 @@ static int init_vqs(struct ports_device *portdev)
>  		}
>  	}
>  	/* Find the queues. */
> -	err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
> -					      io_callbacks,
> -					      (const char **)io_names, NULL);
> +	err = virtio_find_vqs(portdev->vdev, nr_queues, vqs,
> +			      io_callbacks,
> +			      (const char **)io_names, NULL);
>  	if (err)
>  		goto free;
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c
> b/drivers/crypto/virtio/virtio_crypto_core.c
> index 21472e4..a111cd72 100644
> --- a/drivers/crypto/virtio/virtio_crypto_core.c
> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> @@ -119,8 +119,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
>  		names[i] = vi->data_vq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c
> b/drivers/gpu/drm/virtio/virtgpu_kms.c
> index 4918668..1e1c90b 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
> @@ -175,8 +175,7 @@ int virtio_gpu_driver_load(struct drm_device *dev,
> unsigned long flags)
>  	DRM_INFO("virgl 3d acceleration not supported by guest\n");
>  #endif
> 
> -	ret = vgdev->vdev->config->find_vqs(vgdev->vdev, 2, vqs,
> -					    callbacks, names, NULL);
> +	ret = virtio_find_vqs(vgdev->vdev, 2, vqs, callbacks, names, NULL);
>  	if (ret) {
>  		DRM_ERROR("failed to find virt queues\n");
>  		goto err_vqs;
> diff --git a/drivers/net/caif/caif_virtio.c b/drivers/net/caif/caif_virtio.c
> index bc0eb47..6122768 100644
> --- a/drivers/net/caif/caif_virtio.c
> +++ b/drivers/net/caif/caif_virtio.c
> @@ -679,8 +679,7 @@ static int cfv_probe(struct virtio_device *vdev)
>  		goto err;
> 
>  	/* Get the TX virtio ring. This is a "guest side vring". */
> -	err = vdev->config->find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names,
> -			NULL);
> +	err = virtio_find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names, NULL);
>  	if (err)
>  		goto err;
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index ea9890d..6802169 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2079,8 +2079,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  		names[txq2vq(i)] = vi->sq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c
> b/drivers/rpmsg/virtio_rpmsg_bus.c
> index 5e66e08..f7cade0 100644
> --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> @@ -869,7 +869,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
>  	init_waitqueue_head(&vrp->sendq);
> 
>  	/* We expect two virtqueues, rx and tx (and in this order) */
> -	err = vdev->config->find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
> +	err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
>  	if (err)
>  		goto free_vrp;
> 
> diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
> index 939c47d..e9222dc 100644
> --- a/drivers/scsi/virtio_scsi.c
> +++ b/drivers/scsi/virtio_scsi.c
> @@ -870,8 +870,7 @@ static int virtscsi_init(struct virtio_device *vdev,
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 34adf9b..408c174 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -418,8 +418,7 @@ static int init_vqs(struct virtio_balloon *vb)
>  	 * optionally stat.
>  	 */
>  	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 :
> 2;
> -	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names,
> -			NULL);
> +	err = virtio_find_vqs(vb->vdev, nvqs, vqs, callbacks, names, NULL);
>  	if (err)
>  		return err;
> 
> diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
> index 79f1293..3a0468f 100644
> --- a/drivers/virtio/virtio_input.c
> +++ b/drivers/virtio/virtio_input.c
> @@ -173,8 +173,7 @@ static int virtinput_init_vqs(struct virtio_input *vi)
>  	static const char * const names[] = { "events", "status" };
>  	int err;
> 
> -	err = vi->vdev->config->find_vqs(vi->vdev, 2, vqs, cbs, names,
> -			NULL);
> +	err = virtio_find_vqs(vi->vdev, 2, vqs, cbs, names, NULL);
>  	if (err)
>  		return err;
>  	vi->evt = vqs[0];
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index 8355bab..47f3d80 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -179,6 +179,15 @@ struct virtqueue *virtio_find_single_vq(struct
> virtio_device *vdev,
>  	return vq;
>  }
> 
> +static inline
> +int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
> +			struct virtqueue *vqs[], vq_callback_t *callbacks[],
> +			const char * const names[],
> +			struct irq_affinity *desc)
> +{
> +	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
> +}
> +
>  /**
>   * virtio_device_ready - enable vq use in probe function
>   * @vdev: the device
> diff --git a/net/vmw_vsock/virtio_transport.c
> b/net/vmw_vsock/virtio_transport.c
> index 68675a1..97e26e2 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -573,9 +573,9 @@ static int virtio_vsock_probe(struct virtio_device
> *vdev)
> 
>  	vsock->vdev = vdev;
> 
> -	ret = vsock->vdev->config->find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> -					    vsock->vqs, callbacks, names,
> -					    NULL);
> +	ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> +			      vsock->vqs, callbacks, names,
> +			      NULL);
>  	if (ret < 0)
>  		goto out;
> 
> --
> MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [PATCH 1/6] virtio: wrap find_vqs
@ 2017-03-30  0:50     ` Gonglei (Arei)
  0 siblings, 0 replies; 50+ messages in thread
From: Gonglei (Arei) @ 2017-03-30  0:50 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: John Fastabend, Jason Wang, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev,
	linux-remoteproc, linux-scsi, kvm


> -----Original Message-----
> From: Michael S. Tsirkin [mailto:mst@redhat.com]
> Sent: Thursday, March 30, 2017 4:49 AM
> Subject: [PATCH 1/6] virtio: wrap find_vqs
> 
> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/block/virtio_blk.c                 | 3 +--
>  drivers/char/virtio_console.c              | 6 +++---
>  drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
>  drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
>  drivers/net/caif/caif_virtio.c             | 3 +--
>  drivers/net/virtio_net.c                   | 3 +--
>  drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
>  drivers/scsi/virtio_scsi.c                 | 3 +--
>  drivers/virtio/virtio_balloon.c            | 3 +--
>  drivers/virtio/virtio_input.c              | 3 +--
>  include/linux/virtio_config.h              | 9 +++++++++
>  net/vmw_vsock/virtio_transport.c           | 6 +++---
>  12 files changed, 24 insertions(+), 23 deletions(-)
> 

Acked-by: Gonglei <arei.gonglei@huawei.com>


> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 1d4c9f8..c08c30c 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -455,8 +455,7 @@ static int init_vq(struct virtio_blk *vblk)
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index e9b7e0b..5da4c8e 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -1945,9 +1945,9 @@ static int init_vqs(struct ports_device *portdev)
>  		}
>  	}
>  	/* Find the queues. */
> -	err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
> -					      io_callbacks,
> -					      (const char **)io_names, NULL);
> +	err = virtio_find_vqs(portdev->vdev, nr_queues, vqs,
> +			      io_callbacks,
> +			      (const char **)io_names, NULL);
>  	if (err)
>  		goto free;
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c
> b/drivers/crypto/virtio/virtio_crypto_core.c
> index 21472e4..a111cd72 100644
> --- a/drivers/crypto/virtio/virtio_crypto_core.c
> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> @@ -119,8 +119,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
>  		names[i] = vi->data_vq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c
> b/drivers/gpu/drm/virtio/virtgpu_kms.c
> index 4918668..1e1c90b 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
> @@ -175,8 +175,7 @@ int virtio_gpu_driver_load(struct drm_device *dev,
> unsigned long flags)
>  	DRM_INFO("virgl 3d acceleration not supported by guest\n");
>  #endif
> 
> -	ret = vgdev->vdev->config->find_vqs(vgdev->vdev, 2, vqs,
> -					    callbacks, names, NULL);
> +	ret = virtio_find_vqs(vgdev->vdev, 2, vqs, callbacks, names, NULL);
>  	if (ret) {
>  		DRM_ERROR("failed to find virt queues\n");
>  		goto err_vqs;
> diff --git a/drivers/net/caif/caif_virtio.c b/drivers/net/caif/caif_virtio.c
> index bc0eb47..6122768 100644
> --- a/drivers/net/caif/caif_virtio.c
> +++ b/drivers/net/caif/caif_virtio.c
> @@ -679,8 +679,7 @@ static int cfv_probe(struct virtio_device *vdev)
>  		goto err;
> 
>  	/* Get the TX virtio ring. This is a "guest side vring". */
> -	err = vdev->config->find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names,
> -			NULL);
> +	err = virtio_find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names, NULL);
>  	if (err)
>  		goto err;
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index ea9890d..6802169 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2079,8 +2079,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  		names[txq2vq(i)] = vi->sq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c
> b/drivers/rpmsg/virtio_rpmsg_bus.c
> index 5e66e08..f7cade0 100644
> --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> @@ -869,7 +869,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
>  	init_waitqueue_head(&vrp->sendq);
> 
>  	/* We expect two virtqueues, rx and tx (and in this order) */
> -	err = vdev->config->find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
> +	err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
>  	if (err)
>  		goto free_vrp;
> 
> diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
> index 939c47d..e9222dc 100644
> --- a/drivers/scsi/virtio_scsi.c
> +++ b/drivers/scsi/virtio_scsi.c
> @@ -870,8 +870,7 @@ static int virtscsi_init(struct virtio_device *vdev,
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 34adf9b..408c174 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -418,8 +418,7 @@ static int init_vqs(struct virtio_balloon *vb)
>  	 * optionally stat.
>  	 */
>  	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 :
> 2;
> -	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names,
> -			NULL);
> +	err = virtio_find_vqs(vb->vdev, nvqs, vqs, callbacks, names, NULL);
>  	if (err)
>  		return err;
> 
> diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
> index 79f1293..3a0468f 100644
> --- a/drivers/virtio/virtio_input.c
> +++ b/drivers/virtio/virtio_input.c
> @@ -173,8 +173,7 @@ static int virtinput_init_vqs(struct virtio_input *vi)
>  	static const char * const names[] = { "events", "status" };
>  	int err;
> 
> -	err = vi->vdev->config->find_vqs(vi->vdev, 2, vqs, cbs, names,
> -			NULL);
> +	err = virtio_find_vqs(vi->vdev, 2, vqs, cbs, names, NULL);
>  	if (err)
>  		return err;
>  	vi->evt = vqs[0];
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index 8355bab..47f3d80 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -179,6 +179,15 @@ struct virtqueue *virtio_find_single_vq(struct
> virtio_device *vdev,
>  	return vq;
>  }
> 
> +static inline
> +int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
> +			struct virtqueue *vqs[], vq_callback_t *callbacks[],
> +			const char * const names[],
> +			struct irq_affinity *desc)
> +{
> +	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
> +}
> +
>  /**
>   * virtio_device_ready - enable vq use in probe function
>   * @vdev: the device
> diff --git a/net/vmw_vsock/virtio_transport.c
> b/net/vmw_vsock/virtio_transport.c
> index 68675a1..97e26e2 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -573,9 +573,9 @@ static int virtio_vsock_probe(struct virtio_device
> *vdev)
> 
>  	vsock->vdev = vdev;
> 
> -	ret = vsock->vdev->config->find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> -					    vsock->vqs, callbacks, names,
> -					    NULL);
> +	ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> +			      vsock->vqs, callbacks, names,
> +			      NULL);
>  	if (ret < 0)
>  		goto out;
> 
> --
> MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [PATCH 1/6] virtio: wrap find_vqs
@ 2017-03-30  0:50     ` Gonglei (Arei)
  0 siblings, 0 replies; 50+ messages in thread
From: Gonglei (Arei) @ 2017-03-30  0:50 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: John Fastabend, Jason Wang, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto


> -----Original Message-----
> From: Michael S. Tsirkin [mailto:mst@redhat.com]
> Sent: Thursday, March 30, 2017 4:49 AM
> Subject: [PATCH 1/6] virtio: wrap find_vqs
> 
> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/block/virtio_blk.c                 | 3 +--
>  drivers/char/virtio_console.c              | 6 +++---
>  drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
>  drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
>  drivers/net/caif/caif_virtio.c             | 3 +--
>  drivers/net/virtio_net.c                   | 3 +--
>  drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
>  drivers/scsi/virtio_scsi.c                 | 3 +--
>  drivers/virtio/virtio_balloon.c            | 3 +--
>  drivers/virtio/virtio_input.c              | 3 +--
>  include/linux/virtio_config.h              | 9 +++++++++
>  net/vmw_vsock/virtio_transport.c           | 6 +++---
>  12 files changed, 24 insertions(+), 23 deletions(-)
> 

Acked-by: Gonglei <arei.gonglei@huawei.com>


> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 1d4c9f8..c08c30c 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -455,8 +455,7 @@ static int init_vq(struct virtio_blk *vblk)
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index e9b7e0b..5da4c8e 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -1945,9 +1945,9 @@ static int init_vqs(struct ports_device *portdev)
>  		}
>  	}
>  	/* Find the queues. */
> -	err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
> -					      io_callbacks,
> -					      (const char **)io_names, NULL);
> +	err = virtio_find_vqs(portdev->vdev, nr_queues, vqs,
> +			      io_callbacks,
> +			      (const char **)io_names, NULL);
>  	if (err)
>  		goto free;
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c
> b/drivers/crypto/virtio/virtio_crypto_core.c
> index 21472e4..a111cd72 100644
> --- a/drivers/crypto/virtio/virtio_crypto_core.c
> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> @@ -119,8 +119,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
>  		names[i] = vi->data_vq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c
> b/drivers/gpu/drm/virtio/virtgpu_kms.c
> index 4918668..1e1c90b 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
> @@ -175,8 +175,7 @@ int virtio_gpu_driver_load(struct drm_device *dev,
> unsigned long flags)
>  	DRM_INFO("virgl 3d acceleration not supported by guest\n");
>  #endif
> 
> -	ret = vgdev->vdev->config->find_vqs(vgdev->vdev, 2, vqs,
> -					    callbacks, names, NULL);
> +	ret = virtio_find_vqs(vgdev->vdev, 2, vqs, callbacks, names, NULL);
>  	if (ret) {
>  		DRM_ERROR("failed to find virt queues\n");
>  		goto err_vqs;
> diff --git a/drivers/net/caif/caif_virtio.c b/drivers/net/caif/caif_virtio.c
> index bc0eb47..6122768 100644
> --- a/drivers/net/caif/caif_virtio.c
> +++ b/drivers/net/caif/caif_virtio.c
> @@ -679,8 +679,7 @@ static int cfv_probe(struct virtio_device *vdev)
>  		goto err;
> 
>  	/* Get the TX virtio ring. This is a "guest side vring". */
> -	err = vdev->config->find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names,
> -			NULL);
> +	err = virtio_find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names, NULL);
>  	if (err)
>  		goto err;
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index ea9890d..6802169 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2079,8 +2079,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  		names[txq2vq(i)] = vi->sq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c
> b/drivers/rpmsg/virtio_rpmsg_bus.c
> index 5e66e08..f7cade0 100644
> --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> @@ -869,7 +869,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
>  	init_waitqueue_head(&vrp->sendq);
> 
>  	/* We expect two virtqueues, rx and tx (and in this order) */
> -	err = vdev->config->find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
> +	err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
>  	if (err)
>  		goto free_vrp;
> 
> diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
> index 939c47d..e9222dc 100644
> --- a/drivers/scsi/virtio_scsi.c
> +++ b/drivers/scsi/virtio_scsi.c
> @@ -870,8 +870,7 @@ static int virtscsi_init(struct virtio_device *vdev,
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 34adf9b..408c174 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -418,8 +418,7 @@ static int init_vqs(struct virtio_balloon *vb)
>  	 * optionally stat.
>  	 */
>  	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 :
> 2;
> -	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names,
> -			NULL);
> +	err = virtio_find_vqs(vb->vdev, nvqs, vqs, callbacks, names, NULL);
>  	if (err)
>  		return err;
> 
> diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
> index 79f1293..3a0468f 100644
> --- a/drivers/virtio/virtio_input.c
> +++ b/drivers/virtio/virtio_input.c
> @@ -173,8 +173,7 @@ static int virtinput_init_vqs(struct virtio_input *vi)
>  	static const char * const names[] = { "events", "status" };
>  	int err;
> 
> -	err = vi->vdev->config->find_vqs(vi->vdev, 2, vqs, cbs, names,
> -			NULL);
> +	err = virtio_find_vqs(vi->vdev, 2, vqs, cbs, names, NULL);
>  	if (err)
>  		return err;
>  	vi->evt = vqs[0];
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index 8355bab..47f3d80 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -179,6 +179,15 @@ struct virtqueue *virtio_find_single_vq(struct
> virtio_device *vdev,
>  	return vq;
>  }
> 
> +static inline
> +int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
> +			struct virtqueue *vqs[], vq_callback_t *callbacks[],
> +			const char * const names[],
> +			struct irq_affinity *desc)
> +{
> +	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
> +}
> +
>  /**
>   * virtio_device_ready - enable vq use in probe function
>   * @vdev: the device
> diff --git a/net/vmw_vsock/virtio_transport.c
> b/net/vmw_vsock/virtio_transport.c
> index 68675a1..97e26e2 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -573,9 +573,9 @@ static int virtio_vsock_probe(struct virtio_device
> *vdev)
> 
>  	vsock->vdev = vdev;
> 
> -	ret = vsock->vdev->config->find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> -					    vsock->vqs, callbacks, names,
> -					    NULL);
> +	ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> +			      vsock->vqs, callbacks, names,
> +			      NULL);
>  	if (ret < 0)
>  		goto out;
> 
> --
> MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-29 20:48   ` Michael S. Tsirkin
  (?)
@ 2017-03-30  0:50   ` Gonglei (Arei)
  -1 siblings, 0 replies; 50+ messages in thread
From: Gonglei (Arei) @ 2017-03-30  0:50 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: Dmitry Tarnyagin, kvm, David Airlie, linux-remoteproc, dri-devel,
	Bjorn Andersson, James E.J. Bottomley, Herbert Xu, linux-scsi,
	John Fastabend, Arnd Bergmann, Amit Shah, Stefan Hajnoczi,
	virtualization, Martin K. Petersen, Greg Kroah-Hartman,
	linux-crypto, netdev


> -----Original Message-----
> From: Michael S. Tsirkin [mailto:mst@redhat.com]
> Sent: Thursday, March 30, 2017 4:49 AM
> Subject: [PATCH 1/6] virtio: wrap find_vqs
> 
> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/block/virtio_blk.c                 | 3 +--
>  drivers/char/virtio_console.c              | 6 +++---
>  drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
>  drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
>  drivers/net/caif/caif_virtio.c             | 3 +--
>  drivers/net/virtio_net.c                   | 3 +--
>  drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
>  drivers/scsi/virtio_scsi.c                 | 3 +--
>  drivers/virtio/virtio_balloon.c            | 3 +--
>  drivers/virtio/virtio_input.c              | 3 +--
>  include/linux/virtio_config.h              | 9 +++++++++
>  net/vmw_vsock/virtio_transport.c           | 6 +++---
>  12 files changed, 24 insertions(+), 23 deletions(-)
> 

Acked-by: Gonglei <arei.gonglei@huawei.com>


> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 1d4c9f8..c08c30c 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -455,8 +455,7 @@ static int init_vq(struct virtio_blk *vblk)
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index e9b7e0b..5da4c8e 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -1945,9 +1945,9 @@ static int init_vqs(struct ports_device *portdev)
>  		}
>  	}
>  	/* Find the queues. */
> -	err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
> -					      io_callbacks,
> -					      (const char **)io_names, NULL);
> +	err = virtio_find_vqs(portdev->vdev, nr_queues, vqs,
> +			      io_callbacks,
> +			      (const char **)io_names, NULL);
>  	if (err)
>  		goto free;
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c
> b/drivers/crypto/virtio/virtio_crypto_core.c
> index 21472e4..a111cd72 100644
> --- a/drivers/crypto/virtio/virtio_crypto_core.c
> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> @@ -119,8 +119,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
>  		names[i] = vi->data_vq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c
> b/drivers/gpu/drm/virtio/virtgpu_kms.c
> index 4918668..1e1c90b 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
> @@ -175,8 +175,7 @@ int virtio_gpu_driver_load(struct drm_device *dev,
> unsigned long flags)
>  	DRM_INFO("virgl 3d acceleration not supported by guest\n");
>  #endif
> 
> -	ret = vgdev->vdev->config->find_vqs(vgdev->vdev, 2, vqs,
> -					    callbacks, names, NULL);
> +	ret = virtio_find_vqs(vgdev->vdev, 2, vqs, callbacks, names, NULL);
>  	if (ret) {
>  		DRM_ERROR("failed to find virt queues\n");
>  		goto err_vqs;
> diff --git a/drivers/net/caif/caif_virtio.c b/drivers/net/caif/caif_virtio.c
> index bc0eb47..6122768 100644
> --- a/drivers/net/caif/caif_virtio.c
> +++ b/drivers/net/caif/caif_virtio.c
> @@ -679,8 +679,7 @@ static int cfv_probe(struct virtio_device *vdev)
>  		goto err;
> 
>  	/* Get the TX virtio ring. This is a "guest side vring". */
> -	err = vdev->config->find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names,
> -			NULL);
> +	err = virtio_find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names, NULL);
>  	if (err)
>  		goto err;
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index ea9890d..6802169 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2079,8 +2079,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  		names[txq2vq(i)] = vi->sq[i].name;
>  	}
> 
> -	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> -					 names, NULL);
> +	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
>  	if (ret)
>  		goto err_find;
> 
> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c
> b/drivers/rpmsg/virtio_rpmsg_bus.c
> index 5e66e08..f7cade0 100644
> --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> @@ -869,7 +869,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
>  	init_waitqueue_head(&vrp->sendq);
> 
>  	/* We expect two virtqueues, rx and tx (and in this order) */
> -	err = vdev->config->find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
> +	err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL);
>  	if (err)
>  		goto free_vrp;
> 
> diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
> index 939c47d..e9222dc 100644
> --- a/drivers/scsi/virtio_scsi.c
> +++ b/drivers/scsi/virtio_scsi.c
> @@ -870,8 +870,7 @@ static int virtscsi_init(struct virtio_device *vdev,
>  	}
> 
>  	/* Discover virtqueues and write information to configuration.  */
> -	err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
> -			&desc);
> +	err = virtio_find_vqs(vdev, num_vqs, vqs, callbacks, names, &desc);
>  	if (err)
>  		goto out;
> 
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 34adf9b..408c174 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -418,8 +418,7 @@ static int init_vqs(struct virtio_balloon *vb)
>  	 * optionally stat.
>  	 */
>  	nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 :
> 2;
> -	err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names,
> -			NULL);
> +	err = virtio_find_vqs(vb->vdev, nvqs, vqs, callbacks, names, NULL);
>  	if (err)
>  		return err;
> 
> diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
> index 79f1293..3a0468f 100644
> --- a/drivers/virtio/virtio_input.c
> +++ b/drivers/virtio/virtio_input.c
> @@ -173,8 +173,7 @@ static int virtinput_init_vqs(struct virtio_input *vi)
>  	static const char * const names[] = { "events", "status" };
>  	int err;
> 
> -	err = vi->vdev->config->find_vqs(vi->vdev, 2, vqs, cbs, names,
> -			NULL);
> +	err = virtio_find_vqs(vi->vdev, 2, vqs, cbs, names, NULL);
>  	if (err)
>  		return err;
>  	vi->evt = vqs[0];
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index 8355bab..47f3d80 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -179,6 +179,15 @@ struct virtqueue *virtio_find_single_vq(struct
> virtio_device *vdev,
>  	return vq;
>  }
> 
> +static inline
> +int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
> +			struct virtqueue *vqs[], vq_callback_t *callbacks[],
> +			const char * const names[],
> +			struct irq_affinity *desc)
> +{
> +	return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, desc);
> +}
> +
>  /**
>   * virtio_device_ready - enable vq use in probe function
>   * @vdev: the device
> diff --git a/net/vmw_vsock/virtio_transport.c
> b/net/vmw_vsock/virtio_transport.c
> index 68675a1..97e26e2 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -573,9 +573,9 @@ static int virtio_vsock_probe(struct virtio_device
> *vdev)
> 
>  	vsock->vdev = vdev;
> 
> -	ret = vsock->vdev->config->find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> -					    vsock->vqs, callbacks, names,
> -					    NULL);
> +	ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX,
> +			      vsock->vqs, callbacks, names,
> +			      NULL);
>  	if (ret < 0)
>  		goto out;
> 
> --
> MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-29 20:48   ` Michael S. Tsirkin
@ 2017-03-30  6:00     ` Jason Wang
  -1 siblings, 0 replies; 50+ messages in thread
From: Jason Wang @ 2017-03-30  6:00 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: John Fastabend, Arnd Bergmann, Greg Kroah-Hartman, Amit Shah,
	Gonglei, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev,
	linux-remoteproc, linux-scsi, kvm



On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
>
> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> ---

A quick glance and it looks ok, but what the benefit of this series, is 
it required by other changes?

Thanks

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
@ 2017-03-30  6:00     ` Jason Wang
  0 siblings, 0 replies; 50+ messages in thread
From: Jason Wang @ 2017-03-30  6:00 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: John Fastabend, Arnd Bergmann, Greg Kroah-Hartman, Amit Shah,
	Gonglei, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev,
	linux-remoteproc



On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
>
> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> ---

A quick glance and it looks ok, but what the benefit of this series, is 
it required by other changes?

Thanks

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-29 20:48   ` Michael S. Tsirkin
                     ` (2 preceding siblings ...)
  (?)
@ 2017-03-30  6:00   ` Jason Wang
  -1 siblings, 0 replies; 50+ messages in thread
From: Jason Wang @ 2017-03-30  6:00 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: Dmitry Tarnyagin, kvm, David Airlie, linux-remoteproc, dri-devel,
	Bjorn Andersson, James E.J. Bottomley, Herbert Xu, linux-scsi,
	John Fastabend, Arnd Bergmann, Amit Shah, Stefan Hajnoczi,
	virtualization, Martin K. Petersen, Greg Kroah-Hartman,
	linux-crypto, netdev, David S. Miller



On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
>
> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> ---

A quick glance and it looks ok, but what the benefit of this series, is 
it required by other changes?

Thanks
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 2/6] virtio: add context flag to find vqs
  2017-03-29 20:48   ` Michael S. Tsirkin
@ 2017-03-30  7:17     ` Cornelia Huck
  -1 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:17 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, linux-s390, kvm, Heiko Carstens, John Fastabend,
	Sudeep Dutt, virtualization, Ashutosh Dixit, Martin Schwidefsky

On Wed, 29 Mar 2017 23:48:51 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> Allows maintaining extra context per vq.  For ease of use, passing in
> NULL is legal and disables the feature for all vqs.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/misc/mic/vop/vop_main.c    |  9 ++++++---
>  drivers/s390/virtio/kvm_virtio.c   |  6 ++++--
>  drivers/s390/virtio/virtio_ccw.c   |  7 ++++---
>  drivers/virtio/virtio_mmio.c       |  8 +++++---
>  drivers/virtio/virtio_pci_common.c | 18 +++++++++++-------
>  drivers/virtio/virtio_pci_common.h |  4 +++-
>  drivers/virtio/virtio_pci_legacy.c |  4 +++-
>  drivers/virtio/virtio_pci_modern.c | 12 ++++++++----
>  drivers/virtio/virtio_ring.c       |  7 +++++--
>  include/linux/virtio_config.h      | 18 +++++++++++++++---
>  include/linux/virtio_ring.h        |  3 +++
>  11 files changed, 67 insertions(+), 29 deletions(-)

This series really needs a cover letter, explaining the motivation for
adding this context.

>From what I understand, you want to track some length parameter in
virtio-net. As you don't use indirect descriptors in that case, you
want to use a context instead. Did I get this correctly?

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 2/6] virtio: add context flag to find vqs
@ 2017-03-30  7:17     ` Cornelia Huck
  0 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:17 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, linux-s390, kvm, Heiko Carstens, John Fastabend,
	Sudeep Dutt, virtualization, Ashutosh Dixit, Martin Schwidefsky

On Wed, 29 Mar 2017 23:48:51 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> Allows maintaining extra context per vq.  For ease of use, passing in
> NULL is legal and disables the feature for all vqs.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/misc/mic/vop/vop_main.c    |  9 ++++++---
>  drivers/s390/virtio/kvm_virtio.c   |  6 ++++--
>  drivers/s390/virtio/virtio_ccw.c   |  7 ++++---
>  drivers/virtio/virtio_mmio.c       |  8 +++++---
>  drivers/virtio/virtio_pci_common.c | 18 +++++++++++-------
>  drivers/virtio/virtio_pci_common.h |  4 +++-
>  drivers/virtio/virtio_pci_legacy.c |  4 +++-
>  drivers/virtio/virtio_pci_modern.c | 12 ++++++++----
>  drivers/virtio/virtio_ring.c       |  7 +++++--
>  include/linux/virtio_config.h      | 18 +++++++++++++++---
>  include/linux/virtio_ring.h        |  3 +++
>  11 files changed, 67 insertions(+), 29 deletions(-)

This series really needs a cover letter, explaining the motivation for
adding this context.

From what I understand, you want to track some length parameter in
virtio-net. As you don't use indirect descriptors in that case, you
want to use a context instead. Did I get this correctly?

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 2/6] virtio: add context flag to find vqs
  2017-03-29 20:48   ` Michael S. Tsirkin
  (?)
  (?)
@ 2017-03-30  7:17   ` Cornelia Huck
  -1 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:17 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-s390, kvm, Heiko Carstens, John Fastabend, linux-kernel,
	Sudeep Dutt, Ashutosh Dixit, Martin Schwidefsky, virtualization

On Wed, 29 Mar 2017 23:48:51 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> Allows maintaining extra context per vq.  For ease of use, passing in
> NULL is legal and disables the feature for all vqs.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/misc/mic/vop/vop_main.c    |  9 ++++++---
>  drivers/s390/virtio/kvm_virtio.c   |  6 ++++--
>  drivers/s390/virtio/virtio_ccw.c   |  7 ++++---
>  drivers/virtio/virtio_mmio.c       |  8 +++++---
>  drivers/virtio/virtio_pci_common.c | 18 +++++++++++-------
>  drivers/virtio/virtio_pci_common.h |  4 +++-
>  drivers/virtio/virtio_pci_legacy.c |  4 +++-
>  drivers/virtio/virtio_pci_modern.c | 12 ++++++++----
>  drivers/virtio/virtio_ring.c       |  7 +++++--
>  include/linux/virtio_config.h      | 18 +++++++++++++++---
>  include/linux/virtio_ring.h        |  3 +++
>  11 files changed, 67 insertions(+), 29 deletions(-)

This series really needs a cover letter, explaining the motivation for
adding this context.

From what I understand, you want to track some length parameter in
virtio-net. As you don't use indirect descriptors in that case, you
want to use a context instead. Did I get this correctly?

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-29 20:48   ` Michael S. Tsirkin
@ 2017-03-30  7:18     ` Cornelia Huck
  -1 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:18 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, Dmitry Tarnyagin, kvm, David Airlie,
	linux-remoteproc, dri-devel, Bjorn Andersson,
	James E.J. Bottomley, Herbert Xu, linux-scsi, John Fastabend,
	Arnd Bergmann, Amit Shah, Stefan Hajnoczi, virtualization,
	Martin K. Petersen  <martin.petersen@oracle.com>,
	Greg Kroah-Hartman, linux-crypto, netdev, David S. Miller

On Wed, 29 Mar 2017 23:48:44 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/block/virtio_blk.c                 | 3 +--
>  drivers/char/virtio_console.c              | 6 +++---
>  drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
>  drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
>  drivers/net/caif/caif_virtio.c             | 3 +--
>  drivers/net/virtio_net.c                   | 3 +--
>  drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
>  drivers/scsi/virtio_scsi.c                 | 3 +--
>  drivers/virtio/virtio_balloon.c            | 3 +--
>  drivers/virtio/virtio_input.c              | 3 +--
>  include/linux/virtio_config.h              | 9 +++++++++
>  net/vmw_vsock/virtio_transport.c           | 6 +++---
>  12 files changed, 24 insertions(+), 23 deletions(-)

Regardless whether that context thing is the right thing to do, this
looks like a sensible cleanup.

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
@ 2017-03-30  7:18     ` Cornelia Huck
  0 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:18 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, Dmitry Tarnyagin, kvm, David Airlie,
	linux-remoteproc, dri-devel, Bjorn Andersson,
	James E.J. Bottomley, Herbert Xu, linux-scsi, John Fastabend,
	Arnd Bergmann, Amit Shah, Stefan Hajnoczi, virtualization,
	Martin K. Petersen, Greg Kroah-Hartman, linux-crypto, netdev,
	David S. Miller

On Wed, 29 Mar 2017 23:48:44 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/block/virtio_blk.c                 | 3 +--
>  drivers/char/virtio_console.c              | 6 +++---
>  drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
>  drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
>  drivers/net/caif/caif_virtio.c             | 3 +--
>  drivers/net/virtio_net.c                   | 3 +--
>  drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
>  drivers/scsi/virtio_scsi.c                 | 3 +--
>  drivers/virtio/virtio_balloon.c            | 3 +--
>  drivers/virtio/virtio_input.c              | 3 +--
>  include/linux/virtio_config.h              | 9 +++++++++
>  net/vmw_vsock/virtio_transport.c           | 6 +++---
>  12 files changed, 24 insertions(+), 23 deletions(-)

Regardless whether that context thing is the right thing to do, this
looks like a sensible cleanup.

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-29 20:48   ` Michael S. Tsirkin
                     ` (5 preceding siblings ...)
  (?)
@ 2017-03-30  7:18   ` Cornelia Huck
  -1 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:18 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Dmitry Tarnyagin, James E.J. Bottomley, Herbert Xu, kvm,
	Amit Shah, David Airlie, John Fastabend, David S. Miller,
	linux-remoteproc, linux-kernel, dri-devel, Bjorn Andersson,
	Greg Kroah-Hartman, Martin K. Petersen, Arnd Bergmann,
	linux-crypto, Stefan Hajnoczi, linux-scsi, virtualization,
	netdev

On Wed, 29 Mar 2017 23:48:44 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/block/virtio_blk.c                 | 3 +--
>  drivers/char/virtio_console.c              | 6 +++---
>  drivers/crypto/virtio/virtio_crypto_core.c | 3 +--
>  drivers/gpu/drm/virtio/virtgpu_kms.c       | 3 +--
>  drivers/net/caif/caif_virtio.c             | 3 +--
>  drivers/net/virtio_net.c                   | 3 +--
>  drivers/rpmsg/virtio_rpmsg_bus.c           | 2 +-
>  drivers/scsi/virtio_scsi.c                 | 3 +--
>  drivers/virtio/virtio_balloon.c            | 3 +--
>  drivers/virtio/virtio_input.c              | 3 +--
>  include/linux/virtio_config.h              | 9 +++++++++
>  net/vmw_vsock/virtio_transport.c           | 6 +++---
>  12 files changed, 24 insertions(+), 23 deletions(-)

Regardless whether that context thing is the right thing to do, this
looks like a sensible cleanup.

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 3/6] virtio: allow extra context per descriptor
  2017-03-29 20:48   ` Michael S. Tsirkin
@ 2017-03-30  7:23     ` Cornelia Huck
  -1 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:23 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: linux-kernel, John Fastabend, virtualization

On Wed, 29 Mar 2017 23:48:53 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> Allow extra context per descriptor. To avoid slow down for data path,
> this disables use of indirect descriptors for this vq.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++++++++++--------
>  include/linux/virtio.h       |  9 ++++++
>  2 files changed, 66 insertions(+), 13 deletions(-)
> 

>  /**
> + * virtqueue_add_inbuf_ctx - expose input buffers to other end
> + * @vq: the struct virtqueue we're talking about.
> + * @sg: scatterlist (must be well-formed and terminated!)
> + * @num: the number of entries in @sg writable by other side
> + * @data: the token identifying the buffer.
> + * @ctx: extra context for the token

I think that needs do that ctx != NULL collides with indirect
descriptors.

> + * @gfp: how to do memory allocations (if necessary).
> + *
> + * Caller must ensure we don't call this with other virtqueue operations
> + * at the same time (except where noted).
> + *
> + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
> + */
> +int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
> +			struct scatterlist *sg, unsigned int num,
> +			void *data,
> +			void *ctx,
> +			gfp_t gfp)
> +{
> +	return virtqueue_add(vq, &sg, num, 0, 1, data, ctx, gfp);
> +}
> +EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx);

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 3/6] virtio: allow extra context per descriptor
@ 2017-03-30  7:23     ` Cornelia Huck
  0 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:23 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: John Fastabend, linux-kernel, virtualization

On Wed, 29 Mar 2017 23:48:53 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> Allow extra context per descriptor. To avoid slow down for data path,
> this disables use of indirect descriptors for this vq.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++++++++++--------
>  include/linux/virtio.h       |  9 ++++++
>  2 files changed, 66 insertions(+), 13 deletions(-)
> 

>  /**
> + * virtqueue_add_inbuf_ctx - expose input buffers to other end
> + * @vq: the struct virtqueue we're talking about.
> + * @sg: scatterlist (must be well-formed and terminated!)
> + * @num: the number of entries in @sg writable by other side
> + * @data: the token identifying the buffer.
> + * @ctx: extra context for the token

I think that needs do that ctx != NULL collides with indirect
descriptors.

> + * @gfp: how to do memory allocations (if necessary).
> + *
> + * Caller must ensure we don't call this with other virtqueue operations
> + * at the same time (except where noted).
> + *
> + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
> + */
> +int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
> +			struct scatterlist *sg, unsigned int num,
> +			void *data,
> +			void *ctx,
> +			gfp_t gfp)
> +{
> +	return virtqueue_add(vq, &sg, num, 0, 1, data, ctx, gfp);
> +}
> +EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx);

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 4/6] virtio_net: allow specifying context for rx
  2017-03-29 20:48   ` Michael S. Tsirkin
  (?)
@ 2017-03-30  7:26   ` Cornelia Huck
  2017-03-30 14:31     ` Michael S. Tsirkin
  2017-03-30 14:31     ` Michael S. Tsirkin
  -1 siblings, 2 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:26 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: linux-kernel, netdev, John Fastabend, virtualization

On Wed, 29 Mar 2017 23:48:54 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> With mergeable buffers we never use s/g for rx,
> so allow specifying context in that case.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/net/virtio_net.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 6802169..340f737 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2044,6 +2044,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  	int ret = -ENOMEM;
>  	int i, total_vqs;
>  	const char **names;
> +	const bool *ctx;
>  
>  	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
>  	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
> @@ -2062,6 +2063,13 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
>  	if (!names)
>  		goto err_names;
> +	if (vi->mergeable_rx_bufs) {
> +		ctx = kzalloc(total_vqs * sizeof(*ctx), GFP_KERNEL);
> +		if (!ctx)
> +			goto err_ctx;
> +	} else {
> +		ctx = NULL;
> +	}
>  
>  	/* Parameters for control virtqueue, if any */
>  	if (vi->has_cvq) {
> @@ -2077,9 +2085,12 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  		sprintf(vi->sq[i].name, "output.%d", i);
>  		names[rxq2vq(i)] = vi->rq[i].name;
>  		names[txq2vq(i)] = vi->sq[i].name;
> +		if (ctx)
> +			ctx[rxq2vq(i)] = true;
>  	}
>  
> -	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
> +	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> +					 names, ctx, NULL);

virtio_find_vqs_ctx()? (Needs to be exported, obviously.)

>  	if (ret)
>  		goto err_find;
>  
> @@ -2101,6 +2112,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  	return 0;
>  
>  err_find:
> +	kfree(ctx);
> +err_ctx:
>  	kfree(names);
>  err_names:
>  	kfree(callbacks);

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 4/6] virtio_net: allow specifying context for rx
  2017-03-29 20:48   ` Michael S. Tsirkin
  (?)
  (?)
@ 2017-03-30  7:26   ` Cornelia Huck
  -1 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30  7:26 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, John Fastabend, linux-kernel, virtualization

On Wed, 29 Mar 2017 23:48:54 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> With mergeable buffers we never use s/g for rx,
> so allow specifying context in that case.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/net/virtio_net.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 6802169..340f737 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2044,6 +2044,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  	int ret = -ENOMEM;
>  	int i, total_vqs;
>  	const char **names;
> +	const bool *ctx;
>  
>  	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
>  	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
> @@ -2062,6 +2063,13 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
>  	if (!names)
>  		goto err_names;
> +	if (vi->mergeable_rx_bufs) {
> +		ctx = kzalloc(total_vqs * sizeof(*ctx), GFP_KERNEL);
> +		if (!ctx)
> +			goto err_ctx;
> +	} else {
> +		ctx = NULL;
> +	}
>  
>  	/* Parameters for control virtqueue, if any */
>  	if (vi->has_cvq) {
> @@ -2077,9 +2085,12 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  		sprintf(vi->sq[i].name, "output.%d", i);
>  		names[rxq2vq(i)] = vi->rq[i].name;
>  		names[txq2vq(i)] = vi->sq[i].name;
> +		if (ctx)
> +			ctx[rxq2vq(i)] = true;
>  	}
>  
> -	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
> +	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> +					 names, ctx, NULL);

virtio_find_vqs_ctx()? (Needs to be exported, obviously.)

>  	if (ret)
>  		goto err_find;
>  
> @@ -2101,6 +2112,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>  	return 0;
>  
>  err_find:
> +	kfree(ctx);
> +err_ctx:
>  	kfree(names);
>  err_names:
>  	kfree(callbacks);

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 4/6] virtio_net: allow specifying context for rx
  2017-03-30  7:26   ` Cornelia Huck
@ 2017-03-30 14:31     ` Michael S. Tsirkin
  2017-03-30 14:46         ` Cornelia Huck
  2017-03-30 14:31     ` Michael S. Tsirkin
  1 sibling, 1 reply; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-30 14:31 UTC (permalink / raw)
  To: Cornelia Huck; +Cc: linux-kernel, netdev, John Fastabend, virtualization

On Thu, Mar 30, 2017 at 09:26:51AM +0200, Cornelia Huck wrote:
> On Wed, 29 Mar 2017 23:48:54 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > With mergeable buffers we never use s/g for rx,
> > so allow specifying context in that case.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  drivers/net/virtio_net.c | 15 ++++++++++++++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 6802169..340f737 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -2044,6 +2044,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >  	int ret = -ENOMEM;
> >  	int i, total_vqs;
> >  	const char **names;
> > +	const bool *ctx;
> >  
> >  	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
> >  	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
> > @@ -2062,6 +2063,13 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >  	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
> >  	if (!names)
> >  		goto err_names;
> > +	if (vi->mergeable_rx_bufs) {
> > +		ctx = kzalloc(total_vqs * sizeof(*ctx), GFP_KERNEL);
> > +		if (!ctx)
> > +			goto err_ctx;
> > +	} else {
> > +		ctx = NULL;
> > +	}
> >  
> >  	/* Parameters for control virtqueue, if any */
> >  	if (vi->has_cvq) {
> > @@ -2077,9 +2085,12 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >  		sprintf(vi->sq[i].name, "output.%d", i);
> >  		names[rxq2vq(i)] = vi->rq[i].name;
> >  		names[txq2vq(i)] = vi->sq[i].name;
> > +		if (ctx)
> > +			ctx[rxq2vq(i)] = true;
> >  	}
> >  
> > -	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
> > +	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> > +					 names, ctx, NULL);
> 
> virtio_find_vqs_ctx()? (Needs to be exported, obviously.)

I guess I can do that but there's a single user ATM.
Do you think it's worth doing right now, or wait until
it gets more users?


> >  	if (ret)
> >  		goto err_find;
> >  
> > @@ -2101,6 +2112,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >  	return 0;
> >  
> >  err_find:
> > +	kfree(ctx);
> > +err_ctx:
> >  	kfree(names);
> >  err_names:
> >  	kfree(callbacks);

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 4/6] virtio_net: allow specifying context for rx
  2017-03-30  7:26   ` Cornelia Huck
  2017-03-30 14:31     ` Michael S. Tsirkin
@ 2017-03-30 14:31     ` Michael S. Tsirkin
  1 sibling, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-30 14:31 UTC (permalink / raw)
  To: Cornelia Huck; +Cc: netdev, John Fastabend, linux-kernel, virtualization

On Thu, Mar 30, 2017 at 09:26:51AM +0200, Cornelia Huck wrote:
> On Wed, 29 Mar 2017 23:48:54 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > With mergeable buffers we never use s/g for rx,
> > so allow specifying context in that case.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  drivers/net/virtio_net.c | 15 ++++++++++++++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 6802169..340f737 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -2044,6 +2044,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >  	int ret = -ENOMEM;
> >  	int i, total_vqs;
> >  	const char **names;
> > +	const bool *ctx;
> >  
> >  	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
> >  	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
> > @@ -2062,6 +2063,13 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >  	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
> >  	if (!names)
> >  		goto err_names;
> > +	if (vi->mergeable_rx_bufs) {
> > +		ctx = kzalloc(total_vqs * sizeof(*ctx), GFP_KERNEL);
> > +		if (!ctx)
> > +			goto err_ctx;
> > +	} else {
> > +		ctx = NULL;
> > +	}
> >  
> >  	/* Parameters for control virtqueue, if any */
> >  	if (vi->has_cvq) {
> > @@ -2077,9 +2085,12 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >  		sprintf(vi->sq[i].name, "output.%d", i);
> >  		names[rxq2vq(i)] = vi->rq[i].name;
> >  		names[txq2vq(i)] = vi->sq[i].name;
> > +		if (ctx)
> > +			ctx[rxq2vq(i)] = true;
> >  	}
> >  
> > -	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
> > +	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> > +					 names, ctx, NULL);
> 
> virtio_find_vqs_ctx()? (Needs to be exported, obviously.)

I guess I can do that but there's a single user ATM.
Do you think it's worth doing right now, or wait until
it gets more users?


> >  	if (ret)
> >  		goto err_find;
> >  
> > @@ -2101,6 +2112,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >  	return 0;
> >  
> >  err_find:
> > +	kfree(ctx);
> > +err_ctx:
> >  	kfree(names);
> >  err_names:
> >  	kfree(callbacks);

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-30  6:00     ` Jason Wang
@ 2017-03-30 14:32       ` Michael S. Tsirkin
  -1 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-30 14:32 UTC (permalink / raw)
  To: Jason Wang
  Cc: linux-kernel, John Fastabend, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Gonglei, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev,
	linux-remoteproc, linux-scsi, kvm

On Thu, Mar 30, 2017 at 02:00:08PM +0800, Jason Wang wrote:
> 
> 
> On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
> > We are going to add more parameters to find_vqs, let's wrap the call so
> > we don't need to tweak all drivers every time.
> > 
> > Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> > ---
> 
> A quick glance and it looks ok, but what the benefit of this series, is it
> required by other changes?
> 
> Thanks

Yes - to avoid touching all devices when doing the rest of
the patchset.

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
@ 2017-03-30 14:32       ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-30 14:32 UTC (permalink / raw)
  To: Jason Wang
  Cc: Dmitry Tarnyagin, kvm, linux-remoteproc, dri-devel,
	Bjorn Andersson, Gerd Hoffmann, James E.J. Bottomley, Herbert Xu,
	linux-scsi, John Fastabend, Gonglei, Ohad Ben-Cohen,
	Arnd Bergmann, Amit Shah, Stefan Hajnoczi, virtualization,
	Martin K. Petersen, Greg Kroah-Hartman, linux-kernel,
	linux-crypto, netdev, David S. Miller

On Thu, Mar 30, 2017 at 02:00:08PM +0800, Jason Wang wrote:
> 
> 
> On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
> > We are going to add more parameters to find_vqs, let's wrap the call so
> > we don't need to tweak all drivers every time.
> > 
> > Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> > ---
> 
> A quick glance and it looks ok, but what the benefit of this series, is it
> required by other changes?
> 
> Thanks

Yes - to avoid touching all devices when doing the rest of
the patchset.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-30  6:00     ` Jason Wang
  (?)
  (?)
@ 2017-03-30 14:32     ` Michael S. Tsirkin
  -1 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-30 14:32 UTC (permalink / raw)
  To: Jason Wang
  Cc: Dmitry Tarnyagin, kvm, David Airlie, linux-remoteproc, dri-devel,
	Bjorn Andersson, James E.J. Bottomley, Herbert Xu, linux-scsi,
	John Fastabend, Arnd Bergmann, Amit Shah, Stefan Hajnoczi,
	virtualization, Martin K. Petersen, Greg Kroah-Hartman,
	linux-kernel, linux-crypto, netdev, David S. Miller

On Thu, Mar 30, 2017 at 02:00:08PM +0800, Jason Wang wrote:
> 
> 
> On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
> > We are going to add more parameters to find_vqs, let's wrap the call so
> > we don't need to tweak all drivers every time.
> > 
> > Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> > ---
> 
> A quick glance and it looks ok, but what the benefit of this series, is it
> required by other changes?
> 
> Thanks

Yes - to avoid touching all devices when doing the rest of
the patchset.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 3/6] virtio: allow extra context per descriptor
  2017-03-30  7:23     ` Cornelia Huck
@ 2017-03-30 14:34       ` Michael S. Tsirkin
  -1 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-30 14:34 UTC (permalink / raw)
  To: Cornelia Huck; +Cc: linux-kernel, John Fastabend, virtualization

On Thu, Mar 30, 2017 at 09:23:16AM +0200, Cornelia Huck wrote:
> On Wed, 29 Mar 2017 23:48:53 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > Allow extra context per descriptor. To avoid slow down for data path,
> > this disables use of indirect descriptors for this vq.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++++++++++--------
> >  include/linux/virtio.h       |  9 ++++++
> >  2 files changed, 66 insertions(+), 13 deletions(-)
> > 
> 
> >  /**
> > + * virtqueue_add_inbuf_ctx - expose input buffers to other end
> > + * @vq: the struct virtqueue we're talking about.
> > + * @sg: scatterlist (must be well-formed and terminated!)
> > + * @num: the number of entries in @sg writable by other side
> > + * @data: the token identifying the buffer.
> > + * @ctx: extra context for the token
> 
> I think that needs do that ctx != NULL collides with indirect
> descriptors.

At the API level what happens is that ctx needs to be enabled
at find_vqs time. Doing that will disable indirect descriptors
but this is not visible in the API.

> > + * @gfp: how to do memory allocations (if necessary).
> > + *
> > + * Caller must ensure we don't call this with other virtqueue operations
> > + * at the same time (except where noted).
> > + *
> > + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
> > + */
> > +int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
> > +			struct scatterlist *sg, unsigned int num,
> > +			void *data,
> > +			void *ctx,
> > +			gfp_t gfp)
> > +{
> > +	return virtqueue_add(vq, &sg, num, 0, 1, data, ctx, gfp);
> > +}
> > +EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx);

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 3/6] virtio: allow extra context per descriptor
@ 2017-03-30 14:34       ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-30 14:34 UTC (permalink / raw)
  To: Cornelia Huck; +Cc: John Fastabend, linux-kernel, virtualization

On Thu, Mar 30, 2017 at 09:23:16AM +0200, Cornelia Huck wrote:
> On Wed, 29 Mar 2017 23:48:53 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > Allow extra context per descriptor. To avoid slow down for data path,
> > this disables use of indirect descriptors for this vq.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  drivers/virtio/virtio_ring.c | 70 ++++++++++++++++++++++++++++++++++++--------
> >  include/linux/virtio.h       |  9 ++++++
> >  2 files changed, 66 insertions(+), 13 deletions(-)
> > 
> 
> >  /**
> > + * virtqueue_add_inbuf_ctx - expose input buffers to other end
> > + * @vq: the struct virtqueue we're talking about.
> > + * @sg: scatterlist (must be well-formed and terminated!)
> > + * @num: the number of entries in @sg writable by other side
> > + * @data: the token identifying the buffer.
> > + * @ctx: extra context for the token
> 
> I think that needs do that ctx != NULL collides with indirect
> descriptors.

At the API level what happens is that ctx needs to be enabled
at find_vqs time. Doing that will disable indirect descriptors
but this is not visible in the API.

> > + * @gfp: how to do memory allocations (if necessary).
> > + *
> > + * Caller must ensure we don't call this with other virtqueue operations
> > + * at the same time (except where noted).
> > + *
> > + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
> > + */
> > +int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
> > +			struct scatterlist *sg, unsigned int num,
> > +			void *data,
> > +			void *ctx,
> > +			gfp_t gfp)
> > +{
> > +	return virtqueue_add(vq, &sg, num, 0, 1, data, ctx, gfp);
> > +}
> > +EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx);

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 4/6] virtio_net: allow specifying context for rx
  2017-03-30 14:31     ` Michael S. Tsirkin
@ 2017-03-30 14:46         ` Cornelia Huck
  0 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30 14:46 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: linux-kernel, netdev, John Fastabend, virtualization

On Thu, 30 Mar 2017 17:31:37 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Thu, Mar 30, 2017 at 09:26:51AM +0200, Cornelia Huck wrote:
> > On Wed, 29 Mar 2017 23:48:54 +0300
> > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > 
> > > With mergeable buffers we never use s/g for rx,
> > > so allow specifying context in that case.
> > > 
> > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > ---
> > >  drivers/net/virtio_net.c | 15 ++++++++++++++-
> > >  1 file changed, 14 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > > index 6802169..340f737 100644
> > > --- a/drivers/net/virtio_net.c
> > > +++ b/drivers/net/virtio_net.c
> > > @@ -2044,6 +2044,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> > >  	int ret = -ENOMEM;
> > >  	int i, total_vqs;
> > >  	const char **names;
> > > +	const bool *ctx;
> > >  
> > >  	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
> > >  	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
> > > @@ -2062,6 +2063,13 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> > >  	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
> > >  	if (!names)
> > >  		goto err_names;
> > > +	if (vi->mergeable_rx_bufs) {
> > > +		ctx = kzalloc(total_vqs * sizeof(*ctx), GFP_KERNEL);
> > > +		if (!ctx)
> > > +			goto err_ctx;
> > > +	} else {
> > > +		ctx = NULL;
> > > +	}
> > >  
> > >  	/* Parameters for control virtqueue, if any */
> > >  	if (vi->has_cvq) {
> > > @@ -2077,9 +2085,12 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> > >  		sprintf(vi->sq[i].name, "output.%d", i);
> > >  		names[rxq2vq(i)] = vi->rq[i].name;
> > >  		names[txq2vq(i)] = vi->sq[i].name;
> > > +		if (ctx)
> > > +			ctx[rxq2vq(i)] = true;
> > >  	}
> > >  
> > > -	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
> > > +	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> > > +					 names, ctx, NULL);
> > 
> > virtio_find_vqs_ctx()? (Needs to be exported, obviously.)
> 
> I guess I can do that but there's a single user ATM.
> Do you think it's worth doing right now, or wait until
> it gets more users?

Given that you introduce it in patch 2, I'd just make it an exported
function from the start. (It also looks nicer IMO.)

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 4/6] virtio_net: allow specifying context for rx
@ 2017-03-30 14:46         ` Cornelia Huck
  0 siblings, 0 replies; 50+ messages in thread
From: Cornelia Huck @ 2017-03-30 14:46 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, John Fastabend, linux-kernel, virtualization

On Thu, 30 Mar 2017 17:31:37 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Thu, Mar 30, 2017 at 09:26:51AM +0200, Cornelia Huck wrote:
> > On Wed, 29 Mar 2017 23:48:54 +0300
> > "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > 
> > > With mergeable buffers we never use s/g for rx,
> > > so allow specifying context in that case.
> > > 
> > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > ---
> > >  drivers/net/virtio_net.c | 15 ++++++++++++++-
> > >  1 file changed, 14 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > > index 6802169..340f737 100644
> > > --- a/drivers/net/virtio_net.c
> > > +++ b/drivers/net/virtio_net.c
> > > @@ -2044,6 +2044,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> > >  	int ret = -ENOMEM;
> > >  	int i, total_vqs;
> > >  	const char **names;
> > > +	const bool *ctx;
> > >  
> > >  	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
> > >  	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
> > > @@ -2062,6 +2063,13 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> > >  	names = kmalloc(total_vqs * sizeof(*names), GFP_KERNEL);
> > >  	if (!names)
> > >  		goto err_names;
> > > +	if (vi->mergeable_rx_bufs) {
> > > +		ctx = kzalloc(total_vqs * sizeof(*ctx), GFP_KERNEL);
> > > +		if (!ctx)
> > > +			goto err_ctx;
> > > +	} else {
> > > +		ctx = NULL;
> > > +	}
> > >  
> > >  	/* Parameters for control virtqueue, if any */
> > >  	if (vi->has_cvq) {
> > > @@ -2077,9 +2085,12 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> > >  		sprintf(vi->sq[i].name, "output.%d", i);
> > >  		names[rxq2vq(i)] = vi->rq[i].name;
> > >  		names[txq2vq(i)] = vi->sq[i].name;
> > > +		if (ctx)
> > > +			ctx[rxq2vq(i)] = true;
> > >  	}
> > >  
> > > -	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, callbacks, names, NULL);
> > > +	ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
> > > +					 names, ctx, NULL);
> > 
> > virtio_find_vqs_ctx()? (Needs to be exported, obviously.)
> 
> I guess I can do that but there's a single user ATM.
> Do you think it's worth doing right now, or wait until
> it gets more users?

Given that you introduce it in patch 2, I'd just make it an exported
function from the start. (It also looks nicer IMO.)

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 2/6] virtio: add context flag to find vqs
  2017-03-30  7:17     ` Cornelia Huck
@ 2017-03-30 14:57       ` Michael S. Tsirkin
  -1 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-30 14:57 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-kernel, linux-s390, kvm, Heiko Carstens, John Fastabend,
	Sudeep Dutt, virtualization, Ashutosh Dixit, Martin Schwidefsky

On Thu, Mar 30, 2017 at 09:17:31AM +0200, Cornelia Huck wrote:
> On Wed, 29 Mar 2017 23:48:51 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > Allows maintaining extra context per vq.  For ease of use, passing in
> > NULL is legal and disables the feature for all vqs.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  drivers/misc/mic/vop/vop_main.c    |  9 ++++++---
> >  drivers/s390/virtio/kvm_virtio.c   |  6 ++++--
> >  drivers/s390/virtio/virtio_ccw.c   |  7 ++++---
> >  drivers/virtio/virtio_mmio.c       |  8 +++++---
> >  drivers/virtio/virtio_pci_common.c | 18 +++++++++++-------
> >  drivers/virtio/virtio_pci_common.h |  4 +++-
> >  drivers/virtio/virtio_pci_legacy.c |  4 +++-
> >  drivers/virtio/virtio_pci_modern.c | 12 ++++++++----
> >  drivers/virtio/virtio_ring.c       |  7 +++++--
> >  include/linux/virtio_config.h      | 18 +++++++++++++++---
> >  include/linux/virtio_ring.h        |  3 +++
> >  11 files changed, 67 insertions(+), 29 deletions(-)
> 
> This series really needs a cover letter, explaining the motivation for
> adding this context.

True. Will try to improve that for v2.

> From what I understand, you want to track some length parameter in
> virtio-net. As you don't use indirect descriptors in that case, you
> want to use a context instead. Did I get this correctly?

Exactly.

-- 
MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 2/6] virtio: add context flag to find vqs
@ 2017-03-30 14:57       ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-30 14:57 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, kvm, Heiko Carstens, John Fastabend, linux-kernel,
	Sudeep Dutt, Ashutosh Dixit, Martin Schwidefsky, virtualization

On Thu, Mar 30, 2017 at 09:17:31AM +0200, Cornelia Huck wrote:
> On Wed, 29 Mar 2017 23:48:51 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > Allows maintaining extra context per vq.  For ease of use, passing in
> > NULL is legal and disables the feature for all vqs.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  drivers/misc/mic/vop/vop_main.c    |  9 ++++++---
> >  drivers/s390/virtio/kvm_virtio.c   |  6 ++++--
> >  drivers/s390/virtio/virtio_ccw.c   |  7 ++++---
> >  drivers/virtio/virtio_mmio.c       |  8 +++++---
> >  drivers/virtio/virtio_pci_common.c | 18 +++++++++++-------
> >  drivers/virtio/virtio_pci_common.h |  4 +++-
> >  drivers/virtio/virtio_pci_legacy.c |  4 +++-
> >  drivers/virtio/virtio_pci_modern.c | 12 ++++++++----
> >  drivers/virtio/virtio_ring.c       |  7 +++++--
> >  include/linux/virtio_config.h      | 18 +++++++++++++++---
> >  include/linux/virtio_ring.h        |  3 +++
> >  11 files changed, 67 insertions(+), 29 deletions(-)
> 
> This series really needs a cover letter, explaining the motivation for
> adding this context.

True. Will try to improve that for v2.

> From what I understand, you want to track some length parameter in
> virtio-net. As you don't use indirect descriptors in that case, you
> want to use a context instead. Did I get this correctly?

Exactly.

-- 
MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-30 14:32       ` Michael S. Tsirkin
@ 2017-03-31  4:04         ` Jason Wang
  -1 siblings, 0 replies; 50+ messages in thread
From: Jason Wang @ 2017-03-31  4:04 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, John Fastabend, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Gonglei, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev,
	linux-remoteproc, linux-scsi, kvm



On 2017年03月30日 22:32, Michael S. Tsirkin wrote:
> On Thu, Mar 30, 2017 at 02:00:08PM +0800, Jason Wang wrote:
>>
>> On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
>>> We are going to add more parameters to find_vqs, let's wrap the call so
>>> we don't need to tweak all drivers every time.
>>>
>>> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
>>> ---
>> A quick glance and it looks ok, but what the benefit of this series, is it
>> required by other changes?
>>
>> Thanks
> Yes - to avoid touching all devices when doing the rest of
> the patchset.

Maybe I'm not clear. I mean the benefit of this series not this single 
patch. I guess it may be used by you proposal that avoid reset when set 
XDP? If yes, do we really want to drop some packets after XDP is set?

Thanks

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
@ 2017-03-31  4:04         ` Jason Wang
  0 siblings, 0 replies; 50+ messages in thread
From: Jason Wang @ 2017-03-31  4:04 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, John Fastabend, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Gonglei, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev



On 2017年03月30日 22:32, Michael S. Tsirkin wrote:
> On Thu, Mar 30, 2017 at 02:00:08PM +0800, Jason Wang wrote:
>>
>> On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
>>> We are going to add more parameters to find_vqs, let's wrap the call so
>>> we don't need to tweak all drivers every time.
>>>
>>> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
>>> ---
>> A quick glance and it looks ok, but what the benefit of this series, is it
>> required by other changes?
>>
>> Thanks
> Yes - to avoid touching all devices when doing the rest of
> the patchset.

Maybe I'm not clear. I mean the benefit of this series not this single 
patch. I guess it may be used by you proposal that avoid reset when set 
XDP? If yes, do we really want to drop some packets after XDP is set?

Thanks

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-30 14:32       ` Michael S. Tsirkin
  (?)
@ 2017-03-31  4:04       ` Jason Wang
  -1 siblings, 0 replies; 50+ messages in thread
From: Jason Wang @ 2017-03-31  4:04 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Dmitry Tarnyagin, kvm, David Airlie, linux-remoteproc, dri-devel,
	Bjorn Andersson, James E.J. Bottomley, Herbert Xu, linux-scsi,
	John Fastabend, Arnd Bergmann, Amit Shah, Stefan Hajnoczi,
	virtualization, Martin K. Petersen, Greg Kroah-Hartman,
	linux-kernel, linux-crypto, netdev, David S. Miller



On 2017年03月30日 22:32, Michael S. Tsirkin wrote:
> On Thu, Mar 30, 2017 at 02:00:08PM +0800, Jason Wang wrote:
>>
>> On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
>>> We are going to add more parameters to find_vqs, let's wrap the call so
>>> we don't need to tweak all drivers every time.
>>>
>>> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
>>> ---
>> A quick glance and it looks ok, but what the benefit of this series, is it
>> required by other changes?
>>
>> Thanks
> Yes - to avoid touching all devices when doing the rest of
> the patchset.

Maybe I'm not clear. I mean the benefit of this series not this single 
patch. I guess it may be used by you proposal that avoid reset when set 
XDP? If yes, do we really want to drop some packets after XDP is set?

Thanks
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-31  4:04         ` Jason Wang
@ 2017-03-31 16:21           ` Michael S. Tsirkin
  -1 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-31 16:21 UTC (permalink / raw)
  To: Jason Wang
  Cc: linux-kernel, John Fastabend, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Gonglei, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev,
	linux-remoteproc, linux-scsi, kvm

On Fri, Mar 31, 2017 at 12:04:55PM +0800, Jason Wang wrote:
> 
> 
> On 2017年03月30日 22:32, Michael S. Tsirkin wrote:
> > On Thu, Mar 30, 2017 at 02:00:08PM +0800, Jason Wang wrote:
> > > 
> > > On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
> > > > We are going to add more parameters to find_vqs, let's wrap the call so
> > > > we don't need to tweak all drivers every time.
> > > > 
> > > > Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> > > > ---
> > > A quick glance and it looks ok, but what the benefit of this series, is it
> > > required by other changes?
> > > 
> > > Thanks
> > Yes - to avoid touching all devices when doing the rest of
> > the patchset.
> 
> Maybe I'm not clear. I mean the benefit of this series not this single
> patch. I guess it may be used by you proposal that avoid reset when set XDP?

In particular, yes. It generally simplifies things significantly if
we can get the true buffer size back.

> If yes, do we really want to drop some packets after XDP is set?
> 
> Thanks

We would rather not drop packets. We could detect and copy them to make
XDP work.

-- 
MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
@ 2017-03-31 16:21           ` Michael S. Tsirkin
  0 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-31 16:21 UTC (permalink / raw)
  To: Jason Wang
  Cc: linux-kernel, John Fastabend, Arnd Bergmann, Greg Kroah-Hartman,
	Amit Shah, Gonglei, Herbert Xu, David S. Miller, David Airlie,
	Gerd Hoffmann, Dmitry Tarnyagin, Ohad Ben-Cohen, Bjorn Andersson,
	James E.J. Bottomley, Martin K. Petersen, Stefan Hajnoczi,
	virtualization, linux-crypto, dri-devel, netdev

On Fri, Mar 31, 2017 at 12:04:55PM +0800, Jason Wang wrote:
> 
> 
> On 2017年03月30日 22:32, Michael S. Tsirkin wrote:
> > On Thu, Mar 30, 2017 at 02:00:08PM +0800, Jason Wang wrote:
> > > 
> > > On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
> > > > We are going to add more parameters to find_vqs, let's wrap the call so
> > > > we don't need to tweak all drivers every time.
> > > > 
> > > > Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> > > > ---
> > > A quick glance and it looks ok, but what the benefit of this series, is it
> > > required by other changes?
> > > 
> > > Thanks
> > Yes - to avoid touching all devices when doing the rest of
> > the patchset.
> 
> Maybe I'm not clear. I mean the benefit of this series not this single
> patch. I guess it may be used by you proposal that avoid reset when set XDP?

In particular, yes. It generally simplifies things significantly if
we can get the true buffer size back.

> If yes, do we really want to drop some packets after XDP is set?
> 
> Thanks

We would rather not drop packets. We could detect and copy them to make
XDP work.

-- 
MST

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-31  4:04         ` Jason Wang
  (?)
  (?)
@ 2017-03-31 16:21         ` Michael S. Tsirkin
  -1 siblings, 0 replies; 50+ messages in thread
From: Michael S. Tsirkin @ 2017-03-31 16:21 UTC (permalink / raw)
  To: Jason Wang
  Cc: Dmitry Tarnyagin, kvm, David Airlie, linux-remoteproc, dri-devel,
	Bjorn Andersson, James E.J. Bottomley, Herbert Xu, linux-scsi,
	John Fastabend, Arnd Bergmann, Amit Shah, Stefan Hajnoczi,
	virtualization, Martin K. Petersen, Greg Kroah-Hartman,
	linux-kernel, linux-crypto, netdev, David S. Miller

On Fri, Mar 31, 2017 at 12:04:55PM +0800, Jason Wang wrote:
> 
> 
> On 2017年03月30日 22:32, Michael S. Tsirkin wrote:
> > On Thu, Mar 30, 2017 at 02:00:08PM +0800, Jason Wang wrote:
> > > 
> > > On 2017年03月30日 04:48, Michael S. Tsirkin wrote:
> > > > We are going to add more parameters to find_vqs, let's wrap the call so
> > > > we don't need to tweak all drivers every time.
> > > > 
> > > > Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> > > > ---
> > > A quick glance and it looks ok, but what the benefit of this series, is it
> > > required by other changes?
> > > 
> > > Thanks
> > Yes - to avoid touching all devices when doing the rest of
> > the patchset.
> 
> Maybe I'm not clear. I mean the benefit of this series not this single
> patch. I guess it may be used by you proposal that avoid reset when set XDP?

In particular, yes. It generally simplifies things significantly if
we can get the true buffer size back.

> If yes, do we really want to drop some packets after XDP is set?
> 
> Thanks

We would rather not drop packets. We could detect and copy them to make
XDP work.

-- 
MST
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
  2017-03-29 20:48   ` Michael S. Tsirkin
@ 2017-04-01 16:13     ` Bjorn Andersson
  -1 siblings, 0 replies; 50+ messages in thread
From: Bjorn Andersson @ 2017-04-01 16:13 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, John Fastabend, Jason Wang, Arnd Bergmann,
	Greg Kroah-Hartman, Amit Shah, Gonglei, Herbert Xu,
	David S. Miller, David Airlie, Gerd Hoffmann, Dmitry Tarnyagin,
	Ohad Ben-Cohen, James E.J. Bottomley, Martin K. Petersen,
	Stefan Hajnoczi, virtualization, linux-crypto, dri-devel, netdev,
	linux-remoteproc, linux-scsi, kvm

On Wed 29 Mar 13:48 PDT 2017, Michael S. Tsirkin wrote:

> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Acked-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [PATCH 1/6] virtio: wrap find_vqs
@ 2017-04-01 16:13     ` Bjorn Andersson
  0 siblings, 0 replies; 50+ messages in thread
From: Bjorn Andersson @ 2017-04-01 16:13 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Dmitry Tarnyagin, kvm, David Airlie, linux-remoteproc, dri-devel,
	virtualization, James E.J. Bottomley, Herbert Xu, linux-scsi,
	John Fastabend, Arnd Bergmann, Amit Shah, Stefan Hajnoczi,
	Martin K. Petersen, Greg Kroah-Hartman, linux-kernel,
	linux-crypto, netdev, David S. Miller

On Wed 29 Mar 13:48 PDT 2017, Michael S. Tsirkin wrote:

> We are going to add more parameters to find_vqs, let's wrap the call so
> we don't need to tweak all drivers every time.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Acked-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

^ permalink raw reply	[flat|nested] 50+ messages in thread

end of thread, other threads:[~2017-04-01 16:13 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-29 20:48 [PATCH 0/6] virtio: support extra per-buffer context Michael S. Tsirkin
2017-03-29 20:48 ` [PATCH 1/6] virtio: wrap find_vqs Michael S. Tsirkin
2017-03-29 20:48   ` Michael S. Tsirkin
2017-03-30  0:50   ` Gonglei (Arei)
2017-03-30  0:50   ` Gonglei (Arei)
2017-03-30  0:50     ` Gonglei (Arei)
2017-03-30  0:50     ` Gonglei (Arei)
2017-03-30  0:50     ` Gonglei (Arei)
2017-03-30  6:00   ` Jason Wang
2017-03-30  6:00   ` Jason Wang
2017-03-30  6:00     ` Jason Wang
2017-03-30 14:32     ` Michael S. Tsirkin
2017-03-30 14:32       ` Michael S. Tsirkin
2017-03-31  4:04       ` Jason Wang
2017-03-31  4:04       ` Jason Wang
2017-03-31  4:04         ` Jason Wang
2017-03-31 16:21         ` Michael S. Tsirkin
2017-03-31 16:21           ` Michael S. Tsirkin
2017-03-31 16:21         ` Michael S. Tsirkin
2017-03-30 14:32     ` Michael S. Tsirkin
2017-03-30  7:18   ` Cornelia Huck
2017-03-30  7:18     ` Cornelia Huck
2017-03-30  7:18   ` Cornelia Huck
2017-04-01 16:13   ` Bjorn Andersson
2017-04-01 16:13     ` Bjorn Andersson
2017-03-29 20:48 ` [PATCH 2/6] virtio: add context flag to find vqs Michael S. Tsirkin
2017-03-29 20:48   ` Michael S. Tsirkin
2017-03-30  7:17   ` Cornelia Huck
2017-03-30  7:17     ` Cornelia Huck
2017-03-30 14:57     ` Michael S. Tsirkin
2017-03-30 14:57       ` Michael S. Tsirkin
2017-03-30  7:17   ` Cornelia Huck
2017-03-29 20:48 ` [PATCH 3/6] virtio: allow extra context per descriptor Michael S. Tsirkin
2017-03-29 20:48   ` Michael S. Tsirkin
2017-03-30  7:23   ` Cornelia Huck
2017-03-30  7:23     ` Cornelia Huck
2017-03-30 14:34     ` Michael S. Tsirkin
2017-03-30 14:34       ` Michael S. Tsirkin
2017-03-29 20:48 ` [PATCH 4/6] virtio_net: allow specifying context for rx Michael S. Tsirkin
2017-03-29 20:48   ` Michael S. Tsirkin
2017-03-30  7:26   ` Cornelia Huck
2017-03-30 14:31     ` Michael S. Tsirkin
2017-03-30 14:46       ` Cornelia Huck
2017-03-30 14:46         ` Cornelia Huck
2017-03-30 14:31     ` Michael S. Tsirkin
2017-03-30  7:26   ` Cornelia Huck
2017-03-29 20:48 ` [PATCH 5/6] virtio_net: rework mergeable buffer handling Michael S. Tsirkin
2017-03-29 20:48   ` Michael S. Tsirkin
2017-03-29 20:48 ` [PATCH 6/6] virtio_net: reduce alignment for buffers Michael S. Tsirkin
2017-03-29 20:48   ` Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.