Skip to contentSkip to conversation

bpf: fix virtio-net's length calc for XDP_PASS

PATCH Applied Nikita V. Shirokov 3 participants 3 messages Apr 23, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: fix virtio-net's length calc for XDP_PASS

In commit 6870de435b90 ("bpf: make virtio compatible w/ bpf_xdp_adjust_tail") i didn't account for vi->hdr_len during new packet's length calculation after bpf_prog_run in receive_mergeable. because of this all packets, if they were passed to the kernel, were truncated by 12 bytes.

Fixes 6870de435b90 ("bpf: make virtio compatible w/ bpf_xdp_adjust_tail")

---

Notes:
unfortunately it looks like that xdp_tx is still broken because fix by Jason (introduced in "XDP_TX for virtio_net not working in recent kernel? " thread) haven't landed yet)

 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index 779a4f798522..08ac2cc986aa 100644
@@ -761,7 +761,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			/* recalculate len if xdp.data or xdp.data_end were
 			 * adjusted
 			 */
-			len = xdp.data_end - xdp.data;
+			len = xdp.data_end - xdp.data + vi->hdr_len;
 			/* We can only create skb based on xdp_page. */
 			if (unlikely(xdp_page != page)) {
 				rcu_read_unlock();
Signature · 1 line
2.15.1
Acked-by on v1 1/1
#1 lore raw
Quoted 25 lines · Nikita V. Shirokov

In commit 6870de435b90 ("bpf: make virtio compatible w/ bpf_xdp_adjust_tail") i didn't account for vi->hdr_len during new packet's length calculation after bpf_prog_run in receive_mergeable. because of this all packets, if they were passed to the kernel, were truncated by 12 bytes.

Fixes 6870de435b90 ("bpf: make virtio compatible w/ bpf_xdp_adjust_tail")

---

Notes:
unfortunately it looks like that xdp_tx is still broken because fix by Jason (introduced in "XDP_TX for virtio_net not working in recent kernel? " thread) haven't landed yet)

  drivers/net/virtio_net.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +0 -0
index 779a4f798522..08ac2cc986aa 100644

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 767

Quoted 8 lines
drivers/net/virtio_net.c +1 -1
@@ -761,7 +761,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  			/* recalculate len if xdp.data or xdp.data_end were
  			 * adjusted
  			 */
-			len = xdp.data_end - xdp.data;
+			len = xdp.data_end - xdp.data + vi->hdr_len;
  			/* We can only create skb based on xdp_page. */
  			if (unlikely(xdp_page != page)) {
  				rcu_read_unlock();
#2 lore raw
Quoted 11 lines · Jason Wang
Quoted 10 lines · Nikita V. Shirokov

In commit 6870de435b90 ("bpf: make virtio compatible w/ bpf_xdp_adjust_tail") i didn't account for vi->hdr_len during new packet's length calculation after bpf_prog_run in receive_mergeable. because of this all packets, if they were passed to the kernel, were truncated by 12 bytes.

Fixes 6870de435b90 ("bpf: make virtio compatible w/ bpf_xdp_adjust_tail")

[...]

Quoted 2 lines

Applied to bpf-next, thanks everyone!