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

Gerd Hoffmann ced5d8
From bee2e929ef342eafbe44f0471154da4270cac91d Mon Sep 17 00:00:00 2001
59c3cd
From: Laszlo Ersek <lersek@redhat.com>
59c3cd
Date: Wed, 24 Jun 2020 11:40:09 +0200
Gerd Hoffmann ced5d8
Subject: [PATCH 19/21] SecurityPkg/Tcg2Dxe: suppress error on no swtpm in
Gerd Hoffmann ced5d8
 silent aa64 build (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.inf |  1 +
Gerd Hoffmann ced5d8
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c   | 17 +++++++++++++++++
59c3cd
 2 files changed, 18 insertions(+)
59c3cd
Gerd Hoffmann ced5d8
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
Gerd Hoffmann ced5d8
index 7dc7a2683d71..3bc88339311e 100644
Gerd Hoffmann ced5d8
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
Gerd Hoffmann ced5d8
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
Gerd Hoffmann ced5d8
@@ -55,6 +55,7 @@ [LibraryClasses]
Gerd Hoffmann ced5d8
   UefiRuntimeServicesTableLib
Gerd Hoffmann ced5d8
   BaseMemoryLib
Gerd Hoffmann ced5d8
   DebugLib
Gerd Hoffmann ced5d8
+  DebugPrintErrorLevelLib
Gerd Hoffmann ced5d8
   Tpm2CommandLib
Gerd Hoffmann ced5d8
   PrintLib
Gerd Hoffmann ced5d8
   UefiLib
59c3cd
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
Gerd Hoffmann ced5d8
index f6ea8b2bbf18..681eb7e08b98 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>
Gerd Hoffmann ced5d8
@@ -2691,6 +2692,22 @@ DriverEntry (
Gerd Hoffmann ced5d8
       CompareGuid (PcdGetPtr (PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid))
Gerd Hoffmann ced5d8
   {
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
-- 
Gerd Hoffmann ced5d8
2.35.1
59c3cd