Received: by 10.192.165.156 with SMTP id m28csp1335627imm; Wed, 18 Apr 2018 08:06:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx49b8iT11lZC6TZd1ZCF5naYjPxqVK/aWTKFBTbKNtNr2Ywe7CDT/57ZmtP4Z2Nf2kPiyBzb X-Received: by 10.98.253.9 with SMTP id p9mr2314855pfh.152.1524064000815; Wed, 18 Apr 2018 08:06:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524064000; cv=none; d=google.com; s=arc-20160816; b=zxCZqvh2oAXUTvcxxebPjphmqbRL5zNvpbhpCjtRSdoDqlvNrrrq9roWQuHLzl55DK IyYJaCn9T7MKJgHLp5WvFJcQ+D84qRsFT+fMycTf85vexdN2NtkrwTZ6+OOuA7ybl/IK VKBtztMUEuYPdq9mL2TRBYILP/N4eUQpptQAT5MO/xd1OTTQ9yv29A5A5fkL4dWkoKyu iSVN4ykLKBssJ6PBqH7At0YrlSRrWe/oED+f7nfmsZmWMufMVuNmuN/lR+NqRzXBpgRx 4DLIsCI5f02rkBylPJH+dcjxxCn5Gpn8nnQOody89npjMz3aFzs8nsP80Qr1bHwTervS 4IFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject :arc-authentication-results; bh=zh3cPcQj2Waos72oa3fr1mkxnxeqDfmbHFC7wl4hmMo=; b=dta3sCkU2EZz1swUYFw9bz2LdFgDDzflyKa8QizkO770RW3MVUcdWZXSl8FotPS7SG ckDh9IGhQQXvfiFdMDBbjVZ61ORbaOFKL84sxqy+eObFUIcumhQpwp6jnxaSlwmD67Us udZY5KQ3/xe3YL841IxSqPaDHxfpaa88tJkXj1/FW2kOqtNs/nkAuK0Gggx9Qx93pZBU OhUNaaJD4WedqHBaeJFMHP9qalmf37F/W84kerO6ksWl9+qlUitpzf6Mbw4FyLYFHZ2U +J/a0vyRLbxDTytXzmUlS4PJmQagNpBaQQKaeM96mf4BPEYcfZuafDwJWCBDJ8yi9YCX pOaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12si1246909pgc.381.2018.04.18.08.06.26; Wed, 18 Apr 2018 08:06:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753065AbeDRPCZ (ORCPT + 99 others); Wed, 18 Apr 2018 11:02:25 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56168 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752948AbeDRPCW (ORCPT ); Wed, 18 Apr 2018 11:02:22 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3IF24cK011603 for ; Wed, 18 Apr 2018 11:02:21 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2he6m1wuvt-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 18 Apr 2018 11:02:21 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Apr 2018 16:02:18 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 18 Apr 2018 16:02:15 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3IF2Flk46465220; Wed, 18 Apr 2018 15:02:15 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0511BAE055; Wed, 18 Apr 2018 15:52:04 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D147AAE05A; Wed, 18 Apr 2018 15:52:02 +0100 (BST) Received: from localhost.localdomain (unknown [9.80.106.43]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 18 Apr 2018 15:52:02 +0100 (BST) Subject: Re: [PATCH v2 2/2] tpm: reduce polling time to usecs for even finer granularity From: Mimi Zohar To: Nayna Jain , linux-integrity@vger.kernel.org Cc: 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 Date: Wed, 18 Apr 2018 11:02:12 -0400 In-Reply-To: <20180417131246.434-3-nayna@linux.vnet.ibm.com> References: <20180417131246.434-1-nayna@linux.vnet.ibm.com> <20180417131246.434-3-nayna@linux.vnet.ibm.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 (3.20.5-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 18041815-0008-0000-0000-000004ECBAA2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041815-0009-0000-0000-00001E80C637 Message-Id: <1524063732.3272.302.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804180135 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-04-17 at 09:12 -0400, Nayna Jain wrote: > The TPM burstcount and status commands are supposed to return very > quickly [1][2]. This patch further reduces the TPM poll sleep time to usecs > in get_burstcount() and wait_for_tpm_stat() by calling usleep_range() > directly. > > After this change, performance on a TPM 1.2 with an 8 byte burstcount for > 1000 extends improved from ~10.7 sec to ~7 sec. > > [1] From TCG Specification "TCG PC Client Specific TPM Interface > Specification (TIS), Family 1.2": > > "NOTE : It takes roughly 330 ns per byte transfer on LPC. 256 bytes would > take 84 us, which is a long time to stall the CPU. Chipsets may not be > designed to post this much data to LPC; therefore, the CPU itself is > stalled for much of this time. Sending 1 kB would take 350 μs. Therefore, > even if the TPM_STS_x.burstCount field is a high value, software SHOULD > be interruptible during this period." > > [2] From TCG Specification 2.0, "TCG PC Client Platform TPM Profile > (PTP) Specification": > > "It takes roughly 330 ns per byte transfer on LPC. 256 bytes would take > 84 us. Chipsets may not be designed to post this much data to LPC; > therefore, the CPU itself is stalled for much of this time. Sending 1 kB > would take 350 us. Therefore, even if the TPM_STS_x.burstCount field is a > high value, software should be interruptible during this period. For SPI, > assuming 20MHz clock and 64-byte transfers, it would take about 120 usec > to move 256B of data. Sending 1kB would take about 500 usec. If the > transactions are done using 4 bytes at a time, then it would take about > 1 msec. to transfer 1kB of data." > > Signed-off-by: Nayna Jain Reviewed-by: Mimi Zohar > --- > drivers/char/tpm/tpm.h | 4 +++- > drivers/char/tpm/tpm_tis_core.c | 5 +++-- > 2 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h > index 7e797377e1eb..f0e4d290c347 100644 > --- a/drivers/char/tpm/tpm.h > +++ b/drivers/char/tpm/tpm.h > @@ -54,7 +54,9 @@ enum tpm_timeout { > TPM_TIMEOUT = 5, /* msecs */ > TPM_TIMEOUT_RETRY = 100, /* msecs */ > TPM_TIMEOUT_RANGE_US = 300, /* usecs */ > - TPM_TIMEOUT_POLL = 1 /* msecs */ > + TPM_TIMEOUT_POLL = 1, /* msecs */ > + TPM_TIMEOUT_USECS_MIN = 100, /* usecs */ > + TPM_TIMEOUT_USECS_MAX = 500 /* usecs */ > }; > > /* TPM addresses */ > diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c > index 021e6b68f2db..5bba5c662423 100644 > --- a/drivers/char/tpm/tpm_tis_core.c > +++ b/drivers/char/tpm/tpm_tis_core.c > @@ -84,7 +84,8 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, > } > } else { > do { > - tpm_msleep(TPM_TIMEOUT_POLL); > + usleep_range(TPM_TIMEOUT_USECS_MIN, > + TPM_TIMEOUT_USECS_MAX); > status = chip->ops->status(chip); > if ((status & mask) == mask) > return 0; > @@ -226,7 +227,7 @@ static int get_burstcount(struct tpm_chip *chip) > burstcnt = (value >> 8) & 0xFFFF; > if (burstcnt) > return burstcnt; > - tpm_msleep(TPM_TIMEOUT_POLL); > + usleep_range(TPM_TIMEOUT_USECS_MIN, TPM_TIMEOUT_USECS_MAX); > } while (time_before(jiffies, stop)); > return -EBUSY; > }