From nobody Fri Nov 1 10:33:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1516856043843168.94235669372028; Wed, 24 Jan 2018 20:54:03 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7CC3A221F93DC; Wed, 24 Jan 2018 20:48:31 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 7BFA221E256AE for ; Wed, 24 Jan 2018 20:48:28 -0800 (PST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2018 20:53:57 -0800 Received: from czhan46-mobl1.ccr.corp.intel.com ([10.239.192.90]) by orsmga005.jf.intel.com with ESMTP; 24 Jan 2018 20:53:56 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=chao.b.zhang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,409,1511856000"; d="scan'208";a="196103084" From: "Zhang, Chao B" To: edk2-devel@lists.01.org Date: Thu, 25 Jan 2018 12:53:50 +0800 Message-Id: <20180125045350.22372-4-chao.b.zhang@intel.com> X-Mailer: git-send-email 2.11.0.windows.1 In-Reply-To: <20180125045350.22372-1-chao.b.zhang@intel.com> References: <20180125045350.22372-1-chao.b.zhang@intel.com> Subject: [edk2] [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: , Cc: Yao Jiewen , Chinnusamy Rajkumar K , Chao Zhang MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Support TPM Command cancel if executing command timeouts. Cancel could happen in long running command case Cc: Yao Jiewen Cc: Chinnusamy Rajkumar K Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Chao Zhang Reviewed-by: Jiewen.yao@intel.com --- 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(-) diff --git a/MdePkg/Include/IndustryStandard/TpmTis.h b/MdePkg/Include/Indu= stryStandard/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 BSD = License which accompanies this distribution. The full text of the license may be = 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 comm= and +/// +#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 used = 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 BSD = License which accompanies this distribution. The full text of the license may be = 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 co= mmand 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 is = 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=20 are licensed and made available under the terms and conditions of the BSD = License=20 @@ -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 by = writing commandCancel, + // Expect TPM_RC_CANCELLED or successfully completed response. + // + DEBUG ((DEBUG_ERROR, "Wait for Tpm2 response data time out. Trying to = 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 igno= red + // + 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 Com= mand Execution state + // + Status =3D EFI_DEVICE_ERROR; + goto Exit; + } } + // // Get response data header // --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel