From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3507C04EB8 for ; Wed, 12 Dec 2018 14:21:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9228E20849 for ; Wed, 12 Dec 2018 14:21:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9228E20849 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726647AbeLLOVA (ORCPT ); Wed, 12 Dec 2018 09:21:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32812 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726223AbeLLOU7 (ORCPT ); Wed, 12 Dec 2018 09:20:59 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EE8230832D2; Wed, 12 Dec 2018 14:20:59 +0000 (UTC) Received: from redhat.com (ovpn-122-106.rdu2.redhat.com [10.10.122.106]) by smtp.corp.redhat.com (Postfix) with SMTP id D99CB5C21A; Wed, 12 Dec 2018 14:20:57 +0000 (UTC) Date: Wed, 12 Dec 2018 09:20:57 -0500 From: "Michael S. Tsirkin" To: Jason Wang Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Tonghao Zhang , David Miller Subject: Re: [PATCH net V2 2/4] vhost_net: switch to use mutex_trylock() in vhost_net_busy_poll() Message-ID: <20181212091957-mutt-send-email-mst@kernel.org> References: <20181212100819.21295-1-jasowang@redhat.com> <20181212100819.21295-3-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181212100819.21295-3-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 12 Dec 2018 14:20:59 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 12, 2018 at 06:08:17PM +0800, Jason Wang wrote: > We used to hold the mutex of paired virtqueue in > vhost_net_busy_poll(). But this will results an inconsistent lock > order which may cause deadlock if we try to bring back the protection > of device IOTLB with vq mutex that requires to hold mutex of all > virtqueues at the same time. > > Fix this simply by switching to use mutex_trylock(), when fail just > skip the busy polling. This can happen when device IOTLB is under > updating which should be rare. > > Fixes: commit 78139c94dc8c ("net: vhost: lock the vqs one by one") > Cc: Tonghao Zhang > Signed-off-by: Jason Wang Acked-by: Michael S. Tsirkin and I think we should try to put this fix in 4.20 too. > --- > drivers/vhost/net.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c > index ab11b2bee273..ad7a6f475a44 100644 > --- a/drivers/vhost/net.c > +++ b/drivers/vhost/net.c > @@ -513,7 +513,13 @@ static void vhost_net_busy_poll(struct vhost_net *net, > struct socket *sock; > struct vhost_virtqueue *vq = poll_rx ? tvq : rvq; > > - mutex_lock_nested(&vq->mutex, poll_rx ? VHOST_NET_VQ_TX: VHOST_NET_VQ_RX); > + /* Try to hold the vq mutex of the paired virtqueue. We can't > + * use mutex_lock() here since we could not guarantee a > + * consistenet lock ordering. > + */ > + if (!mutex_trylock(&vq->mutex)) > + return; > + > vhost_disable_notify(&net->dev, vq); > sock = rvq->private_data; > > -- > 2.17.1