From patchwork Wed Oct 4 10:29:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nayna X-Patchwork-Id: 9984163 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 A731960237 for ; Wed, 4 Oct 2017 10:29:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95C4A28834 for ; Wed, 4 Oct 2017 10:29:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87C0528842; Wed, 4 Oct 2017 10:29:58 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 012F328834 for ; Wed, 4 Oct 2017 10:29:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751511AbdJDK34 (ORCPT ); Wed, 4 Oct 2017 06:29:56 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:59340 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751385AbdJDK3x (ORCPT ); Wed, 4 Oct 2017 06:29:53 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v94ATALB140527 for ; Wed, 4 Oct 2017 06:29:53 -0400 Received: from e23smtp04.au.ibm.com (e23smtp04.au.ibm.com [202.81.31.146]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dcvyxucfe-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 04 Oct 2017 06:29:52 -0400 Received: from localhost by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Oct 2017 20:29:50 +1000 Received: from d23relay06.au.ibm.com (202.81.31.225) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Oct 2017 20:29:48 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v94ATlRU42991780; Wed, 4 Oct 2017 21:29:47 +1100 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v94ATkfv009745; Wed, 4 Oct 2017 21:29:47 +1100 Received: from dhcp-9-60-73-202.endicott.ibm.com (dhcp-9-60-73-202.endicott.ibm.com [9.60.73.202]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v94ATZs0009465; Wed, 4 Oct 2017 21:29:43 +1100 From: Nayna Jain To: linux-integrity@vger.kernel.org Cc: zohar@linux.vnet.ibm.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, peterhuewe@gmx.de, jarkko.sakkinen@linux.intel.com, tpmdd@selhorst.net, jgunthorpe@obsidianresearch.com, patrickc@us.ibm.com, Nayna Jain Subject: [PATCH v3 2/5] tpm: ignore burstcount to improve tpm_tis send() performance Date: Wed, 4 Oct 2017 06:29:21 -0400 X-Mailer: git-send-email 2.13.3 In-Reply-To: <20171004102924.12355-1-nayna@linux.vnet.ibm.com> References: <20171004102924.12355-1-nayna@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17100410-0012-0000-0000-0000025F446B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17100410-0013-0000-0000-0000077DF96B Message-Id: <20171004102924.12355-3-nayna@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-04_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=5 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710040153 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The TPM burstcount status indicates the number of bytes that can be sent to the TPM without causing bus wait states. Effectively, it is the number of empty bytes in the command FIFO. Further, some TPMs have a static burstcount, when the value remains zero until the entire FIFO is empty. This patch optimizes the tpm_tis_send_data() function by checking the burstcount only once. And if the burstcount is valid, it writes all the bytes at once, permitting wait states. The performance of a 34 byte extend on a TPM 1.2 with an 8 byte burstcount improved from 41msec to 14msec. After this change, performance on a TPM 1.2 with an 8 byte burstcount for 1000 extends improved from ~41sec to ~14sec. Suggested-by: Ken Goldman in conjunction with the TPM Device Driver work group. Signed-off-by: Nayna Jain Acked-by: Mimi Zohar --- drivers/char/tpm/tpm_tis_core.c | 42 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index b33126a35694..8da425e1783f 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc, status, burstcnt; - size_t count = 0; bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND; status = tpm_tis_status(chip); @@ -330,35 +329,26 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) } } - while (count < len - 1) { - burstcnt = get_burstcount(chip); - if (burstcnt < 0) { - dev_err(&chip->dev, "Unable to read burstcount\n"); - rc = burstcnt; - goto out_err; - } - burstcnt = min_t(int, burstcnt, len - count - 1); - rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), - burstcnt, buf + count); - if (rc < 0) - goto out_err; + /* + * Get the initial burstcount to ensure TPM is ready to + * accept data. + */ + burstcnt = get_burstcount(chip); + if (burstcnt < 0) { + dev_err(&chip->dev, "Unable to read burstcount\n"); + rc = burstcnt; + goto out_err; + } - count += burstcnt; + burstcnt = len - 1; - if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c, - &priv->int_queue, false) < 0) { - rc = -ETIME; - goto out_err; - } - status = tpm_tis_status(chip); - if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) { - rc = -EIO; - goto out_err; - } - } + rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), + burstcnt, buf); + if (rc < 0) + goto out_err; /* write last byte */ - rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]); + rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-1]); if (rc < 0) goto out_err;