From patchwork Fri Jun 10 11:08: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: 12877479 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 EB750C433EF for ; Fri, 10 Jun 2022 11:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346627AbiFJLJc (ORCPT ); Fri, 10 Jun 2022 07:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348322AbiFJLJY (ORCPT ); Fri, 10 Jun 2022 07:09:24 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E81EA14642B; Fri, 10 Jun 2022 04:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859344; bh=cRKDsGN0VdsCFTBnRcstCXzf84DjLh3s5S//H6evbxU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=RxvoEM2s+GCQWM8A+/5BrjdTPCe9c9CIHvswgUwXjKtrwa8Bh1/Cnfi68qad2XeMA /HDZYht5oWlChjbdATxTWqYm/u5vg3ff3iE6nmmsF0b4g6z4uaO4yGlNN2dL/RV4id NRLRDrLTC8i8mNBBt1TSn4DdoRFe4q3cgJQm5maA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MrhQ6-1nNEtv3Rky-00njsc; Fri, 10 Jun 2022 13:09:03 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 01/10] tpm, tpm_tis: Avoid cache incoherency in test for interrupts Date: Fri, 10 Jun 2022 13:08:37 +0200 Message-Id: <20220610110846.8307-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:q8bU0YAnT48OWQ7N8IAEbPbVAzWl5CCrfbTQSDm5sbhGjdqIjlf LbPynvy15Ag5+DzsHakUiEJN8MAPK3p2HVIPpLQmW9Jzl9oSsSoxhzQYbvj+qFcNP9d5Xyo rMu8RFCICskwoiPKXu4yquCQ8+rtWeySkPHonWidwznKy+CcyivcOWXgVNob0aLl7v/Ms1S aJHRweNtbDjWhkWs5ujDA== X-UI-Out-Filterresults: notjunk:1;V03:K0:d09viExLtiY=:zlE2J+H0tdbp/D9Rgg8PAj UgB3M2NRHpR20pM03pyVo3iXvCpwIn6uPuMVqLE4jm7xzGex8nYgqZT35nvulLLlHPCVzcykg zqzYDdwiBthklFrHcM4cR2PfnzxiTlI+kXRiUyVDol+aAgXZpr1fwIonwjeK3f5vB5+JrUZvs 2Y5Z0XLEtOAIjWQ4+y9mhs6LwLRx2GVcpeafRwRhXtlO+iDpR2OM9aTZnrNMZyb6hFjkYopQ1 pv0dKmkquDNG2kcRoRpaG2T42T5wuL2ElX6GninO6sSUjNtfSwm+fC1KyzN1Fqzu1g38LBBHs JhxVjofqierOSIOve5aNfGw5E5L2M4nEmL4b0TRbkXqBSdB0trfEQqjkU9zTixCezgCoeFUQD BGYTlWm562KAlmqHgHtoYopbtQrMNmxzRbygsy3kBUbDHRxkJRh61LqhqyT4PiuGD/C/10sF5 CmXt3+3OZ/44E/mXiEO/jEAUauE6VmAJSoctpAF0lm2zxPESEmCrP6rAj6XdXf60Yh35tf0kY r+oNnVgE7PY99noQKCiaT1rQ/oTj05h2aZK8IHQxMvGOMR+eq9glEodkmrgQR3DwihfHoGwF2 xkMEXV0MDV3hVQ0r7AGVUJgrqzUXJ5INnM5OdyDJisDrpIU3DaCiyxZw1lYcbauRt4pEiRNwH f+RdFuzkO675eiVrKBFf1dCM2vdTbep6icKfWROLuz5pG4xIxx8t6jhaeFtELj9QuCx0e9YQx RUvFxunDP/SUP+NrIC9SdSxJxyR07l0nVV00MKMiuK567KhACO+SRfBe6luXJ1UUZw3yKBxQR m6kD9IqS4ZheaESBWcahczLpr0h6bgiWHK7EfzMUhLr6Fw//pD4UWm8k4bOYBizjGZqiLIF4n t/6gRjOD5HOReUHDnKsqOQAkYv6AUsS18XSkG95r8JdBGt21V/OuNwaFsVBsvjc0BO73roDF7 fA95DKkF8UWsCc8xLEU5qPxeis2huJioWO8kA/W7z0zq+Ulyf/pxqi6uOTuoQvpdBY8D8kGcq 3lejuEPHaBZjzHWYbW+gVjf3sn4VVcOHK78LpPrKt3q1woyYbcrCQmKz2qX2rsa8hAvBBthPM ZTmfIHcUrXou4du8VYN7iyb6S8YpwXnk/5Uff28GKsVuITRuQrBn8S+ZQ== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo The interrupt handler that sets the boolean variable irq_tested may run on another CPU as the thread that checks irq_tested as part of the irq test in tmp_tis_send(). Since nothing guarantees cache coherency between CPUs for unsynchronized accesses to boolean variables the testing thread might not perceive the value change done in the interrupt handler. Avoid this issue by using a bitfield instead of a boolean variable and by accessing this field with the bit manipulating functions that provide cache coherency. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 13 +++++++------ drivers/char/tpm/tpm_tis_core.h | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index dc56b976d816..6f2cf75add8b 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -470,7 +470,8 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) int rc, irq; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested) + if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || + test_bit(TPM_TIS_IRQ_TESTED, &priv->irqtest_flags)) return tpm_tis_send_main(chip, buf, len); /* Verify receipt of the expected IRQ */ @@ -480,11 +481,11 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) rc = tpm_tis_send_main(chip, buf, len); priv->irq = irq; chip->flags |= TPM_CHIP_FLAG_IRQ; - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQ_TESTED, &priv->irqtest_flags)) tpm_msleep(1); - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQ_TESTED, &priv->irqtest_flags)) disable_interrupts(chip); - priv->irq_tested = true; + set_bit(TPM_TIS_IRQ_TESTED, &priv->irqtest_flags); return rc; } @@ -693,7 +694,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) if (interrupt == 0) return IRQ_NONE; - priv->irq_tested = true; + set_bit(TPM_TIS_IRQ_TESTED, &priv->irqtest_flags); if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&priv->read_queue); if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) @@ -779,7 +780,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, if (rc < 0) return rc; - priv->irq_tested = false; + clear_bit(TPM_TIS_IRQ_TESTED, &priv->irqtest_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 3be24f221e32..0f29d0b68c3e 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -88,11 +88,15 @@ enum tpm_tis_flags { TPM_TIS_INVALID_STATUS = BIT(1), }; +enum tpm_tis_irqtest_flags { + TPM_TIS_IRQ_TESTED = BIT(0), +}; + struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; - bool irq_tested; + unsigned long irqtest_flags; unsigned long flags; void __iomem *ilb_base_addr; u16 clkrun_enabled; From patchwork Fri Jun 10 11:08:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877471 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 6D58DC433EF for ; Fri, 10 Jun 2022 11:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348518AbiFJLJY (ORCPT ); Fri, 10 Jun 2022 07:09:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347368AbiFJLJW (ORCPT ); Fri, 10 Jun 2022 07:09:22 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C297D145595; Fri, 10 Jun 2022 04:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859344; bh=gceo6ZyZ+3/FHWvb4g2ddGemHTh6VUEjyhULSfblaes=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=XKlEkY8iOrWA/a+k0cnaJnC8GlL2A9c/kpH6TSVHcB0kLVBD0e5VapHyX9nurnHkI pojh5Me71KVznHY2+ylxx1uNlHIqWRqm995pooIH6S/I4Mkglr2GCVY4QQh5cp3G6e +eT2nyYXwt65OZslrwu8cqd360n7zT9he/Ox3lkE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mlw7V-1nGtuN0nSN-00j5Jh; Fri, 10 Jun 2022 13:09:04 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 02/10] tpm, tpm_tis: Claim locality before writing TPM_INT_ENABLE register Date: Fri, 10 Jun 2022 13:08:38 +0200 Message-Id: <20220610110846.8307-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+T2VMvPYLN9HNY9SF32J3bu/AAmCYyuCfuIPXtTCm+C4hFezLbu ncVG1mcLvoy6eb7fGAdjLVw65s9DLRUClHD8zgP5PMx8JKsgP3curSZBEjRnB2NsTRchY5F ix3savnkOEubwxopsVAXBHOwdOnDvnb1Ccnw9g5II4Xr10OP1umpEycaw98fyfv91xen3Z9 DlMh0uolqQGgyl8v8tkkg== X-UI-Out-Filterresults: notjunk:1;V03:K0:/+6qvJ1QfqA=:5lFmzGCTwQY7Wj12cDc213 PHJVHeYgsO8qmqOdwoizmjNUCLkCEQLlFQGh3BWzbcVlU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be1NKHvEgWd75QA+1HgBVoDXF55UyTMQw== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo In disable_interrupts() the TPM_GLOBAL_INT_ENABLE bit is unset in the TPM_INT_ENABLE register to shut the interrupts off. However modifying the register is only possible with a held locality. So claim the locality before disable_interrupts() is called. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 6f2cf75add8b..ee6b48c55ac9 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1084,7 +1084,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; disable_interrupts(chip); + release_locality(chip, 0); } } else { tpm_tis_probe_irq(chip, intmask); From patchwork Fri Jun 10 11:08:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877470 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 8D691C43334 for ; Fri, 10 Jun 2022 11:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347847AbiFJLJX (ORCPT ); Fri, 10 Jun 2022 07:09:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347236AbiFJLJW (ORCPT ); Fri, 10 Jun 2022 07:09:22 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1FF014558E; Fri, 10 Jun 2022 04:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859344; bh=h2TS/0VnUJCYBFtIAAMCfO7jV4vdocdBAuzudeNWs78=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=WjH8K5MYxkrE9XH9tqAaaWBGobyqIbELAYNFCfZY0+/uuu3VB0Ripvn8SsocTSvfp OK1IYksTcIcgxf4QLrcZpAktfy44NQsc7G5cT8xWxrMrFy3mi622ueJOO827bgyIJm ZCCoc0+sa+b4HxNnO+lbEyE/E2kGhw4l6ovl9Gy4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M8QS2-1o42M42AGO-004TUg; Fri, 10 Jun 2022 13:09:04 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 03/10] tpm, tpm_tis: Disable interrupts if tpm_tis_probe_irq() failed Date: Fri, 10 Jun 2022 13:08:39 +0200 Message-Id: <20220610110846.8307-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:zej+GdlgXsvMXt3EbX2BjWswFuyOPmIPYQx4w9z5fZzqNm6LNTt AfMQ9LT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LTZhGHCvSDGnwWqGU5Ffe2PNL1oyktX0QXmforLc kPMi4SrZk9xxleUx8nqAb5JttOGY+HVldw1nTc5k9+8Pj9LCNzEDT5HNEIjhsyjCBxhEPfvRK yWBYvlb/I/SRaJnZqu5Qpo5nFTRNfmtsgVBs83W6SWkuUALLl93fVidUVlyt+g8GnClRPaqz9 BbI+bhcjWVf5ffFNZEJZPTUHbw5NN7+J0uSdcDfXaxNw2EFR/aRnWhPyxJvDQ09Ez/SLfXJk0 gX86p6IQM8n1Eqfo5a1e6pnX9DroIGSGv482hTWo/VdoOL27BoE2uHgFA== 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 chips->flags. Currently the interrupt setup is only undone if tpm_tis_probe_irq_single() fails. Undo the setup also if tpm_tis_probe_irq() fails. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index ee6b48c55ac9..dee701609b80 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1077,21 +1077,21 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - if (irq) { + if (irq) tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED, irq); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - dev_err(&chip->dev, FW_BUG + else + tpm_tis_probe_irq(chip, intmask); + + if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - rc = request_locality(chip, 0); - if (rc < 0) - goto out_err; - disable_interrupts(chip); - release_locality(chip, 0); - } - } else { - tpm_tis_probe_irq(chip, intmask); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; + disable_interrupts(chip); + release_locality(chip, 0); } } From patchwork Fri Jun 10 11:08:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877472 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 C7D2FC43334 for ; Fri, 10 Jun 2022 11:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348748AbiFJLJZ (ORCPT ); Fri, 10 Jun 2022 07:09:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347791AbiFJLJW (ORCPT ); Fri, 10 Jun 2022 07:09:22 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D06B11455BC; Fri, 10 Jun 2022 04:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859345; bh=HJYYp0bwrNF5C8gYN46qoheOfhuHaP68v0BHQ9qHpDY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=D6kYMg6GW9E/h0Lbwe993mV7qxqsZMl8/EuAJ22E93iTJDbLXiQvicx9vauCmJJnC eOb+/Cl9uxWMXjk30OT3l3OXd5GsLTCirj1oGWo8VPI03hF1Q8RSf81fDCfpkA4f7H Gv8kl/2L8qPEj5oWbv7LI+paMmg8oZicyAyoSNU0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MWAOW-1oEWjq3QPS-00XawK; Fri, 10 Jun 2022 13:09:04 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 04/10] tpm, tmp_tis: Claim locality before writing interrupt registers Date: Fri, 10 Jun 2022 13:08:40 +0200 Message-Id: <20220610110846.8307-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:NAHbs6qnkD2A+YAgGc+z0d3gM2Lu/P3TMQtD1xYaQWoXrocevb+ i1qhqFvmrn9IoGB9AsiKNbNAfAX8igRP+8vOJ0KChdAuY5Qn7YSTjd9MYCPJEe5b/djw26i OpHm0GORvZXwSSIga38RYO7zk1divOEH+eBYT9KxLIW6xpLrajlQT7ZmAyp8Z6ehaCeENDF 61P2ssTVor1PDzx8Jzggg== X-UI-Out-Filterresults: notjunk:1;V03:K0:Nl6VUL5xV1g=:zddIOInR5fYQ59+fi1uA6I OwKSbx+eo4sl0iWiGEarOjU2QdBTBmqwqqcp7S2NUvwDC0nUY8MHn3eGryU6kxsKe8C+YoETp RSz58wKz9W/J5QPe0ANsuNxz1gBhETwZy9c+vKoSuzfMm/bhStq7H/GZEUxtwEq5ejdwxzdP+ ULejMwDlkoitOXjZDP1dqks5r2TtrraC92up/JfM9yIpHXh9a93MFy0iimaZJu8WWT2V2sWeW DuLrvFEqLEjoau2zhMmWXUWWuKmICQNi+EW/KwYy5waFtBikvJG6CDbYZzdb01Bc952aDDlSC uZGTKhyUTnT7QKj1rMv+YpZhRzb2CUSGOf786MI0W67X5b5Q4mDTa6f14F305DO/ahsvLA1pv jIrcZaRLhdwSwe1tkthx5ABAH3vmyr7fkI4fphJp6DI6rgNbRjSsZAwOMEZwrD1t/IBUHWFuv i4/yhCJ1q+XOx5t0RS0ltpZMaRX+hUbXOEWEK1W5bUD+EhpSb3p0O+YNjv2u7P48nhFnfFPbJ /EH6OdWf5NsxwfxaY31FYPlKZvfHYFdfOSnAh1xR33M0biNPOZu+Je4cjVxD5cM99tkRd8kFK S7bSfWcnWnvxs3rv++FtLfdOIpY3lHUUNGUxToAIa9JkDUZUTAvkxKPdGXaBmBsuQz5+8OcXJ MlzLGZsxGvkaBqB3X6eCzBJSg4t/6hfvgft3F0sNF5dIwMynH/6uC1V5+P9JGRgRJbYjCCf/W 1QY0fi4XEUN2aUoWkNphrxs/X2nbGMld7EoH/MK5If0fDSLge2QxorQgS7ro3AaXabAH1fUPs d0W3CfOfrwHCNbcW8iQM2tcuUN951I7fk8rBQ49TDUuABarQ4GrVewyhqTbUdNbL6iB6wL2D4 O1WQZpxg6PBNj7R0wxYWHm5ODq27DBnZYVNO1T2l1T+DE1qdYGKk5mZB1xHhkbPx5Jh6WAXFd 6JpkZ+5u4ErTCdyRX48aha0ASl9tog5UFiSeGR+1uoHmLOxBFyc73Xf1BO5TtUgIn69vHSp02 ozWLgbQ1rpPRn8xH3z5Lkg2/MW9NXvu3PYXUREommk2c5GuiVb77KyzEc+Lwrj3Q7vHfpHHtI uMamiLxKI3N/w1QZygv8Tt2DPZ07rXc2B/A4drH8MNtRXU5KObyk0c/Ow== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo In tpm_tis_probe_single_irq interrupt registers TPM_INT_VECTOR, TPM_INT_STATUS and TPM_INT_ENABLE are modified to setup the interrupts. Currently these modifications are done without holding a locality thus they have no effect. Fix this by claiming the (default) locality before the registers are written. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index dee701609b80..718525fcadc0 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -756,30 +756,45 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, } priv->irq = irq; + rc = request_locality(chip, 0); + if (rc < 0) + return rc; + rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } /* Turn on */ rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } + release_locality(chip, priv->locality); clear_bit(TPM_TIS_IRQ_TESTED, &priv->irqtest_flags); /* Generate an interrupt by having the core call through to From patchwork Fri Jun 10 11:08:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877475 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 C8D59C43334 for ; Fri, 10 Jun 2022 11:09:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348677AbiFJLJ2 (ORCPT ); Fri, 10 Jun 2022 07:09:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348086AbiFJLJX (ORCPT ); Fri, 10 Jun 2022 07:09:23 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7F39146416; Fri, 10 Jun 2022 04:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859345; bh=p955SyiSzBhWDKZyzjCb0RQrzzzHMlRchzhBPwUvL9c=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Uedbp9PiIwiSA/4jX7EyXN7wrD93q8GdX6vyvHoIJEJWaPkbdSsZDql9w2L8lKRSX rYdc/HGsra9oM4x5he6ITRilDoRuGkNT4mev7vmJIE0+1oPipXusGoeDsJHcEbgfx+ P1200JSGOBOgYZQFc1bDNY266ZrE1t9mplWertW8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N3bWr-1nYZHe0aHr-010cAT; Fri, 10 Jun 2022 13:09:05 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 05/10] tpm, tpm_tis: Store result of interrupt capability query Date: Fri, 10 Jun 2022 13:08:41 +0200 Message-Id: <20220610110846.8307-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BY2VZJgYcZdy5zIhVGCICkZ8eePhQQc4vLdN+/MI383CBnP2/uF VIFiiFQuv6pKsETm1HfMeLdoIezpnagNlHViF3AXuwdsrDaV/sSkdKP1hYcg24IX0ZjlXux FgvQH94dcrFKCKMqO8UngfCJOmirlXt7yrEFhN9eKBV8zmeVCdoMLg+hxXJdHvyIawLl19+ qGrg3lse45tsWYsVgc2ww== X-UI-Out-Filterresults: notjunk:1;V03:K0:+SrIRyz0C/w=:sNiyQ6W9TEhnIIqWjbBPLZ UJApolDV3vfx4d5UQxjaN89QrRWSpPZiuye9/AqtUlK5kkVrmmWfiX0HGD1E6XBFHnQab/ivA Fs5nonakShpW3omY7YidNzeY+g1UL84SmTyF6Q2s2PE3uflHRV2u6yZqxgGTo48gc6JkykO8h CogY6l2nTWi9YcPJyqqaBkBoYtUsLiKRgtbFuS3CPLjgkAtK4MCZXjc2ckSokLCAkBuBg83ZU aA9gnI5qeS//jsiS6qn2Od0gG2v5AgiABVhExIWirpvtb/xAK22tQKCcmHASJ8oh0bRRwfsuR 2+Pf1d32aQUohqVDB8bLw57snN2401gkNHycNLdGIwT2qWOsajSHja4jRVH1IPjLH80u83E9l cT+gyBQJCHS7nxRboKRvBeWJywkR/PkBS36bIQZmbAJJdAkhaIhnzSLis5CeeVP1VjW5rinNU B8i4371yY19LPCAYQ5eBGVPPHRiCFai8TmzFlIcNebRylPvzORXa091//ZAWOCHu3QaKXYw4x FQq3tLqzKGW1UvSqQvUz7IaY0Qm1Wj7kueglOwGIUC6v8ZjGj86SgR6I4xihE+SfulDsjYUL4 k4RR/urEmwd6pbmY/QUbbLLkeTGV6MD2+AFdwgurq1+pFdU5BMLTQqSoGJAcTRljiAx0HZAWI WinTPIfYVpYQdXBmIXp6L1jnjv2kp3KVLKf+f+Ka7X2hCxWrC8PQpzyUqVQsgCFga+dqMuAhw nigfniTJX/MTPTZOnIf6WW2Wz2t1H2USTN2Hz4livJcQLkZ7CrjNeRoq1wxeDYpy6oIPVT+Mj iNzVcHUCiar1NukMZWdjFOE6owErYbMLQOH375RFVMlu0Aeol0bUYi9P69zDL0l0R/sSBjNIc 22o2Bg7dEiDoP6U+lqmYJddQwCMKnDwAF+3YNLUu+WrjJyYhMVzxqJGm0kHATRXIEdyfitrvF 15Htseh0uxdMu4EW2PK7ULLY9rUVJ+FdwIl3JVR8a0MlKQgRrZnk5xQ0Sh9imz11czebPvdcX mBliLN50/yuS733hj8/H2KERLaJ6IBi1KHHYURP1xDmx+pxA1e1DXqskm1he8qNYHkB23QpQL +C45WAH9Tz24l8aMxrFEIYY0dJ1/I/ZG8fT6B+S+R+bPUdVEdXWvsZNwg== 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(). So query the set of supported interrupts and store it in a global variable so that it can be accessed later. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 73 +++++++++++++++++---------------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 718525fcadc0..2f03fefa1706 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1007,8 +1007,39 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, if (rc < 0) goto out_err; - intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT | - TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT; + /* Figure out the capabilities */ + rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); + if (rc < 0) + goto out_err; + + dev_dbg(dev, "TPM interface capabilities (0x%x):\n", + intfcaps); + if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) + dev_dbg(dev, "\tBurst Count Static\n"); + if (intfcaps & TPM_INTF_CMD_READY_INT) { + intmask |= TPM_INTF_CMD_READY_INT; + dev_dbg(dev, "\tCommand Ready Int Support\n"); + } + if (intfcaps & TPM_INTF_INT_EDGE_FALLING) + dev_dbg(dev, "\tInterrupt Edge Falling\n"); + if (intfcaps & TPM_INTF_INT_EDGE_RISING) + dev_dbg(dev, "\tInterrupt Edge Rising\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_LOW) + dev_dbg(dev, "\tInterrupt Level Low\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) + dev_dbg(dev, "\tInterrupt Level High\n"); + if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) + intmask |= TPM_INTF_LOCALITY_CHANGE_INT; + dev_dbg(dev, "\tLocality Change Int Support\n"); + if (intfcaps & TPM_INTF_STS_VALID_INT) { + intmask |= TPM_INTF_STS_VALID_INT; + dev_dbg(dev, "\tSts Valid Int Support\n"); + } + if (intfcaps & TPM_INTF_DATA_AVAIL_INT) { + intmask |= TPM_INTF_DATA_AVAIL_INT; + dev_dbg(dev, "\tData Avail Int Support\n"); + } + intmask &= ~TPM_GLOBAL_INT_ENABLE; rc = request_locality(chip, 0); @@ -1042,32 +1073,6 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - /* Figure out the capabilities */ - rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); - if (rc < 0) - goto out_err; - - dev_dbg(dev, "TPM interface capabilities (0x%x):\n", - intfcaps); - if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) - dev_dbg(dev, "\tBurst Count Static\n"); - if (intfcaps & TPM_INTF_CMD_READY_INT) - dev_dbg(dev, "\tCommand Ready Int Support\n"); - if (intfcaps & TPM_INTF_INT_EDGE_FALLING) - dev_dbg(dev, "\tInterrupt Edge Falling\n"); - if (intfcaps & TPM_INTF_INT_EDGE_RISING) - dev_dbg(dev, "\tInterrupt Edge Rising\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_LOW) - dev_dbg(dev, "\tInterrupt Level Low\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) - dev_dbg(dev, "\tInterrupt Level High\n"); - if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) - dev_dbg(dev, "\tLocality Change Int Support\n"); - if (intfcaps & TPM_INTF_STS_VALID_INT) - dev_dbg(dev, "\tSts Valid Int Support\n"); - if (intfcaps & TPM_INTF_DATA_AVAIL_INT) - dev_dbg(dev, "\tData Avail Int Support\n"); - /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); @@ -1098,7 +1103,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->irqs_in_use = intmask; + } else { dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); @@ -1145,13 +1152,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->irqs_in_use | 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 0f29d0b68c3e..8e02faa4079d 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -96,6 +96,7 @@ struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; + unsigned int irqs_in_use; unsigned long irqtest_flags; unsigned long flags; void __iomem *ilb_base_addr; From patchwork Fri Jun 10 11:08:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877474 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 1A451C433EF for ; Fri, 10 Jun 2022 11:09:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348046AbiFJLJ2 (ORCPT ); Fri, 10 Jun 2022 07:09:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347832AbiFJLJX (ORCPT ); Fri, 10 Jun 2022 07:09:23 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7D7D14640A; Fri, 10 Jun 2022 04:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859345; bh=mLuSt9GrDvQ8CHVFpIFl/BDsUxB55rqACDGcwmQPwX0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=IggaaXsWOn6fl59/cFAZmlF3IkeQkvdvCn6nwxUv17A2xnKSm5Umao0tjJt1rAGr7 Jl0CLIXrachWQPVcYAuR0M7wOu1NrqM7z/tb++BaUB1FLnvICzF8aK3QhrNkDjgeY6 a4kJAtGbUgXYXTC2Xw/1lBqCwtP1uj5M7cH80guI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1McH5a-1nTrfJ1zEy-00cjOA; Fri, 10 Jun 2022 13:09:05 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 06/10] tpm, tpm_tis: Only handle supported interrupts in wait_for_tpm_stat() Date: Fri, 10 Jun 2022 13:08:42 +0200 Message-Id: <20220610110846.8307-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:V9ZSj7NtP38cs9cWw3vp2komO17Wj/HumTOgtp20/73V9KjgMfa cvye23uGL22ne2bQCUvSEnEZSRd2LGYpIW2f1Pr4LB9MFX6umJcv1JcLmukQFWQU0y/plI7 nLxfJDs3GEdt9sHnA+6ZVTIFrN1Difx0pvAhMY2ceYWjBm5akUvMsLxqkKlJF3gWf01eSzF pJTpVRo7VVzhElkFB+bOQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:mhz9Ol5hJp4=:DOvdfBWCHo8CQkhJ5W44gL yMtxWCBVPO4LD2R4Di/MALIDlwcUB62NLcoN2gwWLtyehDCcuL8dCjMYnsL2SJGW+F1OYjkQG BxCtsdsSDuzY6PPNCY3WwzlKZvyBy3Q5Gj2BlFwqQAxZeYWZscXE/J0CisjknJfH3Vx9nCPnW QwkQnUYXpioWfvXRbObBZBSnc0hmotHQg9NqzgWvi6XxuPBYPqx5Kvsvt3tdfoVtIe9Kp1APZ tdt7trTESd110gyCSVfciILTQFKn4blPs2NmWvvOxLfa235w66IFn7J0WDy7iQLjPJcOMfTan sumz+UWGpMtWVAKM+fGkXMqTw42Jyys2rRVt9nRxNQR2yqZoBcuLzUsdql5JGky2NZtZLAc70 dj5VmipviVxpgjfcwDhmDQ5q9PLh/bxuZCEpQ3P0JO+6+Bw9sZHKZTYHmn3g10+Pu3QznnkBd xN7qq3qBKVM1sLc5bfnM3NgKe2uDUujAsNWpVZdxg1tYCE0PeCmbQh89jO48pVB64mL3xCShw K/OLrH755ysLixZ4V7Wr+JQaQJqdLpzpoqNUAe5uvp+dkvS0CDwMH+5bfxxadCCxQtNRYBpPK WES+97JYROXZhkTsxQNjJHx43tHnbLgSio+O6wwHBZYL4zAtTetNicccUh7UcJFuuG8avWHU2 dQYWQzNYMrq1sG/1OxCkwbo4zyqxoc2+BCLCfVzJACxKFLRlhf9+eyQPLNcF5b6nkw2hi/hyw wNx6WVu3p2xFjPTyff6onISMj3x7IjPi9TbwxaJ4SNd51Jx/qbMnhFeK/lqWr1tGlEiHYesZS Zq6+eNNk0mi2VD0pfDBz+A15kH+goiHYXqcsuPwUxqMUPvyAOos77MlBnrA7qPzprMCuHxAQy xJOFQ3ESYkBvEUa0uixQSI6SPQuePVNjU44G0w+wuOw1MVoqJ7wGIfTT8BETUB+k2urNdogeh jz3Ks6x5/Up74iC1zZgSFAuaIhTHFbRFijYYJLtwjradAvuE7owfxvut/YKS7js2+4GzqtvpB AkSggowdK9xQoubhQacwbGRb4pACqZqGD0HZapke12h6B3pv4jwzE7PrHq1n4YfNc8D+9G5uL lNLd5lbx9mD2NaeaQdzbZtZ66lXz6RunpN5YZsCSSHZXVh3fZ0habllkA== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo According to the TPM Interface Specification (TIS) interrupts for "stsValid" and "commandReady" might not be supported. Take this into account and only wait for interrupts which are actually in use in wait_for_tpm_stat(). After that process all the remaining status changes by polling the status register. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 46 ++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 2f03fefa1706..028bec44362d 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 active_irqs = 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->irqs_in_use & TPM_INTF_STS_VALID_INT) + active_irqs |= TPM_STS_VALID; - if (chip->flags & TPM_CHIP_FLAG_IRQ) { + if (priv->irqs_in_use & TPM_INTF_DATA_AVAIL_INT) + active_irqs |= TPM_STS_DATA_AVAIL; + + if (priv->irqs_in_use & TPM_INTF_CMD_READY_INT) + active_irqs |= TPM_STS_COMMAND_READY; + + active_irqs &= mask; + + stop = jiffies + timeout; + /* process status changes with irq support */ + if (active_irqs) { + 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, active_irqs, 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 &= ~active_irqs; + 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; } From patchwork Fri Jun 10 11:08:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877476 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 21C56CCA47F for ; Fri, 10 Jun 2022 11:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345515AbiFJLJ3 (ORCPT ); Fri, 10 Jun 2022 07:09:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348108AbiFJLJX (ORCPT ); Fri, 10 Jun 2022 07:09:23 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7FFC14642A; Fri, 10 Jun 2022 04:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859346; bh=O45VmH8NuxzGZD4XqpbBWPkt09hOK0EdvFcOYQOngco=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=XUJ4KEBOFPQEsECL8OmhSz9RoumufW+odPQuCknWFgKaS+1cwtdt2G0bUwELwSP4+ +GHGuMZmiQh0ekfiCtpfp2sNmXsnu44GtxyvDeDwjt98dc9DhynGODLQa2AkbDOsOX h8dWOlynCn2VasbYdKoEYy7Ah6J/yJfPFUZNOePQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MxDkw-1noqxF3HVg-00xY1S; Fri, 10 Jun 2022 13:09:05 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 07/10] tmp, tmp_tis: Implement usage counter for locality Date: Fri, 10 Jun 2022 13:08:43 +0200 Message-Id: <20220610110846.8307-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:73KXtmhSPA6z0Ps5tcxg1HoBOwfkc5Jk0+wV0CmquaXV+7z05O3 aqDSmUVnsO3xpKCNG5BMtrLphY4YGBfJSpLR84thdCOTio3z1BPd1amY3YVcdo0rj1pzUZe Cl3STbGbuFRuF6/e5dIQlMrVk8iVGPslpyXPxh8fcigMqRgKs25+E2bED+PEc1nXaPUfseU eobIvmN/CKirKOqvu/4Zg== X-UI-Out-Filterresults: notjunk:1;V03:K0:reKjEVESRyE=:QMiPPmAMowHXw9o0jUspbw CajIooEWEI/df6zM8PGtE2wWmxIGfNxolS0a91dRjXDEsqY3HcoUgNNU3l1f+RQ47Dsn2eKtc t8WdFZqu1PemGArS3aIYS9aOKDUWd6WhlNliabGZtf2GJmWKdbqG6yiRTgJQ9wKqUnI5EqwBH Xatzkl/vqK66bYKGEq29VnE81ha6NZqJ2B0/KQpZ4ujZgZqBj4EAsOems9bjpKllkyzhOqBUK edVnEuA9KR9VXoSS5Va9OSmxBfiJ/Poo2JAZ6kMgY+xsJFIBIMraoh8tra5jafG7JwoviY9vf GQ7AAQtgrfegfIuBtyBDAQa0Jj0vtwJDKRh8yY8HT8snvzylx7oXfUNa4k5J1CffQlAyKxrFa tYMvkvNpoCuNXNrCVk5gw7E9Yy00hQNzFEHxCBtntLSc+ip3vWJlRTTyfh19f0tJKuzMxwa+W GOdTxXpW7g701IcTCas1W+Yo+m8FroNxOXeTMpZ3V1GsJHz1Q0mL+RGhRCnJmV89HGs3jzLO7 VVu4PFFM9SDxfxCmpDM1TiaeL3DvpOUnDEGSu1UC7/X1U05kYxdztvWPHGS1Xfbqu4jAAiF44 Em7W/LtM5s22lGGZkdJfIJGmlY+fZXGwkLv5JsZxpwoTgRWQdX7XHxpyB6xeHk/GiRyac+cel 6yFSmJi1WwWDxKnpfPrifcxLtWytPohLz3M5gs77dT3w4oL8lL4PXjFdowj78hRZb0P1125ok ktyBxcbdm1tnUxDhDKAKd73aegtz8LGSLwxYtfFgftT3DWngSj6HaggAlTsLE3spMDM34/qSG Xp2tWNwfCR2sHxu3OCoov8mBjj/HB/nRkRa4L9TFa75zZYW04CeUPMoDipXUdNLfXAQ1b+t5d 1APrec5jmZ1P9CnSlUEfOvGaASJm1PxzpWQNnl00P0Z2Ovm8gIXFLZnbxOv0HM29woI5MYaxr 05IJULpe2WXLa7kcm4UBfy2D/Rpk6Vqla4orjTdw9nrBShNG5xihQ+iJ49IjFkwhDW9TXRo60 3dmsmDKfwPvXoeG4j8BUbnHH9z0nbDoWjm0b62WOoWu2m52GIiDbqoerAm+tUrXYnBujJpI2R UalgGtv0TRNYpyGHRYwU++tElfmz2yfOHBeDcClOQNdKzAycFFeCJnYeQ== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Implement a usage counter for the (default) locality used by the TPM TIS driver: Request the locality from the TPM if it has not been claimed yet, otherwise only increment the counter. Also release the locality if the counter is 0 otherwise only decrement the counter. Ensure thread-safety by protecting the counter with a mutex. This allows to request and release the locality from a thread and the interrupt handler at the same time without the danger to interfere with each other. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 30 ++++++++++++++++++++++++++++-- drivers/char/tpm/tpm_tis_core.h | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 028bec44362d..0ef74979bc2c 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -158,16 +158,26 @@ static bool check_locality(struct tpm_chip *chip, int l) return false; } +static int release_locality_locked(struct tpm_tis_data *priv, int l) +{ + tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + return 0; +} + static int release_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + mutex_lock(&priv->locality_count_mutex); + priv->locality_count--; + if (priv->locality_count == 0) + release_locality_locked(priv, l); + mutex_unlock(&priv->locality_count_mutex); return 0; } -static int request_locality(struct tpm_chip *chip, int l) +static int request_locality_locked(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); unsigned long stop, timeout; @@ -208,6 +218,20 @@ static int request_locality(struct tpm_chip *chip, int l) return -1; } +static int 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 = request_locality_locked(chip, l); + if (!ret) + priv->locality_count++; + mutex_unlock(&priv->locality_count_mutex); + return ret; +} + static u8 tpm_tis_status(struct tpm_chip *chip) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); @@ -987,6 +1011,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); diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 8e02faa4079d..e1871c482da2 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -94,6 +94,8 @@ enum tpm_tis_irqtest_flags { struct tpm_tis_data { u16 manufacturer_id; + struct mutex locality_count_mutex; + unsigned int locality_count; int locality; int irq; unsigned int irqs_in_use; From patchwork Fri Jun 10 11:08:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877478 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 5849AC43334 for ; Fri, 10 Jun 2022 11:09:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348335AbiFJLJa (ORCPT ); Fri, 10 Jun 2022 07:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348299AbiFJLJY (ORCPT ); Fri, 10 Jun 2022 07:09:24 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95E9814642D; Fri, 10 Jun 2022 04:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859346; bh=8pa7jmlaKih9YrYAMoxNaZ4QPmCYmk4V26CTRIglNhA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=bSwRaHR586/m1GevqhL75iI+ujBW/f+Qho62120MsI46IzSmF7WT2qizxPIgoUWsy dB9XuBFuHOXL0dsV3vct/qFqU5j4xwXzLb788zN9aAhAW8D8KdPMPGjcyVyQyZjyhF NYlg/nYA5Lx5M9IwDpdiTyWWJBgKS43lMKgSh2hk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M4s4r-1nztED0Tpv-0020n7; Fri, 10 Jun 2022 13:09:06 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 08/10] tpm, tpm_tis: Request threaded interrupt handler Date: Fri, 10 Jun 2022 13:08:44 +0200 Message-Id: <20220610110846.8307-9-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:V8BbFXXEchexOiGgDifqmFJO5c+ZfjhBgyOVfLvGI3Jop7tZA7S /9n1aO6Ae0L/iEXqIrJI5j0YQZicb743GM7rpdSeE2LuitpKwhZ5Fioop6mFwsg3XvH7ADP 7piw+gvaZLsbMuEk9s59YPTbxx2lui2Q7LE1/CfbIyzUqvvsBfiQbiTQhaYE0nIAPK/Dc+E OJlBLSO9Btad+57sP0lOA== X-UI-Out-Filterresults: notjunk:1;V03:K0:Wbm3A45bWdA=:Slu9pDXD1h6gIoApPQiRbx hEt9s++g1LT8l9m0HPDFkZSMSh2VLOSgxHBeej8F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NK4AB4Oqtx3UhA5nFHvWgFSVirWtNgBZUSRexA== 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. Fixes: 1a339b658d9d ("tpm_tis_spi: Pass the SPI IRQ down to the driver") Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 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 0ef74979bc2c..8b5aa4fdbe92 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -794,8 +794,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 Fri Jun 10 11:08:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877477 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 5FAE7C433EF for ; Fri, 10 Jun 2022 11:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348883AbiFJLJ3 (ORCPT ); Fri, 10 Jun 2022 07:09:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348215AbiFJLJX (ORCPT ); Fri, 10 Jun 2022 07:09:23 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7FA814641A; Fri, 10 Jun 2022 04:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859346; bh=f0hgcapl/IoE42TzU30gGyD7O3DJqxrqwIi8kJgwDuE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=K0l9Q28V4fQiCGQDblJ+XmxBcV/+PLzeV0fXd+UDX+sDmKLddhM8FRHHXhLPxTZEM c0yIf3UY37XSJnQDH0VAjA2ieMt8454gbsyxWQYZI1sZhoI/TBMKXZzQ1sQD9VYBiU a4+9WjPqIopmNPxI+Fha41V7L9Z3Fod1d7UVWmeU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MSc1L-1oAO8x20lN-00SwNX; Fri, 10 Jun 2022 13:09:06 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 09/10] tpm, tpm_tis: Claim locality in interrupt handler Date: Fri, 10 Jun 2022 13:08:45 +0200 Message-Id: <20220610110846.8307-10-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de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jjZ3OeUa3tnTAM1r Q2TGCC6jROegDHztYnbTdzxxUr95Z/1v41BO4PC+xy9kdTiQP6eyBUQD8T498eFtPjLyrLp0B ZOmCIKf/mtmiEpXUgtF5wlUZtvnb02dYY/9aLQqVphD7SMykEhrgWM3kEC7CT7Lt1TBvbE+m5 BmB1d2Zsm3iQFmFZNglHq6KMBsOuZd3XSw2pjh9F/m2XZgIJYhCjrgjAg4dtPCJz6lGcMb3Qu XE17MkT+LZvqjytYYbNyp9rCg5/MmfB8sG9uQhG2Xa9rYuhlGqtoKQeV2Kn3VrTnwDFwhVE1G 2waroHGqHRAtBi363pMI6irCLhVRHzuUSQ2ATGQIOTTev/HpCr1hdWEhGBG3LoFQfPO5aNFrb HlvHxS4BcHh1AERknna5EOke9fXXxqEFUOKXA1A5Evn8BCxzLlm2ENO4Q== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Writing the TPM_INT_STATUS register in the interrupt handler to clear the interrupts only has effect if a locality is held. Since this is not guaranteed at the time the interrupt is fired, claim the locality explicitly in the handler. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 8b5aa4fdbe92..e5edf745fb23 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -753,7 +753,9 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) wake_up_interruptible(&priv->int_queue); /* Clear interrupts handled with TPM_EOI */ + request_locality(chip, 0); rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), interrupt); + release_locality(chip, 0); if (rc < 0) return IRQ_NONE; From patchwork Fri Jun 10 11:08:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877480 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 6ADBCC43334 for ; Fri, 10 Jun 2022 11:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347505AbiFJLJc (ORCPT ); Fri, 10 Jun 2022 07:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348835AbiFJLJ1 (ORCPT ); Fri, 10 Jun 2022 07:09:27 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54E4F14640A; Fri, 10 Jun 2022 04:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859347; bh=5mv2L2DeQtB9WAxWjQEkuqF+lIxHB5iiZmw17kddLBE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ZAsLZG65uKhet/wJCH1L6tN32sLsqMSBYtktiwhXTZTtbUyiN9iln1S2ebTeNYDdC JYiV27tO/eQ20904tYn5JV+q5TzjbYe9PB0rvQD9/mWi42Wq0n17x4301YNzS8wLte QHeO0qUhMoVbHSCQBl8InSpY/dy7WQJB0BQY8zAA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MjjCL-1nJ6pl3YgF-00lIF7; Fri, 10 Jun 2022 13:09:06 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 10/10] tpm, tpm_tis: Enable interrupt test Date: Fri, 10 Jun 2022 13:08:46 +0200 Message-Id: <20220610110846.8307-11-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:qYfihU3Jxj2U0goYEWYlcSqbgqtc13j943e/09qd+M9OufS+/dA YbAOE9tf33yMOARUfdxAg+lJ0yYfbQEtt/FNYNykyAM8VLCxCFvuPQ6+4GuoBofHXaX6CSs 2g7cIWGl/puLAP/zC59vjAO5HtF0cSg0Beu9+95mF9HaQoq/ovRofSbMA5ixLNcW/hM2uGY swcBPpNEXP84OZ/U3DT+A== X-UI-Out-Filterresults: notjunk:1;V03:K0:01WtxPALruo=:0cjONS1HN29ihMExGaaW9f vdK2+HqSs4v4/m4hLNz0ubjO6mWJS3jUjwN3vbeqkVkkGkRTAW4gVfVL+4RimSpKsvAWMetqy 9x5I2x7BNsLlf8Smvrxd9phzwvFoDLgJdVrPzsfab8CpQeMREdgbjRMoL5Qvlw/01yOYnFEjz Xtj2MuB2RUjqgt7HGVbPMYudyiNit8w8Ja0OaMWue99tKJdznF+YB8MFw29G0nHf0J0jcdg9N VNvAwfF93T/xIjBcd1+Oz+fzMPQB0RdbHfb7sG+XWuC58hHtgje526DqEBnpb8IAvc45Bt7Xf T+1mRQKE7tPVN6ZPBedORNdOBCJ8yBCnGvbyMUXeQkV2EdhNYRsduB3EyqQTokf1HFkhvbzGk eK7MtZulaN5ZyzrENm1bsAMH28uMtbd+pxP9BIKAiqExgDNyMmtB0AO2U2hzVVp4uvYZfYdzp rAnnn8uHYtP3+wgrJ9CtyBJEzqlWyO91WU4BrvpA1OIIHvtdrUAAaF5MgHqfqWI6sz8GDbzF/ 8va01jXiKBKKYiSPBtrzZaBDjUSMnT1guUaD7miy9OxMhpvWorUIbyyQSVg/BjVf8KVeH6OKc CF2xdu5U4vP4TZqdPvgYztumyC6YyGMEbMUVODuiTWeYCxT4/JI5TfFSvvGZp/k+ZiTSseSdT HCEerX8wkyEH6Fl5pA/FO9rX7eCUfGeKzdfS7wiH/KsfwZUeN+HDHKnOs7/d2cbUD21FMLOE2 3r9FqLfZuxsoOe+osu9EF3TSytH9vuC1GzFdmbP5mxFBXqQQyGDMazCcv3PVkP0N9zfGykPSp mGrRrAPKZnP4QzOq3VPayPnOWzbawCH+zKAhYwEtreQs1D/nYTVOoYMJfqA+XPbfY5+BT4l5e Hc+fHOtlMZ9khhOkzypyKQYc/wN6GC6dZYVVC4CYwUI4tZw1dscTGje3sHTPZhDJcazs8o+Tc OAng8fQkHxgfISUBr8hoaFi6G5wdfEb3JmQxeKrnZqvbJKDqvCYVVD05y4k8vcrMyAmm5VDYL 5L/6NJ1V3V5olB+AZS7hb3tigKHvgr0wB5fXYWwD99vDFkNM5ha6c69seisQGxKrui/0xadrp vPh/X+OgHTCTU2/g6/SnKQqTA8NaUN4hZMfQWjmh+i5n1/Gryun6UpaIw== 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. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index e5edf745fb23..be229c173f10 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -774,11 +774,16 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) if (ret < 0) return ret; + chip->flags |= TPM_CHIP_FLAG_IRQ; + if (chip->flags & TPM_CHIP_FLAG_TPM2) ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + if (ret) + chip->flags &= ~TPM_CHIP_FLAG_IRQ; + release_locality(chip, 0); return ret;