Skip to content

Commit

Permalink
virtio-net: get build_skb() buf by data ptr
Browse files Browse the repository at this point in the history
In the case of merge, the page passed into page_to_skb() may be a head
page, not the page where the current data is located. So when trying to
get the buf where the data is located, you should directly use the
pointer(p) to get the address corresponding to the page.

At the same time, the offset of the data in the page should also be
obtained using offset_in_page().

This patch solves this problem. But if you don’t use this patch, the
original code can also run, because if the page is not the page of the
current data, the calculated tailroom will be less than 0, and will not
enter the logic of build_skb() . The significance of this patch is to
modify this logical problem, allowing more situations to use
build_skb().

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Xuan Zhuo authored and David S. Miller committed May 13, 2021
1 parent 6c66c14 commit 7bf6446
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,12 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
* 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;
Expand Down

0 comments on commit 7bf6446

Please sign in to comment.