* [PATCH 1/6] virtio: wrap find_vqs
[not found] <1490820507-8005-1-git-send-email-mst@redhat.com>
@ 2017-03-29 20:48 ` Michael S. Tsirkin
2017-03-30 0:50 ` Gonglei (Arei)
` (3 more replies)
2017-03-29 20:48 ` [PATCH 4/6] virtio_net: allow specifying context for rx Michael S. Tsirkin
` (2 subsequent siblings)
3 siblings, 4 replies; 14+ 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] 14+ messages in thread
* RE: [PATCH 1/6] virtio: wrap find_vqs
2017-03-29 20:48 ` [PATCH 1/6] virtio: wrap find_vqs Michael S. Tsirkin
@ 2017-03-30 0:50 ` Gonglei (Arei)
2017-03-30 6:00 ` Jason Wang
` (2 subsequent siblings)
3 siblings, 0 replies; 14+ messages in thread
From: Gonglei (Arei) @ 2017-03-30 0:50 UTC (permalink / raw)
To: Michael S. Tsirkin, linux-kernel@vger.kernel.org
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@lists.linux-foundation.org,
linux-crypto@vger.kernel.org
> -----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] 14+ messages in thread
* Re: [PATCH 1/6] virtio: wrap find_vqs
2017-03-29 20:48 ` [PATCH 1/6] virtio: wrap find_vqs Michael S. Tsirkin
2017-03-30 0:50 ` Gonglei (Arei)
@ 2017-03-30 6:00 ` Jason Wang
2017-03-30 14:32 ` Michael S. Tsirkin
2017-03-30 7:18 ` Cornelia Huck
2017-04-01 16:13 ` Bjorn Andersson
3 siblings, 1 reply; 14+ 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] 14+ 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
2017-03-31 4:04 ` Jason Wang
0 siblings, 1 reply; 14+ 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] 14+ 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
2017-03-31 16:21 ` Michael S. Tsirkin
0 siblings, 1 reply; 14+ 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] 14+ 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
0 siblings, 0 replies; 14+ 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] 14+ messages in thread
* Re: [PATCH 1/6] virtio: wrap find_vqs
2017-03-29 20:48 ` [PATCH 1/6] virtio: wrap find_vqs Michael S. Tsirkin
2017-03-30 0:50 ` Gonglei (Arei)
2017-03-30 6:00 ` Jason Wang
@ 2017-03-30 7:18 ` Cornelia Huck
2017-04-01 16:13 ` Bjorn Andersson
3 siblings, 0 replies; 14+ 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] 14+ messages in thread
* Re: [PATCH 1/6] virtio: wrap find_vqs
2017-03-29 20:48 ` [PATCH 1/6] virtio: wrap find_vqs Michael S. Tsirkin
` (2 preceding siblings ...)
2017-03-30 7:18 ` Cornelia Huck
@ 2017-04-01 16:13 ` Bjorn Andersson
3 siblings, 0 replies; 14+ 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] 14+ messages in thread
* [PATCH 4/6] virtio_net: allow specifying context for rx
[not found] <1490820507-8005-1-git-send-email-mst@redhat.com>
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 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 ` [PATCH 6/6] virtio_net: reduce alignment for buffers Michael S. Tsirkin
3 siblings, 1 reply; 14+ 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] 14+ messages in thread
* Re: [PATCH 4/6] virtio_net: allow specifying context for rx
2017-03-29 20:48 ` [PATCH 4/6] virtio_net: allow specifying context for rx Michael S. Tsirkin
@ 2017-03-30 7:26 ` Cornelia Huck
2017-03-30 14:31 ` Michael S. Tsirkin
0 siblings, 1 reply; 14+ 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] 14+ 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
0 siblings, 1 reply; 14+ 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] 14+ 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; 14+ 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] 14+ messages in thread
* [PATCH 5/6] virtio_net: rework mergeable buffer handling
[not found] <1490820507-8005-1-git-send-email-mst@redhat.com>
2017-03-29 20:48 ` [PATCH 1/6] virtio: wrap find_vqs 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-29 20:48 ` [PATCH 6/6] virtio_net: reduce alignment for buffers Michael S. Tsirkin
3 siblings, 0 replies; 14+ 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] 14+ messages in thread
* [PATCH 6/6] virtio_net: reduce alignment for buffers
[not found] <1490820507-8005-1-git-send-email-mst@redhat.com>
` (2 preceding siblings ...)
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
3 siblings, 0 replies; 14+ 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] 14+ messages in thread