From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8D250A00C3; Thu, 14 May 2020 10:03:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 83E181D6C2; Thu, 14 May 2020 10:02:51 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by dpdk.org (Postfix) with ESMTP id 4A3401D674 for ; Thu, 14 May 2020 10:02:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589443366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L23EYYDQnt1kpmDXqzogWQoltBCFMyLVefIJOcVZvTg=; b=b3PC5ycQ9T1n3KgIAAZeJq18GQNT9wCvaNzClqIpVzRtjUIrt3oeihzxMlJiAiKrafVzeS cYrvqyZTotkl+J9wtos6VWP5lZwSoL8phplQb6rMJ4dDEitUzGIVkq5Dri6RJ030dHFbbF hy1svnDEJzWj7gEvlYVHQbLIhkaMpxo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-53-0bvbFdHhPnOZv2WL3eQmfg-1; Thu, 14 May 2020 04:02:43 -0400 X-MC-Unique: 0bvbFdHhPnOZv2WL3eQmfg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A286EC1A0; Thu, 14 May 2020 08:02:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C9E36E9E0; Thu, 14 May 2020 08:02:39 +0000 (UTC) From: Maxime Coquelin To: xiaolong.ye@intel.com, shahafs@mellanox.com, matan@mellanox.com, amorenoz@redhat.com, xiao.w.wang@intel.com, viacheslavo@mellanox.com, dev@dpdk.org Cc: jasowang@redhat.com, lulu@redhat.com, Maxime Coquelin Date: Thu, 14 May 2020 10:02:11 +0200 Message-Id: <20200514080218.1435344-3-maxime.coquelin@redhat.com> In-Reply-To: <20200514080218.1435344-1-maxime.coquelin@redhat.com> References: <20200514080218.1435344-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 2/9] vhost: refactor Virtio ready check 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" This patch is a small refactoring, as preliminary work for adding support to Virtio status support. No functionnal change here. Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 1 + lib/librte_vhost/vhost_user.c | 40 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 0266318440..fd8ba1be2d 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -716,6 +716,7 @@ vhost_enable_dequeue_zero_copy(int vid) return; dev->dequeue_zero_copy = 1; + VHOST_LOG_CONFIG(INFO, "dequeue zero copy is enabled\n"); } void diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 106b6d7609..f5800bd9c1 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1315,6 +1315,9 @@ virtio_is_ready(struct virtio_net *dev) struct vhost_virtqueue *vq; uint32_t i; + if (dev->flags & VIRTIO_DEV_READY) + return 1; + if (dev->nr_vring == 0) return 0; @@ -1325,8 +1328,11 @@ virtio_is_ready(struct virtio_net *dev) return 0; } + dev->flags |= VIRTIO_DEV_READY; + VHOST_LOG_CONFIG(INFO, "virtio is now ready for processing.\n"); + return 1; } @@ -2606,7 +2612,6 @@ vhost_user_msg_handler(int vid, int fd) struct virtio_net *dev; struct VhostUserMsg msg; struct rte_vdpa_device *vdpa_dev; - int did = -1; int ret; int unlock_required = 0; bool handled; @@ -2784,30 +2789,33 @@ vhost_user_msg_handler(int vid, int fd) return -1; } - if (!(dev->flags & VIRTIO_DEV_READY) && virtio_is_ready(dev)) { - dev->flags |= VIRTIO_DEV_READY; + if (!virtio_is_ready(dev)) + goto out; - if (!(dev->flags & VIRTIO_DEV_RUNNING)) { - if (dev->dequeue_zero_copy) { - VHOST_LOG_CONFIG(INFO, - "dequeue zero copy is enabled\n"); - } + /* + * Virtio is now ready. If not done already, it is time + * to notify the application it can process the rings and + * configure the vDPA device if present. + */ - if (dev->notify_ops->new_device(dev->vid) == 0) - dev->flags |= VIRTIO_DEV_RUNNING; - } + if (!(dev->flags & VIRTIO_DEV_RUNNING)) { + if (dev->notify_ops->new_device(dev->vid) == 0) + dev->flags |= VIRTIO_DEV_RUNNING; } - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); - if (vdpa_dev && virtio_is_ready(dev) && - !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) && - msg.request.master == VHOST_USER_SET_VRING_CALL) { + vdpa_dev = rte_vdpa_get_device(dev->vdpa_dev_id); + if (!vdpa_dev) + goto out; + + if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) && + request == VHOST_USER_SET_VRING_CALL) { if (vdpa_dev->ops->dev_conf) vdpa_dev->ops->dev_conf(dev->vid); + dev->flags |= VIRTIO_DEV_VDPA_CONFIGURED; } +out: return 0; } -- 2.25.4