Blame 0027-SecurityPkg-Tcg2Dxe-suppress-error-on-no-swtpm-in-si.patch

59c3cd
From dc27035d2a8ca09dc5b0113c97a643341f286c08 Mon Sep 17 00:00:00 2001
59c3cd
From: Laszlo Ersek <lersek@redhat.com>
59c3cd
Date: Wed, 24 Jun 2020 11:40:09 +0200
59c3cd
Subject: SecurityPkg/Tcg2Dxe: suppress error on no swtpm in silent aa64 build
59c3cd
 (RH)
59c3cd
59c3cd
Notes about the RHEL-8.3/20200603-ca407c7246bf [edk2-stable202005] ->
59c3cd
RHEL-8.5/20210520-e1999b264f1f [edk2-stable202105] rebase:
59c3cd
59c3cd
- Remove obsolete commit message tags related to downstream patch
59c3cd
  management: Message-id, Patchwork-id, O-Subject, Acked-by, From,
59c3cd
  RH-Acked-by, RH-Author (RHBZ#1846481).
59c3cd
59c3cd
Bugzilla: 1844682
59c3cd
59c3cd
If swtpm / vTPM2 is not being used, Tcg2Dxe should return EFI_UNSUPPORTED,
59c3cd
so that the DXE Core can unload it. However, the associated error message,
59c3cd
logged by the DXE Core to the serial console, is not desired in the silent
59c3cd
edk2-aarch64 build, given that the absence of swtpm / vTPM2 is nothing out
59c3cd
of the ordinary. Therefore, return success and stay resident. The wasted
59c3cd
guest RAM still gets freed after ExitBootServices().
59c3cd
59c3cd
(Inspired by RHEL-8.1.0 commit aaaedc1e2cfd.)
59c3cd
59c3cd
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
59c3cd
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
59c3cd
(cherry picked from commit cbce29f7749477e271f9764fed82de94724af5df)
59c3cd
---
59c3cd
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c   | 17 +++++++++++++++++
59c3cd
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf |  1 +
59c3cd
 2 files changed, 18 insertions(+)
59c3cd
59c3cd
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
59c3cd
index 6d17616c1c..f1a97d4b2d 100644
59c3cd
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
59c3cd
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
59c3cd
@@ -28,6 +28,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
59c3cd
 #include <Protocol/ResetNotification.h>
59c3cd
 
59c3cd
 #include <Library/DebugLib.h>
59c3cd
+#include <Library/DebugPrintErrorLevelLib.h>
59c3cd
 #include <Library/BaseMemoryLib.h>
59c3cd
 #include <Library/UefiRuntimeServicesTableLib.h>
59c3cd
 #include <Library/UefiDriverEntryPoint.h>
59c3cd
@@ -2642,6 +2643,22 @@ DriverEntry (
59c3cd
   if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid) ||
59c3cd
       CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){
59c3cd
     DEBUG ((DEBUG_INFO, "No TPM2 instance required!\n"));
59c3cd
+#if defined (MDE_CPU_AARCH64)
59c3cd
+    //
59c3cd
+    // RHBZ#1844682
59c3cd
+    //
59c3cd
+    // If swtpm / vTPM2 is not being used, this driver should return
59c3cd
+    // EFI_UNSUPPORTED, so that the DXE Core can unload it. However, the
59c3cd
+    // associated error message, logged by the DXE Core to the serial console,
59c3cd
+    // is not desired in the silent edk2-aarch64 build, given that the absence
59c3cd
+    // of swtpm / vTPM2 is nothing out of the ordinary. Therefore, return
59c3cd
+    // success and stay resident. The wasted guest RAM still gets freed after
59c3cd
+    // ExitBootServices().
59c3cd
+    //
59c3cd
+    if (GetDebugPrintErrorLevel () == DEBUG_ERROR) {
59c3cd
+      return EFI_SUCCESS;
59c3cd
+    }
59c3cd
+#endif
59c3cd
     return EFI_UNSUPPORTED;
59c3cd
   }
59c3cd
 
59c3cd
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
59c3cd
index 7dc7a2683d..3bc8833931 100644
59c3cd
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
59c3cd
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
59c3cd
@@ -55,6 +55,7 @@
59c3cd
   UefiRuntimeServicesTableLib
59c3cd
   BaseMemoryLib
59c3cd
   DebugLib
59c3cd
+  DebugPrintErrorLevelLib
59c3cd
   Tpm2CommandLib
59c3cd
   PrintLib
59c3cd
   UefiLib
59c3cd
-- 
59c3cd
2.27.0
59c3cd