From patchwork Thu Nov 24 13:55: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: 13055015 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 22F46C43217 for ; Thu, 24 Nov 2022 13:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230223AbiKXN5F (ORCPT ); Thu, 24 Nov 2022 08:57:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230138AbiKXN4g (ORCPT ); Thu, 24 Nov 2022 08:56:36 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D48116067; Thu, 24 Nov 2022 05:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298170; bh=A4TNiZ1MIqgxBlywM7kePzrqXJ+tGCscjealDs3aYxw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=hagk1JxJE4VdMc0GZGSSvhM4IGCJC8Jth77FtedhS4ETNsascWJ5pRIexQybW+tKe oELxZe9XBBWMwFY8ib3l+KHru9F2/28kxgJ4K6Y3oOq4VCa/LZXm/LIYR9WjqBHThf MQUhtojT9Udarjn34rXeQsFpGQHBnIwUTHC8GeAkz+/4ziJzDxtKRGTzqUyoqHMGsB DEuzjN7QuOHcNWJylfvuiCfmtTj2E3Cu96MoA27cuw7jd/boQ1Ay7mkBso6lA7F/sB P+oOfzptf5bRPxFWwD/DPu8e9LhNLATRBaYLhyBGfoiTQqcPkfpp9r/B4bZFe/VpCm 0DNlajCZ7lFQw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MjS9I-1pLxfE1AEc-00kulG; Thu, 24 Nov 2022 14:56:10 +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 v11 01/14] tpm, tpm_tis: Avoid cache incoherency in test for interrupts Date: Thu, 24 Nov 2022 14:55:25 +0100 Message-Id: <20221124135538.31020-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:MQQR6Jun0BPLpfZQKEpXcjYTEKKRsXbOtOxBKv5g8XyUjQMxeL1 wdCg2l+1GnKsuAMeRdZ9RMLr663bQDOqDCZdUT3Q5n5ssMDs8rJItbYlVwk8bvokECh0VpJ 8RB4mfmRHGFf9B4Z39gwFECsuwY2YUMJZP/c/znwPoaPOepJ09OhoBSq6P6Uw+W30ev3DCO gjDdjHI/G7N/l2dN6P/YQ== UI-OutboundReport: notjunk:1;M01:P0:pkzNZjHCOV4=;khFbfQ6MIG0InRJW8D6vRzSBJKd +BFcnCShZ55mzyUCUh3BauK0F6RF3Lv3M1d7fSqovH7+O9NUX6EM82AsIxIywJ7h1ze3lRYNk z9V63qZF3gj2d82fF5ehzadQVk2uE3CcHYRmpLVfm3FQY2YcI0mhmZ86ViFf75CqtFIOPRV1R rW42HTswseB+wF9mZQeY1RgMj6IW2WTAKB66itvrp2YZwtQHaylwMpYB5m7nIQxr/BM66MGuY h46k/VPVUcMuUN5VuzrpsFvfLlaAe9UdYVEehRnMFhoHyIF83yKptelszm+zIpHxV6/D7vhCt JPbv946ul5kDsZaPE5HLAgbXgngLjUCtqGv5nmuQ09tVDad/+nb/K13p9Ba4eQg6hgmU/DlZx 6EZAEKqJL6ETQLRFym2EsuvAx/bBHtbmtMrcQQ6vu1vqYBXl1oFbeuQ1L8397NKXFnc7A8iSz GoGa8aWzzCoocVyTLbU3ORTfSIfiUmBC3DYgJZR7t59jA1mWUM2KiolRegcQvDSZlweNaMUC2 /7CAZgnagdIaKPyttuCgTNh5wHpeqTMDKxZdhBjCqDe6+FkcLylAlSpaxqHn/RRTID8GaeNEq OvYq9giFrrTO/h7z3+/qeNSEci7MxwJTJvswNiQSMEapWxtA6F7yd8vVNs4TK8bscTVDBFd6T nr2L6QZZTkpYzsTWVRXMxuzW6lfFi6evdoYCOVHFxSmL0RaaWhYF7Lc2vhUfWTd+ZUnXGWlnC zqIc1aG6et6OVdPw1jk1k+sYyOMjQDkrx3qFwus1/Z8tfRqvthoHSFoSDwgfpPNZ/eY8Gjzt4 VZaL1k5V29raudesjEIRppLOiO4slZtzJmgFDGfUN91DCnORN5bSP6jK4V62jXNmVfuTMy41R F1YPfZv2V/r2GG2ytN4s1PaEdl365uikll3yaqVRS5VgDEv6WleG4jjM7o9rT6n7qtj8V+8oy O3oUng== 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 Thu Nov 24 13:55: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: 13055018 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 68496C433FE for ; Thu, 24 Nov 2022 13:57:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230232AbiKXN5I (ORCPT ); Thu, 24 Nov 2022 08:57:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbiKXN4f (ORCPT ); Thu, 24 Nov 2022 08:56:35 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4A90109581; Thu, 24 Nov 2022 05:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298170; bh=1jiHlANZ8thD5aPn63BXGYT+VamFBFNIAjBcdG+2s2o=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=UOWVQLAEwRmAhazeSMBLFFnEeZy4gaNKKbQmhUqSmkj6Ds/Ve8rIw9q2g/zYhgyS4 073XagHy1yL/rfdAnUv7rCaphbUI7buTJJQWBFr/+wjFBL0IGjG/vC/WwoHsNxDH7a IwMxByKnRINLR1UX/1aoCR6xfAtkAtvYxIFSAdX54CMYfF1qVQqe30y0u/1JPjNOBT h1OSSuf1GrbwBERkRaMAREm82q6wx3mKvQdIejQyuxyyKwtsL5chZexwF+HNYEvvHA ShZBo1Z2+XrNENaTX2Nts2UX0b0FdKTr1R8CVpsoO4g/JTxsuvl73DnsJPlYRrrSBz B0znFO4OCbJ0g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M7b2d-1oqDQ72fZF-0081Ir; Thu, 24 Nov 2022 14:56:10 +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 v11 02/14] tpm, tpm_tis: Claim locality before writing TPM_INT_ENABLE register Date: Thu, 24 Nov 2022 14:55:26 +0100 Message-Id: <20221124135538.31020-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:DZ1Si0DEmG0L5zHqGquL0G/lLXvo4a2ppnyqcfrgWJfcYCf7Evj S3kJKA7ORN7oi5wckuLKqgRyKtpzDQGPPW+gaaxPTAY/62eZs2hEzMb+LktxX5jXaPLZT7W 4UsVNmm3BRmeZIBJvlTodcp32nv9qgYVmr4gNEhMO7lXPO288X73suCMIwKiacAY/U5o+kh zPPJe5zd2kaImK7yWj7JQ== UI-OutboundReport: notjunk:1;M01:P0:+7AxXzLltVk=;pdVShctUccjd2fZJI04dQxP2BEN zjUxWppz68TTq2Cz61wHDjPFHD4XPz55tfD3UG72J3zU77dHfFGT+dRUwtk8G1HuLFGCtwdxv rnDwaBtx8+v/d9YRMH2yIavLhYVwyz79yreWrcHLjbhl217evFjHK2TPnfIb2iygOKTwbSqB3 gIjAWOctPSohtyq7UZTc+aIKvbkz4ka8JhiolhwPltFnS14+0R9FalLo6c4AHztfDirVPPP+q 3XKPa7L2TcL7RzzOsgBz5STmXEfgczQkl+GoxEaAsYbCDe+kJEdYXPpfsrRVDGb6s9ZdKjuvf dUY9/r+X7vvpfNN3bdFGaDuf9UXnD8QW2ombbj54EJRmdIhUefS0XQb4kL1N9F3eTal9VvGYh ao/RdyrE8U29s5yMOpEUZcGkLMvYnouTb/6CsxRpMEzbpPsL4QgEzhIwiqWkzCUwrnWYeQv/P 87cVWPoRW8m5cf1Laionh8QUl3jg1Ns9Jlqd/50FxP60nTv6I1NWiNexDZLT2Fk1tzZWuI3ev 3Z9PXh6GwfFvtkLTl0/ivZYqhOXWf4R26xRYNPNliZxdR65NCga85Sf5M7cVszBOoEIJbG/SJ /0/ANPdT4V/f49NCoYUfK4MDqqOQCLwAdMmrtxPuVKyDCxokyOJQtbayCcP17wFGnkGUiCClq Gbu23jugtQzzfPcOqs6YKarckYAzQVtLgldOhu+21u6bny5Z7I5FH22ykDwyLcpABdPuzHd2C TQnyaQvtTIcitTNeLnNCzmqbguAiDt4kCy4D5dZ42tKc3NCWZj+diZLHB/tJYpLEL5eirqHIJ 1I/trltoN1ki/n1CTSX1nAXgHtBdPAWOcav2G09awz/owNnaswUcTDVBkZ3GvyRJHp6xw4u31 2/+M63ZIFK1MCWe8xYE3n/Uc4IMb1cOjfCPcWFmwgkMzZh9z2arIynj7UvqKgjXVdJPVe8mdx 3UG0DA== 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 Thu Nov 24 13:55:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055014 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 D697BC433FE for ; Thu, 24 Nov 2022 13:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbiKXN5C (ORCPT ); Thu, 24 Nov 2022 08:57:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230127AbiKXN4g (ORCPT ); Thu, 24 Nov 2022 08:56:36 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B23ED116046; Thu, 24 Nov 2022 05:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298171; bh=vmr8i0HILdqGMwVhgOxfm//3j+C4M5iWtBnT+hrsrRw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=aeYWtnKXEc4nQzzb3bzdwrlz7OJzg4yLtj9IudBGnc9B+VDwKYdPnvW+V0kU78oFU VEX7a2ngjwnJc8Nop4ZG8m+DlbdsQAdv3QQLY3MrMRIReB1z6kSmG+msV8QGqN3xmO dugS+OIT6BYcl1FQQC9a2AvGkWM8v+xNaf65IHBcWHiyANnmo4TgrbFAJNXThXMCKB hmwOe1eVxr8u4YjM4NdfpEeHhzUBQ1gDIpZ9K0i5FXGd4nkfoOKFZBRCdZzfaPu8us BWLp9H78rm2TGSwuAUvTIbtBmB/qPOIOGoKr0CyK+4PrVkFJPqak1mHSL1kpl+hVzU mMWJZdBrGqy3Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MCsU6-1opN0M3yoi-008p3Y; Thu, 24 Nov 2022 14:56:11 +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 v11 03/14] tpm, tpm_tis: Disable interrupts if tpm_tis_probe_irq() failed Date: Thu, 24 Nov 2022 14:55:27 +0100 Message-Id: <20221124135538.31020-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:J4RfakH6lXbtsfGkrYwY7v5IByUOUdOvSQVf5Cc74pzRKb//+s1 uZCUlng01wMqRHxrd+8wsIdck8EFmK1mC/4hRDdvpb1HEj5oTC0n/V/RAITCJ8aIti8Kc0U OUDsMtfeL4iTStHyzP/FJSyjn78+465o/f2JWjxk6frWbS4dHIMpaJGZw1eMyzAoj0PX6ry 0jkVPHrN7ywsh+wlw2hPA== UI-OutboundReport: notjunk:1;M01:P0:ltTGGu0PJSg=;eIk+5LoGT7XTQjLpNW0DUWjp2Nw jzA33pBS5udjjETZrAL1VKho2FxCsHpjafOJCSzQqtASCj1sPzfWY7SVLGHJ0RhjZxe7BS1yE luJYLg2ZhhNWkudEskl1oUco6ChPSnxWtb5YXeFYAIi518ibB/AUplrlaAJDWa1j269vj6FIS M/GDvDsQP8KjsG1lUv0OfheHfrwtATphwZlDJ0L3LN1l/M2plYNvAfsR6xzDPOWNse89H3L3U x5ANK/79jk1M8Za3Zwbq6yl9QVx0PvdDbNqPwd1BiUEGuqtaFmeJ2J1Bgv/Lquhhv4tsjgB/o h/f0n4s8MoB+ZFJp8q+06E+r76SIyIt54kG4fQefccmo3mfd4YDtzI/QSMrOYvRJTc2xIdhXr x1XUTpwzvjx6TSeicWwq+Sl8/dirjGZeU4ASnyGyJNtJIgf+tHnuC0Hp752QZZDlK3WKbRAnT cLiZ9Rd2uD1E+iIZ1tyvg0EuLLZpycGw4GDlesevlRE4KtlYxvtIfYlaFLzrZGDR5XMYxorm+ b+TJzCdFtZPhxiW/XcRDIC9X0Terwy6khKZfEY2TUNGbqMd/LS4c3t9UL3+0bkr79eYFhJsn9 Qau2u40jUFQRpcXP1aJTZHsDDA0zwJC6rnM7pNJoXqcG+nSDT+5GnAfQFj+1AtyaKpkH1y/ux TXCNyrn80Qa854T7lC9joaYgPCGWvP1HMO6rtMAyp08TItH+Fbb/NonfqQBRPrFvAOvOEkzdl RCRdQ8X6RKyuPwMYfBdSAGXwHTH6+imoj3askaOHNdNgZ7zy5VptV+VpKOkN1qPwnMFyzwv+j s6Jnfw28NLUnMvVAXAq86iV1LX7gX+Jk8vTzYn6K1M4N1Y1QLTi+sozsA7MDuZmH4DYuzBdiO ZsYsVfYOWZujCFBuOa044k7d5ONle9uRKwzEafHBWMP1oBa2PZDQXRlpHkAHgk0up2paYkNIf RoY+Fw== 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 Thu Nov 24 13:55: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: 13055012 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 AD088C4321E for ; Thu, 24 Nov 2022 13:57:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbiKXN5C (ORCPT ); Thu, 24 Nov 2022 08:57:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230121AbiKXN4g (ORCPT ); Thu, 24 Nov 2022 08:56:36 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 959531144A0; Thu, 24 Nov 2022 05:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298171; bh=ptF3+UGs4RT73xf2t1eIkj3kEEU2mVqh+94Ww0mBJ/Y=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=AnW4r+OsnxZ+EYbiLrZC1GEfrkwBMKkGjVbunHu9MVuFBEg8tJv4TkeXrSLD8HVib 2pL4ZWpLDB/eD/XjdwtKOR9haHd/ygJ6ThKqgy9/vfglCvO6Pbo1kuqmRc0bZj3mQY /f8di0hXImAOFVtsTfmQx+PYBCWY2sP79gtebkLS9Z4HuOd91+qjJX3OJKePk60qeQ l8hDjg7fSqtIjxHmL9x1u2WHIQXjKaouDYKWr11xC6htp67F/b/morily0q26F37N9 RYQ40TQZ6JMYnsIVae5hINasFXYcMTIQYx0F+Yxz/OBSLs/U80QpK6RTlJydrAY71c /6JnRskhZrXug== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MjS9I-1pLxfF1RgQ-00kulG; Thu, 24 Nov 2022 14:56:11 +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 v11 04/14] tpm, tpm_tis: Do not skip reset of original interrupt vector Date: Thu, 24 Nov 2022 14:55:28 +0100 Message-Id: <20221124135538.31020-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xa3nABt20tkSDNQZTlmJqGyJFMR+Hbk/kMbprAIaZ7AODF6LfDJ Ga0c6+Iat/fGjI8FJXKlN6Y9C2aNPvUmcmx5LzMenvb2JTFxXVDHdC6ureaQ7UKKFobQMW7 XZbwotp3OCfIyfy9i35yO3DFlo9WhGXR1BKBPiDVYPyWupMdSJaUjIlU3aMBqdP2chOexIU kCDWZSOL7frbQ5qM+piSg== UI-OutboundReport: notjunk:1;M01:P0:2Hr5OHt1gBo=;NUhu4G4cDfH7sTC3pjO8cBUfk7h tZCb0PHuDXpJsMonJd/CvI5LHnzBltvRtPHblBrRTMe5zFPGZSBmlWjqTefk1dH/wNHET60lr MrAaRG4l1xqlw+AEztk4wr1UoiS6tI2dwXuae9XpRuOE3eZVLYJ2J0O86eHVn1ZZBQ6tmQPJ0 Ge7zmvA0ZYoWmruFXMO7b8+rIhuMzo1aXOvI8IIHY0jLKvemekT3PSHPNOzntqA3SwPG+7lUc mVX+T0njRTLcGoWJSiuJFFH4RJrCgwST+L0/cINzUydQbzfJbN1YfpstXTvd8FE9NeHEhbqaI bkG7d8K7NKmauHaF+dZ1tSDhMsn1Qt2zCcNRZgXZ0NcN75qE8OR9x35gWfmKgAA3snMok0kl4 fPJinvr5oX6R/ZrNrqJ7sU0B3xbNsAnzneaCcHxCdTR2jO5VMiXN6U3PG6xjxlUwprDeXoNE4 FUZMvVyz90wGq+t0BSgnjFgMPIHh3oJChdWNRrghoX3GjFFEFqVvEAUJGGbPqnptk5dfkiirr RNdt/t65fxSfRF+HhsZqF8x3SYQMfD24J7pfbAOihuafH3q3z5le9d+juhl/puqHxTjG5QOqb 4hpAjCxlS/ELD80617vknBZlTnXp/49vAQfqJVjEKRx5kFiYHZIC+HMUnWJZd8RkWGTpuhHWD bLfwdAKSTe26fFaf449kTB6P+D080NwhGsgde3udeqt3o/H5V2wbiL0MHDmgxOkCu2nrpSGZG B5UwJmzvN47wxJWSOMXE0mcxWjPENKu/8C57BAXYUCL1XHBrlWi5zZC47PqWil4BLb6Q76cKs hg2Jbw47bupIuN4sC9OOsHMJiCZkdw9Z1qfqqNTbQROvsUxxA86weCLHZ+T9xA1Uo5gOa8ARg vMuYmSUIxQaxA1qjmg1zDKADcCxzIxg397Ivy4DzgSzzACqQg73a84aE1+/+NVZM2ZNaz8NvS OmIYpA== 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 Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 603b82ca56da..81b9726d3ed2 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,7 +738,7 @@ 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); @@ -746,8 +746,6 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) ret = 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 Thu Nov 24 13:55:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055017 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 C8001C43217 for ; Thu, 24 Nov 2022 13:57:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbiKXN5G (ORCPT ); Thu, 24 Nov 2022 08:57:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbiKXN4g (ORCPT ); Thu, 24 Nov 2022 08:56:36 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75CE11604C; Thu, 24 Nov 2022 05:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298171; bh=nfj6LxEEakS1d9oZm1Vln0mVngkSUD4WhjDUy9R8goU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=SIpKaQvo39+/4NrHUTAzIjtNS5X9hGHJXHnX2qgwSeaYMSlJAWLIEIOrpYEZJ5YJb B0FJwZQ6RQrFs2+hPoNhUklaYNeB+c+bHvNV/20JwkWh3cr1XpvJme9DSfu9WDBgiZ AYOnCW2Nte1anJo7A70I0jbPaI0gIS4wOcGbfuyCLvNBHwCgmXLvJQ7694NghaNXt9 KjrCrIwLFuYGHuXZdVXm9Zz5jNnla+R2GMK3sYObxu0LszAQqUkVx9JjcbZLP0uo8U SVXp280OBqTY5qX+yrhhefftRzbsp6nAjJ8pwSucyofUNTAGwhEdvxUN5P7HV6fEZo A12ltdQolCm3g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mjj8D-1pLgY42t7j-00lBsR; Thu, 24 Nov 2022 14:56:11 +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 v11 05/14] tpm, tpm_tis: Claim locality before writing interrupt registers Date: Thu, 24 Nov 2022 14:55:29 +0100 Message-Id: <20221124135538.31020-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:VB7psXmoZkW0IM+pjguIbLL50aHa+0ppnyDiamI4IevQAzorTbS DN1FMlxqHjwgFCmjNlcT78/3720y6XYjrRdytKbwNyd144yREiDnpOfPqeUEm0EIJQDZjGp tEY69lnVO+hH7TRvSapOJ6ScMoYrJ5h+pBUw/wKv/wO4H1LxHxMqeP1ht+jq7PInvG+ddyV 3yK5Qmy5ivPI8+G76VBPA== UI-OutboundReport: notjunk:1;M01:P0:HR9zpvCBO74=;u5PMihDoYh3FpZMRJEm9ZrHdye6 1SNHWZzEn+F0ZHl2nXdF8XG0FN+EbfqlIb8rCY3GUf2RXY2kvY5bxJo6/5XOpopibay6itEoz xhrKNV4nIB48OfkcZzLDjKuoR+vcQ5AFjn7LBpcvoHsfV13GdUraeCE/bPQ7H6hjqGWvEyPKw eX2YryeXpKPDaGoC/4QJgpUN63LNf/PddP1CAJjnZ9hc7moa6J8uonaAcs3cqpLRsxcE78YI/ 6L/+QtrCgQpChjWP9TODeOQX65QExUgwEOAL84CKCn6BPpriCMl/ToqMj/zGUOLrs0nL3SZOo 8YJc9VcbCGoiyT/x1gPRRFRqftFNAxS5fkWeNoWC5HIt2OQbJujvgz9MGDLAqK/CUN9tYcKIp jK1j9mTg9omWDmnttzGcWaPW2qJmne/VPubOIaX1OHTiS/cjXX8ImSz5WP5Pe05sVhMZA/vvB vTFked3bgOXobgiPm7o4BXcSwtTMKokJ1BOVGoyMTWccmccl0ysqFHSNVTbYmV8hMjpoSeZm7 XPcQh5ug9TX1vdtBE4DOh1fx1GGwGADRT1oaYZr3JS+nlugIz/aP4tSnLuIKscWYLzuI0jH69 zMxdjlR5IA5pNOp1wjdXBG+n4U4OwOEgAL6oM6o3hRkfJrxYwY6CRPuAY9ZTFK7+3nggpTgw1 z65G4KJiV5Q+ejVsbUumDicWvn+JPyxeKYYLSu9QCGzmztoPUS4msyJKM5shswK3ZuIeL8SF8 hpsgFRA6bS4BbThyZ7k61tZb6w+c0mGimoLZEQ20WmU6YdXBZ7kQB+aL8al4ET5f6+in/wtKn Z+Rqo4wf4z5Rd7tFlfobyQM63xai5jf6t23bZjMYvBY/jKZw2yLJ1ONWUVqjNQfj5p3x4If7x 3M1b8oZqBUUUt3e/yauhsJsqo0atO3Ql4r/feU7yc5R2wOKJsZiD/Evi5UpjkHbKBJ9sh11IQ Az97XcDFLwnor90Ro5xyscPImiM= 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 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 81b9726d3ed2..49848268f547 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -736,16 +736,10 @@ static void tpm_tis_gen_interrupt(struct tpm_chip *chip) cap_t cap; int ret; - ret = request_locality(chip, 0); - if (ret < 0) - return; - if (chip->flags & TPM_CHIP_FLAG_TPM2) ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); - - release_locality(chip, 0); } /* Register the IRQ and issue a command that will cause an interrupt. If an @@ -768,10 +762,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 +805,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 Thu Nov 24 13:55: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: 13055010 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 8F57FC433FE for ; Thu, 24 Nov 2022 13:56:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbiKXN4k (ORCPT ); Thu, 24 Nov 2022 08:56:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230003AbiKXN4d (ORCPT ); Thu, 24 Nov 2022 08:56:33 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 934CBF5A1B; Thu, 24 Nov 2022 05:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298172; bh=/LIepLLbPWcHWTum88qdQFhReQDSW470FeNeEDgXBaE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=BGJc5p5j+7qHYahYlcBr4a6uozSb9nhA9r/+Los+6iUOxthJE0sW4fFWw6Le/SO47 Z7tq0OWILZrA+TxuS+w+rMlOp+OX31oG6JY4U26sI0e3KnA72zwT7P0eXEcvRs75pe pljZnhRSTCTpsxpcYHJ5eNT4VDbUmBLuKqAQipaJJi0kr38ije+zO0RSHqpxPomkC+ GD9KnnnZ77r1HqOwhPJT84nDcnQr5s1sApqObSG53AtoAJXZP1/t9ZKcnD9dwx8oh5 jPWF43EzAK2gliXbdPQf8EGj7um+QdLDdVDnZm5pcse7dFZFI3wNO0MPoYUYdypkk/ ka5LDy70uVbBw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MNKm0-1oZNME08sc-00Orb8; Thu, 24 Nov 2022 14:56:12 +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 v11 06/14] tpm, tpm_tis: Only handle supported interrupts Date: Thu, 24 Nov 2022 14:55:30 +0100 Message-Id: <20221124135538.31020-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:67o+5BRMDYtidqREBdNHB+oywrFTm9p0D+fHxBUOOEXWbXOiKO3 P2ExBY73eaQFFm5PkSstT+ezw8gxHLZbmrkgiOfbOVMXS7WFlsNOQufRUjx29141gVbAvwf Nw0FZGM3AXYkIwysp2UrwSoFTBrtsOVPDY0maiVwx5EyhcKBy7q8+w7CSN84LcD36XJCqG7 HlehynnNh7p5NDYU87laQ== UI-OutboundReport: notjunk:1;M01:P0:vpdU4kdjoPI=;8Ksw9yPGaSp+fNnK40CiYbdyZIc biz+cVRG3NvqFlGWCrVg6blB0bu+ocByBpc4jlpRDTBDb5lChp5SmpQc58o+npk1N7i4hlcf9 +T48J734dIW2ed6mY0c2DNjoROvY1IS0USnba5ohw6/Dhnx0FDzECgugkG13j9s1FIUPy8+hg 6c0/gnZO1lFwtQZAyhcetH6rzSIJmwQoRs5EJUcrPkBMFH5F7rO7tQPjxpE7FCgIhxK41r/Cn WeSDVdE+lfki1zd1e+SP2DXQQuxckd1GIoBaygp2PhFq5ymYNVJC+SyMwu73KPWI4zZm3bOO1 vIJDyrvAkXXDoO7H1+bgTmjargfn/zwAatGu7S9yStSoJCkcngjSnu4ajeoZs7ezq6yhbHL9X jdH6KHhxZ7wv135dGdzntQAimz3eBTyETnAElLCy8bewRjFBE7e3I8fdPeIl5PuK3LUGEjEsA JJmUJVNNAzlAyx76j8zDFQN23bnQ5PMuQz8xrKHFOxQieGW0SWgkE8PYhxu4rA09q3x2UAW+m 4rWGEsgWL78J+uCzjl5ETBklNj6LaKbNoZvjF5FANNjnQTQh+uWr8W6iJajBhk67U/7+RQE+v tCEPfAxSLjyQF2TtzakvtEXkOATz1zBY2T8BFN7QtHMhdVbidZhjYj0YlRf69npguFBLaQDhN xmvXkmhzMisDNgxD9HnlQSQfxhFAqbtLpw4bmERPeuu4o+kgl2HPVOXzYCAPqlLwEJfbBMlu/ SeplPkVNuVqT1SCTlurWmMEebqiK6wLuELNE0h5igs5k6vO2o5E7iTJIkBIRsqzgShn3vUGnA uSrVyAr8vg1vvvUOHuQuE0hLe4VRGX25sx7agTajfLWKfJjg1+gffpk+aZGO8iLe0ae/oY7vA FFGmdLDSlKDI1U50WE6usnapllcl8ctp3FVoSHfPIvrJReGWz2RofC1NicC0JCTOph/VIk0x5 NC2AVGCujEpWc/l3K4XxOVgp4ZA= 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 49848268f547..2694b1bb77de 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; } @@ -1001,8 +1023,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); @@ -1036,32 +1090,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); @@ -1092,7 +1120,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"); @@ -1139,13 +1169,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 Thu Nov 24 13:55:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055006 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 201E0C4321E for ; Thu, 24 Nov 2022 13:56:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230112AbiKXN4f (ORCPT ); Thu, 24 Nov 2022 08:56:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbiKXN4c (ORCPT ); Thu, 24 Nov 2022 08:56:32 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AB80F8028; Thu, 24 Nov 2022 05:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298172; bh=acaYZLOzjstSk1ewiw/25/8EH4h8E4f6Mhp7/e/Rz5w=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=OaCBfR5NBfypcT1zSMwJD814rZYvvu1zviaK+TZg+laBXbTG99/ckYdVg+29iJCE3 WOZ0QoeyRJingQVkLhacS9qmFt7dFmT/BVS9P2cWDVEVk/JaCSvaGrob/VYOzMMFq/ Pk60gwgGt2+SCROVVFqaddpSrX+d/ACqQR/splHbNENsiX/pCxEdcADcagfC2ud3g8 a28SdMFKfFrp4X71P7cehGUZoHfCbQpR5nsGKXcENqZFMseXEG0U196+NCsXkcIMbm 8543BhEunC6OCN6Ii/qTFk3b6mk4IWY5FHWN6s41qXrTsqlbj3LEw4IxCVDw05zvq8 Bk00eDa6lFtzA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M6Db0-1orazs1YVM-006eG0; Thu, 24 Nov 2022 14:56:12 +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 v11 07/14] tpm, tpm_tis: Move interrupt mask checks into own function Date: Thu, 24 Nov 2022 14:55:31 +0100 Message-Id: <20221124135538.31020-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:on5JjKFr/xjl/gz/QEuHuParjIQHmU7ELMmZZwpGlAZEBanrutQ 2DdmYrVPk4MXxqNOEjgNM1o/5202rmsWDop2c4+y1Dd+eAu6B0gEBvosJfuCbNs1QRZu+3V qP3NayH4ShRp4zVTwwcUQUUdFlefi6r2iBYNB/W19rryCjjBBk8hYlZSSFRtvztaMtg1uG0 hGWbAIvKJV3lEse9ay9ww== UI-OutboundReport: notjunk:1;M01:P0:qKA8UB9uP7o=;NJHWReHTds23j2YjqLN53o8czve pO8MMywFusnZoBq752jV++IRjLJ3npvTyinry9nqWvRaxmrIj1ZjrTkFGHztRgaFq6nIoP/Zz 8DeTgGAHaTLgr+VO+rgpBmuKQe/8kv0utfunymD9mFUhU1N6a3oul+HDqWavxCEVWie3H7wqW UvSbpL7PZEkEE1XCxGVJCzzku07N73BMxinTVZWZV/JJYPdUsfT/Mz6dRqMfFhEW9YZ/6NukL 18E0f+PRHZeQu/nkT7T2wFCo9caKtjwqQhGj5x4qZkFkuI2sowKfh/ygkS823SqAR46crAHTp VhdIVEb0w8F9naqRWqwD9wtGCJsadfQBQH4AHB2a4COnjHnxxx/Wf3V/quUzYVXf46uIXSRGW qJo8TkZ6Fhvnv+kOF7RAwG8JVCyq3C5Yc7BosykHuJrsZdPoexaLQRPRer3YGrYXp29kVaHa4 aN4Q5vHy5SmQGf5hEf/FE2kevdzxUBXBf0zdyMnLwWmuylpiQQdHkN1HZfBJveTjSRTd+DMuc fUmkKxLkiOIAambnVlznRKR8WeU6Yd9W6RsfrWKPQvSGwscWiQiWT53OGUbTZIG3SsaF60tf0 adsO+2SXenbr+g8X9O+olynu4D6kWljgjfyoc64tY0KldkoesA3PIbel7I3SsZTwp+zDfb9vR zwG4hPsyWf1d3Q2yPPtj61oQhBMlip8Tck/8cxu1f08FVXA6NnuTFZ499F5fny0/YFHxmcxCA a4DngGmbrZEcpxnGfnrff/CF2MKNxvb/8YsnXUIVtyeZ1hb+X/iFxYacOGKbq9i9nKtLdxm8y KhvcsEoCIGKfCOYQLyQACo7eGFHE0u4fdMeuK5yKGIe/nhsA3HdZSuTwUO7S9bXm4DabGxHHm 9fWkz0hojsmU0vfMjLCSrgkNfWFDc4wIStTkxskzUt0EdNzgs5qWqq4nlDb/rDEwEq2t2Jdgy dU+KeIa1xHjdKS2GFKMVIXadGKs= 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 2694b1bb77de..65d1ec7eb4c3 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 Thu Nov 24 13:55: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: 13055005 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 F0DC6C43217 for ; Thu, 24 Nov 2022 13:56:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbiKXN4f (ORCPT ); Thu, 24 Nov 2022 08:56:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiKXN4c (ORCPT ); Thu, 24 Nov 2022 08:56:32 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D2D4FCDE5; Thu, 24 Nov 2022 05:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298172; bh=KYgm8KRRqsXZGdn21yoPTnrJv96Ne6lqyUqKM2FAIYk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=l3aJvhaSv1q0D+rXI60cI/Ma/anYl/lkYrN80NC1/0UTnepJGz5pH5nnaoGzmzMsI kzDRZ9wfyYQ6g33KPjVvOj+sApYyCFRQxoJxcalz1yVrVoz1wS0cqMd1w4+vTp8vHJ 8t+g0DxSyqcgDd9YjNiHTTNTUKYne8cYShzHrZPo29G1FIZjWJpfmbgzFl8PpccO4k mFw9w7C1hmEHp0oVMCVz3c/E4bqeauKGwwAF2JuQTTb+Rwqm3fmieAVwauPC+VlawG oaJfVGS6Onu+ahQGtJwkIlgtxkyu3ac1N/HfMsDUSqWBjucrTN7eSa0RN4l/QeSXyR 2LWZtRLX9R9Dw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MybGh-1p7slF2snt-00z1Ur; Thu, 24 Nov 2022 14:56:12 +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 v11 08/14] tpm, tpm_tis: do not check for the active locality in interrupt handler Date: Thu, 24 Nov 2022 14:55:32 +0100 Message-Id: <20221124135538.31020-9-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:YZiUudcwOuChyLmzP4dwIkl3/awLNQ8KvBhXt/WodxMvdwl6lqo LlvMEiHfeu8ijXYdt5z3l1dJ8nClGm3ZE/fOr0XUIvycnjXXKIE/a9nSTHWz2Lx7j+PLOFz UoIsae9eEmaE265WB9dK/wPWCsVS9zLGWYpPzJeKKcPyOki2TCwCFwMxS9j9TLKqdr2dVZb 5S/AFQr/uIehx5tMNoMZg== UI-OutboundReport: notjunk:1;M01:P0:6fJmel/inqo=;Xf58vLAIKBd8FABsoQ2j5E1vpHB Pm6ssHhRUxLjlzXsLBNl2lVwOC0N/daWFx+PkqgPMJk5A1EQDCpiyPpEluUKiZEv1P5KXQrIM aceYNzDS2M2CAa5f88BD8MtIosfhLQUC5GGCvgUvKg66ch57MUHZqfORiRgdjhYjS1Zb/SDIo 2DjUWlkneDzOkdEHYrybkVSgDKLyCwWE99qx4LvL4yZSIYlLjj4MgJT7wJmbIZ3NMflV1zSqU lq1fxrkmQAxYQEzt2gVdQslzl7qMuCRjpT40xBA9qKXaLgEycj2CqviIWmTKoOx99Ajf5qqKZ yD9ZHYL3ab706mtUUesc2ZjVIw+MbwkbCRgxrirQd4Sa9QRiyOXGB55CxJr1AwrHA7xNnvxCR tIF74Ul9W/NoVCTtxPjLv3jTd6bK4lSeIXqCvUUR0q+FRSX6weFKB6i8gzqeUFJhvpszziTPc 7rS+nrqTMU3XdFkBnW20reV1f7bvtJf4tekEXyq1rHQATYKphAIzxe/OycuXWoYibJs2I+rWy ZaPkA0gkmtVCrFYwPxY673u4j7exBZyOCx8kgfTfbz5gbs8dH85dmcs7KKyMtZYliJD44PYl5 eZFgvh1rhgq9vHBfuh1WAs6VlzOjEn50IvW/Gj1qhflSdG90eLUARCPe0L56Z8EupCaDBYZ1/ dtYf8tYpz01YAUefzdtkXkDuTatW5iS9J9rbRb8l6a19Y4jl+xKVa1QzUp2MbN59lv3d9u6X7 gX7LY/neHAwh39NVD6z6p0fR6yCtjA6Ytz2LOIrC+2jLT7vWB6sZzjQUd+vhi8SVq2ULyGwYf nhNXQVy/dMTex496Sfs/vvLMW0nrNgNPdSaFf4skJy0ICO42cMITdLUyXw8hWdyiybnFOvm2v DlrKXyEbRxQAxi3HWByT84Py+MENN+J+TowiEKUJD4CdFV6rAjX61xgNrPHFK/FQkCUkFsvdC J9jXqg== 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 65d1ec7eb4c3..d705dfb64cf9 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 Thu Nov 24 13:55:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055008 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 A5C2CC43217 for ; Thu, 24 Nov 2022 13:56:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229630AbiKXN4h (ORCPT ); Thu, 24 Nov 2022 08:56:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbiKXN4d (ORCPT ); Thu, 24 Nov 2022 08:56:33 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 424A1ECCD3; Thu, 24 Nov 2022 05:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298173; bh=fv8SjyD4xDuS845+FrgNrBwr4CQVNrdzJ9YRUMiA+TY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=lcI1cZuAQ5wvaNyZE2ryqYmERayGugVT8v30Rz2tx8ePi7YqKY4DUqScBesUGVBVZ 42EhV05+qTtJK/OfukMidyvXmQf4gt35gtG8y4gJ2maVY25i5sSj+hD6JhZPxZ3e1w ZW2lThEle+prgpPVoBWy4Kt7WB33rTUgDJ5dSuG3gzXDCKHcPHX6PlXHqEUqhDuvXQ PltNzr4PvdPbMOen+7/sv44xrYBjwxs3WB/LH4lQQpt7zo5EKNVOCroVvuYq1KxoBj lJTfCK74SpfqlQo7i/ZyrQrzTw1q5LWN3l86E+BWZ/s/Xwld699aU/W6omESjQSk8W /SIFDqwpd4OAA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MuUnA-1pFJp10EAU-00rbly; Thu, 24 Nov 2022 14:56:13 +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 v11 09/14] tpm, tpm: Implement usage counter for locality Date: Thu, 24 Nov 2022 14:55:33 +0100 Message-Id: <20221124135538.31020-10-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:EARtN2yQKkakweGe45TiFY3vqXI2qDGZjL4gyp78j5cHVteVZv5 HF3CDFi80lqOezCuQexU50FPdC7jHz82F492j3aBJmwLcdKMVEaafWdF1Ed7FaGDz3TUXCw i8ObbYI5qXlaOcqPEausj+fmQ+PSB05XO4NMzQo6qgg3LlMM86D7DdLoO3To04pMISoL2Oe p34/cDpN+TJrzJb7zWHQg== UI-OutboundReport: notjunk:1;M01:P0:+jLTMtAND+4=;hqIEXAWKxiuPKFVUiViFreV/Ml6 Tz4XPEUrjoJC3sNeBfK48XhgbgwTtd74/le+W/XQnSd+j+Tm4iV5EO3C+v8+w2yQ5vrEhjcBx bDAJYuWbq9YJbLHcPgZ+YbX4pwsk0GtMYLfq6HoQjx7xwBNLr4CxVjO8dsZLjTgkgZQFoKDzO 8Mw2vmUzZ4E6D6LuuJm2vVs963Ph5WLQbzw7iv3nI7JxG6FLSogbSXGJIidIm57QNHZW+fsdC aLPlByevOrgjAkcTjRx2EHsczzKytJhbCGI4IlKe67rV1ysEletFo+T6eAAb8DW1JKDDSN+pE Yure738l2W5OpqNewln7/fXluSXjHQQgAKZwfuCSxKBTKbenz0zDa7QgGAXGouA3vo/pqo+yW qp8haKRjUCCpvjv8Iu51erz6xViPcxzkYPAdARgqiQ4fgX/uccXoAQK2NzqwcvwnWTK9YhIkx 632phS2rNVt19qPoKD0hKpJR5QnTbsBAYn6Nbl/WT2qtS5KGjtcZOhnGpbOdyt3pF+D7L2lc6 Arf7qJe606693CrRO1gumFTHr8PKf1Qv0zRmOSQg0lWUBuLYXug2ytMw1HrjZTZoEAFS0ato9 /318EyZfm8gSRg5JXmM1zH2aM1I/+zLX4/AUxL1IktDm7CxtWH+UyBXbNtgtDPT8iA1HmoOzy qWYnrljVRkIPhayxuWYfuXOr6vnZWGeu+u1ofwj1BTKBVugKfvLdaRUjIcc9XSmNVnNoj0SOD hSaWvR9fTe2n7WYlDziiAqh5oAeWtwGKN6ZmuaueOP2GVy0jXwjIRNTsAsuVJFxC6pIiBEVRI i8UaKU465yYWTwFjdvtpWIFQzWsL/+XBnOr5WdaypUMfyWsPYlnJCuRchOCMjTnkk0P66PEmc XfAS8vwvwRkSHyOhpVSunvj/r6VUb9egniD3tJxEi7YaWg89vBkRshT+vXo8wmNc29Uylxf4v 5Tn7e4RsIF6OykJPDegG7QV6Zak= 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 Reviewed-by: Jarkko Sakkinen --- 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 d705dfb64cf9..f00f1057fd27 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; } @@ -788,14 +813,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; } @@ -834,7 +859,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; } @@ -950,8 +975,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, }; @@ -985,6 +1010,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); @@ -1063,14 +1090,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) @@ -1104,13 +1131,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"); @@ -1130,11 +1157,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); } } @@ -1201,13 +1228,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 Thu Nov 24 13:55: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: 13055011 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 0A635C47088 for ; Thu, 24 Nov 2022 13:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230155AbiKXN4k (ORCPT ); Thu, 24 Nov 2022 08:56:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbiKXN4d (ORCPT ); Thu, 24 Nov 2022 08:56:33 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F22ED100B3E; Thu, 24 Nov 2022 05:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298173; bh=vnp21/mfPoqtAE/9hipMWqTIgnCW9bDnAe+K+uHJwrI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=LvEQYqwKKJlb5S4pUaX7RxL3noLuSJv1rRgUqNElsH5Cj44g9xXImgXuGiSPYNajp LoyxrJhhJ9LhlZ6AbdES/IB23dtxOMoPZnb4Sca0xWatzN7V0cClfoXv4qIJQsFwTz gd/j++4x6FZRihrfjkrruMbIdBHTrYKUl/Que9sCIazI00gRfqhHTBRebUlb7HJoDN gazlUgsJPGsHe3NfvvJ1+ILK1Q3ssp0zFMYiylySFkF8GFZJLpLTI/tV4M6pqEnVcb VCNiPtIZg6rUFdXCp1e74MeAsCB0B48FW3SXfHWuUe+2GKLeUuTEddvoS/kvQZPIO4 x5+G8YSkK+0Rw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MxUnz-1p8zDw1j8z-00xvZB; Thu, 24 Nov 2022 14:56:13 +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 v11 10/14] tpm, tpm_tis: Request threaded interrupt handler Date: Thu, 24 Nov 2022 14:55:34 +0100 Message-Id: <20221124135538.31020-11-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:FpAKGsitxv+CMneiAfduiO2RrZijFQTQp+bMXElnc3uL6bI8p7F zTshYoLZPrT8axM3jWbcpMLVq9mDHDdAM3tEq1uBH7XummJ8qw+y0+qVRCRfiBBWWjPfPKR HxVBk5dWcGeX13WUf5W/H/MUSLp/5/IiDTX7Aojuz0RmODZhawY2YNzTV92vhwoK7k4mYYw I6ycvYQPwupnhA3TxH/4Q== UI-OutboundReport: notjunk:1;M01:P0:LNScq3ME++Q=;BKzLYTTefHVMCZH5KtkD/2MYx2g yEEGIXB0VrNAzG1MPNtuPEad1NpHbQnDBhREjjp2/F+WkVba7j3fnsy5VBRpIJH4wJ+85Kl4P w3YeiiTuCcv1C2PWe0jYoCbyq8Sc2jpJB48ohmPZAtcopjolLQy6NhIHFx+ZLWqSfBLzDI1cC U2lRinQ6QHVwAk5j9UEPsZ1DZ3oi755kiFg8cIc1qCjKvVdwVuNb/LPBY0ESyqDyzuezG90y1 wQKIBFR7v11f69N2jVBKyjm+Fyjt8Z9irgLHT5YA8Edflc9jEU8gf4XlZAyYRiJjBIROl5si/ rKZT1XI8wypgy4T6eWIB3EzKcLPqGvJJaIcLPB7xXbfKbXV8h1PpJzG+nRuhS2lHqAAjpB0Bm YL3Jl+dFIHYSqqjAlyuqVpGmgR8OY7UR3OtUuCmU9HoUYyzSaiPLtAvwUCInmXuQqFEep/6QW rlZOHn1eWdulQ3cYXq/99ZEptGZP44GnSBgo10kfT743jbVJGseynRiPgg0ULyS1fiItL3OJE SVXyBr1dosQpVdJ+JZzaNzYsWsEx5Y2w1oRTBrM0hljT8aLkF3ZSDmF2sbwZj00je7CVFXg4Z KB8KQYCpM4cXiX9cVlpCtEv4cQwcX0rlcOwHfJdaGIICsf30pTVN6PiQo8DNxROccjN297fMo L3EXLpEP/IclWwfi/wCSySfN3Ogn4nxD5aekud0T89sl45LR2CJT5iGY2etExs6KdQRCtPseO wg4hpy7Jo6jp7vQPlK763YN8d4GRcgInN2xb/2D4+0FzaETFqjJAHKX8qvCifjEJAd6HARFyy lUUhJsekePLsi19qReLqJePnVSCah0YyulLyC7axAhMQgtsBLML7ah1bcH5LeG2E5R7Hd6CCE vn75t6E8BowE7vcJGB9IT0Zru91gag8mt3KduLDx/X1WveZIiNnVhcjHNdQhOfl/aRQ60R47Z jxc/+A== 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 f00f1057fd27..3891499f9877 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -805,8 +805,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 Thu Nov 24 13:55:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055009 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 045FDC352A1 for ; Thu, 24 Nov 2022 13:56:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229453AbiKXN4i (ORCPT ); Thu, 24 Nov 2022 08:56:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbiKXN4d (ORCPT ); Thu, 24 Nov 2022 08:56:33 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB867FFAA4; Thu, 24 Nov 2022 05:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298174; bh=RNoCSRg3R8Wx3i1g1q633Fjj4lnL+OK+lra5ATnMp4U=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=EaPyy9kWmOu7yKDblEHFb1TJ5KSgmh9amRrtcp6n4LxnIot32DPejBQEp6w5OZQMb wvGeQC8V5z2rSj0pQ1wZAVJP6dQqnCTae817QMGQ1xwCksrsb7fUSDcQ6phiyUQfWP Ba0nHQZ0ERIHCurT5pYh9gQKxcnG6GkGGu5UWSD3/aZmYOx4uNNR4IXIH0+fameSR4 BOidMDBAlEHo7entttgS2iAvsSus35bEgBZdrzLjCQ5swNMwux4uJTnoz607VQaQQA r/WXQ3kEy2wvRKtObjNS5wIy2mVlZF96wB67Xc609JwVa0r0Iha7wql8TDfUxkqIX1 Ttu292M01Cm0Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MtwZ4-1pCZjF3EZo-00uMey; Thu, 24 Nov 2022 14:56:13 +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 v11 11/14] tpm, tpm_tis: Claim locality in interrupt handler Date: Thu, 24 Nov 2022 14:55:35 +0100 Message-Id: <20221124135538.31020-12-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+4teyRziUIPdBKrwSWvjbsYkNgwpeKjz1mYZdtd3vDEeyiycqjq Wn9EuRUn7cNzN0xLlFliMQlxrp3BVEhJBSEoTBpSpElfCo/J7xOXQ9/2TkRPrT0mGaalOUy 97c/MhwXZU2JvaFyfG+PHlwYacqYGORMF/RkmbU2JdwE2Wodb4K7URnxMG3W6fSRMKMjzWq VTXro35eiHY+OdD1aOzGg== UI-OutboundReport: notjunk:1;M01:P0:9cGxeBqa+go=;IZmiS8eY/s4mXxdKxByX1ytWAaV D7ibIuts1yzeVae/mmUwoaaegD1M24aTq+2HcJNDfQybbRRrp/xUSN48bKXNKHFwkA7BJOnw1 HUFjgAAU65YSumPyzvpOhjJv/addNEkVybPaq41S1SqmZN5rAhMOvZmnZILLRWd5cAOaUrHdZ wHooG4mwvJWcT/F9i9GksWlqSNPdlrsW8HLfybtlMs0X/77AzXUAFPmdG/ecJJ+vgb45MXTb2 FFgtiYPrSGBbNIZpQ8Puzn5yBgvkHWGXkia9tkx2BjGgu8yO0JfhrwjdnKtn0M+FutqkIvMnk aVcm2trverNdhUrwL8K+WmOTDRcUGJwplzJET08gaPmramDZH/NQ2FQioxMKE3OOEourBcier GfYu2NtVJrKd2uEMyhOxdLMbJJNDAxa7tQoXgKm+sGgT69VZ9tyWN7IM4ONlLc7pGnJ3HeCLE 30sKBMxjIC9OZflH9NqEZKjaAJIPfjYKaRgrl/K13mkr1rHWIq6V9B96QZYVIiMS8BDVBjGI5 zoPkOqaI0cduKu6gCrBKuANPDuhVl5moHKFPVBV9+trzcMp0C/Q4lfYRdwhQHkjdiDp1TL74D lXmTQ67gcWK3WMMof4sJmyFcxMBaO2bvnYP9QHoeo61FMuLxtX4x00jAwpnDPSP1Up9omPzDG Uc04HeDrs4PjK53D6ZgLwIeVACfL29Upgk/+BdToD5LwEbfqR3KkJgZg1N0q2iUJaLfGyCjNP Gtj9uWJZ9Xgs5S25P3cdefAQDuaBF/LkHW3HgwBZpUWDUyhVumLdFsC/MbLI3AWwqfRT74Asj 0X0mT9s0UpIQJQAgXeS0ClFoeKhgB1O1rbauvAZ8fwtRuWtAkkKZEJOZaRKJ7m3Mr1hI0Ae5f 6db04brPOWz2pHfpyd39uTgbq+2g2hKkKkSTEa2jTpFWcaaCujrYwU20hBjZWJt3a6gMW5X5M 4k24Cg== 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 3891499f9877..eda3b122e540 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 Thu Nov 24 13:55:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055007 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 93EC2C433FE for ; Thu, 24 Nov 2022 13:56:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbiKXN4h (ORCPT ); Thu, 24 Nov 2022 08:56:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbiKXN4c (ORCPT ); Thu, 24 Nov 2022 08:56:32 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E270CFFA83; Thu, 24 Nov 2022 05:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298174; bh=ZQrQ2undxx4v+6nZgOuKeQ4fsU8UgfXoZI9MOOth8tE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ddo6u5hs4cj434HcTpvwD7vW5+PiLY02huNtyJ4ohWXaqqaSRC8kFnEX1Oj1/186W f5JQW+ArJNDd88wHAGIFB2/Ewor1o5IZfXdV2Z0j8BuswykfniZffgtTnV8/ObB118 wSquDx1nblWyPykGdYHSUCxaDbA3ILAfhhHyRoHqnlI3D/Yi8mph6U/QXLBLH6wPE7 LQPlao0reGbUfmLBZZuMBYXJp+ZPnO8MytdAyXZOiTFvNjA5pxttEx7N9UwwvV1Kno Gc+YCMSIrZyYcP6CuhEegwtY05QLm88r0wfeGr/D1OQPcxkV1dLWDvCj0Cd4t+6+GH WcpSx9yqGegkg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N33Ed-1p3SuR0Ny9-013PDZ; Thu, 24 Nov 2022 14:56:14 +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 v11 12/14] tpm, tpm_tis: Claim locality when interrupts are reenabled on resume Date: Thu, 24 Nov 2022 14:55:36 +0100 Message-Id: <20221124135538.31020-13-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:yRmIK1f7+KxuNnECWFfKad/tTssuC85ALDbC/SoyTS81qtmvqpc AwTK5Hk2uvTdkpPGPYrmxnkYAyuykDIPFH1hQ8ViCKeKAg7N0jx9eMxVXT+BHCbIQfwq1fm ++obvjcECsK1RpCjoFxvWhSV3yVS3dMTB6GuYJlWd27RYjG5hP4SlLg60HP7rwVWtJUhxjs PtxAMW45nsfvyImDBW3gg== UI-OutboundReport: notjunk:1;M01:P0:Z2d0MsdV5WE=;XM9FBqeSHw8Rx9MapvOY3cFSXaZ TC5cmrDnDLdiVszxx1katTwJrXLSo3xzmP6t7u08luQvC/KkeXD0ldetn3rkG1HPwy9iWqwGq HTEjSyYryS4qLssywWSmBK/MFilZoDrJXB8wrmNlaIrQ2YMzmfioHf9cisgqeSJ8cTbvTQe7T OqKjs88MgELFapfpNiIdFG2ECoa1XRc8Ljf7Dy9bLdqTXBk/L9+Rx9SU+PKZQfvt73wxIEmed IT6+WXiK/N3U/c/dkmBmxufp8QdyNzml3LnEvt3s7sLaxRqo8vHOWbw/mPslxwduN8ZTDHbt6 MsKUIPoK2SnJbI/Qb8Kg+aP/c/SbJusfsRlDbUuuEzLImH/eCHxI62Wvl8otGYrjMBWoKcIpe vrrWbx/pNkjvul8uEem7bDNd5MUhuU0PQnqRQPyKvhW141WcPrJu4+ubsvN/jfuFCfE5aSxqG yUufGqqCnIlCDEJgI2WaV0PV43V/AKwCJUOn2UayRRbTmbOhC/YcK6zeTt7G3oO2iaj4URrH4 nxtNfyQQz1RCHu931HXJ3bhZUl9JmhZ0RPLtNpFwN5PY0HTQwjLgSng+UJ6PJnTJT48ElV3cs Qnqd/Dou35TyR0FnUz/yFPp19Wx7VyQ8NGjGuCKbL+feZiGECgKNXDbl4ONCKW+f2pE82YHfy TzK6AsYIx7LAYCxub+iQNn+HP2wYSG76GmQTd/a2W/67l2KmKf3h2WMf7OXt2zt+vGSXUIkBc O2NSzOU4YvLQlzs+Ax4Zml/Lmx5UllM7uPJpcjVkWpYO9zwtz9Ie3n3gvwEesjZhD+/ac76Mv q7/nKY0UHSpg5Ytl/ZRswiXHZ8zjKg6f2d/W2hfIfG2XHaRFZXOJR/uoPWdHjhpTjWlgyGy1W MCNjOFAwR8+vBlX789a8++OwFeg+s8yAlF/1NagbadH7I60qS43p9pKBJrcmhgp6KrqzgNcTp HunYdQ== 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 eda3b122e540..ddaf362e62c1 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1221,28 +1221,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 Thu Nov 24 13:55:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055016 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 27766C4321E for ; Thu, 24 Nov 2022 13:57:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230226AbiKXN5F (ORCPT ); Thu, 24 Nov 2022 08:57:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbiKXN44 (ORCPT ); Thu, 24 Nov 2022 08:56:56 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FCFFFFAA4; Thu, 24 Nov 2022 05:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298174; bh=SccepFkG1BaYDhxThv4kTIw73gWWQ8B34c8oBRXziP8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=N5oSIApeIyqhSeyC5gdSR0djmO35Q82/vTO7AnK+pUNovI047gP53VxHdyEh644Gs vDbkjFbFt4syPSalb34P3JmOTUqPiUORWZ3cu/CtvTl1I5MDTSI5LbrbRykKs3MPPB gDqmJMCbW/daQoZ5iTvHIoqr6zvwolRhD2aLsgkpb99iWmZybH3HfbmPqUJnkMNObK 4M2a2Ouq50SagnRldDSMKXrD4VUHBcq6CmZ+/BDhv32/We5dpWepTL9XotCwnkiFVu TYXuIvIFTdnNeOaR/smYBw2k8Rv1UALGd+DflsGFfHRtoG9vBH3jN5QSKi9OQr1Lm0 TWJ58lS+6OZLQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mg6e4-1pPH3Q1hnS-00hcyE; Thu, 24 Nov 2022 14:56:14 +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 v11 13/14] tpm, tpm_tis: startup chip before testing for interrupts Date: Thu, 24 Nov 2022 14:55:37 +0100 Message-Id: <20221124135538.31020-14-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:zL2CNXLyU474XTdrXuPgbob0QK0DB8meDAMR4XbMdR/tbE5lv3k k6dilEu5PY/7pIfCkYcsG9ONqgIh7Yw14eA/C71RO2XlIIRNDC/vszFhWB6E7PjthtspBOF bnGzBzzik2FbNsoASv1b3OfHAbGE6h6nhndFb/bw8w++/zya1A07LDjeoY7MMXfTDUMrYbf bxYBAriPFhSep3+hjLCSQ== UI-OutboundReport: notjunk:1;M01:P0:1LYpu2fBXps=;CrGmYwKDDI8dwJQBn3y2fmWp8Gs IA7PqgPDCI0YelnX1m174eoQ7ICsvUkRLf1qhlw0+1kEcAK/s11cWQO+JCsG2tBuUYf6t/N+s 4dXVf06KzusaVhyfHT9ULvmQtbNi53Bex54+G9IBwrvtHJzY3SDYxpA9KfYYrOATllrP9XKGe ytOWAHB6oOlnLA1OPJd70P9KkALdtKQq187b2MY6T7GN7NCcsoz3AVromPiCdF1PLIfZdWdsH CSwfcRCgOlL6tzkTLO5HdsRlGBQDto3v9YpHtHqKwPtSqgL529thm0QvOy7DpAcYfG0UacLCk l/RrWNlHMjSzjYLDqmjDU6hrMG+wJ1qGq9SP8Ag5RhPIzJkvXFVWpLX2UzNF0w54Oly8nYZkh 6JLFhVMRhZJyqxlKIc09Rn8JSf6jaEwHsOlGs8wk9Q35d4H2LWF9CatxP3A6q02Ebg/pnFx41 mj7jZk4qEGpvEqEqSUd7lTtEMRIbJr8T5J4oRMasG2bXXTok66l+ecll1GWZzvZqnrBo8+sqf 2vENlVO5QQiHp+7CYFzhVyaL2kfGIBHJ90QCKc2FRI81DYEz+Sudd000dC/TMmjA+gOAxwrqE 4dZM/+C223BAwUhs6oJRZieLki5Gm+BXafGFJWENkDez2vfSTqaObWy1O0+3Fsg5K67R2Be5n PSQKkM6gUaWh7oI9xMVfrzOq2NYGjQDmhS/dtqOFM2p/w2xAZOF52M3EhYEhIEh9JmtmDJfhy CdMQCRHDF5Cm9pIRuLdV1IDx/MmcxYg2MhwON1ghtxxte5TYdXZ+QIpebHcJdIFDnfGKJs4XO 4GOu4AKLF9SNddSHjn1qu/b67IKA4NLdlFiEB4QYUQhpL0nsFgH9aBIqZebPWX9tG84Tz6cgR 5PXiwM0vVzJRDLlq5Jj3PJc29ZfEBRVsIlCC7fTsVyDIDlSR3vya9bCIdI6r7b1Qd5yws60o0 be2bAg== 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 Reviewed-by: Jarkko Sakkinen --- 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 ddaf362e62c1..94a2bfb244b3 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1129,6 +1129,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 Thu Nov 24 13:55:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 13055013 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 2F565C47088 for ; Thu, 24 Nov 2022 13:57:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230220AbiKXN5E (ORCPT ); Thu, 24 Nov 2022 08:57:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbiKXN44 (ORCPT ); Thu, 24 Nov 2022 08:56:56 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C0151165B7; Thu, 24 Nov 2022 05:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298175; bh=tNxzriKju7X09wVvY3INkMxvkZLtq7M5+64P/eal/h4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Ays7wa/uQDWJNn3ep6L/CDUcb4ZbmIcHpU+KmoMdvXBjKvK83GtjGEsyvd2qG0sIQ jXqfKpVOGzay688FLBVMEJRiKT2OV7HQ36O5Mkn6qQaVq7Zp7zHHdQX1bM+Qp/Lvjk P3RigZ7k0WeJWKs7u/gRcPTBe6BYpTP1ttD+kc4A5gPfl86ZDL0UcfGAVpnoMIGAn0 lN7SXSViEGsg6FMjYIMhIA1UYbXzdgnY+F3ixchd/bWFnHSKBju6+SvJPwT0XgqAHv bED6lKWY+e10CibuVdHMKIFk2XgZebcpcIpYr+0GoLrqN2ev56/+dqlfI0U51PgQD6 xWyhCwaiuS+ug== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MQe9s-1oaSkq35Hy-00Nkbe; Thu, 24 Nov 2022 14:56:14 +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 v11 14/14] tpm, tpm_tis: Enable interrupt test Date: Thu, 24 Nov 2022 14:55:38 +0100 Message-Id: <20221124135538.31020-15-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xfdO2tuW/H6iYYoumuTl2JI/87L4z6XQerQt8f+R27hsPCrO64Z JwwfgAMboMKyAW+te2wxvETCWMQl9n7oGkgVUgttVuzOj8mppqb7n8fDCtqi3gU1NkCuN4I 8LP8lBZUixMLA2IPpHG9hkg1CYcxXkcQZMY7SDAVvbLzkKFnCKKLNHH388WCpvJ3+iHELmx 06AlFwwV950PY1Vn1fsLQ== UI-OutboundReport: notjunk:1;M01:P0:1X7tueyk1qI=;cI7BBTNCszsaJNj810LcBY0NURn uUcFyWg8EsV5Iz5QF46XdeZhniFC8uMWGw4gXOHAXbzn+q8gbtvSsKKV8eY4hK7RlJnn9sRSg 2Ug/tnVjG+HSmx+j0z5Jii9oE/m7TF16M41Qt4mmYGiWEhWk+pMaiSwHSyHDmNnfGHBtr5QE3 aRmggsoxFYZGsrlmfRojCDjLiASKcpDPrwFqhAmievr+2HXfPCf2ACnTjrqaqgsg75FrQ1UGg dLNV+2O3sfYKhceOcfAkqr7XJtQNksALkXcxOhUOx3mWWGATFG1byaXFGkCac1Zfu4gUSAxiB 23Z7j60SLUP+vqMLOqXMObULp2xJr/DkpYzpFkcnR5FzirSHIqUs7Pz+68xJDCEOODT8zaiwv OTMQlt8uwu6Qu87Mu++czibfjbBzRh9be+rjxCNbMZd3jZoyalXQcLtE3M8H0Nyf8/1JF2sys UKUnrQ9qUyPv/RVFD10Au9zn/+i2+ZEzYFjjUaO2czM2lHwtd89NiKaipU+WRBl3zeZC/iK7o jxgeWrECkTBMowMMQ2ReCtRE6Zbn310uahyYwGzdxlVcAghq/nZcTfz8eu4Ouwx6xwZ7psZgU 2mfmUyLmxOv64aKvNOUIaQvqWdndXP96qZkIRgdzix4FVQBFgCOSwoMH5TzxHuMO+X4fcEbSL lf17I0Cdkj27nlqBJci2Ps12+NnlmUNf7vlshbiXT5R1WUXs/kZBxA54+N9kALIQyKuWScJvf 4Z1fdDg8JMBuw7INIZ1c1a4DxQ4SFJQySCkDa7/+1fxNSn0qMYwT9Cc98EJHoysAjzlSHo8EF Epy6CrgVvaNX5HwwH6bC0WDZ5UqMxEYDPV0H3gOvMA3aKIxoZTcyytTP3wju1pYUPXCHsu3G7 jsW4BqTXcX/5Ot24Wdww+BJCDeUCNE4N+sesPYPF8FkSqU1Qps1oNWjWpnQt56Vd4tkLRWerF 6GPs7ot75nofwZMUtwA+18S73Co= 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 | 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 94a2bfb244b3..602ca4bb8e2f 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -789,10 +789,15 @@ static void tpm_tis_gen_interrupt(struct tpm_chip *chip) cap_t cap; int 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; } /* Register the IRQ and issue a command that will cause an interrupt. If an