From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>, Paolo Abeni <pabeni@redhat.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Colin King (gmail)" <colin.i.king@gmail.com>
Subject: Re: virtio_net: support device stats
Date: Tue, 15 Oct 2024 17:55:29 +0800 [thread overview]
Message-ID: <1728986129.331167-1-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <20241014054305-mutt-send-email-mst@kernel.org>
On Mon, 14 Oct 2024 05:47:41 -0400, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Mon, Oct 14, 2024 at 10:39:26AM +0100, Colin King (gmail) wrote:
> > Hi,
> >
> > Static analysis on Linux-next has detected a potential issue with the
> > following commit:
> >
> > commit 941168f8b40e50518a3bc6ce770a7062a5d99230
> > Author: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > Date: Fri Apr 26 11:39:24 2024 +0800
> >
> > virtio_net: support device stats
> >
> >
> > The issue is in function virtnet_stats_ctx_init, in drivers/net/virtio_net.c
> > as follows:
> >
> > if (vi->device_stats_cap & VIRTIO_NET_STATS_TYPE_CVQ) {
> > queue_type = VIRTNET_Q_TYPE_CQ;
> >
> > ctx->bitmap[queue_type] |= VIRTIO_NET_STATS_TYPE_CVQ;
> > ctx->desc_num[queue_type] +=
> > ARRAY_SIZE(virtnet_stats_cvq_desc);
> > ctx->size[queue_type] += sizeof(struct
> > virtio_net_stats_cvq);
> > }
> >
> >
> > ctx->bitmap is declared as a u32 however it is being bit-wise or'd with
> > VIRTIO_NET_STATS_TYPE_CVQ and this is defined as 1 << 32:
> >
> > include/uapi/linux/virtio_net.h:#define VIRTIO_NET_STATS_TYPE_CVQ (1ULL <<
> > 32)
> >
> > ..and hence the bit-wise or operation won't set any bits in ctx->bitmap
> > because 1ULL < 32 is too wide for a u32.
>
> Indeed. Xuan Zhuo how did you test this patch?
In our machines, cvq type is not supported. ^_^
Why gcc has not warning for this, or I missed it.
>
> > I suspect ctx->bitmap should be
> > declared as u64.
> >
> > Colin
> >
> >
>
> In fact, it is read into a u64:
>
> u64 offset, bitmap;
> ....
> bitmap = ctx->bitmap[queue_type];
>
> we'll have to reorder fields to avoid wasting memory.
> Like this I guess:
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Thanks
>
> Colin, can you confirm pls?
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index c6af18948092..ef221429f784 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -4111,12 +4111,12 @@ struct virtnet_stats_ctx {
> /* Used to calculate the offset inside the output buffer. */
> u32 desc_num[3];
>
> - /* The actual supported stat types. */
> - u32 bitmap[3];
> -
> /* Used to calculate the reply buffer size. */
> u32 size[3];
>
> + /* The actual supported stat types. */
> + u64 bitmap[3];
> +
> /* Record the output buffer. */
> u64 *data;
> };
> --
> MST
>
prev parent reply other threads:[~2024-10-15 9:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 9:39 Colin King (gmail)
2024-10-14 9:47 ` Michael S. Tsirkin
2024-10-14 10:14 ` Colin King (gmail)
2024-10-18 7:25 ` Jason Wang
2024-10-15 9:55 ` Xuan Zhuo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1728986129.331167-1-xuanzhuo@linux.alibaba.com \
--to=xuanzhuo@linux.alibaba.com \
--cc=colin.i.king@gmail.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®