From patchwork Tue Jun 21 01:53: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: 9189163 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 A5AD96075F for ; Tue, 21 Jun 2016 01:54:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92A0E27E66 for ; Tue, 21 Jun 2016 01:54:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 879A227F7A; Tue, 21 Jun 2016 01:54:31 +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 1A43627E66 for ; Tue, 21 Jun 2016 01:54:31 +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 1bFAtX-0001zy-Kc; Tue, 21 Jun 2016 01:54:27 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bFAtW-0001zs-AW for tpmdd-devel@lists.sourceforge.net; Tue, 21 Jun 2016 01:54:26 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of skyportsystems.com designates 209.85.192.179 as permitted sender) client-ip=209.85.192.179; envelope-from=eswierk@skyportsystems.com; helo=mail-pf0-f179.google.com; Received: from mail-pf0-f179.google.com ([209.85.192.179]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1bFAtU-0000VT-Kk for tpmdd-devel@lists.sourceforge.net; Tue, 21 Jun 2016 01:54:26 +0000 Received: by mail-pf0-f179.google.com with SMTP id h14so947050pfe.1 for ; Mon, 20 Jun 2016 18:54:24 -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=+wPGmQRRCyjbvY4BVI8er6KyBjedNLjCS2Q4FBBiyAE=; b=a9IMD9MVwQXrvefgPlkXy3t5JVmPSrkFCg9h73cFwVvkB6lahpqNuv36rpNfXb2FsK jOmeKPVmO4otDqjfe8T7OD+sSttmJIweexWPFnjPOJYQfAeun2PNsNG8T782F2xEewjw IYTRiy9Ckb8wk9GpRJckcOv+hUN6GE2G5F27aTHTH+VoSyVnqU1wk2SArFNnOTuVPaqo PkgUmKRV1oyGcl4eYLqpXrzK9cJDjivA112GKngCmaafLz/GX0UoiyeWBz7Jalp6A4v9 DJkv3Oto6hVTCvJ/7oVoCVc43A+rTRRS9zU/zZjJ/hMyE6NAm0N1gPjv1H50Dsc8O25c Lclg== X-Gm-Message-State: ALyK8tIYhjqcRa4ElxCYxDVYDpc60vTaI/GP2embES+x24IXFSoY7gdbAElI6Q3s0nDKGu+8 X-Received: by 10.98.130.65 with SMTP id w62mr25173220pfd.5.1466474058914; Mon, 20 Jun 2016 18:54:18 -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 i8sm91219159pao.26.2016.06.20.18.54.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Jun 2016 18:54:18 -0700 (PDT) From: Ed Swierk To: tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Date: Mon, 20 Jun 2016 18:53:59 -0700 Message-Id: <1466474042-110773-3-git-send-email-eswierk@skyportsystems.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466474042-110773-1-git-send-email-eswierk@skyportsystems.com> References: <1465610107-87762-1-git-send-email-eswierk@skyportsystems.com> <1466474042-110773-1-git-send-email-eswierk@skyportsystems.com> X-Headers-End: 1bFAtU-0000VT-Kk Subject: [tpmdd-devel] [PATCH v7 2/5] tpm: Add optional logging of TPM command durations 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 Some TPMs violate their own advertised command durations. This is much easier to debug with data about how long each command actually takes to complete. Add debug messages that can be enabled by running echo -n 'module tpm +p' >/sys/kernel/debug/dynamic_debug/control on a kernel configured with DYNAMIC_DEBUG=y. Signed-off-by: Ed Swierk Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-interface.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index c50637d..cc1e5bc 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -333,13 +333,14 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, { ssize_t rc; u32 count, ordinal; - unsigned long stop; + unsigned long start, stop; if (bufsiz > TPM_BUFSIZE) bufsiz = TPM_BUFSIZE; count = be32_to_cpu(*((__be32 *) (buf + 2))); ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); + dev_dbg(chip->pdev, "starting command %d count %d\n", ordinal, count); if (count == 0) return -ENODATA; if (count > bufsiz) { @@ -360,18 +361,24 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, if (chip->vendor.irq) goto out_recv; + start = jiffies; if (chip->flags & TPM_CHIP_FLAG_TPM2) - stop = jiffies + tpm2_calc_ordinal_duration(chip, ordinal); + stop = start + tpm2_calc_ordinal_duration(chip, ordinal); else - stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); + stop = start + tpm_calc_ordinal_duration(chip, ordinal); do { u8 status = chip->ops->status(chip); if ((status & chip->ops->req_complete_mask) == - chip->ops->req_complete_val) + chip->ops->req_complete_val) { + dev_dbg(chip->pdev, "completed command %d in %d ms\n", + ordinal, jiffies_to_msecs(jiffies - start)); goto out_recv; + } if (chip->ops->req_canceled(chip, status)) { dev_err(chip->pdev, "Operation Canceled\n"); + dev_dbg(chip->pdev, "canceled command %d after %d ms\n", + ordinal, jiffies_to_msecs(jiffies - start)); rc = -ECANCELED; goto out; } @@ -382,6 +389,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, chip->ops->cancel(chip); dev_err(chip->pdev, "Operation Timed out\n"); + dev_dbg(chip->pdev, "command %d timed out after %d ms\n", ordinal, + jiffies_to_msecs(jiffies - start)); rc = -ETIME; goto out;