From patchwork Sun Nov 20 13:31:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13050031 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 801E7C43217 for ; Sun, 20 Nov 2022 13:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbiKTNcb (ORCPT ); Sun, 20 Nov 2022 08:32:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0106AA7; Sun, 20 Nov 2022 05:32:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951125; bh=A4TNiZ1MIqgxBlywM7kePzrqXJ+tGCscjealDs3aYxw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=U1MnMRiLo7lFIAsJR2Z3mDisNFMsDebDtqUsFR3FTFIbYphcarJk13Smb84Zi66pJ x9fGmLZSeYMFqSl7/hVg082vUAf8wAo5dzqRxaCCX0H/HfrB04kHIgsdnlLkHZA0t9 zzNm23vt1iG3BcBtdE1crOeaIkdsp+sxpsBD8RKmOxOB5yShWS7KiFdFIJ6H8lisgb mvZ1k/lPEYPvNYlhA/dY2vEGyQWoM5+K0WdQXMmQYsj+irdHQXGNF4bAldc17ovkwi upBtmO3qrTchrOA20vXXe//XCvo/F0ibq8A8xlzFyQHX+Rh7cJcx17uS9flN9QAXAY 0wawjg1Mm8Tzg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1McYCl-1pVFMn3grd-00d2kE; Sun, 20 Nov 2022 14:32:04 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 01/14] tpm, tpm_tis: Avoid cache incoherency in test for interrupts Date: Sun, 20 Nov 2022 14:31:21 +0100 Message-Id: <20221120133134.28926-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:RuWFAxuNwY2FT86vJNtzPuYEZpoztucbVYAdGLlXTQtT88zV49q KCydeoKPHV5YH+pMz6lMCZ862z8nrCJ3t8aj/jBdLg5gaSCgxo++V98TgT3Bfe8hXmM/kvu EXrvyyP9q62Z0RzfY5+P72e6mdEqk8/52QS3qmy3tgbRrBSLawXH0Lms0kQ52jgOECIBJuP O5XF/9xmFuMhh4Cyklqcw== UI-OutboundReport: notjunk:1;M01:P0:Q+0a9ri9s2U=;cO6kOhfTm36JQ3YSj3SePfm9L3D a+SejTbtWaqb6w8chLd7DuWYH8c62Ia9tV/1HdVKF/rkXduIKgdd/ivkAMP1g3teF8ERiaHm2 xQ1LYfdhKma84M+6PEElYAdUbRbg4KHOZDGfEwq9JNaFSW2k6BVaiLtklc516N3eY8jKdbuT8 rSs0TTnrxx0EQsGU7NdJ7a+2zxwDLm5XVHoxpmlpu6/Q5AiAw4jnaxCGRQK+v/ntTnpZoYVW0 T9F5f53Vx841SzlXntD8zRFVsAr/tVd4ZdbuZ29FQ+qFA+KvFdZJxeI4PH8LWS1kqh2xCMX2m 2qNyp9nxRFV1fiVACOm5BBl+rJMZ/x5f+YL+R38Ewz2xzZs+Pd8Vyw0cFP8ID92F959fe94EW iHlXU9Alu46IVEo/kZfc8h8QmBfmnWAvbYlcrKvZyv+pfzXeTWr1ZMcGcX8Hh0eSHmKEim+uq sRLENbcJmW7rH4XIOH0BzFt8CpHYuXmIpsJBlPXInWAlpH2fE0sTC6RifLd3Ty+nIBqxtZBA8 SbkWppgwKDgq+QGU9PfCyvcIuelbaoxoECxyNT/4DZMmbAow0SxUHri3ZJTu85vuayn2I1Wq2 3nRsTdELLob/WYTd/u/hR0uiYcE2XZHx/SXw2yp7yBAdydldya0sUoS6OSYsnBc7gUAUSeWW5 xVWW9vfR1Hk0hC1z6TdttQTT97tDWBKRg0AmcPF274w/9szWITVkg5J3DQMMv8JoLlXmyUDWv 8MI+mQKPGThXMYN3JLgu1M3AE5sXt/fsuZXbL50LYcD1blDqNKMb7H18Fpi+HXdqJ7GOoKvPD rbrnCEWxmBXydZj64yr672yMhGvThzzypGgvi5dUs0ZiR0aghz7HhijvQGnQV4IIWnmei2qbV jJcYMNCS9450pQlLT6YZp+z5uyd9WfuG6cd3mR9P8SWkUxau4GDyFg2n/LX/bbnZDWSW0TUwl r9I7IpQUDbvEJ9HbkPcy2nYFpQE= 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 tpm_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 Sun Nov 20 13:31: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: 13050035 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 DF955C43217 for ; Sun, 20 Nov 2022 13:32:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229701AbiKTNcn (ORCPT ); Sun, 20 Nov 2022 08:32:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbiKTNcb (ORCPT ); Sun, 20 Nov 2022 08:32:31 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B80DF27D; Sun, 20 Nov 2022 05:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951125; bh=1jiHlANZ8thD5aPn63BXGYT+VamFBFNIAjBcdG+2s2o=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ESJFfUJNvLFaEbcb5D3Iaq5mvXH433duVgAaH2oyhqUEKANpXBFF9tTRw3dFazHOh IgHsxvR12p7evjL6IepKdvLMZDYDSeupz7pSEGkEnwlkSVrFJvVcnyW9VpLJO1237y eF957fI/wjSTAnnFjLpOFznT7mfzeoMxZ/UdsgJo0Eu/+BxIDrvaluYjn5lZDGeTmL aZId0F8IzQFs6s0uADyJMNztiI2TBATIV3tIY11712gTAOPDQ6a1kzWiIJcAdCeHad sjton3aicJ/bR2BIudzVQgGBB5TyYcMoYzn4hQT4jHtZQYXh1rqix5uKf8aru981L5 OQ+2R5FifreNw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Msq2E-1pCLRF13qi-00tC3L; Sun, 20 Nov 2022 14:32:05 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 02/14] tpm, tpm_tis: Claim locality before writing TPM_INT_ENABLE register Date: Sun, 20 Nov 2022 14:31:22 +0100 Message-Id: <20221120133134.28926-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:dVUxQWuZX1rElk66a9cVkpJrvR06Gi4LdaXs27+gK9dEmE056yk 33YAC81FsrqNb+F/GS0ziIoLFBYuf/Ser1dsjsD/4e5vFweOIsrVSUSvXBwt6aOzbT7gOOK SdR3z4KY3rT6/XHhk1JAXxj5+whdmoKD9QehN5J9EQM2t2eLs4CbNOI1MR3o2UDfAEfp7W8 ddAtyJyMrv1Gn4egUOHCQ== UI-OutboundReport: notjunk:1;M01:P0:OxC45659cqI=;3PIefNXqEQ/fzKvFqqkFufmg4bn cPo5ZmNr4LTUzuafbBkqgupOfwG0K2zz5Mh19dzlindm2ufM7EfiLxzeKUPSawBTZcbExOwk4 7VQl1T7s/TXiZwnncMLq6svmx0TYUZpZaOeeveOXc7WGZ0EX2+IV6Ushkib+46S35AQFEh803 bwlOFwNC3L3EASKmpSAhoJ8+ehkaofXuCt3Q17YfvLLFZ2k8aNp9YZUxTDXK4x8Rv1aJ5HTyt 8ec/w2OT/BG5Y8lvlYW4L+5++wWGbO5ef8p9KYv1nlulGQk97jridFM0CamkOIWod4OO0944E M3600oGGFMgmNZxw/85j4l+o4XnUavuGtq9nsxitroj1T8zyOzJ1JmiiBC4YCkj0hB87o3Aaf SKfSru4E/+2BMLt36y4XHOhWe202lL97RzPqYJZCiknrd/UNcIfQwq5zW6iiAYYHr2hU/h9P4 UZ0xNxlmsCcvkc4ZQH7sHvhXkdq1qLc9xkLOBpubGgtT+OcESJ1fbQ3pCKxex6Mx7sgK0geE3 gSzXuhYjzOS0UDGDEmANFbI723PRjqhUb2Ib3zy4wIS/2x2Ig5FOdGoFTWgokNECtcW3EaTzo NxMGuIooMpSRGtJpF+gI2vEPn2SyUXMvjhHmXzwRUVGAaNSYi0np1AU0mJBgu5lnYYefKWS3c okCLpGmWO/Xh7HOvIqfi0N/XlDlZZdHd1DBZl3jgBCtn5PZZOeSp/CNYQ8KRnOq0OeJS3nWjA NKrcnMKIUp3Mh6yXW0mGVH/LmiqryJpQnBYmF0OV81pthYhcwIDkoHFQYkAEZstIQwiarM4XF 3egErqiaJzc+PVN6mxcOrsv9XeJ8HarLD9ERs09I7+RIWLiszG5HNS1ttFsFUDqZ+gqMmud+O kXLQu6gVbuvQ19HNOvZMqV83AAe6LKWA7JGMxPiR18XHRDAwicxWt882u6Efhj8cHDxK5h+U6 98uJew== 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 Sun Nov 20 13:31: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: 13050029 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 ABED0C4332F for ; Sun, 20 Nov 2022 13:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229547AbiKTNcY (ORCPT ); Sun, 20 Nov 2022 08:32:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiKTNcX (ORCPT ); Sun, 20 Nov 2022 08:32:23 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB5D128E13; Sun, 20 Nov 2022 05:32:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951125; bh=vmr8i0HILdqGMwVhgOxfm//3j+C4M5iWtBnT+hrsrRw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=TMP3jz03SMBORLJ1Osq4NJBLaCq5d0dw8jsLS1ocyJhst++3mlOZzBTmQBqZWjKWv Voxzb/CQ6RCoeo7qn6/J/9C71Ry/WZsSFaulE6y7ESVN793wcmhDVAj4MNXBq0AP9i qdDmg6LDUbciSZdaXi+No2YJpxW3W0J+D//iRMt8zl5D6anEc723u8h63zHiFywoUn L2a+9hPW0AOGMc4wG450lLEID/gHX41CCJoWqkV1f9yuO2eIHhJmZlZoyMAvXHHPhG 29ZrSrj2z8vJlqhCF83PQLt/o1ecqy2FmXV2Y4U5L8n/yy4g2SHxLP58OTgMWQ8r8+ SWTw8fUQKRfOA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MXp5a-1oQt8j2T4W-00Y6vT; Sun, 20 Nov 2022 14:32:05 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 03/14] tpm, tpm_tis: Disable interrupts if tpm_tis_probe_irq() failed Date: Sun, 20 Nov 2022 14:31:23 +0100 Message-Id: <20221120133134.28926-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:b4C2M5Qz3awQq0TkuQ6vgiwoMtTbqIlRfmnv0OiMblSzZLZq228 BaaIfCHUp0oCYSs1lVBZoDmGSQvGKfk9Znbbm1oKwMdK2GDQaSlNOQZOsHVfh1BDxtrFT+k Yi6UqX2Us0VDNI6jgP4INwB8nW5Yb4JMr6X+4AO4MkeXetbnwqeuafOMSrROsMP/or/mK8t xuz7RZR61pEoZ12pTwE7A== UI-OutboundReport: notjunk:1;M01:P0:Z7y9UfKX6mM=;Q1Umg7DU5Dvyq+vxVLBm7PMycSI L2FyUFkk5FKNJrGCKp5FvID1bZEq0odl/FRjq0YEwP3L4dQQovH6krb1gCk14wDVhiVK4wJNu a8HELXz+JRZ512cQkSVNSAMkAcspVnucQY0pqK6jta2zxSIGp34sKkK/77stXgNHYbWwRdS6T fbW6ZWy7y7eaWYE5Ts3a9fFietpRoed7fxzdomjClJsP1RTUxJpMezu95k3UnsQjc4RFqZixf w9f/KP6fAWomT6HBgYx1CxSasp8jOgIZN7wUDOpRy3TUF+wUSGVX/ldKJKNtRJDFI82D1haMl syvZxABa8z0D+R6j3tpKL5VAmrlPShNx7y9JSaehAikJYGvLqnB+ezSLxGHBrrfZXPvMVmbj9 UeJ3OB/DQe2SLkLvX9noAAf5G9K3tOSXyB+YrgdRRF6DJ6NfK0sI+4AjYgOFgsxUil7UFky1a 687Ll/PTJXIfWnCJHh5wVC3GBhuU7ydCH9JuGT2PA/X+OtW1MYLORZKwWFEk1YgPQCCMTI2Kn /7oy/r4/IN8diVkGJ62JSEj6BhXqj7nNgMyFH2KHONxDMIm0Wk08mzEq/O3zEraaKB4daXJIP pmabEL0l3tts7IFCzaqBg65iFjtxDe8nOQvXtEEjU9tilCSCcc4mWmn8q9UIB1evQIFi55LM2 pohbrFj958CkB1EG9ZoRFwMFgp3W/yPhknNFV5JGKAq6cz0xSfk4Spd8EqUEAZ38kuycZT9nN y7VCtKo9PfT6zU9MUBbqfSWH1g0vsQQd2g4bk5xOZTkUtIfDhOn0R2d9TMfBEv5b3PXJDKtjw mLmZ2KSzWJRmgVpe87AAWYJNgLzkx7jXTU4hwvV+iDQ6wZAXBbkH3JHcC7up42Lggmn/r1Ec8 VoWJ8eq03qGNaAmXmXPCWlcslbajAJEYMIO4NC4UlCpljM7flBilgxD+o/HwV4ZgGnWEuC5x1 GnvWiA== 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 Sun Nov 20 13:31:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13050037 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 02044C43219 for ; Sun, 20 Nov 2022 13:32:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbiKTNcm (ORCPT ); Sun, 20 Nov 2022 08:32:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E809254; Sun, 20 Nov 2022 05:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951126; bh=Wzja5YwaKAZiFWUMEa0HIMVITjRNh5lgwkhDjVIIVv8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=WI9WkzvqAEVlFAx3MSFarxoHXZ38m3UoVBGKV2bxv521t9ZMeYK3/S75R5P9hjGDg ab4V7zvRgndKizWT8DvP/9Aw99q6KtIC/ZIPE823oZLer7DCFILFkDsS7ntfinQ6hx nA0Ge3cYB+J7yY/sh/5ckOs1+0JCdLSh+XD0+sAQKqO5h3W/39AtG2zj8zq/Or4qoR gKARc+JazRAbBTy6OXo1THYJK56G8wBhYZU3Jzc+Jnp0oqqUyxm3Gi/fv4eGM0aUZB Jzv/GQLuwiOJoXcS74fja1y6T3BqGnjPh1S0xKOqzz1PMp2aKtbMmqdSIJHGIVSl8e 0bB3B0duPSN0w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MrhQ6-1pJxlR3urM-00nhs3; Sun, 20 Nov 2022 14:32:06 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 04/14] tpm, tpm_tis: Do not skip reset of original interrupt vector Date: Sun, 20 Nov 2022 14:31:24 +0100 Message-Id: <20221120133134.28926-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:VUd5I5eDNIynx/FyCcZmsE7B+Hj1CZFkjV5brjm+tc5mzgN2tIH eh0PWN/12QLtOELXmf0NMG5+HCPKEyA5G6L8UqJdL5epvFI9aEysg+NzXS60H1QEcbAXx0a D9oZ1PTbFWhorQp5mHR3Ptu9iCuxpGdn28/ST+U/z+3KV6PLNuwr9/qtpsaFwDlpRVOrwHU VKuaTChCH7d73U34ciS8g== UI-OutboundReport: notjunk:1;M01:P0:asWYfnMi/Wo=;S+A6QUJ0wtwWQ7q2ybxhH9+aYvF U0HaOIIsKHYk6HBVUMH2mhQWYzo/5IRadKEyWsEvwBfsZj7FP/Avb2lBRFN0Peu7ezb5wYVwn GszS/t9X3woWxPTz3tTHZ8kl50mJRzwolWtFTY2mCQzxIIT+hmQjPY4+6/mSTWvZwvXv6GCsf s+Q/b9H68eAhI6tdd2ywlloM+pPl1C8oUafH3Wr7+h8lP9itrChA8aZdnaYLGTPqnKp1DGlZL IwS/WVR8LKEksKMYQ4JyyTT5MOnY7O/oKRz1FVh+a2KxLu/nZRFYwgRnvtWulVnX3rQFSxH3Q Dk5I12Yq3YrLayZAOezJlDq2cmMmx4qv6AxuZhmmgu/yypnULilvwdEj/jMJupT7FcTlm3T2M 9yPMSwkDKHqqcD4s+j7pTl6AtDMuGWhju5oF7T6Vy4g22Ud1SM+CfYECU09XvCr+lEYMgRptR pThYNmL69AM3azQjRowL9HjV4QUccOGemxMr0S5gGxDkoJJkukXWs1cVoU9M8s6KOwbE55VaQ 5jL184fv92djeX9fNmu/Sz506nH8T2jTc1ss6mOfVrX6PtM3q4KgQEpi2WAn5eMuZ0qkF+DmL og4bsoETA8babipE0pkHLTMvOFGVSz5VqzbAljeLAQAXeR3zp6l1FY0Uu0XuY5ApWknlZJOvM G58dicL7MZr3bdNvp+VVr4IshnvXBx8cTG2goeeoV/nVEdxqdWdP+7kNn/vz/X9oJxsYGGsOJ OYnW03gZF2+h6g+UT5Zehb70pN3BTQZllL8Qq0nnEsrOM7Q1fSsOjgIwCPJw4lXFxsYNs5zZ1 QWj5Rf7IdzjP2O19GN4xSo8OdjYBEOtybR0CQ+6BWdNG5DfuprvBeawm+QTkgZHw6enaaeYbX JTI3l64q3d+sQCu2JrL1NlblPrKzImtSg/u6xWPEy0DtUuFo1ho5j5Ve5sJLC/0yfoDfIzkGw FIu9Rw== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo If in tpm_tis_probe_irq_single() an error occurs after the original interrupt vector has been read, restore the interrupts before the error is returned. Since the caller does not check the error value, return -1 in any case that the TPM_CHIP_FLAG_IRQ flag is not set. Since the return value of function tpm_tis_gen_interrupt() is not longer used, make it a void function. Fixes: 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for TPM access") Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 603b82ca56da..1eac1279594d 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -729,7 +729,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) return IRQ_HANDLED; } -static int tpm_tis_gen_interrupt(struct tpm_chip *chip) +static void tpm_tis_gen_interrupt(struct tpm_chip *chip) { const char *desc = "attempting to generate an interrupt"; u32 cap2; @@ -738,16 +738,14 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) ret = request_locality(chip, 0); if (ret < 0) - return ret; + return; if (chip->flags & TPM_CHIP_FLAG_TPM2) - ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); + tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else - ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); release_locality(chip, 0); - - return ret; } /* Register the IRQ and issue a command that will cause an interrupt. If an @@ -777,42 +775,37 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); if (rc < 0) - return rc; + goto restore_irqs; rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); if (rc < 0) - return rc; + goto restore_irqs; /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); if (rc < 0) - return rc; - + goto restore_irqs; /* Turn on */ rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); if (rc < 0) - return rc; + goto restore_irqs; clear_bit(TPM_TIS_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to * tpm_tis_send */ - rc = tpm_tis_gen_interrupt(chip); - if (rc < 0) - return rc; + tpm_tis_gen_interrupt(chip); +restore_irqs: /* tpm_tis_send will either confirm the interrupt is working or it * will call disable_irq which undoes all of the above. */ if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - rc = tpm_tis_write8(priv, original_int_vec, - TPM_INT_VECTOR(priv->locality)); - if (rc < 0) - return rc; - - return 1; + tpm_tis_write8(priv, original_int_vec, + TPM_INT_VECTOR(priv->locality)); + return -1; } return 0; From patchwork Sun Nov 20 13:31:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13050036 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 DAF77C4332F for ; Sun, 20 Nov 2022 13:32:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229745AbiKTNco (ORCPT ); Sun, 20 Nov 2022 08:32:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbiKTNcb (ORCPT ); Sun, 20 Nov 2022 08:32:31 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FBB529A; Sun, 20 Nov 2022 05:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951126; bh=mo0aex3xZinBFgfr39bfyhV1oZv6iyWkgvj5WLXVwQo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=bkpmWPdYYu4avftPo6rrf1aFmdEju2RTaGGoD+EgwTHfLs5d4OInUCAbLL4Hbin3E zfesiYSlDp9XnmruYuV+ArJ/W+s/DeCwowDA6JB2Ge4zJDGM9oAXclRBk3ZrRvDVPO wb22PxU7zn4TA6Xlp8LTheCZr5UztCUrRuxOOT3RPolVNLu9PUl2cUmzMEztc4h48K bdGsmEjufoPXvbVKlMcE8idw0IAnuDVgt5+EP4mUUv4xEcOBug9oYQpj3FXKSaVqqy 051odHIUS06eYFseOw/IRS1Mv9psTUMlzUWt3VnVXaqdtWH1h546D2v5lQIElBLjP2 mPTiTZ5evz6xg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MVNAr-1oXCvx1UKV-00SLd2; Sun, 20 Nov 2022 14:32:06 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 05/14] tpm, tpm_tis: Claim locality before writing interrupt registers Date: Sun, 20 Nov 2022 14:31:25 +0100 Message-Id: <20221120133134.28926-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:f6nQ5ZH2k0l7L/RDWWZNUoDawHxfUyilTX7+GGR9iDdgaGyKXhX GYfdpjigd0/KIKMw3uFyAriEijDYFktSMgH8HI76SL9WrnqDB9918GOUJNwl3YaKBRYyW5B V/zsZzfKCf5eAp6imLZkkW2F4RbplVfWw3yG0s9NdTq21Nj1Rwnq2D8dDCymUD9acCzt0B1 U2w6f2RaOYBuCaUjgOdgQ== UI-OutboundReport: notjunk:1;M01:P0:7PKF015SJ3k=;ZQ+6RO+dhA8NmXq+NwqOtgXnECp WdYnA0BoBnscfzWwRbebUA1EK34VYc7scgcqnoNG+aUfoWA3r8MJn229qHZfdEHGBmUCHbYmE Vqcr5KMsin9JBRByyDhiWwXl4yscRtjxYbyYJ7NUP9nDHHY9qX6KWBA0n0Dsw1naS2cfzt2sG awEZQ8xnNV1paExhEojGfl2ZpJOmnjajfWVR1gD3YxeT8YjFQMsH+SPFDhr9Lyo2O7QczUWLW OTDfYUJ6Gn116666pF52nUN4ZvEezhxT8RhawpK/BL7azZsV875GN9vCW9HLjosGyDfjYf/ql Q88hTleVP6cVnDmsaTlrxtgqiffyJP+BjgWO01CRoNHbP1k0/K4DLyyA8hYDcRQVrHX2lvbLM GqnLGbemneIObAAPkMvYEWYxTyQG0JUaXAJu8sdfB7fofO2n47wMtYCqJtr4BU408ahSRadeJ pi/KTaMSRwB7x8VX1K2pY67MKlM7Ygcr0AEcqES6ZYd3r1WfTxM1hhHd7qYuaZ0ii4NvW+HGF r3bghOL8p7DWbiMoNiASu6GuqKoVzyEVBmaPRjYQKGRdsaVwbcPzkUirAC0SGkf9a3en6z1jr X1qV/38cGUlUhWAXesWCxCv8OYoGalm2uR0HAfWgVRIXLOE9/B4qme5+yGv1FWxELqTZSTXSD i8n8m7qjR1VVfQJa7VWfLv9Oyz8CWOML6dNbeEcff78E8QA9QVTjCb32CTX3hJeLrMI6qLdqr OFrOaj4BPmI0s6tfMGB6eYPCqXV0JUsUWiN8axciD9xzBtUgYUJSE+qnm7j9StN9RhF0amd7K JLyJBAXE72cmfQUjHOZZ5WRPYDr0/VXSYmj77c4tGZFUUKFi1KVY4JJsCUUltTYfL2A56A3lD eqXfprcibZuj6lnnfN5a5eHo6M9KB2OXG+tLaNmkPvVhcLuXE8/5DSuWg2VpjnlXFaluPIsyl 1gku5A== 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. Since now tpm_tis_gen_interrupt() is called with the locality already claimed remove locality request and release from this function. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 1eac1279594d..58a53ec534aa 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -734,18 +734,11 @@ static void tpm_tis_gen_interrupt(struct tpm_chip *chip) const char *desc = "attempting to generate an interrupt"; u32 cap2; cap_t cap; - int ret; - - ret = request_locality(chip, 0); - if (ret < 0) - return; if (chip->flags & TPM_CHIP_FLAG_TPM2) tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); - - release_locality(chip, 0); } /* Register the IRQ and issue a command that will cause an interrupt. If an @@ -768,10 +761,16 @@ 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) @@ -805,10 +804,12 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { tpm_tis_write8(priv, original_int_vec, TPM_INT_VECTOR(priv->locality)); - return -1; + rc = -1; } - return 0; + release_locality(chip, priv->locality); + + return rc; } /* Try to find the IRQ the TPM is using. This is for legacy x86 systems that From patchwork Sun Nov 20 13:31: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: 13050043 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 81702C4332F for ; Sun, 20 Nov 2022 13:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229554AbiKTNcw (ORCPT ); Sun, 20 Nov 2022 08:32:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbiKTNcj (ORCPT ); Sun, 20 Nov 2022 08:32:39 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AD67E82; Sun, 20 Nov 2022 05:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951126; bh=S+hhbmGWDO0VTuSnSrMDyNR5O/r2XEHMgIEZ7ffd/3o=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=N8Pr9BhFF3SCxSv1LBebt52RsBq77SoQGxRDE0yI9UTR0SGoSZe3Mv1WFfV8qzIih iAvCJQiyEeLK49eqi7neJWSEIY+xXgGNmKsAlE2mZQ9NJGhYlOEBeIKOEUZhbP0jSI RB3fh/iKG4C4YsVQoqffXEqqQBaQdGKM9147eNYzYHFiweffHrUZuTwBJBQUtFg8WF aTNTJKEISHBS3NEZfezhdZOWrBbt4lTz36QaLu3/ZFU2rQYKOZeIYDhmJFlHdxrKQE 8+N9xJzYHv2gLpnTwmbrgLo/KFFBbT2wNiC9jTZps373eoHVz46ck+gdn7BoUcboYG PmIsPiQZb6FWw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MhD2O-1pR9Yi2qFm-00eOCL; Sun, 20 Nov 2022 14:32:06 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 06/14] tpm, tpm_tis: Only handle supported interrupts Date: Sun, 20 Nov 2022 14:31:26 +0100 Message-Id: <20221120133134.28926-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:pj9FekuflmRkmp8yKItK+S15WfK+mvG73cJI33XbaCDKiXdEYhH RMuk+wI0Bzde5PWEpNMdaJFim3D4B0DSVlWxvSdBjLAEIfFQgYzTqn2bOhnHWRNCIta3ttB E84mMOrbYZRVnU63L6wUOiBGhqcKmc9jnxHuvhZjerzkmai88MzxxHM1oT0Aapi1k8hKRbq BKxr0kxEdOkXMfunZ+JOA== UI-OutboundReport: notjunk:1;M01:P0:6AjY/MVFtng=;jLWczQZvTXNacP1t7vpKs+IaCFW yObG/QcyeDJVIMIkwolW6f77oIMVYXe5kag/9tri6fzZPF521H95EfpN6UdPgrtLNQGYJSHn+ XsEP4tdFIPxqX/oBuE7cuUBaQbQtDsFMMUAJfI0Ze/Y5QYnfOPrmPUTkwY72zj1RBg3DUNTei Nu1IwA/bak6DviOczNz4Dq7x5KiesoJawOCWfRQTM6EnQFT2F5286ILrbLf8X8PX/tNJTK4rn ainZNGgFFqsuxIHvg0jMr4VbMpKw84ANLLWtCnPPJoUKfpoo4BKU7j9C2NvmhPC3neOQPqFNy P2d1hfdErCy7yV3PlpdjHWh/5Dc/lwv0SnvrvWJyYcUuAbtdqS9BxxNtcmlfqqcghmcjwc944 sUQ3uc6a+FeWypDfyYewLQaVmJtpgQdrZUYbVQDs7ddTiZECydGc93tMSu+z2g3//kxaGtgI3 oTmXAO18QOfh7yPv3T2HsWoxu1pu7Ly8dITe2GqHoGZXhThCSty68H+AXoP8m98O4mVPF7Fg+ lzyWwLdQK+XrQ2AboUrPWdviG+wHputox4SVd2FEm5Uuj82DZUtQvyI4JBLYfyvBDOa/a8WZr +5fvqhkNFUq7GXCgEUPW/YKcJuBvRB176Bugkgp3X0pD70bzTfgsJcvNKtjJlq9vzXzfuQTEc FjJ4ZjnHDEwnetV38tmkaPqP/LsCVVJc+AzwzQp9U8Ig4asIXavPsVdWoXxMPzPbcOWhzFL36 0w26YtkMtnC2m8G5Y2dnRPZR7g4ndwigmzndzmB35xY2vvuZoMt+IEuKfAAXR/JKo4Mmklke+ PTVeQlkGjXIfpMOy9qc3Fl6BU+BEv7fq+AHNDEYAH+e13tIiMl/nFa6u/chUjiXCjL5pXVF6o 0Yh3R4IuvObdAdgbqE2jU9SaxNQLu3DV3XTXd9m8Rjn2oI/9De+k536XvNmW68ntEyKGNOnF3 IB5ySa6fjJgYME90gQt52ev7UEk= 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 58a53ec534aa..fbad92b18788 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; } @@ -1000,8 +1022,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); @@ -1035,32 +1089,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); @@ -1091,7 +1119,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"); @@ -1138,13 +1168,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 Sun Nov 20 13:31: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: 13050032 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 AD645C4332F for ; Sun, 20 Nov 2022 13:32:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A779D9; Sun, 20 Nov 2022 05:32:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951127; bh=qYlv/2skNZrIAGuyoSI3M0nAcicGS7Q3OukmLXnsYCU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=bINaJezFcxVr1hZkuhXGGG/2P5YvXFPExjykSf9Aq9BWFSnyc/JG0CKtSXqG0ernX 2mzba7mnHeqr+CI+MxQlACgpMiOgLUiQKiDPcvzYVKo5LmUJC8E1ZYysC3HIzOevwz yHGHpCVB/RiUHpBUL3D21AMXSsSQtRSkMpIzM/O+Hr3/9hr7/aquYtCWt27BLLdZ+2 XswO/1Nl25iqGmwI0O8jXAKJbua+gi02OGgYQRPc/9gonIcF7kEduS5t9XyQ+R7yA7 vLGfUtwqmo3pGUsebmfyl1gcrcQrLj1ezfEAurNIpdtXXURybv8BCbpjWtUODnIuDA Am3yXkp2FwWeg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mn2aD-1pO4dU02Ex-00k9Um; Sun, 20 Nov 2022 14:32:07 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 07/14] tpm, tpm_tis: Move interrupt mask checks into own function Date: Sun, 20 Nov 2022 14:31:27 +0100 Message-Id: <20221120133134.28926-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:pWAON8thYn0lythSLMLr5a6vn8X+rSQV7RGJf4FePhBemJDVbHJ Hewfyiy1zoHiO0PppPaKhgFHzzdJOC87VLsVk9STi0amA2vvqZY0KydBmpGEFPiv5DDM9LX Fd7tTrVkkVkDcP62zmMBR1J4jzv90OhubpvkyUnQ5jEaBXN1GJNQe3zG54pm5ksBZS0J8pr YsENuCqXjdQ1cejij1sGA== UI-OutboundReport: notjunk:1;M01:P0:8z07yEUH/Mc=;A3pki4bQWNkoOeu7W1hASW4PWAp r+JGTVzFFTA4hfnr/BNz6rB5gwW0j/zWH+SzD6VS7gA7246S4p6yh29mk6jemwuqSHqctC0rR Z3IDdr7u1ZPcUv6m+zxOJmHl46pKj1g85IPP4AKnJCR6TwqlqBFj2nHp+8tXqJBPmlaNd8CGR IJ6QdjMCaSNDiIWs3FTcP5+CCF8m1i4NYT+pig63RE0I7EWaRZ49auUxHlaJK0KAkWJvYkD/5 dxBRW0zL7wqz+Wp1JeH0v47gAnDrnW9N9ktJcnv17vnFcI3Jp81xgGKERe+mN0DBnC5yOv/yv MZ61v/wpHVl51hwWoSPTVYzhQAxtZ2dWYqZAxMcOy4dlUUCSE9a5aQFwJ/i/owt4QaLSkidCb RROsFrLFFo7AH3jbLn7G198Dk7Q0hgkUx18P0THrCqu0ajd1ZrMoATmjgSDccFpW5rwGrM5DW KUscoqZi/ZwhGMGXVbIKRvQcaB7jNbN6+AZ0m0YjBcSsnbHuwc4I9OMNQyWpiLAyPoI5y5TbB Yq26m37IruH9lOLydrMmDpT5n/grc5/4SfbBNNI01EW6IFB2pPmXoNv+qM8giVg9BBXlMuxph tQUxZrCoCqS6TFed3LcGgCmuMQQjXYpZaxMm9UWm8ZI6QVQ934DBMIt+fN5RBPCMOOmZV0iF7 +EIBMgVBExnCUiwdRXEdB1svC9cwz0WJeuc1pgZsNNqTCkmx2Lq0XBHxWbaqoijPOC4CL47t7 ZA2576RoFBqrmub9VI1ZzCnLEJVJvrdy+DJOY7ys5sHNom6HeXQhB18WttHi3z78pBOnIf8iv Rz/+Sq6Mo+lCQZGF50TzGpZknmc3oVKTIHFGLXkEgkbTTo1So8cNZWtAHKAo596cqoiFmJ68V /GzG3GLcBXw4wvPlyFsVaKMuGgjFPTTHcmK9l3GmyCpdLVHMfmLXx6UAvGkZn+pq7IqlcYgjR 6kVPQg== 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 fbad92b18788..5ff4ca5fb936 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 Sun Nov 20 13:31: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: 13050033 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 37B1FC433FE for ; Sun, 20 Nov 2022 13:32:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbiKTNck (ORCPT ); Sun, 20 Nov 2022 08:32:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDCE7202; Sun, 20 Nov 2022 05:32:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951127; bh=F2hzzeSzk8y4Ogbig7FSAtP0DXv6VqmVYAg81reycu8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=YoAOpnl2cGULoCrUpsM4P43BSWEiq0m2yNqAU8UnpBomByPL1uyDiPhOhE9kInDVI 3zmUAT4KOY5xcGNCzmwoCqA4LPaR0ej/yIQGoha8vbju9CSKQ/OVuglRsfTgm1x93B uGtVHA/u7PMwJakPWPYJOFQDwTmOMLwI+zpBv6sjfQWbf8bbFA95v4Mvyhz8VM1jza ccPWefZOOGaeTCAuo+YVooRiIJcjgbbW2785wlQx2Ck7fIzFjmKZ67fKaoJllLj1nd mG0uFMPTY93mbro0raOmi3zS0HA6q3fEcEjPJeXaiSQ7i4OlmbeNQ2fhoWAfhkO2Br 9+C6/34Kci7FA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MtwUw-1pDRMp1Z1A-00uIVv; Sun, 20 Nov 2022 14:32:07 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 08/14] tpm, tpm_tis: do not check for the active locality in interrupt handler Date: Sun, 20 Nov 2022 14:31:28 +0100 Message-Id: <20221120133134.28926-9-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:qDOS5QDjXdbwOofh6vZTHErbO+5mCvO4iiSZ5/xFYyCEu6lwU1K 93ZMirCD+aeoLEIT1HWNIrru1jnO8tLVJcMsRi+CEWuexoAttgGDD3fode2VQA+QedOtaM5 N/xzjYqwe7Dxl6JdINF1/tQiH0fRkAdxFLbLPwRrD574ipm3pf6HiX5DRU0/ULJrF0+g+HT y1T7eZ/lZ38apE9GlIxHg== UI-OutboundReport: notjunk:1;M01:P0:z5JKXYd0BeY=;vUttoE07kPsMS0FVFrXeO2dmo2e zkJx0Rw4PUQy5qqtuv3wfTECOF7u1eTEYyvoAfyBKVUOpr2RyDF3AwFXYBfdWt3gmd0Bdxzgf TzKKI17UN+SUdV+/lzlyoRkymCbp+krZ6fNLHB6fAbJuimQd3K7FFnC2WmJN4yKaVQY/MQMLE qw3l/96CLSPGEhKf3k1Ca2Xrksu4rUAEckCvaNS/AzHdkhTmqP1Ld1+3rwM5MFfK/FWBjcc2c ISeOu367IgxXqgBA/QYu86dQFFyOVPCB4vWkpfpq2NbM/+Hq6pUNJ+PfhTBsNnkyu/uygggIL W+ZKkcdgWBrvk3cWyNNOwRmgtGka1kGilngZam1DFRcq71ko3t85njxjiXPov1SvdRz5YjPL9 yk79vTjk9oB45sNED8RxxaG8wBl2wVDPjbnN/VkvTsLxAbPd7qqwSed6ntuedUMTO84tW0Kdj m0bSm3pF3d+GKf5zxaCmSol85+2WsLEXERK8E/jv1N/RqBcPBhFct/8zg8gki5MWw+5NYrXpM UPxuNXoBUgGbtuHV2jIkGhTQZvDGcsxtmPWisqjVnUUs9kTBa8AAP1oVsxnuL4PbSTiHU+xES cEjOi/jI98cwqW0iZ0FhVE3kB/rqW6gxSYpmln3uVRRg+9K3JGf6+W9C+C6P28s5CcRrmtJJ3 D0QPPawxEKF8bVJyLhAfz+kvxVn7GIELCVqOg5DmmGxv86DHUhGTLIcBXEVyTetV6mXy2v+M/ Q5DvNixN7AtaJgNDZoDwnK/QLErjEMRVdHUjCqBMYllmBanRcy7Lz6QkUJD+OwRcaEPYqZ1LJ 5Eso5GI4zd/+3ILsVToGds//+aQIQAIVCRNkHulVxKBAqQRGV7yY8qntedEJCj3wsRFFuJNKY 4/Fk6QP1Q16SO5iPAr1+5fhGuNOQMK9TIdVci2xhaVSTnrqu1NBK6gDtEH6l30diRHZz2mzRm 9TB1pQ== 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 5ff4ca5fb936..d0e5acd6b769 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 Sun Nov 20 13:31: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: 13050039 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 4F6FCC43217 for ; Sun, 20 Nov 2022 13:32:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbiKTNcq (ORCPT ); Sun, 20 Nov 2022 08:32:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 148FDB34; Sun, 20 Nov 2022 05:32:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951127; bh=mujM8XcZPtYkQ3B4FgSH2rYtTxc0/C3MRTBTnMu6dmk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=r6atztG5AplYF5bQD8RKXwicx5nJmkkIFzrgrPiuRAzsXzCV1UMMR5W9dZ52u8Hkr hIpr4O74UVkvPK7em3I8gD6yb8MVMSZqFZDggHLnT8NTnPSKAULdlIWDGy+v4M6BnF wS1kdeopMIsLS7B4SMinLcGw+zV+JdIDnKGtdwpjCjaacHaInm/kyjMOOq3XI+FWOL Al5hrkmXhVVGF8KZ/GO23d0eib56rTvnqdYEkGF5AOoAb6FQzl7akXpNCFIztEd490 55K1Qf0TDQSbYj7PvAU9VTpZDBfm8EnUfZ6OwS/6ByudeOVAJwFWxzs074jifXqdMq I4fQidtqfvD+w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MXGrE-1oQLAv31VG-00Yf9l; Sun, 20 Nov 2022 14:32:07 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 09/14] tpm, tpm: Implement usage counter for locality Date: Sun, 20 Nov 2022 14:31:29 +0100 Message-Id: <20221120133134.28926-10-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:a0lGO7ZgpoqQrWS0J6BFuHx+9CWESj/c6Q3CXkaKzSPe0+wurak gmT+Rn4Q/GpoXapCyXYECv0oyhy8RPfzTYmUJ49mz8wQvrcrEE+vVkwa2XARVEeahV8sq2x wq2IKgT2fhxdbJkfQ0jO4q0bLrGh0fWcskhMJb5XcOWq1fN3W5ePvF9wiFj7BGR5QbY3BgQ BiElQwsIQ4V2ijXngmCdg== UI-OutboundReport: notjunk:1;M01:P0:dtFF5JtrtR4=;xEMjq8XaQR1RpMrusqtbhQQ4LcL xhI7eEkOwhq5BO64PIxbW3krsIdXup0aOfx9EXcoPggXzwIjSsupBMAZHPMd+gqpFOAS39zSO RddG1c2/1CsNtqsSxguaZK03DgnX4+WFSxcNLT7e1zGuqoWM4tKrzwF8gBNO6xwSwvyApI3Gg fW51/Yf9VXZ6nFg7pglaiNKj5rbFbtJGr2UMpK9HdVq83hOFeEdCFrcznOoVRZDX054kqp8ZI S276xOU4PDlv/KMOIjz7xjXu2s1ym4ZpAx1Lm5M3T703BLIw4laofrm5PX8NVsk41ysWMm/nz QhgivpVTYL5TDP+NulT/Htsc9Ulryls2iXgrE1krSAAGPVObhEWiHnWF5CoC9btbg3bSHI7Vx yAtJzO7wyg+EOhC1xqXTOF9KOiohbnxj6cGW0Aor7KjVIhQypVPXPqlMd7esB1s0Ur28Jv9fU jaBqV6GVO9I+aahgNGYp5mr1EdG1TFb3n0CCfhjFgpAe3J6xhbI7qel0hdglJ1yv9w0mePcQw DYrm67rpBPX2GOysl9iFrQtED4HpRTHNksjCU0QPZmeChxI3sbw/ASjAXrKxmKm10rTGj8RgW HQH0S8Mnyd6FC0NRugS0TSj3ov8IK294CYqXT04YVIJBVNZMIEaiDudg4pFkej8e3nzUJRfiW rgMc6tn6Tv/ooJuSk6IKcSpGiW63gPvR8ngR4TRgYC6ouwd9wugw4vvl1PIZX3Kghp+Sx+RHc 1dvjzvN3U40Xlx8RATYYWIeoVKfot7Nr8+6lRiSkV2vTCKi+5PGplRAMzVDvq4SZuLci0wVKM 98ej9q8N90HxUQkJK4Ha3ObYqYhQoiEe5wdueyUuIYNV70BFrqwJHgDwKk7mCPQDHmEW2b/Pj olvuW2KtJCjSHqy/t0bF77AenUa6tpxbPZ1stePqthlPj3ogZ2b4OPjrlEUC+shmxNswinUqb 4w87sw== 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. Since in case of SPI the register accesses are locked by means of the SPI bus mutex use a sleepable lock (i.e. also a mutex) to ensure thread-safety of the counter which may be accessed by both a userspace thread and the interrupt handler. By doing this refactor the names of the amended functions to use a more appropriate prefix. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 63 +++++++++++++++++++++++---------- drivers/char/tpm/tpm_tis_core.h | 2 ++ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index d0e5acd6b769..9aed9c26d2d5 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_relinquish_locality(struct tpm_tis_data *priv, int l) +{ + tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + + return 0; +} + +static int tpm_tis_relinquish_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_relinquish_locality(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(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(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_relinquish_locality(chip, priv->locality); return rc; } @@ -787,14 +812,14 @@ 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_relinquish_locality(chip, priv->locality); return rc; } @@ -833,7 +858,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = -1; } - release_locality(chip, priv->locality); + tpm_tis_relinquish_locality(chip, priv->locality); return rc; } @@ -949,8 +974,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_relinquish_locality, .clk_enable = tpm_tis_clkrun_enable, }; @@ -984,6 +1009,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); @@ -1062,14 +1089,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_relinquish_locality(chip, 0); rc = tpm_chip_start(chip); if (rc) @@ -1103,13 +1130,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_relinquish_locality(chip, 0); if (rc) { dev_err(dev, "Could not get TPM timeouts and durations\n"); @@ -1129,11 +1156,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_relinquish_locality(chip, 0); } } @@ -1200,13 +1227,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_relinquish_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 Sun Nov 20 13:31: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: 13050042 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 7DA7CC43217 for ; Sun, 20 Nov 2022 13:32:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229655AbiKTNcu (ORCPT ); Sun, 20 Nov 2022 08:32:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6017CE33; Sun, 20 Nov 2022 05:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951128; bh=Fh91Z/S6CdFbZcIlWAtBWi5M+Ufp4fdLO7yRx0mA5co=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=eBvdx59MiCt7nWfZqJpVdNH00Q+524VzOGZt5Iwpnu/O8aACnEjsN/r3KWjXnHVS9 jqWWkUkabri9ZL7nf2K3/6dL9En7XegauqEXx1eJE8QqkaH0mFpmQOlWFuAbAcv0nZ uH9HAIEFPnK6o2zJLDwjpA3hx3ij9oQypKWNeP62VF/fj4fZs6ppnF9gH0IoKqIUXA hI4cSQE/AYxJWSpp7x5WKfkIbslPt3j719PrqnC8e24t/+iRe5T+FiY6jxFHBWOqet 7fe5tqFo7Vzdvq+2hucM5+DHqxvBrIMlyGT+SUv2+TNTTUY0mBCwkO2W7M0pbpM4BX D7V76EGkHapCg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MBDjA-1omFmQ0MFq-00CkYD; Sun, 20 Nov 2022 14:32:08 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 10/14] tpm, tpm_tis: Request threaded interrupt handler Date: Sun, 20 Nov 2022 14:31:30 +0100 Message-Id: <20221120133134.28926-11-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:eOWaNTW8FLNMvyPKVdWuy8VMWOkkayU+lKPsQWbeIJ+zIUri7QD fQHMBToTd6EmbYjH4xD/EZ/89RUU5GzupzCyP2hk+prD23Vis0/SDMyGp8HW7OfbZZ1jkbh YptTTe415Q7YxRuudPV812H5jqrp66HE1/LScLLxHyTQ1p+qulo4lOVRGryMpLgYXaSfGFG nZonkZ+NtssoyLQG6HluQ== UI-OutboundReport: notjunk:1;M01:P0:9dwm6XbUp9Q=;gqt37mfZgKTSzuXO8S2lBU6hWrU vShXolsRIQR9cMOgiNNPT4yanYtb2Z5NSk7c8h0nN0noCaTKEfb/to5TYXQEo7LK8/pn/mCKI VtzI5aNV/8oUaFNuvl7QSl51J3mQiIREjsckpk4Nl848cPUNbDwQuq0wu0auB4gfJv2lz5IKN aMQCI2QU4WvzeyU8YdbuqT7Q9FwrFYSVt+rm4QYcnC6KtedYChlFueIBdlzKpziN9Ww74wVry flOj+SmzZTx4drXWcNHVOATQTrxT2HRK5ke6qjukVjKd//f4PI1d18lk37um+nGkyRUkR4Q7X MuFQIazC45gURjhCUvJNvBmxMG9xUKSawMqYUEkRt464Jx3h3KhkDu/4dzMdhoIL5R/QjDaiT woNJPcP8o026UGBqFnjsYHDk8k4Gjz/fYE6JrS7/khnzkOzehR1mdlAdO4cAYOEQXQD+86KRP YlS9VHGZatcyvfTblqiYS1HXvfa28Zdkby6d813twthsjZ5AYB5/qclVejR1rrLAyZCMtcbZF 8hwSG/UEgpG9tcquw0L7GZpcVhnT/WtAQnKHHHS9bX5UGAbxYwVX9tXWnpbdGpPRiEOIaU9li k8RY1ur4PS5cdl0sLxp1uiy7N3YvcPzePErgP9VgDvxeM7rTfGktDd/Q/I9/VsJRQbs6qy9zV vFlcBMRiWGfD1jZQrcwpAu1mf0EE/puQh65sZKWC4Gw4I4W+WKnGR9zyqi4vHiEWAj2Yf6wMr TYuqHAAKNUvGVtfuAkCgeAn3qb1U3SifUaJS/+0zYF9mDu0cLHjaD9qGGEqe1U99Bsx1W2Cpt dlcCiIREY5GQz1BmLamTaM/tKdfVTxDMfiRspFXTaK9LpliJVLlPX1XMK9mWSGOCK7otUPZX8 qarwIJelf4Pr8T/370LivR+WPiZ081l5cVZ0DzMTDw+wjEqhJ8KvOr6bXkBO5pna7JxOJuvHE 43JglQ== 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 9aed9c26d2d5..6c765a4406bc 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -804,8 +804,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 Sun Nov 20 13:31: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: 13050041 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 5EBE1C4332F for ; Sun, 20 Nov 2022 13:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229713AbiKTNcs (ORCPT ); Sun, 20 Nov 2022 08:32:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6848AB7A; Sun, 20 Nov 2022 05:32:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951128; bh=oScRVbxrfAZvMb4vGMxtk0THIEPoRWv4PH6mpzzQxyU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=BIsKDu9oeKvrALhGSAcrokwQfOIXZZdmtP22KCKbqiS+dD4mhMEu4dRm5H1hRBhKG ZnoutdrPJewrCEBcauz1gcFlvHcGsu8cS0pQCU7UoeIg/1ieF6eV03XjWs37woIL64 n522vv32jRvY0/euLkMlUApdc9hJ4OJkN5Qy3CAtrnPCRmbt/7uHfJDsiK6V9n6URD 5uSMLCXMVoODZgP99ZyfMWfZGEgXWnr7tSe8gp3i5b8uHg1PvPOCrkOXpYZchqcJ0o T8YxJVVSoL/63XURzZIV5OAG9K65iOL2/mJuxBTyNbc3st37kAcwfhClAriXJkBJmY 3TSND06Ta8aqg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MGhuK-1oiz3S1l22-00DotB; Sun, 20 Nov 2022 14:32:08 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 11/14] tpm, tpm_tis: Claim locality in interrupt handler Date: Sun, 20 Nov 2022 14:31:31 +0100 Message-Id: <20221120133134.28926-12-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:84xPu3tCUK7zirPgmWTPn+CQfvQtzq9WkhaRX7+boR4TkLhrnOf g79mgN5DxYpBbTu+2iAPgUpC+mRLb8F5Toqpr01QbqCVvNAFIEVo8Oip6IwFpMtFl/sdZ0A 0PPkjD6FApCR4ldNCUga/kuiNUP+mENaq6xHCPkQJLNjw5t1dRtPKp2zl84pvdw2L/HlB66 nbkO1VEqsCOYCc3HfdfTQ== UI-OutboundReport: notjunk:1;M01:P0:38sDud5K77I=;2r4LHhx5wFQcp81SQEy+mGfWmDT fnLE8e969kQ8lOHGNbx2PbfY3myXkYjBqa1879OBiYEi95v0qusWI2Kv17iG3yNxdD0GdOZOV CKA5N9MyP/oTfCjerxtXD3b1W3nQ7H1QAa1Ffz0nWd0hsDP9hbqUxduthWKPPP1XPvdO51oux zIm9cM4xoMdTsJYq6+Uzi1ywTLNrNfjE1EuJxPTCHpg8/yFJblVaYPz2Ue/qOYT54zX0qP45t ZMTgcj1gybtmimxoRnSZrIyzaEp+cZsrPaCI95b2KqKpupqjgFybhF3D4XfLLhdQaZWvLY94W qyV5cGp4YKuaSJEvTQUVZncWFTKungOinQCx7U349SlGIPlMsU4WAw2r68A9T8V6reAx5JpSo Wl1uZ4co/o0dTCTudXXLPVzQZx618ZQm6k591m0y2AgFYVy0gqNWh8MNiWRjsYjKxZoWNqnYJ ql0NQnjshQ5nlL5/yf68Rx/dj5hiEP6YG+XBAH/ysqH7nHj5W+uVvY7uR08xklJXbXhtjTFD2 sNrTz4EqFU4YCe9cH1DnUO87VGgN1qwR9zV/CKQm1dCoWQoJPePE1PkBMEMlwU28q5DccNW0p yj330R+jS62JWu4bO9xG4yebvXjizW/Sikfwgc5wrGuINFzLk56uJDCXk/PpFLTHrrkNeMSpz xnq//WurEtCX8pv6cDC9+bIW0+jdYi0CB/f0YSPKeaiM7ppxka2zk7ggl4iTWtYgTVxMldtdI uB/7m7fp7MfdNFN41UI7qgNxvjpptPaZnwr1MsDWQV3rCTsVtALFxnnKUKv4yqVR4ZKsJgBLT wgIjmD9EySj18BkN3leeWgcmU+dfoGw2NeNPKTj+tnuTMNbWcRn7jrl1xhebr3oFJTDZwvEH0 1XcPL3/iJEjyfHulcOGOtEU1TpZW/Yq2J2omPHV30qRYdmyJBrjfBQIqsfEbHbs8JUO9NNJjL HrXqOA== 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 6c765a4406bc..4312c5cc13da 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_relinquish_locality(chip, 0); if (rc < 0) return IRQ_NONE; From patchwork Sun Nov 20 13:31:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13050034 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 2929FC4332F for ; Sun, 20 Nov 2022 13:32:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229773AbiKTNcl (ORCPT ); Sun, 20 Nov 2022 08:32:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CDA824C; Sun, 20 Nov 2022 05:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951128; bh=4OA7IK6FYkk305Zhb0W1evKbz0zZ40AwmsMipD4BkLE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=NSBTHCpbkjFFSJ2iELowShWXLJ/DsbOAcN5yzEAo+5jUsmHpdecwn/PEWEp1OZu7x +iZ9Dzon0CDxHEUAPQ5/wq95yje7yK1+Cy3BBC9vQuXdaVn3YrEJqQyJXgP9/S6wL6 es5TT7Kk3kEZVBCG//62/vJk6p+9guMF+uozKh29uAyHjYy0V+VZTT0AEHOCzoxPgZ D8tBINVQEzOIHDGqVDgjx/YSXg1UitREpki5ezClrMiita84qYb5NTRwDJH8ourAgn XnHOArEWN433lxP1FtaT/ia5SgJnq3Za8Ej7t8AvrspcsVpjG/vkhdC4fp5kedAF/J Kmbj1Tp1/rnow== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MCKBc-1onMmA3ACg-009RAT; Sun, 20 Nov 2022 14:32:08 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 12/14] tpm, tpm_tis: Claim locality when interrupts are reenabled on resume Date: Sun, 20 Nov 2022 14:31:32 +0100 Message-Id: <20221120133134.28926-13-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Y2Bn6bdeDl3t3/ithIn9bOFj1yJNMiWUB6ywXGw5LG20I8Pov/9 QvJYibFa1pdIC3bTtDU+GUHDY24TPVfdTvJ506nTc9DYSqmXZ7vevwNzbaHLe4jtpG194c8 mDP0STxKk2YNQE6Yb1aUsHsM6tN8ouuh8WkQD/JMwxUCIoJ3qGr2Epui3fgaG5ZilWW0boB ZCZ7Hn3YNez4hQeaejUyw== UI-OutboundReport: notjunk:1;M01:P0:Nok8fe+gyn0=;mDY6JN+z9tqG7De91VyS9iEMns/ gRYGlqR+3QOdsfOPZlj51R4mCZZ3gnl7iSQEVPvdA5JHovRI63axlIg/Dd8Zn+Yx+daiPwAUK HeHDGD6ymUE7r7YujIyVkNM9HUjoCQ6ketUoT4ytRki3qvgisQ6jHEaMfc9MXFHd7bVj2sMJ9 sO5E2suzurAVEnhQD1Kz5qMcYTQmA0VCEuDxoyqYvDEjzQxcvG/wSV6MFc64UVOA0MTePtZEQ c2hTBnGXmvPHutIHBKuxg2Z1cfHmaF8DF/gFMHVLfO1YBvaMc3Uc313kt5KTDCFU2cejsxdxd B290wl5KsAXVVIGLDX8TFjnNYtwjmk3NW64Gzni8UVX49iLwx2zN6RbMSuAtqDwY6zTyJuJWE JjESKjwNswHIIeFSLTNPVW1BP2QEiqeYzubFxjT5jObf4j99adDrLY0cDWrvI082D7RXTA3s+ LZ4khSBzcT3MK8pVu1wXxG7AI0gLv1y7Tav+O9IYhtlt3abCHluaLeUNNRIPori+v3/4z/cx7 yA0H0gVqUdp2ZR/wNL01kExlP/AyxZHQlOQOcRmLe8JzSN+hbmpSxGj/a9gUvk5oxcXRTN2Sv iaX+BcYq6fHLE+OYrlz0miHQMpQgjO+9wMjIvT73GBblzARx4yXhVkiUa18+bNLRTNp9a9XYw Hit9BrdAquEehZKoQqKXqmZzhiIaVFe+Usca+m7AvuHvB0h3kIJwdmOEj+BMKelzGctTFeq1c hGe38Kuo4V7pzXuXk2mqv8gQesdCNGEQ/9Oe+2GvxCTDvIXKnqbjBQXNMxGnIEZnfxsWnSQwz B+KvkWWEaN73/eQfrrNG3C15YNkkOZqAGvUNamGXNjfkZmoDogVZgRxHpeC0AN53WbaklZuJ7 DUpVv3zhD167/NxRthzyuGqxgU3yh5XbSI70YPjlKydB+w9BbZK172rNC5mVfkIi7RqAqWMIk bIVd8Q== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo In tpm_tis_resume() make sure that the locality has been claimed when tpm_tis_reenable_interrupts() is called. Otherwise the writings to the register might not have any effect. Fixes: 45baa1d1fa39 ("tpm_tis: Re-enable interrupts upon (S3) resume") Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 4312c5cc13da..2514e60f6778 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1220,28 +1220,27 @@ int tpm_tis_resume(struct device *dev) struct tpm_chip *chip = dev_get_drvdata(dev); int ret; + ret = tpm_tis_request_locality(chip, 0); + if (ret < 0) + return ret; + if (chip->flags & TPM_CHIP_FLAG_IRQ) tpm_tis_reenable_interrupts(chip); ret = tpm_pm_resume(dev); if (ret) - return ret; + goto out; /* * TPM 1.2 requires self-test on resume. This function actually returns * an error code but for unknown reason it isn't handled. */ - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { - ret = tpm_tis_request_locality(chip, 0); - if (ret < 0) - return ret; - + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) tpm1_do_selftest(chip); +out: + tpm_tis_relinquish_locality(chip, 0); - tpm_tis_relinquish_locality(chip, 0); - } - - return 0; + return ret; } EXPORT_SYMBOL_GPL(tpm_tis_resume); #endif From patchwork Sun Nov 20 13:31:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13050040 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 66BCDC433FE for ; Sun, 20 Nov 2022 13:32:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229644AbiKTNcr (ORCPT ); Sun, 20 Nov 2022 08:32:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9C4FB28; Sun, 20 Nov 2022 05:32:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951129; bh=E6zlWIm9oM/GjzOpdjNAuGrLapusFr2z5NlJBYv1qs8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=i2h2mOc3C3vVDsqj33TjYpssnck9VB33EVvQavhM5O1mXJ1hes4o2R/cYv0TEd2Eo wlSqFrpy/oVTQ7yNOWRKiJLwurBOgFekfAos71dho1uqrQJLninyfgdRc46esrVKQC KZDEMoQyD2d5FyM/1h91YM4Y4FnTlZ3AFZ8JF8shMOzPA3kHjbvLKQJeDQ3RF8j/dZ 3sUgXv3aFrSyoQ5B9S15Fw4SCgc+eIkNhagKI70qEe7fpvzQ6dVIP65fzILWSeBEOi FvC063QBQRC3DCnFXziokM5zVJTGimc+XTQQ3jjNmAqPvod2lRdRljRp6oaeki7iHa ei3WJIpMU8hLw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MTAFh-1oV00k0XGB-00UYYC; Sun, 20 Nov 2022 14:32:09 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 13/14] tpm, tpm_tis: startup chip before testing for interrupts Date: Sun, 20 Nov 2022 14:31:33 +0100 Message-Id: <20221120133134.28926-14-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:o4Yv8LXi3e7EPxUvPlF5naCJKcyg/01QSCkduQcXf0VhvL/9xWN 38/8XEupEFIFwFL7cLZJwOr7L/zZd4ME0aTqvIJLPDO7FlH1VMKTHPX7/3rVVHaijWKxRyK GcILisb7Tld1OHTL204XKo21XVuoFoRF5UQWzJdrVgSmevwBHpfzW52gdnHDkaS231D9lqm X938WbCORj9Bk02IkYABg== UI-OutboundReport: notjunk:1;M01:P0:06rG0ZS1J/c=;RSMRuY/3OKsQ5trQLbvspA8j/tt me5d23IVCWFvb9DvjpfT3gogOJWPob2IOX42+dPgWH8Rig9J9bLaYsp9VAU+R89TBPaGjmayp KvQrZFVxq0HNc1pVmzXwZ5VKs+Qf1QDMSS4P2Ptbg/ruYg2mgdJFxHC+6f4b+um22BePTTPQo WSgDdPe1tcXJe1+41jfa5bq6I1Kx/7rHjBOr8JgME4xf4P8t4fsiCzrUFJH8KgJYEWGedMVny fw4yLh/CTjlS5Dz+0/STt7jcpUYWya2aK/GJ8n/5Xk4aBCI9H7ZTg1NsLWYmDPKyd0Gik/YE7 Q8LYsTVYYK8e7ycG17s/njOqHP7i1q53ZSrS7AuthCPiEiRykIujAY9tnE+wFknRj9jxSig4M 1u216Ww5Nvvd4ElJFUgxZm3i6U9bwV7ehWjpKKW3uodoQIF6foU4siPwl3qUwL/1cqjAj+CcO y7KjfmNQk58ZGiGueLWORK39KfgS1eCDwzC2G83qbh0Ac9koKaJ0GK/GffcUg7blvb63h9T+A zTXg7fv/7+gsaU8po3/0vR3E7aKxJlJVXUONMiHX/5tpZ03K8rYfzR0mMweYF/SAomPcNSc6O xsIBy4WJ5vriUBYSGyUkNxYLTFGb+8fw9mC5hlZ7dqrLf2tPcRPvYydnCFHXsRE6zq2B3+u6U tpTDEvgjc+MMFc5uBKGEtG35oqRUDu22KdllIxTkxOHJowUFHXm4S72yp0PYtuffLX/FFuxGX jsCSWm/haU9h0bz6AW3XyciivTo/I79KshCxmrn5t2hFeid96t1a/l5Ww9OyHtVMYRDz66wB3 0UBjX/E0gGuRvwxW70T15APOFvUz8ZafBbxSDeyBiF3MhnRe1VQ2o/EdgzYeK9LCFQcKW4VXx jCEFguNv16Pd1hb7fvAPPaMgLHeXs8ywGvbEzTvykYFvtTe3zkrInXCogjFxT/qi+8Am11Mf3 7AtzgQ== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo In tpm_tis_gen_interrupt() a request for a property value is sent to the TPM to test if interrupts are generated. However after a power cycle the TPM responds with TPM_RC_INITIALIZE which indicates that the TPM is not yet properly initialized. Fix this by first starting the TPM up before the request is sent. For this the startup implementation is removed from tpm_chip_register() and put into the new function tpm_chip_startup() which is called before the interrupts are tested. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm-chip.c | 38 +++++++++++++++++++++------------ drivers/char/tpm/tpm.h | 1 + drivers/char/tpm/tpm_tis_core.c | 5 +++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 783d65fc71f0..370aa1f529f2 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -543,6 +543,30 @@ static int tpm_get_pcr_allocation(struct tpm_chip *chip) return rc; } +/* + * tpm_chip_startup() - performs auto startup and allocates the PCRs + * @chip: TPM chip to use. + */ +int tpm_chip_startup(struct tpm_chip *chip) +{ + int rc; + + rc = tpm_chip_start(chip); + if (rc) + return rc; + + rc = tpm_auto_startup(chip); + if (rc) + goto stop; + + rc = tpm_get_pcr_allocation(chip); +stop: + tpm_chip_stop(chip); + + return rc; +} +EXPORT_SYMBOL_GPL(tpm_chip_startup); + /* * tpm_chip_register() - create a character device for the TPM chip * @chip: TPM chip to use. @@ -558,20 +582,6 @@ int tpm_chip_register(struct tpm_chip *chip) { int rc; - rc = tpm_chip_start(chip); - if (rc) - return rc; - rc = tpm_auto_startup(chip); - if (rc) { - tpm_chip_stop(chip); - return rc; - } - - rc = tpm_get_pcr_allocation(chip); - tpm_chip_stop(chip); - if (rc) - return rc; - tpm_sysfs_add_device(chip); tpm_bios_log_setup(chip); diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 24ee4e1cc452..919bb0b88b12 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -190,6 +190,7 @@ static inline void tpm_msleep(unsigned int delay_msec) delay_msec * 1000); }; +int tpm_chip_startup(struct tpm_chip *chip); int tpm_chip_start(struct tpm_chip *chip); void tpm_chip_stop(struct tpm_chip *chip); struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 2514e60f6778..b97cb325ccb7 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1128,6 +1128,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); + + rc = tpm_chip_startup(chip); + if (rc) + goto out_err; + if (irq != -1) { /* * Before doing irq testing issue a command to the TPM in polling mode From patchwork Sun Nov 20 13:31:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13050038 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 7ABC6C433FE for ; Sun, 20 Nov 2022 13:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbiKTNcp (ORCPT ); Sun, 20 Nov 2022 08:32:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F1CF326; Sun, 20 Nov 2022 05:32:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951129; bh=b2p9orljkPQAtfm2cx8Ohv8A3ug+yirHYm4KhuxDbQg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=cLJ3ZWl4KL9RDxAMDQazxg/pLd+UAJ34UD2jdHsrA8zzTo0oZuodjjbrCIaz6ztdu 9cQ11nbp1mfazF3yTPaPX9QZ4cZ3GkCm3iqjKhSud4umBw4KGR98KnmC5X3fbmvoot 6pgPZ2vcyLUDUbclQLgzDfdyBmt6AahXVjwkgd7XWXvhxbwN/J535tAo3mRPw7qS76 OL75adGNRqhq8oOOysn3HkdJxylcl5o5lIyTJldqnZWL1SbpWmWRtVApJvWWwGK/hz mAaZUx3xI/K+0u1xiKGPtjNb9Ho8oQXYDJ435hDGrPG0sqfEdj1accCwPnm38sOizy xV7mWRLrqQRZQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M8QS2-1osMht1t56-004VDT; Sun, 20 Nov 2022 14:32:09 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 14/14] tpm, tpm_tis: Enable interrupt test Date: Sun, 20 Nov 2022 14:31:34 +0100 Message-Id: <20221120133134.28926-15-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BKMRYOEhyfnkSjTu8QNQmyWBrZ0shgweC98K2S5I+em4v1FZ1vw xJm/V0KgsjeT2pkq7QRrr2FLo/CfBqDLcYP60wIBRTvSLhV68R/Ams+kdnFxcYt8jb2L3ou pZX5r3uJjv09RWyvQxM4GR0ioUKekCkRPUT1LtkvJkbc4AY47ouqSRekmuK3Rmai8TxViw/ ynwEGbIg2JzXb0ffAcbEw== UI-OutboundReport: notjunk:1;M01:P0:mrSM3TH/Aok=;Dkll088hNQPY5V9rJi8UGOJXlhK /cloz7pNK06KOjCzCC7ZWEhOByE0aQhQh/yKhebkyyVJzoIOi7ySiRWEn7/k/WVebebusWZW5 igSfzp1b/aMLUvcKxZ0zBROBN7QemmtzaJkYVUUVIYx1OAXtndVQOj7LD47Qy7MFIA8yTcdcu qUnFLg3CTqrNLkNylDVcxLqPmjv0m4PhCCFuUBsZnkPHnNrn2TJx9mgPdiV2hU1Nf/Tnm+HMV gvyIL4YVTruDZ6U6OWhwyl6YTlpJ1XImMPm0F9LRxTegVJmYB18oDaf+3jtySuBYVA7f+6a+g RX33Z+uitevMgTTkiEeXgMk2l6AAlLmz/jVusjuAheRxqy7PgDHSVepwAPTGNXvMLSHnwS/aC 6MJr5oUJdDfeHFyUgYhpQkPf3HHdCds6xObHFPFqFpd2JP8mSSXoo7zfH72QfwjJ2Alyss9wY VQZy9Le8z307WUKTx8nRijLcRWh0a8i5DhlO4LxJ3vYDkUM7g/kkduiowOiFTJnFCDiR2C2Ei vRzVFdQgx8HlUQWES9VC/LfFuIotKfPMYFuHRl/8YSF0lfDyvMgGchuTLTDQ6W8VRSGivjsa8 rBbP2n0JLxVleUFmJJV1qTqWw+ysuXQa992+eD9mJZuuEY0JtOQrgHurJhlBj0kvGLKfxG5Zh Dpa6StViIIfspolhEyzYsSG72zgPgrZFLxlgWDR1D11BpSgGWW7iwYBV5Jkx0QzjUn30aVTsJ OhyCQYN3bncQigf2207ca5wL+fT8yREiW6y7ZroM4ZA40IoaVAzwQgKWT+JmHioetZg6ZmKJT xhXDqh+0DMn6eG1DEG+ch7yUVh8j0zxQKgMTufJBCZNFIIz8T6h81SA3vDnE6JWIQTfwj4hua uypPw1ZsctNbDOWQtnjsxDyRpMr4Ngk6/4UYYqNKEKsEi5/+SeMOetD5l2aEExv+qyVhll3ZZ MPrTOg== 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 Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index b97cb325ccb7..602ca4bb8e2f 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -787,11 +787,17 @@ static void tpm_tis_gen_interrupt(struct tpm_chip *chip) const char *desc = "attempting to generate an interrupt"; u32 cap2; cap_t cap; + int ret; + + chip->flags |= TPM_CHIP_FLAG_IRQ; if (chip->flags & TPM_CHIP_FLAG_TPM2) - tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); + ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else - tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + + if (ret) + chip->flags &= ~TPM_CHIP_FLAG_IRQ; } /* Register the IRQ and issue a command that will cause an interrupt. If an