From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9A9AA21F7D517 for ; Thu, 12 Oct 2017 00:57:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52C061E2D7; Thu, 12 Oct 2017 08:01:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 52C061E2D7 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-92.rdu2.redhat.com [10.10.120.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CC7218A5C; Thu, 12 Oct 2017 08:01:04 +0000 (UTC) To: Eric Dong Cc: edk2-devel@lists.01.org, Ruiyu Ni , Jiewen Yao References: <1507710130-3044-1-git-send-email-eric.dong@intel.com> <1507710130-3044-3-git-send-email-eric.dong@intel.com> From: Laszlo Ersek Message-ID: <8d678707-fb07-0326-acfd-878bb7e8c5d6@redhat.com> Date: Thu, 12 Oct 2017 10:01:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1507710130-3044-3-git-send-email-eric.dong@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 12 Oct 2017 08:01:06 +0000 (UTC) Subject: Re: [Patch v3 2/3] UefiCpuPkg/S3Resume2Pei: Send S3 resume finished event to SmmCore. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Oct 2017 07:57:36 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Hi, I'm sorry that I couldn't comment on this patch in time. However, I must observe that version 1 of the patch, http://mid.mail-archive.com/1507688554-10264-3-git-send-email-eric.dong@intel.com was sent out at 04:22 AM on 11 Oct, in my time zone; and version 3 of the patch was committed at 04:17 AM on 12 Oct in my time zone. That's not a lot of time for reviewers to comment -- I was very busy with other stuff yesterday. I even set up an auto-reply about that, asking for a bit of patience. Of course the auto-reply didn't help, because I wasn't CC'd on the patch in the first place; despite my earlier request to be CC'd on all SMM- and/or S3-related patches. So, after this introduction: On 10/11/17 10:22, Eric Dong wrote: > Driver will send S3 resume finished event to SmmCore through communicate > buffer after it signals EndOfPei event. > > V2 Changes: > 1. Change structures name to avoid they start with EFI_. > 2. Base on DXE phase bits to provide communication buffer, current implement > check both PEI and DXE phase. > > V3 Changes: > 1. Change structure name for better understanding. > 2. Enhance communication buffer calculate logic to more accurate. > > Cc: Ruiyu Ni > Cc: Jiewen Yao > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Eric Dong > --- > UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c | 87 ++++++++++++++++++++++ > .../Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf | 4 + > 2 files changed, 91 insertions(+) > > diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c > index e53ed21..c2171cb 100644 > --- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c > +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c > @@ -28,6 +28,9 @@ > #include > #include > #include > +#include > + > +#include > > #include > #include > @@ -151,6 +154,22 @@ typedef union { > UINT64 Uint64; > } PAGE_TABLE_1G_ENTRY; > > +// > +// Define two type of smm communicate headers. > +// One for 32 bits PEI + 64 bits DXE, the other for 32 bits PEI + 32 bits DXE case. > +// > +typedef struct { > + EFI_GUID HeaderGuid; > + UINT32 MessageLength; > + UINT8 Data[1]; > +} SMM_COMMUNICATE_HEADER_32; > + > +typedef struct { > + EFI_GUID HeaderGuid; > + UINT64 MessageLength; > + UINT8 Data[1]; > +} SMM_COMMUNICATE_HEADER_64; > + > #pragma pack() > > // > @@ -430,6 +449,68 @@ IsLongModeWakingVector ( > } > > /** > + Send EndOfS3Resume event to SmmCore through communication buffer way. > + > + @retval EFI_SUCCESS Return send the event success. > +**/ > +EFI_STATUS > +SignalEndOfS3Resume ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + EFI_PEI_SMM_COMMUNICATION_PPI *SmmCommunicationPpi; > + UINTN CommSize; > + SMM_COMMUNICATE_HEADER_32 Header32; > + SMM_COMMUNICATE_HEADER_64 Header64; > + VOID *CommBuffer; > + > + DEBUG ((EFI_D_INFO, "SignalEndOfS3Resume - Enter\n")); > + > + // > + // This buffer consumed in DXE phase, so base on DXE mode to prepare communicate buffer. > + // Detect whether DXE is 64 bits mode. > + // if (sizeof(UINTN) == sizeof(UINT64), PEI already 64 bits, assume DXE also 64 bits. > + // or (FeaturePcdGet (PcdDxeIplSwitchToLongMode)), Dxe will switch to 64 bits. > + // > + if ((sizeof(UINTN) == sizeof(UINT64)) || (FeaturePcdGet (PcdDxeIplSwitchToLongMode))) { > + CommBuffer = &Header64; > + Header64.MessageLength = 0; > + CommSize = OFFSET_OF (SMM_COMMUNICATE_HEADER_64, Data); > + } else { > + CommBuffer = &Header32; > + Header32.MessageLength = 0; > + CommSize = OFFSET_OF (SMM_COMMUNICATE_HEADER_32, Data); > + } > + CopyGuid (CommBuffer, &gEdkiiSmmEndOfS3ResumeProtocolGuid); > + > + // > + // Get needed resource > + // > + Status = PeiServicesLocatePpi ( > + &gEfiPeiSmmCommunicationPpiGuid, > + 0, > + NULL, > + (VOID **)&SmmCommunicationPpi > + ); > + ASSERT_EFI_ERROR (Status); This patch breaks S3 resume with OVMF+SMM. OVMF does not have or install an EFI_PEI_SMM_COMMUNICATION_PPI. We discussed this ~2 years ago, when SMM was being added to KVM, QEMU, and OVMF. OVMF would have needed EFI_PEI_SMM_COMMUNICATION_PPI only for SmmLockBoxPeiLib. But we agreed that SmmLockBoxPeiLib would work without this PPI; exactly the same as if the PPI existed, but Communicate() returned EFI_NOT_STARTED. Namely, if RestoreLockBox() failed to locate EFI_PEI_SMM_COMMUNICATION_PPI, then InternalRestoreLockBoxFromSmram() would be called instead, which only needed PEI_SMM_ACCESS_PPI. And OVMF would provide that, so everything would work fine. Please see the following edk2 commits: https://github.com/tianocore/edk2/commit/bd3afeb1d62c https://github.com/tianocore/edk2/commit/9d560947f6d3 Eric, can you please modify SignalEndOfS3Resume() as follows: - locate EFI_PEI_SMM_COMMUNICATION_PPI as first action, - if it is not found, return EFI_NOT_FOUND gracefully, - in S3ResumeBootOs(), simply log the return value, and proceed. Currently, during S3 resume (with SMM), I get > SignalEndOfS3Resume - Enter > ASSERT_EFI_ERROR (Status = Not Found) > ASSERT UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c(496): !EFI_ERROR (Status) Thanks, Laszlo > + > + // > + // Send command > + // > + Status = SmmCommunicationPpi->Communicate ( > + SmmCommunicationPpi, > + (VOID *)CommBuffer, > + &CommSize > + ); > + ASSERT_EFI_ERROR (Status); > + > + DEBUG ((EFI_D_INFO, "SignalEndOfS3Resume - Exit (%r)\n", Status)); > + > + return Status; > +} > + > +/** > Jump to OS waking vector. > The function will install boot script done PPI, report S3 resume status code, and then jump to OS waking vector. > > @@ -504,6 +585,12 @@ S3ResumeBootOs ( > ASSERT_EFI_ERROR (Status); > > // > + // Signal EndOfS3Resume event. > + // > + Status = SignalEndOfS3Resume (); > + ASSERT_EFI_ERROR (Status); > + > + // > // report status code on S3 resume > // > REPORT_STATUS_CODE (EFI_PROGRESS_CODE, EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_OS_WAKE); > diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf > index d514523..943f114 100644 > --- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf > +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf > @@ -85,6 +85,10 @@ > gPeiSmmAccessPpiGuid ## SOMETIMES_CONSUMES > gPeiPostScriptTablePpiGuid ## SOMETIMES_PRODUCES > gEfiEndOfPeiSignalPpiGuid ## SOMETIMES_PRODUCES > + gEfiPeiSmmCommunicationPpiGuid ## SOMETIMES_CONSUMES > + > +[Protocols] > + gEdkiiSmmEndOfS3ResumeProtocolGuid ## SOMETIMES_CONSUMES > > [FeaturePcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUMES >