From patchwork Mon Dec 5 09:52:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 702662 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tXKt7578Fz9srZ for ; Mon, 5 Dec 2016 20:57:03 +1100 (AEDT) Received: from localhost ([::1]:38757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cDq16-00051l-P1 for incoming@patchwork.ozlabs.org; Mon, 05 Dec 2016 04:57:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cDpwZ-0001KE-Fh for qemu-devel@nongnu.org; Mon, 05 Dec 2016 04:52:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cDpwU-0006zm-Au for qemu-devel@nongnu.org; Mon, 05 Dec 2016 04:52:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cDpwU-0006zV-5r for qemu-devel@nongnu.org; Mon, 05 Dec 2016 04:52:14 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37270C04B928; Mon, 5 Dec 2016 09:52:13 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-10.pek2.redhat.com [10.72.5.10]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB59q4KP022596; Mon, 5 Dec 2016 04:52:10 -0500 From: Jason Wang To: peter.maydell@linaro.org, stefanha@redhat.com, qemu-devel@nongnu.org Date: Mon, 5 Dec 2016 17:52:02 +0800 Message-Id: <1480931523-5769-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1480931523-5769-1-git-send-email-jasowang@redhat.com> References: <1480931523-5769-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 05 Dec 2016 09:52:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/3] fsl_etsec: Pad short payloads with zeros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrey Smirnov , Jason Wang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Andrey Smirnov 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 Signed-off-by: Jason Wang --- 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__,