From patchwork Tue Aug 23 04:35:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pei, Andy" X-Patchwork-Id: 115347 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CEFC3A0093; Tue, 23 Aug 2022 07:25:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E164742905; Tue, 23 Aug 2022 07:25:02 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 05A454284D for ; Tue, 23 Aug 2022 07:25:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661232301; x=1692768301; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=B5lziUqtBtLk67ML+WiHfj0sJ1taOXpoF1Gt2nBE048=; b=aCXSuw5Ve4nPHQ9h0MpBd+NUp47uRs19bOhrT7mO5C6DO4K3iLVXAapb vu9TZY05Pxq09cfqhnANWTxOn8wFv6SR4qvlratHvbvsLzz1x8dKu+WOn +W9Kwlivff3kmqy/iA6E9yD296L4u+MYNSRq1e5RnjFnZXAnQP6rXIt9h Dbv9ms3WjXEEF+yUVHrkfk4kj+iIAT7Qfa/zQ3X12vQ3euH1BwmbZmF60 azvE43w+zs41teo7keFFJtGCE9DFWcud3MIMpUFgOdMPo5IjA3pIXQup8 yPjyRQToweCbiGJNhExAXPGN78KnlbpzAEYEeG225hQYOKLA94DaSPT25 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="355325329" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="355325329" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2022 22:25:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="669864787" Received: from dpdk-dipei.sh.intel.com ([10.67.110.251]) by fmsmga008.fm.intel.com with ESMTP; 22 Aug 2022 22:24:59 -0700 From: Andy Pei To: dev@dpdk.org Cc: chenbo.xia@intel.com, rosen.xu@intel.com, wei.huang@intel.com, gang.cao@intel.com, maxime.coquelin@redhat.com Subject: [PATCH 7/8] vhost: configure device when any queue is ready for BLK device Date: Tue, 23 Aug 2022 12:35:04 +0800 Message-Id: <1661229305-240952-8-git-send-email-andy.pei@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1661229305-240952-1-git-send-email-andy.pei@intel.com> References: <1661229305-240952-1-git-send-email-andy.pei@intel.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When boot from virtio blk device, seabois in QEMU only enables one queue. To work in this scenario, vDPA BLK device back-end conf_dev when any queue is ready. Signed-off-by: Andy Pei --- lib/vhost/vhost_user.c | 56 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 4ad28ba..b65fba3 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -1451,6 +1451,25 @@ #define VIRTIO_BUILTIN_NUM_VQS_TO_BE_READY 2u static int +virtio_has_queue_ready(struct virtio_net *dev) +{ + struct vhost_virtqueue *vq; + uint32_t i, nr_vring = dev->nr_vring; + + if (!dev->nr_vring) + return 0; + + for (i = 0; i < nr_vring; i++) { + vq = dev->virtqueue[i]; + + if (vq_is_ready(dev, vq)) + return 1; + } + + return 0; +} + +static int virtio_is_ready(struct virtio_net *dev) { struct vhost_virtqueue *vq; @@ -3167,9 +3186,33 @@ static int is_vring_iotlb(struct virtio_net *dev, if (unlock_required) vhost_user_unlock_all_queue_pairs(dev); - if (ret != 0 || !virtio_is_ready(dev)) + if (ret != 0) goto out; + vdpa_dev = dev->vdpa_dev; + if (vdpa_dev) { + if (vdpa_dev->ops->get_dev_type) { + ret = vdpa_dev->ops->get_dev_type(vdpa_dev, &vdpa_type); + if (ret) { + VHOST_LOG_CONFIG(dev->ifname, ERR, + "failed to get vdpa dev type.\n"); + ret = -1; + goto out; + } + } else { + vdpa_type = RTE_VHOST_VDPA_DEVICE_TYPE_NET; + } + } + + if (!virtio_is_ready(dev)) { + if (vdpa_type == RTE_VHOST_VDPA_DEVICE_TYPE_BLK) { + if (!virtio_has_queue_ready(dev)) + goto out; + } else { + goto out; + } + } + /* * Virtio is now ready. If not done already, it is time * to notify the application it can process the rings and @@ -3181,20 +3224,9 @@ static int is_vring_iotlb(struct virtio_net *dev, dev->flags |= VIRTIO_DEV_RUNNING; } - vdpa_dev = dev->vdpa_dev; if (!vdpa_dev) goto out; - if (vdpa_dev->ops->get_dev_type) { - ret = vdpa_dev->ops->get_dev_type(vdpa_dev, &vdpa_type); - if (ret) { - VHOST_LOG_CONFIG(dev->ifname, ERR, "failed to get vdpa dev type.\n"); - ret = -1; - goto out; - } - } else { - vdpa_type = RTE_VHOST_VDPA_DEVICE_TYPE_NET; - } if (vdpa_type == RTE_VHOST_VDPA_DEVICE_TYPE_BLK && request != VHOST_USER_SET_VRING_CALL) goto out;