From patchwork Wed Jul 12 12:34:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Attak, Hamza" X-Patchwork-Id: 9836575 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 73D4660363 for ; Wed, 12 Jul 2017 12:34:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62B61269DA for ; Wed, 12 Jul 2017 12:34:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55FBE27FA6; Wed, 12 Jul 2017 12:34:44 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 83CDE269DA for ; Wed, 12 Jul 2017 12:34:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dVGqo-00045a-Ig; Wed, 12 Jul 2017 12:34:42 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dVGqn-00045V-C8 for tpmdd-devel@lists.sourceforge.net; Wed, 12 Jul 2017 12:34:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Message-ID:Date:Subject:CC:To:From; bh=EdjhVhgnUJxMpJTmAgsx1k0OmFGUmBnNjCCsRHr8wxI=; b=W648c19eoO3ICDrHc6aVd+PBcQ8AR9tH25fVVM6ltOVDkCeEXGAJz5AaQHUan0iHVNw0VtjcU/Du8C2G2/U5DSmdTIM84FievgS7IMRxsp3qOlO/y4j2+eeHR/a8mlRXL1rxoydeWHbm+e1GSuinuj4Oo9BUGwK2SAp4/0kd4Nk=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=MIME-Version:Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Message-ID:Date:Subject:CC:To:From; bh=EdjhVhgnUJxMpJTmAgsx1k0OmFGUmBnNjCCsRHr8wxI=; b=UaQmCjZ1MjFlBmZXqelnXdDbZFJreOZH2bKMKs+j8qMq8XZ5uDyy+DUPG+Zo0jBqXFNZPWQXCT00rHXuARyapBPZAk9UkzhoYNKSEMOAw0wD+95o7S/IMb3pKMZxFX1ZT0QR/YvOAopvWciAMSAsoOW9gzRS9ZGFOgc8eFuKoi8=; Received: from g2t2352.austin.hpe.com ([15.233.44.25]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1dVGqm-0005dS-2k for tpmdd-devel@lists.sourceforge.net; Wed, 12 Jul 2017 12:34:41 +0000 Received: from G4W9120.americas.hpqcorp.net (g4w9120.houston.hp.com [16.210.21.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g2t2352.austin.hpe.com (Postfix) with ESMTPS id 7ED6941; Wed, 12 Jul 2017 12:34:34 +0000 (UTC) Received: from G2W6310.americas.hpqcorp.net (2002:10c5:4034::10c5:4034) by G4W9120.americas.hpqcorp.net (2002:10d2:150f::10d2:150f) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Wed, 12 Jul 2017 12:34:22 +0000 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (15.241.52.11) by G2W6310.americas.hpqcorp.net (16.197.64.52) with Microsoft SMTP Server (TLS) id 15.0.1178.4 via Frontend Transport; Wed, 12 Jul 2017 12:34:22 +0000 Received: from DF4PR84MB0028.NAMPRD84.PROD.OUTLOOK.COM (10.162.192.142) by DF4PR84MB0059.NAMPRD84.PROD.OUTLOOK.COM (10.162.192.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1240.13; Wed, 12 Jul 2017 12:34:20 +0000 Received: from DF4PR84MB0028.NAMPRD84.PROD.OUTLOOK.COM ([10.162.192.142]) by DF4PR84MB0028.NAMPRD84.PROD.OUTLOOK.COM ([10.162.192.142]) with mapi id 15.01.1240.020; Wed, 12 Jul 2017 12:34:19 +0000 From: "Attak, Hamza" To: Jarkko Sakkinen Thread-Topic: [tpmdd-devel] [PATCH] msleep() delays - replace with usleep_range() in TPM 1.2/2.0 generic drivers Thread-Index: AdL5fazy8FxIFcKGTLWBBLXsMiOnuAAMzZWAAFaJ0dA= Date: Wed, 12 Jul 2017 12:34:19 +0000 Message-ID: References: <20170710191527.qlurrqit6naoaotp@linux.intel.com> In-Reply-To: <20170710191527.qlurrqit6naoaotp@linux.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: linux.intel.com; dkim=none (message not signed) header.d=none; linux.intel.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [15.195.179.254] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DF4PR84MB0059; 7:QpydDIVhxp0460j6VpblxMgCw3rGtUHFN8nuTPiu7PKIBZjyZ21PFylUeZEtiOlke/6NUMdi9dK6MZ9YyJAPnK9yx/P2GjdiYCrEhTR4ZX0nmuzbmM9fkTPZ7ATgiRaNzkhxwXjrWYLxfveZGiE9lDSMX4XhjXtymXbj4TyNi5QlsEN5inZiJCOiB/nqsbAVoxkaQtN0ccWNlO3W9l4xKjixYusp6eTxN4ii3eRi3AwlE0eAz+7zX+Is5jNLB363L4fSgLIC+Brdwx3djOAaI9oSGOMhkUUIwRLzFu8oyBGYUXIgOjdbiGx1QmVgWJ/6CT6KTG3ChM3Y3R9Ukb6tmFWtQ++oLDEsdI1ZkywOAOByYcH6bZme7v7RxjmlqZ5XmjeKpPVp7088J/gPwY6xtSB5DBv01kAjroX2jpuIOAAG1Lo2yroJedyTnyVtOitQgHrzlIHA23j10+GphiN4j2G/UbuzdpI/duVKBXSVBOwlCFzNYt3wOUtTuwtgMYbCFko3+q4vrvy6JYWdrNySQLJz9+3HasHVFJRpmBQXn6nUQRaHjO01pThB16arlXYwm/oRv6xa77sByYzpQIw7llkZA6yaSC6cqBHLxEVw9EgEQhO5H+eZsmy3U/P6Cg0gkHt5+k05qE8P9vHdITIlap8G07KXsi2szqDRA0rse15A+/Ujuoug9SBcD7HdY/kKrzRsPVgW7AqaJQgAN8VEkpjsJYHr8zC4Wbi2/oR2uZfrtoYPv6B7PpBQ95KELhsnb+ruBFXWXBoya8tHE1uEJS61L++6UwmVTKsUKSnzny8= x-forefront-antispam-report: SFV:SKI; SCL:-1SFV:NSPM; SFS:(10019020)(6009001)(39410400002)(39840400002)(39860400002)(39400400002)(39850400002)(39450400003)(50986999)(6246003)(6116002)(6506006)(575784001)(76176999)(3846002)(102836003)(4326008)(229853002)(8676002)(81166006)(86362001)(305945005)(7696004)(189998001)(5660300001)(8936002)(54356999)(25786009)(77096006)(7736002)(2950100002)(55016002)(2906002)(38730400002)(14454004)(2900100001)(3660700001)(53936002)(74316002)(110136004)(478600001)(54906002)(66066001)(9686003)(6436002)(33656002)(3280700002)(6916009)(41533002); DIR:OUT; SFP:1102; SCL:1; SRVR:DF4PR84MB0059; H:DF4PR84MB0028.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; MLV:sfv; LANG:en; x-ms-office365-filtering-correlation-id: 932b5156-bbf2-4c66-8d2e-08d4c9225161 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(48565401081)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DF4PR84MB0059; x-ms-traffictypediagnostic: DF4PR84MB0059: x-exchange-antispam-report-test: UriScan:(227479698468861)(236129657087228)(788757137089)(148574349560750); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(2017060910075)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DF4PR84MB0059; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DF4PR84MB0059; x-forefront-prvs: 036614DD9C spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Jul 2017 12:34:19.6600 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0059 X-OriginatorOrg: hpe.com X-Headers-End: 1dVGqm-0005dS-2k Subject: Re: [tpmdd-devel] [PATCH] msleep() delays - replace with usleep_range() in TPM 1.2/2.0 generic drivers X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jacquin, Ludovic" , "tpmdd-devel@lists.sourceforge.net" , "Edwards, Nigel" Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP msleep() delays - replace with usleep_range() in TPM 1.2/2.0 generic drivers The patch simply replaces all msleep function calls with usleep_range calls in the generic drivers. Tested with an Infineon TPM 1.2, using the generic tpm-tis module, for a thousand PCR extends, we see results going from 1m57s unpatched to 40s with the new patch. We obtain similar results when using the original and patched tpm_infineon driver, which is also part of the patch. Similarly with a STM TPM 2.0, using the CRB driver, it takes about 20ms per extend unpatched and around 7ms with the new patch. Note that the PCR consistency is untouched with this patch, each TPM has been tested with 10 million extends and the aggregated PCR value is continuously verified to be correct. As an extension of this work, this could potentially and easily be applied to other vendor's drivers. Still, these changes are not included in the proposed patch as they are untested. Signed-off-by: Hamza Attak --- drivers/char/tpm/tpm-interface.c | 13 ++++++++----- drivers/char/tpm/tpm2-cmd.c | 2 +- drivers/char/tpm/tpm_infineon.c | 9 ++++++--- drivers/char/tpm/tpm_tis_core.c | 9 +++++---- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index bd2128e..513b801 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -395,7 +395,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz, goto out; } - msleep(TPM_TIMEOUT); /* CHECK */ + usleep_range(TPM_TIMEOUT * 1000, (TPM_TIMEOUT * 1000) + 300); rmb(); } while (time_before(jiffies, stop)); @@ -862,7 +862,8 @@ int tpm_do_selftest(struct tpm_chip *chip) dev_info( &chip->dev, HW_ERR "TPM command timed out during continue self test"); - msleep(delay_msec); + usleep_range(delay_msec * 1000, + (delay_msec * 1000) + 300); continue; } @@ -877,7 +878,7 @@ int tpm_do_selftest(struct tpm_chip *chip) } if (rc != TPM_WARN_DOING_SELFTEST) return rc; - msleep(delay_msec); + usleep_range(delay_msec * 1000, (delay_msec * 1000) + 300); } while (--loops > 0); return rc; @@ -977,7 +978,8 @@ again: } } else { do { - msleep(TPM_TIMEOUT); + usleep_range(TPM_TIMEOUT * 1000, + (TPM_TIMEOUT * 1000) + 300); status = chip->ops->status(chip); if ((status & mask) == mask) return 0; @@ -1045,7 +1047,8 @@ int tpm_pm_suspend(struct device *dev) */ if (rc != TPM_WARN_RETRY) break; - msleep(TPM_TIMEOUT_RETRY); + usleep_range(TPM_TIMEOUT_RETRY * 1000, + (TPM_TIMEOUT_RETRY * 1000) + 300); } if (rc) diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index 881aea9..bdae205 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -961,7 +961,7 @@ static int tpm2_do_selftest(struct tpm_chip *chip) if (rc != TPM2_RC_TESTING) break; - msleep(delay_msec); + usleep_range(delay_msec * 1000, (delay_msec * 1000) + 300); } return rc; diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c index e3cf9f3..1846151 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c @@ -191,7 +191,8 @@ static int wait(struct tpm_chip *chip, int wait_for_bit) /* check the status-register if wait_for_bit is set */ if (status & 1 << wait_for_bit) break; - msleep(TPM_MSLEEP_TIME); + usleep_range(TPM_MSLEEP_TIME * 1000, + (TPM_MSLEEP_TIME * 1000) + 300); } if (i == TPM_MAX_TRIES) { /* timeout occurs */ if (wait_for_bit == STAT_XFE) @@ -226,7 +227,8 @@ static void tpm_wtx(struct tpm_chip *chip) wait_and_send(chip, TPM_CTRL_WTX); wait_and_send(chip, 0x00); wait_and_send(chip, 0x00); - msleep(TPM_WTX_MSLEEP_TIME); + usleep_range(TPM_WTX_MSLEEP_TIME * 1000, + (TPM_WTX_MSLEEP_TIME * 1000) + 300); } static void tpm_wtx_abort(struct tpm_chip *chip) @@ -237,7 +239,8 @@ static void tpm_wtx_abort(struct tpm_chip *chip) wait_and_send(chip, 0x00); wait_and_send(chip, 0x00); number_of_wtx = 0; - msleep(TPM_WTX_MSLEEP_TIME); + usleep_range(TPM_WTX_MSLEEP_TIME * 1000, + (TPM_WTX_MSLEEP_TIME * 1000) + 300); } static int tpm_inf_recv(struct tpm_chip *chip, u8 * buf, size_t count) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index c0f296b..62c0915 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -51,7 +51,7 @@ static int wait_startup(struct tpm_chip *chip, int l) if (access & TPM_ACCESS_VALID) return 0; - msleep(TPM_TIMEOUT); + usleep_range(TPM_TIMEOUT * 1000, (TPM_TIMEOUT * 1000) + 300); } while (time_before(jiffies, stop)); return -1; } @@ -125,7 +125,8 @@ again: do { if (check_locality(chip, l) >= 0) return l; - msleep(TPM_TIMEOUT); + usleep_range(TPM_TIMEOUT * 1000, + (TPM_TIMEOUT * 1000) + 300); } while (time_before(jiffies, stop)); } return -1; @@ -170,7 +171,7 @@ static int get_burstcount(struct tpm_chip *chip) burstcnt = (value >> 8) & 0xFFFF; if (burstcnt) return burstcnt; - msleep(TPM_TIMEOUT); + usleep_range(TPM_TIMEOUT * 1000, (TPM_TIMEOUT * 1000) + 300); } while (time_before(jiffies, stop)); return -EBUSY; } @@ -408,7 +409,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) priv->irq = irq; chip->flags |= TPM_CHIP_FLAG_IRQ; if (!priv->irq_tested) - msleep(1); + usleep_range(1000, 1300); if (!priv->irq_tested) disable_interrupts(chip); priv->irq_tested = true;