From patchwork Fri Jun 26 13:26:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72232 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 37FF5A051C; Fri, 26 Jun 2020 15:28:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1DD801BF97; Fri, 26 Jun 2020 15:28:01 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 25B481BF84 for ; Fri, 26 Jun 2020 15:28:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178079; 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=lwomoS5iFv58UFiGq+3o0r3oeXlIyZ4IwrDY02MrQBo=; b=XiJL83UTd+JZaRlidrSkJ4tg9B2QWENJU8Kt1BE35fIYC8lTGWt68QozKzUZFz3edfwA/T fkxhbhH0Ku6Pzpw1cxITjyS3etSNkCGi371E2KprZevNDNRPn8yIuaeYjedpx/gGwhadZp zflWO3jVyyhXASs7jAoWqHOl7cTo5bA= 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-224-5CEtj2TvN6S58f-wFSH89g-1; Fri, 26 Jun 2020 09:27:56 -0400 X-MC-Unique: 5CEtj2TvN6S58f-wFSH89g-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E98C8464BF; Fri, 26 Jun 2020 13:27:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDA4758851; Fri, 26 Jun 2020 13:27:46 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin , stable@dpdk.org Date: Fri, 26 Jun 2020 15:26:59 +0200 Message-Id: <20200626132712.1437673-2-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 01/14] bus/dpaa: fix null pointer dereference 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 patches fixes a null pointer derefencing that happens when the device string passed to the iterator is NULL. This situation can happen when iterating on a class type. For example: RTE_DEV_FOREACH(dev, "class=eth", &dev_iter) { ... } Fixes: e79df833d3f6 ("bus/dpaa: support hotplug ops") Cc: stable@dpdk.org Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- drivers/bus/dpaa/dpaa_bus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c index d53fe6083a..591e28c1e7 100644 --- a/drivers/bus/dpaa/dpaa_bus.c +++ b/drivers/bus/dpaa/dpaa_bus.c @@ -703,6 +703,11 @@ dpaa_bus_dev_iterate(const void *start, const char *str, struct rte_dpaa_device *dev; char *dup, *dev_name = NULL; + if (str == NULL) { + DPAA_BUS_DEBUG("No device string"); + return NULL; + } + /* Expectation is that device would be name=device_name */ if (strncmp(str, "name=", 5) != 0) { DPAA_BUS_DEBUG("Invalid device string (%s)\n", str); From patchwork Fri Jun 26 13:27:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72233 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 A0869A051C; Fri, 26 Jun 2020 15:28:14 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 799AB1BF95; Fri, 26 Jun 2020 15:28:10 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 38E501BF95 for ; Fri, 26 Jun 2020 15:28:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178088; 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=PiZgF1xPVT432AFDzBxkR+QdO91M4PuWoIciT5FH88c=; b=jBeUk58bmP8oDdiq/bzuBUZqkf8/nrteG6EQvTlNAdQtHKiGCBDb4LQ0p6+oKytecAeM4i YoflgqEVbmsIlTi2AwTuBa3dzN0Kc3cP3KItfEOQmcjm3cXFydNRHWz+SK5lQHfK+FxWFy Vf40HKGC4mjjQ8fZh3IvOzlv+7blrZA= 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-417-4_mqfVQvP62yu9Gz6LM57g-1; Fri, 26 Jun 2020 09:28:05 -0400 X-MC-Unique: 4_mqfVQvP62yu9Gz6LM57g-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B4791006B1F; Fri, 26 Jun 2020 13:28:02 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6D3A5FC17; Fri, 26 Jun 2020 13:27:54 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin , stable@dpdk.org, shreyansh.jain@nxp.com Date: Fri, 26 Jun 2020 15:27:00 +0200 Message-Id: <20200626132712.1437673-3-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 02/14] bus/fslmc: fix null pointer dereference 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 patches fixes a null pointer derefencing that happens when the device string passed to the iterator is NULL. This situation can happen when iterating on a class type. For example: RTE_DEV_FOREACH(dev, "class=eth", &dev_iter) { ... } Fixes: e67a61614d0b ("bus/fslmc: support device iteration") Cc: stable@dpdk.org Cc: shreyansh.jain@nxp.com Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- drivers/bus/fslmc/fslmc_bus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index afbd82e8db..ac46eb4fe8 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -603,6 +603,11 @@ fslmc_bus_dev_iterate(const void *start, const char *str, struct rte_dpaa2_device *dev; char *dup, *dev_name = NULL; + if (str == NULL) { + DPAA2_BUS_DEBUG("No device string"); + return NULL; + } + /* Expectation is that device would be name=device_name */ if (strncmp(str, "name=", 5) != 0) { DPAA2_BUS_DEBUG("Invalid device string (%s)\n", str); From patchwork Fri Jun 26 13:27:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72234 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 D7DCEA051C; Fri, 26 Jun 2020 15:28:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E482F1BFA9; Fri, 26 Jun 2020 15:28:20 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id C06371BF93 for ; Fri, 26 Jun 2020 15:28:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178098; 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=a11ps+nTW+xpyUwaJvAVwALxg76U10DOIwPcCvQkmK4=; b=GqlRy1NuRTzHJSNwVoUqOnbyTWAl4h9bz3n5n9yU+0yaUyJfIc489AG8kpTOBx0sCOErci ZIHpISqwDRV/GyLiNuUOf27d0LYPGIbSPOBYsKeo2b+OtvhocuC1rfC2+qHSrf85HXk3W5 38kVUc8j+Wx1wcV0dUK0zZ2uD3aL/Xw= 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-119-5yS7v8VCP2SL54BVySulWA-1; Fri, 26 Jun 2020 09:28:13 -0400 X-MC-Unique: 5yS7v8VCP2SL54BVySulWA-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 179E4107ACF5; Fri, 26 Jun 2020 13:28:11 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 934A718211; Fri, 26 Jun 2020 13:28:02 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:01 +0200 Message-Id: <20200626132712.1437673-4-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 v3 03/14] vhost: introduce vDPA devices class 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 introduces vDPA device class. It will enable application to iterate over the vDPA devices. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vdpa.c | 115 +++++++++++++++++++++++++++++++++------- 1 file changed, 97 insertions(+), 18 deletions(-) diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 1f5cdcd64b..a429841691 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -10,11 +10,12 @@ #include +#include #include #include "rte_vdpa.h" #include "vhost.h" -static struct rte_vdpa_device *vdpa_devices[MAX_VHOST_DEVICE]; +static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; static uint32_t vdpa_device_num; static bool @@ -46,35 +47,28 @@ rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, struct rte_vdpa_dev_ops *ops) { struct rte_vdpa_device *dev; - char device_name[MAX_VDPA_NAME_LEN]; int i; if (vdpa_device_num >= MAX_VHOST_DEVICE || addr == NULL || ops == NULL) return -1; for (i = 0; i < MAX_VHOST_DEVICE; i++) { - dev = vdpa_devices[i]; - if (dev && is_same_vdpa_device(&dev->addr, addr)) + dev = &vdpa_devices[i]; + if (dev->ops && is_same_vdpa_device(&dev->addr, addr)) return -1; } for (i = 0; i < MAX_VHOST_DEVICE; i++) { - if (vdpa_devices[i] == NULL) + if (vdpa_devices[i].ops == NULL) break; } if (i == MAX_VHOST_DEVICE) return -1; - snprintf(device_name, sizeof(device_name), "vdpa-dev-%d", i); - dev = rte_zmalloc(device_name, sizeof(struct rte_vdpa_device), - RTE_CACHE_LINE_SIZE); - if (!dev) - return -1; - + dev = &vdpa_devices[i]; memcpy(&dev->addr, addr, sizeof(struct rte_vdpa_dev_addr)); dev->ops = ops; - vdpa_devices[i] = dev; vdpa_device_num++; return i; @@ -83,11 +77,10 @@ rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, int rte_vdpa_unregister_device(int did) { - if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did] == NULL) + if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did].ops == NULL) return -1; - rte_free(vdpa_devices[did]); - vdpa_devices[did] = NULL; + memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); vdpa_device_num--; return did; @@ -103,8 +96,11 @@ rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr) return -1; for (i = 0; i < MAX_VHOST_DEVICE; ++i) { - dev = vdpa_devices[i]; - if (dev && is_same_vdpa_device(&dev->addr, addr)) + dev = &vdpa_devices[i]; + if (dev->ops == NULL) + continue; + + if (is_same_vdpa_device(&dev->addr, addr)) return i; } @@ -117,7 +113,7 @@ rte_vdpa_get_device(int did) if (did < 0 || did >= MAX_VHOST_DEVICE) return NULL; - return vdpa_devices[did]; + return &vdpa_devices[did]; } int @@ -274,3 +270,86 @@ rte_vdpa_reset_stats(int did, uint16_t qid) return vdpa_dev->ops->reset_stats(did, qid); } + +static uint16_t +vdpa_dev_to_id(const struct rte_vdpa_device *dev) +{ + if (dev == NULL) + return MAX_VHOST_DEVICE; + + if (dev < &vdpa_devices[0] || + dev >= &vdpa_devices[MAX_VHOST_DEVICE]) + return MAX_VHOST_DEVICE; + + return (uint16_t)(dev - vdpa_devices); +} + +static int +vdpa_dev_match(struct rte_vdpa_device *dev, + const struct rte_device *rte_dev) +{ + struct rte_vdpa_dev_addr addr; + + /* Only PCI bus supported for now */ + if (strcmp(rte_dev->bus->name, "pci") != 0) + return -1; + + addr.type = VDPA_ADDR_PCI; + + if (rte_pci_addr_parse(rte_dev->name, &addr.pci_addr) != 0) + return -1; + + if (!is_same_vdpa_device(&dev->addr, &addr)) + return -1; + + return 0; +} + +/* Generic rte_vdpa_dev comparison function. */ +typedef int (*rte_vdpa_cmp_t)(struct rte_vdpa_device *, + const struct rte_device *rte_dev); + +static struct rte_vdpa_device * +vdpa_find_device(const struct rte_vdpa_device *start, rte_vdpa_cmp_t cmp, + struct rte_device *rte_dev) +{ + struct rte_vdpa_device *dev; + uint16_t idx; + + if (start != NULL) + idx = vdpa_dev_to_id(start) + 1; + else + idx = 0; + for (; idx < MAX_VHOST_DEVICE; idx++) { + dev = &vdpa_devices[idx]; + /* + * ToDo: Certainly better to introduce a state field, + * but rely on ops being set for now. + */ + if (dev->ops == NULL) + continue; + if (cmp(dev, rte_dev) == 0) + return dev; + } + return NULL; +} + +static void * +vdpa_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it) +{ + struct rte_vdpa_device *vdpa_dev = NULL; + + RTE_SET_USED(str); + + vdpa_dev = vdpa_find_device(start, vdpa_dev_match, it->device); + + return vdpa_dev; +} + +static struct rte_class rte_class_vdpa = { + .dev_iterate = vdpa_dev_iterate, +}; + +RTE_REGISTER_CLASS(vdpa, rte_class_vdpa); From patchwork Fri Jun 26 13:27:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72235 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 51305A051C; Fri, 26 Jun 2020 15:28:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 039621BFB3; Fri, 26 Jun 2020 15:28:26 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 044A01BFB3 for ; Fri, 26 Jun 2020 15:28:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178103; 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=WsxfBQasApIR1XhpEG1lskrQuW43cnZQFtblaF5Eqzs=; b=W7Xr7gwSGE5zfI6FqtJMQVkAjo3Kv8aVrG/o8EyE3iGArLpoRFOdtuj/ih1F9ozComgwKj fYcud1tfBuiQDaiKGsq/8bh/Gu/xoizTgNO2m0EVhTy+ZsUBOQ0zLI3VMh7aQrOzEDnV8W t1Nbg3+bLVlJ8fNTQzNO8d1RuhcKau4= 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-114-PL20xy6JNRWWpGxNstJECg-1; Fri, 26 Jun 2020 09:28:21 -0400 X-MC-Unique: PL20xy6JNRWWpGxNstJECg-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A85CA84E28D; Fri, 26 Jun 2020 13:28:15 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D7F25F9DB; Fri, 26 Jun 2020 13:28:11 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:02 +0200 Message-Id: <20200626132712.1437673-5-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 v3 04/14] vhost: make vDPA framework bus agnostic 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 makes the vDPA framework to no more support only PCI devices, but any devices by relying on the generic device name as identifier. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- drivers/vdpa/ifc/ifcvf_vdpa.c | 9 +-- drivers/vdpa/mlx5/mlx5_vdpa.c | 8 +-- drivers/vdpa/mlx5/mlx5_vdpa.h | 2 +- examples/vdpa/main.c | 49 ++++++++-------- lib/librte_vhost/rte_vdpa.h | 42 +++++++------- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/vdpa.c | 79 +++++++++++--------------- 7 files changed, 87 insertions(+), 103 deletions(-) diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index ec97178dcb..ac9e218c23 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -47,7 +47,6 @@ static const char * const ifcvf_valid_arguments[] = { static int ifcvf_vdpa_logtype; struct ifcvf_internal { - struct rte_vdpa_dev_addr dev_addr; struct rte_pci_device *pdev; struct ifcvf_hw hw; int vfio_container_fd; @@ -116,7 +115,8 @@ find_internal_resource_by_dev(struct rte_pci_device *pdev) pthread_mutex_lock(&internal_list_lock); TAILQ_FOREACH(list, &internal_list, next) { - if (pdev == list->internal->pdev) { + if (!rte_pci_addr_cmp(&pdev->addr, + &list->internal->pdev->addr)) { found = 1; break; } @@ -1176,8 +1176,6 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | (1ULL << VHOST_F_LOG_ALL); - internal->dev_addr.pci_addr = pci_dev->addr; - internal->dev_addr.type = VDPA_ADDR_PCI; list->internal = internal; if (rte_kvargs_count(kvlist, IFCVF_SW_FALLBACK_LM)) { @@ -1188,8 +1186,7 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, } internal->sw_lm = sw_fallback_lm; - internal->did = rte_vdpa_register_device(&internal->dev_addr, - &ifcvf_ops); + internal->did = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops); if (internal->did < 0) { DRV_LOG(ERR, "failed to register device %s", pci_dev->name); goto error; diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index 8b0b3b8193..7b5ae62bdc 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -681,14 +681,13 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, priv->caps = attr.vdpa; priv->log_max_rqt_size = attr.log_max_rqt_size; priv->ctx = ctx; - priv->dev_addr.pci_addr = pci_dev->addr; - priv->dev_addr.type = VDPA_ADDR_PCI; + priv->pci_dev = pci_dev; priv->var = mlx5_glue->dv_alloc_var(ctx, 0); if (!priv->var) { DRV_LOG(ERR, "Failed to allocate VAR %u.\n", errno); goto error; } - priv->id = rte_vdpa_register_device(&priv->dev_addr, &mlx5_vdpa_ops); + priv->id = rte_vdpa_register_device(&pci_dev->device, &mlx5_vdpa_ops); if (priv->id < 0) { DRV_LOG(ERR, "Failed to register vDPA device."); rte_errno = rte_errno ? rte_errno : EINVAL; @@ -730,8 +729,7 @@ mlx5_vdpa_pci_remove(struct rte_pci_device *pci_dev) pthread_mutex_lock(&priv_list_lock); TAILQ_FOREACH(priv, &priv_list, next) { - if (memcmp(&priv->dev_addr.pci_addr, &pci_dev->addr, - sizeof(pci_dev->addr)) == 0) { + if (!rte_pci_addr_cmp(&priv->pci_dev->addr, &pci_dev->addr)) { found = 1; break; } diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index 80b4c4bda9..5fc801eff3 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -106,7 +106,7 @@ struct mlx5_vdpa_priv { int id; /* vDPA device id. */ int vid; /* vhost device id. */ struct ibv_context *ctx; /* Device context. */ - struct rte_vdpa_dev_addr dev_addr; + struct rte_pci_device *pci_dev; struct mlx5_hca_vdpa_attr caps; uint32_t pdn; /* Protection Domain number. */ struct ibv_pd *pd; diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index bb30796df6..e72f6646e7 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -280,10 +280,14 @@ static void cmd_list_vdpa_devices_parsed( uint32_t queue_num; uint64_t features; struct rte_vdpa_device *vdev; - struct rte_pci_addr addr; + struct rte_device *dev; + struct rte_dev_iterator dev_iter; - cmdline_printf(cl, "device id\tdevice address\tqueue num\tsupported features\n"); - for (did = 0; did < dev_total; did++) { + cmdline_printf(cl, "device id\tdevice name\tqueue num\tsupported features\n"); + RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { + did = rte_vdpa_find_device_id_by_name(dev->name); + if (did < 0) + continue; vdev = rte_vdpa_get_device(did); if (!vdev) continue; @@ -299,11 +303,8 @@ static void cmd_list_vdpa_devices_parsed( "for device id %d.\n", did); continue; } - addr = vdev->addr.pci_addr; - cmdline_printf(cl, - "%d\t\t" PCI_PRI_FMT "\t%" PRIu32 "\t\t0x%" PRIx64 "\n", - did, addr.domain, addr.bus, addr.devid, - addr.function, queue_num, features); + cmdline_printf(cl, "%d\t\t%s\t\t%" PRIu32 "\t\t0x%" PRIx64 "\n", + did, dev->name, queue_num, features); } } @@ -333,17 +334,12 @@ static void cmd_create_vdpa_port_parsed(void *parsed_result, { int did; struct cmd_create_result *res = parsed_result; - struct rte_vdpa_dev_addr addr; rte_strscpy(vports[devcnt].ifname, res->socket_path, MAX_PATH_LEN); - if (rte_pci_addr_parse(res->bdf, &addr.pci_addr) != 0) { - cmdline_printf(cl, "Unable to parse the given bdf.\n"); - return; - } - addr.type = VDPA_ADDR_PCI; - did = rte_vdpa_find_device_id(&addr); + did = rte_vdpa_find_device_id_by_name(res->bdf); if (did < 0) { - cmdline_printf(cl, "Unable to find vdpa device id.\n"); + cmdline_printf(cl, "Unable to find vdpa device id for %s.\n", + res->bdf); return; } @@ -519,9 +515,11 @@ int main(int argc, char *argv[]) { char ch; - int i; + int did; int ret; struct cmdline *cl; + struct rte_device *dev; + struct rte_dev_iterator dev_iter; ret = rte_eal_init(argc, argv); if (ret < 0) @@ -547,13 +545,18 @@ main(int argc, char *argv[]) cmdline_interact(cl); cmdline_stdin_exit(cl); } else { - for (i = 0; i < RTE_MIN(MAX_VDPA_SAMPLE_PORTS, dev_total); - i++) { - vports[i].did = i; - snprintf(vports[i].ifname, MAX_PATH_LEN, "%s%d", - iface, i); + RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { + did = rte_vdpa_find_device_id_by_name(dev->name); + if (did < 0) { + rte_panic("Failed to find device id for %s\n", + dev->name); + } + vports[devcnt].did = did; + snprintf(vports[devcnt].ifname, MAX_PATH_LEN, "%s%d", + iface, devcnt); - start_vdpa(&vports[i]); + start_vdpa(&vports[devcnt]); + devcnt++; } printf("enter \'q\' to quit\n"); diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index ecb3d911d0..b752dfeb96 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -18,25 +18,6 @@ #define MAX_VDPA_NAME_LEN 128 -enum vdpa_addr_type { - VDPA_ADDR_PCI, - VDPA_ADDR_MAX -}; - -/** - * vdpa device address - */ -struct rte_vdpa_dev_addr { - /** vdpa address type */ - enum vdpa_addr_type type; - - /** vdpa pci address */ - union { - uint8_t __dummy[64]; - struct rte_pci_addr pci_addr; - }; -}; - /** Maximum name length for statistics counters */ #define RTE_VDPA_STATS_NAME_SIZE 64 @@ -120,8 +101,8 @@ struct rte_vdpa_dev_ops { * vdpa device structure includes device address and device operations. */ struct rte_vdpa_device { - /** vdpa device address */ - struct rte_vdpa_dev_addr addr; + /** Generic device information */ + struct rte_device *device; /** vdpa device operations */ struct rte_vdpa_dev_ops *ops; } __rte_cache_aligned; @@ -141,7 +122,7 @@ struct rte_vdpa_device { */ __rte_experimental int -rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, +rte_vdpa_register_device(struct rte_device *rte_dev, struct rte_vdpa_dev_ops *ops); /** @@ -159,6 +140,21 @@ __rte_experimental int rte_vdpa_unregister_device(int did); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Find the device id of a vdpa device from its name + * + * @param name + * the vdpa device name + * @return + * device id on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_find_device_id_by_name(const char *name); + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice @@ -172,7 +168,7 @@ rte_vdpa_unregister_device(int did); */ __rte_experimental int -rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr); +rte_vdpa_find_device_id(struct rte_vdpa_device *dev); /** * @warning diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 3a2f7df1e5..9325ee4227 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -69,4 +69,5 @@ EXPERIMENTAL { rte_vhost_get_vhost_ring_inflight; rte_vhost_get_vring_base_from_inflight; rte_vhost_slave_config_change; + rte_vdpa_find_device_id_by_name; }; diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index a429841691..87334c88c0 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -18,43 +18,22 @@ static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; static uint32_t vdpa_device_num; -static bool -is_same_vdpa_device(struct rte_vdpa_dev_addr *a, - struct rte_vdpa_dev_addr *b) -{ - bool ret = true; - - if (a->type != b->type) - return false; - - switch (a->type) { - case VDPA_ADDR_PCI: - if (a->pci_addr.domain != b->pci_addr.domain || - a->pci_addr.bus != b->pci_addr.bus || - a->pci_addr.devid != b->pci_addr.devid || - a->pci_addr.function != b->pci_addr.function) - ret = false; - break; - default: - break; - } - - return ret; -} - int -rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, +rte_vdpa_register_device(struct rte_device *rte_dev, struct rte_vdpa_dev_ops *ops) { struct rte_vdpa_device *dev; int i; - if (vdpa_device_num >= MAX_VHOST_DEVICE || addr == NULL || ops == NULL) + if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL) return -1; for (i = 0; i < MAX_VHOST_DEVICE; i++) { dev = &vdpa_devices[i]; - if (dev->ops && is_same_vdpa_device(&dev->addr, addr)) + if (dev->ops == NULL) + continue; + + if (dev->device == rte_dev) return -1; } @@ -67,7 +46,7 @@ rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, return -1; dev = &vdpa_devices[i]; - memcpy(&dev->addr, addr, sizeof(struct rte_vdpa_dev_addr)); + dev->device = rte_dev; dev->ops = ops; vdpa_device_num++; @@ -87,12 +66,33 @@ rte_vdpa_unregister_device(int did) } int -rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr) +rte_vdpa_find_device_id(struct rte_vdpa_device *dev) +{ + struct rte_vdpa_device *tmp_dev; + int i; + + if (dev == NULL) + return -1; + + for (i = 0; i < MAX_VHOST_DEVICE; ++i) { + tmp_dev = &vdpa_devices[i]; + if (tmp_dev->ops == NULL) + continue; + + if (tmp_dev == dev) + return i; + } + + return -1; +} + +int +rte_vdpa_find_device_id_by_name(const char *name) { struct rte_vdpa_device *dev; int i; - if (addr == NULL) + if (name == NULL) return -1; for (i = 0; i < MAX_VHOST_DEVICE; ++i) { @@ -100,7 +100,7 @@ rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr) if (dev->ops == NULL) continue; - if (is_same_vdpa_device(&dev->addr, addr)) + if (strncmp(dev->device->name, name, RTE_DEV_NAME_MAX_LEN) == 0) return i; } @@ -288,21 +288,10 @@ static int vdpa_dev_match(struct rte_vdpa_device *dev, const struct rte_device *rte_dev) { - struct rte_vdpa_dev_addr addr; + if (dev->device == rte_dev) + return 0; - /* Only PCI bus supported for now */ - if (strcmp(rte_dev->bus->name, "pci") != 0) - return -1; - - addr.type = VDPA_ADDR_PCI; - - if (rte_pci_addr_parse(rte_dev->name, &addr.pci_addr) != 0) - return -1; - - if (!is_same_vdpa_device(&dev->addr, &addr)) - return -1; - - return 0; + return -1; } /* Generic rte_vdpa_dev comparison function. */ From patchwork Fri Jun 26 13:27:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72236 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 825C9A051C; Fri, 26 Jun 2020 15:28:46 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BD3791BFA6; Fri, 26 Jun 2020 15:28:36 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id B5E301BF7C for ; Fri, 26 Jun 2020 15:28:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178115; 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=olqraQL7aU3zbGTHTX/8e+ullM88PCrFdhc27f4L2OQ=; b=cwvaCrrC7Ppx54UQ6Noytbna7jHuAFKy2szt8xeowLCW0abRqti9eyjnUzKdeop7s8ggj3 zmCwOKEKoTfaym+uD/yvokoFYMSklc/qjKSMhnktVyw7UbYILfszM2sH7p8/MBA9xjmb3i g39WvzGrGbDzg73e4wHKODETr3+Okp8= 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-8-artqtSxNOdCy3rDrMvSIHw-1; Fri, 26 Jun 2020 09:28:31 -0400 X-MC-Unique: artqtSxNOdCy3rDrMvSIHw-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE64A100CD07; Fri, 26 Jun 2020 13:28:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 182EC61B60; Fri, 26 Jun 2020 13:28:15 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:03 +0200 Message-Id: <20200626132712.1437673-6-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 v3 05/14] vhost: replace device ID in vDPA ops 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 preliminary step to get rid of the vDPA device ID. It makes vDPA callbacks to use the vDPA device struct as a reference instead of the ID. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- drivers/vdpa/ifc/ifcvf_vdpa.c | 79 ++++++++++---------- drivers/vdpa/mlx5/mlx5_vdpa.c | 134 ++++++++++++++++++++-------------- drivers/vdpa/mlx5/mlx5_vdpa.h | 2 +- examples/vdpa/main.c | 4 +- lib/librte_vhost/rte_vdpa.h | 28 ++++--- lib/librte_vhost/socket.c | 6 +- lib/librte_vhost/vdpa.c | 101 ++++++++++++------------- 7 files changed, 195 insertions(+), 159 deletions(-) diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index ac9e218c23..0418f9a07f 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -55,7 +55,7 @@ struct ifcvf_internal { pthread_t tid; /* thread for notify relay */ int epfd; int vid; - int did; + struct rte_vdpa_device *vdev; uint16_t max_queues; uint64_t features; rte_atomic32_t started; @@ -84,7 +84,7 @@ static pthread_mutex_t internal_list_lock = PTHREAD_MUTEX_INITIALIZER; static void update_used_ring(struct ifcvf_internal *internal, uint16_t qid); static struct internal_list * -find_internal_resource_by_did(int did) +find_internal_resource_by_vdev(struct rte_vdpa_device *vdev) { int found = 0; struct internal_list *list; @@ -92,7 +92,7 @@ find_internal_resource_by_did(int did) pthread_mutex_lock(&internal_list_lock); TAILQ_FOREACH(list, &internal_list, next) { - if (did == list->internal->did) { + if (vdev == list->internal->vdev) { found = 1; break; } @@ -877,14 +877,14 @@ ifcvf_sw_fallback_switchover(struct ifcvf_internal *internal) static int ifcvf_dev_config(int vid) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; struct ifcvf_internal *internal; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -894,7 +894,8 @@ ifcvf_dev_config(int vid) update_datapath(internal); if (rte_vhost_host_notifier_ctrl(vid, true) != 0) - DRV_LOG(NOTICE, "vDPA (%d): software relay is used.", did); + DRV_LOG(NOTICE, "vDPA (%s): software relay is used.", + vdev->device->name); return 0; } @@ -902,14 +903,14 @@ ifcvf_dev_config(int vid) static int ifcvf_dev_close(int vid) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; struct ifcvf_internal *internal; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -941,15 +942,15 @@ static int ifcvf_set_features(int vid) { uint64_t features = 0; - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; struct ifcvf_internal *internal; uint64_t log_base = 0, log_size = 0; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -974,13 +975,13 @@ ifcvf_set_features(int vid) static int ifcvf_get_vfio_group_fd(int vid) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -990,13 +991,13 @@ ifcvf_get_vfio_group_fd(int vid) static int ifcvf_get_vfio_device_fd(int vid) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -1006,16 +1007,16 @@ ifcvf_get_vfio_device_fd(int vid) static int ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; struct ifcvf_internal *internal; struct vfio_region_info reg = { .argsz = sizeof(reg) }; int ret; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -1036,13 +1037,13 @@ ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) } static int -ifcvf_get_queue_num(int did, uint32_t *queue_num) +ifcvf_get_queue_num(struct rte_vdpa_device *vdev, uint32_t *queue_num) { struct internal_list *list; - list = find_internal_resource_by_did(did); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -1052,13 +1053,13 @@ ifcvf_get_queue_num(int did, uint32_t *queue_num) } static int -ifcvf_get_vdpa_features(int did, uint64_t *features) +ifcvf_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features) { struct internal_list *list; - list = find_internal_resource_by_did(did); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -1074,8 +1075,10 @@ ifcvf_get_vdpa_features(int did, uint64_t *features) 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | \ 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) static int -ifcvf_get_protocol_features(int did __rte_unused, uint64_t *features) +ifcvf_get_protocol_features(struct rte_vdpa_device *vdev, uint64_t *features) { + RTE_SET_USED(vdev); + *features = VDPA_SUPPORTED_PROTOCOL_FEATURES; return 0; } @@ -1186,8 +1189,8 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, } internal->sw_lm = sw_fallback_lm; - internal->did = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops); - if (internal->did < 0) { + internal->vdev = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops); + if (internal->vdev == NULL) { DRV_LOG(ERR, "failed to register device %s", pci_dev->name); goto error; } @@ -1230,7 +1233,7 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev) rte_pci_unmap_device(internal->pdev); rte_vfio_container_destroy(internal->vfio_container_fd); - rte_vdpa_unregister_device(internal->did); + rte_vdpa_unregister_device(internal->vdev); pthread_mutex_lock(&internal_list_lock); TAILQ_REMOVE(&internal_list, list, next); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index 7b5ae62bdc..9ea032d57b 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -50,21 +50,21 @@ static pthread_mutex_t priv_list_lock = PTHREAD_MUTEX_INITIALIZER; int mlx5_vdpa_logtype; static struct mlx5_vdpa_priv * -mlx5_vdpa_find_priv_resource_by_did(int did) +mlx5_vdpa_find_priv_resource_by_vdev(struct rte_vdpa_device *vdev) { struct mlx5_vdpa_priv *priv; int found = 0; pthread_mutex_lock(&priv_list_lock); TAILQ_FOREACH(priv, &priv_list, next) { - if (did == priv->id) { + if (vdev == priv->vdev) { found = 1; break; } } pthread_mutex_unlock(&priv_list_lock); if (!found) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); rte_errno = EINVAL; return NULL; } @@ -72,12 +72,13 @@ mlx5_vdpa_find_priv_resource_by_did(int did) } static int -mlx5_vdpa_get_queue_num(int did, uint32_t *queue_num) +mlx5_vdpa_get_queue_num(struct rte_vdpa_device *vdev, uint32_t *queue_num) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -1; } *queue_num = priv->caps.max_num_virtio_queues; @@ -85,12 +86,13 @@ mlx5_vdpa_get_queue_num(int did, uint32_t *queue_num) } static int -mlx5_vdpa_get_vdpa_features(int did, uint64_t *features) +mlx5_vdpa_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -1; } *features = MLX5_VDPA_DEFAULT_FEATURES; @@ -110,12 +112,14 @@ mlx5_vdpa_get_vdpa_features(int did, uint64_t *features) } static int -mlx5_vdpa_get_protocol_features(int did, uint64_t *features) +mlx5_vdpa_get_protocol_features(struct rte_vdpa_device *vdev, + uint64_t *features) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -1; } *features = MLX5_VDPA_PROTOCOL_FEATURES; @@ -125,11 +129,13 @@ mlx5_vdpa_get_protocol_features(int did, uint64_t *features) static int mlx5_vdpa_set_vring_state(int vid, int vring, int state) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } if (vring >= (int)priv->caps.max_num_virtio_queues * 2) { @@ -165,14 +171,16 @@ mlx5_vdpa_direct_db_prepare(struct mlx5_vdpa_priv *priv) static int mlx5_vdpa_features_set(int vid) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); uint64_t log_base, log_size; uint64_t features; int ret; if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } ret = rte_vhost_get_negotiated_features(vid, &features); @@ -284,12 +292,14 @@ mlx5_vdpa_mtu_set(struct mlx5_vdpa_priv *priv) static int mlx5_vdpa_dev_close(int vid) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); int ret = 0; if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -1; } if (priv->configured) @@ -312,11 +322,13 @@ mlx5_vdpa_dev_close(int vid) static int mlx5_vdpa_dev_config(int vid) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } if (priv->configured && mlx5_vdpa_dev_close(vid)) { @@ -325,7 +337,8 @@ mlx5_vdpa_dev_config(int vid) } priv->vid = vid; if (mlx5_vdpa_mtu_set(priv)) - DRV_LOG(WARNING, "MTU cannot be set on device %d.", did); + DRV_LOG(WARNING, "MTU cannot be set on device %s.", + vdev->device->name); if (mlx5_vdpa_pd_create(priv) || mlx5_vdpa_mem_register(priv) || mlx5_vdpa_direct_db_prepare(priv) || mlx5_vdpa_virtqs_prepare(priv) || mlx5_vdpa_steer_setup(priv) || @@ -341,11 +354,13 @@ mlx5_vdpa_dev_config(int vid) static int mlx5_vdpa_get_device_fd(int vid) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } return priv->ctx->cmd_fd; @@ -354,17 +369,19 @@ mlx5_vdpa_get_device_fd(int vid) static int mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); RTE_SET_USED(qid); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } if (!priv->var) { - DRV_LOG(ERR, "VAR was not created for device %d, is the device" - " configured?.", did); + DRV_LOG(ERR, "VAR was not created for device %s, is the device" + " configured?.", vdev->device->name); return -EINVAL; } *offset = priv->var->mmap_off; @@ -373,8 +390,9 @@ mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) } static int -mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, - unsigned int size) +mlx5_vdpa_get_stats_names(struct rte_vdpa_device *vdev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size) { static const char *mlx5_vdpa_stats_names[MLX5_VDPA_STATS_MAX] = { "received_descriptors", @@ -384,11 +402,12 @@ mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, "invalid buffer", "completion errors", }; - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); unsigned int i; if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name); return -ENODEV; } if (!stats_names) @@ -401,51 +420,57 @@ mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, } static int -mlx5_vdpa_get_stats(int did, int qid, struct rte_vdpa_stat *stats, - unsigned int n) +mlx5_vdpa_get_stats(struct rte_vdpa_device *vdev, int qid, + struct rte_vdpa_stat *stats, unsigned int n) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name); return -ENODEV; } if (!priv->configured) { - DRV_LOG(ERR, "Device %d was not configured.", did); + DRV_LOG(ERR, "Device %s was not configured.", + vdev->device->name); return -ENODATA; } if (qid >= (int)priv->nr_virtqs) { - DRV_LOG(ERR, "Too big vring id: %d.", qid); + DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid, + vdev->device->name); return -E2BIG; } if (!priv->caps.queue_counters_valid) { - DRV_LOG(ERR, "Virtq statistics is not supported for device %d.", - did); + DRV_LOG(ERR, "Virtq statistics is not supported for device %s.", + vdev->device->name); return -ENOTSUP; } return mlx5_vdpa_virtq_stats_get(priv, qid, stats, n); } static int -mlx5_vdpa_reset_stats(int did, int qid) +mlx5_vdpa_reset_stats(struct rte_vdpa_device *vdev, int qid) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name); return -ENODEV; } if (!priv->configured) { - DRV_LOG(ERR, "Device %d was not configured.", did); + DRV_LOG(ERR, "Device %s was not configured.", + vdev->device->name); return -ENODATA; } if (qid >= (int)priv->nr_virtqs) { - DRV_LOG(ERR, "Too big vring id: %d.", qid); + DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid, + vdev->device->name); return -E2BIG; } if (!priv->caps.queue_counters_valid) { - DRV_LOG(ERR, "Virtq statistics is not supported for device %d.", - did); + DRV_LOG(ERR, "Virtq statistics is not supported for device %s.", + vdev->device->name); return -ENOTSUP; } return mlx5_vdpa_virtq_stats_reset(priv, qid); @@ -687,8 +712,9 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, DRV_LOG(ERR, "Failed to allocate VAR %u.\n", errno); goto error; } - priv->id = rte_vdpa_register_device(&pci_dev->device, &mlx5_vdpa_ops); - if (priv->id < 0) { + priv->vdev = rte_vdpa_register_device(&pci_dev->device, + &mlx5_vdpa_ops); + if (priv->vdev == NULL) { DRV_LOG(ERR, "Failed to register vDPA device."); rte_errno = rte_errno ? rte_errno : EINVAL; goto error; diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index 5fc801eff3..ea09576c5a 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -103,7 +103,7 @@ struct mlx5_vdpa_priv { TAILQ_ENTRY(mlx5_vdpa_priv) next; uint8_t configured; uint8_t direct_notifier; /* Whether direct notifier is on or off. */ - int id; /* vDPA device id. */ + struct rte_vdpa_device *vdev; /* vDPA device. */ int vid; /* vhost device id. */ struct ibv_context *ctx; /* Device context. */ struct rte_pci_device *pci_dev; diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index e72f6646e7..bdb00603cc 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -291,13 +291,13 @@ static void cmd_list_vdpa_devices_parsed( vdev = rte_vdpa_get_device(did); if (!vdev) continue; - if (vdev->ops->get_queue_num(did, &queue_num) < 0) { + if (vdev->ops->get_queue_num(vdev, &queue_num) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa queue number " "for device id %d.\n", did); continue; } - if (vdev->ops->get_features(did, &features) < 0) { + if (vdev->ops->get_features(vdev, &features) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa features " "for device id %d.\n", did); diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index b752dfeb96..109cf83b8f 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -21,6 +21,8 @@ /** Maximum name length for statistics counters */ #define RTE_VDPA_STATS_NAME_SIZE 64 +struct rte_vdpa_device; + /** * A vDPA device statistic structure * @@ -51,13 +53,14 @@ struct rte_vdpa_stat_name { */ struct rte_vdpa_dev_ops { /** Get capabilities of this device */ - int (*get_queue_num)(int did, uint32_t *queue_num); + int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num); /** Get supported features of this device */ - int (*get_features)(int did, uint64_t *features); + int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features); /** Get supported protocol features of this device */ - int (*get_protocol_features)(int did, uint64_t *protocol_features); + int (*get_protocol_features)(struct rte_vdpa_device *dev, + uint64_t *protocol_features); /** Driver configure/close the device */ int (*dev_conf)(int vid); @@ -83,15 +86,16 @@ struct rte_vdpa_dev_ops { uint64_t *offset, uint64_t *size); /** Get statistics name */ - int (*get_stats_names)(int did, struct rte_vdpa_stat_name *stats_names, - unsigned int size); + int (*get_stats_names)(struct rte_vdpa_device *dev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size); /** Get statistics of the queue */ - int (*get_stats)(int did, int qid, struct rte_vdpa_stat *stats, - unsigned int n); + int (*get_stats)(struct rte_vdpa_device *dev, int qid, + struct rte_vdpa_stat *stats, unsigned int n); /** Reset statistics of the queue */ - int (*reset_stats)(int did, int qid); + int (*reset_stats)(struct rte_vdpa_device *dev, int qid); /** Reserved for future extension */ void *reserved[2]; @@ -118,10 +122,10 @@ struct rte_vdpa_device { * @param ops * the vdpa device operations * @return - * device id on success, -1 on failure + * vDPA device pointer on success, NULL on failure */ __rte_experimental -int +struct rte_vdpa_device * rte_vdpa_register_device(struct rte_device *rte_dev, struct rte_vdpa_dev_ops *ops); @@ -132,13 +136,13 @@ rte_vdpa_register_device(struct rte_device *rte_dev, * Unregister a vdpa device * * @param did - * vdpa device id + * vDPA device pointer * @return * device id on success, -1 on failure */ __rte_experimental int -rte_vdpa_unregister_device(int did); +rte_vdpa_unregister_device(struct rte_vdpa_device *); /** * @warning diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 0a66ef9767..da575b608c 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -712,7 +712,7 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features) goto unlock_exit; } - if (vdpa_dev->ops->get_features(did, &vdpa_features) < 0) { + if (vdpa_dev->ops->get_features(vdpa_dev, &vdpa_features) < 0) { VHOST_LOG_CONFIG(ERR, "failed to get vdpa features " "for socket file %s.\n", path); @@ -767,7 +767,7 @@ rte_vhost_driver_get_protocol_features(const char *path, goto unlock_exit; } - if (vdpa_dev->ops->get_protocol_features(did, + if (vdpa_dev->ops->get_protocol_features(vdpa_dev, &vdpa_protocol_features) < 0) { VHOST_LOG_CONFIG(ERR, "failed to get vdpa protocol features " @@ -809,7 +809,7 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num) goto unlock_exit; } - if (vdpa_dev->ops->get_queue_num(did, &vdpa_queue_num) < 0) { + if (vdpa_dev->ops->get_queue_num(vdpa_dev, &vdpa_queue_num) < 0) { VHOST_LOG_CONFIG(ERR, "failed to get vdpa queue number " "for socket file %s.\n", path); diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 87334c88c0..49ada00277 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -18,52 +18,6 @@ static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; static uint32_t vdpa_device_num; -int -rte_vdpa_register_device(struct rte_device *rte_dev, - struct rte_vdpa_dev_ops *ops) -{ - struct rte_vdpa_device *dev; - int i; - - if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL) - return -1; - - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - dev = &vdpa_devices[i]; - if (dev->ops == NULL) - continue; - - if (dev->device == rte_dev) - return -1; - } - - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - if (vdpa_devices[i].ops == NULL) - break; - } - - if (i == MAX_VHOST_DEVICE) - return -1; - - dev = &vdpa_devices[i]; - dev->device = rte_dev; - dev->ops = ops; - vdpa_device_num++; - - return i; -} - -int -rte_vdpa_unregister_device(int did) -{ - if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did].ops == NULL) - return -1; - - memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); - vdpa_device_num--; - - return did; -} int rte_vdpa_find_device_id(struct rte_vdpa_device *dev) @@ -116,6 +70,55 @@ rte_vdpa_get_device(int did) return &vdpa_devices[did]; } +struct rte_vdpa_device * +rte_vdpa_register_device(struct rte_device *rte_dev, + struct rte_vdpa_dev_ops *ops) +{ + struct rte_vdpa_device *dev; + int i; + + if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL) + return NULL; + + for (i = 0; i < MAX_VHOST_DEVICE; i++) { + dev = &vdpa_devices[i]; + if (dev->ops == NULL) + continue; + + if (dev->device == rte_dev) + return NULL; + } + + for (i = 0; i < MAX_VHOST_DEVICE; i++) { + if (vdpa_devices[i].ops == NULL) + break; + } + + if (i == MAX_VHOST_DEVICE) + return NULL; + + dev = &vdpa_devices[i]; + dev->device = rte_dev; + dev->ops = ops; + vdpa_device_num++; + + return dev; +} + +int +rte_vdpa_unregister_device(struct rte_vdpa_device *vdev) +{ + int did = rte_vdpa_find_device_id(vdev); + + if (did < 0 || vdpa_devices[did].ops == NULL) + return -1; + + memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); + vdpa_device_num--; + + return 0; +} + int rte_vdpa_get_device_num(void) { @@ -236,7 +239,7 @@ rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats_names, -ENOTSUP); - return vdpa_dev->ops->get_stats_names(did, stats_names, size); + return vdpa_dev->ops->get_stats_names(vdpa_dev, stats_names, size); } int @@ -254,7 +257,7 @@ rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats, RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats, -ENOTSUP); - return vdpa_dev->ops->get_stats(did, qid, stats, n); + return vdpa_dev->ops->get_stats(vdpa_dev, qid, stats, n); } int @@ -268,7 +271,7 @@ rte_vdpa_reset_stats(int did, uint16_t qid) RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->reset_stats, -ENOTSUP); - return vdpa_dev->ops->reset_stats(did, qid); + return vdpa_dev->ops->reset_stats(vdpa_dev, qid); } static uint16_t From patchwork Fri Jun 26 13:27:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72237 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 54E5EA051C; Fri, 26 Jun 2020 15:28:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A44A61BFC1; Fri, 26 Jun 2020 15:28:38 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 8BA611BFBA for ; Fri, 26 Jun 2020 15:28:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178117; 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=OxDM6oxq26O6xQfwyzL1uhxUA1T/3N8FSBILErxRHWo=; b=hK+EH//UCM+xhBHMfXuHJKJ/fVQPy2mlYipd2ZWsSLat8f+irUJrU/2ijDulQe4S54aIkm 927PzNHQKygAxvEYCEVbUB0ezWb+xRZMFjIUo/+l4p12wBg67dT/xxMSbaEtN/F9NvaJLi sWvCdHnx+t+Lei3JEgaYHfx3VZiji58= 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-151-25Q8t57KPtS6qdYFYuuNWA-1; Fri, 26 Jun 2020 09:28:35 -0400 X-MC-Unique: 25Q8t57KPtS6qdYFYuuNWA-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 846ED105251D; Fri, 26 Jun 2020 13:28:26 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F9065C663; Fri, 26 Jun 2020 13:28:23 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:04 +0200 Message-Id: <20200626132712.1437673-7-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 06/14] vhost: replace vDPA device ID in Vhost 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 removes the notion of device ID in Vhost library as a preliminary step to get rid of the vDPA device ID. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- drivers/vdpa/ifc/ifcvf_vdpa.c | 12 ++++---- drivers/vdpa/mlx5/mlx5_vdpa.c | 18 ++++------- examples/vdpa/main.c | 9 +++++- lib/librte_vhost/rte_vhost.h | 20 ++++++------ lib/librte_vhost/rte_vhost_version.map | 4 +-- lib/librte_vhost/socket.c | 42 ++++++++++---------------- lib/librte_vhost/vhost.c | 19 +++++------- lib/librte_vhost/vhost.h | 8 ++--- lib/librte_vhost/vhost_user.c | 28 +++++------------ 9 files changed, 66 insertions(+), 94 deletions(-) diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index 0418f9a07f..4163047744 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -881,7 +881,7 @@ ifcvf_dev_config(int vid) struct internal_list *list; struct ifcvf_internal *internal; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -907,7 +907,7 @@ ifcvf_dev_close(int vid) struct internal_list *list; struct ifcvf_internal *internal; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -947,7 +947,7 @@ ifcvf_set_features(int vid) struct ifcvf_internal *internal; uint64_t log_base = 0, log_size = 0; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -978,7 +978,7 @@ ifcvf_get_vfio_group_fd(int vid) struct rte_vdpa_device *vdev; struct internal_list *list; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -994,7 +994,7 @@ ifcvf_get_vfio_device_fd(int vid) struct rte_vdpa_device *vdev; struct internal_list *list; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -1013,7 +1013,7 @@ ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) struct vfio_region_info reg = { .argsz = sizeof(reg) }; int ret; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index 9ea032d57b..47db5fd6f4 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -129,8 +129,7 @@ mlx5_vdpa_get_protocol_features(struct rte_vdpa_device *vdev, static int mlx5_vdpa_set_vring_state(int vid, int vring, int state) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); @@ -171,8 +170,7 @@ mlx5_vdpa_direct_db_prepare(struct mlx5_vdpa_priv *priv) static int mlx5_vdpa_features_set(int vid) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); uint64_t log_base, log_size; @@ -292,8 +290,7 @@ mlx5_vdpa_mtu_set(struct mlx5_vdpa_priv *priv) static int mlx5_vdpa_dev_close(int vid) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); int ret = 0; @@ -322,8 +319,7 @@ mlx5_vdpa_dev_close(int vid) static int mlx5_vdpa_dev_config(int vid) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); @@ -354,8 +350,7 @@ mlx5_vdpa_dev_config(int vid) static int mlx5_vdpa_get_device_fd(int vid) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); @@ -369,8 +364,7 @@ mlx5_vdpa_get_device_fd(int vid) static int mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index bdb00603cc..6a719e32d8 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -149,6 +149,7 @@ start_vdpa(struct vdpa_port *vport) { int ret; char *socket_path = vport->ifname; + struct rte_vdpa_device *vdev; int did = vport->did; if (client_mode) @@ -173,7 +174,13 @@ start_vdpa(struct vdpa_port *vport) "register driver ops failed: %s\n", socket_path); - ret = rte_vhost_driver_attach_vdpa_device(socket_path, did); + vdev = rte_vdpa_get_device(did); + if (!vdev) + rte_exit(EXIT_FAILURE, + "vDPA device retrieval failed: %p\n", + vdev); + + ret = rte_vhost_driver_attach_vdpa_device(socket_path, vdev); if (ret != 0) rte_exit(EXIT_FAILURE, "attach vdpa device failed: %s\n", diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h index d43669f2c2..2fbc364643 100644 --- a/lib/librte_vhost/rte_vhost.h +++ b/lib/librte_vhost/rte_vhost.h @@ -90,6 +90,7 @@ extern "C" { #define VHOST_USER_F_PROTOCOL_FEATURES 30 #endif +struct rte_vdpa_device; /** * Information relating to memory regions including offsets to @@ -402,14 +403,15 @@ int rte_vhost_driver_unregister(const char *path); * * @param path * The vhost-user socket file path - * @param did - * Device id + * @param dev + * vDPA device pointer * @return * 0 on success, -1 on failure */ __rte_experimental int -rte_vhost_driver_attach_vdpa_device(const char *path, int did); +rte_vhost_driver_attach_vdpa_device(const char *path, + struct rte_vdpa_device *dev); /** * Unset the vdpa device id @@ -429,11 +431,11 @@ rte_vhost_driver_detach_vdpa_device(const char *path); * @param path * The vhost-user socket file path * @return - * Device id, -1 on failure + * vDPA device pointer, NULL on failure */ __rte_experimental -int -rte_vhost_driver_get_vdpa_device_id(const char *path); +struct rte_vdpa_device * +rte_vhost_driver_get_vdpa_device(const char *path); /** * Set the feature bits the vhost-user driver supports. @@ -977,11 +979,11 @@ rte_vhost_extern_callback_register(int vid, * @param vid * vhost device id * @return - * device id + * vDPA device pointer on success, NULL on failure */ __rte_experimental -int -rte_vhost_get_vdpa_device_id(int vid); +struct rte_vdpa_device * +rte_vhost_get_vdpa_device(int vid); /** * Notify the guest that should get virtio configuration space from backend. diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 9325ee4227..60d67445d7 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -43,8 +43,8 @@ EXPERIMENTAL { rte_vdpa_reset_stats; rte_vhost_driver_attach_vdpa_device; rte_vhost_driver_detach_vdpa_device; - rte_vhost_driver_get_vdpa_device_id; - rte_vhost_get_vdpa_device_id; + rte_vhost_driver_get_vdpa_device; + rte_vhost_get_vdpa_device; rte_vhost_driver_get_protocol_features; rte_vhost_driver_get_queue_num; rte_vhost_get_log_base; diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index da575b608c..49267cebf9 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -55,12 +55,7 @@ struct vhost_user_socket { uint64_t protocol_features; - /* - * Device id to identify a specific backend device. - * It's set to -1 for the default software implementation. - * If valid, one socket can have 1 connection only. - */ - int vdpa_dev_id; + struct rte_vdpa_device *vdpa_dev; struct vhost_device_ops const *notify_ops; }; @@ -230,7 +225,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net); - vhost_attach_vdpa_device(vid, vsocket->vdpa_dev_id); + vhost_attach_vdpa_device(vid, vsocket->vdpa_dev); if (vsocket->dequeue_zero_copy) vhost_enable_dequeue_zero_copy(vid); @@ -578,17 +573,18 @@ find_vhost_user_socket(const char *path) } int -rte_vhost_driver_attach_vdpa_device(const char *path, int did) +rte_vhost_driver_attach_vdpa_device(const char *path, + struct rte_vdpa_device *dev) { struct vhost_user_socket *vsocket; - if (rte_vdpa_get_device(did) == NULL || path == NULL) + if (dev == NULL || path == NULL) return -1; pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); if (vsocket) - vsocket->vdpa_dev_id = did; + vsocket->vdpa_dev = dev; pthread_mutex_unlock(&vhost_user.mutex); return vsocket ? 0 : -1; @@ -602,25 +598,25 @@ rte_vhost_driver_detach_vdpa_device(const char *path) pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); if (vsocket) - vsocket->vdpa_dev_id = -1; + vsocket->vdpa_dev = NULL; pthread_mutex_unlock(&vhost_user.mutex); return vsocket ? 0 : -1; } -int -rte_vhost_driver_get_vdpa_device_id(const char *path) +struct rte_vdpa_device * +rte_vhost_driver_get_vdpa_device(const char *path) { struct vhost_user_socket *vsocket; - int did = -1; + struct rte_vdpa_device *dev = NULL; pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); if (vsocket) - did = vsocket->vdpa_dev_id; + dev = vsocket->vdpa_dev; pthread_mutex_unlock(&vhost_user.mutex); - return did; + return dev; } int @@ -693,7 +689,6 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features) struct vhost_user_socket *vsocket; uint64_t vdpa_features; struct rte_vdpa_device *vdpa_dev; - int did = -1; int ret = 0; pthread_mutex_lock(&vhost_user.mutex); @@ -705,8 +700,7 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features) goto unlock_exit; } - did = vsocket->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = vsocket->vdpa_dev; if (!vdpa_dev || !vdpa_dev->ops->get_features) { *features = vsocket->features; goto unlock_exit; @@ -748,7 +742,6 @@ rte_vhost_driver_get_protocol_features(const char *path, struct vhost_user_socket *vsocket; uint64_t vdpa_protocol_features; struct rte_vdpa_device *vdpa_dev; - int did = -1; int ret = 0; pthread_mutex_lock(&vhost_user.mutex); @@ -760,8 +753,7 @@ rte_vhost_driver_get_protocol_features(const char *path, goto unlock_exit; } - did = vsocket->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = vsocket->vdpa_dev; if (!vdpa_dev || !vdpa_dev->ops->get_protocol_features) { *protocol_features = vsocket->protocol_features; goto unlock_exit; @@ -790,7 +782,6 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num) struct vhost_user_socket *vsocket; uint32_t vdpa_queue_num; struct rte_vdpa_device *vdpa_dev; - int did = -1; int ret = 0; pthread_mutex_lock(&vhost_user.mutex); @@ -802,8 +793,7 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num) goto unlock_exit; } - did = vsocket->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = vsocket->vdpa_dev; if (!vdpa_dev || !vdpa_dev->ops->get_queue_num) { *queue_num = VHOST_MAX_QUEUE_PAIRS; goto unlock_exit; @@ -878,7 +868,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) "error: failed to init connection mutex\n"); goto out_free; } - vsocket->vdpa_dev_id = -1; + vsocket->vdpa_dev = NULL; vsocket->dequeue_zero_copy = flags & RTE_VHOST_USER_DEQUEUE_ZERO_COPY; vsocket->extbuf = flags & RTE_VHOST_USER_EXTBUF_SUPPORT; vsocket->linearbuf = flags & RTE_VHOST_USER_LINEARBUF_SUPPORT; diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 0266318440..0d822d6a3f 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -633,7 +633,6 @@ vhost_new_device(void) dev->vid = i; dev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET; dev->slave_req_fd = -1; - dev->vdpa_dev_id = -1; dev->postcopy_ufd = -1; rte_spinlock_init(&dev->slave_req_lock); @@ -644,11 +643,9 @@ void vhost_destroy_device_notify(struct virtio_net *dev) { struct rte_vdpa_device *vdpa_dev; - int did; if (dev->flags & VIRTIO_DEV_RUNNING) { - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && vdpa_dev->ops->dev_close) vdpa_dev->ops->dev_close(dev->vid); dev->flags &= ~VIRTIO_DEV_RUNNING; @@ -677,17 +674,14 @@ vhost_destroy_device(int vid) } void -vhost_attach_vdpa_device(int vid, int did) +vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *vdpa_dev) { struct virtio_net *dev = get_device(vid); if (dev == NULL) return; - if (rte_vdpa_get_device(did) == NULL) - return; - - dev->vdpa_dev_id = did; + dev->vdpa_dev = vdpa_dev; } void @@ -1402,14 +1396,15 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) return ret; } -int rte_vhost_get_vdpa_device_id(int vid) +struct rte_vdpa_device * +rte_vhost_get_vdpa_device(int vid) { struct virtio_net *dev = get_device(vid); if (dev == NULL) - return -1; + return NULL; - return dev->vdpa_dev_id; + return dev->vdpa_dev; } int rte_vhost_get_log_base(int vid, uint64_t *log_base, diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index df98d15de6..819857a65a 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -377,11 +377,7 @@ struct virtio_net { int postcopy_ufd; int postcopy_listening; - /* - * Device id to identify a specific backend device. - * It's set to -1 for the default software implementation. - */ - int vdpa_dev_id; + struct rte_vdpa_device *vdpa_dev; /* context data for the external message handlers */ void *extern_data; @@ -639,7 +635,7 @@ void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq); int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx); -void vhost_attach_vdpa_device(int vid, int did); +void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev); void vhost_set_ifname(int, const char *if_name, unsigned int if_len); void vhost_enable_dequeue_zero_copy(int vid); diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index ea9cd107b9..3405cd8c0b 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -315,7 +315,6 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, uint64_t features = msg->payload.u64; uint64_t vhost_features = 0; struct rte_vdpa_device *vdpa_dev; - int did = -1; if (validate_msg_fds(msg, 0) != 0) return RTE_VHOST_MSG_RESULT_ERR; @@ -384,8 +383,7 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, } } - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && vdpa_dev->ops->set_features) vdpa_dev->ops->set_features(dev->vid); @@ -1971,7 +1969,6 @@ vhost_user_set_vring_enable(struct virtio_net **pdev, int enable = (int)msg->payload.state.num; int index = (int)msg->payload.state.index; struct rte_vdpa_device *vdpa_dev; - int did = -1; if (validate_msg_fds(msg, 0) != 0) return RTE_VHOST_MSG_RESULT_ERR; @@ -1980,8 +1977,7 @@ vhost_user_set_vring_enable(struct virtio_net **pdev, "set queue enable: %d to qp idx: %d\n", enable, index); - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && vdpa_dev->ops->set_vring_state) vdpa_dev->ops->set_vring_state(dev->vid, index, enable); @@ -2147,7 +2143,6 @@ vhost_user_send_rarp(struct virtio_net **pdev, struct VhostUserMsg *msg, struct virtio_net *dev = *pdev; uint8_t *mac = (uint8_t *)&msg->payload.u64; struct rte_vdpa_device *vdpa_dev; - int did = -1; if (validate_msg_fds(msg, 0) != 0) return RTE_VHOST_MSG_RESULT_ERR; @@ -2165,8 +2160,7 @@ vhost_user_send_rarp(struct virtio_net **pdev, struct VhostUserMsg *msg, * copied before the flag is set. */ __atomic_store_n(&dev->broadcast_rarp, 1, __ATOMIC_RELEASE); - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && vdpa_dev->ops->migration_done) vdpa_dev->ops->migration_done(dev->vid); @@ -2613,7 +2607,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; @@ -2805,8 +2798,7 @@ vhost_user_msg_handler(int vid, int fd) } } - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) && msg.request.master == VHOST_USER_SET_VRING_CALL) { @@ -2955,7 +2947,7 @@ int rte_vhost_host_notifier_ctrl(int vid, bool enable) { struct virtio_net *dev; struct rte_vdpa_device *vdpa_dev; - int vfio_device_fd, did, ret = 0; + int vfio_device_fd, ret = 0; uint64_t offset, size; unsigned int i; @@ -2963,9 +2955,9 @@ int rte_vhost_host_notifier_ctrl(int vid, bool enable) if (!dev) return -ENODEV; - did = dev->vdpa_dev_id; - if (did < 0) - return -EINVAL; + vdpa_dev = dev->vdpa_dev; + if (vdpa_dev == NULL) + return -ENODEV; if (!(dev->features & (1ULL << VIRTIO_F_VERSION_1)) || !(dev->features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) || @@ -2977,10 +2969,6 @@ int rte_vhost_host_notifier_ctrl(int vid, bool enable) (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER))) return -ENOTSUP; - vdpa_dev = rte_vdpa_get_device(did); - if (!vdpa_dev) - return -ENODEV; - RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_vfio_device_fd, -ENOTSUP); RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_notify_area, -ENOTSUP); From patchwork Fri Jun 26 13:27:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72238 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 0C2EBA051C; Fri, 26 Jun 2020 15:29:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5441B1BFC0; Fri, 26 Jun 2020 15:28:47 +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 AED161BF90 for ; Fri, 26 Jun 2020 15:28:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178125; 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=EoLSLw8Uy2YifsLR+6MZOT/F84WTwiMFvINty31VZPk=; b=jMbOgKu0QMZxNMTg404x7n/yBBNr+2bmNVMmOkcEegYRpAXqemz9WTGG7/WJAfFQhcVHcT V93Zy13kJxR4KbjquEzyIGM03BNaRMLvYpdaPtXdkjf1rxfLCsQ/2N/H9fwhtDODDkiBld 6/3rPwKUMzhwDQNyVrC3OUhOJhX6J4g= 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-273-JLYqiHhINiWoNemFTP_UnQ-1; Fri, 26 Jun 2020 09:28:43 -0400 X-MC-Unique: JLYqiHhINiWoNemFTP_UnQ-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id CCC6080453F; Fri, 26 Jun 2020 13:28:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id D29E458; Fri, 26 Jun 2020 13:28:26 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:05 +0200 Message-Id: <20200626132712.1437673-8-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 07/14] vhost: replace device ID in applications 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 replaces the use of vDPA device ID with vDPA device pointer. The goals is to remove the vDPA device ID to avoid condusion with the Vhost ID. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- examples/vdpa/main.c | 118 +++++++++++++------------ lib/librte_vhost/rte_vdpa.h | 44 ++++++--- lib/librte_vhost/rte_vhost_version.map | 3 +- lib/librte_vhost/vdpa.c | 64 +++++++------- 4 files changed, 123 insertions(+), 106 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 6a719e32d8..54f4940b31 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -27,7 +27,7 @@ struct vdpa_port { char ifname[MAX_PATH_LEN]; - int did; + struct rte_vdpa_device *dev; int vid; uint64_t flags; int stats_n; @@ -105,16 +105,23 @@ static int new_device(int vid) { char ifname[MAX_PATH_LEN]; + struct rte_device *dev; int i; rte_vhost_get_ifname(vid, ifname, sizeof(ifname)); for (i = 0; i < MAX_VDPA_SAMPLE_PORTS; i++) { - if (strncmp(ifname, vports[i].ifname, MAX_PATH_LEN) == 0) { - printf("\nnew port %s, did: %d\n", - ifname, vports[i].did); - vports[i].vid = vid; - break; + if (strncmp(ifname, vports[i].ifname, MAX_PATH_LEN)) + continue; + + dev = rte_vdpa_get_rte_device(vports[i].dev); + if (!dev) { + RTE_LOG(ERR, VDPA, + "Failed to get generic device for port %d\n", i); + continue; } + printf("\nnew port %s, device : %s\n", ifname, dev->name); + vports[i].vid = vid; + break; } if (i >= MAX_VDPA_SAMPLE_PORTS) @@ -126,16 +133,24 @@ new_device(int vid) static void destroy_device(int vid) { + struct rte_device *dev; char ifname[MAX_PATH_LEN]; int i; rte_vhost_get_ifname(vid, ifname, sizeof(ifname)); for (i = 0; i < MAX_VDPA_SAMPLE_PORTS; i++) { - if (strcmp(ifname, vports[i].ifname) == 0) { - printf("\ndestroy port %s, did: %d\n", - ifname, vports[i].did); - break; + if (strncmp(ifname, vports[i].ifname, MAX_PATH_LEN)) + continue; + + dev = rte_vdpa_get_rte_device(vports[i].dev); + if (!dev) { + RTE_LOG(ERR, VDPA, + "Failed to get generic device for port %d\n", i); + continue; } + + printf("\ndestroy port %s, device: %s\n", ifname, dev->name); + break; } } @@ -149,8 +164,6 @@ start_vdpa(struct vdpa_port *vport) { int ret; char *socket_path = vport->ifname; - struct rte_vdpa_device *vdev; - int did = vport->did; if (client_mode) vport->flags |= RTE_VHOST_USER_CLIENT; @@ -174,13 +187,7 @@ start_vdpa(struct vdpa_port *vport) "register driver ops failed: %s\n", socket_path); - vdev = rte_vdpa_get_device(did); - if (!vdev) - rte_exit(EXIT_FAILURE, - "vDPA device retrieval failed: %p\n", - vdev); - - ret = rte_vhost_driver_attach_vdpa_device(socket_path, vdev); + ret = rte_vhost_driver_attach_vdpa_device(socket_path, vport->dev); if (ret != 0) rte_exit(EXIT_FAILURE, "attach vdpa device failed: %s\n", @@ -283,35 +290,31 @@ static void cmd_list_vdpa_devices_parsed( struct cmdline *cl, __rte_unused void *data) { - int did; uint32_t queue_num; uint64_t features; struct rte_vdpa_device *vdev; struct rte_device *dev; struct rte_dev_iterator dev_iter; - cmdline_printf(cl, "device id\tdevice name\tqueue num\tsupported features\n"); + cmdline_printf(cl, "device name\tqueue num\tsupported features\n"); RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { - did = rte_vdpa_find_device_id_by_name(dev->name); - if (did < 0) - continue; - vdev = rte_vdpa_get_device(did); + vdev = rte_vdpa_find_device_by_name(dev->name); if (!vdev) continue; if (vdev->ops->get_queue_num(vdev, &queue_num) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa queue number " - "for device id %d.\n", did); + "for device %s.\n", dev->name); continue; } if (vdev->ops->get_features(vdev, &features) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa features " - "for device id %d.\n", did); + "for device %s.\n", dev->name); continue; } - cmdline_printf(cl, "%d\t\t%s\t\t%" PRIu32 "\t\t0x%" PRIx64 "\n", - did, dev->name, queue_num, features); + cmdline_printf(cl, "%s\t\t%" PRIu32 "\t\t0x%" PRIx64 "\n", + dev->name, queue_num, features); } } @@ -339,18 +342,18 @@ static void cmd_create_vdpa_port_parsed(void *parsed_result, struct cmdline *cl, __rte_unused void *data) { - int did; + struct rte_vdpa_device *dev; struct cmd_create_result *res = parsed_result; rte_strscpy(vports[devcnt].ifname, res->socket_path, MAX_PATH_LEN); - did = rte_vdpa_find_device_id_by_name(res->bdf); - if (did < 0) { + dev = rte_vdpa_find_device_by_name(res->bdf); + if (dev == NULL) { cmdline_printf(cl, "Unable to find vdpa device id for %s.\n", res->bdf); return; } - vports[devcnt].did = did; + vports[devcnt].dev = dev; if (start_vdpa(&vports[devcnt]) == 0) devcnt++; @@ -378,7 +381,7 @@ cmdline_parse_inst_t cmd_create_vdpa_port = { /* *** STATS *** */ struct cmd_stats_result { cmdline_fixed_string_t stats; - uint16_t did; + cmdline_fixed_string_t bdf; uint16_t qid; }; @@ -386,25 +389,24 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, __rte_unused void *data) { struct cmd_stats_result *res = parsed_result; - struct rte_vdpa_device *vdev = rte_vdpa_get_device(res->did); + struct rte_vdpa_device *vdev = rte_vdpa_find_device_by_name(res->bdf); struct vdpa_port *vport = NULL; uint32_t first, last; int i; if (!vdev) { - RTE_LOG(ERR, VDPA, "Invalid device id %" PRIu16 ".\n", - res->did); + RTE_LOG(ERR, VDPA, "Invalid device: %s.\n", + res->bdf); return; } for (i = 0; i < RTE_MIN(MAX_VDPA_SAMPLE_PORTS, dev_total); i++) { - if (vports[i].did == res->did) { + if (vports[i].dev == vdev) { vport = &vports[i]; break; } } if (!vport) { - RTE_LOG(ERR, VDPA, "Device id %" PRIu16 " was not created.\n", - res->did); + RTE_LOG(ERR, VDPA, "Device %s was not created.\n", res->bdf); return; } if (res->qid == 0xFFFF) { @@ -412,7 +414,7 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, last = rte_vhost_get_vring_num(vport->vid); if (last == 0) { RTE_LOG(ERR, VDPA, "Failed to get num of actual virtqs" - " for device id %d.\n", (int)res->did); + " for device %s.\n", res->bdf); return; } last--; @@ -421,10 +423,10 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, last = res->qid; } if (!vport->stats_names) { - vport->stats_n = rte_vdpa_get_stats_names(vport->did, NULL, 0); + vport->stats_n = rte_vdpa_get_stats_names(vport->dev, NULL, 0); if (vport->stats_n <= 0) { RTE_LOG(ERR, VDPA, "Failed to get names number of " - "device %d stats.\n", (int)res->did); + "device %s stats.\n", res->bdf); return; } vport->stats_names = rte_zmalloc(NULL, @@ -432,26 +434,26 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, vport->stats_n, 0); if (!vport->stats_names) { RTE_LOG(ERR, VDPA, "Failed to allocate memory for stat" - " names of device %d.\n", (int)res->did); + " names of device %s.\n", res->bdf); return; } - i = rte_vdpa_get_stats_names(vport->did, vport->stats_names, + i = rte_vdpa_get_stats_names(vport->dev, vport->stats_names, vport->stats_n); if (vport->stats_n != i) { - RTE_LOG(ERR, VDPA, "Failed to get names of device %d " - "stats.\n", (int)res->did); + RTE_LOG(ERR, VDPA, "Failed to get names of device %s " + "stats.\n", res->bdf); return; } vport->stats = (struct rte_vdpa_stat *) (vport->stats_names + vport->stats_n); } - cmdline_printf(cl, "\nDevice %d:\n", (int)res->did); + cmdline_printf(cl, "\nDevice %s:\n", res->bdf); for (; first <= last; first++) { memset(vport->stats, 0, sizeof(*vport->stats) * vport->stats_n); - if (rte_vdpa_get_stats(vport->did, (int)first, vport->stats, + if (rte_vdpa_get_stats(vport->dev, (int)first, vport->stats, vport->stats_n) <= 0) { RTE_LOG(ERR, VDPA, "Failed to get vdpa queue statistics" - " for device id %d qid %d.\n", (int)res->did, + " for device %s qid %d.\n", res->bdf, (int)first); return; } @@ -467,8 +469,8 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, cmdline_parse_token_string_t cmd_device_stats_ = TOKEN_STRING_INITIALIZER(struct cmd_stats_result, stats, "stats"); -cmdline_parse_token_num_t cmd_device_id = - TOKEN_NUM_INITIALIZER(struct cmd_stats_result, did, UINT32); +cmdline_parse_token_string_t cmd_device_bdf = + TOKEN_STRING_INITIALIZER(struct cmd_stats_result, bdf, NULL); cmdline_parse_token_num_t cmd_queue_id = TOKEN_NUM_INITIALIZER(struct cmd_stats_result, qid, UINT32); @@ -478,7 +480,7 @@ cmdline_parse_inst_t cmd_device_stats = { .help_str = "stats: show device statistics", .tokens = { (void *)&cmd_device_stats_, - (void *)&cmd_device_id, + (void *)&cmd_device_bdf, (void *)&cmd_queue_id, NULL, }, @@ -522,9 +524,9 @@ int main(int argc, char *argv[]) { char ch; - int did; int ret; struct cmdline *cl; + struct rte_vdpa_device *vdev; struct rte_device *dev; struct rte_dev_iterator dev_iter; @@ -553,12 +555,12 @@ main(int argc, char *argv[]) cmdline_stdin_exit(cl); } else { RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { - did = rte_vdpa_find_device_id_by_name(dev->name); - if (did < 0) { - rte_panic("Failed to find device id for %s\n", + vdev = rte_vdpa_find_device_by_name(dev->name); + if (vdev == NULL) { + rte_panic("Failed to find vDPA dev for %s\n", dev->name); } - vports[devcnt].did = did; + vports[devcnt].dev = vdev; snprintf(vports[devcnt].ifname, MAX_PATH_LEN, "%s%d", iface, devcnt); diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index 109cf83b8f..549b0a2cb0 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -153,11 +153,26 @@ rte_vdpa_unregister_device(struct rte_vdpa_device *); * @param name * the vdpa device name * @return - * device id on success, -1 on failure + * vDPA device pointer on success, NULL on failure */ __rte_experimental -int -rte_vdpa_find_device_id_by_name(const char *name); +struct rte_vdpa_device * +rte_vdpa_find_device_by_name(const char *name); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Get the generic device from the vdpa device + * + * @param vdpa_dev + * the vdpa device pointer + * @return + * generic device pointer on success, NULL on failure + */ +__rte_experimental +struct rte_device * +rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev); /** * @warning @@ -252,8 +267,8 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); * And the array index is same with id field of 'struct rte_vdpa_stat': * stats[i].id == i * - * @param did - * device id + * @param dev + * vDPA device pointer * @param stats_names * array of at least size elements to be filled. * If set to NULL, the function returns the required number of elements. @@ -265,8 +280,9 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); */ __rte_experimental int -rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, - unsigned int size); +rte_vdpa_get_stats_names(struct rte_vdpa_device *dev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size); /** * @warning @@ -280,8 +296,8 @@ rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, * And the array index is same with id field of 'struct rte_vdpa_stat': * stats[i].id == i * - * @param did - * device id + * @param dev + * vDPA device pointer * @param qid * queue id * @param stats @@ -295,16 +311,16 @@ rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, */ __rte_experimental int -rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats, - unsigned int n); +rte_vdpa_get_stats(struct rte_vdpa_device *dev, uint16_t qid, + struct rte_vdpa_stat *stats, unsigned int n); /** * @warning * @b EXPERIMENTAL: this API may change without prior notice * * Reset statistics of a vDPA device. * - * @param did - * device id + * @param dev + * vDPA device pointer * @param qid * queue id * @return @@ -312,5 +328,5 @@ rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats, */ __rte_experimental int -rte_vdpa_reset_stats(int did, uint16_t qid); +rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid); #endif /* _RTE_VDPA_H_ */ diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 60d67445d7..ba55f6f421 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -69,5 +69,6 @@ EXPERIMENTAL { rte_vhost_get_vhost_ring_inflight; rte_vhost_get_vring_base_from_inflight; rte_vhost_slave_config_change; - rte_vdpa_find_device_id_by_name; + rte_vdpa_find_device_by_name; + rte_vdpa_get_rte_device; }; diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 49ada00277..cececc3098 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -40,14 +40,14 @@ rte_vdpa_find_device_id(struct rte_vdpa_device *dev) return -1; } -int -rte_vdpa_find_device_id_by_name(const char *name) +struct rte_vdpa_device * +rte_vdpa_find_device_by_name(const char *name) { struct rte_vdpa_device *dev; int i; if (name == NULL) - return -1; + return NULL; for (i = 0; i < MAX_VHOST_DEVICE; ++i) { dev = &vdpa_devices[i]; @@ -55,10 +55,19 @@ rte_vdpa_find_device_id_by_name(const char *name) continue; if (strncmp(dev->device->name, name, RTE_DEV_NAME_MAX_LEN) == 0) - return i; + return dev; } - return -1; + return NULL; +} + +struct rte_device * +rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev) +{ + if (vdpa_dev == NULL) + return NULL; + + return vdpa_dev->device; } struct rte_vdpa_device * @@ -228,50 +237,39 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m) } int -rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, - unsigned int size) +rte_vdpa_get_stats_names(struct rte_vdpa_device *dev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size) { - struct rte_vdpa_device *vdpa_dev; - - vdpa_dev = rte_vdpa_get_device(did); - if (!vdpa_dev) - return -ENODEV; + if (!dev) + return -EINVAL; - RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats_names, -ENOTSUP); + RTE_FUNC_PTR_OR_ERR_RET(dev->ops->get_stats_names, -ENOTSUP); - return vdpa_dev->ops->get_stats_names(vdpa_dev, stats_names, size); + return dev->ops->get_stats_names(dev, stats_names, size); } int -rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats, - unsigned int n) +rte_vdpa_get_stats(struct rte_vdpa_device *dev, uint16_t qid, + struct rte_vdpa_stat *stats, unsigned int n) { - struct rte_vdpa_device *vdpa_dev; - - vdpa_dev = rte_vdpa_get_device(did); - if (!vdpa_dev) - return -ENODEV; - - if (!stats || !n) + if (!dev || !stats || !n) return -EINVAL; - RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats, -ENOTSUP); + RTE_FUNC_PTR_OR_ERR_RET(dev->ops->get_stats, -ENOTSUP); - return vdpa_dev->ops->get_stats(vdpa_dev, qid, stats, n); + return dev->ops->get_stats(dev, qid, stats, n); } int -rte_vdpa_reset_stats(int did, uint16_t qid) +rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid) { - struct rte_vdpa_device *vdpa_dev; - - vdpa_dev = rte_vdpa_get_device(did); - if (!vdpa_dev) - return -ENODEV; + if (!dev) + return -EINVAL; - RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->reset_stats, -ENOTSUP); + RTE_FUNC_PTR_OR_ERR_RET(dev->ops->reset_stats, -ENOTSUP); - return vdpa_dev->ops->reset_stats(vdpa_dev, qid); + return dev->ops->reset_stats(dev, qid); } static uint16_t From patchwork Fri Jun 26 13:27:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72239 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 99C9BA051C; Fri, 26 Jun 2020 15:29:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AF3AB1BF9D; Fri, 26 Jun 2020 15:28:51 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 34D431BF9F for ; Fri, 26 Jun 2020 15:28:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178125; 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=q1XSETQVDQnGniiRePqT4QGY/XDWt4QmYXIv+adPXPM=; b=DnilCVh5ynM90lagOK6ecuviT+dH+/0pb2Iqeo1v/VdoyNFvlYV4KwBIgZ8R3HenW7WTOf +hFS+xXFpR6dZwCfDj/B7qFHNJZHnbLaMZ92oxYAHbSAiSQNXNVZmaJfVethF9MYbCspOq T5JqhU7LCagQxsbJsu/lhI9VJ+IYaFA= 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-8-rrBCH_GkPjS9uSuTid8B0Q-1; Fri, 26 Jun 2020 09:28:40 -0400 X-MC-Unique: rrBCH_GkPjS9uSuTid8B0Q-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1ACE1100CCF2; Fri, 26 Jun 2020 13:28:37 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34E5A1E4; Fri, 26 Jun 2020 13:28:33 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:06 +0200 Message-Id: <20200626132712.1437673-9-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 v3 08/14] vhost: remove useless vDPA API 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" vDPA is no more used outside of the vDPA internals, so remove rte_vdpa_get_device() API that is now useless. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- lib/librte_vhost/rte_vdpa.h | 30 ----------------- lib/librte_vhost/rte_vhost_version.map | 1 - lib/librte_vhost/vdpa.c | 46 ++++++-------------------- 3 files changed, 10 insertions(+), 67 deletions(-) diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index 549b0a2cb0..da8ee33ab1 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -174,36 +174,6 @@ __rte_experimental struct rte_device * rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev); -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Find the device id of a vdpa device - * - * @param addr - * the vdpa device address - * @return - * device id on success, -1 on failure - */ -__rte_experimental -int -rte_vdpa_find_device_id(struct rte_vdpa_device *dev); - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Find a vdpa device based on device id - * - * @param did - * device id - * @return - * rte_vdpa_device on success, NULL on failure - */ -__rte_experimental -struct rte_vdpa_device * -rte_vdpa_get_device(int did); - /** * @warning * @b EXPERIMENTAL: this API may change without prior notice diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index ba55f6f421..d9124d0462 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -36,7 +36,6 @@ EXPERIMENTAL { rte_vdpa_register_device; rte_vdpa_unregister_device; rte_vdpa_find_device_id; - rte_vdpa_get_device; rte_vdpa_get_device_num; rte_vdpa_get_stats_names; rte_vdpa_get_stats; diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index cececc3098..bed20a3103 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -19,27 +19,6 @@ static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; static uint32_t vdpa_device_num; -int -rte_vdpa_find_device_id(struct rte_vdpa_device *dev) -{ - struct rte_vdpa_device *tmp_dev; - int i; - - if (dev == NULL) - return -1; - - for (i = 0; i < MAX_VHOST_DEVICE; ++i) { - tmp_dev = &vdpa_devices[i]; - if (tmp_dev->ops == NULL) - continue; - - if (tmp_dev == dev) - return i; - } - - return -1; -} - struct rte_vdpa_device * rte_vdpa_find_device_by_name(const char *name) { @@ -70,15 +49,6 @@ rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev) return vdpa_dev->device; } -struct rte_vdpa_device * -rte_vdpa_get_device(int did) -{ - if (did < 0 || did >= MAX_VHOST_DEVICE) - return NULL; - - return &vdpa_devices[did]; -} - struct rte_vdpa_device * rte_vdpa_register_device(struct rte_device *rte_dev, struct rte_vdpa_dev_ops *ops) @@ -117,15 +87,19 @@ rte_vdpa_register_device(struct rte_device *rte_dev, int rte_vdpa_unregister_device(struct rte_vdpa_device *vdev) { - int did = rte_vdpa_find_device_id(vdev); + int i; - if (did < 0 || vdpa_devices[did].ops == NULL) - return -1; + for (i = 0; i < MAX_VHOST_DEVICE; i++) { + if (vdev != &vdpa_devices[i]) + continue; - memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); - vdpa_device_num--; + memset(vdev, 0, sizeof(struct rte_vdpa_device)); + vdpa_device_num--; - return 0; + return 0; + } + + return -1; } int From patchwork Fri Jun 26 13:27:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72241 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 A1ED4A051C; Fri, 26 Jun 2020 15:29:41 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id ACF241BFA4; Fri, 26 Jun 2020 15:29:06 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 2B9E01BF94 for ; Fri, 26 Jun 2020 15:28:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178132; 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=VDzLNPqsaU7mTSZzb+fLuktRdsbWvJEioLIxrp1BFUQ=; b=dVpvOxkyPxh28i1b8tINIUnb8ouBXlYKclo03lhc6K+uYiViF6jI4zi1a5Ol55GCGdPmQI F4Df1ivqfkjvFRm6HrreX6z183VxJx23BNpCo/JsGTx4GXn8kNnBed/lMzK5vtnDaNaAPp Cp8CsnIFNpd33RPfYRFkwHH+jrXHR8Q= 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-246-iM5iOue1P6e4eTFrUIZE9g-1; Fri, 26 Jun 2020 09:28:51 -0400 X-MC-Unique: iM5iOue1P6e4eTFrUIZE9g-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B569D18CA26C; Fri, 26 Jun 2020 13:28:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 649305C557; Fri, 26 Jun 2020 13:28:37 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:07 +0200 Message-Id: <20200626132712.1437673-10-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 09/14] vhost: use linked-list for vDPA devices 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" There is no more notion of device ID outside of vdpa.c. We can now move from array to linked-list model for keeping track of the vDPA devices. There is no point in using array here, as all vDPA API are used from the control path, so no performance concerns. Signed-off-by: Maxime Coquelin --- lib/librte_vhost/rte_vdpa.h | 1 + lib/librte_vhost/vdpa.c | 134 +++++++++++++++++++----------------- 2 files changed, 70 insertions(+), 65 deletions(-) diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index da8ee33ab1..dbdc273702 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -105,6 +105,7 @@ struct rte_vdpa_dev_ops { * vdpa device structure includes device address and device operations. */ struct rte_vdpa_device { + TAILQ_ENTRY(rte_vdpa_device) next; /** Generic device information */ struct rte_device *device; /** vdpa device operations */ diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index bed20a3103..49e3654380 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -9,35 +9,54 @@ */ #include +#include #include #include +#include +#include + #include "rte_vdpa.h" #include "vhost.h" -static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; +/** Double linked list of vDPA devices. */ +TAILQ_HEAD(vdpa_device_list, rte_vdpa_device); + +static struct vdpa_device_list vdpa_device_list = + TAILQ_HEAD_INITIALIZER(vdpa_device_list); +static rte_spinlock_t vdpa_device_list_lock = RTE_SPINLOCK_INITIALIZER; static uint32_t vdpa_device_num; -struct rte_vdpa_device * -rte_vdpa_find_device_by_name(const char *name) +/* Unsafe, needs to be called with vdpa_device_list_lock held */ +static struct rte_vdpa_device * +__vdpa_find_device_by_name(const char *name) { - struct rte_vdpa_device *dev; - int i; + struct rte_vdpa_device *dev, *ret = NULL; if (name == NULL) return NULL; - for (i = 0; i < MAX_VHOST_DEVICE; ++i) { - dev = &vdpa_devices[i]; - if (dev->ops == NULL) - continue; - - if (strncmp(dev->device->name, name, RTE_DEV_NAME_MAX_LEN) == 0) - return dev; + TAILQ_FOREACH(dev, &vdpa_device_list, next) { + if (!strncmp(dev->device->name, name, RTE_DEV_NAME_MAX_LEN)) { + ret = dev; + break; + } } - return NULL; + return ret; +} + +struct rte_vdpa_device * +rte_vdpa_find_device_by_name(const char *name) +{ + struct rte_vdpa_device *dev; + + rte_spinlock_lock(&vdpa_device_list_lock); + dev = __vdpa_find_device_by_name(name); + rte_spinlock_unlock(&vdpa_device_list_lock); + + return dev; } struct rte_device * @@ -54,52 +73,52 @@ rte_vdpa_register_device(struct rte_device *rte_dev, struct rte_vdpa_dev_ops *ops) { struct rte_vdpa_device *dev; - int i; - if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL) + if (ops == NULL) return NULL; - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - dev = &vdpa_devices[i]; - if (dev->ops == NULL) - continue; - - if (dev->device == rte_dev) - return NULL; - } - - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - if (vdpa_devices[i].ops == NULL) - break; + rte_spinlock_lock(&vdpa_device_list_lock); + /* Check the device hasn't been register already */ + dev = __vdpa_find_device_by_name(rte_dev->name); + if (dev) { + dev = NULL; + goto out_unlock; } - if (i == MAX_VHOST_DEVICE) - return NULL; + dev = rte_zmalloc(NULL, sizeof(*dev), 0); + if (!dev) + goto out_unlock; - dev = &vdpa_devices[i]; dev->device = rte_dev; dev->ops = ops; + TAILQ_INSERT_TAIL(&vdpa_device_list, dev, next); vdpa_device_num++; +out_unlock: + rte_spinlock_unlock(&vdpa_device_list_lock); return dev; } int -rte_vdpa_unregister_device(struct rte_vdpa_device *vdev) +rte_vdpa_unregister_device(struct rte_vdpa_device *dev) { - int i; + struct rte_vdpa_device *cur_dev, *tmp_dev; + int ret = -1; - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - if (vdev != &vdpa_devices[i]) + rte_spinlock_lock(&vdpa_device_list_lock); + TAILQ_FOREACH_SAFE(cur_dev, &vdpa_device_list, next, tmp_dev) { + if (dev != cur_dev) continue; - memset(vdev, 0, sizeof(struct rte_vdpa_device)); + TAILQ_REMOVE(&vdpa_device_list, dev, next); + rte_free(dev); vdpa_device_num--; - - return 0; + ret = 0; + break; } + rte_spinlock_lock(&vdpa_device_list_lock); - return -1; + return ret; } int @@ -246,19 +265,6 @@ rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid) return dev->ops->reset_stats(dev, qid); } -static uint16_t -vdpa_dev_to_id(const struct rte_vdpa_device *dev) -{ - if (dev == NULL) - return MAX_VHOST_DEVICE; - - if (dev < &vdpa_devices[0] || - dev >= &vdpa_devices[MAX_VHOST_DEVICE]) - return MAX_VHOST_DEVICE; - - return (uint16_t)(dev - vdpa_devices); -} - static int vdpa_dev_match(struct rte_vdpa_device *dev, const struct rte_device *rte_dev) @@ -278,24 +284,22 @@ vdpa_find_device(const struct rte_vdpa_device *start, rte_vdpa_cmp_t cmp, struct rte_device *rte_dev) { struct rte_vdpa_device *dev; - uint16_t idx; - if (start != NULL) - idx = vdpa_dev_to_id(start) + 1; + rte_spinlock_lock(&vdpa_device_list_lock); + if (start == NULL) + dev = TAILQ_FIRST(&vdpa_device_list); else - idx = 0; - for (; idx < MAX_VHOST_DEVICE; idx++) { - dev = &vdpa_devices[idx]; - /* - * ToDo: Certainly better to introduce a state field, - * but rely on ops being set for now. - */ - if (dev->ops == NULL) - continue; + dev = TAILQ_NEXT(start, next); + + while (dev != NULL) { if (cmp(dev, rte_dev) == 0) - return dev; + break; + + dev = TAILQ_NEXT(dev, next); } - return NULL; + rte_spinlock_unlock(&vdpa_device_list_lock); + + return dev; } static void * From patchwork Fri Jun 26 13:27:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72240 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 D37F3A051C; Fri, 26 Jun 2020 15:29:30 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9D9C61BFF0; Fri, 26 Jun 2020 15:28:58 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id C5E721BF9F for ; Fri, 26 Jun 2020 15:28:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178131; 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=yFoc/+ueWQQMy1xmSyVwOHSAq0wguQOHAxo2VoWA08w=; b=b3u/j4Zm0yxz3P/Kv9bESCxkTc+ioIO7U1N0MYosQQZrC8Yj3MpIL8pyNKnoIn2V06x6Mw Ji+UY0UWor/qllOcAO5oF5GX7Tb66UmcH8g6HMsf2Q3aCk0MI5A0/I9DALGYapSEx28biJ uMTSm4ESx21BVOMiBsgcNkLKfaA8ssc= 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-346-yJbxglIFML6uuxEo-k9jUw-1; Fri, 26 Jun 2020 09:28:49 -0400 X-MC-Unique: yJbxglIFML6uuxEo-k9jUw-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50478804015; Fri, 26 Jun 2020 13:28:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E3725C557; Fri, 26 Jun 2020 13:28:43 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:08 +0200 Message-Id: <20200626132712.1437673-11-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 10/14] vhost: introduce wrappers for some vDPA ops 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 preliminary work to make the vDPA device structure opaque to the user application. Some callbacks of the vDPA devices are used to query capabilities before attaching to a Vhost port. This patch introduces wrappers for these ops. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- lib/librte_vhost/rte_vdpa.h | 72 ++++++++++++++++++++++++++ lib/librte_vhost/rte_vhost_version.map | 3 ++ lib/librte_vhost/vdpa.c | 28 ++++++++++ 3 files changed, 103 insertions(+) diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index dbdc273702..eda56dd556 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -226,6 +226,78 @@ __rte_experimental int rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Get number of queue pairs supported by the vDPA device + * + * @param dev + * vDP device pointer + * @param queue_num + * pointer on where the number of queue is stored + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_get_queue_num(struct rte_vdpa_device *dev, uint32_t *queue_num); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Get the Virtio features supported by the vDPA device + * + * @param dev + * vDP device pointer + * @param features + * pointer on where the supported features are stored + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_get_features(struct rte_vdpa_device *dev, uint64_t *features); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Get the Vhost-user protocol features supported by the vDPA device + * + * @param dev + * vDP device pointer + * @param features + * pointer on where the supported protocol features are stored + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_get_protocol_features(struct rte_vdpa_device *dev, uint64_t *features); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Synchronize the used ring from mediated ring to guest, log dirty + * page for each writeable buffer, caller should handle the used + * ring logging before device stop. + * + * @param vid + * vhost device id + * @param qid + * vhost queue id + * @param vring_m + * mediated virtio ring pointer + * @return + * number of synced used entries on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index d9124d0462..7a919102cf 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -70,4 +70,7 @@ EXPERIMENTAL { rte_vhost_slave_config_change; rte_vdpa_find_device_by_name; rte_vdpa_get_rte_device; + rte_vdpa_get_queue_num; + rte_vdpa_get_features; + rte_vdpa_get_protocol_features; }; diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 49e3654380..66fa5a0728 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -229,6 +229,34 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m) return -1; } +int +rte_vdpa_get_queue_num(struct rte_vdpa_device *dev, uint32_t *queue_num) +{ + if (dev == NULL || dev->ops == NULL || dev->ops->get_queue_num == NULL) + return -1; + + return dev->ops->get_queue_num(dev, queue_num); +} + +int +rte_vdpa_get_features(struct rte_vdpa_device *dev, uint64_t *features) +{ + if (dev == NULL || dev->ops == NULL || dev->ops->get_features == NULL) + return -1; + + return dev->ops->get_features(dev, features); +} + +int +rte_vdpa_get_protocol_features(struct rte_vdpa_device *dev, uint64_t *features) +{ + if (dev == NULL || dev->ops == NULL || + dev->ops->get_protocol_features == NULL) + return -1; + + return dev->ops->get_protocol_features(dev, features); +} + int rte_vdpa_get_stats_names(struct rte_vdpa_device *dev, struct rte_vdpa_stat_name *stats_names, From patchwork Fri Jun 26 13:27:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72242 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 4D72BA051C; Fri, 26 Jun 2020 15:29:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6D89B1C010; Fri, 26 Jun 2020 15:29:10 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id B10FA1BFFA for ; Fri, 26 Jun 2020 15:28:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178138; 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=JLZkL9jSYw3TtrKpuqdW7XmcVj7BEfJ7fqiCyUEtt5w=; b=bPOZM90kp2eTL/1mZT0szXUGUTdxas892PhRskX7GPdEwypW8eR9lzMPvIeZJf94jHJPGU BZfH+wQciAQ3Blnb5SUQ2OZZe0ZC/OeOlaYVamByx0ifewB+x76t/r/elGpruh36wsWuKk 9Wfeca58v/XTJMhC1RcybFYxveunVvA= 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-354-PAEpZUxoMVmVQyOVnLuEkg-1; Fri, 26 Jun 2020 09:28:56 -0400 X-MC-Unique: PAEpZUxoMVmVQyOVnLuEkg-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A616E107ACCA; Fri, 26 Jun 2020 13:28:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id A172D5C663; Fri, 26 Jun 2020 13:28:47 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:09 +0200 Message-Id: <20200626132712.1437673-12-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 11/14] examples/vdpa: use new wrappers instead of ops 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" Now that wrappers to query number of queues, Virtio features and Vhost-user protocol features are available, let's make the vDPA example to use them. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- examples/vdpa/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 54f4940b31..d59c7fa9b4 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -301,13 +301,13 @@ static void cmd_list_vdpa_devices_parsed( vdev = rte_vdpa_find_device_by_name(dev->name); if (!vdev) continue; - if (vdev->ops->get_queue_num(vdev, &queue_num) < 0) { + if (rte_vdpa_get_queue_num(vdev, &queue_num) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa queue number " "for device %s.\n", dev->name); continue; } - if (vdev->ops->get_features(vdev, &features) < 0) { + if (rte_vdpa_get_features(vdev, &features) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa features " "for device %s.\n", dev->name); From patchwork Fri Jun 26 13:27:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72243 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 79D65A051C; Fri, 26 Jun 2020 15:29:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C34BA1C01B; Fri, 26 Jun 2020 15:29:12 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 77DCA1C00D for ; Fri, 26 Jun 2020 15:29:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178140; 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=TNcauoDqg+M7kAXQV7xZiG2HCDLQPB99jJWXcUhqHZ0=; b=fJTCMAdKAAvm34XPs3MlrQrUcJLL0B2Z5yBUxft3CbES62tidKzN/2arXgOQP3wVhPdgeq KJqrUiEo3alc8RKbvKslzWhejju3iV8xNn57LY/ZgybB4yN7+hJy7J9iLL3Bu5h3Ls1xpp HTleWh7Y9+RIcmc7zqsIKBlTivmu9ds= 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-70-xPCtHDaPOCCGZEwUlD1MUQ-1; Fri, 26 Jun 2020 09:28:58 -0400 X-MC-Unique: xPCtHDaPOCCGZEwUlD1MUQ-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 589C6800D5C; Fri, 26 Jun 2020 13:28:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F2EF5C6C0; Fri, 26 Jun 2020 13:28:53 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:10 +0200 Message-Id: <20200626132712.1437673-13-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 v3 12/14] examples/vdpa: remove useless device count 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" The VDPA example now uses the vDPA class iterator, so knowing the number of available devices beforehand is no longer needed. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- examples/vdpa/main.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index d59c7fa9b4..2345f98665 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -38,7 +38,6 @@ struct vdpa_port { static struct vdpa_port vports[MAX_VDPA_SAMPLE_PORTS]; static char iface[MAX_PATH_LEN]; -static int dev_total; static int devcnt; static int interactive; static int client_mode; @@ -227,7 +226,7 @@ static void vdpa_sample_quit(void) { int i; - for (i = 0; i < RTE_MIN(MAX_VDPA_SAMPLE_PORTS, dev_total); i++) { + for (i = 0; i < RTE_MIN(MAX_VDPA_SAMPLE_PORTS, devcnt); i++) { if (vports[i].ifname[0] != '\0') close_vdpa(&vports[i]); } @@ -399,7 +398,7 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, res->bdf); return; } - for (i = 0; i < RTE_MIN(MAX_VDPA_SAMPLE_PORTS, dev_total); i++) { + for (i = 0; i < RTE_MIN(MAX_VDPA_SAMPLE_PORTS, devcnt); i++) { if (vports[i].dev == vdev) { vport = &vports[i]; break; @@ -536,10 +535,6 @@ main(int argc, char *argv[]) argc -= ret; argv += ret; - dev_total = rte_vdpa_get_device_num(); - if (dev_total <= 0) - rte_exit(EXIT_FAILURE, "No available vdpa device found\n"); - signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); From patchwork Fri Jun 26 13:27:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72244 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 BCA0AA051C; Fri, 26 Jun 2020 15:30:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 483F81C025; Fri, 26 Jun 2020 15:29:15 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 973CB1BFBF for ; Fri, 26 Jun 2020 15:29:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178148; 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=xki9dVhWb7WngqNBmT7hyuueD0g2bJqR/0oiKCk5EvY=; b=Pzcc8uBK6TLU6VIZ87rmjg7nH3XRViVHnLKKtViRpPMzFbBq1NY3rv5Vnxv4Dn8ezsrYDg 6mKZH5daqqRgZZY9b0j+k6SOdZmlo7I2pe25gGLQWqTec22+qqObqmH51u1/JjRw68RRUq 8YaXs2ABay9tdwm3chp3qry8UKQWJlY= 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-273-ZyR39N8BOB-xDq2WnrYaSw-1; Fri, 26 Jun 2020 09:29:05 -0400 X-MC-Unique: ZyR39N8BOB-xDq2WnrYaSw-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 959F8BFC1; Fri, 26 Jun 2020 13:29:03 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6C845C663; Fri, 26 Jun 2020 13:28:57 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:11 +0200 Message-Id: <20200626132712.1437673-14-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 13/14] vhost: remove vDPA device count API 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 API is no more useful, this patch removes it. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- lib/librte_vhost/rte_vdpa.h | 13 ------------- lib/librte_vhost/rte_vhost_version.map | 1 - lib/librte_vhost/vdpa.c | 9 --------- 3 files changed, 23 deletions(-) diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index eda56dd556..776ed67c16 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -175,19 +175,6 @@ __rte_experimental struct rte_device * rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev); -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Get current available vdpa device number - * - * @return - * available vdpa device number - */ -__rte_experimental -int -rte_vdpa_get_device_num(void); - /** * @warning * @b EXPERIMENTAL: this API may change without prior notice diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 7a919102cf..299576a494 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -36,7 +36,6 @@ EXPERIMENTAL { rte_vdpa_register_device; rte_vdpa_unregister_device; rte_vdpa_find_device_id; - rte_vdpa_get_device_num; rte_vdpa_get_stats_names; rte_vdpa_get_stats; rte_vdpa_reset_stats; diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 66fa5a0728..edf6bb6116 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -25,7 +25,6 @@ TAILQ_HEAD(vdpa_device_list, rte_vdpa_device); static struct vdpa_device_list vdpa_device_list = TAILQ_HEAD_INITIALIZER(vdpa_device_list); static rte_spinlock_t vdpa_device_list_lock = RTE_SPINLOCK_INITIALIZER; -static uint32_t vdpa_device_num; /* Unsafe, needs to be called with vdpa_device_list_lock held */ @@ -92,7 +91,6 @@ rte_vdpa_register_device(struct rte_device *rte_dev, dev->device = rte_dev; dev->ops = ops; TAILQ_INSERT_TAIL(&vdpa_device_list, dev, next); - vdpa_device_num++; out_unlock: rte_spinlock_unlock(&vdpa_device_list_lock); @@ -112,7 +110,6 @@ rte_vdpa_unregister_device(struct rte_vdpa_device *dev) TAILQ_REMOVE(&vdpa_device_list, dev, next); rte_free(dev); - vdpa_device_num--; ret = 0; break; } @@ -121,12 +118,6 @@ rte_vdpa_unregister_device(struct rte_vdpa_device *dev) return ret; } -int -rte_vdpa_get_device_num(void) -{ - return vdpa_device_num; -} - int rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m) { From patchwork Fri Jun 26 13:27:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72245 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 F28B7A051C; Fri, 26 Jun 2020 15:30:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0D28C1C02A; Fri, 26 Jun 2020 15:29:17 +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 2517B1BF9F for ; Fri, 26 Jun 2020 15:29:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593178150; 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=aUh3mtmCzxZaOM1EUaVwOGTrO7Aa7OkiQYdD3IhrciE=; b=LAG1HAEhPsRlPDul3NBEKJczBgNYFVyOEtO07gEvEI713nDPys7JOcsCErxcf53M4isjUt 6PMBoSjKTfXoxMb+jhzMNYBvP9xj63Fdt5TAABqpetSuuj8See1nfVksmQdlmBrGYyJN+u koyqbRRlqyTQiF+eqC1fHEg/JN+uABg= 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-397-BjtJkAuZNoaHzVcuw91o7w-1; Fri, 26 Jun 2020 09:29:08 -0400 X-MC-Unique: BjtJkAuZNoaHzVcuw91o7w-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 16A7318FF660; Fri, 26 Jun 2020 13:29:07 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4AAF5C557; Fri, 26 Jun 2020 13:29:03 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 15:27:12 +0200 Message-Id: <20200626132712.1437673-15-maxime.coquelin@redhat.com> In-Reply-To: <20200626132712.1437673-1-maxime.coquelin@redhat.com> References: <20200626132712.1437673-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 14/14] vhost: split vDPA header file 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 split the vDPA header file in two, making rte_vdpa_device structure opaque to the application. Applications should only include rte_vdpa.h, while drivers should include both rte_vdpa.h and rte_vdpa_dev.h. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- drivers/vdpa/ifc/ifcvf_vdpa.c | 1 + drivers/vdpa/mlx5/mlx5_vdpa.h | 1 + lib/librte_vhost/Makefile | 3 +- lib/librte_vhost/meson.build | 3 +- lib/librte_vhost/rte_vdpa.h | 142 ------------------------------ lib/librte_vhost/rte_vdpa_dev.h | 147 ++++++++++++++++++++++++++++++++ lib/librte_vhost/vdpa.c | 1 + lib/librte_vhost/vhost.h | 1 + 8 files changed, 155 insertions(+), 144 deletions(-) create mode 100644 lib/librte_vhost/rte_vdpa_dev.h diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index 4163047744..f81d13a2c8 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index ea09576c5a..de4154b183 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -12,6 +12,7 @@ #pragma GCC diagnostic ignored "-Wpedantic" #endif #include +#include #include #ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic" diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile index e592795f22..b7ff7dc4b3 100644 --- a/lib/librte_vhost/Makefile +++ b/lib/librte_vhost/Makefile @@ -41,7 +41,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \ vhost_user.c virtio_net.c vdpa.c # install includes -SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h rte_vdpa.h +SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h rte_vdpa.h \ + rte_vdpa_dev.h # only compile vhost crypto when cryptodev is enabled ifeq ($(CONFIG_RTE_LIBRTE_CRYPTODEV),y) diff --git a/lib/librte_vhost/meson.build b/lib/librte_vhost/meson.build index f80632848c..882a0eaf41 100644 --- a/lib/librte_vhost/meson.build +++ b/lib/librte_vhost/meson.build @@ -21,5 +21,6 @@ cflags += '-fno-strict-aliasing' sources = files('fd_man.c', 'iotlb.c', 'socket.c', 'vdpa.c', 'vhost.c', 'vhost_user.c', 'virtio_net.c', 'vhost_crypto.c') -headers = files('rte_vhost.h', 'rte_vdpa.h', 'rte_vhost_crypto.h') +headers = files('rte_vhost.h', 'rte_vdpa.h', 'rte_vdpa_dev.h', + 'rte_vhost_crypto.h') deps += ['ethdev', 'cryptodev', 'hash', 'pci'] diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index 776ed67c16..5065e2130e 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -11,13 +11,6 @@ * Device specific vhost lib */ -#include - -#include -#include "rte_vhost.h" - -#define MAX_VDPA_NAME_LEN 128 - /** Maximum name length for statistics counters */ #define RTE_VDPA_STATS_NAME_SIZE 64 @@ -48,103 +41,6 @@ struct rte_vdpa_stat_name { char name[RTE_VDPA_STATS_NAME_SIZE]; /**< The statistic name */ }; -/** - * vdpa device operations - */ -struct rte_vdpa_dev_ops { - /** Get capabilities of this device */ - int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num); - - /** Get supported features of this device */ - int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features); - - /** Get supported protocol features of this device */ - int (*get_protocol_features)(struct rte_vdpa_device *dev, - uint64_t *protocol_features); - - /** Driver configure/close the device */ - int (*dev_conf)(int vid); - int (*dev_close)(int vid); - - /** Enable/disable this vring */ - int (*set_vring_state)(int vid, int vring, int state); - - /** Set features when changed */ - int (*set_features)(int vid); - - /** Destination operations when migration done */ - int (*migration_done)(int vid); - - /** Get the vfio group fd */ - int (*get_vfio_group_fd)(int vid); - - /** Get the vfio device fd */ - int (*get_vfio_device_fd)(int vid); - - /** Get the notify area info of the queue */ - int (*get_notify_area)(int vid, int qid, - uint64_t *offset, uint64_t *size); - - /** Get statistics name */ - int (*get_stats_names)(struct rte_vdpa_device *dev, - struct rte_vdpa_stat_name *stats_names, - unsigned int size); - - /** Get statistics of the queue */ - int (*get_stats)(struct rte_vdpa_device *dev, int qid, - struct rte_vdpa_stat *stats, unsigned int n); - - /** Reset statistics of the queue */ - int (*reset_stats)(struct rte_vdpa_device *dev, int qid); - - /** Reserved for future extension */ - void *reserved[2]; -}; - -/** - * vdpa device structure includes device address and device operations. - */ -struct rte_vdpa_device { - TAILQ_ENTRY(rte_vdpa_device) next; - /** Generic device information */ - struct rte_device *device; - /** vdpa device operations */ - struct rte_vdpa_dev_ops *ops; -} __rte_cache_aligned; - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Register a vdpa device - * - * @param addr - * the vdpa device address - * @param ops - * the vdpa device operations - * @return - * vDPA device pointer on success, NULL on failure - */ -__rte_experimental -struct rte_vdpa_device * -rte_vdpa_register_device(struct rte_device *rte_dev, - struct rte_vdpa_dev_ops *ops); - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Unregister a vdpa device - * - * @param did - * vDPA device pointer - * @return - * device id on success, -1 on failure - */ -__rte_experimental -int -rte_vdpa_unregister_device(struct rte_vdpa_device *); - /** * @warning * @b EXPERIMENTAL: this API may change without prior notice @@ -175,44 +71,6 @@ __rte_experimental struct rte_device * rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev); -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Enable/Disable host notifier mapping for a vdpa port. - * - * @param vid - * vhost device id - * @param enable - * true for host notifier map, false for host notifier unmap - * @return - * 0 on success, -1 on failure - */ -__rte_experimental -int -rte_vhost_host_notifier_ctrl(int vid, bool enable); - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Synchronize the used ring from mediated ring to guest, log dirty - * page for each writeable buffer, caller should handle the used - * ring logging before device stop. - * - * @param vid - * vhost device id - * @param qid - * vhost queue id - * @param vring_m - * mediated virtio ring pointer - * @return - * number of synced used entries on success, -1 on failure - */ -__rte_experimental -int -rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); - /** * @warning * @b EXPERIMENTAL: this API may change without prior notice diff --git a/lib/librte_vhost/rte_vdpa_dev.h b/lib/librte_vhost/rte_vdpa_dev.h new file mode 100644 index 0000000000..fecaa8e081 --- /dev/null +++ b/lib/librte_vhost/rte_vdpa_dev.h @@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _RTE_VDPA_H_DEV_ +#define _RTE_VDPA_H_DEV_ + +#include + +#include "rte_vhost.h" + +/** + * vdpa device operations + */ +struct rte_vdpa_dev_ops { + /** Get capabilities of this device */ + int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num); + + /** Get supported features of this device */ + int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features); + + /** Get supported protocol features of this device */ + int (*get_protocol_features)(struct rte_vdpa_device *dev, + uint64_t *protocol_features); + + /** Driver configure/close the device */ + int (*dev_conf)(int vid); + int (*dev_close)(int vid); + + /** Enable/disable this vring */ + int (*set_vring_state)(int vid, int vring, int state); + + /** Set features when changed */ + int (*set_features)(int vid); + + /** Destination operations when migration done */ + int (*migration_done)(int vid); + + /** Get the vfio group fd */ + int (*get_vfio_group_fd)(int vid); + + /** Get the vfio device fd */ + int (*get_vfio_device_fd)(int vid); + + /** Get the notify area info of the queue */ + int (*get_notify_area)(int vid, int qid, + uint64_t *offset, uint64_t *size); + + /** Get statistics name */ + int (*get_stats_names)(struct rte_vdpa_device *dev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size); + + /** Get statistics of the queue */ + int (*get_stats)(struct rte_vdpa_device *dev, int qid, + struct rte_vdpa_stat *stats, unsigned int n); + + /** Reset statistics of the queue */ + int (*reset_stats)(struct rte_vdpa_device *dev, int qid); + + /** Reserved for future extension */ + void *reserved[2]; +}; + +/** + * vdpa device structure includes device address and device operations. + */ +struct rte_vdpa_device { + TAILQ_ENTRY(rte_vdpa_device) next; + /** Generic device information */ + struct rte_device *device; + /** vdpa device operations */ + struct rte_vdpa_dev_ops *ops; +}; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Register a vdpa device + * + * @param rte_dev + * the generic device pointer + * @param ops + * the vdpa device operations + * @return + * vDPA device pointer on success, NULL on failure + */ +__rte_experimental +struct rte_vdpa_device * +rte_vdpa_register_device(struct rte_device *rte_dev, + struct rte_vdpa_dev_ops *ops); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Unregister a vdpa device + * + * @param dev + * vDPA device pointer + * @return + * device id on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_unregister_device(struct rte_vdpa_device *dev); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Enable/Disable host notifier mapping for a vdpa port. + * + * @param vid + * vhost device id + * @param enable + * true for host notifier map, false for host notifier unmap + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vhost_host_notifier_ctrl(int vid, bool enable); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Synchronize the used ring from mediated ring to guest, log dirty + * page for each writeable buffer, caller should handle the used + * ring logging before device stop. + * + * @param vid + * vhost device id + * @param qid + * vhost queue id + * @param vring_m + * mediated virtio ring pointer + * @return + * number of synced used entries on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); + +#endif /* _RTE_VDPA_DEV_H_ */ diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index edf6bb6116..c8b5663d01 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -17,6 +17,7 @@ #include #include "rte_vdpa.h" +#include "rte_vdpa_dev.h" #include "vhost.h" /** Double linked list of vDPA devices. */ diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 819857a65a..941a42637e 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -22,6 +22,7 @@ #include "rte_vhost.h" #include "rte_vdpa.h" +#include "rte_vdpa_dev.h" /* Used to indicate that the device is running on a data core */ #define VIRTIO_DEV_RUNNING 1