From patchwork Thu Nov 24 13:55:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27766C4321E for ; Thu, 24 Nov 2022 13:57:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230226AbiKXN5F (ORCPT ); Thu, 24 Nov 2022 08:57:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbiKXN44 (ORCPT ); Thu, 24 Nov 2022 08:56:56 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FCFFFFAA4; Thu, 24 Nov 2022 05:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298174; bh=SccepFkG1BaYDhxThv4kTIw73gWWQ8B34c8oBRXziP8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=N5oSIApeIyqhSeyC5gdSR0djmO35Q82/vTO7AnK+pUNovI047gP53VxHdyEh644Gs vDbkjFbFt4syPSalb34P3JmOTUqPiUORWZ3cu/CtvTl1I5MDTSI5LbrbRykKs3MPPB gDqmJMCbW/daQoZ5iTvHIoqr6zvwolRhD2aLsgkpb99iWmZybH3HfbmPqUJnkMNObK 4M2a2Ouq50SagnRldDSMKXrD4VUHBcq6CmZ+/BDhv32/We5dpWepTL9XotCwnkiFVu TYXuIvIFTdnNeOaR/smYBw2k8Rv1UALGd+DflsGFfHRtoG9vBH3jN5QSKi9OQr1Lm0 TWJ58lS+6OZLQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mg6e4-1pPH3Q1hnS-00hcyE; Thu, 24 Nov 2022 14:56:14 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 13/14] tpm, tpm_tis: startup chip before testing for interrupts Date: Thu, 24 Nov 2022 14:55:37 +0100 Message-Id: <20221124135538.31020-14-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:zL2CNXLyU474XTdrXuPgbob0QK0DB8meDAMR4XbMdR/tbE5lv3k k6dilEu5PY/7pIfCkYcsG9ONqgIh7Yw14eA/C71RO2XlIIRNDC/vszFhWB6E7PjthtspBOF bnGzBzzik2FbNsoASv1b3OfHAbGE6h6nhndFb/bw8w++/zya1A07LDjeoY7MMXfTDUMrYbf bxYBAriPFhSep3+hjLCSQ== UI-OutboundReport: notjunk:1;M01:P0:1LYpu2fBXps=;CrGmYwKDDI8dwJQBn3y2fmWp8Gs IA7PqgPDCI0YelnX1m174eoQ7ICsvUkRLf1qhlw0+1kEcAK/s11cWQO+JCsG2tBuUYf6t/N+s 4dXVf06KzusaVhyfHT9ULvmQtbNi53Bex54+G9IBwrvtHJzY3SDYxpA9KfYYrOATllrP9XKGe ytOWAHB6oOlnLA1OPJd70P9KkALdtKQq187b2MY6T7GN7NCcsoz3AVromPiCdF1PLIfZdWdsH CSwfcRCgOlL6tzkTLO5HdsRlGBQDto3v9YpHtHqKwPtSqgL529thm0QvOy7DpAcYfG0UacLCk l/RrWNlHMjSzjYLDqmjDU6hrMG+wJ1qGq9SP8Ag5RhPIzJkvXFVWpLX2UzNF0w54Oly8nYZkh 6JLFhVMRhZJyqxlKIc09Rn8JSf6jaEwHsOlGs8wk9Q35d4H2LWF9CatxP3A6q02Ebg/pnFx41 mj7jZk4qEGpvEqEqSUd7lTtEMRIbJr8T5J4oRMasG2bXXTok66l+ecll1GWZzvZqnrBo8+sqf 2vENlVO5QQiHp+7CYFzhVyaL2kfGIBHJ90QCKc2FRI81DYEz+Sudd000dC/TMmjA+gOAxwrqE 4dZM/+C223BAwUhs6oJRZieLki5Gm+BXafGFJWENkDez2vfSTqaObWy1O0+3Fsg5K67R2Be5n PSQKkM6gUaWh7oI9xMVfrzOq2NYGjQDmhS/dtqOFM2p/w2xAZOF52M3EhYEhIEh9JmtmDJfhy CdMQCRHDF5Cm9pIRuLdV1IDx/MmcxYg2MhwON1ghtxxte5TYdXZ+QIpebHcJdIFDnfGKJs4XO 4GOu4AKLF9SNddSHjn1qu/b67IKA4NLdlFiEB4QYUQhpL0nsFgH9aBIqZebPWX9tG84Tz6cgR 5PXiwM0vVzJRDLlq5Jj3PJc29ZfEBRVsIlCC7fTsVyDIDlSR3vya9bCIdI6r7b1Qd5yws60o0 be2bAg== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo In tpm_tis_gen_interrupt() a request for a property value is sent to the TPM to test if interrupts are generated. However after a power cycle the TPM responds with TPM_RC_INITIALIZE which indicates that the TPM is not yet properly initialized. Fix this by first starting the TPM up before the request is sent. For this the startup implementation is removed from tpm_chip_register() and put into the new function tpm_chip_startup() which is called before the interrupts are tested. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-chip.c | 38 +++++++++++++++++++++------------ drivers/char/tpm/tpm.h | 1 + drivers/char/tpm/tpm_tis_core.c | 5 +++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 783d65fc71f0..370aa1f529f2 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -543,6 +543,30 @@ static int tpm_get_pcr_allocation(struct tpm_chip *chip) return rc; } +/* + * tpm_chip_startup() - performs auto startup and allocates the PCRs + * @chip: TPM chip to use. + */ +int tpm_chip_startup(struct tpm_chip *chip) +{ + int rc; + + rc = tpm_chip_start(chip); + if (rc) + return rc; + + rc = tpm_auto_startup(chip); + if (rc) + goto stop; + + rc = tpm_get_pcr_allocation(chip); +stop: + tpm_chip_stop(chip); + + return rc; +} +EXPORT_SYMBOL_GPL(tpm_chip_startup); + /* * tpm_chip_register() - create a character device for the TPM chip * @chip: TPM chip to use. @@ -558,20 +582,6 @@ int tpm_chip_register(struct tpm_chip *chip) { int rc; - rc = tpm_chip_start(chip); - if (rc) - return rc; - rc = tpm_auto_startup(chip); - if (rc) { - tpm_chip_stop(chip); - return rc; - } - - rc = tpm_get_pcr_allocation(chip); - tpm_chip_stop(chip); - if (rc) - return rc; - tpm_sysfs_add_device(chip); tpm_bios_log_setup(chip); diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 24ee4e1cc452..919bb0b88b12 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -190,6 +190,7 @@ static inline void tpm_msleep(unsigned int delay_msec) delay_msec * 1000); }; +int tpm_chip_startup(struct tpm_chip *chip); int tpm_chip_start(struct tpm_chip *chip); void tpm_chip_stop(struct tpm_chip *chip); struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index ddaf362e62c1..94a2bfb244b3 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1129,6 +1129,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); + + rc = tpm_chip_startup(chip); + if (rc) + goto out_err; + if (irq != -1) { /* * Before doing irq testing issue a command to the TPM in polling mode