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.84989.1673612572946759782 for ; Fri, 13 Jan 2023 04:22:53 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CVpCUOnS; 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=1673612572; 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=i1TyU+msMAvjjVFH9Hu8XRF3NaFSQiHb2FMUhQT/RTI=; b=CVpCUOnS4y77f6EFqVOoHeHEgfkFaSoVy6/ixgNHe9QNBAzFwlLs1+zV7EOPHScQyFUCtf wDnHAihcwNm08Ka3PPhG0OLhUnTOluPqPlsO9sm+ZPRizW9HU+adcN7OmT7In3ITSJfADl e7izXkX5CeXhTNMqFuPN2Oxwgto8MlQ= 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-171-QZSH1byMPdSroOxEsOlMqg-1; Fri, 13 Jan 2023 07:22:49 -0500 X-MC-Unique: QZSH1byMPdSroOxEsOlMqg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 694B21C008C6; Fri, 13 Jan 2023 12:22:48 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F025F1121314; Fri, 13 Jan 2023 12:22:47 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 9DF491800606; Fri, 13 Jan 2023 13:22:46 +0100 (CET) Date: Fri, 13 Jan 2023 13:22:46 +0100 From: "Gerd Hoffmann" To: Laszlo Ersek Cc: devel@edk2.groups.io, Michael Brown , Ard Biesheuvel , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Jordan Justen , Min Xu , Oliver Steffen , Sebastien Boeuf , Tom Lendacky Subject: Re: [edk2-devel] [PATCH v2] OvmfPkg/PlatformInitLib: catch QEMU's CPU hotplug reg block regression Message-ID: <20230113122246.uabdhut4ziwerivm@sirius.home.kraxel.org> References: <20230112082845.128463-1-lersek@redhat.com> <01020185a568604c-e16d8581-963a-4ff3-8566-bf0640ad327d-000000@eu-west-1.amazonses.com> <407c5cee-7a6c-cbc8-35cc-8f2c2724914c@redhat.com> <01020185a6bda78a-05d82180-4d1a-4af4-9a9b-ac78088d11ed-000000@eu-west-1.amazonses.com> <49e4e8bb-3bbd-0ca8-ee59-e75560deffa7@redhat.com> <20230113060354.siony3rjwpgzd5tk@sirius.home.kraxel.org> <20230113093205.oh7euprqlmp26wpu@sirius.home.kraxel.org> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jan 13, 2023 at 11:10:54AM +0100, Laszlo Ersek wrote: > On 1/13/23 10:32, Gerd Hoffmann wrote: > > On Fri, Jan 13, 2023 at 07:03:54AM +0100, Gerd Hoffmann wrote: > >> Hi, > >> > >>> - QEMU can be configured with other compat properties on the command > >>> line so that "CPU hotplug with SMI" and "CPU hot-unplug with SMI" *not* > >>> be offered to the firmware. Then QEMU will reject hotplug attempts, and > >>> the SMM hotplug code in edk2 will not be triggered by the (virtual) > >>> hardware. > >> > >> Can we have edk2 print instructions for that in the error message? > > > > This seems to be: > > > > qemu -M q35 \ > > -global ICH9-LPC.x-smi-cpu-hotplug=off \ > > -global ICH9-LPC.x-smi-cpu-hotunplug=off > > Yes, those are the flags. > > > But it appears to not work. > > They should work, but they take effect in QEMU, and not in the firmware. > These knobs control what CPU hot(un)plug+SMI features QEMU exposes to > the guest fw, via fw_cfg, Ok, I see, only the SMM code actually checks that. > In particular the firmware makes no further decisions based on whether > QEMU advertized some of these features. I was thinking the other way around: When cpu hotplug is disabled in qemu it should be safe to skip the whole cpu hotplug checking dance. See test patch below. That would give us a config switch (turn off cpu hotplug support) which would allow edk2 run on qemu versions with broken cpu hotplug. Does the idea look sane or do I miss something? take care, Gerd commit bd2e36eba35268ab46c0125d2b9125391ea6f9fc Author: Gerd Hoffmann Date: Fri Jan 13 13:07:36 2023 +0100 skip cpu present checking when hotplug is off diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/PlatformInitLib/Platform.c index 13348afb4890..2b0f0c836f85 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -415,8 +415,9 @@ PlatformMaxCpuCountInitialization ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { - UINT16 BootCpuCount = 0; - UINT32 MaxCpuCount; + UINT16 BootCpuCount = 0; + UINT32 MaxCpuCount; + BOOLEAN CpuHotplugSupported = FALSE; // // Try to fetch the boot CPU count. @@ -424,6 +425,31 @@ PlatformMaxCpuCountInitialization ( if (QemuFwCfgIsAvailable ()) { QemuFwCfgSelectItem (QemuFwCfgItemSmpCpuCount); BootCpuCount = QemuFwCfgRead16 (); + DEBUG ((DEBUG_INFO, "%a: BootCpuCount: %d\n", __FUNCTION__, BootCpuCount)); + } + + { + FIRMWARE_CONFIG_ITEM SupportedFeaturesItem; + UINTN SupportedFeaturesSize; + UINT64 mSmiFeatures; + EFI_STATUS Status; + + Status = QemuFwCfgFindFile ( + "etc/smi/supported-features", + &SupportedFeaturesItem, + &SupportedFeaturesSize + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: etc/smi/supported-features: %r\n", __FUNCTION__, Status)); + } else { + QemuFwCfgSelectItem (SupportedFeaturesItem); + QemuFwCfgReadBytes (sizeof mSmiFeatures, &mSmiFeatures); + DEBUG ((DEBUG_INFO, "%a: etc/smi/supported-features: 0x%x\n", __FUNCTION__, mSmiFeatures)); + if (mSmiFeatures & (BIT1 /* hotplug */ | BIT2 /* hotunplug */)) { + CpuHotplugSupported = TRUE; + } + } } if (BootCpuCount == 0) { @@ -435,6 +461,9 @@ PlatformMaxCpuCountInitialization ( // DEBUG ((DEBUG_WARN, "%a: boot CPU count unavailable\n", __FUNCTION__)); MaxCpuCount = PlatformInfoHob->DefaultMaxCpuNumber; + } else if (!CpuHotplugSupported) { + DEBUG ((DEBUG_INFO, "%a: CPU hotplug support not available\n", __FUNCTION__)); + MaxCpuCount = BootCpuCount; } else { // // We will expose BootCpuCount to MpInitLib. MpInitLib will count APs up to