From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379918; b=XkY9dptW883BuaQRxOamQOWinPQp0Mi2Ld0VQnF8q7K9sdOhKd6EOoO3tiY7CLWgaS0f fnFUAgDM3vxZRXyz5GqkB48uAs4eTOhtq5Ba/ScKkE22EXqqmKyTuhtF1zGONhraZex1T gcGF1F/mWuO1FUxGaslFG4LHhZCXwgJwpX4oDPzhvgawhNDv8Z4NdZU9i1SjiPUneIGu2 etj9ZVxA41EywZTP12hjiNy3wQ6JlY4h7pI7jMi3nZpB2KxCEu4tQbcodZ9IAqGWrSmn6 6OrFT5ev6074WlxlcacbvJbXHty9DL4g2CRs43gFViKloudnX3wgIZ7dBKs2M6nnSJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379918; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=glF3Mvras6CoqBuDaWKRJ4dETdDeme+ngayL4svc9wY=; b=bl8jU9f3MQeIL2WdBmJKpy2kytQPV2bpujJxaEm70WxjldZhje1+Am9r4WF6pSA3I90m 0cgupE4HbAdI4eK+TucvRvZ9Pk7rfzUH5XCRB3+uk72CwFH0gusLzX51oPZCU8PQpEorp iLp/CIMLvby5+cd/drm6gYgvU+B5mcogiER4hM3+jNu3Im2VQBAEQqQl3IWy3yd/RzSJd a0i/wG/GzoXLO/T12s0ZGHsC9gKtq5NPSkBsJVq9kGwpFpLrWrLb14I/i9AhiSr+diGIo tN028tGsPlIToxHn+4Bm8Iu6qlY41E926wiX8blEKcSs6rq0+UodMWuNQj+soFiR9rQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tNgIULR7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0297A606A32C; Fri, 4 Dec 2026 10:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tNgIULR7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 195981F000C2; Fri, 4 Dec 2026 10:25:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379917; bh=glF3Mvras6CoqBuDaWKRJ4dETdDeme+ngayL4svc9wY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tNgIULR7GfcBhlqXl/rzpQmD+2b6coEDzeEIyRb1/tq/h2wE0S8kkQSewiO7Y3S5S eKlNboLee+YEvQmMxqRaHDg4cNISiudE4BM8AB5WI0EBn9yGGIFRQo+nJNN2nxLf53 25GibbxzAONuCIMXNHeOwrI/UUNirrU1SxwGILQA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mario Limonciello , Jarkko Sakkinen Subject: [PATCH 7.3 049/742] tpm: Call cmd_ready/go_idle for each command transmission Date: Fri, 4 Dec 2026 18:58:33 +0900 Message-ID: <20261204100636.368344917@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mario Limonciello commit 313acd594a799d6b4b3af937eaca7bf4a1803c4a upstream. Some TPM implementations, particularly fTPM using the CRB interface, require the TPM to transition through idle and ready states for each command rather than once per session. The current implementation calls cmd_ready once during tpm_chip_start() and go_idle once during tpm_chip_stop(). For fTPM, when multiple commands are sent without per-command idle transitions, subsequent commands timeout as the TPM is waiting for the transition. Fix this by calling cmd_ready before each command and go_idle on all exit paths in tpm_try_transmit(). For TPM implementations that don't require per-command transitions, the callbacks return immediately based on the start method. Remove the now-redundant per-session calls from tpm_chip_start() and tpm_chip_stop() along with their helpers. This resolves timeout errors during TPM initialization on systems where BIOS has already performed TPM startup. Signed-off-by: Mario Limonciello Reviewed-by: Jarkko Sakkinen Link: https://lore.kernel.org/r/20260901213723.3017371-1-mario.limonciello@amd.com Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm-chip.c | 24 ------------------------ drivers/char/tpm/tpm-interface.c | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 24 deletions(-) --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -66,22 +66,6 @@ static void tpm_relinquish_locality(stru chip->locality = -1; } -static int tpm_cmd_ready(struct tpm_chip *chip) -{ - if (!chip->ops->cmd_ready) - return 0; - - return chip->ops->cmd_ready(chip); -} - -static int tpm_go_idle(struct tpm_chip *chip) -{ - if (!chip->ops->go_idle) - return 0; - - return chip->ops->go_idle(chip); -} - static void tpm_clk_enable(struct tpm_chip *chip) { if (chip->ops->clk_enable) @@ -116,13 +100,6 @@ int tpm_chip_start(struct tpm_chip *chip } } - ret = tpm_cmd_ready(chip); - if (ret) { - tpm_relinquish_locality(chip); - tpm_clk_disable(chip); - return ret; - } - return 0; } EXPORT_SYMBOL_GPL(tpm_chip_start); @@ -137,7 +114,6 @@ EXPORT_SYMBOL_GPL(tpm_chip_start); */ void tpm_chip_stop(struct tpm_chip *chip) { - tpm_go_idle(chip); tpm_relinquish_locality(chip); tpm_clk_disable(chip); } --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -19,6 +19,7 @@ * calls to msleep. */ +#include #include #include #include @@ -89,8 +90,17 @@ static bool tpm_transmit_completed(u8 st return status_masked == chip->ops->req_complete_val; } +static void tpm_go_idle(struct tpm_chip *chip) +{ + if (chip->ops->go_idle) + chip->ops->go_idle(chip); +} + +DEFINE_FREE(tpm_go_idle, struct tpm_chip *, if (_T) tpm_go_idle(_T)) + static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) { + struct tpm_chip *chip_idle __free(tpm_go_idle) = NULL; struct tpm_header *header = buf; int rc; ssize_t len = 0; @@ -113,6 +123,18 @@ static ssize_t tpm_try_transmit(struct t return -E2BIG; } + if (chip->ops->cmd_ready) { + rc = chip->ops->cmd_ready(chip); + if (rc) { + dev_err(&chip->dev, + "%s: cmd_ready(): error %d\n", __func__, rc); + return rc; + } + } + + /* Ensure go_idle() is called on every exit path from here on. */ + chip_idle = chip; + rc = chip->ops->send(chip, buf, bufsiz, count); if (rc < 0) { if (rc != -EPIPE)