From mboxrd@z Thu Jan 1 00:00:00 1970 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.12144.1672924388236904098 for ; Thu, 05 Jan 2023 05:13:08 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IZWYHebb; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672924387; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+mRyUTh5SFXqPUnJtnqX5bFiSD1lid8nP87Y/nqvwvA=; b=IZWYHebbeiNqCIl5SHrWB3yKzy1U47OTLa8SB6o4kFePTz9/v5lpUqPPmilO/kwVPnBWmu BidR4I5G5FOU0RRl46o/nU00umIWO1Wgcfq2InXR/7TVbBw+dJx4Vit1NxgcmZP9iOKl9e KQncfOQbxnqd56DPIdc312ZGZ/B/eo4= 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-633-k5ijGkhwMIGP9gJC5ekV1g-1; Thu, 05 Jan 2023 08:13:01 -0500 X-MC-Unique: k5ijGkhwMIGP9gJC5ekV1g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7A4EB3C0D18E; Thu, 5 Jan 2023 13:12:57 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 458EF2166B30; Thu, 5 Jan 2023 13:12:57 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 0E54E180062F; Thu, 5 Jan 2023 14:12:56 +0100 (CET) Date: Thu, 5 Jan 2023 14:12:56 +0100 From: "Gerd Hoffmann" To: Laszlo Ersek Cc: devel@edk2.groups.io, Ard Biesheuvel , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Jordan Justen , Min Xu , Sebastien Boeuf , Tom Lendacky Subject: Re: [PATCH 1/1] OvmfPkg/PlatformInitLib: catch QEMU's CPU hotplug reg block regression Message-ID: <20230105131256.m3tgqu4antgrk7rt@sirius.home.kraxel.org> References: <20230104151234.286030-1-lersek@redhat.com> <20230104151234.286030-2-lersek@redhat.com> MIME-Version: 1.0 In-Reply-To: <20230104151234.286030-2-lersek@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Jan 04, 2023 at 04:12:34PM +0100, Laszlo Ersek wrote: > 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=0 > Possible=1. 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=4234#c2 > > [1] https://bugzilla.tianocore.org/show_bug.cgi?id=4234#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 block > 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=4250 > Signed-off-by: Laszlo Ersek Reviewed-by: Gerd Hoffmann