From patchwork Mon Jun 6 22:27:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Swierk X-Patchwork-Id: 9159287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B852D60573 for ; Mon, 6 Jun 2016 22:28:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A800828210 for ; Mon, 6 Jun 2016 22:28:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CD812833E; Mon, 6 Jun 2016 22:28:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1210D28210 for ; Mon, 6 Jun 2016 22:28:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bA30F-00013q-Lv; Mon, 06 Jun 2016 22:28:11 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bA30E-00013k-Ck for tpmdd-devel@lists.sourceforge.net; Mon, 06 Jun 2016 22:28:10 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of skyportsystems.com designates 209.85.192.177 as permitted sender) client-ip=209.85.192.177; envelope-from=eswierk@skyportsystems.com; helo=mail-pf0-f177.google.com; Received: from mail-pf0-f177.google.com ([209.85.192.177]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1bA30C-0004hV-Ku for tpmdd-devel@lists.sourceforge.net; Mon, 06 Jun 2016 22:28:10 +0000 Received: by mail-pf0-f177.google.com with SMTP id g64so70924620pfb.2 for ; Mon, 06 Jun 2016 15:28:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WoLmWZu1mZ0EMQM4FN5t4CDY6jTOBOmTNmT5qQDypS0=; b=CQRz2QXj2inFh2ReVJ5QUlVHFpDvvYmVNdzJwvxANXhENPt4suAJx/W3xTXHcLXjm8 FsrRkZMMEynvqSWDfs+n2Ki748niDgkNxBtOuGg2aPLEJ/RG33217LwCLJX16oPyR3K5 +PJfoH9swYzptnhlmXg/zcIwNepOkQuy5OHBW7ILhxZjJ51nzGONrFLEObaAJdlhc+3g cx1Nh7ycfU0ZP7xpmPT4jhWxUZpUH16D3OyD8JZ1tefgowLGB7npA0fGhUR2p7VwO4Ki GMQktTTaoyIJJetWCeoz/ZyIJnf8kHBsqTLdsYI6mclgkl/K5gTXAjqUrWOUXCwlWKC9 UD1w== X-Gm-Message-State: ALyK8tLyexM9khG3RP98hsgZkqGr/ypLGL9ra1yov78YgURvD4cvjYoJofxT2NdUug6K+uKy X-Received: by 10.98.71.135 with SMTP id p7mr27787905pfi.165.1465252082859; Mon, 06 Jun 2016 15:28:02 -0700 (PDT) Received: from eswierk-sc.localdomain (67-207-112-138.static.wiline.com. [67.207.112.138]) by smtp.gmail.com with ESMTPSA id 75sm29924241pfo.82.2016.06.06.15.28.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Jun 2016 15:28:02 -0700 (PDT) From: Ed Swierk To: tpmdd-devel@lists.sourceforge.net Date: Mon, 6 Jun 2016 15:27:59 -0700 Message-Id: <1465252079-126836-1-git-send-email-eswierk@skyportsystems.com> X-Mailer: git-send-email 1.9.1 X-Headers-End: 1bA30C-0004hV-Ku Subject: [tpmdd-devel] [PATCH v2] tpm_tis: Increase ST19NP18 TPM command timeout to avoid chip lockup X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP The STMicro ST19NP18-TPM sometimes takes much longer to execute commands than it reports in its capabilities. For example, command 186 (TPM_FlushSpecific) has been observed to take 14560 msec to complete, far longer than the 750 msec limit for "short" commands reported by the chip. The behavior has also been seen with command 101 (TPM_GetCapability). Worse, when the tpm_tis driver attempts to cancel the current command (by writing commandReady = 1 to TPM_STS_x), the chip locks up completely, returning all-1s from all memory-mapped register reads. The lockup can be cleared only by resetting the system. The occurrence of this excessive command duration depends on the sequence of commands preceding it. One sequence is creating at least 2 new keys via TPM_CreateWrapKey, then letting the TPM idle for at least 30 seconds, then loading a key via TPM_LoadKey2. The next TPM_FlushSpecific occasionally takes tens of seconds to complete. Another sequence is creating many keys in a row without pause. The TPM_CreateWrapKey operation gets much slower after the first few iterations, as one would expect when the pool of precomputed keys is exhausted. Then after a 35-second pause, the same TPM_LoadKey2 followed by TPM_FlushSpecific sequence triggers the behavior. Our working theory is that this older TPM sometimes pauses to perform internal garbage collection, which modern chips implement as a background process. Without access to the chip's implementation details it's impossible to know whether any commands are immune to this behavior. So it seems safest to ignore the chip's reported command durations, and use a value much higher than any observed duration, like 2 minutes (which happens to be the value used for TPM_UNDEFINED commands in tpm_calc_ordinal_duration()). v2: Minor correction of patch description. Signed-off-by: Ed Swierk Reviewed-by: Stefan Berger Acked-by: Jarkko Sakkinne --- drivers/char/tpm/tpm_tis.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index 088fa86..3070be2 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -484,6 +484,9 @@ static const struct tis_vendor_timeout_override vendor_timeout_overrides[] = { /* Atmel 3204 */ { 0x32041114, { (TIS_SHORT_TIMEOUT*1000), (TIS_LONG_TIMEOUT*1000), (TIS_SHORT_TIMEOUT*1000), (TIS_SHORT_TIMEOUT*1000) } }, + /* STMicro ST19NP18-TPM */ + { 0x0000104a, { (120*1000*1000), (120*1000*1000), + (120*1000*1000), (120*1000*1000) } }, }; static bool tpm_tis_update_timeouts(struct tpm_chip *chip,