From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (EUR05-VI1-obe.outbound.protection.outlook.com [40.107.21.73]) by mx.groups.io with SMTP id smtpd.web10.305.1582612870364571025 for ; Mon, 24 Feb 2020 22:41:11 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nxp.com header.s=selector2 header.b=hvNtJ0mD; spf=pass (domain: nxp.com, ip: 40.107.21.73, mailfrom: gaurav.jain@nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KA97Akf4mP+PeY+HpYhSD+NG4PNI8ggip8Wu1b6aMK2zHLFKmu7veThCA5AXNBV4Wd4hvyR3jIEVxPKxoiIzCtvvVERzkMsP5KZC/TJnsCY2U5X26KABz1NG9lZwBqhrTbRkcOWsv2f5Qd1NV4WyIHpUw1mscPOAZHqKmcZuCtP2EbTE5LanLYdiSJkcM29l1UGqE444MGWeEdNiZhpMwI83/Mj107pdpV5i1I6k1vwG/y/aOn0Dckp1VugOwL7qmnyNxlYhXLOUKPvhOibo4mK9Eg0MNBsivey7Jfh9MdWYs0QRo2vxJteFNMogIgdYbh0kdXOlHYtn676vRwqv3A== 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=bLjNlJ8pb2tilACZjbLlnUnhRryQPodJQ+JQnYyk4LQ=; b=S1eX32Ye/acGx6+HQR4J20xSMcrGWwuVBgCLZ4dgS8PPNXRW/EDyUhL8hdkQHpxelXz0YGfcLPZ9xHzsYr7UcuLPY0ZibWrm4JHoaGRIBUHkfwttQuQcHgs4k+75pk9GPjhrD7VS2Rgh737p/2gIed+QNLgXYsYwOvGvZp/7iqtpD54C3Ca9Y3SrjILR/aQdGn2ha2A8QNpVNHNqBBAQnuy47Cv8PNNvuVKsb4aRPiuFwoGrvf4laxfMiejbE3Da3JM03KdNHo3nvyCgaUKcBOwyEZmm2Ka83e7wgYW3hrkSzHdp8j3mu07IpeWFnJjx9d4bjzxIyvNkxD5JyHH6lA== 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=bLjNlJ8pb2tilACZjbLlnUnhRryQPodJQ+JQnYyk4LQ=; b=hvNtJ0mDHo438htx3o2USl35Rs2Pzp+G9TKjsrEnEoLEge4auc8Q+ArbrTvjc/Xy05JstMM9qDBU6DHP8ehoA6HNxZ2PgiTtPzv2bLMnkfW4WL/op5IEmKwvakjZjEEefg3pKgaxGxlD8dS0wyySWrjs+3OhfGfUQbJKMJQDiJ4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=gaurav.jain@nxp.com; Received: from DB7PR04MB4091.eurprd04.prod.outlook.com (52.134.110.144) by DB7PR04MB4441.eurprd04.prod.outlook.com (52.135.141.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.22; Tue, 25 Feb 2020 06:41:08 +0000 Received: from DB7PR04MB4091.eurprd04.prod.outlook.com ([fe80::183:969:2508:3c92]) by DB7PR04MB4091.eurprd04.prod.outlook.com ([fe80::183:969:2508:3c92%6]) with mapi id 15.20.2750.021; Tue, 25 Feb 2020 06:41:08 +0000 From: "Gaurav Jain" To: devel@edk2.groups.io CC: Jian J Wang , Hao A Wu , Ray Ni , Ard Biesheuvel , Pankaj Bansal , Gaurav Jain Subject: [PATCH v3 1/1] MdeModulePkg/Pci: Fixed Asserts in SCT PCIIO Protocol Test. Date: Tue, 25 Feb 2020 17:30:41 +0530 Message-ID: <20200225120041.31570-1-gaurav.jain@nxp.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: SG2PR02CA0019.apcprd02.prod.outlook.com (2603:1096:3:17::31) To DB7PR04MB4091.eurprd04.prod.outlook.com (2603:10a6:5:1e::16) Return-Path: gaurav.jain@nxp.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from uefi-workstation.ap.freescale.net (92.120.1.69) by SG2PR02CA0019.apcprd02.prod.outlook.com (2603:1096:3:17::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.18 via Frontend Transport; Tue, 25 Feb 2020 06:41:05 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [92.120.1.69] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d8b69e4e-ecc8-4336-4fdd-08d7b9bdb1a5 X-MS-TrafficTypeDiagnostic: DB7PR04MB4441:|DB7PR04MB4441: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-Forefront-PRVS: 0324C2C0E2 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(346002)(376002)(39860400002)(136003)(366004)(396003)(199004)(189003)(81156014)(6666004)(4326008)(36756003)(66476007)(54906003)(6486002)(316002)(1076003)(66946007)(66556008)(2906002)(16526019)(6916009)(5660300002)(8676002)(86362001)(81166006)(8936002)(52116002)(956004)(6512007)(44832011)(478600001)(2616005)(26005)(186003)(6506007);DIR:OUT;SFP:1101;SCL:1;SRVR:DB7PR04MB4441;H:DB7PR04MB4091.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; 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: /CX/paHn8My9waXXd3Bgz5fyvDlQ+0WU+bSxBFZ8JAdq/jlLw6lX0hvbPnipGBAe0al18qflv+g1KLuO25HecyyHfYErCcoi8TWdyVpvWgkgh9seSHXd0Z654gGePVz0Y6Cm27Z+KIKBBgulhAyfOZ3msNxkl6fQE36gFdgzxQ6fAq49uYwbWfNnWj7g6UQGsW0sNSwUCxS0FSYY77e82QU1oV9+MsT5HViQPetuedpJhG5SZe5HzKEvIlVEiMdMmbNn5DjrpUHBN7S7aAUM7srKzmNOI/8A5eIwMn+0xO7Do9MRmJgNhnWxjcrHLuf271Pme2Gpz/RvbvDsRUSONtfAT0wDx6WUGX1CQoJ8bmO5N6+Q3Su4KgVmOWSUrxGnGsMmALh4er+mzGu13dNXrCZwoI/HxB4KEwVxgX0xdC0OtihoNhmOnKXTHSRREpwE X-MS-Exchange-AntiSpam-MessageData: 9AMe+K2fVfVzk0X5iP4IYYT6HlKztxqddbGQXh/HilVc8LCRd40VK32WLLWfmXix1mTTQUINnnbiZGYXQqW0+7+joiOAKefwkfm2S8RpLBpG/evAMAVjAJFlvANllGhzI3yqpXh+OD8lVzd5NPp7SQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8b69e4e-ecc8-4336-4fdd-08d7b9bdb1a5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2020 06:41:07.8552 (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: bXWkVFbaijshJLq0I9fZgkNezrO2w3s2zwwVYl37QmMwC+ZEeS4q7u9zexh5FwA744rnJK6E9IXKxA2Y4LOHDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4441 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain ASSERT in PollMem_Conf, CopyMem_Conf, SetBarAttributes_Conf Conformance Test. SCT Test expect return as Invalid Parameter or Unsupported. Added Checks for Function Parameters. return Invalid or Unsupported if Check fails. Added Checks in PciIoPollIo(), PciIoIoRead() PciIoIoWrite() Signed-off-by: Gaurav Jain --- Notes: v3 - Corrected Width check in PciIoIoRead, PciIoIoWrite. - Removed BarIndex check as it is already in GetBarResource(). - Moved DEV_SUPPORTED_ATTRIBUTES Macro from NonDiscoverablePciDeviceIo.= c to NonDiscoverablePciDeviceIo.h =20 v2 - Reverted ASSERT(FALSE) code. - Added Checks for Width, BarIndex, Buffer, Address range in PciIoIoRead, PciIoIoWrite. - Added Checks for Width, BarIndex, Result, Address range in PciIoPollIo, PciIoPollMem, PciIoCopyMem. - Added Checks for Attributes, BarIndex, Address range in PciIoSetBarAttributes. .../NonDiscoverablePciDeviceIo.c | 155 +++++++++++++++++- .../NonDiscoverablePciDeviceIo.h | 3 + 2 files changed, 155 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisco= verablePciDeviceIo.c index 2d55c9699322..c3e83003a01c 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c @@ -93,6 +93,31 @@ PciIoPollMem ( OUT UINT64 *Result ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + UINTN Count; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (Result =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Count =3D 1; + + Status =3D GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -126,6 +151,31 @@ PciIoPollIo ( OUT UINT64 *Result ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + UINTN Count; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (Result =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Count =3D 1; + + Status =3D GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -396,6 +446,29 @@ PciIoIoRead ( IN OUT VOID *Buffer ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_STATUS Status; + + if ((UINT32)Width >=3D EfiPciIoWidthMaximum) { + return EFI_INVALID_PARAMETER; + } + + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status =3D GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -425,6 +498,29 @@ PciIoIoWrite ( IN OUT VOID *Buffer ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_STATUS Status; + + if ((UINT32)Width >=3D EfiPciIoWidthMaximum) { + return EFI_INVALID_PARAMETER; + } + + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status =3D GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -556,6 +652,35 @@ PciIoCopyMem ( IN UINTN Count ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *DestDesc; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *SrcDesc; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status =3D GetBarResource (Dev, DestBarIndex, &DestDesc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (DestOffset + (Count << (Width & 0x3)) > DestDesc->AddrLen) { + return EFI_UNSUPPORTED; + } + + Status =3D GetBarResource (Dev, SrcBarIndex, &SrcDesc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (SrcOffset + (Count << (Width & 0x3)) > SrcDesc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -1265,9 +1390,6 @@ PciIoAttributes ( NON_DISCOVERABLE_PCI_DEVICE *Dev; BOOLEAN Enable; =20 - #define DEV_SUPPORTED_ATTRIBUTES \ - (EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) - Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); =20 if ((Attributes & (~(DEV_SUPPORTED_ATTRIBUTES))) !=3D 0) { @@ -1414,6 +1536,33 @@ PciIoSetBarAttributes ( IN OUT UINT64 *Length ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_PCI_IO_PROTOCOL_WIDTH Width; + UINTN Count; + EFI_STATUS Status; + + if ((Attributes & (~DEV_SUPPORTED_ATTRIBUTES)) !=3D 0) { + return EFI_UNSUPPORTED; + } + + if (Offset =3D=3D NULL || Length =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Width =3D EfiPciIoWidthUint8; + Count =3D (UINT32) *Length; + + Status =3D GetBarResource(Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (*Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceIo.h b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisco= verablePciDeviceIo.h index 6511fbb13770..15541c281153 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.h +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.h @@ -30,6 +30,9 @@ CR (PciIoPointer, NON_DISCOVERABLE_PCI_DEVICE, PciIo, \ NON_DISCOVERABLE_PCI_DEVICE_SIG) =20 +#define DEV_SUPPORTED_ATTRIBUTES \ + (EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) + #define PCI_ID_VENDOR_UNKNOWN 0xffff #define PCI_ID_DEVICE_DONTCARE 0x0000 =20 --=20 2.17.1