vmxnet3, vnet_hdr, and minimum length padding
When running ESXi under qemu there is an issue with the ESXi guest
discarding packets that are too short. The guest discards any packets under the normal minimum length for an ethernet packet (60). This results in odd behaviour where other hosts or VMs on other hosts can communicate with the ESXi guest just fine (since there's a physical NIC somewhere doing padding), but VMs on the host and the host itself cannot because the ARP request packets are too small for the ESXi host to accept.
Someone in the past thought this was worth fixing, and added code
to the vmxnet3 qemu emulation such that if it is receiving packets smaller than 60 bytes to pad the packet out to 60. Unfortunately this code is wrong (or at least in the wrong place). It does so BEFORE before taking into account the vnet_hdr at the front of the packet added by the tap device. As a result, it might add padding, but it never adds enough. Specifically it adds 10 less (the length of the vnet_hdr) than it needs to.
The following (hopefully "obviously correct") patch simply swaps
the order of processing the vnet header and the padding. With this patch an ESXi guest is able to communicate with the host or other local VMs.
qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 renamed from qemu-2.3.0/hw/net/vmxnet3.c 2015-04-27 10:08:24.000000000 -0400 +6 -6
@@ -1879,6 +1879,12 @@ return -1; } + if (s->peer_has_vhdr) { + vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); + buf += sizeof(struct virtio_net_hdr); + size -= sizeof(struct virtio_net_hdr); + } + /* Pad to minimum Ethernet frame length */ if (size < sizeof(min_buf)) { memcpy(min_buf, buf, size);
@@ -1887,12 +1893,6 @@ size = sizeof(min_buf); } - if (s->peer_has_vhdr) { - vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); - buf += sizeof(struct virtio_net_hdr); - size -= sizeof(struct virtio_net_hdr); - } - vmxnet_rx_pkt_set_packet_type(s->rx_pkt, get_eth_packet_type(PKT_GET_ETH_HDR(buf)));
On Tue, Jun 23, 2015 at 11:49:25AM -0400, Brian Kress wrote:
Thanks for sending a patch!
I have CCed the vmxnet3 maintainer and Jason Wang, who looks at net subsystem patches:
$ scripts/get_maintainer.pl -f hw/net/vmxnet3.c Dmitry Fleytman <[email protected]> (maintainer:Vmware)
Quoted 9 lines
When running ESXi under qemu there is an issue with the ESXi guest
discarding packets that are too short. The guest discards any packets under the normal minimum length for an ethernet packet (60). This results in odd behaviour where other hosts or VMs on other hosts can communicate with the ESXi guest just fine (since there's a physical NIC somewhere doing padding), but VMs on the host and the host itself cannot because the ARP request packets are too small for the ESXi host to accept.
Someone in the past thought this was worth fixing, and added code to the
vmxnet3 qemu emulation such that if it is receiving packets smaller than 60
Quoted 10 lines
bytes to pad the packet out to 60. Unfortunately this code is wrong (or at least in the wrong place). It does so BEFORE before taking into account the
vnet_hdrat the front of the packet added by the tap device. As a result,
it might add padding, but it never adds enough. Specifically it adds 10 less (the length of thevnet_hdr) than it needs to.
The following (hopefully "obviously correct") patch simply swaps the
order of processing the vnet header and the padding. With this patch an ESXi guest is able to communicate with the host or other local VMs.
Please add your Signed-off-by. Details about Signed-off-by are on the
http://qemu-project.org/Contribute/SubmitAPatch page.
Quoted 32 lines
qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 renamed from qemu-2.3.0/hw/net/vmxnet3.c 2015-04-27 10:08:24.000000000 -0400 +6
-6@@ -1879,6 +1879,12 @@ return -1; } + if (s->peer_has_vhdr) { + vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); + buf += sizeof(struct virtio_net_hdr); + size -= sizeof(struct virtio_net_hdr); + } + /* Pad to minimum Ethernet frame length */ if (size < sizeof(min_buf)) { memcpy(min_buf, buf, size);@@ -1887,12 +1893,6 @@ size = sizeof(min_buf); } - if (s->peer_has_vhdr) { - vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); - buf += sizeof(struct virtio_net_hdr); - size -= sizeof(struct virtio_net_hdr); - } - vmxnet_rx_pkt_set_packet_type(s->rx_pkt, get_eth_packet_type(PKT_GET_ETH_HDR(buf)));
Resending by request with Signed-off-by:
When running ESXi under qemu there is an issue with the ESXi guest
discarding packets that are too short. The guest discards any packets under the normal minimum length for an ethernet packet (60). This results in odd behaviour where other hosts or VMs on other hosts can communicate with the ESXi guest just fine (since there's a physical NIC somewhere doing padding), but VMs on the host and the host itself cannot because the ARP request packets are too small for the ESXi host to accept.
Someone in the past thought this was worth fixing, and added code
to the vmxnet3 qemu emulation such that if it is receiving packets smaller than 60 bytes to pad the packet out to 60. Unfortunately this code is wrong (or at least in the wrong place). It does so BEFORE before taking into account the vnet_hdr at the front of the packet added by the tap device. As a result, it might add padding, but it never adds enough. Specifically it adds 10 less (the length of the vnet_hdr) than it needs to.
The following (hopefully "obviously correct") patch simply swaps
the order of processing the vnet header and the padding. With this patch an ESXi guest is able to communicate with the host or other local VMs.
qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 renamed from qemu-2.3.0/hw/net/vmxnet3.c 2015-04-27 10:08:24.000000000 -0400 +6 -6
@@ -1879,6 +1879,12 @@ return -1; } + if (s->peer_has_vhdr) { + vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); + buf += sizeof(struct virtio_net_hdr); + size -= sizeof(struct virtio_net_hdr); + } + /* Pad to minimum Ethernet frame length */ if (size < sizeof(min_buf)) { memcpy(min_buf, buf, size);
@@ -1887,12 +1893,6 @@ size = sizeof(min_buf); } - if (s->peer_has_vhdr) { - vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); - buf += sizeof(struct virtio_net_hdr); - size -= sizeof(struct virtio_net_hdr); - } - vmxnet_rx_pkt_set_packet_type(s->rx_pkt, get_eth_packet_type(PKT_GET_ETH_HDR(buf)));
Paolo Bonzini
Reviewed-byQuoted 12 lines · Brian Kress
Resending by request with Signed-off-by:
When running ESXi under qemu there is an issue with the ESXi guest
discarding packets that are too short. The guest discards any packets under the normal minimum length for an ethernet packet (60). This results in odd behaviour where other hosts or VMs on other hosts can communicate with the ESXi guest just fine (since there's a physical NIC somewhere doing padding), but VMs on the host and the host itself cannot because the ARP request packets are too small for the ESXi host to accept.
Someone in the past thought this was worth fixing, and added code to
the vmxnet3 qemu emulation such that if it is receiving packets smaller
Quoted 8 lines
than 60 bytes to pad the packet out to 60. Unfortunately this code is wrong (or at least in the wrong place). It does so BEFORE before taking into account the
vnet_hdrat the front of the packet added by the tap
device. As a result, it might add padding, but it never adds enough.
Specifically it adds 10 less (the length of thevnet_hdr) than it needs to.
The following (hopefully "obviously correct") patch simply swaps the
order of processing the vnet header and the padding. With this patch an ESXi guest is able to communicate with the host or other local VMs.
This is not the correct format for a patch:
- the subject should start with [PATCH]
- the subject should describe what the patch does
- the lines of the body of the commit message should be ~72 characters long at most
- the patch should apply with "patch -p1" (your patch requires "-p2").
For more information, see http://wiki.qemu.org/Contribute/SubmitAPatch.
It's up to the maintainer whether to fix the above; the code however is fine so:
Thanks,
Paolo
Quoted 33 lines
Signed-off-by Brian Kress <[email protected]>qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 renamed from qemu-2.3.0/hw/net/vmxnet3.c 2015-04-27 10:08:24.000000000 -0400 +6
-6@@ -1879,6 +1879,12 @@ return -1; } + if (s->peer_has_vhdr) { + vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); + buf += sizeof(struct virtio_net_hdr); + size -= sizeof(struct virtio_net_hdr); + } + /* Pad to minimum Ethernet frame length */ if (size < sizeof(min_buf)) { memcpy(min_buf, buf, size);@@ -1887,12 +1893,6 @@ size = sizeof(min_buf); } - if (s->peer_has_vhdr) { - vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); - buf += sizeof(struct virtio_net_hdr); - size -= sizeof(struct virtio_net_hdr); - } - vmxnet_rx_pkt_set_packet_type(s->rx_pkt, get_eth_packet_type(PKT_GET_ETH_HDR(buf)));
Dmitry Fleytman
Reviewed-byQuoted 24 lines · Brian Kress
When running ESXi under qemu there is an issue with the ESXi guest discarding packets that are too short. The guest discards any packets under the normal minimum length for an ethernet packet (60). This results in odd behaviour where other hosts or VMs on other hosts can communicate with the ESXi guest just fine (since there's a physical NIC somewhere doing padding), but VMs on the host and the host itself cannot because the ARP request packets are too small for the ESXi host to accept.
Someone in the past thought this was worth fixing, and added code to the vmxnet3 qemu emulation such that if it is receiving packets smaller than 60 bytes to pad the packet out to 60. Unfortunately this code is wrong (or at least in the wrong place). It does so BEFORE before taking into account thevnet_hdrat the front of the packet added by the tap device. As a result, it might add padding, but it never adds enough. Specifically it adds 10 less (the length of thevnet_hdr) than it needs to.
The following (hopefully "obviously correct") patch simply swaps the order of processing the vnet header and the padding. With this patch an ESXi guest is able to communicate with the host or other local VMs.qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 renamed from qemu-2.3.0/hw/net/vmxnet3.c 2015-04-27 10:08:24.000000000 -0400 +6
-0@@ -1879,6 +1879,12 @@ return -1; } + if (s->peer_has_vhdr) { + vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); + buf += sizeof(struct virtio_net_hdr); + size -= sizeof(struct virtio_net_hdr); + } + /* Pad to minimum Ethernet frame length */ if (size < sizeof(min_buf)) { memcpy(min_buf, buf, size);
qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 line 1895
Quoted 9 lines
qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 renamed from qemu-2.3.0/hw/net/vmxnet3.c 2015-04-27 10:08:24.000000000 -0400 +0
-6@@ -1887,12 +1893,6 @@ size = sizeof(min_buf); } - if (s->peer_has_vhdr) { - vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); - buf += sizeof(struct virtio_net_hdr); - size -= sizeof(struct virtio_net_hdr); - } -
The code is fine, thanks!
Please fix the patch according to Paolo comments.
Regards,
Dmitry.
Quoted 7 lines
qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 renamed from qemu-2.3.0/hw/net/vmxnet3.c 2015-04-27 10:08:24.000000000 -0400 +0
-0vmxnet_rx_pkt_set_packet_type(s->rx_pkt, get_eth_packet_type(PKT_GET_ETH_HDR(buf)));
Stefan Hajnoczi
AppliedQuoted 36 lines · Brian Kress
When running ESXi under qemu there is an issue with the ESXi guest
discarding packets that are too short. The guest discards any packets under the normal minimum length for an ethernet packet (60). This results in odd behaviour where other hosts or VMs on other hosts can communicate with the ESXi guest just fine (since there's a physical NIC somewhere doing padding), but VMs on the host and the host itself cannot because the ARP request packets are too small for the ESXi host to accept.
Someone in the past thought this was worth fixing, and added code to the
vmxnet3 qemu emulation such that if it is receiving packets smaller than 60 bytes to pad the packet out to 60. Unfortunately this code is wrong (or at least in the wrong place). It does so BEFORE before taking into account thevnet_hdrat the front of the packet added by the tap device. As a result,
it might add padding, but it never adds enough. Specifically it adds 10 less (the length of thevnet_hdr) than it needs to.
The following (hopefully "obviously correct") patch simply swaps the
order of processing the vnet header and the padding. With this patch an ESXi guest is able to communicate with the host or other local VMs.qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 renamed from qemu-2.3.0/hw/net/vmxnet3.c 2015-04-27 10:08:24.000000000 -0400 +6
-0@@ -1879,6 +1879,12 @@ return -1; } + if (s->peer_has_vhdr) { + vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); + buf += sizeof(struct virtio_net_hdr); + size -= sizeof(struct virtio_net_hdr); + } + /* Pad to minimum Ethernet frame length */ if (size < sizeof(min_buf)) { memcpy(min_buf, buf, size);@@ -1887,12 +1893,6 @@ size = sizeof(min_buf);
qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 line 1897
Quoted 10 lines
qemu-2.3.0/hw/net/vmxnet3.c 2015-06-23 11:38:48.865728713 -0400 renamed from qemu-2.3.0/hw/net/vmxnet3.c 2015-04-27 10:08:24.000000000 -0400 +0
-6} - if (s->peer_has_vhdr) { - vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); - buf += sizeof(struct virtio_net_hdr); - size -= sizeof(struct virtio_net_hdr); - } - vmxnet_rx_pkt_set_packet_type(s->rx_pkt, get_eth_packet_type(PKT_GET_ETH_HDR(buf)));
Thanks, applied to my net tree:
https://github.com/stefanha/qemu/commits/net
Stefan