public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, min.m.xu@intel.com
Cc: Erdem Aktas <erdemaktas@google.com>,
	James Bottomley <jejb@linux.ibm.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Tom Lendacky <thomas.lendacky@amd.com>
Subject: Re: [edk2-devel] [PATCH V2 5/6] OvmfPkg/AcpiPlatformDxe: Refactor QemuAcpiTableNotifyProtocol
Date: Tue, 10 Jan 2023 06:50:33 +0100	[thread overview]
Message-ID: <f5fa0a69-64d4-dce4-effb-1a40616f3b65@redhat.com> (raw)
In-Reply-To: <20230109135917.1752-6-min.m.xu@intel.com>

Hi Min,

On 1/9/23 14:59, Min Xu wrote:
> From: Min M Xu <min.m.xu@intel.com>
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4237
> 
> Commit 9fdc70af6ba8 install the QemuAcpiTableNotifyProtocol at a
> wrong positioin. It should be called before TransferS3ContextToBootScript
> because TransferS3ContextToBootScript is the last operation in
> InstallQemuFwCfgTables(). Another error is that we should check the
> returned value after installing the QemuAcpiTableNotifyProtocol.
> 
> This patch refactors the installation and error handling of
> QemuAcpiTableNotifyProtocol in InstallQemuFwCfgTables ().
> 
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Erdem Aktas <erdemaktas@google.com>
> Cc: James Bottomley <jejb@linux.ibm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Reported-by: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Min Xu <min.m.xu@intel.com>
> ---
>  OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c | 36 ++++++++++++++++---------
>  1 file changed, 24 insertions(+), 12 deletions(-)
> 
> diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c
> index f27a95957f47..14ae13055a30 100644
> --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c
> +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c
> @@ -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
> @@ -1257,7 +1271,7 @@ InstallQemuFwCfgTables (
>    if (S3Context != NULL) {
>      Status = TransferS3ContextToBootScript (S3Context);
>      if (EFI_ERROR (Status)) {
> -      goto UninstallAcpiTables;
> +      goto UninstallQemuAcpiTableNotifyProtocol;
>      }
>  
>      //
> @@ -1268,6 +1282,15 @@ InstallQemuFwCfgTables (
>  
>    DEBUG ((DEBUG_INFO, "%a: installed %d tables\n", __FUNCTION__, Installed));
>  
> +UninstallQemuAcpiTableNotifyProtocol:
> +  if (EFI_ERROR (Status)) {
> +    gBS->UninstallProtocolInterface (
> +           QemuAcpiHandle,
> +           &gQemuAcpiTableNotifyProtocolGuid,
> +           NULL
> +           );
> +  }
> +
>  UninstallAcpiTables:
>    if (EFI_ERROR (Status)) {
>      //
> @@ -1277,17 +1300,6 @@ UninstallAcpiTables:
>        --Installed;
>        AcpiProtocol->UninstallAcpiTable (AcpiProtocol, InstalledKey[Installed]);
>      }
> -  } else {
> -    //
> -    // Install a protocol to notify that the ACPI table provided by Qemu is
> -    // ready.
> -    //
> -    gBS->InstallProtocolInterface (
> -           &QemuAcpiHandle,
> -           &gQemuAcpiTableNotifyProtocolGuid,
> -           EFI_NATIVE_INTERFACE,
> -           NULL
> -           );
>    }
>  
>    for (SeenPointerEntry = OrderedCollectionMin (SeenPointers);

Previously, I wrote:

> In fact, I request that you *not* set QemuAcpiHandle to NULL at the
> top of the function. Letting *only* InstallProtocolInterface() set it,
> upon success, is safe, as long as you use the pattern shown above.

That was wrong. When I wrote that, I forgot that, for
EFI_BOOT_SERVICES.InstallProtocolInterface(), the "Handle" parameter is
"IN OUT", not just OUT. In other words, we state that we want a new
handle by setting the Handle to NULL on input. My comment above missed
that, I'm sorry.

So, I think this patch is good. I do have small request though. Please
bear with me:

- in patch #3, can you move the "QemuAcpiHandle = NULL" assignment right
above the gBS->InstallProtocolInterface() call?

- and in patch #5 (i.e., here), can you please *keep* the
"QemuAcpiHandle = NULL" assignment together with the
gBS->InstallProtocolInterface() call that is being moved?

Because, you are right that we need to set QemuAcpiHandle to NULL before
we call InstallProtocolInterface(); however, I'd like to prevent the
function from making the impression that we depend on "initializing"
QemuAcpiHandle like that.

Sorry about the churn!

Thanks,
Laszlo


  reply	other threads:[~2023-01-10  5:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09 13:59 [PATCH V2 0/6] Refactor installation of gQemuAcpiTableNotifyProtocol Min Xu
2023-01-09 13:59 ` [PATCH V2 1/6] OvmfPkg/AcpiPlatformDxe: Remove QEMU_ACPI_TABLE_NOTIFY_PROTOCOL Min Xu
2023-01-10  5:05   ` [edk2-devel] " Laszlo Ersek
2023-01-09 13:59 ` [PATCH V2 2/6] OvmfPkg/AcpiPlatformDxe: Use local variable in CloudHvAcpi.c Min Xu
2023-01-09 13:59 ` [PATCH V2 3/6] OvmfPkg/AcpiPlatformDxe: Use local variable in QemuFwCfgAcpi.c Min Xu
2023-01-10  5:06   ` [edk2-devel] " Laszlo Ersek
2023-01-09 13:59 ` [PATCH V2 4/6] OvmfPkg/AcpiPlatformDxe: Add log to show the installed tables Min Xu
2023-01-10  5:10   ` [edk2-devel] " Laszlo Ersek
2023-01-09 13:59 ` [PATCH V2 5/6] OvmfPkg/AcpiPlatformDxe: Refactor QemuAcpiTableNotifyProtocol Min Xu
2023-01-10  5:50   ` Laszlo Ersek [this message]
2023-01-10  6:23     ` [edk2-devel] " Min Xu
2023-01-09 13:59 ` [PATCH V2 6/6] OvmfPkg/AcpiPlatformDxe: Return error if installing NotifyProtocol failed Min Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f5fa0a69-64d4-dce4-effb-1a40616f3b65@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox