Skip to contentSkip to conversation

xdp and fragments with virtio

PATCH David Ahern 2 participants 5 messages May 16, 2018 – May 18, 2018

Subsystems (5)
Networking Network drivers BPF XDP +1 more subsystems
lore
Share & tools
lore
#0 lore raw

Hi Jason:

I am trying to test MTU changes to the BPF fib_lookup helper and seeing something odd. Hoping you can help.

I have a VM with multiple virtio based NICs and tap backends. I install the xdp program on eth1 and eth2 to do forwarding. In the host I send a large packet to eth1:

$ ping -s 1500 9.9.9.9

The tap device in the host sees 2 packets:

$ sudo tcpdump -nv -i vm02-eth1
20:44:33.943160 IP (tos 0x0, ttl 64, id 58746, offset 0, flags [+],
proto ICMP (1), length 1500)
    10.100.1.254 > 9.9.9.9: ICMP echo request, id 17917, seq 1, length 1480
20:44:33.943172 IP (tos 0x0, ttl 64, id 58746, offset 1480, flags
[none], proto ICMP (1), length 48)
    10.100.1.254 > 9.9.9.9: ip-proto-1

In the VM, the XDP program only sees the first packet, not the fragment. I added a printk to the program (see diff below):

$ cat trace_pipe
          <idle>-0     [003] ..s2   254.436467: 0: packet length 1514

Anything come to mind in the virtio xdp implementation that affects fragment packets? I see this with both IPv4 and v6.

Thanks,
David

[1] xdp program diff showing printk that dumps packet length:

samples/bpf/xdp_fwd_kern.c +0 -0
index 4a6be0f87505..f119b506e782 100644
@@ -52,6 +52,11 @@ static __always_inline int xdp_fwd_flags(struct

xdp_md *ctx, u32 flags)

        u16 h_proto;
        u64 nh_off;

+ {
+ char fmt[] = "packet length %u\n";
+
+ bpf_trace_printk(fmt, sizeof(fmt), ctx->data_end-ctx->data);
+ }

        nh_off = sizeof(*eth);
        if (data + nh_off > data_end)
                return XDP_DROP;
#1 lore raw
Quoted 26 lines · David Ahern

Hi Jason:

I am trying to test MTU changes to the BPF fib_lookup helper and seeing something odd. Hoping you can help.

I have a VM with multiple virtio based NICs and tap backends. I install the xdp program on eth1 and eth2 to do forwarding. In the host I send a large packet to eth1:

$ ping -s 1500 9.9.9.9

The tap device in the host sees 2 packets:

$ sudo tcpdump -nv -i vm02-eth1
20:44:33.943160 IP (tos 0x0, ttl 64, id 58746, offset 0, flags [+],
proto ICMP (1), length 1500)
     10.100.1.254 > 9.9.9.9: ICMP echo request, id 17917, seq 1, length 1480
20:44:33.943172 IP (tos 0x0, ttl 64, id 58746, offset 1480, flags
[none], proto ICMP (1), length 48)
     10.100.1.254 > 9.9.9.9: ip-proto-1

In the VM, the XDP program only sees the first packet, not the fragment. I added a printk to the program (see diff below):

Quoted 6 lines
$ cat trace_pipe
           <idle>-0     [003] ..s2   254.436467: 0: packet length 1514

Anything come to mind in the virtio xdp implementation that affects fragment packets? I see this with both IPv4 and v6.

Not yet. But we do turn of tap gso when virtio has XDP set, but it shouldn't matter this case.

Will try to see what's wrong.

Thanks

Quoted 24 lines

Thanks,
David

[1] xdp program diff showing printk that dumps packet length:

samples/bpf/xdp_fwd_kern.c +5 -0
index 4a6be0f87505..f119b506e782 100644
@@ -52,6 +52,11 @@ static __always_inline int xdp_fwd_flags(struct
 xdp_md *ctx, u32 flags)
         u16 h_proto;
         u64 nh_off;
 
+       {
+               char fmt[] = "packet length %u\n";
+
+               bpf_trace_printk(fmt, sizeof(fmt), ctx->data_end-ctx->data);
+       }
         nh_off = sizeof(*eth);
         if (data + nh_off > data_end)
                 return XDP_DROP;
#2 lore raw
Quoted 34 lines · Jason Wang
Quoted 31 lines · David Ahern

Hi Jason:

I am trying to test MTU changes to the BPF fib_lookup helper and seeing something odd. Hoping you can help.

I have a VM with multiple virtio based NICs and tap backends. I install the xdp program on eth1 and eth2 to do forwarding. In the host I send a large packet to eth1:

$ ping -s 1500 9.9.9.9

The tap device in the host sees 2 packets:

$ sudo tcpdump -nv -i vm02-eth1
20:44:33.943160 IP (tos 0x0, ttl 64, id 58746, offset 0, flags [+],
proto ICMP (1), length 1500)
     10.100.1.254 > 9.9.9.9: ICMP echo request, id 17917, seq 1,
length 1480
20:44:33.943172 IP (tos 0x0, ttl 64, id 58746, offset 1480, flags
[none], proto ICMP (1), length 48)
     10.100.1.254 > 9.9.9.9: ip-proto-1

In the VM, the XDP program only sees the first packet, not the fragment. I added a printk to the program (see diff below):

$ cat trace_pipe
           <idle>-0     [003] ..s2   254.436467: 0: packet length 1514
Quoted 8 lines
Quoted 2 lines

Anything come to mind in the virtio xdp implementation that affects fragment packets? I see this with both IPv4 and v6.

Not yet. But we do turn of tap gso when virtio has XDP set, but it shouldn't matter this case.

Will try to see what's wrong.

I added this to the command line for the NICs and it works:

"mrg_rxbuf=off,guest_tso4=off,guest_tso6=off,guest_ecn=off,guest_ufo=off"

XDP program sees the full size packet and the fragment.

Fun fact: only adding mrg_rxbuf=off so that mergeable_rx_bufs is false but big_packets is true generates a panic when it receives large packets.

#3 lore raw
Quoted 41 lines · David Ahern
Quoted 33 lines · Jason Wang
Quoted 31 lines · David Ahern

Hi Jason:

I am trying to test MTU changes to the BPF fib_lookup helper and seeing something odd. Hoping you can help.

I have a VM with multiple virtio based NICs and tap backends. I install the xdp program on eth1 and eth2 to do forwarding. In the host I send a large packet to eth1:

$ ping -s 1500 9.9.9.9

The tap device in the host sees 2 packets:

$ sudo tcpdump -nv -i vm02-eth1
20:44:33.943160 IP (tos 0x0, ttl 64, id 58746, offset 0, flags [+],
proto ICMP (1), length 1500)
      10.100.1.254 > 9.9.9.9: ICMP echo request, id 17917, seq 1,
length 1480
20:44:33.943172 IP (tos 0x0, ttl 64, id 58746, offset 1480, flags
[none], proto ICMP (1), length 48)
      10.100.1.254 > 9.9.9.9: ip-proto-1

In the VM, the XDP program only sees the first packet, not the fragment. I added a printk to the program (see diff below):

$ cat trace_pipe
            <idle>-0     [003] ..s2   254.436467: 0: packet length 1514
Quoted 7 lines
Quoted 2 lines

Anything come to mind in the virtio xdp implementation that affects fragment packets? I see this with both IPv4 and v6.

Not yet. But we do turn of tap gso when virtio has XDP set, but it shouldn't matter this case.

Will try to see what's wrong.

Quoted 8 lines

I added this to the command line for the NICs and it works:

"mrg_rxbuf=off,guest_tso4=off,guest_tso6=off,guest_ecn=off,guest_ufo=off"

XDP program sees the full size packet and the fragment.

Fun fact: only adding mrg_rxbuf=off so that mergeable_rx_bufs is false but big_packets is true generates a panic when it receives large packets.

It looks like we wrongly drop packets after linearizing the packets during XDP_REDIRECT.

Please try the patch (but I do spot some other issues, will post a series):

Thanks

drivers/net/virtio_net.c +0 -0
index f34794a..59702f9 100644
@@ -800,7 +800,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,

                        }
                        *xdp_xmit = true;
                        if (unlikely(xdp_page != page)) -                               goto err_xdp; +                               put_page(page); rcu_read_unlock(); goto xdp_xmit; default:

#4 lore raw
Quoted 20 lines · Jason Wang

It looks like we wrongly drop packets after linearizing the packets during XDP_REDIRECT.

Please try the patch (but I do spot some other issues, will post a series):

Thanks

drivers/net/virtio_net.c +1 -1
index f34794a..59702f9 100644
@@ -800,7 +800,7 @@ static struct sk_buff *receive_mergeable(struct
 net_device *dev,
                         }
                         *xdp_xmit = true;
                         if (unlikely(xdp_page != page))
-                               goto err_xdp;
+                               put_page(page);
                         rcu_read_unlock();
                         goto xdp_xmit;
Quoted 1 line

                default:

Yes, that does solve the problem of fragments getting lost.