From: Lianjie Wang <karin0.zst@gmail.com>
To: Paolo Abeni <pabeni@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
netdev@vger.kernel.org, virtualization@lists.linux.dev,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net] virtio_net: reject stats replies for queues outside the request
Date: Tue, 27 Oct 2026 22:53:16 +0900 [thread overview]
Message-ID: <auCkXHi6IulXgm7v@wang0.localdomain> (raw)
In-Reply-To: <096bd22b-c569-4998-a943-0381c3fa9998@redhat.com>
On Tue, Oct 27, 2026 at 01:06:41PM +0100, Paolo Abeni wrote:
> On 10/22/26 20:26, Lianjie Wang wrote:
> > [...]
> > @@ -4976,6 +4977,10 @@ static int __virtnet_get_hw_stats(struct virtnet_info *vi,
> > for (p = reply; p - reply < res_size; p += le16_to_cpu(hdr->size)) {
> > hdr = p;
> > qid = le16_to_cpu(hdr->vq_index);
> > + if ((qid < first_vq || qid > last_vq) &&
> > + !(enable_cvq && qid == vi->max_queue_pairs * 2))
> > + return -EINVAL;
>
> I think the above check could be simplified to:
> if (qid < first_vq || qid > last_vq)
> return -EINVAL;
>
> squashing the following in virtnet_get_hw_stats():
>
> - if (enable_cvq)
> + if (enable_cvq) {
> virtnet_make_stat_req(vi, ctx, req, vi->max_queue_pairs * 2, &j);
> + last_vq++;
> + }
>
> (likely with some meaningful comment).
Thanks for the review!
I looked into this, and I think last_vq + 1 matches the control vq
only when all queue pairs are in use. The control vq index is
max_queue_pairs * 2, while last_vq is curr_queue_pairs * 2 - 1 for
ethtool -S. After ethtool -L lowers the queue count, or when probe caps
curr_queue_pairs at num_online_cpus(), last_vq + 1 is the receive vq at
index curr_queue_pairs * 2, which is not in the request. The simplified
check would accept a record for it. Since the ethtool -S array has
slots for only curr_queue_pairs queue pairs, with the transmit slots at
its end, virtnet_fill_stats() would write the counters of that record
into the transmit slots, and can write past the end of the array.
Would you like me to keep the current check or change it in some
other way?
As for the comment, I would add the following above the check in v2:
/* The control vq comes after all max_queue_pairs pairs, so it
* exceeds last_vq + 1 when fewer pairs are in use.
*/
Thanks,
Lianjie Wang
prev parent reply other threads:[~2026-10-27 13:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 18:26 Lianjie Wang
2026-10-27 12:06 ` Paolo Abeni
2026-10-27 13:53 ` Lianjie Wang [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=auCkXHi6IulXgm7v@wang0.localdomain \
--to=karin0.zst@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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®