From patchwork Fri Jun 26 14:04:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72246 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 11938A051C; Fri, 26 Jun 2020 16:05:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E8CD61BFBF; Fri, 26 Jun 2020 16:05:00 +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 D1A301BFBB for ; Fri, 26 Jun 2020 16:04:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lwomoS5iFv58UFiGq+3o0r3oeXlIyZ4IwrDY02MrQBo=; b=A6ZMDwxWLSeV4BulLpvjObubfmPs2yKrvDtmtrIhMpRFl5znCCpX07/18VEtQaDW8hwTd7 mFqVuO8nPpQeTra+qOawFNbwvvTOD2peKzIYXXjvXglfkTXdP/UAM+ICt5FnKh+s4kpUIy b8BEz98nNWbEbk3N6iBGjuHoyrsrrIA= 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-330-7sn-QEziP_qsFMhwSdAnvg-1; Fri, 26 Jun 2020 10:04:57 -0400 X-MC-Unique: 7sn-QEziP_qsFMhwSdAnvg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E26E10059A6; Fri, 26 Jun 2020 14:04:55 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F0C05BAE1; Fri, 26 Jun 2020 14:04: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 , stable@dpdk.org Date: Fri, 26 Jun 2020 16:04:28 +0200 Message-Id: <20200626140441.1441763-2-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 01/14] bus/dpaa: fix null pointer dereference X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patches fixes a null pointer derefencing that happens when the device string passed to the iterator is NULL. This situation can happen when iterating on a class type. For example: RTE_DEV_FOREACH(dev, "class=eth", &dev_iter) { ... } Fixes: e79df833d3f6 ("bus/dpaa: support hotplug ops") Cc: stable@dpdk.org Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- drivers/bus/dpaa/dpaa_bus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c index d53fe6083a..591e28c1e7 100644 --- a/drivers/bus/dpaa/dpaa_bus.c +++ b/drivers/bus/dpaa/dpaa_bus.c @@ -703,6 +703,11 @@ dpaa_bus_dev_iterate(const void *start, const char *str, struct rte_dpaa_device *dev; char *dup, *dev_name = NULL; + if (str == NULL) { + DPAA_BUS_DEBUG("No device string"); + return NULL; + } + /* Expectation is that device would be name=device_name */ if (strncmp(str, "name=", 5) != 0) { DPAA_BUS_DEBUG("Invalid device string (%s)\n", str); From patchwork Fri Jun 26 14:04:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72248 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 DE036A051C; Fri, 26 Jun 2020 16:05:19 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D6B221C01E; Fri, 26 Jun 2020 16:05:10 +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 60A321C001 for ; Fri, 26 Jun 2020 16:05:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180307; 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=eg3gdqOutD9HRD87fYH3LbN7ePw7dWL1Fl7OXQU91kU=; b=f16O4KAQaKINyZs2Lc4pa2jhaXF+9q2wYl344GMwNTtJQwR5/1i0x5DofSs5E1NYH8aMnE qoBE1latwZ9K7dwiRy0Yuc8Wubuhf2qb4EWalBcOLzZFcrWslSf640zm+SD+yL8AUsPT+0 R1DSElIW1UWLsWccvU7YpvGAiJ67vCE= 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-171-IWwgY1_-MwOY3c27e13bQg-1; Fri, 26 Jun 2020 10:05:00 -0400 X-MC-Unique: IWwgY1_-MwOY3c27e13bQg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B777A10059A0; Fri, 26 Jun 2020 14:04:58 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4A745BAE1; Fri, 26 Jun 2020 14:04: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 , stable@dpdk.org Date: Fri, 26 Jun 2020 16:04:29 +0200 Message-Id: <20200626140441.1441763-3-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 02/14] bus/fslmc: fix null pointer dereference X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patches fixes a null pointer derefencing that happens when the device string passed to the iterator is NULL. This situation can happen when iterating on a class type. For example: RTE_DEV_FOREACH(dev, "class=eth", &dev_iter) { ... } Fixes: e67a61614d0b ("bus/fslmc: support device iteration") Cc: stable@dpdk.org Acked-by: Adrián Moreno 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..ac46eb4fe8 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -603,6 +603,11 @@ fslmc_bus_dev_iterate(const void *start, const char *str, struct rte_dpaa2_device *dev; char *dup, *dev_name = NULL; + if (str == NULL) { + DPAA2_BUS_DEBUG("No device string"); + return NULL; + } + /* Expectation is that device would be name=device_name */ if (strncmp(str, "name=", 5) != 0) { DPAA2_BUS_DEBUG("Invalid device string (%s)\n", str); From patchwork Fri Jun 26 14:04:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72249 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 00DBCA051C; Fri, 26 Jun 2020 16:05:31 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5DF6D1C029; Fri, 26 Jun 2020 16:05:13 +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 11E011BFFF for ; Fri, 26 Jun 2020 16:05:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a11ps+nTW+xpyUwaJvAVwALxg76U10DOIwPcCvQkmK4=; b=XXbe46Aiv9kOCoTdD1lvYYOKxfSxLPzhuE7LsDSNmaEg/NU392RW0c4Av/F4wdwycYzYeH p/Zh7aFnSUyl59YsvD/DmZdeBG8E+TdY96zzAFeNF2AsmeGibHWHpiDJPeKRRfzTCqvGKl gzZ3R/YCb883ZjWaCGNOP1XvaYX7z6k= 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-332-oOl5XxcvOYKvqe04LI7PfQ-1; Fri, 26 Jun 2020 10:05:06 -0400 X-MC-Unique: oOl5XxcvOYKvqe04LI7PfQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01223800D5C; Fri, 26 Jun 2020 14:05:05 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 289D580882; Fri, 26 Jun 2020 14:04:58 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:30 +0200 Message-Id: <20200626140441.1441763-4-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 03/14] vhost: introduce vDPA devices class X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch introduces vDPA device class. It will enable application to iterate over the vDPA devices. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vdpa.c | 115 +++++++++++++++++++++++++++++++++------- 1 file changed, 97 insertions(+), 18 deletions(-) diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 1f5cdcd64b..a429841691 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -10,11 +10,12 @@ #include +#include #include #include "rte_vdpa.h" #include "vhost.h" -static struct rte_vdpa_device *vdpa_devices[MAX_VHOST_DEVICE]; +static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; static uint32_t vdpa_device_num; static bool @@ -46,35 +47,28 @@ rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, struct rte_vdpa_dev_ops *ops) { struct rte_vdpa_device *dev; - char device_name[MAX_VDPA_NAME_LEN]; int i; if (vdpa_device_num >= MAX_VHOST_DEVICE || addr == NULL || ops == NULL) return -1; for (i = 0; i < MAX_VHOST_DEVICE; i++) { - dev = vdpa_devices[i]; - if (dev && is_same_vdpa_device(&dev->addr, addr)) + dev = &vdpa_devices[i]; + if (dev->ops && is_same_vdpa_device(&dev->addr, addr)) return -1; } for (i = 0; i < MAX_VHOST_DEVICE; i++) { - if (vdpa_devices[i] == NULL) + if (vdpa_devices[i].ops == NULL) break; } if (i == MAX_VHOST_DEVICE) return -1; - snprintf(device_name, sizeof(device_name), "vdpa-dev-%d", i); - dev = rte_zmalloc(device_name, sizeof(struct rte_vdpa_device), - RTE_CACHE_LINE_SIZE); - if (!dev) - return -1; - + dev = &vdpa_devices[i]; memcpy(&dev->addr, addr, sizeof(struct rte_vdpa_dev_addr)); dev->ops = ops; - vdpa_devices[i] = dev; vdpa_device_num++; return i; @@ -83,11 +77,10 @@ rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, int rte_vdpa_unregister_device(int did) { - if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did] == NULL) + if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did].ops == NULL) return -1; - rte_free(vdpa_devices[did]); - vdpa_devices[did] = NULL; + memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); vdpa_device_num--; return did; @@ -103,8 +96,11 @@ rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr) return -1; for (i = 0; i < MAX_VHOST_DEVICE; ++i) { - dev = vdpa_devices[i]; - if (dev && is_same_vdpa_device(&dev->addr, addr)) + dev = &vdpa_devices[i]; + if (dev->ops == NULL) + continue; + + if (is_same_vdpa_device(&dev->addr, addr)) return i; } @@ -117,7 +113,7 @@ rte_vdpa_get_device(int did) if (did < 0 || did >= MAX_VHOST_DEVICE) return NULL; - return vdpa_devices[did]; + return &vdpa_devices[did]; } int @@ -274,3 +270,86 @@ rte_vdpa_reset_stats(int did, uint16_t qid) return vdpa_dev->ops->reset_stats(did, qid); } + +static uint16_t +vdpa_dev_to_id(const struct rte_vdpa_device *dev) +{ + if (dev == NULL) + return MAX_VHOST_DEVICE; + + if (dev < &vdpa_devices[0] || + dev >= &vdpa_devices[MAX_VHOST_DEVICE]) + return MAX_VHOST_DEVICE; + + return (uint16_t)(dev - vdpa_devices); +} + +static int +vdpa_dev_match(struct rte_vdpa_device *dev, + const struct rte_device *rte_dev) +{ + struct rte_vdpa_dev_addr addr; + + /* Only PCI bus supported for now */ + if (strcmp(rte_dev->bus->name, "pci") != 0) + return -1; + + addr.type = VDPA_ADDR_PCI; + + if (rte_pci_addr_parse(rte_dev->name, &addr.pci_addr) != 0) + return -1; + + if (!is_same_vdpa_device(&dev->addr, &addr)) + return -1; + + return 0; +} + +/* Generic rte_vdpa_dev comparison function. */ +typedef int (*rte_vdpa_cmp_t)(struct rte_vdpa_device *, + const struct rte_device *rte_dev); + +static struct rte_vdpa_device * +vdpa_find_device(const struct rte_vdpa_device *start, rte_vdpa_cmp_t cmp, + struct rte_device *rte_dev) +{ + struct rte_vdpa_device *dev; + uint16_t idx; + + if (start != NULL) + idx = vdpa_dev_to_id(start) + 1; + else + idx = 0; + for (; idx < MAX_VHOST_DEVICE; idx++) { + dev = &vdpa_devices[idx]; + /* + * ToDo: Certainly better to introduce a state field, + * but rely on ops being set for now. + */ + if (dev->ops == NULL) + continue; + if (cmp(dev, rte_dev) == 0) + return dev; + } + return NULL; +} + +static void * +vdpa_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it) +{ + struct rte_vdpa_device *vdpa_dev = NULL; + + RTE_SET_USED(str); + + vdpa_dev = vdpa_find_device(start, vdpa_dev_match, it->device); + + return vdpa_dev; +} + +static struct rte_class rte_class_vdpa = { + .dev_iterate = vdpa_dev_iterate, +}; + +RTE_REGISTER_CLASS(vdpa, rte_class_vdpa); From patchwork Fri Jun 26 14:04:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72250 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 6637EA051C; Fri, 26 Jun 2020 16:05:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 05EBA1BFE8; Fri, 26 Jun 2020 16:05:28 +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 86D5A1BFE8 for ; Fri, 26 Jun 2020 16:05:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180326; 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=P4rupp0MGzlOUDCaIaDyAqOQQud1dJ94EQ1dbg973i0=; b=Jj6GUYDHDwtpmS54I8bglSIcnQ2DATL8f1O2BITOaIs36b7OcM+wejzJ9JIBQscvXLCh3S FBAz3fjl5lvNPLjpfxxVhT9Ecg5215HEeM1Ol+1/J4hJG2Ig2m7WUREpdghsAYQVqWrbJU U5hCfJrhim03/LUYXtwceMOqCU0k3cY= 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-467-7Wz96Z4MObaulxp8OsjRcw-1; Fri, 26 Jun 2020 10:05:24 -0400 X-MC-Unique: 7Wz96Z4MObaulxp8OsjRcw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD93410059C1; Fri, 26 Jun 2020 14:05:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D3105BAE1; Fri, 26 Jun 2020 14:05:05 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:31 +0200 Message-Id: <20200626140441.1441763-5-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 04/14] vhost: make vDPA framework bus agnostic X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch makes the vDPA framework to no more support only PCI devices, but any devices by relying on the generic device name as identifier. Acked-by: Adrián Moreno 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..87334c88c0 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -18,43 +18,22 @@ static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; static uint32_t vdpa_device_num; -static bool -is_same_vdpa_device(struct rte_vdpa_dev_addr *a, - struct rte_vdpa_dev_addr *b) -{ - bool ret = true; - - if (a->type != b->type) - return false; - - switch (a->type) { - case VDPA_ADDR_PCI: - if (a->pci_addr.domain != b->pci_addr.domain || - a->pci_addr.bus != b->pci_addr.bus || - a->pci_addr.devid != b->pci_addr.devid || - a->pci_addr.function != b->pci_addr.function) - ret = false; - break; - default: - break; - } - - return ret; -} - int -rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, +rte_vdpa_register_device(struct rte_device *rte_dev, struct rte_vdpa_dev_ops *ops) { struct rte_vdpa_device *dev; int i; - if (vdpa_device_num >= MAX_VHOST_DEVICE || addr == NULL || ops == NULL) + if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL) return -1; for (i = 0; i < MAX_VHOST_DEVICE; i++) { dev = &vdpa_devices[i]; - if (dev->ops && is_same_vdpa_device(&dev->addr, addr)) + if (dev->ops == NULL) + continue; + + if (dev->device == rte_dev) return -1; } @@ -67,7 +46,7 @@ rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr, return -1; dev = &vdpa_devices[i]; - memcpy(&dev->addr, addr, sizeof(struct rte_vdpa_dev_addr)); + dev->device = rte_dev; dev->ops = ops; vdpa_device_num++; @@ -87,12 +66,33 @@ rte_vdpa_unregister_device(int did) } int -rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr) +rte_vdpa_find_device_id(struct rte_vdpa_device *dev) +{ + struct rte_vdpa_device *tmp_dev; + int i; + + if (dev == NULL) + return -1; + + for (i = 0; i < MAX_VHOST_DEVICE; ++i) { + tmp_dev = &vdpa_devices[i]; + if (tmp_dev->ops == NULL) + continue; + + if (tmp_dev == dev) + return i; + } + + return -1; +} + +int +rte_vdpa_find_device_id_by_name(const char *name) { struct rte_vdpa_device *dev; int i; - if (addr == NULL) + if (name == NULL) return -1; for (i = 0; i < MAX_VHOST_DEVICE; ++i) { @@ -100,7 +100,7 @@ rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr) if (dev->ops == NULL) continue; - if (is_same_vdpa_device(&dev->addr, addr)) + if (strncmp(dev->device->name, name, RTE_DEV_NAME_MAX_LEN) == 0) return i; } @@ -288,21 +288,10 @@ static int vdpa_dev_match(struct rte_vdpa_device *dev, const struct rte_device *rte_dev) { - struct rte_vdpa_dev_addr addr; + if (dev->device == rte_dev) + return 0; - /* Only PCI bus supported for now */ - if (strcmp(rte_dev->bus->name, "pci") != 0) - return -1; - - addr.type = VDPA_ADDR_PCI; - - if (rte_pci_addr_parse(rte_dev->name, &addr.pci_addr) != 0) - return -1; - - if (!is_same_vdpa_device(&dev->addr, &addr)) - return -1; - - return 0; + return -1; } /* Generic rte_vdpa_dev comparison function. */ From patchwork Fri Jun 26 14:04:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72251 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 91F92A051C; Fri, 26 Jun 2020 16:06:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 895CC1C068; Fri, 26 Jun 2020 16:05:31 +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 AEB541C067 for ; Fri, 26 Jun 2020 16:05:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=olqraQL7aU3zbGTHTX/8e+ullM88PCrFdhc27f4L2OQ=; b=Pz6ovq15fQsoiC4QFMz7AC9F4fk59MrWrcRzxRZkXQhE8Oqb78WS/V62ptgn1JJUvUgIhk KrORDxNSP+tOK7YrAIN1MNkpEZ3YJH5SRmoswUks1WbiwwBGbTcMsy1CU11uQhihmG715v AAFYSc5c/C3RKOfuXu5q2I0OXMJjcFU= 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-318--Mo_3dHqOrie-1hiKXowMQ-1; Fri, 26 Jun 2020 10:05:27 -0400 X-MC-Unique: -Mo_3dHqOrie-1hiKXowMQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E30F4BFCB; Fri, 26 Jun 2020 14:05:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 147C85BAE1; Fri, 26 Jun 2020 14:05:22 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:32 +0200 Message-Id: <20200626140441.1441763-6-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 05/14] vhost: replace device ID in vDPA ops X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch is a preliminary step to get rid of the vDPA device ID. It makes vDPA callbacks to use the vDPA device struct as a reference instead of the ID. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- drivers/vdpa/ifc/ifcvf_vdpa.c | 79 ++++++++++---------- drivers/vdpa/mlx5/mlx5_vdpa.c | 134 ++++++++++++++++++++-------------- drivers/vdpa/mlx5/mlx5_vdpa.h | 2 +- examples/vdpa/main.c | 4 +- lib/librte_vhost/rte_vdpa.h | 28 ++++--- lib/librte_vhost/socket.c | 6 +- lib/librte_vhost/vdpa.c | 101 ++++++++++++------------- 7 files changed, 195 insertions(+), 159 deletions(-) diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index ac9e218c23..0418f9a07f 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -55,7 +55,7 @@ struct ifcvf_internal { pthread_t tid; /* thread for notify relay */ int epfd; int vid; - int did; + struct rte_vdpa_device *vdev; uint16_t max_queues; uint64_t features; rte_atomic32_t started; @@ -84,7 +84,7 @@ static pthread_mutex_t internal_list_lock = PTHREAD_MUTEX_INITIALIZER; static void update_used_ring(struct ifcvf_internal *internal, uint16_t qid); static struct internal_list * -find_internal_resource_by_did(int did) +find_internal_resource_by_vdev(struct rte_vdpa_device *vdev) { int found = 0; struct internal_list *list; @@ -92,7 +92,7 @@ find_internal_resource_by_did(int did) pthread_mutex_lock(&internal_list_lock); TAILQ_FOREACH(list, &internal_list, next) { - if (did == list->internal->did) { + if (vdev == list->internal->vdev) { found = 1; break; } @@ -877,14 +877,14 @@ ifcvf_sw_fallback_switchover(struct ifcvf_internal *internal) static int ifcvf_dev_config(int vid) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; struct ifcvf_internal *internal; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -894,7 +894,8 @@ ifcvf_dev_config(int vid) update_datapath(internal); if (rte_vhost_host_notifier_ctrl(vid, true) != 0) - DRV_LOG(NOTICE, "vDPA (%d): software relay is used.", did); + DRV_LOG(NOTICE, "vDPA (%s): software relay is used.", + vdev->device->name); return 0; } @@ -902,14 +903,14 @@ ifcvf_dev_config(int vid) static int ifcvf_dev_close(int vid) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; struct ifcvf_internal *internal; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -941,15 +942,15 @@ static int ifcvf_set_features(int vid) { uint64_t features = 0; - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; struct ifcvf_internal *internal; uint64_t log_base = 0, log_size = 0; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -974,13 +975,13 @@ ifcvf_set_features(int vid) static int ifcvf_get_vfio_group_fd(int vid) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -990,13 +991,13 @@ ifcvf_get_vfio_group_fd(int vid) static int ifcvf_get_vfio_device_fd(int vid) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -1006,16 +1007,16 @@ ifcvf_get_vfio_device_fd(int vid) static int ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) { - int did; + struct rte_vdpa_device *vdev; struct internal_list *list; struct ifcvf_internal *internal; struct vfio_region_info reg = { .argsz = sizeof(reg) }; int ret; - did = rte_vhost_get_vdpa_device_id(vid); - list = find_internal_resource_by_did(did); + vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -1036,13 +1037,13 @@ ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) } static int -ifcvf_get_queue_num(int did, uint32_t *queue_num) +ifcvf_get_queue_num(struct rte_vdpa_device *vdev, uint32_t *queue_num) { struct internal_list *list; - list = find_internal_resource_by_did(did); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -1052,13 +1053,13 @@ ifcvf_get_queue_num(int did, uint32_t *queue_num) } static int -ifcvf_get_vdpa_features(int did, uint64_t *features) +ifcvf_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features) { struct internal_list *list; - list = find_internal_resource_by_did(did); + list = find_internal_resource_by_vdev(vdev); if (list == NULL) { - DRV_LOG(ERR, "Invalid device id: %d", did); + DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); return -1; } @@ -1074,8 +1075,10 @@ ifcvf_get_vdpa_features(int did, uint64_t *features) 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER | \ 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) static int -ifcvf_get_protocol_features(int did __rte_unused, uint64_t *features) +ifcvf_get_protocol_features(struct rte_vdpa_device *vdev, uint64_t *features) { + RTE_SET_USED(vdev); + *features = VDPA_SUPPORTED_PROTOCOL_FEATURES; return 0; } @@ -1186,8 +1189,8 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, } internal->sw_lm = sw_fallback_lm; - internal->did = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops); - if (internal->did < 0) { + internal->vdev = rte_vdpa_register_device(&pci_dev->device, &ifcvf_ops); + if (internal->vdev == NULL) { DRV_LOG(ERR, "failed to register device %s", pci_dev->name); goto error; } @@ -1230,7 +1233,7 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev) rte_pci_unmap_device(internal->pdev); rte_vfio_container_destroy(internal->vfio_container_fd); - rte_vdpa_unregister_device(internal->did); + rte_vdpa_unregister_device(internal->vdev); pthread_mutex_lock(&internal_list_lock); TAILQ_REMOVE(&internal_list, list, next); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index 7b5ae62bdc..9ea032d57b 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -50,21 +50,21 @@ static pthread_mutex_t priv_list_lock = PTHREAD_MUTEX_INITIALIZER; int mlx5_vdpa_logtype; static struct mlx5_vdpa_priv * -mlx5_vdpa_find_priv_resource_by_did(int did) +mlx5_vdpa_find_priv_resource_by_vdev(struct rte_vdpa_device *vdev) { struct mlx5_vdpa_priv *priv; int found = 0; pthread_mutex_lock(&priv_list_lock); TAILQ_FOREACH(priv, &priv_list, next) { - if (did == priv->id) { + if (vdev == priv->vdev) { found = 1; break; } } pthread_mutex_unlock(&priv_list_lock); if (!found) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); rte_errno = EINVAL; return NULL; } @@ -72,12 +72,13 @@ mlx5_vdpa_find_priv_resource_by_did(int did) } static int -mlx5_vdpa_get_queue_num(int did, uint32_t *queue_num) +mlx5_vdpa_get_queue_num(struct rte_vdpa_device *vdev, uint32_t *queue_num) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -1; } *queue_num = priv->caps.max_num_virtio_queues; @@ -85,12 +86,13 @@ mlx5_vdpa_get_queue_num(int did, uint32_t *queue_num) } static int -mlx5_vdpa_get_vdpa_features(int did, uint64_t *features) +mlx5_vdpa_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -1; } *features = MLX5_VDPA_DEFAULT_FEATURES; @@ -110,12 +112,14 @@ mlx5_vdpa_get_vdpa_features(int did, uint64_t *features) } static int -mlx5_vdpa_get_protocol_features(int did, uint64_t *features) +mlx5_vdpa_get_protocol_features(struct rte_vdpa_device *vdev, + uint64_t *features) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -1; } *features = MLX5_VDPA_PROTOCOL_FEATURES; @@ -125,11 +129,13 @@ mlx5_vdpa_get_protocol_features(int did, uint64_t *features) static int mlx5_vdpa_set_vring_state(int vid, int vring, int state) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } if (vring >= (int)priv->caps.max_num_virtio_queues * 2) { @@ -165,14 +171,16 @@ mlx5_vdpa_direct_db_prepare(struct mlx5_vdpa_priv *priv) static int mlx5_vdpa_features_set(int vid) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); uint64_t log_base, log_size; uint64_t features; int ret; if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } ret = rte_vhost_get_negotiated_features(vid, &features); @@ -284,12 +292,14 @@ mlx5_vdpa_mtu_set(struct mlx5_vdpa_priv *priv) static int mlx5_vdpa_dev_close(int vid) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); int ret = 0; if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -1; } if (priv->configured) @@ -312,11 +322,13 @@ mlx5_vdpa_dev_close(int vid) static int mlx5_vdpa_dev_config(int vid) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } if (priv->configured && mlx5_vdpa_dev_close(vid)) { @@ -325,7 +337,8 @@ mlx5_vdpa_dev_config(int vid) } priv->vid = vid; if (mlx5_vdpa_mtu_set(priv)) - DRV_LOG(WARNING, "MTU cannot be set on device %d.", did); + DRV_LOG(WARNING, "MTU cannot be set on device %s.", + vdev->device->name); if (mlx5_vdpa_pd_create(priv) || mlx5_vdpa_mem_register(priv) || mlx5_vdpa_direct_db_prepare(priv) || mlx5_vdpa_virtqs_prepare(priv) || mlx5_vdpa_steer_setup(priv) || @@ -341,11 +354,13 @@ mlx5_vdpa_dev_config(int vid) static int mlx5_vdpa_get_device_fd(int vid) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } return priv->ctx->cmd_fd; @@ -354,17 +369,19 @@ mlx5_vdpa_get_device_fd(int vid) static int mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) { - int did = rte_vhost_get_vdpa_device_id(vid); - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct rte_vdpa_device *vdev = rte_vdpa_get_device( + rte_vhost_get_vdpa_device_id(vid)); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); RTE_SET_USED(qid); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name); return -EINVAL; } if (!priv->var) { - DRV_LOG(ERR, "VAR was not created for device %d, is the device" - " configured?.", did); + DRV_LOG(ERR, "VAR was not created for device %s, is the device" + " configured?.", vdev->device->name); return -EINVAL; } *offset = priv->var->mmap_off; @@ -373,8 +390,9 @@ mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) } static int -mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, - unsigned int size) +mlx5_vdpa_get_stats_names(struct rte_vdpa_device *vdev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size) { static const char *mlx5_vdpa_stats_names[MLX5_VDPA_STATS_MAX] = { "received_descriptors", @@ -384,11 +402,12 @@ mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, "invalid buffer", "completion errors", }; - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); unsigned int i; if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name); return -ENODEV; } if (!stats_names) @@ -401,51 +420,57 @@ mlx5_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, } static int -mlx5_vdpa_get_stats(int did, int qid, struct rte_vdpa_stat *stats, - unsigned int n) +mlx5_vdpa_get_stats(struct rte_vdpa_device *vdev, int qid, + struct rte_vdpa_stat *stats, unsigned int n) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name); return -ENODEV; } if (!priv->configured) { - DRV_LOG(ERR, "Device %d was not configured.", did); + DRV_LOG(ERR, "Device %s was not configured.", + vdev->device->name); return -ENODATA; } if (qid >= (int)priv->nr_virtqs) { - DRV_LOG(ERR, "Too big vring id: %d.", qid); + DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid, + vdev->device->name); return -E2BIG; } if (!priv->caps.queue_counters_valid) { - DRV_LOG(ERR, "Virtq statistics is not supported for device %d.", - did); + DRV_LOG(ERR, "Virtq statistics is not supported for device %s.", + vdev->device->name); return -ENOTSUP; } return mlx5_vdpa_virtq_stats_get(priv, qid, stats, n); } static int -mlx5_vdpa_reset_stats(int did, int qid) +mlx5_vdpa_reset_stats(struct rte_vdpa_device *vdev, int qid) { - struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did); + struct mlx5_vdpa_priv *priv = + mlx5_vdpa_find_priv_resource_by_vdev(vdev); if (priv == NULL) { - DRV_LOG(ERR, "Invalid device id: %d.", did); + DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name); return -ENODEV; } if (!priv->configured) { - DRV_LOG(ERR, "Device %d was not configured.", did); + DRV_LOG(ERR, "Device %s was not configured.", + vdev->device->name); return -ENODATA; } if (qid >= (int)priv->nr_virtqs) { - DRV_LOG(ERR, "Too big vring id: %d.", qid); + DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid, + vdev->device->name); return -E2BIG; } if (!priv->caps.queue_counters_valid) { - DRV_LOG(ERR, "Virtq statistics is not supported for device %d.", - did); + DRV_LOG(ERR, "Virtq statistics is not supported for device %s.", + vdev->device->name); return -ENOTSUP; } return mlx5_vdpa_virtq_stats_reset(priv, qid); @@ -687,8 +712,9 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, DRV_LOG(ERR, "Failed to allocate VAR %u.\n", errno); goto error; } - priv->id = rte_vdpa_register_device(&pci_dev->device, &mlx5_vdpa_ops); - if (priv->id < 0) { + priv->vdev = rte_vdpa_register_device(&pci_dev->device, + &mlx5_vdpa_ops); + if (priv->vdev == NULL) { DRV_LOG(ERR, "Failed to register vDPA device."); rte_errno = rte_errno ? rte_errno : EINVAL; goto error; diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index 5fc801eff3..ea09576c5a 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -103,7 +103,7 @@ struct mlx5_vdpa_priv { TAILQ_ENTRY(mlx5_vdpa_priv) next; uint8_t configured; uint8_t direct_notifier; /* Whether direct notifier is on or off. */ - int id; /* vDPA device id. */ + struct rte_vdpa_device *vdev; /* vDPA device. */ int vid; /* vhost device id. */ struct ibv_context *ctx; /* Device context. */ struct rte_pci_device *pci_dev; diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index e72f6646e7..bdb00603cc 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -291,13 +291,13 @@ static void cmd_list_vdpa_devices_parsed( vdev = rte_vdpa_get_device(did); if (!vdev) continue; - if (vdev->ops->get_queue_num(did, &queue_num) < 0) { + if (vdev->ops->get_queue_num(vdev, &queue_num) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa queue number " "for device id %d.\n", did); continue; } - if (vdev->ops->get_features(did, &features) < 0) { + if (vdev->ops->get_features(vdev, &features) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa features " "for device id %d.\n", did); diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index b752dfeb96..109cf83b8f 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -21,6 +21,8 @@ /** Maximum name length for statistics counters */ #define RTE_VDPA_STATS_NAME_SIZE 64 +struct rte_vdpa_device; + /** * A vDPA device statistic structure * @@ -51,13 +53,14 @@ struct rte_vdpa_stat_name { */ struct rte_vdpa_dev_ops { /** Get capabilities of this device */ - int (*get_queue_num)(int did, uint32_t *queue_num); + int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num); /** Get supported features of this device */ - int (*get_features)(int did, uint64_t *features); + int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features); /** Get supported protocol features of this device */ - int (*get_protocol_features)(int did, uint64_t *protocol_features); + int (*get_protocol_features)(struct rte_vdpa_device *dev, + uint64_t *protocol_features); /** Driver configure/close the device */ int (*dev_conf)(int vid); @@ -83,15 +86,16 @@ struct rte_vdpa_dev_ops { uint64_t *offset, uint64_t *size); /** Get statistics name */ - int (*get_stats_names)(int did, struct rte_vdpa_stat_name *stats_names, - unsigned int size); + int (*get_stats_names)(struct rte_vdpa_device *dev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size); /** Get statistics of the queue */ - int (*get_stats)(int did, int qid, struct rte_vdpa_stat *stats, - unsigned int n); + int (*get_stats)(struct rte_vdpa_device *dev, int qid, + struct rte_vdpa_stat *stats, unsigned int n); /** Reset statistics of the queue */ - int (*reset_stats)(int did, int qid); + int (*reset_stats)(struct rte_vdpa_device *dev, int qid); /** Reserved for future extension */ void *reserved[2]; @@ -118,10 +122,10 @@ struct rte_vdpa_device { * @param ops * the vdpa device operations * @return - * device id on success, -1 on failure + * vDPA device pointer on success, NULL on failure */ __rte_experimental -int +struct rte_vdpa_device * rte_vdpa_register_device(struct rte_device *rte_dev, struct rte_vdpa_dev_ops *ops); @@ -132,13 +136,13 @@ rte_vdpa_register_device(struct rte_device *rte_dev, * Unregister a vdpa device * * @param did - * vdpa device id + * vDPA device pointer * @return * device id on success, -1 on failure */ __rte_experimental int -rte_vdpa_unregister_device(int did); +rte_vdpa_unregister_device(struct rte_vdpa_device *); /** * @warning diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 0a66ef9767..da575b608c 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -712,7 +712,7 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features) goto unlock_exit; } - if (vdpa_dev->ops->get_features(did, &vdpa_features) < 0) { + if (vdpa_dev->ops->get_features(vdpa_dev, &vdpa_features) < 0) { VHOST_LOG_CONFIG(ERR, "failed to get vdpa features " "for socket file %s.\n", path); @@ -767,7 +767,7 @@ rte_vhost_driver_get_protocol_features(const char *path, goto unlock_exit; } - if (vdpa_dev->ops->get_protocol_features(did, + if (vdpa_dev->ops->get_protocol_features(vdpa_dev, &vdpa_protocol_features) < 0) { VHOST_LOG_CONFIG(ERR, "failed to get vdpa protocol features " @@ -809,7 +809,7 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num) goto unlock_exit; } - if (vdpa_dev->ops->get_queue_num(did, &vdpa_queue_num) < 0) { + if (vdpa_dev->ops->get_queue_num(vdpa_dev, &vdpa_queue_num) < 0) { VHOST_LOG_CONFIG(ERR, "failed to get vdpa queue number " "for socket file %s.\n", path); diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 87334c88c0..49ada00277 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -18,52 +18,6 @@ static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; static uint32_t vdpa_device_num; -int -rte_vdpa_register_device(struct rte_device *rte_dev, - struct rte_vdpa_dev_ops *ops) -{ - struct rte_vdpa_device *dev; - int i; - - if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL) - return -1; - - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - dev = &vdpa_devices[i]; - if (dev->ops == NULL) - continue; - - if (dev->device == rte_dev) - return -1; - } - - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - if (vdpa_devices[i].ops == NULL) - break; - } - - if (i == MAX_VHOST_DEVICE) - return -1; - - dev = &vdpa_devices[i]; - dev->device = rte_dev; - dev->ops = ops; - vdpa_device_num++; - - return i; -} - -int -rte_vdpa_unregister_device(int did) -{ - if (did < 0 || did >= MAX_VHOST_DEVICE || vdpa_devices[did].ops == NULL) - return -1; - - memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); - vdpa_device_num--; - - return did; -} int rte_vdpa_find_device_id(struct rte_vdpa_device *dev) @@ -116,6 +70,55 @@ rte_vdpa_get_device(int did) return &vdpa_devices[did]; } +struct rte_vdpa_device * +rte_vdpa_register_device(struct rte_device *rte_dev, + struct rte_vdpa_dev_ops *ops) +{ + struct rte_vdpa_device *dev; + int i; + + if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL) + return NULL; + + for (i = 0; i < MAX_VHOST_DEVICE; i++) { + dev = &vdpa_devices[i]; + if (dev->ops == NULL) + continue; + + if (dev->device == rte_dev) + return NULL; + } + + for (i = 0; i < MAX_VHOST_DEVICE; i++) { + if (vdpa_devices[i].ops == NULL) + break; + } + + if (i == MAX_VHOST_DEVICE) + return NULL; + + dev = &vdpa_devices[i]; + dev->device = rte_dev; + dev->ops = ops; + vdpa_device_num++; + + return dev; +} + +int +rte_vdpa_unregister_device(struct rte_vdpa_device *vdev) +{ + int did = rte_vdpa_find_device_id(vdev); + + if (did < 0 || vdpa_devices[did].ops == NULL) + return -1; + + memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); + vdpa_device_num--; + + return 0; +} + int rte_vdpa_get_device_num(void) { @@ -236,7 +239,7 @@ rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats_names, -ENOTSUP); - return vdpa_dev->ops->get_stats_names(did, stats_names, size); + return vdpa_dev->ops->get_stats_names(vdpa_dev, stats_names, size); } int @@ -254,7 +257,7 @@ rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats, RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats, -ENOTSUP); - return vdpa_dev->ops->get_stats(did, qid, stats, n); + return vdpa_dev->ops->get_stats(vdpa_dev, qid, stats, n); } int @@ -268,7 +271,7 @@ rte_vdpa_reset_stats(int did, uint16_t qid) RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->reset_stats, -ENOTSUP); - return vdpa_dev->ops->reset_stats(did, qid); + return vdpa_dev->ops->reset_stats(vdpa_dev, qid); } static uint16_t From patchwork Fri Jun 26 14:04:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72252 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 A42BEA051C; Fri, 26 Jun 2020 16:06:24 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DA7CE1C066; Fri, 26 Jun 2020 16:05:39 +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 4C0011BFC3 for ; Fri, 26 Jun 2020 16:05:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OxDM6oxq26O6xQfwyzL1uhxUA1T/3N8FSBILErxRHWo=; b=XzSiFJsXAod5UTM05CJiOqeg/e+3xYVtPq+VlmDGDegn+62syhDB/HsHknXYXu4+eU4/+J Xt8K9vyTG413kreAljlN7ymaBGiNmnGjkIl+4n56t/uze8CqA27jHaUDpcrZERxLtm7bLU WrgvMZAsxvqJLLthxmcscqkPTzNpMmE= 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-467-5xDyrNYkOKKYBg0-vB7TiA-1; Fri, 26 Jun 2020 10:05:36 -0400 X-MC-Unique: 5xDyrNYkOKKYBg0-vB7TiA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8759A804006; Fri, 26 Jun 2020 14:05:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E4505BAE1; Fri, 26 Jun 2020 14:05:26 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:33 +0200 Message-Id: <20200626140441.1441763-7-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 06/14] vhost: replace vDPA device ID in Vhost X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This removes the notion of device ID in Vhost library as a preliminary step to get rid of the vDPA device ID. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- drivers/vdpa/ifc/ifcvf_vdpa.c | 12 ++++---- drivers/vdpa/mlx5/mlx5_vdpa.c | 18 ++++------- examples/vdpa/main.c | 9 +++++- lib/librte_vhost/rte_vhost.h | 20 ++++++------ lib/librte_vhost/rte_vhost_version.map | 4 +-- lib/librte_vhost/socket.c | 42 ++++++++++---------------- lib/librte_vhost/vhost.c | 19 +++++------- lib/librte_vhost/vhost.h | 8 ++--- lib/librte_vhost/vhost_user.c | 28 +++++------------ 9 files changed, 66 insertions(+), 94 deletions(-) diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index 0418f9a07f..4163047744 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -881,7 +881,7 @@ ifcvf_dev_config(int vid) struct internal_list *list; struct ifcvf_internal *internal; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -907,7 +907,7 @@ ifcvf_dev_close(int vid) struct internal_list *list; struct ifcvf_internal *internal; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -947,7 +947,7 @@ ifcvf_set_features(int vid) struct ifcvf_internal *internal; uint64_t log_base = 0, log_size = 0; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -978,7 +978,7 @@ ifcvf_get_vfio_group_fd(int vid) struct rte_vdpa_device *vdev; struct internal_list *list; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -994,7 +994,7 @@ ifcvf_get_vfio_device_fd(int vid) struct rte_vdpa_device *vdev; struct internal_list *list; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); @@ -1013,7 +1013,7 @@ ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) struct vfio_region_info reg = { .argsz = sizeof(reg) }; int ret; - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); + vdev = rte_vhost_get_vdpa_device(vid); list = find_internal_resource_by_vdev(vdev); if (list == NULL) { DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index 9ea032d57b..47db5fd6f4 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -129,8 +129,7 @@ mlx5_vdpa_get_protocol_features(struct rte_vdpa_device *vdev, static int mlx5_vdpa_set_vring_state(int vid, int vring, int state) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); @@ -171,8 +170,7 @@ mlx5_vdpa_direct_db_prepare(struct mlx5_vdpa_priv *priv) static int mlx5_vdpa_features_set(int vid) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); uint64_t log_base, log_size; @@ -292,8 +290,7 @@ mlx5_vdpa_mtu_set(struct mlx5_vdpa_priv *priv) static int mlx5_vdpa_dev_close(int vid) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); int ret = 0; @@ -322,8 +319,7 @@ mlx5_vdpa_dev_close(int vid) static int mlx5_vdpa_dev_config(int vid) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); @@ -354,8 +350,7 @@ mlx5_vdpa_dev_config(int vid) static int mlx5_vdpa_get_device_fd(int vid) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); @@ -369,8 +364,7 @@ mlx5_vdpa_get_device_fd(int vid) static int mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) { - struct rte_vdpa_device *vdev = rte_vdpa_get_device( - rte_vhost_get_vdpa_device_id(vid)); + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_vdev(vdev); diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index bdb00603cc..6a719e32d8 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -149,6 +149,7 @@ start_vdpa(struct vdpa_port *vport) { int ret; char *socket_path = vport->ifname; + struct rte_vdpa_device *vdev; int did = vport->did; if (client_mode) @@ -173,7 +174,13 @@ start_vdpa(struct vdpa_port *vport) "register driver ops failed: %s\n", socket_path); - ret = rte_vhost_driver_attach_vdpa_device(socket_path, did); + vdev = rte_vdpa_get_device(did); + if (!vdev) + rte_exit(EXIT_FAILURE, + "vDPA device retrieval failed: %p\n", + vdev); + + ret = rte_vhost_driver_attach_vdpa_device(socket_path, vdev); if (ret != 0) rte_exit(EXIT_FAILURE, "attach vdpa device failed: %s\n", diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h index d43669f2c2..2fbc364643 100644 --- a/lib/librte_vhost/rte_vhost.h +++ b/lib/librte_vhost/rte_vhost.h @@ -90,6 +90,7 @@ extern "C" { #define VHOST_USER_F_PROTOCOL_FEATURES 30 #endif +struct rte_vdpa_device; /** * Information relating to memory regions including offsets to @@ -402,14 +403,15 @@ int rte_vhost_driver_unregister(const char *path); * * @param path * The vhost-user socket file path - * @param did - * Device id + * @param dev + * vDPA device pointer * @return * 0 on success, -1 on failure */ __rte_experimental int -rte_vhost_driver_attach_vdpa_device(const char *path, int did); +rte_vhost_driver_attach_vdpa_device(const char *path, + struct rte_vdpa_device *dev); /** * Unset the vdpa device id @@ -429,11 +431,11 @@ rte_vhost_driver_detach_vdpa_device(const char *path); * @param path * The vhost-user socket file path * @return - * Device id, -1 on failure + * vDPA device pointer, NULL on failure */ __rte_experimental -int -rte_vhost_driver_get_vdpa_device_id(const char *path); +struct rte_vdpa_device * +rte_vhost_driver_get_vdpa_device(const char *path); /** * Set the feature bits the vhost-user driver supports. @@ -977,11 +979,11 @@ rte_vhost_extern_callback_register(int vid, * @param vid * vhost device id * @return - * device id + * vDPA device pointer on success, NULL on failure */ __rte_experimental -int -rte_vhost_get_vdpa_device_id(int vid); +struct rte_vdpa_device * +rte_vhost_get_vdpa_device(int vid); /** * Notify the guest that should get virtio configuration space from backend. diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 9325ee4227..60d67445d7 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -43,8 +43,8 @@ EXPERIMENTAL { rte_vdpa_reset_stats; rte_vhost_driver_attach_vdpa_device; rte_vhost_driver_detach_vdpa_device; - rte_vhost_driver_get_vdpa_device_id; - rte_vhost_get_vdpa_device_id; + rte_vhost_driver_get_vdpa_device; + rte_vhost_get_vdpa_device; rte_vhost_driver_get_protocol_features; rte_vhost_driver_get_queue_num; rte_vhost_get_log_base; diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index da575b608c..49267cebf9 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -55,12 +55,7 @@ struct vhost_user_socket { uint64_t protocol_features; - /* - * Device id to identify a specific backend device. - * It's set to -1 for the default software implementation. - * If valid, one socket can have 1 connection only. - */ - int vdpa_dev_id; + struct rte_vdpa_device *vdpa_dev; struct vhost_device_ops const *notify_ops; }; @@ -230,7 +225,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net); - vhost_attach_vdpa_device(vid, vsocket->vdpa_dev_id); + vhost_attach_vdpa_device(vid, vsocket->vdpa_dev); if (vsocket->dequeue_zero_copy) vhost_enable_dequeue_zero_copy(vid); @@ -578,17 +573,18 @@ find_vhost_user_socket(const char *path) } int -rte_vhost_driver_attach_vdpa_device(const char *path, int did) +rte_vhost_driver_attach_vdpa_device(const char *path, + struct rte_vdpa_device *dev) { struct vhost_user_socket *vsocket; - if (rte_vdpa_get_device(did) == NULL || path == NULL) + if (dev == NULL || path == NULL) return -1; pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); if (vsocket) - vsocket->vdpa_dev_id = did; + vsocket->vdpa_dev = dev; pthread_mutex_unlock(&vhost_user.mutex); return vsocket ? 0 : -1; @@ -602,25 +598,25 @@ rte_vhost_driver_detach_vdpa_device(const char *path) pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); if (vsocket) - vsocket->vdpa_dev_id = -1; + vsocket->vdpa_dev = NULL; pthread_mutex_unlock(&vhost_user.mutex); return vsocket ? 0 : -1; } -int -rte_vhost_driver_get_vdpa_device_id(const char *path) +struct rte_vdpa_device * +rte_vhost_driver_get_vdpa_device(const char *path) { struct vhost_user_socket *vsocket; - int did = -1; + struct rte_vdpa_device *dev = NULL; pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); if (vsocket) - did = vsocket->vdpa_dev_id; + dev = vsocket->vdpa_dev; pthread_mutex_unlock(&vhost_user.mutex); - return did; + return dev; } int @@ -693,7 +689,6 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features) struct vhost_user_socket *vsocket; uint64_t vdpa_features; struct rte_vdpa_device *vdpa_dev; - int did = -1; int ret = 0; pthread_mutex_lock(&vhost_user.mutex); @@ -705,8 +700,7 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features) goto unlock_exit; } - did = vsocket->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = vsocket->vdpa_dev; if (!vdpa_dev || !vdpa_dev->ops->get_features) { *features = vsocket->features; goto unlock_exit; @@ -748,7 +742,6 @@ rte_vhost_driver_get_protocol_features(const char *path, struct vhost_user_socket *vsocket; uint64_t vdpa_protocol_features; struct rte_vdpa_device *vdpa_dev; - int did = -1; int ret = 0; pthread_mutex_lock(&vhost_user.mutex); @@ -760,8 +753,7 @@ rte_vhost_driver_get_protocol_features(const char *path, goto unlock_exit; } - did = vsocket->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = vsocket->vdpa_dev; if (!vdpa_dev || !vdpa_dev->ops->get_protocol_features) { *protocol_features = vsocket->protocol_features; goto unlock_exit; @@ -790,7 +782,6 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num) struct vhost_user_socket *vsocket; uint32_t vdpa_queue_num; struct rte_vdpa_device *vdpa_dev; - int did = -1; int ret = 0; pthread_mutex_lock(&vhost_user.mutex); @@ -802,8 +793,7 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num) goto unlock_exit; } - did = vsocket->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = vsocket->vdpa_dev; if (!vdpa_dev || !vdpa_dev->ops->get_queue_num) { *queue_num = VHOST_MAX_QUEUE_PAIRS; goto unlock_exit; @@ -878,7 +868,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) "error: failed to init connection mutex\n"); goto out_free; } - vsocket->vdpa_dev_id = -1; + vsocket->vdpa_dev = NULL; vsocket->dequeue_zero_copy = flags & RTE_VHOST_USER_DEQUEUE_ZERO_COPY; vsocket->extbuf = flags & RTE_VHOST_USER_EXTBUF_SUPPORT; vsocket->linearbuf = flags & RTE_VHOST_USER_LINEARBUF_SUPPORT; diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 0266318440..0d822d6a3f 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -633,7 +633,6 @@ vhost_new_device(void) dev->vid = i; dev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET; dev->slave_req_fd = -1; - dev->vdpa_dev_id = -1; dev->postcopy_ufd = -1; rte_spinlock_init(&dev->slave_req_lock); @@ -644,11 +643,9 @@ void vhost_destroy_device_notify(struct virtio_net *dev) { struct rte_vdpa_device *vdpa_dev; - int did; if (dev->flags & VIRTIO_DEV_RUNNING) { - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && vdpa_dev->ops->dev_close) vdpa_dev->ops->dev_close(dev->vid); dev->flags &= ~VIRTIO_DEV_RUNNING; @@ -677,17 +674,14 @@ vhost_destroy_device(int vid) } void -vhost_attach_vdpa_device(int vid, int did) +vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *vdpa_dev) { struct virtio_net *dev = get_device(vid); if (dev == NULL) return; - if (rte_vdpa_get_device(did) == NULL) - return; - - dev->vdpa_dev_id = did; + dev->vdpa_dev = vdpa_dev; } void @@ -1402,14 +1396,15 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) return ret; } -int rte_vhost_get_vdpa_device_id(int vid) +struct rte_vdpa_device * +rte_vhost_get_vdpa_device(int vid) { struct virtio_net *dev = get_device(vid); if (dev == NULL) - return -1; + return NULL; - return dev->vdpa_dev_id; + return dev->vdpa_dev; } int rte_vhost_get_log_base(int vid, uint64_t *log_base, diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index df98d15de6..819857a65a 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -377,11 +377,7 @@ struct virtio_net { int postcopy_ufd; int postcopy_listening; - /* - * Device id to identify a specific backend device. - * It's set to -1 for the default software implementation. - */ - int vdpa_dev_id; + struct rte_vdpa_device *vdpa_dev; /* context data for the external message handlers */ void *extern_data; @@ -639,7 +635,7 @@ void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq); int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx); -void vhost_attach_vdpa_device(int vid, int did); +void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev); void vhost_set_ifname(int, const char *if_name, unsigned int if_len); void vhost_enable_dequeue_zero_copy(int vid); diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index ea9cd107b9..3405cd8c0b 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -315,7 +315,6 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, uint64_t features = msg->payload.u64; uint64_t vhost_features = 0; struct rte_vdpa_device *vdpa_dev; - int did = -1; if (validate_msg_fds(msg, 0) != 0) return RTE_VHOST_MSG_RESULT_ERR; @@ -384,8 +383,7 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, } } - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && vdpa_dev->ops->set_features) vdpa_dev->ops->set_features(dev->vid); @@ -1971,7 +1969,6 @@ vhost_user_set_vring_enable(struct virtio_net **pdev, int enable = (int)msg->payload.state.num; int index = (int)msg->payload.state.index; struct rte_vdpa_device *vdpa_dev; - int did = -1; if (validate_msg_fds(msg, 0) != 0) return RTE_VHOST_MSG_RESULT_ERR; @@ -1980,8 +1977,7 @@ vhost_user_set_vring_enable(struct virtio_net **pdev, "set queue enable: %d to qp idx: %d\n", enable, index); - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && vdpa_dev->ops->set_vring_state) vdpa_dev->ops->set_vring_state(dev->vid, index, enable); @@ -2147,7 +2143,6 @@ vhost_user_send_rarp(struct virtio_net **pdev, struct VhostUserMsg *msg, struct virtio_net *dev = *pdev; uint8_t *mac = (uint8_t *)&msg->payload.u64; struct rte_vdpa_device *vdpa_dev; - int did = -1; if (validate_msg_fds(msg, 0) != 0) return RTE_VHOST_MSG_RESULT_ERR; @@ -2165,8 +2160,7 @@ vhost_user_send_rarp(struct virtio_net **pdev, struct VhostUserMsg *msg, * copied before the flag is set. */ __atomic_store_n(&dev->broadcast_rarp, 1, __ATOMIC_RELEASE); - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && vdpa_dev->ops->migration_done) vdpa_dev->ops->migration_done(dev->vid); @@ -2613,7 +2607,6 @@ vhost_user_msg_handler(int vid, int fd) struct virtio_net *dev; struct VhostUserMsg msg; struct rte_vdpa_device *vdpa_dev; - int did = -1; int ret; int unlock_required = 0; bool handled; @@ -2805,8 +2798,7 @@ vhost_user_msg_handler(int vid, int fd) } } - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); + vdpa_dev = dev->vdpa_dev; if (vdpa_dev && virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) && msg.request.master == VHOST_USER_SET_VRING_CALL) { @@ -2955,7 +2947,7 @@ int rte_vhost_host_notifier_ctrl(int vid, bool enable) { struct virtio_net *dev; struct rte_vdpa_device *vdpa_dev; - int vfio_device_fd, did, ret = 0; + int vfio_device_fd, ret = 0; uint64_t offset, size; unsigned int i; @@ -2963,9 +2955,9 @@ int rte_vhost_host_notifier_ctrl(int vid, bool enable) if (!dev) return -ENODEV; - did = dev->vdpa_dev_id; - if (did < 0) - return -EINVAL; + vdpa_dev = dev->vdpa_dev; + if (vdpa_dev == NULL) + return -ENODEV; if (!(dev->features & (1ULL << VIRTIO_F_VERSION_1)) || !(dev->features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) || @@ -2977,10 +2969,6 @@ int rte_vhost_host_notifier_ctrl(int vid, bool enable) (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER))) return -ENOTSUP; - vdpa_dev = rte_vdpa_get_device(did); - if (!vdpa_dev) - return -ENODEV; - RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_vfio_device_fd, -ENOTSUP); RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_notify_area, -ENOTSUP); From patchwork Fri Jun 26 14:04:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72253 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 40395A051C; Fri, 26 Jun 2020 16:06:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3BB4E1C0B1; Fri, 26 Jun 2020 16:05:42 +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 5B3141C037 for ; Fri, 26 Jun 2020 16:05:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EoLSLw8Uy2YifsLR+6MZOT/F84WTwiMFvINty31VZPk=; b=P+SrrNtGG4FLfMHYic2atkP/Hekpp20ANQe/vtFKIpBWotQ3pHgzYZWlXYC4ulx6ZZzLXo C+IzhefXhAQPt4NFi+n6CC0aGkRU6EtUI3oEMmY0F7eHLRDJPi/XB69Zqlphx+z0pQCuyJ g6gkgQeSpAbSbUhvRii7ZV5F6MlWgxY= 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-72-ZgryD-d5OjiFkyQhcc4Fwg-1; Fri, 26 Jun 2020 10:05:38 -0400 X-MC-Unique: ZgryD-d5OjiFkyQhcc4Fwg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9B7F8064B4; Fri, 26 Jun 2020 14:05:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8D165BAE1; Fri, 26 Jun 2020 14:05:33 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:34 +0200 Message-Id: <20200626140441.1441763-8-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 07/14] vhost: replace device ID in applications X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch replaces the use of vDPA device ID with vDPA device pointer. The goals is to remove the vDPA device ID to avoid condusion with the Vhost ID. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- examples/vdpa/main.c | 118 +++++++++++++------------ lib/librte_vhost/rte_vdpa.h | 44 ++++++--- lib/librte_vhost/rte_vhost_version.map | 3 +- lib/librte_vhost/vdpa.c | 64 +++++++------- 4 files changed, 123 insertions(+), 106 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 6a719e32d8..54f4940b31 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -27,7 +27,7 @@ struct vdpa_port { char ifname[MAX_PATH_LEN]; - int did; + struct rte_vdpa_device *dev; int vid; uint64_t flags; int stats_n; @@ -105,16 +105,23 @@ static int new_device(int vid) { char ifname[MAX_PATH_LEN]; + struct rte_device *dev; int i; rte_vhost_get_ifname(vid, ifname, sizeof(ifname)); for (i = 0; i < MAX_VDPA_SAMPLE_PORTS; i++) { - if (strncmp(ifname, vports[i].ifname, MAX_PATH_LEN) == 0) { - printf("\nnew port %s, did: %d\n", - ifname, vports[i].did); - vports[i].vid = vid; - break; + if (strncmp(ifname, vports[i].ifname, MAX_PATH_LEN)) + continue; + + dev = rte_vdpa_get_rte_device(vports[i].dev); + if (!dev) { + RTE_LOG(ERR, VDPA, + "Failed to get generic device for port %d\n", i); + continue; } + printf("\nnew port %s, device : %s\n", ifname, dev->name); + vports[i].vid = vid; + break; } if (i >= MAX_VDPA_SAMPLE_PORTS) @@ -126,16 +133,24 @@ new_device(int vid) static void destroy_device(int vid) { + struct rte_device *dev; char ifname[MAX_PATH_LEN]; int i; rte_vhost_get_ifname(vid, ifname, sizeof(ifname)); for (i = 0; i < MAX_VDPA_SAMPLE_PORTS; i++) { - if (strcmp(ifname, vports[i].ifname) == 0) { - printf("\ndestroy port %s, did: %d\n", - ifname, vports[i].did); - break; + if (strncmp(ifname, vports[i].ifname, MAX_PATH_LEN)) + continue; + + dev = rte_vdpa_get_rte_device(vports[i].dev); + if (!dev) { + RTE_LOG(ERR, VDPA, + "Failed to get generic device for port %d\n", i); + continue; } + + printf("\ndestroy port %s, device: %s\n", ifname, dev->name); + break; } } @@ -149,8 +164,6 @@ start_vdpa(struct vdpa_port *vport) { int ret; char *socket_path = vport->ifname; - struct rte_vdpa_device *vdev; - int did = vport->did; if (client_mode) vport->flags |= RTE_VHOST_USER_CLIENT; @@ -174,13 +187,7 @@ start_vdpa(struct vdpa_port *vport) "register driver ops failed: %s\n", socket_path); - vdev = rte_vdpa_get_device(did); - if (!vdev) - rte_exit(EXIT_FAILURE, - "vDPA device retrieval failed: %p\n", - vdev); - - ret = rte_vhost_driver_attach_vdpa_device(socket_path, vdev); + ret = rte_vhost_driver_attach_vdpa_device(socket_path, vport->dev); if (ret != 0) rte_exit(EXIT_FAILURE, "attach vdpa device failed: %s\n", @@ -283,35 +290,31 @@ static void cmd_list_vdpa_devices_parsed( struct cmdline *cl, __rte_unused void *data) { - int did; uint32_t queue_num; uint64_t features; struct rte_vdpa_device *vdev; struct rte_device *dev; struct rte_dev_iterator dev_iter; - cmdline_printf(cl, "device id\tdevice name\tqueue num\tsupported features\n"); + cmdline_printf(cl, "device name\tqueue num\tsupported features\n"); RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { - did = rte_vdpa_find_device_id_by_name(dev->name); - if (did < 0) - continue; - vdev = rte_vdpa_get_device(did); + vdev = rte_vdpa_find_device_by_name(dev->name); if (!vdev) continue; if (vdev->ops->get_queue_num(vdev, &queue_num) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa queue number " - "for device id %d.\n", did); + "for device %s.\n", dev->name); continue; } if (vdev->ops->get_features(vdev, &features) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa features " - "for device id %d.\n", did); + "for device %s.\n", dev->name); continue; } - cmdline_printf(cl, "%d\t\t%s\t\t%" PRIu32 "\t\t0x%" PRIx64 "\n", - did, dev->name, queue_num, features); + cmdline_printf(cl, "%s\t\t%" PRIu32 "\t\t0x%" PRIx64 "\n", + dev->name, queue_num, features); } } @@ -339,18 +342,18 @@ static void cmd_create_vdpa_port_parsed(void *parsed_result, struct cmdline *cl, __rte_unused void *data) { - int did; + struct rte_vdpa_device *dev; struct cmd_create_result *res = parsed_result; rte_strscpy(vports[devcnt].ifname, res->socket_path, MAX_PATH_LEN); - did = rte_vdpa_find_device_id_by_name(res->bdf); - if (did < 0) { + dev = rte_vdpa_find_device_by_name(res->bdf); + if (dev == NULL) { cmdline_printf(cl, "Unable to find vdpa device id for %s.\n", res->bdf); return; } - vports[devcnt].did = did; + vports[devcnt].dev = dev; if (start_vdpa(&vports[devcnt]) == 0) devcnt++; @@ -378,7 +381,7 @@ cmdline_parse_inst_t cmd_create_vdpa_port = { /* *** STATS *** */ struct cmd_stats_result { cmdline_fixed_string_t stats; - uint16_t did; + cmdline_fixed_string_t bdf; uint16_t qid; }; @@ -386,25 +389,24 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, __rte_unused void *data) { struct cmd_stats_result *res = parsed_result; - struct rte_vdpa_device *vdev = rte_vdpa_get_device(res->did); + struct rte_vdpa_device *vdev = rte_vdpa_find_device_by_name(res->bdf); struct vdpa_port *vport = NULL; uint32_t first, last; int i; if (!vdev) { - RTE_LOG(ERR, VDPA, "Invalid device id %" PRIu16 ".\n", - res->did); + RTE_LOG(ERR, VDPA, "Invalid device: %s.\n", + res->bdf); return; } for (i = 0; i < RTE_MIN(MAX_VDPA_SAMPLE_PORTS, dev_total); i++) { - if (vports[i].did == res->did) { + if (vports[i].dev == vdev) { vport = &vports[i]; break; } } if (!vport) { - RTE_LOG(ERR, VDPA, "Device id %" PRIu16 " was not created.\n", - res->did); + RTE_LOG(ERR, VDPA, "Device %s was not created.\n", res->bdf); return; } if (res->qid == 0xFFFF) { @@ -412,7 +414,7 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, last = rte_vhost_get_vring_num(vport->vid); if (last == 0) { RTE_LOG(ERR, VDPA, "Failed to get num of actual virtqs" - " for device id %d.\n", (int)res->did); + " for device %s.\n", res->bdf); return; } last--; @@ -421,10 +423,10 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, last = res->qid; } if (!vport->stats_names) { - vport->stats_n = rte_vdpa_get_stats_names(vport->did, NULL, 0); + vport->stats_n = rte_vdpa_get_stats_names(vport->dev, NULL, 0); if (vport->stats_n <= 0) { RTE_LOG(ERR, VDPA, "Failed to get names number of " - "device %d stats.\n", (int)res->did); + "device %s stats.\n", res->bdf); return; } vport->stats_names = rte_zmalloc(NULL, @@ -432,26 +434,26 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, vport->stats_n, 0); if (!vport->stats_names) { RTE_LOG(ERR, VDPA, "Failed to allocate memory for stat" - " names of device %d.\n", (int)res->did); + " names of device %s.\n", res->bdf); return; } - i = rte_vdpa_get_stats_names(vport->did, vport->stats_names, + i = rte_vdpa_get_stats_names(vport->dev, vport->stats_names, vport->stats_n); if (vport->stats_n != i) { - RTE_LOG(ERR, VDPA, "Failed to get names of device %d " - "stats.\n", (int)res->did); + RTE_LOG(ERR, VDPA, "Failed to get names of device %s " + "stats.\n", res->bdf); return; } vport->stats = (struct rte_vdpa_stat *) (vport->stats_names + vport->stats_n); } - cmdline_printf(cl, "\nDevice %d:\n", (int)res->did); + cmdline_printf(cl, "\nDevice %s:\n", res->bdf); for (; first <= last; first++) { memset(vport->stats, 0, sizeof(*vport->stats) * vport->stats_n); - if (rte_vdpa_get_stats(vport->did, (int)first, vport->stats, + if (rte_vdpa_get_stats(vport->dev, (int)first, vport->stats, vport->stats_n) <= 0) { RTE_LOG(ERR, VDPA, "Failed to get vdpa queue statistics" - " for device id %d qid %d.\n", (int)res->did, + " for device %s qid %d.\n", res->bdf, (int)first); return; } @@ -467,8 +469,8 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, cmdline_parse_token_string_t cmd_device_stats_ = TOKEN_STRING_INITIALIZER(struct cmd_stats_result, stats, "stats"); -cmdline_parse_token_num_t cmd_device_id = - TOKEN_NUM_INITIALIZER(struct cmd_stats_result, did, UINT32); +cmdline_parse_token_string_t cmd_device_bdf = + TOKEN_STRING_INITIALIZER(struct cmd_stats_result, bdf, NULL); cmdline_parse_token_num_t cmd_queue_id = TOKEN_NUM_INITIALIZER(struct cmd_stats_result, qid, UINT32); @@ -478,7 +480,7 @@ cmdline_parse_inst_t cmd_device_stats = { .help_str = "stats: show device statistics", .tokens = { (void *)&cmd_device_stats_, - (void *)&cmd_device_id, + (void *)&cmd_device_bdf, (void *)&cmd_queue_id, NULL, }, @@ -522,9 +524,9 @@ int main(int argc, char *argv[]) { char ch; - int did; int ret; struct cmdline *cl; + struct rte_vdpa_device *vdev; struct rte_device *dev; struct rte_dev_iterator dev_iter; @@ -553,12 +555,12 @@ main(int argc, char *argv[]) cmdline_stdin_exit(cl); } else { RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { - did = rte_vdpa_find_device_id_by_name(dev->name); - if (did < 0) { - rte_panic("Failed to find device id for %s\n", + vdev = rte_vdpa_find_device_by_name(dev->name); + if (vdev == NULL) { + rte_panic("Failed to find vDPA dev for %s\n", dev->name); } - vports[devcnt].did = did; + vports[devcnt].dev = vdev; snprintf(vports[devcnt].ifname, MAX_PATH_LEN, "%s%d", iface, devcnt); diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index 109cf83b8f..549b0a2cb0 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -153,11 +153,26 @@ rte_vdpa_unregister_device(struct rte_vdpa_device *); * @param name * the vdpa device name * @return - * device id on success, -1 on failure + * vDPA device pointer on success, NULL on failure */ __rte_experimental -int -rte_vdpa_find_device_id_by_name(const char *name); +struct rte_vdpa_device * +rte_vdpa_find_device_by_name(const char *name); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Get the generic device from the vdpa device + * + * @param vdpa_dev + * the vdpa device pointer + * @return + * generic device pointer on success, NULL on failure + */ +__rte_experimental +struct rte_device * +rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev); /** * @warning @@ -252,8 +267,8 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); * And the array index is same with id field of 'struct rte_vdpa_stat': * stats[i].id == i * - * @param did - * device id + * @param dev + * vDPA device pointer * @param stats_names * array of at least size elements to be filled. * If set to NULL, the function returns the required number of elements. @@ -265,8 +280,9 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); */ __rte_experimental int -rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, - unsigned int size); +rte_vdpa_get_stats_names(struct rte_vdpa_device *dev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size); /** * @warning @@ -280,8 +296,8 @@ rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, * And the array index is same with id field of 'struct rte_vdpa_stat': * stats[i].id == i * - * @param did - * device id + * @param dev + * vDPA device pointer * @param qid * queue id * @param stats @@ -295,16 +311,16 @@ rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, */ __rte_experimental int -rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats, - unsigned int n); +rte_vdpa_get_stats(struct rte_vdpa_device *dev, uint16_t qid, + struct rte_vdpa_stat *stats, unsigned int n); /** * @warning * @b EXPERIMENTAL: this API may change without prior notice * * Reset statistics of a vDPA device. * - * @param did - * device id + * @param dev + * vDPA device pointer * @param qid * queue id * @return @@ -312,5 +328,5 @@ rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats, */ __rte_experimental int -rte_vdpa_reset_stats(int did, uint16_t qid); +rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid); #endif /* _RTE_VDPA_H_ */ diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 60d67445d7..ba55f6f421 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -69,5 +69,6 @@ EXPERIMENTAL { rte_vhost_get_vhost_ring_inflight; rte_vhost_get_vring_base_from_inflight; rte_vhost_slave_config_change; - rte_vdpa_find_device_id_by_name; + rte_vdpa_find_device_by_name; + rte_vdpa_get_rte_device; }; diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 49ada00277..cececc3098 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -40,14 +40,14 @@ rte_vdpa_find_device_id(struct rte_vdpa_device *dev) return -1; } -int -rte_vdpa_find_device_id_by_name(const char *name) +struct rte_vdpa_device * +rte_vdpa_find_device_by_name(const char *name) { struct rte_vdpa_device *dev; int i; if (name == NULL) - return -1; + return NULL; for (i = 0; i < MAX_VHOST_DEVICE; ++i) { dev = &vdpa_devices[i]; @@ -55,10 +55,19 @@ rte_vdpa_find_device_id_by_name(const char *name) continue; if (strncmp(dev->device->name, name, RTE_DEV_NAME_MAX_LEN) == 0) - return i; + return dev; } - return -1; + return NULL; +} + +struct rte_device * +rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev) +{ + if (vdpa_dev == NULL) + return NULL; + + return vdpa_dev->device; } struct rte_vdpa_device * @@ -228,50 +237,39 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m) } int -rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names, - unsigned int size) +rte_vdpa_get_stats_names(struct rte_vdpa_device *dev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size) { - struct rte_vdpa_device *vdpa_dev; - - vdpa_dev = rte_vdpa_get_device(did); - if (!vdpa_dev) - return -ENODEV; + if (!dev) + return -EINVAL; - RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats_names, -ENOTSUP); + RTE_FUNC_PTR_OR_ERR_RET(dev->ops->get_stats_names, -ENOTSUP); - return vdpa_dev->ops->get_stats_names(vdpa_dev, stats_names, size); + return dev->ops->get_stats_names(dev, stats_names, size); } int -rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats, - unsigned int n) +rte_vdpa_get_stats(struct rte_vdpa_device *dev, uint16_t qid, + struct rte_vdpa_stat *stats, unsigned int n) { - struct rte_vdpa_device *vdpa_dev; - - vdpa_dev = rte_vdpa_get_device(did); - if (!vdpa_dev) - return -ENODEV; - - if (!stats || !n) + if (!dev || !stats || !n) return -EINVAL; - RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_stats, -ENOTSUP); + RTE_FUNC_PTR_OR_ERR_RET(dev->ops->get_stats, -ENOTSUP); - return vdpa_dev->ops->get_stats(vdpa_dev, qid, stats, n); + return dev->ops->get_stats(dev, qid, stats, n); } int -rte_vdpa_reset_stats(int did, uint16_t qid) +rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid) { - struct rte_vdpa_device *vdpa_dev; - - vdpa_dev = rte_vdpa_get_device(did); - if (!vdpa_dev) - return -ENODEV; + if (!dev) + return -EINVAL; - RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->reset_stats, -ENOTSUP); + RTE_FUNC_PTR_OR_ERR_RET(dev->ops->reset_stats, -ENOTSUP); - return vdpa_dev->ops->reset_stats(vdpa_dev, qid); + return dev->ops->reset_stats(dev, qid); } static uint16_t From patchwork Fri Jun 26 14:04:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72254 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 A908BA051C; Fri, 26 Jun 2020 16:06:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 28D7A1C042; Fri, 26 Jun 2020 16:05:52 +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 812591BFC8 for ; Fri, 26 Jun 2020 16:05:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q1XSETQVDQnGniiRePqT4QGY/XDWt4QmYXIv+adPXPM=; b=eEsI5UV2CdH+4zBlG028B280tU7ojJN4SETJ9ryHxYMMansq8qDDi+N7VT+k1GYEGq+PjM ce5/OSDbFx+yfy3/db/7rIYJy5Ykm0ahp3cSoYWmhAKXX5vLOhO7nEqDgSBwfBC8vDxyRa UeJ2dpuxi2GYJ+WKMKjILHS3mZPtoy0= 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-14-eIgOwVdINgmZsfya9ZTjXg-1; Fri, 26 Jun 2020 10:05:48 -0400 X-MC-Unique: eIgOwVdINgmZsfya9ZTjXg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89F90107ACCA; Fri, 26 Jun 2020 14:05:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05F3B8476F; Fri, 26 Jun 2020 14:05:36 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:35 +0200 Message-Id: <20200626140441.1441763-9-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 08/14] vhost: remove useless vDPA API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" vDPA is no more used outside of the vDPA internals, so remove rte_vdpa_get_device() API that is now useless. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- lib/librte_vhost/rte_vdpa.h | 30 ----------------- lib/librte_vhost/rte_vhost_version.map | 1 - lib/librte_vhost/vdpa.c | 46 ++++++-------------------- 3 files changed, 10 insertions(+), 67 deletions(-) diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index 549b0a2cb0..da8ee33ab1 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -174,36 +174,6 @@ __rte_experimental struct rte_device * rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev); -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Find the device id of a vdpa device - * - * @param addr - * the vdpa device address - * @return - * device id on success, -1 on failure - */ -__rte_experimental -int -rte_vdpa_find_device_id(struct rte_vdpa_device *dev); - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Find a vdpa device based on device id - * - * @param did - * device id - * @return - * rte_vdpa_device on success, NULL on failure - */ -__rte_experimental -struct rte_vdpa_device * -rte_vdpa_get_device(int did); - /** * @warning * @b EXPERIMENTAL: this API may change without prior notice diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index ba55f6f421..d9124d0462 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -36,7 +36,6 @@ EXPERIMENTAL { rte_vdpa_register_device; rte_vdpa_unregister_device; rte_vdpa_find_device_id; - rte_vdpa_get_device; rte_vdpa_get_device_num; rte_vdpa_get_stats_names; rte_vdpa_get_stats; diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index cececc3098..bed20a3103 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -19,27 +19,6 @@ static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; static uint32_t vdpa_device_num; -int -rte_vdpa_find_device_id(struct rte_vdpa_device *dev) -{ - struct rte_vdpa_device *tmp_dev; - int i; - - if (dev == NULL) - return -1; - - for (i = 0; i < MAX_VHOST_DEVICE; ++i) { - tmp_dev = &vdpa_devices[i]; - if (tmp_dev->ops == NULL) - continue; - - if (tmp_dev == dev) - return i; - } - - return -1; -} - struct rte_vdpa_device * rte_vdpa_find_device_by_name(const char *name) { @@ -70,15 +49,6 @@ rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev) return vdpa_dev->device; } -struct rte_vdpa_device * -rte_vdpa_get_device(int did) -{ - if (did < 0 || did >= MAX_VHOST_DEVICE) - return NULL; - - return &vdpa_devices[did]; -} - struct rte_vdpa_device * rte_vdpa_register_device(struct rte_device *rte_dev, struct rte_vdpa_dev_ops *ops) @@ -117,15 +87,19 @@ rte_vdpa_register_device(struct rte_device *rte_dev, int rte_vdpa_unregister_device(struct rte_vdpa_device *vdev) { - int did = rte_vdpa_find_device_id(vdev); + int i; - if (did < 0 || vdpa_devices[did].ops == NULL) - return -1; + for (i = 0; i < MAX_VHOST_DEVICE; i++) { + if (vdev != &vdpa_devices[i]) + continue; - memset(&vdpa_devices[did], 0, sizeof(struct rte_vdpa_device)); - vdpa_device_num--; + memset(vdev, 0, sizeof(struct rte_vdpa_device)); + vdpa_device_num--; - return 0; + return 0; + } + + return -1; } int From patchwork Fri Jun 26 14:04:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72255 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 CE28BA051C; Fri, 26 Jun 2020 16:07:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 476281C0C6; Fri, 26 Jun 2020 16:06:03 +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 2C29D1BFC8 for ; Fri, 26 Jun 2020 16:06:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180360; 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=gcTclqgfzyl1twdC/7nu7+BqHHV77Ij8XRkKTfyuyfA=; b=Of6Nv3G77lwBM69fqvW06b2o7piQKvX3f3wqtUEWbihVBnI/l0bNdH3z2AyRChShAa5XU3 Wn2AmFx98YBUMRlVv0CLBGra5I+X2q6Ir5UVf6I7RAwbpZHLeILigXI6rZWpPPsPuxIw+E G1EbOnW/cDRd3Lqzw+dYRHWWDvR4IOM= 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-486-dMquNgsvMV29ce5j6-Hc0A-1; Fri, 26 Jun 2020 10:05:59 -0400 X-MC-Unique: dMquNgsvMV29ce5j6-Hc0A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A53F71883625; Fri, 26 Jun 2020 14:05:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF5E35BAE1; Fri, 26 Jun 2020 14:05:46 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:36 +0200 Message-Id: <20200626140441.1441763-10-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 09/14] vhost: use linked-list for vDPA devices X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" There is no more notion of device ID outside of vdpa.c. We can now move from array to linked-list model for keeping track of the vDPA devices. There is no point in using array here, as all vDPA API are used from the control path, so no performance concerns. Signed-off-by: Maxime Coquelin Acked-by: Adrián Moreno --- lib/librte_vhost/rte_vdpa.h | 1 + lib/librte_vhost/vdpa.c | 134 +++++++++++++++++++----------------- 2 files changed, 70 insertions(+), 65 deletions(-) diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index da8ee33ab1..dbdc273702 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -105,6 +105,7 @@ struct rte_vdpa_dev_ops { * vdpa device structure includes device address and device operations. */ struct rte_vdpa_device { + TAILQ_ENTRY(rte_vdpa_device) next; /** Generic device information */ struct rte_device *device; /** vdpa device operations */ diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index bed20a3103..72561552c3 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -9,35 +9,54 @@ */ #include +#include #include #include +#include +#include + #include "rte_vdpa.h" #include "vhost.h" -static struct rte_vdpa_device vdpa_devices[MAX_VHOST_DEVICE]; +/** Double linked list of vDPA devices. */ +TAILQ_HEAD(vdpa_device_list, rte_vdpa_device); + +static struct vdpa_device_list vdpa_device_list = + TAILQ_HEAD_INITIALIZER(vdpa_device_list); +static rte_spinlock_t vdpa_device_list_lock = RTE_SPINLOCK_INITIALIZER; static uint32_t vdpa_device_num; -struct rte_vdpa_device * -rte_vdpa_find_device_by_name(const char *name) +/* Unsafe, needs to be called with vdpa_device_list_lock held */ +static struct rte_vdpa_device * +__vdpa_find_device_by_name(const char *name) { - struct rte_vdpa_device *dev; - int i; + struct rte_vdpa_device *dev, *ret = NULL; if (name == NULL) return NULL; - for (i = 0; i < MAX_VHOST_DEVICE; ++i) { - dev = &vdpa_devices[i]; - if (dev->ops == NULL) - continue; - - if (strncmp(dev->device->name, name, RTE_DEV_NAME_MAX_LEN) == 0) - return dev; + TAILQ_FOREACH(dev, &vdpa_device_list, next) { + if (!strncmp(dev->device->name, name, RTE_DEV_NAME_MAX_LEN)) { + ret = dev; + break; + } } - return NULL; + return ret; +} + +struct rte_vdpa_device * +rte_vdpa_find_device_by_name(const char *name) +{ + struct rte_vdpa_device *dev; + + rte_spinlock_lock(&vdpa_device_list_lock); + dev = __vdpa_find_device_by_name(name); + rte_spinlock_unlock(&vdpa_device_list_lock); + + return dev; } struct rte_device * @@ -54,52 +73,52 @@ rte_vdpa_register_device(struct rte_device *rte_dev, struct rte_vdpa_dev_ops *ops) { struct rte_vdpa_device *dev; - int i; - if (vdpa_device_num >= MAX_VHOST_DEVICE || ops == NULL) + if (ops == NULL) return NULL; - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - dev = &vdpa_devices[i]; - if (dev->ops == NULL) - continue; - - if (dev->device == rte_dev) - return NULL; - } - - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - if (vdpa_devices[i].ops == NULL) - break; + rte_spinlock_lock(&vdpa_device_list_lock); + /* Check the device hasn't been register already */ + dev = __vdpa_find_device_by_name(rte_dev->name); + if (dev) { + dev = NULL; + goto out_unlock; } - if (i == MAX_VHOST_DEVICE) - return NULL; + dev = rte_zmalloc(NULL, sizeof(*dev), 0); + if (!dev) + goto out_unlock; - dev = &vdpa_devices[i]; dev->device = rte_dev; dev->ops = ops; + TAILQ_INSERT_TAIL(&vdpa_device_list, dev, next); vdpa_device_num++; +out_unlock: + rte_spinlock_unlock(&vdpa_device_list_lock); return dev; } int -rte_vdpa_unregister_device(struct rte_vdpa_device *vdev) +rte_vdpa_unregister_device(struct rte_vdpa_device *dev) { - int i; + struct rte_vdpa_device *cur_dev, *tmp_dev; + int ret = -1; - for (i = 0; i < MAX_VHOST_DEVICE; i++) { - if (vdev != &vdpa_devices[i]) + rte_spinlock_lock(&vdpa_device_list_lock); + TAILQ_FOREACH_SAFE(cur_dev, &vdpa_device_list, next, tmp_dev) { + if (dev != cur_dev) continue; - memset(vdev, 0, sizeof(struct rte_vdpa_device)); + TAILQ_REMOVE(&vdpa_device_list, dev, next); + rte_free(dev); vdpa_device_num--; - - return 0; + ret = 0; + break; } + rte_spinlock_unlock(&vdpa_device_list_lock); - return -1; + return ret; } int @@ -246,19 +265,6 @@ rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid) return dev->ops->reset_stats(dev, qid); } -static uint16_t -vdpa_dev_to_id(const struct rte_vdpa_device *dev) -{ - if (dev == NULL) - return MAX_VHOST_DEVICE; - - if (dev < &vdpa_devices[0] || - dev >= &vdpa_devices[MAX_VHOST_DEVICE]) - return MAX_VHOST_DEVICE; - - return (uint16_t)(dev - vdpa_devices); -} - static int vdpa_dev_match(struct rte_vdpa_device *dev, const struct rte_device *rte_dev) @@ -278,24 +284,22 @@ vdpa_find_device(const struct rte_vdpa_device *start, rte_vdpa_cmp_t cmp, struct rte_device *rte_dev) { struct rte_vdpa_device *dev; - uint16_t idx; - if (start != NULL) - idx = vdpa_dev_to_id(start) + 1; + rte_spinlock_lock(&vdpa_device_list_lock); + if (start == NULL) + dev = TAILQ_FIRST(&vdpa_device_list); else - idx = 0; - for (; idx < MAX_VHOST_DEVICE; idx++) { - dev = &vdpa_devices[idx]; - /* - * ToDo: Certainly better to introduce a state field, - * but rely on ops being set for now. - */ - if (dev->ops == NULL) - continue; + dev = TAILQ_NEXT(start, next); + + while (dev != NULL) { if (cmp(dev, rte_dev) == 0) - return dev; + break; + + dev = TAILQ_NEXT(dev, next); } - return NULL; + rte_spinlock_unlock(&vdpa_device_list_lock); + + return dev; } static void * From patchwork Fri Jun 26 14:04:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72256 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 1AABDA051C; Fri, 26 Jun 2020 16:07:22 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 231AB1C012; Fri, 26 Jun 2020 16:06:15 +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 9BD061BFC8 for ; Fri, 26 Jun 2020 16:06:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180373; 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=rttQfusn8y+xGsbGYmyauBK8b2vPiV2DUSYOD66iOvc=; b=TV0kUChLzlAXG+ghEjpqRKR2xyNISj7BM3TdA+zvfQb0Kmr2Z9ksUZHJwX8UsUKsZT56LO KHUdCk0QGiVNmjkVa+Qd9PErnO4q65VkP36sByPR5WJ0tp5agn7OmymO2ixvFIjlzpR7i3 QZWs83R+sZdJZC1zCDfbXx7h1T0uqaM= 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-UcTTBxETN--GLwhw95R_iw-1; Fri, 26 Jun 2020 10:06:10 -0400 X-MC-Unique: UcTTBxETN--GLwhw95R_iw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F5A6804003; Fri, 26 Jun 2020 14:06:08 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id F23D45BAE1; Fri, 26 Jun 2020 14:05:57 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:37 +0200 Message-Id: <20200626140441.1441763-11-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 10/14] vhost: introduce wrappers for some vDPA ops X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch is preliminary work to make the vDPA device structure opaque to the user application. Some callbacks of the vDPA devices are used to query capabilities before attaching to a Vhost port. This patch introduces wrappers for these ops. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- lib/librte_vhost/rte_vdpa.h | 72 ++++++++++++++++++++++++++ lib/librte_vhost/rte_vhost_version.map | 3 ++ lib/librte_vhost/vdpa.c | 28 ++++++++++ 3 files changed, 103 insertions(+) diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index dbdc273702..eda56dd556 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -226,6 +226,78 @@ __rte_experimental int rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Get number of queue pairs supported by the vDPA device + * + * @param dev + * vDP device pointer + * @param queue_num + * pointer on where the number of queue is stored + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_get_queue_num(struct rte_vdpa_device *dev, uint32_t *queue_num); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Get the Virtio features supported by the vDPA device + * + * @param dev + * vDP device pointer + * @param features + * pointer on where the supported features are stored + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_get_features(struct rte_vdpa_device *dev, uint64_t *features); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Get the Vhost-user protocol features supported by the vDPA device + * + * @param dev + * vDP device pointer + * @param features + * pointer on where the supported protocol features are stored + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_get_protocol_features(struct rte_vdpa_device *dev, uint64_t *features); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Synchronize the used ring from mediated ring to guest, log dirty + * page for each writeable buffer, caller should handle the used + * ring logging before device stop. + * + * @param vid + * vhost device id + * @param qid + * vhost queue id + * @param vring_m + * mediated virtio ring pointer + * @return + * number of synced used entries on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index d9124d0462..7a919102cf 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -70,4 +70,7 @@ EXPERIMENTAL { rte_vhost_slave_config_change; rte_vdpa_find_device_by_name; rte_vdpa_get_rte_device; + rte_vdpa_get_queue_num; + rte_vdpa_get_features; + rte_vdpa_get_protocol_features; }; diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 72561552c3..8810bf3b36 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -229,6 +229,34 @@ rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m) return -1; } +int +rte_vdpa_get_queue_num(struct rte_vdpa_device *dev, uint32_t *queue_num) +{ + if (dev == NULL || dev->ops == NULL || dev->ops->get_queue_num == NULL) + return -1; + + return dev->ops->get_queue_num(dev, queue_num); +} + +int +rte_vdpa_get_features(struct rte_vdpa_device *dev, uint64_t *features) +{ + if (dev == NULL || dev->ops == NULL || dev->ops->get_features == NULL) + return -1; + + return dev->ops->get_features(dev, features); +} + +int +rte_vdpa_get_protocol_features(struct rte_vdpa_device *dev, uint64_t *features) +{ + if (dev == NULL || dev->ops == NULL || + dev->ops->get_protocol_features == NULL) + return -1; + + return dev->ops->get_protocol_features(dev, features); +} + int rte_vdpa_get_stats_names(struct rte_vdpa_device *dev, struct rte_vdpa_stat_name *stats_names, From patchwork Fri Jun 26 14:04:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72257 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 36ED1A051C; Fri, 26 Jun 2020 16:07:35 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F0A981C0D0; Fri, 26 Jun 2020 16:06:20 +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 C79001C0D0 for ; Fri, 26 Jun 2020 16:06:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JLZkL9jSYw3TtrKpuqdW7XmcVj7BEfJ7fqiCyUEtt5w=; b=CXgQIJWpfsgXCq35Ig+g0rT9xBQfqoN5jzV7VF7qbQBvmpwysTXeTQvY2sumHM4dZn/uCm 0p175CGKkepUqhBjaF/OMfcWp+6TSTqv82/VCa/YAgMoDY1yPvphZpWvoq9YKtz9PCT5Bu GXZiezvergTNtyaqSIl4/ro0tr4cByY= 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-328--okXECCoOxOVcUHDhTJGpA-1; Fri, 26 Jun 2020 10:06:17 -0400 X-MC-Unique: -okXECCoOxOVcUHDhTJGpA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7073B10059A2; Fri, 26 Jun 2020 14:06:15 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id F15845BAE1; Fri, 26 Jun 2020 14:06:08 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:38 +0200 Message-Id: <20200626140441.1441763-12-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 11/14] examples/vdpa: use new wrappers instead of ops X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Now that wrappers to query number of queues, Virtio features and Vhost-user protocol features are available, let's make the vDPA example to use them. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- examples/vdpa/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 54f4940b31..d59c7fa9b4 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -301,13 +301,13 @@ static void cmd_list_vdpa_devices_parsed( vdev = rte_vdpa_find_device_by_name(dev->name); if (!vdev) continue; - if (vdev->ops->get_queue_num(vdev, &queue_num) < 0) { + if (rte_vdpa_get_queue_num(vdev, &queue_num) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa queue number " "for device %s.\n", dev->name); continue; } - if (vdev->ops->get_features(vdev, &features) < 0) { + if (rte_vdpa_get_features(vdev, &features) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa features " "for device %s.\n", dev->name); From patchwork Fri Jun 26 14:04:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72258 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 EA09DA051C; Fri, 26 Jun 2020 16:07:47 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0CF9F1C0D8; Fri, 26 Jun 2020 16:06:23 +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 4F04F1C0D7 for ; Fri, 26 Jun 2020 16:06:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180381; 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=G+/FPsP0tIYYyfEXY+dtp7S9cavYMKqYIZXlrUXzKQA=; b=FFykQm1U/8AiTKPG7c4MbtXJ7ESWnuMOzTWmmegoVQSz0yD5Whv6m6Q+s3XVaI8vvyL/WQ C+AmwyNElB1zV6OE8AYK8qdd/Ig9s7Ckgrrb8RQUf2yhR+c9RjUTAgrwXzD14FHeY7PqcM m/2PBFaUi+xa7Pcc3cVVNctFLYbdTXU= 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-468-BbGqL1-9PVOJo0GDMtvQ0A-1; Fri, 26 Jun 2020 10:06:20 -0400 X-MC-Unique: BbGqL1-9PVOJo0GDMtvQ0A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77860800D5C; Fri, 26 Jun 2020 14:06:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBCA15BAE1; Fri, 26 Jun 2020 14:06:15 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:39 +0200 Message-Id: <20200626140441.1441763-13-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 12/14] examples/vdpa: remove useless device count X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The VDPA example now uses the vDPA class iterator, so knowing the number of available devices beforehand is no longer needed. Acked-by: Adrián Moreno 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 Fri Jun 26 14:04:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72259 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 89D96A051C; Fri, 26 Jun 2020 16:08:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0D90E1C01B; Fri, 26 Jun 2020 16:06:32 +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 CC0111BFC3 for ; Fri, 26 Jun 2020 16:06:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180390; 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=aWIlol7MEDPlqSYPOShjpFbfzuF6vOwJdASgPivRwKw=; b=HJmAoEylNU5IStEmbpwOh/xpLkbNRAQqnY9FVi3fN/ho4dBN7A/2bvl940verjfzZHffwW bqKl35D92fbsrTeVrQ5wqgolJF0rvbOsStojoQLoJ9HPOjizJ6GtUN4bokag5rYGm0uXys SW3nsgCWJj0cWUZwrCXrRrV78aCX6+g= 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-384-bF2f5fmRMTOPuDgdKpov2Q-1; Fri, 26 Jun 2020 10:06:23 -0400 X-MC-Unique: bF2f5fmRMTOPuDgdKpov2Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9783107ACF7; Fri, 26 Jun 2020 14:06:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE7F95BAE1; Fri, 26 Jun 2020 14:06:18 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:40 +0200 Message-Id: <20200626140441.1441763-14-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 13/14] vhost: remove vDPA device count API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This API is no more useful, this patch removes it. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- lib/librte_vhost/rte_vdpa.h | 13 ------------- lib/librte_vhost/rte_vhost_version.map | 1 - lib/librte_vhost/vdpa.c | 9 --------- 3 files changed, 23 deletions(-) diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index eda56dd556..776ed67c16 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -175,19 +175,6 @@ __rte_experimental struct rte_device * rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev); -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Get current available vdpa device number - * - * @return - * available vdpa device number - */ -__rte_experimental -int -rte_vdpa_get_device_num(void); - /** * @warning * @b EXPERIMENTAL: this API may change without prior notice diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 7a919102cf..299576a494 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -36,7 +36,6 @@ EXPERIMENTAL { rte_vdpa_register_device; rte_vdpa_unregister_device; rte_vdpa_find_device_id; - rte_vdpa_get_device_num; rte_vdpa_get_stats_names; rte_vdpa_get_stats; rte_vdpa_reset_stats; diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index 8810bf3b36..e41c73eb9a 100644 --- a/lib/librte_vhost/vdpa.c +++ b/lib/librte_vhost/vdpa.c @@ -25,7 +25,6 @@ TAILQ_HEAD(vdpa_device_list, rte_vdpa_device); static struct vdpa_device_list vdpa_device_list = TAILQ_HEAD_INITIALIZER(vdpa_device_list); static rte_spinlock_t vdpa_device_list_lock = RTE_SPINLOCK_INITIALIZER; -static uint32_t vdpa_device_num; /* Unsafe, needs to be called with vdpa_device_list_lock held */ @@ -92,7 +91,6 @@ rte_vdpa_register_device(struct rte_device *rte_dev, dev->device = rte_dev; dev->ops = ops; TAILQ_INSERT_TAIL(&vdpa_device_list, dev, next); - vdpa_device_num++; out_unlock: rte_spinlock_unlock(&vdpa_device_list_lock); @@ -112,7 +110,6 @@ rte_vdpa_unregister_device(struct rte_vdpa_device *dev) TAILQ_REMOVE(&vdpa_device_list, dev, next); rte_free(dev); - vdpa_device_num--; ret = 0; break; } @@ -121,12 +118,6 @@ rte_vdpa_unregister_device(struct rte_vdpa_device *dev) return ret; } -int -rte_vdpa_get_device_num(void) -{ - return vdpa_device_num; -} - int rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m) { From patchwork Fri Jun 26 14:04:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 72260 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 1BE94A051C; Fri, 26 Jun 2020 16:08:14 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CA9BE1C115; Fri, 26 Jun 2020 16:06:36 +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 A1F491C0C3 for ; Fri, 26 Jun 2020 16:06:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593180394; 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=cLZaaWCskfFnryB3DzVzlOPJdZPMqP+QUFtjB06YfYU=; b=OxwZ9OWscRt81sy8bTdM9dh377lkFJg13DiosH3lHbrtVuINW2hKLWQzWklEza25SMjNkP jYqHCXPwzJ6I1obvbdb8sVDsD5XvAKD90xfIsl02xYDpzK7no3mFixnLNgYJ6mOGZmByF9 fH6topvG88o1wRF3ncYhaeAPiNmVNJ4= 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-13-ZH_-uCXfO8er8zGabElf_w-1; Fri, 26 Jun 2020 10:06:29 -0400 X-MC-Unique: ZH_-uCXfO8er8zGabElf_w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A5B3804003; Fri, 26 Jun 2020 14:06:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 416695BAE1; Fri, 26 Jun 2020 14:06:22 +0000 (UTC) From: Maxime Coquelin To: matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, amorenoz@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org Cc: Maxime Coquelin Date: Fri, 26 Jun 2020 16:04:41 +0200 Message-Id: <20200626140441.1441763-15-maxime.coquelin@redhat.com> In-Reply-To: <20200626140441.1441763-1-maxime.coquelin@redhat.com> References: <20200626140441.1441763-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 14/14] vhost: split vDPA header file X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch split the vDPA header file in two, making rte_vdpa_device structure opaque to the application. Applications should only include rte_vdpa.h, while drivers should include both rte_vdpa.h and rte_vdpa_dev.h. Acked-by: Adrián Moreno Signed-off-by: Maxime Coquelin --- drivers/vdpa/ifc/ifcvf_vdpa.c | 1 + drivers/vdpa/mlx5/mlx5_vdpa.h | 1 + lib/librte_vhost/Makefile | 3 +- lib/librte_vhost/meson.build | 3 +- lib/librte_vhost/rte_vdpa.h | 142 ------------------------------ lib/librte_vhost/rte_vdpa_dev.h | 147 ++++++++++++++++++++++++++++++++ lib/librte_vhost/vdpa.c | 1 + lib/librte_vhost/vhost.h | 1 + 8 files changed, 155 insertions(+), 144 deletions(-) create mode 100644 lib/librte_vhost/rte_vdpa_dev.h diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index 4163047744..f81d13a2c8 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index ea09576c5a..de4154b183 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -12,6 +12,7 @@ #pragma GCC diagnostic ignored "-Wpedantic" #endif #include +#include #include #ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic" diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile index e592795f22..b7ff7dc4b3 100644 --- a/lib/librte_vhost/Makefile +++ b/lib/librte_vhost/Makefile @@ -41,7 +41,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \ vhost_user.c virtio_net.c vdpa.c # install includes -SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h rte_vdpa.h +SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h rte_vdpa.h \ + rte_vdpa_dev.h # only compile vhost crypto when cryptodev is enabled ifeq ($(CONFIG_RTE_LIBRTE_CRYPTODEV),y) diff --git a/lib/librte_vhost/meson.build b/lib/librte_vhost/meson.build index f80632848c..882a0eaf41 100644 --- a/lib/librte_vhost/meson.build +++ b/lib/librte_vhost/meson.build @@ -21,5 +21,6 @@ cflags += '-fno-strict-aliasing' sources = files('fd_man.c', 'iotlb.c', 'socket.c', 'vdpa.c', 'vhost.c', 'vhost_user.c', 'virtio_net.c', 'vhost_crypto.c') -headers = files('rte_vhost.h', 'rte_vdpa.h', 'rte_vhost_crypto.h') +headers = files('rte_vhost.h', 'rte_vdpa.h', 'rte_vdpa_dev.h', + 'rte_vhost_crypto.h') deps += ['ethdev', 'cryptodev', 'hash', 'pci'] diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h index 776ed67c16..5065e2130e 100644 --- a/lib/librte_vhost/rte_vdpa.h +++ b/lib/librte_vhost/rte_vdpa.h @@ -11,13 +11,6 @@ * Device specific vhost lib */ -#include - -#include -#include "rte_vhost.h" - -#define MAX_VDPA_NAME_LEN 128 - /** Maximum name length for statistics counters */ #define RTE_VDPA_STATS_NAME_SIZE 64 @@ -48,103 +41,6 @@ struct rte_vdpa_stat_name { char name[RTE_VDPA_STATS_NAME_SIZE]; /**< The statistic name */ }; -/** - * vdpa device operations - */ -struct rte_vdpa_dev_ops { - /** Get capabilities of this device */ - int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num); - - /** Get supported features of this device */ - int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features); - - /** Get supported protocol features of this device */ - int (*get_protocol_features)(struct rte_vdpa_device *dev, - uint64_t *protocol_features); - - /** Driver configure/close the device */ - int (*dev_conf)(int vid); - int (*dev_close)(int vid); - - /** Enable/disable this vring */ - int (*set_vring_state)(int vid, int vring, int state); - - /** Set features when changed */ - int (*set_features)(int vid); - - /** Destination operations when migration done */ - int (*migration_done)(int vid); - - /** Get the vfio group fd */ - int (*get_vfio_group_fd)(int vid); - - /** Get the vfio device fd */ - int (*get_vfio_device_fd)(int vid); - - /** Get the notify area info of the queue */ - int (*get_notify_area)(int vid, int qid, - uint64_t *offset, uint64_t *size); - - /** Get statistics name */ - int (*get_stats_names)(struct rte_vdpa_device *dev, - struct rte_vdpa_stat_name *stats_names, - unsigned int size); - - /** Get statistics of the queue */ - int (*get_stats)(struct rte_vdpa_device *dev, int qid, - struct rte_vdpa_stat *stats, unsigned int n); - - /** Reset statistics of the queue */ - int (*reset_stats)(struct rte_vdpa_device *dev, int qid); - - /** Reserved for future extension */ - void *reserved[2]; -}; - -/** - * vdpa device structure includes device address and device operations. - */ -struct rte_vdpa_device { - TAILQ_ENTRY(rte_vdpa_device) next; - /** Generic device information */ - struct rte_device *device; - /** vdpa device operations */ - struct rte_vdpa_dev_ops *ops; -} __rte_cache_aligned; - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Register a vdpa device - * - * @param addr - * the vdpa device address - * @param ops - * the vdpa device operations - * @return - * vDPA device pointer on success, NULL on failure - */ -__rte_experimental -struct rte_vdpa_device * -rte_vdpa_register_device(struct rte_device *rte_dev, - struct rte_vdpa_dev_ops *ops); - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Unregister a vdpa device - * - * @param did - * vDPA device pointer - * @return - * device id on success, -1 on failure - */ -__rte_experimental -int -rte_vdpa_unregister_device(struct rte_vdpa_device *); - /** * @warning * @b EXPERIMENTAL: this API may change without prior notice @@ -175,44 +71,6 @@ __rte_experimental struct rte_device * rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev); -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Enable/Disable host notifier mapping for a vdpa port. - * - * @param vid - * vhost device id - * @param enable - * true for host notifier map, false for host notifier unmap - * @return - * 0 on success, -1 on failure - */ -__rte_experimental -int -rte_vhost_host_notifier_ctrl(int vid, bool enable); - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Synchronize the used ring from mediated ring to guest, log dirty - * page for each writeable buffer, caller should handle the used - * ring logging before device stop. - * - * @param vid - * vhost device id - * @param qid - * vhost queue id - * @param vring_m - * mediated virtio ring pointer - * @return - * number of synced used entries on success, -1 on failure - */ -__rte_experimental -int -rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); - /** * @warning * @b EXPERIMENTAL: this API may change without prior notice diff --git a/lib/librte_vhost/rte_vdpa_dev.h b/lib/librte_vhost/rte_vdpa_dev.h new file mode 100644 index 0000000000..fecaa8e081 --- /dev/null +++ b/lib/librte_vhost/rte_vdpa_dev.h @@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _RTE_VDPA_H_DEV_ +#define _RTE_VDPA_H_DEV_ + +#include + +#include "rte_vhost.h" + +/** + * vdpa device operations + */ +struct rte_vdpa_dev_ops { + /** Get capabilities of this device */ + int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num); + + /** Get supported features of this device */ + int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features); + + /** Get supported protocol features of this device */ + int (*get_protocol_features)(struct rte_vdpa_device *dev, + uint64_t *protocol_features); + + /** Driver configure/close the device */ + int (*dev_conf)(int vid); + int (*dev_close)(int vid); + + /** Enable/disable this vring */ + int (*set_vring_state)(int vid, int vring, int state); + + /** Set features when changed */ + int (*set_features)(int vid); + + /** Destination operations when migration done */ + int (*migration_done)(int vid); + + /** Get the vfio group fd */ + int (*get_vfio_group_fd)(int vid); + + /** Get the vfio device fd */ + int (*get_vfio_device_fd)(int vid); + + /** Get the notify area info of the queue */ + int (*get_notify_area)(int vid, int qid, + uint64_t *offset, uint64_t *size); + + /** Get statistics name */ + int (*get_stats_names)(struct rte_vdpa_device *dev, + struct rte_vdpa_stat_name *stats_names, + unsigned int size); + + /** Get statistics of the queue */ + int (*get_stats)(struct rte_vdpa_device *dev, int qid, + struct rte_vdpa_stat *stats, unsigned int n); + + /** Reset statistics of the queue */ + int (*reset_stats)(struct rte_vdpa_device *dev, int qid); + + /** Reserved for future extension */ + void *reserved[2]; +}; + +/** + * vdpa device structure includes device address and device operations. + */ +struct rte_vdpa_device { + TAILQ_ENTRY(rte_vdpa_device) next; + /** Generic device information */ + struct rte_device *device; + /** vdpa device operations */ + struct rte_vdpa_dev_ops *ops; +}; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Register a vdpa device + * + * @param rte_dev + * the generic device pointer + * @param ops + * the vdpa device operations + * @return + * vDPA device pointer on success, NULL on failure + */ +__rte_experimental +struct rte_vdpa_device * +rte_vdpa_register_device(struct rte_device *rte_dev, + struct rte_vdpa_dev_ops *ops); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Unregister a vdpa device + * + * @param dev + * vDPA device pointer + * @return + * device id on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_unregister_device(struct rte_vdpa_device *dev); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Enable/Disable host notifier mapping for a vdpa port. + * + * @param vid + * vhost device id + * @param enable + * true for host notifier map, false for host notifier unmap + * @return + * 0 on success, -1 on failure + */ +__rte_experimental +int +rte_vhost_host_notifier_ctrl(int vid, bool enable); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Synchronize the used ring from mediated ring to guest, log dirty + * page for each writeable buffer, caller should handle the used + * ring logging before device stop. + * + * @param vid + * vhost device id + * @param qid + * vhost queue id + * @param vring_m + * mediated virtio ring pointer + * @return + * number of synced used entries on success, -1 on failure + */ +__rte_experimental +int +rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); + +#endif /* _RTE_VDPA_DEV_H_ */ diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c index e41c73eb9a..ef21ca2a1e 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