From patchwork Thu Nov 24 13:55:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3411069wrr; Thu, 24 Nov 2022 05:58:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf42f0Rl/sapBu3Vx9tj1Buc9UPjP3n6zK4AaYhcY1cpSb/4BXsE5tLSu/bPC5WJrJ2obJ9f X-Received: by 2002:a05:6402:1814:b0:469:d569:a478 with SMTP id g20-20020a056402181400b00469d569a478mr13649436edy.369.1669298308438; Thu, 24 Nov 2022 05:58:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298308; cv=none; d=google.com; s=arc-20160816; b=TUMeiZM8hzPUt0KkQCX5ARyEjriL1mdQCAPWLNv4nXTOGC1Yt5x4d7WqtsFaYo4/JU Q5i0H6P+R0x++YQyaXTQmddTOlieFbm13Seko1TADOM47bMfI9BciNCFrMw9QtCU9g3H HvrXc7/HKrJrUqYgmk8ieIUZfZ8rhkECcpKGxhPYRunb0YEBGFjDyT/LYqWtI1St/UJ7 PLm32HxFlvvTo+AKz+3ArK16u18JQTJvgRzHb1DQOkxHEDC3i5d3b7QCqrRgxOdO0zn/ qzFUHqCwEuwkwYfN5Nc8g0iYw7BYFL0ZQPnNURlRongOvPP3e4NX+Ru3pvM+BMWINn1V cg8g== 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=O3hPngwKvnADMqJEop2ssddB6++YvyJzeV6Pzvii2HbOXi38Zwo573iYbGFIIQdCiB 00Sa+yMvxGrolhL9SgchIsoi7HUPT/F+vY/bpPeuCrQfj/jTRaORUqqTtbAfHYxH07zo 6giJ2qQpdXzqdDoFOL0d0FbhY1x+jF/gdvKQ/Oqnwf2pgHWQVkPIiHCFgP4+EWUPHy/S JT5CMJRvNgyIQPw46Rfsb/qz0PXdmkspp5tVV+z51JkWkypnA4pe41B30U4KmNwNHK1m IRV9bNR4Pvf1nWWEdR1zIcG7xyiXttKv5pCsewmy7AfjhqxT+lV0qfzEyelLzdJg3Qze nOeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=hagk1JxJ; 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 xh13-20020a170906da8d00b007b8b7da6490si966197ejb.660.2022.11.24.05.58.05; Thu, 24 Nov 2022 05:58:28 -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=hagk1JxJ; 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 S230326AbiKXN5S (ORCPT + 99 others); Thu, 24 Nov 2022 08:57:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230138AbiKXN4g (ORCPT ); Thu, 24 Nov 2022 08:56:36 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D48116067; Thu, 24 Nov 2022 05:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298170; bh=A4TNiZ1MIqgxBlywM7kePzrqXJ+tGCscjealDs3aYxw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=hagk1JxJE4VdMc0GZGSSvhM4IGCJC8Jth77FtedhS4ETNsascWJ5pRIexQybW+tKe oELxZe9XBBWMwFY8ib3l+KHru9F2/28kxgJ4K6Y3oOq4VCa/LZXm/LIYR9WjqBHThf MQUhtojT9Udarjn34rXeQsFpGQHBnIwUTHC8GeAkz+/4ziJzDxtKRGTzqUyoqHMGsB DEuzjN7QuOHcNWJylfvuiCfmtTj2E3Cu96MoA27cuw7jd/boQ1Ay7mkBso6lA7F/sB P+oOfzptf5bRPxFWwD/DPu8e9LhNLATRBaYLhyBGfoiTQqcPkfpp9r/B4bZFe/VpCm 0DNlajCZ7lFQw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MjS9I-1pLxfE1AEc-00kulG; Thu, 24 Nov 2022 14:56:10 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 01/14] tpm, tpm_tis: Avoid cache incoherency in test for interrupts Date: Thu, 24 Nov 2022 14:55:25 +0100 Message-Id: <20221124135538.31020-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:MQQR6Jun0BPLpfZQKEpXcjYTEKKRsXbOtOxBKv5g8XyUjQMxeL1 wdCg2l+1GnKsuAMeRdZ9RMLr663bQDOqDCZdUT3Q5n5ssMDs8rJItbYlVwk8bvokECh0VpJ 8RB4mfmRHGFf9B4Z39gwFECsuwY2YUMJZP/c/znwPoaPOepJ09OhoBSq6P6Uw+W30ev3DCO gjDdjHI/G7N/l2dN6P/YQ== UI-OutboundReport: notjunk:1;M01:P0:pkzNZjHCOV4=;khFbfQ6MIG0InRJW8D6vRzSBJKd +BFcnCShZ55mzyUCUh3BauK0F6RF3Lv3M1d7fSqovH7+O9NUX6EM82AsIxIywJ7h1ze3lRYNk z9V63qZF3gj2d82fF5ehzadQVk2uE3CcHYRmpLVfm3FQY2YcI0mhmZ86ViFf75CqtFIOPRV1R rW42HTswseB+wF9mZQeY1RgMj6IW2WTAKB66itvrp2YZwtQHaylwMpYB5m7nIQxr/BM66MGuY h46k/VPVUcMuUN5VuzrpsFvfLlaAe9UdYVEehRnMFhoHyIF83yKptelszm+zIpHxV6/D7vhCt JPbv946ul5kDsZaPE5HLAgbXgngLjUCtqGv5nmuQ09tVDad/+nb/K13p9Ba4eQg6hgmU/DlZx 6EZAEKqJL6ETQLRFym2EsuvAx/bBHtbmtMrcQQ6vu1vqYBXl1oFbeuQ1L8397NKXFnc7A8iSz GoGa8aWzzCoocVyTLbU3ORTfSIfiUmBC3DYgJZR7t59jA1mWUM2KiolRegcQvDSZlweNaMUC2 /7CAZgnagdIaKPyttuCgTNh5wHpeqTMDKxZdhBjCqDe6+FkcLylAlSpaxqHn/RRTID8GaeNEq OvYq9giFrrTO/h7z3+/qeNSEci7MxwJTJvswNiQSMEapWxtA6F7yd8vVNs4TK8bscTVDBFd6T nr2L6QZZTkpYzsTWVRXMxuzW6lfFi6evdoYCOVHFxSmL0RaaWhYF7Lc2vhUfWTd+ZUnXGWlnC zqIc1aG6et6OVdPw1jk1k+sYyOMjQDkrx3qFwus1/Z8tfRqvthoHSFoSDwgfpPNZ/eY8Gjzt4 VZaL1k5V29raudesjEIRppLOiO4slZtzJmgFDGfUN91DCnORN5bSP6jK4V62jXNmVfuTMy41R F1YPfZv2V/r2GG2ytN4s1PaEdl365uikll3yaqVRS5VgDEv6WleG4jjM7o9rT6n7qtj8V+8oy O3oUng== 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?1750386143155620434?= X-GMAIL-MSGID: =?utf-8?q?1750386143155620434?= From: Lino Sanfilippo The interrupt handler that sets the boolean variable irq_tested may run on another CPU as the thread that checks irq_tested as part of the irq test in tpm_tis_send(). Since nothing guarantees cache coherency between CPUs for unsynchronized accesses to boolean variables the testing thread might not perceive the value change done in the interrupt handler. Avoid this issue by setting the bit TPM_TIS_IRQ_TESTED in the flags field of the tpm_tis_data struct and by accessing this field with the bit manipulating functions that provide cache coherency. Also convert all other existing sites to use the proper macros when accessing this bitfield. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis.c | 2 +- drivers/char/tpm/tpm_tis_core.c | 21 +++++++++++---------- drivers/char/tpm/tpm_tis_core.h | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index bcff6429e0b4..ce43412eb398 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -226,7 +226,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info) irq = tpm_info->irq; if (itpm || is_itpm(ACPI_COMPANION(dev))) - phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND; + set_bit(TPM_TIS_ITPM_WORKAROUND, &phy->priv.flags); return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg, ACPI_HANDLE(dev)); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 757623bacfd5..c0008efb95dc 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -351,7 +351,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc, status, burstcnt; size_t count = 0; - bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND; + bool itpm = test_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags); status = tpm_tis_status(chip); if ((status & TPM_STS_COMMAND_READY) == 0) { @@ -484,7 +484,8 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) int rc, irq; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested) + if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || + test_bit(TPM_TIS_IRQ_TESTED, &priv->flags)) return tpm_tis_send_main(chip, buf, len); /* Verify receipt of the expected IRQ */ @@ -494,11 +495,11 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) rc = tpm_tis_send_main(chip, buf, len); priv->irq = irq; chip->flags |= TPM_CHIP_FLAG_IRQ; - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQ_TESTED, &priv->flags)) tpm_msleep(1); - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQ_TESTED, &priv->flags)) disable_interrupts(chip); - priv->irq_tested = true; + set_bit(TPM_TIS_IRQ_TESTED, &priv->flags); return rc; } @@ -641,7 +642,7 @@ static int probe_itpm(struct tpm_chip *chip) size_t len = sizeof(cmd_getticks); u16 vendor; - if (priv->flags & TPM_TIS_ITPM_WORKAROUND) + if (test_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags)) return 0; rc = tpm_tis_read16(priv, TPM_DID_VID(0), &vendor); @@ -661,13 +662,13 @@ static int probe_itpm(struct tpm_chip *chip) tpm_tis_ready(chip); - priv->flags |= TPM_TIS_ITPM_WORKAROUND; + set_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags); rc = tpm_tis_send_data(chip, cmd_getticks, len); if (rc == 0) dev_info(&chip->dev, "Detected an iTPM.\n"); else { - priv->flags &= ~TPM_TIS_ITPM_WORKAROUND; + clear_bit(TPM_TIS_ITPM_WORKAROUND, &priv->flags); rc = -EFAULT; } @@ -707,7 +708,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) if (interrupt == 0) return IRQ_NONE; - priv->irq_tested = true; + set_bit(TPM_TIS_IRQ_TESTED, &priv->flags); if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&priv->read_queue); if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) @@ -793,7 +794,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, if (rc < 0) return rc; - priv->irq_tested = false; + clear_bit(TPM_TIS_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to * tpm_tis_send diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 66a5a13cd1df..695a2516dce0 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -86,13 +86,13 @@ enum tis_defaults { enum tpm_tis_flags { TPM_TIS_ITPM_WORKAROUND = BIT(0), TPM_TIS_INVALID_STATUS = BIT(1), + TPM_TIS_IRQ_TESTED = BIT(2), }; struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; - bool irq_tested; unsigned long flags; void __iomem *ilb_base_addr; u16 clkrun_enabled; From patchwork Thu Nov 24 13:55:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410769wrr; Thu, 24 Nov 2022 05:57:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4cn/O9mR4iQ45Ut8NBgr/58lB98EOflVwikQf/roBZA7tzDeuu0LC5PSLAd/5KpdXycsqV X-Received: by 2002:a17:906:c7d1:b0:7ae:fdcd:8198 with SMTP id dc17-20020a170906c7d100b007aefdcd8198mr28790041ejb.475.1669298268341; Thu, 24 Nov 2022 05:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298268; cv=none; d=google.com; s=arc-20160816; b=lYrCYGUY2eFsfjjtVy83NQrDK4yBppbLcHy8KgQCAE95dEqE1J4ZeZeakuC7vxY4/s BdfiL3eCWpcjOiSEZ3RPl0jhETNVtJZUklPoFGVuVlXklFABkfYOlMVnCySVnMfQITx9 SsqxEJc52dagsYSrP+0plPGlZm4gfEYhczQ8N1bSdjSR2dcqaLwAbBHWl8KhsgGHNqHm dZAv4Pp0Dk2drnzaz2NLHkXLr3ytvK61CHs+zohXjSwEtg59XbEQ8qS2vM6NZ07JRitn bkoXQgO5/zfRbqjRLrkwUlDz2i+p073WbPfn9qlSVBqW+O+PZVt/C4MFACsHx6ReUgpr 7e8w== 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=ckeW8jTWeKJgI6kvzuGkGwJ8L7Ia7XQ201Bb32/C+tnWXZQ91c0o8LxwFbyA5+STev duHg5vTyOX1sXbdT8ZbWF483UEXvS84mEW/qDcmDaCCcKb3MQt1Gq/mHHnOKDth5M50n 3SH7b2X9HHXca2f+daThKowBV7jdpYBMiJLZEco318ZNhYRfl6iVoU6X9pkT+DSX1iyX cfjoYtSS5HBcBNkoC/xA1MI7SAOI5rTrcmJMpphkpUQrLr7ptHoQp5oF4517pHKO1WPH dg7Eh/pfk8nsiQwGazW6RYhs7ZqNsPpNm9akfAaV7XEyT8qc3tk9yBqZyaqeWHG6p6IC Gy1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=UOWVQLAE; 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 sa26-20020a1709076d1a00b0078db1343eedsi1096797ejc.774.2022.11.24.05.57.24; Thu, 24 Nov 2022 05:57: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=UOWVQLAE; 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 S230218AbiKXN5D (ORCPT + 99 others); Thu, 24 Nov 2022 08:57:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbiKXN4f (ORCPT ); Thu, 24 Nov 2022 08:56:35 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4A90109581; Thu, 24 Nov 2022 05:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298170; bh=1jiHlANZ8thD5aPn63BXGYT+VamFBFNIAjBcdG+2s2o=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=UOWVQLAEwRmAhazeSMBLFFnEeZy4gaNKKbQmhUqSmkj6Ds/Ve8rIw9q2g/zYhgyS4 073XagHy1yL/rfdAnUv7rCaphbUI7buTJJQWBFr/+wjFBL0IGjG/vC/WwoHsNxDH7a IwMxByKnRINLR1UX/1aoCR6xfAtkAtvYxIFSAdX54CMYfF1qVQqe30y0u/1JPjNOBT h1OSSuf1GrbwBERkRaMAREm82q6wx3mKvQdIejQyuxyyKwtsL5chZexwF+HNYEvvHA ShZBo1Z2+XrNENaTX2Nts2UX0b0FdKTr1R8CVpsoO4g/JTxsuvl73DnsJPlYRrrSBz B0znFO4OCbJ0g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M7b2d-1oqDQ72fZF-0081Ir; Thu, 24 Nov 2022 14:56:10 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 02/14] tpm, tpm_tis: Claim locality before writing TPM_INT_ENABLE register Date: Thu, 24 Nov 2022 14:55:26 +0100 Message-Id: <20221124135538.31020-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:DZ1Si0DEmG0L5zHqGquL0G/lLXvo4a2ppnyqcfrgWJfcYCf7Evj S3kJKA7ORN7oi5wckuLKqgRyKtpzDQGPPW+gaaxPTAY/62eZs2hEzMb+LktxX5jXaPLZT7W 4UsVNmm3BRmeZIBJvlTodcp32nv9qgYVmr4gNEhMO7lXPO288X73suCMIwKiacAY/U5o+kh zPPJe5zd2kaImK7yWj7JQ== UI-OutboundReport: notjunk:1;M01:P0:+7AxXzLltVk=;pdVShctUccjd2fZJI04dQxP2BEN zjUxWppz68TTq2Cz61wHDjPFHD4XPz55tfD3UG72J3zU77dHfFGT+dRUwtk8G1HuLFGCtwdxv rnDwaBtx8+v/d9YRMH2yIavLhYVwyz79yreWrcHLjbhl217evFjHK2TPnfIb2iygOKTwbSqB3 gIjAWOctPSohtyq7UZTc+aIKvbkz4ka8JhiolhwPltFnS14+0R9FalLo6c4AHztfDirVPPP+q 3XKPa7L2TcL7RzzOsgBz5STmXEfgczQkl+GoxEaAsYbCDe+kJEdYXPpfsrRVDGb6s9ZdKjuvf dUY9/r+X7vvpfNN3bdFGaDuf9UXnD8QW2ombbj54EJRmdIhUefS0XQb4kL1N9F3eTal9VvGYh ao/RdyrE8U29s5yMOpEUZcGkLMvYnouTb/6CsxRpMEzbpPsL4QgEzhIwiqWkzCUwrnWYeQv/P 87cVWPoRW8m5cf1Laionh8QUl3jg1Ns9Jlqd/50FxP60nTv6I1NWiNexDZLT2Fk1tzZWuI3ev 3Z9PXh6GwfFvtkLTl0/ivZYqhOXWf4R26xRYNPNliZxdR65NCga85Sf5M7cVszBOoEIJbG/SJ /0/ANPdT4V/f49NCoYUfK4MDqqOQCLwAdMmrtxPuVKyDCxokyOJQtbayCcP17wFGnkGUiCClq Gbu23jugtQzzfPcOqs6YKarckYAzQVtLgldOhu+21u6bny5Z7I5FH22ykDwyLcpABdPuzHd2C TQnyaQvtTIcitTNeLnNCzmqbguAiDt4kCy4D5dZ42tKc3NCWZj+diZLHB/tJYpLEL5eirqHIJ 1I/trltoN1ki/n1CTSX1nAXgHtBdPAWOcav2G09awz/owNnaswUcTDVBkZ3GvyRJHp6xw4u31 2/+M63ZIFK1MCWe8xYE3n/Uc4IMb1cOjfCPcWFmwgkMzZh9z2arIynj7UvqKgjXVdJPVe8mdx 3UG0DA== 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, 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?1750386101024984048?= X-GMAIL-MSGID: =?utf-8?q?1750386101024984048?= From: Lino Sanfilippo In disable_interrupts() the TPM_GLOBAL_INT_ENABLE bit is unset in the TPM_INT_ENABLE register to shut the interrupts off. However modifying the register is only possible with a held locality. So claim the locality before disable_interrupts() is called. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index c0008efb95dc..d2c9c9d76893 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1098,7 +1098,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; disable_interrupts(chip); + release_locality(chip, 0); } } else { tpm_tis_probe_irq(chip, intmask); From patchwork Thu Nov 24 13:55:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3411044wrr; Thu, 24 Nov 2022 05:58:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Q7np7uLuNM0F/QtHudcmDvGBkhr86X9Yj7FI73YIanGGdERZyDwiTQ3VW/yd1LqHtrQoR X-Received: by 2002:a17:906:8252:b0:7b8:3098:a067 with SMTP id f18-20020a170906825200b007b83098a067mr11569659ejx.701.1669298305191; Thu, 24 Nov 2022 05:58:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298305; cv=none; d=google.com; s=arc-20160816; b=HXWvE90ixEwZVXevOBRI/5fMLkA7fiUbMsOqfmKSjMyA4MA6IORplpABkxchOY9H6U lw6YBSzxOMENLIEawU9wwykVwka5MfBd+/3+1FWJdhSpvq5SWnoaiu+V4pAK0i4KuLYt +b33m/fhTbWQ7RGoJMqWa594zhyNCL+Qa65SMZDDstPU7BHeUZvoHa5Q3UTizvBexENK cfPgzVkAslTbl1xT5F6TJg0ctYV4YOBcwXC//k2RCfRiM/rshoyeCO9iva+6BbpcpCJC dU65iUcQ4rH4tmTXI6Ai/SENceCFWZcWg3Qpcz+7SteqqKnzronYizraotWxbIl40wUd 7Xaw== 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=QbVHEvJiJVGYGx46mstvZi9xmTA4xQdkonXDt5Pv7IPG1OhBBThH6C1PPPanZT50ZV f9XfhEWeDMK3cEisXlSFyaM9NXjP7M1M9VO3xXIu7GcODM4VJAsGC2wTFuXG4IEwkEVa DMhpkEznKxSZV73XkAVKgpEFuzLWAzVvn+treUJIAjDAcB/1wO9OCBZ7HZbj0nmDupN/ wkFehYN1BLKFci24/kXocAiUlD5oBxm+RrnveFWGqQUBDF69XYug2wqDKZnSO9zC6LJ9 BRLp4tQK7V4s5Zji7AQoh38BSsnPqg60YJ+7ALO1vhHdNqt0VttEhRleWhivnVYvWZA3 zIfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=aeYWtnKX; 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 dn3-20020a17090794c300b0078de4629958si1057881ejc.248.2022.11.24.05.58.01; Thu, 24 Nov 2022 05:58:25 -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=aeYWtnKX; 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 S230246AbiKXN5M (ORCPT + 99 others); Thu, 24 Nov 2022 08:57:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230127AbiKXN4g (ORCPT ); Thu, 24 Nov 2022 08:56:36 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B23ED116046; Thu, 24 Nov 2022 05:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298171; bh=vmr8i0HILdqGMwVhgOxfm//3j+C4M5iWtBnT+hrsrRw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=aeYWtnKXEc4nQzzb3bzdwrlz7OJzg4yLtj9IudBGnc9B+VDwKYdPnvW+V0kU78oFU VEX7a2ngjwnJc8Nop4ZG8m+DlbdsQAdv3QQLY3MrMRIReB1z6kSmG+msV8QGqN3xmO dugS+OIT6BYcl1FQQC9a2AvGkWM8v+xNaf65IHBcWHiyANnmo4TgrbFAJNXThXMCKB hmwOe1eVxr8u4YjM4NdfpEeHhzUBQ1gDIpZ9K0i5FXGd4nkfoOKFZBRCdZzfaPu8us BWLp9H78rm2TGSwuAUvTIbtBmB/qPOIOGoKr0CyK+4PrVkFJPqak1mHSL1kpl+hVzU mMWJZdBrGqy3Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MCsU6-1opN0M3yoi-008p3Y; Thu, 24 Nov 2022 14:56:11 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 03/14] tpm, tpm_tis: Disable interrupts if tpm_tis_probe_irq() failed Date: Thu, 24 Nov 2022 14:55:27 +0100 Message-Id: <20221124135538.31020-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:J4RfakH6lXbtsfGkrYwY7v5IByUOUdOvSQVf5Cc74pzRKb//+s1 uZCUlng01wMqRHxrd+8wsIdck8EFmK1mC/4hRDdvpb1HEj5oTC0n/V/RAITCJ8aIti8Kc0U OUDsMtfeL4iTStHyzP/FJSyjn78+465o/f2JWjxk6frWbS4dHIMpaJGZw1eMyzAoj0PX6ry 0jkVPHrN7ywsh+wlw2hPA== UI-OutboundReport: notjunk:1;M01:P0:ltTGGu0PJSg=;eIk+5LoGT7XTQjLpNW0DUWjp2Nw jzA33pBS5udjjETZrAL1VKho2FxCsHpjafOJCSzQqtASCj1sPzfWY7SVLGHJ0RhjZxe7BS1yE luJYLg2ZhhNWkudEskl1oUco6ChPSnxWtb5YXeFYAIi518ibB/AUplrlaAJDWa1j269vj6FIS M/GDvDsQP8KjsG1lUv0OfheHfrwtATphwZlDJ0L3LN1l/M2plYNvAfsR6xzDPOWNse89H3L3U x5ANK/79jk1M8Za3Zwbq6yl9QVx0PvdDbNqPwd1BiUEGuqtaFmeJ2J1Bgv/Lquhhv4tsjgB/o h/f0n4s8MoB+ZFJp8q+06E+r76SIyIt54kG4fQefccmo3mfd4YDtzI/QSMrOYvRJTc2xIdhXr x1XUTpwzvjx6TSeicWwq+Sl8/dirjGZeU4ASnyGyJNtJIgf+tHnuC0Hp752QZZDlK3WKbRAnT cLiZ9Rd2uD1E+iIZ1tyvg0EuLLZpycGw4GDlesevlRE4KtlYxvtIfYlaFLzrZGDR5XMYxorm+ b+TJzCdFtZPhxiW/XcRDIC9X0Terwy6khKZfEY2TUNGbqMd/LS4c3t9UL3+0bkr79eYFhJsn9 Qau2u40jUFQRpcXP1aJTZHsDDA0zwJC6rnM7pNJoXqcG+nSDT+5GnAfQFj+1AtyaKpkH1y/ux TXCNyrn80Qa854T7lC9joaYgPCGWvP1HMO6rtMAyp08TItH+Fbb/NonfqQBRPrFvAOvOEkzdl RCRdQ8X6RKyuPwMYfBdSAGXwHTH6+imoj3askaOHNdNgZ7zy5VptV+VpKOkN1qPwnMFyzwv+j s6Jnfw28NLUnMvVAXAq86iV1LX7gX+Jk8vTzYn6K1M4N1Y1QLTi+sozsA7MDuZmH4DYuzBdiO ZsYsVfYOWZujCFBuOa044k7d5ONle9uRKwzEafHBWMP1oBa2PZDQXRlpHkAHgk0up2paYkNIf RoY+Fw== 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?1750386139953154114?= X-GMAIL-MSGID: =?utf-8?q?1750386139953154114?= From: Lino Sanfilippo Both functions tpm_tis_probe_irq_single() and tpm_tis_probe_irq() may setup the interrupts and then return with an error. This case is indicated by a missing TPM_CHIP_FLAG_IRQ flag in chip->flags. Currently the interrupt setup is only undone if tpm_tis_probe_irq_single() fails. Undo the setup also if tpm_tis_probe_irq() fails. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index d2c9c9d76893..603b82ca56da 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1091,21 +1091,21 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - if (irq) { + if (irq) tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED, irq); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - dev_err(&chip->dev, FW_BUG + else + tpm_tis_probe_irq(chip, intmask); + + if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - rc = request_locality(chip, 0); - if (rc < 0) - goto out_err; - disable_interrupts(chip); - release_locality(chip, 0); - } - } else { - tpm_tis_probe_irq(chip, intmask); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; + disable_interrupts(chip); + release_locality(chip, 0); } } From patchwork Thu Nov 24 13:55:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410856wrr; Thu, 24 Nov 2022 05:58:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf6WjXF29+zGUl7neOYeqObnBKyIFaOwk+dfEOwjzHXcd41casyV/81rUKO5VAA8dvXnANVU X-Received: by 2002:a17:906:1713:b0:7a3:fc74:7fb4 with SMTP id c19-20020a170906171300b007a3fc747fb4mr28991650eje.17.1669298281247; Thu, 24 Nov 2022 05:58:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298281; cv=none; d=google.com; s=arc-20160816; b=RG3G2KZ/oB6MbDWHKnep34WeOytHitBazUDj02drQG3DmGqyYqErqq3qoJFpNIPprZ qfSaxur3py+dTI/ZsOdkvLrREdxcqM4KslHxZH19A4z8JR84+/FB350JSq5Ah83JVCLn 6F2+Zt8iTKZAcvkoHLa1RvjOAJa/2VgLnBXPkfeo8Bf+Cpen4XnzMMbW3ZGjqNC0f9LU s70ObmQL3zHxAGHYNnroeJsG9yl3Ej/9sM7DRemgGMoL3QuERL3TJZGkNvmOIZxBZZnm p/gbjK2fo9dHj/fuaKk9yTvBSk080GdCEB6epAk4MkhajWRqBWtsRHGYmsh1zyXxG7C9 kacQ== 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=ptF3+UGs4RT73xf2t1eIkj3kEEU2mVqh+94Ww0mBJ/Y=; b=Cv6Jxnn3HF4H5EOXK/3HtpIUUc6ZCPFz/z+ogTHTnbU7qKD4f4njyV8NGDUoB+9PC9 Vc2FsLW9lOr9WCqDQs7exnMM1/fdo0liy3KGdn3Fn+dQ/cTkB/+xxNfhFCTr4ojeOD6L 3xYx7Lw/yFgzSaJoxKLLjMk04xJ9MGFM07xhuwk7iFZxGajsntbth+bEDE96KLe2iru5 oh57eEADTRTY3buAZNfCJtWFGAXo9LsxDjjmVKCUVSHrVQeI2lciAX58cbvuxnUhaOxM 6rln7hgqoi+fJCOfQSSiXGRiusFo7O1ojJW5CHTiaoJbkaHlwpipIqwajz+I0RWcCeLm qBHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=AnW4r+Os; 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 by4-20020a0564021b0400b0045be16903d0si969454edb.310.2022.11.24.05.57.37; Thu, 24 Nov 2022 05:58:01 -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=AnW4r+Os; 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 S230233AbiKXN5J (ORCPT + 99 others); Thu, 24 Nov 2022 08:57:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230121AbiKXN4g (ORCPT ); Thu, 24 Nov 2022 08:56:36 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 959531144A0; Thu, 24 Nov 2022 05:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298171; bh=ptF3+UGs4RT73xf2t1eIkj3kEEU2mVqh+94Ww0mBJ/Y=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=AnW4r+OsnxZ+EYbiLrZC1GEfrkwBMKkGjVbunHu9MVuFBEg8tJv4TkeXrSLD8HVib 2pL4ZWpLDB/eD/XjdwtKOR9haHd/ygJ6ThKqgy9/vfglCvO6Pbo1kuqmRc0bZj3mQY /f8di0hXImAOFVtsTfmQx+PYBCWY2sP79gtebkLS9Z4HuOd91+qjJX3OJKePk60qeQ l8hDjg7fSqtIjxHmL9x1u2WHIQXjKaouDYKWr11xC6htp67F/b/morily0q26F37N9 RYQ40TQZ6JMYnsIVae5hINasFXYcMTIQYx0F+Yxz/OBSLs/U80QpK6RTlJydrAY71c /6JnRskhZrXug== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MjS9I-1pLxfF1RgQ-00kulG; Thu, 24 Nov 2022 14:56:11 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 04/14] tpm, tpm_tis: Do not skip reset of original interrupt vector Date: Thu, 24 Nov 2022 14:55:28 +0100 Message-Id: <20221124135538.31020-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xa3nABt20tkSDNQZTlmJqGyJFMR+Hbk/kMbprAIaZ7AODF6LfDJ Ga0c6+Iat/fGjI8FJXKlN6Y9C2aNPvUmcmx5LzMenvb2JTFxXVDHdC6ureaQ7UKKFobQMW7 XZbwotp3OCfIyfy9i35yO3DFlo9WhGXR1BKBPiDVYPyWupMdSJaUjIlU3aMBqdP2chOexIU kCDWZSOL7frbQ5qM+piSg== UI-OutboundReport: notjunk:1;M01:P0:2Hr5OHt1gBo=;NUhu4G4cDfH7sTC3pjO8cBUfk7h tZCb0PHuDXpJsMonJd/CvI5LHnzBltvRtPHblBrRTMe5zFPGZSBmlWjqTefk1dH/wNHET60lr MrAaRG4l1xqlw+AEztk4wr1UoiS6tI2dwXuae9XpRuOE3eZVLYJ2J0O86eHVn1ZZBQ6tmQPJ0 Ge7zmvA0ZYoWmruFXMO7b8+rIhuMzo1aXOvI8IIHY0jLKvemekT3PSHPNOzntqA3SwPG+7lUc mVX+T0njRTLcGoWJSiuJFFH4RJrCgwST+L0/cINzUydQbzfJbN1YfpstXTvd8FE9NeHEhbqaI bkG7d8K7NKmauHaF+dZ1tSDhMsn1Qt2zCcNRZgXZ0NcN75qE8OR9x35gWfmKgAA3snMok0kl4 fPJinvr5oX6R/ZrNrqJ7sU0B3xbNsAnzneaCcHxCdTR2jO5VMiXN6U3PG6xjxlUwprDeXoNE4 FUZMvVyz90wGq+t0BSgnjFgMPIHh3oJChdWNRrghoX3GjFFEFqVvEAUJGGbPqnptk5dfkiirr RNdt/t65fxSfRF+HhsZqF8x3SYQMfD24J7pfbAOihuafH3q3z5le9d+juhl/puqHxTjG5QOqb 4hpAjCxlS/ELD80617vknBZlTnXp/49vAQfqJVjEKRx5kFiYHZIC+HMUnWJZd8RkWGTpuhHWD bLfwdAKSTe26fFaf449kTB6P+D080NwhGsgde3udeqt3o/H5V2wbiL0MHDmgxOkCu2nrpSGZG B5UwJmzvN47wxJWSOMXE0mcxWjPENKu/8C57BAXYUCL1XHBrlWi5zZC47PqWil4BLb6Q76cKs hg2Jbw47bupIuN4sC9OOsHMJiCZkdw9Z1qfqqNTbQROvsUxxA86weCLHZ+T9xA1Uo5gOa8ARg vMuYmSUIxQaxA1qjmg1zDKADcCxzIxg397Ivy4DzgSzzACqQg73a84aE1+/+NVZM2ZNaz8NvS OmIYpA== 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?1750386114490977339?= X-GMAIL-MSGID: =?utf-8?q?1750386114490977339?= From: Lino Sanfilippo If in tpm_tis_probe_irq_single() an error occurs after the original interrupt vector has been read, restore the interrupts before the error is returned. Since the caller does not check the error value, return -1 in any case that the TPM_CHIP_FLAG_IRQ flag is not set. Since the return value of function tpm_tis_gen_interrupt() is not longer used, make it a void function. Fixes: 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for TPM access") Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 603b82ca56da..81b9726d3ed2 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -729,7 +729,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) return IRQ_HANDLED; } -static int tpm_tis_gen_interrupt(struct tpm_chip *chip) +static void tpm_tis_gen_interrupt(struct tpm_chip *chip) { const char *desc = "attempting to generate an interrupt"; u32 cap2; @@ -738,7 +738,7 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) ret = request_locality(chip, 0); if (ret < 0) - return ret; + return; if (chip->flags & TPM_CHIP_FLAG_TPM2) ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); @@ -746,8 +746,6 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); release_locality(chip, 0); - - return ret; } /* Register the IRQ and issue a command that will cause an interrupt. If an @@ -777,42 +775,37 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); if (rc < 0) - return rc; + goto restore_irqs; rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); if (rc < 0) - return rc; + goto restore_irqs; /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); if (rc < 0) - return rc; - + goto restore_irqs; /* Turn on */ rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); if (rc < 0) - return rc; + goto restore_irqs; clear_bit(TPM_TIS_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to * tpm_tis_send */ - rc = tpm_tis_gen_interrupt(chip); - if (rc < 0) - return rc; + tpm_tis_gen_interrupt(chip); +restore_irqs: /* tpm_tis_send will either confirm the interrupt is working or it * will call disable_irq which undoes all of the above. */ if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - rc = tpm_tis_write8(priv, original_int_vec, - TPM_INT_VECTOR(priv->locality)); - if (rc < 0) - return rc; - - return 1; + tpm_tis_write8(priv, original_int_vec, + TPM_INT_VECTOR(priv->locality)); + return -1; } return 0; From patchwork Thu Nov 24 13:55:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3411053wrr; Thu, 24 Nov 2022 05:58:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf6AELj5OA+2uy1lk5neCnfMhyNIv0uWzMMRu9/8D1EfvJfjlBLjiEBm359M7Qk9vVjNb9CE X-Received: by 2002:a17:906:64e:b0:7b7:c1b9:8cb4 with SMTP id t14-20020a170906064e00b007b7c1b98cb4mr13082896ejb.96.1669298305662; Thu, 24 Nov 2022 05:58:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298305; cv=none; d=google.com; s=arc-20160816; b=nulpELpYMGZH7p3qONe58N7NA7GQFna4+PsreM0WIaHY8wfMYNjELHYkhnSgJESoaq 0/6oTUvyGNCRHIbbjEKn/9CW0hjOc55TnmjTv5Z7de91zVS/y3qqmKIHzSp+aI7o6Nez gJvTugvQBCwGQe8dRCrYZvLXX+2FR9HiBtrGJ8Y45tpMrG0lfqm5R8EG6vR3FVcilBxR QXBH1z4zxbSUs49EzGg9Bg8M5Fuh26tJHTO9eC/EHu7IG2iotcMoYKLQx82iUTadkjRq Fr1XmPhE3MctwILOiBFZTVeXbPEAulN3o/XILWN3ydO0PNeO3W6S+dFZMyS5J00wRQ57 R/dA== 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=nfj6LxEEakS1d9oZm1Vln0mVngkSUD4WhjDUy9R8goU=; b=08KvaMStT0/W4rPrBlqWNJeyuGyO9T/15THw/iYVXZ0wefxDj0mZie2O/5cj0Dou+h oSJsBRTtVN/GD0D60UX5GchEHQ09EGasn+y4DCfMqV1yNkG6LhWgiaW2vPW5W98r2t42 yOk1VcI31S0d7OpSE5bL51We7aUD4BCQMxXgpVrdZactYXOYFb9rptiiAnWYwtnO6ZgU gEgDbNFG9gFBC4o5Xe/D5qUZIk0eHB8sMUlfbLb4+1VfuxQrCrgW58FOelmZ5sgjO+ea WL6Td8PnT8g7JeUtw9x/86ir2RtPA4d7VdNkDtITqGZQmBm5831TN4J0pCpu9+G9z8MQ DlTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=SIpKaQvo; 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 wz2-20020a170906fe4200b0078e176ef65csi843898ejb.723.2022.11.24.05.58.02; Thu, 24 Nov 2022 05:58:25 -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=SIpKaQvo; 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 S230319AbiKXN5P (ORCPT + 99 others); Thu, 24 Nov 2022 08:57:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbiKXN4g (ORCPT ); Thu, 24 Nov 2022 08:56:36 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75CE11604C; Thu, 24 Nov 2022 05:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298171; bh=nfj6LxEEakS1d9oZm1Vln0mVngkSUD4WhjDUy9R8goU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=SIpKaQvo39+/4NrHUTAzIjtNS5X9hGHJXHnX2qgwSeaYMSlJAWLIEIOrpYEZJ5YJb B0FJwZQ6RQrFs2+hPoNhUklaYNeB+c+bHvNV/20JwkWh3cr1XpvJme9DSfu9WDBgiZ AYOnCW2Nte1anJo7A70I0jbPaI0gIS4wOcGbfuyCLvNBHwCgmXLvJQ7694NghaNXt9 KjrCrIwLFuYGHuXZdVXm9Zz5jNnla+R2GMK3sYObxu0LszAQqUkVx9JjcbZLP0uo8U SVXp280OBqTY5qX+yrhhefftRzbsp6nAjJ8pwSucyofUNTAGwhEdvxUN5P7HV6fEZo A12ltdQolCm3g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mjj8D-1pLgY42t7j-00lBsR; Thu, 24 Nov 2022 14:56:11 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 05/14] tpm, tpm_tis: Claim locality before writing interrupt registers Date: Thu, 24 Nov 2022 14:55:29 +0100 Message-Id: <20221124135538.31020-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:VB7psXmoZkW0IM+pjguIbLL50aHa+0ppnyDiamI4IevQAzorTbS DN1FMlxqHjwgFCmjNlcT78/3720y6XYjrRdytKbwNyd144yREiDnpOfPqeUEm0EIJQDZjGp tEY69lnVO+hH7TRvSapOJ6ScMoYrJ5h+pBUw/wKv/wO4H1LxHxMqeP1ht+jq7PInvG+ddyV 3yK5Qmy5ivPI8+G76VBPA== UI-OutboundReport: notjunk:1;M01:P0:HR9zpvCBO74=;u5PMihDoYh3FpZMRJEm9ZrHdye6 1SNHWZzEn+F0ZHl2nXdF8XG0FN+EbfqlIb8rCY3GUf2RXY2kvY5bxJo6/5XOpopibay6itEoz xhrKNV4nIB48OfkcZzLDjKuoR+vcQ5AFjn7LBpcvoHsfV13GdUraeCE/bPQ7H6hjqGWvEyPKw eX2YryeXpKPDaGoC/4QJgpUN63LNf/PddP1CAJjnZ9hc7moa6J8uonaAcs3cqpLRsxcE78YI/ 6L/+QtrCgQpChjWP9TODeOQX65QExUgwEOAL84CKCn6BPpriCMl/ToqMj/zGUOLrs0nL3SZOo 8YJc9VcbCGoiyT/x1gPRRFRqftFNAxS5fkWeNoWC5HIt2OQbJujvgz9MGDLAqK/CUN9tYcKIp jK1j9mTg9omWDmnttzGcWaPW2qJmne/VPubOIaX1OHTiS/cjXX8ImSz5WP5Pe05sVhMZA/vvB vTFked3bgOXobgiPm7o4BXcSwtTMKokJ1BOVGoyMTWccmccl0ysqFHSNVTbYmV8hMjpoSeZm7 XPcQh5ug9TX1vdtBE4DOh1fx1GGwGADRT1oaYZr3JS+nlugIz/aP4tSnLuIKscWYLzuI0jH69 zMxdjlR5IA5pNOp1wjdXBG+n4U4OwOEgAL6oM6o3hRkfJrxYwY6CRPuAY9ZTFK7+3nggpTgw1 z65G4KJiV5Q+ejVsbUumDicWvn+JPyxeKYYLSu9QCGzmztoPUS4msyJKM5shswK3ZuIeL8SF8 hpsgFRA6bS4BbThyZ7k61tZb6w+c0mGimoLZEQ20WmU6YdXBZ7kQB+aL8al4ET5f6+in/wtKn Z+Rqo4wf4z5Rd7tFlfobyQM63xai5jf6t23bZjMYvBY/jKZw2yLJ1ONWUVqjNQfj5p3x4If7x 3M1b8oZqBUUUt3e/yauhsJsqo0atO3Ql4r/feU7yc5R2wOKJsZiD/Evi5UpjkHbKBJ9sh11IQ Az97XcDFLwnor90Ro5xyscPImiM= 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?1750386140208164123?= X-GMAIL-MSGID: =?utf-8?q?1750386140208164123?= From: Lino Sanfilippo In tpm_tis_probe_single_irq() interrupt registers TPM_INT_VECTOR, TPM_INT_STATUS and TPM_INT_ENABLE are modified to setup the interrupts. Currently these modifications are done without holding a locality thus they have no effect. Fix this by claiming the (default) locality before the registers are written. Since now tpm_tis_gen_interrupt() is called with the locality already claimed remove locality request and release from this function. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 81b9726d3ed2..49848268f547 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -736,16 +736,10 @@ static void tpm_tis_gen_interrupt(struct tpm_chip *chip) cap_t cap; int ret; - ret = request_locality(chip, 0); - if (ret < 0) - return; - if (chip->flags & TPM_CHIP_FLAG_TPM2) ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); - - release_locality(chip, 0); } /* Register the IRQ and issue a command that will cause an interrupt. If an @@ -768,10 +762,16 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, } priv->irq = irq; + rc = request_locality(chip, 0); + if (rc < 0) + return rc; + rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); if (rc < 0) @@ -805,10 +805,12 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { tpm_tis_write8(priv, original_int_vec, TPM_INT_VECTOR(priv->locality)); - return -1; + rc = -1; } - return 0; + release_locality(chip, priv->locality); + + return rc; } /* Try to find the IRQ the TPM is using. This is for legacy x86 systems that From patchwork Thu Nov 24 13:55:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25541 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410650wrr; Thu, 24 Nov 2022 05:57:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf5lN2+wl58HwmuZ2aKLLlTBBg+XCACNzrT3Jy3tj5Txring3wLUxq0Oib8v5gY/8lBUhVmS X-Received: by 2002:a05:6402:cf:b0:458:a1bb:4c9a with SMTP id i15-20020a05640200cf00b00458a1bb4c9amr30495089edu.121.1669298253732; Thu, 24 Nov 2022 05:57:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298253; cv=none; d=google.com; s=arc-20160816; b=cl+EnEbK1f+BJvzeBkcrDjKDoF+y/UsRdJ0WU3watJ/FLgvqeUZzdbiPoGvWKFALQH KBNnpIfrrg/tfw0Gz55y/hVcOmcEwMpjl2hkk/Ls/PMhsbahZEcapyC833PqoSc5tP/P FZDoQMnkTV3Wfkh74D47N1n7jRQlW/Up2srXGub7wetWmVbYVp86pC5JC9NY9zpboXN+ co28qO6u+5RfRJdwmOpIyYnufuA4Mhs0XxteNwk1GhWGt7j6WXOVGylP54gbdbXaMqI1 2G4D6oihrtJkC1/aOrUXncoq76EwSuNxmRz5VDTWueW+k+HTKvMyS6kOR4hn5vEJW15B zt/g== 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=/LIepLLbPWcHWTum88qdQFhReQDSW470FeNeEDgXBaE=; b=dajmayULypPqHaBshHwGqz+971YUMiG7TdiROC7GUSOleRugs7tej6LxACfEmVcTid y4SMJWcLHsZVPhDGvnT4gj6Gn5Ttoi5SKBFEGNKROo2v3+PwU0epe7tEYVczsV7YFgSH KantAhJnuJleTekukMTaWnxUgm4+1g9Sy5BT9YD7Ea3l0Hj3lsx1qJ8p2Q54+qfE0uNu Ck9W0BbQmZKCSnDcAkoTFvlBwB74+aAQ8cMAey0oSrMXyEA8gMRuYKyK+lWEH5UWa1nt kyGbbKYMYx8c2S1uDczM6/e0lY/n/O5JYwpn9V1bkdhMF3Y3wouwgEwVA8ARLV5ewjt+ 8jJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=BGJc5p5j; 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 xa3-20020a170906fd8300b00791a3dd01b6si914769ejb.864.2022.11.24.05.57.10; Thu, 24 Nov 2022 05:57:33 -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=BGJc5p5j; 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 S230181AbiKXN4v (ORCPT + 99 others); Thu, 24 Nov 2022 08:56:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230003AbiKXN4d (ORCPT ); Thu, 24 Nov 2022 08:56:33 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 934CBF5A1B; Thu, 24 Nov 2022 05:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298172; bh=/LIepLLbPWcHWTum88qdQFhReQDSW470FeNeEDgXBaE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=BGJc5p5j+7qHYahYlcBr4a6uozSb9nhA9r/+Los+6iUOxthJE0sW4fFWw6Le/SO47 Z7tq0OWILZrA+TxuS+w+rMlOp+OX31oG6JY4U26sI0e3KnA72zwT7P0eXEcvRs75pe pljZnhRSTCTpsxpcYHJ5eNT4VDbUmBLuKqAQipaJJi0kr38ije+zO0RSHqpxPomkC+ GD9KnnnZ77r1HqOwhPJT84nDcnQr5s1sApqObSG53AtoAJXZP1/t9ZKcnD9dwx8oh5 jPWF43EzAK2gliXbdPQf8EGj7um+QdLDdVDnZm5pcse7dFZFI3wNO0MPoYUYdypkk/ ka5LDy70uVbBw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MNKm0-1oZNME08sc-00Orb8; Thu, 24 Nov 2022 14:56:12 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 06/14] tpm, tpm_tis: Only handle supported interrupts Date: Thu, 24 Nov 2022 14:55:30 +0100 Message-Id: <20221124135538.31020-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:67o+5BRMDYtidqREBdNHB+oywrFTm9p0D+fHxBUOOEXWbXOiKO3 P2ExBY73eaQFFm5PkSstT+ezw8gxHLZbmrkgiOfbOVMXS7WFlsNOQufRUjx29141gVbAvwf Nw0FZGM3AXYkIwysp2UrwSoFTBrtsOVPDY0maiVwx5EyhcKBy7q8+w7CSN84LcD36XJCqG7 HlehynnNh7p5NDYU87laQ== UI-OutboundReport: notjunk:1;M01:P0:vpdU4kdjoPI=;8Ksw9yPGaSp+fNnK40CiYbdyZIc biz+cVRG3NvqFlGWCrVg6blB0bu+ocByBpc4jlpRDTBDb5lChp5SmpQc58o+npk1N7i4hlcf9 +T48J734dIW2ed6mY0c2DNjoROvY1IS0USnba5ohw6/Dhnx0FDzECgugkG13j9s1FIUPy8+hg 6c0/gnZO1lFwtQZAyhcetH6rzSIJmwQoRs5EJUcrPkBMFH5F7rO7tQPjxpE7FCgIhxK41r/Cn WeSDVdE+lfki1zd1e+SP2DXQQuxckd1GIoBaygp2PhFq5ymYNVJC+SyMwu73KPWI4zZm3bOO1 vIJDyrvAkXXDoO7H1+bgTmjargfn/zwAatGu7S9yStSoJCkcngjSnu4ajeoZs7ezq6yhbHL9X jdH6KHhxZ7wv135dGdzntQAimz3eBTyETnAElLCy8bewRjFBE7e3I8fdPeIl5PuK3LUGEjEsA JJmUJVNNAzlAyx76j8zDFQN23bnQ5PMuQz8xrKHFOxQieGW0SWgkE8PYhxu4rA09q3x2UAW+m 4rWGEsgWL78J+uCzjl5ETBklNj6LaKbNoZvjF5FANNjnQTQh+uWr8W6iJajBhk67U/7+RQE+v tCEPfAxSLjyQF2TtzakvtEXkOATz1zBY2T8BFN7QtHMhdVbidZhjYj0YlRf69npguFBLaQDhN xmvXkmhzMisDNgxD9HnlQSQfxhFAqbtLpw4bmERPeuu4o+kgl2HPVOXzYCAPqlLwEJfbBMlu/ SeplPkVNuVqT1SCTlurWmMEebqiK6wLuELNE0h5igs5k6vO2o5E7iTJIkBIRsqzgShn3vUGnA uSrVyAr8vg1vvvUOHuQuE0hLe4VRGX25sx7agTajfLWKfJjg1+gffpk+aZGO8iLe0ae/oY7vA FFGmdLDSlKDI1U50WE6usnapllcl8ctp3FVoSHfPIvrJReGWz2RofC1NicC0JCTOph/VIk0x5 NC2AVGCujEpWc/l3K4XxOVgp4ZA= 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?1750386085795931348?= X-GMAIL-MSGID: =?utf-8?q?1750386085795931348?= From: Lino Sanfilippo According to the TPM Interface Specification (TIS) support for "stsValid" and "commandReady" interrupts is only optional. This has to be taken into account when handling the interrupts in functions like wait_for_tpm_stat(). To determine the supported interrupts use the capability query. Also adjust wait_for_tpm_stat() to only wait for interrupt reported status changes. After that process all the remaining status changes by polling the status register. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 120 +++++++++++++++++++------------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 73 insertions(+), 48 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 49848268f547..2694b1bb77de 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -53,41 +53,63 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, long rc; u8 status; bool canceled = false; + u8 sts_mask = 0; + int ret = 0; /* check current status */ status = chip->ops->status(chip); if ((status & mask) == mask) return 0; - stop = jiffies + timeout; + /* check what status changes can be handled by irqs */ + if (priv->int_mask & TPM_INTF_STS_VALID_INT) + sts_mask |= TPM_STS_VALID; - if (chip->flags & TPM_CHIP_FLAG_IRQ) { + if (priv->int_mask & TPM_INTF_DATA_AVAIL_INT) + sts_mask |= TPM_STS_DATA_AVAIL; + + if (priv->int_mask & TPM_INTF_CMD_READY_INT) + sts_mask |= TPM_STS_COMMAND_READY; + + sts_mask &= mask; + + stop = jiffies + timeout; + /* process status changes with irq support */ + if (sts_mask) { + ret = -ETIME; again: timeout = stop - jiffies; if ((long)timeout <= 0) return -ETIME; rc = wait_event_interruptible_timeout(*queue, - wait_for_tpm_stat_cond(chip, mask, check_cancel, + wait_for_tpm_stat_cond(chip, sts_mask, check_cancel, &canceled), timeout); if (rc > 0) { if (canceled) return -ECANCELED; - return 0; + ret = 0; } if (rc == -ERESTARTSYS && freezing(current)) { clear_thread_flag(TIF_SIGPENDING); goto again; } - } else { - do { - usleep_range(priv->timeout_min, - priv->timeout_max); - status = chip->ops->status(chip); - if ((status & mask) == mask) - return 0; - } while (time_before(jiffies, stop)); } + + if (ret) + return ret; + + mask &= ~sts_mask; + if (!mask) /* all done */ + return 0; + /* process status changes without irq support */ + do { + status = chip->ops->status(chip); + if ((status & mask) == mask) + return 0; + usleep_range(priv->timeout_min, + priv->timeout_max); + } while (time_before(jiffies, stop)); return -ETIME; } @@ -1001,8 +1023,40 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, if (rc < 0) goto out_err; - intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT | - TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT; + /* Figure out the capabilities */ + rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); + if (rc < 0) + goto out_err; + + dev_dbg(dev, "TPM interface capabilities (0x%x):\n", + intfcaps); + if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) + dev_dbg(dev, "\tBurst Count Static\n"); + if (intfcaps & TPM_INTF_CMD_READY_INT) { + intmask |= TPM_INTF_CMD_READY_INT; + dev_dbg(dev, "\tCommand Ready Int Support\n"); + } + if (intfcaps & TPM_INTF_INT_EDGE_FALLING) + dev_dbg(dev, "\tInterrupt Edge Falling\n"); + if (intfcaps & TPM_INTF_INT_EDGE_RISING) + dev_dbg(dev, "\tInterrupt Edge Rising\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_LOW) + dev_dbg(dev, "\tInterrupt Level Low\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) + dev_dbg(dev, "\tInterrupt Level High\n"); + if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) { + intmask |= TPM_INTF_LOCALITY_CHANGE_INT; + dev_dbg(dev, "\tLocality Change Int Support\n"); + } + if (intfcaps & TPM_INTF_STS_VALID_INT) { + intmask |= TPM_INTF_STS_VALID_INT; + dev_dbg(dev, "\tSts Valid Int Support\n"); + } + if (intfcaps & TPM_INTF_DATA_AVAIL_INT) { + intmask |= TPM_INTF_DATA_AVAIL_INT; + dev_dbg(dev, "\tData Avail Int Support\n"); + } + intmask &= ~TPM_GLOBAL_INT_ENABLE; rc = request_locality(chip, 0); @@ -1036,32 +1090,6 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - /* Figure out the capabilities */ - rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); - if (rc < 0) - goto out_err; - - dev_dbg(dev, "TPM interface capabilities (0x%x):\n", - intfcaps); - if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) - dev_dbg(dev, "\tBurst Count Static\n"); - if (intfcaps & TPM_INTF_CMD_READY_INT) - dev_dbg(dev, "\tCommand Ready Int Support\n"); - if (intfcaps & TPM_INTF_INT_EDGE_FALLING) - dev_dbg(dev, "\tInterrupt Edge Falling\n"); - if (intfcaps & TPM_INTF_INT_EDGE_RISING) - dev_dbg(dev, "\tInterrupt Edge Rising\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_LOW) - dev_dbg(dev, "\tInterrupt Level Low\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) - dev_dbg(dev, "\tInterrupt Level High\n"); - if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) - dev_dbg(dev, "\tLocality Change Int Support\n"); - if (intfcaps & TPM_INTF_STS_VALID_INT) - dev_dbg(dev, "\tSts Valid Int Support\n"); - if (intfcaps & TPM_INTF_DATA_AVAIL_INT) - dev_dbg(dev, "\tData Avail Int Support\n"); - /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); @@ -1092,7 +1120,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, else tpm_tis_probe_irq(chip, intmask); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + if (chip->flags & TPM_CHIP_FLAG_IRQ) { + priv->int_mask = intmask; + } else { dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); @@ -1139,13 +1169,7 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip) if (rc < 0) goto out; - rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); - if (rc < 0) - goto out; - - intmask |= TPM_INTF_CMD_READY_INT - | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT - | TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE; + intmask = priv->int_mask | TPM_GLOBAL_INT_ENABLE; tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 695a2516dce0..2deef11c88db 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -93,6 +93,7 @@ struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; + unsigned int int_mask; unsigned long flags; void __iomem *ilb_base_addr; u16 clkrun_enabled; From patchwork Thu Nov 24 13:55:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410586wrr; Thu, 24 Nov 2022 05:57:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf62HMApBsrH8CZJS9z040pYoAusnTeKgWCCsyjP7tZM6gGg7WwGoPsYiatNcbtrU/wKtrlS X-Received: by 2002:a17:906:b794:b0:7ae:6450:c620 with SMTP id dt20-20020a170906b79400b007ae6450c620mr11448398ejb.270.1669298246659; Thu, 24 Nov 2022 05:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298246; cv=none; d=google.com; s=arc-20160816; b=MS4ngnDFWOTtbllcF3SN01ichCUI4Xmyvny3ZP0woezyBZAZyIJUx9lWLCxzybM17V gOh97JQhYRG4dqjV+RzOOQzXZUbM/DGKIq69C9u2iGLEhtDGSMcC9X2lCz1+9WAcB0UC euZH6BilkSfuIeDPf0xYrV3dd4dGIF/upNE3Cye48NyPjpaI1lwP6mOho2iKc9QSCGWB 2ch3bulri6hi4b0Um92qvbQaDzYh65btEdBos2/1uv0SUDKlF96URhVVBEHEl+VTJwG/ RwilS4vmPmGu7BJsQSPmWfESDlhxJkdNBYQmlPccsQUxyXBtt38DwKdZelhfYfFkWcti UZnw== 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=acaYZLOzjstSk1ewiw/25/8EH4h8E4f6Mhp7/e/Rz5w=; b=gdp5NEsVN5BvrPbOyzf5E72tCz0Ek8fE84WJQCles+PfJfa+lDhTOi1uQy7Xqg5vsw knSBdsEGuJx3/UG3wRoPboEDCSaH1FvhAU/nhgSAvtyVGUEH0gpwseOAU2hhXGDHpKaz zorVBofhT86nI7YgDkQO54tesjg8Ft2yQgF0bsm3/tVmPNfKKDn1bN7toxoL5dT9o+un qPV2Gl0nzPsWMY/csnx47FxXAP6VaSygJPK4O4787E2C9ciTHxtDksSRslEzzJKkKAXq dsx/Koei0UqyqfT+Bxbj3SN6jpdc+E7Qt+1RT1gr+mdAabmUPTSuHZ6keSQF7eLElMnN rVXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=OaCBfR5N; 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 ga27-20020a1709070c1b00b007ade20fc40csi1020816ejc.810.2022.11.24.05.57.02; Thu, 24 Nov 2022 05:57:26 -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=OaCBfR5N; 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 S230153AbiKXN4k (ORCPT + 99 others); Thu, 24 Nov 2022 08:56:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbiKXN4c (ORCPT ); Thu, 24 Nov 2022 08:56:32 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AB80F8028; Thu, 24 Nov 2022 05:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298172; bh=acaYZLOzjstSk1ewiw/25/8EH4h8E4f6Mhp7/e/Rz5w=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=OaCBfR5NBfypcT1zSMwJD814rZYvvu1zviaK+TZg+laBXbTG99/ckYdVg+29iJCE3 WOZ0QoeyRJingQVkLhacS9qmFt7dFmT/BVS9P2cWDVEVk/JaCSvaGrob/VYOzMMFq/ Pk60gwgGt2+SCROVVFqaddpSrX+d/ACqQR/splHbNENsiX/pCxEdcADcagfC2ud3g8 a28SdMFKfFrp4X71P7cehGUZoHfCbQpR5nsGKXcENqZFMseXEG0U196+NCsXkcIMbm 8543BhEunC6OCN6Ii/qTFk3b6mk4IWY5FHWN6s41qXrTsqlbj3LEw4IxCVDw05zvq8 Bk00eDa6lFtzA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M6Db0-1orazs1YVM-006eG0; Thu, 24 Nov 2022 14:56:12 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 07/14] tpm, tpm_tis: Move interrupt mask checks into own function Date: Thu, 24 Nov 2022 14:55:31 +0100 Message-Id: <20221124135538.31020-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:on5JjKFr/xjl/gz/QEuHuParjIQHmU7ELMmZZwpGlAZEBanrutQ 2DdmYrVPk4MXxqNOEjgNM1o/5202rmsWDop2c4+y1Dd+eAu6B0gEBvosJfuCbNs1QRZu+3V qP3NayH4ShRp4zVTwwcUQUUdFlefi6r2iBYNB/W19rryCjjBBk8hYlZSSFRtvztaMtg1uG0 hGWbAIvKJV3lEse9ay9ww== UI-OutboundReport: notjunk:1;M01:P0:qKA8UB9uP7o=;NJHWReHTds23j2YjqLN53o8czve pO8MMywFusnZoBq752jV++IRjLJ3npvTyinry9nqWvRaxmrIj1ZjrTkFGHztRgaFq6nIoP/Zz 8DeTgGAHaTLgr+VO+rgpBmuKQe/8kv0utfunymD9mFUhU1N6a3oul+HDqWavxCEVWie3H7wqW UvSbpL7PZEkEE1XCxGVJCzzku07N73BMxinTVZWZV/JJYPdUsfT/Mz6dRqMfFhEW9YZ/6NukL 18E0f+PRHZeQu/nkT7T2wFCo9caKtjwqQhGj5x4qZkFkuI2sowKfh/ygkS823SqAR46crAHTp VhdIVEb0w8F9naqRWqwD9wtGCJsadfQBQH4AHB2a4COnjHnxxx/Wf3V/quUzYVXf46uIXSRGW qJo8TkZ6Fhvnv+kOF7RAwG8JVCyq3C5Yc7BosykHuJrsZdPoexaLQRPRer3YGrYXp29kVaHa4 aN4Q5vHy5SmQGf5hEf/FE2kevdzxUBXBf0zdyMnLwWmuylpiQQdHkN1HZfBJveTjSRTd+DMuc fUmkKxLkiOIAambnVlznRKR8WeU6Yd9W6RsfrWKPQvSGwscWiQiWT53OGUbTZIG3SsaF60tf0 adsO+2SXenbr+g8X9O+olynu4D6kWljgjfyoc64tY0KldkoesA3PIbel7I3SsZTwp+zDfb9vR zwG4hPsyWf1d3Q2yPPtj61oQhBMlip8Tck/8cxu1f08FVXA6NnuTFZ499F5fny0/YFHxmcxCA a4DngGmbrZEcpxnGfnrff/CF2MKNxvb/8YsnXUIVtyeZ1hb+X/iFxYacOGKbq9i9nKtLdxm8y KhvcsEoCIGKfCOYQLyQACo7eGFHE0u4fdMeuK5yKGIe/nhsA3HdZSuTwUO7S9bXm4DabGxHHm 9fWkz0hojsmU0vfMjLCSrgkNfWFDc4wIStTkxskzUt0EdNzgs5qWqq4nlDb/rDEwEq2t2Jdgy dU+KeIa1xHjdKS2GFKMVIXadGKs= 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?1750386078044488616?= X-GMAIL-MSGID: =?utf-8?q?1750386078044488616?= From: Lino Sanfilippo Clean up wait_for_tpm_stat() by moving multiple similar interrupt mask checks into an own function. Signed-off-by: Lino Sanfilippo Suggested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 2694b1bb77de..65d1ec7eb4c3 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -44,6 +44,20 @@ static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask, return false; } +static u8 tpm_tis_filter_sts_mask(u8 int_mask, u8 sts_mask) +{ + if (!(int_mask & TPM_INTF_STS_VALID_INT)) + sts_mask &= ~TPM_STS_VALID; + + if (!(int_mask & TPM_INTF_DATA_AVAIL_INT)) + sts_mask &= ~TPM_STS_DATA_AVAIL; + + if (!(int_mask & TPM_INTF_CMD_READY_INT)) + sts_mask &= ~TPM_STS_COMMAND_READY; + + return sts_mask; +} + static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, wait_queue_head_t *queue, bool check_cancel) @@ -53,7 +67,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, long rc; u8 status; bool canceled = false; - u8 sts_mask = 0; + u8 sts_mask; int ret = 0; /* check current status */ @@ -61,17 +75,10 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, if ((status & mask) == mask) return 0; + sts_mask = mask & (TPM_STS_VALID | TPM_STS_DATA_AVAIL | + TPM_STS_COMMAND_READY); /* check what status changes can be handled by irqs */ - if (priv->int_mask & TPM_INTF_STS_VALID_INT) - sts_mask |= TPM_STS_VALID; - - if (priv->int_mask & TPM_INTF_DATA_AVAIL_INT) - sts_mask |= TPM_STS_DATA_AVAIL; - - if (priv->int_mask & TPM_INTF_CMD_READY_INT) - sts_mask |= TPM_STS_COMMAND_READY; - - sts_mask &= mask; + sts_mask = tpm_tis_filter_sts_mask(priv->int_mask, sts_mask); stop = jiffies + timeout; /* process status changes with irq support */ From patchwork Thu Nov 24 13:55:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410492wrr; Thu, 24 Nov 2022 05:57:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf6xf1plcL2fZWIFyesjtSsMiEgYrDxMADeNzDq/RUA6jlG7KU6Od1JcKaJq6SzkIKVFf0I+ X-Received: by 2002:a17:906:6d88:b0:7ad:b86b:3ff with SMTP id h8-20020a1709066d8800b007adb86b03ffmr29008562ejt.448.1669298232417; Thu, 24 Nov 2022 05:57:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298232; cv=none; d=google.com; s=arc-20160816; b=y0xCG5m1KiLezEgeX2GFDLmW76uEGuUM7S85fqIzbrdqivnJ6zA9hXziCCVuHtWiu7 W7BMMHwFr1sX8twSL9EMUEEzuCM2RjQVOg5LWglpKvfO4sqoWFFekym77lX1MNpCM5PB 9UV7OyaRai5UivhnuD4l2z7H3i5+u1k8zAknnnAYCurxYZxWJBcYLF7Lsiw8UEn6Y4fj wt8frc2U5MP2YmZJSfUOGJH9JW+2FyxRR8HscD3MgiD4aCzhjM4wjouTCb4VRnQrH3PN I2LJ8Lp3xuFNhUnl9bbaGqrSBXtHt3T7EGCHN/zrHyHSIivaGs3BPyl88qifJzfdzdI1 1Wuw== 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=KYgm8KRRqsXZGdn21yoPTnrJv96Ne6lqyUqKM2FAIYk=; b=pSEAKHWbRr8fewB5fU5U1uslsxhFX0P5p8TgRMRKff5r9YRYuAtVLCnC9nfPR29Huq vZjw23QfxyuN2ZTux43q8CQH6VeBg/DzkIxQsRaWtsccv/2XaSDHW4woIDFMZk2TiZSD ZWp99N8moa06rkATx5nVVq6vJqyLHgvaFFekvUW7/x9zehETrhmbNenXPPUDCkk06lMg sI43SdXAp/YZMjbboy+2oYcYYmOVb+wqvlXix/zZUhjF7XXeSbCGz9FSO5nedso+FzzL CI+qzGNiUOK9dIuEGnwaGA+zGFm/JqR2tzyAnq4Dtl3EBQ7PMOsrEmqguCknvvD5KK+Z BOAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=l3aJvhaS; 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 dr5-20020a170907720500b0078dc5c888f1si1208989ejc.135.2022.11.24.05.56.47; Thu, 24 Nov 2022 05:57:12 -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=l3aJvhaS; 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 S230120AbiKXN4g (ORCPT + 99 others); Thu, 24 Nov 2022 08:56:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiKXN4c (ORCPT ); Thu, 24 Nov 2022 08:56:32 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D2D4FCDE5; Thu, 24 Nov 2022 05:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298172; bh=KYgm8KRRqsXZGdn21yoPTnrJv96Ne6lqyUqKM2FAIYk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=l3aJvhaSv1q0D+rXI60cI/Ma/anYl/lkYrN80NC1/0UTnepJGz5pH5nnaoGzmzMsI kzDRZ9wfyYQ6g33KPjVvOj+sApYyCFRQxoJxcalz1yVrVoz1wS0cqMd1w4+vTp8vHJ 8t+g0DxSyqcgDd9YjNiHTTNTUKYne8cYShzHrZPo29G1FIZjWJpfmbgzFl8PpccO4k mFw9w7C1hmEHp0oVMCVz3c/E4bqeauKGwwAF2JuQTTb+Rwqm3fmieAVwauPC+VlawG oaJfVGS6Onu+ahQGtJwkIlgtxkyu3ac1N/HfMsDUSqWBjucrTN7eSa0RN4l/QeSXyR 2LWZtRLX9R9Dw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MybGh-1p7slF2snt-00z1Ur; Thu, 24 Nov 2022 14:56:12 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 08/14] tpm, tpm_tis: do not check for the active locality in interrupt handler Date: Thu, 24 Nov 2022 14:55:32 +0100 Message-Id: <20221124135538.31020-9-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:YZiUudcwOuChyLmzP4dwIkl3/awLNQ8KvBhXt/WodxMvdwl6lqo LlvMEiHfeu8ijXYdt5z3l1dJ8nClGm3ZE/fOr0XUIvycnjXXKIE/a9nSTHWz2Lx7j+PLOFz UoIsae9eEmaE265WB9dK/wPWCsVS9zLGWYpPzJeKKcPyOki2TCwCFwMxS9j9TLKqdr2dVZb 5S/AFQr/uIehx5tMNoMZg== UI-OutboundReport: notjunk:1;M01:P0:6fJmel/inqo=;Xf58vLAIKBd8FABsoQ2j5E1vpHB Pm6ssHhRUxLjlzXsLBNl2lVwOC0N/daWFx+PkqgPMJk5A1EQDCpiyPpEluUKiZEv1P5KXQrIM aceYNzDS2M2CAa5f88BD8MtIosfhLQUC5GGCvgUvKg66ch57MUHZqfORiRgdjhYjS1Zb/SDIo 2DjUWlkneDzOkdEHYrybkVSgDKLyCwWE99qx4LvL4yZSIYlLjj4MgJT7wJmbIZ3NMflV1zSqU lq1fxrkmQAxYQEzt2gVdQslzl7qMuCRjpT40xBA9qKXaLgEycj2CqviIWmTKoOx99Ajf5qqKZ yD9ZHYL3ab706mtUUesc2ZjVIw+MbwkbCRgxrirQd4Sa9QRiyOXGB55CxJr1AwrHA7xNnvxCR tIF74Ul9W/NoVCTtxPjLv3jTd6bK4lSeIXqCvUUR0q+FRSX6weFKB6i8gzqeUFJhvpszziTPc 7rS+nrqTMU3XdFkBnW20reV1f7bvtJf4tekEXyq1rHQATYKphAIzxe/OycuXWoYibJs2I+rWy ZaPkA0gkmtVCrFYwPxY673u4j7exBZyOCx8kgfTfbz5gbs8dH85dmcs7KKyMtZYliJD44PYl5 eZFgvh1rhgq9vHBfuh1WAs6VlzOjEn50IvW/Gj1qhflSdG90eLUARCPe0L56Z8EupCaDBYZ1/ dtYf8tYpz01YAUefzdtkXkDuTatW5iS9J9rbRb8l6a19Y4jl+xKVa1QzUp2MbN59lv3d9u6X7 gX7LY/neHAwh39NVD6z6p0fR6yCtjA6Ytz2LOIrC+2jLT7vWB6sZzjQUd+vhi8SVq2ULyGwYf nhNXQVy/dMTex496Sfs/vvLMW0nrNgNPdSaFf4skJy0ICO42cMITdLUyXw8hWdyiybnFOvm2v DlrKXyEbRxQAxi3HWByT84Py+MENN+J+TowiEKUJD4CdFV6rAjX61xgNrPHFK/FQkCUkFsvdC J9jXqg== 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,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?1750386063503629353?= X-GMAIL-MSGID: =?utf-8?q?1750386063503629353?= From: Lino Sanfilippo After driver initialization tpm_tis_data->locality may only be modified in case of a LOCALITY CHANGE interrupt. In this case the interrupt handler iterates over all localities only to assign the active one to tpm_tis_data->locality. However this information is never used any more, so the assignment is not needed. Furthermore without the assignment tpm_tis_data->locality cannot change any more at driver runtime, and thus no protection against concurrent modification is required when the variable is read at other places. So remove this iteration entirely. Signed-off-by: Lino Sanfilippo Acked-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 65d1ec7eb4c3..d705dfb64cf9 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -728,7 +728,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) struct tpm_chip *chip = dev_id; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); u32 interrupt; - int i, rc; + int rc; rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt); if (rc < 0) @@ -740,10 +740,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) set_bit(TPM_TIS_IRQ_TESTED, &priv->flags); if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&priv->read_queue); - if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) - for (i = 0; i < 5; i++) - if (check_locality(chip, i)) - break; + if (interrupt & (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT | TPM_INTF_CMD_READY_INT)) From patchwork Thu Nov 24 13:55:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410602wrr; Thu, 24 Nov 2022 05:57:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6OflHtkjFlKe+Z8r/GahideIXJhKY2oIAlzHdaCvgomlTQpquSaCMaFsvTcLslSFFRyrVa X-Received: by 2002:a17:906:60d0:b0:78d:3f87:1725 with SMTP id f16-20020a17090660d000b0078d3f871725mr11805466ejk.492.1669298249272; Thu, 24 Nov 2022 05:57:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298249; cv=none; d=google.com; s=arc-20160816; b=zSLvIcltPeAkBPijt+Ceyuxk8tK+Ho4RMVPiddcOvLY0EWSfY3TOKzRwUT7er4mlSC DzkFyKn6E9eLf/yMqnhltVmIPGkvbkRjhJ+0AE72CN9dQFef+AXnAGaqvwuwzthdiGh8 IoREWoP6plO+hc0gk0vHn843LTbJ+s15TNiHD3qoKJs4OlZzyVHoSlWeQBG0HnEIMV6w stsLAWPI1+W/PNT2zMCGY774oH1sDo6zS2/LXSIgKg8zwU5tBpBiJrwyQOXvi/dUDBlU tf23hSGnu5ecuBd/tZCZzQoPRGKp2+N/LvACQbYTrs2WQQ8hjl/lBz0Tsuti220AsK4N DFEg== 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=fv8SjyD4xDuS845+FrgNrBwr4CQVNrdzJ9YRUMiA+TY=; b=mZQxUBpId1Q+1aRh7T1VdX1CQtZTLcRf5iU3BbbML2Ec9cQILdpPVfZE5/UDnRg8LS Njg8137xIpDM9Pzt8dbVQN5klb9mZu2jQqFtGv2RC/OBMb4pKji3XFUaDYRj+25Bcq6I 2OiuuY4FH9juUD7pK3Jd4NwPVMuekb9KJSQyV0cwmJiaNF6yWrEvUPAug+uPlYGKuk0S AGglFPhtWdVBrywVsyzeIZqj1jcKPF9O4JJEjHYdNHRVF6cc8JjzSC+j0ckA6OLfq1ed X8X4Eg8VERaPnPXd4J//XOs+vVM8tlvg4J5sxestaZ0FkqwJ5/484Ppcjhu7CwrrHsmX l71A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=lcI1cZuA; 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 cs19-20020a170906dc9300b0078c5d28e27esi1001703ejc.604.2022.11.24.05.57.04; Thu, 24 Nov 2022 05:57:29 -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=lcI1cZuA; 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 S230171AbiKXN4p (ORCPT + 99 others); Thu, 24 Nov 2022 08:56:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbiKXN4d (ORCPT ); Thu, 24 Nov 2022 08:56:33 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 424A1ECCD3; Thu, 24 Nov 2022 05:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298173; bh=fv8SjyD4xDuS845+FrgNrBwr4CQVNrdzJ9YRUMiA+TY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=lcI1cZuAQ5wvaNyZE2ryqYmERayGugVT8v30Rz2tx8ePi7YqKY4DUqScBesUGVBVZ 42EhV05+qTtJK/OfukMidyvXmQf4gt35gtG8y4gJ2maVY25i5sSj+hD6JhZPxZ3e1w ZW2lThEle+prgpPVoBWy4Kt7WB33rTUgDJ5dSuG3gzXDCKHcPHX6PlXHqEUqhDuvXQ PltNzr4PvdPbMOen+7/sv44xrYBjwxs3WB/LH4lQQpt7zo5EKNVOCroVvuYq1KxoBj lJTfCK74SpfqlQo7i/ZyrQrzTw1q5LWN3l86E+BWZ/s/Xwld699aU/W6omESjQSk8W /SIFDqwpd4OAA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MuUnA-1pFJp10EAU-00rbly; Thu, 24 Nov 2022 14:56:13 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 09/14] tpm, tpm: Implement usage counter for locality Date: Thu, 24 Nov 2022 14:55:33 +0100 Message-Id: <20221124135538.31020-10-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:EARtN2yQKkakweGe45TiFY3vqXI2qDGZjL4gyp78j5cHVteVZv5 HF3CDFi80lqOezCuQexU50FPdC7jHz82F492j3aBJmwLcdKMVEaafWdF1Ed7FaGDz3TUXCw i8ObbYI5qXlaOcqPEausj+fmQ+PSB05XO4NMzQo6qgg3LlMM86D7DdLoO3To04pMISoL2Oe p34/cDpN+TJrzJb7zWHQg== UI-OutboundReport: notjunk:1;M01:P0:+jLTMtAND+4=;hqIEXAWKxiuPKFVUiViFreV/Ml6 Tz4XPEUrjoJC3sNeBfK48XhgbgwTtd74/le+W/XQnSd+j+Tm4iV5EO3C+v8+w2yQ5vrEhjcBx bDAJYuWbq9YJbLHcPgZ+YbX4pwsk0GtMYLfq6HoQjx7xwBNLr4CxVjO8dsZLjTgkgZQFoKDzO 8Mw2vmUzZ4E6D6LuuJm2vVs963Ph5WLQbzw7iv3nI7JxG6FLSogbSXGJIidIm57QNHZW+fsdC aLPlByevOrgjAkcTjRx2EHsczzKytJhbCGI4IlKe67rV1ysEletFo+T6eAAb8DW1JKDDSN+pE Yure738l2W5OpqNewln7/fXluSXjHQQgAKZwfuCSxKBTKbenz0zDa7QgGAXGouA3vo/pqo+yW qp8haKRjUCCpvjv8Iu51erz6xViPcxzkYPAdARgqiQ4fgX/uccXoAQK2NzqwcvwnWTK9YhIkx 632phS2rNVt19qPoKD0hKpJR5QnTbsBAYn6Nbl/WT2qtS5KGjtcZOhnGpbOdyt3pF+D7L2lc6 Arf7qJe606693CrRO1gumFTHr8PKf1Qv0zRmOSQg0lWUBuLYXug2ytMw1HrjZTZoEAFS0ato9 /318EyZfm8gSRg5JXmM1zH2aM1I/+zLX4/AUxL1IktDm7CxtWH+UyBXbNtgtDPT8iA1HmoOzy qWYnrljVRkIPhayxuWYfuXOr6vnZWGeu+u1ofwj1BTKBVugKfvLdaRUjIcc9XSmNVnNoj0SOD hSaWvR9fTe2n7WYlDziiAqh5oAeWtwGKN6ZmuaueOP2GVy0jXwjIRNTsAsuVJFxC6pIiBEVRI i8UaKU465yYWTwFjdvtpWIFQzWsL/+XBnOr5WdaypUMfyWsPYlnJCuRchOCMjTnkk0P66PEmc XfAS8vwvwRkSHyOhpVSunvj/r6VUb9egniD3tJxEi7YaWg89vBkRshT+vXo8wmNc29Uylxf4v 5Tn7e4RsIF6OykJPDegG7QV6Zak= 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?1750386081099275524?= X-GMAIL-MSGID: =?utf-8?q?1750386081099275524?= From: Lino Sanfilippo Implement a usage counter for the (default) locality used by the TPM TIS driver: Request the locality from the TPM if it has not been claimed yet, otherwise only increment the counter. Also release the locality if the counter is 0 otherwise only decrement the counter. Since in case of SPI the register accesses are locked by means of the SPI bus mutex use a sleepable lock (i.e. also a mutex) to ensure thread-safety of the counter which may be accessed by both a userspace thread and the interrupt handler. By doing this refactor the names of the amended functions to use a more appropriate prefix. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 63 +++++++++++++++++++++++---------- drivers/char/tpm/tpm_tis_core.h | 2 ++ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index d705dfb64cf9..f00f1057fd27 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -165,16 +165,27 @@ static bool check_locality(struct tpm_chip *chip, int l) return false; } -static int release_locality(struct tpm_chip *chip, int l) +static int __tpm_tis_relinquish_locality(struct tpm_tis_data *priv, int l) +{ + tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + + return 0; +} + +static int tpm_tis_relinquish_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + mutex_lock(&priv->locality_count_mutex); + priv->locality_count--; + if (priv->locality_count == 0) + __tpm_tis_relinquish_locality(priv, l); + mutex_unlock(&priv->locality_count_mutex); return 0; } -static int request_locality(struct tpm_chip *chip, int l) +static int __tpm_tis_request_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); unsigned long stop, timeout; @@ -215,6 +226,20 @@ static int request_locality(struct tpm_chip *chip, int l) return -1; } +static int tpm_tis_request_locality(struct tpm_chip *chip, int l) +{ + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); + int ret = 0; + + mutex_lock(&priv->locality_count_mutex); + if (priv->locality_count == 0) + ret = __tpm_tis_request_locality(chip, l); + if (!ret) + priv->locality_count++; + mutex_unlock(&priv->locality_count_mutex); + return ret; +} + static u8 tpm_tis_status(struct tpm_chip *chip) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); @@ -682,7 +707,7 @@ static int probe_itpm(struct tpm_chip *chip) if (vendor != TPM_VID_INTEL) return 0; - if (request_locality(chip, 0) != 0) + if (tpm_tis_request_locality(chip, 0) != 0) return -EBUSY; rc = tpm_tis_send_data(chip, cmd_getticks, len); @@ -703,7 +728,7 @@ static int probe_itpm(struct tpm_chip *chip) out: tpm_tis_ready(chip); - release_locality(chip, priv->locality); + tpm_tis_relinquish_locality(chip, priv->locality); return rc; } @@ -788,14 +813,14 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, } priv->irq = irq; - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) return rc; rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_relinquish_locality(chip, priv->locality); return rc; } @@ -834,7 +859,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = -1; } - release_locality(chip, priv->locality); + tpm_tis_relinquish_locality(chip, priv->locality); return rc; } @@ -950,8 +975,8 @@ static const struct tpm_class_ops tpm_tis = { .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_canceled = tpm_tis_req_canceled, - .request_locality = request_locality, - .relinquish_locality = release_locality, + .request_locality = tpm_tis_request_locality, + .relinquish_locality = tpm_tis_relinquish_locality, .clk_enable = tpm_tis_clkrun_enable, }; @@ -985,6 +1010,8 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, priv->timeout_min = TPM_TIMEOUT_USECS_MIN; priv->timeout_max = TPM_TIMEOUT_USECS_MAX; priv->phy_ops = phy_ops; + priv->locality_count = 0; + mutex_init(&priv->locality_count_mutex); dev_set_drvdata(&chip->dev, priv); @@ -1063,14 +1090,14 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, intmask &= ~TPM_GLOBAL_INT_ENABLE; - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) { rc = -ENODEV; goto out_err; } tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); - release_locality(chip, 0); + tpm_tis_relinquish_locality(chip, 0); rc = tpm_chip_start(chip); if (rc) @@ -1104,13 +1131,13 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, * proper timeouts for the driver. */ - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) goto out_err; rc = tpm_get_timeouts(chip); - release_locality(chip, 0); + tpm_tis_relinquish_locality(chip, 0); if (rc) { dev_err(dev, "Could not get TPM timeouts and durations\n"); @@ -1130,11 +1157,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - rc = request_locality(chip, 0); + rc = tpm_tis_request_locality(chip, 0); if (rc < 0) goto out_err; disable_interrupts(chip); - release_locality(chip, 0); + tpm_tis_relinquish_locality(chip, 0); } } @@ -1201,13 +1228,13 @@ int tpm_tis_resume(struct device *dev) * an error code but for unknown reason it isn't handled. */ if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { - ret = request_locality(chip, 0); + ret = tpm_tis_request_locality(chip, 0); if (ret < 0) return ret; tpm1_do_selftest(chip); - release_locality(chip, 0); + tpm_tis_relinquish_locality(chip, 0); } return 0; diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 2deef11c88db..13bdcf38e56f 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -91,6 +91,8 @@ enum tpm_tis_flags { struct tpm_tis_data { u16 manufacturer_id; + struct mutex locality_count_mutex; + unsigned int locality_count; int locality; int irq; unsigned int int_mask; From patchwork Thu Nov 24 13:55:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410671wrr; Thu, 24 Nov 2022 05:57:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5qNCN91b7jjGW2saZnrXntUxMPFu1KYd3rQHEKiIwbLmcDw1AJGw6vkgAickvxeDbLqBvF X-Received: by 2002:a05:6402:4311:b0:458:c66a:3664 with SMTP id m17-20020a056402431100b00458c66a3664mr16248575edc.79.1669298256330; Thu, 24 Nov 2022 05:57:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298256; cv=none; d=google.com; s=arc-20160816; b=vTnKN+qgj4sVjUoDbRz78gygtg9gNcXfyahqFKl60CCFenA+ZETSGXXVpmiNM0FEMP j059Dqn1PwyICjJPNVNtYQb/ukHEh5MO4dXeYtW1HoFbdTRzRMUziCdUpQKGF302O12m Dn7rzNdC8b/tcQl0BlgBzj0NYGq8JzMj44TCLGyalOrP41V//2eW55eZQvTcMPRtXJof 2F8cYphwcTf96mkbNhdrJXKYbiakxNAYN7KvnRy4kd+m1YrzX5nKtOUo6KV6M6P1FZTu PmZBXYHr7DQyFpY9enBhdFsRr+nwaML2M/KWbrkoJP3eG2+bFHLsC11Dq67SgDEWRpqz TF6g== 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=vnp21/mfPoqtAE/9hipMWqTIgnCW9bDnAe+K+uHJwrI=; b=NM54EhFLULgh540IPCOfKvpNaMgPF00F2Z3NMz3w4+ZclpNzRi8fLsKAe/paAcWFC/ Qx/bvkniCpjWS6KoWawi43PYsLhoqgjEyAnKJnJSoigpNgHRcrP1J7yPZm/6tVmgOwk4 vzF9dQg5kVYkktp1jWs63ElFf2Bku+b8SljEg2+ue4/JZxC6GkMGnQh8JjZjwg5z2oLT e2M8JZBMiAD9D5ENWavZW32csA0hZvnIYkitBHEnMfEeK4KpYsAvbEjoNeUFek5aUb4n umveWfM114DY7iSkYpsuvMsGdusi7QBYL5v18BxfYNhCpAxdcksZ9ZUVvz5o4ANdYBJF 1+dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=LvEQYqwK; 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 dd9-20020a1709069b8900b007ae61d89b3esi1243261ejc.356.2022.11.24.05.57.12; Thu, 24 Nov 2022 05:57: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=LvEQYqwK; 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 S230201AbiKXN4y (ORCPT + 99 others); Thu, 24 Nov 2022 08:56:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbiKXN4d (ORCPT ); Thu, 24 Nov 2022 08:56:33 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F22ED100B3E; Thu, 24 Nov 2022 05:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298173; bh=vnp21/mfPoqtAE/9hipMWqTIgnCW9bDnAe+K+uHJwrI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=LvEQYqwKKJlb5S4pUaX7RxL3noLuSJv1rRgUqNElsH5Cj44g9xXImgXuGiSPYNajp LoyxrJhhJ9LhlZ6AbdES/IB23dtxOMoPZnb4Sca0xWatzN7V0cClfoXv4qIJQsFwTz gd/j++4x6FZRihrfjkrruMbIdBHTrYKUl/Que9sCIazI00gRfqhHTBRebUlb7HJoDN gazlUgsJPGsHe3NfvvJ1+ILK1Q3ssp0zFMYiylySFkF8GFZJLpLTI/tV4M6pqEnVcb VCNiPtIZg6rUFdXCp1e74MeAsCB0B48FW3SXfHWuUe+2GKLeUuTEddvoS/kvQZPIO4 x5+G8YSkK+0Rw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MxUnz-1p8zDw1j8z-00xvZB; Thu, 24 Nov 2022 14:56:13 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 10/14] tpm, tpm_tis: Request threaded interrupt handler Date: Thu, 24 Nov 2022 14:55:34 +0100 Message-Id: <20221124135538.31020-11-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:FpAKGsitxv+CMneiAfduiO2RrZijFQTQp+bMXElnc3uL6bI8p7F zTshYoLZPrT8axM3jWbcpMLVq9mDHDdAM3tEq1uBH7XummJ8qw+y0+qVRCRfiBBWWjPfPKR HxVBk5dWcGeX13WUf5W/H/MUSLp/5/IiDTX7Aojuz0RmODZhawY2YNzTV92vhwoK7k4mYYw I6ycvYQPwupnhA3TxH/4Q== UI-OutboundReport: notjunk:1;M01:P0:LNScq3ME++Q=;BKzLYTTefHVMCZH5KtkD/2MYx2g yEEGIXB0VrNAzG1MPNtuPEad1NpHbQnDBhREjjp2/F+WkVba7j3fnsy5VBRpIJH4wJ+85Kl4P w3YeiiTuCcv1C2PWe0jYoCbyq8Sc2jpJB48ohmPZAtcopjolLQy6NhIHFx+ZLWqSfBLzDI1cC U2lRinQ6QHVwAk5j9UEPsZ1DZ3oi755kiFg8cIc1qCjKvVdwVuNb/LPBY0ESyqDyzuezG90y1 wQKIBFR7v11f69N2jVBKyjm+Fyjt8Z9irgLHT5YA8Edflc9jEU8gf4XlZAyYRiJjBIROl5si/ rKZT1XI8wypgy4T6eWIB3EzKcLPqGvJJaIcLPB7xXbfKbXV8h1PpJzG+nRuhS2lHqAAjpB0Bm YL3Jl+dFIHYSqqjAlyuqVpGmgR8OY7UR3OtUuCmU9HoUYyzSaiPLtAvwUCInmXuQqFEep/6QW rlZOHn1eWdulQ3cYXq/99ZEptGZP44GnSBgo10kfT743jbVJGseynRiPgg0ULyS1fiItL3OJE SVXyBr1dosQpVdJ+JZzaNzYsWsEx5Y2w1oRTBrM0hljT8aLkF3ZSDmF2sbwZj00je7CVFXg4Z KB8KQYCpM4cXiX9cVlpCtEv4cQwcX0rlcOwHfJdaGIICsf30pTVN6PiQo8DNxROccjN297fMo L3EXLpEP/IclWwfi/wCSySfN3Ogn4nxD5aekud0T89sl45LR2CJT5iGY2etExs6KdQRCtPseO wg4hpy7Jo6jp7vQPlK763YN8d4GRcgInN2xb/2D4+0FzaETFqjJAHKX8qvCifjEJAd6HARFyy lUUhJsekePLsi19qReLqJePnVSCah0YyulLyC7axAhMQgtsBLML7ah1bcH5LeG2E5R7Hd6CCE vn75t6E8BowE7vcJGB9IT0Zru91gag8mt3KduLDx/X1WveZIiNnVhcjHNdQhOfl/aRQ60R47Z jxc/+A== 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?1750386088199012696?= X-GMAIL-MSGID: =?utf-8?q?1750386088199012696?= From: Lino Sanfilippo The TIS interrupt handler at least has to read and write the interrupt status register. In case of SPI both operations result in a call to tpm_tis_spi_transfer() which uses the bus_lock_mutex of the spi device and thus must only be called from a sleepable context. To ensure this request a threaded interrupt handler. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index f00f1057fd27..3891499f9877 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -805,8 +805,11 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, int rc; u32 int_status; - if (devm_request_irq(chip->dev.parent, irq, tis_int_handler, flags, - dev_name(&chip->dev), chip) != 0) { + + rc = devm_request_threaded_irq(chip->dev.parent, irq, NULL, + tis_int_handler, IRQF_ONESHOT | flags, + dev_name(&chip->dev), chip); + if (rc) { dev_info(&chip->dev, "Unable to request irq: %d for probe\n", irq); return -1; From patchwork Thu Nov 24 13:55:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410828wrr; Thu, 24 Nov 2022 05:57:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf564h295169eWmIHVbn78IzYkACDOKmBM+AlyoKMEmI02ohNX45qlJcxa7dITCIgygRqpt7 X-Received: by 2002:a17:906:a397:b0:7ae:5381:bd02 with SMTP id k23-20020a170906a39700b007ae5381bd02mr27023944ejz.286.1669298276634; Thu, 24 Nov 2022 05:57:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298276; cv=none; d=google.com; s=arc-20160816; b=BGqW9vtD/FsZ+0Ysyu2cGoqts3tYjicI/GMaImQP13403RghIXrUP2YJFMPSzBZYnQ lpmY7rf3ywROmuNOZwrgaowBH1/8pJbphfwMi7iI4jFZLInbErZjy8ZGo7f9lWkiv5J3 wO28TQov8vecCqZMDZ6mZpq8TIvOIkx5ugCKfeYp8fDGNrS5kEeAyNFNpej5PpndKFjv u4Z39lF70iyjorCKqbcxuSIcpNgEabJxW5qX9EV0oUtkYJs7n9mdcZ+vQuskMqDSptmC xkLxONvvvLIfiKtm12HRhrEPVcr09JGhspVpxMBmSnknzxXqh7eitSYRgaiBHMOGesqT JXDA== 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=RNoCSRg3R8Wx3i1g1q633Fjj4lnL+OK+lra5ATnMp4U=; b=W6McehjJj0UoJoU8EVprcEwbJbKq1hsTBrtvOKFrhAfOC1TnAS6eTcQk+VndOOacov 2+rsj/svfFLqOtzbPDq5zPDnqShUZZYuV6ughY7ouJXNhTRpXj5sOWQQoGsaeNE1DneF EdfonwtkH9OLLdx0yrCgPXVDWag27q0RJ4mpkuySlAhOvVxY4yEKrkP99Wv5pRkN+vY4 8tFH0Xr0hlvsK8UCuiaAO2ZZQaGq7YvBpzRLO+yRLK7OvZqhJvMvexqURBEDq4cjJHAA hqF+EOC1OAmvHD/+wZcmER/IlIY66V11KcmMrDwBLokTU2GvM5HxvQYNAlk9xDwgUlgh +Xeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=EaPyy9kW; 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 hv12-20020a17090760cc00b007ae832c0b6bsi970568ejc.508.2022.11.24.05.57.32; Thu, 24 Nov 2022 05:57:56 -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=EaPyy9kW; 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 S230175AbiKXN4t (ORCPT + 99 others); Thu, 24 Nov 2022 08:56:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbiKXN4d (ORCPT ); Thu, 24 Nov 2022 08:56:33 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB867FFAA4; Thu, 24 Nov 2022 05:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298174; bh=RNoCSRg3R8Wx3i1g1q633Fjj4lnL+OK+lra5ATnMp4U=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=EaPyy9kWmOu7yKDblEHFb1TJ5KSgmh9amRrtcp6n4LxnIot32DPejBQEp6w5OZQMb wvGeQC8V5z2rSj0pQ1wZAVJP6dQqnCTae817QMGQ1xwCksrsb7fUSDcQ6phiyUQfWP Ba0nHQZ0ERIHCurT5pYh9gQKxcnG6GkGGu5UWSD3/aZmYOx4uNNR4IXIH0+fameSR4 BOidMDBAlEHo7entttgS2iAvsSus35bEgBZdrzLjCQ5swNMwux4uJTnoz607VQaQQA r/WXQ3kEy2wvRKtObjNS5wIy2mVlZF96wB67Xc609JwVa0r0Iha7wql8TDfUxkqIX1 Ttu292M01Cm0Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MtwZ4-1pCZjF3EZo-00uMey; Thu, 24 Nov 2022 14:56:13 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 11/14] tpm, tpm_tis: Claim locality in interrupt handler Date: Thu, 24 Nov 2022 14:55:35 +0100 Message-Id: <20221124135538.31020-12-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+4teyRziUIPdBKrwSWvjbsYkNgwpeKjz1mYZdtd3vDEeyiycqjq Wn9EuRUn7cNzN0xLlFliMQlxrp3BVEhJBSEoTBpSpElfCo/J7xOXQ9/2TkRPrT0mGaalOUy 97c/MhwXZU2JvaFyfG+PHlwYacqYGORMF/RkmbU2JdwE2Wodb4K7URnxMG3W6fSRMKMjzWq VTXro35eiHY+OdD1aOzGg== UI-OutboundReport: notjunk:1;M01:P0:9cGxeBqa+go=;IZmiS8eY/s4mXxdKxByX1ytWAaV D7ibIuts1yzeVae/mmUwoaaegD1M24aTq+2HcJNDfQybbRRrp/xUSN48bKXNKHFwkA7BJOnw1 HUFjgAAU65YSumPyzvpOhjJv/addNEkVybPaq41S1SqmZN5rAhMOvZmnZILLRWd5cAOaUrHdZ wHooG4mwvJWcT/F9i9GksWlqSNPdlrsW8HLfybtlMs0X/77AzXUAFPmdG/ecJJ+vgb45MXTb2 FFgtiYPrSGBbNIZpQ8Puzn5yBgvkHWGXkia9tkx2BjGgu8yO0JfhrwjdnKtn0M+FutqkIvMnk aVcm2trverNdhUrwL8K+WmOTDRcUGJwplzJET08gaPmramDZH/NQ2FQioxMKE3OOEourBcier GfYu2NtVJrKd2uEMyhOxdLMbJJNDAxa7tQoXgKm+sGgT69VZ9tyWN7IM4ONlLc7pGnJ3HeCLE 30sKBMxjIC9OZflH9NqEZKjaAJIPfjYKaRgrl/K13mkr1rHWIq6V9B96QZYVIiMS8BDVBjGI5 zoPkOqaI0cduKu6gCrBKuANPDuhVl5moHKFPVBV9+trzcMp0C/Q4lfYRdwhQHkjdiDp1TL74D lXmTQ67gcWK3WMMof4sJmyFcxMBaO2bvnYP9QHoeo61FMuLxtX4x00jAwpnDPSP1Up9omPzDG Uc04HeDrs4PjK53D6ZgLwIeVACfL29Upgk/+BdToD5LwEbfqR3KkJgZg1N0q2iUJaLfGyCjNP Gtj9uWJZ9Xgs5S25P3cdefAQDuaBF/LkHW3HgwBZpUWDUyhVumLdFsC/MbLI3AWwqfRT74Asj 0X0mT9s0UpIQJQAgXeS0ClFoeKhgB1O1rbauvAZ8fwtRuWtAkkKZEJOZaRKJ7m3Mr1hI0Ae5f 6db04brPOWz2pHfpyd39uTgbq+2g2hKkKkSTEa2jTpFWcaaCujrYwU20hBjZWJt3a6gMW5X5M 4k24Cg== 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, 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?1750386109656862201?= X-GMAIL-MSGID: =?utf-8?q?1750386109656862201?= From: Lino Sanfilippo Writing the TPM_INT_STATUS register in the interrupt handler to clear the interrupts only has effect if a locality is held. Since this is not guaranteed at the time the interrupt is fired, claim the locality explicitly in the handler. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 3891499f9877..eda3b122e540 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -772,7 +772,9 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) wake_up_interruptible(&priv->int_queue); /* Clear interrupts handled with TPM_EOI */ + tpm_tis_request_locality(chip, 0); rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), interrupt); + tpm_tis_relinquish_locality(chip, 0); if (rc < 0) return IRQ_NONE; From patchwork Thu Nov 24 13:55:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3410786wrr; Thu, 24 Nov 2022 05:57:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ZCHvIISzPPsWOkylelv2cp45z0OpEJaNhVzgzsP5ecou3dxSXGNE6J54xbiiJUQv8v7Me X-Received: by 2002:a17:907:7666:b0:7bb:dc8a:519b with SMTP id kk6-20020a170907766600b007bbdc8a519bmr980624ejc.209.1669298270572; Thu, 24 Nov 2022 05:57:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298270; cv=none; d=google.com; s=arc-20160816; b=uRcVueu1w7VNJwa4xU/1K4rDAtR2C80IWsfEtE27Gl7dqbklzEv4xJ+3bwiUHbIFf0 78VMRtlLkIkn+2aGI6W3WRM4/ZUf3983AUMbjB3E6/ZZv3utU/O1KGHYv6YId+Yk+dXV 3G5YnME3Vlag+K4vjXYEF4lXXms7MEodVNW4RJzvDjrUxoLGnNT/nuyjZXR7NqqC16Is K7WOPZE92JRlpJpPW0QH01Kt4iHCcfNB+aq3ufZxP7ya24K0QUtzIXC/h/ZyZO8SWLzo RZRq1YTNEraQZOxYieKI7TbCZDk8d4R4prUElimen9nHKo5Tm2txcO/nrlG+W/4aFBpO 6Itg== 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=ZQrQ2undxx4v+6nZgOuKeQ4fsU8UgfXoZI9MOOth8tE=; b=0s8OiG8rznD7YhVB5abkNaoUpl5XrYBkz1hp0La4n/irSasXVD3wAE1oxihD7j+jXq BFVauLlonl0xav0xSP8Aw1tbcgBxVOeedB877NIsvIEJFvLnOYA4N14nX6d4L305lUCa NqyepPmS7ttEtNXkejdBzRJCFLgKcUPORJONmB56wp+cjhKeBRsKUMGlVDDsyA77dRP2 bdhvgxBYW1gHf9TYU2X7WNKgaValRwk5SrO/uKguhpDYlcERP3RzuUiWyNHqvs6uvWza NW1e9FgyZOoRAqnEVvCeGGW+/yXlP+v2TeRMs7fuVKIRgd43FQd6jjoGdZLJvECyc/UF MLnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=ddo6u5hs; 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 ht10-20020a170907608a00b007ada03062e9si1152161ejc.415.2022.11.24.05.57.26; Thu, 24 Nov 2022 05:57:50 -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=ddo6u5hs; 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 S230161AbiKXN4l (ORCPT + 99 others); Thu, 24 Nov 2022 08:56:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbiKXN4c (ORCPT ); Thu, 24 Nov 2022 08:56:32 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E270CFFA83; Thu, 24 Nov 2022 05:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298174; bh=ZQrQ2undxx4v+6nZgOuKeQ4fsU8UgfXoZI9MOOth8tE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ddo6u5hs4cj434HcTpvwD7vW5+PiLY02huNtyJ4ohWXaqqaSRC8kFnEX1Oj1/186W f5JQW+ArJNDd88wHAGIFB2/Ewor1o5IZfXdV2Z0j8BuswykfniZffgtTnV8/ObB118 wSquDx1nblWyPykGdYHSUCxaDbA3ILAfhhHyRoHqnlI3D/Yi8mph6U/QXLBLH6wPE7 LQPlao0reGbUfmLBZZuMBYXJp+ZPnO8MytdAyXZOiTFvNjA5pxttEx7N9UwwvV1Kno Gc+YCMSIrZyYcP6CuhEegwtY05QLm88r0wfeGr/D1OQPcxkV1dLWDvCj0Cd4t+6+GH WcpSx9yqGegkg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N33Ed-1p3SuR0Ny9-013PDZ; Thu, 24 Nov 2022 14:56:14 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 12/14] tpm, tpm_tis: Claim locality when interrupts are reenabled on resume Date: Thu, 24 Nov 2022 14:55:36 +0100 Message-Id: <20221124135538.31020-13-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:yRmIK1f7+KxuNnECWFfKad/tTssuC85ALDbC/SoyTS81qtmvqpc AwTK5Hk2uvTdkpPGPYrmxnkYAyuykDIPFH1hQ8ViCKeKAg7N0jx9eMxVXT+BHCbIQfwq1fm ++obvjcECsK1RpCjoFxvWhSV3yVS3dMTB6GuYJlWd27RYjG5hP4SlLg60HP7rwVWtJUhxjs PtxAMW45nsfvyImDBW3gg== UI-OutboundReport: notjunk:1;M01:P0:Z2d0MsdV5WE=;XM9FBqeSHw8Rx9MapvOY3cFSXaZ TC5cmrDnDLdiVszxx1katTwJrXLSo3xzmP6t7u08luQvC/KkeXD0ldetn3rkG1HPwy9iWqwGq HTEjSyYryS4qLssywWSmBK/MFilZoDrJXB8wrmNlaIrQ2YMzmfioHf9cisgqeSJ8cTbvTQe7T OqKjs88MgELFapfpNiIdFG2ECoa1XRc8Ljf7Dy9bLdqTXBk/L9+Rx9SU+PKZQfvt73wxIEmed IT6+WXiK/N3U/c/dkmBmxufp8QdyNzml3LnEvt3s7sLaxRqo8vHOWbw/mPslxwduN8ZTDHbt6 MsKUIPoK2SnJbI/Qb8Kg+aP/c/SbJusfsRlDbUuuEzLImH/eCHxI62Wvl8otGYrjMBWoKcIpe vrrWbx/pNkjvul8uEem7bDNd5MUhuU0PQnqRQPyKvhW141WcPrJu4+ubsvN/jfuFCfE5aSxqG yUufGqqCnIlCDEJgI2WaV0PV43V/AKwCJUOn2UayRRbTmbOhC/YcK6zeTt7G3oO2iaj4URrH4 nxtNfyQQz1RCHu931HXJ3bhZUl9JmhZ0RPLtNpFwN5PY0HTQwjLgSng+UJ6PJnTJT48ElV3cs Qnqd/Dou35TyR0FnUz/yFPp19Wx7VyQ8NGjGuCKbL+feZiGECgKNXDbl4ONCKW+f2pE82YHfy TzK6AsYIx7LAYCxub+iQNn+HP2wYSG76GmQTd/a2W/67l2KmKf3h2WMf7OXt2zt+vGSXUIkBc O2NSzOU4YvLQlzs+Ax4Zml/Lmx5UllM7uPJpcjVkWpYO9zwtz9Ie3n3gvwEesjZhD+/ac76Mv q7/nKY0UHSpg5Ytl/ZRswiXHZ8zjKg6f2d/W2hfIfG2XHaRFZXOJR/uoPWdHjhpTjWlgyGy1W MCNjOFAwR8+vBlX789a8++OwFeg+s8yAlF/1NagbadH7I60qS43p9pKBJrcmhgp6KrqzgNcTp HunYdQ== 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,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?1750386103028176196?= X-GMAIL-MSGID: =?utf-8?q?1750386103028176196?= From: Lino Sanfilippo In tpm_tis_resume() make sure that the locality has been claimed when tpm_tis_reenable_interrupts() is called. Otherwise the writings to the register might not have any effect. Fixes: 45baa1d1fa39 ("tpm_tis: Re-enable interrupts upon (S3) resume") Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index eda3b122e540..ddaf362e62c1 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1221,28 +1221,27 @@ int tpm_tis_resume(struct device *dev) struct tpm_chip *chip = dev_get_drvdata(dev); int ret; + ret = tpm_tis_request_locality(chip, 0); + if (ret < 0) + return ret; + if (chip->flags & TPM_CHIP_FLAG_IRQ) tpm_tis_reenable_interrupts(chip); ret = tpm_pm_resume(dev); if (ret) - return ret; + goto out; /* * TPM 1.2 requires self-test on resume. This function actually returns * an error code but for unknown reason it isn't handled. */ - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { - ret = tpm_tis_request_locality(chip, 0); - if (ret < 0) - return ret; - + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) tpm1_do_selftest(chip); +out: + tpm_tis_relinquish_locality(chip, 0); - tpm_tis_relinquish_locality(chip, 0); - } - - return 0; + return ret; } EXPORT_SYMBOL_GPL(tpm_tis_resume); #endif From patchwork Thu Nov 24 13:55:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3411274wrr; Thu, 24 Nov 2022 05:58:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf4cyhJFoz7t0rttP427UA/2RuGya3YRq4jRWy+yk7GTOLQO+V/12CPchAx1KlrFFaWEYHGJ X-Received: by 2002:a17:906:fa06:b0:7ae:72ae:264b with SMTP id lo6-20020a170906fa0600b007ae72ae264bmr11586317ejb.301.1669298335238; Thu, 24 Nov 2022 05:58:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298335; cv=none; d=google.com; s=arc-20160816; b=EP97o9Dyzw7pWdUZfirSCcdKHNNNtZSMjaYxXfvzCxX0XdR88/W+tOR4tXm8PaJ+T9 8BacWRNFHCLpzuosi16yt6Gc2z8BAvRdOgbb7xdHvoNvF5NO2GBSJ59ItPR1U6GriXvE CFAs8ozK580LujTOEk7R3qB+b4t9QL9TuT03DFZZZ2Wdh6JDE80zMTxW2hwe6AKtI8zq 7+CMHCvMuDxK+ii8sBHZcBHL+PNsTW3SfcJEHwNIwQElRFXYqOnYQXWz+VSDbIfRUHi+ L+xjKT/ez5gFWvbn3YKm0K6zmizbVKrAKizkS6AEnUl1ppXlx18a3Mhnq7BlQHuQpDGi bPGg== 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=SccepFkG1BaYDhxThv4kTIw73gWWQ8B34c8oBRXziP8=; b=cYcU8dfQprYJ82U+JVfFeIdZNAMeUUD1yAJpCjd5HJ68YGoWF5IikN+R4CjA/vIvz3 OA/X/3WXXwvBasIZpcFZIcxeTRQOIVew8hmFdwJFiPhbQQRni82VwDxbrzcGplAxtB/K yaPF/udxjDH+mJismBgVSpFUDXPHVz9pr4SJpOdJ4cFipf3iUeDGykViKVTr+Ha4H9q0 XqasvHUBbysUPvf9BKtGUTIw1WXuf4LRZEAKDWEs+7FyvOA9rs99M8v+Gt4ikt2I9Fbi 4n6578euEs/AmQKoMJzs61gEXB3wESsoz8F/9nxoVSlh0HNF4FRJCh9pJ0b/4xKhZZxs 2+FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=N5oSIApe; 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 go36-20020a1709070da400b00781b6ce15e1si1196916ejc.101.2022.11.24.05.58.30; Thu, 24 Nov 2022 05:58:55 -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=N5oSIApe; 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 S230342AbiKXN50 (ORCPT + 99 others); Thu, 24 Nov 2022 08:57:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbiKXN44 (ORCPT ); Thu, 24 Nov 2022 08:56:56 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FCFFFFAA4; Thu, 24 Nov 2022 05:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298174; bh=SccepFkG1BaYDhxThv4kTIw73gWWQ8B34c8oBRXziP8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=N5oSIApeIyqhSeyC5gdSR0djmO35Q82/vTO7AnK+pUNovI047gP53VxHdyEh644Gs vDbkjFbFt4syPSalb34P3JmOTUqPiUORWZ3cu/CtvTl1I5MDTSI5LbrbRykKs3MPPB gDqmJMCbW/daQoZ5iTvHIoqr6zvwolRhD2aLsgkpb99iWmZybH3HfbmPqUJnkMNObK 4M2a2Ouq50SagnRldDSMKXrD4VUHBcq6CmZ+/BDhv32/We5dpWepTL9XotCwnkiFVu TYXuIvIFTdnNeOaR/smYBw2k8Rv1UALGd+DflsGFfHRtoG9vBH3jN5QSKi9OQr1Lm0 TWJ58lS+6OZLQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mg6e4-1pPH3Q1hnS-00hcyE; Thu, 24 Nov 2022 14:56:14 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 13/14] tpm, tpm_tis: startup chip before testing for interrupts Date: Thu, 24 Nov 2022 14:55:37 +0100 Message-Id: <20221124135538.31020-14-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:zL2CNXLyU474XTdrXuPgbob0QK0DB8meDAMR4XbMdR/tbE5lv3k k6dilEu5PY/7pIfCkYcsG9ONqgIh7Yw14eA/C71RO2XlIIRNDC/vszFhWB6E7PjthtspBOF bnGzBzzik2FbNsoASv1b3OfHAbGE6h6nhndFb/bw8w++/zya1A07LDjeoY7MMXfTDUMrYbf bxYBAriPFhSep3+hjLCSQ== UI-OutboundReport: notjunk:1;M01:P0:1LYpu2fBXps=;CrGmYwKDDI8dwJQBn3y2fmWp8Gs IA7PqgPDCI0YelnX1m174eoQ7ICsvUkRLf1qhlw0+1kEcAK/s11cWQO+JCsG2tBuUYf6t/N+s 4dXVf06KzusaVhyfHT9ULvmQtbNi53Bex54+G9IBwrvtHJzY3SDYxpA9KfYYrOATllrP9XKGe ytOWAHB6oOlnLA1OPJd70P9KkALdtKQq187b2MY6T7GN7NCcsoz3AVromPiCdF1PLIfZdWdsH CSwfcRCgOlL6tzkTLO5HdsRlGBQDto3v9YpHtHqKwPtSqgL529thm0QvOy7DpAcYfG0UacLCk l/RrWNlHMjSzjYLDqmjDU6hrMG+wJ1qGq9SP8Ag5RhPIzJkvXFVWpLX2UzNF0w54Oly8nYZkh 6JLFhVMRhZJyqxlKIc09Rn8JSf6jaEwHsOlGs8wk9Q35d4H2LWF9CatxP3A6q02Ebg/pnFx41 mj7jZk4qEGpvEqEqSUd7lTtEMRIbJr8T5J4oRMasG2bXXTok66l+ecll1GWZzvZqnrBo8+sqf 2vENlVO5QQiHp+7CYFzhVyaL2kfGIBHJ90QCKc2FRI81DYEz+Sudd000dC/TMmjA+gOAxwrqE 4dZM/+C223BAwUhs6oJRZieLki5Gm+BXafGFJWENkDez2vfSTqaObWy1O0+3Fsg5K67R2Be5n PSQKkM6gUaWh7oI9xMVfrzOq2NYGjQDmhS/dtqOFM2p/w2xAZOF52M3EhYEhIEh9JmtmDJfhy CdMQCRHDF5Cm9pIRuLdV1IDx/MmcxYg2MhwON1ghtxxte5TYdXZ+QIpebHcJdIFDnfGKJs4XO 4GOu4AKLF9SNddSHjn1qu/b67IKA4NLdlFiEB4QYUQhpL0nsFgH9aBIqZebPWX9tG84Tz6cgR 5PXiwM0vVzJRDLlq5Jj3PJc29ZfEBRVsIlCC7fTsVyDIDlSR3vya9bCIdI6r7b1Qd5yws60o0 be2bAg== 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?1750386170779736746?= X-GMAIL-MSGID: =?utf-8?q?1750386170779736746?= From: Lino Sanfilippo In tpm_tis_gen_interrupt() a request for a property value is sent to the TPM to test if interrupts are generated. However after a power cycle the TPM responds with TPM_RC_INITIALIZE which indicates that the TPM is not yet properly initialized. Fix this by first starting the TPM up before the request is sent. For this the startup implementation is removed from tpm_chip_register() and put into the new function tpm_chip_startup() which is called before the interrupts are tested. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-chip.c | 38 +++++++++++++++++++++------------ drivers/char/tpm/tpm.h | 1 + drivers/char/tpm/tpm_tis_core.c | 5 +++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 783d65fc71f0..370aa1f529f2 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -543,6 +543,30 @@ static int tpm_get_pcr_allocation(struct tpm_chip *chip) return rc; } +/* + * tpm_chip_startup() - performs auto startup and allocates the PCRs + * @chip: TPM chip to use. + */ +int tpm_chip_startup(struct tpm_chip *chip) +{ + int rc; + + rc = tpm_chip_start(chip); + if (rc) + return rc; + + rc = tpm_auto_startup(chip); + if (rc) + goto stop; + + rc = tpm_get_pcr_allocation(chip); +stop: + tpm_chip_stop(chip); + + return rc; +} +EXPORT_SYMBOL_GPL(tpm_chip_startup); + /* * tpm_chip_register() - create a character device for the TPM chip * @chip: TPM chip to use. @@ -558,20 +582,6 @@ int tpm_chip_register(struct tpm_chip *chip) { int rc; - rc = tpm_chip_start(chip); - if (rc) - return rc; - rc = tpm_auto_startup(chip); - if (rc) { - tpm_chip_stop(chip); - return rc; - } - - rc = tpm_get_pcr_allocation(chip); - tpm_chip_stop(chip); - if (rc) - return rc; - tpm_sysfs_add_device(chip); tpm_bios_log_setup(chip); diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 24ee4e1cc452..919bb0b88b12 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -190,6 +190,7 @@ static inline void tpm_msleep(unsigned int delay_msec) delay_msec * 1000); }; +int tpm_chip_startup(struct tpm_chip *chip); int tpm_chip_start(struct tpm_chip *chip); void tpm_chip_stop(struct tpm_chip *chip); struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index ddaf362e62c1..94a2bfb244b3 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1129,6 +1129,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); + + rc = tpm_chip_startup(chip); + if (rc) + goto out_err; + if (irq != -1) { /* * Before doing irq testing issue a command to the TPM in polling mode From patchwork Thu Nov 24 13:55:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 25550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3411239wrr; Thu, 24 Nov 2022 05:58:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf7pQd4mcItBuzAJgh8kThq1sbFWnZOcEYpXw5xHlK8eT6gs/M/YfFpT8NEUKkovhHVy0tkC X-Received: by 2002:a05:6402:520a:b0:459:4c7b:e852 with SMTP id s10-20020a056402520a00b004594c7be852mr17502108edd.347.1669298328931; Thu, 24 Nov 2022 05:58:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669298328; cv=none; d=google.com; s=arc-20160816; b=ZWJ2BdnwWQODBmlVopAn2+PoQ6XsTnTXiqySEJxVO5T2TbIKRYWxFsF/wEfza+6VZU dnKvbVqRj+YQgc2H/a6FnW+esrVqiXJp78qDGfJer5wj78RICG0PSQzz9g+w41BiCklz txpmXV6AbYDOVws0BP1NHCPlo1Ixv2dKj8jxMqZcvNJaahd8eifVuniPxuGfZbeoslJU NNFuULKRIQNx/hA3vXuBM+CRJFW67op3zcB7xVgHK7K6t0AsVInOg7HG76jj8JEMkQ8x FLvfJ6k9Q/NyLxSxx9VeuzOddXTVqQ39M4Xt0s07QdYo7qzKYDuljrDrGp4XSMLUWphl hTbw== 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=tNxzriKju7X09wVvY3INkMxvkZLtq7M5+64P/eal/h4=; b=YS84AP2She+P10iWcAEmLidlmKrNhBLnkoI6jsoYZDH5L2SOcCrKD3Yfy2q2aAQfw6 WyvFdpl7Ek4im7R9lByK7UFDByTaSMOCWJVldK1vw9dWEMc/3OJvA+KC73+vzsJXaqHv OTXjyZb7eNH0MMDs8EOMGdHX2t1WjlpOA1AjrTtCq2iffA3JZEBN8xQusq0J12Ti36xO jXRnGS2LrSkBpqhwiLrtjCdwKkqPsrNV6oSxtsW/G5v4gOlU6F+tAgmjQWTJ9PscP8UE oMqgL7QnOPhuSI9PkunF73zYvKXiElOVMaxQJxU+cIeV5Rq1q4PJSzxQWGVPvLEZV3q4 EFyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b="Ays7wa/u"; 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 ce11-20020a170906b24b00b0078e1b6060f7si739309ejb.299.2022.11.24.05.58.23; Thu, 24 Nov 2022 05:58: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="Ays7wa/u"; 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 S230337AbiKXN5X (ORCPT + 99 others); Thu, 24 Nov 2022 08:57:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbiKXN44 (ORCPT ); Thu, 24 Nov 2022 08:56:56 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C0151165B7; Thu, 24 Nov 2022 05:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669298175; bh=tNxzriKju7X09wVvY3INkMxvkZLtq7M5+64P/eal/h4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Ays7wa/uQDWJNn3ep6L/CDUcb4ZbmIcHpU+KmoMdvXBjKvK83GtjGEsyvd2qG0sIQ jXqfKpVOGzay688FLBVMEJRiKT2OV7HQ36O5Mkn6qQaVq7Zp7zHHdQX1bM+Qp/Lvjk P3RigZ7k0WeJWKs7u/gRcPTBe6BYpTP1ttD+kc4A5gPfl86ZDL0UcfGAVpnoMIGAn0 lN7SXSViEGsg6FMjYIMhIA1UYbXzdgnY+F3ixchd/bWFnHSKBju6+SvJPwT0XgqAHv bED6lKWY+e10CibuVdHMKIFk2XgZebcpcIpYr+0GoLrqN2ev56/+dqlfI0U51PgQD6 xWyhCwaiuS+ug== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.7.17]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MQe9s-1oaSkq35Hy-00Nkbe; Thu, 24 Nov 2022 14:56:14 +0100 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v11 14/14] tpm, tpm_tis: Enable interrupt test Date: Thu, 24 Nov 2022 14:55:38 +0100 Message-Id: <20221124135538.31020-15-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221124135538.31020-1-LinoSanfilippo@gmx.de> References: <20221124135538.31020-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xfdO2tuW/H6iYYoumuTl2JI/87L4z6XQerQt8f+R27hsPCrO64Z JwwfgAMboMKyAW+te2wxvETCWMQl9n7oGkgVUgttVuzOj8mppqb7n8fDCtqi3gU1NkCuN4I 8LP8lBZUixMLA2IPpHG9hkg1CYcxXkcQZMY7SDAVvbLzkKFnCKKLNHH388WCpvJ3+iHELmx 06AlFwwV950PY1Vn1fsLQ== UI-OutboundReport: notjunk:1;M01:P0:1X7tueyk1qI=;cI7BBTNCszsaJNj810LcBY0NURn uUcFyWg8EsV5Iz5QF46XdeZhniFC8uMWGw4gXOHAXbzn+q8gbtvSsKKV8eY4hK7RlJnn9sRSg 2Ug/tnVjG+HSmx+j0z5Jii9oE/m7TF16M41Qt4mmYGiWEhWk+pMaiSwHSyHDmNnfGHBtr5QE3 aRmggsoxFYZGsrlmfRojCDjLiASKcpDPrwFqhAmievr+2HXfPCf2ACnTjrqaqgsg75FrQ1UGg dLNV+2O3sfYKhceOcfAkqr7XJtQNksALkXcxOhUOx3mWWGATFG1byaXFGkCac1Zfu4gUSAxiB 23Z7j60SLUP+vqMLOqXMObULp2xJr/DkpYzpFkcnR5FzirSHIqUs7Pz+68xJDCEOODT8zaiwv OTMQlt8uwu6Qu87Mu++czibfjbBzRh9be+rjxCNbMZd3jZoyalXQcLtE3M8H0Nyf8/1JF2sys UKUnrQ9qUyPv/RVFD10Au9zn/+i2+ZEzYFjjUaO2czM2lHwtd89NiKaipU+WRBl3zeZC/iK7o jxgeWrECkTBMowMMQ2ReCtRE6Zbn310uahyYwGzdxlVcAghq/nZcTfz8eu4Ouwx6xwZ7psZgU 2mfmUyLmxOv64aKvNOUIaQvqWdndXP96qZkIRgdzix4FVQBFgCOSwoMH5TzxHuMO+X4fcEbSL lf17I0Cdkj27nlqBJci2Ps12+NnlmUNf7vlshbiXT5R1WUXs/kZBxA54+N9kALIQyKuWScJvf 4Z1fdDg8JMBuw7INIZ1c1a4DxQ4SFJQySCkDa7/+1fxNSn0qMYwT9Cc98EJHoysAjzlSHo8EF Epy6CrgVvaNX5HwwH6bC0WDZ5UqMxEYDPV0H3gOvMA3aKIxoZTcyytTP3wju1pYUPXCHsu3G7 jsW4BqTXcX/5Ot24Wdww+BJCDeUCNE4N+sesPYPF8FkSqU1Qps1oNWjWpnQt56Vd4tkLRWerF 6GPs7ot75nofwZMUtwA+18S73Co= 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?1750386164699440031?= X-GMAIL-MSGID: =?utf-8?q?1750386164699440031?= From: Lino Sanfilippo The test for interrupts in tpm_tis_send() is skipped if the flag TPM_CHIP_FLAG_IRQ is not set. Since the current code never sets the flag initially the test is never executed. Fix this by setting the flag in tpm_tis_gen_interrupt() right after interrupts have been enabled and before the test is executed. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 94a2bfb244b3..602ca4bb8e2f 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -789,10 +789,15 @@ static void tpm_tis_gen_interrupt(struct tpm_chip *chip) cap_t cap; int ret; + chip->flags |= TPM_CHIP_FLAG_IRQ; + if (chip->flags & TPM_CHIP_FLAG_TPM2) ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + + if (ret) + chip->flags &= ~TPM_CHIP_FLAG_IRQ; } /* Register the IRQ and issue a command that will cause an interrupt. If an