From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3F0E81A1E8E for ; Tue, 11 Oct 2016 01:35:11 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP; 11 Oct 2016 01:35:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,476,1473145200"; d="scan'208";a="18404213" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga005.jf.intel.com with ESMTP; 11 Oct 2016 01:35:10 -0700 Received: from fmsmsx126.amr.corp.intel.com (10.18.125.43) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 11 Oct 2016 01:35:10 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX126.amr.corp.intel.com (10.18.125.43) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 11 Oct 2016 01:35:10 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.118]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.95]) with mapi id 14.03.0248.002; Tue, 11 Oct 2016 16:35:08 +0800 From: "Tian, Feng" To: "Dong, Eric" , "edk2-devel@lists.01.org" CC: "Tian, Feng" Thread-Topic: [Patch] SecurityPkg OpalPasswordSmm: Fix S3 resume failure. Thread-Index: AQHSI5W8Vn60Ta4NOEy8PYoYj2b1I6Ci7YLQ Date: Tue, 11 Oct 2016 08:35:07 +0000 Message-ID: <7F1BAD85ADEA444D97065A60D2E97EE566E26E0D@SHSMSX101.ccr.corp.intel.com> References: <1476172908-70824-1-git-send-email-eric.dong@intel.com> In-Reply-To: <1476172908-70824-1-git-send-email-eric.dong@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] SecurityPkg OpalPasswordSmm: Fix S3 resume failure. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Oct 2016 08:35:11 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Looks good to me Reviewed-by: Feng Tian Thanks Feng -----Original Message----- From: Dong, Eric=20 Sent: Tuesday, October 11, 2016 4:02 PM To: edk2-devel@lists.01.org Cc: Tian, Feng Subject: [Patch] SecurityPkg OpalPasswordSmm: Fix S3 resume failure. Changes includes: 1.Check SMM device list before update it to avoid duplicate creation. 2.Clean up the configuration buffer before use it in S3 resume phase. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong Cc: Feng Tian --- .../Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c | 8 ++ .../Tcg/Opal/OpalPasswordSmm/OpalPasswordSmm.c | 89 +++++++++++++++++-= ---- 2 files changed, 76 insertions(+), 21 deletions(-) diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c b/Security= Pkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c index 3826698..9e90d54 100644 --- a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c +++ b/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c @@ -1691,6 +1691,14 @@ NvmeControllerInit ( Nvme->Cid[0] =3D 0; Nvme->Cid[1] =3D 0; =20 + Nvme->Pt[0] =3D 0; + Nvme->Pt[1] =3D 0; + + ZeroMem ((VOID *)(UINTN)(&(Nvme->SqTdbl[0])), sizeof (NVME_SQTDBL) *=20 + NVME_MAX_IO_QUEUES); ZeroMem ((VOID *)(UINTN)(&(Nvme->CqHdbl[0])),=20 + sizeof (NVME_CQHDBL) * NVME_MAX_IO_QUEUES); + + ZeroMem ((VOID *)(UINTN)Nvme->BaseMem, NVME_MEM_MAX_SIZE); + Status =3D NvmeDisableController (Nvme); if (EFI_ERROR(Status)) { DEBUG ((DEBUG_ERROR, "NvmeDisableController fail, Status: %r\n", Statu= s)); diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalPasswordSmm.c b/= SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalPasswordSmm.c index 47b570f..2f2a1d9 100644 --- a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalPasswordSmm.c +++ b/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalPasswordSmm.c @@ -483,6 +483,53 @@ done: return Status; } =20 +/** + The function extracts device information from OpalDeviceList and creat S= mmDeviceList used for S3. + + @param[in] OpalDeviceList Opal device list created at POST which= contains the information of OPAL_DISK_AND_PASSWORD_INFO + @param[in,out] SmmDeviceList Opal Smm device list to be created and= used for unlocking devices at S3 resume. + + @retval EFI_SUCCESS Create SmmDeviceList successfully. + @retval Others Other execution results. +**/ +EFI_STATUS +CreateSmmDeviceList ( + IN LIST_ENTRY *OpalDeviceList, + IN OUT LIST_ENTRY *SmmDeviceList + ) +{ + LIST_ENTRY *Entry; + OPAL_DISK_AND_PASSWORD_INFO *PciDev; + OPAL_SMM_DEVICE *SmmDev; + + for (Entry =3D OpalDeviceList->ForwardLink; Entry !=3D OpalDeviceList; E= ntry =3D Entry->ForwardLink) { + PciDev =3D BASE_CR (Entry, OPAL_DISK_AND_PASSWORD_INFO, Link); + + SmmDev =3D AllocateZeroPool (sizeof (OPAL_SMM_DEVICE)); + if (SmmDev =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + SmmDev->Signature =3D OPAL_SMM_DEVICE_SIGNATURE; + + ExtractDeviceInfoFromDevicePath(&PciDev->OpalDevicePath, SmmDev); + + SmmDev->PasswordLength =3D PciDev->PasswordLength; + CopyMem(&(SmmDev->Password), PciDev->Password,=20 + OPAL_PASSWORD_MAX_LENGTH); + + SmmDev->Sscp.ReceiveData =3D SecurityReceiveData; + SmmDev->Sscp.SendData =3D SecuritySendData; + + DEBUG ((DEBUG_INFO, "Opal SMM: Insert device node to SmmDeviceList:\n"= )); + DEBUG ((DEBUG_INFO, "DeviceType:%x, Bus:%d, Dev:%d, Fun:%d\n", \ + SmmDev->DeviceType, SmmDev->BusNum, SmmDev->DevNum, SmmDev->FuncNum)= ); + DEBUG ((DEBUG_INFO, "SataPort:%x, MultiplierPort:%x, NvmeNamespaceId:%= x\n", \ + SmmDev->SataPort, SmmDev->SataPortMultiplierPort,=20 + SmmDev->NvmeNamespaceId)); + + InsertHeadList (SmmDeviceList, &SmmDev->Link); } + + return EFI_SUCCESS; +} =20 /** Main entry point for an SMM handler dispatch or communicate-based callba= ck. @@ -521,7 +568,6 @@ S3SleepEntryCallBack ( UINT64 Address; S3_BOOT_SCRIPT_LIB_WIDTH Width; UINT32 Data; - OPAL_DISK_AND_PASSWORD_INFO *PciDev; OPAL_HC_PCI_REGISTER_SAVE *HcRegisterSaveListPtr; UINTN Count; OPAL_SMM_DEVICE *SmmDev; @@ -530,25 +576,28 @@ S3SleepEntryCallBack ( Status =3D EFI_SUCCESS; =20 mOpalDeviceList =3D OpalSupportGetOpalDeviceList(); + if (IsListEmpty (mOpalDeviceList)) { + // + // No Opal enabled device. Do nothing. + // + return EFI_SUCCESS; + } =20 - for (Entry =3D mOpalDeviceList->ForwardLink; Entry !=3D mOpalDeviceList;= Entry =3D Entry->ForwardLink) { - PciDev =3D BASE_CR (Entry, OPAL_DISK_AND_PASSWORD_INFO, Link); - - SmmDev =3D AllocateZeroPool (sizeof (OPAL_SMM_DEVICE)); - if (SmmDev =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; + if (IsListEmpty (&mSmmDeviceList)) { + // + // mSmmDeviceList for S3 is empty, creat it by mOpalDeviceList. + // + Status =3D CreateSmmDeviceList (mOpalDeviceList, &mSmmDeviceList); + if (EFI_ERROR (Status)) { + return Status; } - SmmDev->Signature =3D OPAL_SMM_DEVICE_SIGNATURE; - - ExtractDeviceInfoFromDevicePath(&PciDev->OpalDevicePath, SmmDev); - - SmmDev->PasswordLength =3D PciDev->PasswordLength; - CopyMem(&(SmmDev->Password), PciDev->Password, OPAL_PASSWORD_MAX_LENGT= H); - - SmmDev->Sscp.ReceiveData =3D SecurityReceiveData; - SmmDev->Sscp.SendData =3D SecuritySendData; + } =20 - InsertHeadList (&mSmmDeviceList, &SmmDev->Link); + // + // Go through SmmDeviceList to save register data for S3 // for=20 + (Entry =3D mSmmDeviceList.ForwardLink; Entry !=3D &mSmmDeviceList; Entry = =3D Entry->ForwardLink) { + SmmDev =3D BASE_CR (Entry, OPAL_SMM_DEVICE, Link); =20 if (SmmDev->DeviceType =3D=3D OPAL_DEVICE_TYPE_NVME) { continue; @@ -592,10 +641,8 @@ S3SleepEntryCallBack ( } } =20 - if (!IsListEmpty (mOpalDeviceList)) { - Status =3D S3BootScriptSaveIoWrite (S3BootScriptWidthUint8, 0xB2, 1, &= mSwSmiValue); - ASSERT_EFI_ERROR (Status); - } + Status =3D S3BootScriptSaveIoWrite (S3BootScriptWidthUint8, 0xB2, 1,=20 + &mSwSmiValue); ASSERT_EFI_ERROR (Status); =20 return Status; } -- 2.6.4.windows.1