From patchwork Mon Feb 8 16:10:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 77785 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o18GAOu9029038 for ; Mon, 8 Feb 2010 16:10:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753336Ab0BHQKW (ORCPT ); Mon, 8 Feb 2010 11:10:22 -0500 Received: from e31.co.us.ibm.com ([32.97.110.149]:55753 "EHLO e31.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752983Ab0BHQKW (ORCPT ); Mon, 8 Feb 2010 11:10:22 -0500 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e31.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o18G1rtb012129 for ; Mon, 8 Feb 2010 09:01:53 -0700 Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id o18GAB7u241400 for ; Mon, 8 Feb 2010 09:10:13 -0700 Received: from d03av05.boulder.ibm.com (loopback [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o18GA4Bm014827 for ; Mon, 8 Feb 2010 09:10:06 -0700 Received: from tomlt1.ibmoffice.com (toml.austin.ibm.com [9.53.41.61]) by d03av05.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o18GA45o014816; Mon, 8 Feb 2010 09:10:04 -0700 From: Tom Lendacky Organization: IBM Linux Performance To: kvm@vger.kernel.org Subject: Re: Network shutdown under load Date: Mon, 8 Feb 2010 10:10:01 -0600 User-Agent: KMail/1.12.4 (Linux/2.6.30.10-105.2.4.fc11.i686.PAE; KDE/4.3.4; i686; ; ) Cc: qemu-devel@nongnu.org, chrisw@redhat.com, avi@redhat.com, herbert@gondor.apana.org.au, rek2@binaryfreedom.info, markmc@redhat.com, aliguori@us.ibm.com References: <201001291406.41559.tahm@linux.vnet.ibm.com> In-Reply-To: <201001291406.41559.tahm@linux.vnet.ibm.com> MIME-Version: 1.0 Message-Id: <201002081010.03751.tahm@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 08 Feb 2010 16:10:24 +0000 (UTC) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 6e48997..5c0093e 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -379,7 +379,15 @@ static int virtio_net_has_buffers(VirtIONet *n, int bufsize) (n->mergeable_rx_bufs && !virtqueue_avail_bytes(n->rx_vq, bufsize, 0))) { virtio_queue_set_notification(n->rx_vq, 1); - return 0; + + /* To avoid a race condition where the guest has made some buffers + * available after the above check but before notification was + * enabled, check for available buffers again. + */ + if (virtio_queue_empty(n->rx_vq) || + (n->mergeable_rx_bufs && + !virtqueue_avail_bytes(n->rx_vq, bufsize, 0))) + return 0; } virtio_queue_set_notification(n->rx_vq, 0);