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: 23424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1117239wrr; Sun, 20 Nov 2022 05:35:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf7sqlKpVCvw9GQXL4D7gMLsK8TR9J8Csdl23XxbpI1JNmE4Ct/b8uAgQlsYMNxtqWEzJjIm X-Received: by 2002:a65:674e:0:b0:439:3ca9:94a with SMTP id c14-20020a65674e000000b004393ca9094amr13733085pgu.107.1668951346268; Sun, 20 Nov 2022 05:35:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951346; cv=none; d=google.com; s=arc-20160816; b=vtcyDUbmPEMcg/7hoa5KlX7eWAR4bGNZUb5uX82f5Je8Gci5/NtHo8KNNVGcufnLUY m97kB73xsGXmpZ3W+akMZd4sOJs/sRvxrH0RNKSGTgEprZk888Fpo6k8KOnr3HawVwmx U3//WnhUNlMbap1YWEhVmxhR57osI0wt3/IDZgpxh7qcwLG296oOg8WlPU+U7eUxbbRA OM7uD3+opjPiEfdgmkXN+OESjRJCjtZ8YtyACVeWNLxZ4gEghXKSN5++5fPKho1R2JwB SjaODtJmmZEPAjxIgHVb0DEhHbTsOV4c6gcvAS+cN1jW3FEHhFjCBfeBqmxhYN2WLXqI 8SAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E6zlWIm9oM/GjzOpdjNAuGrLapusFr2z5NlJBYv1qs8=; b=Yb0xxG1YTj2LSlWvERnFmL2XH7EH6M9qh2++5juhQfn60V8c6jprQcwtP3cFFf1TZt ywmm183H/n7HHXbYj693XvYtUbdBejWzLfgGevVwUqpKAqScvO4CUcnWFzWDbYiY0Yvs 8Cjx56FF1OZiugjNJXtf9WHDI5yisG7e5LPcUCa78cbcOa83uuFqOlkHcYiN+BgwaRTZ JWkRho0srtrqylsW2d1f038VasL3J+TplIRA7YKZqOWAL1QjISlHIPuszJdK9v4wiL5d QzXGLyMkfvVx9f7CRAeEAkupDrAmTrZ11YsWAlQm20/mi4YazQfADGciNqp38bzyGCMd 75pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=i2h2mOc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g2-20020a056a000b8200b005732e831300si7573416pfj.337.2022.11.20.05.35.30; Sun, 20 Nov 2022 05:35:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=i2h2mOc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbiKTNdK (ORCPT + 99 others); Sun, 20 Nov 2022 08:33:10 -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== X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MIME_BASE64_TEXT, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022327247035909?= X-GMAIL-MSGID: =?utf-8?q?1750022327247035909?= 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