Blame SOURCES/edk2-OvmfPkg-SmmControl2Dxe-negotiate-ICH9_LPC_SMI_F_CPU_.patch

f60719
From a5efebddb858c739d4a67865a4f8d836ba989d30 Mon Sep 17 00:00:00 2001
f60719
From: Laszlo Ersek <lersek@redhat.com>
f60719
Date: Tue, 14 Jul 2020 20:43:05 +0200
f60719
Subject: [PATCH 1/5] OvmfPkg/SmmControl2Dxe: negotiate
f60719
 ICH9_LPC_SMI_F_CPU_HOTPLUG
f60719
MIME-Version: 1.0
f60719
Content-Type: text/plain; charset=UTF-8
f60719
Content-Transfer-Encoding: 8bit
f60719
f60719
RH-Author: Laszlo Ersek (lersek)
f60719
RH-MergeRequest: 1: [RHEL-8.4.0] complete the "VCPU hotplug with SMI" OVMF feature
f60719
RH-Commit: [1/3] 33d820d43a1be2ece09044b0cf105275f3fcc9ce (lersek/edk2)
f60719
RH-Bugzilla: 1849177
f60719
f60719
The ICH9_LPC_SMI_F_BROADCAST and ICH9_LPC_SMI_F_CPU_HOTPLUG feature flags
f60719
cause QEMU to behave as follows:
f60719
f60719
  BROADCAST  CPU_HOTPLUG  use case / behavior
f60719
  ---------  -----------  ------------------------------------------------
f60719
  clear      clear        OVMF built without SMM_REQUIRE; or very old OVMF
f60719
                          (from before commit a316d7ac91d3 / 2017-02-07).
f60719
                          QEMU permits CPU hotplug operations, and does
f60719
                          not cause the OS to inject an SMI upon hotplug.
f60719
                          Firmware is not expected to be aware of hotplug
f60719
                          events.
f60719
f60719
  clear      set          Invalid feature set; QEMU rejects the feature
f60719
                          negotiation.
f60719
f60719
  set        clear        OVMF after a316d7ac91d3 / 2017-02-07, built with
f60719
                          SMM_REQUIRE, but no support for CPU hotplug.
f60719
                          QEMU gracefully refuses hotplug operations.
f60719
f60719
  set        set          OVMF after a316d7ac91d3 / 2017-02-07, built with
f60719
                          SMM_REQUIRE, and supporting CPU hotplug. QEMU
f60719
                          permits CPU hotplug operations, and causes the
f60719
                          OS to inject an SMI upon hotplug. Firmware is
f60719
                          expected to deal with hotplug events.
f60719
f60719
Negotiate ICH9_LPC_SMI_F_CPU_HOTPLUG -- but only if SEV is disabled, as
f60719
OvmfPkg/CpuHotplugSmm can't deal with SEV yet.
f60719
f60719
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
f60719
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
f60719
Cc: Igor Mammedov <imammedo@redhat.com>
f60719
Cc: Jordan Justen <jordan.l.justen@intel.com>
f60719
Cc: Liran Alon <liran.alon@oracle.com>
f60719
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
f60719
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
f60719
Message-Id: <20200714184305.9814-1-lersek@redhat.com>
f60719
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
f60719
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
f60719
(cherry picked from commit 5ba203b54e5953572e279e5505cd65e4cc360e34)
f60719
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
f60719
---
f60719
 OvmfPkg/SmmControl2Dxe/SmiFeatures.c      | 26 +++++++++++++++++++++--
f60719
 OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf |  1 +
f60719
 2 files changed, 25 insertions(+), 2 deletions(-)
f60719
f60719
diff --git a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c b/OvmfPkg/SmmControl2Dxe/SmiFeatures.c
f60719
index 6210b7515e..c9d8755432 100644
f60719
--- a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c
f60719
+++ b/OvmfPkg/SmmControl2Dxe/SmiFeatures.c
f60719
@@ -9,6 +9,7 @@
f60719
 
f60719
 #include <Library/BaseLib.h>
f60719
 #include <Library/DebugLib.h>
f60719
+#include <Library/MemEncryptSevLib.h>
f60719
 #include <Library/MemoryAllocationLib.h>
f60719
 #include <Library/PcdLib.h>
f60719
 #include <Library/QemuFwCfgLib.h>
f60719
@@ -21,6 +22,12 @@
f60719
 // "etc/smi/supported-features" and "etc/smi/requested-features" fw_cfg files.
f60719
 //
f60719
 #define ICH9_LPC_SMI_F_BROADCAST BIT0
f60719
+//
f60719
+// The following bit value stands for "enable CPU hotplug, and inject an SMI
f60719
+// with control value ICH9_APM_CNT_CPU_HOTPLUG upon hotplug", in the
f60719
+// "etc/smi/supported-features" and "etc/smi/requested-features" fw_cfg files.
f60719
+//
f60719
+#define ICH9_LPC_SMI_F_CPU_HOTPLUG BIT1
f60719
 
f60719
 //
f60719
 // Provides a scratch buffer (allocated in EfiReservedMemoryType type memory)
f60719
@@ -67,6 +74,7 @@ NegotiateSmiFeatures (
f60719
   UINTN                SupportedFeaturesSize;
f60719
   UINTN                RequestedFeaturesSize;
f60719
   UINTN                FeaturesOkSize;
f60719
+  UINT64               RequestedFeaturesMask;
f60719
 
f60719
   //
f60719
   // Look up the fw_cfg files used for feature negotiation. The selector keys
f60719
@@ -104,9 +112,16 @@ NegotiateSmiFeatures (
f60719
   QemuFwCfgReadBytes (sizeof mSmiFeatures, &mSmiFeatures);
f60719
 
f60719
   //
f60719
-  // We want broadcast SMI and nothing else.
f60719
+  // We want broadcast SMI, SMI on CPU hotplug, and nothing else.
f60719
   //
f60719
-  mSmiFeatures &= ICH9_LPC_SMI_F_BROADCAST;
f60719
+  RequestedFeaturesMask = ICH9_LPC_SMI_F_BROADCAST;
f60719
+  if (!MemEncryptSevIsEnabled ()) {
f60719
+    //
f60719
+    // For now, we only support hotplug with SEV disabled.
f60719
+    //
f60719
+    RequestedFeaturesMask |= ICH9_LPC_SMI_F_CPU_HOTPLUG;
f60719
+  }
f60719
+  mSmiFeatures &= RequestedFeaturesMask;
f60719
   QemuFwCfgSelectItem (mRequestedFeaturesItem);
f60719
   QemuFwCfgWriteBytes (sizeof mSmiFeatures, &mSmiFeatures);
f60719
 
f60719
@@ -144,6 +159,13 @@ NegotiateSmiFeatures (
f60719
     DEBUG ((DEBUG_INFO, "%a: using SMI broadcast\n", __FUNCTION__));
f60719
   }
f60719
 
f60719
+  if ((mSmiFeatures & ICH9_LPC_SMI_F_CPU_HOTPLUG) == 0) {
f60719
+    DEBUG ((DEBUG_INFO, "%a: CPU hotplug not negotiated\n", __FUNCTION__));
f60719
+  } else {
f60719
+    DEBUG ((DEBUG_INFO, "%a: CPU hotplug with SMI negotiated\n",
f60719
+      __FUNCTION__));
f60719
+  }
f60719
+
f60719
   //
f60719
   // Negotiation successful (although we may not have gotten the optimal
f60719
   // feature set).
f60719
diff --git a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf b/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf
f60719
index 3abed141e6..b8fdea8deb 100644
f60719
--- a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf
f60719
+++ b/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf
f60719
@@ -46,6 +46,7 @@
f60719
   BaseLib
f60719
   DebugLib
f60719
   IoLib
f60719
+  MemEncryptSevLib
f60719
   MemoryAllocationLib
f60719
   PcdLib
f60719
   PciLib
f60719
-- 
f60719
2.27.0
f60719