From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpYOt-0002JH-4A for qemu-devel@nongnu.org; Thu, 20 Jun 2013 02:31:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpYOr-0005yf-Tw for qemu-devel@nongnu.org; Thu, 20 Jun 2013 02:31:19 -0400 Received: from mail-la0-x233.google.com ([2a00:1450:4010:c03::233]:61750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpYOr-0005yb-NY for qemu-devel@nongnu.org; Thu, 20 Jun 2013 02:31:17 -0400 Received: by mail-la0-f51.google.com with SMTP id fq12so5283762lab.38 for ; Wed, 19 Jun 2013 23:31:16 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20130618125753.GL7649@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> From: liu ping fan Date: Thu, 20 Jun 2013 14:30:56 +0800 Message-ID: Content-Type: text/plain; charset=ISO-8859-1 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: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , mdroth 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. Thx & regards, Pingfan