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 <kra...@redhat.com>
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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#98475): https://edk2.groups.io/g/devel/message/98475
Mute This Topic: https://groups.io/mt/96218818/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to