From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4D7A2A0528; Sat, 11 Jul 2020 05:27:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F32311DA8F; Sat, 11 Jul 2020 05:27:32 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 510221D9E7 for ; Sat, 11 Jul 2020 05:27:31 +0200 (CEST) IronPort-SDR: 4yLLQzjiJZWHWrdW6vg1j9pvx+pMfFWSAPTIY6sXHEcLU/j2YgKzGmS/nBeXgj3aW8M8WXLY5k vE3eEr+qCwsQ== X-IronPort-AV: E=McAfee;i="6000,8403,9678"; a="128399072" X-IronPort-AV: E=Sophos;i="5.75,338,1589266800"; d="scan'208";a="128399072" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2020 20:27:30 -0700 IronPort-SDR: hmd9ccqZ5VCuqRVWDKpqWvIkjCDEEmsdY1zlq2iEj/CkQIqPmlEHhED186/h7xp8J3vVZJFyme wBjZGre8Zudg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,338,1589266800"; d="scan'208";a="280841967" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga003.jf.intel.com with ESMTP; 10 Jul 2020 20:27:30 -0700 Received: from orsmsx605.amr.corp.intel.com (10.22.229.18) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Fri, 10 Jul 2020 20:27:29 -0700 Received: from ORSEDG001.ED.cps.intel.com (10.7.248.4) by orsmsx605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Fri, 10 Jul 2020 20:27:29 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.174) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Jul 2020 20:27:29 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dYDYVYmWE4l6XsbKuidftuxKSkTSW/xvWt76xlFuoR/W6094kPEKzZ7D0LxB9dCMa8iqf2533cneEv176uuIlhbc5pmFmyIYnki8VLh2ZsSEJ7zp3UYM8f0U51g3745kqxcrqFcd0OsMK9BRZtF5fOb/AB4iMSo/ZP+VKPkJ832JsspPhVZS4Onmqb8v1y0rV4NshcGtxh9gWNs258WwPCdMyuZwLEAhMtu8Z37MXEjWX8NHkCiH0/2n+n1yPBVvWoGZ0B783AfiR+c5YCG2nxVrdDhRprADM3V8+Xf182QZhr1qlZsl/J3CuQhInVGrPFHMp4vNSq46HBnSeBn0Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ye/cjZfr9QAmmEb50IGD1PHxI2UI5suemNxmwvih9kw=; b=nvki1HS72lvC047NIOEstYhb15QiYse7Wsd4WTBD6DjG1bB26QtU2ObiTHS/QS2iNzwjPe45FKv4sTpqrK7O6mnmeQiFqlohp3ZHRY0g689l/o2mpP2hvn1PaXF81tSdrDKMVUuIgELBijxbcr0TNSIk8rzHyl6c67LXeY7uyvdLQph5GnT0uc+cpnsJ4mjlusXx3JHX1pXuJsA8rdbI1rZhRVFfmY6qRCS0/UVDH7cXayR2qD+TJsFGGBp16S43AsnFZlmSQGha/z2Rg3paWRx7yJLbt1vbxBoERZUb1ldcxzDRbs+Dcgm2BEZAzcMQ4Oau0lJaFT53Rfp5Vg7acQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ye/cjZfr9QAmmEb50IGD1PHxI2UI5suemNxmwvih9kw=; b=OoAP1mdB2wA5a65qQIDzCBur2ERrYRsOV7F3x9689Lo58kWUGuAaySVHHqEeL4ORmtOhfOnY+4F4BFBmrMDdlvWJYN6yk0x5x91f5MTCudxE8SSA4y+5Ul3FZSRGt1a/k7+gnTQm/O+85Gs9RvX5ug3BdUS548GJCWH5ZrRex9k= Received: from BN8PR11MB3715.namprd11.prod.outlook.com (2603:10b6:408:85::13) by BN8PR11MB3716.namprd11.prod.outlook.com (2603:10b6:408:8a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.21; Sat, 11 Jul 2020 03:27:23 +0000 Received: from BN8PR11MB3715.namprd11.prod.outlook.com ([fe80::1174:140a:4a28:2cfe]) by BN8PR11MB3715.namprd11.prod.outlook.com ([fe80::1174:140a:4a28:2cfe%4]) with mapi id 15.20.3153.031; Sat, 11 Jul 2020 03:27:23 +0000 From: "Ma, LihongX" To: Thomas Monjalon , "dev@dpdk.org" CC: "david.marchand@redhat.com" , "Yigit, Ferruh" , "grive@u256.net" , "Zhang, AlvinX" , "Xing, Beilei" , "Guo, Jia" , "Burakov, Anatoly" , "Richardson, Bruce" , "dmitry.kozliuk@gmail.com" , "navasile@linux.microsoft.com" , "dmitrym@microsoft.com" , "Kadam, Pallavi" , "talshn@mellanox.com" Thread-Topic: [dpdk-dev] [PATCH v2] pci: keep API compatibility with mmap values Thread-Index: AQHWVvp1CPEzXkoVUkmXTux0Hldtw6kBuFiw Date: Sat, 11 Jul 2020 03:27:23 +0000 Message-ID: References: <20200710115324.3902559-1-thomas@monjalon.net> <20200710204034.4158330-1-thomas@monjalon.net> In-Reply-To: <20200710204034.4158330-1-thomas@monjalon.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: monjalon.net; dkim=none (message not signed) header.d=none;monjalon.net; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.193] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9da0d24c-e5dd-4a63-26e6-08d8254a53a6 x-ms-traffictypediagnostic: BN8PR11MB3716: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2201; x-forefront-prvs: 046164D5C4 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /X/nW2CTxEiAil04k42EVF+51jnoD/pquqxOXzCxhGyiQuejF159TGLoI9yZoGdaAskA3H4am4bxss1EU1EVbARRS/pJh94lcvtltANzo4SFaPeLIOPtjyhxtZlrpMxXFezicCt39h0mJHbIf78W9F2hIzrz5QVHDL51t2G0Xh1KKRSvwZNNNBCEwXeKadhDLU5mcDGXCj3HKrRIzcEuPaTrZrfxwf6tBn7NwWWV0TrQ15ZlQn+BNu7miF0huz3D5ToFVNfB/03rQRwqtucZ/xh/ISNY7Y7qjcfD4tW+fJJLNgVfhzZ9E7v+FMeacvRGkFwur05XAZRmJQY+KJkvvA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN8PR11MB3715.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(396003)(376002)(136003)(346002)(366004)(39860400002)(45080400002)(71200400001)(4326008)(8676002)(7696005)(66556008)(66946007)(8936002)(53546011)(66476007)(66446008)(64756008)(76116006)(6506007)(86362001)(83380400001)(316002)(478600001)(9686003)(110136005)(5660300002)(54906003)(2906002)(186003)(52536014)(26005)(33656002)(55016002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: g77zZy7DJ/m/jhfLci2cvEN3jU2EzT2xYygAzJvMv4NQJL5cTi2REFwVU9l7hVpvmH+KIAsZefCPF2Vp8e4WcNsLj+2w6gtBeuEEOK6T2wUofiX3tzJXQXCKsAALeW7HQ7lYyaqCVXb5F9nHdvUec55giGP6OyYdyQPRYe9LQn51kHV/Q5+AEWG95hbjoYf7iDUj9q0o1PsdkaHtD5g5rMUN8DUXKNoXnhcm9L1WYOOexIQqven5mAr4ZGfmW69TctnnR/dmAMWLAuDkh0Pd8RKBgm0gB2RihSx9YoTCCrqRQj+ShaD00PSQ1ntOc1+uMX6Xn7ImwEfV2rBcKIa+YZ+5kttqY6CHzMu4LYN+i0fFIg7sFuJBuHjJ0xCbtjTEvf2Xsa5MIx+bIMQV3deEodpCCtMzU4Xo8O08eD+iO3tmnTYOTSHYiLv14XywD3JF4S8EznUk5OPlzDZF/4QWK7zjsakUdOJFFtoy3Bi5oY9jAKKHbq/374eh7CoYW8v/ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN8PR11MB3715.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9da0d24c-e5dd-4a63-26e6-08d8254a53a6 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jul 2020 03:27:23.1312 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: PHL2RxXcDpdLGzrInSeeMPPzaNmZOeENsXmjqMsR82mj8hKAxUNT0m8C+7vRTlhZwK1C3eMtm+CS6+XPhYayNA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR11MB3716 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v2] pci: keep API compatibility with mmap values 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Tested-by:ma,lhong Regards, Ma,lihong -----Original Message----- From: dev On Behalf Of Thomas Monjalon Sent: Saturday, July 11, 2020 4:41 AM To: dev@dpdk.org Cc: david.marchand@redhat.com; Yigit, Ferruh ; griv= e@u256.net; Zhang, AlvinX ; Xing, Beilei ; Guo, Jia ; Burakov, Anatoly ; Richardson, Bruce ; dmitry.kozl= iuk@gmail.com; navasile@linux.microsoft.com; dmitrym@microsoft.com; Kadam, = Pallavi ; talshn@mellanox.com Subject: [dpdk-dev] [PATCH v2] pci: keep API compatibility with mmap values The function pci_map_resource() returns MAP_FAILED in case of error. When replacing the call to mmap() by rte_mem_map(), the error code became N= ULL, breaking the API. This function is probably not used outside of DPDK, but it is still a probl= em for two reasons: - the deprecation process was not followed - the Linux function pci_vfio_mmap_bar() is broken for i40e The error code is reverted to the Unix value MAP_FAILED. Windows needs to define this special value (-1 as in Unix). After proper deprecation process, the API could be changed again if really = needed. Because of the switch from mmap() to rte_mem_map(), another part of the API= was changed: "int additional_flags" are defined as "additional flags for the mapping range" without mentioning it was directly used in mmap(). Currently it is directly used in rte_mem_map(), that's why the values rte_m= ap_flags must be mapped (sic) on the mmap ones in case of Unix OS. These are side effects of a badly defined API using Unix values. Bugzilla ID: 503 Fixes: 2fd3567e5425 ("pci: use OS generic memory mapping functions") Cc: talshn@mellanox.com Reported-by: David Marchand Signed-off-by: Thomas Monjalon --- v2: move MAP_FAILED from sys/mman.h to rte_os.h --- drivers/bus/pci/bsd/pci.c | 2 +- drivers/bus/pci/linux/pci_uio.c | 2 +- drivers/bus/pci/linux/pci_vfio.c | 4 ++-- drivers/bus/pci/pci_common_uio.c | 2 +- lib/librte_eal/include/rte_eal_paging.h | 10 ++++++++++ lib/librte_eal/wi= ndows/include/rte_os.h | 6 ++++++ lib/librte_pci/rte_pci.c | 1 + lib/librte_pci/rte_pci.h | 2 +- 8 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index 8b= c473eb9a..6ec27b4b5b 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -192,7 +192,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *de= v, int res_idx, mapaddr =3D pci_map_resource(NULL, fd, (off_t)offset, (size_t)dev->mem_resource[res_idx].len, 0); close(fd); - if (mapaddr =3D=3D NULL) + if (mapaddr =3D=3D MAP_FAILED) goto error; =20 maps[map_idx].phaddr =3D dev->mem_resource[res_idx].phys_addr; diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_ui= o.c index b622001539..097dc19225 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -345,7 +345,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *de= v, int res_idx, mapaddr =3D pci_map_resource(pci_map_addr, fd, 0, (size_t)dev->mem_resource[res_idx].len, 0); close(fd); - if (mapaddr =3D=3D NULL) + if (mapaddr =3D=3D MAP_FAILED) goto error; =20 pci_map_addr =3D RTE_PTR_ADD(mapaddr, diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_v= fio.c index fdeb9a8caf..07e072e13f 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -566,7 +566,7 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_re= source *vfio_res, } =20 /* if there's a second part, try to map it */ - if (map_addr !=3D NULL + if (map_addr !=3D MAP_FAILED && memreg[1].offset && memreg[1].size) { void *second_addr =3D RTE_PTR_ADD(bar_addr, (uintptr_t)(memreg[1].offset - @@ -578,7 +578,7 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_re= source *vfio_res, RTE_MAP_FORCE_ADDRESS); } =20 - if (map_addr =3D=3D NULL) { + if (map_addr =3D=3D NULL || map_addr =3D=3D MAP_FAILED) { munmap(bar_addr, bar->size); bar_addr =3D MAP_FAILED; RTE_LOG(ERR, EAL, "Failed to map pci BAR%d\n", diff --git a/drivers/bus= /pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c index 793dfd0a7c..f4dca9da91 100644 --- a/drivers/bus/pci/pci_common_uio.c +++ b/drivers/bus/pci/pci_common_uio.c @@ -58,7 +58,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev) "Cannot mmap device resource file %s to address: %p\n", uio_res->maps[i].path, uio_res->maps[i].addr); - if (mapaddr !=3D NULL) { + if (mapaddr !=3D MAP_FAILED) { /* unmap addrs correctly mapped */ for (j =3D 0; j < i; j++) pci_unmap_resource( diff --git a/lib/librte_eal/include/rte_eal_paging.h b/lib/librte_eal/inclu= de/rte_eal_paging.h index ed98e70e9e..429f896c8c 100644 --- a/lib/librte_eal/include/rte_eal_paging.h +++ b/lib/librte_eal/include/rte_eal_paging.h @@ -3,6 +3,9 @@ */ =20 #include +#ifndef RTE_EXEC_ENV_WINDOWS +#include +#endif =20 #include =20 @@ -22,6 +25,7 @@ enum rte_mem_prot { =20 /** Additional flags for memory mapping. */ enum rte_map_flags { +#ifdef RTE_EXEC_ENV_WINDOWS /** Changes to the mapped memory are visible to other processes. */ RTE_MAP_SHARED =3D 1 << 0, /** Mapping is not backed by a regular file. */ @@ -35,6 +39,12 @@ enum r= te_map_flags { * it is not required to do so, thus mapping with this flag may fail. */ RTE_MAP_FORCE_ADDRESS =3D 1 << 3 +#else /* map mmap flags because they are exposed in pci_map_resource() API= */ + RTE_MAP_SHARED =3D MAP_SHARED, + RTE_MAP_ANONYMOUS =3D MAP_ANONYMOUS, + RTE_MAP_PRIVATE =3D MAP_PRIVATE, + RTE_MAP_FORCE_ADDRESS =3D MAP_FIXED, +#endif }; =20 /** diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windo= ws/include/rte_os.h index 569ed92d51..2881bf2224 100644 --- a/lib/librte_eal/windows/include/rte_os.h +++ b/lib/librte_eal/windows/include/rte_os.h @@ -25,6 +25,12 @@ extern "C" { #define PATH_MAX _MAX_PATH #endif =20 +/* sys/mman.h + * The syscall mmap does not exist on Windows, + * but this error code is used in a badly defined DPDK API for PCI mapping= . + */ +#define MAP_FAILED ((void *) -1) + #define sleep(x) Sleep(1000 * (x)) =20 #define strerror_r(a, b, c) strerror_s(b, c, a) diff --git a/lib/librte_pc= i/rte_pci.c b/lib/librte_pci/rte_pci.c index d8272b9076..1d1cbc75ac 100644 --- a/lib/librte_pci/rte_pci.c +++ b/lib/librte_pci/rte_pci.c @@ -163,6 +163,7 @@ pci_map_resource(void *requested_addr, int fd, off_t of= fset, size_t size, __func__, fd, requested_addr, size, (unsigned long long)offset, rte_strerror(rte_errno), mapaddr); + mapaddr =3D MAP_FAILED; /* API uses mmap error code */ } else RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr); =20 diff --git a/lib/librte_pci/rte_pci.h b/lib/librte_pci/rte_pci.h index 104b= 2bb858..a03235da1f 100644 --- a/lib/librte_pci/rte_pci.h +++ b/lib/librte_pci/rte_pci.h @@ -160,7 +160,7 @@ int rte_pci_addr_parse(const char *str, struct rte_pci_= addr *addr); * The additional flags for the mapping range. * @return * - On success, the function returns a pointer to the mapped area. - * - On error, NULL is returned. + * - On error, MAP_FAILED is returned. */ void *pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size, int additional_flags); -- 2.27.0