From patchwork Sat Feb 20 02:36:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 385556 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DDAFC433E0 for ; Sat, 20 Feb 2021 02:37:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 468A364E54 for ; Sat, 20 Feb 2021 02:37:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229771AbhBTChn (ORCPT ); Fri, 19 Feb 2021 21:37:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:42692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbhBTChl (ORCPT ); Fri, 19 Feb 2021 21:37:41 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id CD88B64E54; Sat, 20 Feb 2021 02:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613788620; bh=11VjwrLVTaCchWbSZbfpOpPCXvnZn7rLf+bfTZNteK0=; h=From:To:Cc:Subject:Date:From; b=shuls3n1ZfjhymTGI0HzOP4nDn77pgLswngIsQrM/9QfWkOzjJJdpnFmiIvaXzKST eM64BxW7r8sb9di/kYILPup5NHw9PKOvoPmRQizFQRLXCUUOiMLLtpGlLiEjLGWJdT aXgCn7A1yn+E1w2mIgU0KRKXraCuqKJJ3lowS7hQEmaU6VMZrjYW+LuRxGE3o3aCyc IVmTgv5O+EKpgvt2EdGzxgMPpys5DOlk7sAicYOf4myKNmCR60Ugk6hA6Dw/Jjvly4 YkA6a3j2LxMEqFVaD7uZvr+nu+cG1CXNgVVDun/lGORtFzrcVdtdiHeRqufnMif2l/ LeWU0c2wNQYZA== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Jarkko Sakkinen , James Bottomley , Guenter Roeck , Laurent Bigonville , stable@vger.kernel.org, Lukasz Majczak , Peter Huewe , Jason Gunthorpe , Jerry Snitselaar , Stefan Berger Subject: [PATCH 1/2] tpm, tpm_tis: Decorate tpm_get_timeouts() with request_locality() Date: Sat, 20 Feb 2021 04:36:41 +0200 Message-Id: <20210220023641.8568-1-jarkko@kernel.org> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org This is shown with Samsung Chromebook Pro (Caroline) with TPM 1.2 (SLB 9670): [ 4.324298] TPM returned invalid status [ 4.324806] WARNING: CPU: 2 PID: 1 at drivers/char/tpm/tpm_tis_core.c:275 tpm_tis_status+0x86/0x8f Background ========== TCG PC Client Platform TPM Profile (PTP) Specification, paragraph 6.1 FIFO Interface Locality Usage per Register, Table 39 Register Behavior Based on Locality Setting for FIFO - a read attempt to TPM_STS_x Registers returns 0xFF in case of lack of locality. The fix ======= Decorate tpm_get_timeouts() with request_locality() and release_locality(). Fixes: a3fbfae82b4c ("tpm: take TPM chip power gating out of tpm_transmit()") Cc: James Bottomley Cc: Guenter Roeck Cc: Laurent Bigonville Cc: stable@vger.kernel.org Reported-by: Lukasz Majczak Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 431919d5f48a..30843954aa36 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1019,11 +1019,21 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); if (irq != -1) { - /* Before doing irq testing issue a command to the TPM in polling mode + /* + * Before doing irq testing issue a command to the TPM in polling mode * to make sure it works. May as well use that command to set the * proper timeouts for the driver. */ - if (tpm_get_timeouts(chip)) { + + rc = request_locality(chip, 0); + if (rc < 0) + goto out_err; + + rc = tpm_get_timeouts(chip); + + release_locality(chip, 0); + + if (rc) { dev_err(dev, "Could not get TPM timeouts and durations\n"); rc = -ENODEV; goto out_err;