Skip to content

Commit c11a49d

Browse files
Wenbo LiPaolo Abeni
authored andcommitted
virtio_net: Fix mismatched buf address when unmapping for small packets
Currently, the virtio-net driver will perform a pre-dma-mapping for small or mergeable RX buffer. But for small packets, a mismatched address without VIRTNET_RX_PAD and xdp_headroom is used for unmapping. That will result in unsynchronized buffers when SWIOTLB is enabled, for example, when running as a TDX guest. This patch unifies the address passed to the virtio core as the address of the virtnet header and fixes the mismatched buffer address. Changes from v2: unify the buf that passed to the virtio core in small and merge mode. Changes from v1: Use ctx to get xdp_headroom. Fixes: 295525e ("virtio_net: merge dma operations when filling mergeable buffers") Signed-off-by: Wenbo Li <[email protected]> Signed-off-by: Jiahui Cen <[email protected]> Signed-off-by: Ying Fang <[email protected]> Reviewed-by: Xuan Zhuo <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 0cbfd45 commit c11a49d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/net/virtio_net.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,11 @@ static struct sk_buff *receive_small(struct net_device *dev,
18071807
struct page *page = virt_to_head_page(buf);
18081808
struct sk_buff *skb;
18091809

1810+
/* We passed the address of virtnet header to virtio-core,
1811+
* so truncate the padding.
1812+
*/
1813+
buf -= VIRTNET_RX_PAD + xdp_headroom;
1814+
18101815
len -= vi->hdr_len;
18111816
u64_stats_add(&stats->bytes, len);
18121817

@@ -2422,8 +2427,9 @@ static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq,
24222427
if (unlikely(!buf))
24232428
return -ENOMEM;
24242429

2425-
virtnet_rq_init_one_sg(rq, buf + VIRTNET_RX_PAD + xdp_headroom,
2426-
vi->hdr_len + GOOD_PACKET_LEN);
2430+
buf += VIRTNET_RX_PAD + xdp_headroom;
2431+
2432+
virtnet_rq_init_one_sg(rq, buf, vi->hdr_len + GOOD_PACKET_LEN);
24272433

24282434
err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp);
24292435
if (err < 0) {

0 commit comments

Comments
 (0)