From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpZbZ-0005EN-9P for qemu-devel@nongnu.org; Thu, 20 Jun 2013 03:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpZbW-0003rk-Ad for qemu-devel@nongnu.org; Thu, 20 Jun 2013 03:48:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpZbW-0003rg-2K for qemu-devel@nongnu.org; Thu, 20 Jun 2013 03:48:26 -0400 Date: Thu, 20 Jun 2013 09:48:20 +0200 From: Stefan Hajnoczi Message-ID: <20130620074820.GD15082@stefanha-thinkpad.redhat.com> References: <1371114186-8854-1-git-send-email-qemulist@gmail.com> <1371114186-8854-6-git-send-email-qemulist@gmail.com> <20130618125753.GL7649@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH v2 5/6] net: defer nested call to BH List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: liu ping fan Cc: Stefan Hajnoczi , qemu-devel@nongnu.org, mdroth On Thu, Jun 20, 2013 at 02:30:56PM +0800, liu ping fan wrote: > On Tue, Jun 18, 2013 at 8:57 PM, Stefan Hajnoczi wrote: > > On Thu, Jun 13, 2013 at 05:03:05PM +0800, Liu Ping Fan wrote: > >> From: Liu Ping Fan > >> > >> Nested call caused by ->receive() will raise issue like deadlock, > >> so postphone it to BH. > >> > >> Signed-off-by: Liu Ping Fan > >> --- > >> net/queue.c | 40 ++++++++++++++++++++++++++++++++++++++-- > >> 1 file changed, 38 insertions(+), 2 deletions(-) > > > > Does this patch belong before the netqueue lock patch? The commit > > history should be bisectable without temporary failures/deadlocks. > > > Ok. > >> diff --git a/net/queue.c b/net/queue.c > >> index 58222b0..9c343ab 100644 > >> --- a/net/queue.c > >> +++ b/net/queue.c > >> @@ -24,6 +24,8 @@ > >> #include "net/queue.h" > >> #include "qemu/queue.h" > >> #include "net/net.h" > >> +#include "block/aio.h" > >> +#include "qemu/main-loop.h" > >> > >> /* The delivery handler may only return zero if it will call > >> * qemu_net_queue_flush() when it determines that it is once again able > >> @@ -183,6 +185,22 @@ static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue, > >> return ret; > >> } > >> > >> +typedef struct NetQueBH { > > > > This file uses "Queue" consistently, please don't add "Que" here. > > > >> @@ -192,8 +210,17 @@ ssize_t qemu_net_queue_send(NetQueue *queue, > >> { > >> ssize_t ret; > >> > >> - if (queue->delivering || !qemu_can_send_packet_nolock(sender)) { > >> + if (queue->delivering || !qemu_can_send_packet_nolock(sender) > >> + || sender->send_queue->delivering) { > > > > Not sure this is safe, we're only holding one NetClientState->peer_lock > > and one NetQueue->lock. How can we access both queue->delivering and > > sender->send_queue->delivering safely? > > Yes, you are right, it is not safely. The queue->delivering is > protected by peer_lock and we do not take the verse direction lock . > So finally the above code can not tell out the nested calling > "A-->B-->A" from "A-->B, B-->A" (where A, B stands for a > NetClientState). > What about using TLS to trace the nested calling? With it, we can > avoid AB-BA lock problem. I would take a step back and see if there's a way to avoid reaching into inspect sender->send_queue->delivering here. Stefan