From patchwork Wed Jun 24 12:26:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72118 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 10218A0350; Wed, 24 Jun 2020 14:27:38 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B52401D8FB; Wed, 24 Jun 2020 14:27:35 +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 F3AF21D8F4 for ; Wed, 24 Jun 2020 14:27:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001653; 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=XT5uGVn4sUr1KhGhcRk1YIvJybNa87Z9+nQHYBzS/vM=; b=HReWQOvjVgzQdQtf35nCOiRZHruR9TCIIUTjy7rSW+3SXnP4Hywpr3In74ST83AQTPUvE1 XKkUqNIfwlmq2DDObcfXDkWwFiT9Gd92K3LmcVkMYTT3JC2JsMYnJcV6iCgwemEFkI0MnM opSH4Fl6W4FVnL82S3hC011d9Iku8v8= 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-490-b3mqHC_rPS61iLr1zQ5m-g-1; Wed, 24 Jun 2020 08:27:30 -0400 X-MC-Unique: b3mqHC_rPS61iLr1zQ5m-g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4878D8015F7; Wed, 24 Jun 2020 12:27:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2ACD78929D; Wed, 24 Jun 2020 12:27:24 +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: Wed, 24 Jun 2020 14:26:45 +0200 Message-Id: <20200624122701.1369327-2-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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 Cc: shreyansh.jain@nxp.com Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- 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..216f38acd4 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\n"); + 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 Wed Jun 24 12:26:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72134 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EE9DCA0350; Wed, 24 Jun 2020 14:30:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 60AD91D950; Wed, 24 Jun 2020 14:29:59 +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 C7DFD1D948 for ; Wed, 24 Jun 2020 14:29:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001797; 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=CzG2L0odJaE6ntRCoK6uUQjvvdIhbOutSlFFUrSsQOk=; b=KG+CI2b12WhrZmosoS1JOHNpG1Xyn5qaMWLESUa4xLj1fHidC1//LDmBHhMceUIgHniYUf qEU6ri2YCaSU1fxIEJRBqrODsC//wNojAMTeok82qiwNpfi9C0P/US9GA7jBOTbKsTiAA4 oYqVXZdmcFEG3SwK+Ndkn3xEn4iTf0c= 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-201-MU88P2ErNMeCc6g0og0K3g-1; Wed, 24 Jun 2020 08:27:33 -0400 X-MC-Unique: MU88P2ErNMeCc6g0og0K3g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A673687950B; Wed, 24 Jun 2020 12:27:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB89B1C4; Wed, 24 Jun 2020 12:27:28 +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: Wed, 24 Jun 2020 14:26:46 +0200 Message-Id: <20200624122701.1369327-3-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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 --- 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..75c15d6b67 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\n"); + 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 Wed Jun 24 12:26:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72119 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 667C0A0350; Wed, 24 Jun 2020 14:27:46 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 098941D90F; Wed, 24 Jun 2020 14:27:46 +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 D48EB1D8E6 for ; Wed, 24 Jun 2020 14:27:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001664; 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=68QcTanHSzHP12mvXkrAg2vpOPs3CD1O7gu5Dc/GPOs=; b=AuSodxrKAiwYsdY14lvRlUg9aRgVMbwFNKXNVsIENDt1IKzaX52fN+TTU0psecsfiCB6xt 230T9xY2pO93UHzSMByTVx0KVWjRrP+TcH7m2MbHLu+P2ZnQmjCB49eQSSozNkgRu+GjPA jue4hZ7Drb3KxEUCQcDuCRkfE8H7m6g= 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-204-xOxrAdySN7ivdONMlsEIsw-1; Wed, 24 Jun 2020 08:27:38 -0400 X-MC-Unique: xOxrAdySN7ivdONMlsEIsw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 264C4107B7C8; Wed, 24 Jun 2020 12:27:37 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 088ED1C4; Wed, 24 Jun 2020 12:27:31 +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: Wed, 24 Jun 2020 14:26:47 +0200 Message-Id: <20200624122701.1369327-4-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- 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 Wed Jun 24 12:26:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72120 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 47282A0350; Wed, 24 Jun 2020 14:27:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 947891D91E; Wed, 24 Jun 2020 14:27:53 +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 632B41D91A for ; Wed, 24 Jun 2020 14:27:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001670; 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=2vq+a3HOrk8ftlX4XkEn0egBru/by6gHR1kQaVMCdEs=; b=gjH2kZj65t8F6s6MZpXId7ueBehPRle4TqCPatdf9JBXsIJYgYCkLltl3tS9yZNZaKQHwd /A086J9XgDS9SQCGedOa1X3/1KbmcIoh1LzBGf6VMz7yGpOAAGBD/o5cKGw/PLEDQoaz+h LE/9gpLdFAa2RSnMpexIwIPpa2+0mME= 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-50-AY4NWhPGO1y855qQIYAImg-1; Wed, 24 Jun 2020 08:27:47 -0400 X-MC-Unique: AY4NWhPGO1y855qQIYAImg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DFF8108BD0A; Wed, 24 Jun 2020 12:27:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DD8C1C4; Wed, 24 Jun 2020 12:27: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: Wed, 24 Jun 2020 14:26:48 +0200 Message-Id: <20200624122701.1369327-5-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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 --- 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..07db5b9e46 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 (strcmp(dev->device->name, name) == 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 Wed Jun 24 12:26:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72121 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B41E8A0350; Wed, 24 Jun 2020 14:28:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5727C1D935; Wed, 24 Jun 2020 14:27:56 +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 01A541D925 for ; Wed, 24 Jun 2020 14:27:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001674; 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=UBB04w1Rr4R0Pzpuj6+Ntfs0rKbeRsugNngg23MFQgU=; b=Lg3M0FyTeNYA1l0UedQTyDR1Uuo6WvP1T+rPbyNlQZQAGjPP+CoYd/0fy+rF84sU8ELiA8 Br1diUXkDIaOvU6IsBonTOB2BFcyWjdG9q9xKW5dxGPGTrE+xkTHjrLkzIvjA33+ewSC+t Tmi5daEmFt5mTAVWq7TYd9qXwNs2yuE= 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-459-8ZZR18PWP1yjo3zcRVo9Cg-1; Wed, 24 Jun 2020 08:27:50 -0400 X-MC-Unique: 8ZZR18PWP1yjo3zcRVo9Cg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34CEF879512; Wed, 24 Jun 2020 12:27:49 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id B89C160C1D; Wed, 24 Jun 2020 12:27:45 +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: Wed, 24 Jun 2020 14:26:49 +0200 Message-Id: <20200624122701.1369327-6-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- 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 07db5b9e46..ed20082f0f 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 Wed Jun 24 12:26:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72122 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 25A3AA0350; Wed, 24 Jun 2020 14:28:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B4A651D91C; Wed, 24 Jun 2020 14:27:59 +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 2E5D71D929 for ; Wed, 24 Jun 2020 14:27:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001677; 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=e6n7Kwp4fmvG0A5hHgJqxCHoMPvSqYassOs7y+qZQdg=; b=dhWONw5Wotv2UYxxXXwjpaYsnlv9J5nYT2B8a8HOA9YqXMjfIbAK1e7CY2o+LPqBTc/zxM I6QcuecrwgNRjamKdDdIggr/1QCvWFQLXLNaNKE1jNmVHBonNzMnHblexfR2oApfftCuj9 gFAWIaaIDu8AeUej/OlsWQ/GVXDkmYQ= 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-319-4IlQYiTfMs-XShrr5lBcFA-1; Wed, 24 Jun 2020 08:27:53 -0400 X-MC-Unique: 4IlQYiTfMs-XShrr5lBcFA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 346EC800597; Wed, 24 Jun 2020 12:27:52 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91D091C4; Wed, 24 Jun 2020 12:27:49 +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: Wed, 24 Jun 2020 14:26:50 +0200 Message-Id: <20200624122701.1369327-7-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- 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 Wed Jun 24 12:26:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72123 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0A2A9A0350; Wed, 24 Jun 2020 14:28:38 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6AB7F1D942; Wed, 24 Jun 2020 14:28:05 +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 6CEA61D712 for ; Wed, 24 Jun 2020 14:28:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001684; 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=WPTCxijJA6uyr2kShMZ5EGiv8erXqVZpbEASU0Lq6Ls=; b=Xm9A1B09m1TJYW2Bw+BtS1ky7/2uTvH2yztFS6nlHMU0F7ImDkdVh8wZ7Rc/6jyKleNm/0 2Jm2rUz20CVb8o+luoj5lXdN7zJxe8O26CNkLjRfjRU7o6QgqzkqifzWA1cKdMMDWBND7r jK+40h7+euy37vUvxogwztygOk0WRWY= 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-345-WYbiEEoMOFG_fopVeHlA3g-1; Wed, 24 Jun 2020 08:28:02 -0400 X-MC-Unique: WYbiEEoMOFG_fopVeHlA3g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADC90107B7C5; Wed, 24 Jun 2020 12:28:00 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8610B1C4; Wed, 24 Jun 2020 12:27:52 +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: Wed, 24 Jun 2020 14:26:51 +0200 Message-Id: <20200624122701.1369327-8-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- 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 ed20082f0f..91bc483774 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 (strcmp(dev->device->name, name) == 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 Wed Jun 24 12:26:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72124 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2F9FCA0350; Wed, 24 Jun 2020 14:28:51 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A80511D94F; Wed, 24 Jun 2020 14:28:09 +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 C0E8D1D93F for ; Wed, 24 Jun 2020 14:28:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001687; 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=pCYrd4o7UuEH8Hob5afxAtQFRcn9rWcyBY9V5T66s/c=; b=aaDVXYXS/Jvg7TzqQ39EhZn/BdUaM5L3JjB4BspDL2r7vw3WO4BToI4aPZHi1Lmi6CYnj5 7CN3FVdCa574OK0XWK0AmwoBJaIlmWKAiGvXOZIUQipCuzOdcxEvuqUyoQG5lksGTboeLp dBK7QZsFFEbVNmTgWpf5YWX6BFNhUi4= 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-484-4A_jvrRrNJiJwqQt8xofpw-1; Wed, 24 Jun 2020 08:28:06 -0400 X-MC-Unique: 4A_jvrRrNJiJwqQt8xofpw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A20D8015F4; Wed, 24 Jun 2020 12:28:04 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 064208FF60; Wed, 24 Jun 2020 12:27:55 +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: Wed, 24 Jun 2020 14:26:52 +0200 Message-Id: <20200624122701.1369327-9-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- 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 91bc483774..d7965b8854 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 Wed Jun 24 12:26:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72125 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 52F76A0350; Wed, 24 Jun 2020 14:29:03 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EEBD61D91A; Wed, 24 Jun 2020 14:28:14 +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 4DCDC1D8DE for ; Wed, 24 Jun 2020 14:28:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001692; 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=BYEa4UUgXriry8vyMskV/GU/JdyMCG3qepwxa0logCI=; b=jONMUORyqSp/fCBz2F5GLGPMGW+P01R4nJfJrI1gsmg+KE3TAhQaWIQV8HJT3BXdaGYmjU qIAR+2HYsXnxLrgFhb8D4EjcnogXSd1ftHdDMxBSSx9mbp6yBkqoARQ/787PMe/CDhhB9+ f1uW24r36EN9VOnshYOSyScNHD+wFvk= 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-189-8-3_l_jKM9yb2_uPRFbxeg-1; Wed, 24 Jun 2020 08:28:09 -0400 X-MC-Unique: 8-3_l_jKM9yb2_uPRFbxeg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D6E887950C; Wed, 24 Jun 2020 12:28:07 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB7681C4; Wed, 24 Jun 2020 12:28:04 +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: Wed, 24 Jun 2020 14:26:53 +0200 Message-Id: <20200624122701.1369327-10-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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 d7965b8854..dc2a138009 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 (strcmp(dev->device->name, name) == 0) - return dev; + TAILQ_FOREACH(dev, &vdpa_device_list, next) { + if (strcmp(dev->device->name, name) == 0) { + 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 Wed Jun 24 12:26:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72126 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 60639A0350; Wed, 24 Jun 2020 14:29:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A3F281D6ED; Wed, 24 Jun 2020 14:28:17 +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 F33221D91A for ; Wed, 24 Jun 2020 14:28:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001693; 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=hbO+v2J5z4y2lggLuk1HTAsRIy4I9UB5YemivP7qLeM=; b=SBnIykVxZcSzghfjnmnI/6wbzHCgE9zWigOy9RtS2ZGoImphAcMJ0PwIB51E4bo6AGEXel ZCtegs5uX/tnxatNOtxv9BMzSd6dZVfxLlvuoMrkCn/0X9YeNYYY51iBFBZx4m+EpTSpE6 Hdsnxw/thVmbZQcqlvv4JviNdjhR1lg= 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-74-owVua2LmPOSWNnOD4U54eg-1; Wed, 24 Jun 2020 08:28:12 -0400 X-MC-Unique: owVua2LmPOSWNnOD4U54eg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7793B800C60; Wed, 24 Jun 2020 12:28:10 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8C818929D; Wed, 24 Jun 2020 12:28:07 +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: Wed, 24 Jun 2020 14:26:54 +0200 Message-Id: <20200624122701.1369327-11-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 10/12] 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. 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 Wed Jun 24 12:26:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72128 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CC7D9A0350; Wed, 24 Jun 2020 14:29:38 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E19441D965; Wed, 24 Jun 2020 14:28:27 +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 336891D92E for ; Wed, 24 Jun 2020 14:28:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001705; 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=SxE1cBkhNxenOt+nU4aOYA9NMb28V393Iv1gHa4G/N2WYJVcFRHvBxKMl81OGjJ+JZWH6l l09jig7VFRN8hygycEV7UaXLxT1KXYhAAq0RxYhBdbtredSo7TsScwMBn+IwfgAMqHoH28 nCQpsZMJb0xlXH3VLiiD3HbqNUtAyqA= 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-39-Hv8xuIo4P8iMldUui66R6g-1; Wed, 24 Jun 2020 08:28:24 -0400 X-MC-Unique: Hv8xuIo4P8iMldUui66R6g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BD577800597; Wed, 24 Jun 2020 12:28:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F48E891D8; Wed, 24 Jun 2020 12:28:14 +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: Wed, 24 Jun 2020 14:26:56 +0200 Message-Id: <20200624122701.1369327-13-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 11/12] 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 --- 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 Wed Jun 24 12:26:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72130 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 65484A0350; Wed, 24 Jun 2020 14:29:56 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 77AA51D97A; Wed, 24 Jun 2020 14:28:35 +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 7C20F1D96A for ; Wed, 24 Jun 2020 14:28:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001713; 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=ecQTiRvO+E6BZipH/6y7nNX+yuqNar0jJBvgkPX0RV05hluA03iwbagZnzkmXSBqI6J1wq gl8WEyx0NQviTHuPh/sLpTuti1k/rgGJTc2i/G/NUURbREWhNpwb5r6LuwwX9sv/L6PqVp NgusNUDPanNIgf8IOv7sSfBN59hai/E= 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-147--XrcZqU1OR2ugMd9y7DDGQ-1; Wed, 24 Jun 2020 08:28:31 -0400 X-MC-Unique: -XrcZqU1OR2ugMd9y7DDGQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98435193F560; Wed, 24 Jun 2020 12:28:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 574081C4; Wed, 24 Jun 2020 12: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: Wed, 24 Jun 2020 14:26:58 +0200 Message-Id: <20200624122701.1369327-15-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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 --- 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 Wed Jun 24 12: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: 72132 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A4D42A0350; Wed, 24 Jun 2020 14:30:19 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D25A21D943; Wed, 24 Jun 2020 14:28:48 +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 8BB0A1D943 for ; Wed, 24 Jun 2020 14:28:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001727; 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=Yr1maEtyBXKhHqDE6B5ckkPUQF6DA8b7F8EwfIAHi5U=; b=aoSpaFamaL+oSGn55SLhl+BOfwR2I3WsodLtxbu08ValXR/rUB+Su5TXYHkhLXTLQBSkw5 Hi7Jsw1sDG+z6exYaSbPhLP4BB5J+WVWvZV0LnffC6qvlXew5pJf8JMvjBSZwQHBllvZV7 bhrvl96sRWlyvQs4hvi9iN0rhPc1NOw= 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-317-lb2F_mrpM1ehIEF51vLOVA-1; Wed, 24 Jun 2020 08:28:43 -0400 X-MC-Unique: lb2F_mrpM1ehIEF51vLOVA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EAF37193F562; Wed, 24 Jun 2020 12:28:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 649511C4; Wed, 24 Jun 2020 12: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: Wed, 24 Jun 2020 14:27:00 +0200 Message-Id: <20200624122701.1369327-17-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- 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 d7f9839eb2..864770d506 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 Wed Jun 24 12: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: 72133 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8F995A0350; Wed, 24 Jun 2020 14:30:30 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0F75C1D976; Wed, 24 Jun 2020 14:28:53 +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 419C61D987 for ; Wed, 24 Jun 2020 14:28:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593001730; 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=GKSFH//JO0kRo/nnYyAHd6iXOGytM512hO3cz9eECcM=; b=FM1HYD0/hBf3B9ey8iCdQiLWciiyItVX7uY07sixBWzlEj0HsufMLRkJ/Nr6WS1fmGhnF4 bvmXsylFA8jxxZpMLjZUIDxiXtnbXzQ2b8MFCEoxp5ufJqzpr5pGRs6XITEMYa605OarsM C6sVbhCLeGgF5quXA/2KCONaP6RYWAY= 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-512-IenACzUWMjOvoJ9X9P2enQ-1; Wed, 24 Jun 2020 08:28:47 -0400 X-MC-Unique: IenACzUWMjOvoJ9X9P2enQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B673C1005512; Wed, 24 Jun 2020 12:28:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 461091C4; Wed, 24 Jun 2020 12:28:42 +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: Wed, 24 Jun 2020 14:27:01 +0200 Message-Id: <20200624122701.1369327-18-maxime.coquelin@redhat.com> In-Reply-To: <20200624122701.1369327-1-maxime.coquelin@redhat.com> References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 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. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- 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 864770d506..04c4b25473 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