From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jiewen.yao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 1316421E256A0 for ; Wed, 24 Jan 2018 22:34:15 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2018 22:39:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,409,1511856000"; d="scan'208";a="196120813" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga005.jf.intel.com with ESMTP; 24 Jan 2018 22:39:43 -0800 Received: from fmsmsx151.amr.corp.intel.com (10.18.125.4) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 24 Jan 2018 22:39:43 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX151.amr.corp.intel.com (10.18.125.4) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 24 Jan 2018 22:39:43 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.189]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.213]) with mapi id 14.03.0319.002; Thu, 25 Jan 2018 14:39:41 +0800 From: "Yao, Jiewen" To: "Zhang, Chao B" , "edk2-devel@lists.01.org" CC: "Chinnusamy, Rajkumar K" Thread-Topic: [PATCH] SecurityPkg:Tpm2DeviceLibDTpm: Support TPM command cancel Thread-Index: AQHTlZiDIxMk5XAnJ0CsPySzazppN6OEI09g Date: Thu, 25 Jan 2018 06:39:39 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AA8B39D@shsmsx102.ccr.corp.intel.com> References: <20180125045350.22372-1-chao.b.zhang@intel.com> <20180125045350.22372-4-chao.b.zhang@intel.com> In-Reply-To: <20180125045350.22372-4-chao.b.zhang@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiM2VhODgxMTQtM2Q5Ny00NjA1LThkNGQtMzNlM2VmMzY2NTFmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiIxdVpUTit3RU9tVEExVVk2TmI4UnpHaEU0Y0FGWTl0VDZPaTJQKzdrTFwvS3BqTU5pZnFqcExlR2dpdkM5XC9IbnYifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] SecurityPkg:Tpm2DeviceLibDTpm: Support TPM command cancel X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jan 2018 06:34:15 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jiewen.yao@intel.com > -----Original Message----- > From: Zhang, Chao B > Sent: Thursday, January 25, 2018 12:54 PM > To: edk2-devel@lists.01.org > Cc: Yao, Jiewen ; Chinnusamy, Rajkumar K > ; Zhang, Chao B > Subject: [PATCH] SecurityPkg:Tpm2DeviceLibDTpm: Support TPM command > cancel >=20 > Support TPM Command cancel if executing command timeouts. Cancel could > happen in long running command case >=20 > Cc: Yao Jiewen > Cc: Chinnusamy Rajkumar K > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Chao Zhang > --- > MdePkg/Include/IndustryStandard/TpmTis.h | 8 +++++-- > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c | 24 > +++++++++++++++++--- > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c | 30 > +++++++++++++++++++++---- > 3 files changed, 53 insertions(+), 9 deletions(-) >=20 > diff --git a/MdePkg/Include/IndustryStandard/TpmTis.h > b/MdePkg/Include/IndustryStandard/TpmTis.h > index 519fa79..f25ca25 100644 > --- a/MdePkg/Include/IndustryStandard/TpmTis.h > +++ b/MdePkg/Include/IndustryStandard/TpmTis.h > @@ -2,7 +2,7 @@ > TPM Interface Specification definition. > It covers both TPM1.2 and TPM2.0. >=20 > -Copyright (c) 2016, Intel Corporation. All rights reserved.
> +Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the BS= D > License > which accompanies this distribution. The full text of the license may b= e found > at > @@ -143,6 +143,10 @@ typedef TIS_PC_REGISTERS > *TIS_PC_REGISTERS_PTR; > #define TIS_PC_ACC_ESTABLISH BIT0 >=20 > /// > +/// Write a 1 to this bit to notify TPM to cancel currently executing co= mmand > +/// > +#define TIS_PC_STS_CANCEL BIT24 > +/// > /// This field indicates that STS_DATA and STS_EXPECT are valid > /// > #define TIS_PC_STS_VALID BIT7 > @@ -180,4 +184,4 @@ typedef TIS_PC_REGISTERS *TIS_PC_REGISTERS_PTR; > #define TIS_TIMEOUT_C (750 * 1000) // 750ms > #define TIS_TIMEOUT_D (750 * 1000) // 750ms >=20 > -#endif > \ No newline at end of file > +#endif > diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c > b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c > index ddd4bd0..d9df264 100644 > --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c > +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c > @@ -1,7 +1,7 @@ > /** @file > PTP (Platform TPM Profile) CRB (Command Response Buffer) interface use= d > by dTPM2.0 library. >=20 > -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> +Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the BS= D > License > which accompanies this distribution. The full text of the license may b= e found > at > @@ -240,8 +240,26 @@ PtpCrbTpmCommand ( > PTP_TIMEOUT_MAX > ); > if (EFI_ERROR (Status)) { > - Status =3D EFI_DEVICE_ERROR; > - goto Exit; > + // > + // Command Completion check timeout. Cancel the currently executing > command by writing TPM_CRB_CTRL_CANCEL, > + // Expect TPM_RC_CANCELLED or successfully completed response. > + // > + MmioWrite32((UINTN)&CrbReg->CrbControlCancel, > PTP_CRB_CONTROL_CANCEL); > + Status =3D PtpCrbWaitRegisterBits ( > + &CrbReg->CrbControlStart, > + 0, > + PTP_CRB_CONTROL_START, > + PTP_TIMEOUT_B > + ); > + MmioWrite32((UINTN)&CrbReg->CrbControlCancel, 0); > + > + if (EFI_ERROR(Status)) { > + // > + // Still in Command Execution state. Try to goIdle, the behavior i= s > agnostic. > + // > + Status =3D EFI_DEVICE_ERROR; > + goto Exit; > + } > } >=20 > // > diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c > b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c > index 6cd7030..0889162 100644 > --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c > +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c > @@ -1,7 +1,7 @@ > /** @file > TIS (TPM Interface Specification) functions used by dTPM2.0 library. >=20 > -Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
> +Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
> (C) Copyright 2015 Hewlett Packard Enterprise Development LP
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the BS= D > License > @@ -295,10 +295,32 @@ Tpm2TisTpmCommand ( > TIS_TIMEOUT_MAX > ); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "Wait for Tpm2 response data time out!!\n")); > - Status =3D EFI_DEVICE_ERROR; > - goto Exit; > + // > + // dataAvail check timeout. Cancel the currently executing command b= y > writing commandCancel, > + // Expect TPM_RC_CANCELLED or successfully completed response. > + // > + DEBUG ((DEBUG_ERROR, "Wait for Tpm2 response data time out. Trying t= o > cancel the command!!\n")); > + > + MmioWrite32((UINTN)&TisReg->Status, TIS_PC_STS_CANCEL); > + Status =3D TisPcWaitRegisterBits ( > + &TisReg->Status, > + (UINT8) (TIS_PC_VALID | TIS_PC_STS_DATA), > + 0, > + TIS_TIMEOUT_B > + ); > + // > + // Do not clear CANCEL bit here bicoz Writes of 0 to this bit are ig= nored > + // > + if (EFI_ERROR (Status)) { > + // > + // Cancel executing command fail to get any response > + // Try to abort the command with write of a 1 to commandReady in > Command Execution state > + // > + Status =3D EFI_DEVICE_ERROR; > + goto Exit; > + } > } > + > // > // Get response data header > // > -- > 1.9.5.msysgit.1