From patchwork Tue Jun 21 13:24:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12889293 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 18577C433EF for ; Tue, 21 Jun 2022 13:34:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbiFUNeO (ORCPT ); Tue, 21 Jun 2022 09:34:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351717AbiFUNbC (ORCPT ); Tue, 21 Jun 2022 09:31:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC5E2AE16; Tue, 21 Jun 2022 06:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655817936; bh=AJ+180dznoEA6GFcYRGs+pxZHzuEPVBLARmJQDdqHuk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=PxWr2MxMRKM798e4UPZowIcHUIM0eHCAOgT6T7aUcG4KqGkfJJPkk6I4avKmeYGBk hfIuZy7s+tB7F4FXlf6liuF33nMpf3RdK+VttT25ftcIS69Y87YNrRylNTH+D0SaSo xgUyDzy6LSAXs4q1W0owlTjpiY8P2SBKpGOoKhcA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.162]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MZCb5-1o7kbh20lV-00V5fh; Tue, 21 Jun 2022 15:25:36 +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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v6 1/9] tpm, tpm_tis: Avoid cache incoherency in test for interrupts Date: Tue, 21 Jun 2022 15:24:39 +0200 Message-Id: <20220621132447.16281-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621132447.16281-1-LinoSanfilippo@gmx.de> References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ydDLXptmfcLAO/E27Nv0MJjCMUB8vODQDtUVlD0CVUVqJGkEKje bBJxR2Wz8SN0gcLqnWx2UMAS0FKXNMkfj+N9u8C4IyTQw/q13Trfq+GyufUEKP1EABgyxbj OQMgm7qIj1C/71s43ZFdk9L7T/dlOuzoiuw31Dr+NQCqxyCFD34knBqV2hX/BxV3QzgIgak 4b8KkKm2PdT+dyGu5L45A== X-UI-Out-Filterresults: notjunk:1;V03:K0:43wHtPHvTCk=:vBjlaBEvHG0EVYiPFiPoPZ 4K8b0BFfBaR/NH88eJcKifrc6oiHk2HaT+g00UbtHSyJ4MVwDDS7lFFi4GN9o6omfkwB7iCyU PqeVXzJgPllFvdbtf9LJq2WUMjykbgkg5zw/CIOaEVkGABQemIm2hEL+dz7q4MQWaWhkA2u2F VIo8f08TG2UAgUqTdyJg0QMx6mPETMiV0DBUo42hjRmbWgoHQEntpAeK1pskpTcZdSbi5jG34 HxTDn6P/ztWa/BAiK2vApvOFz/nRL8EdspegXOSUpFJ/5vJ8nnhdqxnq2eTWTANk8vdRSHyo0 tUijNB50X6PTgqcd5KmQwbA88eTzCJFkQHnjTKdsvAe9ByqxPwO08laEM7M224Fzb7GlmV2RF jDKju/tZQvJsu7Jqh2I41VgJNO2qBZb5ki0Mi606RiJ6zcHMxebLlPIBQhEWYJDA5jCQLvtfx PLxDT5PygztVBKI9J5rfgMgm86skDtWomDKiqTz5ykv6lj8o7bYEZ1o398NhIBjONYx+Mq1bS 72vppkTFCGLSmbPQQlDfFg3Z6OCRqB6XVWu3Y4xV9+c1TweA8E4FdY+5NKLTi1fhuOPQf/AwF S7SOliyxXYWTuuCDVRJ7BUi0/V6WW7vX5yak9bdAgQgGUW9ElKLt9B9glOPX8+3qLLuZs/P84 Hh5tqDO2DybpBfcXfKJ/Eh/UNLBFpg76AdIcBza9fF4PnCgW2g6l7yy5Z3R6WZYwPvLsPnWNJ X4MlgT6LnQA3HTjabJeD9F3aRdBNBtd8lHI3292rp4vq0dXQ/bbyN/6nQFSl8xL7xSwjEoyWw 76WuYpILR8nO6ac3jl/p+9q9cBYztPrr9ykZQdebgpOkXVzcL8h8wuieNDhrkaIws8xB09EP9 Oj0cJ3VKMwEIcg1FbO9lNq3QnVmEWE9zGOrslWaHYKeuWmfkcwYQh3BZBIAmLwe5O5+d9lJkJ /K8H0vxL0ozIkBn55nJcUDrhXWt9DSEEVC5j4+wC1xMSGXoP7bDyebQjhZySMrJ1gOM7rE7+Q B29HfbGLNnyQIJcj0xvSL90qTmW1Uwi+WCXfCVyuhguUxBTlT18YxzAbrIFY1idUEe3MlRIzI PlPxUzAjh2n50uHY/TqFDly9sbZwFJbzOIV5XbXB/NBWf5msv7BuUHtng== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo The interrupt handler that sets the boolean variable irq_tested may run on another CPU as the thread that checks irq_tested as part of the irq test in tmp_tis_send(). Since nothing guarantees cache coherency between CPUs for unsynchronized accesses to boolean variables the testing thread might not perceive the value change done in the interrupt handler. Avoid this issue by setting the bit TPM_TIS_IRQ_TESTED in the flags field of the tpm_tis_data struct and by accessing this field with the bit manipulating functions that provide cache coherency. Also convert all other existing sites to use the proper macros when accessing this bitfield. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis.c | 2 +- drivers/char/tpm/tpm_tis_core.c | 21 +++++++++++---------- drivers/char/tpm/tpm_tis_core.h | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index bcff6429e0b4..ce43412eb398 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -226,7 +226,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info) irq = tpm_info->irq; if (itpm || is_itpm(ACPI_COMPANION(dev))) - phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND; + set_bit(TPM_TIS_ITPM_WORKAROUND, &phy->priv.flags); return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg, ACPI_HANDLE(dev)); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index dc56b976d816..b5fd4ff46666 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -343,7 +343,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc, status, burstcnt; size_t count = 0; - bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND; + bool itpm = test_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags); status = tpm_tis_status(chip); if ((status & TPM_STS_COMMAND_READY) == 0) { @@ -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_IRQ_TESTED, &priv->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_IRQ_TESTED, &priv->flags)) tpm_msleep(1); - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQ_TESTED, &priv->flags)) disable_interrupts(chip); - priv->irq_tested = true; + set_bit(TPM_TIS_IRQ_TESTED, &priv->flags); return rc; } @@ -627,7 +628,7 @@ static int probe_itpm(struct tpm_chip *chip) size_t len = sizeof(cmd_getticks); u16 vendor; - if (priv->flags & TPM_TIS_ITPM_WORKAROUND) + if (test_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags)) return 0; rc = tpm_tis_read16(priv, TPM_DID_VID(0), &vendor); @@ -647,13 +648,13 @@ static int probe_itpm(struct tpm_chip *chip) tpm_tis_ready(chip); - priv->flags |= TPM_TIS_ITPM_WORKAROUND; + set_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags); rc = tpm_tis_send_data(chip, cmd_getticks, len); if (rc == 0) dev_info(&chip->dev, "Detected an iTPM.\n"); else { - priv->flags &= ~TPM_TIS_ITPM_WORKAROUND; + clear_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags); rc = -EFAULT; } @@ -693,7 +694,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_IRQ_TESTED, &priv->flags); if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&priv->read_queue); if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) @@ -779,7 +780,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_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to * tpm_tis_send diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 6c203f36b8a1..bf07379dea42 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -86,13 +86,13 @@ enum tis_defaults { enum tpm_tis_flags { TPM_TIS_ITPM_WORKAROUND = BIT(0), TPM_TIS_INVALID_STATUS = BIT(1), + TPM_TIS_IRQ_TESTED = BIT(2), }; struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; - bool irq_tested; unsigned long flags; void __iomem *ilb_base_addr; u16 clkrun_enabled; From patchwork Tue Jun 21 13:24:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12889302 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 6BA07C43334 for ; Tue, 21 Jun 2022 13:34:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230177AbiFUNe0 (ORCPT ); Tue, 21 Jun 2022 09:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351477AbiFUNbC (ORCPT ); Tue, 21 Jun 2022 09:31:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 016AC2AE14; Tue, 21 Jun 2022 06:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655817937; bh=maYa2L+CZbzp+f7QcA0qs/6WRE/UVVILl5dq1Oq1CAM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=jmGV2LnecYwW01LEZV8rqOJgKasRC4jfmr8NZbQk01zyb04xCNE/x7l1rOpajEuYb TUl0WxVmgDxjR+Z4w/o9rpEfjXQT+StX7/6kQWG434NgbTpa4pDHWfalM4RvEp7dwu crUzqFFjUlGV5H66dwv7z1ngGnlfuVGg+Efj+3R8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.162]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MAOJV-1nxMMt3X35-00Bu7r; Tue, 21 Jun 2022 15:25:36 +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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v6 2/9] tpm, tpm_tis: Claim locality before writing TPM_INT_ENABLE register Date: Tue, 21 Jun 2022 15:24:40 +0200 Message-Id: <20220621132447.16281-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621132447.16281-1-LinoSanfilippo@gmx.de> References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:gifxAZRXM0plMBXYUpN8b4ed99qm35ucRjTWTjFlReD8vsJmBc5 d3tVWL5zgA4oggV65gRT9mDOR8rEHcuuRAQ18/MDquAJG133DcznJ4nbhnyS33f+HI1gJHI ghYl/CppOys9N8s/3xGsdAifrvL1CPpERvhwIAxMzKxpa1nDlxwBwY7tBN2r/2z1g+QKp3Q uWyeet8A/v3f3xcjuW9OQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:nrTty1lvEqg=:9P6xa22IfT28cH3BUJ4RlP +rkTA0zTSKyWwt1p2v3zMzfYxxaguVGbMTX3ouald+2PjTonHtFLNzKL5L5YGmywzlWszaRuj /I9nmyMFKm6qOzU9FhrwlCuFPZ06XN99lJJDPV4rUJIYXRYtuoGjHHr3Ocg4//gdsGGjjVPC5 7WXAkn3N1sFGBaT5KEAq1bNAHwl/SdgYCTDm4m+zShZvRiOODUwYGOowCjSHq5am1Qk6twU62 X0aJ2lmJa8fy4L2t9x2fs4GI3My1vh4uFySd3eTxZ+IWozjyp1XHC7EaJ+EfkcN/NfKYeNZ3V 3sC1DRnoaEeJvgLUxZ0+mY+tp0DJ/SOeVQTbW0+l3P5N4LyOCxvEmHlTq9zEQ0K+7POvtYQL8 65MuwnfDya9OuI6EHWN5XUPGeqdWr+wCOmhmvL+0soj9BkZzSF8hfaj38U8CnVI9R+dFkquyw EXSF7oihpMeCIr0H0isf4s2bWY43WTsum81G7wyGUCCIg+w0tyiWL9/whwFjr08CEzvy7hhUo utUCLhVJN3ej+jvhNdJis5YmIM32ujpEtkIwh1jRn43TurFGvuENzyDtxJO4Jp+OUj/ElTR7i 1QQ8ADWPmRRksmSpNjpPunN4DIawiNwwy3/SxYss52F9/AtxpwAtm4vrKABlUE8G3JJKSaFDX 1dS0OZfZsuq92/4YeOVeaWhKdcQv63faosNrMGs3KnmPm3wvn2AZVf3cIyv+ESCfZHArwmI+n 6HIZkQfmfwn8iQRwkC3Xf6NgJTvKa3DKsJXzF+3RjjyID3/cxnn2DghZDQaTy22LsADVWMN04 7kzc1DydYyO992Xz61Sv7g1ZV0JCbuV/8gB71e278NeapWXVcD4nE3L3FOfhr4Yimi+udYpi4 goniTzUDUAZLofU5UBJeqwopwwMEJH0YoG0qbQaNhexXFhZFbnpDIZ8DSugvE/wZ4GBZ8GK8d CPNT3xq4tN8kQ1lYGbDUYoGfrhqoXQjLpI7THjqxwLFk4fvmqDJZzQXia4BhzbyulUI+6SyF7 w1nX10ccMKBmXQfCqcNUIYQaj3kZiku8OjaB5N0sIbpPvpx6Xm4pTEZBzMg7zlO9QaH7Iomue Ry33nFaixGFIzoIADwIzjN1YfyqDlqMBYnil0gdu1WS1HfGjJPOmPEnRw== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo In disable_interrupts() the TPM_GLOBAL_INT_ENABLE bit is unset in the TPM_INT_ENABLE register to shut the interrupts off. However modifying the register is only possible with a held locality. So claim the locality before disable_interrupts() is called. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index b5fd4ff46666..0e68e4502a56 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1084,7 +1084,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; disable_interrupts(chip); + release_locality(chip, 0); } } else { tpm_tis_probe_irq(chip, intmask); From patchwork Tue Jun 21 13:24:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12889296 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 2D29FCCA481 for ; Tue, 21 Jun 2022 13:34:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232268AbiFUNeS (ORCPT ); Tue, 21 Jun 2022 09:34:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351719AbiFUNbC (ORCPT ); Tue, 21 Jun 2022 09:31:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 897822AE1D; Tue, 21 Jun 2022 06:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655817937; bh=DRphZ/l39/9GYPej7UvI8/O4Gz2dDgvZS7UWsf3aqIE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=XsfFdQGesBGo+d6jFBt7KwUZyTkzPntZJYZaf75N5WdwuZW474pAeYAuMFtGR1Vh0 j9irPZA4O5C6NvLxP+VSYGJev/m+N/SelnMmIns9CCCHjMysqXFFpqoYxl7nV3LQkv I1/3z8DWt6oUZ2t0HRzLVvLSx4BcwllkXT0HyyTE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.162]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MXp9i-1oBKRh0p6y-00Y7wW; Tue, 21 Jun 2022 15:25:37 +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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v6 3/9] tpm, tpm_tis: Disable interrupts if tpm_tis_probe_irq() failed Date: Tue, 21 Jun 2022 15:24:41 +0200 Message-Id: <20220621132447.16281-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621132447.16281-1-LinoSanfilippo@gmx.de> References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:9JtmR9KMEqWCGdhBCxpCM1SHKiKG1NG9K14z71jAmxvmXo5bQfg +tNzkMCHEl8sWEscHLU1ZFgKfu9EIrIpopTa1Tf29SK0KVSi1m4J+WVZ1+MOWQwlEyonhfu M1f0J9+HBuZDaBCBadHeFXh5pfZDT9zwTrI8akaplIBlF8btvbBbiYLEzO+8w2NiSIP4qjk opGtv1y09cwHytfpSsVZA== X-UI-Out-Filterresults: notjunk:1;V03:K0:QH/j+wn9piI=:V69SuUQHmNngJbKTt60HnZ yVkHYgg5fmaOaCILpalYehML/iHQooumiaBIn4dttRRqSg+9tZ9955FMX26Jf/S+Wk77PZCAq fi0L8LU3YeSIsqNBE2Dxq6kihAtJx+KUPVMihtF/bKlt+meY9DC8q1DeeqRS3spPuyQ+P2Ii0 cdNhPXNWcj8y87idsaWBTS80wKpRVOCW9dpSP3mGXfKODw27eUwslCNc9hg5j5RHG6qC8MjQs AkEx117fOHvQLS3Y5tRQN8NSDwsr+fG+dv464+MSoQisFLuiTVIIjFBaj38a8j8QaEcfaPPOx EN1n/9gr3uHiQNndosSw0KfQUDeUMMwuxd4n3x7jl/P1Y2a/78VnOpkz/loHcjrDFUiEH/mKU HuCLr7KIUuLI5yY1040orbBSqFzkSXloap1Nt4cHeSzVIcLnfemliOnzc6AnT6YwYTGmn+rPV GizeVzBFOYAHFKtW7Aw//R6j41NRUDLL3nrQcB1KBevqWJ5+Ookq8hOC4WXGxSdGm4e8SdODT OGrLAnFzQIEFxVUC8X5EffoPsMjs0UGdMMZD88wsMzcbcIclElcqekOUaC1P1OXM+dhYl8sBA chp0egkVnImTuTxdop9J8Sl3RQOR37qcYk2VL7WEiNe4aiG7sGJxB/D/ukd2loLVVtebgaNhc N1ZR478vdTnigULh4B9oEXISCZJ2f6sRrSTRBct8mPEQMqS0KOGpDXW3Py2ssJ11/d9zGlGkE ENCre6P1AxK/pIu6G94s2qs/wLOkiOI39aWtovRmKcZNSNXpI9Ea/JAbY7s/SSbkXMUdJwdSO 4tDt8eMgY9IGE27AftZu40VCmVS41J4RrfvDu5ncf2SIelKvciswNiw2mbVWuXpmt1aTe8jeK /8fcT9p0SOn6PxuMnJ/6levV4ztKgJ7X/ZPqTb3uBNljkngZXNRvtowUcd4tN4SS7oQnH8aur WbNsmwfx2jv42HX8EAvdBgxyDQxVqayyTGm4HRaWEvi+9IuBf6eYxIP3kFvt/IikLBg7Mk7PA GSakP8NWbihfB9e0xyNxf0UyMvTCkGi53aqYkmUAGrR9NYyNKn0VFhXw+zjzvcjCxFS17OPmy 0LIizjyBx3Qejgx5SHhehptSNmdp7mezbkGQatGFMqe8p/7weIYIsHuXQ== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Both functions tpm_tis_probe_irq_single() and tpm_tis_probe_irq() may setup the interrupts and then return with an error. This case is indicated by a missing TPM_CHIP_FLAG_IRQ flag in chip->flags. Currently the interrupt setup is only undone if tpm_tis_probe_irq_single() fails. Undo the setup also if tpm_tis_probe_irq() fails. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 0e68e4502a56..d32e93c86f48 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1077,21 +1077,21 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - if (irq) { + if (irq) tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED, irq); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - dev_err(&chip->dev, FW_BUG + else + tpm_tis_probe_irq(chip, intmask); + + if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - rc = request_locality(chip, 0); - if (rc < 0) - goto out_err; - disable_interrupts(chip); - release_locality(chip, 0); - } - } else { - tpm_tis_probe_irq(chip, intmask); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; + disable_interrupts(chip); + release_locality(chip, 0); } } From patchwork Tue Jun 21 13:24:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12889295 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 E5311CCA482 for ; Tue, 21 Jun 2022 13:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350448AbiFUNeQ (ORCPT ); Tue, 21 Jun 2022 09:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351464AbiFUNbC (ORCPT ); Tue, 21 Jun 2022 09:31:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97EC62AE10; Tue, 21 Jun 2022 06:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655817937; bh=nG5TFXtaC8PNjcCZBi+MuXoKdmTiTe8KMPDK4ENUAc4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=iMgMfSK2mXDNnkP+XMQ2NUuY3poFKmqCGW8Yr+3bBrD3YMRL+rFHKgtyfC/tgMdqa qp49iyRDMNH++hD3SuD+xDcPhwf2aYyZ8w7jv5nU01yoO6dw3/9u5shS0snhZrgUXR gNMFibTaRJ6pbwerhP+o39/Pot9npFmZwzg2+/lk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.162]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N1wlv-1nf0R62K6r-012DYz; Tue, 21 Jun 2022 15:25:37 +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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v6 4/9] tpm, tmp_tis: Claim locality before writing interrupt registers Date: Tue, 21 Jun 2022 15:24:42 +0200 Message-Id: <20220621132447.16281-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621132447.16281-1-LinoSanfilippo@gmx.de> References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:09LnH54cpStXE0uTVUiQV6pfDV4LO4SkQhy0j666VacW70TuVE9 KAkn8YYYXOBaH/wSS05mFd3JxVlYDVOc3xzYxnOq1SKi8zZjP4MOmsG1+s5WSbGRaiZpUA+ wygqgZcfcCIi0zuxxoPkGyIXFXQgdYUbhtL+UwyYk+WNblb/vNaumCEL/Zf4tYTmQAtzxRv cFZ3HVzWsRWgVe3hXaYLA== X-UI-Out-Filterresults: notjunk:1;V03:K0:rv21BbkZ3Vw=:bNA5aVx3G6I9cguEHz5qj9 vpYftr2YlA/UoZAFEP/wyvFTNLEiEHBDCkc9y/1tfKY/N3jdolOXf3hQU0A5FwzDje+u0JEMH 0kunrtDu5JyfHBYGZlPXxRa7V9AcUsXApvJHv9z15EmTsikJVOiP3hRSSwzTxyaUfvDOWFWRd xI9m9aA/ttP5ORA0rFod4qHCke9dOyUMH0oDJ1lcNV3/mTwXZXEdhtTOQXjXJOrzc9Oda/F2J GudKVN3JqCmuoNu8dL827jBbWtg/nRrcR0UFTbzF/g1Ff2i3ffjlJzPolqloLRXGEIrBN9gn+ aDwm+fvBK/m6zewIXTuae3svcSABJ1fOmHxhoJZAyPftfDsIRxEM5msbqDNJSAjyTUroaTtbH IRbRUIFcxfzU1Jl1pVFdYStwIdP0/lTaA7KttAn4BP+ganqVoTvrZJAhVfapbFTAKbLq6wwn6 iGV14dyKc4px3TvGArp4QvBCt/RZeXzB90C0OhnLcj8/pB4iweVMdBieQxeiQ8t0vogrvr1PW GJgQPcDnxP5QuG9wgQp5zINosKDp8VvkpsAs9E+VSeAWGjF9hc+77JtinC3Yc4YlIcJ9Fdc8+ 1n4mKq8guGbD6ewkIOsEb7+llGoIkNRRK3j5OL1kv/VN/DzhIlLThPdKalXb9hQ4WBZE7o+8q k7OtDacirkB/nt++15c38TAW36f5koMSOH1rsnw3LrBymLeVOG93SeFPVZvL062QM7cYqMmuA FUTqYVT+OB19s8pQzUh5Q2p38G63DEzAkFsJIoiCNQ724eR1VyNuUM55O0gBbsSGhxD3wgP7G dJgL3Cx3vFf/fIQOIVRKTFxOKPnYeW26i6wyNgKk/w3TqQ2EhsDumlmnlRbnetDQN2m7LLFi6 BHv7S+nBXCumONzPSYsJwWATD43xs3R78jdVqZoYqJTI3+hrGhyuWs2+P7iJeN0QkORe/Ohh6 w9CbpW0Tuzyv0IWxQmOPyXZFgX2ogPEBWIJ0yh6WhSsvQkpOokpJPIhQz5GORvxJnBuPZH8sI 3GcDhZg8vVf5WqozV1CdMevD6CD2woByZJnoyqijwIyHvRyTCAtWW/vPlCpYbjkTvzf0Qas9j FG8wVH2SYWlGhgGb2QQ1DpPHveQZFsQ/XBsM5HAOMccIf16JYR5pT0a+w== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo In tpm_tis_probe_single_irq() interrupt registers TPM_INT_VECTOR, TPM_INT_STATUS and TPM_INT_ENABLE are modified to setup the interrupts. Currently these modifications are done without holding a locality thus they have no effect. Fix this by claiming the (default) locality before the registers are written. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index d32e93c86f48..09d8f04cbc81 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -756,30 +756,45 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, } priv->irq = irq; + rc = request_locality(chip, 0); + if (rc < 0) + return rc; + rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } /* Turn on */ rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } + release_locality(chip, priv->locality); clear_bit(TPM_TIS_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to From patchwork Tue Jun 21 13:24:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12889300 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 E7037C43334 for ; Tue, 21 Jun 2022 13:34:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351462AbiFUNeY (ORCPT ); Tue, 21 Jun 2022 09:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351722AbiFUNbC (ORCPT ); Tue, 21 Jun 2022 09:31:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 678DD2AE19; Tue, 21 Jun 2022 06:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655817938; bh=ZtEf9z9KJysNGGV3ChvOjRTJrFhCrpznXAsR54JnfUE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=OzUTeAj6/Yec0YXXCrxnrihQym7oUcnXm/+bI/eRw6Y7kMIeJWjjXuioR9y/61yGE 6bKj/Sl6FFaOMHU+LKQjncFk/44e5UXXkGEyufJ1YA5KWbJzrWrIgb+QgIrePHoeuS 8JFGuMNWDyYfYxMg8je4Nk1HcIXE3ptOGzhbkOac= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.162]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MhD6W-1nQTJL3ozS-00ePJO; Tue, 21 Jun 2022 15:25:38 +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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v6 5/9] tpm, tpm_tis: Only handle supported interrupts Date: Tue, 21 Jun 2022 15:24:43 +0200 Message-Id: <20220621132447.16281-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621132447.16281-1-LinoSanfilippo@gmx.de> References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:PfAWhCJFoEHpwbXMfPUh7kYO31Tnx8Cf5/J7Gpg8nzHJD17NSJS A9z46GMWp0J+eAaQ/oOnB1XTWj3eoo1HiZXwmrgOdZ+505PBRKp+AMgA/oaBYWn2nUjZv2A AB0C8s+5xX4SeMrZYOmtI/x8+schZerxyGuUwVFnsY0amSIKqUHdtAbEix+OC7vuRt9i9Ym e4ik1o7L9itY5PHe34MEA== X-UI-Out-Filterresults: notjunk:1;V03:K0:G+++L7UgAio=:vHehAF1AaVLEPwfa7S05gL aoahPZHLW22hMlDcBURPbL6TFlOnrbymKuWLXxj8ThnBIDm9YVa4ETKQE+cjQJx1ud68nZMGI I4MzOS/E1yzDsrpsqb6KiN7ekXtR/cQm03ttdrtdim9JAMiBA8xv0LjYPxVifxzjMBNT9+kf0 tdHfgOrSaX5lCyYls2rMSY6ogsSECukhCUdXo+6p6sPu+QZzTTjT4mWNzwNrtIJym4MTUWLAS W5C5fHL9GZCQMkyBy4IpFBy6mWE1j6aPg7RjGFv2RBzA4FjmVnytvNy+5h7FCZUZdMukBCaUc YXZYa32BfeUm8jqPNTgLEuvSyJqchw0VLrskzo4EzXmzZ8i/rem/mchhaCq3KbJ33nmszhGO1 O2PZ4lqk2/dyDYd4hMOuw4/sb81PfTykqJ6/ZKbst/qtAPCtdRCTV7F6qwOtxc1vuwePPjnoZ ePhfxjJ/kAoUsp6Op8ZmjGIuxaj8C34ilmqLfzSt034JyWb2lXtNWxVJSSwB0Ws6MQZywsHeM pEqo0Dl6vf/ldYo440034wxkkxt2DS+bu17939iarzYvLV9UJRSqWcllFFMkd7CuxPJ13JBBi 7S2UVq+r4H/6O/+F6KS3eWNCTU+fu3zAIUr23PpEi5ubdgRhHuitebCEHyUhXJTa3NAUgF/cJ 6f6e+UKfgZQXkH6NoVHGNXBjwlPYe3RnHygTj5rffnWnBh8rqmpftzTAoUKMOa3jiN+Z6mjjs UY8QcTsZ0XKvhNiTCT+AXmy9FFR49gyZ0VsGV1V28E+7EN+QZjN9Wsr9g1oEbhtSnF7fq2PSp DnwfNjuID7eeI9Z6yK8rHs7KF0/rNyZBKKV08vqKBwFfiCMo+PNtFKwgYuEk4C8ivPTVKLrhY hJfBuKhQmGxVy0iLkDy2i6PyG6PvqKdiQU8AuZ/h/1e+QYX7qCxo9mcX4GgLJBLszII/0Fc1c 1g4oWySyfsdTxMe9vY6TZpVyaT/dSR/QKnl4Eh3p8bLPv83IlDXXImw5afZABDCFjdCCAxASQ oleW3CA5y3uUoJr/OFiMd4TsX92l43DZt9/UeDla2N/IMR/rRhhswrV0xk0DA6WXVxSralNFE ydZLGlB76O/gzc7i3kv/arWOa/xEF9smfsMDgvwJDsmHXHUWfKxhn4SdA== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo According to the TPM Interface Specification (TIS) support for "stsValid" and "commandReady" interrupts is only optional. This has to be taken into account when handling the interrupts in functions like wait_for_tpm_stat(). To determine the supported interrupts use the capability query. Also adjust wait_for_tpm_stat() to only wait for interrupt reported status changes. After that process all the remaining status changes by polling the status register. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 119 +++++++++++++++++++------------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 72 insertions(+), 48 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 09d8f04cbc81..cb469591373a 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -53,41 +53,63 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, long rc; u8 status; bool canceled = false; + u8 sts_mask = 0; + int ret = 0; /* check current status */ status = chip->ops->status(chip); if ((status & mask) == mask) return 0; - stop = jiffies + timeout; + /* check what status changes can be handled by irqs */ + if (priv->int_mask & TPM_INTF_STS_VALID_INT) + sts_mask |= TPM_STS_VALID; - if (chip->flags & TPM_CHIP_FLAG_IRQ) { + if (priv->int_mask & TPM_INTF_DATA_AVAIL_INT) + sts_mask |= TPM_STS_DATA_AVAIL; + + if (priv->int_mask & TPM_INTF_CMD_READY_INT) + sts_mask |= TPM_STS_COMMAND_READY; + + sts_mask &= mask; + + stop = jiffies + timeout; + /* process status changes with irq support */ + if (sts_mask) { + ret = -ETIME; again: timeout = stop - jiffies; if ((long)timeout <= 0) return -ETIME; rc = wait_event_interruptible_timeout(*queue, - wait_for_tpm_stat_cond(chip, mask, check_cancel, + wait_for_tpm_stat_cond(chip, sts_mask, check_cancel, &canceled), timeout); if (rc > 0) { if (canceled) return -ECANCELED; - return 0; + ret = 0; } if (rc == -ERESTARTSYS && freezing(current)) { clear_thread_flag(TIF_SIGPENDING); goto again; } - } else { - do { - usleep_range(priv->timeout_min, - priv->timeout_max); - status = chip->ops->status(chip); - if ((status & mask) == mask) - return 0; - } while (time_before(jiffies, stop)); } + + if (ret) + return ret; + + mask &= ~sts_mask; + if (!mask) /* all done */ + return 0; + /* process status changes without irq support */ + do { + status = chip->ops->status(chip); + if ((status & mask) == mask) + return 0; + usleep_range(priv->timeout_min, + priv->timeout_max); + } while (time_before(jiffies, stop)); return -ETIME; } @@ -1007,8 +1029,39 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, 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; + /* 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) { + intmask |= 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) + intmask |= TPM_INTF_LOCALITY_CHANGE_INT; + dev_dbg(dev, "\tLocality Change Int Support\n"); + if (intfcaps & TPM_INTF_STS_VALID_INT) { + intmask |= TPM_INTF_STS_VALID_INT; + dev_dbg(dev, "\tSts Valid Int Support\n"); + } + if (intfcaps & TPM_INTF_DATA_AVAIL_INT) { + intmask |= TPM_INTF_DATA_AVAIL_INT; + dev_dbg(dev, "\tData Avail Int Support\n"); + } + intmask &= ~TPM_GLOBAL_INT_ENABLE; rc = request_locality(chip, 0); @@ -1042,32 +1095,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); @@ -1098,7 +1125,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, else tpm_tis_probe_irq(chip, intmask); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + if (chip->flags & TPM_CHIP_FLAG_IRQ) { + priv->int_mask = intmask; + } else { dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); @@ -1145,13 +1174,7 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip) if (rc < 0) goto out; - rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); - 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->int_mask | 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 bf07379dea42..e005eb99480e 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -93,6 +93,7 @@ struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; + unsigned int int_mask; unsigned long flags; void __iomem *ilb_base_addr; u16 clkrun_enabled; From patchwork Tue Jun 21 13:24:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12889297 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 E23D6CCA473 for ; Tue, 21 Jun 2022 13:34:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351315AbiFUNeR (ORCPT ); Tue, 21 Jun 2022 09:34:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351479AbiFUNbC (ORCPT ); Tue, 21 Jun 2022 09:31:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 695B82AE1A; Tue, 21 Jun 2022 06:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655817938; bh=UqrXeJeyucbWKhNmptMWsyd6uHrhoNhsf8+CRRXH2jk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Rp4vy+NYBHbZuabQdJKfPHAGgjpz3NRRkDylO+Gj6wfCOSVmWwhYjOao90t8zXY6f 5nYAbnpViF4V/7knSmVQjgEZfpgmPSa3KzyQF0yekdQpQJBbdE5KgVEcbpg/tIlxDo XHT+l6C+pUasnhksqIYYwennOqFsts2/OoFKrJ2I= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.162]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N4QwW-1neiO41Mpy-011ODK; Tue, 21 Jun 2022 15:25:38 +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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v6 6/9] tmp, tmp_tis: Implement usage counter for locality Date: Tue, 21 Jun 2022 15:24:44 +0200 Message-Id: <20220621132447.16281-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621132447.16281-1-LinoSanfilippo@gmx.de> References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:EucHbQAyhaDO2OFslHJYpn5K9j86a67vVh2xprBNsZmGLRt+qR5 0UxqXz0bYGV4O480o0mLSwNE72TQrseinaQpAx/pwXllfuNAeFINyfiN4Ui68SbdUsxwD3U viSxqvtqkfrPQ4+SySz7GGK0L+Xq00z+u7otqCBfF1aO+/5WAh0rxKJiRUPOPpyFldRYP78 cM37USIIz6vhlAn6iGhFw== X-UI-Out-Filterresults: notjunk:1;V03:K0:PWSlkNlO4ss=:e+Lgkg5lFOex/P3Qw8nor9 zh66PyWzE+FD7xaHCV3X+4wQBdE9GOFX0jLX5qRhClRjCCb92PHZMlPDIFQQY0IXWJd6NbBW+ UUrl5tYuB4DIVljfKajGzWOO/LKCL7MotnoUAaURJO24lgItAQtrAKj2i4V8+eb9WokN1O/tm ezcv2275Zq03lDy+K8NBgEwvSLx9Cgnszxn53oXcSEKC45f2pUDlUzjMzFRvjnatZbjv9fmfg iScRC5Ra6AS2wUZAt8uYc5M1ip7/dw3wgV49lSW2b9Tk9zXuEBdABE0vkXQd3uMvo2TK5bG97 yunn6O98EZp+AXMCtKqqWjylo/LVb5j55E5AaHUGT78jT3LULoPqbEyE1dC8ABJ4gePrAlVu0 sTuKIEhqhK96bbHXx+/ws/m8gwD4bfkk43U0eiTujXW0wHnwwOEgx6dPZVk/BniC8b6KAW29O Io39An7IRoZ5Iaore1PreIhMiavIBLFHSIYMUKd5c4b0dNRLDrpS/1TBzgGB8rKYcTNemxYAX 9It7UIjkNqXcFkIKVFppZQjUHnQOEpU/pNks0io3D0KX4K+DALyuGn4FRdphQM0dTcUJABTLe PKYzGBMKCTVzzAYe+iTPPiVmJ0l8bhGFK5B4vP0bOEzTw5BslgBYZYvENDA/e6hQ625V1Bn97 oyj06y32u9RuyB52IrUBac9t3b0sKyEPabzPVGvKNr/X4mzF7pHIJq8A7NUO40Hl+N8OcbbFF Nv/Ty5xuBRMG+s67Qul9CIdVHN7DoSVHp/otRXe7TROPmdSeebtp4EwVRJawiJ9CiU7cCkYIf QGo7ES+cO1M63Oj9/dG8l6n80amLKvqaEBlFdWqEZK70pcYj7amGI5H5eZ2c+J3pQxBuK33rx cQAa3CtSVsu92ZRXlMxRdjkVUN2eTvOfxY5UHX0AJIGcLdfnzxIgtlPzwtdf6gGL29hDzV1oY RT82qdG1Y8fjswHBe89A7eI9cja3y3Oa2euOf8ORsyi2lNUY+/Z0St2cIkq/JvMwP8VdtTpyD IEacZ2uW4D4sazICAi83RFWlS/rsUH9C3FQ7u20tA0xe6yxFd1rut5rbfaobq1buEr8Jsj0s9 NXpgFcnc8VO1KlnIeztQURhuIClownuAc8QGx0fEF2lt/TtOUSrcOBedA== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Implement a usage counter for the (default) locality used by the TPM TIS driver: Request the locality from the TPM if it has not been claimed yet, otherwise only increment the counter. Also release the locality if the counter is 0 otherwise only decrement the counter. Ensure thread-safety by protecting the counter with a mutex. This allows to request and release the locality from a thread and the interrupt handler at the same time without the danger to interfere with each other. By doing this refactor the names of the amended functions to use the proper prefix. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 75 ++++++++++++++++++++++----------- drivers/char/tpm/tpm_tis_core.h | 2 + 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index cb469591373a..639838c5cfe3 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -158,16 +158,27 @@ static bool check_locality(struct tpm_chip *chip, int l) return false; } -static int release_locality(struct tpm_chip *chip, int l) +static int tpm_tis_release_locality_locked(struct tpm_tis_data *priv, int l) +{ + tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + + return 0; +} + +static int tpm_tis_release_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + mutex_lock(&priv->locality_count_mutex); + priv->locality_count--; + if (priv->locality_count == 0) + tpm_tis_release_locality_locked(priv, l); + mutex_unlock(&priv->locality_count_mutex); return 0; } -static int request_locality(struct tpm_chip *chip, int l) +static int tpm_tis_request_locality_locked(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); unsigned long stop, timeout; @@ -208,6 +219,20 @@ static int request_locality(struct tpm_chip *chip, int l) return -1; } +static int tpm_tis_request_locality(struct tpm_chip *chip, int l) +{ + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); + int ret = 0; + + mutex_lock(&priv->locality_count_mutex); + if (priv->locality_count == 0) + ret = tpm_tis_request_locality_locked(chip, l); + if (!ret) + priv->locality_count++; + mutex_unlock(&priv->locality_count_mutex); + return ret; +} + static u8 tpm_tis_status(struct tpm_chip *chip) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); @@ -661,7 +686,7 @@ static int probe_itpm(struct tpm_chip *chip) if (vendor != TPM_VID_INTEL) return 0; - if (request_locality(chip, 0) != 0) + if (tpm_tis_request_locality(chip, 0) != 0) return -EBUSY; rc = tpm_tis_send_data(chip, cmd_getticks, len); @@ -682,7 +707,7 @@ static int probe_itpm(struct tpm_chip *chip) out: tpm_tis_ready(chip); - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } @@ -744,7 +769,7 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) cap_t cap; int ret; - ret = request_locality(chip, 0); + ret = tpm_tis_request_locality(chip, 0); if (ret < 0) return ret; @@ -753,7 +778,7 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) else ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); - release_locality(chip, 0); + tpm_tis_release_locality(chip, 0); return ret; } @@ -778,33 +803,33 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, } priv->irq = irq; - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) return rc; rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } @@ -812,11 +837,11 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); clear_bit(TPM_TIS_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to @@ -952,8 +977,8 @@ 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, + .request_locality = tpm_tis_request_locality, + .relinquish_locality = tpm_tis_release_locality, .clk_enable = tpm_tis_clkrun_enable, }; @@ -987,6 +1012,8 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, priv->timeout_min = TPM_TIMEOUT_USECS_MIN; priv->timeout_max = TPM_TIMEOUT_USECS_MAX; priv->phy_ops = phy_ops; + priv->locality_count = 0; + mutex_init(&priv->locality_count_mutex); dev_set_drvdata(&chip->dev, priv); @@ -1064,14 +1091,14 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, intmask &= ~TPM_GLOBAL_INT_ENABLE; - rc = request_locality(chip, 0); + rc = tpm_tis_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); + tpm_tis_release_locality(chip, 0); rc = tpm_chip_start(chip); if (rc) @@ -1105,13 +1132,13 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, * proper timeouts for the driver. */ - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) goto out_err; rc = tpm_get_timeouts(chip); - release_locality(chip, 0); + tpm_tis_release_locality(chip, 0); if (rc) { dev_err(dev, "Could not get TPM timeouts and durations\n"); @@ -1131,11 +1158,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) goto out_err; disable_interrupts(chip); - release_locality(chip, 0); + tpm_tis_release_locality(chip, 0); } } @@ -1202,13 +1229,13 @@ int tpm_tis_resume(struct device *dev) * an error code but for unknown reason it isn't handled. */ if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { - ret = request_locality(chip, 0); + ret = tpm_tis_request_locality(chip, 0); if (ret < 0) return ret; tpm1_do_selftest(chip); - release_locality(chip, 0); + tpm_tis_release_locality(chip, 0); } return 0; diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index e005eb99480e..7c6c14707e31 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -91,6 +91,8 @@ enum tpm_tis_flags { struct tpm_tis_data { u16 manufacturer_id; + struct mutex locality_count_mutex; + unsigned int locality_count; int locality; int irq; unsigned int int_mask; From patchwork Tue Jun 21 13:24:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12889299 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 980B4CCA483 for ; Tue, 21 Jun 2022 13:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351435AbiFUNeU (ORCPT ); Tue, 21 Jun 2022 09:34:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351724AbiFUNbC (ORCPT ); Tue, 21 Jun 2022 09:31:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8D5E2AE21; Tue, 21 Jun 2022 06:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655817939; bh=DoyUOUgtLRmwTXrdCxwv4uyz3gneFIuw1ykEwqWoKmk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=fKg0FPNJ+QhuxDvoyU3GWxbPagIh+fqfozdg45qiBM1ujcKUBvGVyX8zWJyky5j2b eLXYb88XLPKAlX26vudyjkr9ZtuK6ThqhaUgdAI6gNx4qJH6tQnkQTa7io1Aiuy5lc RntGorcb7dvVPmijjti9Od+JGUUqc17ecrvuYMEk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.162]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MPXhA-1oHKym33tC-00MbLS; Tue, 21 Jun 2022 15:25:38 +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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v6 7/9] tpm, tpm_tis: Request threaded interrupt handler Date: Tue, 21 Jun 2022 15:24:45 +0200 Message-Id: <20220621132447.16281-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621132447.16281-1-LinoSanfilippo@gmx.de> References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:LSFolzDTqrxzG241zWlFs0bZTJW6YP2K+0p264Voigwvs6X3g10 q0izPBl+f62rpvBvWkR85sAtIJ6jkhKx7SuTO2J2V8OQwTM+jasC/tNC8/o6GkrX6QOqBG4 8KdTq/5fg9muaZU5cdFH1Ipjp15NUfsxdHPzlaaFvS8d+mYsyGbW5bG5UpiJtVKMqfMuVDD yiUGKm8fWBqgmSKdHEeAQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:uDSmFMLF+R8=:yWUtSU9WlaxR4aBz2TGW40 vCM7msOYbff7lyc3E+x8BaFtCWUMMtcFt1o6/7SdNatkZlNQVSplvhRFRiQ+gY6M8BAQUNj0C zIpQr8MxD3K+htr1ZWs2CEDjca79TQ8+VcBUnWTPojJzTcc8LZqZzNxe/yjx5MlSfEC3bgQKJ r1f5QmPdxGk8/W4aWBTbpYfS75BpETH+nr2jA2MmXvwfMcz9E6xY/JPdfDOI8BEcb+SfS0/ug jX6NAXq0AdF/2TOR7yvmuJvlyzFubII6OS1pI8EWuRCNBMlJZcipyLrWaewwmFWuCbpbctQXF mAHl4FVFz4TmfsLJiAMMXcz1ZLlQsRwM21IbfoMipWiGq6a70OefkUiRORGiOcJfzLsPq839B 8gatpyy2SNYSkPhJapkmxvNwhBljEaJtA9gQJOnas8NCqrgI2yrNy0Ov5kIeuk0hJeSa8QqbL k6W/YYvKIgVkhMIQ4jUuysvxKIYnWhvAgPUtIGwMAs9FqypVmPXAlHMHG/JGV3oTeZK84F3NH 5YQBsapUrieHBXQhYWDCUjfNPl96d0rMOAkzUCUFYN1pH0uSTVgPaiy7YO0pOVja95jniX/Kj 4HplBtRZzsnD0FBPAG4zzcuQUN63UWnSkfFp8lt3O0FzVo/AX2sQW6S1Gj0/0S/z8NrA972Rd SFmJazzzMELlBEWlqPzu7UHjgTvrY2XqgYLwynxjp3uEN9crkWKAsPp2JVGkngyzN98V5J2p9 FdrJqrwKsNxNcynJ1mVNNZ4CQfb/DoaYMOQhhylSDEg5O8tSQ6kNxHcYZh4Mxg5KJXb73U2RN HqD0Sq9SGIGf3/lwQ+/E46C4kmX6A6gSdwuSCdq6RzGKMRcUiUxJgScZtw3pfDCmlpYpA5lrV PXs8Ag5MtMG2w4t6p5OrE1rvNq6Jp60ZwJk9bj2QUuqhcW1s4n/m+AL2L26lBjQPwDh6BvJHx FY8gGbDDuUjU4hHtaVrbeX7FZHi27V0dabJEcd24VEeaC22j9N8RPGUwP253KsbjO8idYih5L uQjmHidrbcqxvctrLhcw5YOeFWYY1ncyYNR9bqmBSH6QFh2H5MPwpKHVievc5t15RCzsUSSja PpitHFfj4r87z3SlZOleds5CFCMMwW8qG1jjdOtPko2+Z6+Ajx5fkKLsQ== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo The TIS interrupt handler at least has to read and write the interrupt status register. In case of SPI both operations result in a call to tpm_tis_spi_transfer() which uses the bus_lock_mutex of the spi device and thus must only be called from a sleepable context. To ensure this request a threaded interrupt handler. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 639838c5cfe3..08a4e82f76a1 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -795,8 +795,11 @@ 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) { + + rc = devm_request_threaded_irq(chip->dev.parent, irq, NULL, + tis_int_handler, IRQF_ONESHOT | flags, + dev_name(&chip->dev), chip); + if (rc) { dev_info(&chip->dev, "Unable to request irq: %d for probe\n", irq); return -1; From patchwork Tue Jun 21 13:24:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12889294 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 CD247CCA473 for ; Tue, 21 Jun 2022 13:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233467AbiFUNeP (ORCPT ); Tue, 21 Jun 2022 09:34:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351572AbiFUNbC (ORCPT ); Tue, 21 Jun 2022 09:31:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 027232AE1C; Tue, 21 Jun 2022 06:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655817939; bh=PvrmjIK2R/7Rg/z0B3aBuH8hQ6T9UKVZJaouKiyYQK8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=NnKKA+LEU1zCj5JU+mRqz3ZY8Hhqonh7iIRlBUBCULX4iO9Jb6ZIu0ufaVhKI1tYH 9J/TarKVbBRl1VsWAlc7Vc9SgcPMz+CasPefn0iCizxrtQIJgKQmAovijfYaJuzuzc 31JMZ9d/26zMosdS3E16Li3KqzMgz18CP1rrefA8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.162]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MFKGZ-1nsQgM0fVJ-00FlkL; Tue, 21 Jun 2022 15:25:39 +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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v6 8/9] tpm, tpm_tis: Claim locality in interrupt handler Date: Tue, 21 Jun 2022 15:24:46 +0200 Message-Id: <20220621132447.16281-9-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621132447.16281-1-LinoSanfilippo@gmx.de> References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:s+KoSs8FVvUDA9xLoRylghz+uOTWZYvnvvybtoZ3KI/xve0hM/w YBWOvQtpSvAmvbRvUq8IfNzzatmUXnXbHVnltc5LVVuYgAzHPrt6iT/PoGe3yqSBZUeblbC 21be5cSDTWbyE3Pt7yq/ihDDn2+3JbdAYxdhqxfcPpLqxKHoGG6GstH86LEpvfrCEitycOS 78dsiRQQwx7qpAfQEbI/g== X-UI-Out-Filterresults: notjunk:1;V03:K0:otVE8FV/LOI=:Y1mcxcjPPQSjIuHh4JPiKH 0iV7Z6R2dpCqDBNkLhCMkWOUFp7Fy00nNy3fDTY6YFop1KQF/xEZYt8CF1C1fNs+slsXXXduc NGbbiWIoB8oAPUeSo+/IiKqiqWeZ054rRAzz2fYS5jnkeoTToBsN2VF2TWL5Y+y0vaHWK0sGi qTWTSD/X8G72M01GxJWQqnUi0+GkB+FErHqFsmNoiz3EVY12Re4rjt0onALEWdqV7+AtmIM96 BnNLwWOTWPbgnilHyqYHsVJh/eLCO0kjKk6Yz9H6A5Rj++2xYrzLllgFkvO60R2BAX+7um7ZK xpwPXygpA6oCcxcCWT5wRwDivTnJ9/SYJQYM7UFc6EiuDLe8NYHbOgwM9fxcUGcm0rjBDBM1N Ec4uBiSjELM5q8WNcs2aCiMhlgZv0t9/0KWqnipmwNjRQC9zv97ZxCL7h1Iaqi2InMV5dkgWR rnE5NzAXPWSYKvqkCpjo65PgXRSR/LQJ3KEzy3keOnj5ChPWD8om0LRqHAdRC0yatq7nD2zb3 e9N42bvGzlfjYf0lPlQYuQqjx7irFtWQO9kHm8C60StRD9kGLF2qFBKyWEdQgq6bCbYxuOAim 4HZQ0lWhV/W+MUNBAPAs6k1Q0UWVhgNdkvHWxP2OjxF1zC2jt+xza6dA9CiJaMRt+iOkIGcra dJzQE2ExJIsB01WaBNH4qocjGTuX2k7ZAWJ3x0hU6QtUN/OPGLxPSVtKPLhDhNSVQs/ri61UA h52bSJv61BRJdaBArlMpnj2uv4RLdXzoPqYkdsZPu9W8As/LbA7c3s65aoPRkclr+um8MIdvZ VXrjwo9RkvP4kkgvcVrONzjcvoCOzarTekfe7R2mSXivCcYETGHisGhjBTlAtvEzd7kpKteQc 7Xk8SI2hB9b3yWK0hWzJKLM/pBf9ldQ+iecPMrKKjjh3c7N/Tj2AjJxRH5Db1aOXFjhBB0ker hrmwxv8igmmniLKpnCAyRmm7/srynmmHGpJ5nItdw24AOxzYpKhWuab21THkGS2L1VQjEcr8j o+MWqeR50TPhzKmh/JZmPlfgch/YMeKE/leGEyG5xMyLIH78uUAsTp0r9DL2MmxWMuXYb7X1L klHzRi1cyhr4ut2KEwfH9C1eCZfU8x8oFZLgjE9CP6CVeZkqFBSfzOO3Q== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Writing the TPM_INT_STATUS register in the interrupt handler to clear the interrupts only has effect if a locality is held. Since this is not guaranteed at the time the interrupt is fired, claim the locality explicitly in the handler. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 08a4e82f76a1..1f7663ac1fc4 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -754,7 +754,9 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) wake_up_interruptible(&priv->int_queue); /* Clear interrupts handled with TPM_EOI */ + tpm_tis_request_locality(chip, 0); rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), interrupt); + tpm_tis_release_locality(chip, 0); if (rc < 0) return IRQ_NONE; From patchwork Tue Jun 21 13:24:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12889298 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 B122DCCA485 for ; Tue, 21 Jun 2022 13:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351445AbiFUNeW (ORCPT ); Tue, 21 Jun 2022 09:34:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351573AbiFUNbC (ORCPT ); Tue, 21 Jun 2022 09:31:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B70A72AE1E; Tue, 21 Jun 2022 06:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655817939; bh=6NOAMXdCUByyszfLupmrTS363FnVyz0cu7VA/+0ZRpg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=We4utsoGckPb7P63tspOFDUOD+/zLTgLvZg9QhtYw8+7TshQCwQZo2L6w+91ky5eV daVcP4lSCdWcRjfOvC98uMchCvp76tnTwziO81Jy3ll5jp7HCWwQyRtXijWvIWB965 d1PuJBwxEIt5633EvI1kAa4wJHR9EHSrFMZGKIAM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.162]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mof5H-1nJ5re2E2L-00p6Z3; Tue, 21 Jun 2022 15:25:39 +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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v6 9/9] tpm, tpm_tis: Enable interrupt test Date: Tue, 21 Jun 2022 15:24:47 +0200 Message-Id: <20220621132447.16281-10-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621132447.16281-1-LinoSanfilippo@gmx.de> References: <20220621132447.16281-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xSB16AR/mNo0Fvb7nCgg54P4T5PTXXJ6u1/cxTo833nbHj1CGwF 85DnFGzQJq2atuTTl2iqce6c8e1HOqzMIO+EymhOc6g/r0MKH7EArUfMfOmJfM8o1mFCEMr VqNOdl9gVUQienIscPHd1P3lYV3ePa/vcMNOROFa5cSEy4WzXYNfYounXqhnixli/nTi9W+ ohvFU5CmjZNRWRQ19eI1g== X-UI-Out-Filterresults: notjunk:1;V03:K0:OkfFheutD+Q=:vbgJUfdRzcOzV95IvgvhwB CF4BNMQGYWVsXIVn55d38NNBBB0qUsZyHgcwI0xX3rWg2miFY85FLWyASWx3oCJpRt6eHQQNS 7FGs+iNFn3/E71ES5tG5PZJU/VglbLq2edlmrpJrCU8mK3Hf4PIx+JwVnnT9eP62OxM99Kvw1 RbasWoVbSUlJMzUqqaC5Hnitm3WUSj0dyAgqQGQCO9NtdsGv1loHJrKDOf3UN8ZqxQwtCEXZ6 O48lBFi9ZtmTzGKG7sy4ozLC88y1YuVcIV3FfrkmQFYuzaTSgTYb6+jrei7vzef73h7sVJF/E UBavHCh01ORKG4CBreAhvvtGktQPo1Iy67F1ov2ckJAG21RX5EMrZshM8rEwLF9If4+p5VMZA TULeP2oXiuo168M3adh1wpcsUf/zrQZqCYFM38/W18Ey9wRTwJYvCgYvz3ZY/nRZhCua6XnGL RpgDVZQr4eh1b++OZAKR3DNnx5EjiOXZ0345rUC15V4kvddpnDPMELp110714ZAUAZAhJKOk3 mOLCugXLGiFpAP4mJv4dNFPhMABxdEgqmemS6XVM6Lw/b+b0L4bEYuVFUd7QDDHTZwMSp1+QJ /TNpy06CpQC+syTZCQebOlDiwqQ8jnGiCWXGkCDuoU1T/PnsyqUTPd0EXgSk92D5pID2dNnw5 4jVceD2HNX5xvPr8fWL4zIs+3w7+Ra5PAwNtW4pKz+AAca9B3z/64T0I9nLvBJn+CyNiPHHK0 XVMa9TurgYuWMbhjuqq42lRdjS7ObkOQmhT/0uig+i1dRWc+EvBAD8F6f4zA9YDrf/WQBaWlC NdkW7FApsx0WJr6t5HJ6KBKGQsJBSB8kqIsvAfH8kYkCIOFoQ5YVwHOoMViuaIaNmTgK3xr1X SowelutJkRpKenaNvA83bmwGy5V7cdmvQV2dtturNeEo+nhDPlhieEVEne/fVPtXsp1Pa7cY+ JFKwA73133eJzO640cTlKiazx76MX5ZmSt3j0YA5aBCVua1pWntnfjkcAUSDUmWPN8EL1aeyH tiMAthMwfRHSxJsANB/xPaAJk8GY50/9lciqCWpwFo1slLTmUsR+92y+6D0ByClXRb1gzR2hS Khe0Lqg5apwUdTw3tAkoid/zZwVHqkz+0wUgOR3tNuVs2eU391nqQm3pQ== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo The test for interrupts in tpm_tis_send() is skipped if the flag TPM_CHIP_FLAG_IRQ is not set. Since the current code never sets the flag initially the test is never executed. Fix this by setting the flag in tpm_tis_gen_interrupt() right after interrupts have been enabled and before the test is executed. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 1f7663ac1fc4..650c202d2f50 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -775,11 +775,16 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) if (ret < 0) return ret; + chip->flags |= TPM_CHIP_FLAG_IRQ; + 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); + if (ret) + chip->flags &= ~TPM_CHIP_FLAG_IRQ; + tpm_tis_release_locality(chip, 0); return ret;