提交 25e248a2 编写于 作者: D David S. Miller

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: NDavid S. Miller <davem@davemloft.net>
...@@ -380,7 +380,7 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, ...@@ -380,7 +380,7 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
struct page *page, unsigned int offset, struct page *page, unsigned int offset,
unsigned int len, unsigned int truesize, unsigned int len, unsigned int truesize,
bool hdr_valid, unsigned int metasize, bool hdr_valid, unsigned int metasize,
unsigned int headroom) bool whole_page)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct virtio_net_hdr_mrg_rxbuf *hdr; struct virtio_net_hdr_mrg_rxbuf *hdr;
...@@ -398,17 +398,21 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, ...@@ -398,17 +398,21 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
else else
hdr_padded_len = sizeof(struct padded_vnet_hdr); 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 * data and the allocated space, otherwise the data and the allocated
* space are aligned. * space are aligned.
*/ */
if (headroom) { if (whole_page) {
/* Buffers with headroom use PAGE_SIZE as alloc size, /* Buffers with whole_page use PAGE_SIZE as alloc size,
* see add_recvbuf_mergeable() + get_mergeable_buf_len() * see add_recvbuf_mergeable() + get_mergeable_buf_len()
*/ */
truesize = PAGE_SIZE; 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 { } else {
tailroom = truesize - len; tailroom = truesize - len;
buf = p; buf = p;
...@@ -958,7 +962,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, ...@@ -958,7 +962,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
put_page(page); put_page(page);
head_skb = page_to_skb(vi, rq, xdp_page, offset, head_skb = page_to_skb(vi, rq, xdp_page, offset,
len, PAGE_SIZE, false, len, PAGE_SIZE, false,
metasize, headroom); metasize, true);
return head_skb; return head_skb;
} }
break; break;
...@@ -1016,7 +1020,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, ...@@ -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, head_skb = page_to_skb(vi, rq, page, offset, len, truesize, !xdp_prog,
metasize, headroom); metasize, !!headroom);
curr_skb = head_skb; curr_skb = head_skb;
if (unlikely(!curr_skb)) if (unlikely(!curr_skb))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册