From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.12921.1672841641246871557 for ; Wed, 04 Jan 2023 06:14:01 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=UJxwO4YV; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672841641; x=1704377641; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=PgUkbDn4/5jEhtsTqO/0n/sZFVXQg1w5Et4Bw8471PQ=; b=UJxwO4YVeGRHw2PWnkjUnbwvXnjjhZm4ewMUONOqVhZwxpTW0FIPU/CY GWGAjYX3v0NsKVeAousjOba5HbqH0YCJLMH5LKzHasL7E+OCbb794GSUk qTOWG9zfBX9ODmG7v21Bt8UJoR/fOp8g4SZO6i1L8BF4V3EnjEUtzV9Jb pX0bhBbjFMrDjjfDWug+7c5f1U58oKGiomnPIJBklsVUKesvQcabg31/9 4L9sar69tudsAc3ixy1QhJhGiLhS+RFj16UfTQCkEnQ0lPU63oIcr7nm2 5FbOYnsq1s3cHdixZjtwyclngs8l6aZlThp9jM1oHjlHaQZzKUA/O7iJu w==; X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="301631400" X-IronPort-AV: E=Sophos;i="5.96,300,1665471600"; d="scan'208";a="301631400" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2023 06:14:00 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="900568502" X-IronPort-AV: E=Sophos;i="5.96,300,1665471600"; d="scan'208";a="900568502" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.169.114]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2023 06:13:58 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Laszlo Ersek , Erdem Aktas , James Bottomley , Jiewen Yao , Gerd Hoffmann , Tom Lendacky , Sebastien Boeuf Subject: [PATCH V1 1/1] OvmfPkg/AcpiPlatformDxe: Add back log and fix code cohesion Date: Wed, 4 Jan 2023 22:13:09 +0800 Message-Id: <20230104141309.1426-1-min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4237 Commit 9fdc70af6ba8 breaks log analysis and code cohesion in AcpiPlatformDxe. See the detailed information in BZ#4237. There are below changes in this patch: 1) Add back debug log 2) Add error checking and handling if InstallProtocolInterface failed. 3) Delete the QemuAcpiTableNotify.h because it is superfluous. 4) Delete the global variable "mQemuAcpiHandle" instead of a local variable. 5) Install the QEMU_ACPI_TABLE_NOTIFY_PROTOCOL with a NULL associated interface. Above changes 2/4/5 are applied in both CloudHvAcpi.c and QemuFwCfgAcpi.c. Cc: Laszlo Ersek Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Tom Lendacky Cc: Sebastien Boeuf Reported-by: Laszlo Ersek Signed-off-by: Min Xu --- OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c | 25 +++++------ OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c | 42 +++++++++++++------ .../Include/Protocol/QemuAcpiTableNotify.h | 27 ------------ 3 files changed, 42 insertions(+), 52 deletions(-) delete mode 100644 OvmfPkg/Include/Protocol/QemuAcpiTableNotify.h diff --git a/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c b/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c index cbe8bb9b0c75..81f387438a64 100644 --- a/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c +++ b/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c @@ -18,13 +18,9 @@ #include #include -#include // QEMU_ACPI_TABLE_NOTIFY_PROTOCOL #include "AcpiPlatform.h" -EFI_HANDLE mChAcpiHandle = NULL; -QEMU_ACPI_TABLE_NOTIFY_PROTOCOL mChAcpiNotifyProtocol; - EFI_STATUS EFIAPI InstallCloudHvTablesTdx ( @@ -33,13 +29,15 @@ InstallCloudHvTablesTdx ( { EFI_STATUS Status; UINTN TableHandle; + EFI_HANDLE ChAcpiHandle; EFI_PEI_HOB_POINTERS Hob; EFI_ACPI_DESCRIPTION_HEADER *CurrentTable; EFI_ACPI_DESCRIPTION_HEADER *DsdtTable; - DsdtTable = NULL; - TableHandle = 0; + DsdtTable = NULL; + TableHandle = 0; + ChAcpiHandle = NULL; Hob.Guid = (EFI_HOB_GUID_TYPE *)GetFirstGuidHob (&gUefiOvmfPkgTdxAcpiHobGuid); @@ -92,12 +90,15 @@ InstallCloudHvTablesTdx ( // Install a protocol to notify that the ACPI table provided by CH is // ready. // - gBS->InstallProtocolInterface ( - &mChAcpiHandle, - &gQemuAcpiTableNotifyProtocolGuid, - EFI_NATIVE_INTERFACE, - &mChAcpiNotifyProtocol - ); + Status = gBS->InstallProtocolInterface ( + &ChAcpiHandle, + &gQemuAcpiTableNotifyProtocolGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; + } return EFI_SUCCESS; } diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c index c8dee17c13e6..22340b13e3ee 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c @@ -19,10 +19,7 @@ #include // QemuFwCfgS3Enabled() #include // gBS -#include #include "AcpiPlatform.h" -EFI_HANDLE mQemuAcpiHandle = NULL; -QEMU_ACPI_TABLE_NOTIFY_PROTOCOL mAcpiNotifyProtocol; // // The user structure for the ordered collection that will track the fw_cfg @@ -1103,6 +1100,9 @@ InstallQemuFwCfgTables ( ORDERED_COLLECTION_ENTRY *TrackerEntry, *TrackerEntry2; ORDERED_COLLECTION *SeenPointers; ORDERED_COLLECTION_ENTRY *SeenPointerEntry, *SeenPointerEntry2; + EFI_HANDLE QemuAcpiHandle; + + QemuAcpiHandle = NULL; Status = QemuFwCfgFindFile ("etc/table-loader", &FwCfgItem, &FwCfgSize); if (EFI_ERROR (Status)) { @@ -1249,6 +1249,20 @@ InstallQemuFwCfgTables ( } } + // + // Install a protocol to notify that the ACPI table provided by Qemu is + // ready. + // + Status = gBS->InstallProtocolInterface ( + &QemuAcpiHandle, + &gQemuAcpiTableNotifyProtocolGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + if (EFI_ERROR (Status)) { + goto UninstallAcpiTables; + } + // // Translating the condensed QEMU_LOADER_WRITE_POINTER commands to ACPI S3 // Boot Script opcodes has to be the last operation in this function, because @@ -1275,17 +1289,19 @@ UninstallAcpiTables: --Installed; AcpiProtocol->UninstallAcpiTable (AcpiProtocol, InstalledKey[Installed]); } + + // + // Uninstall the notification if it has been installed. + // + if (QemuAcpiHandle != NULL) { + gBS->UninstallProtocolInterface ( + QemuAcpiHandle, + &gQemuAcpiTableNotifyProtocolGuid, + NULL + ); + } } else { - // - // Install a protocol to notify that the ACPI table provided by Qemu is - // ready. - // - gBS->InstallProtocolInterface ( - &mQemuAcpiHandle, - &gQemuAcpiTableNotifyProtocolGuid, - EFI_NATIVE_INTERFACE, - &mAcpiNotifyProtocol - ); + DEBUG ((DEBUG_INFO, "%a: installed %d tables\n", __FUNCTION__, Installed)); } for (SeenPointerEntry = OrderedCollectionMin (SeenPointers); diff --git a/OvmfPkg/Include/Protocol/QemuAcpiTableNotify.h b/OvmfPkg/Include/Protocol/QemuAcpiTableNotify.h deleted file mode 100644 index a3dd2fc1dc91..000000000000 --- a/OvmfPkg/Include/Protocol/QemuAcpiTableNotify.h +++ /dev/null @@ -1,27 +0,0 @@ -/** @file - - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef QEMU_ACPI_TABLE_NOTIFY_H_ -#define QEMU_ACPI_TABLE_NOTIFY_H_ - -#define QEMU_ACPI_TABLE_NOTIFY_GUID \ - { 0x928939b2, 0x4235, 0x462f, { 0x95, 0x80, 0xf6, 0xa2, 0xb2, 0xc2, 0x1a, 0x4f } }; - -/// -/// Forward declaration -/// -typedef struct _QEMU_ACPI_TABLE_NOTIFY_PROTOCOL QEMU_ACPI_TABLE_NOTIFY_PROTOCOL; - -/// -/// Protocol structure -/// -struct _QEMU_ACPI_TABLE_NOTIFY_PROTOCOL { - UINT8 Notify; -}; - -extern EFI_GUID gQemuAcpiTableNotifyProtocolGuid; - -#endif -- 2.29.2.windows.2