Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751948AbdHGO0B (ORCPT ); Mon, 7 Aug 2017 10:26:01 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51727 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751408AbdHGOZ7 (ORCPT ); Mon, 7 Aug 2017 10:25:59 -0400 Subject: Re: [PATCH] tpm: improve tpm_tis send() performance by ignoring burstcount To: Peter Huewe , tpmdd-devel@lists.sourceforge.net References: <20170807114632.1339-1-nayna@linux.vnet.ibm.com> Cc: tpmdd@selhorst.net, jarkko.sakkinen@linux.intel.com, jgunthorpe@obsidianresearch.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, patrickc@us.ibm.com From: Nayna Date: Mon, 7 Aug 2017 19:55:49 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17080714-0016-0000-0000-0000074E38A7 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007501; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000217; SDB=6.00898882; UDB=6.00449865; IPR=6.00679087; BA=6.00005515; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016574; XFM=3.00000015; UTC=2017-08-07 14:25:56 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17080714-0017-0000-0000-00003AEE9661 Message-Id: <5988786D.3080301@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-08-07_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1708070241 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4167 Lines: 140 On 08/07/2017 05:22 PM, Peter Huewe wrote: > > > Am 7. August 2017 13:46:32 MESZ schrieb Nayna Jain : >> 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 ignores burstcount, permitting wait states, and thus >> writes the command as fast as the TPM can accept the bytes. >> The performance of a 34 byte extend on a TPM 1.2 improved from >> 52 msec to 11 msec. >> >> Suggested-by: Ken Goldman in >> conjunction with the TPM Device Driver work group. >> Signed-off-by: Nayna Jain >> Acked-by: Mimi Zohar > > Are you sure this is a good idea? > On lpc systems this more or less stalls the bus, including keyboard/mouse (if connected via superio lpc). Thanks Peter for quick response. I actually meant to post this patch as RFC. Sorry, missed that. It was meant to be a starting place for the discussion related to burst_count. > > On which systems have you tested this? > Spi/Lpc? Architecture? Tested it with LPC on x86. > > This might not be noticable for small transfers, but think about much larger transfers.... I did the following testing: * Ran a script with 1000 extends. This was to test continuous extends which are generally in large numbers when IMA is enabled. * Ran a command to ask TPM to hash big size file like 1MB. This was to test the long command. In both of the above cases, I didn't face any tpm specific errors. Is there any test-script or test-cases which I can try to test the scenario(stalling the bus, including keyboard/mouse) with the patch ? Thanks & Regards, - Nayna > > Imho: NACK from my side. > > Thanks, > Peter > >> --- >> drivers/char/tpm/tpm_tis_core.c | 45 >> ++--------------------------------------- >> 1 file changed, 2 insertions(+), 43 deletions(-) >> >> diff --git a/drivers/char/tpm/tpm_tis_core.c >> b/drivers/char/tpm/tpm_tis_core.c >> index b617b2eeb080..478cbc0f61c3 100644 >> --- a/drivers/char/tpm/tpm_tis_core.c >> +++ b/drivers/char/tpm/tpm_tis_core.c >> @@ -255,9 +255,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 >> *buf, size_t count) >> 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; >> + int rc, status; >> >> status = tpm_tis_status(chip); >> if ((status & TPM_STS_COMMAND_READY) == 0) { >> @@ -270,49 +268,10 @@ 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; >> - >> - count += burstcnt; >> - >> - 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; >> - } >> - } >> - >> - /* write last byte */ >> - rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]); >> + rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality), len, >> buf); >> if (rc < 0) >> goto out_err; >> >> - 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; >> - } >> - >> return 0; >> >> out_err: >