From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <anatoly.burakov@intel.com>
Received: from mga03.intel.com (mga03.intel.com [134.134.136.65])
 by dpdk.org (Postfix) with ESMTP id 543282BC9
 for <dev@dpdk.org>; Tue,  8 Aug 2017 14:06:16 +0200 (CEST)
Received: from fmsmga005.fm.intel.com ([10.253.24.32])
 by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 08 Aug 2017 05:06:15 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.41,343,1498546800"; d="scan'208";a="137037736"
Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155])
 by fmsmga005.fm.intel.com with ESMTP; 08 Aug 2017 05:06:14 -0700
Received: from irsmsx109.ger.corp.intel.com ([169.254.13.187]) by
 IRSMSX102.ger.corp.intel.com ([169.254.2.211]) with mapi id 14.03.0319.002;
 Tue, 8 Aug 2017 13:06:14 +0100
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Jonas Pfefferle <jpf@zurich.ibm.com>
CC: "dev@dpdk.org" <dev@dpdk.org>, "aik@ozlabs.ru" <aik@ozlabs.ru>
Thread-Topic: [PATCH v4] vfio: fix sPAPR IOMMU DMA window size
Thread-Index: AQHTEDfpou/Idb8Ux0CFLxpHKM1qxKJ6XO6Q
Date: Tue, 8 Aug 2017 12:06:12 +0000
Message-ID: <C6ECDF3AB251BE4894318F4E4512369782271CF9@IRSMSX109.ger.corp.intel.com>
References: <1502191002-13988-1-git-send-email-jpf@zurich.ibm.com>
In-Reply-To: <1502191002-13988-1-git-send-email-jpf@zurich.ibm.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-ctpclassification: CTP_IC
x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNmY5YWY1YjItZjgxNS00NmVhLWJmMTQtM2ZkZGJjYWUxMzVhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6InRqQkNNaThSUEgzSkpJN1ZLVlZMNHFQWTNra3c1QTUrcjh4VTBzbzlTT289In0=
dlp-product: dlpe-windows
dlp-version: 11.0.0.116
dlp-reaction: no-action
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 v4] vfio: fix sPAPR IOMMU DMA window size
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 08 Aug 2017 12:06:17 -0000

> From: Jonas Pfefferle [mailto:jpf@zurich.ibm.com]
> Sent: Tuesday, August 8, 2017 12:17 PM
> To: Burakov, Anatoly <anatoly.burakov@intel.com>
> Cc: dev@dpdk.org; aik@ozlabs.ru; Jonas Pfefferle <jpf@zurich.ibm.com>
> Subject: [PATCH v4] vfio: fix sPAPR IOMMU DMA window size
>=20
> DMA window size needs to be big enough to span all memory segment's
> physical addresses. We do not need multiple levels of IOMMU tables as we
> already span ~70TB of physical memory with 16MB hugepages.
>=20
> Signed-off-by: Jonas Pfefferle <jpf@zurich.ibm.com>
> ---
> v2:
> * roundup to next power 2 function without loop.
>=20
> v3:
> * Replace roundup_next_pow2 with rte_align64pow2
>=20
> v4:
> * do not assume ordering of physical addresses of memsegs
>=20
>  lib/librte_eal/linuxapp/eal/eal_vfio.c | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
>=20
> diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c
> b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> index 946df7e..7d5d61d 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> @@ -759,10 +759,19 @@ vfio_spapr_dma_map(int vfio_container_fd)
>  		return -1;
>  	}
>=20
> -	/* calculate window size based on number of hugepages configured
> */
> -	create.window_size =3D rte_eal_get_physmem_size();
> +	/* create DMA window from 0 to max(phys_addr + len) */
> +	for (i =3D 0; i < RTE_MAX_MEMSEG; i++) {
> +		if (ms[i].addr =3D=3D NULL)
> +			break;
> +
> +		create.window_size =3D RTE_MAX(create.window_size,
> +				ms[i].phys_addr + ms[i].len);
> +	}
> +
> +	/* sPAPR requires window size to be a power of 2 */
> +	create.window_size =3D rte_align64pow2(create.window_size);
>  	create.page_shift =3D __builtin_ctzll(ms->hugepage_sz);
> -	create.levels =3D 2;
> +	create.levels =3D 1;
>=20
>  	ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_CREATE,
> &create);
>  	if (ret) {
> @@ -771,6 +780,11 @@ vfio_spapr_dma_map(int vfio_container_fd)
>  		return -1;
>  	}
>=20
> +	if (create.start_addr !=3D 0) {
> +		RTE_LOG(ERR, EAL, "  DMA window start address !=3D 0\n");
> +		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;
> --
> 2.7.4

Acked by: Anatoly Burakov <anatoly.burakov@intel.com>

Thanks,
Anatoly