From nobody Fri May 3 00:40:19 2024 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- From nobody Fri May 3 00:40:19 2024 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+70551+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+70551+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611071698; cv=none; d=zohomail.com; s=zohoarc; b=IxjSfl2WOHpMT2zz6rAB+UCkrbSm9z9UVl2jw2K8egp+fUOd8hOBYLbIejJZSEtO6kMEzM/XzX3LP9gfWY6TOho9AoqTyjkz8EpxdNEw/2H/5h4+FOHz+4GVb2JnPw2Y2gFd6Y0pZvJ0ajyVdo5fe0WWZR24Lo0u9aYKPaWBh84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611071698; 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=LaoZEWpFQD8qkiUmgIfG9fGI6+TWfek04irPwzOthao=; b=CCFYqd4EvzNEcdM+SdjcrKsS4GYXDPexTkx3y9HhUHjARhiKTmqX9yc2v1+RLSvdg/zjIibmyptzKo1sFDCgRgESbxpvYc772zUpJ2kCABkL8e0gfTI34U5D35yLOcqstSwhddc0nAnE7NNcr6nKEzIqQc79H0DTJ0fV7XhLU9Y= 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+70551+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 1611071698940889.8695146776059; Tue, 19 Jan 2021 07:54:58 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id eLS9YY1788612xCr79gvmnYI; Tue, 19 Jan 2021 07:54:58 -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.web09.12946.1611071695461027094 for ; Tue, 19 Jan 2021 07:54:55 -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-552-l-6t2AAPOsuevTfg51W4Ew-1; Tue, 19 Jan 2021 10:54:50 -0500 X-MC-Unique: l-6t2AAPOsuevTfg51W4Ew-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 A2DEC3E74B; Tue, 19 Jan 2021 15:54:49 +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 2FDC160CCB; Tue, 19 Jan 2021 15:54:47 +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 2/4] UefiCpuPkg/AcpiCpuData: update comments on register table fields Date: Tue, 19 Jan 2021 16:54:38 +0100 Message-Id: <20210119155440.2262-3-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: w2gZAmQB0TCcaAYKyxvVjYf7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611071698; bh=LaoZEWpFQD8qkiUmgIfG9fGI6+TWfek04irPwzOthao=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=CummjoB9PLSNpPj/E+64dbytG3Yuj1K9mnZpq07I2ITzPd6iXDTRld5IV/lA5XAVc3m T8KW2ucoGjjqMvDjVo3jLvJDxk5ZxMA7ifHFiXHw1ykixNFgEELbEb6gwbj21x9UGWqOJ bcOaqBAY2/X3cYYh7XoIeeETGYmZG709wKI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" After commit e992cc3f4859 ("UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption in CpuS3.c", 2021-01-11), it is valid for a CPU S3 Data DXE Driver to set "ACPI_CPU_DATA.PreSmmInitRegisterTable" and/or "ACPI_CPU_DATA.RegisterTable" to 0, in case none of the CPUs needs a register table of the corresponding kind, during S3 resume. Document this fact in the "UefiCpuPkg/Include/AcpiCpuData.h" header file. 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: Laszlo Ersek Reviewed-by: Ray Ni Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Notes: v2: =20 - no changes, pick up feedback tags UefiCpuPkg/Include/AcpiCpuData.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UefiCpuPkg/Include/AcpiCpuData.h b/UefiCpuPkg/Include/AcpiCpuD= ata.h index b5a69ad80c88..62a01b2c6bac 100644 --- a/UefiCpuPkg/Include/AcpiCpuData.h +++ b/UefiCpuPkg/Include/AcpiCpuData.h @@ -178,6 +178,8 @@ typedef struct { // If TableLength is > 0, then elements of RegisterTableEntry are used to // initialize the CPU that matches InitialApicId, during an ACPI S3 resu= me, // before SMBASE relocation is performed. + // If a register table is not required for any one of the CPUs, then + // PreSmmInitRegisterTable may be set to 0. // EFI_PHYSICAL_ADDRESS PreSmmInitRegisterTable; // @@ -187,6 +189,8 @@ typedef struct { // If TableLength is > 0, then elements of RegisterTableEntry are used to // initialize the CPU that matches InitialApicId, during an ACPI S3 resu= me, // after SMBASE relocation is performed. + // If a register table is not required for any one of the CPUs, then + // RegisterTable may be set to 0. // EFI_PHYSICAL_ADDRESS RegisterTable; // --=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 (#70551): https://edk2.groups.io/g/devel/message/70551 Mute This Topic: https://groups.io/mt/79954427/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- From nobody Fri May 3 00:40:19 2024 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+70550+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+70550+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611071698; cv=none; d=zohomail.com; s=zohoarc; b=id4cTw38CqUsPEbHWdjEfSy+lSEhTZMe6peXv+ZId2ZnukwPfXUpv1dGbO6AgUj98rVGhoCLg+s2IJwijSSB/qn+cmbiv9r5gH7phjWiu2aKub5+hC+rgwV+ck2s14x6A8he/QoujaZYkbw3+15cAFVkruzecWd9GbVSK4WFqKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611071698; 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=32Lr/pFLTIwvML4wKqNooLGayr5oeFcu2nfHBbeFSUE=; b=geUl0JZminnILh0Qv0waOsICICYwT5/+cVP9HZw96MoqxTO71dpan2D9lHNmGeGolgA2rLoA09UlbQ1TIj56n0SaYm+38+60wPRKlBdp61JNzh5jGlIc2SbR1PcrkB7JiFFxvE6QraODG+aMQBe1TLXr6zH+aKDxjgICxy4/DB8= 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+70550+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 1611071698313893.0031492388205; Tue, 19 Jan 2021 07:54:58 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id eYPiYY1788612xkx3btMtSf1; Tue, 19 Jan 2021 07:54:55 -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.web09.12945.1611071695379241745 for ; Tue, 19 Jan 2021 07:54:55 -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-578-av2DEKd7MTGl9n1fjwSm3w-1; Tue, 19 Jan 2021 10:54:52 -0500 X-MC-Unique: av2DEKd7MTGl9n1fjwSm3w-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 75B80800D62; Tue, 19 Jan 2021 15:54:51 +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 02DBF614ED; Tue, 19 Jan 2021 15:54:49 +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 3/4] UefiCpuPkg/CpuS3DataDxe: do not allocate useless register tables Date: Tue, 19 Jan 2021 16:54:39 +0100 Message-Id: <20210119155440.2262-4-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: BdUqTpKZDW1tvm4143X3AGcXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611071695; bh=32Lr/pFLTIwvML4wKqNooLGayr5oeFcu2nfHBbeFSUE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=gRgFISw/xBSvIRym7S0/MIGZSU08MnpuFjSGcJz/ZpL+zdbgwJRKW3ADWZ8SFzKU7fm 5iDUYugLeO4MNuR04bRktHLw157tUvv8iIXTnbB+FRv4454+PP+RDCLvp5jFfrGxEzMpB gUaxi7ILDHaa4vmDRM4iGlfb7/oFF0xaLQU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" CpuS3DataDxe allocates the "RegisterTable" and "PreSmmInitRegisterTable" arrays in ACPI_CPU_DATA just so every processor in the system can have its own empty register table, matched by APIC ID. This has never been useful in practice. Given commit e992cc3f4859 ("UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption in CpuS3.c", 2021-01-11), simply leave both "AcpiCpuData->RegisterTable" and "AcpiCpuData->PreSmmInitRegisterTable" initialized to the zero address. This simplifies the driver, and saves both normal RAM (boot services data type memory) and -- in PiSmmCpuDxeSmm -- SMRAM. 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: Laszlo Ersek Reviewed-by: Ray Ni --- Notes: v2: =20 - no changes, pick up feedback tags =20 v1: =20 - Tested by temporarily replacing OvmfPkgPkg/CpuS3DataDxe in the OVMF IA32 and IA32X64 platforms with this driver -- this driver works OK in OVMF as long as no CPUs are hot-plugged. UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c | 32 -------------------- 1 file changed, 32 deletions(-) diff --git a/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c b/UefiCpuPkg/CpuS3DataDxe/= CpuS3Data.c index 2be335d91903..078af36cfb41 100644 --- a/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c +++ b/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c @@ -165,10 +165,6 @@ CpuS3DataInitialize ( UINTN NumberOfCpus; UINTN NumberOfEnabledProcessors; VOID *Stack; - UINTN TableSize; - CPU_REGISTER_TABLE *RegisterTable; - UINTN Index; - EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer; UINTN GdtSize; UINTN IdtSize; VOID *Gdt; @@ -255,34 +251,6 @@ CpuS3DataInitialize ( AcpiCpuData->PreSmmInitRegisterTable =3D OldAcpiCpuData->PreSmmInitReg= isterTable; AcpiCpuData->ApLocation =3D OldAcpiCpuData->ApLocation; CopyMem (&AcpiCpuData->CpuStatus, &OldAcpiCpuData->CpuStatus, sizeof (= CPU_STATUS_INFORMATION)); - } else { - // - // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable= for all CPUs - // - TableSize =3D 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); - RegisterTable =3D (CPU_REGISTER_TABLE *)AllocateZeroPages (TableSize); - ASSERT (RegisterTable !=3D NULL); - - for (Index =3D 0; Index < NumberOfCpus; Index++) { - Status =3D MpServices->GetProcessorInfo ( - MpServices, - 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; - } - AcpiCpuData->RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)= RegisterTable; - AcpiCpuData->PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)= (RegisterTable + NumberOfCpus); } =20 // --=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 (#70550): https://edk2.groups.io/g/devel/message/70550 Mute This Topic: https://groups.io/mt/79954426/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- From nobody Fri May 3 00:40:19 2024 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+70552+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+70552+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611071703; cv=none; d=zohomail.com; s=zohoarc; b=K5opyomznPUCN8M+vSu6zWXRubDpuy7UZtqFlkoty54Lqnru7bG9leuht4W2PxQdawb+/OYCVazrBYwRcWkCOi4S/AtgkCEQ3TVmIZe9l4C/yTGUh1fqE2EoWpgGJndVgiQD5rmwzE3FCMcM9HUqYxVPM3NAxkwDilzKkL/sVGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611071703; 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=wYMPWBX+324WTVHgr+NsTOP50N4rZb4uJVeWbg/H2RU=; b=SkDTZNENBnTNt0wugx3UAqaNG92HmF+IgM0NY4B1aLodA1tOSvvhgPwFMVDEPjTcooGQmEVZeWqeq4gWCXB1xwvs2c4bcw8rjX4trHonfKrLy6H4nzm0cNFeIjQTuw/q8xC9Af61WxBmu4gU+zJX7JDsyVleruNOEgBSuUm0MCA= 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+70552+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 1611071703245463.5059332321712; Tue, 19 Jan 2021 07:55:03 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id qqKcYY1788612xL72cs5OVN8; Tue, 19 Jan 2021 07:55:02 -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.web11.13009.1611071697190688416 for ; Tue, 19 Jan 2021 07:54:57 -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-106-5T3d73O7P3Oh_RXbzCsUpw-1; Tue, 19 Jan 2021 10:54:54 -0500 X-MC-Unique: 5T3d73O7P3Oh_RXbzCsUpw-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 E7F2A8015D0; Tue, 19 Jan 2021 15:54:52 +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 CAAB860CCB; Tue, 19 Jan 2021 15:54:51 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [PATCH v2 4/4] OvmfPkg/CpuS3DataDxe: do not allocate useless register tables Date: Tue, 19 Jan 2021 16:54:40 +0100 Message-Id: <20210119155440.2262-5-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: 4CzJqthy8pVsxnGBZSiG49gCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611071702; bh=wYMPWBX+324WTVHgr+NsTOP50N4rZb4uJVeWbg/H2RU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=xAnESLpLuSyiPSmS5GPdfQqbsaWpLy5rtPMGd+uI108+om46t9/APlWjmLaeWaa5Tpl J+g94zeStRUc1+slqdHFgFMj4kZcNcGdJ1ROdJjw6HMX4tjJC03qxUnj7avQzBsGBQf7Q RC07q9TkHv53GdallyQEdGRNdmKmjqTWiyg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" CpuS3DataDxe allocates the "RegisterTable" and "PreSmmInitRegisterTable" arrays in ACPI_CPU_DATA just so every processor in the system can have its own empty register table, matched by APIC ID. This has never been useful in practice. Given commit e992cc3f4859 ("UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption in CpuS3.c", 2021-01-11), simply leave both "AcpiCpuData->RegisterTable" and "AcpiCpuData->PreSmmInitRegisterTable" initialized to the zero address. This simplifies the driver, and saves both normal RAM (boot services data type memory) and -- in PiSmmCpuDxeSmm -- SMRAM. (This simplification backs out a good chunk of commit 1158fc8e2c7b ("OvmfPkg/CpuS3DataDxe: enable S3 resume after CPU hotplug", 2020-03-04). But CpuS3DataDxe still differs between UefiCpuPkg and OvmfPkg, due to the latter supporting CPU hotplug; thus, we can't remove OvmfPkg/CpuS3DataDxe altogether.) Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3159 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- Notes: v2: =20 - no changes, pick up feedback tags OvmfPkg/CpuS3DataDxe/CpuS3DataDxe.inf | 1 - OvmfPkg/CpuS3DataDxe/CpuS3Data.c | 70 +------------------- 2 files changed, 1 insertion(+), 70 deletions(-) diff --git a/OvmfPkg/CpuS3DataDxe/CpuS3DataDxe.inf b/OvmfPkg/CpuS3DataDxe/C= puS3DataDxe.inf index ceae1d4078c7..228d5ae1b260 100644 --- a/OvmfPkg/CpuS3DataDxe/CpuS3DataDxe.inf +++ b/OvmfPkg/CpuS3DataDxe/CpuS3DataDxe.inf @@ -42,7 +42,6 @@ [LibraryClasses] BaseLib BaseMemoryLib DebugLib - IoLib MemoryAllocationLib MtrrLib UefiBootServicesTableLib diff --git a/OvmfPkg/CpuS3DataDxe/CpuS3Data.c b/OvmfPkg/CpuS3DataDxe/CpuS3D= ata.c index bac7285aa2f3..5ffe1f3cd74e 100644 --- a/OvmfPkg/CpuS3DataDxe/CpuS3Data.c +++ b/OvmfPkg/CpuS3DataDxe/CpuS3Data.c @@ -23,7 +23,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include #include #include #include @@ -31,9 +30,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include =20 -#include -#include - // // Data structure used to allocate ACPI_CPU_DATA and its supporting struct= ures // @@ -168,17 +164,12 @@ CpuS3DataInitialize ( EFI_MP_SERVICES_PROTOCOL *MpServices; UINTN NumberOfCpus; VOID *Stack; - UINTN TableSize; - CPU_REGISTER_TABLE *RegisterTable; - UINTN Index; - EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer; UINTN GdtSize; UINTN IdtSize; VOID *Gdt; VOID *Idt; EFI_EVENT Event; ACPI_CPU_DATA *OldAcpiCpuData; - BOOLEAN FetchPossibleApicIds; =20 if (!PcdGetBool (PcdAcpiS3Enable)) { return EFI_UNSUPPORTED; @@ -193,13 +184,7 @@ CpuS3DataInitialize ( ASSERT (AcpiCpuDataEx !=3D NULL); AcpiCpuData =3D &AcpiCpuDataEx->AcpiCpuData; =20 - // - // The "SMRAM at default SMBASE" feature guarantees that - // QEMU_CPUHP_CMD_GET_ARCH_ID too is available. - // - FetchPossibleApicIds =3D PcdGetBool (PcdQ35SmramAtDefaultSmbase); - - if (FetchPossibleApicIds) { + if (PcdGetBool (PcdQ35SmramAtDefaultSmbase)) { NumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber); } else { UINTN NumberOfEnabledProcessors; @@ -271,59 +256,6 @@ CpuS3DataInitialize ( AcpiCpuData->PreSmmInitRegisterTable =3D OldAcpiCpuData->PreSmmInitReg= isterTable; AcpiCpuData->ApLocation =3D OldAcpiCpuData->ApLocation; CopyMem (&AcpiCpuData->CpuStatus, &OldAcpiCpuData->CpuStatus, sizeof (= CPU_STATUS_INFORMATION)); - } else { - // - // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable= for all CPUs - // - TableSize =3D 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); - RegisterTable =3D (CPU_REGISTER_TABLE *)AllocateZeroPages (TableSize); - ASSERT (RegisterTable !=3D NULL); - - if (FetchPossibleApicIds) { - // - // Write a valid selector so that other hotplug registers can be - // accessed. - // - IoWrite32 (ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_W_CPU_SEL, 0); - // - // We'll be fetching the APIC IDs. - // - IoWrite8 (ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_W_CMD, - QEMU_CPUHP_CMD_GET_ARCH_ID); - } - for (Index =3D 0; Index < NumberOfCpus; Index++) { - UINT32 InitialApicId; - - if (FetchPossibleApicIds) { - IoWrite32 (ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_W_CPU_SEL, - (UINT32)Index); - InitialApicId =3D IoRead32 ( - ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_RW_CMD_DATA); - } else { - Status =3D MpServices->GetProcessorInfo ( - MpServices, - Index, - &ProcessorInfoBuffer - ); - ASSERT_EFI_ERROR (Status); - InitialApicId =3D (UINT32)ProcessorInfoBuffer.ProcessorId; - } - - DEBUG ((DEBUG_VERBOSE, "%a: Index=3D%05Lu ApicId=3D0x%08x\n", __FUNC= TION__, - (UINT64)Index, InitialApicId)); - - RegisterTable[Index].InitialApicId =3D InitialApicId; - RegisterTable[Index].TableLength =3D 0; - RegisterTable[Index].AllocatedSize =3D 0; - RegisterTable[Index].RegisterTableEntry =3D 0; - - RegisterTable[NumberOfCpus + Index].InitialApicId =3D InitialAp= icId; - RegisterTable[NumberOfCpus + Index].TableLength =3D 0; - RegisterTable[NumberOfCpus + Index].AllocatedSize =3D 0; - RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D 0; - } - AcpiCpuData->RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)= RegisterTable; - AcpiCpuData->PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)= (RegisterTable + NumberOfCpus); } =20 // --=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 (#70552): https://edk2.groups.io/g/devel/message/70552 Mute This Topic: https://groups.io/mt/79954428/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-