Skip to content

Commit 8fb7da9

Browse files
fengidridavem330
authored andcommitted
virtio_net: get build_skb() buf by data ptr
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, we should get buf based on headroom instead of offset. 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 <[email protected]> Acked-by: Jason Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5c37711 commit 8fb7da9

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

drivers/net/virtio_net.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,18 +401,13 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
401401
/* If headroom is not 0, there is an offset between the beginning of the
402402
* data and the allocated space, otherwise the data and the allocated
403403
* space are aligned.
404+
*
405+
* Buffers with headroom use PAGE_SIZE as alloc size, see
406+
* add_recvbuf_mergeable() + get_mergeable_buf_len()
404407
*/
405-
if (headroom) {
406-
/* Buffers with headroom use PAGE_SIZE as alloc size,
407-
* see add_recvbuf_mergeable() + get_mergeable_buf_len()
408-
*/
409-
truesize = PAGE_SIZE;
410-
tailroom = truesize - len - offset;
411-
buf = page_address(page);
412-
} else {
413-
tailroom = truesize - len;
414-
buf = p;
415-
}
408+
truesize = headroom ? PAGE_SIZE : truesize;
409+
tailroom = truesize - len - headroom;
410+
buf = p - headroom;
416411

417412
len -= hdr_len;
418413
offset += hdr_padded_len;

0 commit comments

Comments
 (0)