From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by dpdk.org (Postfix) with ESMTP id 1D9E0201 for ; Thu, 9 Mar 2017 02:38:42 +0100 (CET) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v291Xcx7079990 for ; Wed, 8 Mar 2017 20:38:42 -0500 Received: from e28smtp07.in.ibm.com (e28smtp07.in.ibm.com [125.16.236.7]) by mx0a-001b2d01.pphosted.com with ESMTP id 292pwm180k-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 08 Mar 2017 20:38:41 -0500 Received: from localhost by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 9 Mar 2017 07:08:38 +0530 Received: from d28relay02.in.ibm.com (9.184.220.59) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 9 Mar 2017 07:08:38 +0530 Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay02.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v291cbvO14942434 for ; Thu, 9 Mar 2017 07:08:37 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v291ca6Q006478 for ; Thu, 9 Mar 2017 07:08:37 +0530 Received: from ADMINIB2M8Q79C ([9.186.50.121]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v291cZDo006426; Thu, 9 Mar 2017 07:08:35 +0530 From: "Chao Zhu" To: "'Gowrishankar'" , Cc: "'Anatoly Burakov'" , "'Thomas Monjalon'" References: In-Reply-To: Date: Thu, 9 Mar 2017 09:38:38 +0800 MIME-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQEl7vohGnI8L0fPv+Ow0/Izc6KmFwGhFz5UotgE9vA= Content-Language: zh-cn X-TM-AS-MML: disable x-cbid: 17030901-0024-0000-0000-000003AF9338 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17030901-0025-0000-0000-0000112CEE6D Message-Id: <000f01d29875$e142e960$a3c8bc20$@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-08_19:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703090012 Subject: Re: [dpdk-dev] [PATCH v3] eal: sPAPR IOMMU support in pci probing for vfio-pci in ppc64le 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, 09 Mar 2017 01:38:43 -0000 > From: Gowrishankar [mailto:gowrishankar.m@linux.vnet.ibm.com] > Sent: 2017=C4=EA3=D4=C26=C8=D5 23:04 > To: dev@dpdk.org > Cc: Chao Zhu ; Anatoly Burakov > ; Thomas Monjalon > ; Gowrishankar Muthukrishnan > > Subject: [PATCH v3] eal: sPAPR IOMMU support in pci probing for = vfio-pci in > ppc64le >=20 > From: Gowrishankar Muthukrishnan >=20 > Below changes adds pci probing support for vfio-pci devices in power8. >=20 > v3 - better validation for kernel not implementing few iocts called > v2 - kernel version checked and doc updated >=20 > Signed-off-by: Gowrishankar Muthukrishnan > > --- > doc/guides/rel_notes/release_17_05.rst | 4 ++ > lib/librte_eal/linuxapp/eal/eal_vfio.c | 90 > ++++++++++++++++++++++++++++++++++ > lib/librte_eal/linuxapp/eal/eal_vfio.h | 25 ++++++++++ > 3 files changed, 119 insertions(+) >=20 > diff --git a/doc/guides/rel_notes/release_17_05.rst > b/doc/guides/rel_notes/release_17_05.rst > index e25ea9f..4b90036 100644 > --- a/doc/guides/rel_notes/release_17_05.rst > +++ b/doc/guides/rel_notes/release_17_05.rst > @@ -42,6 +42,10 @@ New Features > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D >=20 >=20 > +* **Added powerpc support in pci probing for vfio-pci devices.** > + > + sPAPR IOMMU based pci probing enabled for vfio-pci devices. > + > Resolved Issues > --------------- >=20 > diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c > b/lib/librte_eal/linuxapp/eal/eal_vfio.c > index 702f7a2..9377a66 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c > @@ -50,12 +50,15 @@ > static struct vfio_config vfio_cfg; >=20 > static int vfio_type1_dma_map(int); > +static int vfio_spapr_dma_map(int); > static int vfio_noiommu_dma_map(int); >=20 > /* IOMMU types we support */ > static const struct vfio_iommu_type iommu_types[] =3D { > /* x86 IOMMU, otherwise known as type 1 */ > { RTE_VFIO_TYPE1, "Type 1", &vfio_type1_dma_map}, > + /* ppc64 IOMMU, otherwise known as spapr */ > + { RTE_VFIO_SPAPR, "sPAPR", &vfio_spapr_dma_map}, > /* IOMMU-less mode */ > { RTE_VFIO_NOIOMMU, "No-IOMMU", &vfio_noiommu_dma_map}, }; > @@ -540,6 +543,93 @@ int vfio_setup_device(const char *sysfs_base, = const > char *dev_addr, } >=20 > static int > +vfio_spapr_dma_map(int vfio_container_fd) { > + const struct rte_memseg *ms =3D rte_eal_get_physmem_layout(); > + int i, ret; > + > + struct vfio_iommu_spapr_register_memory reg =3D { > + .argsz =3D sizeof(reg), > + .flags =3D 0 > + }; > + struct vfio_iommu_spapr_tce_info info =3D { > + .argsz =3D sizeof(info), > + }; > + struct vfio_iommu_spapr_tce_create create =3D { > + .argsz =3D sizeof(create), > + }; > + struct vfio_iommu_spapr_tce_remove remove =3D { > + .argsz =3D sizeof(remove), > + }; > + > + /* query spapr iommu info */ > + ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, > &info); > + if (ret) { > + RTE_LOG(ERR, EAL, " cannot get iommu info, " > + "error %i (%s)\n", errno, strerror(errno)); > + return -1; > + } > + > + /* remove default DMA of 32 bit window */ > + remove.start_addr =3D info.dma32_window_start; > + ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_REMOVE, > &remove); > + if (ret) { > + RTE_LOG(ERR, EAL, " cannot remove default DMA window, " > + "error %i (%s)\n", errno, strerror(errno)); > + return -1; > + } > + > + /* calculate window size based on number of hugepages configured */ > + create.window_size =3D rte_eal_get_physmem_size(); > + create.page_shift =3D __builtin_ctzll(ms->hugepage_sz); > + create.levels =3D 2; > + > + ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_CREATE, > &create); > + if (ret) { > + RTE_LOG(ERR, EAL, " cannot create new DMA window, " > + "error %i (%s)\n", errno, strerror(errno)); > + return -1; > + } > + > + /* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */ > + for (i =3D 0; i < RTE_MAX_MEMSEG; i++) { > + struct vfio_iommu_type1_dma_map dma_map; > + > + if (ms[i].addr =3D=3D NULL) > + break; > + > + reg.vaddr =3D (uintptr_t) ms[i].addr; > + reg.size =3D ms[i].len; > + ret =3D ioctl(vfio_container_fd, > + VFIO_IOMMU_SPAPR_REGISTER_MEMORY, ®); > + if (ret) { > + RTE_LOG(ERR, EAL, " cannot register vaddr for IOMMU, " > + "error %i (%s)\n", errno, strerror(errno)); > + return -1; > + } > + > + memset(&dma_map, 0, sizeof(dma_map)); > + dma_map.argsz =3D sizeof(struct vfio_iommu_type1_dma_map); > + dma_map.vaddr =3D ms[i].addr_64; > + dma_map.size =3D ms[i].len; > + dma_map.iova =3D ms[i].phys_addr; > + dma_map.flags =3D VFIO_DMA_MAP_FLAG_READ | > + VFIO_DMA_MAP_FLAG_WRITE; > + > + ret =3D 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; > + } > + > + } > + > + return 0; > +} > + > +static int > vfio_noiommu_dma_map(int __rte_unused vfio_container_fd) { > /* No-IOMMU mode does not need DMA mapping */ diff --git > a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h > index 29f7f3e..ac31a4f 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h > +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h > @@ -54,6 +54,31 @@ >=20 > #define RTE_VFIO_TYPE1 VFIO_TYPE1_IOMMU >=20 > +#ifndef VFIO_SPAPR_TCE_v2_IOMMU > +#define RTE_VFIO_SPAPR 7 > +#define VFIO_IOMMU_SPAPR_REGISTER_MEMORY _IO(VFIO_TYPE, > VFIO_BASE + 17) > +#define VFIO_IOMMU_SPAPR_TCE_CREATE _IO(VFIO_TYPE, VFIO_BASE + 19) > +#define VFIO_IOMMU_SPAPR_TCE_REMOVE _IO(VFIO_TYPE, VFIO_BASE + > 20) > +struct vfio_iommu_spapr_register_memory { > + uint32_t argsz; > + uint32_t flags; > + uint64_t vaddr; > + uint64_t size; > +}; > +struct vfio_iommu_spapr_tce_create { > + uint32_t argsz; > + uint32_t page_shift; > + uint64_t window_size; > + uint32_t levels; > +}; > +struct vfio_iommu_spapr_tce_remove { > + uint32_t argsz; > + uint64_t start_addr; > +}; > +#else > +#define RTE_VFIO_SPAPR VFIO_SPAPR_TCE_v2_IOMMU #endif > + > #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) #define > RTE_VFIO_NOIOMMU 8 #else > -- > 1.9.1 Acked-by: Chao Zhu