Skip to content

Commit f8844df

Browse files
Di Zhukuba-moo
authored andcommitted
virtio-net: enable NETIF_F_GRO_HW only if GRO-related offloads are supported
Negotiating VIRTIO_NET_F_CTRL_GUEST_OFFLOADS indicates the device allows control over offload support, but the offloads that can be controlled may have nothing to do with GRO (e.g., if neither GUEST_TSO4 nor GUEST_TSO6 is supported). In such a setup, reporting NETIF_F_GRO_HW as available for the device is too optimistic and misleading to the user. Improve the situation by masking off NETIF_F_GRO_HW unless the device possesses actual GRO-related offload capabilities. Out of an abundance of caution, this does not change the current behaviour for hardware with just v6 or just v4 GRO: current interfaces do not allow distinguishing between v6/v4 GRO, so we can't expose them to userspace precisely. Signed-off-by: Di Zhu <zhud@hygon.cn> Acked-by: Jason Wang <jasowang@redhat.com> Link: https://patch.msgid.link/20260323041730.986351-1-zhud@hygon.cn Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 6a539ee commit f8844df

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

drivers/net/virtio_net.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6800,8 +6800,6 @@ static int virtnet_probe(struct virtio_device *vdev)
68006800
if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
68016801
virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6))
68026802
dev->features |= NETIF_F_GRO_HW;
6803-
if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS))
6804-
dev->hw_features |= NETIF_F_GRO_HW;
68056803

68066804
dev->vlan_features = dev->features;
68076805
dev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
@@ -6994,6 +6992,19 @@ static int virtnet_probe(struct virtio_device *vdev)
69946992

69956993
enable_rx_mode_work(vi);
69966994

6995+
for (i = 0; i < ARRAY_SIZE(guest_offloads); i++) {
6996+
unsigned int fbit;
6997+
6998+
fbit = virtio_offload_to_feature(guest_offloads[i]);
6999+
if (virtio_has_feature(vi->vdev, fbit))
7000+
set_bit(guest_offloads[i], &vi->guest_offloads);
7001+
}
7002+
vi->guest_offloads_capable = vi->guest_offloads;
7003+
7004+
if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) &&
7005+
(vi->guest_offloads_capable & GUEST_OFFLOAD_GRO_HW_MASK))
7006+
dev->hw_features |= NETIF_F_GRO_HW;
7007+
69977008
/* serialize netdev register + virtio_device_ready() with ndo_open() */
69987009
rtnl_lock();
69997010

@@ -7076,15 +7087,6 @@ static int virtnet_probe(struct virtio_device *vdev)
70767087
netif_carrier_on(dev);
70777088
}
70787089

7079-
for (i = 0; i < ARRAY_SIZE(guest_offloads); i++) {
7080-
unsigned int fbit;
7081-
7082-
fbit = virtio_offload_to_feature(guest_offloads[i]);
7083-
if (virtio_has_feature(vi->vdev, fbit))
7084-
set_bit(guest_offloads[i], &vi->guest_offloads);
7085-
}
7086-
vi->guest_offloads_capable = vi->guest_offloads;
7087-
70887090
rtnl_unlock();
70897091

70907092
err = virtnet_cpu_notif_add(vi);

0 commit comments

Comments
 (0)