Skip to content

Commit 0eff2ea

Browse files
fengidriPaolo Abeni
authored andcommitted
virtio-net: fix incorrect flags recording in big mode
The purpose of commit 703eec1 ("virtio_net: fixing XDP for fully checksummed packets handling") is to record the flags in advance, as their value may be overwritten in the XDP case. However, the flags recorded under big mode are incorrect, because in big mode, the passed buf does not point to the rx buffer, but rather to the page of the submitted buffer. This commit fixes this issue. For the small mode, the commit c11a49d ("virtio_net: Fix mismatched buf address when unmapping for small packets") fixed it. Tested-by: Alyssa Ross <hi@alyssa.is> Fixes: 703eec1 ("virtio_net: fixing XDP for fully checksummed packets handling") Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Acked-by: Jason Wang <jasowang@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Link: https://patch.msgid.link/20251111090828.23186-1-xuanzhuo@linux.alibaba.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent fe82c4f commit 0eff2ea

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

drivers/net/virtio_net.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,22 +2631,28 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
26312631
return;
26322632
}
26332633

2634-
/* 1. Save the flags early, as the XDP program might overwrite them.
2634+
/* About the flags below:
2635+
* 1. Save the flags early, as the XDP program might overwrite them.
26352636
* These flags ensure packets marked as VIRTIO_NET_HDR_F_DATA_VALID
26362637
* stay valid after XDP processing.
26372638
* 2. XDP doesn't work with partially checksummed packets (refer to
26382639
* virtnet_xdp_set()), so packets marked as
26392640
* VIRTIO_NET_HDR_F_NEEDS_CSUM get dropped during XDP processing.
26402641
*/
2641-
flags = ((struct virtio_net_common_hdr *)buf)->hdr.flags;
26422642

2643-
if (vi->mergeable_rx_bufs)
2643+
if (vi->mergeable_rx_bufs) {
2644+
flags = ((struct virtio_net_common_hdr *)buf)->hdr.flags;
26442645
skb = receive_mergeable(dev, vi, rq, buf, ctx, len, xdp_xmit,
26452646
stats);
2646-
else if (vi->big_packets)
2647+
} else if (vi->big_packets) {
2648+
void *p = page_address((struct page *)buf);
2649+
2650+
flags = ((struct virtio_net_common_hdr *)p)->hdr.flags;
26472651
skb = receive_big(dev, vi, rq, buf, len, stats);
2648-
else
2652+
} else {
2653+
flags = ((struct virtio_net_common_hdr *)buf)->hdr.flags;
26492654
skb = receive_small(dev, vi, rq, buf, ctx, len, xdp_xmit, stats);
2655+
}
26502656

26512657
if (unlikely(!skb))
26522658
return;

0 commit comments

Comments
 (0)