Skip to contentSkip to conversation

net: Fix announce_self with vhost

PATCH Applied Laurent Vivier 5 participants 13 messages Jan 17, 2025 – Feb 2, 2025 Networking

lore
Share & tools
lore
#0 lore raw

cover net: Fix announce_self with vhost

announce_self that sends a RARP packet after migration or with announce_self QMP/HMP command doesn't work with vhost because of the vnet headers.

announce_self is the only user of QEMU_NET_PACKET_FLAG_RAW and this flag is not correctly managed.

This series fix a problem with this flag in filter-dump and in qemu_deliver_packet_iov().

Laurent Vivier (2):
net: Fix announce_self
net/dump: Correctly compute Ethernet packet offset

 net/dump.c | 3 ++-
 net/net.c  | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/2 net: Fix announce_self

b9ad513e1876 ("net: Remove receive_raw()") adds an iovec entry in qemu_deliver_packet_iov() to add the virtio-net header in the data when QEMU_NET_PACKET_FLAG_RAW is set but forgets to increase the number of iovec entries in the array, so receive_iov() will only send the first entry (the virtio-net entry, full of 0) and no data. The packet will be discarded.

The only user of QEMU_NET_PACKET_FLAG_RAW is announce_self.

We can see the problem with tcpdump:

- QEMU parameters:

  .. -monitor stdio \
     -netdev bridge,id=netdev0,br=virbr0 \
     -device virtio-net,mac=9a:2b:2c:2d:2e:2f,netdev=netdev0 \

- HMP command:

(qemu) announce_self

- TCP dump:

  $ sudo tcpdump -nxi virbr0

without the fix:

<nothing>

with the fix:

ARP, Reverse Request who-is 9a:2b:2c:2d:2e:2f tell 9a:2b:2c:2d:2e:2f, length 46

        0x0000:  0001 0800 0604 0003 9a2b 2c2d 2e2f 0000
        0x0010:  0000 9a2b 2c2d 2e2f 0000 0000 0000 0000
        0x0020:  0000 0000 0000 0000 0000 0000 0000
---
 net/net.c | 1 +
 1 file changed, 1 insertion(+)
net/net.c +1 -0
index c1bb19a52373..9cded70dde74 100644
@@ -822,6 +822,7 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *sender,
         iov_copy[0].iov_len =  nc->vnet_hdr_len;
         memcpy(&iov_copy[1], iov, iovcnt * sizeof(*iov));
         iov = iov_copy;
+        iovcnt++;
     }
 
     if (nc->info->receive_iov) {
Signature · 1 line
2.47.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] net: Fix announce_self

Quoted 36 lines · Laurent Vivier

b9ad513e1876 ("net: Remove receive_raw()") adds an iovec entry in qemu_deliver_packet_iov() to add the virtio-net header in the data when QEMU_NET_PACKET_FLAG_RAW is set but forgets to increase the number of iovec entries in the array, so receive_iov() will only send the first entry (the virtio-net entry, full of 0) and no data. The packet will be discarded.

The only user of QEMU_NET_PACKET_FLAG_RAW is announce_self.

We can see the problem with tcpdump:

- QEMU parameters:

   .. -monitor stdio \
      -netdev bridge,id=netdev0,br=virbr0 \
      -device virtio-net,mac=9a:2b:2c:2d:2e:2f,netdev=netdev0 \

- HMP command:

(qemu) announce_self

- TCP dump:

   $ sudo tcpdump -nxi virbr0
   without the fix:

     <nothing>

   with the fix:

    ARP, Reverse Request who-is 9a:2b:2c:2d:2e:2f tell 9a:2b:2c:2d:2e:2f, length 46
         0x0000:  0001 0800 0604 0003 9a2b 2c2d 2e2f 0000
         0x0010:  0000 9a2b 2c2d 2e2f 0000 0000 0000 0000
         0x0020:  0000 0000 0000 0000 0000 0000 0000
Quoted 5 lines

Thanks for finding out this bug:

I believe this should have:

Quoted 16 lines
---
  net/net.c | 1 +
  1 file changed, 1 insertion(+)
net/net.c +1 -0
index c1bb19a52373..9cded70dde74 100644
@@ -822,6 +822,7 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *sender,
          iov_copy[0].iov_len =  nc->vnet_hdr_len;
          memcpy(&iov_copy[1], iov, iovcnt * sizeof(*iov));
          iov = iov_copy;
+        iovcnt++;
      }
 
      if (nc->info->receive_iov) {
Acked-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] net: Fix announce_self

In reply to Laurent Vivier
Quoted 37 lines · Laurent Vivier

b9ad513e1876 ("net: Remove receive_raw()") adds an iovec entry in qemu_deliver_packet_iov() to add the virtio-net header in the data when QEMU_NET_PACKET_FLAG_RAW is set but forgets to increase the number of iovec entries in the array, so receive_iov() will only send the first entry (the virtio-net entry, full of 0) and no data. The packet will be discarded.

The only user of QEMU_NET_PACKET_FLAG_RAW is announce_self.

We can see the problem with tcpdump:

- QEMU parameters:

  .. -monitor stdio \
     -netdev bridge,id=netdev0,br=virbr0 \
     -device virtio-net,mac=9a:2b:2c:2d:2e:2f,netdev=netdev0 \

- HMP command:

(qemu) announce_self

- TCP dump:

  $ sudo tcpdump -nxi virbr0

without the fix:

<nothing>

with the fix:

   ARP, Reverse Request who-is 9a:2b:2c:2d:2e:2f tell 9a:2b:2c:2d:2e:2f, length 46
        0x0000:  0001 0800 0604 0003 9a2b 2c2d 2e2f 0000
        0x0010:  0000 9a2b 2c2d 2e2f 0000 0000 0000 0000
        0x0020:  0000 0000 0000 0000 0000 0000 0000
Quoted 6 lines

---

Thanks

#4 lore raw

PATCH 2/2 net/dump: Correctly compute Ethernet packet offset

In reply to Laurent Vivier

When a packet is sent with QEMU_NET_PACKET_FLAG_RAW by QEMU it never includes virtio-net header even if qemu_get_vnet_hdr_len() is not 0, and filter-dump is not managing this case.

The only user of QEMU_NET_PACKET_FLAG_RAW is announce_self, we can show the problem using it and tcpddump:

- QEMU parameters:

  .. -monitor stdio \
     -netdev bridge,id=netdev0,br=virbr0 \
     -device virtio-net,mac=9a:2b:2c:2d:2e:2f,netdev=netdev0 \
     -object filter-dump,netdev=netdev0,file=log.pcap,id=pcap0

- HMP command:

(qemu) announce_self

- TCP dump:

  $ tcpdump -nxr log.pcap

without the fix:

    08:00:06:04:00:03 > 2e:2f:80:35:00:01, ethertype Unknown (0x9a2b), length 50:
         0x0000:  2c2d 2e2f 0000 0000 9a2b 2c2d 2e2f 0000
         0x0010:  0000 0000 0000 0000 0000 0000 0000 0000
         0x0020:  0000 0000

with the fix:

    ARP, Reverse Request who-is 9a:2b:2c:2d:2e:2f tell 9a:2b:2c:2d:2e:2f, length 46
         0x0000:  0001 0800 0604 0003 9a2b 2c2d 2e2f 0000
         0x0010:  0000 9a2b 2c2d 2e2f 0000 0000 0000 0000
         0x0020:  0000 0000 0000 0000 0000 0000 0000
Fixes 481c52320a26 ("net: Strip virtio-net header when dumping")
---
 net/dump.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/dump.c +2 -1
index d7dd2ce461de..140215aa1054 100644
@@ -155,7 +155,8 @@ static ssize_t filter_dump_receive_iov(NetFilterState *nf, NetClientState *sndr,
 {
     NetFilterDumpState *nfds = FILTER_DUMP(nf);
 
-    dump_receive_iov(&nfds->ds, iov, iovcnt, qemu_get_vnet_hdr_len(nf->netdev));
+    dump_receive_iov(&nfds->ds, iov, iovcnt, flags & QEMU_NET_PACKET_FLAG_RAW ?
+                     0 : qemu_get_vnet_hdr_len(nf->netdev));
     return 0;
 }
 
Signature · 1 line
2.47.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] net/dump: Correctly compute Ethernet packet offset

Quoted 36 lines · Laurent Vivier

When a packet is sent with QEMU_NET_PACKET_FLAG_RAW by QEMU it never includes virtio-net header even if qemu_get_vnet_hdr_len() is not 0, and filter-dump is not managing this case.

The only user of QEMU_NET_PACKET_FLAG_RAW is announce_self, we can show the problem using it and tcpddump:

- QEMU parameters:

   .. -monitor stdio \
      -netdev bridge,id=netdev0,br=virbr0 \
      -device virtio-net,mac=9a:2b:2c:2d:2e:2f,netdev=netdev0 \
      -object filter-dump,netdev=netdev0,file=log.pcap,id=pcap0

- HMP command:

(qemu) announce_self

- TCP dump:

   $ tcpdump -nxr log.pcap
   without the fix:

     08:00:06:04:00:03 > 2e:2f:80:35:00:01, ethertype Unknown (0x9a2b), length 50:
          0x0000:  2c2d 2e2f 0000 0000 9a2b 2c2d 2e2f 0000
          0x0010:  0000 0000 0000 0000 0000 0000 0000 0000
          0x0020:  0000 0000

   with the fix:

     ARP, Reverse Request who-is 9a:2b:2c:2d:2e:2f tell 9a:2b:2c:2d:2e:2f, length 46
          0x0000:  0001 0800 0604 0003 9a2b 2c2d 2e2f 0000
          0x0010:  0000 9a2b 2c2d 2e2f 0000 0000 0000 0000
          0x0020:  0000 0000 0000 0000 0000 0000 0000
Quoted 3 lines
Fixes 481c52320a26 ("net: Strip virtio-net header when dumping")
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] net/dump: Correctly compute Ethernet packet offset

In reply to Laurent Vivier
Quoted 37 lines · Laurent Vivier

When a packet is sent with QEMU_NET_PACKET_FLAG_RAW by QEMU it never includes virtio-net header even if qemu_get_vnet_hdr_len() is not 0, and filter-dump is not managing this case.

The only user of QEMU_NET_PACKET_FLAG_RAW is announce_self, we can show the problem using it and tcpddump:

- QEMU parameters:

  .. -monitor stdio \
     -netdev bridge,id=netdev0,br=virbr0 \
     -device virtio-net,mac=9a:2b:2c:2d:2e:2f,netdev=netdev0 \
     -object filter-dump,netdev=netdev0,file=log.pcap,id=pcap0

- HMP command:

(qemu) announce_self

- TCP dump:

  $ tcpdump -nxr log.pcap

without the fix:

    08:00:06:04:00:03 > 2e:2f:80:35:00:01, ethertype Unknown (0x9a2b), length 50:
         0x0000:  2c2d 2e2f 0000 0000 9a2b 2c2d 2e2f 0000
         0x0010:  0000 0000 0000 0000 0000 0000 0000 0000
         0x0020:  0000 0000

with the fix:

    ARP, Reverse Request who-is 9a:2b:2c:2d:2e:2f tell 9a:2b:2c:2d:2e:2f, length 46
         0x0000:  0001 0800 0604 0003 9a2b 2c2d 2e2f 0000
         0x0010:  0000 9a2b 2c2d 2e2f 0000 0000 0000 0000
         0x0020:  0000 0000 0000 0000 0000 0000 0000
Quoted 4 lines
Fixes 481c52320a26 ("net: Strip virtio-net header when dumping")

---

Thanks

#7 lore raw
In reply to Laurent Vivier
CC qemu-stable and qemu-trivial.
Quoted 18 lines · Laurent Vivier

announce_self that sends a RARP packet after migration or with announce_self QMP/HMP command doesn't work with vhost because of the vnet headers.

announce_self is the only user of QEMU_NET_PACKET_FLAG_RAW and this flag is not correctly managed.

This series fix a problem with this flag in filter-dump and in qemu_deliver_packet_iov().

Laurent Vivier (2):
net: Fix announce_self
net/dump: Correctly compute Ethernet packet offset

  net/dump.c | 3 ++-
  net/net.c  | 1 +
  2 files changed, 3 insertions(+), 1 deletion(-)
#8 lore raw
Quoted 16 lines · Laurent Vivier
CC qemu-stable and qemu-trivial.
Quoted 13 lines · Laurent Vivier

announce_self that sends a RARP packet after migration or with announce_self QMP/HMP command doesn't work with vhost because of the vnet headers.

announce_self is the only user of QEMU_NET_PACKET_FLAG_RAW and this flag is not correctly managed.

This series fix a problem with this flag in filter-dump and in qemu_deliver_packet_iov().

Laurent Vivier (2):
   net: Fix announce_self
   net/dump: Correctly compute Ethernet packet offset

Is this one - "Correctly compute Ethernet packet offset" - needed for older stable series too, like 8.2 and 7.2 (currently active ones)?

Since it doesn't apply without 4b52d63249 (tap: Remove qemu_using_vnet_hdr()).

Thanks,

/mjt

#9 lore raw

Le 01/02/2025 à 20:36, Michael Tokarev a écrit :

Quoted 14 lines
Quoted 13 lines · Laurent Vivier
CC qemu-stable and qemu-trivial.
Quoted 10 lines · Laurent Vivier

announce_self that sends a RARP packet after migration or with announce_self QMP/HMP command doesn't work with vhost because of the vnet headers.

announce_self is the only user of QEMU_NET_PACKET_FLAG_RAW and this flag is not correctly managed.

This series fix a problem with this flag in filter-dump and in qemu_deliver_packet_iov().

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Laurent Vivier (2):
   net: Fix announce_self
   net/dump: Correctly compute Ethernet packet offset

Is this one - "Correctly compute Ethernet packet offset" - needed for older stable series too, like 8.2 and 7.2 (currently active ones)?

Since it doesn't apply without 4b52d63249 (tap: Remove qemu_using_vnet_hdr()).

It fixes 481c52320a26 ("net: Strip virtio-net header when dumping") that is only in 8.0.
But I'm not sure the bug exists without 4b52d63249 (tap: Remove qemu_using_vnet_hdr()), so it should be tested first.

Thanks,
Laurent

Reviewed-by on the v1 series Applied
#10 lore raw
In reply to Laurent Vivier
Quoted 10 lines · Laurent Vivier

announce_self that sends a RARP packet after migration or with announce_self QMP/HMP command doesn't work with vhost because of the vnet headers.

announce_self is the only user of QEMU_NET_PACKET_FLAG_RAW and this flag is not correctly managed.

This series fix a problem with this flag in filter-dump and in qemu_deliver_packet_iov().

Quoted 7 lines

Laurent Vivier (2):
net: Fix announce_self
net/dump: Correctly compute Ethernet packet offset

  net/dump.c | 3 ++-
  net/net.c  | 1 +
  2 files changed, 3 insertions(+), 1 deletion(-)

Applied to trivial-patches and queued for qemu-stable.

Thanks,

/mjt

#11 lore raw
Quoted 15 lines · Michael Tokarev
Quoted 14 lines · Laurent Vivier

announce_self that sends a RARP packet after migration or with announce_self QMP/HMP command doesn't work with vhost because of the vnet headers.

announce_self is the only user of QEMU_NET_PACKET_FLAG_RAW and this flag is not correctly managed.

This series fix a problem with this flag in filter-dump and in qemu_deliver_packet_iov().

Laurent Vivier (2):
   net: Fix announce_self
   net/dump: Correctly compute Ethernet packet offset

Quoted 8 lines
Quoted 3 lines

  net/dump.c | 3 ++-
  net/net.c  | 1 +

  2 files changed, 3 insertions(+), 1 deletion(-)

Applied to trivial-patches and queued for qemu-stable.

When do you plan to send the PR for them?

Thanks,
Laurent

#12 lore raw
Quoted 1 line · Laurent Vivier

When do you plan to send the PR for them?

Um, sorry for the delay. Will do ASAP.

Thank you for the reminder!

/mjt