From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 01956A04B7; Wed, 14 Oct 2020 16:41:22 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2DD241DE7A; Wed, 14 Oct 2020 16:41:20 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 117AC1DE6F for ; Wed, 14 Oct 2020 16:41:16 +0200 (CEST) IronPort-SDR: rdSsaZMvp+8ot5RlSi8SNfaZZORXETMRK3qFheJOjQ4twuloL+SDpCxo2/y1eXra6ZkapBWxLc IS5tcdOYGhug== X-IronPort-AV: E=McAfee;i="6000,8403,9773"; a="183640463" X-IronPort-AV: E=Sophos;i="5.77,375,1596524400"; d="scan'208";a="183640463" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2020 07:39:38 -0700 IronPort-SDR: YFSCWa1ZahlmVV9XVaUwJXAgjRs1xpzhhFTiqQAPyFbgkaRyN7XbPkWPACToeOqVZUSBMYvBpx kkT0lCE7dKHg== X-IronPort-AV: E=Sophos;i="5.77,375,1596524400"; d="scan'208";a="520401727" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.251.84.158]) ([10.251.84.158]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2020 07:39:38 -0700 To: Nithin Dabilpuram Cc: jerinj@marvell.com, dev@dpdk.org References: <20201012081106.10610-1-ndabilpuram@marvell.com> <20201012081106.10610-2-ndabilpuram@marvell.com> From: "Burakov, Anatoly" Message-ID: Date: Wed, 14 Oct 2020 15:39:36 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201012081106.10610-2-ndabilpuram@marvell.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 1/2] 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" On 12-Oct-20 9:11 AM, Nithin Dabilpuram wrote: > Add test case in test_memory to test VFIO DMA map/unmap. > > Signed-off-by: Nithin Dabilpuram > --- > app/test/test_memory.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 79 insertions(+) > > diff --git a/app/test/test_memory.c b/app/test/test_memory.c > index 7d5ae99..1c56455 100644 > --- a/app/test/test_memory.c > +++ b/app/test/test_memory.c > @@ -4,11 +4,16 @@ > > #include > #include > +#include > +#include > +#include > > #include > +#include > #include > #include > #include > +#include > > #include "test.h" > > @@ -70,6 +75,71 @@ check_seg_fds(const struct rte_memseg_list *msl, const struct rte_memseg *ms, > } > > static int > +test_memory_vfio_dma_map(void) > +{ > + uint64_t sz = 2 * sysconf(_SC_PAGESIZE), sz1, sz2; i think we now have a function for that, rte_page_size() ? Also, i would prefer uint64_t sz1, sz2, sz = 2 * rte_page_size(); Easier to parse IMO. > + uint64_t unmap1, unmap2; > + uint8_t *mem; > + int ret; > + > + /* Check if vfio is enabled in both kernel and eal */ > + ret = rte_vfio_is_enabled("vfio"); > + if (!ret) > + return 1; No need, rte_vfio_container_dma_map() should set errno to ENODEV if vfio is not enabled. > + > + /* 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, > + (uint64_t)mem, (rte_iova_t)mem, sz); should be (uintptr_t) perhaps? Also, this can return -1 with rte_errno == ENOTSUP, i think this happens if there are no devices attached (or if there's no VFIO support, like it would be on FreeBSD or Windows). > + if (ret) { > + printf("Failed to dma map whole region, ret=%d\n", ret); > + 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 send half region, ret=%d(%d)\n", I think "send half" is a typo? Also, here and in other places, i would prefer a rte_strerror() instead of raw rte_errno number. > + ret, 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(%d)\n", ret, > + rte_errno); > + goto fail; > + } > + > +fail: > + munmap(mem, sz); > + return ret; > +} > + > +static int > test_memory(void) > { > uint64_t s; > @@ -101,6 +171,15 @@ test_memory(void) > return -1; > } > > + /* 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; > + } > + This looks odd in this autotest. Perhaps create a new autotest for VFIO? > return 0; > } > > -- Thanks, Anatoly