diff mbox series

[net-next,v2,1/2] virtio_net: introduce ability to get reply info from device

Message ID 20240426065441.120710-2-hengqi@linux.alibaba.com (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series virtio_net: support getting initial value of irq coalesce | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 926 this patch: 926
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 937 this patch: 937
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 937 this patch: 937
netdev/checkpatch warning WARNING: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants WARNING: line length of 81 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-04-29--06-00 (tests: 999)

Commit Message

Heng Qi April 26, 2024, 6:54 a.m. UTC
From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>

As the spec https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82

Based on the description provided in the above specification, we have
enabled the virtio-net driver to support acquiring some response
information from the device via the CVQ (Control Virtqueue).

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 drivers/net/virtio_net.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

Comments

Jason Wang May 7, 2024, 6:24 a.m. UTC | #1
On Fri, Apr 26, 2024 at 2:54 PM Heng Qi <hengqi@linux.alibaba.com> wrote:
>
> From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
>
> As the spec https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
>
> Based on the description provided in the above specification, we have
> enabled the virtio-net driver to support acquiring some response
> information from the device via the CVQ (Control Virtqueue).
>
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>

I wonder if we need to tweak the spec as it has:

"""
Upon disabling and re-enabling a transmit virtqueue, the device MUST
set the coalescing parameters of the virtqueue
to those configured through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET
command, or, if the driver did not set any TX coalescing parameters,
to 0.
"""

So for reset, this patch tells us the device would have a non-zero
default value.

But spec tolds us after vq reset, it has a zero default value ...

Thanks


> ---
>  drivers/net/virtio_net.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 7176b956460b..3bc9b1e621db 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2527,11 +2527,12 @@ static int virtnet_tx_resize(struct virtnet_info *vi,
>   * supported by the hypervisor, as indicated by feature bits, should
>   * never fail unless improperly formatted.
>   */
> -static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> -                                struct scatterlist *out)
> +static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd,
> +                                      struct scatterlist *out,
> +                                      struct scatterlist *in)
>  {
> -       struct scatterlist *sgs[4], hdr, stat;
> -       unsigned out_num = 0, tmp;
> +       struct scatterlist *sgs[5], hdr, stat;
> +       u32 out_num = 0, tmp, in_num = 0;
>         int ret;
>
>         /* Caller should know better */
> @@ -2549,10 +2550,13 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
>
>         /* Add return status. */
>         sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status));
> -       sgs[out_num] = &stat;
> +       sgs[out_num + in_num++] = &stat;
>
> -       BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
> -       ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
> +       if (in)
> +               sgs[out_num + in_num++] = in;
> +
> +       BUG_ON(out_num + in_num > ARRAY_SIZE(sgs));
> +       ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, in_num, vi, GFP_ATOMIC);
>         if (ret < 0) {
>                 dev_warn(&vi->vdev->dev,
>                          "Failed to add sgs for command vq: %d\n.", ret);
> @@ -2574,6 +2578,12 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
>         return vi->ctrl->status == VIRTIO_NET_OK;
>  }
>
> +static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> +                                struct scatterlist *out)
> +{
> +       return virtnet_send_command_reply(vi, class, cmd, out, NULL);
> +}
> +
>  static int virtnet_set_mac_address(struct net_device *dev, void *p)
>  {
>         struct virtnet_info *vi = netdev_priv(dev);
> --
> 2.32.0.3.g01195cf9f
>
Heng Qi May 7, 2024, 6:53 a.m. UTC | #2
On Tue, 7 May 2024 14:24:19 +0800, Jason Wang <jasowang@redhat.com> wrote:
> On Fri, Apr 26, 2024 at 2:54 PM Heng Qi <hengqi@linux.alibaba.com> wrote:
> >
> > From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> >
> > As the spec https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> >
> > Based on the description provided in the above specification, we have
> > enabled the virtio-net driver to support acquiring some response
> > information from the device via the CVQ (Control Virtqueue).
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> 
> I wonder if we need to tweak the spec as it has:
> 
> """
> Upon disabling and re-enabling a transmit virtqueue, the device MUST
> set the coalescing parameters of the virtqueue
> to those configured through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET
> command, or, if the driver did not set any TX coalescing parameters,
> to 0.
> """
> 
> So for reset, this patch tells us the device would have a non-zero
> default value.
> 
> But spec tolds us after vq reset, it has a zero default value ...

Maybe we add a bool or flag for driver to mark whether the user has actively
configured interrupt coalescing parameters. Then we can take actions when
vq reset occurs?

Thanks.

> 
> Thanks
> 
> 
> > ---
> >  drivers/net/virtio_net.c | 24 +++++++++++++++++-------
> >  1 file changed, 17 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 7176b956460b..3bc9b1e621db 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -2527,11 +2527,12 @@ static int virtnet_tx_resize(struct virtnet_info *vi,
> >   * supported by the hypervisor, as indicated by feature bits, should
> >   * never fail unless improperly formatted.
> >   */
> > -static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > -                                struct scatterlist *out)
> > +static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd,
> > +                                      struct scatterlist *out,
> > +                                      struct scatterlist *in)
> >  {
> > -       struct scatterlist *sgs[4], hdr, stat;
> > -       unsigned out_num = 0, tmp;
> > +       struct scatterlist *sgs[5], hdr, stat;
> > +       u32 out_num = 0, tmp, in_num = 0;
> >         int ret;
> >
> >         /* Caller should know better */
> > @@ -2549,10 +2550,13 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> >
> >         /* Add return status. */
> >         sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status));
> > -       sgs[out_num] = &stat;
> > +       sgs[out_num + in_num++] = &stat;
> >
> > -       BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
> > -       ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
> > +       if (in)
> > +               sgs[out_num + in_num++] = in;
> > +
> > +       BUG_ON(out_num + in_num > ARRAY_SIZE(sgs));
> > +       ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, in_num, vi, GFP_ATOMIC);
> >         if (ret < 0) {
> >                 dev_warn(&vi->vdev->dev,
> >                          "Failed to add sgs for command vq: %d\n.", ret);
> > @@ -2574,6 +2578,12 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> >         return vi->ctrl->status == VIRTIO_NET_OK;
> >  }
> >
> > +static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > +                                struct scatterlist *out)
> > +{
> > +       return virtnet_send_command_reply(vi, class, cmd, out, NULL);
> > +}
> > +
> >  static int virtnet_set_mac_address(struct net_device *dev, void *p)
> >  {
> >         struct virtnet_info *vi = netdev_priv(dev);
> > --
> > 2.32.0.3.g01195cf9f
> >
>
Jason Wang May 8, 2024, 2:20 a.m. UTC | #3
On Tue, May 7, 2024 at 2:56 PM Heng Qi <hengqi@linux.alibaba.com> wrote:
>
> On Tue, 7 May 2024 14:24:19 +0800, Jason Wang <jasowang@redhat.com> wrote:
> > On Fri, Apr 26, 2024 at 2:54 PM Heng Qi <hengqi@linux.alibaba.com> wrote:
> > >
> > > From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > >
> > > As the spec https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> > >
> > > Based on the description provided in the above specification, we have
> > > enabled the virtio-net driver to support acquiring some response
> > > information from the device via the CVQ (Control Virtqueue).
> > >
> > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> >
> > I wonder if we need to tweak the spec as it has:
> >
> > """
> > Upon disabling and re-enabling a transmit virtqueue, the device MUST
> > set the coalescing parameters of the virtqueue
> > to those configured through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET
> > command, or, if the driver did not set any TX coalescing parameters,
> > to 0.
> > """
> >
> > So for reset, this patch tells us the device would have a non-zero
> > default value.
> >
> > But spec tolds us after vq reset, it has a zero default value ...
>
> Maybe we add a bool or flag for driver to mark whether the user has actively
> configured interrupt coalescing parameters. Then we can take actions when
> vq reset occurs?

I basically mean we probably need to tweak the spec. For example say
the device may have a default value for coalescing so driver need to
read them.

Thanks

>
> Thanks.
>
> >
> > Thanks
> >
> >
> > > ---
> > >  drivers/net/virtio_net.c | 24 +++++++++++++++++-------
> > >  1 file changed, 17 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > > index 7176b956460b..3bc9b1e621db 100644
> > > --- a/drivers/net/virtio_net.c
> > > +++ b/drivers/net/virtio_net.c
> > > @@ -2527,11 +2527,12 @@ static int virtnet_tx_resize(struct virtnet_info *vi,
> > >   * supported by the hypervisor, as indicated by feature bits, should
> > >   * never fail unless improperly formatted.
> > >   */
> > > -static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > > -                                struct scatterlist *out)
> > > +static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd,
> > > +                                      struct scatterlist *out,
> > > +                                      struct scatterlist *in)
> > >  {
> > > -       struct scatterlist *sgs[4], hdr, stat;
> > > -       unsigned out_num = 0, tmp;
> > > +       struct scatterlist *sgs[5], hdr, stat;
> > > +       u32 out_num = 0, tmp, in_num = 0;
> > >         int ret;
> > >
> > >         /* Caller should know better */
> > > @@ -2549,10 +2550,13 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > >
> > >         /* Add return status. */
> > >         sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status));
> > > -       sgs[out_num] = &stat;
> > > +       sgs[out_num + in_num++] = &stat;
> > >
> > > -       BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
> > > -       ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
> > > +       if (in)
> > > +               sgs[out_num + in_num++] = in;
> > > +
> > > +       BUG_ON(out_num + in_num > ARRAY_SIZE(sgs));
> > > +       ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, in_num, vi, GFP_ATOMIC);
> > >         if (ret < 0) {
> > >                 dev_warn(&vi->vdev->dev,
> > >                          "Failed to add sgs for command vq: %d\n.", ret);
> > > @@ -2574,6 +2578,12 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > >         return vi->ctrl->status == VIRTIO_NET_OK;
> > >  }
> > >
> > > +static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > > +                                struct scatterlist *out)
> > > +{
> > > +       return virtnet_send_command_reply(vi, class, cmd, out, NULL);
> > > +}
> > > +
> > >  static int virtnet_set_mac_address(struct net_device *dev, void *p)
> > >  {
> > >         struct virtnet_info *vi = netdev_priv(dev);
> > > --
> > > 2.32.0.3.g01195cf9f
> > >
> >
>
Heng Qi May 8, 2024, 2:44 a.m. UTC | #4
On Wed, 8 May 2024 10:20:05 +0800, Jason Wang <jasowang@redhat.com> wrote:
> On Tue, May 7, 2024 at 2:56 PM Heng Qi <hengqi@linux.alibaba.com> wrote:
> >
> > On Tue, 7 May 2024 14:24:19 +0800, Jason Wang <jasowang@redhat.com> wrote:
> > > On Fri, Apr 26, 2024 at 2:54 PM Heng Qi <hengqi@linux.alibaba.com> wrote:
> > > >
> > > > From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > >
> > > > As the spec https://github.com/oasis-tcs/virtio-spec/commit/42f389989823039724f95bbbd243291ab0064f82
> > > >
> > > > Based on the description provided in the above specification, we have
> > > > enabled the virtio-net driver to support acquiring some response
> > > > information from the device via the CVQ (Control Virtqueue).
> > > >
> > > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > >
> > > I wonder if we need to tweak the spec as it has:
> > >
> > > """
> > > Upon disabling and re-enabling a transmit virtqueue, the device MUST
> > > set the coalescing parameters of the virtqueue
> > > to those configured through the VIRTIO_NET_CTRL_NOTF_COAL_TX_SET
> > > command, or, if the driver did not set any TX coalescing parameters,
> > > to 0.
> > > """
> > >
> > > So for reset, this patch tells us the device would have a non-zero
> > > default value.
> > >
> > > But spec tolds us after vq reset, it has a zero default value ...
> >
> > Maybe we add a bool or flag for driver to mark whether the user has actively
> > configured interrupt coalescing parameters. Then we can take actions when
> > vq reset occurs?
> 
> I basically mean we probably need to tweak the spec. For example say
> the device may have a default value for coalescing so driver need to
> read them.

Well, I'll post a tweak patch, and since the current virtio spec mailing list
is still not ready, I'll Cc people who were previously involved in the
discussion.

Thanks.

> 
> Thanks
> 
> >
> > Thanks.
> >
> > >
> > > Thanks
> > >
> > >
> > > > ---
> > > >  drivers/net/virtio_net.c | 24 +++++++++++++++++-------
> > > >  1 file changed, 17 insertions(+), 7 deletions(-)
> > > >
> > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > > > index 7176b956460b..3bc9b1e621db 100644
> > > > --- a/drivers/net/virtio_net.c
> > > > +++ b/drivers/net/virtio_net.c
> > > > @@ -2527,11 +2527,12 @@ static int virtnet_tx_resize(struct virtnet_info *vi,
> > > >   * supported by the hypervisor, as indicated by feature bits, should
> > > >   * never fail unless improperly formatted.
> > > >   */
> > > > -static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > > > -                                struct scatterlist *out)
> > > > +static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd,
> > > > +                                      struct scatterlist *out,
> > > > +                                      struct scatterlist *in)
> > > >  {
> > > > -       struct scatterlist *sgs[4], hdr, stat;
> > > > -       unsigned out_num = 0, tmp;
> > > > +       struct scatterlist *sgs[5], hdr, stat;
> > > > +       u32 out_num = 0, tmp, in_num = 0;
> > > >         int ret;
> > > >
> > > >         /* Caller should know better */
> > > > @@ -2549,10 +2550,13 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > > >
> > > >         /* Add return status. */
> > > >         sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status));
> > > > -       sgs[out_num] = &stat;
> > > > +       sgs[out_num + in_num++] = &stat;
> > > >
> > > > -       BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
> > > > -       ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
> > > > +       if (in)
> > > > +               sgs[out_num + in_num++] = in;
> > > > +
> > > > +       BUG_ON(out_num + in_num > ARRAY_SIZE(sgs));
> > > > +       ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, in_num, vi, GFP_ATOMIC);
> > > >         if (ret < 0) {
> > > >                 dev_warn(&vi->vdev->dev,
> > > >                          "Failed to add sgs for command vq: %d\n.", ret);
> > > > @@ -2574,6 +2578,12 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > > >         return vi->ctrl->status == VIRTIO_NET_OK;
> > > >  }
> > > >
> > > > +static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
> > > > +                                struct scatterlist *out)
> > > > +{
> > > > +       return virtnet_send_command_reply(vi, class, cmd, out, NULL);
> > > > +}
> > > > +
> > > >  static int virtnet_set_mac_address(struct net_device *dev, void *p)
> > > >  {
> > > >         struct virtnet_info *vi = netdev_priv(dev);
> > > > --
> > > > 2.32.0.3.g01195cf9f
> > > >
> > >
> >
>
diff mbox series

Patch

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 7176b956460b..3bc9b1e621db 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2527,11 +2527,12 @@  static int virtnet_tx_resize(struct virtnet_info *vi,
  * supported by the hypervisor, as indicated by feature bits, should
  * never fail unless improperly formatted.
  */
-static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
-				 struct scatterlist *out)
+static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd,
+				       struct scatterlist *out,
+				       struct scatterlist *in)
 {
-	struct scatterlist *sgs[4], hdr, stat;
-	unsigned out_num = 0, tmp;
+	struct scatterlist *sgs[5], hdr, stat;
+	u32 out_num = 0, tmp, in_num = 0;
 	int ret;
 
 	/* Caller should know better */
@@ -2549,10 +2550,13 @@  static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
 
 	/* Add return status. */
 	sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status));
-	sgs[out_num] = &stat;
+	sgs[out_num + in_num++] = &stat;
 
-	BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
-	ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
+	if (in)
+		sgs[out_num + in_num++] = in;
+
+	BUG_ON(out_num + in_num > ARRAY_SIZE(sgs));
+	ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, in_num, vi, GFP_ATOMIC);
 	if (ret < 0) {
 		dev_warn(&vi->vdev->dev,
 			 "Failed to add sgs for command vq: %d\n.", ret);
@@ -2574,6 +2578,12 @@  static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
 	return vi->ctrl->status == VIRTIO_NET_OK;
 }
 
+static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
+				 struct scatterlist *out)
+{
+	return virtnet_send_command_reply(vi, class, cmd, out, NULL);
+}
+
 static int virtnet_set_mac_address(struct net_device *dev, void *p)
 {
 	struct virtnet_info *vi = netdev_priv(dev);