From patchwork Mon Oct 17 23:57:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009720 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 891EDC43219 for ; Mon, 17 Oct 2022 23:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230519AbiJQX6Q (ORCPT ); Mon, 17 Oct 2022 19:58:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230337AbiJQX6P (ORCPT ); Mon, 17 Oct 2022 19:58:15 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54ABE7E03A; Mon, 17 Oct 2022 16:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051070; bh=4XguBKph++G698gHdOWKE+P4P1KjkhqLb40WCE6oSOk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=VDlCJq/sLhkIqnFmAfwgqVdTszKEFM6wd8ROiHLc/tmEMWsfsR5i2aV1AWrVwrI9i T1EzBxnGJTXyvep0yx4y6P/+22fPgV0mOm5EQcHOLc8sRGzrCeOwlAzZhV59OtJKrC nSqkgWBw+Rgi4pS5CATft7rIMF8BgsG4lu+IVWyc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MkHMP-1pPv4p2iXB-00kc99; Tue, 18 Oct 2022 01:57:50 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 01/11] tpm, tpm_tis: Avoid cache incoherency in test for interrupts Date: Tue, 18 Oct 2022 01:57:22 +0200 Message-Id: <20221017235732.10145-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:XBj2+8GlMIfJHthnW+YlvZeBjO2uSz7mk6GpwHfOVZW/7hCgP3m M4uJIdXKuNOi7x0advx/i+ZGwojo5WJDEedSArJOkCCY46yqCeGDufbHbXk8+DWSJUy5gzv lg8+1G7Id0yfcUbInv8VBqvC0QlFfV8gH/3pIcejq+0XXJHivt8uE+dfi620uXTcPeWapOp /TQhHN9nTQsBA3kPFj68w== X-UI-Out-Filterresults: notjunk:1;V03:K0:Uk/nBJMNopc=:8m/oKWfmwfEf5R36N3NBdV aPAnuFL+Zfann0xG/kCsdxBFaTB0SkDFsOhq1oVsTwJSDdZM+9P2/i/H09rzb58Ikfw+zcnTS 35tAF6um+S5/AWPIhIYjGS8jbPdaBrr0sdyhhtlHKDev6ZNCKzUyYb2d5i0xAE6KdonM0v6vm lAk/vsrKYmYIWFgPLSqMuBv8NMluVz3tsxxW6LYA2eFkoo86RLQsdpHQgXwgGPHJlCDw4SV6o 5CBPX7GqOf/7D9DhtTmCXH0HIsmmanXi2zCeZHumUBTkSaQpcnUubdZ9JOL6bXh1X/U0v6fvu 69LGNvHmNuBm4Y1smUuoEl3je+ecCBU+oLpeoD6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74TH4E6FM3oeYG3dvnxMzQMCCJbEAx/A3tImOYmPaXW2WV7jMxdU8GhzIvL7TwP4jb/0 1sYe6Bz+zO6Odlp/IbQe9XoUH64ZgJFRBY9GAXEF+/STnB5AmOzMBt+SM87j/fGSNOPVb/qc6 UNJI7DyTiUYxWvuSCbs0EkDFoNbttCxC2a9+veGyjPYj4 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 Tested-by: Michael Niewöhner --- 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 757623bacfd5..c0008efb95dc 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -351,7 +351,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) { @@ -484,7 +484,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 */ @@ -494,11 +495,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; } @@ -641,7 +642,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); @@ -661,13 +662,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; } @@ -707,7 +708,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) @@ -793,7 +794,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 66a5a13cd1df..695a2516dce0 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 Mon Oct 17 23:57:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009722 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 3FE0AC43217 for ; Mon, 17 Oct 2022 23:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbiJQX6W (ORCPT ); Mon, 17 Oct 2022 19:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbiJQX6S (ORCPT ); Mon, 17 Oct 2022 19:58:18 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 807D07E320; Mon, 17 Oct 2022 16:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051071; bh=1jiHlANZ8thD5aPn63BXGYT+VamFBFNIAjBcdG+2s2o=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=WfOSUaFoPW6HJeqbKH+NcSgdPAX0B5ef9lmxQeZCm5eQ+sWUG/h3zZ4BlUZ0KeB3L kON0QSj2zBrS+jNnsuLuQTr0/3NG+Y9SSUVUyhz2PFmGzw8wORNnT+ynp+UsV9TMgx v2nDioMQ/Q1N8I2dE4d8JIS02DjoW/0SEI+NvxP0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MrhUK-1pVj2245BM-00newU; Tue, 18 Oct 2022 01:57:51 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 02/11] tpm, tpm_tis: Claim locality before writing TPM_INT_ENABLE register Date: Tue, 18 Oct 2022 01:57:23 +0200 Message-Id: <20221017235732.10145-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:whnPCRKszgC0VgfRk1iaMt3PYAXQaO9DbMnke0FD70ejHgdIZYz FW/+L6Nx4I6sLOM/msmQC4djx9ELQ+m18UrEng6kHRW7mw17Qaibyts6KutKT0BhfxYH+Uc L5af/A0V5731fnhpzS1NHJHtlCThZ0D6d1QcWUl/jRxL31Hms7DGOFldgxd+htzPZeTIrWM No9LCspdPnw2jXliLZInA== X-UI-Out-Filterresults: notjunk:1;V03:K0:rm9hQAolfWY=:AmHIBZamZBq/hhplD7Btke 2DoMix2mAEavR3w14Jtm9aNsIWhRJCpVK+hnveXnRd52Ixa2ZX10mv39/shArTBy9TQyJEUGz 7/gtHpfqmTV1pe94P9k/URq2ZWf+CxX4ZAZaiSuoZAGofLIMq5m1fJOUfQwMaWPlE3DCkYToI FL0CQ642K9h5mkfBlmy6GdyN1HIT09FkQy7GYx7RCMiVREx7KFRS6YWotUOfSRUkHDqgUUVr9 ZvwV5lmVZR2j2sqioiAeEoRv7y7f9p9BxjywIgWEz+itmc5Kek9QBC4fjhCzUGHxpLfnwvF0w AJq0TYSFpn/mewbi5M7W13RQK1UfHUQ7s3VqGqAdWOSji/I78jATelWLSHi0ajB1taW+QT5pN oyCSCLwL/9QMQHlxsJnJISC7208RqPqn3hBGHT5IOEPGeyi21aTaQecWfZlQDB1TmmQpPPt1j 1XK4HP+vVW2/d6FB/yxX/dmK9u4n9YneQic5RwwQYJ7HG9GT5VfrNT2NFfO2uqxCWeii1eLRM aWkdw1e5s+qf6Q66ZmyyBQ9eNuob/D7P7BKbBQTT+78Hi+b9wwUJQvKCZxKELKr7uSLt9jalk MI4njFeWEjZPgMF4p7PCZmY+hVnYq4zUMLK0XsCq2VhOQlhoh8o0bKeUkvaLB/As9Qp00UE8/ gR35AP+CuF3YopqVgmc1iSVb7IFQFfrJVeHfgCbUNJj/28YNsD6BZHxzuQWfsRTnnmMpe2Hwd wkQ4okUDfK5FCRbRj0Biq17luNv0D8UQA8OX3uhWdwzIxmKBVpl+hdSvMHQA2hYjXiAB1Yi8n WOhM2+eoz8VZX6wIaHQXGCYNs1sHk4FcQ9X6HvEaeSJaHQaTNjcxF8pMCWbHT20u10AmVU5LJ 12NQLB2jk09kkrjaDyINJuQP48OPgA7Jv7NL7YMls1kdut2rg5S/jPqaTpE5yhemfJIE6V2lc 5qKfzqBgFzvz4DxHapuEg0jIL0vGrBqqgO55LwYXo1P0bY7nWIjvxf0MLENepRDmmm3jZFPXN E0NqQpMyW+Va/88Esuq8ZjVG8lTkI0u84ZKZzpUagh5QbBG1bPBorO3H1071M01kBX6OUDok2 JWgQ/B0ZXg9VjR2ocLU66+3dYQbkIaQtFroJnXsVinCmQ7r638tUA/6DUf8PcAtLN1GeXfEYx ps7/ro2SXh68CZhuKGE0DGpH/DcdtaePKa8nRNeehVvfX8c+bCg6o8RlDtWY7/yAMPWomdCD5 H0DszsuFqkZrSz2SCc2KaUYPQTrkrtRz0tka6xLs3O5EhYZV40eM4ZlRLZDDG/eswGEfYyYsF mda2pkEOZ/biKe+aXd6mRKuYMB/CHNAXzYcK6f8A1eaR1ja6jWxu8VmYPHSRBWYZ61mG73H+S tFZrXPOZqN8/oHPtd0zjetF8buuUOnnsodwj9kvo5Lzl7/OQyEWqIo4skQfH1z0tNDDIt5bcj UAqK5lIa/lJKbkEzTzhqrVGcbx//5pLCK1DL8/ILORwOA6pny0LYtpOahjH/9QK4HWsEtc8SE iV29t0sjcJ0tpTnpsV55iAvdsNv/0ciNuyL3MUctNmor6 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 Tested-by: Michael Niewöhner --- 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 c0008efb95dc..d2c9c9d76893 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1098,7 +1098,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 Mon Oct 17 23:57:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009715 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 CADC1C4332F for ; Mon, 17 Oct 2022 23:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbiJQX6N (ORCPT ); Mon, 17 Oct 2022 19:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229828AbiJQX6M (ORCPT ); Mon, 17 Oct 2022 19:58:12 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B94F87E320; Mon, 17 Oct 2022 16:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051071; bh=vmr8i0HILdqGMwVhgOxfm//3j+C4M5iWtBnT+hrsrRw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=UGR6R5tth0NiE2sA+sAhH8DeYrTP+DQD34wTB2Wlw0RCmkXhFI6No+HlWROdxyAeP PEYttZNttt5RXA/1U8R/o99TEuYgGKoDjji0pZT2CdQDzKFTu/VR+0BksmmQtzCKOl ijJVnIpnkVNup3ylMPgX4aapOK4wrjV1iZ9YyZcQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mwfac-1p4jAL1OIc-00yD3U; Tue, 18 Oct 2022 01:57:51 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 03/11] tpm, tpm_tis: Disable interrupts if tpm_tis_probe_irq() failed Date: Tue, 18 Oct 2022 01:57:24 +0200 Message-Id: <20221017235732.10145-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:hwsqVwRGmzxbKnmZok/36mfl4BodcJBOVORnYPI4rKLdbIMNacV c0iREGdvWzG7xr0Rs07Wt5kCpgSm1hz0agH5T5HR2glpgCNTu5qJGmIalB2EJuBwb665zx9 GdENV1JJqCu8AVSKSz80BvpQ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oiWFuaXbTF oK424Mo21Z1Bj6vLUD2IP+rRZf7CtpWUM7HInGsXv9wlB2v14QJifKNPWbeBa+LOratVtBQBE /44+wpUGmGnqF1ryjNWKKa6Mzf9sYVrNA08uckZO7Bk6PcHIX4UgOarWUsQ0HIINgqoLUMSYD znNxcTzI6ma5S51w5TJNQCOlU/SPkdn/2r4fJuqWukdOv77gRPWNA14qjm6bvao0bNCq2Lbso 1mw38xRtG6puqwTzmI+LseVvPlw0hSdrx6NKN+cYWgBQv0FHPQfimUDL/sNLJaWNH1HSkNEoq it3YMPXgXKnetGD4DQEuYeX9Ndhepk6ssBIQSkIjoysdAYXavcJdPxFGIxKftwW5qG+gxWWXY 1Y2+RHUAd9VgSZNLploXaWMYPWrbaEASLU1UnT147svmsirifjx0TxiouQuqskzROt+r4hJjh +aIR0xtkhmhjlVYfCAv60IkDYHYOyt9H3zmMAc4RNsqamNeXVyxJgS22cFqlHzBp5/bbKlKBw maOiSmc5D+TQit/tBaPkjj5r8TH+OgbTLrTMW1N6fAq2Alt6jyfEhq3HBliJHChs9lcwYWu4M ntXcDj552AgAwEiWwgLE88aUeTllycuX5qlAYqk1UBL4t 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 Tested-by: Michael Niewöhner --- 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 d2c9c9d76893..603b82ca56da 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1091,21 +1091,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 Mon Oct 17 23:57:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009718 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 0F104C43217 for ; Mon, 17 Oct 2022 23:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbiJQX6P (ORCPT ); Mon, 17 Oct 2022 19:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbiJQX6N (ORCPT ); Mon, 17 Oct 2022 19:58:13 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A7C27E03A; Mon, 17 Oct 2022 16:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051071; bh=A5gzN4mXM9p6SpYjvt1lyWJmsiJr8fpb+zizXUo+H9o=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=OfZrc2OxiuEIW1kDYkBDMHzkpB3HTAQ+mPmYb2XP4xPLjOwrYP/A2hkKsHC0fgqZV Hp4LzQ8YZnADNg+p2hF1R52tC1+h5KuhN3uwdu89G+IeUcXv4bEzdFVJjTe7EUxOiz 1JllyscdKZTXFzqezk8a/SVTJFYjjwkD3qMMJsW4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N5G9t-1p9MfC2mTl-011Bad; Tue, 18 Oct 2022 01:57:51 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 04/11] tpm, tmp_tis: Claim locality before writing interrupt registers Date: Tue, 18 Oct 2022 01:57:25 +0200 Message-Id: <20221017235732.10145-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:RLlc1AfZ1NIbHfi1JEu1isUf4ptuCNEd04D0B5dUC/z/3eXyz30 Or/zGIJ+DYVhZskfDa6VWbUU5MpzAZaFb9iBen8AqKsqP7KO91laDvNHg09GuJWmj0ioK1/ fgHEflm+WOIPDsSXcEkOBcferdR23EL6tq0I6HMxniGTy5q+Dbpr1aEtUfuIZDphpnc+GhH VYnitsF3de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rWk80iS+W9b+ZoUr4eC5EHhvwt+zXX40 MFswVuQ+afn0zDGqXCaO1K4Mo8lyecBALoMZvjhcM/+gKGD0+h3OpbwmI7CPpXM8GRAmvyloE zckWHc1h5WN3QklIYJStk6bTC4Q4Lky4w0mnaiplgtEqBIRldIDmJS95Hy0/3mOnw+GSgxE0M 2Ml4QLdIQE26348axkS3cI5zPX/VfNKTyeRPIYC9jS/rCuu3pGVn2AVE6YTLxRpxBqE8ROTes fx4g5IyRmRObvKsaXUy8tG/6L6C96bdSdyc053p0b+BIzQA6S1ZtsdwsPuJ/GYROABzwkeNDh zuLgEE/exOebOGR3FOO7xt9Cp4/B7NrzHPLVfBbZjJiMY9nku11o2jHnCGMjP4lS8alMq69H2 JGrosVQbgUzXTSdnD+u+atXRRzVigXuuIErIpPI3RhDq88ZdrYAPzf+7ZGqVt1TzVX1o0s241 3ePsTQGtcjYJJqoPDspmG7x2BmBEfN4Zv3hbJVlcTwxiiwco/lzMwz0kTmvaC2EJfSvpDhU/b sMJJuUl1pW04lkSs5I/EGGWCnX/ZRiAQb/LXr4aMbk09Z 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 Tested-by: Michael Niewöhner --- 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 603b82ca56da..52205a1fee9e 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -770,30 +770,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 Mon Oct 17 23:57:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009719 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 66401C4167B for ; Mon, 17 Oct 2022 23:58:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230390AbiJQX6Q (ORCPT ); Mon, 17 Oct 2022 19:58:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230254AbiJQX6O (ORCPT ); Mon, 17 Oct 2022 19:58:14 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7617E320; Mon, 17 Oct 2022 16:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051072; bh=aGoHsAcDuhhqSpkLQAxXzsC5Nh/HzN5f5Q02AEnI5+I=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=CQnw5FNrGJNnfwbeZ1tCNB1MFkNeGujM/NnltvNvJFZ+3HE68JAsYfdnHlrbJFaYt ITQouyu0X5vBCOMrTTjL7yYz1FAT4lQk5gn4PxAS9CK21sZkSiYqyReuI7WPue98TO jUBoYujT8tC6ibZMa0tpPKVZNq07e+oJd9XPXQ0U= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MF3HU-1ovYKl4Awa-00FQ7i; Tue, 18 Oct 2022 01:57:52 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 05/11] tpm, tpm_tis: Only handle supported interrupts Date: Tue, 18 Oct 2022 01:57:26 +0200 Message-Id: <20221017235732.10145-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:nUbU4NRPZD5rhgOWoMvN+mlSIdLkSir1mw9uGxYDN1Ie3MUq4bE b9JdPFI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xtMs++MrA7m3VMpvYw5LBSHtGXD8p9GrUVtQeiL1BjC89fl Xxh6Jv/uSvKO5l16apTiFiFtunEiTUkSaA9Wm2bKoapMap0eTmLhOgRTEVsBY9VVET1FdTzbW 6GtpQKb8qR0sQfY5YTLd/zqLyvemAQzJk15uk2uG01wurqaglLqAGb//PImT+QU51nC/5T712 rBLxu4AyVT2zv/xTfdpGdJ/CkJNmEU7w8HFm/bvHkBxR4nAJ7IzKmGD6o0BuZWC34N48Tf9R6 0qKgrt/S6zCe6ZLD/D/xPPJqE7cgjbPLJetfqRFo4ArArBR9ySypL9ynkn3GAjrMMCiu6Fa/q kHYSxFYAvmh6MCz2tQw5MLGzgJwkemjaOwlXydgARqbILtPqgxOuSgMbWUIKcwW0BFcMhKBRg Y9Sj44bR0I6f0j8Q5vqn4drbGHdPK2xFvI+X51IRx7vY3M0a3ORjAdz3pU4y9wS2/lpl0eVjA 4Nt47s23yteUS3FEqS7lBCq77oREHTCwPEMWUu0Ip/p3ZezxcjJar6Uq/lCqLRbFbVwQSywT6 MnaPmeYx9J1sA6Ts6vlGq3LREvxC9vmOdCSt4qqlKfs0xlIQD1SqP0LL5Z0UkYuPjMNDANweK +zVSnSyhh4VFvm8pcIcCN/m22FyUCWZ2Z22GZ5roGPe8CefVRtz0TvU8nurFEv2YHVY0lIKVl Tn1avMzuHtlCtOmzugKA4KFxlsa4XZrDPpOAAPchMjtwP 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 Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 120 +++++++++++++++++++------------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 73 insertions(+), 48 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 52205a1fee9e..d07debc3182c 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; } @@ -1021,8 +1043,40 @@ 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); @@ -1056,32 +1110,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); @@ -1112,7 +1140,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"); @@ -1159,13 +1189,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 695a2516dce0..2deef11c88db 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 Mon Oct 17 23:57:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009723 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 8D73FC43219 for ; Mon, 17 Oct 2022 23:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231208AbiJQX6X (ORCPT ); Mon, 17 Oct 2022 19:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbiJQX6S (ORCPT ); Mon, 17 Oct 2022 19:58:18 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AD047E03A; Mon, 17 Oct 2022 16:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051072; bh=BzRmHyDjx6k9QxSMFomIGBOCh5qkOm5olPta9ZMqnS8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=j/khhM9e5wP+lpawLuxx74yOycNZXoKBT8E+6UYh2N4nvDr3jZCVR2NR0MfC9UUjW v1i1nNtrlQNm/nxRPJFFAw4ffa+MKvNCqbgebowRaQWfqu5L/Azcw3JpSRH5ZbdwJx gpFcC52q61PtXpoYj5CU0gxa04wxFgo66VzPL03c= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MFKGP-1ovHNh1Lzd-00FhEt; Tue, 18 Oct 2022 01:57:52 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 06/11] tpm, tpm_tis: Move interrupt mask checks into own function Date: Tue, 18 Oct 2022 01:57:27 +0200 Message-Id: <20221017235732.10145-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:WDob0q+nal8PS7PWDU+fKAFyHJK7IwCY8X4P/1Xsz/Pgvm8OM6r sl7h41ANDn+c6YsHCP7tPEqtOCh5M/LnOpygKNBlI/Vgg7DqrPRqmi42JeCocQncP3j+ZTs LNxp+JnMjWWWuavT/jQb2ErlHMtJhG7cbQ3X2lNDQxpMeRNULLAKqWoc0C8as7Qyps7ub1P B5QLqclCbJJZZx4EBYH6Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:gXPKTH2PjG4=:obtYWnaAhcTFSm6nRSj41U 4L0ea1LbBk+IGzYTWSIkiQ2KAWTWOe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+dS1V6Qp0QDQ+8E/2k7Wloo0MPomWisYVxk5hJDUoqGqyq2MwUWF9R B4Ap4Bg9L3JI5TtMXJPDhlpPAj5p7SB4tpP3V5+taTwZe/Jt/f64x0xHbtgFjYtWT5w1m7sme ylSUAmTieYCCDulxjF7kt+7RU+rPM4FXnPBtRBknkBm+aG8LXGBM0/O9WlYS3aFMZ71cMkQaI 4HvckO10vJO4eYXF4Y3igLUysSkQSWHDjRgs/Kcp+jWDd4Weh0USfseA8LsYyOeAAu8swICPO httAa7pv8NvpbQbGMPJMVFGmeEECHUz4IGsm24e9yvhp/at05WhTkiiIZMCf1KD67PYO9kS6H veBKYlaiDEhhtXPT2eJUoQaY0jXrawG6xnwNVnhvXF7Z9XStCw8O+qI/uJXvcoUJKUxMHxfvb yUihLO8RDuJh2HJLB6DDV+6IS7jPIPErp/s9rfgnBjpVU Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Clean up wait_for_tpm_stat() by moving multiple similar interrupt mask checks into an own function. Signed-off-by: Lino Sanfilippo Suggested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index d07debc3182c..181c291b0bb8 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -44,6 +44,20 @@ static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask, return false; } +static u8 tpm_tis_filter_sts_mask(u8 int_mask, u8 sts_mask) +{ + if (!(int_mask & TPM_INTF_STS_VALID_INT)) + sts_mask &= ~TPM_STS_VALID; + + if (!(int_mask & TPM_INTF_DATA_AVAIL_INT)) + sts_mask &= ~TPM_STS_DATA_AVAIL; + + if (!(int_mask & TPM_INTF_CMD_READY_INT)) + sts_mask &= ~TPM_STS_COMMAND_READY; + + return sts_mask; +} + static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, wait_queue_head_t *queue, bool check_cancel) @@ -53,7 +67,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, long rc; u8 status; bool canceled = false; - u8 sts_mask = 0; + u8 sts_mask; int ret = 0; /* check current status */ @@ -61,17 +75,10 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, if ((status & mask) == mask) return 0; + sts_mask = mask & (TPM_STS_VALID | TPM_STS_DATA_AVAIL | + TPM_STS_COMMAND_READY); /* check what status changes can be handled by irqs */ - if (priv->int_mask & TPM_INTF_STS_VALID_INT) - sts_mask |= TPM_STS_VALID; - - 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; + sts_mask = tpm_tis_filter_sts_mask(priv->int_mask, sts_mask); stop = jiffies + timeout; /* process status changes with irq support */ From patchwork Mon Oct 17 23:57:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009717 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 829F8C4321E for ; Mon, 17 Oct 2022 23:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbiJQX6P (ORCPT ); Mon, 17 Oct 2022 19:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbiJQX6O (ORCPT ); Mon, 17 Oct 2022 19:58:14 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 015647E31C; Mon, 17 Oct 2022 16:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051073; bh=jDPq1ycfLA3Z7wF+Um4FjFbBCWSe4kP5xzmSs1/LP9Q=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Z8jztJPXlVz/DtDZuXC5yKXEEdFj49irePwI8mQLYfihn5KQcUNxGeSx7vX4PKhNR 2L1GOXcIq6XF/mCijRb8x/F0d2AdxDkdPBLCBF9203oSrRecYTUNYE/ApP0QhA5OFK nPJcfZDgDR1YgSfvj4RDCNsJFknWOeuekcYuDBcs= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MtwYu-1oyf082nGu-00uKuQ; Tue, 18 Oct 2022 01:57:52 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 07/11] tpm, tpm_tis: do not check for the active locality in interrupt handler Date: Tue, 18 Oct 2022 01:57:28 +0200 Message-Id: <20221017235732.10145-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:8fzQ80YFE1JxOIOkmc8gb1a4v07OCSU8Nki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GWa6LkNRtc43FgyMOIrxNbNfz8Cbr1FNzWRVxcCr5eMdxDlehb cvUVZLAzGAyk1C4/9+Un5cZIu9W67RD4ybSAQEnf1FDoZMeTN+nTcRIvLsvmIZfU60fmwV5yD DmjQmapxqFIaB3nJ+I72M0q1o3gXHCbby4hLv/2PmNHJ564+8GuBd3lGLEbvALq1/GJmiICCx 55jokqbvQY0aaVQnJIyXOpBws6ZBtZUoDyrqDZPLHY6SA9DRrJqwd7KcdYhhql8uXvOiCRkEv oBdZl2juMrVlbf9LGvv45jlXovMduNlFd78fnvXRBJ9tVICmvCvzJ+4KUlqX3LYuM79ak2d+I 7LbFwgCwRf0+d2/7FSu2i8AklopF7dxBKvUqfVM8iDb3Lndkg5M2HPhG7SnV6uEpA64mqAXMC BUx/LKXp5KyQ0rNJFRev2qX1P1aKJeJjAfDQ3F/aqB4xe/XWRs6M+3ejsXCJEmBoxyeLJP3aZ 3k/wnv7Xx3Fepp7qXVW/TquvnpQ1T/D74aex1FMydHRuYCdH4Rcr9Lx/T48vpLotP54GW6+W4 QyIGGazDYcy7rQ6rnPbDtNiod4y2epIEuScPQtX6gV2eIPyzGlBfGOCHkitvaniMUGflDgANA aDeG199a4kTCd05/qizehM7Tz4wexRaGKG/y8HeznWf0Rd8LKaeY4mNknUzWRi9fS9t2Q2bXr 5ZZZ6vZwBnuluUpJsHaWinc0mIKOB9n5QMn33Ruv7zSBR Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo After driver initialization tpm_tis_data->locality may only be modified in case of a LOCALITY CHANGE interrupt. In this case the interrupt handler iterates over all localities only to assign the active one to tpm_tis_data->locality. However this information is never used any more, so the assignment is not needed. Furthermore without the assignment tpm_tis_data->locality cannot change any more at driver runtime, and thus no protection against concurrent modification is required when the variable is read at other places. So remove this iteration entirely. Signed-off-by: Lino Sanfilippo Acked-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 181c291b0bb8..4336f7ea8c2b 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -728,7 +728,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) struct tpm_chip *chip = dev_id; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); u32 interrupt; - int i, rc; + int rc; rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt); if (rc < 0) @@ -740,10 +740,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) 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) - for (i = 0; i < 5; i++) - if (check_locality(chip, i)) - break; + if (interrupt & (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT | TPM_INTF_CMD_READY_INT)) From patchwork Mon Oct 17 23:57:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009724 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 BEDA3C43217 for ; Mon, 17 Oct 2022 23:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231241AbiJQX60 (ORCPT ); Mon, 17 Oct 2022 19:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230527AbiJQX6U (ORCPT ); Mon, 17 Oct 2022 19:58:20 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E48768680E; Mon, 17 Oct 2022 16:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051073; bh=juUo90/80vPHuf7Br7pPmfpOCEHFG9Rm2lnetqnzIHM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=fnPIkL8W4M5bNzWcyi9a75ql9//2R5Qy5TTlZIAT+iB8WFEVVuSSmN1bSc1RtN0uY LhMTzPVAdreBkT0DkwGUWoLcGL/JFoUSTjPSLgSh0djG4HqgFFJFvcppL3qhatMWaa uXuzZuPfEHACEPBWbUEYr8maZL5rmCW/s3yzS7iQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MvbG2-1p1Q9e4Ays-00shHM; Tue, 18 Oct 2022 01:57:53 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 08/11] tpm, tpm: Implement usage counter for locality Date: Tue, 18 Oct 2022 01:57:29 +0200 Message-Id: <20221017235732.10145-9-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:pfbvcY5/MnkRaWRBLgtPcwmK2mbOel1Z3UYYqdvt3JndJu+H5cD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fjwSnYOele/xrUCgrEvZA0lZ s5esI/w4tCmBuW/rKWBMktrbHfM6IdPF3DM/ci3FXTTGkoKozhGOLAgZOEgEXnLPOeMmIGPZj rATlNmgTLuvyPe6jW0/X617a+vlkZOnw3QkuJz5wAkRc6vrERw6QYgE73wYRAfhR3nwLxuolx zAGXFm2o+ggOaohgTuvyqOTXNxv4PAY5ZmbES7gDeFxyBhSa8W0/apBKC2hXDd7MzFwU46E+E KynRTv9hu8D6XOoyXhH4Qv9JImL6k214AJFGjKKRnVmUM0ZUMFkWo9haeM6iiy8ACpkaiOMHf ny4FVS9kmW/C3gpdgkHopdmFn1/fZYq5vuktEHP1a2o3RiUlHWZ9lXnD8fwSfRsK1dxky9LPA lGctsENdBn/Hy5QYIUSWTKdDjmVINVcWJRXI5ptBbWg0I7aw5ga6e3Xgnn0+LX6WNVUWPL8jb Q9hl6KxGaficrqsN63yz9KWf2mgHf8m656+Mzl3IO6HPt2ktyjxgPQATMUBzzeADcHOkPZekd JtbO525f9QKDCSM/c8hnSlO0syEkBqU8tBDp93MlOcyT+JwgIy7Xy24Ww0lDtJEIeOeyYAc3c EL0bUJMT9bNzKPWrP7/s3ndh8a27fGgrGV72540cxK4kaQtcvrvNn4Cf7b1jsgD14gY8tIT5e zZ0XvaYKFL1TPRy6BHRa7mFasUbRLAlzMGem5sPI9tP7U 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 Tested-by: Michael Niewöhner --- 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 4336f7ea8c2b..79dfab65976f 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -165,16 +165,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; @@ -215,6 +226,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); @@ -682,7 +707,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); @@ -703,7 +728,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; } @@ -762,7 +787,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; @@ -771,7 +796,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; } @@ -796,33 +821,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; } @@ -830,11 +855,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 @@ -970,8 +995,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, }; @@ -1005,6 +1030,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); @@ -1083,14 +1110,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) @@ -1124,13 +1151,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"); @@ -1150,11 +1177,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); } } @@ -1221,13 +1248,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 2deef11c88db..13bdcf38e56f 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 Mon Oct 17 23:57:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009716 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 7C51CC433FE for ; Mon, 17 Oct 2022 23:58:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbiJQX6O (ORCPT ); Mon, 17 Oct 2022 19:58:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbiJQX6N (ORCPT ); Mon, 17 Oct 2022 19:58:13 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ADCD7E326; Mon, 17 Oct 2022 16:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051073; bh=KEA4wfis+vvcc4jeyKKQbKPArLj4tacnaogTuqRwocY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=VwkBy4qkAUamg/cyvpBu4RBbcyHXsIMZLp7MfHllM7E/XccXueflc0KjvJ7EvZURp C+1rcjVyhXtahFUyUcPbPmqXAAaK5Acfja85PmEseyHSzxQlZkXv45M9B6sx7kdLU4 Naz4aS8vvlQDja1ZUzZXiZWmmmMhPMMbOq78UlyU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N33ET-1p79Se1OIv-013NRz; Tue, 18 Oct 2022 01:57:53 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 09/11] tpm, tpm_tis: Request threaded interrupt handler Date: Tue, 18 Oct 2022 01:57:30 +0200 Message-Id: <20221017235732.10145-10-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:dIa9SZQTn6cWmM3h4lHDimeagtlxOyrDcI1LJ7rggPeOZ74g5CN oYk73lhX/30vNw/cn58H4fIerri4GH3ig0PE//0dzyzOxoTjOA6G1UxUSxq6V/rXDlXpyKY 9dNvexRXEScfOqcqJi9ZK3sAxs47CWUHQqUaa5YORsFHEPEq3/UI4gNTxfz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cVUP0T1jUJHjodYD9NU9so9mXZTy0lzSf/rBe0U5SloRa qm8RGJro7Hhy/TBI7790mQIc4xD6Z0IzzrBDhP1y1QfLsQWjUFy3EArdRofQCgGaDfQv2vwQo JxB0L9cqgayCxvdmGE2uIiGOSV8365Ii4ePl/MFLa05nTxX7wUrPhrJ0qFSrLebvyzWd7OQWu AwkzzlVX88IP0D6Bjy/0kHC35ZS05FVHjxWH4jQC2wbGQOrNZqSz+F4+Kgr+VBBb53QjQop8+ 9w/OFuTKwSggq6QopV/QgMzUMWg+gRgz/qFUv/8avMYefetxj98bWgszFwl3qftsmfS0djy6S 15pCohFe8sZ5o3CSzuRW0ni3B59Hv9tKOTlv9PENmKSZ4BsMcCAD6m/BsfAZwiaxmrMTl+I56 EghAPJlJfxhW+dr5VxA1pzGvsT83hwn7NBJNHAP+qAWcNk9BA5n3fzQALxvKOPcraL0YXcG5Y maV9FO8LUs4qeHqpgoIkXuJDj947YlzFvfh2v2mXljMc1/A8JtrGR0o/mCnbRQTJ+dnrvgutx TpEemKqb96ChCEkNofbO0yUou/5pXtd6yGl5dps/3ErQg 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 Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- 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 79dfab65976f..1e065e7ac460 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -813,8 +813,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 Mon Oct 17 23:57:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009725 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 CB46FC43219 for ; Mon, 17 Oct 2022 23:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231259AbiJQX61 (ORCPT ); Mon, 17 Oct 2022 19:58:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbiJQX6U (ORCPT ); Mon, 17 Oct 2022 19:58:20 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 076B48680F; Mon, 17 Oct 2022 16:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051073; bh=PbG1OYX6Y4kEPBzVrb+ulM+TX4iJNklZW45J9wC/7KE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=KGtWOlMGgNx7n09+tKlPuD6lxv3cZbh2ucucazoy9nsOts6rTDFQXDvFgjHBxrMnW MmtyxzbrPcv90argVqs7cLTJva56fODUm3Q5sVSseyK9hUgwsOJjZiXrBRHLX5OVqA c1zURgJ6uenfI+S+t0uALGz6mdmw+A6E6CkaTgBY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MAOJP-1orPlC2ldD-00Bpcr; Tue, 18 Oct 2022 01:57:53 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 10/11] tpm, tpm_tis: Claim locality in interrupt handler Date: Tue, 18 Oct 2022 01:57:31 +0200 Message-Id: <20221017235732.10145-11-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+Q245lTUnEiVujLhjvtNoaAeMRZ564XmmtJA1FOAgd1QoYjag6I ucpHK1Neq2jBwcV5z02NNlIfrQyxyLdDLMY6NuRvAX77OBG4YVr38aba8tkpAywHJbsMc43 HbTOPzXQLYUYN8hao5SrtXK3bLbzGn2hRo7y+pqibPJb37xD/5iJ1k8/gsx9hRPoZGZxJWN 1dDD3dEhi0Q+lgHG9ib1A== X-UI-Out-Filterresults: notjunk:1;V03:K0:rmmYQAqyqLY=:gOvchMX92CmjVRyT9DSMTT 7P1gR8zjFRUCKYya372G9xXafC8uNc3hDei0GDOhw2ZjQFXRQ972S/e5KqaqkeQNNK8zYVhwJ V2mf2ctLRG0GMDKO35yuEUvcpbZOcvos/KJfk5vzDPooMAZyL+eotHhsgKxluyC+Ekj/6rShF hsCQO7vNP8jPFvpCr9+a5mj0HMWiwao/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CrdS+sm2/+q1biiqhKUVctz1W3LfjNFCj1yS81F0/ZPNy6ydJXt qHVcHeXp/ePDMYxsyaI7XoZZTJfyCG2cFXzCKjfC8bF7D05eIMBNwDRd3zz+4bxReGprJGMcx f60dloO87Owm96TWIMzpWnX+qYpQMCg3bCEAKgA6SE8zVV9ccf91D4g8RicHFsbdjpYEI8gha 6qr6tUi24KfNCrMVVgDm0or2grb1SkDzpEySpUp0TQk7Ka+ns3T4uknuPTP7HOSODXIMHlOyz ZbMm11i/4JFoSXtKGt6yN/aUaEctdIpp9TZ4Exk5IyLlc 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 Tested-by: Michael Niewöhner --- 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 1e065e7ac460..42f628e52cde 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -772,7 +772,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 Mon Oct 17 23:57:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13009726 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 48A6AC433FE for ; Mon, 17 Oct 2022 23:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229944AbiJQX6Z (ORCPT ); Mon, 17 Oct 2022 19:58:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbiJQX6T (ORCPT ); Mon, 17 Oct 2022 19:58:19 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FDC586802; Mon, 17 Oct 2022 16:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666051074; bh=buEw+w1lPaY9DnLnvIwHNA83JT8Bq6RdLmvLWuRAigo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=C1uKCl14AdWDIjY1KVavFgtxvfuBAr1j1iTRRE/BySwSCXiv6Znp7HDjevv+52ZID L1oHKz2kXBovl1q6qaBsK9Sw+91gJEssdVR4zM8qDq+nDiG7aiigu6TWCIsjcsNbNQ J/E5jgQvsUCswnLf0b4ztRBa8Q1kZMVVMcRT4TXk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.speedport.ip ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MbivG-1pGsbn48pq-00dDlQ; Tue, 18 Oct 2022 01:57:54 +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, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v8 11/11] tpm, tpm_tis: Enable interrupt test Date: Tue, 18 Oct 2022 01:57:32 +0200 Message-Id: <20221017235732.10145-12-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221017235732.10145-1-LinoSanfilippo@gmx.de> References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:G/UrceEJMQh7OfbfZywk0mbMyJC0ez0JbQCh2fp8L4GbW1scecR MxktYbhNp81XSKlyTQJ9vnG6diNUOeH78L/NAZ9vhiEXcVtFynmKRzz3nYChxYS4ruB1vlX c3JAuk7x+zRnawWu9mdx0UDlSiTfd/PpqXNk/HrpCzt2sdHotAWRVFu+YP9KDWNu+kvLiWs nDp0MCO/1CCqktZHvXHsw== X-UI-Out-Filterresults: notjunk:1;V03:K0:QTPKhxW+/Y4=:DG+4oVkJurEO+P5euZJ65W +XszL3dIXeK5rBI1aCcaCbZZpX9P7Ypn5tQWM7sDBQoOrzXCDmqU2tHzYkDqnQYSrMdXuvv6n Zrovy232IVy2kjyJlgCryOZFxou+pjJjKw4sgWK7TVcaCga1Xc4uAYTxiAJtVB7/60NCqueRB Lf6xDWT+XRbF4LEvKBA02sN2s2y2NvSNZ2vyIZCXvoHLCYia6mW+e4t978YmNDhEwKYClw9BB VKgRh8qSuVC1cdrsga1oXnAq3Xjko6Qpv809rG7emQdIXTobUrJWABP2kLVNNuipIbcJCLXBQ g6DQNbp89PBGuG8BhhcZpIK4s0FNi1zyhcWgUfotHgUX01WDG9R97gXoEvHePLmT/jIyndYOg y5VAOMKM97I+99xQMyDxOwRHNV+DWH4iMn0yYba1Opy6twgkUzmjnWBov1pV4j9HSSlxsHXCX kcSEbmAV0P3oi2BVyJyevTUrTT1YryvvVMjuo0wRJKKG+3DFwuMBWXcYekuRh53q5jC4oly1x H3ojD/DvhFbs2bJpBNTw3mfvvswo51uiAj4k+nT42tJSxHiJIR1L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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 Reviewed-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen --- 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 42f628e52cde..9778860e1598 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -793,11 +793,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;