From patchwork Wed Apr 26 17:29:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 13224816 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 9A54CC7618E for ; Wed, 26 Apr 2023 17:29:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238432AbjDZR3j (ORCPT ); Wed, 26 Apr 2023 13:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233678AbjDZR3i (ORCPT ); Wed, 26 Apr 2023 13:29:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4425EBE; Wed, 26 Apr 2023 10:29:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D76856232F; Wed, 26 Apr 2023 17:29:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAEE3C433EF; Wed, 26 Apr 2023 17:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682530176; bh=dcW/YGcfbxh1/KUv8M6Wk49tlitkkdIukS6SS0m9pEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T0d38LH2IrCAUzZ3Ljnkpq7lWYQ10iQ7lD0UNtxp3dtB1QhtTGKYwRMaVwe+Q383d r32hskaz+qbLvPgwaj5D6xRl9HRWAGOGcyBjsinyo4WyEeBSF7Lthir2RCTXtnR57m XFRTFKUUB2Uob7VCrAlDqRFlBSyO9Nq+S+LDnHZWnOKfU5KtwfeQf6Ug2EDa9AHU0e KVCEFaVuck9yig1f7nyW2026ZzDYJlwZ5zoAxTja2kR53ExIRld5CRf995ZyChBKTV Ac0jLjllKJqr+Pm85FC/34lFX67KmHeZ+Hy0MOnDS/AdWa48QuixooT1BKCLE6+6qi LotndTosOc+FQ== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , Jerry Snitselaar , Stefan Berger , James Bottomley Cc: stable@vger.kernel.org, "Jason A . Donenfeld" Subject: [PATCH 1/2] tpm_tis: Use tpm_chip_{start,stop} decoration inside tpm_tis_resume Date: Wed, 26 Apr 2023 20:29:27 +0300 Message-Id: <20230426172928.3963287-2-jarkko@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230426172928.3963287-1-jarkko@kernel.org> References: <20230426172928.3963287-1-jarkko@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Before sending a TPM command, CLKRUN protocol must be disabled. This is not done in the case of tpm1_do_selftest() call site inside tpm_tis_resume(). Address this by decorating the calls with tpm_chip_{start,stop}, which arm and disarm the TPM chip for transmission, and take care of disabling and re-enabling CLKRUN, among other things. Cc: stable@vger.kernel.org Reported-by: Jason A. Donenfeld Link: https://lore.kernel.org/linux-integrity/CS68AWILHXS4.3M36M1EKZLUMS@suppilovahvero/ Fixes: a3fbfae82b4c ("tpm: take TPM chip power gating out of tpm_transmit()") Signed-off-by: Jarkko Sakkinen Reviewed-by: Jerry Snitselaar ops->clk_enable != NULL) - chip->ops->clk_enable(chip, true); - - /* reenable interrupts that device may have lost or - * BIOS/firmware may have disabled + /* + * Re-enable interrupts that device may have lost or BIOS/firmware may + * have disabled. */ rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), priv->irq); - if (rc < 0) - goto out; + if (rc < 0) { + dev_err(&chip->dev, "Setting IRQ failed.\n"); + return; + } intmask = priv->int_mask | TPM_GLOBAL_INT_ENABLE; - - tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); - -out: - if (chip->ops->clk_enable != NULL) - chip->ops->clk_enable(chip, false); - - return; + rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); + if (rc < 0) + dev_err(&chip->dev, "Enabling interrupts failed.\n"); } int tpm_tis_resume(struct device *dev) @@ -1235,27 +1230,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) + ret = tpm_chip_start(chip); + if (ret) return ret; if (chip->flags & TPM_CHIP_FLAG_IRQ) tpm_tis_reenable_interrupts(chip); - ret = tpm_pm_resume(dev); - if (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)) tpm1_do_selftest(chip); -out: - tpm_tis_relinquish_locality(chip, 0); - return ret; + tpm_chip_stop(chip); + + ret = tpm_pm_resume(dev); + if (ret) + return ret; + + return 0; } EXPORT_SYMBOL_GPL(tpm_tis_resume); #endif