From patchwork Wed Jul 13 16:19:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Swierk X-Patchwork-Id: 9228017 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 28E726075D for ; Wed, 13 Jul 2016 16:57:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16DEB27FAB for ; Wed, 13 Jul 2016 16:57:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0897727FBB; Wed, 13 Jul 2016 16:57:44 +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=unavailable 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 78ADC27FAB for ; Wed, 13 Jul 2016 16:57:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bNNTi-0002L3-7X; Wed, 13 Jul 2016 16:57:42 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bNMyI-0006W6-Mp for tpmdd-devel@lists.sourceforge.net; Wed, 13 Jul 2016 16:25:14 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of skyportsystems.com designates 209.85.220.44 as permitted sender) client-ip=209.85.220.44; envelope-from=eswierk@skyportsystems.com; helo=mail-pa0-f44.google.com; Received: from mail-pa0-f44.google.com ([209.85.220.44]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1bNMyH-0001gl-UH for tpmdd-devel@lists.sourceforge.net; Wed, 13 Jul 2016 16:25:14 +0000 Received: by mail-pa0-f44.google.com with SMTP id pp5so12496575pac.3 for ; Wed, 13 Jul 2016 09:25:13 -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:in-reply-to :references; bh=9XE+uy3r4mmxkNRXI7Isf2TcDrttJoC4Cm0lQKHIQ7E=; b=JVxJ9w9kfSMETGY0dqFahqXwd+WI6JNwl1PHdI/M3W+VVIXezmheuI0HxmDPOGZIwY RCOdV5+tENMPHlePXSqkNPMAlAMpQC4DIHjknEey4DkHvsyAREF7U1yR3+7Qaxm/dId6 8akJitTv0stWDg9s63QPOgkk8vr8abLtNmN7a79OMK5BDOy5833M9jiBTa1723nzq6dJ wlQlMRMY1V8BdsDVa0sa9aKFE2RYIYx9pO33eTJEqhyodB9IwkGXkFurpYe6Vixw4gat KcfRPp/PSEuiDb9MSuvBocshdv96Mv/6l9kEd7TCCsou6qYqWNm3T6DZHAozJ64Qe2vY aMiw== X-Gm-Message-State: ALyK8tLyoIIBRo4XrjGfYYlowJ3w1xyI5CR7bw52igJOrHYfoSF5Rziisnne8eEkA+PM8o7N X-Received: by 10.66.7.199 with SMTP id l7mr14861153paa.136.1468426790368; Wed, 13 Jul 2016 09:19:50 -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 15sm6015473pfz.36.2016.07.13.09.19.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Jul 2016 09:19:49 -0700 (PDT) From: Ed Swierk To: tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Date: Wed, 13 Jul 2016 09:19:36 -0700 Message-Id: <1468426776-42762-6-git-send-email-eswierk@skyportsystems.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468426776-42762-1-git-send-email-eswierk@skyportsystems.com> References: <1466557831-113440-1-git-send-email-eswierk@skyportsystems.com> <1468426776-42762-1-git-send-email-eswierk@skyportsystems.com> X-Headers-End: 1bNMyH-0001gl-UH Subject: [tpmdd-devel] [PATCH v9 5/5] tpm_tis: Increase ST19NP18 TPM command duration 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 3000 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 precompute keys, 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 being blocked by this process. So it seems safest to ignore the chip's reported command durations, and use a value much higher than any observed duration, like 180 sec (which is the duration this chip reports for "long" commands). Signed-off-by: Ed Swierk --- drivers/char/tpm/tpm_tis_core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index f013664..84d6008 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -416,6 +416,12 @@ static void tpm_tis_update_timeouts(struct tpm_chip *chip) chip->timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); chip->timeout_adjusted = true; break; + case 0x0000104a: /* STMicro ST19NP18-TPM */ + chip->duration[TPM_SHORT] = 180 * HZ; + chip->duration[TPM_MEDIUM] = 180 * HZ; + chip->duration[TPM_LONG] = 180 * HZ; + chip->duration_adjusted = true; + break; } }