From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.73]) by mx.groups.io with SMTP id smtpd.web11.6562.1587649930362738673 for ; Thu, 23 Apr 2020 06:52:11 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nxp.com header.s=selector2 header.b=kTZqndt1; spf=pass (domain: nxp.com, ip: 40.107.20.73, mailfrom: wasim.khan@nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FljmNI5pUHfrozITCqmdnhLB9ObmngJ18QK5lTLeDB795QfS5XqeADtlD8uKMWxfKODe02BQpxzDn4oNxIA//4i5m9pJbS5LzrrLvtS6kSmYmmiA/hUFLXwicQmrfVpKZGFEGK0FRQYy3Xy1x7i3sIr9wMyWtDSiWURwuWhHMedw5iYs/fDQG27TsUIgqBsANtVInly0nqPkOJxQ1yneElsHh1+mkaP8WLKH+wHGF1muqWI9zxrySXS3vdkoJD7zNIc79hfKtInZbDlwyk5S16Jsvcr5QSIsmDGLy2aNuYH7lDrlhl95vHSgoxGbZ1ldyr20gmPZ3YMkOZ+3Le8JTg== 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=UaOMO4HnEwczLqGK3nyGd3xey/I/C0iHWd2m3nNrXC8=; b=D7qPrp6wBNMTeD73Ets3AKzqiGB0uzPFO7Uh+H8w485b2zRjY1TD7ighgMeqXbfmEqumnMg3hjMmVtpLyHuVZmr9GMXsKGbuMLXsPzUNwDTTXkR5utZgVtB/NGvViPov3ekUQzy86gjUAHlHxIY56MnNY6anrVmly9F+Nm74mcsTuqHfN1cPpKs1KE5aNbehXWp8pqvpZ79L2SCnf449qmeJj+oupo7c2hIeMTCmoUmbr2HJuOMIN0Vpwl1KaCUNc1O0RPyFN/ju6jCh5QbJRoXRaa6Knf3KQ+cRithNSY4WwXOQbRfmoRFiKgYyzCMoiTjj9EqUVoEyv1NLlc4MpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UaOMO4HnEwczLqGK3nyGd3xey/I/C0iHWd2m3nNrXC8=; b=kTZqndt1wQ+TG4Xs5GehMwN5OWxfpIMsFZzLLPf86qpY6Khz4ffFBJZlrxdahpxR0UxMQOMFOqj3nKI4Yjo9IH8ngDWXg8nnoIELLjhnjlHHnMRYn8ShOhI1jKIhKY24qJacz84zqRahGHYtktUo8Eyx40PxgxI1vlsjHANTqyM= Received: from VE1PR04MB6702.eurprd04.prod.outlook.com (2603:10a6:803:123::13) by VE1PR04MB6672.eurprd04.prod.outlook.com (2603:10a6:803:127::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.27; Thu, 23 Apr 2020 13:52:08 +0000 Received: from VE1PR04MB6702.eurprd04.prod.outlook.com ([fe80::c092:8f65:8b04:dd28]) by VE1PR04MB6702.eurprd04.prod.outlook.com ([fe80::c092:8f65:8b04:dd28%5]) with mapi id 15.20.2937.012; Thu, 23 Apr 2020 13:52:08 +0000 From: "Wasim Khan" To: "Ni, Ray" , "devel@edk2.groups.io" CC: "ard.biesheuvel@linaro.org" , Varun Sethi , "Wu, Hao A" Subject: Re: [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem Limit Checks Thread-Topic: [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem Limit Checks Thread-Index: AQHWGVwVTvFEzXmpYUaOtumZsnOqHqiGlDUAgAAjx6A= Date: Thu, 23 Apr 2020 13:52:08 +0000 Message-ID: References: <1587638612-13056-1-git-send-email-wasim.khan@nxp.com> <734D49CCEBEEF84792F5B80ED585239D5C50A98E@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <734D49CCEBEEF84792F5B80ED585239D5C50A98E@SHSMSX104.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=wasim.khan@nxp.com; x-originating-ip: [157.37.82.244] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: d91a0cee-f397-46ff-0cec-08d7e78d83da x-ms-traffictypediagnostic: VE1PR04MB6672:|VE1PR04MB6672: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 03827AF76E x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6702.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(376002)(136003)(366004)(39860400002)(396003)(346002)(66556008)(52536014)(316002)(71200400001)(66446008)(64756008)(76116006)(8676002)(81156014)(86362001)(186003)(44832011)(15650500001)(6506007)(9686003)(110136005)(7696005)(54906003)(5660300002)(53546011)(8936002)(4326008)(55016002)(66476007)(26005)(478600001)(66946007)(2906002)(33656002);DIR:OUT;SFP:1101; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Btnk6BKBpFoA6pmVY6EeeA1SVJ/5gNYsHbT39JT0Bz3qnF+QRgr9bBIhSbSkww3vJ3YxEJWlb4JUTSt7emdrkAd1i27pmVE9SBt4cnLclwu7AJ2SuD3s7zbjAvpbngru57Wt/gBnQPmiPpfRSOXK5xEOtOtihYPLnqpdU0h3F1sfmTlgZ/TQym+R6IcHRuuvvhWLKiefooerAPcBG2yPbdf5Xc76HaeRMgIq45WYBHu8kaC+Z5q2PqDR1+FFITmR9cN/MXMd6psw9ozg6q6bfZVQCgo0HP13JPaZ3plBNCBlmg9rDOENzvPKyj6pEEzy23u4OIQPEx1MRRnJHuzsLXtxX8xdK3BMNnCjsFlhWnl+JdKBAhoV+ITDBv/JXXsuUxEZcz+ojJo4Kj1rmskB7lFcGJ2OWThpyeo+Uqy/yj4NFfDBySMdoDSA9tHNRYHV x-ms-exchange-antispam-messagedata: EnBi0Oq23N1xg3+pGWGMum6ExTszx075uhcZamXs6RrEYwXNtPJx/R4/f8aeie1FkkflsKC2MHrMEcixv6nypSdCqb8x8csLCtzsrHoZg9hBolIBVbrc9WdIXrkgUU9A4WGev8d71ShTEibIFGI8BA== MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d91a0cee-f397-46ff-0cec-08d7e78d83da X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Apr 2020 13:52:08.3145 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: JeGLBzdvEWUAfbE7csOS2Jl0QDXqE8E/2xCUfhvbKleNTib5+9JMG7AI2Lj2hoj7GvkueWaNdEgqs1Ihd4gLXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6672 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Ni, Ray > Sent: Thursday, April 23, 2020 5:07 PM > To: Wasim Khan ; devel@edk2.groups.io > Cc: ard.biesheuvel@linaro.org; Varun Sethi ; Wu, Hao A > > Subject: RE: [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem > Limit Checks >=20 > Thanks for fixing the check. >=20 > PCI_ROOT_BRIDGE_APERTURE.Base/Limit are device address while the memory > space in GCD belongs to host domain. > So, host address for Mem/Pmem should be below 4GB while device address ca= n > across 4GB. >=20 Hi Ray, Thank you for the review.=20 There are cases when we don't have PCIe host address below 4GB, and the PCI= e HOST Address space is only available above 4GB.=20 For Example, Mem: 40000000 - FFFFFFFF Translation=3DFFFFFF6000000000 will r= esult in HOST Address =3D 0xA0FFFFFFFF . This is a valid use case, but belo= w check will report ASSERT for this HOST ADDRESS.=20 > Can you enhance the check as below? > ASSERT (TO_HOST_ADDRESS (Bridge->Mem.Limit, Bridge->Mem.Translation) < > SIZE_4GB); > if (TO_HOST_ADDRESS (Bridge->Mem.Limit, Bridge->Mem.Translation) >=3D > SIZE_4GB) { > return NULL; > } >=20 > It will look more precise and can detect invalid Mem/Pmem resource. >=20 > > -----Original Message----- > > From: Wasim Khan > > Sent: Thursday, April 23, 2020 6:44 PM > > To: devel@edk2.groups.io > > Cc: ard.biesheuvel@linaro.org; v.sethi@nxp.com; Wu, Hao A > > ; Ni, Ray ; Wasim Khan > > > > Subject: [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem > Limit > > Checks > > > > With Address Translation Support, it is possible and also correct that > > Mem and Pmem Limit cross the 4GB boundary. > > Update the checks so that Mem/PMem Limit should not cross 4GB from the > > Mem/PMem Base address. > > > > Signed-off-by: Wasim Khan > > --- > > MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c | 8 ++++---- > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c > > b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c > > index d304fae..9cf7e98 100644 > > --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c > > +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c > > @@ -117,8 +117,8 @@ CreateRootBridge ( > > // Make sure Mem and MemAbove4G apertures are valid > > // > > if (RESOURCE_VALID (&Bridge->Mem)) { > > - ASSERT (Bridge->Mem.Limit < SIZE_4GB); > > - if (Bridge->Mem.Limit >=3D SIZE_4GB) { > > + ASSERT (Bridge->Mem.Limit < (Bridge->Mem.Base + SIZE_4GB)); > > + if (Bridge->Mem.Limit >=3D (Bridge->Mem.Base + SIZE_4GB)) { > > return NULL; > > } > > } > > @@ -129,8 +129,8 @@ CreateRootBridge ( > > } > > } > > if (RESOURCE_VALID (&Bridge->PMem)) { > > - ASSERT (Bridge->PMem.Limit < SIZE_4GB); > > - if (Bridge->PMem.Limit >=3D SIZE_4GB) { > > + ASSERT (Bridge->PMem.Limit < (Bridge->PMem.Base + SIZE_4GB)); > > + if (Bridge->PMem.Limit >=3D (Bridge->PMem.Base + SIZE_4GB)) { > > return NULL; > > } > > } > > -- > > 2.7.4