From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by dpdk.org (Postfix) with ESMTP id 2B29D3772 for ; Fri, 30 Mar 2018 11:42:18 +0200 (CEST) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2U9d4s4071937 for ; Fri, 30 Mar 2018 05:42:18 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0b-001b2d01.pphosted.com with ESMTP id 2h1j6s1ftf-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Fri, 30 Mar 2018 05:42:17 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 30 Mar 2018 10:42:15 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 30 Mar 2018 10:42:12 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2U9gCRK54919350; Fri, 30 Mar 2018 09:42:12 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38994AE04D; Fri, 30 Mar 2018 10:32:23 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2B891AE058; Fri, 30 Mar 2018 10:32:22 +0100 (BST) Received: from chozha.in.ibm.com (unknown [9.124.35.170]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 30 Mar 2018 10:32:21 +0100 (BST) From: Gowrishankar To: Anatoly Burakov Cc: Jonas Pfefferle1 , Chao Zhu , dev@dpdk.org, Gowrishankar Muthukrishnan Date: Fri, 30 Mar 2018 15:12:10 +0530 X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-TM-AS-GCONF: 00 x-cbid: 18033009-0012-0000-0000-000005C52E8D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18033009-0013-0000-0000-00001941303D Message-Id: <274801adfd9b371a15a9fa3b7c6d21716809a0b7.1522402857.git.gowrishankar.m@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-30_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803300099 Subject: [dpdk-dev] [PATCH v2 24/41] vfio: allow to map other memory regions 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: Fri, 30 Mar 2018 09:42:19 -0000 From: Gowrishankar Muthukrishnan Below patch adds powerpc arch specific changes. Signed-off-by: Gowrishankar Muthukrishnan --- lib/librte_eal/linuxapp/eal/eal_vfio.c | 63 +++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index 4e9e296..063982c 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -24,6 +24,7 @@ static int vfio_type1_dma_map(int); static int vfio_type1_dma_mem_map(int, uint64_t, uint64_t, uint64_t, int); static int vfio_spapr_dma_map(int); +static int vfio_spapr_dma_mem_map(int, uint64_t, uint64_t, uint64_t, int); static int vfio_noiommu_dma_map(int); static int vfio_noiommu_dma_mem_map(int, uint64_t, uint64_t, uint64_t, int); @@ -41,8 +42,7 @@ .type_id = RTE_VFIO_SPAPR, .name = "sPAPR", .dma_map_func = &vfio_spapr_dma_map, - .dma_user_map_func = NULL - // TODO: work with PPC64 people on enabling this, window size! + .dma_user_map_func = &vfio_spapr_dma_mem_map }, /* IOMMU-less mode */ { @@ -801,10 +801,51 @@ struct spapr_create_window_walk_param { } static int +vfio_spapr_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, + uint64_t len, int do_map) +{ + struct vfio_iommu_type1_dma_map dma_map; + struct vfio_iommu_type1_dma_unmap dma_unmap; + int ret; + + if (do_map != 0) { + memset(&dma_map, 0, sizeof(dma_map)); + dma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map); + dma_map.vaddr = vaddr; + dma_map.size = len; + dma_map.iova = iova; + dma_map.flags = VFIO_DMA_MAP_FLAG_READ | + VFIO_DMA_MAP_FLAG_WRITE; + + ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map); + if (ret) { + RTE_LOG(ERR, EAL, " cannot set up DMA remapping, error %i (%s)\n", + errno, strerror(errno)); + return -1; + } + + } else { + memset(&dma_unmap, 0, sizeof(dma_unmap)); + dma_unmap.argsz = sizeof(struct vfio_iommu_type1_dma_unmap); + dma_unmap.size = len; + dma_unmap.iova = iova; + + ret = ioctl(vfio_container_fd, VFIO_IOMMU_UNMAP_DMA, + &dma_unmap); + if (ret) { + RTE_LOG(ERR, EAL, " cannot clear DMA remapping, error %i (%s)\n", + errno, strerror(errno)); + return -1; + } + } + + return 0; +} + +static int vfio_spapr_dma_map_walk(const struct rte_memseg_list *msl __rte_unused, const struct rte_memseg *ms, void *arg) { - struct vfio_iommu_type1_dma_map dma_map; struct vfio_iommu_spapr_register_memory reg = { .argsz = sizeof(reg), .flags = 0 @@ -828,17 +869,8 @@ struct spapr_create_window_walk_param { return -1; } - memset(&dma_map, 0, sizeof(dma_map)); - dma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map); - dma_map.vaddr = addr; - dma_map.size = len; - dma_map.iova = hw_addr; - dma_map.flags = VFIO_DMA_MAP_FLAG_READ | - VFIO_DMA_MAP_FLAG_WRITE; - - ret = ioctl(*vfio_container_fd, VFIO_IOMMU_MAP_DMA, - &dma_map); - + ret = vfio_spapr_dma_mem_map(*vfio_container_fd, addr, + hw_addr, len, 1); if (ret) { RTE_LOG(ERR, EAL, " cannot set up DMA remapping, error %i (%s)\n", errno, strerror(errno)); @@ -852,7 +884,6 @@ struct spapr_create_window_walk_param { vfio_spapr_dma_map(int vfio_container_fd) { int ret; - uint64_t hugepage_sz = 0; struct spapr_create_window_walk_param wa; struct vfio_iommu_spapr_tce_info info = { @@ -890,7 +921,7 @@ struct spapr_create_window_walk_param { /* sPAPR requires window size to be a power of 2 */ create.window_size = rte_align64pow2(create.window_size); - create.page_shift = __builtin_ctzll(hugepage_sz); + create.page_shift = __builtin_ctzll(wa.hugepage_sz); create.levels = 1; ret = ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create); -- 1.9.1