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 167A8A0526; Wed, 8 Jul 2020 15:58:15 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DF4C51DD89; Wed, 8 Jul 2020 15:58:14 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id E07271DD89 for ; Wed, 8 Jul 2020 15:58:12 +0200 (CEST) IronPort-SDR: L61WxFM7I0eNJPb53aG36dQCOmOt4zTLoYBZmerccvvWQu/gGl5jx1MameReJIv20Vi1f2FgW0 GIdLSBCs1qIg== X-IronPort-AV: E=McAfee;i="6000,8403,9675"; a="149305768" X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="149305768" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2020 06:58:12 -0700 IronPort-SDR: 2Y1DEUyXbP1dwKGraI18c+EFDLIvsTcRnPpOcnki44KCrGWPURaQs5aP2LLjxhgcQgJhqjyiwS nYsJljDrtTkw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="427845832" Received: from orsmsx102.amr.corp.intel.com ([10.22.225.129]) by orsmga004.jf.intel.com with ESMTP; 08 Jul 2020 06:58:11 -0700 Received: from ORSEDG001.ED.cps.intel.com (10.7.248.4) by ORSMSX102.amr.corp.intel.com (10.22.225.129) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 8 Jul 2020 06:58:11 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.168) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 8 Jul 2020 06:58:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IM+7oxFrvXljq5jFg/uEX02+upeG3wxhRrP1IpknvwXqxKNeVLUz4iy3hjfJ04QUKEzPEz3TyPtniz41KyipsT2Rn5YK3F9oPMI5vNO+HYVySsZpQDwdJOAR0h9eeXtmG2WhJn+FmwVt37judQWQ3iMKgk4hk6khn4a3tWjp+7fL/BBMWvjCBNmdacLnHUXrcY0TwBDou5MHiyiH2NezffzMHYpwZzmBFpCDECKcuTRAZLO4ebgNeQsApTYg1SctTiV7T26GcG0zyv6kYNHjvpnZDvkO0MwyKGnK1K+ynROsk5JGVjMnlh5o0rawu6w3giD6BVtr50zUlTSk0lu5wA== 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=JQfXFFr9hqvQNzC4Q+xM9wjc9tDzzLLl90E035w4nbE=; b=fjZg6UihVW52TshFfQPUEgIR0lDJoajd+OQ9s1cI44/rNn0QkDynWr9rYwCayXIjZq/9j1b1vlUg172iaqM0v7x9DoYxvf/z/lv/HqtEeqqMbWUFfTQ6Fcy0rKcHQBjr1ZwWhRi3HLVly+5CE34aBt9MmGZRklqvfOrAyTSDBe+gg7OswFHgU3gOt0kjP3yldhY0zfOeXePRxGF4DkgHXxhD0ckO/5x7Qv2yn3REb4KrYIQmu4Jz//owTZu3hWwVCbyIM+i+Uqj5Xdfb/g0OsZsC9d7dAd+aD5pW2Ih/mKp99W0JwC/EqmqadJL4b7xC7oEGuCNPzjVF4cx+Ri6p6g== 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=JQfXFFr9hqvQNzC4Q+xM9wjc9tDzzLLl90E035w4nbE=; b=qPmPveCbbPND/QW7P872i3X3CRSREfboBrweim/zxA+6ZW32/sAaM3anv8QYVrvAbOtBjAafwMtxoAW9k6g1mKB7Z7ZuY0Rcc1KJa7U2PeZr9IU2tVlcQqDKHzalUzwC1pe+Z2IWPGcj0KLOURFsjXBgUIcsLTY+2JNGuL0eDTk= Received: from MN2PR11MB4063.namprd11.prod.outlook.com (2603:10b6:208:13f::22) by MN2PR11MB4048.namprd11.prod.outlook.com (2603:10b6:208:153::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.29; Wed, 8 Jul 2020 13:58:09 +0000 Received: from MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::7cde:8326:5010:c47e]) by MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::7cde:8326:5010:c47e%7]) with mapi id 15.20.3153.029; Wed, 8 Jul 2020 13:58:09 +0000 From: "Xia, Chenbo" To: "Zhang, AlvinX" , "dev@dpdk.org" CC: "Xing, Beilei" , "Guo, Jia" , David Marchand , Tal Shnaiderman , "Burakov, Anatoly" , "thomas@monjalon.net" Thread-Topic: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource Thread-Index: AQHWVQny4OL7AABPaUCG1PWCsxlEOaj9sExQ Date: Wed, 8 Jul 2020 13:58:09 +0000 Message-ID: References: <20200708092435.9776-1-alvinx.zhang@intel.com> In-Reply-To: <20200708092435.9776-1-alvinx.zhang@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.2.0.6 authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.199] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 68b3049c-75de-4e1e-bfbd-08d82346f296 x-ms-traffictypediagnostic: MN2PR11MB4048: 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:10000; x-forefront-prvs: 04583CED1A x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: sWl12OzHyfIpGs+AswLPaZoj6gZCP5K450zo39Zd6dfulrVTgtxLXXujoQT76S7CDF4clkYF+fjroCetz+xIaFwD8wUMZFa38GQ5EHseylt3MpVZHVBNDnhhwIxmjlOKn9LwUqQtGU0eSMtjWyUGb5twGYbl8V6l3X/BqNwFo+Vc1YwngsXIQtKRhbx94iSb27sqMe34oyBPnNS8ukH0OLqJQLNhQRVR9Z2PS2Gk5IFHZgYQFw8XMxN08JsiL6XjhTsUPpT15iNF8QB3FnTD3/qx5ZNS99aBvrva+oMdeC1I8QXI3JBM7xwxWeaUdmcaP8sPhTaHCWrQ2l/Qu2Snbn2vcc4WNwkC0uitsyfAB34= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR11MB4063.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(366004)(39860400002)(346002)(396003)(376002)(6506007)(53546011)(4326008)(7696005)(76116006)(9686003)(66446008)(66476007)(66946007)(66556008)(64756008)(52536014)(55016002)(86362001)(2906002)(186003)(26005)(71200400001)(8676002)(5660300002)(8936002)(33656002)(316002)(478600001)(110136005)(83380400001)(54906003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: DSPiikRz7jahQwny8yu2BMSQ5vJMqvaUcQtyZrXPDE+oe2GVnlP5UdCjou6TOrLT7SXj75Z8tHawwSV2mMPNu8lFemRqVX33bxOxlZALtSea4fhnGjRUCdBiJeSYTDMjRwO1mQlPmdI0IRDYZy4ZNjTb/yJ7B78sgiuGb6mRE55Y37a8Yj05cMrZn6UCECjlWXrn1xTOs5JnGWTTuxjDF6VOhFakjQA155M1WROnm/Nl7g6gLWZVmazTLh6AJJlGLO7EgbRI+5tY2yS791ZexXeg3ztPISXgvAYOcL7oIzSWuDk1HAiDZaWrBQLKs47eJjV37WueXurukOA7XNvypBxg+i9YgmZ2ihj5cOur2ei71NCV1/RjiHTC+wrLC6TUcMjtMI/CSCwFCNVyBtcfVR1hWLCkYCSAn2ARhKYRFGHnRuuJuD3eYT2tfiwqLNrQzU5WF452aXmtPvVQ6MLCbwUMZ1HPQZHSFNZShpooScZ3DXgeUPUi+bq+75/B0ipi 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: MN2PR11MB4063.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68b3049c-75de-4e1e-bfbd-08d82346f296 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jul 2020 13:58:09.5574 (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: RDeRRYgWDjGm/DP08hktP5eAdM++V7JBEvKPM04X/0bVBu/w75O5HDwD2oA0EVYhRDTGJeOip2Np79xB0LA8Gw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4048 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource 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" Hi Alvin, CC the maintainers. Comments below. > -----Original Message----- > From: dev On Behalf Of alvinx.zhang@intel.com > Sent: Wednesday, July 8, 2020 5:25 PM > To: dev@dpdk.org > Cc: Xing, Beilei ; Guo, Jia > Subject: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource >=20 > From: Alvin Zhang >=20 > When mapping a PCI BAR containing an MSI-X table, some devices do not nee= d > to actually map this BAR or only need to map part of them, which may caus= e the > mapping to fail. Now some checks are added and a non-NULL initial value i= s set > to the variable to avoid this situation. >=20 > Fixes: 2fd3567e5425 ("pci: use OS generic memory mapping functions") > Cc: talshn@mellanox.com >=20 > Signed-off-by: Alvin Zhang > --- > drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci= _vfio.c > index fdeb9a8..9143bfc 100644 > --- a/drivers/bus/pci/linux/pci_vfio.c > +++ b/drivers/bus/pci/linux/pci_vfio.c > @@ -547,6 +547,14 @@ > bar_index, > memreg[0].offset, memreg[0].size, > memreg[1].offset, memreg[1].size); > + > + if (memreg[0].size =3D=3D 0 && memreg[1].size =3D=3D 0) { > + /* No need to map this BAR */ > + RTE_LOG(DEBUG, EAL, "Skipping BAR%d\n", bar_index); > + bar->size =3D 0; > + bar->addr =3D 0; > + return 0; > + } I'm not sure if this corner case will happen. If you confirmed it, Just ignore this. > } else { > memreg[0].offset =3D bar->offset; > memreg[0].size =3D bar->size; > @@ -556,7 +564,9 @@ > bar_addr =3D mmap(bar->addr, bar->size, 0, MAP_PRIVATE | > MAP_ANONYMOUS | additional_flags, -1, 0); > if (bar_addr !=3D MAP_FAILED) { > - void *map_addr =3D NULL; > + /* Set non NULL initial value for in case of no PCI mapping */ > + void *map_addr =3D bar_addr; > + I see the issue that this patch wants to fix is based on an old kernel. In older vfio-pci kernel module, MSI related reg cannot be mmaped in userspace while in newer kernel it can be. That's why sometimes it cannot be reproduced (https://bugs.dpdk.org/show_bug.cgi?id=3D503) So under the condition of old kernel, there could be an example that Memreg 0 has size 0 but Memreg 1 has non-zero size, which leads to Memreg 1 cannot be mmaped. So I'm fine with this part of code change. As this issue is blocking test, we should do fast confirm and review. Thanks, Chenbo > if (memreg[0].size) { > /* actual map of first part */ > map_addr =3D pci_map_resource(bar_addr, vfio_dev_fd, > -- > 1.8.3.1