diff options
author | David S. Miller <davem@davemloft.net> | 2021-05-13 15:51:14 -0700 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-05-13 15:51:14 -0700 |
commit | 25e248a2bc43fe4a7a9815addf1f46d26c0d2442 (patch) | |
tree | ddf5446f1fc95b4219761f87deef5a6278b44917 | |
parent | 33b314265683c9ef09593c3390e57ba85194f635 (diff) | |
parent | 7bf64460e3b2af4e6e46d932b2fbd933d662d19f (diff) |
Merge branch 'virtio_net-fixes'
Xuan Zhuo says:
====================
virtio-net: fix for build_skb()
The logic of this piece is really messy. Fortunately, my refactored patch can be
completed with a small amount of testing.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/virtio_net.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 9b6a4a875c55..073fec4c0df1 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -380,7 +380,7 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, struct page *page, unsigned int offset, unsigned int len, unsigned int truesize, bool hdr_valid, unsigned int metasize, - unsigned int headroom) + bool whole_page) { struct sk_buff *skb; struct virtio_net_hdr_mrg_rxbuf *hdr; @@ -398,17 +398,21 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, else hdr_padded_len = sizeof(struct padded_vnet_hdr); - /* If headroom is not 0, there is an offset between the beginning of the + /* If whole_page, there is an offset between the beginning of the * data and the allocated space, otherwise the data and the allocated * space are aligned. */ - if (headroom) { - /* Buffers with headroom use PAGE_SIZE as alloc size, + if (whole_page) { + /* Buffers with whole_page use PAGE_SIZE as alloc size, * see add_recvbuf_mergeable() + get_mergeable_buf_len() */ truesize = PAGE_SIZE; - tailroom = truesize - len - offset; - buf = page_address(page); + + /* page maybe head page, so we should get the buf by p, not the + * page + */ + tailroom = truesize - len - offset_in_page(p); + buf = (char *)((unsigned long)p & PAGE_MASK); } else { tailroom = truesize - len; buf = p; @@ -958,7 +962,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, put_page(page); head_skb = page_to_skb(vi, rq, xdp_page, offset, len, PAGE_SIZE, false, - metasize, headroom); + metasize, true); return head_skb; } break; @@ -1016,7 +1020,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, } head_skb = page_to_skb(vi, rq, page, offset, len, truesize, !xdp_prog, - metasize, headroom); + metasize, !!headroom); curr_skb = head_skb; if (unlikely(!curr_skb)) |