>From c2778eb8ee4b7558bccb53f2fc7f1b0aaf1fcb58 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Tue, 28 Apr 2020 11:37:39 +0800 Subject: [PATCH 2/2] virtio-net: fix the XDP truesize calculation for mergeable buffers We should not exclude headroom and tailroom when XDP is set. So this patch fixes this by initializing the truesize from PAGE_SIZE when XDP is set. Signed-off-by: Jason Wang --- drivers/net/virtio_net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 9bdaf2425e6e..f9ba5275e447 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1172,7 +1172,7 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi, char *buf; void *ctx; int err; - unsigned int len, hole; + unsigned int len, hole, truesize; /* Extra tailroom is needed to satisfy XDP's assumption. This * means rx frags coalescing won't work, but consider we've @@ -1182,6 +1182,7 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi, if (unlikely(!skb_page_frag_refill(len + room, alloc_frag, gfp))) return -ENOMEM; + truesize = headroom ? PAGE_SIZE: len; buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset; buf += headroom; /* advance address leaving hole at front of pkt */ get_page(alloc_frag->page); @@ -1193,11 +1194,12 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi, * the current buffer. */ len += hole; + truesize += hole; alloc_frag->offset += hole; } sg_init_one(rq->sg, buf, len); - ctx = mergeable_len_to_ctx(len, headroom); + ctx = mergeable_len_to_ctx(truesize, headroom); err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp); if (err < 0) put_page(virt_to_head_page(buf)); -- 2.20.1