From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 34A16FA5A for ; Mon, 6 Mar 2017 17:46:31 +0100 (CET) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2017 08:46:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,254,1484035200"; d="scan'208";a="72806077" Received: from irsmsx153.ger.corp.intel.com ([163.33.192.75]) by fmsmga005.fm.intel.com with ESMTP; 06 Mar 2017 08:46:29 -0800 Received: from irsmsx112.ger.corp.intel.com (10.108.20.5) by IRSMSX153.ger.corp.intel.com (163.33.192.75) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 6 Mar 2017 16:46:28 +0000 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.44]) by irsmsx112.ger.corp.intel.com ([169.254.1.175]) with mapi id 14.03.0248.002; Mon, 6 Mar 2017 16:46:28 +0000 From: "Burakov, Anatoly" To: Gowrishankar , "dev@dpdk.org" CC: Chao Zhu , Thomas Monjalon Thread-Topic: [PATCH v3] eal: sPAPR IOMMU support in pci probing for vfio-pci in ppc64le Thread-Index: AQHSlosQumthfKKtgEuYqAhVq90rsaGIBRFg Date: Mon, 6 Mar 2017 16:46:27 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZTNhZmViNjEtNmIzYi00OTJmLWEzYzItZGE5NDE4OTI4NGZjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6ImVidis5VWdUT0ZvVGl6NFJGR0F6cUVXY2N3YWtrK2hrVG5KNkg4a3BKSVU9In0= x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: Mon, 06 Mar 2017 16:46:32 -0000 > From: Gowrishankar [mailto:gowrishankar.m@linux.vnet.ibm.com] > Sent: Monday, March 6, 2017 3:04 PM > To: dev@dpdk.org > Cc: Chao Zhu ; Burakov, Anatoly > ; 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 >=20 > =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 The commit message will probably need to be edited to not include the chang= e notes (v2-v3 stuff), but as for commit contents, Acked-by: Anatoly Burakov