From patchwork Mon May 9 08:05:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12843167 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 087B9C433EF for ; Mon, 9 May 2022 08:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230310AbiEIIpv (ORCPT ); Mon, 9 May 2022 04:45:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235627AbiEIIOx (ORCPT ); Mon, 9 May 2022 04:14:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3E4D1D043B; Mon, 9 May 2022 01:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1652083626; bh=viBGPAXuNsA7zjTMIINHaGbiAR7IRO1hyoh+kfXxmY0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=fQNZFMRgksIrIe1fiR8JNLrpFt4Y/x5UnAfyjEue7NREmwhU9WxIsr3JGc53N6Dzl Qc/X7kRseIZiHGWlcFObZ5EJ5xI4xV9WcWvcUyTkY1EqgKeiuXfN5O1DMpTzdz5tUO hhYdrplLxh/Iv8YVgz63okbLgBiStTAAbdolUG6k= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.89]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N8GQy-1nsDak1Bqq-014A2v; Mon, 09 May 2022 10:07:06 +0200 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, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, Lino Sanfilippo Subject: [PATCH v4 2/6] tpm, tpm_tis: Claim and release locality only once Date: Mon, 9 May 2022 10:05:55 +0200 Message-Id: <20220509080559.4381-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220509080559.4381-1-LinoSanfilippo@gmx.de> References: <20220509080559.4381-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:EzX1A8+1f3IydNHHtPhvWaoNMgzrH3pWX0+iA3ZGSjVn4WzbSiA 7tXpS9EjNgRGfvsQOnVJp3W41Q/mmT7PpH5i1JayytG5WGPPH6nDUEf+9qAyXOORqPR4A3w 1R8EYJhSK/YR22qt3Q/86X9TaDoj1Sp9wtBEb1xl+FjNZfnVPdjmT2Gi9ll3nDJOI/uyB8I oEVcD/GX5KVsb5ySn1Q1A== X-UI-Out-Filterresults: notjunk:1;V03:K0:L4tfxDCfs0g=:+77T31xfuLq9b3eZAfE9aa vZQ5tLluGX4TBfZOLBcRPAeO5xV2kBk4yMLSJrj6r/wNBPGBLfqPGsIEJrheexryyGu3+Nymu FoD6LqKhyjEi/dvj2R31bff8TKp8z34DdXLPuf2klDOoQQMpIa3z5LZaQ71vzsGG0AdMPmrH9 DY/8mo6PKtG6ZDVsH2vQSuPnJOnN57k1ZwIrQCsKSMcWKtuk0kvltnwNHSiHe8fTIDaAZ0V4v +szy9kPZ/xY7c0EhKN+IN3+LBOIMQOOO+8BQryjxX2tkp82bzk7PyfLd/3WqrqfTnlLlu2MwU v2YTAymuPcFKcasYA7LEA7hSpVIsLYxnL6nXD8jOqO3AQCtiIage+9y9I8UPc8spoyiGv6BX4 /2SNozOaE5Pu2F+icLGZEdyUMrr8Xx4FALZxl/ilYyMPDiZpb89Uvgu41Li2sjFxzGVI9gXwY BzPs0Y7c5X/S1ekGi0IQqVwX/RZdTCIzwc6yfkkkBLycsKK6RDbNWcKqxi0nnxFJYbTsZF7Gl aAlUHlXdPln/A/3hJe6x+4Ez5Unnjbc5/vi1BWPVDs97ztkadLTCl8/apVZHCBs21uy/BI5vy EYvOsuPohsn0ijeCxX1kMnev0DRQgfNqftH8aQX/NwKMr2iPQCrdM27UQq1RgkqTTwxl6ctVD yQ00qq0m+CYd12FTR9HRJzIXGFFpIGQcf6jkXZtKRBEg3KZtpajzRFTLupwYl8E4F8qVTd86M GDs0wh8LoZx/BpKg64YNdneUwok+EEBzeqiii4QaagJnhN6N/1c4d5zOxRsAbtM1IgmyPpNJU Jej+Ok2OM/fesb3EnZJNCtgaoqClerdTD+4eJjUV6k5A4AnGAcKJKy4rpdoweZN0tULCBtPJt f2fJuenmUIY750h0cyQFu495CtwrLtBjBTymiBjPHxm4xDO73cTLTZkJ+ormVYxZtYFZFQtiW fowMvZhU0MqpJpci1WqcyQFP5eikxZhN4CpUuVbtN784l7ae+oq2W02xhY9NwaQf+StUTZaJ5 zKYxt3cC0QnTantCHBbUREFv3TyYN8LJCxdVM86H5nXhVnBT7RbboG81EY5SRl1x2inritw3B 2Znek6pLqvoJWg= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo It is not necessary to claim and release the default locality for each TPM command. Instead claim the locality once at driver startup and release it at driver shutdown. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 50 +++++++++------------------------ 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 52369ef39b03..46f504fb5084 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -638,9 +638,6 @@ static int probe_itpm(struct tpm_chip *chip) if (vendor != TPM_VID_INTEL) return 0; - if (request_locality(chip, 0) != 0) - return -EBUSY; - rc = tpm_tis_send_data(chip, cmd_getticks, len); if (rc == 0) goto out; @@ -659,7 +656,6 @@ static int probe_itpm(struct tpm_chip *chip) out: tpm_tis_ready(chip); - release_locality(chip, priv->locality); return rc; } @@ -721,17 +717,11 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) cap_t cap; int ret; - ret = request_locality(chip, 0); - if (ret < 0) - return ret; - if (chip->flags & TPM_CHIP_FLAG_TPM2) ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); - release_locality(chip, 0); - return ret; } @@ -855,6 +845,8 @@ void tpm_tis_remove(struct tpm_chip *chip) tpm_tis_write32(priv, reg, ~TPM_GLOBAL_INT_ENABLE & interrupt); + release_locality(chip, 0); + tpm_tis_clkrun_enable(chip, false); if (priv->ilb_base_addr) @@ -925,8 +917,6 @@ static const struct tpm_class_ops tpm_tis = { .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_canceled = tpm_tis_req_canceled, - .request_locality = request_locality, - .relinquish_locality = release_locality, .clk_enable = tpm_tis_clkrun_enable, }; @@ -963,9 +953,15 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_set_drvdata(&chip->dev, priv); + rc = request_locality(chip, 0); + if (rc) + return rc; + rc = tpm_tis_read32(priv, TPM_DID_VID(0), &vendor); - if (rc < 0) + if (rc < 0) { + release_locality(chip, 0); return rc; + } priv->manufacturer_id = vendor; @@ -978,8 +974,10 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, if (is_bsw()) { priv->ilb_base_addr = ioremap(INTEL_LEGACY_BLK_BASE_ADDR, ILB_REMAP_SIZE); - if (!priv->ilb_base_addr) + if (!priv->ilb_base_addr) { + release_locality(chip, 0); return -ENOMEM; + } clkrun_val = ioread32(priv->ilb_base_addr + LPC_CNTRL_OFFSET); /* Check if CLKRUN# is already not enabled in the LPC bus */ @@ -1006,14 +1004,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT; intmask &= ~TPM_GLOBAL_INT_ENABLE; - rc = request_locality(chip, 0); - if (rc < 0) { - rc = -ENODEV; - goto out_err; - } - tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); - release_locality(chip, 0); rc = tpm_chip_start(chip); if (rc) @@ -1072,15 +1063,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, * to make sure it works. May as well use that command to set the * proper timeouts for the driver. */ - - rc = request_locality(chip, 0); - if (rc < 0) - goto out_err; - rc = tpm_get_timeouts(chip); - - release_locality(chip, 0); - if (rc) { dev_err(dev, "Could not get TPM timeouts and durations\n"); rc = -ENODEV; @@ -1169,16 +1152,9 @@ int tpm_tis_resume(struct device *dev) * TPM 1.2 requires self-test on resume. This function actually returns * an error code but for unknown reason it isn't handled. */ - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { - ret = request_locality(chip, 0); - if (ret < 0) - return ret; - + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) tpm1_do_selftest(chip); - release_locality(chip, 0); - } - return 0; } EXPORT_SYMBOL_GPL(tpm_tis_resume);