Blame SOURCES/edk2-SecurityPkg-Tcg2Dxe-suppress-error-on-no-swtpm-in-si.patch

1d2c45
From cbce29f7749477e271f9764fed82de94724af5df Mon Sep 17 00:00:00 2001
1d2c45
From: Laszlo Ersek <lersek@redhat.com>
1d2c45
Date: Wed, 24 Jun 2020 11:40:09 +0200
1d2c45
Subject: [PATCH 3/3] SecurityPkg/Tcg2Dxe: suppress error on no swtpm in silent
1d2c45
 aa64 build (RH)
1d2c45
MIME-Version: 1.0
1d2c45
Content-Type: text/plain; charset=UTF-8
1d2c45
Content-Transfer-Encoding: 8bit
1d2c45
1d2c45
RH-Author: Laszlo Ersek <lersek@redhat.com>
1d2c45
Message-id: <20200615080105.11859-4-lersek@redhat.com>
1d2c45
Patchwork-id: 97534
1d2c45
O-Subject: [RHEL-8.3.0 edk2 PATCH 3/3] SecurityPkg/Tcg2Dxe: suppress error on no swtpm in silent aa64 build (RH)
1d2c45
Bugzilla: 1844682
1d2c45
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
1d2c45
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
1d2c45
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
1d2c45
1d2c45
If swtpm / vTPM2 is not being used, Tcg2Dxe should return EFI_UNSUPPORTED,
1d2c45
so that the DXE Core can unload it. However, the associated error message,
1d2c45
logged by the DXE Core to the serial console, is not desired in the silent
1d2c45
edk2-aarch64 build, given that the absence of swtpm / vTPM2 is nothing out
1d2c45
of the ordinary. Therefore, return success and stay resident. The wasted
1d2c45
guest RAM still gets freed after ExitBootServices().
1d2c45
1d2c45
(Inspired by RHEL-8.1.0 commit aaaedc1e2cfd.)
1d2c45
1d2c45
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
1d2c45
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1d2c45
---
1d2c45
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c   | 17 +++++++++++++++++
1d2c45
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf |  1 +
1d2c45
 2 files changed, 18 insertions(+)
1d2c45
1d2c45
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
1d2c45
index 9a5f987e68..da2153cb25 100644
1d2c45
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
1d2c45
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
1d2c45
@@ -28,6 +28,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
1d2c45
 #include <Protocol/ResetNotification.h>
1d2c45
 
1d2c45
 #include <Library/DebugLib.h>
1d2c45
+#include <Library/DebugPrintErrorLevelLib.h>
1d2c45
 #include <Library/BaseMemoryLib.h>
1d2c45
 #include <Library/UefiRuntimeServicesTableLib.h>
1d2c45
 #include <Library/UefiDriverEntryPoint.h>
1d2c45
@@ -2642,6 +2643,22 @@ DriverEntry (
1d2c45
   if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid) ||
1d2c45
       CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){
1d2c45
     DEBUG ((DEBUG_INFO, "No TPM2 instance required!\n"));
1d2c45
+#if defined (MDE_CPU_AARCH64)
1d2c45
+    //
1d2c45
+    // RHBZ#1844682
1d2c45
+    //
1d2c45
+    // If swtpm / vTPM2 is not being used, this driver should return
1d2c45
+    // EFI_UNSUPPORTED, so that the DXE Core can unload it. However, the
1d2c45
+    // associated error message, logged by the DXE Core to the serial console,
1d2c45
+    // is not desired in the silent edk2-aarch64 build, given that the absence
1d2c45
+    // of swtpm / vTPM2 is nothing out of the ordinary. Therefore, return
1d2c45
+    // success and stay resident. The wasted guest RAM still gets freed after
1d2c45
+    // ExitBootServices().
1d2c45
+    //
1d2c45
+    if (GetDebugPrintErrorLevel () == DEBUG_ERROR) {
1d2c45
+      return EFI_SUCCESS;
1d2c45
+    }
1d2c45
+#endif
1d2c45
     return EFI_UNSUPPORTED;
1d2c45
   }
1d2c45
 
1d2c45
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
1d2c45
index 576cf80d06..851471afb7 100644
1d2c45
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
1d2c45
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
1d2c45
@@ -55,6 +55,7 @@
1d2c45
   UefiRuntimeServicesTableLib
1d2c45
   BaseMemoryLib
1d2c45
   DebugLib
1d2c45
+  DebugPrintErrorLevelLib
1d2c45
   Tpm2CommandLib
1d2c45
   PrintLib
1d2c45
   UefiLib
1d2c45
-- 
1d2c45
2.27.0
1d2c45