From patchwork Tue Aug 28 06:23:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Yang X-Patchwork-Id: 180335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 788052C008B for ; Tue, 28 Aug 2012 16:23:18 +1000 (EST) Received: from localhost ([::1]:43935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6FCm-0000Qq-Ge for incoming@patchwork.ozlabs.org; Tue, 28 Aug 2012 02:23:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6FCU-0000OU-Os for qemu-devel@nongnu.org; Tue, 28 Aug 2012 02:23:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T6FCN-0006bJ-Dc for qemu-devel@nongnu.org; Tue, 28 Aug 2012 02:22:58 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:52599) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6FCN-0006am-7G for qemu-devel@nongnu.org; Tue, 28 Aug 2012 02:22:51 -0400 Received: by wibhm2 with SMTP id hm2so2969954wib.10 for ; Mon, 27 Aug 2012 23:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer; bh=GHtdp2+S4tcegVY1BmuzfuMm5O2WS+SfsrgqUkA4fxg=; b=X2JuDdOO1k3piwwjy4pYhSPDdSzOdFBhjF+Q4NjJ+bKGAAeHKfGjo0rT4jNcSlTuyx Y8XgzB4KdnbQG+WOfnaZtsuYvo55YIGeruCeWu4rxIEAHsCu8XIAmIYk6veb7sTzvqgD Wrafr3HS8gDfLgcQ67yvVwNF2WmNVlye4EC2HfpvAWeMYPrb/81H7MPxFo6wOJ2plNUH TKoHfLYh81WZv19bkpvGww5VFnV0w+mwbqrT7eumD8linB72YFb4In2uMaW37G4okJR4 K9OyUxnX+gsam82+vnOFwmdytaqbpI4oRIdfLEMYvreBWq9D+HcdghkqoJ0bLzb8D8nm +rPA== Received: by 10.216.232.84 with SMTP id m62mr7796083weq.200.1346134970138; Mon, 27 Aug 2012 23:22:50 -0700 (PDT) Received: from localhost.localdomain ([222.126.194.154]) by mx.google.com with ESMTPS id n15sm3264855wie.7.2012.08.27.23.22.47 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 27 Aug 2012 23:22:49 -0700 (PDT) From: Bo Yang To: qemu-devel@nongnu.org Date: Tue, 28 Aug 2012 14:23:37 +0800 Message-Id: <1346135017-5975-1-git-send-email-boyang@suse.com> X-Mailer: git-send-email 1.6.0.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.181 Subject: [Qemu-devel] [PATCH] Fix buffer run out in eepro100. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The guest may enter into state of no receive descriptors, and if there is no interrupt, the descriptor filling function has no chance to run again,which causes network stall. According to liunux driver's implementation, the descriptor with EL bit set must not be touched by hardware, usually, the buffer size of this descriptor is set to 0. Signed-off-by: Bo Yang --- hw/eepro100.c | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-) diff --git a/hw/eepro100.c b/hw/eepro100.c index 50d117e..e0efd96 100644 --- a/hw/eepro100.c +++ b/hw/eepro100.c @@ -1619,8 +1619,13 @@ static const MemoryRegionOps eepro100_ops = { static int nic_can_receive(NetClientState *nc) { EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque; + ru_state_t state; TRACE(RXTX, logout("%p\n", s)); - return get_ru_state(s) == ru_ready; + state = get_ru_state(s); + if (state == ru_no_resources) { + eepro100_rnr_interrupt(s); + } + return state == ru_ready; #if 0 return !eepro100_buffer_full(s); #endif @@ -1732,6 +1737,15 @@ static ssize_t nic_receive(NetClientState *nc, const uint8_t * buf, size_t size) &rx, sizeof(eepro100_rx_t)); uint16_t rfd_command = le16_to_cpu(rx.command); uint16_t rfd_size = le16_to_cpu(rx.size); + /* don't touch the rx descriptor with EL set. */ + if (rfd_command & COMMAND_EL) { + /* EL bit is set, so this was the last frame. */ + logout("receive: Running out of frames\n"); + set_ru_state(s, ru_no_resources); + s->statistics.rx_resource_errors++; + eepro100_rnr_interrupt(s); + return -1; + } if (size > rfd_size) { logout("Receive buffer (%" PRId16 " bytes) too small for data " @@ -1767,11 +1781,6 @@ static ssize_t nic_receive(NetClientState *nc, const uint8_t * buf, size_t size) s->statistics.rx_good_frames++; eepro100_fr_interrupt(s); s->ru_offset = le32_to_cpu(rx.link); - if (rfd_command & COMMAND_EL) { - /* EL bit is set, so this was the last frame. */ - logout("receive: Running out of frames\n"); - set_ru_state(s, ru_suspended); - } if (rfd_command & COMMAND_S) { /* S bit is set. */ set_ru_state(s, ru_suspended);