From patchwork Sun Nov 20 13:31:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116321wrr; Sun, 20 Nov 2022 05:33:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf4YDl8b/z3lO72oJ+EkYbU0kUl/xpuY9rQk4SW7QsuQ1wn+HKeACunQ/+x0EQswsSLPQAEB X-Received: by 2002:a17:902:c652:b0:177:e4c7:e8b7 with SMTP id s18-20020a170902c65200b00177e4c7e8b7mr720682pls.118.1668951195643; Sun, 20 Nov 2022 05:33:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951195; cv=none; d=google.com; s=arc-20160816; b=zS3+GOz3ABxkZHR6HG1NwYrImX8TAbjlshXpPLX9BQZL9JEf5MJpxNdfXWtKdNMixh hXt5CDJ3NfWOty3fYwk7kCiX776b+aprJYzdD3wuMC3OmR+paHvnoPSWcNJS+MHdhHU+ Ymhg6/pgzJIk8Vwa/iesXfUyAt6y1mdnbfNScY3wPCFH+LVPZJ0oDB1uE1e/jtX1kwoQ 8oGyvMvTBwRPWTYrKAMLWglpQDnz1xjIEZdccfhe2P0wX05Y/p4KoItcQcN8yASOQBJ4 Fgj/ZmRhCzPR8pgohxWr5rBmHP6IG0uGDbXEyV078GskzMvBh7tJK9yAOCCq7Y40vU41 QNqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=A4TNiZ1MIqgxBlywM7kePzrqXJ+tGCscjealDs3aYxw=; b=Kw3Tqrl7s++CPeobO3uy34+vd3ftEI8Unw+VQC0DQvULIRg9XfqPXt73DeNXgclI7t zFoQlITWrmftsidm2pQK02hNWZpkuDGfRrfVX+NtMHRfSNP/3EFQWrqdozZfvUONV1u3 5GgtdO3g2uHhBknnWd3ls6jYpS1jJWKUpxRVhA7RUIGwku0FQeU2jSr7KjL84+W8DhdR y6k4SFSFlxgKUoyoJyrG73E2L9WxTHccokzWXNHQfIOIn318JsP1uvZv/KXP7TbgkfNx Q9j4oY5F+v7UCdyZSlvcAUC1FWeJLWwG/GH54MOMhyycMkKlcqRf2rFYwRvy0aIzmJAn uPjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=U1MnMRiL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y17-20020a17090322d100b00187073496b4si9865622plg.136.2022.11.20.05.32.59; Sun, 20 Nov 2022 05:33:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=U1MnMRiL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbiKTNcb (ORCPT + 99 others); Sun, 20 Nov 2022 08:32:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0106AA7; Sun, 20 Nov 2022 05:32:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951125; bh=A4TNiZ1MIqgxBlywM7kePzrqXJ+tGCscjealDs3aYxw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=U1MnMRiLo7lFIAsJR2Z3mDisNFMsDebDtqUsFR3FTFIbYphcarJk13Smb84Zi66pJ x9fGmLZSeYMFqSl7/hVg082vUAf8wAo5dzqRxaCCX0H/HfrB04kHIgsdnlLkHZA0t9 zzNm23vt1iG3BcBtdE1crOeaIkdsp+sxpsBD8RKmOxOB5yShWS7KiFdFIJ6H8lisgb mvZ1k/lPEYPvNYlhA/dY2vEGyQWoM5+K0WdQXMmQYsj+irdHQXGNF4bAldc17ovkwi upBtmO3qrTchrOA20vXXe//XCvo/F0ibq8A8xlzFyQHX+Rh7cJcx17uS9flN9QAXAY 0wawjg1Mm8Tzg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1McYCl-1pVFMn3grd-00d2kE; Sun, 20 Nov 2022 14:32:04 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 01/14] tpm, tpm_tis: Avoid cache incoherency in test for interrupts Date: Sun, 20 Nov 2022 14:31:21 +0100 Message-Id: <20221120133134.28926-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:RuWFAxuNwY2FT86vJNtzPuYEZpoztucbVYAdGLlXTQtT88zV49q KCydeoKPHV5YH+pMz6lMCZ862z8nrCJ3t8aj/jBdLg5gaSCgxo++V98TgT3Bfe8hXmM/kvu EXrvyyP9q62Z0RzfY5+P72e6mdEqk8/52QS3qmy3tgbRrBSLawXH0Lms0kQ52jgOECIBJuP O5XF/9xmFuMhh4Cyklqcw== UI-OutboundReport: notjunk:1;M01:P0:Q+0a9ri9s2U=;cO6kOhfTm36JQ3YSj3SePfm9L3D a+SejTbtWaqb6w8chLd7DuWYH8c62Ia9tV/1HdVKF/rkXduIKgdd/ivkAMP1g3teF8ERiaHm2 xQ1LYfdhKma84M+6PEElYAdUbRbg4KHOZDGfEwq9JNaFSW2k6BVaiLtklc516N3eY8jKdbuT8 rSs0TTnrxx0EQsGU7NdJ7a+2zxwDLm5XVHoxpmlpu6/Q5AiAw4jnaxCGRQK+v/ntTnpZoYVW0 T9F5f53Vx841SzlXntD8zRFVsAr/tVd4ZdbuZ29FQ+qFA+KvFdZJxeI4PH8LWS1kqh2xCMX2m 2qNyp9nxRFV1fiVACOm5BBl+rJMZ/x5f+YL+R38Ewz2xzZs+Pd8Vyw0cFP8ID92F959fe94EW iHlXU9Alu46IVEo/kZfc8h8QmBfmnWAvbYlcrKvZyv+pfzXeTWr1ZMcGcX8Hh0eSHmKEim+uq sRLENbcJmW7rH4XIOH0BzFt8CpHYuXmIpsJBlPXInWAlpH2fE0sTC6RifLd3Ty+nIBqxtZBA8 SbkWppgwKDgq+QGU9PfCyvcIuelbaoxoECxyNT/4DZMmbAow0SxUHri3ZJTu85vuayn2I1Wq2 3nRsTdELLob/WYTd/u/hR0uiYcE2XZHx/SXw2yp7yBAdydldya0sUoS6OSYsnBc7gUAUSeWW5 xVWW9vfR1Hk0hC1z6TdttQTT97tDWBKRg0AmcPF274w/9szWITVkg5J3DQMMv8JoLlXmyUDWv 8MI+mQKPGThXMYN3JLgu1M3AE5sXt/fsuZXbL50LYcD1blDqNKMb7H18Fpi+HXdqJ7GOoKvPD rbrnCEWxmBXydZj64yr672yMhGvThzzypGgvi5dUs0ZiR0aghz7HhijvQGnQV4IIWnmei2qbV jJcYMNCS9450pQlLT6YZp+z5uyd9WfuG6cd3mR9P8SWkUxau4GDyFg2n/LX/bbnZDWSW0TUwl r9I7IpQUDbvEJ9HbkPcy2nYFpQE= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022168421437961?= X-GMAIL-MSGID: =?utf-8?q?1750022168421437961?= From: Lino Sanfilippo The interrupt handler that sets the boolean variable irq_tested may run on another CPU as the thread that checks irq_tested as part of the irq test in tpm_tis_send(). Since nothing guarantees cache coherency between CPUs for unsynchronized accesses to boolean variables the testing thread might not perceive the value change done in the interrupt handler. Avoid this issue by setting the bit TPM_TIS_IRQ_TESTED in the flags field of the tpm_tis_data struct and by accessing this field with the bit manipulating functions that provide cache coherency. Also convert all other existing sites to use the proper macros when accessing this bitfield. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis.c | 2 +- drivers/char/tpm/tpm_tis_core.c | 21 +++++++++++---------- drivers/char/tpm/tpm_tis_core.h | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index bcff6429e0b4..ce43412eb398 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -226,7 +226,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info) irq = tpm_info->irq; if (itpm || is_itpm(ACPI_COMPANION(dev))) - phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND; + set_bit(TPM_TIS_ITPM_WORKAROUND, &phy->priv.flags); return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg, ACPI_HANDLE(dev)); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 757623bacfd5..c0008efb95dc 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -351,7 +351,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc, status, burstcnt; size_t count = 0; - bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND; + bool itpm = test_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags); status = tpm_tis_status(chip); if ((status & TPM_STS_COMMAND_READY) == 0) { @@ -484,7 +484,8 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) int rc, irq; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested) + if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || + test_bit(TPM_TIS_IRQ_TESTED, &priv->flags)) return tpm_tis_send_main(chip, buf, len); /* Verify receipt of the expected IRQ */ @@ -494,11 +495,11 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) rc = tpm_tis_send_main(chip, buf, len); priv->irq = irq; chip->flags |= TPM_CHIP_FLAG_IRQ; - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQ_TESTED, &priv->flags)) tpm_msleep(1); - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQ_TESTED, &priv->flags)) disable_interrupts(chip); - priv->irq_tested = true; + set_bit(TPM_TIS_IRQ_TESTED, &priv->flags); return rc; } @@ -641,7 +642,7 @@ static int probe_itpm(struct tpm_chip *chip) size_t len = sizeof(cmd_getticks); u16 vendor; - if (priv->flags & TPM_TIS_ITPM_WORKAROUND) + if (test_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags)) return 0; rc = tpm_tis_read16(priv, TPM_DID_VID(0), &vendor); @@ -661,13 +662,13 @@ static int probe_itpm(struct tpm_chip *chip) tpm_tis_ready(chip); - priv->flags |= TPM_TIS_ITPM_WORKAROUND; + set_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags); rc = tpm_tis_send_data(chip, cmd_getticks, len); if (rc == 0) dev_info(&chip->dev, "Detected an iTPM.\n"); else { - priv->flags &= ~TPM_TIS_ITPM_WORKAROUND; + clear_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags); rc = -EFAULT; } @@ -707,7 +708,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) if (interrupt == 0) return IRQ_NONE; - priv->irq_tested = true; + set_bit(TPM_TIS_IRQ_TESTED, &priv->flags); if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&priv->read_queue); if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) @@ -793,7 +794,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, if (rc < 0) return rc; - priv->irq_tested = false; + clear_bit(TPM_TIS_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to * tpm_tis_send diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 66a5a13cd1df..695a2516dce0 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -86,13 +86,13 @@ enum tis_defaults { enum tpm_tis_flags { TPM_TIS_ITPM_WORKAROUND = BIT(0), TPM_TIS_INVALID_STATUS = BIT(1), + TPM_TIS_IRQ_TESTED = BIT(2), }; struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; - bool irq_tested; unsigned long flags; void __iomem *ilb_base_addr; u16 clkrun_enabled; From patchwork Sun Nov 20 13:31:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116684wrr; Sun, 20 Nov 2022 05:34:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf5/HOk3bqN0KdPJfBkGiRmTPARebma/HYEedna7FV6ifcanHFKqnKoljPVd2h5jcfn4uEv5 X-Received: by 2002:a63:4c24:0:b0:476:7742:de17 with SMTP id z36-20020a634c24000000b004767742de17mr13816705pga.345.1668951246747; Sun, 20 Nov 2022 05:34:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951246; cv=none; d=google.com; s=arc-20160816; b=d8o90d6HCMgIlKvSr6UylPMhSNpT3kRtaX6CvsS6f2f6H6RWg6bbX1hBU/GFbCTeG/ rhEI6zqJlJmYGc3HMOIWHiZJv5MpkZ3jDUH2jonoimNhvMGUqo9iPK62ife4q9StXAdg hpFm5YbHDznmRKwSK0rgaGb8J7LpeNGgUPhJghpANwtYtCrDbk0c81MTWqJMCSyZaix+ zNFf9rPf8IVJ9nuuB+A/Q5qxq08gpISa7/BTGAfNudGQT1sAayJ8OT0yZfynJp88XmoH aeUWYJgKrKtKf3E13alJMXFCyKaA/s4yp25VKWgFv/tngUUHPf3LSJKJjj+eIkMk5/Y5 1q0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1jiHlANZ8thD5aPn63BXGYT+VamFBFNIAjBcdG+2s2o=; b=oV09i9/MqOGH+AzNp2D2aQkH+TCsrz7nNGjTrQ5kP5a1ITiaeGVk0oLdNu9LYxh6lT YML1mybRBPsjsEDKFsvljoXdHJ2vGMpRXkVuNP6ogDwBZC4X6BZxi86dVfIZ5gWo4S2B Sf3y+rjqyNdA/d/43NCLwDfT7YwsnPVgALBKe0WHTDtV1hKtWww/bGqCBOP9KFmObu4Y U5oW2j8Cr1AEYcwmv+UrSlduE1/ULOQc2b1TAKa/eCkjBm1Q/kjvCLYKfwXGG0C0wBhP WX0xcU9uO/j5qNRBHKo2ZvnX7MDcjiDoosjSIyj9FFoDPXA0i2+OWKpyIludJdQ3l8GP yVuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=ESJFfUJN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s83-20020a632c56000000b0047702d15bcesi9514241pgs.42.2022.11.20.05.33.53; Sun, 20 Nov 2022 05:34:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=ESJFfUJN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229772AbiKTNc4 (ORCPT + 99 others); Sun, 20 Nov 2022 08:32:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbiKTNcb (ORCPT ); Sun, 20 Nov 2022 08:32:31 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B80DF27D; Sun, 20 Nov 2022 05:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951125; bh=1jiHlANZ8thD5aPn63BXGYT+VamFBFNIAjBcdG+2s2o=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ESJFfUJNvLFaEbcb5D3Iaq5mvXH433duVgAaH2oyhqUEKANpXBFF9tTRw3dFazHOh IgHsxvR12p7evjL6IepKdvLMZDYDSeupz7pSEGkEnwlkSVrFJvVcnyW9VpLJO1237y eF957fI/wjSTAnnFjLpOFznT7mfzeoMxZ/UdsgJo0Eu/+BxIDrvaluYjn5lZDGeTmL aZId0F8IzQFs6s0uADyJMNztiI2TBATIV3tIY11712gTAOPDQ6a1kzWiIJcAdCeHad sjton3aicJ/bR2BIudzVQgGBB5TyYcMoYzn4hQT4jHtZQYXh1rqix5uKf8aru981L5 OQ+2R5FifreNw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Msq2E-1pCLRF13qi-00tC3L; Sun, 20 Nov 2022 14:32:05 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 02/14] tpm, tpm_tis: Claim locality before writing TPM_INT_ENABLE register Date: Sun, 20 Nov 2022 14:31:22 +0100 Message-Id: <20221120133134.28926-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:dVUxQWuZX1rElk66a9cVkpJrvR06Gi4LdaXs27+gK9dEmE056yk 33YAC81FsrqNb+F/GS0ziIoLFBYuf/Ser1dsjsD/4e5vFweOIsrVSUSvXBwt6aOzbT7gOOK SdR3z4KY3rT6/XHhk1JAXxj5+whdmoKD9QehN5J9EQM2t2eLs4CbNOI1MR3o2UDfAEfp7W8 ddAtyJyMrv1Gn4egUOHCQ== UI-OutboundReport: notjunk:1;M01:P0:OxC45659cqI=;3PIefNXqEQ/fzKvFqqkFufmg4bn cPo5ZmNr4LTUzuafbBkqgupOfwG0K2zz5Mh19dzlindm2ufM7EfiLxzeKUPSawBTZcbExOwk4 7VQl1T7s/TXiZwnncMLq6svmx0TYUZpZaOeeveOXc7WGZ0EX2+IV6Ushkib+46S35AQFEh803 bwlOFwNC3L3EASKmpSAhoJ8+ehkaofXuCt3Q17YfvLLFZ2k8aNp9YZUxTDXK4x8Rv1aJ5HTyt 8ec/w2OT/BG5Y8lvlYW4L+5++wWGbO5ef8p9KYv1nlulGQk97jridFM0CamkOIWod4OO0944E M3600oGGFMgmNZxw/85j4l+o4XnUavuGtq9nsxitroj1T8zyOzJ1JmiiBC4YCkj0hB87o3Aaf SKfSru4E/+2BMLt36y4XHOhWe202lL97RzPqYJZCiknrd/UNcIfQwq5zW6iiAYYHr2hU/h9P4 UZ0xNxlmsCcvkc4ZQH7sHvhXkdq1qLc9xkLOBpubGgtT+OcESJ1fbQ3pCKxex6Mx7sgK0geE3 gSzXuhYjzOS0UDGDEmANFbI723PRjqhUb2Ib3zy4wIS/2x2Ig5FOdGoFTWgokNECtcW3EaTzo NxMGuIooMpSRGtJpF+gI2vEPn2SyUXMvjhHmXzwRUVGAaNSYi0np1AU0mJBgu5lnYYefKWS3c okCLpGmWO/Xh7HOvIqfi0N/XlDlZZdHd1DBZl3jgBCtn5PZZOeSp/CNYQ8KRnOq0OeJS3nWjA NKrcnMKIUp3Mh6yXW0mGVH/LmiqryJpQnBYmF0OV81pthYhcwIDkoHFQYkAEZstIQwiarM4XF 3egErqiaJzc+PVN6mxcOrsv9XeJ8HarLD9ERs09I7+RIWLiszG5HNS1ttFsFUDqZ+gqMmud+O kXLQu6gVbuvQ19HNOvZMqV83AAe6LKWA7JGMxPiR18XHRDAwicxWt882u6Efhj8cHDxK5h+U6 98uJew== X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022222387103020?= X-GMAIL-MSGID: =?utf-8?q?1750022222387103020?= From: Lino Sanfilippo In disable_interrupts() the TPM_GLOBAL_INT_ENABLE bit is unset in the TPM_INT_ENABLE register to shut the interrupts off. However modifying the register is only possible with a held locality. So claim the locality before disable_interrupts() is called. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index c0008efb95dc..d2c9c9d76893 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1098,7 +1098,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; disable_interrupts(chip); + release_locality(chip, 0); } } else { tpm_tis_probe_irq(chip, intmask); From patchwork Sun Nov 20 13:31:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116259wrr; Sun, 20 Nov 2022 05:33:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf76L34PPVkQN4Cm3v1cr/mykHa2YdeVOPd4v/p+tH9UeBugiyzvG1eMUUygEqPTncFrUmoY X-Received: by 2002:a63:e509:0:b0:474:4380:cca6 with SMTP id r9-20020a63e509000000b004744380cca6mr13984375pgh.229.1668951186347; Sun, 20 Nov 2022 05:33:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951186; cv=none; d=google.com; s=arc-20160816; b=TEuX6ya9xJxMrmoNHe5mr+xX5YeYLIAxYgfJhcl490u5e81w2jXadYDxR5rmsf5neV 9H+brkQJReWsZAzbwaJhYpY9ZIWiWNFhOjJ1nip6lmtGYsYG94Fu0OR+wwa0AyKntY8m svwukJGL0dDEwaA9uyR/uDY1NaM2yyaEDpl+mcoR7wv0I47Oks93oK6ZuDqvypK+8fzX FLV5A48dvUD83m3cuRexBNjmTA8oRzYhCGfAf+E0CksmtcP5V+8O+Dnre6rBFBBN4A/m nAba6Q/YJlne3GEqDj9nnenKiDJR5glnxfrGsAvbKoabGRHrWvBfsTfX2OdxT3ewWI00 Dgtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vmr8i0HILdqGMwVhgOxfm//3j+C4M5iWtBnT+hrsrRw=; b=ZchDxHx2+yC77g69OQFes67aJq5I62Ng5uiH9ZqRGCm6PudZTVP7UgITSDdIL2dYIX QsdFp31Iy6MS3o9EqA8EV+E/soeGEnv2rZhEuBnKSw6Xd72I1Rl8+L1xtoRQOldkrkeq lOxhMCZD47UbPraaWEvMGb5lQmLx1/ffvah2QaPR9K/hzT1FZAxRyS2Pfo0DBKE7K6aE hPe8ACxEhUdGWstKP4TuYl5C7DX4pEdyoAFLFHeFoUz4D1o08NkgDcZHjvS8HYyKxRl6 SuRBrwHJCT8LW91Fdp/o0qnD2477cHWuvkJeg3ln99S1YroAFnhAN40PTsX1rN4wV8Tf Z9Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=TMP3jz03; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a17090a664500b0020a774637a6si12087159pjm.67.2022.11.20.05.32.52; Sun, 20 Nov 2022 05:33:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=TMP3jz03; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229598AbiKTNcZ (ORCPT + 99 others); Sun, 20 Nov 2022 08:32:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiKTNcX (ORCPT ); Sun, 20 Nov 2022 08:32:23 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB5D128E13; Sun, 20 Nov 2022 05:32:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951125; bh=vmr8i0HILdqGMwVhgOxfm//3j+C4M5iWtBnT+hrsrRw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=TMP3jz03SMBORLJ1Osq4NJBLaCq5d0dw8jsLS1ocyJhst++3mlOZzBTmQBqZWjKWv Voxzb/CQ6RCoeo7qn6/J/9C71Ry/WZsSFaulE6y7ESVN793wcmhDVAj4MNXBq0AP9i qdDmg6LDUbciSZdaXi+No2YJpxW3W0J+D//iRMt8zl5D6anEc723u8h63zHiFywoUn L2a+9hPW0AOGMc4wG450lLEID/gHX41CCJoWqkV1f9yuO2eIHhJmZlZoyMAvXHHPhG 29ZrSrj2z8vJlqhCF83PQLt/o1ecqy2FmXV2Y4U5L8n/yy4g2SHxLP58OTgMWQ8r8+ SWTw8fUQKRfOA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MXp5a-1oQt8j2T4W-00Y6vT; Sun, 20 Nov 2022 14:32:05 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 03/14] tpm, tpm_tis: Disable interrupts if tpm_tis_probe_irq() failed Date: Sun, 20 Nov 2022 14:31:23 +0100 Message-Id: <20221120133134.28926-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:b4C2M5Qz3awQq0TkuQ6vgiwoMtTbqIlRfmnv0OiMblSzZLZq228 BaaIfCHUp0oCYSs1lVBZoDmGSQvGKfk9Znbbm1oKwMdK2GDQaSlNOQZOsHVfh1BDxtrFT+k Yi6UqX2Us0VDNI6jgP4INwB8nW5Yb4JMr6X+4AO4MkeXetbnwqeuafOMSrROsMP/or/mK8t xuz7RZR61pEoZ12pTwE7A== UI-OutboundReport: notjunk:1;M01:P0:Z7y9UfKX6mM=;Q1Umg7DU5Dvyq+vxVLBm7PMycSI L2FyUFkk5FKNJrGCKp5FvID1bZEq0odl/FRjq0YEwP3L4dQQovH6krb1gCk14wDVhiVK4wJNu a8HELXz+JRZ512cQkSVNSAMkAcspVnucQY0pqK6jta2zxSIGp34sKkK/77stXgNHYbWwRdS6T fbW6ZWy7y7eaWYE5Ts3a9fFietpRoed7fxzdomjClJsP1RTUxJpMezu95k3UnsQjc4RFqZixf w9f/KP6fAWomT6HBgYx1CxSasp8jOgIZN7wUDOpRy3TUF+wUSGVX/ldKJKNtRJDFI82D1haMl syvZxABa8z0D+R6j3tpKL5VAmrlPShNx7y9JSaehAikJYGvLqnB+ezSLxGHBrrfZXPvMVmbj9 UeJ3OB/DQe2SLkLvX9noAAf5G9K3tOSXyB+YrgdRRF6DJ6NfK0sI+4AjYgOFgsxUil7UFky1a 687Ll/PTJXIfWnCJHh5wVC3GBhuU7ydCH9JuGT2PA/X+OtW1MYLORZKwWFEk1YgPQCCMTI2Kn /7oy/r4/IN8diVkGJ62JSEj6BhXqj7nNgMyFH2KHONxDMIm0Wk08mzEq/O3zEraaKB4daXJIP pmabEL0l3tts7IFCzaqBg65iFjtxDe8nOQvXtEEjU9tilCSCcc4mWmn8q9UIB1evQIFi55LM2 pohbrFj958CkB1EG9ZoRFwMFgp3W/yPhknNFV5JGKAq6cz0xSfk4Spd8EqUEAZ38kuycZT9nN y7VCtKo9PfT6zU9MUBbqfSWH1g0vsQQd2g4bk5xOZTkUtIfDhOn0R2d9TMfBEv5b3PXJDKtjw mLmZ2KSzWJRmgVpe87AAWYJNgLzkx7jXTU4hwvV+iDQ6wZAXBbkH3JHcC7up42Lggmn/r1Ec8 VoWJ8eq03qGNaAmXmXPCWlcslbajAJEYMIO4NC4UlCpljM7flBilgxD+o/HwV4ZgGnWEuC5x1 GnvWiA== X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022159199195107?= X-GMAIL-MSGID: =?utf-8?q?1750022159199195107?= From: Lino Sanfilippo Both functions tpm_tis_probe_irq_single() and tpm_tis_probe_irq() may setup the interrupts and then return with an error. This case is indicated by a missing TPM_CHIP_FLAG_IRQ flag in chip->flags. Currently the interrupt setup is only undone if tpm_tis_probe_irq_single() fails. Undo the setup also if tpm_tis_probe_irq() fails. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index d2c9c9d76893..603b82ca56da 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1091,21 +1091,21 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - if (irq) { + if (irq) tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED, irq); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - dev_err(&chip->dev, FW_BUG + else + tpm_tis_probe_irq(chip, intmask); + + if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - rc = request_locality(chip, 0); - if (rc < 0) - goto out_err; - disable_interrupts(chip); - release_locality(chip, 0); - } - } else { - tpm_tis_probe_irq(chip, intmask); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; + disable_interrupts(chip); + release_locality(chip, 0); } } From patchwork Sun Nov 20 13:31:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23418 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116480wrr; Sun, 20 Nov 2022 05:33:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf6RxQOpB7c135WS81pG/4BFTX12NSm6j0mUOUzPyys2AcQU4ghu6RU4wNFH4aFna4619fsf X-Received: by 2002:a17:902:aa0c:b0:180:4030:1c7d with SMTP id be12-20020a170902aa0c00b0018040301c7dmr7517801plb.99.1668951215416; Sun, 20 Nov 2022 05:33:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951215; cv=none; d=google.com; s=arc-20160816; b=OV3zEC33lthh0C1Wms/BuKwi06ohq9zkgwlSFcv9BLX3dSseytuuOaro8M1VAu6bI5 K0sf5+Qy7C3kMyuydsOSpDML+zSnJkdJ88NZpqiC3g73ymCGTU+0TKn5rx/N9SyJnsga OJOSWVq0nuF1uGzPeQL7WyVeUVb07MF06pGkbmoFW1LSNl9Ma6niBcBU8AerLMN9LDWU Sup8eqTtRAah2RbkTBD6B6MNMR3tEgQ/HGty7dZjQ7EiTndhBxdTUOBRcUkPf/8Q0UvC zm8XsOKsjW4IGX8zHRWwPYuoCOUsDRrAjKlaaZ9uouly9JKdkTrx3aMy1icJbj9FFxir XVlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Wzja5YwaKAZiFWUMEa0HIMVITjRNh5lgwkhDjVIIVv8=; b=ASBKV7SbGgJWDA6iW+HVoHgXnKYqYDBrdcm8dPsPoB5yhZuoH0zIFy6TrPTfoxKOsb lakRAvjqy4g4sM/y2zIUqxf5LeoVTjfwVW+C7lyBQYxB//kW/6hAQk3A9bGRWV5LAppK jEzvZGxyLCHxKnXpDTvIGbQJzhQeAZXqxUJkpfrYrfddGk/52I9nSdnGeG9Uklm/jLSS wxV+ur5ejEFXsI3S/3bvbVHuHg7yXv7oNYJb1ZlXuNrPs6fJQXbCfNj0Y0VTSoH0ywhE lnR+zJRCCO+t5xeBjdOY44DYPxt9BdIacIrLBk7nzCJ4X4DSRonQ1FzW5ZWob3hcNwBA d8LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=WI9Wkzvq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu18-20020a17090b1b1200b001fd70129092si10014921pjb.15.2022.11.20.05.33.21; Sun, 20 Nov 2022 05:33:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=WI9Wkzvq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbiKTNcx (ORCPT + 99 others); Sun, 20 Nov 2022 08:32:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E809254; Sun, 20 Nov 2022 05:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951126; bh=Wzja5YwaKAZiFWUMEa0HIMVITjRNh5lgwkhDjVIIVv8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=WI9WkzvqAEVlFAx3MSFarxoHXZ38m3UoVBGKV2bxv521t9ZMeYK3/S75R5P9hjGDg ab4V7zvRgndKizWT8DvP/9Aw99q6KtIC/ZIPE823oZLer7DCFILFkDsS7ntfinQ6hx nA0Ge3cYB+J7yY/sh/5ckOs1+0JCdLSh+XD0+sAQKqO5h3W/39AtG2zj8zq/Or4qoR gKARc+JazRAbBTy6OXo1THYJK56G8wBhYZU3Jzc+Jnp0oqqUyxm3Gi/fv4eGM0aUZB Jzv/GQLuwiOJoXcS74fja1y6T3BqGnjPh1S0xKOqzz1PMp2aKtbMmqdSIJHGIVSl8e 0bB3B0duPSN0w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MrhQ6-1pJxlR3urM-00nhs3; Sun, 20 Nov 2022 14:32:06 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 04/14] tpm, tpm_tis: Do not skip reset of original interrupt vector Date: Sun, 20 Nov 2022 14:31:24 +0100 Message-Id: <20221120133134.28926-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:VUd5I5eDNIynx/FyCcZmsE7B+Hj1CZFkjV5brjm+tc5mzgN2tIH eh0PWN/12QLtOELXmf0NMG5+HCPKEyA5G6L8UqJdL5epvFI9aEysg+NzXS60H1QEcbAXx0a D9oZ1PTbFWhorQp5mHR3Ptu9iCuxpGdn28/ST+U/z+3KV6PLNuwr9/qtpsaFwDlpRVOrwHU VKuaTChCH7d73U34ciS8g== UI-OutboundReport: notjunk:1;M01:P0:asWYfnMi/Wo=;S+A6QUJ0wtwWQ7q2ybxhH9+aYvF U0HaOIIsKHYk6HBVUMH2mhQWYzo/5IRadKEyWsEvwBfsZj7FP/Avb2lBRFN0Peu7ezb5wYVwn GszS/t9X3woWxPTz3tTHZ8kl50mJRzwolWtFTY2mCQzxIIT+hmQjPY4+6/mSTWvZwvXv6GCsf s+Q/b9H68eAhI6tdd2ywlloM+pPl1C8oUafH3Wr7+h8lP9itrChA8aZdnaYLGTPqnKp1DGlZL IwS/WVR8LKEksKMYQ4JyyTT5MOnY7O/oKRz1FVh+a2KxLu/nZRFYwgRnvtWulVnX3rQFSxH3Q Dk5I12Yq3YrLayZAOezJlDq2cmMmx4qv6AxuZhmmgu/yypnULilvwdEj/jMJupT7FcTlm3T2M 9yPMSwkDKHqqcD4s+j7pTl6AtDMuGWhju5oF7T6Vy4g22Ud1SM+CfYECU09XvCr+lEYMgRptR pThYNmL69AM3azQjRowL9HjV4QUccOGemxMr0S5gGxDkoJJkukXWs1cVoU9M8s6KOwbE55VaQ 5jL184fv92djeX9fNmu/Sz506nH8T2jTc1ss6mOfVrX6PtM3q4KgQEpi2WAn5eMuZ0qkF+DmL og4bsoETA8babipE0pkHLTMvOFGVSz5VqzbAljeLAQAXeR3zp6l1FY0Uu0XuY5ApWknlZJOvM G58dicL7MZr3bdNvp+VVr4IshnvXBx8cTG2goeeoV/nVEdxqdWdP+7kNn/vz/X9oJxsYGGsOJ OYnW03gZF2+h6g+UT5Zehb70pN3BTQZllL8Qq0nnEsrOM7Q1fSsOjgIwCPJw4lXFxsYNs5zZ1 QWj5Rf7IdzjP2O19GN4xSo8OdjYBEOtybR0CQ+6BWdNG5DfuprvBeawm+QTkgZHw6enaaeYbX JTI3l64q3d+sQCu2JrL1NlblPrKzImtSg/u6xWPEy0DtUuFo1ho5j5Ve5sJLC/0yfoDfIzkGw FIu9Rw== X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MIME_BASE64_TEXT, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022189851103379?= X-GMAIL-MSGID: =?utf-8?q?1750022189851103379?= From: Lino Sanfilippo If in tpm_tis_probe_irq_single() an error occurs after the original interrupt vector has been read, restore the interrupts before the error is returned. Since the caller does not check the error value, return -1 in any case that the TPM_CHIP_FLAG_IRQ flag is not set. Since the return value of function tpm_tis_gen_interrupt() is not longer used, make it a void function. Fixes: 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for TPM access") Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 603b82ca56da..1eac1279594d 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -729,7 +729,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) return IRQ_HANDLED; } -static int tpm_tis_gen_interrupt(struct tpm_chip *chip) +static void tpm_tis_gen_interrupt(struct tpm_chip *chip) { const char *desc = "attempting to generate an interrupt"; u32 cap2; @@ -738,16 +738,14 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) ret = request_locality(chip, 0); if (ret < 0) - return ret; + return; if (chip->flags & TPM_CHIP_FLAG_TPM2) - ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); + tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else - ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); release_locality(chip, 0); - - return ret; } /* Register the IRQ and issue a command that will cause an interrupt. If an @@ -777,42 +775,37 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); if (rc < 0) - return rc; + goto restore_irqs; rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); if (rc < 0) - return rc; + goto restore_irqs; /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); if (rc < 0) - return rc; - + goto restore_irqs; /* Turn on */ rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); if (rc < 0) - return rc; + goto restore_irqs; clear_bit(TPM_TIS_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to * tpm_tis_send */ - rc = tpm_tis_gen_interrupt(chip); - if (rc < 0) - return rc; + tpm_tis_gen_interrupt(chip); +restore_irqs: /* tpm_tis_send will either confirm the interrupt is working or it * will call disable_irq which undoes all of the above. */ if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - rc = tpm_tis_write8(priv, original_int_vec, - TPM_INT_VECTOR(priv->locality)); - if (rc < 0) - return rc; - - return 1; + tpm_tis_write8(priv, original_int_vec, + TPM_INT_VECTOR(priv->locality)); + return -1; } return 0; From patchwork Sun Nov 20 13:31:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23420 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116549wrr; Sun, 20 Nov 2022 05:33:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf5eYtQtvl2g5IPHUFQUFW9u7g52iXsKlu8FFPHjOPs4+pBuKgleRm3YJ8ZchNYMAfovcobl X-Received: by 2002:a63:5b0e:0:b0:476:c832:aa74 with SMTP id p14-20020a635b0e000000b00476c832aa74mr4558663pgb.456.1668951223022; Sun, 20 Nov 2022 05:33:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951223; cv=none; d=google.com; s=arc-20160816; b=Z+uoytM1hrsoqROcilceNIbQYAIuGdcImKvSKNE1Nxb6Tq9LArLRQXMLBp80o+jVIA dlmiIfSuCzklsMBhVgvZ1Hv5pbRALjoppF6BE3B4IdSylLA9Xk10PGaOBnAI1WfXUWjb ARuoxAFRPKaaC8d1xPT7nyZSO1l+i/wbaN7iBqXMSVf3yZUNSc978p80pyQmAX9LgxuO 0YJlDbEoSEJKtjkkYaW18oZq/qJjLOaQx/lnV17MoPhGpXL7Ag26dXODdDmhrKcrFv8C QczHhYJaClkiyPDjU14ghxEnVzm0T8u07E2dYAfdEgw/S3iU6ftn+4gXAMMeDbojR/6+ Q3Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mo0aex3xZinBFgfr39bfyhV1oZv6iyWkgvj5WLXVwQo=; b=OZ9yeOl6EJbKq3AcjqwC6nGc5H/hzJBKK4SmGeYdYtBEvUlPZpzdKH5VOJDeN/dPdA eviGC+CDkecqsdnEVwgBCMH3tlkwL7t4CVDYOr46JHGDbTKV9W9P4EhrcMtuRN1gE7bk q5bOPispvAgZeRJQnvPsw/33jn3GY5FmYnzVgwsX3x7JII4GIkk/4ChcNakgSABKz3eS BMG2/SigHLZwCfML49Jj1LHrLr8mj1t5TtC6/5LNAXsGLUVtN4v4RGRWeWlafegL6Rua kp5BUnhnJwN/cm3d2E2u2406GAVYaxObjGaldPa99kD1HD6cjh8g92hh9z2iORHaBjV6 /K0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=bkpmWPdY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k38-20020a635626000000b0046ebb8f5cb4si4071001pgb.691.2022.11.20.05.33.29; Sun, 20 Nov 2022 05:33:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=bkpmWPdY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229794AbiKTNdB (ORCPT + 99 others); Sun, 20 Nov 2022 08:33:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbiKTNcb (ORCPT ); Sun, 20 Nov 2022 08:32:31 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FBB529A; Sun, 20 Nov 2022 05:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951126; bh=mo0aex3xZinBFgfr39bfyhV1oZv6iyWkgvj5WLXVwQo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=bkpmWPdYYu4avftPo6rrf1aFmdEju2RTaGGoD+EgwTHfLs5d4OInUCAbLL4Hbin3E zfesiYSlDp9XnmruYuV+ArJ/W+s/DeCwowDA6JB2Ge4zJDGM9oAXclRBk3ZrRvDVPO wb22PxU7zn4TA6Xlp8LTheCZr5UztCUrRuxOOT3RPolVNLu9PUl2cUmzMEztc4h48K bdGsmEjufoPXvbVKlMcE8idw0IAnuDVgt5+EP4mUUv4xEcOBug9oYQpj3FXKSaVqqy 051odHIUS06eYFseOw/IRS1Mv9psTUMlzUWt3VnVXaqdtWH1h546D2v5lQIElBLjP2 mPTiTZ5evz6xg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MVNAr-1oXCvx1UKV-00SLd2; Sun, 20 Nov 2022 14:32:06 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 05/14] tpm, tpm_tis: Claim locality before writing interrupt registers Date: Sun, 20 Nov 2022 14:31:25 +0100 Message-Id: <20221120133134.28926-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:f6nQ5ZH2k0l7L/RDWWZNUoDawHxfUyilTX7+GGR9iDdgaGyKXhX GYfdpjigd0/KIKMw3uFyAriEijDYFktSMgH8HI76SL9WrnqDB9918GOUJNwl3YaKBRYyW5B V/zsZzfKCf5eAp6imLZkkW2F4RbplVfWw3yG0s9NdTq21Nj1Rwnq2D8dDCymUD9acCzt0B1 U2w6f2RaOYBuCaUjgOdgQ== UI-OutboundReport: notjunk:1;M01:P0:7PKF015SJ3k=;ZQ+6RO+dhA8NmXq+NwqOtgXnECp WdYnA0BoBnscfzWwRbebUA1EK34VYc7scgcqnoNG+aUfoWA3r8MJn229qHZfdEHGBmUCHbYmE Vqcr5KMsin9JBRByyDhiWwXl4yscRtjxYbyYJ7NUP9nDHHY9qX6KWBA0n0Dsw1naS2cfzt2sG awEZQ8xnNV1paExhEojGfl2ZpJOmnjajfWVR1gD3YxeT8YjFQMsH+SPFDhr9Lyo2O7QczUWLW OTDfYUJ6Gn116666pF52nUN4ZvEezhxT8RhawpK/BL7azZsV875GN9vCW9HLjosGyDfjYf/ql Q88hTleVP6cVnDmsaTlrxtgqiffyJP+BjgWO01CRoNHbP1k0/K4DLyyA8hYDcRQVrHX2lvbLM GqnLGbemneIObAAPkMvYEWYxTyQG0JUaXAJu8sdfB7fofO2n47wMtYCqJtr4BU408ahSRadeJ pi/KTaMSRwB7x8VX1K2pY67MKlM7Ygcr0AEcqES6ZYd3r1WfTxM1hhHd7qYuaZ0ii4NvW+HGF r3bghOL8p7DWbiMoNiASu6GuqKoVzyEVBmaPRjYQKGRdsaVwbcPzkUirAC0SGkf9a3en6z1jr X1qV/38cGUlUhWAXesWCxCv8OYoGalm2uR0HAfWgVRIXLOE9/B4qme5+yGv1FWxELqTZSTXSD i8n8m7qjR1VVfQJa7VWfLv9Oyz8CWOML6dNbeEcff78E8QA9QVTjCb32CTX3hJeLrMI6qLdqr OFrOaj4BPmI0s6tfMGB6eYPCqXV0JUsUWiN8axciD9xzBtUgYUJSE+qnm7j9StN9RhF0amd7K JLyJBAXE72cmfQUjHOZZ5WRPYDr0/VXSYmj77c4tGZFUUKFi1KVY4JJsCUUltTYfL2A56A3lD eqXfprcibZuj6lnnfN5a5eHo6M9KB2OXG+tLaNmkPvVhcLuXE8/5DSuWg2VpjnlXFaluPIsyl 1gku5A== X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MIME_BASE64_TEXT, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022197581941853?= X-GMAIL-MSGID: =?utf-8?q?1750022197581941853?= From: Lino Sanfilippo In tpm_tis_probe_single_irq() interrupt registers TPM_INT_VECTOR, TPM_INT_STATUS and TPM_INT_ENABLE are modified to setup the interrupts. Currently these modifications are done without holding a locality thus they have no effect. Fix this by claiming the (default) locality before the registers are written. Since now tpm_tis_gen_interrupt() is called with the locality already claimed remove locality request and release from this function. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 1eac1279594d..58a53ec534aa 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -734,18 +734,11 @@ static void tpm_tis_gen_interrupt(struct tpm_chip *chip) const char *desc = "attempting to generate an interrupt"; u32 cap2; cap_t cap; - int ret; - - ret = request_locality(chip, 0); - if (ret < 0) - return; if (chip->flags & TPM_CHIP_FLAG_TPM2) tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); - - release_locality(chip, 0); } /* Register the IRQ and issue a command that will cause an interrupt. If an @@ -768,10 +761,16 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, } priv->irq = irq; + rc = request_locality(chip, 0); + if (rc < 0) + return rc; + rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); if (rc < 0) @@ -805,10 +804,12 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { tpm_tis_write8(priv, original_int_vec, TPM_INT_VECTOR(priv->locality)); - return -1; + rc = -1; } - return 0; + release_locality(chip, priv->locality); + + return rc; } /* Try to find the IRQ the TPM is using. This is for legacy x86 systems that From patchwork Sun Nov 20 13:31:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23427 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1120226wrr; Sun, 20 Nov 2022 05:45:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Nyu0DT99GSuXRVJ6ZFLTt+HBjCDM9eWnO98oDZXLt78k8ZHZ013yo8Zl/hqCHZyreW14F X-Received: by 2002:a17:906:3607:b0:78d:585e:d183 with SMTP id q7-20020a170906360700b0078d585ed183mr11877068ejb.768.1668951948137; Sun, 20 Nov 2022 05:45:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951948; cv=none; d=google.com; s=arc-20160816; b=wVQWEFRCh2QfltZgVPSLJXW4o5dSE8MJmNS61mFSH5ZDueJgItWYUxIeCCsm9+TBZv Nro7aYW/CNbqyYvKF/NTZ0mLHXkoKd3LvtnWHMBxEBcvU0qyhkAyW36PnaveNIiYsI0S kWX/KVDiFMjxlcyPXWFylri82a8sN00rubtbeRpfJUNkxh3RCvhtVKL49F2a6yqvikmw PzZLMwft0wLcD5ar2FTq30Y8fiBgYTpKz5rbftvIi9vJP3VVxYVMRdr8D5UGKMz/19kr TSHR9T5ROoJx0J0EH6Wc/RBHBl6JthJuNCvkbOAbA32PxoZg5udhcHntTrklenCuNCaX QJWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S+hhbmGWDO0VTuSnSrMDyNR5O/r2XEHMgIEZ7ffd/3o=; b=NgzWPoK2nrs99usJpyND8/ZQE6Yd+ja1Mzs/7bi+OgT4E8CElrINJfWY4D+NuaY3du ry/yY742Y572cxVN6tgWR7Vo4JKj13IGsLorfWywvh9f9zI0gF5OW3Rik+gje3ogJNUe VSfQUjcCmFTVbS64iw72zpBAuWB2Ot4yOrjVYzABErpUwv8ilFhlkdrJGlT/abfARucr DzGnzXgN5V+UYaxYb+56e04I2o5YUUgn1AjLo+3zxIBHb7vLbZXiHZYIwHlFkyzrXCWj /vp9Os2MXOd93N+8Rr5rVlRj1bCHNg1hpy5EKHZCv7NHfqXuPlyy3XBwV8Fd/eghAaGC 3H1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=N8Pr9BhF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a05640205ca00b004680dcb8900si7830807edx.213.2022.11.20.05.45.24; Sun, 20 Nov 2022 05:45:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=N8Pr9BhF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbiKTNdT (ORCPT + 99 others); Sun, 20 Nov 2022 08:33:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbiKTNcj (ORCPT ); Sun, 20 Nov 2022 08:32:39 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AD67E82; Sun, 20 Nov 2022 05:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951126; bh=S+hhbmGWDO0VTuSnSrMDyNR5O/r2XEHMgIEZ7ffd/3o=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=N8Pr9BhFF3SCxSv1LBebt52RsBq77SoQGxRDE0yI9UTR0SGoSZe3Mv1WFfV8qzIih iAvCJQiyEeLK49eqi7neJWSEIY+xXgGNmKsAlE2mZQ9NJGhYlOEBeIKOEUZhbP0jSI RB3fh/iKG4C4YsVQoqffXEqqQBaQdGKM9147eNYzYHFiweffHrUZuTwBJBQUtFg8WF aTNTJKEISHBS3NEZfezhdZOWrBbt4lTz36QaLu3/ZFU2rQYKOZeIYDhmJFlHdxrKQE 8+N9xJzYHv2gLpnTwmbrgLo/KFFBbT2wNiC9jTZps373eoHVz46ck+gdn7BoUcboYG PmIsPiQZb6FWw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MhD2O-1pR9Yi2qFm-00eOCL; Sun, 20 Nov 2022 14:32:06 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 06/14] tpm, tpm_tis: Only handle supported interrupts Date: Sun, 20 Nov 2022 14:31:26 +0100 Message-Id: <20221120133134.28926-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:pj9FekuflmRkmp8yKItK+S15WfK+mvG73cJI33XbaCDKiXdEYhH RMuk+wI0Bzde5PWEpNMdaJFim3D4B0DSVlWxvSdBjLAEIfFQgYzTqn2bOhnHWRNCIta3ttB E84mMOrbYZRVnU63L6wUOiBGhqcKmc9jnxHuvhZjerzkmai88MzxxHM1oT0Aapi1k8hKRbq BKxr0kxEdOkXMfunZ+JOA== UI-OutboundReport: notjunk:1;M01:P0:6AjY/MVFtng=;jLWczQZvTXNacP1t7vpKs+IaCFW yObG/QcyeDJVIMIkwolW6f77oIMVYXe5kag/9tri6fzZPF521H95EfpN6UdPgrtLNQGYJSHn+ XsEP4tdFIPxqX/oBuE7cuUBaQbQtDsFMMUAJfI0Ze/Y5QYnfOPrmPUTkwY72zj1RBg3DUNTei Nu1IwA/bak6DviOczNz4Dq7x5KiesoJawOCWfRQTM6EnQFT2F5286ILrbLf8X8PX/tNJTK4rn ainZNGgFFqsuxIHvg0jMr4VbMpKw84ANLLWtCnPPJoUKfpoo4BKU7j9C2NvmhPC3neOQPqFNy P2d1hfdErCy7yV3PlpdjHWh/5Dc/lwv0SnvrvWJyYcUuAbtdqS9BxxNtcmlfqqcghmcjwc944 sUQ3uc6a+FeWypDfyYewLQaVmJtpgQdrZUYbVQDs7ddTiZECydGc93tMSu+z2g3//kxaGtgI3 oTmXAO18QOfh7yPv3T2HsWoxu1pu7Ly8dITe2GqHoGZXhThCSty68H+AXoP8m98O4mVPF7Fg+ lzyWwLdQK+XrQ2AboUrPWdviG+wHputox4SVd2FEm5Uuj82DZUtQvyI4JBLYfyvBDOa/a8WZr +5fvqhkNFUq7GXCgEUPW/YKcJuBvRB176Bugkgp3X0pD70bzTfgsJcvNKtjJlq9vzXzfuQTEc FjJ4ZjnHDEwnetV38tmkaPqP/LsCVVJc+AzwzQp9U8Ig4asIXavPsVdWoXxMPzPbcOWhzFL36 0w26YtkMtnC2m8G5Y2dnRPZR7g4ndwigmzndzmB35xY2vvuZoMt+IEuKfAAXR/JKo4Mmklke+ PTVeQlkGjXIfpMOy9qc3Fl6BU+BEv7fq+AHNDEYAH+e13tIiMl/nFa6u/chUjiXCjL5pXVF6o 0Yh3R4IuvObdAdgbqE2jU9SaxNQLu3DV3XTXd9m8Rjn2oI/9De+k536XvNmW68ntEyKGNOnF3 IB5ySa6fjJgYME90gQt52ev7UEk= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022957777722957?= X-GMAIL-MSGID: =?utf-8?q?1750022957777722957?= From: Lino Sanfilippo According to the TPM Interface Specification (TIS) support for "stsValid" and "commandReady" interrupts is only optional. This has to be taken into account when handling the interrupts in functions like wait_for_tpm_stat(). To determine the supported interrupts use the capability query. Also adjust wait_for_tpm_stat() to only wait for interrupt reported status changes. After that process all the remaining status changes by polling the status register. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 120 +++++++++++++++++++------------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 73 insertions(+), 48 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 58a53ec534aa..fbad92b18788 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -53,41 +53,63 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, long rc; u8 status; bool canceled = false; + u8 sts_mask = 0; + int ret = 0; /* check current status */ status = chip->ops->status(chip); if ((status & mask) == mask) return 0; - stop = jiffies + timeout; + /* check what status changes can be handled by irqs */ + if (priv->int_mask & TPM_INTF_STS_VALID_INT) + sts_mask |= TPM_STS_VALID; - if (chip->flags & TPM_CHIP_FLAG_IRQ) { + if (priv->int_mask & TPM_INTF_DATA_AVAIL_INT) + sts_mask |= TPM_STS_DATA_AVAIL; + + if (priv->int_mask & TPM_INTF_CMD_READY_INT) + sts_mask |= TPM_STS_COMMAND_READY; + + sts_mask &= mask; + + stop = jiffies + timeout; + /* process status changes with irq support */ + if (sts_mask) { + ret = -ETIME; again: timeout = stop - jiffies; if ((long)timeout <= 0) return -ETIME; rc = wait_event_interruptible_timeout(*queue, - wait_for_tpm_stat_cond(chip, mask, check_cancel, + wait_for_tpm_stat_cond(chip, sts_mask, check_cancel, &canceled), timeout); if (rc > 0) { if (canceled) return -ECANCELED; - return 0; + ret = 0; } if (rc == -ERESTARTSYS && freezing(current)) { clear_thread_flag(TIF_SIGPENDING); goto again; } - } else { - do { - usleep_range(priv->timeout_min, - priv->timeout_max); - status = chip->ops->status(chip); - if ((status & mask) == mask) - return 0; - } while (time_before(jiffies, stop)); } + + if (ret) + return ret; + + mask &= ~sts_mask; + if (!mask) /* all done */ + return 0; + /* process status changes without irq support */ + do { + status = chip->ops->status(chip); + if ((status & mask) == mask) + return 0; + usleep_range(priv->timeout_min, + priv->timeout_max); + } while (time_before(jiffies, stop)); return -ETIME; } @@ -1000,8 +1022,40 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, if (rc < 0) goto out_err; - intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT | - TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT; + /* Figure out the capabilities */ + rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); + if (rc < 0) + goto out_err; + + dev_dbg(dev, "TPM interface capabilities (0x%x):\n", + intfcaps); + if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) + dev_dbg(dev, "\tBurst Count Static\n"); + if (intfcaps & TPM_INTF_CMD_READY_INT) { + intmask |= TPM_INTF_CMD_READY_INT; + dev_dbg(dev, "\tCommand Ready Int Support\n"); + } + if (intfcaps & TPM_INTF_INT_EDGE_FALLING) + dev_dbg(dev, "\tInterrupt Edge Falling\n"); + if (intfcaps & TPM_INTF_INT_EDGE_RISING) + dev_dbg(dev, "\tInterrupt Edge Rising\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_LOW) + dev_dbg(dev, "\tInterrupt Level Low\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) + dev_dbg(dev, "\tInterrupt Level High\n"); + if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) { + intmask |= TPM_INTF_LOCALITY_CHANGE_INT; + dev_dbg(dev, "\tLocality Change Int Support\n"); + } + if (intfcaps & TPM_INTF_STS_VALID_INT) { + intmask |= TPM_INTF_STS_VALID_INT; + dev_dbg(dev, "\tSts Valid Int Support\n"); + } + if (intfcaps & TPM_INTF_DATA_AVAIL_INT) { + intmask |= TPM_INTF_DATA_AVAIL_INT; + dev_dbg(dev, "\tData Avail Int Support\n"); + } + intmask &= ~TPM_GLOBAL_INT_ENABLE; rc = request_locality(chip, 0); @@ -1035,32 +1089,6 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - /* Figure out the capabilities */ - rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); - if (rc < 0) - goto out_err; - - dev_dbg(dev, "TPM interface capabilities (0x%x):\n", - intfcaps); - if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) - dev_dbg(dev, "\tBurst Count Static\n"); - if (intfcaps & TPM_INTF_CMD_READY_INT) - dev_dbg(dev, "\tCommand Ready Int Support\n"); - if (intfcaps & TPM_INTF_INT_EDGE_FALLING) - dev_dbg(dev, "\tInterrupt Edge Falling\n"); - if (intfcaps & TPM_INTF_INT_EDGE_RISING) - dev_dbg(dev, "\tInterrupt Edge Rising\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_LOW) - dev_dbg(dev, "\tInterrupt Level Low\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) - dev_dbg(dev, "\tInterrupt Level High\n"); - if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) - dev_dbg(dev, "\tLocality Change Int Support\n"); - if (intfcaps & TPM_INTF_STS_VALID_INT) - dev_dbg(dev, "\tSts Valid Int Support\n"); - if (intfcaps & TPM_INTF_DATA_AVAIL_INT) - dev_dbg(dev, "\tData Avail Int Support\n"); - /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); @@ -1091,7 +1119,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, else tpm_tis_probe_irq(chip, intmask); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + if (chip->flags & TPM_CHIP_FLAG_IRQ) { + priv->int_mask = intmask; + } else { dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); @@ -1138,13 +1168,7 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip) if (rc < 0) goto out; - rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); - if (rc < 0) - goto out; - - intmask |= TPM_INTF_CMD_READY_INT - | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT - | TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE; + intmask = priv->int_mask | TPM_GLOBAL_INT_ENABLE; tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 695a2516dce0..2deef11c88db 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -93,6 +93,7 @@ struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; + unsigned int int_mask; unsigned long flags; void __iomem *ilb_base_addr; u16 clkrun_enabled; From patchwork Sun Nov 20 13:31:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23416 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116365wrr; Sun, 20 Nov 2022 05:33:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf52YMUkXsU77Crrxt91rMc3lxAmR5zIp88q7vwm9bP+bWP4qqzUTD+vfb1x/J+19LuPJAQK X-Received: by 2002:a17:90b:1bc6:b0:218:4d16:cecf with SMTP id oa6-20020a17090b1bc600b002184d16cecfmr15909067pjb.96.1668951200389; Sun, 20 Nov 2022 05:33:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951200; cv=none; d=google.com; s=arc-20160816; b=mMVBxuoq7ID7exMcg/OuWZ7hE9VJGfTR+ytmGCPhu4kuBMjaEJrPmtxvprOR0JT8IW F9sRBL9Zm5NUXCKCysIwNK2dAB9rn2ojNRmlcmRXFtbLK8KnZuXXENKWlvYnTOIIdAa6 njwnfagBBChBT0slZjXjTOKU6YacbouKilLAr2BH9Gm4gxnm2lEpuzoyInVL2LzWZJ/J FaAr+fn5sKquG0Dmji6/f9oKm5MNowbPd/X9r+bmHRszTtP0dQZtMQ8rHJg0iP3Eqn1z R4qryxoKanMr2i+oj1Lea00ty0LKVbhtpFKmVQHvn29Q2tpenEKSpzAowTAwvbKGG9ys 4G1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qYlv/2skNZrIAGuyoSI3M0nAcicGS7Q3OukmLXnsYCU=; b=MzWVQqLZIZVhlGTdxygi4IY7J66cs9WbUtcGLrGAfDdx7XoZ55K2YB4CabphOYpNSN mtCWxzEOWJJbR9AQ2uJm86e94VLomFP4BU9RPm5IoR9fk+ZwUUZ8jrc3vjxxHgvTurT/ sExQoYPG1gnMmFJsOsU3lOXK+84EmwYPCdywIOyRXrYEb7w03rRgNhvJKmX9yewgR/qj q6K+SoAUpS737dw5EqrcLvBdiucsoVTKs8oaVQbLh7++vNAu5+RN3CQb9xUPqY9z73vt QZRkriv9OEj803r7Q3DgaCPk4oxAEJJAIXHUPDaKqQgOs2PRWPGvTIZoSKDD1K3JjQ/c NqEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=bINaJezF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw14-20020a17090b4d0e00b0021425cf457fsi9626054pjb.32.2022.11.20.05.33.07; Sun, 20 Nov 2022 05:33:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=bINaJezF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbiKTNcl (ORCPT + 99 others); Sun, 20 Nov 2022 08:32:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A779D9; Sun, 20 Nov 2022 05:32:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951127; bh=qYlv/2skNZrIAGuyoSI3M0nAcicGS7Q3OukmLXnsYCU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=bINaJezFcxVr1hZkuhXGGG/2P5YvXFPExjykSf9Aq9BWFSnyc/JG0CKtSXqG0ernX 2mzba7mnHeqr+CI+MxQlACgpMiOgLUiQKiDPcvzYVKo5LmUJC8E1ZYysC3HIzOevwz yHGHpCVB/RiUHpBUL3D21AMXSsSQtRSkMpIzM/O+Hr3/9hr7/aquYtCWt27BLLdZ+2 XswO/1Nl25iqGmwI0O8jXAKJbua+gi02OGgYQRPc/9gonIcF7kEduS5t9XyQ+R7yA7 vLGfUtwqmo3pGUsebmfyl1gcrcQrLj1ezfEAurNIpdtXXURybv8BCbpjWtUODnIuDA Am3yXkp2FwWeg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mn2aD-1pO4dU02Ex-00k9Um; Sun, 20 Nov 2022 14:32:07 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 07/14] tpm, tpm_tis: Move interrupt mask checks into own function Date: Sun, 20 Nov 2022 14:31:27 +0100 Message-Id: <20221120133134.28926-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:pWAON8thYn0lythSLMLr5a6vn8X+rSQV7RGJf4FePhBemJDVbHJ Hewfyiy1zoHiO0PppPaKhgFHzzdJOC87VLsVk9STi0amA2vvqZY0KydBmpGEFPiv5DDM9LX Fd7tTrVkkVkDcP62zmMBR1J4jzv90OhubpvkyUnQ5jEaBXN1GJNQe3zG54pm5ksBZS0J8pr YsENuCqXjdQ1cejij1sGA== UI-OutboundReport: notjunk:1;M01:P0:8z07yEUH/Mc=;A3pki4bQWNkoOeu7W1hASW4PWAp r+JGTVzFFTA4hfnr/BNz6rB5gwW0j/zWH+SzD6VS7gA7246S4p6yh29mk6jemwuqSHqctC0rR Z3IDdr7u1ZPcUv6m+zxOJmHl46pKj1g85IPP4AKnJCR6TwqlqBFj2nHp+8tXqJBPmlaNd8CGR IJ6QdjMCaSNDiIWs3FTcP5+CCF8m1i4NYT+pig63RE0I7EWaRZ49auUxHlaJK0KAkWJvYkD/5 dxBRW0zL7wqz+Wp1JeH0v47gAnDrnW9N9ktJcnv17vnFcI3Jp81xgGKERe+mN0DBnC5yOv/yv MZ61v/wpHVl51hwWoSPTVYzhQAxtZ2dWYqZAxMcOy4dlUUCSE9a5aQFwJ/i/owt4QaLSkidCb RROsFrLFFo7AH3jbLn7G198Dk7Q0hgkUx18P0THrCqu0ajd1ZrMoATmjgSDccFpW5rwGrM5DW KUscoqZi/ZwhGMGXVbIKRvQcaB7jNbN6+AZ0m0YjBcSsnbHuwc4I9OMNQyWpiLAyPoI5y5TbB Yq26m37IruH9lOLydrMmDpT5n/grc5/4SfbBNNI01EW6IFB2pPmXoNv+qM8giVg9BBXlMuxph tQUxZrCoCqS6TFed3LcGgCmuMQQjXYpZaxMm9UWm8ZI6QVQ934DBMIt+fN5RBPCMOOmZV0iF7 +EIBMgVBExnCUiwdRXEdB1svC9cwz0WJeuc1pgZsNNqTCkmx2Lq0XBHxWbaqoijPOC4CL47t7 ZA2576RoFBqrmub9VI1ZzCnLEJVJvrdy+DJOY7ys5sHNom6HeXQhB18WttHi3z78pBOnIf8iv Rz/+Sq6Mo+lCQZGF50TzGpZknmc3oVKTIHFGLXkEgkbTTo1So8cNZWtAHKAo596cqoiFmJ68V /GzG3GLcBXw4wvPlyFsVaKMuGgjFPTTHcmK9l3GmyCpdLVHMfmLXx6UAvGkZn+pq7IqlcYgjR 6kVPQg== X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MIME_BASE64_TEXT, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022173944030052?= X-GMAIL-MSGID: =?utf-8?q?1750022173944030052?= From: Lino Sanfilippo Clean up wait_for_tpm_stat() by moving multiple similar interrupt mask checks into an own function. Signed-off-by: Lino Sanfilippo Suggested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index fbad92b18788..5ff4ca5fb936 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -44,6 +44,20 @@ static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask, return false; } +static u8 tpm_tis_filter_sts_mask(u8 int_mask, u8 sts_mask) +{ + if (!(int_mask & TPM_INTF_STS_VALID_INT)) + sts_mask &= ~TPM_STS_VALID; + + if (!(int_mask & TPM_INTF_DATA_AVAIL_INT)) + sts_mask &= ~TPM_STS_DATA_AVAIL; + + if (!(int_mask & TPM_INTF_CMD_READY_INT)) + sts_mask &= ~TPM_STS_COMMAND_READY; + + return sts_mask; +} + static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, wait_queue_head_t *queue, bool check_cancel) @@ -53,7 +67,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, long rc; u8 status; bool canceled = false; - u8 sts_mask = 0; + u8 sts_mask; int ret = 0; /* check current status */ @@ -61,17 +75,10 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, if ((status & mask) == mask) return 0; + sts_mask = mask & (TPM_STS_VALID | TPM_STS_DATA_AVAIL | + TPM_STS_COMMAND_READY); /* check what status changes can be handled by irqs */ - if (priv->int_mask & TPM_INTF_STS_VALID_INT) - sts_mask |= TPM_STS_VALID; - - if (priv->int_mask & TPM_INTF_DATA_AVAIL_INT) - sts_mask |= TPM_STS_DATA_AVAIL; - - if (priv->int_mask & TPM_INTF_CMD_READY_INT) - sts_mask |= TPM_STS_COMMAND_READY; - - sts_mask &= mask; + sts_mask = tpm_tis_filter_sts_mask(priv->int_mask, sts_mask); stop = jiffies + timeout; /* process status changes with irq support */ From patchwork Sun Nov 20 13:31:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23417 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116409wrr; Sun, 20 Nov 2022 05:33:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf606SwBh+S9ZonlgLm7O5Utf0c4QAYpyrte4uO8HjulUnUa+DRmzjlS0WYk4l7b7aaspwK6 X-Received: by 2002:a63:711:0:b0:464:527a:5796 with SMTP id 17-20020a630711000000b00464527a5796mr14245251pgh.38.1668951204300; Sun, 20 Nov 2022 05:33:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951204; cv=none; d=google.com; s=arc-20160816; b=OHjLJOTIpUChcRVn9giPFRHsp/kcO2EkhfcwdGGjU0gSpNuQEQYkbXtSeZr6kg5OUw VMnl0Xq92kdugVDqRlWBx1OgcIvC1rQ5yNJhdB1LoExIDMNj4pj82uIs2FmczY1zTX/R HNMzUITKtUimvDym0JR1ygwCYFJLGNPeqMufIscfV33r59P2i8OJZgM7WzTSiivQAodd QMdOJdl9n4+W8e5ESHgZybGpGgypvcV39MsKYs451ZuSazHQPk1h0IGyOvLmhoZUgKlP +JROdaNo8qDUo0o9C4R7us/JbimzGoo5+9GcVmesBytk+t9Z/BzCZUUX+6/otX+rsE+p iYrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F2hzzeSzk8y4Ogbig7FSAtP0DXv6VqmVYAg81reycu8=; b=lrDsLX25aHrxyRCM78W3N0mxk1UeTKKuvtSYqxFdAJWV/Hmqz9Qd06+AbOKOuoiQzB 74Ktxb+L8JAnJ1+Hx0jIqTgCNVHMaK6xLmllOqN7tcgQAtAMRrieAx7RHp65bLHG0vjj MmF8GX7CIuF0sI+xNKJ+BMHTxgTFYE5jJDAAwBuaoNIBk58/z3nYFPzKhgTBviXbuJV1 9L7cen7qS3xoAydn6scl09WMfVnbzMOua8qDecMgHoqurLGYCj5Ljt8rsR/5ouAjZxPS SJJgL5/wEUxfvGfj310cbA3YMXNJkOi92RENFrFm9QChNV36G/AgcFl+8eKlxZ91kDh+ LESA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=YoAOpnl2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a170902f54600b00176d5b20ebesi10102539plf.355.2022.11.20.05.33.10; Sun, 20 Nov 2022 05:33:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=YoAOpnl2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229762AbiKTNcp (ORCPT + 99 others); Sun, 20 Nov 2022 08:32:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDCE7202; Sun, 20 Nov 2022 05:32:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951127; bh=F2hzzeSzk8y4Ogbig7FSAtP0DXv6VqmVYAg81reycu8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=YoAOpnl2cGULoCrUpsM4P43BSWEiq0m2yNqAU8UnpBomByPL1uyDiPhOhE9kInDVI 3zmUAT4KOY5xcGNCzmwoCqA4LPaR0ej/yIQGoha8vbju9CSKQ/OVuglRsfTgm1x93B uGtVHA/u7PMwJakPWPYJOFQDwTmOMLwI+zpBv6sjfQWbf8bbFA95v4Mvyhz8VM1jza ccPWefZOOGaeTCAuo+YVooRiIJcjgbbW2785wlQx2Ck7fIzFjmKZ67fKaoJllLj1nd mG0uFMPTY93mbro0raOmi3zS0HA6q3fEcEjPJeXaiSQ7i4OlmbeNQ2fhoWAfhkO2Br 9+C6/34Kci7FA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MtwUw-1pDRMp1Z1A-00uIVv; Sun, 20 Nov 2022 14:32:07 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 08/14] tpm, tpm_tis: do not check for the active locality in interrupt handler Date: Sun, 20 Nov 2022 14:31:28 +0100 Message-Id: <20221120133134.28926-9-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:qDOS5QDjXdbwOofh6vZTHErbO+5mCvO4iiSZ5/xFYyCEu6lwU1K 93ZMirCD+aeoLEIT1HWNIrru1jnO8tLVJcMsRi+CEWuexoAttgGDD3fode2VQA+QedOtaM5 N/xzjYqwe7Dxl6JdINF1/tQiH0fRkAdxFLbLPwRrD574ipm3pf6HiX5DRU0/ULJrF0+g+HT y1T7eZ/lZ38apE9GlIxHg== UI-OutboundReport: notjunk:1;M01:P0:z5JKXYd0BeY=;vUttoE07kPsMS0FVFrXeO2dmo2e zkJx0Rw4PUQy5qqtuv3wfTECOF7u1eTEYyvoAfyBKVUOpr2RyDF3AwFXYBfdWt3gmd0Bdxzgf TzKKI17UN+SUdV+/lzlyoRkymCbp+krZ6fNLHB6fAbJuimQd3K7FFnC2WmJN4yKaVQY/MQMLE qw3l/96CLSPGEhKf3k1Ca2Xrksu4rUAEckCvaNS/AzHdkhTmqP1Ld1+3rwM5MFfK/FWBjcc2c ISeOu367IgxXqgBA/QYu86dQFFyOVPCB4vWkpfpq2NbM/+Hq6pUNJ+PfhTBsNnkyu/uygggIL W+ZKkcdgWBrvk3cWyNNOwRmgtGka1kGilngZam1DFRcq71ko3t85njxjiXPov1SvdRz5YjPL9 yk79vTjk9oB45sNED8RxxaG8wBl2wVDPjbnN/VkvTsLxAbPd7qqwSed6ntuedUMTO84tW0Kdj m0bSm3pF3d+GKf5zxaCmSol85+2WsLEXERK8E/jv1N/RqBcPBhFct/8zg8gki5MWw+5NYrXpM UPxuNXoBUgGbtuHV2jIkGhTQZvDGcsxtmPWisqjVnUUs9kTBa8AAP1oVsxnuL4PbSTiHU+xES cEjOi/jI98cwqW0iZ0FhVE3kB/rqW6gxSYpmln3uVRRg+9K3JGf6+W9C+C6P28s5CcRrmtJJ3 D0QPPawxEKF8bVJyLhAfz+kvxVn7GIELCVqOg5DmmGxv86DHUhGTLIcBXEVyTetV6mXy2v+M/ Q5DvNixN7AtaJgNDZoDwnK/QLErjEMRVdHUjCqBMYllmBanRcy7Lz6QkUJD+OwRcaEPYqZ1LJ 5Eso5GI4zd/+3ILsVToGds//+aQIQAIVCRNkHulVxKBAqQRGV7yY8qntedEJCj3wsRFFuJNKY 4/Fk6QP1Q16SO5iPAr1+5fhGuNOQMK9TIdVci2xhaVSTnrqu1NBK6gDtEH6l30diRHZz2mzRm 9TB1pQ== X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MIME_BASE64_TEXT, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022177933730283?= X-GMAIL-MSGID: =?utf-8?q?1750022177933730283?= From: Lino Sanfilippo After driver initialization tpm_tis_data->locality may only be modified in case of a LOCALITY CHANGE interrupt. In this case the interrupt handler iterates over all localities only to assign the active one to tpm_tis_data->locality. However this information is never used any more, so the assignment is not needed. Furthermore without the assignment tpm_tis_data->locality cannot change any more at driver runtime, and thus no protection against concurrent modification is required when the variable is read at other places. So remove this iteration entirely. Signed-off-by: Lino Sanfilippo Acked-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 5ff4ca5fb936..d0e5acd6b769 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -728,7 +728,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) struct tpm_chip *chip = dev_id; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); u32 interrupt; - int i, rc; + int rc; rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt); if (rc < 0) @@ -740,10 +740,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) set_bit(TPM_TIS_IRQ_TESTED, &priv->flags); if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&priv->read_queue); - if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) - for (i = 0; i < 5; i++) - if (check_locality(chip, i)) - break; + if (interrupt & (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT | TPM_INTF_CMD_READY_INT)) From patchwork Sun Nov 20 13:31:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23422 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116817wrr; Sun, 20 Nov 2022 05:34:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf7hqRvqA5MlDD2UMT2l67ShI34WT0Il/b0Qg/DliwCWy2v9Q+LRajT/jKy7mZExJz4jMzWb X-Received: by 2002:a63:595d:0:b0:476:f2b0:b318 with SMTP id j29-20020a63595d000000b00476f2b0b318mr14189206pgm.598.1668951270305; Sun, 20 Nov 2022 05:34:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951270; cv=none; d=google.com; s=arc-20160816; b=XIN+5ZfLLwMUod+4Vx0iM1aefXp1uRVVlWV2e8eWycYked2VlyQ1TkV9iX/WuvQ+jD jsqHuKR9rJhbLGhHu1FwVgqT7+iVGX2oNsZe2uBwcQ9C/vlbXaB9W31KgzagAPNOJc9e ErJc5cLgKN5zZDRVLBopYeKYfpLuW/Y6u+ZNWTD7phP26vTHGAaRY1Fqhvw5/4dgnQ0j rw5jZcZammlJshmFPgfxzYGmy3E+X4BJqeRykGwmRC1lEcSLhY5iwJzm6ribmoF4Ai7W AiUK+py0ETcVjrt0GAtTxK/UFvCc66TtVmz5GYK8UNxq3QJ8C6ZTpUQOikcgISaAn8fv BVBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mujM8XcZPtYkQ3B4FgSH2rYtTxc0/C3MRTBTnMu6dmk=; b=H3W6yPsSd45QWhKQ9ANObe+8twXgwlq9DUR4paAfxStuthT9I5moMjEnDD9WY6NnDg DvCD0XQdTlk1oGoL6WSmdHTlOy6ILKczihwVWIeijODa0R/9F5tgDFcgtYW4Q8Eo7KTN VCrcbpm3PUiEHE11PlQ7dfW/RxCabvf9KGFjQBmhNTQtta3fMbJdnEjqAzf8oCDXuqXl hRDbp6pFj/sBRXGIc2ZX1lvOErIqxlxvc6tIGtb6WO0FJrkui3HEoY2JXhr/DwoodFc1 u5fLZBvpldCWsAzsi63q8NmUzHgq2oXrV3r+AF1HLVSYBmjZwNhr/fraJs3X8r37B8VG R8Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=r6atztG5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a170902c94900b00186827cc5e9si9389983pla.562.2022.11.20.05.34.14; Sun, 20 Nov 2022 05:34:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=r6atztG5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229837AbiKTNdH (ORCPT + 99 others); Sun, 20 Nov 2022 08:33:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 148FDB34; Sun, 20 Nov 2022 05:32:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951127; bh=mujM8XcZPtYkQ3B4FgSH2rYtTxc0/C3MRTBTnMu6dmk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=r6atztG5AplYF5bQD8RKXwicx5nJmkkIFzrgrPiuRAzsXzCV1UMMR5W9dZ52u8Hkr hIpr4O74UVkvPK7em3I8gD6yb8MVMSZqFZDggHLnT8NTnPSKAULdlIWDGy+v4M6BnF wS1kdeopMIsLS7B4SMinLcGw+zV+JdIDnKGtdwpjCjaacHaInm/kyjMOOq3XI+FWOL Al5hrkmXhVVGF8KZ/GO23d0eib56rTvnqdYEkGF5AOoAb6FQzl7akXpNCFIztEd490 55K1Qf0TDQSbYj7PvAU9VTpZDBfm8EnUfZ6OwS/6ByudeOVAJwFWxzs074jifXqdMq I4fQidtqfvD+w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MXGrE-1oQLAv31VG-00Yf9l; Sun, 20 Nov 2022 14:32:07 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 09/14] tpm, tpm: Implement usage counter for locality Date: Sun, 20 Nov 2022 14:31:29 +0100 Message-Id: <20221120133134.28926-10-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:a0lGO7ZgpoqQrWS0J6BFuHx+9CWESj/c6Q3CXkaKzSPe0+wurak gmT+Rn4Q/GpoXapCyXYECv0oyhy8RPfzTYmUJ49mz8wQvrcrEE+vVkwa2XARVEeahV8sq2x wq2IKgT2fhxdbJkfQ0jO4q0bLrGh0fWcskhMJb5XcOWq1fN3W5ePvF9wiFj7BGR5QbY3BgQ BiElQwsIQ4V2ijXngmCdg== UI-OutboundReport: notjunk:1;M01:P0:dtFF5JtrtR4=;xEMjq8XaQR1RpMrusqtbhQQ4LcL xhI7eEkOwhq5BO64PIxbW3krsIdXup0aOfx9EXcoPggXzwIjSsupBMAZHPMd+gqpFOAS39zSO RddG1c2/1CsNtqsSxguaZK03DgnX4+WFSxcNLT7e1zGuqoWM4tKrzwF8gBNO6xwSwvyApI3Gg fW51/Yf9VXZ6nFg7pglaiNKj5rbFbtJGr2UMpK9HdVq83hOFeEdCFrcznOoVRZDX054kqp8ZI S276xOU4PDlv/KMOIjz7xjXu2s1ym4ZpAx1Lm5M3T703BLIw4laofrm5PX8NVsk41ysWMm/nz QhgivpVTYL5TDP+NulT/Htsc9Ulryls2iXgrE1krSAAGPVObhEWiHnWF5CoC9btbg3bSHI7Vx yAtJzO7wyg+EOhC1xqXTOF9KOiohbnxj6cGW0Aor7KjVIhQypVPXPqlMd7esB1s0Ur28Jv9fU jaBqV6GVO9I+aahgNGYp5mr1EdG1TFb3n0CCfhjFgpAe3J6xhbI7qel0hdglJ1yv9w0mePcQw DYrm67rpBPX2GOysl9iFrQtED4HpRTHNksjCU0QPZmeChxI3sbw/ASjAXrKxmKm10rTGj8RgW HQH0S8Mnyd6FC0NRugS0TSj3ov8IK294CYqXT04YVIJBVNZMIEaiDudg4pFkej8e3nzUJRfiW rgMc6tn6Tv/ooJuSk6IKcSpGiW63gPvR8ngR4TRgYC6ouwd9wugw4vvl1PIZX3Kghp+Sx+RHc 1dvjzvN3U40Xlx8RATYYWIeoVKfot7Nr8+6lRiSkV2vTCKi+5PGplRAMzVDvq4SZuLci0wVKM 98ej9q8N90HxUQkJK4Ha3ObYqYhQoiEe5wdueyUuIYNV70BFrqwJHgDwKk7mCPQDHmEW2b/Pj olvuW2KtJCjSHqy/t0bF77AenUa6tpxbPZ1stePqthlPj3ogZ2b4OPjrlEUC+shmxNswinUqb 4w87sw== X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022246785724379?= X-GMAIL-MSGID: =?utf-8?q?1750022246785724379?= From: Lino Sanfilippo Implement a usage counter for the (default) locality used by the TPM TIS driver: Request the locality from the TPM if it has not been claimed yet, otherwise only increment the counter. Also release the locality if the counter is 0 otherwise only decrement the counter. Since in case of SPI the register accesses are locked by means of the SPI bus mutex use a sleepable lock (i.e. also a mutex) to ensure thread-safety of the counter which may be accessed by both a userspace thread and the interrupt handler. By doing this refactor the names of the amended functions to use a more appropriate prefix. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 63 +++++++++++++++++++++++---------- drivers/char/tpm/tpm_tis_core.h | 2 ++ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index d0e5acd6b769..9aed9c26d2d5 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -165,16 +165,27 @@ static bool check_locality(struct tpm_chip *chip, int l) return false; } -static int release_locality(struct tpm_chip *chip, int l) +static int __tpm_tis_relinquish_locality(struct tpm_tis_data *priv, int l) +{ + tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + + return 0; +} + +static int tpm_tis_relinquish_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + mutex_lock(&priv->locality_count_mutex); + priv->locality_count--; + if (priv->locality_count == 0) + __tpm_tis_relinquish_locality(priv, l); + mutex_unlock(&priv->locality_count_mutex); return 0; } -static int request_locality(struct tpm_chip *chip, int l) +static int __tpm_tis_request_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); unsigned long stop, timeout; @@ -215,6 +226,20 @@ static int request_locality(struct tpm_chip *chip, int l) return -1; } +static int tpm_tis_request_locality(struct tpm_chip *chip, int l) +{ + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); + int ret = 0; + + mutex_lock(&priv->locality_count_mutex); + if (priv->locality_count == 0) + ret = __tpm_tis_request_locality(chip, l); + if (!ret) + priv->locality_count++; + mutex_unlock(&priv->locality_count_mutex); + return ret; +} + static u8 tpm_tis_status(struct tpm_chip *chip) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); @@ -682,7 +707,7 @@ static int probe_itpm(struct tpm_chip *chip) if (vendor != TPM_VID_INTEL) return 0; - if (request_locality(chip, 0) != 0) + if (tpm_tis_request_locality(chip, 0) != 0) return -EBUSY; rc = tpm_tis_send_data(chip, cmd_getticks, len); @@ -703,7 +728,7 @@ static int probe_itpm(struct tpm_chip *chip) out: tpm_tis_ready(chip); - release_locality(chip, priv->locality); + tpm_tis_relinquish_locality(chip, priv->locality); return rc; } @@ -787,14 +812,14 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, } priv->irq = irq; - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) return rc; rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_relinquish_locality(chip, priv->locality); return rc; } @@ -833,7 +858,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = -1; } - release_locality(chip, priv->locality); + tpm_tis_relinquish_locality(chip, priv->locality); return rc; } @@ -949,8 +974,8 @@ static const struct tpm_class_ops tpm_tis = { .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_canceled = tpm_tis_req_canceled, - .request_locality = request_locality, - .relinquish_locality = release_locality, + .request_locality = tpm_tis_request_locality, + .relinquish_locality = tpm_tis_relinquish_locality, .clk_enable = tpm_tis_clkrun_enable, }; @@ -984,6 +1009,8 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, priv->timeout_min = TPM_TIMEOUT_USECS_MIN; priv->timeout_max = TPM_TIMEOUT_USECS_MAX; priv->phy_ops = phy_ops; + priv->locality_count = 0; + mutex_init(&priv->locality_count_mutex); dev_set_drvdata(&chip->dev, priv); @@ -1062,14 +1089,14 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, intmask &= ~TPM_GLOBAL_INT_ENABLE; - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) { rc = -ENODEV; goto out_err; } tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); - release_locality(chip, 0); + tpm_tis_relinquish_locality(chip, 0); rc = tpm_chip_start(chip); if (rc) @@ -1103,13 +1130,13 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, * proper timeouts for the driver. */ - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) goto out_err; rc = tpm_get_timeouts(chip); - release_locality(chip, 0); + tpm_tis_relinquish_locality(chip, 0); if (rc) { dev_err(dev, "Could not get TPM timeouts and durations\n"); @@ -1129,11 +1156,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) goto out_err; disable_interrupts(chip); - release_locality(chip, 0); + tpm_tis_relinquish_locality(chip, 0); } } @@ -1200,13 +1227,13 @@ int tpm_tis_resume(struct device *dev) * an error code but for unknown reason it isn't handled. */ if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { - ret = request_locality(chip, 0); + ret = tpm_tis_request_locality(chip, 0); if (ret < 0) return ret; tpm1_do_selftest(chip); - release_locality(chip, 0); + tpm_tis_relinquish_locality(chip, 0); } return 0; diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 2deef11c88db..13bdcf38e56f 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -91,6 +91,8 @@ enum tpm_tis_flags { struct tpm_tis_data { u16 manufacturer_id; + struct mutex locality_count_mutex; + unsigned int locality_count; int locality; int irq; unsigned int int_mask; From patchwork Sun Nov 20 13:31:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1119215wrr; Sun, 20 Nov 2022 05:42:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf58klfG5msI8s7mMc/Os1q7ut757mv/kj1HjGSNWsRoBpUbzDOF5/GCkNT/QfNNQJRfzXez X-Received: by 2002:a17:906:9490:b0:77f:8a04:5d56 with SMTP id t16-20020a170906949000b0077f8a045d56mr12087705ejx.559.1668951760385; Sun, 20 Nov 2022 05:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951760; cv=none; d=google.com; s=arc-20160816; b=tjFutCusfd/O7oVkiUAKEcKZPnb48lTWBRpjfPmG5y36iAgjyPCkU6Bx9QG41+I4V6 iqw7+Kogx7AvS+cVSxx+BIoGDIo9IN7YH8ffhFXMTqcDPbsWqL4XJM3v9e9FYcCrH3A9 KgzCMoN8ZyqApHBdfSIBB0hzUSQFx2aLs+wBTGF5/pXq1RgdImREnqBgZhiwCUB2+smW nWmafUlAro37Kw+luBdtgmuzwOnHxHLAcRHPvi+pqqrXLV942S+Ocb8DND93Po9Ol36v 2Ai6nn4SkFtmmaCTJW3MGoLSLCWZ6lm8hlQy/OZfcYaqMTpVz/GpmtQHQxd09sdacpxV qsLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Fh91Z/S6CdFbZcIlWAtBWi5M+Ufp4fdLO7yRx0mA5co=; b=dhhz0cfDfruhgFTbxx+cqT+5n21GLoabxy+rmIbHkvRNOahW8IUEMrm282fa0nA126 Dq7EHo4+X1vIzWuYqh5IuKRpC04dqXx1KwhcZiYRAqCCI3PqYVgFEsvVgyo/whCjGtAT QHosfKBsRqkeN8i9BLmeqGOERLdb6cYOboeYY+/5u+TlBU1FoMMpTB3qbzmshMAHyoUE y3O6yBsQTEOY6f23uP+OhWDntoV4ttGgE49a+nMdv3YSyAOXm9FuR0CmVgJ76vAk5ZPG lZ8FteZpPuWiw3FvCxPKp2NMdQ5m236lpGcDkha0FGQtb4xQgFrNcdhBoQqsdfZcVCwV xG9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=eBvdx59M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh18-20020a1709076e9200b007ae5fa9b603si7878700ejc.374.2022.11.20.05.42.10; Sun, 20 Nov 2022 05:42:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=eBvdx59M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229852AbiKTNdQ (ORCPT + 99 others); Sun, 20 Nov 2022 08:33:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6017CE33; Sun, 20 Nov 2022 05:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951128; bh=Fh91Z/S6CdFbZcIlWAtBWi5M+Ufp4fdLO7yRx0mA5co=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=eBvdx59MiCt7nWfZqJpVdNH00Q+524VzOGZt5Iwpnu/O8aACnEjsN/r3KWjXnHVS9 jqWWkUkabri9ZL7nf2K3/6dL9En7XegauqEXx1eJE8QqkaH0mFpmQOlWFuAbAcv0nZ uH9HAIEFPnK6o2zJLDwjpA3hx3ij9oQypKWNeP62VF/fj4fZs6ppnF9gH0IoKqIUXA hI4cSQE/AYxJWSpp7x5WKfkIbslPt3j719PrqnC8e24t/+iRe5T+FiY6jxFHBWOqet 7fe5tqFo7Vzdvq+2hucM5+DHqxvBrIMlyGT+SUv2+TNTTUY0mBCwkO2W7M0pbpM4BX D7V76EGkHapCg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MBDjA-1omFmQ0MFq-00CkYD; Sun, 20 Nov 2022 14:32:08 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 10/14] tpm, tpm_tis: Request threaded interrupt handler Date: Sun, 20 Nov 2022 14:31:30 +0100 Message-Id: <20221120133134.28926-11-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:eOWaNTW8FLNMvyPKVdWuy8VMWOkkayU+lKPsQWbeIJ+zIUri7QD fQHMBToTd6EmbYjH4xD/EZ/89RUU5GzupzCyP2hk+prD23Vis0/SDMyGp8HW7OfbZZ1jkbh YptTTe415Q7YxRuudPV812H5jqrp66HE1/LScLLxHyTQ1p+qulo4lOVRGryMpLgYXaSfGFG nZonkZ+NtssoyLQG6HluQ== UI-OutboundReport: notjunk:1;M01:P0:9dwm6XbUp9Q=;gqt37mfZgKTSzuXO8S2lBU6hWrU vShXolsRIQR9cMOgiNNPT4yanYtb2Z5NSk7c8h0nN0noCaTKEfb/to5TYXQEo7LK8/pn/mCKI VtzI5aNV/8oUaFNuvl7QSl51J3mQiIREjsckpk4Nl848cPUNbDwQuq0wu0auB4gfJv2lz5IKN aMQCI2QU4WvzeyU8YdbuqT7Q9FwrFYSVt+rm4QYcnC6KtedYChlFueIBdlzKpziN9Ww74wVry flOj+SmzZTx4drXWcNHVOATQTrxT2HRK5ke6qjukVjKd//f4PI1d18lk37um+nGkyRUkR4Q7X MuFQIazC45gURjhCUvJNvBmxMG9xUKSawMqYUEkRt464Jx3h3KhkDu/4dzMdhoIL5R/QjDaiT woNJPcP8o026UGBqFnjsYHDk8k4Gjz/fYE6JrS7/khnzkOzehR1mdlAdO4cAYOEQXQD+86KRP YlS9VHGZatcyvfTblqiYS1HXvfa28Zdkby6d813twthsjZ5AYB5/qclVejR1rrLAyZCMtcbZF 8hwSG/UEgpG9tcquw0L7GZpcVhnT/WtAQnKHHHS9bX5UGAbxYwVX9tXWnpbdGpPRiEOIaU9li k8RY1ur4PS5cdl0sLxp1uiy7N3YvcPzePErgP9VgDvxeM7rTfGktDd/Q/I9/VsJRQbs6qy9zV vFlcBMRiWGfD1jZQrcwpAu1mf0EE/puQh65sZKWC4Gw4I4W+WKnGR9zyqi4vHiEWAj2Yf6wMr TYuqHAAKNUvGVtfuAkCgeAn3qb1U3SifUaJS/+0zYF9mDu0cLHjaD9qGGEqe1U99Bsx1W2Cpt dlcCiIREY5GQz1BmLamTaM/tKdfVTxDMfiRspFXTaK9LpliJVLlPX1XMK9mWSGOCK7otUPZX8 qarwIJelf4Pr8T/370LivR+WPiZ081l5cVZ0DzMTDw+wjEqhJ8KvOr6bXkBO5pna7JxOJuvHE 43JglQ== X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022760708314870?= X-GMAIL-MSGID: =?utf-8?q?1750022760708314870?= From: Lino Sanfilippo The TIS interrupt handler at least has to read and write the interrupt status register. In case of SPI both operations result in a call to tpm_tis_spi_transfer() which uses the bus_lock_mutex of the spi device and thus must only be called from a sleepable context. To ensure this request a threaded interrupt handler. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 9aed9c26d2d5..6c765a4406bc 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -804,8 +804,11 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, int rc; u32 int_status; - if (devm_request_irq(chip->dev.parent, irq, tis_int_handler, flags, - dev_name(&chip->dev), chip) != 0) { + + rc = devm_request_threaded_irq(chip->dev.parent, irq, NULL, + tis_int_handler, IRQF_ONESHOT | flags, + dev_name(&chip->dev), chip); + if (rc) { dev_info(&chip->dev, "Unable to request irq: %d for probe\n", irq); return -1; From patchwork Sun Nov 20 13:31:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1117447wrr; Sun, 20 Nov 2022 05:36:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gMq1+EQD/KJbGoUy5Xji6IhFMna3Q2gAvmbMdvfVOUuApogPN9ZKR0Sm04T0ncZtNxFjg X-Received: by 2002:a63:a05:0:b0:42b:42fb:3da1 with SMTP id 5-20020a630a05000000b0042b42fb3da1mr14212123pgk.538.1668951379961; Sun, 20 Nov 2022 05:36:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951379; cv=none; d=google.com; s=arc-20160816; b=wYDiw5/Sg1WBFO30R5fhIcyuuPjwGkgaIliBVHLPB1zv62VTYNbFAnJ+ttWBlkoXvb LRUKL/AdsI/p59waDr/eJs+YIvDk6Cqrl0htHDSkD6cggnhyFbB8953bfUvX9nYGHqyv hDK31qXp65GJZJfP3aGhFZ7vRC8Eq+dFxGzlxHy4FkaNB2B7GsCqXA7fa8KHBe3eHmAc X1E36j3uPOHkSRS4TN/ll2tU+vXM12PcQOz2vT/Zdn7qOebpC5KW17q2sb3gllyStsX2 mODRyPQRnnSigbZme4YcX/fQihuQ2mu6SLV4cyEvg0Bxae8dw04RtE50IDbceAjeO0qo 7mTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oScRVbxrfAZvMb4vGMxtk0THIEPoRWv4PH6mpzzQxyU=; b=lveiOQEcTpxOoFaYM/xn4wdU7veAMVGklikPkS+ZrK7u+nRChbTl24w3FMV196nmkB pU9HkQfO7UrdEEasAut3wKxisCuQkt543uM3XGbX8U7LH5vFVMD6F0OAI3zo4kPDO/Hr OitXHSjB5k/s62I4Fe+LCswGbBZ3PVSHq+fMNXAhWKpSylLx47Q/1bpbSCoy/QF/2utr ce0xsbk0IfVI/cWMbwpLxTKc9/KVMqyKjqqYMUwxuwFLws//C+wC8e0Ws627YI1GK9N3 0gqRpYtnuay9WcHSIlEGNkkyZ6OpLMiVJWWw551L0kuvRP4nbOzLXm+z6sF2synWcGco /zpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=BIsKDu9o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i11-20020a17090332cb00b00186de874df8si9938749plr.442.2022.11.20.05.36.05; Sun, 20 Nov 2022 05:36:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=BIsKDu9o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbiKTNdM (ORCPT + 99 others); Sun, 20 Nov 2022 08:33:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6848AB7A; Sun, 20 Nov 2022 05:32:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951128; bh=oScRVbxrfAZvMb4vGMxtk0THIEPoRWv4PH6mpzzQxyU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=BIsKDu9oeKvrALhGSAcrokwQfOIXZZdmtP22KCKbqiS+dD4mhMEu4dRm5H1hRBhKG ZnoutdrPJewrCEBcauz1gcFlvHcGsu8cS0pQCU7UoeIg/1ieF6eV03XjWs37woIL64 n522vv32jRvY0/euLkMlUApdc9hJ4OJkN5Qy3CAtrnPCRmbt/7uHfJDsiK6V9n6URD 5uSMLCXMVoODZgP99ZyfMWfZGEgXWnr7tSe8gp3i5b8uHg1PvPOCrkOXpYZchqcJ0o T8YxJVVSoL/63XURzZIV5OAG9K65iOL2/mJuxBTyNbc3st37kAcwfhClAriXJkBJmY 3TSND06Ta8aqg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MGhuK-1oiz3S1l22-00DotB; Sun, 20 Nov 2022 14:32:08 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 11/14] tpm, tpm_tis: Claim locality in interrupt handler Date: Sun, 20 Nov 2022 14:31:31 +0100 Message-Id: <20221120133134.28926-12-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:84xPu3tCUK7zirPgmWTPn+CQfvQtzq9WkhaRX7+boR4TkLhrnOf g79mgN5DxYpBbTu+2iAPgUpC+mRLb8F5Toqpr01QbqCVvNAFIEVo8Oip6IwFpMtFl/sdZ0A 0PPkjD6FApCR4ldNCUga/kuiNUP+mENaq6xHCPkQJLNjw5t1dRtPKp2zl84pvdw2L/HlB66 nbkO1VEqsCOYCc3HfdfTQ== UI-OutboundReport: notjunk:1;M01:P0:38sDud5K77I=;2r4LHhx5wFQcp81SQEy+mGfWmDT fnLE8e969kQ8lOHGNbx2PbfY3myXkYjBqa1879OBiYEi95v0qusWI2Kv17iG3yNxdD0GdOZOV CKA5N9MyP/oTfCjerxtXD3b1W3nQ7H1QAa1Ffz0nWd0hsDP9hbqUxduthWKPPP1XPvdO51oux zIm9cM4xoMdTsJYq6+Uzi1ywTLNrNfjE1EuJxPTCHpg8/yFJblVaYPz2Ue/qOYT54zX0qP45t ZMTgcj1gybtmimxoRnSZrIyzaEp+cZsrPaCI95b2KqKpupqjgFybhF3D4XfLLhdQaZWvLY94W qyV5cGp4YKuaSJEvTQUVZncWFTKungOinQCx7U349SlGIPlMsU4WAw2r68A9T8V6reAx5JpSo Wl1uZ4co/o0dTCTudXXLPVzQZx618ZQm6k591m0y2AgFYVy0gqNWh8MNiWRjsYjKxZoWNqnYJ ql0NQnjshQ5nlL5/yf68Rx/dj5hiEP6YG+XBAH/ysqH7nHj5W+uVvY7uR08xklJXbXhtjTFD2 sNrTz4EqFU4YCe9cH1DnUO87VGgN1qwR9zV/CKQm1dCoWQoJPePE1PkBMEMlwU28q5DccNW0p yj330R+jS62JWu4bO9xG4yebvXjizW/Sikfwgc5wrGuINFzLk56uJDCXk/PpFLTHrrkNeMSpz xnq//WurEtCX8pv6cDC9+bIW0+jdYi0CB/f0YSPKeaiM7ppxka2zk7ggl4iTWtYgTVxMldtdI uB/7m7fp7MfdNFN41UI7qgNxvjpptPaZnwr1MsDWQV3rCTsVtALFxnnKUKv4yqVR4ZKsJgBLT wgIjmD9EySj18BkN3leeWgcmU+dfoGw2NeNPKTj+tnuTMNbWcRn7jrl1xhebr3oFJTDZwvEH0 1XcPL3/iJEjyfHulcOGOtEU1TpZW/Yq2J2omPHV30qRYdmyJBrjfBQIqsfEbHbs8JUO9NNJjL HrXqOA== X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022362153516742?= X-GMAIL-MSGID: =?utf-8?q?1750022362153516742?= From: Lino Sanfilippo Writing the TPM_INT_STATUS register in the interrupt handler to clear the interrupts only has effect if a locality is held. Since this is not guaranteed at the time the interrupt is fired, claim the locality explicitly in the handler. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 6c765a4406bc..4312c5cc13da 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -772,7 +772,9 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) wake_up_interruptible(&priv->int_queue); /* Clear interrupts handled with TPM_EOI */ + tpm_tis_request_locality(chip, 0); rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), interrupt); + tpm_tis_relinquish_locality(chip, 0); if (rc < 0) return IRQ_NONE; From patchwork Sun Nov 20 13:31:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116495wrr; Sun, 20 Nov 2022 05:33:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf7S83d7Z1h/Oum7dfFNYsbuprToRO1DIjuZcCzwc6jXrtcBt5wC1HcdQ98cPwKpX+mpNB8i X-Received: by 2002:a17:902:e04b:b0:186:605b:f99b with SMTP id x11-20020a170902e04b00b00186605bf99bmr5728627plx.49.1668951216756; Sun, 20 Nov 2022 05:33:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951216; cv=none; d=google.com; s=arc-20160816; b=sE7gHR7i9TCA4tykZfdUIBmhGrqTU7MHLnTx8o3Tu3RS/IeWS2sBYLKU9R2K0vWkhw hmdNyUN1xMrEGYQ+63Uq9xbGhQVIoq7qqSXNq8p7tqkRYQnZoyjfLD+FO5CfybR9tMo2 TaCMMZ0DxRLw7Qe0ZFFW9k5GMAjEFxcNZJv7SMM+lrDsj+/zIkTrF6EgVeBuXfTt8GKm 7Z1km5CgukPtZAJAzlAoJl7EpI5BG0YUKrxa27H7mCFR88ABuY1JJkqid3sweOTC/SIm Lps1Kg7fgSEtilG1ZD/sWaxNKEVfLrVazSfhda3fVpSr4V9V4NNAvtA7Qxavp0BV8CB7 u84Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4OA7IK6FYkk305Zhb0W1evKbz0zZ40AwmsMipD4BkLE=; b=YH8BrH+H9j96R6ZjYJyKAUSy2F1YmejKqMBmAcwQzwGzxqvjG89ldx8NJxO2Q4KUw5 YwWYq3xq5KZnLxrF6N48prjvu2vc/cYuepdJ7oonhLXrtf5RQg3RufOZH9vKhhI/h2V1 BD1WyHC8XdgH3oyOA1/K2NLX3exJbfApjr2zbFn6R+ykaPTJeOkF40v24BQD9dGc2gGb AI1FoZ+iKgakVK2bdHXUXO0DEfRf0RYFU+rTq7EtVlejtZkel8QYuFq98KKap6YQHegv MbNWMHdYA1FdlQRfvVqmZQFvHkuekDi8h37MQtbHhcOoGNojly8mZvdr6LQL/S9WLn3m 2DGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=NSBTHCpb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a656445000000b004468ff8fd57si8907630pgv.680.2022.11.20.05.33.23; Sun, 20 Nov 2022 05:33:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=NSBTHCpb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229455AbiKTNcs (ORCPT + 99 others); Sun, 20 Nov 2022 08:32:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbiKTNc3 (ORCPT ); Sun, 20 Nov 2022 08:32:29 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CDA824C; Sun, 20 Nov 2022 05:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951128; bh=4OA7IK6FYkk305Zhb0W1evKbz0zZ40AwmsMipD4BkLE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=NSBTHCpbkjFFSJ2iELowShWXLJ/DsbOAcN5yzEAo+5jUsmHpdecwn/PEWEp1OZu7x +iZ9Dzon0CDxHEUAPQ5/wq95yje7yK1+Cy3BBC9vQuXdaVn3YrEJqQyJXgP9/S6wL6 es5TT7Kk3kEZVBCG//62/vJk6p+9guMF+uozKh29uAyHjYy0V+VZTT0AEHOCzoxPgZ D8tBINVQEzOIHDGqVDgjx/YSXg1UitREpki5ezClrMiita84qYb5NTRwDJH8ourAgn XnHOArEWN433lxP1FtaT/ia5SgJnq3Za8Ej7t8AvrspcsVpjG/vkhdC4fp5kedAF/J Kmbj1Tp1/rnow== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MCKBc-1onMmA3ACg-009RAT; Sun, 20 Nov 2022 14:32:08 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 12/14] tpm, tpm_tis: Claim locality when interrupts are reenabled on resume Date: Sun, 20 Nov 2022 14:31:32 +0100 Message-Id: <20221120133134.28926-13-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Y2Bn6bdeDl3t3/ithIn9bOFj1yJNMiWUB6ywXGw5LG20I8Pov/9 QvJYibFa1pdIC3bTtDU+GUHDY24TPVfdTvJ506nTc9DYSqmXZ7vevwNzbaHLe4jtpG194c8 mDP0STxKk2YNQE6Yb1aUsHsM6tN8ouuh8WkQD/JMwxUCIoJ3qGr2Epui3fgaG5ZilWW0boB ZCZ7Hn3YNez4hQeaejUyw== UI-OutboundReport: notjunk:1;M01:P0:Nok8fe+gyn0=;mDY6JN+z9tqG7De91VyS9iEMns/ gRYGlqR+3QOdsfOPZlj51R4mCZZ3gnl7iSQEVPvdA5JHovRI63axlIg/Dd8Zn+Yx+daiPwAUK HeHDGD6ymUE7r7YujIyVkNM9HUjoCQ6ketUoT4ytRki3qvgisQ6jHEaMfc9MXFHd7bVj2sMJ9 sO5E2suzurAVEnhQD1Kz5qMcYTQmA0VCEuDxoyqYvDEjzQxcvG/wSV6MFc64UVOA0MTePtZEQ c2hTBnGXmvPHutIHBKuxg2Z1cfHmaF8DF/gFMHVLfO1YBvaMc3Uc313kt5KTDCFU2cejsxdxd B290wl5KsAXVVIGLDX8TFjnNYtwjmk3NW64Gzni8UVX49iLwx2zN6RbMSuAtqDwY6zTyJuJWE JjESKjwNswHIIeFSLTNPVW1BP2QEiqeYzubFxjT5jObf4j99adDrLY0cDWrvI082D7RXTA3s+ LZ4khSBzcT3MK8pVu1wXxG7AI0gLv1y7Tav+O9IYhtlt3abCHluaLeUNNRIPori+v3/4z/cx7 yA0H0gVqUdp2ZR/wNL01kExlP/AyxZHQlOQOcRmLe8JzSN+hbmpSxGj/a9gUvk5oxcXRTN2Sv iaX+BcYq6fHLE+OYrlz0miHQMpQgjO+9wMjIvT73GBblzARx4yXhVkiUa18+bNLRTNp9a9XYw Hit9BrdAquEehZKoQqKXqmZzhiIaVFe+Usca+m7AvuHvB0h3kIJwdmOEj+BMKelzGctTFeq1c hGe38Kuo4V7pzXuXk2mqv8gQesdCNGEQ/9Oe+2GvxCTDvIXKnqbjBQXNMxGnIEZnfxsWnSQwz B+KvkWWEaN73/eQfrrNG3C15YNkkOZqAGvUNamGXNjfkZmoDogVZgRxHpeC0AN53WbaklZuJ7 DUpVv3zhD167/NxRthzyuGqxgU3yh5XbSI70YPjlKydB+w9BbZK172rNC5mVfkIi7RqAqWMIk bIVd8Q== X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MIME_BASE64_TEXT, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022191321833539?= X-GMAIL-MSGID: =?utf-8?q?1750022191321833539?= From: Lino Sanfilippo In tpm_tis_resume() make sure that the locality has been claimed when tpm_tis_reenable_interrupts() is called. Otherwise the writings to the register might not have any effect. Fixes: 45baa1d1fa39 ("tpm_tis: Re-enable interrupts upon (S3) resume") Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 4312c5cc13da..2514e60f6778 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1220,28 +1220,27 @@ int tpm_tis_resume(struct device *dev) struct tpm_chip *chip = dev_get_drvdata(dev); int ret; + ret = tpm_tis_request_locality(chip, 0); + if (ret < 0) + return ret; + if (chip->flags & TPM_CHIP_FLAG_IRQ) tpm_tis_reenable_interrupts(chip); ret = tpm_pm_resume(dev); if (ret) - return ret; + goto out; /* * TPM 1.2 requires self-test on resume. This function actually returns * an error code but for unknown reason it isn't handled. */ - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { - ret = tpm_tis_request_locality(chip, 0); - if (ret < 0) - return ret; - + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) tpm1_do_selftest(chip); +out: + tpm_tis_relinquish_locality(chip, 0); - tpm_tis_relinquish_locality(chip, 0); - } - - return 0; + return ret; } EXPORT_SYMBOL_GPL(tpm_tis_resume); #endif From patchwork Sun Nov 20 13:31:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1117239wrr; Sun, 20 Nov 2022 05:35:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf7sqlKpVCvw9GQXL4D7gMLsK8TR9J8Csdl23XxbpI1JNmE4Ct/b8uAgQlsYMNxtqWEzJjIm X-Received: by 2002:a65:674e:0:b0:439:3ca9:94a with SMTP id c14-20020a65674e000000b004393ca9094amr13733085pgu.107.1668951346268; Sun, 20 Nov 2022 05:35:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951346; cv=none; d=google.com; s=arc-20160816; b=vtcyDUbmPEMcg/7hoa5KlX7eWAR4bGNZUb5uX82f5Je8Gci5/NtHo8KNNVGcufnLUY m97kB73xsGXmpZ3W+akMZd4sOJs/sRvxrH0RNKSGTgEprZk888Fpo6k8KOnr3HawVwmx U3//WnhUNlMbap1YWEhVmxhR57osI0wt3/IDZgpxh7qcwLG296oOg8WlPU+U7eUxbbRA OM7uD3+opjPiEfdgmkXN+OESjRJCjtZ8YtyACVeWNLxZ4gEghXKSN5++5fPKho1R2JwB SjaODtJmmZEPAjxIgHVb0DEhHbTsOV4c6gcvAS+cN1jW3FEHhFjCBfeBqmxhYN2WLXqI 8SAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E6zlWIm9oM/GjzOpdjNAuGrLapusFr2z5NlJBYv1qs8=; b=Yb0xxG1YTj2LSlWvERnFmL2XH7EH6M9qh2++5juhQfn60V8c6jprQcwtP3cFFf1TZt ywmm183H/n7HHXbYj693XvYtUbdBejWzLfgGevVwUqpKAqScvO4CUcnWFzWDbYiY0Yvs 8Cjx56FF1OZiugjNJXtf9WHDI5yisG7e5LPcUCa78cbcOa83uuFqOlkHcYiN+BgwaRTZ JWkRho0srtrqylsW2d1f038VasL3J+TplIRA7YKZqOWAL1QjISlHIPuszJdK9v4wiL5d QzXGLyMkfvVx9f7CRAeEAkupDrAmTrZ11YsWAlQm20/mi4YazQfADGciNqp38bzyGCMd 75pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=i2h2mOc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g2-20020a056a000b8200b005732e831300si7573416pfj.337.2022.11.20.05.35.30; Sun, 20 Nov 2022 05:35:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=i2h2mOc3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbiKTNdK (ORCPT + 99 others); Sun, 20 Nov 2022 08:33:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9C4FB28; Sun, 20 Nov 2022 05:32:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951129; bh=E6zlWIm9oM/GjzOpdjNAuGrLapusFr2z5NlJBYv1qs8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=i2h2mOc3C3vVDsqj33TjYpssnck9VB33EVvQavhM5O1mXJ1hes4o2R/cYv0TEd2Eo wlSqFrpy/oVTQ7yNOWRKiJLwurBOgFekfAos71dho1uqrQJLninyfgdRc46esrVKQC KZDEMoQyD2d5FyM/1h91YM4Y4FnTlZ3AFZ8JF8shMOzPA3kHjbvLKQJeDQ3RF8j/dZ 3sUgXv3aFrSyoQ5B9S15Fw4SCgc+eIkNhagKI70qEe7fpvzQ6dVIP65fzILWSeBEOi FvC063QBQRC3DCnFXziokM5zVJTGimc+XTQQ3jjNmAqPvod2lRdRljRp6oaeki7iHa ei3WJIpMU8hLw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MTAFh-1oV00k0XGB-00UYYC; Sun, 20 Nov 2022 14:32:09 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 13/14] tpm, tpm_tis: startup chip before testing for interrupts Date: Sun, 20 Nov 2022 14:31:33 +0100 Message-Id: <20221120133134.28926-14-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:o4Yv8LXi3e7EPxUvPlF5naCJKcyg/01QSCkduQcXf0VhvL/9xWN 38/8XEupEFIFwFL7cLZJwOr7L/zZd4ME0aTqvIJLPDO7FlH1VMKTHPX7/3rVVHaijWKxRyK GcILisb7Tld1OHTL204XKo21XVuoFoRF5UQWzJdrVgSmevwBHpfzW52gdnHDkaS231D9lqm X938WbCORj9Bk02IkYABg== UI-OutboundReport: notjunk:1;M01:P0:06rG0ZS1J/c=;RSMRuY/3OKsQ5trQLbvspA8j/tt me5d23IVCWFvb9DvjpfT3gogOJWPob2IOX42+dPgWH8Rig9J9bLaYsp9VAU+R89TBPaGjmayp KvQrZFVxq0HNc1pVmzXwZ5VKs+Qf1QDMSS4P2Ptbg/ruYg2mgdJFxHC+6f4b+um22BePTTPQo WSgDdPe1tcXJe1+41jfa5bq6I1Kx/7rHjBOr8JgME4xf4P8t4fsiCzrUFJH8KgJYEWGedMVny fw4yLh/CTjlS5Dz+0/STt7jcpUYWya2aK/GJ8n/5Xk4aBCI9H7ZTg1NsLWYmDPKyd0Gik/YE7 Q8LYsTVYYK8e7ycG17s/njOqHP7i1q53ZSrS7AuthCPiEiRykIujAY9tnE+wFknRj9jxSig4M 1u216Ww5Nvvd4ElJFUgxZm3i6U9bwV7ehWjpKKW3uodoQIF6foU4siPwl3qUwL/1cqjAj+CcO y7KjfmNQk58ZGiGueLWORK39KfgS1eCDwzC2G83qbh0Ac9koKaJ0GK/GffcUg7blvb63h9T+A zTXg7fv/7+gsaU8po3/0vR3E7aKxJlJVXUONMiHX/5tpZ03K8rYfzR0mMweYF/SAomPcNSc6O xsIBy4WJ5vriUBYSGyUkNxYLTFGb+8fw9mC5hlZ7dqrLf2tPcRPvYydnCFHXsRE6zq2B3+u6U tpTDEvgjc+MMFc5uBKGEtG35oqRUDu22KdllIxTkxOHJowUFHXm4S72yp0PYtuffLX/FFuxGX jsCSWm/haU9h0bz6AW3XyciivTo/I79KshCxmrn5t2hFeid96t1a/l5Ww9OyHtVMYRDz66wB3 0UBjX/E0gGuRvwxW70T15APOFvUz8ZafBbxSDeyBiF3MhnRe1VQ2o/EdgzYeK9LCFQcKW4VXx jCEFguNv16Pd1hb7fvAPPaMgLHeXs8ywGvbEzTvykYFvtTe3zkrInXCogjFxT/qi+8Am11Mf3 7AtzgQ== X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MIME_BASE64_TEXT, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022327247035909?= X-GMAIL-MSGID: =?utf-8?q?1750022327247035909?= From: Lino Sanfilippo In tpm_tis_gen_interrupt() a request for a property value is sent to the TPM to test if interrupts are generated. However after a power cycle the TPM responds with TPM_RC_INITIALIZE which indicates that the TPM is not yet properly initialized. Fix this by first starting the TPM up before the request is sent. For this the startup implementation is removed from tpm_chip_register() and put into the new function tpm_chip_startup() which is called before the interrupts are tested. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm-chip.c | 38 +++++++++++++++++++++------------ drivers/char/tpm/tpm.h | 1 + drivers/char/tpm/tpm_tis_core.c | 5 +++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 783d65fc71f0..370aa1f529f2 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -543,6 +543,30 @@ static int tpm_get_pcr_allocation(struct tpm_chip *chip) return rc; } +/* + * tpm_chip_startup() - performs auto startup and allocates the PCRs + * @chip: TPM chip to use. + */ +int tpm_chip_startup(struct tpm_chip *chip) +{ + int rc; + + rc = tpm_chip_start(chip); + if (rc) + return rc; + + rc = tpm_auto_startup(chip); + if (rc) + goto stop; + + rc = tpm_get_pcr_allocation(chip); +stop: + tpm_chip_stop(chip); + + return rc; +} +EXPORT_SYMBOL_GPL(tpm_chip_startup); + /* * tpm_chip_register() - create a character device for the TPM chip * @chip: TPM chip to use. @@ -558,20 +582,6 @@ int tpm_chip_register(struct tpm_chip *chip) { int rc; - rc = tpm_chip_start(chip); - if (rc) - return rc; - rc = tpm_auto_startup(chip); - if (rc) { - tpm_chip_stop(chip); - return rc; - } - - rc = tpm_get_pcr_allocation(chip); - tpm_chip_stop(chip); - if (rc) - return rc; - tpm_sysfs_add_device(chip); tpm_bios_log_setup(chip); diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 24ee4e1cc452..919bb0b88b12 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -190,6 +190,7 @@ static inline void tpm_msleep(unsigned int delay_msec) delay_msec * 1000); }; +int tpm_chip_startup(struct tpm_chip *chip); int tpm_chip_start(struct tpm_chip *chip); void tpm_chip_stop(struct tpm_chip *chip); struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 2514e60f6778..b97cb325ccb7 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1128,6 +1128,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); + + rc = tpm_chip_startup(chip); + if (rc) + goto out_err; + if (irq != -1) { /* * Before doing irq testing issue a command to the TPM in polling mode From patchwork Sun Nov 20 13:31:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 23423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1116897wrr; Sun, 20 Nov 2022 05:34:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf6AFYX8+aNntI26relpoWnbCLs0TiA6XiVwjrO7S6LdlmX77KmV//63P+Px/WmJnVWDovT9 X-Received: by 2002:a63:470e:0:b0:440:69bc:c972 with SMTP id u14-20020a63470e000000b0044069bcc972mr13735229pga.86.1668951286021; Sun, 20 Nov 2022 05:34:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668951286; cv=none; d=google.com; s=arc-20160816; b=VHOr6TgQ5f7GEbTLLBDLJvjr1CbqRRV5Fz0C9J6Mpf3/++PO7keGWmEr/KzGWBaBWB 3NIfSq/fabFS0vEOANjGpJqftkxvsJ0WzWPhwWd2bKJIxd+6Z6EKEeyJxhlv3bjZBbHk dc7804paXyEVbhLufnyw8rYUyvt+mUh5nmhN5vcb104Qq9Nhj/ILj/6sYk2BI2J4XEif KmVR4Rw0AwSuzDbxrY3jq+2BNQCgNwzmgWjBa/+PQZapoiZzCBw3fmhmKRLxLY2Y1K3m JIZWZpi3Bi4Qdsc9iCYlraKKwmIex4vly2IaosWG9MT4i3uvxOKExmxQ/VPgOJbdg7CX b1eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b2p9orljkPQAtfm2cx8Ohv8A3ug+yirHYm4KhuxDbQg=; b=L2sQWKBJy9fHSr6iAsdw5y64PgrmExSJy4LTkJNq28lIQ2H4BEMZ4U6Rym/09Y8/6c UrpjZwDrLqoV8X72ja3bHEsHQMemnNJIxy4c16AlIP7RP8cs/YfGhs9vS9L820QVsdrm ABK+IPfMoKy41/UMeBi7Pm06gvq4m/w4gR56Ir9mp33WaSf3tJlmnzkUdBqFOEQZlW9k TPCCosx66mPkUUV0X3RrJrpa292grxuiYBbtcb6oXaNxTK/QP81GsNak9kEV8glmrc9R OAhvxBFsWoo1jXkapuuE6nHfEgNNugtINdkbXa0nmHfefxKjKPJa89uBBk9rGi06Es4n F8Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=cLJ3ZWl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a634c04000000b00476f8b57e46si8688090pga.638.2022.11.20.05.34.31; Sun, 20 Nov 2022 05:34:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=cLJ3ZWl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbiKTNdE (ORCPT + 99 others); Sun, 20 Nov 2022 08:33:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbiKTNci (ORCPT ); Sun, 20 Nov 2022 08:32:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F1CF326; Sun, 20 Nov 2022 05:32:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668951129; bh=b2p9orljkPQAtfm2cx8Ohv8A3ug+yirHYm4KhuxDbQg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=cLJ3ZWl4KL9RDxAMDQazxg/pLd+UAJ34UD2jdHsrA8zzTo0oZuodjjbrCIaz6ztdu 9cQ11nbp1mfazF3yTPaPX9QZ4cZ3GkCm3iqjKhSud4umBw4KGR98KnmC5X3fbmvoot 6pgPZ2vcyLUDUbclQLgzDfdyBmt6AahXVjwkgd7XWXvhxbwN/J535tAo3mRPw7qS76 OL75adGNRqhq8oOOysn3HkdJxylcl5o5lIyTJldqnZWL1SbpWmWRtVApJvWWwGK/hz mAaZUx3xI/K+0u1xiKGPtjNb9Ho8oQXYDJ435hDGrPG0sqfEdj1accCwPnm38sOizy xV7mWRLrqQRZQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M8QS2-1osMht1t56-004VDT; Sun, 20 Nov 2022 14:32:09 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v10 14/14] tpm, tpm_tis: Enable interrupt test Date: Sun, 20 Nov 2022 14:31:34 +0100 Message-Id: <20221120133134.28926-15-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221120133134.28926-1-LinoSanfilippo@gmx.de> References: <20221120133134.28926-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BKMRYOEhyfnkSjTu8QNQmyWBrZ0shgweC98K2S5I+em4v1FZ1vw xJm/V0KgsjeT2pkq7QRrr2FLo/CfBqDLcYP60wIBRTvSLhV68R/Ams+kdnFxcYt8jb2L3ou pZX5r3uJjv09RWyvQxM4GR0ioUKekCkRPUT1LtkvJkbc4AY47ouqSRekmuK3Rmai8TxViw/ ynwEGbIg2JzXb0ffAcbEw== UI-OutboundReport: notjunk:1;M01:P0:mrSM3TH/Aok=;Dkll088hNQPY5V9rJi8UGOJXlhK /cloz7pNK06KOjCzCC7ZWEhOByE0aQhQh/yKhebkyyVJzoIOi7ySiRWEn7/k/WVebebusWZW5 igSfzp1b/aMLUvcKxZ0zBROBN7QemmtzaJkYVUUVIYx1OAXtndVQOj7LD47Qy7MFIA8yTcdcu qUnFLg3CTqrNLkNylDVcxLqPmjv0m4PhCCFuUBsZnkPHnNrn2TJx9mgPdiV2hU1Nf/Tnm+HMV gvyIL4YVTruDZ6U6OWhwyl6YTlpJ1XImMPm0F9LRxTegVJmYB18oDaf+3jtySuBYVA7f+6a+g RX33Z+uitevMgTTkiEeXgMk2l6AAlLmz/jVusjuAheRxqy7PgDHSVepwAPTGNXvMLSHnwS/aC 6MJr5oUJdDfeHFyUgYhpQkPf3HHdCds6xObHFPFqFpd2JP8mSSXoo7zfH72QfwjJ2Alyss9wY VQZy9Le8z307WUKTx8nRijLcRWh0a8i5DhlO4LxJ3vYDkUM7g/kkduiowOiFTJnFCDiR2C2Ei vRzVFdQgx8HlUQWES9VC/LfFuIotKfPMYFuHRl/8YSF0lfDyvMgGchuTLTDQ6W8VRSGivjsa8 rBbP2n0JLxVleUFmJJV1qTqWw+ysuXQa992+eD9mJZuuEY0JtOQrgHurJhlBj0kvGLKfxG5Zh Dpa6StViIIfspolhEyzYsSG72zgPgrZFLxlgWDR1D11BpSgGWW7iwYBV5Jkx0QzjUn30aVTsJ OhyCQYN3bncQigf2207ca5wL+fT8yREiW6y7ZroM4ZA40IoaVAzwQgKWT+JmHioetZg6ZmKJT xhXDqh+0DMn6eG1DEG+ch7yUVh8j0zxQKgMTufJBCZNFIIz8T6h81SA3vDnE6JWIQTfwj4hua uypPw1ZsctNbDOWQtnjsxDyRpMr4Ngk6/4UYYqNKEKsEi5/+SeMOetD5l2aEExv+qyVhll3ZZ MPrTOg== X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750022263599470098?= X-GMAIL-MSGID: =?utf-8?q?1750022263599470098?= From: Lino Sanfilippo The test for interrupts in tpm_tis_send() is skipped if the flag TPM_CHIP_FLAG_IRQ is not set. Since the current code never sets the flag initially the test is never executed. Fix this by setting the flag in tpm_tis_gen_interrupt() right after interrupts have been enabled and before the test is executed. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index b97cb325ccb7..602ca4bb8e2f 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -787,11 +787,17 @@ static void tpm_tis_gen_interrupt(struct tpm_chip *chip) const char *desc = "attempting to generate an interrupt"; u32 cap2; cap_t cap; + int ret; + + chip->flags |= TPM_CHIP_FLAG_IRQ; if (chip->flags & TPM_CHIP_FLAG_TPM2) - tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); + ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else - tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + + if (ret) + chip->flags &= ~TPM_CHIP_FLAG_IRQ; } /* Register the IRQ and issue a command that will cause an interrupt. If an