[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CACGkMEs0huXk4KF894nFo2Vg1gRnasnm4Hnte6twmqq6hr0nxA@mail.gmail.com>
Date: Fri, 18 Oct 2024 15:25:55 +0800
From: Jason Wang <jasowang@...hat.com>
To: "Colin King (gmail)" <colin.i.king@...il.com>
Cc: "Michael S. Tsirkin" <mst@...hat.com>, Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
Paolo Abeni <pabeni@...hat.com>, "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: virtio_net: support device stats
On Mon, Oct 14, 2024 at 6:15 PM Colin King (gmail)
<colin.i.king@...il.com> wrote:
>
> On 14/10/2024 10:47, Michael S. Tsirkin 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@...ux.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?
> >
> >> 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@...hat.com>
> >
> > Colin, can you confirm pls?
>
> Fix looks sane to be, with u64 bitmap[3] struct size field re-ordering
> does not seem to make any difference on x86-64 (64 bytes) and i586 (56
> bytes) when I compiled with gcc-12, gcc-14 and clang-20.
>
> I can't functionally test this though (not sure how).
>
> Reviewed-by: Colin Ian King <colin.king@...il.com>
Maybe it's time to ask for a prototype for each virtio-net feature
before it can be merged into the spec.
Thanks
Powered by blists - more mailing lists