From patchwork Wed Jun 29 23:26:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EDC4CCA47E for ; Wed, 29 Jun 2022 23:27:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231378AbiF2X1k (ORCPT ); Wed, 29 Jun 2022 19:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbiF2X1i (ORCPT ); Wed, 29 Jun 2022 19:27:38 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B48225586; Wed, 29 Jun 2022 16:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545243; bh=DIND2TdGrcdcYcqNbcqvgd28SywcZMNNgfngQqDPZoI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=WEN0wniqlUYqgtosjaxt1AVqRjrbpV+PQrTchivii79X+O4e/VnFlhBfggY9l5uV8 HAUyH2ji7Zu3lZPjvlmt/X/japjdHbwnLg4zAjYfAEYlDSwx6Aa6DFj825KL+x2ozK g76JGIYvWoVYmz9RIX9yAserdPnJ14b3EP82/C2k= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N3bWr-1ngwe02cgl-010ggW; Thu, 30 Jun 2022 01:27:23 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 01/10] tpm, tpm_tis: Avoid cache incoherency in test for interrupts Date: Thu, 30 Jun 2022 01:26:44 +0200 Message-Id: <20220629232653.1306735-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+VDe8/cKLoCmkTb+aHJfyXV9TreCCa6tzO/Fe8CFo/bXIy7RqZ8 AgH5CgNC3PX7/LALbPcvwACkjiz0b6vjXQ5fCzTXsmEzkoT3JvSbY/lqsuS35gDXbwClC5b d3UfRudOBi/4THwQBCVSoOEKyoLJp6CY/h53lsr5hCtxgMpRcxUYgdnVQa/0JMAQOdMd1/8 bbjcp6vz/FulqEC2+cVhQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:GvRzEbue8FE=:kMLBGcBRiAZcH1k2Dhyb4L WfZ/Ngo6b485xHUNB69L3blM/bYOLDS5Tq6MhvVJ0ZOmbZJC9vlsI9lKo0KCK9MwYVb4rqUtl 5xHB6hVGQN30ss2WOPVSdxijaI1w3hhBl16MgU6pP+Omc1t8wCwz/ZY8hfXbMXeNIeypgTgOQ EiRIhOxBBhPls/1aSAO1EGcD3m61YtMaPMWzTKUUdsDaBUDfdxLVpQTyYLJUgmNYMtO9P1r1n lCm+GG7coQp6JvUEScq7NHgnM3sQL7RLT3pzaXJWTjZho8dvkLUid5Cb3Ovibl/DiDfYUJR9y +PxkVEtmTez7nWjbdguoNq1635EvPMeBP4QnAMfA0Ws9YrZLV/ZUMLp38uYi/NhwaDMNfjmIt Mz+JE8lFiJs06rGhn2Nmo173KTh5PQXPRBNo3q93SrBbL4TFoRhKbsWNrjpo3otoQ3xgjIcI1 LFri5FpCFxlBpT+MaWvww/QQC8no/kSuxobQxV7IpUS2YfjHmE0WqrY69MJLT/8OBwRXnFs2X 2V7JQJ97HtcV4iXjxkCkFWU3E8qGnWwPSf/QluZk2DkZI2ey5CDia4qKKptOjkSLhbajDVnzZ Y32ILTr8hL+LHVETtVbjK7P2cwnzDoJ1dL2NkAxjE9deTLPbQnAFuAjDN/DVmeK3luamPKJhc WDJyN/TTZcq/E7IL56LnRrjDiD8rYbYyVZ+Og2d76nJW+j9Y7HjQ9Ck6xoNtq6py34bAUBioK FUogdd4JtoaQBdMppzuBHAxDXYc8Acq/tLPh1y+Ohp4Fup7JUa687IDhXwVMha+rBx1I3+E3u IJBMx16pSxC5ptzCUhLSeF0oVOhOjW9pMujDki1c0XeQfLlkYpM+E8bHMOPe3YpxTTbTplKXg B9w7eBVvHeWOWxuCfdjkii2SVNUwGJyohG38fe2/pWGoMLk/EwR9SUHMidNimkLLmEcuVMX4v dgqIigJPHox/A1EVxXHxGEgUbRhnlO0kMRUqMXJnPOS3XqsQlGXID1uDXSrSaZIh4Dggumt4k 4myt4ZE5/nWL0AdZLPbdmfS2n2sHphEqXiIm0kHjrSH09KsaZ6sgJ7//PU5p4r58oEMbygLuu xEsYUAwB2CO87b7e8LdwYCyDm18P6XLnnsCGJcnShga/1XlDX9c8ZHq4Q== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo The interrupt handler that sets the boolean variable irq_tested may run on another CPU as the thread that checks irq_tested as part of the irq test in tmp_tis_send(). Since nothing guarantees cache coherency between CPUs for unsynchronized accesses to boolean variables the testing thread might not perceive the value change done in the interrupt handler. Avoid this issue by 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 dc56b976d816..b5fd4ff46666 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -343,7 +343,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) { @@ -470,7 +470,8 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) int rc, irq; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested) + if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || + test_bit(TPM_TIS_IRQ_TESTED, &priv->flags)) return tpm_tis_send_main(chip, buf, len); /* Verify receipt of the expected IRQ */ @@ -480,11 +481,11 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) rc = tpm_tis_send_main(chip, buf, len); priv->irq = irq; chip->flags |= TPM_CHIP_FLAG_IRQ; - if (!priv->irq_tested) + if (!test_bit(TPM_TIS_IRQ_TESTED, &priv->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; } @@ -627,7 +628,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); @@ -647,13 +648,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; } @@ -693,7 +694,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) if (interrupt == 0) return IRQ_NONE; - priv->irq_tested = true; + set_bit(TPM_TIS_IRQ_TESTED, &priv->flags); if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&priv->read_queue); if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) @@ -779,7 +780,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, if (rc < 0) return rc; - priv->irq_tested = false; + clear_bit(TPM_TIS_IRQ_TESTED, &priv->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 6c203f36b8a1..bf07379dea42 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 Wed Jun 29 23:26:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6655CCA481 for ; Wed, 29 Jun 2022 23:27:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbiF2X1l (ORCPT ); Wed, 29 Jun 2022 19:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231205AbiF2X1i (ORCPT ); Wed, 29 Jun 2022 19:27:38 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81E1A24F13; Wed, 29 Jun 2022 16:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545244; bh=rvhNW71j9WjbkK+WwiRm/itDduq081D1SK95P44Pd40=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=DQPILKvBISTA7EHXGHDLqdtdxTZWToCf8pSAI0rmVMWdSp6lltGq+tFW6qVgSa4+s sQBUCsHxHc9rOEzeUhfXAJ44hYyQOEtzmkdJjzq4q9Ow+p9RnMpyIRBVgwdmnTNOqp gcZmAc6BQXYAkYcijNI0TDZSEzuJguhS5mfUd3dg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MirjS-1nRpxQ00pw-00eqix; Thu, 30 Jun 2022 01:27:24 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 02/10] tpm, tpm_tis: Claim locality before writing TPM_INT_ENABLE register Date: Thu, 30 Jun 2022 01:26:45 +0200 Message-Id: <20220629232653.1306735-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:lCmI/VIZRRhTn9k7p1XCSCVWoC8yP5MpZUkj0y+lB/CYEgL7Uak cp/85+QHwaJrGXOBeahieR2MwW4CVQG/30f8NPUa9Yo7h1Tc3ZUoM00OnToI+fjFMdt8Tc5 ha2CebNSuUA9eR9fK3DeZ7oS/Yz+hBKHyTPo1GI/mnuGJVuGM8JDEGEBAF+W9kd9MGJqdqg zWMa1rcZQI/JKnhTsrYGw== X-UI-Out-Filterresults: notjunk:1;V03:K0:neVAYdnlpbM=:Snqgt/Ij9MzApfs3mv9PMG xv2KXxQpJttBxqfVw5tHnrtpfh8FWfmyI8bRTZf6HFzmrTSB7NqEg6mdhVzQdK8cHOXWSY1xV R/ttwXmV1z2zIyn9QGycoHjvJECL8+68s3N6o+1B+PU3z8sC+lYKILZrTaUcA0h24oO3PvitQ qIu5x9MxbNVfrynU6VsuuOZcSa/k+g06DyC9ML9aW5SQ5UXvIx5bEvwqg5JV8CQKQA0XIh5QG G59Yqy+qAa9cRmwXfmjA35oyPT/GLecagdKpECkKisqAi8+rQ6zce8/lQfKJF2FhY3a0SYGPB gWSYAHCyFzXqaffcj8rVkuH3sYl44vBayXmdlhW7lDKL/KR2q4RoMC7Y56ql/Ba9U6KBAFy6z 5xSy8/FjIRTwhKz3bgRS9UKwPGT/08JQKntq+bv353xbmZHrUJmsU6I8SisqnQcx/eldenxiQ CkVJCgSjDZ+HP5eDbf2qqGgf8Dj1vpoL6Dxj3K70U8+b3sSifAXWpAFu+6UZxjWsIOMvroF1t YFBhD19opUrnf0aC+QN2WHwZwq905VNUbUlJFCCSy+3Vtrd9Sb4uOTE8gLx3E4cp5YGBadFHa 0edkTMOTLTDRkeRKxuEWLgg4fUkSMM6R3cQN2I0BN6D7xYl1XFuEBLpeomY4psl6KsR8PNmvi trVwllMcBH3YgUXpEcK2Y6UXhleAvi0/vqaLn1t1G3gNDZxaS463uVLzbjGAJJlFHdrZ8yTVH kZ02Si71Wa2r9EThy/UBfPIsMq179RYLwUisLuTN6tCxTuu3uIos/vVwcGfO8yElFz94lJmzR bUUGV8tvnLFV4Fq76WGTYPaPl0UGwRnzFKrN50oYCDS6Iap5bwBTUBRFCpZph9bCQ+Lt3b6qS CptdMjqjsbu1OwAPZ21SX8hZP0Y6ouxK/wXpuQERvlx6sieuzg7XxslwB1uD0fyxaDidDZdiN MRj7VcPO/Qku3zeLZX0rSqln/DmaSLTPhnsfD9ejn9g/eSOLP6Mq9zMN3hNxytdDfKW+3r2NZ toYANi4j0L5iRxRkFdkRZxyJtZNPiabjPtBkg5CA1aOIqaM2Ise/n+CqrR260a5WR70mscuLo F/kTbJfNcGJ43+XrQRJYv80ldZYM1ZkbZatcYiaL/MHgUESkmr9cbGoQg== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo In disable_interrupts() the TPM_GLOBAL_INT_ENABLE bit is unset in the TPM_INT_ENABLE register to shut the interrupts off. However modifying the register is only possible with a held locality. So claim the locality before disable_interrupts() is called. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index b5fd4ff46666..0e68e4502a56 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1084,7 +1084,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; disable_interrupts(chip); + release_locality(chip, 0); } } else { tpm_tis_probe_irq(chip, intmask); From patchwork Wed Jun 29 23:26:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D339BC43334 for ; Wed, 29 Jun 2022 23:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231361AbiF2X1k (ORCPT ); Wed, 29 Jun 2022 19:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229821AbiF2X1i (ORCPT ); Wed, 29 Jun 2022 19:27:38 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F27525280; Wed, 29 Jun 2022 16:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545244; bh=8bvwjFzHTyN26RyydHQkqmMi4yXOCOXQzUZ4H55Cz3k=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=FrsMyOxlLPHj0Tow/axOBTr3wlJNmmROtrdlpcVVoUeQmcl/RGCOQkXVXSW35BWSI Ki0mRaewvoU/C8AYf4R6lmeY4TXro7fukJGoMTyrvC4Sq4hpQYMujgVkeisFyRzqET gHhT3PGBVaX7Nk2J1khj33UnKwj1eKqXasCtqA1c= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mlf0K-1nP8oQ1bs2-00ikC5; Thu, 30 Jun 2022 01:27:24 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 03/10] tpm, tpm_tis: Disable interrupts if tpm_tis_probe_irq() failed Date: Thu, 30 Jun 2022 01:26:46 +0200 Message-Id: <20220629232653.1306735-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ZEm7Xr3wPZL8SwaVhzJKfajnZv1T/Wh0WBV/B78vB3xkgDwvz9V OMdOhATHxNjcxay4ENz7BvqLOhPr01uXgKAWKChBQjY/Beqt84zAQP7opn2qHGDvpAxNDUw Lv3YR4+k6iMS4NNXdCziEVGYSK5J/4GbSEtme5A3DmDO82PmQiYDPJRZmJWRXm9Dhz7Hfyr ZLVwbvAlgog34Z33wkxDw== X-UI-Out-Filterresults: notjunk:1;V03:K0:WzdQ9i/npDM=:3pl8kCLN1WwvFMKdq5JqUm pkga61uB3/gyge304Fy7pqsZGRkkxk5FkYDYDp35jME8pLAWTY6YjwZj6wv/z2FBEmMKYSITn M5Ip6LI0yOgIW72QtEWEPKDssTEBfrtO8iXMkqxSC/8p4iNKM+RXDwjfKIKy5N5LnxvguCEse CMU1gRu0LU7wq4a+Yex1A05tKIL7dPJK8B/SHaET7rVtD0g0IPI4iCpm9VoUzL7aY8UaQLk9N xL2hxwhtz3mb9kB7SzM9afJnmjNSLKLo7aiJ1QHWZid3h3NYGLA3xSRA6kuzyrxms1IOVRQb2 5Wzbtx4i92FXWvINMQBJzz1GTvk3ye/0fBhG3oZFuYt8NvT+64rb9mkAxG0W7u4spzG2imOp+ wH4SRD2smbU3z61E0z3t4dUB5crLd88mGypn5FspxRZApky1zPK/CMyxBAGwBruDhV10dnaTG 7u2WYeGiOyD+JTGiQzTD9wdsxe/ggAMnuU78BqpBlzLs1u7QEZi0FKVU2nKv8w7ym2axyFpVL JgiVSvC3vExMGD7vfJlka00T55xzSLMhLRLKDbB8kYLhUDF/W2fEbGErk8rbKUAI+Ifekywyw TUzZJkzq9mxP767JjUQxI+XSY+INR+5ZEs6CSFf6d47JA/Bmp33XNiei9Zj41/rNnskt9/S8J H38F1WYlX0eYjO4yowxSBltWSlwR62xcPZs042OUncHNeBUcG2M5cOtuszTMLgTVXFywWdqRU db9QEiVLDnr8TK/ZTIKHJfCXtZnQ7+54mU7MtJt5BQAehSNiVkJ43RFXoEhwGOcapA1+Aix6d ngQKFpEgoZtdWnWBym0Vyg/4DhWqEjLZlcOuwNy4nOCZmpIL8+SqWE7WIq9dpUp7J8cz/Ebx4 HsRMP4YLwjIlj6gkGzRMqToCMWCoZcSV5xnQE8pdDws8JyxcHK5JVwo+grvVIjfH0JeZuYxZ+ xttIZgSWptGxU+zlhaf7M3bfCjhN1gVvKgflvvyzDx/MBT5WTDZEHmxod51GGjrnnBEx9Jfdm Wx8nQT+dyAF2M2DTkRvqCfOvKJEx05mrZHfkTo8WIvM/NLYGPgWtrBLDRhKs3l68r6np6rGmz 1K6bXx4ZdPtiHy2IVSIgKkJ+IIrAOTm/wWm9oc/YlnXliDJQjWWjDl/Rw== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Both functions tpm_tis_probe_irq_single() and tpm_tis_probe_irq() may setup the interrupts and then return with an error. This case is indicated by a missing TPM_CHIP_FLAG_IRQ flag in chip->flags. Currently the interrupt setup is only undone if tpm_tis_probe_irq_single() fails. Undo the setup also if tpm_tis_probe_irq() fails. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 0e68e4502a56..d32e93c86f48 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1077,21 +1077,21 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - if (irq) { + if (irq) tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED, irq); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { - dev_err(&chip->dev, FW_BUG + else + tpm_tis_probe_irq(chip, intmask); + + if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); - rc = request_locality(chip, 0); - if (rc < 0) - goto out_err; - disable_interrupts(chip); - release_locality(chip, 0); - } - } else { - tpm_tis_probe_irq(chip, intmask); + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; + disable_interrupts(chip); + release_locality(chip, 0); } } From patchwork Wed Jun 29 23:26:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9FE6CCA47C for ; Wed, 29 Jun 2022 23:27:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231393AbiF2X1l (ORCPT ); Wed, 29 Jun 2022 19:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231143AbiF2X1i (ORCPT ); Wed, 29 Jun 2022 19:27:38 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 236FA2558B; Wed, 29 Jun 2022 16:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545245; bh=o0C44923qTpK68+z577TDUD6416MfHxXXHwGvB8ySvI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=fgNkEG16d5mUk2r2YeQsHTWM1ctILEQM04NnkKlnvzR0syPOp81aJdYx8fKcpUUAL Bbz2MvHQDT7Ha3Cl+/882oFbnBd/GNHlqJtp35s6cqErqhfIoVctIhH9FOrPThd7Dc QZOitoi5Iuf5Gi0EwdgyFh6ddlNEs1MHjEiB9Dkg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MZCfD-1oBJe93Acj-00VBgs; Thu, 30 Jun 2022 01:27:24 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 04/10] tpm, tmp_tis: Claim locality before writing interrupt registers Date: Thu, 30 Jun 2022 01:26:47 +0200 Message-Id: <20220629232653.1306735-5-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:HzRj5Rb2KA7Nu5VSQVaUmCPY8sGIHyFlrsjDdpV90jnEsvtYn01 +rLxPPjeW3H5Q4fYCy/4jweYnDv0KQyPi7vzd7wWuWu2TYYlG1mjL4Gvhkvydy7J5Gl1qYV gmZgKQIIB9itEX5vnDZSyPQliUsXItSnUR0lNOWqFcyLwch/BUUMa3jY4R3k1nqVKuP6E8r V7Q5Ixwg2yRWA/HQ2hgvQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:PeaggYm+1DE=:9OBtesXyF9wQ9o1wIITlyk FVPjw+xxyB3EzeTO6odteVyYTqBgDV1pMxWxOaByHXid5ZQySNmD09d/3jO43zC2hoTDsY9D/ FDx/9YdIOzL3679UDVEuWjmR3Lsi44c2orrZBOLzc6+C1I8HUONWZYVjO5wPYNvGKdQWDQ14i 6LMLwYgHuGQzQh4dwRSWF3ScMV/clTezkMqG0WIib5w30TCSaDLkHHgb8lsLFJAs/kW7i0tmC ZZnyfan3sthR6wnnL2AeLnfblu+bgjvpl1iKr0GdmxQMm36j7smqQnzYltN2BrzLgwcnP6AxA 5CmckGY3RGujbd0w0McIGs8R8qGZooUm727viJGqbxF7ZKIM4sa4v0fsQmwEOY8UTZ2vC+I+7 V0yetN67UW4Bgfv5axNvscqkcgqQOYyQQBjLlxpuNDA931jYFaWpr6bcqLdanTJvN9fniSKdo 5d7IF7ZXaOTbbmG0FI9G0mBAYaDUxPnmmvz2wJTB/3bMcwhF5I0MdgANMewFhI5sDUZNlPpcZ Vl0y0iAZoH01pa9el7fzaQ2btnOaFIiOlWg+0yQFphHNkSwonakZ8aDVUVdgtj+ffONw5v+3a J0iWxEPAOReCQ1NVSdgtQCBbHZ9+jUMXx7h6ScLaKitU6PJP4wLT1TeuiCieuawuU3yGqbhGi G+9NojNf2R9eCWFFy62P5QWNf2Pf32iPxtbNZZ1jZpIny58Io//9ts90WwHNO0sryypgv4i5O +LKyPjyIbwRzMqhL877IlA3UiJPp4wVy0+Y+mqkePYyaID9qN8UR9Ga6mP5ikP+mnUkHg7Rtm XDxtVGRfMguUodVsibAHG97Il1otv9V9EImgCvYxmMEiZWSeCP/kGiYc37g5IX3a9d3xQ4M6A jhZz4plEt+KlWPaDXQdy119pczl7pu7FCl9k9CamlULJ+PfZRXdT1y8RfhIk0gSMaG69ATYRJ ZMheYx3E2Prira35dwv6F0JgCRH/wgAxpOCH4WXiQNh05v3ieUp7JZX0EzXtOOHSQpYDbnsOC t0aIuQYQNAJ9UVdpKxjV5EbvdoGaEoGT/vzIeGLpGrJ2wMXeg0od9AnVT9VVs/oHOFSXx84qr GNenFTpgls78BTQ5/D3xK2QLrPUkYUPjGdLnRLbQdupkdem0W9PE+xp1Q== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo In tpm_tis_probe_single_irq() interrupt registers TPM_INT_VECTOR, TPM_INT_STATUS and TPM_INT_ENABLE are modified to setup the interrupts. Currently these modifications are done without holding a locality thus they have no effect. Fix this by claiming the (default) locality before the registers are written. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index d32e93c86f48..09d8f04cbc81 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -756,30 +756,45 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, } priv->irq = irq; + rc = request_locality(chip, 0); + if (rc < 0) + return rc; + rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality), &original_int_vec); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } /* Turn on */ rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); - if (rc < 0) + if (rc < 0) { + release_locality(chip, priv->locality); return rc; + } + release_locality(chip, priv->locality); clear_bit(TPM_TIS_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to From patchwork Wed Jun 29 23:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1ECAC43334 for ; Wed, 29 Jun 2022 23:27:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229821AbiF2X1m (ORCPT ); Wed, 29 Jun 2022 19:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbiF2X1j (ORCPT ); Wed, 29 Jun 2022 19:27:39 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDB91255B9; Wed, 29 Jun 2022 16:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545245; bh=OxT6orG/M1ZoEPE31KTuTtlu7fY3J7clKbTWUReYR3E=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=AICp0kL+UNCRRslzxDIC3IorVL/hk2Xh8wm7n1fgMMoxrgcsjhk0gm7vq2uMMKDqz LDuC2oDDfi3P0sTQCfxAv1c+/QkSsNGIfvmfMdysMCNa80UfE/dZNn3qD2llIxdW2Q bxUc8zCIe7bgYMCI+mwSNAOZol/komn/tfudTlXo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MK3Rs-1oLSWB0XFe-00LXS5; Thu, 30 Jun 2022 01:27:25 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 05/10] tpm, tpm_tis: Only handle supported interrupts Date: Thu, 30 Jun 2022 01:26:48 +0200 Message-Id: <20220629232653.1306735-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:YG934ZGUnKJQRghRcLKlPcTHwIXbpcVYxg/nNlYt0aycyfeLYjB Vzxm4atoO4qDUKm7TuVHx22Xs8LeLk8vg64+VxXv1aR85pXqbx5oLYi+jxUvavBg/7TnUXi FW9GReqDrfJX3+n7td4MFD29MShLW1RiV9NqEFPRNgzymA0jBghcJK879Y6KbaR1KRBjVaX lF4jrrcrIbBl23980FYYA== X-UI-Out-Filterresults: notjunk:1;V03:K0:l95XRWW19XU=:bsoR4jlGol1mxZubUDJvdO tfiuzWkcdAZZ/0PZZcWGi4QQDZQBQlM2CHfm+mLTb5HN7qWziVEOCGlfbd3SmVAdu9GtwVOGU 0HMDzPNt5Ehl8peIJJGFMDd5CNIVvgSX05LqQPVdqI8w9f1B8/E1FxBsx2daaQWQut8IWPYJN YscYBOTRtR2TJEasuFRgzA7nI0ZMnjAVMAgWfcqPkjXCuH4iFl8M6Clw+nasqU9bl3a6HdwW5 kXydEN71S/fS3lTyEv7n70JF94wb6KUm3tnUCfgwgAo9O+9/S3V5CCwPXd3nsibxODVOGc0HP xFnNoKDuMvZFq4gHr0oURpZoZT3YBcLQyu/8yCQmS3pF1Oervf0Pll3wo+6G8i4KwdDpQFjna TwdWyn4skEhofhyZEhfFAHf4koCyjyte0WPaE18MacKcqMRLkKkFYFh0ZHDWu5iOLTs02N9VB tbyHWcrdnvvL6usmXS0I67zfV47t+1TQNA5fREwPCJOdXXMDeMD5fN0JIPAhxbbUNq5ZfXfE5 AhV1UTZWbusE6kfg7dN7yuR0P27qTn8E5yVZB53HHaCsnzNeoGnkEg/gvZ4A0cnBBTVaOJ+E6 8ln707k1Ti76PZRmKJGqJ9T0yrZEtLeGuXCwR3jfP7x8W7pZXtgF315YZwhnxiD5KLI50zF6p 7EpQPnaLVbDPF1Vp78OFGIP60/U4i06t9oPf/LiXZVgmvxCt4Y6HehaeO45kLnEUBfQPCiYYa TC1A7TRbHuYIF3gWwZPCJJ4gd3UaRLiCIbGnk99FvwTeEgDcb986C7NYE4RtXhMMXrjRo++zs SGYtvupu/6IpWW1ruoc5rIOy0Qnb9ApKBMCWRFEg77GEm6L47P8OiPmVkjr6+BCMDJcbaEZFJ XfytOLy3V1dpC7f+eh9+SjdXmCH1oxn2Rtfh0XIrk9sL0y1/2/OALbSB+pdffyAd3ifJ5hpso z6FU/+UqGBcQPRzqbkJ7ifT+qQ5JgT++pMnv/wm8RjwplzJuQKCg1yfH9tEyM/4J4EsWiBcX4 rn5p+usSdKqPGCHZ4oyVnTW8vp56N7NFzRzQJowgf2OZbUZm3GGSkOSZ0QaFi5ahe0SheUvjh kT7gNrfSOOEZZpz4nRCTiYva4BzgVwj4cw6W703FUWYJp0UE75D3qAygg== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo According to the TPM Interface Specification (TIS) support for "stsValid" and "commandReady" interrupts is only optional. This has to be taken into account when handling the interrupts in functions like wait_for_tpm_stat(). To determine the supported interrupts use the capability query. Also adjust wait_for_tpm_stat() to only wait for interrupt reported status changes. After that process all the remaining status changes by polling the status register. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 119 +++++++++++++++++++------------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 72 insertions(+), 48 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 09d8f04cbc81..c13599e94ab6 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 which 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; } @@ -1007,8 +1029,39 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, if (rc < 0) goto out_err; - intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT | - TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT; + /* Figure out the capabilities */ + rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); + if (rc < 0) + goto out_err; + + dev_dbg(dev, "TPM interface capabilities (0x%x):\n", + intfcaps); + if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) + dev_dbg(dev, "\tBurst Count Static\n"); + if (intfcaps & TPM_INTF_CMD_READY_INT) { + intmask |= TPM_INTF_CMD_READY_INT; + dev_dbg(dev, "\tCommand Ready Int Support\n"); + } + if (intfcaps & TPM_INTF_INT_EDGE_FALLING) + dev_dbg(dev, "\tInterrupt Edge Falling\n"); + if (intfcaps & TPM_INTF_INT_EDGE_RISING) + dev_dbg(dev, "\tInterrupt Edge Rising\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_LOW) + dev_dbg(dev, "\tInterrupt Level Low\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) + dev_dbg(dev, "\tInterrupt Level High\n"); + if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) + intmask |= TPM_INTF_LOCALITY_CHANGE_INT; + dev_dbg(dev, "\tLocality Change Int Support\n"); + if (intfcaps & TPM_INTF_STS_VALID_INT) { + intmask |= TPM_INTF_STS_VALID_INT; + dev_dbg(dev, "\tSts Valid Int Support\n"); + } + if (intfcaps & TPM_INTF_DATA_AVAIL_INT) { + intmask |= TPM_INTF_DATA_AVAIL_INT; + dev_dbg(dev, "\tData Avail Int Support\n"); + } + intmask &= ~TPM_GLOBAL_INT_ENABLE; rc = request_locality(chip, 0); @@ -1042,32 +1095,6 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - /* Figure out the capabilities */ - rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); - if (rc < 0) - goto out_err; - - dev_dbg(dev, "TPM interface capabilities (0x%x):\n", - intfcaps); - if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) - dev_dbg(dev, "\tBurst Count Static\n"); - if (intfcaps & TPM_INTF_CMD_READY_INT) - dev_dbg(dev, "\tCommand Ready Int Support\n"); - if (intfcaps & TPM_INTF_INT_EDGE_FALLING) - dev_dbg(dev, "\tInterrupt Edge Falling\n"); - if (intfcaps & TPM_INTF_INT_EDGE_RISING) - dev_dbg(dev, "\tInterrupt Edge Rising\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_LOW) - dev_dbg(dev, "\tInterrupt Level Low\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) - dev_dbg(dev, "\tInterrupt Level High\n"); - if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) - dev_dbg(dev, "\tLocality Change Int Support\n"); - if (intfcaps & TPM_INTF_STS_VALID_INT) - dev_dbg(dev, "\tSts Valid Int Support\n"); - if (intfcaps & TPM_INTF_DATA_AVAIL_INT) - dev_dbg(dev, "\tData Avail Int Support\n"); - /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); @@ -1098,7 +1125,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"); @@ -1145,13 +1174,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 bf07379dea42..e005eb99480e 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 Wed Jun 29 23:26:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9A30CCA47E for ; Wed, 29 Jun 2022 23:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231523AbiF2X1r (ORCPT ); Wed, 29 Jun 2022 19:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231368AbiF2X1k (ORCPT ); Wed, 29 Jun 2022 19:27:40 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7597624F13; Wed, 29 Jun 2022 16:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545245; bh=FO1qKvjwo5OYPnKK1TQ+U7MMExJ4/KOfblZ/tjJSnxI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=jtTO7FOnilg87GhuFWwBPTq/qv/GMfnu/MrKug3vt4+GVjenkEbVGxAGCAn3aKMs0 /BGnUY7D/HUMk1hbZluL60hnO/UqNijfROrt95whTlCFgA7lpL6Uo9iH1++A7k1X6k 7iBfo5oLl62nnCCjDTn4sXVk9YuiYy2MoxRAmDeg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N49lD-1ngOgG23zV-0108ik; Thu, 30 Jun 2022 01:27:25 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 06/10] tpm, tpm_tis: Move interrupt mask checks into own function Date: Thu, 30 Jun 2022 01:26:49 +0200 Message-Id: <20220629232653.1306735-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:NK8V6gYmS9shuxcrgqlJD2IVankIghQH/8sonM50vYYQWUMuy8/ M6RiAs5r3z2QL7Dq1LGMWSkqdc+/QXaqtXT5PfT1r1goRtROuQfOQ6zzGdPN0ZKhcNqYT7i R50Y+jzin0V7tRBJqXSxKagbDHcjJJpsMmcTh8suHkSqofml97iD24sxJJyI0Ua9CgWGWxg XV+CpN7+fUi3NapKcUqKA== X-UI-Out-Filterresults: notjunk:1;V03:K0:4zETysfYVlw=:Z4puwgExUg62rspa9x73sk HBeJyveXQ29pji3+OnyuK/bmRWdX3lqtN0rHD7eKyqhRs1Fkw9gBUL61ZtfA+T4DEGl39ABx2 IE4aoOlr8K3Xay++20AX+Iek28fkQ+pHHuZ1WspveKXUJsfWlRKKXqf/OsXl9ufkC4WqKnVsX qmv0USFh2sAFZywJh9mkBX4lLkpwuaDumfYc6jlf3EHcWjvJZXceLS7CG65G/dSvViXrDSogB 860dD/gEli6NrtuhRvsnFTM61LtdQ3jFO7LvXBs58Bxrc/nZ3yG/ObWJNdtWCt15+82u75Jdz 5PGWmkt5fiYa7j7KBgmXJTj74Vgf68brLcy8VxW/drNR2UZJRc/gRmREA+EAcTqzL6ReysysK h6wymat8V6PEhRaTB52leBE0j3HG3xHmim8677hWuTvIfars4rwBLqIHBMDMrjnKHSDvyMIt8 G6XpY6CTkj8q45YXhwXisizdRA2GzoOtelyOqdlq/jey3TwHpe69ixP2dRnlhO4CsD6SfkqLW BQSrIvjGUy4ewzMX4TebejFfbkd+jd6agnH84a4KB/BfvGDt/Mju5Xogn34mqa9BO88JpTMC+ dCeehcj/OAcGlBrPt5Ca0Rg0zNTlUsmW/LlfWPhol1w7Vu+baapj1MrV2Gs0Hp5qmSzz88hwK i4IsoZtyatfSBl/uV1cADxzJ1Rt0TMe14aBO/QHTgr+u+3z02VlCM6W82Pw/xGIjwhwLu+S+c 6+JS2otPjK7QGDInWdifGgw/vJYRTmTOAxgCA5oJo4xGkMycXsI70ZnkE3HPLHIOxPqMbKnFK tg2qIBKRi19zxJJ3gEc3G0O920yHmFv63uMsA/JKpBDYZcbjKX1VQ4ted4LxmM+DHDB0B3CeF aVcFvOHZ4f69Yjm1qnwEoPDaUK4NPnyoEpHR7DB9/4OpSH8jVWg0WJXeqqLIhZHdQjn3/F3Iu KsXD9cy49e86/3lo5TDdvBjZ06K4E/xBmsIdtuKEZZTm7cIpFBjVUn3OggTrS8VbN5nKFtR5E 6jLU2bk9mtnN6O7fLHBP3FyeLx1HFiLRTxdzkFdZw29QqyMAV9zIEAloxRSDKqYFr2Ht8g3Qn odH8HDvoUF4wLFQzeC4wXN9OJ668jvWNyrVGqElID7tsQoUCLA+7E+KIg== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Clean up wait_for_tpm_stat() by moving multiple similar interrupt mask checks into an own function. Signed-off-by: Lino Sanfilippo Suggested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index c13599e94ab6..bd4eeb0b2192 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 which 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 Wed Jun 29 23:26:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 464CBC433EF for ; Wed, 29 Jun 2022 23:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231159AbiF2X1q (ORCPT ); Wed, 29 Jun 2022 19:27:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbiF2X1j (ORCPT ); Wed, 29 Jun 2022 19:27:39 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4139D25E96; Wed, 29 Jun 2022 16:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545246; bh=Ao6e13p1aZ8k0TVF/ZFV/nK4nyhFpQ+3TpXuc/A/kmQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=BA/nD1dAD/a9sfE4zDBxVN+xL0jWIUEjM40ggzHoJG10+jFR6T5d9yy8NHiOT+4Y0 IIyG54PQnuibvLt1R8LQkGtLXZ5HoHLgutnt+xGB+ksHDxW84wIyvwukSAiCznN6f2 aER39wmGHoXreH5MrPqoreukbPqIiFamvkU+G1HY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M7b6l-1nzEpc3eyD-007yws; Thu, 30 Jun 2022 01:27:25 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 07/10] tmp, tmp_tis: Implement usage counter for locality Date: Thu, 30 Jun 2022 01:26:50 +0200 Message-Id: <20220629232653.1306735-8-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:NojbFqVNT2axLISAEAds6qZ1mjlpRrwCD/UN7O5naID7z3aXeoF +HFwNi9+GP1V/OTCmAzGSKzDu31SFzg7ntHFhWNq8lVhoSMyZKka2qgDji4u462+/leCMcD PPTFPd/IswpKqiF/nZP4PMhjS46SkMfHFmcHJ1UMaav+zqienKDlRh9MMKkmE0w4xRCsgR4 YlHBdPq3akF1ytYZdRD0g== X-UI-Out-Filterresults: notjunk:1;V03:K0:4q+weHVv0J8=:b9Wi+qWZpF6Z6JsNn+2VI1 H5qbuqzr2NdbtuwnnTgF6UxA/HITEAe2tJdlZsgROF+MFS/60aS+tJe7EXkanN0iuvtFDfofr GfHfz6cj3ZsmQc4CqDwc8lxkCk3lvH5WiEm1jj3sBJrrXp+tVJnzQIfKHyvE8KlasH9brRDpx d6TNVcpe/pFAzjcO8ikzBQaIb2rSSesiEDOTupecPT+umam4xFG59aGlqfkJMyRiPzmacFijt sdrxKayc4gEcGj/y1vto85WvaOS21VOggWi02SZaziUDRQGK+NE0D3Q2+LTy6c3CS+Aaz6+4v c7yH9qgrTeNaIUjgv/jJ25uGbXtdsJaCK6FW5zh669tOJ4F9GhHBvDERcEgLsNHflWIZmwJMu WXlj/zKuuJY+swJghUMErjq2PQMZtwsobfYey9wzJfYSRooyXF4BqpmIT7KEU5Cu9rp+4Ub3Q yH6cihhSwXYLT56gbKQUxR/PSoPcoo3HjoDHcn75euXs9Gd9zR2LVA4Z8yA6UWYfbZLdzspRJ 17V8WbYD83VOQRWY2fYTHihXokdeGeaMMVJCVJyAK/oSxeiyLne7/L6z0UQbVcaBKTZ/jdYsC N+vx+4Y0SFYLYPBzOgbaY3OOG8xujdxevJ0D4Mxpokp8VDUkjZG415/eM1qTnORVJexo7WnW2 E9k2nqsX776lWNmaYHAecVGf6NDwfdU2il8mdOVjbKQsaWTPFzOHAY25uu4S2v1/iWCKjYZYh FUPcyGkfSeWISyaw2c1VoQhxw7eOW5i5Nb6Xe0vTOCp7UIBMq5iKXBeKHMULXhT71LZllF5iK Fmzashn2SEtBABhGHEN00NTV20HWeOCSeKYB7L3e8qLdd1LZLmyj+7qTNWppheIpYOdE3/Dqa imtjBoGRd1EO6ObaAd1f9f7OiZi3KMg9OKmqR5ySLzXRQY6QjpC6JrDj+6w0xlypIVnOhsUWk r6tGarDN3+tTr8GfZ/Vb+2IKt8SdHvj46k2Im0mDgVmUs5GqGaUGRF7u350JXAGsH6WLF0JtU 0gE1CHJu9BBgyQC0LzncnEqPkXQLC65L7x280J8pnEez3Qjj3REMQPKIhv+TYjXsZaKiNJjog L9D7yyNwZbzhYooB+BZFZcCfcvUyt1Hknm7KyKk6lQ9YSoVr09tDJh9Bg== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Implement a usage counter for the (default) locality used by the TPM TIS driver: Request the locality from the TPM if it has not been claimed yet, otherwise only increment the counter. Also release the locality if the counter is 0 otherwise only decrement the counter. Ensure thread-safety by protecting the counter with a mutex. This allows to request and release the locality from a thread and the interrupt handler at the same time without the danger to interfere with each other. By doing this refactor the names of the amended functions to use the proper prefix. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 75 ++++++++++++++++++++++----------- drivers/char/tpm/tpm_tis_core.h | 2 + 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index bd4eeb0b2192..e50a2c78de9f 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_release_locality_locked(struct tpm_tis_data *priv, int l) +{ + tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + + return 0; +} + +static int tpm_tis_release_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); + mutex_lock(&priv->locality_count_mutex); + priv->locality_count--; + if (priv->locality_count == 0) + tpm_tis_release_locality_locked(priv, l); + mutex_unlock(&priv->locality_count_mutex); return 0; } -static int request_locality(struct tpm_chip *chip, int l) +static int tpm_tis_request_locality_locked(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_locked(chip, l); + if (!ret) + priv->locality_count++; + mutex_unlock(&priv->locality_count_mutex); + return ret; +} + static u8 tpm_tis_status(struct tpm_chip *chip) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); @@ -668,7 +693,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); @@ -689,7 +714,7 @@ static int probe_itpm(struct tpm_chip *chip) out: tpm_tis_ready(chip); - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } @@ -751,7 +776,7 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) cap_t cap; int ret; - ret = request_locality(chip, 0); + ret = tpm_tis_request_locality(chip, 0); if (ret < 0) return ret; @@ -760,7 +785,7 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) else ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); - release_locality(chip, 0); + tpm_tis_release_locality(chip, 0); return ret; } @@ -785,33 +810,33 @@ 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_release_locality(chip, priv->locality); return rc; } rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } /* Clear all existing */ rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } @@ -819,11 +844,11 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask | TPM_GLOBAL_INT_ENABLE); if (rc < 0) { - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); return rc; } - release_locality(chip, priv->locality); + tpm_tis_release_locality(chip, priv->locality); clear_bit(TPM_TIS_IRQ_TESTED, &priv->flags); /* Generate an interrupt by having the core call through to @@ -959,8 +984,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_release_locality, .clk_enable = tpm_tis_clkrun_enable, }; @@ -994,6 +1019,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); @@ -1071,14 +1098,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_release_locality(chip, 0); rc = tpm_chip_start(chip); if (rc) @@ -1112,13 +1139,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_release_locality(chip, 0); if (rc) { dev_err(dev, "Could not get TPM timeouts and durations\n"); @@ -1138,11 +1165,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_release_locality(chip, 0); } } @@ -1209,13 +1236,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_release_locality(chip, 0); } return 0; diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index e005eb99480e..7c6c14707e31 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 Wed Jun 29 23:26:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7956C3F2D4 for ; Wed, 29 Jun 2022 23:27:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231416AbiF2X1m (ORCPT ); Wed, 29 Jun 2022 19:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbiF2X1i (ORCPT ); Wed, 29 Jun 2022 19:27:38 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9900225597; Wed, 29 Jun 2022 16:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545246; bh=iNwUdaKb68n0qxpDMrgDE5swA3FwnfSS8OFF1YKICm0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=MYURaPEE07eP0U6aG73dPHNWtgGNzNW5U0k8L39BjGFDdBOkvcoUMBu6MNKiQ21EL 1phQhH0rvCFz+ihcSw4ICOmig3dA3GMpCt9/Ip/flZCHbd44iRFOGtMxXnMj+R/ZR2 9j7xM5c0PsL1OGYytIgTXEOw2ZsxshsT795FU+ao= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M7b6l-1nzEpf0yk9-007yws; Thu, 30 Jun 2022 01:27:26 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 08/10] tpm, tpm_tis: Request threaded interrupt handler Date: Thu, 30 Jun 2022 01:26:51 +0200 Message-Id: <20220629232653.1306735-9-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+4tCCSaPV7LTvCzpch7DT6xJYWP7yrxgAb8FnoGQ3n6/FjHKRhB Ub9aP6Bm8GCGDTzGt9q+wg7OtoUJdXfIGGAkDj62pPblbV4S8lCHWC45tBzTi1F76nXNVZM OUnCbABk1CSPnovmF0gLfM9yuO82eqPvvz+t9llCBV4+76xStwsZFtLHwpq+XUMDGCPB919 wet9FfJeImK8fQEgBSx6A== X-UI-Out-Filterresults: notjunk:1;V03:K0:BoTu01VJatw=:olh2Myk9n4aF5al80hc26h 1ugJ+5HO8oMiRmwKhkUqK8A+xeE+AfWlh5GL7aq4s9UF5ZLZy2DHTjSUpCKmUDSjREdwklqvj xrASFdQPHQc+6iUXnaLaqcB8IwS4kw0IdWwBUU8LXn4f+ypcce3bgRK1vr/HUejg8+TQy77vd iXpLOG/QW4S3TvJ03IiXyoAorYugCftuPbslRfDOrX3Ywconf5rm+E3q/oS1Ky1ZfHhiL/IL4 I08csF7thlEeCIAbt05vx7jbNvcO/AcQGHIhqoI3+xOszcgTpqZIVmUYBFTnrT17z9X5bjjoT USWozb56Jl/uzyx3DioytHcCAxrQtrZC553ycqNr12k8Oj1A7vw6qpypIUzooSzqu+9t8CB0u XDxtHwwAVy/VAn+ZTbUbEPRIIf/sTq16i9DWJQvY7wgcah/9T/EYX5BxR+TesJCf6J+lU0gpL zMZFeXSjbhRtpy+t5hma/3iJQrTPcfp+ljbkS9iTbr9fNQLP10zCttZfURfSa53GYnWZOf31C 76djt+bWm8p6v62jOwFjuIcObYXupYzH+g4HaI2LxJb9VY/RGMyjg/W4RGe3HzIFW6j7GVnxZ FPbcowyTh8hDqbDGo3YX24fPvAhYakinC5F4eyGv4nsA9y46YxZiKkulcPi3iUEReYHWzyvBU YaTHTZhfI9NKa3T1TNKosskPOgcVfe9NHtA7bglYpVkVeliRuvh93UwZEATfMZB0IyfnxEDGn joVlK6/NzNWR4eIPaqOmuCJiq9MRXfG7Roj2W5R/uDYRyGxPfkiFPdtNGoBefksdNblYz2MSI 8+tdS4u/M6x3USHfvmVFk2xLY/A5Ledd4abU14IIGvlGXfTBFYj6Do/eiyD5mYD/7fb2AhMnQ N5EK19E3DKUFbEg6NkAP4HRzUP2WeB9tmL+2OWSZnq/uwiOfudWSRGOBu3OXd/s7XPpRICu2K m30PbXik8QP/n/oCDOULUDRrdrInr5MT8fo77LTiyAqgAqHzzMbf7IyjSQrOJd/NBn5nYdXG1 w8SDMZefzB/43C0OOUYHphUFY0KBGmGoSv2JtkJ49HigvkVo5g4h6zX3WEUAI4onxpnOmC6ut ushdtOawGjmmM6BUoGnvrals7aBZVcW1m8ebdU3R27xe7CEOW+D4Ziciw== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo The TIS interrupt handler at least has to read and write the interrupt status register. In case of SPI both operations result in a call to tpm_tis_spi_transfer() which uses the bus_lock_mutex of the spi device and thus must only be called from a sleepable context. To ensure this request a threaded interrupt handler. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index e50a2c78de9f..83b31c25e55c 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -802,8 +802,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 Wed Jun 29 23:26:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900800 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2343CCA47C for ; Wed, 29 Jun 2022 23:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231480AbiF2X1o (ORCPT ); Wed, 29 Jun 2022 19:27:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231237AbiF2X1j (ORCPT ); Wed, 29 Jun 2022 19:27:39 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 551CE26134; Wed, 29 Jun 2022 16:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545246; bh=oL28C5/txX1WMfNKiS3Enygdd/Bx8aylw3RToNnKp7Q=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=YhQ6qeJ4Hk9WVn3PU/12GzBnpCFji16amM0y8SZs8tYBY8e0gbs5LzjDiGnYn2fNf Aa7cfAiTblbUOTX5+0J64NpcB4wsZGLZ6gDleL5S3JFAJgbmBv9oXiHvbL/fdRwwMB pt6v0UyNB1j4UEn94E2ym8DquWYqfLnFlP8L01ac= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MwfWa-1nioJI2Z1W-00y9Sn; Thu, 30 Jun 2022 01:27:26 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 09/10] tpm, tpm_tis: Claim locality in interrupt handler Date: Thu, 30 Jun 2022 01:26:52 +0200 Message-Id: <20220629232653.1306735-10-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:YXr1/sAgSWNaNDcJ76G9BWW6M81O9IOQ329c77KLTTYXl6+Z9PU xyS8aHZtq83P3yAaG650/kwLQbNMFHMkOTeDUrC/BI/QQ2MdEEB/Qe5B9z19fCY4kESCaGm iFTjmozsHTvTrX2rjZykkxDiVSVRdxMZNqwB2fOvYghE/l7Jxpokos0HNk2CqmHNtYcyP7F c1gzTmpR/wszUHus+aT7Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:JFmiFTMlH4M=:A17eICZZ5FFC9QA/8n/VBY GSPeBxsGl0QGIzINjDf4zcwnp2qbMslVKhcwuKetm/4dzwDdKqWyMgVRH4ZEkHwvyc8ITJdeP B7+ZyZ/Et54pBCIuNzTM6f4Jx1F6uLXiXRH+V3V0ryWyyHAtKEfgJ9TjW8c1dp8cBFeZ4YZGk D9+9NqB8D+O3f2vW/XyPYSmJBFEI1d5Q/LR6ogD4PnNLXj4WlXzkYHgTeVvzapmc/b3m+lwJ5 cGKXPsuEW0yNxZeQv4NJhsfPGPnsFd9hCAJVqbMnJfyQPrMxSdEtL0GYXyklCVcAmB4hSMKmm FxI3h4IYoYPBiTL2WdTr6URr68X6zo7JE0z5Qa49VoBj3Pb+z5OGtS+/t2um4afEaVsChjGPZ KYHsW8FI3L16/BMZz+3Fj9Qvmt8NOFCzlXxpcyQabgeQYrZp/y24oNyFEEG2FoUH9xdtTI1In HIxUD8mkcDIjPru6qTuO/wT+5HySgGkPcxacT5klQJ5iJQmUZX16XCsFZZAVrZz018Fke0k/x RTKIs1P2C9D+Wfo2bHdOTE1Q//0IjEMSzuX83iR5ITzEvnJv9/jxn9uVZkN4fyt4Xn/3CXjwN cO480dYZEVw0lG6YJ6srAiZrDl6pwfW3mbOJUjWC8jufco9D7NJAWBbjn9nTxAx/VN40t4mda HuLGTVu4r+a+6ek8SYE2NMmSVSwHgOFSAG1mIHUEEVOo/BuoDHKgQpsd/xEZv1RF65+bYYw0e GQ9EC0MeRhVt2zlbEynprj1bZDarw3p5GOoSyhFFAQdB64LNRuLg0YFzJSZtJfxPq0XF1UPXd YthRuZeFLP69hkNa9nf+IMsBM4xJ75VQegDfwN5T0iPyNVbynQ0Y8Kzv6ktY0Kp8j2zg5T790 I7ZLk97e6vaxh3Uww1oO9vQwEi0LkgpUbiCAN6ZAUZdFoeFV3WMLhaO1/AMjg1RaWFHSdrxJg +4VdUi08FcgNA18JAwvdXTtvrS7rjOtNYCmplthLNSsg7CEinDiYHVSPpxM6xrRP2z+kfOO08 K9uT51RSOGb6yzk247vcpC8pt/UQKIphfkOCnc5k3tKNBAYWSi9OuU+wx4O0hCwFC25pz9Trv rzTOkabdeS4Ff5oZA/SjLPlPxLagMJndz4d9roqGtMObngM3ZGq3KLcUQ== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Writing the TPM_INT_STATUS register in the interrupt handler to clear the interrupts only has effect if a locality is held. Since this is not guaranteed at the time the interrupt is fired, claim the locality explicitly in the handler. Signed-off-by: Lino Sanfilippo Reviewed-by: Jarkko Sakkinen Tested-by: Michael Niewöhner --- drivers/char/tpm/tpm_tis_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 83b31c25e55c..307a7a3a55c6 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -761,7 +761,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_release_locality(chip, 0); if (rc < 0) return IRQ_NONE; From patchwork Wed Jun 29 23:26:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12900801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 561AFCCA481 for ; Wed, 29 Jun 2022 23:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231491AbiF2X1p (ORCPT ); Wed, 29 Jun 2022 19:27:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231324AbiF2X1j (ORCPT ); Wed, 29 Jun 2022 19:27:39 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C789F26546; Wed, 29 Jun 2022 16:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656545247; bh=trJhlzE+9h7nejkPPDRUJXRB5bu1x2yTJPTeKLNCj6w=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ZJfr34/M7u05kxJerTQq/7yMBUHy75csgDCyOplAhX2i9/PW8SWuhB8TPUAX1hvAI wiAbEPmy6L/sG1Yi9Wvo3Oebaid7cfpJKN/UUn8aDBqahcK6ZTUDfbuLq2/xRx21ZE 2kxrWEPihk4EA43ufBDHy8eBeA8HiEoibkYQkkkI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.23]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mq2j2-1nKixY457C-00n7un; Thu, 30 Jun 2022 01:27:27 +0200 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, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v7 10/10] tpm, tpm_tis: Enable interrupt test Date: Thu, 30 Jun 2022 01:26:53 +0200 Message-Id: <20220629232653.1306735-11-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:wD89YvMA7Ghz21K7RCd1iGNpk5t5Qtb8lm2ALSnWhZzJkJD+cMW SPNERSZsdCRFDxdzyS4/CstbmOXywFpk2oG3UeQ9fEFX3bESMfr4Nm/puceFN3H83gKREFq I6kaAD2jKwIfWaeB9lXMXmUv3YWGB/6R6QZrXIqBwH8dcKx0jmvQ2ExnWvrbQ5OokPpyn33 cPw6JYgfSctF9C51icMCw== X-UI-Out-Filterresults: notjunk:1;V03:K0:3aAohqBAv5Y=:LDpEX1KrDh/NMyxlHknzpI aLk2uxA8LH54kya7/5t7LsrdH6sKMjSz7T1ewILGcxNaD9VKeWhmYiHLNOve4ryICDf+HczIp qByFA7esuGjqtnkDPvFJ2KZ+gMroFqnV3ROVC3WD2tl0ur39Xweq45ukpdceTdEHR8YH/XUBE hpLF9fh4l8Y7G5tGK7Ck2YkwmMaVNQEb+hXmVJNUiW06O8VCVEaw5xYGyyJKEH7yyERb9ecVm MWXC3xV7BVozO9u2STXZSf1CUVU9M+T9CRG9c4Jug3pHbRaTCC4ycXRlXNfSx5Al8CGpvT1e3 O6CMneZxRcStklvtsG+4c8/XMZTFPHLWkto6Cknoec9mVUX3/FW+bIgpMuXvlRP3NlumRuc2r PZqJVV1aZC79oYSLqsl4CwS3uZ7lGDPL5ppL/B66GLeEiQNrkjwphEO+jVNxOf2lvwH3wmLpp 9LvNDi0J53VON8ZNWwpK4MNknGWtQkckAt7t5y4lFgewLEXcZinPWQMj6zR3Am1XUOnsPNsah 8U78JGXjWe5vKhMv0vyOmiFU51o6jwaUCBMpLbCd+/XBtv6Sb7/AH0geNOzJ5hHqaISZdOgmu RfcC035Bp+0CX3HHWhaXM2GNF/2paoAXHtHgt6ntPwfs0K5i9jPwxrqkcbRhx22OX3NWk1YXz ld1bu/CF0E46YYt0KqaKK73t4wI5sm3YVO3Y0aIs8WsJs7Qlvvz6fps99kFM/zs10iTFMNKdD iQ+TswGONBYF9nZ0ttkySNEy4ciDUUJHEsB4GOlu809y/VmdkjooLnuqTtQfXZJvGBU5kSVT9 J7bfvMXzdLCR/5BwWpoQZjx4FAf3z3bhckzNIiq4bNo7RKxdBSRmmtB/y7mtJ5zrgR2r1VcBi bKz+1H+R1gI+Dv/oOKDn3u0S0ZO0c4hK1GY10yx47fqdCJRUAqfhdT3bFBv2cxuphkYa8qk4U hRZf7VsUIxfOEg+ul9A0rZepitwD3KR20zGVd+ZH9+6cBfX84aIYnMLf7gZqa8wHm6QuGTYvj 6DzOFBY940x/r9QFNO4OEXPXj/HnYB0vQCTcX6YY+SFsnHb2dYp5c4TAMZ3RLd1h2B5hw3WUp iT1U5ckAsJBIt/MUguD45uggXYXU52WlALqdZd76MZBuZiN8t3NQz4tSg== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo The test for interrupts in tpm_tis_send() is skipped if the flag TPM_CHIP_FLAG_IRQ is not set. Since the current code never sets the flag initially the test is never executed. Fix this by setting the flag in tpm_tis_gen_interrupt() right after interrupts have been enabled and before the test is executed. Signed-off-by: Lino Sanfilippo Tested-by: Michael Niewöhner --- 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 307a7a3a55c6..e0889c152909 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -782,11 +782,16 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) if (ret < 0) return ret; + chip->flags |= TPM_CHIP_FLAG_IRQ; + if (chip->flags & TPM_CHIP_FLAG_TPM2) ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); else ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + if (ret) + chip->flags &= ~TPM_CHIP_FLAG_IRQ; + tpm_tis_release_locality(chip, 0); return ret;