From patchwork Wed Dec 2 05:46:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nithin Dabilpuram X-Patchwork-Id: 84668 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 50922A04DB; Wed, 2 Dec 2020 06:48:05 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4C8A8C9EE; Wed, 2 Dec 2020 06:47:07 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id E6A46C9DC for ; Wed, 2 Dec 2020 06:47:03 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0B25epR6012496; Tue, 1 Dec 2020 21:47:03 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=andQF2cMPMS689UaSZ0L4YaiPZylwVi+WjJx1foN0wc=; b=HhEFERBGVwu5ka5HKgrnLkgwt+tYuILPhu1iaBTANlhiFWaqiaTUUohcU32X5xirfCSy OfPY8lMpzCYJxC9IqiGRYSsn1mr8xjlk033T1F4au/bdYn3I2c8Q+KkLntUMZLNisB8d gAFk47dwUIk9NIsq7Ndfu49h5wYIeFnechNcYwBzSXQtANVyZXFU8wFvWjo/J+MLF5Tp FhXPNtxGXgDZ83XOxsLrxYHCqG3yf473v1P9YxaoitjaHuWfv3/xTxSazW6iwvuFzp3M JZec0oO1McSzfPXdCfinAsY+UVLedtwwrwTKlzYu+XlbV/4aiqKmthhFxEH/mLoakRBC 3w== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0b-0016f401.pphosted.com with ESMTP id 355w5097cv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 01 Dec 2020 21:47:03 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 1 Dec 2020 21:47:01 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 1 Dec 2020 21:47:01 -0800 Received: from hyd1588t430.marvell.com (unknown [10.29.52.204]) by maili.marvell.com (Postfix) with ESMTP id ADED93F703F; Tue, 1 Dec 2020 21:46:59 -0800 (PST) From: Nithin Dabilpuram To: , David Christensen , CC: , , Nithin Dabilpuram Date: Wed, 2 Dec 2020 11:16:46 +0530 Message-ID: <20201202054647.3449-4-ndabilpuram@marvell.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20201202054647.3449-1-ndabilpuram@marvell.com> References: <20201012081106.10610-1-ndabilpuram@marvell.com> <20201202054647.3449-1-ndabilpuram@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-12-02_01:2020-11-30, 2020-12-02 signatures=0 Subject: [dpdk-dev] [PATCH v4 3/4] test: add test case to validate VFIO DMA map/unmap 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" Test case mmap's system pages and tries to performs a user DMA map and unmap both partially and fully. Signed-off-by: Nithin Dabilpuram Acked-by: Anatoly Burakov --- app/test/meson.build | 1 + app/test/test_vfio.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 app/test/test_vfio.c diff --git a/app/test/meson.build b/app/test/meson.build index 94fd39f..d9eedb6 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -139,6 +139,7 @@ test_sources = files('commands.c', 'test_trace_register.c', 'test_trace_perf.c', 'test_version.c', + 'test_vfio.c', 'virtual_pmd.c' ) diff --git a/app/test/test_vfio.c b/app/test/test_vfio.c new file mode 100644 index 0000000..00626d4 --- /dev/null +++ b/app/test/test_vfio.c @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "test.h" + +static int +test_memory_vfio_dma_map(void) +{ + uint64_t sz1, sz2, sz = 2 * rte_mem_page_size(); + uint64_t unmap1, unmap2; + uint8_t *mem; + int ret; + + /* Allocate twice size of page */ + mem = mmap(NULL, sz, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (mem == MAP_FAILED) { + printf("Failed to allocate memory for external heap\n"); + return -1; + } + + /* Force page allocation */ + memset(mem, 0, sz); + + /* map the whole region */ + ret = rte_vfio_container_dma_map(RTE_VFIO_DEFAULT_CONTAINER_FD, + (uintptr_t)mem, (rte_iova_t)mem, sz); + if (ret) { + /* Check if VFIO is not available or no device is probed */ + if (rte_errno == ENOTSUP || rte_errno == ENODEV) { + ret = 1; + goto fail; + } + printf("Failed to dma map whole region, ret=%d(%s)\n", + ret, rte_strerror(rte_errno)); + goto fail; + } + + unmap1 = (uint64_t)mem + (sz / 2); + sz1 = sz / 2; + unmap2 = (uint64_t)mem; + sz2 = sz / 2; + /* unmap the partial region */ + ret = rte_vfio_container_dma_unmap(RTE_VFIO_DEFAULT_CONTAINER_FD, + unmap1, (rte_iova_t)unmap1, sz1); + if (ret) { + if (rte_errno == ENOTSUP) { + printf("Partial dma unmap not supported\n"); + unmap2 = (uint64_t)mem; + sz2 = sz; + } else { + printf("Failed to unmap second half region, ret=%d(%s)\n", + ret, rte_strerror(rte_errno)); + goto fail; + } + } + + /* unmap the remaining region */ + ret = rte_vfio_container_dma_unmap(RTE_VFIO_DEFAULT_CONTAINER_FD, + unmap2, (rte_iova_t)unmap2, sz2); + if (ret) { + printf("Failed to unmap remaining region, ret=%d(%s)\n", ret, + rte_strerror(rte_errno)); + goto fail; + } + +fail: + munmap(mem, sz); + return ret; +} + +static int +test_vfio(void) +{ + int ret; + + /* test for vfio dma map/unmap */ + ret = test_memory_vfio_dma_map(); + if (ret == 1) { + printf("VFIO dma map/unmap unsupported\n"); + } else if (ret < 0) { + printf("Error vfio dma map/unmap, ret=%d\n", ret); + return -1; + } + + return 0; +} + +REGISTER_TEST_COMMAND(vfio_autotest, test_vfio);