From patchwork Mon Dec 11 16:05:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 10105483 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 70F4660360 for ; Mon, 11 Dec 2017 16:05:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7311A29771 for ; Mon, 11 Dec 2017 16:05:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6692729776; Mon, 11 Dec 2017 16:05:32 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD12A29771 for ; Mon, 11 Dec 2017 16:05:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752405AbdLKQFb (ORCPT ); Mon, 11 Dec 2017 11:05:31 -0500 Received: from smtp2.infineon.com ([217.10.52.18]:12789 "EHLO smtp2.infineon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584AbdLKQFa (ORCPT ); Mon, 11 Dec 2017 11:05:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1513008330; x=1544544330; h=from:to:cc:subject:date:message-id:mime-version; bh=Eujz9lYGnOWTxt+YulLlecdrG5amnrSZo2Vhy/nSoJE=; b=O7f0wsG8gloxj0DM1YT7stobzSWH0XaZRx3i1zNrNr9A9CJk9xba2d3G Nj1p/5E1EsBcGUzh7Oj85TKWhXVNCUMNod8HOWVJ3ud/1TDAz+BHLLeDS YkVEn5GYsDcaDoIo/TYAsl/XPZ0mjd67C4EYeDBlD3kdtxQy6oFscljp+ k=; X-SBRS: None Received: from unknown (HELO mucxv003.muc.infineon.com) ([172.23.11.20]) by smtp2.infineon.com with ESMTP/TLS/AES256-GCM-SHA384; 11 Dec 2017 17:05:29 +0100 Received: from MUCSE708.infineon.com (mucse708.infineon.com [172.23.7.82]) by mucxv003.muc.infineon.com (Postfix) with ESMTPS; Mon, 11 Dec 2017 17:05:29 +0100 (CET) Received: from ABGN5CG4522MQD.eu.infineon.com (172.23.8.247) by MUCSE708.infineon.com (172.23.7.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.669.32; Mon, 11 Dec 2017 17:05:28 +0100 From: Alexander Steffen To: , , , CC: Alexander Steffen Subject: [PATCH] tpm2-cmd: allow more attempts for selftest execution Date: Mon, 11 Dec 2017 17:05:25 +0100 Message-ID: <20171211160525.10576-1-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.11.1.windows.1 MIME-Version: 1.0 X-Originating-IP: [172.23.8.247] X-ClientProxiedBy: MUCSE706.infineon.com (172.23.7.80) To MUCSE708.infineon.com (172.23.7.82) Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Previously, if the last attempt to execute the selftest command failed with RC_TESTING, there was still a call to tpm_msleep, even though no further attempt would be made. This causes an unnecessary delay, therefore ensure that if the last attempt fails the function is left immediately. Also, instead of ensuring that the cumulated runtime of all attempts is larger than the command duration for TPM2_SelfTest, ensure that there is at least one attempt for which the delay is larger than the expected command duration. This allows slow TPMs to execute all their tests in the background, without slowing down faster TPMs that have finished their tests earlier. If tests are still not finished even with this long delay, then something is broken and the TPM is not used. Fixes: 125a22105410 ("tpm: React correctly to RC_TESTING from TPM 2.0 self tests") Signed-off-by: Alexander Steffen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm2-cmd.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index f40d206..c17e753 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -849,28 +849,26 @@ static const struct tpm_input_header tpm2_selftest_header = { static int tpm2_do_selftest(struct tpm_chip *chip) { int rc; - unsigned int delay_msec = 20; + unsigned int delay_msec = 10; long duration; struct tpm2_cmd cmd; duration = jiffies_to_msecs( tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST)); - while (duration > 0) { + while (1) { cmd.header.in = tpm2_selftest_header; cmd.params.selftest_in.full_test = 0; rc = tpm_transmit_cmd(chip, NULL, &cmd, TPM2_SELF_TEST_IN_SIZE, 0, 0, "continue selftest"); - if (rc != TPM2_RC_TESTING) + if (rc != TPM2_RC_TESTING || delay_msec >= duration) break; - tpm_msleep(delay_msec); - duration -= delay_msec; - - /* wait longer the next round */ + /* wait longer than before */ delay_msec *= 2; + tpm_msleep(delay_msec); } return rc;