From nobody Tue Feb 10 04:13:03 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+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 --- 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-