From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0081.outbound.protection.outlook.com [104.47.0.81]) by dpdk.org (Postfix) with ESMTP id AAC611B777 for ; Mon, 9 Apr 2018 11:46:21 +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=aIwpLJ17aaJDKpEsro6CpTwCocfmtwKW1FW+kA+rcVI=; b=wP7Ui5jEFoDJmxz9O/U/U+I0EgBVFRh2TLap31dgyVR2VCc4iy3MwTuhbQ0AhLWPsFCOeNhocz5HZojXE20MDvUxWdGEAzBzZQKnpDNU1NAgiwtq9LqBAaTAbqaMPGrw5RWIwXnWTONkkSdPY71C5EyHopXbuxXjJd3yALU9fYc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=shreyansh.jain@nxp.com; Received: from [10.232.14.39] (14.142.187.166) by HE1PR0402MB2778.eurprd04.prod.outlook.com (2603:10a6:3:d4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Mon, 9 Apr 2018 09:46:18 +0000 To: Anatoly Burakov Cc: dev@dpdk.org References: From: Shreyansh Jain Message-ID: Date: Mon, 9 Apr 2018 15:31:28 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [14.142.187.166] X-ClientProxiedBy: HK2PR02CA0191.apcprd02.prod.outlook.com (2603:1096:201:21::27) To HE1PR0402MB2778.eurprd04.prod.outlook.com (2603:10a6:3:d4::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 45054b27-f618-4bd1-51dd-08d59dfebf67 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:HE1PR0402MB2778; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0402MB2778; 3:nJyxURhgAE2tQAB+5yomn+cQNQA03cjNyBl0QsYJulcKBVvtvcKKl+B1Fhu5PEYAk0+/b97As16gPudsiNZoZEqYM6dCtOa5RHcXlULQJ5UukJ8YTvwrXrRhbEAHcy3Sqa7vd/Z3vF6ur0L3J63v2SuKkeY2+DuUk+cpgdE58Pw97i8iQDd2tXyfAVM4UV7EB9i+rfGet6u/3fQ8r47rj7L9sZWtAbyJndhVNhI/nT1q7og9KErl/+8JA5IpCE62; 25:ZdsBoZdmgoahgKwhtKS/GxEhkWX8VkT1GFJHxqBrwYNoLU9C8kSHUzJZEFI3aLx1+5ax9UYl4kH5E+nloYx5zmGJOZIgUwEvTlTfzzolf1vFWOjL8u7LQqpcYYvnR3zMO6nFysRGSQHr6pWoDoNaNJmI/LyU4xGNHl6PCDifXge2X4IaTD7gfoTsBqyaLmiduRSGzJKxYtKjGIvqzfWK94uedDGy5EhwiEzD7NSK17twFYOsCe2vEM7kJV46HPnAtbPC4V0mxBxTcFZ5+fyMF3el5WzVN7K4SxJ5ChrvY+8TCzGmKzhfZBKl9Ii327zqw68+q1sxB+kDecR+q6oTBg==; 31:Eax1vOsJoFKlh9X4iMaO9GmlwN9+6UAdCtreVAK1SedbhM+ntqPTHdcnUVvDHe3UcQEJ1nFNdXdjOgNoFC4p4v9tjylV1wANs/LKcXSQtSSh3ZqY+/IKxcUhppVnMj9zpVjwRFLYRnUe3M05K02MOlxNM3Lg1XVFCpPvs/DNc2Rh643JGRmHWQrslC+7CxMiv/f5ESPv6GGUSxwuVCPCWFVZdnzmIQzDY+AQaSb/H1M= X-MS-TrafficTypeDiagnostic: HE1PR0402MB2778: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0402MB2778; 20:NNO6Ygs80w3qgZ+JQSbP4b8P2KpIbSXwOTDD4ROB7Pt+X07UGoFj2+GiLWo0TMkjPaORx+Db5qRTbB7impbe9YGAfLObvesCP64NRq/hCl7hWKWJlFMmna7jznjaZY2AVtVkfR9rwZnrPgNvsnJVmX6rTlnq0JOkxTzSl5JxKvUDVq1qJTQYQ7NzRjcnPcAhj2N1S/7jhoTOo/xkyQRcyzqV+1G9zEVA5uMqSe3shL5z2rRVBr7La4Lx/wf2UbDSiuNVklmeRGt097jCAEeCdicTnCpgGnEykff/YzsjXWuEPxn/ONp81JaUDb+qVP9LC+4w0tfOzL7nMlnoGN/h79JDH/WW9u41be5BvrC5Jf/NBLM0e6rnFJoZRVnzK/34+S9GxCrf15EBE/HGEXIWDGWgDeGyVcqf6o5VPYin1pm7Ct723ObInpmvkJcvtXHhxh1VlJTutkEOcAucHDMVKmFU6OZsznxgmAL1/4P5qHxG3uBxQDFrfFe8P/RxNnQz; 4:/SBTIoLMmxduDZgGKvm81ychBFGQzuhi2jXA+OGv/fScwpEzHT857tmmN0qP2Mc73DM3ktckFuc4wtQCjrQC+gTh1HngATE7O4i8t1P4jYNQg+rySpdT78+FbPEM/S6Jxw+8BcGsFuZk3g6l4hsGEjLpgggyLZBLjcaMphZmxTkUDiZrutKWQ1+QEkDQ2J0LtecQL6V8RZN6sfsyM/u2aT0QzORbNbNKKlzM0th6yzPLGMHVdjQeDg42PKRF+gF9cUZWtXxpo61ruPj3KX6UL68UPRelcNWBbIKZ43iMRf7jNN5oaDJdTqH9uHtlOnMvK8A8rCLhBHPyha5j5Xb8wqCmyDUccbXlgsbJJd1CvHA= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(6055026)(6041310)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:HE1PR0402MB2778; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0402MB2778; X-Forefront-PRVS: 0637FCE711 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6049001)(376002)(346002)(39860400002)(396003)(39380400002)(366004)(199004)(189003)(64126003)(6246003)(478600001)(106356001)(66066001)(6486002)(65806001)(65956001)(6116002)(3846002)(50466002)(486006)(81166006)(36756003)(446003)(68736007)(8676002)(16576012)(65826007)(2486003)(2906002)(52146003)(55236004)(52116002)(77096007)(956004)(76176011)(58126008)(316002)(23676004)(59450400001)(6666003)(2616005)(476003)(230700001)(229853002)(53936002)(8936002)(31686004)(105586002)(5009440100003)(25786009)(86362001)(386003)(5660300001)(31696002)(11346002)(47776003)(81156014)(6916009)(186003)(7736002)(26005)(4326008)(67846002)(16526019)(97736004)(305945005)(110426004); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0402MB2778; H:[10.232.14.39]; 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: =?utf-8?B?MTtIRTFQUjA0MDJNQjI3Nzg7MjM6K25WNERwMDR5TWp4RnZTV2pXekt0UzdP?= =?utf-8?B?d1c0SCtkVGIyRVJId0tkcDFTTW9BQzcrWDJhek44YVQ0R3FRbjRHYjFxYzFr?= =?utf-8?B?QWw1ZFgvNHJIVlAyWnpsSDNlUUVwVGtPV1VjaVZxQ0czSWFrLzJ4dCtUTSsr?= =?utf-8?B?VEJ1Vk5Ld25qRWNYL0hXZmxMbDB3dkZJeVdVMVJjUGF5anU0RkZpMXpYRUV4?= =?utf-8?B?eGI4WGVPSkk4R2xlNld3WXlXU1BQdzl5Z1NTU1g0VEp6VzlrSGFPSTNp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X-Microsoft-Antispam-Message-Info: +ABHEYR/SlRkCJ8XhSSRW/DhRt+jhBzhFHY+9qDWWP19Tn1l7EsbXaNN/b0VEeLm9zvtq75apbo1vtHUIVCZY6lsqYoAtJfxbM8pLpO97/KfHEL/elJq6V7yoRQhXrLcpxNPWboUvYWlrATyJuoZf/pJzhoMZBy3InSVUN6zczAxh4q/zdxyb06yLOg5CyrH X-Microsoft-Exchange-Diagnostics: 1; HE1PR0402MB2778; 6:Pw7pS3AHozvu5Aouv5mxW9cTAIndlH1rnaZLPKxbYVD1FslH2GqNf8+0t0ZNlb1OUaGoMsmQwz3GkS99kD4LvSWn0nSJK2fR12hl9IbKzrY0EFQwChnuW0KxyBWlcy7d44zrEi04/swBVWA5Na/g46gfs8ukW47yCeP0ijBw7V81hfjBRMvBLHLs/iXzwHteVO2VZoW/Cm8qK8f+LzPO5f8WLLm7a7jcZovqVgUSX7gKgbtGtmoYmTTFo8u78XY2Mp3M6ETBVRivp1bqOFyaD8geUSXoUN8XM/VH8/ngeUPPEdTReMyItua1x+DJaE/fO3eE5Upcl9xTodrxInxdUCr0wtC63ZWLLKhzogFDP+NJTeXSL/x1EkaiDJcXaQzrZX6gLc7gEIoFvzjOb0l1eMoRcXxyRaej3B5jeWuzwjxO6ZWLtWSiFsEs5H1j2VdHewS2C8qL/FQoYg5HEtBuXg==; 5:+Iobjch0l47JFRhIMYbGJeAnuC8MsLF2orSeabqWBV/IvJo4xpCefQ+enQuKhhio4yg3wQ5cTw9Gc7XTe8ri96fBEgcjssKeg04qmKSwEcpEEjBemxwBXYTUocEKJ4F9ICpZt/x1i0u3vs4Fn7o6nbiU/3v50vnmcqhUy5WskVo=; 24:/5UYw9fOKFW4ADl8JBjw9v5iKXofXuY8MWhHTDlufBZIWHpdUFEUyaj+xMJ/MNVnu71X6HfdG+menxMvSpqypgxikEt+Nq/eOa2kSqAZiAg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0402MB2778; 7:ER7wHSogV5TyCJAtqJQZ/n4Ql7JAkf7gOz2FoEzzgXCc947bOG8SQM9InB8qTPIQPJ7SBHtjLED2OXHOgQ9oaW3tcIgHzmb6jOHusAzSY9dYykc0+0viw7oMNqjFLl7UwdYzaqk07SaNlDexaPPwvuLfZ+LdciW8hkbB5PUpe7BAdOhcGkX8Y0XNcVBIaajmwGSmaCSvwwvqs/464Nogg2QOnqKFQgKZT5Xea5DC0Ch7bwVxCNxqnbpYjnN9ljkW X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2018 09:46:18.6735 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 45054b27-f618-4bd1-51dd-08d59dfebf67 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0402MB2778 Subject: Re: [dpdk-dev] [PATCH v4 66/70] bus/fslmc: enable support for mem event callbacks for vfio 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: Mon, 09 Apr 2018 09:46:21 -0000 Hi Anatoly, On Monday 09 April 2018 01:48 AM, Anatoly Burakov wrote: > VFIO needs to map and unmap segments for DMA whenever they > become available or unavailable, so register a callback for > memory events, and provide map/unmap functions. > > Signed-off-by: Shreyansh Jain > Signed-off-by: Anatoly Burakov > --- > drivers/bus/fslmc/fslmc_vfio.c | 150 +++++++++++++++++++++++++++++++++++++---- > 1 file changed, 136 insertions(+), 14 deletions(-) > > diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c > index db3eb61..dfdd2bc 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" > @@ -188,11 +189,57 @@ 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 virt_addr; > + rte_iova_t iova_addr; > + int ret; > + > + msl = rte_mem_virt2memseg_list(addr); > + > + while (cur_len < len) { > + const void *va = RTE_PTR_ADD(addr, cur_len); > + > + ms = rte_mem_virt2memseg(va, msl); > + iova_addr = ms->iova; > + virt_addr = ms->addr_64; > + map_len = ms->len; > + > + DPAA2_BUS_DEBUG("Calling with type=%d, va=%p, virt_addr=0x%" PRIx64 ", iova=0x%" PRIx64 ", map_len=%zu\n", I would like to correct this message (80char + rewording) - What do you suggest? Should I send a new patch to you or just convey what should be changed? > + 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) { > + DPAA2_BUS_ERR("DMA Mapping/Unmapping failed. Map=%d, addr=%p, len=%zu, err:(%d)", > + type, va, map_len, ret); Same as above. 80 Char issue. > + return; > + } > + > + cur_len += map_len; > + } > + > + if (type == RTE_MEM_EVENT_ALLOC) > + DPAA2_BUS_DEBUG("Total Mapped: addr=%p, len=%zu\n", > + addr, len); > + else > + DPAA2_BUS_DEBUG("Total Unmapped: addr=%p, len=%zu\n", > + addr, len); > +} > + > static int > -fslmc_vfio_map(const struct rte_memseg_list *msl __rte_unused, > - const struct rte_memseg *ms, void *arg) > +fslmc_map_dma(uint64_t vaddr, rte_iova_t iovaddr __rte_unused, size_t len) > { > - 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), > @@ -200,10 +247,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 > @@ -216,30 +264,99 @@ fslmc_vfio_map(const struct rte_memseg_list *msl __rte_unused, > return -1; > } > > - DPAA2_BUS_DEBUG("-->Initial SHM Virtual ADDR %llX", > - dma_map.vaddr); > - DPAA2_BUS_DEBUG("-----> DMA size 0x%llX", dma_map.size); > - ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA, > - &dma_map); > + DPAA2_BUS_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) { > DPAA2_BUS_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) { > + DPAA2_BUS_ERR("Container is not connected "); > + return -1; > + } > + > + DPAA2_BUS_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) { > + DPAA2_BUS_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) > + DPAA2_BUS_ERR("Unable to VFIO map (addr=%p, len=%zu)\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; > + > + /* Lock before parsing and registering callback to memory subsystem */ > + rte_rwlock_read_lock(mem_lock); > > - if (rte_memseg_walk(fslmc_vfio_map, &i) < 0) > + if (rte_memseg_walk(fslmc_dmamap_seg, &i) < 0) { > + rte_rwlock_read_unlock(mem_lock); > return -1; > + } > + > + ret = rte_mem_event_callback_register("fslmc_memevent_clb", > + fslmc_memevent_cb); > + if (ret && rte_errno == ENOTSUP) > + DPAA2_BUS_DEBUG("Memory event callbacks not supported"); > + else if (ret) > + DPAA2_BUS_DEBUG("Unable to install memory handler"); > + else > + DPAA2_BUS_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? > + */ And this as well - if call backs are not going to appear in case of legacy, this needs to be removed. let me know how do you want to take these changes. > DPAA2_BUS_ERR("No Segments found for VFIO Mapping"); > + rte_rwlock_read_unlock(mem_lock); > return -1; > } > DPAA2_BUS_DEBUG("Total %d segments found.", i); > @@ -250,6 +367,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); > + > return 0; > } > >