qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: peter.maydell@linaro.org, stefanha@redhat.com, qemu-devel@nongnu.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>,
	Jason Wang <jasowang@redhat.com>
Subject: [Qemu-devel] [PULL 2/3] fsl_etsec: Pad short payloads with zeros
Date: Mon,  5 Dec 2016 17:52:02 +0800	[thread overview]
Message-ID: <1480931523-5769-3-git-send-email-jasowang@redhat.com> (raw)
In-Reply-To: <1480931523-5769-1-git-send-email-jasowang@redhat.com>

From: Andrey Smirnov <andrew.smirnov@gmail.com>

Depending on QEMU network setup it is possible for us to receive a
complete Ethernet packet that is less 64 bytes long. One such example is
when QEMU is configured to use a standalone TAP device (not set to be a
part of any bridge) receives and ARP packet. In cases like that we need
to add more than just 4-bytes of CRC padding and ensure that our payload
is at least 60 bytes long, such that, when combined with CRC padding
bytes the resulting size is at least 802.3 minimum MTU bytes
long (64). Failing to do that results in code in etsec_walk_rx_ring()
setting BD_RX_SH which, in turn, makes corresponding Linux driver of
emulated host to reject buffer as a runt packet

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/net/fsl_etsec/rings.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/net/fsl_etsec/rings.c b/hw/net/fsl_etsec/rings.c
index 79d2f14..1434c91 100644
--- a/hw/net/fsl_etsec/rings.c
+++ b/hw/net/fsl_etsec/rings.c
@@ -474,6 +474,13 @@ static void rx_init_frame(eTSEC *etsec, const uint8_t *buf, size_t size)
     /* CRC padding (We don't have to compute the CRC) */
     etsec->rx_padding = 4;
 
+    /*
+     * Ensure that payload length + CRC length is at least 802.3
+     * minimum MTU size bytes long (64)
+     */
+    if (etsec->rx_buffer_len < 60)
+        etsec->rx_padding += 60 - etsec->rx_buffer_len;
+
     etsec->rx_first_in_frame = 1;
     etsec->rx_remaining_data = etsec->rx_buffer_len;
     RING_DEBUG("%s: rx_buffer_len:%u rx_padding+crc:%u\n", __func__,
-- 
2.7.4

  parent reply	other threads:[~2016-12-05  9:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-05  9:52 [Qemu-devel] [PULL 0/3] Net patches Jason Wang
2016-12-05  9:52 ` [Qemu-devel] [PULL 1/3] net: mcf: check receive buffer size register value Jason Wang
2016-12-05  9:52 ` Jason Wang [this message]
2016-12-05  9:52 ` [Qemu-devel] [PULL 3/3] fsl_etsec: Fix various small problems in hexdump code Jason Wang
2016-12-05 10:42 ` [Qemu-devel] [PULL 0/3] Net patches no-reply
2016-12-05 14:35 ` Stefan Hajnoczi
2016-12-06  2:32   ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480931523-5769-3-git-send-email-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).