From nobody Mon Feb 9 12:15:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+70549+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70549+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611071693; cv=none; d=zohomail.com; s=zohoarc; b=JrInUle1U4n+Y8lbWE2HH/b/66mou068cVDFa6YccaJcmcZSYziqg/Zb/0vVNo0/iRXILNJ+ZAjRWXz0G+U0eZa4Mbj6Q+QgKvA21KIF/4gMyG0l4QJ85QmRnvqnNumB6IRfRHISronzeMGQgdkkbZ1cu7TXQdggQeThQ4bvtGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611071693; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=xgew4vBSG7ZDQg9oxNVr6AX+nxnyDvQvfdVwLCCTFB0=; b=AvvCKQdNM9YhCJjO+MntmRQ/CXZFAhVa2ytPzyy8MyKyxrYM9tMfdb9GZmxDjIE8gvQ15Oz/cit4OphRBhjO2O5QaUVyXTgrjLPMmwGkNtB/v9vazr3Abb+5Xj40Hp2Hx5DncZ4bfTnPmt20sgkvuXKAK4lHrbkMifm+8Gjem3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70549+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1611071693482880.0204416252677; Tue, 19 Jan 2021 07:54:53 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ijJzYY1788612xTS4iFZvibG; Tue, 19 Jan 2021 07:54:53 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.13017.1611071691495311016 for ; Tue, 19 Jan 2021 07:54:52 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-186-xQgoqoD9ObaE84fIUMedEg-1; Tue, 19 Jan 2021 10:54:47 -0500 X-MC-Unique: xQgoqoD9ObaE84fIUMedEg-1 X-Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DB3CD87950E; Tue, 19 Jan 2021 15:54:45 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-176.ams2.redhat.com [10.36.114.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64CF960C5A; Tue, 19 Jan 2021 15:54:44 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Eric Dong , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rahul Kumar , Ray Ni , Star Zeng Subject: [edk2-devel] [PATCH v2 1/4] UefiCpuPkg/CpuFeature: Don't assume CpuS3DataDxe alloc RegisterTable Date: Tue, 19 Jan 2021 16:54:37 +0100 Message-Id: <20210119155440.2262-2-lersek@redhat.com> In-Reply-To: <20210119155440.2262-1-lersek@redhat.com> References: <20210119155440.2262-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: Zy0qWYyab0q7GeaudOWh9mMVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611071693; bh=xgew4vBSG7ZDQg9oxNVr6AX+nxnyDvQvfdVwLCCTFB0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=WpEuVdh57kJauIXKKwKHHymvX1eBug8Dl6xLdtfzBlRaWX26FxEbnW6yQV6JQIDxrAh UNyvBgSe1rt+1Sj/eh5cTQBd/4og0an5fuHVcSF0VP7REoROVCJ2f7jns8xIworrPTVMY U1nANDoFZIsZ2pOmerrUy0rMeCJM6iRF7e8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Ray Ni There are lots of fields in ACPI_CPU_DATA structure while only followings are accessed by CpuFeature infra: * NumberOfCpus * PreSmmInitRegisterTable // pointer * RegisterTable // pointer * CpuStatus * ApLocation // pointer So it's possible that an implementation of CpuS3DataDxe doesn't allocate memory for PreSmmInitRegisterTable/RegisterTable/ApLocation. This patch handles the case when CpuS3DataDxe doesn't allocate memory for PreSmmInitRegisterTable/RegisterTable. Cc: Eric Dong Cc: Philippe Mathieu-Daud=C3=A9 Cc: Rahul Kumar Cc: Ray Ni Cc: Star Zeng Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3159 Signed-off-by: Ray Ni [lersek@redhat.com: update CC list, add BZ reference, add my S-o-b] [lersek@redhat.com: deal with RegisterTable and PreSmmInitRegisterTable being zero independently of each other; replacing the ASSERT()] Signed-off-by: Laszlo Ersek --- Notes: v2: =20 - new patch, cherry-picked from =20 - Update as follows: do not assume that (RegisterTable =3D=3D 0) implies (PreSmmInitRegisterTable =3D=3D 0). The ACPI_CPU_DATA documentation u= pdate in the next patch permits each field to be zero in separation, and updating Ray's patch for accommodating that is not difficult. Some normal RAM may be wasted if exactly one of the "RegisterTable" and "PreSmmInitRegisterTable" fields is zero (the memory is allocated with the PEI or DXE instance of MemoryAllocationLib). =20 - this patch is easiest to review with "git show -b -W" UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c | 80 ++= +++++++++--------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesL= ib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c index 4063d45760ad..7bb92404027f 100644 --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c @@ -1,7 +1,7 @@ /** @file CPU Register Table Library functions. =20 - Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
+ Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -937,45 +937,51 @@ GetAcpiCpuData ( EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer; =20 AcpiCpuData =3D (ACPI_CPU_DATA *) (UINTN) PcdGet64 (PcdCpuS3DataAddress); - if (AcpiCpuData !=3D NULL) { - return AcpiCpuData; - } - - AcpiCpuData =3D AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA= ))); - ASSERT (AcpiCpuData !=3D NULL); - - // - // Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA stru= cture - // - Status =3D PcdSet64S (PcdCpuS3DataAddress, (UINT64)(UINTN)AcpiCpuData); - ASSERT_EFI_ERROR (Status); - - GetNumberOfProcessor (&NumberOfCpus, &NumberOfEnabledProcessors); - AcpiCpuData->NumberOfCpus =3D (UINT32)NumberOfCpus; - - // - // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable f= or all CPUs - // - TableSize =3D 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); - RegisterTable =3D AllocatePages (EFI_SIZE_TO_PAGES (TableSize)); - ASSERT (RegisterTable !=3D NULL); - - for (Index =3D 0; Index < NumberOfCpus; Index++) { - Status =3D GetProcessorInformation (Index, &ProcessorInfoBuffer); + if (AcpiCpuData =3D=3D NULL) { + AcpiCpuData =3D AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DA= TA))); + ASSERT (AcpiCpuData !=3D NULL); + ZeroMem (AcpiCpuData, sizeof (ACPI_CPU_DATA)); + + // + // Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA st= ructure + // + Status =3D PcdSet64S (PcdCpuS3DataAddress, (UINT64)(UINTN)AcpiCpuData); ASSERT_EFI_ERROR (Status); =20 - RegisterTable[Index].InitialApicId =3D (UINT32)ProcessorInfoBuffe= r.ProcessorId; - RegisterTable[Index].TableLength =3D 0; - RegisterTable[Index].AllocatedSize =3D 0; - RegisterTable[Index].RegisterTableEntry =3D 0; - - RegisterTable[NumberOfCpus + Index].InitialApicId =3D (UINT32)Pro= cessorInfoBuffer.ProcessorId; - RegisterTable[NumberOfCpus + Index].TableLength =3D 0; - RegisterTable[NumberOfCpus + Index].AllocatedSize =3D 0; - RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D 0; + GetNumberOfProcessor (&NumberOfCpus, &NumberOfEnabledProcessors); + AcpiCpuData->NumberOfCpus =3D (UINT32)NumberOfCpus; + } + + if (AcpiCpuData->RegisterTable =3D=3D 0 || + AcpiCpuData->PreSmmInitRegisterTable =3D=3D 0) { + // + // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable= for all CPUs + // + TableSize =3D 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); + RegisterTable =3D AllocatePages (EFI_SIZE_TO_PAGES (TableSize)); + ASSERT (RegisterTable !=3D NULL); + + for (Index =3D 0; Index < NumberOfCpus; Index++) { + Status =3D GetProcessorInformation (Index, &ProcessorInfoBuffer); + ASSERT_EFI_ERROR (Status); + + RegisterTable[Index].InitialApicId =3D (UINT32)ProcessorInfoBuf= fer.ProcessorId; + RegisterTable[Index].TableLength =3D 0; + RegisterTable[Index].AllocatedSize =3D 0; + RegisterTable[Index].RegisterTableEntry =3D 0; + + RegisterTable[NumberOfCpus + Index].InitialApicId =3D (UINT32)P= rocessorInfoBuffer.ProcessorId; + RegisterTable[NumberOfCpus + Index].TableLength =3D 0; + RegisterTable[NumberOfCpus + Index].AllocatedSize =3D 0; + RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D 0; + } + if (AcpiCpuData->RegisterTable =3D=3D 0) { + AcpiCpuData->RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Register= Table; + } + if (AcpiCpuData->PreSmmInitRegisterTable =3D=3D 0) { + AcpiCpuData->PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINT= N)(RegisterTable + NumberOfCpus); + } } - AcpiCpuData->RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Re= gisterTable; - AcpiCpuData->PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)(R= egisterTable + NumberOfCpus); =20 return AcpiCpuData; } --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#70549): https://edk2.groups.io/g/devel/message/70549 Mute This Topic: https://groups.io/mt/79954424/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-