Skip to content

Commit

Permalink
virtio-net: realign page_to_skb() after merges
Browse files Browse the repository at this point in the history
We ended up merging two versions of the same patch set:

commit 8fb7da9 ("virtio_net: get build_skb() buf by data ptr")
commit 5c37711 ("virtio-net: fix for unable to handle page fault for address")

into net, and

commit 7bf6446 ("virtio-net: get build_skb() buf by data ptr")
commit 6c66c14 ("virtio-net: fix for unable to handle page fault for address")

into net-next. Redo the merge from commit 1262856 ("Merge
ra.kernel.org:/pub/scm/linux/kernel/git/netdev/net"), so that
the most recent code remains.

Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed Aug 3, 2021
1 parent dc1a807 commit c32325b
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
bool whole_page)
unsigned int headroom)
{
struct sk_buff *skb;
struct virtio_net_hdr_mrg_rxbuf *hdr;
Expand All @@ -398,28 +398,16 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
else
hdr_padded_len = sizeof(struct padded_vnet_hdr);

/* If whole_page, there is an offset between the beginning of the
/* If headroom is not 0, there is an offset between the beginning of the
* data and the allocated space, otherwise the data and the allocated
* space are aligned.
*
* Buffers with headroom use PAGE_SIZE as alloc size, see
* add_recvbuf_mergeable() + get_mergeable_buf_len()
*/
if (whole_page) {
/* Buffers with whole_page use PAGE_SIZE as alloc size,
* see add_recvbuf_mergeable() + get_mergeable_buf_len()
*/
truesize = PAGE_SIZE;

/* 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;
}
truesize = headroom ? PAGE_SIZE : truesize;
tailroom = truesize - len - headroom;
buf = p - headroom;

len -= hdr_len;
offset += hdr_padded_len;
Expand Down Expand Up @@ -978,7 +966,8 @@ 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, true);
metasize,
VIRTIO_XDP_HEADROOM);
return head_skb;
}
break;
Expand Down Expand Up @@ -1029,7 +1018,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
rcu_read_unlock();

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))
Expand Down

0 comments on commit c32325b

Please sign in to comment.