Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp353051imm; Sat, 14 Jul 2018 02:06:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfZ52qSU2reWAhfAAKgxtUSRqvG4wDQwMTVXf/KGclmqnpZ/t65WTce7KZmq/7FxYmAyoxf X-Received: by 2002:a62:d34a:: with SMTP id q71-v6mr10356190pfg.17.1531559167293; Sat, 14 Jul 2018 02:06:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531559167; cv=none; d=google.com; s=arc-20160816; b=TWUACfunVUXZybXF4iAMose5mDdilkpvUJIVAogSxN1ZYBzESZ5PoIjtNqN6denN+4 6arMy+RQfjvtBuukEe5nrbSC0Mz/q9EHb5SaWzYV2EcnJLFs7i/Un4g7S8M2RXDQXaJ1 uti2CV3cY2UaY7I9dS/4y/DArPgt+l77nLCubkYyVU+7f1BE8HGhJv0dpiVvVazkNF9+ x8EcCvjEESevdDW502MI8XMSAfE4QbTGefZThMLnRCoNFQep7aPMQ7pEugOUcHcgCCPY PVLVPtTEbMV2qG7pJObtXokMl1eliCWDSUJhh4Y2/1z4/lcRXrG6k4XrRSr6Lxe8rG4Z u5/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=WYWYiBbOZts1NGlgKq4ir0Y3RGOqZwUQ8trTZPHF+Ig=; b=Q3ZblFvhOTmau7xjcqed4heApSpyxdZNpPKKZCgO7VN4k6WAs8/C7MLXUsp5vrfDco piMIDrLuAET9lJXXWZlFiDZHMt63OetJZRnOw03tmh971lgcZnzfkde6cD0VkHb0Kyp0 OhMY46iltvINidYE85OIqFA81LwWHWk4P9TDwbX1azN8FLXLJiuhwS78EKkapTpoBb70 hAN1H/olZbUuAbxD/gx1XhElAlN8F/ihUYWmlArCnxMfxr8Blmh3BGX90sybto4+9Cpa b3q4N0rWMXIGU3fnFt2UzsrIdZmp9xmSdBZPH+Hu8G37Q8hrIB3dsSgf2Cv0bmEi1bZm QRGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f28-v6si28443668pfh.33.2018.07.14.02.05.52; Sat, 14 Jul 2018 02:06:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727046AbeGNJXn (ORCPT + 99 others); Sat, 14 Jul 2018 05:23:43 -0400 Received: from nautica.notk.org ([91.121.71.147]:54448 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbeGNJXn (ORCPT ); Sat, 14 Jul 2018 05:23:43 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 1ACBCC009; Sat, 14 Jul 2018 11:05:17 +0200 (CEST) Date: Sat, 14 Jul 2018 11:05:02 +0200 From: Dominique Martinet To: jiangyiwen Cc: Andrew Morton , Eric Van Hensbergen , Ron Minnich , Latchesar Ionkov , Linux Kernel Mailing List , v9fs-developer@lists.sourceforge.net Subject: Re: [V9fs-developer] [PATCH] net/9p: Fix a deadlock case in the virtio transport Message-ID: <20180714090502.GA16186@nautica> References: <5B49B8CF.40709@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5B49B8CF.40709@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org jiangyiwen wrote on Sat, Jul 14, 2018: > When client has multiple threads that issue io requests all the > time, and the server has a very good performance, it may cause > cpu is running in the irq context for a long time because it can > check virtqueue has buf in the *while* loop. > > So we should keep chan->lock in the whole loop. Hmm, this is generally bad practice to hold a spin lock for long. In general, spin locks are meant to protect data, not code. I'd want some numbers to decide on this one, even if I think this particular case is safe (e.g. this cannot dead-lock) > Signed-off-by: Yiwen Jiang > --- > net/9p/trans_virtio.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c > index 05006cb..9b0f5f2 100644 > --- a/net/9p/trans_virtio.c > +++ b/net/9p/trans_virtio.c > @@ -148,20 +148,18 @@ static void req_done(struct virtqueue *vq) > > p9_debug(P9_DEBUG_TRANS, ": request done\n"); > > + spin_lock_irqsave(&chan->lock, flags); > while (1) { > - spin_lock_irqsave(&chan->lock, flags); > req = virtqueue_get_buf(chan->vq, &len); > - if (req == NULL) { > - spin_unlock_irqrestore(&chan->lock, flags); > + if (req == NULL) > break; > - } > chan->ring_bufs_avail = 1; > - spin_unlock_irqrestore(&chan->lock, flags); > /* Wakeup if anyone waiting for VirtIO ring space. */ > wake_up(chan->vc_wq); In particular, the wake up here echoes to wait events that will immediately try to grab the lock, and will needlessly spin on it until this thread is done. If we do go this way I'd want setting chan->ring_bufs_avail to be done just before unlocking and the wakeup to be done just after unlocking out of the loop iff we processed at least one iteration here. That should also save you precious cpu cycles while under lock :) -- Dominique Martinet