From patchwork Sun Nov 20 13:31:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13050040 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 66BCDC433FE for ; Sun, 20 Nov 2022 13:32:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229644AbiKTNcr (ORCPT ); Sun, 20 Nov 2022 08:32:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9C4FB28; Sun, 20 Nov 2022 05:32:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951129; bh=E6zlWIm9oM/GjzOpdjNAuGrLapusFr2z5NlJBYv1qs8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=i2h2mOc3C3vVDsqj33TjYpssnck9VB33EVvQavhM5O1mXJ1hes4o2R/cYv0TEd2Eo wlSqFrpy/oVTQ7yNOWRKiJLwurBOgFekfAos71dho1uqrQJLninyfgdRc46esrVKQC KZDEMoQyD2d5FyM/1h91YM4Y4FnTlZ3AFZ8JF8shMOzPA3kHjbvLKQJeDQ3RF8j/dZ 3sUgXv3aFrSyoQ5B9S15Fw4SCgc+eIkNhagKI70qEe7fpvzQ6dVIP65fzILWSeBEOi FvC063QBQRC3DCnFXziokM5zVJTGimc+XTQQ3jjNmAqPvod2lRdRljRp6oaeki7iHa ei3WJIpMU8hLw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MTAFh-1oV00k0XGB-00UYYC; Sun, 20 Nov 2022 14:32:09 +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 v10 13/14] tpm, tpm_tis: startup chip before testing for interrupts Date: Sun, 20 Nov 2022 14:31:33 +0100 Message-Id: <20221120133134.28926-14-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:o4Yv8LXi3e7EPxUvPlF5naCJKcyg/01QSCkduQcXf0VhvL/9xWN 38/8XEupEFIFwFL7cLZJwOr7L/zZd4ME0aTqvIJLPDO7FlH1VMKTHPX7/3rVVHaijWKxRyK GcILisb7Tld1OHTL204XKo21XVuoFoRF5UQWzJdrVgSmevwBHpfzW52gdnHDkaS231D9lqm X938WbCORj9Bk02IkYABg== UI-OutboundReport: notjunk:1;M01:P0:06rG0ZS1J/c=;RSMRuY/3OKsQ5trQLbvspA8j/tt me5d23IVCWFvb9DvjpfT3gogOJWPob2IOX42+dPgWH8Rig9J9bLaYsp9VAU+R89TBPaGjmayp KvQrZFVxq0HNc1pVmzXwZ5VKs+Qf1QDMSS4P2Ptbg/ruYg2mgdJFxHC+6f4b+um22BePTTPQo WSgDdPe1tcXJe1+41jfa5bq6I1Kx/7rHjBOr8JgME4xf4P8t4fsiCzrUFJH8KgJYEWGedMVny fw4yLh/CTjlS5Dz+0/STt7jcpUYWya2aK/GJ8n/5Xk4aBCI9H7ZTg1NsLWYmDPKyd0Gik/YE7 Q8LYsTVYYK8e7ycG17s/njOqHP7i1q53ZSrS7AuthCPiEiRykIujAY9tnE+wFknRj9jxSig4M 1u216Ww5Nvvd4ElJFUgxZm3i6U9bwV7ehWjpKKW3uodoQIF6foU4siPwl3qUwL/1cqjAj+CcO y7KjfmNQk58ZGiGueLWORK39KfgS1eCDwzC2G83qbh0Ac9koKaJ0GK/GffcUg7blvb63h9T+A zTXg7fv/7+gsaU8po3/0vR3E7aKxJlJVXUONMiHX/5tpZ03K8rYfzR0mMweYF/SAomPcNSc6O xsIBy4WJ5vriUBYSGyUkNxYLTFGb+8fw9mC5hlZ7dqrLf2tPcRPvYydnCFHXsRE6zq2B3+u6U tpTDEvgjc+MMFc5uBKGEtG35oqRUDu22KdllIxTkxOHJowUFHXm4S72yp0PYtuffLX/FFuxGX jsCSWm/haU9h0bz6AW3XyciivTo/I79KshCxmrn5t2hFeid96t1a/l5Ww9OyHtVMYRDz66wB3 0UBjX/E0gGuRvwxW70T15APOFvUz8ZafBbxSDeyBiF3MhnRe1VQ2o/EdgzYeK9LCFQcKW4VXx jCEFguNv16Pd1hb7fvAPPaMgLHeXs8ywGvbEzTvykYFvtTe3zkrInXCogjFxT/qi+8Am11Mf3 7AtzgQ== 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 --- 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 2514e60f6778..b97cb325ccb7 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1128,6 +1128,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