From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10079.outbound.protection.outlook.com [40.107.1.79]) by dpdk.org (Postfix) with ESMTP id 39E691CBFC for ; Thu, 5 Apr 2018 16:00:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5N4KE490aHbyJ5pKncBV//YFNUilvbISnHG0y7yllis=; b=nYml6PDXbirhDX6LIFdnpx5jdS/LOML/alveW9cMjPCddgllyhP2YgbQrWyh3xEwI1TGc3a1yUT4Os+J02vcED5r++D2LUuA4RDjdD7Pyxd6Gb7ive2x1sxqe3/+q//P4JjLVfd1Xv4KrDI+p5tvTBMUgtmFB++eFX3M/e9xnvU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=shreyansh.jain@nxp.com; Received: from localhost.localdomain (14.142.187.166) by HE1PR0402MB2780.eurprd04.prod.outlook.com (2603:10a6:3:d4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.10; Thu, 5 Apr 2018 14:00:47 +0000 From: Shreyansh Jain To: anatoly.burakov@intel.com Cc: dev@dpdk.org, Shreyansh Jain Date: Thu, 5 Apr 2018 19:44:14 +0530 Message-Id: <20180405141414.11146-1-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [14.142.187.166] X-ClientProxiedBy: MAXPR0101CA0036.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::22) To HE1PR0402MB2780.eurprd04.prod.outlook.com (2603:10a6:3:d4::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1f415e43-fdf2-40f0-d5c9-08d59afda2b0 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:HE1PR0402MB2780; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0402MB2780; 3:jecjI3ExiVBcbdnGa6KRTBCx1F55o0GaN/ec4e4Iis46hFxeSKr7MftGNYU+mMmyNAz47ab2DaJU2uYQuHzYaYz+dBVimLSUeCd5otXevVkjAE6/6cv9b/gblfVDmsHTHOXTsq/CeFM7EWS2wWZ/bhKXwNVb8hP2W7M3ie1knm1NgVoqYkHmiXHLKfNmYT2tJafnG4ReipuTxH9tcMRMDmnNYbaZdbKwMclpq/b5uSGypE5bfiZIZxQUr8TWe3cL; 25:rAxVY5IMeVgx0ilSuXGi1Cvekj40u9FWDjWjWijkG53c0e7rBUEebzORmr0dx70nAG/qBeJ/aXqYbLMOjHBc6cErpOvy5DaR5G2UNlwie3FlLmgGC9mXj6mV0KYkiKWLsg61eowp6vMZzPuJK0TRUVgLGDA4e5zlp+67BDiW1QYKDwAf67YQNL9UBi9OMo1NrfC1f+/pNyu8la8J83RKVESjPtj8ahe06VXPX9diyd/9YBqBGeoudGj/cQKxlu4PE0NByseccgzCuRk0pxpe0oyDmVLLRfDuxlim6k/+XQesUfKEZEHtGgsUr2C3U4cJpT7uSYW8is9YzxLDpJoMZA==; 31:H3qEh5jXDj4DTV5cEFIHajYiuHRKCJTAZE9TWIQ3CqQoWqKP2rjDZJFOiW8MYciG2wudfEhA4rHnbTbimJkZ7HrWuxoMrw8XD6xbdiYRJ5NJoJerpCQtyre1l7fYJr2RG7s+ChXG1+tuKYbOLNCPxUo2/s41tF9dIO1WVvVsqqxyM25a1CeCd6Fa1R+5URAujLlFeumln4gMPA3TWK6AydmOwXsFvLnO7R0kT5H23qg= X-MS-TrafficTypeDiagnostic: HE1PR0402MB2780: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0402MB2780; 20:h0xUWl9ApQW7t8ZJnLp/E12XXbmFEU2UpFI1X++EN+gWCtlcwl4Ea6SevDepQZocHq0a5SgsYGcQtZ75zrGvOeQS4Be1+BeUb4SJ8Q9e2J2uShdln8OZw9w+5cGmTjJ/Ux2j/hkerGzl2XGnNGd8qHtJyo/3awbI9SG8M7U8JHjtyIOeHtm8puu6H0c8A5SSPLlSZSxv9Le7C1YI6Doac28j29InDnopOejzEXedlIXQ0wDSmc+Dwi0EKoMz69cFg9Sm2H4FjRaA5NSxDE0BPNYPmFS6Y936/2VVwGCIV1EeDlsL54jRFdVIW3fJ3COvfB6hqRXo6sXcrYZmgFc2kwLnADhdcBeFKS0+jU3QlPQlSHkMRZO2R3BEDnsNKYrnf3GpyhcVEt294RIqVHEEFyU4SSBHXlA+K+u05Eyia1eEmxZLywtYdyad5Lh6HmGOKsS0tQUTrclYmWQKubkY59fa6mslOiOMMj/V0o1w0Yvd5SJ3oKQ59a4yx7Z3T8Bm; 4:yS025ABL5s6jMh6TFex+kVEIBsEB76gW1NV8P7mmiXve1/rUYSrNQHnbRL8VbetSniPXtYkNCI/k86mP/AkgIc9d4kDg19fr/+PuOJWYW2Xlnn4XHjl0mK/vCagZzOcv3vfwmSUh0dtmMeiq9iyQYHx2OEPLKfEeLFvuF/bxR4XADIG048fFzi3DMtKPDTWD/cffnt0qvAQxe51jx+jV5WZKc8uc9KxICxGiGaukIM8ESUZPjYuEGZldUSRbwsnJLZtHEb/3lEQ9fP/QY1BiQlzcxep/WQgR8YhijetaCKpuPUeskoePKHCF1IEDmZSV X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(6072148)(201708071742011); SRVR:HE1PR0402MB2780; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0402MB2780; X-Forefront-PRVS: 06339BAE63 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(39860400002)(366004)(346002)(39380400002)(396003)(376002)(199004)(189003)(5009440100003)(1857600001)(105586002)(8936002)(68736007)(81156014)(50226002)(476003)(8676002)(186003)(6512007)(53936002)(76176011)(16526019)(16586007)(97736004)(59450400001)(25786009)(26005)(3846002)(6116002)(11346002)(316002)(6506007)(956004)(478600001)(6486002)(55236004)(2616005)(386003)(81166006)(51416003)(2351001)(86362001)(6916009)(1076002)(47776003)(446003)(6666003)(7736002)(305945005)(2906002)(4326008)(106356001)(575784001)(50466002)(66066001)(52116002)(36756003)(5660300001)(48376002)(2361001)(486006)(110426004); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0402MB2780; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0402MB2780; 23:ysGeSAiIaDMpsaoR+MBEF57MDtd0jgZN9qkyZxL?= =?us-ascii?Q?+iFYGcabQl3pk4HVi6rk22xJ+igNRGQWWGkK/Z4bEKdlSj5skOmAwchrvtTl?= =?us-ascii?Q?8IOJy0MHPWysv7gwbm80oq/BHcLJ365mJM+XqLsqoh1eM58PcYYpWKU9vGI6?= =?us-ascii?Q?f6zlDbv5V9GWeYkwjLuF2KYdDYGEI57C80vQrImvQsOozWqNbP9nR98EfwHB?= =?us-ascii?Q?BJAFk01eHpA/sbMn7Me8uld3JXlBtIXydgvTcM0jJvgGXWMI9VPie6ZwfGTi?= =?us-ascii?Q?WOCJ8hGn+nF9CiwllphKeL/JPUVbxLlq6Kka4M8tgM/CDDp+EWDYvD0k1Zzi?= =?us-ascii?Q?cfOQNy4wCf4G5HGsKGf4lH1b5gq2fFHqGgmXlat5MOCsaDZiLQEzAqQdPEuJ?= =?us-ascii?Q?591KITn5+EYY1WZP8KTJbxIfvJADZ80Sod8xTDOwkeCd1IOdrqrE4Uj8gYUh?= =?us-ascii?Q?hH86zYmOXHd9SI675MI1erBn25l9gjm+Jxf5unWiA5fR3sty1Xdkv6MiZrh6?= =?us-ascii?Q?Oj8AcAjM/Yg2wDDrquCNyFzTCyXXTVRSdYAxJ3J2Q8EK4WdoXDBGC+MlkU0z?= =?us-ascii?Q?hzfxqYkp+4hCaH63mEnyCjalN4FqgT+WwWozjm+jO7rAi3/pNV3LgZM5fkHh?= =?us-ascii?Q?3JbhzosfclopO2l3AEP2BeACHvP7CGU/OTcCWD8/DgH2IGXx+rVFOpN+vjWm?= =?us-ascii?Q?RjVzqIdAH6rMwrPH4JPE+94R+LlMe5sVY3k3Migd60bsX8QtLfB1CJ8vXQCj?= =?us-ascii?Q?nT/G2d0L8/9kDLA0E5l3aDl6tfDMBz7JVgnngi+JH5PstLX4gvXhdcLF/UZJ?= =?us-ascii?Q?SbIT6MRM0DQftyttGmlLDfoM9NlV18rVYJxPaXa/1s3UCjYQwez9PLiHRiRi?= =?us-ascii?Q?WSdpuXK5coou+WLfk8HKRV4OJN4Qp6dloCwLfx2xLwCtTIXT8hWYpcDcnphd?= =?us-ascii?Q?Q9T+6elBo3EG4NzYorpV5XTXGlxr/NTxdhfINDhNGf5dToz3u7Vkign331f5?= =?us-ascii?Q?+eiIIhvHWIekr2Mf1WBMnSsS+1utW5qg3RcOIbL7rAyKFAM3jBN0TkYBWvu6?= =?us-ascii?Q?N5YulCJb7yGGx2KZjrd+g0PbTAuNSZ5vmtVQzMzR20Zz2aCpBq8u6vHlcvIT?= =?us-ascii?Q?bvnCL8druZlKvwaNQSZZxrobvMGlcawG61zkmlzIOyBJRwuHuBCSqvWZ/0yE?= =?us-ascii?Q?IkYxSRPLK/1NV3DFVamV2IkHb/Fmj9v5tDuWL9xJL25g0lVEc1C7NCLrNPsm?= =?us-ascii?Q?co8md8axZ6OBl1/0qTdPYe9m1K2YvvQqaKAUqPIrhi/YdfASWgBaUsO4LSky?= =?us-ascii?Q?FN0LFIX5jk0ZMKJtdYvXdvB6A24yr3REH4evF8MsNqH+rc7GEFu0icoG8m8m?= =?us-ascii?Q?CIm6wCFej9TcHP+smz0eaAdcRGokl9kG69TYz9zhJm/w7qlRa?= X-Microsoft-Antispam-Message-Info: VZqb88PlyqxwiLE0bWTfyqTtkFu+phhKL2LPtLdBBKnFaBN9mvJdM4AWl8wIlPLwdeOK2TsQGsaHgoJOgBh4fJuw6Oth6BNhWbq3f0a+hKDxfO8T5lVZG6KyjboHTkSM9EKoXj08zs3ZGwgMMeY1ilIxc68bz2ZwWrbT2okKOoMNHr62CArLWhCwrGqIKv1b X-Microsoft-Exchange-Diagnostics: 1; HE1PR0402MB2780; 6:zrwxORZZ21FletEIwhnJkJST8JFnELAArld1evoLjfBGajejydPyIdJPO0C5B09uzk8mqL3aIysui6opG9/Nc4oYwVPMt4MOmCegDa4yZzAzDxRL3sV8246prqoE3Mc91TXoeVtPv5VRzovQXJJ0+G4kQg3mZ2kogCyI08zrLeBX9fZx97eGlHEaLCpqY6texhQWrMt+ZS6KgoEk63J0aLFxhyWdSmo/LDqIy9GrUaWJCX6VndkSqOktOgZzOHP5O/CZbZcGi9u13B6c247m1VmXFQMFVLCzbUG36d1Cv/uq+jINCqAJWbWcLMChpoPL6hwhVe9+0iBMUtebk5qmJAyOe9Hw2s4u9uVGU+AIauGqCoyRrzH0g8pX2dTYxNH62tRkzuEEVpQljhG2Iut3CBZoxIsjKpT3jib9PrO4udUlro+HX4a1FbRlq5RpjcVGRNv8VwEMzvqvLyPuB/dHJA==; 5:P0cfDHIQ2BZ2XJgMAq+uL3rvNy+LaVORnSZKODAUNXSvmjJsja1toarJkQnJ3o/wJY51lToYnMxCAi/GlUfd1njR55ULWREYzu55SGWokVqQDP5r76oJVl12WMqjpnK+Wd0+Jem0GkEtd92kmIYBq2z9apbJln1j9lIscRTzPfg=; 24:lbKZJRqLFmIIJt+IzPvhIXERsPdNeGSeC+4YnVbqkOwOqL/vaGsZNyEjRWmvEenCYSICv9LVNKZIKLJ/t6EkPcLEX1qxfD7xvJRoTNG0+3Y= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0402MB2780; 7:tPCpaFffLaas2gts7C9pvculMPdiQ0jgOF3Sl+mUjELPOjNLkJRWCK4cJ8IO5/4f2WFsRFXSoq54GpQyhNH35MAqCAIn+zltwDec3ejhOm80/UfKZ4ZZyT6H74MbyZ35cA/Ukin0xX8bkP0yMlavHvyTZOSgV5f8ulkhzvQMqIv7dyE9ObxdM3W37I8XxKjbAdoH5fFRH15AJ3PJYaCFdR0mWIAnzNPhI/u39xJhECIhQOrXR0x1b/KESi5J60MP X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2018 14:00:47.8131 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f415e43-fdf2-40f0-d5c9-08d59afda2b0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0402MB2780 Subject: [dpdk-dev] [PATCH] bus/fslmc: support for hotplugging of 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: , X-List-Received-Date: Thu, 05 Apr 2018 14:00:51 -0000 Restructure VFIO DMA code for handling hotplug memory events (callbacks) and --legacy case. Signed-off-by: Shreyansh Jain --- ### This is based on the 16fbfef04a3 github repository. This is assuming that changes already exists as done in patch 26/68. Though, this can be a standalone, replacing 26/88. Though, the Makefile changes don't exist in this. Also, this just a first draft. I will push any review changes after this incrementally over v4. ### drivers/bus/fslmc/fslmc_bus.c | 15 ++++ drivers/bus/fslmc/fslmc_vfio.c | 161 +++++++++++++++++++++++++++++++++++---- drivers/bus/fslmc/fslmc_vfio.h | 1 + drivers/net/dpaa2/dpaa2_ethdev.c | 1 - 4 files changed, 163 insertions(+), 15 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 5ee0beb85..50884ff3a 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -266,6 +266,21 @@ rte_fslmc_probe(void) return 0; } + if (rte_log_get_global_level() >= RTE_LOG_DEBUG) + rte_dump_physmem_layout(stdout); + + /* Map existing segments as well as, in case of hotpluggable memory, + * install callback handler. + */ + ret = rte_fslmc_vfio_dmamap(); + if (ret) { + FSLMC_BUS_LOG(ERR, "Unable to DMA map existing VAs: (%d)", + ret); + /* Not continuing ahead */ + FSLMC_BUS_LOG(ERR, "FSLMC VFIO Mapping failed"); + return 0; + } + ret = fslmc_vfio_process_group(); if (ret) { FSLMC_BUS_LOG(ERR, "Unable to setup devices %d", ret); diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 31831e3ce..60725fb70 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "rte_fslmc.h" #include "fslmc_vfio.h" @@ -193,11 +194,68 @@ static int vfio_map_irq_region(struct fslmc_vfio_group *group) return -errno; } +static int fslmc_map_dma(uint64_t vaddr, rte_iova_t iovaddr, size_t len); +static int fslmc_unmap_dma(uint64_t vaddr, rte_iova_t iovaddr, size_t len); + +static void +fslmc_memevent_cb(enum rte_mem_event type, const void *addr, size_t len) +{ + struct rte_memseg_list *msl; + struct rte_memseg *ms; + size_t cur_len = 0, map_len = 0; + uint64_t pgsz, virt_addr; + rte_iova_t iova_addr; + int ret; + + msl = rte_mem_virt2memseg_list(addr); + pgsz = msl->page_sz; + + while (cur_len < len) { + const void *va = RTE_PTR_ADD(addr, cur_len); + + ms = rte_mem_virt2memseg(va, msl); + iova_addr = rte_mem_virt2iova(va); + virt_addr = ms->addr_64; + + map_len = len - map_len; + /* Can only work with max pg_sz */ + if (map_len > pgsz) + map_len = pgsz; + + FSLMC_VFIO_LOG(DEBUG, "Calling with type=%d, va=%p," + " virt_addr=%lX, iova=%lu, map_len=%lu\n", + type, va, virt_addr, iova_addr, map_len); + + if (type == RTE_MEM_EVENT_ALLOC) + ret = fslmc_map_dma(virt_addr, iova_addr, map_len); + else + ret = fslmc_unmap_dma(virt_addr, iova_addr, map_len); + + if (ret != 0) { + FSLMC_VFIO_LOG(ERR, "DMA Mapping/Unmapping failed. " + "Map=%d, addr=%p, len=%lu, err:(%d)", + type, va, map_len, ret); + return; + } + + cur_len += map_len; + } + + if (type == RTE_MEM_EVENT_ALLOC) + FSLMC_VFIO_LOG(DEBUG, "Total Mapped: addr=%p, len=%lu\n", + addr, len); + else + FSLMC_VFIO_LOG(DEBUG, "Total Unmapped: addr=%p, len=%lu\n", + addr, len); +} + static int -fslmc_vfio_map(const struct rte_memseg_list *msl __rte_unused, - const struct rte_memseg *ms, void *arg) +#ifdef RTE_LIBRTE_DPAA2_USE_PHYS_IOVA +fslmc_map_dma(uint64_t vaddr, rte_iova_t iovaddr, size_t len) +#else +fslmc_map_dma(uint64_t vaddr, rte_iova_t iovaddr __rte_unused, size_t len) +#endif { - int *n_segs = arg; struct fslmc_vfio_group *group; struct vfio_iommu_type1_dma_map dma_map = { .argsz = sizeof(struct vfio_iommu_type1_dma_map), @@ -205,10 +263,11 @@ fslmc_vfio_map(const struct rte_memseg_list *msl __rte_unused, }; int ret; - dma_map.size = ms->len; - dma_map.vaddr = ms->addr_64; + dma_map.size = len; + dma_map.vaddr = vaddr; + #ifdef RTE_LIBRTE_DPAA2_USE_PHYS_IOVA - dma_map.iova = ms->iova; + dma_map.iova = iovaddr; #else dma_map.iova = dma_map.vaddr; #endif @@ -221,33 +280,102 @@ fslmc_vfio_map(const struct rte_memseg_list *msl __rte_unused, return -1; } - FSLMC_VFIO_LOG(DEBUG, "-->Initial SHM Virtual ADDR %llX", - dma_map.vaddr); - FSLMC_VFIO_LOG(DEBUG, "-----> DMA size 0x%llX", dma_map.size); - ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA, - &dma_map); + FSLMC_VFIO_LOG(DEBUG, "--> Map address: %llX, size: 0x%llX\n", + dma_map.vaddr, dma_map.size); + ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA, &dma_map); if (ret) { FSLMC_VFIO_LOG(ERR, "VFIO_IOMMU_MAP_DMA API(errno = %d)", errno); return -1; } - (*n_segs)++; + return 0; } +static int +fslmc_unmap_dma(uint64_t vaddr, uint64_t iovaddr __rte_unused, size_t len) +{ + struct fslmc_vfio_group *group; + struct vfio_iommu_type1_dma_unmap dma_unmap = { + .argsz = sizeof(struct vfio_iommu_type1_dma_unmap), + .flags = 0, + }; + int ret; + + dma_unmap.size = len; + dma_unmap.iova = vaddr; + + /* SET DMA MAP for IOMMU */ + group = &vfio_group; + + if (!group->container) { + FSLMC_VFIO_LOG(ERR, "Container is not connected "); + return -1; + } + + FSLMC_VFIO_LOG(DEBUG, "--> Unmap address: %llX, size: 0x%llX\n", + dma_unmap.iova, dma_unmap.size); + ret = ioctl(group->container->fd, VFIO_IOMMU_UNMAP_DMA, &dma_unmap); + if (ret) { + FSLMC_VFIO_LOG(ERR, "VFIO_IOMMU_UNMAP_DMA API(errno = %d)", + errno); + return -1; + } + + return 0; +} + +static int +fslmc_dmamap_seg(const struct rte_memseg_list *msl __rte_unused, + const struct rte_memseg *ms, void *arg) +{ + int *n_segs = arg; + int ret; + + ret = fslmc_map_dma(ms->addr_64, ms->iova, ms->len); + if (ret) + FSLMC_VFIO_LOG(ERR, "Unable to VFIO map (addr=%p, len=%lu)\n", + ms->addr, ms->len); + else + (*n_segs)++; + + return ret; +} + int rte_fslmc_vfio_dmamap(void) { - int i = 0; + int i = 0, ret; + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + rte_rwlock_t *mem_lock = &mcfg->memory_hotplug_lock; if (is_dma_done) return 0; - if (rte_memseg_walk(fslmc_vfio_map, &i) < 0) + /* Lock before parsing and registering callback to memory subsystem */ + rte_rwlock_read_lock(mem_lock); + + if (rte_memseg_walk(fslmc_dmamap_seg, &i) < 0) { + rte_rwlock_read_lock(mem_lock); return -1; + } + + ret = rte_mem_event_callback_register("fslmc_memevent_clb", + fslmc_memevent_cb); + if (ret) + /* Cannot install callback handler - thus, DMA Mapping cannot + * be done. But, this is possible for --legacy-mem option + */ + FSLMC_VFIO_LOG(DEBUG, "Unable to install memory handler"); + FSLMC_VFIO_LOG(DEBUG, "Installed memory callback handler"); /* Verifying that at least single segment is available */ if (i <= 0) { + /* TODO: Is this verification required any more? What would + * happen to non-legacy case where nothing was preallocated + * thus causing i==0? + */ FSLMC_VFIO_LOG(ERR, "No Segments found for VFIO Mapping"); + rte_rwlock_read_unlock(mem_lock); return -1; } FSLMC_VFIO_LOG(DEBUG, "Total %d segments found.", i); @@ -258,6 +386,11 @@ int rte_fslmc_vfio_dmamap(void) */ vfio_map_irq_region(&vfio_group); + /* Existing segments have been mapped and memory callback for hotplug + * has been installed. + */ + rte_rwlock_read_unlock(mem_lock); + is_dma_done = 1; return 0; diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h index e8fb3445f..e77e4c4ac 100644 --- a/drivers/bus/fslmc/fslmc_vfio.h +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -9,6 +9,7 @@ #define _FSLMC_VFIO_H_ #include +#include #include "eal_vfio.h" diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c index 2fb7b2da7..962b90035 100644 --- a/drivers/net/dpaa2/dpaa2_ethdev.c +++ b/drivers/net/dpaa2/dpaa2_ethdev.c @@ -1850,7 +1850,6 @@ dpaa2_dev_init(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx; eth_dev->tx_pkt_burst = dpaa2_dev_tx; - rte_fslmc_vfio_dmamap(); RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name); return 0; -- 2.14.1