From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20057.outbound.protection.outlook.com [40.107.2.57]) by dpdk.org (Postfix) with ESMTP id 5BAC31B1F0 for ; Wed, 13 Feb 2019 20:52:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iyIrR+utQhFSyfVuDNpb6O84TulIWC5Mc3YMV76wKSQ=; b=fmuArJwuroWsbHRW3x/N4mYPHYLzzL2SQGK1N8BE6EGp9QCfVdeoDEtJgKnAJePZmaOi6xl3y8iYruBvuPynb4t+h+oF3zHb1zkbI3k2iiJrJh/nPk/LcBGet9UgZdbpgzQ/YxeqS0to2tRO10nQ16tMoJv7pB0Y3M9Rnt/A1B4= Received: from AM0PR0502MB3795.eurprd05.prod.outlook.com (52.133.47.29) by AM0PR0502MB3746.eurprd05.prod.outlook.com (52.133.47.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1622.16; Wed, 13 Feb 2019 19:52:01 +0000 Received: from AM0PR0502MB3795.eurprd05.prod.outlook.com ([fe80::386e:f86:50bf:31be]) by AM0PR0502MB3795.eurprd05.prod.outlook.com ([fe80::386e:f86:50bf:31be%5]) with mapi id 15.20.1622.016; Wed, 13 Feb 2019 19:52:01 +0000 From: Shahaf Shuler To: =?iso-8859-1?Q?Ga=EBtan_Rivet?= CC: "anatoly.burakov@intel.com" , Yongseok Koh , Thomas Monjalon , "ferruh.yigit@intel.com" , "nhorman@tuxdriver.com" , "dev@dpdk.org" Thread-Topic: [PATCH 2/6] vfio: don't fail to DMA map if memory is already mapped Thread-Index: AQHUw4LFEGIPHxMZIE64iM8yEa4YxqXeItNw Date: Wed, 13 Feb 2019 19:52:01 +0000 Message-ID: References: <20190213095846.qn55sx5smlgvxo6h@bidouze.vm.6wind.com> In-Reply-To: <20190213095846.qn55sx5smlgvxo6h@bidouze.vm.6wind.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=shahafs@mellanox.com; x-originating-ip: [31.154.10.105] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 07d33234-e370-430f-3800-08d691ecb867 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600110)(711020)(4605077)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:AM0PR0502MB3746; x-ms-traffictypediagnostic: AM0PR0502MB3746: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1; AM0PR0502MB3746; 23:22S1te5chUctFdGhgSljMNVByJ9a2fPeoiH2X?= =?iso-8859-1?Q?o71bFTFDW08I2mj9yjRXelXzj8iahO6Z41A89yHPKiQXrkz/cP3frkeJGe?= =?iso-8859-1?Q?ceOCxvIlfnj+FKHR+gM0HiiuwYqgg6RZMpOR9uJs0WemQGG5z+Da5ONNEQ?= =?iso-8859-1?Q?eJ4CqJPLuRYvAxu3wzjCXwlhLUb7uKcLlswR0aGsGFW7SpGXmLC2MX1piY?= =?iso-8859-1?Q?tshiW0aQlYkSS3YvO5tTMaC1+jnuCqwXDkSbbJsCNBVO12sI1GwOxhFJzR?= =?iso-8859-1?Q?mUr2UrPBsWSOg1WSIfrCVkiZ88imYpl6Rpmu7Flvz/5HEHb5ReyB+0BMdr?= =?iso-8859-1?Q?piQfC8p9eEIzIZMAIeIE2W8/o53U7o8TcHgfNIo/QE2rE4MM1npwgjwPrD?= =?iso-8859-1?Q?wz26BCIchvFu30vzsPqPgTD9yg2ZAFN5Cu7qhJ4KqCFu08qLUTQ0Bsj0Wt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dZ9aa4ipiWelqOKJKWw3Q=3D=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 094700CA91 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(346002)(136003)(396003)(376002)(366004)(39860400002)(189003)(199004)(54906003)(53936002)(102836004)(6246003)(33656002)(66066001)(229853002)(305945005)(7736002)(6506007)(99286004)(74316002)(9686003)(7696005)(76176011)(105586002)(106356001)(25786009)(186003)(26005)(8936002)(6916009)(316002)(81156014)(81166006)(8676002)(11346002)(4326008)(446003)(476003)(486006)(71200400001)(71190400001)(14444005)(256004)(2906002)(68736007)(478600001)(66574012)(6116002)(55016002)(97736004)(86362001)(3846002)(14454004)(6436002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3746; H:AM0PR0502MB3795.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: Luht8qPsE+YxP0lkxAq5Smq6POkmO+i4fJb0mAFqZPpb0vcKFthrgJZQCiLsA/pqrbnxABVLpxcJQ1fkStGIioqKmcTXlY9xhk6CLaCgcv2CrBH0F0QSYe749ptRVqjm1hxodRqHdmWj8QwpRc3i/Zlz22o/ZJhZw7xpmWZodXF0Qei1jqZ9f+YvsgC7VIl/l6dZ7oDPHNdxmf9B9V3VUG20/R4YRnayYJ7YZ7YzmVDrDEHNatrCrqcc8tlfDRnpSWaTcDS+oDW/0KrnCh9nJLhhusO9xuhYhvkWFp/fJ2ZPz95j5f2gu0m1ayzXTmVC6DLjrT1udJRM5oI0AP8RZgWHabu+jVr67ARjxM5pP8DxMzDmmYStBMvVo5d4+Oe0dakFKcuXVjOsKZUadSDiqmBIMNvP/S27DmAv0esICwE= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07d33234-e370-430f-3800-08d691ecb867 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Feb 2019 19:52:01.0594 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0502MB3746 Subject: Re: [dpdk-dev] [PATCH 2/6] vfio: don't fail to DMA map if memory is already mapped 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: Wed, 13 Feb 2019 19:52:03 -0000 Wednesday, February 13, 2019 11:59 AM, Ga=EBtan RiveT: > Subject: Re: [PATCH 2/6] vfio: don't fail to DMA map if memory is already > mapped >=20 > On Wed, Feb 13, 2019 at 11:10:22AM +0200, Shahaf Shuler wrote: > > Currently vfio DMA map function will fail in case the same memory > > segment is mapped twice. > > > > This is too strict, as this is not an error to map the same memory > > twice. > > > > Instead, use the kernel return value to detect such state and have the > > DMA function to return as successful. > > > > For type1 mapping the kernel driver first implementation returns EBUSY > > and since kernel 3.11 returns EEXISTS. For spapr mapping EBUSY is > > returned since kernel 4.10. > > >=20 > What is the earliest version supported by DPDK? I thought 3.10 was droppe= d, > should we care about the 3.11 return value? According to DPDK doc it is 3.16, however compatibility for Centos/RH 7 sho= uld be kept. I have looked on Centos 7 source code (linux-3.10.0-957.5.1.el7), it uses E= EXIST for the vfio type 1.=20 So I think, I can drop the EBUSY error check and leave only the EEXIST one.= =20 >=20 > > Signed-off-by: Shahaf Shuler > > --- > > lib/librte_eal/linuxapp/eal/eal_vfio.c | 12 ++++++++++-- > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c > > b/lib/librte_eal/linuxapp/eal/eal_vfio.c > > index 48ca9465d4..2a2d655b37 100644 > > --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c > > +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c > > @@ -1263,7 +1263,11 @@ vfio_type1_dma_mem_map(int > vfio_container_fd, uint64_t vaddr, uint64_t iova, > > VFIO_DMA_MAP_FLAG_WRITE; > > > > ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, > &dma_map); > > - if (ret) { > > + /** > > + * In case the mapping was already done EEXIST will be > > + * returned from kernel. > > + */ > > + if ((ret !=3D -EEXIST) && (ret !=3D -EBUSY)) { >=20 > Won't a ret =3D=3D 0 trigger the error then? Yes good catch.=20 >=20 > It seems ifdef about linux versions are not common in vfio code, but bar = that > I think it would be cleaner to restrict the acceptable error to it. >=20 > When a version will be dropped it will be much easier to remove the relat= ed > code instead of digging in the commit logs, and leaving both would not be > clean. Relaying on kernel version is not safe enough. Many distro backport to thei= r kernel w/o updating its version. This will lead to unexpected behavior.=20 >=20 > > RTE_LOG(ERR, EAL, " cannot set up DMA remapping, > error %i (%s)\n", > > errno, strerror(errno)); > > return -1; > > @@ -1324,7 +1328,11 @@ vfio_spapr_dma_do_map(int vfio_container_fd, > uint64_t vaddr, uint64_t iova, > > VFIO_DMA_MAP_FLAG_WRITE; > > > > ret =3D ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, > &dma_map); > > - if (ret) { > > + /** > > + * In case the mapping was already done EBUSY will be > > + * returned from kernel. > > + */ > > + if (ret !=3D -EBUSY) { > > RTE_LOG(ERR, EAL, " cannot set up DMA remapping, > error %i (%s)\n", > > errno, strerror(errno)); > > return -1; > > -- > > 2.12.0 > > >=20 > -- > Ga=EBtan Rivet > 6WIND