From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector1-arm-com header.b=L6ag4c6c; spf=pass (domain: arm.com, ip: 40.107.1.48, mailfrom: krzysztof.koch@arm.com) Received: from EUR02-HE1-obe.outbound.protection.outlook.com (EUR02-HE1-obe.outbound.protection.outlook.com [40.107.1.48]) by groups.io with SMTP; Thu, 16 May 2019 03:11:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7OMxRh35ywHBXd8u6WaniEHsPWAHp4v5M2UCdi4gznM=; b=L6ag4c6cmWeHgJRg3iULZ/jClRPxK2AKKxIsLpCP2JrhX/vhm+LdlZR06lgU8o162kFyNqkUtGS/HiTtHOUbAZERDrsZAcb2+PC3WO5d6pHRjdj7DrdQnYc3ufCQkgCEEhV8S3pIqILKwet53a7EHrK+4Nsm2Bsfki1jB92uCKo= Received: from VI1PR08CA0229.eurprd08.prod.outlook.com (2603:10a6:802:15::38) by DBBPR08MB4775.eurprd08.prod.outlook.com (2603:10a6:10:d5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1878.24; Thu, 16 May 2019 10:11:44 +0000 Received: from VE1EUR03FT055.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::200) by VI1PR08CA0229.outlook.office365.com (2603:10a6:802:15::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1900.16 via Frontend Transport; Thu, 16 May 2019 10:11:44 +0000 Authentication-Results: spf=temperror (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT055.mail.protection.outlook.com (10.152.19.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.1856.11 via Frontend Transport; Thu, 16 May 2019 10:11:43 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Thu, 16 May 2019 10:11:40 +0000 Received: from E119924.Arm.com (10.1.37.21) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Thu, 16 May 2019 10:11:40 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [PATCH v1 2/3] DynamicTablesPkg: Test for duplicate UIDs in MADT generator Date: Thu, 16 May 2019 11:11:32 +0100 Message-ID: <20190516101133.34912-3-krzysztof.koch@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20190516101133.34912-1-krzysztof.koch@arm.com> References: <20190516101133.34912-1-krzysztof.koch@arm.com> Return-Path: Krzysztof.Koch@arm.com MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:40.67.248.234;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(376002)(346002)(396003)(136003)(39860400002)(2980300002)(189003)(199004)(53416004)(6916009)(76176011)(6666004)(48376002)(50466002)(356004)(186003)(68736007)(26005)(77096007)(16586007)(316002)(70586007)(70206006)(1076003)(47776003)(5660300002)(86362001)(14444005)(2906002)(305945005)(478600001)(4326008)(44832011)(53936002)(426003)(63370400001)(2616005)(486006)(11346002)(126002)(336012)(8936002)(476003)(81156014)(81166006)(72206003)(446003)(2351001)(63350400001)(36756003)(54906003)(7696005)(51416003)(8676002)(50226002);DIR:OUT;SFP:1101;SCL:1;SRVR:DBBPR08MB4775;H:nebula.arm.com;FPR:;SPF:TempError;LANG:en;PTR:InfoDomainNonexistent;MX:1;A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c5d1161-4b8b-47c3-afaa-08d6d9e6e537 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328);SRVR:DBBPR08MB4775; X-MS-TrafficTypeDiagnostic: DBBPR08MB4775: NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 0039C6E5C5 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: WGnTyTgoTEqRX2AIiMZuOEWAa2FQzRzqDc53lnluuPe9/bbIzkmO1rRLzAcVYs3JqVX4Mz+PptNpIbtm4m9GRqpTNxBsgtN+W0DQqMYaKB0z4rtgAwOeNPWCUoxDC3A17fxVFqqOW5BbG6cXm94lP8XowVneAZ7KRC8hVgmL6v93+9tGciFT+Qx9/xBJ4mcYl2bi8rkdUVv8q2UmiGmE/X841z9ILmBy0XQrWDjpIQk9hglwFK8bhjU9grSKzR4lXeDOOZwJFMYVRBidj/ZU+HJeS+gkGRmw0AedBYEJz07x0GuLwWfIhsm0YFMGCaT0+mQbn4MZqqRMifWcVfFeqYaaQANn5sCG+Bhkr+5dho7R7vLI/I5XzHFNmKf+yhXdl7CRjesnLvRg9b7bbngVk1QiwO6UjU19GBWOhq9ayZ8= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2019 10:11:43.0070 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c5d1161-4b8b-47c3-afaa-08d6d9e6e537 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4775 Content-Type: text/plain Check for duplicate ACPI Processor UIDs when populating the GIC CPU (GICC) Interface structures inside the MADT table generator. Signed-off-by: Krzysztof Koch --- Notes: v1: - Detect duplicate ACPI Processor UIDs in GICCs [Krzysztof] DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c | 90 ++++++++++++++++++-- 1 file changed, 83 insertions(+), 7 deletions(-) diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c index ab9734fb31480f1b653227d1d56abf60bb04f98a..613bf665d9cecc6495f5ac84c2515ea89f476194 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c @@ -140,28 +140,96 @@ AddGICC ( Gicc->Reserved2[2] = EFI_ACPI_RESERVED_BYTE; } +/** + Function to test if two GIC CPU Interface information structures have the + same ACPI Processor UID. + + @param [in] GicCInfo1 Pointer to the first GICC info structure. + @param [in] GicCInfo2 Pointer to the second GICC info structure. + @param [in] Index1 Index of GicCInfo1 in the shared list of GIC + CPU Interface Info structures. + @param [in] Index2 Index of GicCInfo2 in the shared list of GIC + CPU Interface Info structures. + + @retval TRUE GicCInfo1 and GicCInfo2 have the same UID. + @retval FALSE GicCInfo1 and GicCInfo2 have different UIDs. +**/ +BOOLEAN +EFIAPI +IsAcpiUidEqual ( + IN CONST VOID * GicCInfo1, + IN CONST VOID * GicCInfo2, + IN UINTN Index1, + IN UINTN Index2 + ) +{ + UINT32 Uid1; + UINT32 Uid2; + + ASSERT ((GicCInfo1 != NULL) && (GicCInfo2 != NULL)); + + Uid1 = ((CM_ARM_GICC_INFO*)GicCInfo1)->AcpiProcessorUid; + Uid2 = ((CM_ARM_GICC_INFO*)GicCInfo2)->AcpiProcessorUid; + + if (Uid1 == Uid2) { + DEBUG (( + DEBUG_ERROR, + "ERROR: MADT: GICC Info Structures %d and %d have the same ACPI " \ + "Processor UID: 0x%x.\n", + Index1, + Index2, + Uid1 + )); + return TRUE; + } + + return FALSE; +} + /** Add the GIC CPU Interface Information to the MADT Table. - @param [in] Gicc Pointer to GIC CPU Interface - structure list. - @param [in] GicCInfo Pointer to the GIC CPU - Information list. - @param [in] GicCCount Count of GIC CPU Interfaces. + This function also checks for duplicate ACPI Processor UIDs. + + @param [in] Gicc Pointer to GIC CPU Interface structure list. + @param [in] GicCInfo Pointer to the GIC CPU Information list. + @param [in] GicCCount Count of GIC CPU Interfaces. + + @retval EFI_SUCCESS GIC CPU Interface Information was added + successfully. + @retval EFI_INVALID_PARAMETER One or more invalid GIC CPU Info values were + provided and the generator failed to add the + information to the table. **/ STATIC -VOID +EFI_STATUS AddGICCList ( IN EFI_ACPI_6_2_GIC_STRUCTURE * Gicc, IN CONST CM_ARM_GICC_INFO * GicCInfo, IN UINT32 GicCCount ) { + BOOLEAN IsAcpiProcUidDuplicated; + ASSERT (Gicc != NULL); ASSERT (GicCInfo != NULL); + IsAcpiProcUidDuplicated = FindDuplicateValue ( + GicCInfo, + GicCCount, + sizeof (CM_ARM_GICC_INFO), + IsAcpiUidEqual + ); + // Duplicate ACPI Processor UID was found so the GICC info provided + // is invalid + if (IsAcpiProcUidDuplicated) { + return EFI_INVALID_PARAMETER; + } + while (GicCCount-- != 0) { AddGICC (Gicc++, GicCInfo++); } + + return EFI_SUCCESS; } /** Update the GIC Distributor Information in the MADT Table. @@ -577,11 +645,19 @@ BuildMadtTable ( goto error_handler; } - AddGICCList ( + Status = AddGICCList ( (EFI_ACPI_6_2_GIC_STRUCTURE*)((UINT8*)Madt + GicCOffset), GicCInfo, GicCCount ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: MADT: Failed to add GICC structures. Status = %r\n", + Status + )); + goto error_handler; + } AddGICD ( (EFI_ACPI_6_2_GIC_DISTRIBUTOR_STRUCTURE*)((UINT8*)Madt + GicDOffset), -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'