From nobody Wed May 15 02:58:28 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+97944+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+97944+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1672845165; cv=none; d=zohomail.com; s=zohoarc; b=XBlHrdduNFyKkNNn0Ghz+RpY2Vo0vUahfEi2QhHGlz/6RqXNPVRn3Ltse9c2Hr7qB4MV7SXAoj/aGsOm/H6Knk3/NBf4W+cL6zHWJdCe5JwADm7sAz/NwuDv15oHXfPrl9/zACfMvoL/QwC43UdabqG4m9GZZnPL4y3eQsfZJ84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1672845165; 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=HuzehvXAh48XRydxHGbTuYEh9m2f670NLYatMC0KmU0=; b=PLQ8xyHBQjuNUjWjJt9RwgudKO2SfffzGb1HPVyox4Nax6Czl/7xLpSD4V5cttqzr1WqEwQVP+2uiLhkR0LQAHoC/Dh5OQsHO7eHu06h5tR2vuaP61OW0mYDIPUTzBEEaGwweL/HnuIlJsacRIgCrqCez/xss4NLGB4+yLUi+3c= 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+97944+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 1672845165223837.2420395675186; Wed, 4 Jan 2023 07:12:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id obcmYY1788612xjoNpVtL5GC; Wed, 04 Jan 2023 07:12: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.14455.1672845163236039241 for ; Wed, 04 Jan 2023 07:12:43 -0800 X-Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-321-_a8q5vxFOmKyxNlBzSwExg-1; Wed, 04 Jan 2023 10:12:41 -0500 X-MC-Unique: _a8q5vxFOmKyxNlBzSwExg-1 X-Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 482AD1C008D3; Wed, 4 Jan 2023 15:12:40 +0000 (UTC) X-Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5678051E5; Wed, 4 Jan 2023 15:12:38 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Brijesh Singh , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Jordan Justen , Min Xu , Sebastien Boeuf , Tom Lendacky Subject: [edk2-devel] [PATCH 1/1] OvmfPkg/PlatformInitLib: catch QEMU's CPU hotplug reg block regression Date: Wed, 4 Jan 2023 16:12:34 +0100 Message-Id: <20230104151234.286030-2-lersek@redhat.com> In-Reply-To: <20230104151234.286030-1-lersek@redhat.com> References: <20230104151234.286030-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: p5DN4GBzcppJnuj6RzxzBjLZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1672845164; bh=HuzehvXAh48XRydxHGbTuYEh9m2f670NLYatMC0KmU0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=UK2sUsrX4BHhgyDmMUd0+kfHQmJA4+bQaYfHEwPGAOAOiNeyzuNsu7pB2ZhpapnyJYo RSb9fdvXwToWyAlteR8rOzhscc4K6LkRYjloBwtnrSRpVE1tpRtW+1HUcoI3b8JUR5BQq xLT+dutYKd5vnMWQyRQU9cUKPaE7GWTxdE4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1672845167113100004 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 PlatformMaxCpuCountInitialization(), and print an error message and *hang* if the issue is present. The problem was originally reported by Ard [0]. We analyzed it at [1] and [2]. A QEMU patch was sent at [3]. [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 result patched patched --- ------- ------- ------------------------------------------------- 0 0 0 CPU counts OK (KVM masks the QEMU bug) 0 0 1 CPU counts OK (KVM masks the QEMU bug) 0 1 0 CPU counts OK (QEMU fix, but KVM masks the QEMU bug anyway) 0 1 1 CPU counts OK (QEMU fix, but KVM masks the QEMU bug anyway) 1 0 0 boot with broken CPU counts (original QEMU bug) 1 0 1 broken CPU count caught (boot hangs) 1 1 0 CPU counts OK (QEMU fix) 1 1 1 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: Min Xu Cc: Sebastien Boeuf Cc: Tom Lendacky Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4250 Signed-off-by: Laszlo Ersek Reviewed-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/Platform.c | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/Platform.c index 3e13c5d4b34f..034282df5aab 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -541,6 +541,40 @@ PlatformMaxCpuCountInitialization ( ASSERT (Selected =3D=3D Possible || Selected =3D=3D 0); } while (Selected > 0); =20 + // + // Sanity check: we need at least 1 present CPU (CPU#0 is always pre= sent). + // + // 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 cl= amping + // differs between TCG and KVM" at + // + // or at + // . + // + // A fix was submitted after QEMU v7.2.0: "[PATCH] acpi: cpuhp: fix + // guest-visible maximum access size to the legacy reg block". + // + // If we're affected by this QEMU bug, then we must not continue: it + // confuses the multiprocessing in UefiCpuPkg/Library/MpInitLib, and + // breaks CPU hot(un)plug with SMI in OvmfPkg/CpuHotplugSmm. + // + if (Present =3D=3D 0) { + DEBUG (( + DEBUG_ERROR, + "%a: Broken CPU hotplug register block: Present=3D%u Possible=3D= %u.\n" + "%a: Switch QEMU's acceleration from TCG to KVM, or update QEMU.= \n" + "%a: Refer to " + ".\n", + __FUNCTION__, + Present, + Possible, + __FUNCTION__, + __FUNCTION__ + )); + ASSERT (FALSE); + CpuDeadLoop (); + } + // // Sanity check: fw_cfg and the modern CPU hotplug interface should // return the same boot CPU count. -=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 (#97944): https://edk2.groups.io/g/devel/message/97944 Mute This Topic: https://groups.io/mt/96051794/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-