From patchwork Fri Sep 25 12:31:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 78847 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2779EA04C0; Fri, 25 Sep 2020 14:32:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 065E21E977; Fri, 25 Sep 2020 14:31:57 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by dpdk.org (Postfix) with ESMTP id 1BC7C1E985 for ; Fri, 25 Sep 2020 14:31:54 +0200 (CEST) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601037113; 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=2uNXRb/3aBdrGFIefOVc1zYkJjnjkrpZLMxMiH5YYxE=; b=WW9li4Vc/j669YFqA3dVwWLic5jUwW8+n34dEzzQVg5gkQYZ3WEcojGlJ3zbQUoQmhDMMq p7MN7O1+fOluh11khAjGOuVi6cD4OTogmsNeGWlCTkuju9+srlyREuXF3xN9PRwsvaS4B+ vHJCbxzx1ATT6N9UAkqTB/6A0i/5aC8= 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-329-vi1erNSoMh66JlfaXryyLg-1; Fri, 25 Sep 2020 08:31:51 -0400 X-MC-Unique: vi1erNSoMh66JlfaXryyLg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CBDD080EDAE; Fri, 25 Sep 2020 12:31:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76DF978833; Fri, 25 Sep 2020 12:31:48 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, patrick.fu@intel.com, amorenoz@redhat.com Cc: Maxime Coquelin Date: Fri, 25 Sep 2020 14:31:12 +0200 Message-Id: <20200925123113.68916-8-maxime.coquelin@redhat.com> In-Reply-To: <20200925123113.68916-1-maxime.coquelin@redhat.com> References: <20200925123113.68916-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 7/8] net/virtio: split virtio-user start 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" Move feature bit settings in device start out as an standalone function, so that feature bit could be negotiated at device feature_ok status. Signed-off-by: Maxime Coquelin --- .../net/virtio/virtio_user/virtio_user_dev.c | 50 ++++++++++++------- .../net/virtio/virtio_user/virtio_user_dev.h | 1 + drivers/net/virtio/virtio_user_ethdev.c | 4 ++ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 5988bc92fe..81257a3996 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -112,25 +112,11 @@ virtio_user_queue_setup(struct virtio_user_dev *dev, } int -virtio_user_start_device(struct virtio_user_dev *dev) +virtio_user_dev_set_features(struct virtio_user_dev *dev) { uint64_t features; - int ret; + int ret = -1; - /* - * XXX workaround! - * - * We need to make sure that the locks will be - * taken in the correct order to avoid deadlocks. - * - * Before releasing this lock, this thread should - * not trigger any memory hotplug events. - * - * This is a temporary workaround, and should be - * replaced when we get proper supports from the - * memory subsystem in the future. - */ - rte_mcfg_mem_read_lock(); pthread_mutex_lock(&dev->mutex); if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER @@ -141,10 +127,8 @@ virtio_user_start_device(struct virtio_user_dev *dev) if (virtio_user_queue_setup(dev, virtio_user_create_queue) < 0) goto error; - /* Step 1: negotiate protocol features & set features */ features = dev->features; - /* Strip VIRTIO_NET_F_MAC, as MAC address is handled in vdev init */ features &= ~(1ull << VIRTIO_NET_F_MAC); /* Strip VIRTIO_NET_F_CTRL_VQ, as devices do not really need to know */ @@ -154,6 +138,36 @@ virtio_user_start_device(struct virtio_user_dev *dev) if (ret < 0) goto error; PMD_DRV_LOG(INFO, "set features: %" PRIx64, features); +error: + pthread_mutex_unlock(&dev->mutex); + + return ret; +} + +int +virtio_user_start_device(struct virtio_user_dev *dev) +{ + int ret; + + /* + * XXX workaround! + * + * We need to make sure that the locks will be + * taken in the correct order to avoid deadlocks. + * + * Before releasing this lock, this thread should + * not trigger any memory hotplug events. + * + * This is a temporary workaround, and should be + * replaced when we get proper supports from the + * memory subsystem in the future. + */ + rte_mcfg_mem_read_lock(); + pthread_mutex_lock(&dev->mutex); + + if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER && + dev->vhostfd < 0) + goto error; /* Step 2: share memory regions */ ret = dev->ops->send_request(dev, VHOST_USER_SET_MEM_TABLE, NULL); diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 1c8c98b1cd..3e9d1a1eb3 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -68,6 +68,7 @@ struct virtio_user_dev { bool started; }; +int virtio_user_dev_set_features(struct virtio_user_dev *dev); int virtio_user_start_device(struct virtio_user_dev *dev); int virtio_user_stop_device(struct virtio_user_dev *dev); int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 3a51afd711..f56fc238c4 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -269,7 +269,11 @@ static void virtio_user_set_status(struct virtio_hw *hw, uint8_t status) { struct virtio_user_dev *dev = virtio_user_get_dev(hw); + uint8_t old_status = dev->status; + if (status & VIRTIO_CONFIG_STATUS_FEATURES_OK && + ~old_status & VIRTIO_CONFIG_STATUS_FEATURES_OK) + virtio_user_dev_set_features(dev); if (status & VIRTIO_CONFIG_STATUS_DRIVER_OK) virtio_user_start_device(dev); else if (status == VIRTIO_CONFIG_STATUS_RESET)