From patchwork Mon May 9 08:05:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12843170 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 D00B7C4167B for ; Mon, 9 May 2022 08:44:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237081AbiEIIq1 (ORCPT ); Mon, 9 May 2022 04:46:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235757AbiEIIOx (ORCPT ); Mon, 9 May 2022 04:14:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3842130C5B; Mon, 9 May 2022 01:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1652083626; bh=y3wkeJ7ZYRxjhV+SmNN+0jvODpsGU4EpwvD7/wY3xLY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=JwAQrkge+fYwTqZgi96aUV3rd1GrvJ6hobZrcDdBGezzjV1JV2jx/G+lVOKfea2YO LjlkkZZKHwauOsp/4vOP97upxsEQO2/2y9zRfWy8xAy0ahKEIncJHgQHKe88hJv9ev f8jfz31p2sLCzRgqWB55ETHxN33aXKFPa+OkSDxc= 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 1MF3HU-1nYcL33stc-00FUCT; 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 1/6] tpm, tpm_tis_spi: Request threaded irq Date: Mon, 9 May 2022 10:05:54 +0200 Message-Id: <20220509080559.4381-2-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:VEe9AQBEptDU/mhnL5y7j/e8z2rQQDtj6jhRmqTdV+HuixTmL63 9rK++fzpomo40G4KKg3h0Nqk99a925rN3ikK7h5TL+0/qaV1KfltA42T6nh+MWAtJmF9oar 4miIyP4VTLgn6Jxj6thQiLyZ/ZtvUhTpMk8xjO9ZVT+94/vGPqug/xi0g9f1kZ3up9qsPZ+ nshBxZycf9c11gvVlJM1Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:RD6S0MjoskY=:V1yn4RcqaWhPTh5QOMXWZv y8IguvIC2ztdh2IpQJxoyvQiFc7JoVd5/wKo+BoFzOmboF/abX5yw11PRi8PhVIcveQcopGD0 vY1ZKhmry02BixB0bH92yleD32xupfOM6oO0/kiO7XU6D8GCXfHc/TWZ+Ncsgz1bwMy//Gfuf ucAkAaBlAw522e4zwnpSR+iPD/Csk3jJA25kRjhbtehXggZ7qwGklnwPXEkZN5Lfo3fVeLWqc lfqoVkJwrND/1XnGkyHhKaJI2aeP+PCuHTwqqjs/NFC3i9wdBHksFdjbzlQicwnyR5sZUl2vh dWkxO7fKx29A3D9vf79yyTB7cRm4lIMsvvkR261mESN8h4BQOW2jSgkCeZrjbniSQNp/FN7ir xSyP7xiDRtf5HkYhoGmeXa03FKk7HHUdExVMSTCxVXcxe0AIiBjgJUzhE/VpSxh2zWdHRxzqw n6PMft+NkRWWCVEWyP6Rc1XTryrrZjZAAHKpZpRvSVDc3PWLoYG/pFUvjLl8xsYe3vRQYHTm3 SAk05jmthyTEBT4i7y34GweQpNeMTLcLTpAyvjvOGneBJLvKzFO+Moet1x7ghteMXGfGuXHGN NcwTgF1RSeEXCSmvPrl5DglNQBo4D9x5DyH0MAnzFvTwNgnulBb2wEOrDkV2mGQCqA457jtlU FQNkeFqWScZSOALYM0pwdO5TIuGB692MXIn/cYM1qvzhS7MT9q+pXyNyQfwF5DgteUrcqHXXO QaKy7LDEIpMnEGCyU2OiVbXzK8UkYaH0qPQFD+e+226lxEvxXwChbYvb0Dzq1x83bv7G45247 V3GmOyRnIpOcFO8T1s87vbx37sUK4EezEQZLwD2ZMoIRa/9LaUivk7v/vvq24vrfwYAfWoR9u 3uiHUGQFgHn6u1F+ILk3JMyYj81c9kGg2Bw9wd4Wn/ZOzy4GHy/Zo/A7ydBeDZ4J+cyQ/b+bQ tTcK4DCg5TcARGsg+MIbIGvXFgtTIAVZbDwyT/+G7IZLsduiWIspBTBKElKsuyUokGlEM/DFy G1VUq6XhydKhQM7L4b81s6hWJ3zgRk6K9hF69lu9cpQyrpZJ7Coyoz6JCYohurF+M3YaOxlcY M7kRElkorBTw+k= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Interrupt handling at least includes reading and writing the interrupt status register within the interrupt routine. Since accesses over the SPI bus are synchronized by a mutex, request a threaded interrupt handler to ensure a sleepable context during interrupt processing. Fixes: 1a339b658d9d ("tpm_tis_spi: Pass the SPI IRQ down to the driver") Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 15 +++++++++++++-- drivers/char/tpm/tpm_tis_core.h | 1 + drivers/char/tpm/tpm_tis_spi_main.c | 5 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index dc56b976d816..52369ef39b03 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -747,8 +747,19 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, int rc; u32 int_status; - if (devm_request_irq(chip->dev.parent, irq, tis_int_handler, flags, - dev_name(&chip->dev), chip) != 0) { + + if (priv->flags & TPM_TIS_USE_THREADED_IRQ) { + rc = devm_request_threaded_irq(chip->dev.parent, irq, NULL, + tis_int_handler, + IRQF_ONESHOT | flags, + dev_name(&chip->dev), + chip); + } else { + rc = devm_request_irq(chip->dev.parent, irq, tis_int_handler, + flags, dev_name(&chip->dev), chip); + } + + if (rc) { dev_info(&chip->dev, "Unable to request irq: %d for probe\n", irq); return -1; diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 3be24f221e32..43b724e55192 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -86,6 +86,7 @@ enum tis_defaults { enum tpm_tis_flags { TPM_TIS_ITPM_WORKAROUND = BIT(0), TPM_TIS_INVALID_STATUS = BIT(1), + TPM_TIS_USE_THREADED_IRQ = BIT(2), }; struct tpm_tis_data { diff --git a/drivers/char/tpm/tpm_tis_spi_main.c b/drivers/char/tpm/tpm_tis_spi_main.c index 184396b3af50..f56613f2946f 100644 --- a/drivers/char/tpm/tpm_tis_spi_main.c +++ b/drivers/char/tpm/tpm_tis_spi_main.c @@ -223,9 +223,10 @@ static int tpm_tis_spi_probe(struct spi_device *dev) phy->flow_control = tpm_tis_spi_flow_control; /* If the SPI device has an IRQ then use that */ - if (dev->irq > 0) + if (dev->irq > 0) { irq = dev->irq; - else + phy->priv.flags |= TPM_TIS_USE_THREADED_IRQ; + } else irq = -1; init_completion(&phy->ready); 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); From patchwork Mon May 9 08:05:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12843172 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 659B7C43219 for ; Mon, 9 May 2022 08:45:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237334AbiEIIqa (ORCPT ); Mon, 9 May 2022 04:46:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235585AbiEIIOw (ORCPT ); Mon, 9 May 2022 04:14:52 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BE246473F; Mon, 9 May 2022 01:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1652083626; bh=MlFNdZlzZ1snP/e8iwy/NN+cugdEdZuPrb2VR9D/dQ4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=O8QrEhCGbPZo4V0UbdRtWXDGegJxC/q7TxlkZFDu8D7KDYCKO54G05lBP1exTUysf 0gZR4rKMVnRMGjvdE/lY2+/piYIwZeCm2hx+DUahgx3qa4B5PRDQElsw+AoUYvzIz7 zXZ2N5xIns7U7iIm2+mfVazWNG4piP/myJ64X97M= 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 1MBDnC-1neeTk2glq-00CimZ; 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 3/6] tpm, tpm_tis: enable irq test Date: Mon, 9 May 2022 10:05:56 +0200 Message-Id: <20220509080559.4381-4-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:yDUEsYMEp33tNMI3hYBWQ7K+MU7i9kK/HNCWtJpBfpdLjIDGXmK hK65PnsSMXLlSD9PJiEOIRbsYskx1mVM9YanE8G/Lh2vd0DLw2RwmQ4glhRYg+eStG7eN0a JDPxDqG97Vm4P0cQY0BBPqS9ozql8x/IN4+dOXvJLlYKTb66taHWzAbqSHXCszUb4y/mRQF MType551/F0d1hn0BayCQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:eoh8oySfHEU=:a46htkS9luq/lb4KtZLhWp fLXOYEjfcOSsAtHxybz+hKDW5UpEcg04hhwxMRxutiqr3uH+D5thZD0MKulPSjIm+byVpGsrf 5rDQfGBl+al4O0I58RvBLRc1UpSB3cdqFf9VtO3jxYV563PIPabBIlJyyjsUU1Rjx762DT2UL EQcMg2h+O4HzVflG+snRaBhxGl6QB5BndkXFh/tm5XmiqIvLSWzfYfwRkNIVJfbiDMwLNI58s iu/gISWfgCvB1s2FQ3VtY9EaCi2TVpPGQKIg4JUmeMMjb2h/QhMvh3PUxCMa2zCj2xcIy/C77 9Jk87vbP7zDPoMQCNPq0FfmWC1nUwjEdBBH8P0GbxYtx8PADh+72Mf+1GSp+MymDX38Ch4Afd EIWTv0PulZPXdtIZBknplZBYSQ2czbYBabhMcH2/gg1DyfBfNE27UnORJVJdLLdU/Mu7cV0iz ez0OoBAmHSZ+j1zYbfQcFxrP7yLe3H8tHTNTG9DImtOnh+2VJyOZ3j4yCZ0Z/NRcaon69awpF l6diwp3IKX+Q2wi1WGByu9Ngc71CheLK0/xgflPNWicmUKJmPRdBeORtG4VrY6jyHiJNjqtjp HQBM3UR4SX6GbN1e+G8v9Ml5Q/2noBJ29rOGW6SBXN9dnpYhKVf7SH4eE8CDRZm5ECjceVojE t/7XpV+3ZcBqlpFRwMRBs/C/OacPVD5QzHbiS5eSp5sJRa6LC/6RSgiIwb+6WDy82kPfgJsda XwOfrWHY/FlfhDqq29EwRvRXKI0GKlMmtCrpTLrfeqWLL27TeRnuO/99etRSywwh2+uG5Moxr cEmYRF6+ptj8ktWM0sacB0f1CH3sp0JxCYX4aG6RrMNEEd0MPA+K1SpKd4GC3UQSvffJ7KxGS b+AYbnYt6Bye44Jx37r0UbIYMXSGsx/gmJbcimmLC0HM5tvm4SiS/YbDtpnAojHpKNGFFtw9Q YNJRqkOtc9cIeI0bFYvuzmlZfUjQ+4B4s/tgc5nwwyIlr05m5v3Lw/1XcSs98/XIcBboSmaWW o7UZrNCiwhYMOUoiiZBvRWXstm7KN3nAQvf3kg3zpL26Arg1A945tjcemOpjqsJ/hqsDH0dA7 jNi0sWnu1aSHCw= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo The test for working irqs which is done in tpm_tis_send() is only executed if both priv->irq_tested is false and TPM_CHIP_FLAG_IRQ is set in chip->flags. While the first condition is initially met, the TPM_CHIP_FLAG_IRQ flag is never set, which prevents the irq test from being ever executed. Fix this by setting TPM_CHIP_FLAG_IRQ just before the test is made. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 46f504fb5084..4f3b82c3f205 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -781,6 +781,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, return rc; priv->irq_tested = false; + chip->flags |= TPM_CHIP_FLAG_IRQ; /* Generate an interrupt by having the core call through to * tpm_tis_send From patchwork Mon May 9 08:05:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12843173 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 D987CC433F5 for ; Mon, 9 May 2022 08:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237328AbiEIIq3 (ORCPT ); Mon, 9 May 2022 04:46:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235727AbiEIIOx (ORCPT ); Mon, 9 May 2022 04:14:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA61515D31D; Mon, 9 May 2022 01:10:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1652083627; bh=xOpvZ8BgGCUz6IDaFNm7AWkuquQ2TTNkNVxmdRJZRIo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=E2vrTJ8P0DxVREsgDXGdGC/uKskZK8QkaM951p2q8ytXOAa41Vx+vtL0AfSCZNxij a/+x9fmIn7/t4Vbdm1+8sy0vG5a+Iik2P1pts7SfpSf35Skolpu3MJlzhdKmc/rrlw drIwxuoi46gCXDqo8bJZlrT87J4ec3/6JtZOpYww= 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 1MbAgq-1oKpCF03EO-00bdkT; Mon, 09 May 2022 10:07:07 +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 4/6] tpm, tpm_tis: avoid CPU cache incoherency in irq test Date: Mon, 9 May 2022 10:05:57 +0200 Message-Id: <20220509080559.4381-5-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:4t6mWcZUnR8Zow/cWZDz9hnDGH0BwWHhkduqhaFeeoJCNlegYyq WMw8AKELkLhuUBk2KStJnG2/LTrmkD5o41pRVjgn1BE+Ib/UQfnUw9rR76RF1mkrtYJvt63 J46ePcf+TzVHpITclAXsg3LvC4FGnJOLPeQbr6gMk0E9VDgPW+n3p3vPifPHjvvu3gktjQU CPlDj2S0GSPL/Y+hMKgXw== X-UI-Out-Filterresults: notjunk:1;V03:K0:jQrDmr+Dqx4=:XOm0JdT4QTHWTtXnZnVPIZ PvNmeB3ZqMrZ4bMl/ARrVO5VFxPCERk+N6xVIJluiBgC9g4sSd6qvHtPhsFCyYH4ns27A6Jm0 93rcrP24l++IBY7pncbYAN8Z7DI4iRzOcwt3ZFDQ2lpOcx7Y5C+OxQeIHgHTm0+2QC2Q5Ic/P uTeIMmA5p6E4qwSasGjN3dYe9+eNBl7U/Fir8MGvh4XvasuNBqSdhD65aiRRcAKw70J+85aWM CdiPGBbovn0MMwO3ixfYX/bTdBO9lfHZdiig/dawKFoXG66CDoTlNCMeK/mL6Q+PEVfdSwtoK FhrZeLIbMdioCJbZZIZfS8lwEvzgufMa6ftys0i8WDYdBYGq4MAa+vtn5IqsCrN1Ct293edcU fJwmM1p/FYs4PwkgPb+C43EcAgcCXcZdh/rmcMQepLA/cwgYQjEZ8HMKCWm6BnZ13k9fGPOCd cu7bhXD0VAvro0kqeioiaQ+EJlDhETcf5FEevEb+V0cKVemGh5G8Yq6VlFExCpzD/JJVh0KSQ oYSX0QOIkRWjZm8W2ux4WD/MZfT18lNVhwNdsB76DKO2UV5PLRVuUKJ7+X5P1VYIsNL0xypWh zWmhIUyM69UrmAZckLqqtQnf/2oztSnI3FuGDZHkDBunOlrRz/BcR63Xgw4NmTCwT6w2P/Dq0 a0t92kMkckjzjMwF0dxYVk2C2cDNBf7pnISmX+Qppmy3DKJ07ReJha5oYOU1iBrkHmmi70dBF NKUtmvJ4+enKrXHQO+GwoUGRGOCaX9ZUKYnErIBptkwumtEqxUfvDBKiTRznHgN+eGmB7amKr NsnJCNfSy6EZEeeK3qhPy/M9JVH8CRDoncueMLU+ibPM76VN2mJnNCJiXUBcUb6dEbQRr03es FlLnTyDPFtbSiOQg3I0f2m5AymsqzDN2P/2lCHsdhQQyV+67+N6lRmT+kt1lkydKPrfjQCqgs oQuZ3lDi7iVYbEX7RVHTwbDDAY2HqdwmTMf1pH/ngxMHOw3Kh2KfwowtTHebTl2iK+61LgLIi MRyLB67p4ZszC6lls1FFxt6MRCu2e/rBbYjh441/ER7CeHSyR65zViVwf1HhwLYU6HOjbizbT z/FU8od+I6f6vQ= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo The interrupt handler that sets irq_tested to indicate that interrupts are working may run on another CPU than the thread that checks this variable in tmp_tis_send(). Since no synchronization is used to access irq_tested, there is no guarantee for cache coherency between the CPUs, so that the value set by the interrupt handler might not be visible to the testing thread. Avoid this issue by using a bitfield instead of a boolean variable and by accessing this field with bit manipulating functions that guarantee cache coherency. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 13 +++++++------ drivers/char/tpm/tpm_tis_core.h | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 4f3b82c3f205..bdfde1cd71fe 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -470,7 +470,8 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) int rc, irq; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested) + if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || + test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) return tpm_tis_send_main(chip, buf, len); /* Verify receipt of the expected IRQ */ @@ -480,11 +481,11 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) rc = tpm_tis_send_main(chip, buf, len); priv->irq = irq; chip->flags |= TPM_CHIP_FLAG_IRQ; - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) tpm_msleep(1); - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) disable_interrupts(chip); - priv->irq_tested = true; + set_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags); return rc; } @@ -689,7 +690,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) if (interrupt == 0) return IRQ_NONE; - priv->irq_tested = true; + set_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags); if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&priv->read_queue); if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) @@ -780,7 +781,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, if (rc < 0) return rc; - priv->irq_tested = false; + clear_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags); chip->flags |= TPM_CHIP_FLAG_IRQ; /* Generate an interrupt by having the core call through to diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 43b724e55192..c8972ea8e13e 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -89,11 +89,15 @@ enum tpm_tis_flags { TPM_TIS_USE_THREADED_IRQ = BIT(2), }; +enum tpm_tis_irqtest_flags { + TPM_TIS_IRQTEST_OK = BIT(0), +}; + struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; - bool irq_tested; + unsigned long irqtest_flags; unsigned long flags; void __iomem *ilb_base_addr; u16 clkrun_enabled; From patchwork Mon May 9 08:05:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12843171 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 B7847C433EF for ; Mon, 9 May 2022 08:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237323AbiEIIq2 (ORCPT ); Mon, 9 May 2022 04:46:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235691AbiEIIOx (ORCPT ); Mon, 9 May 2022 04:14:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B40751D075D; 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=1652083627; bh=XQDSzEYmlgJhOdBUnEG20yQFV5PTnn/Qs44xno+mB9E=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=hVQ2W9b2tfB7146tpn+kH7M/xmPM0JWeRSOhFaFdJu2+Qy+K73Kf/V2jiG8reON26 ebh7O2hG/nTyl6yENGOm36kTmTm31LR5c55iPrjsbKRCzs66TRYlmnmN4VMaXBRfd3 bbvMTP8sz2el9606JdkYjkDQ3xHt3m9/4l4kTGnk= 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 1MIMfc-1nbvjD1aNQ-00EOnx; Mon, 09 May 2022 10:07:07 +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 5/6] tpm, tpm_tis: Move irq test from tpm_tis_send() to tpm_tis_probe_irq_single() Date: Mon, 9 May 2022 10:05:58 +0200 Message-Id: <20220509080559.4381-6-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:4kJWVwqbBEo2xvrqes8YKbtx9fvrePzaXpK+nDtCFLzgR0AV2U2 4nsfLXapkftu9kQt2xNb9eXi1gCIoOCHgVNIjSYRywavlSATdL8K3PuIpt8mu9NBhAr8P+r PSMPJnG1OSBXX8BLoYeQg56Wl7kRIrPZbRcJ6CjqTHwNbF/EAdfusEqdNKVcz0+bq9TV52U b10V8HiRx1lQiDXGCm0Zw== X-UI-Out-Filterresults: notjunk:1;V03:K0:ojO5q+OKEN0=:Acv4EVI+xsaeaOKkYz29tN Bjmy4p9CrVuOVLy4gk5qic5ra/hu9f8/6B9ttNVtl2tWVyIiwYSgO1KOedViw9A2izblC6ocu tpmSTgWlXeRGcnCi9CqU6Z6BGRDcmk+2N0NH4PjL8PnpbsWD6faw2a3KQkJdM5ohsm130KzYU vakclW0quoyd4qGeWvR5R/GDZpr+wpzCwRpFK29wbq0GFpCdT/EqTXVynrahgWIwc+tANGALA Yt+OxagvC9AtaqUpxfCCTuH8n24rKnwB1dWj4PGJt5AVJgzrE4bGogTai+aPKFx7GNLF6ep16 2lRyr94XBVQ6PCYybrYBRhpzhj2lgJqeorcx58owCPh+PTI2ZjTYXZi8D3HoLzbGnB6iwqM5Z ZI/Yz0seVQgqVkWSFqQFk5DXMpZKJkDTO1FLXjRfs1maxHZ5mzjSMyDlE+HtYl2z4Tolzx9k5 hDDoehSjSCml7/lt2eEj+I2RX2rndCLHV7JZVQSlwHZh7HZdzQpoPJT+EWesnmhtTXvunxvRM 1+o9fwUuI/N0fHf3IU+tWv+By3H9ozk8TZkq9nJ5dsl0gcFjaXlUyWgqXw+3CyJXNc76K+RpB xsRd9I2mWgE8rKuU6RxuaqP2X1ViYEUmi6UZXS5zgpmN2rqPV/0+TNSpAV0zMbjuRZ2wUkKtv vFGbXDHicu9qcIVC4B0xzm5tldLFNyuxJTzDz5xGf7OysVjqY9BNs31crfAOY0V3o9kQI/ogK VunBVJM7X4GvcOpITXODChgolSivAH/qJLUWdILye5ZehbHSjniwm0lx6c10VvZxW27gIZi4k 6n+yF+5joQN+O2oK8WzbmMTvMg0En6SsQjaF+kSy7j0Gzw1MSRvO3+cb8iSQDGjA3QFWipgMr knflQCw2p41x0mI1Lzcla/XoT7KqXCH9q3xPdyUhMHcAUxj3I15cnYdt7MFg9XU5Sugo+UHBE UxDjOisR3e9yCG43hDEjCO1YbAv3J0E6MADScXWPclOqvno3VYcSekX2acqt0ugtWpB7hp5eL sQQNCzYTqOUI0Ly9NUrYBZ7LYaxUbz1PkzjfDbdcLOjV1Ag7HaJqObg3J+IVB6vWJy3kqOdX+ neNg/urj4wy/bk= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo There is no need to check for the irq test completion at each data transmission during the driver livetime. Instead do the check only once at driver startup. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 68 +++++++++++---------------------- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index bdfde1cd71fe..4c65718feb7d 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -432,7 +432,7 @@ static void disable_interrupts(struct tpm_chip *chip) * tpm.c can skip polling for the data to be available as the interrupt is * waited for here */ -static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) +static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc; @@ -465,30 +465,6 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) return rc; } -static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) -{ - int rc, irq; - struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - - if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || - test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) - return tpm_tis_send_main(chip, buf, len); - - /* Verify receipt of the expected IRQ */ - irq = priv->irq; - priv->irq = 0; - chip->flags &= ~TPM_CHIP_FLAG_IRQ; - rc = tpm_tis_send_main(chip, buf, len); - priv->irq = irq; - chip->flags |= TPM_CHIP_FLAG_IRQ; - if (!test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) - tpm_msleep(1); - if (!test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) - disable_interrupts(chip); - set_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags); - return rc; -} - struct tis_vendor_durations_override { u32 did_vid; struct tpm1_version version; @@ -759,51 +735,54 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); - if (rc < 0) + if (rc < 0) { + disable_interrupts(chip); return rc; + } rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); if (rc < 0) - return rc; + goto out_err; rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); if (rc < 0) - return rc; + goto out_err; /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); if (rc < 0) - return rc; + goto out_err; /* Turn on */ rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); if (rc < 0) - return rc; + goto out_err; clear_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags); - chip->flags |= TPM_CHIP_FLAG_IRQ; /* Generate an interrupt by having the core call through to * tpm_tis_send */ rc = tpm_tis_gen_interrupt(chip); if (rc < 0) - return rc; + goto out_err; - /* tpm_tis_send will either confirm the interrupt is working or it - * will call disable_irq which undoes all of the above. - */ - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - rc = tpm_tis_write8(priv, original_int_vec, - TPM_INT_VECTOR(priv->locality)); - if (rc < 0) - return rc; + tpm_msleep(1); - return 1; - } + /* Verify receipt of the expected IRQ */ + if (!test_bit(TPM_TIS_IRQTEST_OK, &priv->irqtest_flags)) + goto out_err; + + chip->flags |= TPM_CHIP_FLAG_IRQ; return 0; + +out_err: + disable_interrupts(chip); + tpm_tis_write8(priv, original_int_vec, TPM_INT_VECTOR(priv->locality)); + + return rc; } /* Try to find the IRQ the TPM is using. This is for legacy x86 systems that @@ -1075,12 +1054,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, if (irq) { tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED, irq); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - - disable_interrupts(chip); - } } else { tpm_tis_probe_irq(chip, intmask); } From patchwork Mon May 9 08:05:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12843169 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 80425C4332F for ; Mon, 9 May 2022 08:44:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237044AbiEIIq1 (ORCPT ); Mon, 9 May 2022 04:46:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235762AbiEIIOx (ORCPT ); Mon, 9 May 2022 04:14:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF12F15C195; Mon, 9 May 2022 01:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1652083627; bh=jawVDLK4M6JXYsElU3UFwvf75JxMX5G0f1UyaQ8LpM8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=MYq/iQWDyjCk3gl9ZzISAo+kOBHX0vIWgQr+yFDFkkA/lt01KFFh1bkuiOJiGFfyP Jct9mC2RA5L/uDvJL2DDVjxiTM1V7uqc3r3AgyxvEWi8XQsqmYLoi8KMOp/U+Dx4Nt DhkYVhlMAo2NEuZfbVhTqeY7/URD2s6lQmfXFcQA= 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 1M9nxt-1nky9W31oD-005uUi; Mon, 09 May 2022 10:07:07 +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 6/6] tpm, tpm_tis: Only enable supported IRQs Date: Mon, 9 May 2022 10:05:59 +0200 Message-Id: <20220509080559.4381-7-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:zN1qIufImPbOTF8Is3GDJkJznI80WelGmSFiugxoRZj2XUS++h+ 1eHp9FzDglV6EEpbH7OpA1kRdwVbSVVrV1t2wtnfKKY2ftKltf7YfvGD3LAiTXDHgHuLIfO /4wgQW/7ic7KWfI7Jf7r2i0ypxgy21ZnJLqKSBc/W7mttzVHePrsDjk+3eeErjWwhPIRFmQ fDQJZDflUGeV+080MhNCg== X-UI-Out-Filterresults: notjunk:1;V03:K0:18GPfPn+WSU=:RafU13f5qOfv30/wg4kEea XmVUVnk3HZKa/t2simI+8Kt7RObFWCF4rh790m581amymT0SmNgIPHyVrELmbSbhoAvFQs+M0 C6aXPvzjyRxGflvXL8nihcaKq3WWVJTuoTMlUZMAmWk9FfSOPE7xqWK0oMPUuBdtWLIHXa6f5 A87baQlDSXVMNBYRtmQ/DnrEcwyWbt+rYUVGgyba3tT2YfDtp2+rBqdK5pfc9hGT0el8HGLpd GRIl0iuyyQ3VELaw4stalFuXavpeoPgmo06mCVhLS0vSz1vUv+EaOr0NGQS/9IZhOI14NwqNR xzMOVtNw83scIVDVmcPM2Qb+X8HcF3ka7996IVg4KZNyHuG8ERaNNrmSOEi+dD5rdEm4J2tYp 8s5UKfGbCRXPHgyu+bqzjBGix6g8Ywt5mV2vXwy3vp3HYNyUAINWdjR51EvaLbqTG5W7Fb6v+ YkeqTnmQc1A2b6Vu+tghtUNB6zRZmFKFFD8b/AL2YbJMcpGHjeJYUbU6pBUVcz9Cy5aekcb85 NOdwoI7zmQ9sK10iedTsQrgOgdRi2fM3blZYnwL/ZWVuC4zoTCwOqimnuV21MaLpjpSmPPdrr lNXiHdredIqtPZZ1G90J15/44DNoQSAj/rGGiBHUEsw5XiI9mPjaYfHPJiCm0mRwVYtkj3Qzq QULsauq+wlI5LpcXt6fAhzbJ3OH3aT+f+maAz3GL+5hN2dFkcqoEKL5+O9+HKt7KqQxDDV6Mt jrbFfA15A3+Wb7kauqWeMrou49veH1gP2XVC8VfGqBcfuHP47AODh0eO9i0kYfNkgWWE4fwrw VL09PmvTxSQlDp8JpXI6/d5cRTADYohkqJIp//spYo5jIB+Lxhj7NXPJsd+5ACQave5+jWsSy mYVy5tS8/c6U6O1Kkb3RYdprxnoy+WNAY9ACDnawjH3NTwwm+5VoTpzTw6xdsJOgNNhk+tK8x X5dCMsLSgf6tBuTJvq6IYrJtWG2FmbfqYLkPaWzQmhamjcHA3Sic/TPzZC0gbiffD3GYwASjD IQhLVtb7XHzf1H/WsKvL3oF1B6XOrUwasfqXByulcBgtEiFeGVByeUVTA3qwEDXKJ4eUts5u5 519qldSRqNvO6I= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Instead of blindly trying to enable all possible interrupts, use the result from the capability query and request only the interrupts that are actually supported. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 67 ++++++++++++++++++--------------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 4c65718feb7d..784e153e2895 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -976,13 +976,46 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } + /* Figure out the capabilities */ + rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); + if (rc < 0) + goto out_err; + + dev_dbg(dev, "TPM interface capabilities (0x%x):\n", + intfcaps); + if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) + dev_dbg(dev, "\tBurst Count Static\n"); + if (intfcaps & TPM_INTF_CMD_READY_INT) { + priv->supported_irqs |= TPM_INTF_CMD_READY_INT; + dev_dbg(dev, "\tCommand Ready Int Support\n"); + } + if (intfcaps & TPM_INTF_INT_EDGE_FALLING) + dev_dbg(dev, "\tInterrupt Edge Falling\n"); + if (intfcaps & TPM_INTF_INT_EDGE_RISING) + dev_dbg(dev, "\tInterrupt Edge Rising\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_LOW) + dev_dbg(dev, "\tInterrupt Level Low\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) + dev_dbg(dev, "\tInterrupt Level High\n"); + if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) { + priv->supported_irqs |= TPM_INTF_LOCALITY_CHANGE_INT; + dev_dbg(dev, "\tLocality Change Int Support\n"); + } + if (intfcaps & TPM_INTF_STS_VALID_INT) { + priv->supported_irqs |= TPM_INTF_STS_VALID_INT; + dev_dbg(dev, "\tSts Valid Int Support\n"); + } + if (intfcaps & TPM_INTF_DATA_AVAIL_INT) { + priv->supported_irqs |= TPM_INTF_DATA_AVAIL_INT; + dev_dbg(dev, "\tData Avail Int Support\n"); + } + /* Take control of the TPM's interrupt hardware and shut it off */ rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); if (rc < 0) goto out_err; - intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT | - TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT; + intmask |= priv->supported_irqs; intmask &= ~TPM_GLOBAL_INT_ENABLE; tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); @@ -1009,32 +1042,6 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - /* Figure out the capabilities */ - rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); - if (rc < 0) - goto out_err; - - dev_dbg(dev, "TPM interface capabilities (0x%x):\n", - intfcaps); - if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) - dev_dbg(dev, "\tBurst Count Static\n"); - if (intfcaps & TPM_INTF_CMD_READY_INT) - dev_dbg(dev, "\tCommand Ready Int Support\n"); - if (intfcaps & TPM_INTF_INT_EDGE_FALLING) - dev_dbg(dev, "\tInterrupt Edge Falling\n"); - if (intfcaps & TPM_INTF_INT_EDGE_RISING) - dev_dbg(dev, "\tInterrupt Edge Rising\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_LOW) - dev_dbg(dev, "\tInterrupt Level Low\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) - dev_dbg(dev, "\tInterrupt Level High\n"); - if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) - dev_dbg(dev, "\tLocality Change Int Support\n"); - if (intfcaps & TPM_INTF_STS_VALID_INT) - dev_dbg(dev, "\tSts Valid Int Support\n"); - if (intfcaps & TPM_INTF_DATA_AVAIL_INT) - dev_dbg(dev, "\tData Avail Int Support\n"); - /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); @@ -1101,9 +1108,7 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip) if (rc < 0) goto out; - intmask |= TPM_INTF_CMD_READY_INT - | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT - | TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE; + intmask |= priv->supported_irqs | TPM_GLOBAL_INT_ENABLE; tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index c8972ea8e13e..3d6b05c6fdba 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -97,6 +97,7 @@ struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; + unsigned int supported_irqs; unsigned long irqtest_flags; unsigned long flags; void __iomem *ilb_base_addr;