* [PATCH] virtio_net: Fix duplicated return values in virtnet_get_hw_stats
@ 2025-05-14 5:44 Tang Longjun
2025-05-15 14:10 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Tang Longjun @ 2025-05-14 5:44 UTC (permalink / raw)
To: xuanzhuo, jasowang
Cc: mst, davem, edumazet, netdev, virtualization, Tang Longjun
From: Tang Longjun <tanglongjun@kylinos.cn>
virtnet_get_hw_stats will return same value of 0 in the following three cases:
1. VIRTIO_NET_F_DEVICE_STATS feature is not configured on the device side.
2. success to obtain device stats.
3. fail to obtain device stats.
This would lead to case 1 and case 3 being unable to be recognized.
So, it's fixed by returning different values for the three cases.
Fixes: 941168f8b40e ("virtio_net: support device stats")
Signed-off-by: Tang Longjun <tanglongjun@kylinos.cn>
---
drivers/net/virtio_net.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index e53ba600605a..c9a86f325619 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -4897,7 +4897,7 @@ static int __virtnet_get_hw_stats(struct virtnet_info *vi,
&sgs_out, &sgs_in);
if (!ok)
- return ok;
+ return 1;
for (p = reply; p - reply < res_size; p += le16_to_cpu(hdr->size)) {
hdr = p;
@@ -4937,7 +4937,7 @@ static int virtnet_get_hw_stats(struct virtnet_info *vi,
int ok;
if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_DEVICE_STATS))
- return 0;
+ return -EOPNOTSUPP;
if (qid == -1) {
last_vq = vi->curr_queue_pairs * 2 - 1;
@@ -5038,10 +5038,12 @@ static void virtnet_get_ethtool_stats(struct net_device *dev,
struct virtnet_stats_ctx ctx = {0};
unsigned int start, i;
const u8 *stats_base;
+ int ret;
virtnet_stats_ctx_init(vi, &ctx, data, false);
- if (virtnet_get_hw_stats(vi, &ctx, -1))
- dev_warn(&vi->dev->dev, "Failed to get hw stats.\n");
+ ret = virtnet_get_hw_stats(vi, &ctx, -1);
+ if (ret)
+ dev_warn(&vi->dev->dev, "Failed to get hw stats. err code:%d\n", ret);
for (i = 0; i < vi->curr_queue_pairs; i++) {
struct receive_queue *rq = &vi->rq[i];
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio_net: Fix duplicated return values in virtnet_get_hw_stats
2025-05-14 5:44 [PATCH] virtio_net: Fix duplicated return values in virtnet_get_hw_stats Tang Longjun
@ 2025-05-15 14:10 ` Jakub Kicinski
2025-05-16 7:36 ` Lange Tang
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2025-05-15 14:10 UTC (permalink / raw)
To: Tang Longjun
Cc: xuanzhuo, jasowang, mst, davem, edumazet, netdev, virtualization,
Tang Longjun
On Wed, 14 May 2025 13:44:33 +0800 Tang Longjun wrote:
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index e53ba600605a..c9a86f325619 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -4897,7 +4897,7 @@ static int __virtnet_get_hw_stats(struct virtnet_info *vi,
> &sgs_out, &sgs_in);
>
> if (!ok)
> - return ok;
> + return 1;
This makes sense, looks like a typo in the original code.
But we are now returning the reverse polarity of "ok", so we should
probably rename the variable in virtnet_get_hw_stats() ok -> failed
Or invert the polarity here and in virtnet_get_hw_stats()
> for (p = reply; p - reply < res_size; p += le16_to_cpu(hdr->size)) {
> hdr = p;
> @@ -4937,7 +4937,7 @@ static int virtnet_get_hw_stats(struct virtnet_info *vi,
> int ok;
>
> if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_DEVICE_STATS))
> - return 0;
> + return -EOPNOTSUPP;
IDK about this part. We should not spam the logs if the device does not
support a feature. We should instead skip reporting the relevant stats.
User can tell that those stats are not supported from the fact they are
not present.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re:Re: [PATCH] virtio_net: Fix duplicated return values in virtnet_get_hw_stats
2025-05-15 14:10 ` Jakub Kicinski
@ 2025-05-16 7:36 ` Lange Tang
0 siblings, 0 replies; 3+ messages in thread
From: Lange Tang @ 2025-05-16 7:36 UTC (permalink / raw)
To: Jakub Kicinski
Cc: xuanzhuo@linux.alibaba.com, jasowang@redhat.com, mst@redhat.com,
davem@davemloft.net, edumazet@google.com, netdev@vger.kernel.org,
virtualization@lists.linux.dev, Tang Longjun
At 2025-05-15 22:10:42, "Jakub Kicinski" <kuba@kernel.org> wrote:
>On Wed, 14 May 2025 13:44:33 +0800 Tang Longjun wrote:
>> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
>> index e53ba600605a..c9a86f325619 100644
>> --- a/drivers/net/virtio_net.c
>> +++ b/drivers/net/virtio_net.c
>> @@ -4897,7 +4897,7 @@ static int __virtnet_get_hw_stats(struct virtnet_info *vi,
>> &sgs_out, &sgs_in);
>>
>> if (!ok)
>> - return ok;
>> + return 1;
>
>This makes sense, looks like a typo in the original code.
>But we are now returning the reverse polarity of "ok", so we should
>probably rename the variable in virtnet_get_hw_stats() ok -> failed
>Or invert the polarity here and in virtnet_get_hw_stats()
>
>> for (p = reply; p - reply < res_size; p += le16_to_cpu(hdr->size)) {
>> hdr = p;
>> @@ -4937,7 +4937,7 @@ static int virtnet_get_hw_stats(struct virtnet_info *vi,
>> int ok;
>>
>> if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_DEVICE_STATS))
>> - return 0;
>> + return -EOPNOTSUPP;
>
>IDK about this part. We should not spam the logs if the device does not
>support a feature. We should instead skip reporting the relevant stats.
>User can tell that those stats are not supported from the fact they are
>not present.
>--
>pw-bot: cr
I found that Dan Carpenter had discovered the same issue before, and he had already submitted a patch, so I'm backing out.
https://lore.kernel.org/netdev/20240515110626-mutt-send-email-mst@kernel.org/
regards,
Tang Longjun
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-16 7:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-14 5:44 [PATCH] virtio_net: Fix duplicated return values in virtnet_get_hw_stats Tang Longjun
2025-05-15 14:10 ` Jakub Kicinski
2025-05-16 7:36 ` Lange Tang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).