From patchwork Mon Jun 7 14:24:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 54856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id ECF71B7D1C for ; Tue, 8 Jun 2010 00:30:08 +1000 (EST) Received: from localhost ([127.0.0.1]:45878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLdL2-00011z-GK for incoming@patchwork.ozlabs.org; Mon, 07 Jun 2010 10:30:04 -0400 Received: from [140.186.70.92] (port=49836 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLdJh-0000b6-LA for qemu-devel@nongnu.org; Mon, 07 Jun 2010 10:28:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLdJc-0002Ao-Nu for qemu-devel@nongnu.org; Mon, 07 Jun 2010 10:28:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58295) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLdJc-0002AV-HJ for qemu-devel@nongnu.org; Mon, 07 Jun 2010 10:28:36 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o57ESZlQ017912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Jun 2010 10:28:35 -0400 Received: from redhat.com (vpn-6-161.tlv.redhat.com [10.35.6.161]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o57ESXAZ025652 for ; Mon, 7 Jun 2010 10:28:34 -0400 Date: Mon, 7 Jun 2010 17:24:01 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20100607142401.GA11644@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCHv3] virtio-net: truncating packet X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org virtio net attempts to peek into virtio queue to determine that we have enough space for the complete packet to fit. However, it fails to account for space consumed by virtio net header when it does this, under stress this results in a failure with the message 'truncating packet'. redhat bz 591494. Signed-off-by: Michael S. Tsirkin v2 was sent in error. Now fixed whitespace for real. --- hw/virtio-net.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 6a9d560..06ba481 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -532,16 +532,17 @@ static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_ if (!virtio_net_can_receive(&n->nic->nc)) return -1; - if (!virtio_net_has_buffers(n, size)) + /* hdr_len refers to the header we supply to the guest */ + hdr_len = n->mergeable_rx_bufs ? + sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr); + + + if (!virtio_net_has_buffers(n, size + hdr_len)) return 0; if (!receive_filter(n, buf, size)) return size; - /* hdr_len refers to the header we supply to the guest */ - hdr_len = n->mergeable_rx_bufs ? - sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr); - offset = i = 0; while (offset < size) { @@ -555,7 +556,9 @@ static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_ virtqueue_pop(n->rx_vq, &elem) == 0) { if (i == 0) return -1; - fprintf(stderr, "virtio-net truncating packet\n"); + fprintf(stderr, "virtio-net truncating packet: " + "offset %zd, size %zd, hdr_len %zd\n", + offset, size, hdr_len); exit(1); }