From nobody Thu May 16 00:42:12 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+98887+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+98887+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674126104; cv=none; d=zohomail.com; s=zohoarc; b=hqWSgNQPn+90frPXyOT6dTs/tFKP09HfvG15F+bhSds5TXoHb3kwzxi4csDsX2xWax7oNkhhB+x14kiZvcPLJ6Erz9upcrpzlbEE/h/CFaNDgPxhsXGU+SxsSScHmrpICHsRxYgEQONWX3+VgxcrXUrF7Il08YVa+jbmiA7rV/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674126104; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=oZ2YKSVSkDsN0VE6TR2ZWL/DXJykgc9tzNJ6v02IbIo=; b=H1HAkSy2mgVfJEHiSpW3FX0s6og1Weo9ZJVOj0Y8UckZypADsvgG8+HHEeaU1T2NAEdo/VQAt+F2TPTxz/Lf/6doUCS/1PW5PXlPbglhueaNy3W8+JZZCgH39slcM8BQ/UrEkhqb/09r0l6jO8/uBj/cGu/DOkevQz90qx50DJo= 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+98887+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674126104685561.0791699906673; Thu, 19 Jan 2023 03:01:44 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id fR3QYY1788612xGPlR2BRTqx; Thu, 19 Jan 2023 03:01:44 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.42550.1674126103295128692 for ; Thu, 19 Jan 2023 03:01:43 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-113-gZuTeppKPvutukB-YDwsXA-1; Thu, 19 Jan 2023 06:01:41 -0500 X-MC-Unique: gZuTeppKPvutukB-YDwsXA-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 995CC805564; Thu, 19 Jan 2023 11:01:40 +0000 (UTC) X-Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC3A7140EBF4; Thu, 19 Jan 2023 11:01:37 +0000 (UTC) From: "Laszlo Ersek" To: lersek@redhat.com, devel@edk2.groups.io Cc: Ard Biesheuvel , Brijesh Singh , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Jordan Justen , Michael Brown , Min Xu , Oliver Steffen , Sebastien Boeuf , Tom Lendacky Subject: [edk2-devel] [PATCH v3 1/2] OvmfPkg/PlatformInitLib: factor out PlatformCpuCountBugCheck() Date: Thu, 19 Jan 2023 12:01:30 +0100 Message-Id: <20230119110131.91923-2-lersek@redhat.com> In-Reply-To: <20230119110131.91923-1-lersek@redhat.com> References: <20230119110131.91923-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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: V0uU5PHM1zNS7L8sF6LTKcWxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674126104; bh=oZ2YKSVSkDsN0VE6TR2ZWL/DXJykgc9tzNJ6v02IbIo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=wS76IYqPuCRnd6Tic3b7y/5TqHW0ZKsUa+Dlog7KT2IYER/4iuxeviHj41hy+rahU/X V21VoNjygvjltOWXf9mATZCjY2XPc0jRb7EJYjGUyY5BYybJsmPBmXa95j2kVIi9NneyM UfwY6E5H/bAJwE/kuOLLNXf+aNJ9MDWk1EI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674126105273100005 Content-Type: text/plain; charset="utf-8"; x-default="true" Move the QEMU v2.7 reset bug check/workaround to a separate function, as we'll need to detect further issues. Cc: Ard Biesheuvel Cc: Brijesh Singh Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Jordan Justen Cc: Michael Brown Cc: Min Xu Cc: Oliver Steffen Cc: Sebastien Boeuf Cc: Tom Lendacky Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4250 Signed-off-by: Laszlo Ersek Acked-by: Gerd Hoffmann --- Notes: v3: - new patch OvmfPkg/Library/PlatformInitLib/Platform.c | 81 ++++++++++++++------ 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/Platform.c index 9ab0342fd8c0..d1be5c2d7970 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -404,6 +404,61 @@ PlatformMiscInitialization ( } } =20 +/** + Check for various QEMU bugs concerning CPU numbers. + + Compensate for those bugs if various conditions are satisfied, by updati= ng a + suitable subset of the input-output parameters. The function may not ret= urn + (it may hang deliberately), even in RELEASE builds, if the QEMU bug is + impossible to cover up. + + @param[in,out] BootCpuCount On input, the boot CPU count reported by QE= MU via + fw_cfg (QemuFwCfgItemSmpCpuCount). The call= er is + responsible for ensuring (BootCpuCount > 0)= ; that + is, if QEMU does not provide the boot CPU c= ount + via fw_cfg *at all*, then this function mus= t not + be called. + + @param[in,out] Present On input, the number of present-at-boot CPU= s, as + reported by QEMU through the modern CPU hot= plug + register block. + + @param[in,out] Possible On input, the number of possible CPUs, as + reported by QEMU through the modern CPU hot= plug + register block. +**/ +STATIC +VOID +PlatformCpuCountBugCheck ( + IN OUT UINT16 *BootCpuCount, + IN OUT UINT32 *Present, + IN OUT UINT32 *Possible + ) +{ + ASSERT (*BootCpuCount > 0); + + // + // Sanity check: fw_cfg and the modern CPU hotplug interface should expo= se the + // same boot CPU count. + // + if (*BootCpuCount !=3D *Present) { + DEBUG (( + DEBUG_WARN, + "%a: QEMU v2.7 reset bug: BootCpuCount=3D%d Present=3D%u\n", + __FUNCTION__, + *BootCpuCount, + *Present + )); + // + // The handling of QemuFwCfgItemSmpCpuCount, across CPU hotplug plus + // platform reset (including S3), was corrected in QEMU commit e3cadac= 073a9 + // ("pc: fix FW_CFG_NB_CPUS to account for -device added CPUs", 2016-1= 1-16), + // part of release v2.8.0. + // + *BootCpuCount =3D (UINT16)*Present; + } +} + /** Fetch the boot CPU count and the possible CPU count from QEMU, and expose them to UefiCpuPkg modules. @@ -518,8 +573,8 @@ PlatformMaxCpuCountInitialization ( UINT8 CpuStatus; =20 // - // Read the status of the currently selected CPU. This will help w= ith a - // sanity check against "BootCpuCount". + // Read the status of the currently selected CPU. This will help w= ith + // various CPU count sanity checks. // CpuStatus =3D IoRead8 (CpuHpBase + QEMU_CPUHP_R_CPU_STAT); if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) !=3D 0) { @@ -540,27 +595,7 @@ PlatformMaxCpuCountInitialization ( ASSERT (Selected =3D=3D Possible || Selected =3D=3D 0); } while (Selected > 0); =20 - // - // Sanity check: fw_cfg and the modern CPU hotplug interface should - // return the same boot CPU count. - // - if (BootCpuCount !=3D Present) { - DEBUG (( - DEBUG_WARN, - "%a: QEMU v2.7 reset bug: BootCpuCount=3D%d " - "Present=3D%u\n", - __FUNCTION__, - BootCpuCount, - Present - )); - // - // The handling of QemuFwCfgItemSmpCpuCount, across CPU hotplug pl= us - // platform reset (including S3), was corrected in QEMU commit - // e3cadac073a9 ("pc: fix FW_CFG_NB_CPUS to account for -device ad= ded - // CPUs", 2016-11-16), part of release v2.8.0. - // - BootCpuCount =3D (UINT16)Present; - } + PlatformCpuCountBugCheck (&BootCpuCount, &Present, &Possible); =20 MaxCpuCount =3D Possible; } -=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 (#98887): https://edk2.groups.io/g/devel/message/98887 Mute This Topic: https://groups.io/mt/96374973/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 Thu May 16 00:42:12 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+98888+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+98888+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674126114; cv=none; d=zohomail.com; s=zohoarc; b=YrE3ziVaG3/YrF8yuF7pZn+4REgrDrUG7CtNQNqoQV4VErUKOTeTDSQVbFeloZnedt+iMYT+Eho+A32NQRhK4jAxnEGTHS08KxHZHvY8MveUgvaRJgZy4jEDyRE+pXEC1EoIJdr0CgxwrhqvI3BR91NHft2Gti/c0VWyCqn0KnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674126114; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zschi5KZVktQ6eezkqFue7iZ+GRAEpHtTDB7oni7LV4=; b=A1LpwgWz27KvSO6XBRfabzu5opQua6XGfE+NupSVVJ6dUfAq4BlNBSOYAhOVUe+ECMNG+MesHN7QGMtQaUkw/DRm1j78l5RACO6SDnAW4bEmpuAE6SxHhmlLfhyd3V0g0H75RKGfHxnJkSiYGROtWf7vnpNfGYZtcGY2q2uU0b8= 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+98888+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674126114355449.34321131907313; Thu, 19 Jan 2023 03:01:54 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id C5QCYY1788612xSy4vz5M3ZT; Thu, 19 Jan 2023 03:01:51 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.42819.1674126111067688100 for ; Thu, 19 Jan 2023 03:01:51 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-461-k3QPyZlTP56-3DtsfBSp3g-1; Thu, 19 Jan 2023 06:01:47 -0500 X-MC-Unique: k3QPyZlTP56-3DtsfBSp3g-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 03317857D0D; Thu, 19 Jan 2023 11:01:46 +0000 (UTC) X-Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44D291415108; Thu, 19 Jan 2023 11:01:43 +0000 (UTC) From: "Laszlo Ersek" To: lersek@redhat.com, devel@edk2.groups.io Cc: Ard Biesheuvel , Brijesh Singh , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Jordan Justen , Michael Brown , Min Xu , Oliver Steffen , Sebastien Boeuf , Tom Lendacky Subject: [edk2-devel] [PATCH v3 2/2] OvmfPkg/PlatformInitLib: catch QEMU's CPU hotplug reg block regression Date: Thu, 19 Jan 2023 12:01:31 +0100 Message-Id: <20230119110131.91923-3-lersek@redhat.com> In-Reply-To: <20230119110131.91923-1-lersek@redhat.com> References: <20230119110131.91923-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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: IHzwp4JdLCzIyBT8FajhnpWAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674126111; bh=zschi5KZVktQ6eezkqFue7iZ+GRAEpHtTDB7oni7LV4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=DOjYQQIZTZ8ukW5zv06K7QsSW6mpBJrOESNQiH2KvtiFgZ+10C8gkpc/w2dtI1MJeea 5Vs91Y5xHpxMUik/zztBc9vOrLeD+ReNq5OUvJznXKPrRKhXFvgqDQvK/NRjLL/K8Rw57 Y6iDOqpM4cOB3/DwVacwqygV2GswuuiMKWQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674126117387100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In QEMU v5.1.0, the CPU hotplug register block misbehaves: the negotiation protocol is (effectively) broken such that it suggests that switching from the legacy interface to the modern interface works, but in reality the switch never happens. The symptom has been witnessed when using TCG acceleration; KVM seems to mask the issue. The issue persists with the following (latest) stable QEMU releases: v5.2.0, v6.2.0, v7.2.0. Currently there is no stable release that addresses the problem. The QEMU bug confuses the Present and Possible counting in function PlatformMaxCpuCountInitialization(), in "OvmfPkg/Library/PlatformInitLib/Platform.c". OVMF ends up with Present=3D0 Possible=3D1. This in turn further confuses MpInitLib in UefiCpuPkg (hence firmware-time multiprocessing will be broken). Worse, CPU hot(un)plug with SMI will be summarily broken in OvmfPkg/CpuHotplugSmm, which (considering the privilege level of SMM) is not that great. Detect the issue in PlatformCpuCountBugCheck(), and print an error message and *hang* if the issue is present. Users willing to take risks can override the hang with the experimental QEMU command line option -fw_cfg name=3Dopt/org.tianocore/X-Cpuhp-Bugcheck-Override,string=3Dyes (The "-fw_cfg" QEMU option itself is not experimental; its above argument, as far it concerns the firmware, is experimental.) The problem was originally reported by Ard [0]. We analyzed it at [1] and [2]. A QEMU patch was sent at [3]; now merged as commit dab30fbef389 ("acpi: cpuhp: fix guest-visible maximum access size to the legacy reg block", 2023-01-08), to be included in QEMU v8.0.0. [0] https://bugzilla.tianocore.org/show_bug.cgi?id=3D4234#c2 [1] https://bugzilla.tianocore.org/show_bug.cgi?id=3D4234#c3 [2] IO port write width clamping differs between TCG and KVM http://mid.mail-archive.com/aaedee84-d3ed-a4f9-21e7-d221a28d1683@redhat= .com https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg00199.html [3] acpi: cpuhp: fix guest-visible maximum access size to the legacy reg bl= ock http://mid.mail-archive.com/20230104090138.214862-1-lersek@redhat.com https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg00278.html NOTE: PlatformInitLib is used in the following platform DSCs: OvmfPkg/AmdSev/AmdSevX64.dsc OvmfPkg/CloudHv/CloudHvX64.dsc OvmfPkg/IntelTdx/IntelTdxX64.dsc OvmfPkg/Microvm/MicrovmX64.dsc OvmfPkg/OvmfPkgIa32.dsc OvmfPkg/OvmfPkgIa32X64.dsc OvmfPkg/OvmfPkgX64.dsc but I can only test this change with the last three platforms, running on QEMU. Test results: TCG QEMU OVMF override result patched patched --- ------- ------- -------- -------------------------------------- 0 0 0 0 CPU counts OK (KVM masks the QEMU bug) 0 0 1 0 CPU counts OK (KVM masks the QEMU bug) 0 1 0 0 CPU counts OK (QEMU fix, but KVM masks the QEMU bug anyway) 0 1 1 0 CPU counts OK (QEMU fix, but KVM masks the QEMU bug anyway) 1 0 0 0 boot with broken CPU counts (original QEMU bug) 1 0 1 0 broken CPU count caught (boot hangs) 1 0 1 1 broken CPU count caught, bug check overridden, boot continues 1 1 0 0 CPU counts OK (QEMU fix) 1 1 1 0 CPU counts OK (QEMU fix) Cc: Ard Biesheuvel Cc: Brijesh Singh Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Jordan Justen Cc: Michael Brown Cc: Min Xu Cc: Oliver Steffen Cc: Sebastien Boeuf Cc: Tom Lendacky Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4250 Signed-off-by: Laszlo Ersek Acked-by: Gerd Hoffmann Reviewed-by: Ard Biesheuvel --- Notes: v3: =20 - reimplement the bug check in the factored out function PlatformCpuCountBugCheck() =20 - add override [Ard, Gerd, Michael] =20 - assert "0 < Present =3D=3D BootCpuCount <=3D Possible" whenever PlatformCpuCountBugCheck() returns =20 - update commit message =20 - update test matrix in commit message =20 - (re)test all "OVMF patched =3D 1" cases (sigh) =20 v2: =20 - V1 was at . =20 - Repo: , branch: cpuhp-reg-catch-4250-v2 =20 - Remove KVM as a proposed workaround from the error message, because in the QEMU discussion, we had found that the KVM accelerator's behavior in QEMU (masking the problem) was not right, and that a fix for that had been in progress for quite some time. =20 - Add the QEMU commit hash to the commit message, the code comment, and the error message. =20 - Pick up Gerd's R-b; add Oliver to the Cc list. OvmfPkg/Library/PlatformInitLib/Platform.c | 87 ++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/Platform.c index d1be5c2d7970..9fee6e481038 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -36,6 +36,9 @@ =20 #include =20 +#define CPUHP_BUGCHECK_OVERRIDE_FWCFG_FILE \ + "opt/org.tianocore/X-Cpuhp-Bugcheck-Override" + VOID EFIAPI PlatformAddIoMemoryBaseSizeHob ( @@ -437,6 +440,87 @@ PlatformCpuCountBugCheck ( { ASSERT (*BootCpuCount > 0); =20 + // + // Sanity check: we need at least 1 present CPU (CPU#0 is always present= ). + // + // The legacy-to-modern switching of the CPU hotplug register block got = broken + // (for TCG) in QEMU v5.1.0. Refer to "IO port write width clamping diff= ers + // between TCG and KVM" at + // + // or at + // . + // + // QEMU received the fix in commit dab30fbef389 ("acpi: cpuhp: fix + // guest-visible maximum access size to the legacy reg block", 2023-01-0= 8), to + // be included in QEMU v8.0.0. + // + // If we're affected by this QEMU bug, then we must not continue: it con= fuses + // the multiprocessing in UefiCpuPkg/Library/MpInitLib, and breaks CPU + // hot(un)plug with SMI in OvmfPkg/CpuHotplugSmm. + // + if (*Present =3D=3D 0) { + UINTN Idx; + STATIC CONST CHAR8 *CONST Message[] =3D { + "Broken CPU hotplug register block found. Update QEMU to version 8+,= or", + "to a stable release with commit dab30fbef389 backported. Refer to", + ".", + "Consequences of the QEMU bug may include, but are not limited to:", + "- all firmware logic, dependent on the CPU hotplug register block,", + " being confused, for example, multiprocessing-related logic;", + "- guest OS data loss, including filesystem corruption, due to crash= or", + " hang during ACPI S3 resume;", + "- SMM privilege escalation, by a malicious guest OS or 3rd partty U= EFI", + " agent, against the platform firmware.", + "These symptoms need not necessarily be limited to the QEMU user", + "attempting to hot(un)plug a CPU.", + "The firmware will now stop (hang) deliberately, in order to prevent= the", + "above symptoms.", + "You can forcibly override the hang, *at your own risk*, with the", + "following *experimental* QEMU command line option:", + " -fw_cfg name=3D" CPUHP_BUGCHECK_OVERRIDE_FWCFG_FILE ",string=3Dye= s", + "Please only report such bugs that you can reproduce *without* the", + "override.", + }; + RETURN_STATUS ParseStatus; + BOOLEAN Override; + + DEBUG (( + DEBUG_ERROR, + "%a: Present=3D%u Possible=3D%u\n", + __FUNCTION__, + *Present, + *Possible + )); + for (Idx =3D 0; Idx < ARRAY_SIZE (Message); ++Idx) { + DEBUG ((DEBUG_ERROR, "%a: %a\n", __FUNCTION__, Message[Idx])); + } + + ParseStatus =3D QemuFwCfgParseBool ( + CPUHP_BUGCHECK_OVERRIDE_FWCFG_FILE, + &Override + ); + if (!RETURN_ERROR (ParseStatus) && Override) { + DEBUG (( + DEBUG_WARN, + "%a: \"%a\" active. You've been warned.\n", + __FUNCTION__, + CPUHP_BUGCHECK_OVERRIDE_FWCFG_FILE + )); + // + // The bug is in QEMU v5.1.0+, where we're not affected by the QEMU = v2.7 + // reset bug, so BootCpuCount from fw_cfg is reliable. Assume a fully + // populated topology, like when the modern CPU hotplug interface is + // unavailable. + // + *Present =3D *BootCpuCount; + *Possible =3D *BootCpuCount; + return; + } + + ASSERT (FALSE); + CpuDeadLoop (); + } + // // Sanity check: fw_cfg and the modern CPU hotplug interface should expo= se the // same boot CPU count. @@ -596,6 +680,9 @@ PlatformMaxCpuCountInitialization ( } while (Selected > 0); =20 PlatformCpuCountBugCheck (&BootCpuCount, &Present, &Possible); + ASSERT (Present > 0); + ASSERT (Present <=3D Possible); + ASSERT (BootCpuCount =3D=3D Present); =20 MaxCpuCount =3D Possible; } -=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 (#98888): https://edk2.groups.io/g/devel/message/98888 Mute This Topic: https://groups.io/mt/96374974/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-