Skip to contentSkip to conversation

vmxnet3: Pad short frames to minimum size (60 bytes)

PATCH In review Ben Draper 4 participants 7 messages Aug 20, 2014 – Aug 25, 2014

lore
Share & tools
lore

Ben Draper

author
#0 lore raw

PATCH 1/1 vmxnet3: Pad short frames to minimum size (60 bytes)

When running VMware ESXi under qemu-kvm the guest discards frames that are too short. Short ARP Requests will be dropped, this prevents guests on the same bridge as VMware ESXi from communicating. This patch simply adds the padding on the network device itself.

---
 hw/net/vmxnet3.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
hw/net/vmxnet3.c +10 -0
index 791321f..f246fa1 100644
@@ -34,6 +34,7 @@
 
 #define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1
 #define VMXNET3_MSIX_BAR_SIZE 0x2000
+#define MIN_BUF_SIZE 60
 
 #define VMXNET3_BAR0_IDX      (0)
 #define VMXNET3_BAR1_IDX      (1)
@@ -1871,12 +1872,21 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size)
 {
     VMXNET3State *s = qemu_get_nic_opaque(nc);
     size_t bytes_indicated;
+    uint8_t min_buf[MIN_BUF_SIZE];
 
     if (!vmxnet3_can_receive(nc)) {
         VMW_PKPRN("Cannot receive now");
         return -1;
     }
 
+    /* Pad to minimum Ethernet frame length */
+    if (size < sizeof(min_buf)) {
+        memcpy(min_buf, buf, size);
+        memset(&min_buf[size], 0, sizeof(min_buf) - size);
+        buf = min_buf;
+        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);
Signature · 1 line
1.7.10.4
author
#1 lore raw

Interestingly this does not appear to affect Windows guests on the same host/bridge as the ESXi guest, as
Windows pads the frames before sending them out. However it does affect Linux guests on the same host/bridge
from communicating with the ESXi guest itself and the guests ESXi hosts.

--

*View My LinkedIn Profile*

http://uk.linkedin.com/in/bendraper00

Quoted 49 lines · Ben Draper

When running VMware ESXi under qemu-kvm the guest discards frames that are too short. Short ARP Requests will be dropped, this prevents guests on the same bridge as VMware ESXi from communicating. This patch simply adds the padding on the network device itself.

---
 hw/net/vmxnet3.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
hw/net/vmxnet3.c +10 -0
index 791321f..f246fa1 100644
@@ -34,6 +34,7 @@
 
 #define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1
 #define VMXNET3_MSIX_BAR_SIZE 0x2000
+#define MIN_BUF_SIZE 60
 
 #define VMXNET3_BAR0_IDX      (0)
 #define VMXNET3_BAR1_IDX      (1)
@@ -1871,12 +1872,21 @@ vmxnet3_receive(NetClientState *nc, const uint8_t
 *buf, size_t size)
 {
     VMXNET3State *s = qemu_get_nic_opaque(nc);
     size_t bytes_indicated;
+    uint8_t min_buf[MIN_BUF_SIZE];
 
     if (!vmxnet3_can_receive(nc)) {
         VMW_PKPRN("Cannot receive now");
         return -1;
     }
 
+    /* Pad to minimum Ethernet frame length */
+    if (size < sizeof(min_buf)) {
+        memcpy(min_buf, buf, size);
+        memset(&min_buf[size], 0, sizeof(min_buf) - size);
+        buf = min_buf;
+        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);

--
1.7.10.4

#2 lore raw
In reply to Ben Draper
Quoted 4 lines · Ben Draper

When running VMware ESXi under qemu-kvm the guest discards frames that are too short. Short ARP Requests will be dropped, this prevents guests on the same bridge as VMware ESXi from communicating. This patch simply adds the padding on the network device itself.

I'm not sure it is "trivial enough", so to say. Do we have a maintainer for vmxnet? It's been written and updated several times by vmware (Daynix) people, maybe they can comment on this somehow? I mean, if we don't have a maintainer for this device, it is okay to go to -trivial, but maybe it's a good idea to try to reach the author(s) first? (Adding Cc).

Especially since this change is only required in certain cases, not generally.

Thanks,

/mjt

Quoted 40 lines
---
 hw/net/vmxnet3.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
hw/net/vmxnet3.c +10 -0
index 791321f..f246fa1 100644
@@ -34,6 +34,7 @@
 
 #define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1
 #define VMXNET3_MSIX_BAR_SIZE 0x2000
+#define MIN_BUF_SIZE 60
 
 #define VMXNET3_BAR0_IDX      (0)
 #define VMXNET3_BAR1_IDX      (1)
@@ -1871,12 +1872,21 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size)
 {
     VMXNET3State *s = qemu_get_nic_opaque(nc);
     size_t bytes_indicated;
+    uint8_t min_buf[MIN_BUF_SIZE];
 
     if (!vmxnet3_can_receive(nc)) {
         VMW_PKPRN("Cannot receive now");
         return -1;
     }
 
+    /* Pad to minimum Ethernet frame length */
+    if (size < sizeof(min_buf)) {
+        memcpy(min_buf, buf, size);
+        memset(&min_buf[size], 0, sizeof(min_buf) - size);
+        buf = min_buf;
+        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);
Reviewed-by
#3 lore raw
Quoted 6 lines · Michael Tokarev
Quoted 4 lines · Ben Draper

When running VMware ESXi under qemu-kvm the guest discards frames that are too short. Short ARP Requests will be dropped, this prevents guests on the same bridge as VMware ESXi from communicating. This patch simply adds the padding on the network device itself.

Quoted 8 lines

I'm not sure it is "trivial enough", so to say. Do we have a maintainer for vmxnet? It's been written and updated several times by vmware (Daynix) people, maybe they can comment on this somehow? I mean, if we don't have a maintainer for this device, it is okay to go to -trivial, but maybe it's a good idea to try to reach the author(s) first? (Adding Cc).

Especially since this change is only required in certain cases, not generally.

Hi Michael,

I’m the maintainer of vmxnet3/pvscsi devices in QEMU. Thanks for CC’ing me.

I think this patch is correct and needed.

As we saw a few times already on different operating systems, vmware drivers expect short packets to be padded as required by corresponding RFC. Therefore this patch fixes a real bug.

Quoted 46 lines

Thanks,

/mjt

Quoted 40 lines

---
hw/net/vmxnet3.c | 10 ++++++++++

1 file changed, 10 insertions(+)
hw/net/vmxnet3.c +10 -0
index 791321f..f246fa1 100644
@@ -34,6 +34,7 @@
 
 #define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1
 #define VMXNET3_MSIX_BAR_SIZE 0x2000
+#define MIN_BUF_SIZE 60
 
 #define VMXNET3_BAR0_IDX      (0)
 #define VMXNET3_BAR1_IDX      (1)
@@ -1871,12 +1872,21 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size)
 {
    VMXNET3State *s = qemu_get_nic_opaque(nc);
    size_t bytes_indicated;
+    uint8_t min_buf[MIN_BUF_SIZE];
 
    if (!vmxnet3_can_receive(nc)) {
        VMW_PKPRN("Cannot receive now");
        return -1;
    }
 
+    /* Pad to minimum Ethernet frame length */
+    if (size < sizeof(min_buf)) {
+        memcpy(min_buf, buf, size);
+        memset(&min_buf[size], 0, sizeof(min_buf) - size);
+        buf = min_buf;
+        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);
#4 lore raw
Quoted 3 lines · Dmitry Fleytman

Hi Michael,

I’m the maintainer of vmxnet3/pvscsi devices in QEMU. Thanks for CC’ing me.

Maybe you can add yourself to MAINTAINERS file as well? :) I dunno if that's actually needed, but at least this should stop "strain" patches like this to be sent to -trivial alone... ;)

Quoted 5 lines

I think this patch is correct and needed.

As we saw a few times already on different operating systems, vmware drivers expect short packets to be padded as required by corresponding RFC. Therefore this patch fixes a real bug.

Okay, since there's no entry for vmxnet in MAINTAINERS, and with your blessing, and since this is a rather specific device which is not in common use, I'll apply it to -trivial, for now, unless you want to pick it up and send a pull request for it.

Given your description, I think it should be Cc: qemu-stable@.

Quoted 1 line

Thanks,

/mjt

#5 lore raw
Quoted 7 lines · Michael Tokarev
Quoted 3 lines · Dmitry Fleytman

Hi Michael,

I’m the maintainer of vmxnet3/pvscsi devices in QEMU. Thanks for CC’ing me.

Maybe you can add yourself to MAINTAINERS file as well? :)

Yes, this should be done.
How we do this? Should I send a patch for MAINTAINETRS?

Quoted 5 lines

I dunno if that's actually needed, but at least this should stop "strain" patches like this to be sent to -trivial alone... ;)

Quoted 2 lines

I think this patch is correct and needed.

Quoted 8 lines
Quoted 3 lines

As we saw a few times already on different operating systems, vmware drivers expect short packets to be padded as required by corresponding RFC. Therefore this patch fixes a real bug.

Okay, since there's no entry for vmxnet in MAINTAINERS, and with your blessing, and since this is a rather specific device which is not in common use, I'll apply it to -trivial, for now, unless you want to pick it up and send a pull request for it.

-trivial is good enough for this patch.

Quoted 8 lines

Given your description, I think it should be Cc: qemu-stable@.

Quoted 1 line

Thanks,

/mjt

#6 lore raw
Quoted 4 lines · Dmitry Fleytman
Quoted 2 lines · Michael Tokarev

24.08.2014 16:28, Dmitry Fleytman wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Hi Michael,

I’m the maintainer of vmxnet3/pvscsi devices in QEMU. Thanks for CC’ing me.

Maybe you can add yourself to MAINTAINERS file as well? :)

Yes, this should be done.
How we do this? Should I send a patch for MAINTAINETRS?

Yes.