From patchwork Mon Jul 10 13:26:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Attak, Hamza" X-Patchwork-Id: 786196 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3x5mGS669hz9s0Z for ; Mon, 10 Jul 2017 23:27:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sourceforge.net header.i=@sourceforge.net header.b="Ayy7p0Ey"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sf.net header.i=@sf.net header.b="Qki1t6nQ"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dUYiP-0002TW-F1; Mon, 10 Jul 2017 13:27:05 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dUYiO-0002TN-8J for tpmdd-devel@lists.sourceforge.net; Mon, 10 Jul 2017 13:27:04 +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:Message-ID:Date:Subject:CC:To:From; bh=fdLFHPz7jbAq2+eLAG7Kg3AsQpsHDLZkI7a1R1O7gy4=; b=Ayy7p0EyoozVtjnqEC9rzzYJLPeH2UDPdB6+EycKPpZZqBrFlKSKybHPE9ZyXSPi3vQ8adxpA7H9CHuDK2+kJIACLonIg/sNjLxKKMrz9Ht5G5kNhoESycbXPrIQC7txzn3HScpTM9HhuEfiKj05d0l4X6W2tzKDcRe8DLqo/BQ=; 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:Message-ID:Date:Subject:CC:To:From; bh=fdLFHPz7jbAq2+eLAG7Kg3AsQpsHDLZkI7a1R1O7gy4=; b=Qki1t6nQZ4pbQrZe/C0UWXIp1Jp72KYj49BH1SNDdFLepIYEGT4gL6j+9f4cyN3w2r0uGNpJlEa+7lgl4OPISLuFCOLeoS4PB7D1JVCJVuYPWqZy3H7xjw2ZbDkliWXUWHjAcHXVpGGv1A4afKivT17Svd2uNF5ShevZndh4euk=; Received: from g2t2353.austin.hpe.com ([15.233.44.26]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1dUYiK-0003v7-Ld for tpmdd-devel@lists.sourceforge.net; Mon, 10 Jul 2017 13:27:03 +0000 Received: from G2W6309.americas.hpqcorp.net (g2w6309.austin.hp.com [16.197.64.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g2t2353.austin.hpe.com (Postfix) with ESMTPS id 1BE9A83 for ; Mon, 10 Jul 2017 13:26:55 +0000 (UTC) Received: from G2W6309.americas.hpqcorp.net (2002:10c5:4033::10c5:4033) by G2W6309.americas.hpqcorp.net (2002:10c5:4033::10c5:4033) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Mon, 10 Jul 2017 13:26:54 +0000 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (15.241.52.13) by G2W6309.americas.hpqcorp.net (16.197.64.51) with Microsoft SMTP Server (TLS) id 15.0.1178.4 via Frontend Transport; Mon, 10 Jul 2017 13:26:54 +0000 Received: from DF4PR84MB0028.NAMPRD84.PROD.OUTLOOK.COM (10.162.192.142) by DF4PR84MB0060.NAMPRD84.PROD.OUTLOOK.COM (10.162.192.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1240.13; Mon, 10 Jul 2017 13:26:52 +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; Mon, 10 Jul 2017 13:26:51 +0000 From: "Attak, Hamza" To: "tpmdd-devel@lists.sourceforge.net" Thread-Topic: [PATCH] msleep() delays - replace with usleep_range() in TPM 1.2/2.0 generic drivers Thread-Index: AdL5fazy8FxIFcKGTLWBBLXsMiOnuA== Date: Mon, 10 Jul 2017 13:26:51 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: lists.sourceforge.net; dkim=none (message not signed) header.d=none; lists.sourceforge.net; dmarc=none action=none header.from=hpe.com; x-originating-ip: [15.195.179.254] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DF4PR84MB0060; 7:jejAxaGODTAVZGsQlKm/C5FAGVgxciTZeObshihYxwA609QWsSQ4IEMe27isLwGmFJxnjP/pdXnYGzoHo+NPVOaR65MKgwDHsCw0dK1sXOLK5ToG0APXj957r9hbMxsax1ovK6VK6tXj8OIpl9gMy+0r5/vN9NleP8sijxfCcCvwWnhfseYFfjnYQaUzmauL6CHzV8P7y/d9KFEH+4twqFClJHfYWAXNUV9lne2OtOib/sHquVktVOjG8YuUPvxz+I9vr+fdsfWSNoEtfEzGRO4pLIfmlEko8VzQBJppfCQkgqVfkpTsKS3Y1Wbw8oIBDAJkfyOmNbPmwp9oRembmL51rvbE21h1+wtpTsjrQNhxFMVFIixlqWj01uHUpudmZFZvot5p1weg4B0K5bB0JCYN1X7tXhfgz2efENhkX2dKau8nuS91PUJtQZL8jZ8f6EJqQ0tVEJkIy/Hy7WyakN4q2GXlxHttb2V2ZGBR+x+nwv8oAoMo5lNKVrtqcz3ik8gjVdcacED/xmdq586FxQHTBRHm4WvouwC++Co+phfZpgFvFfXG7wU6kPcZFGWu/GmlxfIv5jjx7bcvRTRB3U8qayqL5krcwbwlZhqJ+7YdKhi/g7ius1KwvqDUENR2Tv5EFX56Oz1p7RwQWXnu4nJTWC3sz2tjQ3rB+DfdkMGNnHGSwyr43D+Zd52+3qQU5BdoIN4LrvBIWXQVQaHCiH2RiNfBNDNx1jsZBgYKfz5BTDPbrlAX9gFIA7lFtX1TfNMuhSZ0vNKlwXF5SRWuJuKgl76ZY5ZfSSCwOxLgitU= x-forefront-antispam-report: SFV:SKI; SCL:-1SFV:NSPM; SFS:(10019020)(6009001)(39450400003)(39840400002)(39850400002)(39860400002)(39400400002)(39410400002)(3280700002)(3660700001)(86362001)(66066001)(6916009)(2351001)(25786009)(2906002)(3846002)(6116002)(102836003)(575784001)(33656002)(189998001)(478600001)(50986999)(2900100001)(7696004)(5660300001)(74316002)(2501003)(8936002)(77096006)(54356999)(5640700003)(6436002)(6306002)(4326008)(14454004)(9686003)(54906002)(110136004)(38730400002)(8676002)(966005)(53936002)(55016002)(6506006)(81166006)(305945005); DIR:OUT; SFP:1102; SCL:1; SRVR:DF4PR84MB0060; H:DF4PR84MB0028.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; MLV:sfv; LANG:en; x-ms-office365-filtering-correlation-id: 08f5bb46-558c-421f-49f0-08d4c7975364 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)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DF4PR84MB0060; x-ms-traffictypediagnostic: DF4PR84MB0060: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(227479698468861)(236129657087228)(788757137089)(42262312472803)(148574349560750); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(2017060910075)(8121501046)(5005006)(10201501046)(3002001)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6041248)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123564025)(20161123558100)(20161123560025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DF4PR84MB0060; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DF4PR84MB0060; x-forefront-prvs: 03648EFF89 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Jul 2017 13:26:51.8371 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0060 X-OriginatorOrg: hpe.com X-Spam-Score: -0.0 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1dUYiK-0003v7-Ld Subject: [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" , "Edwards, Nigel" Errors-To: tpmdd-devel-bounces@lists.sourceforge.net msleep() delays - replace with usleep_range() in TPM 1.2/2.0 generic drivers Following the recent Nuvoton patch submitted by Mimi Zohar: https://sourceforge.net/p/tpmdd/mailman/message/35685260/ Based on this work, I decided to apply a similar modification to the generic TPM drivers in the kernel. The patch simply replaces all msleep function calls with usleep_range calls in the generic drivers. As a former patch already exists for the Nuvoton TPM, it is therefore not included in this new patch. 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 | 10 +++++----- drivers/char/tpm/tpm2-cmd.c | 2 +- drivers/char/tpm/tpm_infineon.c | 6 +++--- drivers/char/tpm/tpm_tis_core.c | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index bd2128e..f03daf5 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,7 @@ 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 +877,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 +977,7 @@ 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 +1045,7 @@ 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..86f0f3e 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c @@ -191,7 +191,7 @@ 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 +226,7 @@ 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 +237,7 @@ 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..e7d3046 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,7 @@ 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 +170,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 +408,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;