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 E4269A0528; Sat, 11 Jul 2020 05:18:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CA3981DA8F; Sat, 11 Jul 2020 05:18:09 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id DF1CF1DA6C for ; Sat, 11 Jul 2020 05:18:07 +0200 (CEST) IronPort-SDR: FrYHsfTXYsktsAXfSi5qzFU6hmUr9SK41Zg2m4rlMCOrYFyw+mq2bZ6ARjueDcmvn+unBRh8fV Jt9WCtTh4M/A== X-IronPort-AV: E=McAfee;i="6000,8403,9678"; a="213204829" X-IronPort-AV: E=Sophos;i="5.75,337,1589266800"; d="scan'208";a="213204829" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2020 20:18:06 -0700 IronPort-SDR: rDSDjOPgLAwdcwSTuKjmVeU1L9m+tbrZlrJs7va+8xdOezJWFgpx5ANeX+ei2MRtGCOB5xujrf FTDw04I0siwg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,337,1589266800"; d="scan'208";a="484372046" Received: from orsmsx108.amr.corp.intel.com ([10.22.240.6]) by fmsmga006.fm.intel.com with ESMTP; 10 Jul 2020 20:18:06 -0700 Received: from orsmsx155.amr.corp.intel.com (10.22.240.21) by ORSMSX108.amr.corp.intel.com (10.22.240.6) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Jul 2020 20:18:05 -0700 Received: from ORSEDG002.ED.cps.intel.com (10.7.248.5) by ORSMSX155.amr.corp.intel.com (10.22.240.21) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Jul 2020 20:18:05 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.45) by edgegateway.intel.com (134.134.137.101) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Jul 2020 20:18:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iUgyEEEMdqN+GMX4aYwD+d7yJCsRl4Y3DuTQllWuu8dNSHlDm3kVtWdilCge9TqKR88OGR/ipon6jbhKJQsYA7I7STIAJqqwXpuNGr++2LRm5Q9nLmmM6jo/0N1jKU3CXKtOx7JuH3VeNtExio1SQTOkAqZ1JhjxetWMvPfjEh6J3NY1fMxdVpJfGK64uQmIQCmiu1zVmngzN4sHoth3H5hd8jI+CHA5HNDP84SfiAonyT+ccKrknYxzrakEUub0n4I6s2o9eHH4iNj01HnQg/ZscgewUaOi65F4mnS4VCiiKw5sImL0kn5o/D7YPkJx+7GkDtUWC6q7mjVx1AQ5Fw== 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=mDeUWCzNcubWsH/VwsP04bCCpDNfz3W6sRSk5XvLtS4=; b=Kml9SWOsO48BXpuPoKbhl8/0BFByfElZGpaqlwPeb8JLEcpbzciJF2ac+iplyppgFflPuvQ7Z7AFIy678WZWAp+6U54rozdPWIh/B359c1DLSEU6BJErQvdoMXlupxKF/yZNsn/CHKSDFVbGowDO2PQJiytSkW5Ll4/C3GhrC93vpW7YzBFrc0t/gebKnaK02YCvqsLTo4efeQZDVzPv4BctlJvIUrShi5nZAWGsr5H6i8GTgFZah0qTAI6OOMDdFhsxvhaOD5f9Ebon8mYtyyB+7sEfguy0av7OzePqwiUxbHn9VqF0BJsbRw57ZYQvcZuLa6RBenokHOaXCX/4bg== 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=mDeUWCzNcubWsH/VwsP04bCCpDNfz3W6sRSk5XvLtS4=; b=IhB/BGhIG7C/bVwQoqPIM3mcqFl8Tl4hyii85q5yoCbidO3oHySuYTlao4gVlm0tljtO3BiM3LCe8axvkbGELZ4qiluH7uveLQl8YRoGMqUf3LFeNbD5O9QI4S9cGAlnoCYn/yxrdQJvoBQ9MuvynDxaF0aEPAjJvtNDm7aOpPo= Received: from BN8PR11MB3715.namprd11.prod.outlook.com (2603:10b6:408:85::13) by BN6PR11MB1428.namprd11.prod.outlook.com (2603:10b6:405:a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Sat, 11 Jul 2020 03:18:01 +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:18:01 +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] pci: keep API compatibility with mmap values Thread-Index: AQHWVrDNRc9flirMd0yNJrhIVtZdkKkBtgnQ Date: Sat, 11 Jul 2020 03:18:01 +0000 Message-ID: References: <20200710115324.3902559-1-thomas@monjalon.net> In-Reply-To: <20200710115324.3902559-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: db5a225d-d3bc-464d-5759-08d8254904b9 x-ms-traffictypediagnostic: BN6PR11MB1428: 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:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: AyMRUxgfwSR7PZkgylJf5ryTvAwifpOnGc7mLyq9vYzizFkQbf6S/9MIz/kxotmQ67RMNzxh4D3OUIS7OZ5cuFAwWizJRBvEh7RQDCG8CK9UokudE0L2Cz7OOM2tCPkH39OEnpd/BNZmr65w5tNkMElmsDSkwQ1TA4BwtYlU3cUJtJ10Pk/nM03Rcx0D6oPRPLXDaIcklH1fSqpSqM6RvCi4W8vbzIE/VhdNMrXtZsKuPgtjn+fCH+RKmseElUmP5q+VuMhCSYHfMmlMCuCXILG5+M3a4s7iI553+k/NBHcONm8EnHShS4DXXFB7FIu1rur6QfPJNVYw8zmsQ0Qolw== 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)(366004)(136003)(39860400002)(346002)(376002)(396003)(55016002)(186003)(26005)(4326008)(86362001)(54906003)(33656002)(83380400001)(316002)(9686003)(110136005)(71200400001)(45080400002)(53546011)(478600001)(8676002)(52536014)(7696005)(5660300002)(76116006)(6506007)(2906002)(66946007)(64756008)(8936002)(66476007)(66446008)(66556008); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: hiJeW1KCZk13nEKvYPYGyNs4Jqzf9mqfrghaGwuZTwejgCKKD154+o+UxVxvPS629lHYqCjHuncKYllSTut8DgmzaW9wOcKCr4QiPotNvB4Pu9seTs0Mtu2q3CYpSvMj5iFb5P9MYsdzwQeMcagUZTTfk9W8GGqv2FH80TFY/oVNDurRoXemOizI65Plev53NHwA2Bxqt/v/sEziMhGrwY8rmmN8IRRUJc3ixK54+iCigYmbVuqNtaXmx8VTG3QcIw7ufEGsLveoJB95nTAXxhcW5hwkLKOCjxkTARSXCZ3CwC06fDSDxZQyJPsRm4RAYTxOtBJsmssq93KPh7m2/IDus/pQrbGIX82jrgi4hYL02bdb8cIEh7NWczRE+byTrRbLU3XaI8PBQeBKMf4CkraeYBrwLhWNy9uq5iF7/wxIg6F3HmdcWXp4D7xiEBx7J782YOUtzujX0Cvp805J02DEGwWW+xCPDEgE9wsH8vFhYb4hyGK1MOgXMmongyFB 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: db5a225d-d3bc-464d-5759-08d8254904b9 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jul 2020 03:18:01.2852 (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: vgyqq63ETX5kLXG/Jy0ay9pMnlYCrbV052ZVIkFyD6sMDxhAFHUB74ksLBy3dRwVhnpU/tjKi8vrdZkZriFSsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB1428 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH] 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,Lihong Regards, Ma,lihong -----Original Message----- From: dev On Behalf Of Thomas Monjalon Sent: Friday, July 10, 2020 7:53 PM 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] 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 --- 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 | 8 ++++++++ lib/librte_eal/windows/include/sys/mman.h | 9 +++++++++ lib/librte_pci/rte_pci.c | 1 + lib/librte_pci/rte_pci.h | 2 +- 8 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 lib/= librte_eal/windows/include/sys/mman.h 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..680a7f2505 100644 --- a/lib/librte_eal/include/rte_eal_paging.h +++ b/lib/librte_eal/include/rte_eal_paging.h @@ -3,6 +3,7 @@ */ =20 #include +#include =20 #include =20 @@ -22,6 +23,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 +37,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/sys/mman.h b/lib/librte_eal/win= dows/include/sys/mman.h new file mode 100644 index 0000000000..0b4b10df1f --- /dev/null +++ b/lib/librte_eal/windows/include/sys/mman.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2020 Mellanox Technologies, Ltd */ + +/* + * 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) diff --git a/lib/librte_pci/rte_pci.c b/lib/librte_pci/rte_pci.c index d827= 2b9076..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