From patchwork Fri Dec 13 14:13:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 63845 X-Patchwork-Delegate: david.marchand@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 A9A08A04F1; Fri, 13 Dec 2019 15:13:44 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7CC8E1BF94; Fri, 13 Dec 2019 15:13:39 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 3E5D21BF8D for ; Fri, 13 Dec 2019 15:13:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576246416; 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=eChFg4knKKoLw7SWxulKYvQhlvXP+awAtpzYacZCbQs=; b=HY8QI8k5grcS0q4KUUWIXcuuO+W7LaF5NYBDbBp3FZsP5EQBOzHPNc12zLbtEj7ZKZX0fK HmMx659pJX5AjPObne0vK55m5Mc9v7vbrseR5e3OcYw/CC+E7wIRmZISwrv678Pru4CAaG lfoVPreseMZZnmzwgg2Q5aiSW/GFetw= 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-209-km5tr3IuOF6bxrHw-lUOxw-1; Fri, 13 Dec 2019 09:13:33 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22849CF98F; Fri, 13 Dec 2019 14:13:32 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 450BE60C05; Fri, 13 Dec 2019 14:13:29 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com, anatoly.burakov@intel.com Cc: Maxime Coquelin Date: Fri, 13 Dec 2019 15:13:19 +0100 Message-Id: <20191213141322.32730-2-maxime.coquelin@redhat.com> In-Reply-To: <20191213141322.32730-1-maxime.coquelin@redhat.com> References: <20191213141322.32730-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: km5tr3IuOF6bxrHw-lUOxw-1 X-Mimecast-Spam-Score: 0 Subject: [dpdk-dev] [PATCH 1/4] eal: add new API to register contiguous external memory 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 new API allows to pass a file descriptor while registering external and contiguous memory in the IOVA space. This is required for using Virtio-user PMD with application using external memory for the mbuf's buffers, like Seastar or VPP. FD is only attached to the segments if single_file_segment option is enabled. Signed-off-by: Maxime Coquelin --- lib/librte_eal/common/eal_common_memory.c | 75 +++++++++++++++++++++- lib/librte_eal/common/include/rte_memory.h | 46 +++++++++++++ lib/librte_eal/common/malloc_heap.c | 17 ++++- lib/librte_eal/common/malloc_heap.h | 2 +- lib/librte_eal/common/rte_malloc.c | 2 +- lib/librte_eal/rte_eal_version.map | 3 + 6 files changed, 141 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c index 4a9cc1f19a..7a4b371828 100644 --- a/lib/librte_eal/common/eal_common_memory.c +++ b/lib/librte_eal/common/eal_common_memory.c @@ -772,6 +772,79 @@ rte_memseg_get_fd_offset(const struct rte_memseg *ms, size_t *offset) return ret; } +int +rte_extmem_register_contig(void *va_addr, size_t len, rte_iova_t iova_addr, + size_t page_sz, int fd) +{ + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + rte_iova_t *iova_addrs = NULL; + unsigned int socket_id, n, i; + int ret = 0; + + if (va_addr == NULL || page_sz == 0 || len == 0 || + !rte_is_power_of_2(page_sz) || + RTE_ALIGN(len, page_sz) != len || + ((len % page_sz) != 0 || + !rte_is_aligned(va_addr, page_sz))) { + rte_errno = EINVAL; + return -1; + } + + n = len / page_sz; + if (iova_addr != 0) { + iova_addrs = malloc(n * sizeof(*iova_addrs)); + if (iova_addrs == NULL) { + rte_errno = -ENOMEM; + return -1; + } + + for (i = 0; i < n; i++) + iova_addrs[i] = iova_addr + n * page_sz; + + } + + + if (fd >= 0 && !internal_config.single_file_segments) { + RTE_LOG(INFO, EAL, "FD won't be attached to the external memory," \ + " requires single file segments\n"); + fd = -1; + } + rte_mcfg_mem_write_lock(); + + /* make sure the segment doesn't already exist */ + if (malloc_heap_find_external_seg(va_addr, len) != NULL) { + rte_errno = EEXIST; + ret = -1; + goto unlock; + } + + /* get next available socket ID */ + socket_id = mcfg->next_socket_id; + if (socket_id > INT32_MAX) { + RTE_LOG(ERR, EAL, "Cannot assign new socket ID's\n"); + rte_errno = ENOSPC; + ret = -1; + goto unlock; + } + + /* we can create a new memseg */ + if (malloc_heap_create_external_seg(va_addr, iova_addrs, n, + page_sz, "extmem_contig", socket_id, fd) == NULL) { + ret = -1; + goto unlock; + } + + /* memseg list successfully created - increment next socket ID */ + mcfg->next_socket_id++; +unlock: + rte_mcfg_mem_write_unlock(); + + if (iova_addrs != NULL) + free(iova_addrs); + + return ret; +} + int rte_extmem_register(void *va_addr, size_t len, rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz) @@ -809,7 +882,7 @@ rte_extmem_register(void *va_addr, size_t len, rte_iova_t iova_addrs[], /* we can create a new memseg */ n = len / page_sz; if (malloc_heap_create_external_seg(va_addr, iova_addrs, n, - page_sz, "extmem", socket_id) == NULL) { + page_sz, "extmem", socket_id, -1) == NULL) { ret = -1; goto unlock; } diff --git a/lib/librte_eal/common/include/rte_memory.h b/lib/librte_eal/common/include/rte_memory.h index 3d8d0bd697..e274e47e5e 100644 --- a/lib/librte_eal/common/include/rte_memory.h +++ b/lib/librte_eal/common/include/rte_memory.h @@ -451,6 +451,10 @@ rte_memseg_get_fd_offset_thread_unsafe(const struct rte_memseg *ms, * is NULL. * @param page_sz * Page size of the underlying memory + * @param fd + * File descriptor for the external memory region registered. Must be set to + * -1 if no FD, and ignored if single-segment isn't not used or if iova + * aren't contiguous (iova_addrs != NULL). * * @return * - 0 on success @@ -461,6 +465,48 @@ rte_memseg_get_fd_offset_thread_unsafe(const struct rte_memseg *ms, */ __rte_experimental int +rte_extmem_register_contig(void *va_addr, size_t len, rte_iova_t iova_addr, + size_t page_sz, int fd); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Register external contiguous memory chunk with DPDK. + * + * @note Using this API is mutually exclusive with ``rte_malloc`` family of + * API's. + * + * @note This API will not perform any DMA mapping. It is expected that user + * will do that themselves. + * + * @note Before accessing this memory in other processes, it needs to be + * attached in each of those processes by calling ``rte_extmem_attach`` in + * each other process. + * + * @param va_addr + * Start of virtual area to register. Must be aligned by ``page_sz``. + * @param len + * Length of virtual area to register. Must be aligned by ``page_sz``. + * @param iova_addr + * IOVA address for the contiguous memory chunck. Can be 0, in which case + * page IOVA addresses will be set to RTE_BAD_IOVA. + * @param page_sz + * Page size of the underlying memory + * @param fd + * File descriptor for the external memory region registered. Must be set to + * -1 if no FD, and ignored if single-segment isn't not used. + * + * @return + * - 0 on success + * - -1 in case of error, with rte_errno set to one of the following: + * EINVAL - one of the parameters was invalid + * EEXIST - memory chunk is already registered + * ENOSPC - no more space in internal config to store a new memory chunk + * ENOMEM - failed to allocate pages IOVA addresses + */ +__rte_experimental +int rte_extmem_register(void *va_addr, size_t len, rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz); diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c index 842eb9de75..229ab6563c 100644 --- a/lib/librte_eal/common/malloc_heap.c +++ b/lib/librte_eal/common/malloc_heap.c @@ -1096,7 +1096,7 @@ destroy_elem(struct malloc_elem *elem, size_t len) struct rte_memseg_list * malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz, const char *seg_name, - unsigned int socket_id) + unsigned int socket_id, int fd) { struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; char fbarray_name[RTE_FBARRAY_NAME_LEN]; @@ -1153,6 +1153,13 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], msl->version = 0; msl->external = 1; + if (fd >= 0) { + int list_idx = msl - mcfg->memsegs; + + if (eal_memalloc_set_seg_list_fd(list_idx, fd)) + RTE_LOG(ERR, EAL, "Failed to set segment list FD\n"); + } + return msl; } @@ -1202,10 +1209,18 @@ malloc_heap_find_external_seg(void *va_addr, size_t len) int malloc_heap_destroy_external_seg(struct rte_memseg_list *msl) { + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + int list_idx; + /* destroy the fbarray backing this memory */ if (rte_fbarray_destroy(&msl->memseg_arr) < 0) return -1; + list_idx = msl - mcfg->memsegs; + if (eal_memalloc_set_seg_list_fd(list_idx, -1)) + RTE_LOG(ERR, EAL, "Failed to reset segment list FD\n"); + + /* reset the memseg list */ memset(msl, 0, sizeof(*msl)); diff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h index 772736b53f..438ce908de 100644 --- a/lib/librte_eal/common/malloc_heap.h +++ b/lib/librte_eal/common/malloc_heap.h @@ -65,7 +65,7 @@ malloc_heap_destroy(struct malloc_heap *heap); struct rte_memseg_list * malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz, const char *seg_name, - unsigned int socket_id); + unsigned int socket_id, int fd); struct rte_memseg_list * malloc_heap_find_external_seg(void *va_addr, size_t len); diff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c index d6026a2b17..aa19b0517f 100644 --- a/lib/librte_eal/common/rte_malloc.c +++ b/lib/librte_eal/common/rte_malloc.c @@ -389,7 +389,7 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len, n = len / page_sz; msl = malloc_heap_create_external_seg(va_addr, iova_addrs, n, page_sz, - heap_name, heap->socket_id); + heap_name, heap->socket_id, -1); if (msl == NULL) { ret = -1; goto unlock; diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index e38d02530c..ddcb4b0512 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -332,4 +332,7 @@ EXPERIMENTAL { # added in 19.11 rte_log_get_stream; rte_mcfg_get_single_file_segments; + + # added in 20.02 + rte_extmem_register_contig; }; From patchwork Fri Dec 13 14:13:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 63846 X-Patchwork-Delegate: david.marchand@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 8A6EBA04F1; Fri, 13 Dec 2019 15:13:55 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DEF5C1BF9D; Fri, 13 Dec 2019 15:13:41 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 252971BF9A for ; Fri, 13 Dec 2019 15:13:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576246419; 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=VOzRomDJ/d2lg7k+EKYhCm+YSUUvwmsIsPy2lXBFQZI=; b=ClsjPxRjiA3DaMGRYcvv9g3n8FWi6A5lSU8YNIig8b92s/y11jARG4yMdPoRPcDGSvP6Ow eovAkYaTos6xqYImuurDB7wZxFZ6iN7aeJzJR40urDzA6T3s31Oy4YJwVi4l/ma4YrDGn1 U4diN6JBZzJPCkd+J1WMqq3dv3T8BZc= 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-392-zzyw3BAhM4-jFnZbk5Tyng-1; Fri, 13 Dec 2019 09:13:36 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50620107B272; Fri, 13 Dec 2019 14:13:35 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C6DA60C05; Fri, 13 Dec 2019 14:13:32 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com, anatoly.burakov@intel.com Cc: Maxime Coquelin Date: Fri, 13 Dec 2019 15:13:20 +0100 Message-Id: <20191213141322.32730-3-maxime.coquelin@redhat.com> In-Reply-To: <20191213141322.32730-1-maxime.coquelin@redhat.com> References: <20191213141322.32730-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: zzyw3BAhM4-jFnZbk5Tyng-1 X-Mimecast-Spam-Score: 0 Subject: [dpdk-dev] [PATCH 2/4] eal: allow getting memory segment FD with external memory 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 it is possible to associate a file descriptor when registering external and contiguous memory, let's allow it. If no FD is available for the memory segment, ENOENT error is returned. Signed-off-by: Maxime Coquelin --- lib/librte_eal/common/eal_common_memory.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c index 7a4b371828..cc660f5b85 100644 --- a/lib/librte_eal/common/eal_common_memory.c +++ b/lib/librte_eal/common/eal_common_memory.c @@ -691,12 +691,6 @@ rte_memseg_get_fd_thread_unsafe(const struct rte_memseg *ms) return -1; } - /* segment fd API is not supported for external segments */ - if (msl->external) { - rte_errno = ENOTSUP; - return -1; - } - ret = eal_memalloc_get_seg_fd(msl_idx, seg_idx); if (ret < 0) { rte_errno = -ret; @@ -746,12 +740,6 @@ rte_memseg_get_fd_offset_thread_unsafe(const struct rte_memseg *ms, return -1; } - /* segment fd API is not supported for external segments */ - if (msl->external) { - rte_errno = ENOTSUP; - return -1; - } - ret = eal_memalloc_get_seg_fd_offset(msl_idx, seg_idx, offset); if (ret < 0) { rte_errno = -ret; From patchwork Fri Dec 13 14:13:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 63847 X-Patchwork-Delegate: david.marchand@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 30834A04F1; Fri, 13 Dec 2019 15:14:04 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A17331BFAC; Fri, 13 Dec 2019 15:13:43 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by dpdk.org (Postfix) with ESMTP id 9197B1BF9C for ; Fri, 13 Dec 2019 15:13:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576246419; 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=9f1DhzMsFTQb2Ey43L2zkluCSwQM0Tjn5LgKUdvc5wQ=; b=D+aSRzZO6mpaWFt2YwGBj0Nc4AWMp0NBdxPgtPXoMMEQwS9XpF+PYi2gZ+EOFZcnn5kIeJ IrqVYuzT4tI+x27LCUPtr04g4KEpM+dPEqyzzKKKv7lrgAWUEJmEr0ZjhJalJU998zhnzN xzqezE2o35RWLmKzQgzRzvVXIFXAWKc= 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-41-N6tHRgGRM9ykrDrNo0QXWQ-1; Fri, 13 Dec 2019 09:13:38 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55DC4800D5B; Fri, 13 Dec 2019 14:13:37 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id B196360C05; Fri, 13 Dec 2019 14:13:35 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com, anatoly.burakov@intel.com Cc: Maxime Coquelin Date: Fri, 13 Dec 2019 15:13:21 +0100 Message-Id: <20191213141322.32730-4-maxime.coquelin@redhat.com> In-Reply-To: <20191213141322.32730-1-maxime.coquelin@redhat.com> References: <20191213141322.32730-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: N6tHRgGRM9ykrDrNo0QXWQ-1 X-Mimecast-Spam-Score: 0 Subject: [dpdk-dev] [PATCH 3/4] bus/vdev: add DMA mapping supprt 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 enables VDEVs to implement their own DMA map and unmap callbacks. It will be used by Virtio-user PMD to support external memory registered by applications like Seastar or VPP. Signed-off-by: Maxime Coquelin --- drivers/bus/vdev/rte_bus_vdev.h | 24 ++++++++++++++++ drivers/bus/vdev/vdev.c | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/drivers/bus/vdev/rte_bus_vdev.h b/drivers/bus/vdev/rte_bus_vdev.h index 2bc46530c9..6f920cb064 100644 --- a/drivers/bus/vdev/rte_bus_vdev.h +++ b/drivers/bus/vdev/rte_bus_vdev.h @@ -53,6 +53,18 @@ rte_vdev_device_args(const struct rte_vdev_device *dev) /** Double linked list of virtual device drivers. */ TAILQ_HEAD(vdev_driver_list, rte_vdev_driver); +/** + * Virtual device DMA map function. + */ +typedef int (rte_vdev_dma_map_t)(struct rte_vdev_device *dev, void *addr, + uint64_t iova, size_t len); + +/** + * Virtual device DMA unmap function. + */ +typedef int (rte_vdev_dma_unmap_t)(struct rte_vdev_device *dev, void *addr, + uint64_t iova, size_t len); + /** * Probe function called for each virtual device driver once. */ @@ -69,10 +81,22 @@ typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev); struct rte_vdev_driver { TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */ struct rte_driver driver; /**< Inherited general driver. */ + rte_vdev_dma_map_t *dma_map; /**name); } +static int +vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len) +{ + struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev); + const struct rte_vdev_driver *vdrv; + + if (!dev || !dev->driver) { + rte_errno = EINVAL; + return -1; + } + + vdrv = RTE_DRV_TO_VDRV_CONST(dev->driver); + if (!vdrv) { + rte_errno = EINVAL; + return -1; + } + + if (vdrv->dma_map) + return vdrv->dma_map(vdev, addr, iova, len); + + rte_errno = ENOTSUP; + return -1; +} + +static int +vdev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len) +{ + struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev); + const struct rte_vdev_driver *vdrv; + + if (!dev || !dev->driver) { + rte_errno = EINVAL; + return -1; + } + + vdrv = RTE_DRV_TO_VDRV_CONST(dev->driver); + if (!vdrv) { + rte_errno = EINVAL; + return -1; + } + + if (vdrv->dma_map) + return vdrv->dma_unmap(vdev, addr, iova, len); + + rte_errno = ENOTSUP; + return -1; +} + static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, @@ -553,6 +601,8 @@ static struct rte_bus rte_vdev_bus = { .plug = vdev_plug, .unplug = vdev_unplug, .parse = vdev_parse, + .dma_map = vdev_dma_map, + .dma_unmap = vdev_dma_unmap, .dev_iterate = rte_vdev_dev_iterate, }; From patchwork Fri Dec 13 14:13:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 63848 X-Patchwork-Delegate: david.marchand@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 8CE6DA04F1; Fri, 13 Dec 2019 15:14:12 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0C94D1BFB3; Fri, 13 Dec 2019 15:13:45 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 3C0EC1BFA9 for ; Fri, 13 Dec 2019 15:13:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576246421; 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=oXqyoVNdKeqPMxeyIbjM1YEPLHWDRCeaFFL3jCsedLk=; b=cjhljLenS/iKz1Upm/fUriuFjQpSd89oxH7QsgiyP2ikXlhg6KOKRMTTwvW6W71lrYDdNs 7kDRZr2sc78LR9IiSEbz2wRbaC1LlvCo4NL0KDZ4FEIRdQOrkbWsHMT3ndc59Ex1g43kFq UwArmj5oVkeDo6wSGjivD7N5+KFbukY= 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-146-zTYvulwSMPmsvr-_Ourueg-1; Fri, 13 Dec 2019 09:13:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 800EB18B62A0; Fri, 13 Dec 2019 14:13:39 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id B021760C05; Fri, 13 Dec 2019 14:13:37 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com, anatoly.burakov@intel.com Cc: Maxime Coquelin Date: Fri, 13 Dec 2019 15:13:22 +0100 Message-Id: <20191213141322.32730-5-maxime.coquelin@redhat.com> In-Reply-To: <20191213141322.32730-1-maxime.coquelin@redhat.com> References: <20191213141322.32730-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: zTYvulwSMPmsvr-_Ourueg-1 X-Mimecast-Spam-Score: 0 Subject: [dpdk-dev] [PATCH 4/4] net/virtio: add DMA mapping callback to virtio-user 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" Signed-off-by: Maxime Coquelin --- .../net/virtio/virtio_user/virtio_user_dev.c | 10 +--- .../net/virtio/virtio_user/virtio_user_dev.h | 3 + drivers/net/virtio/virtio_user_ethdev.c | 58 +++++++++++++++++++ 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index ea016e85d8..c72a9543cd 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -313,21 +313,15 @@ virtio_user_fill_intr_handle(struct virtio_user_dev *dev) return 0; } -static void +void virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused, - const void *addr, + const void *addr __rte_unused, size_t len __rte_unused, void *arg) { struct virtio_user_dev *dev = arg; - struct rte_memseg_list *msl; uint16_t i; - /* ignore externally allocated memory */ - msl = rte_mem_virt2memseg_list(addr); - if (msl->external) - return; - pthread_mutex_lock(&dev->mutex); if (dev->started == false) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index ad86837717..5a147c74f0 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -67,4 +67,7 @@ void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx); void virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx); uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs); +void +virtio_user_mem_event_cb(enum rte_mem_event type, + const void *addr, size_t len , void *arg); #endif diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 3fc1725736..fd3ce2dfab 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -385,6 +385,62 @@ const struct virtio_pci_ops virtio_user_ops = { .notify_queue = virtio_user_notify_queue, }; +static int +virtio_user_dma_map(struct rte_vdev_device *vdev, void *addr, + uint64_t iova __rte_unused, size_t len) +{ + const char *name; + struct rte_eth_dev *eth_dev; + struct virtio_hw *hw; + struct virtio_user_dev *dev; + + if (!vdev) + return -EINVAL; + + name = rte_vdev_device_name(vdev); + eth_dev = rte_eth_dev_allocated(name); + if (!eth_dev) + return -ENODEV; + + hw = eth_dev->data->dev_private; + dev = hw->virtio_user_dev; + + virtio_user_mem_event_cb(RTE_MEM_EVENT_ALLOC, + addr, + len, + (void *)dev); + + return 0; +} + +static int +virtio_user_dma_unmap(struct rte_vdev_device *vdev, void *addr, + uint64_t iova __rte_unused, size_t len) +{ + const char *name; + struct rte_eth_dev *eth_dev; + struct virtio_hw *hw; + struct virtio_user_dev *dev; + + if (!vdev) + return -EINVAL; + + name = rte_vdev_device_name(vdev); + eth_dev = rte_eth_dev_allocated(name); + if (!eth_dev) + return -ENODEV; + + hw = eth_dev->data->dev_private; + dev = hw->virtio_user_dev; + + virtio_user_mem_event_cb(RTE_MEM_EVENT_FREE, + addr, + len, + (void *)dev); + + return 0; +} + static const char *valid_args[] = { #define VIRTIO_USER_ARG_QUEUES_NUM "queues" VIRTIO_USER_ARG_QUEUES_NUM, @@ -717,6 +773,8 @@ virtio_user_pmd_remove(struct rte_vdev_device *vdev) } static struct rte_vdev_driver virtio_user_driver = { + .dma_map = virtio_user_dma_map, + .dma_unmap = virtio_user_dma_unmap, .probe = virtio_user_pmd_probe, .remove = virtio_user_pmd_remove, };