From patchwork Thu Oct 12 15:38:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 30305 X-Patchwork-Delegate: yuanhan.liu@linux.intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5BBF31B3DB; Thu, 12 Oct 2017 17:39:11 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 9CECC1B3CE for ; Thu, 12 Oct 2017 17:39:07 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF65F7F3FB; Thu, 12 Oct 2017 15:39:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EF65F7F3FB Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=maxime.coquelin@redhat.com Received: from localhost.localdomain (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EBF017D5B; Thu, 12 Oct 2017 15:39:05 +0000 (UTC) From: Maxime Coquelin To: yliu@fridaylinux.org, thomas@monjalon.net, dev@dpdk.org Cc: Maxime Coquelin Date: Thu, 12 Oct 2017 17:38:49 +0200 Message-Id: <20171012153850.21837-2-maxime.coquelin@redhat.com> In-Reply-To: <20171012153850.21837-1-maxime.coquelin@redhat.com> References: <20171012153850.21837-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 12 Oct 2017 15:39:07 +0000 (UTC) Subject: [dpdk-dev] [PATCH 1/2] vhost: fix deadlock on IOTLB miss X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" An optimization was done to only take the iotlb cache lock once per packet burst instead of once per IOVA translation. With this, IOTLB miss requests are sent to Qemu with the lock held, which can cause a deadlock if the socket buffer is full, and if Qemu is waiting for an IOTLB update to be done. Holding the lock is not necessary when sending an IOTLB miss request, as it is not manipulating the IOTLB cache list, which the lock protects. Let's just release it while sending the IOTLB miss. Signed-off-by: Maxime Coquelin Reviewed-by: Jens Freimann --- lib/librte_vhost/vhost.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 54a1864eb..4f8b73a09 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -55,6 +55,7 @@ struct virtio_net *vhost_devices[MAX_VHOST_DEVICE]; +/* Called with iotlb_lock read-locked */ uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t iova, uint64_t size, uint8_t perm) @@ -71,8 +72,19 @@ __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq, return vva; if (!vhost_user_iotlb_pending_miss(vq, iova + tmp_size, perm)) { + /* + * iotlb_lock is read-locked for a full burst, + * but it only protects the iotlb cache. + * In case of IOTLB miss, we might block on the socket, + * which could cause a deadlock with QEMU if an IOTLB update + * is being handled. We can safely unlock here to avoid it. + */ + vhost_user_iotlb_rd_unlock(vq); + vhost_user_iotlb_pending_insert(vq, iova + tmp_size, perm); vhost_user_iotlb_miss(dev, iova + tmp_size, perm); + + vhost_user_iotlb_rd_lock(vq); } return 0;