From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753139AbdKWOss (ORCPT ); Thu, 23 Nov 2017 09:48:48 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33900 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753126AbdKWOsq (ORCPT ); Thu, 23 Nov 2017 09:48:46 -0500 Date: Thu, 23 Nov 2017 20:17:42 +0530 From: Nayna Jain To: Alexander.Steffen@infineon.com Cc: linux-integrity@vger.kernel.org, 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, patrickc@us.ibm.com Subject: Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance References: <20171017203232.2262-1-nayna@linux.vnet.ibm.com> <20171017203232.2262-3-nayna@linux.vnet.ibm.com> <5ef60315f2254b3b8bcc217a572280e5@infineon.com> <3ff12c6536de4379aa61cb09ebc9d105@infineon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3ff12c6536de4379aa61cb09ebc9d105@infineon.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-TM-AS-GCONF: 00 x-cbid: 17112314-0024-0000-0000-0000178B8CAC X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008107; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000241; SDB=6.00950065; UDB=6.00479789; IPR=6.00730175; BA=6.00005706; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018148; XFM=3.00000015; UTC=2017-11-23 14:48:43 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112314-0025-0000-0000-00004DA0E445 Message-Id: <20171123144742.GC8862@swastik> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-23_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711230201 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 22, 2017 at 06:52:03AM +0000, Alexander.Steffen@infineon.com wrote: > > > > > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to > > > > send large amounts of data, e.g. with TPM2_Hash, and subsequent tests > > > > seem to take an unusual amount of time. More analysis probably has to > > > wait > > > > until November, since I am going to be in Prague next week. > > > > > > > > Thanks Alex for testing these.. Did you get the chance to do any further > > > > analysis ? > > > > > > I am working on that now. Ken's suggestion seems reasonable, so I am > > going > > > to test whether correctly waiting for the flags to change fixes the problem. > > If > > > it does, I'll send the patches. > > > > Sorry for the delay, I had to take care of some device tree changes in v4.14 > > that broke my ARM test machines. > > > > I've implemented some patches that fix the issue that Ken pointed out and > > rebased your patch 2/4 ("ignore burstcount") on top. While doing this I > > noticed that your original patch does not, as the commit message says, write > > all the bytes at once, but still unnecessarily splits all commands into at least > > two transfers (as did the original code). I've fixed this as well in my patches, > > so that all bytes are indeed sent in a single call, without special handling for > > the last byte. This should speed up things further, especially for small > > commands and drivers like tpm_tis_spi, where writing a single byte > > translates into additional SPI transfers. Thanks Alex, for digging into. Yeah, you are right, the first version of this patch sent all the bytes together, but after hearing ddwg inputs, i.e. "The last byte was introduced for error checking purposes (history).", I reverted back to original to be safe. It seems that the last byte was sent from the beginning (27084ef [PATCH] tpm: driver for next generation TPM chips,), does anyone remember the reason ? > > > > Unfortunately, even with those changes the problem persists. But I've got > > more detailed logs now and will try to understand and hopefully fix the issue. > > I'll follow up with more details and/or patches once I know more. > > Okay, so the problem seems to be that at some point the TPM starts inserting wait states for the FIFO access. The driver tries to handle this, but fails since even the 50 retries that are currently used do not seem to be enough. Adding small (millisecond) delays between the attempts did not help so far. > > Is there any limit in the specification for how many wait states the TPM may generate or for how long it may do so? I could not find anything, but we need to use something there to prevent a faulty TPM from blocking the kernel forever. > I have been thinking on this, so was wondering: 1. As you said the problem started while sending large amounts of data for TPM2_Hash, how large is "large" ? I mean did it work for some specific large values before failing. 2. Are these wait states limited to SPI, or does it happen on LPC as well? Thanks & Regards, - Nayna > Alexander >