From patchwork Mon Oct 26 01:41:51 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rusty Russell X-Patchwork-Id: 55802 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9Q1rQlW024866 for ; Mon, 26 Oct 2009 01:53:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754219AbZJZBlu (ORCPT ); Sun, 25 Oct 2009 21:41:50 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751815AbZJZBlu (ORCPT ); Sun, 25 Oct 2009 21:41:50 -0400 Received: from ozlabs.org ([203.10.76.45]:46203 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752559AbZJZBlt (ORCPT ); Sun, 25 Oct 2009 21:41:49 -0400 Received: from vivaldi.localnet (unknown [150.101.102.135]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPSA id 971EFB7BDD; Mon, 26 Oct 2009 12:41:53 +1100 (EST) From: Rusty Russell To: "Michael S. Tsirkin" Subject: Re: [PATCH] virtio-net: fix data corruption with OOM Date: Mon, 26 Oct 2009 12:11:51 +1030 User-Agent: KMail/1.11.2 (Linux/2.6.28-16-generic; KDE/4.2.2; i686; ; ) Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, netdev@vger.kernel.org References: <20091025170340.GA22099@redhat.com> In-Reply-To: <20091025170340.GA22099@redhat.com> MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200910261211.52148.rusty@rustcorp.com.au> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -516,8 +516,7 @@ again: /* Free up any pending old buffers before queueing new ones. */ free_old_xmit_skbs(vi); - /* Put new one in send queue and do transmit */ - __skb_queue_head(&vi->send, skb); + /* Try to transmit */ capacity = xmit_skb(vi, skb); /* This can happen with OOM and indirect buffers. */ @@ -531,8 +530,17 @@ again: } return NETDEV_TX_BUSY; } + vi->svq->vq_ops->kick(vi->svq); - vi->svq->vq_ops->kick(vi->svq); + /* + * Put new one in send queue. You'd expect we'd need this before + * xmit_skb calls add_buf(), since the callback can be triggered + * immediately after that. But since the callback just triggers + * another call back here, normal network xmit locking prevents the + * race. + */ + __skb_queue_head(&vi->send, skb); + /* Don't wait up for transmitted skbs to be freed. */ skb_orphan(skb); nf_reset(skb);