Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2853045pxb; Fri, 12 Feb 2021 03:09:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxw7wnnWrp16MbA9x/RbE6pvQZDOkoPsulZgFNNPkwM12iStqfCG65CG1JD53ZCJKlInjgz X-Received: by 2002:a50:ff0d:: with SMTP id a13mr2659417edu.321.1613128162554; Fri, 12 Feb 2021 03:09:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613128162; cv=none; d=google.com; s=arc-20160816; b=CZEMgfo7KzvY1CwoGH2CprbNMK5N7ch9lE+ITzGf0w57aotKHkRIWmXYk8/TViBNK5 THkeFwx3mFyY0iSB7/0kilTxnaJiUVRh2J0PglN6UcI+GHfQAudLbkiyzSSQsL6wK9bm smIrqrym7yjwoMYIQpF/i6DqFvUt5Ta8KWmhhaRzwKCDmO3UsC7usuPc3u9UvS+i65/h 0Bz1+iTRZT21wglTwNKARPOlHLkSQF6SVBv96RDoc9Vx4AZ5sOCJTmdiTgAh17OKkKeB A2qnGFWMsdCVWWZrvsi+mI5RoilwGsI0bQmKOS1JFsU9BQWDRW7P1Scxm/Uv5VLvqBat mVoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=p2xh5jdgGHTIrdu5lQXA6yzf53MI3dqdPEuKDN8QxP0=; b=gC66I+UBoDB/3R0pxpEepnQdgLG3hLjrXPTLHIDJO56bYAXk0vbV8K7FhOC36KoTmW sKZs7Y209B2v5lfKUuzSZ7x9mVM8WqlpW5LrWvU7qy7kNk5IRnVhIyBpLtthcKKtvfGU UuUuutHVEah1UETL9vgmONv6I613Zqe301aqDNJH2BNbMlEAI5+c4QJW9XO2+ksqeYYz 8vYovtFcIwJh18+ZNvqIfn/8dGgFiQt76b/5Xc4ZMWajoMYHptyDmIhSQxIjg0NleDTp kMau8migBWzKPlRI2BHoZq7v8fvp9r78J+UvVyVpofMHLbfIuT+3O38kVTxjxw8gTBfD c5Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=awaLbyc7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t11si6016574edy.280.2021.02.12.03.08.58; Fri, 12 Feb 2021 03:09:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=awaLbyc7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230318AbhBLLH4 (ORCPT + 99 others); Fri, 12 Feb 2021 06:07:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230443AbhBLLHZ (ORCPT ); Fri, 12 Feb 2021 06:07:25 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CEF6C0613D6 for ; Fri, 12 Feb 2021 03:06:45 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id z11so4576653lfb.9 for ; Fri, 12 Feb 2021 03:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=p2xh5jdgGHTIrdu5lQXA6yzf53MI3dqdPEuKDN8QxP0=; b=awaLbyc7oZphZTpAspqt8g3EyUJFSVCH+NnR7m4d9Y2ufof0nl9DcCoSrdtbdTjIYg nMfDqMu5IywKsfxUoBTMyB6hpb0m4xElIcZ15V5gQWZSDJL1dQsfSKnLGe6TZcZaiwEu uzr3aMd+WvW5IF2efECaWAHlRZoLF/xfUlB9jlSBhPAL2RntxlfZ19Bxr4nncKnTA99A zuLVvv+BKY9mt3MfUzKosAqlJ6Wc9PolxjxGQrtYX0v1Uofu8cX3d4yRSzab9MVQ6/dc vIINbKeQtNzf6Zc6IrhVZZt9ilBsrbtYuAghUByZeFJQAtJ+aBlW/KtoNGUltUWonx+Z J/3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=p2xh5jdgGHTIrdu5lQXA6yzf53MI3dqdPEuKDN8QxP0=; b=V8JCBAh8iYi3+Ai9OcDioS2xO5fqHHrMU74K6ndxUQChzUPPB9D0gGELJLuEx1rIvI 9fvyNsu68wY9kEXPEACIe90+3rVzbXyeoG2W1Qcvo6yP3CZYWm9znQie2CMJWxlNknHb KZ+dMSc1k+9HufIV4/Q0wltwP9e/9xQmzO+MO7oDqQthiAXttLcvbxPSEDrvd30YV/lE /fy2k0z5GK8myKvcNL4LpxlwEqelh8hhwJPAPC77AcAhH8zI7pWpOdWTYeo4LoIn+CkC Jsxsvt6NtK6/sp9b970wEAChuPPj/dYSFODcraWwBSuiQYYtNajcMaQEhHIj1kVPY1om rnuw== X-Gm-Message-State: AOAM531VHc9BtwKzIEU+a8BdrEeSADxVqA7V1IVkU2tDfVVmAivrTsF/ 8Os3N3/kN2LYTgCBDbF0Jf8Lmg== X-Received: by 2002:a05:6512:11e2:: with SMTP id p2mr1280262lfs.321.1613128003337; Fri, 12 Feb 2021 03:06:43 -0800 (PST) Received: from localhost.localdomain (89-70-221-122.dynamic.chello.pl. [89.70.221.122]) by smtp.gmail.com with ESMTPSA id 84sm937488lfd.131.2021.02.12.03.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Feb 2021 03:06:42 -0800 (PST) From: Lukasz Majczak To: Guenter Roeck , Jarkko Sakkinen , James Bottomley Cc: Tj , Dirk Gouders , Peter Huewe , Jason Gunthorpe , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Radoslaw Biernacki , Marcin Wojtas , Alex Levin , upstream@semihalf.com Subject: [PATCH v5] tpm_tis: Add missing tpm_request/relinquish_locality() calls Date: Fri, 12 Feb 2021 12:06:00 +0100 Message-Id: <20210212110600.19216-1-lma@semihalf.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are missing calls to tpm_request_locality() before the calls to the tpm_get_timeouts() and tpm_tis_probe_irq_single() - both functions internally send commands to the tpm using tpm_tis_send_data() which in turn, at the very beginning, calls the tpm_tis_status(). This one tries to read TPM_STS register, what fails and propagates this error upward. The read fails due to lack of acquired locality, as it is described in 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 described situation manifests itself with the following warning trace: [ 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 Tested on Samsung Chromebook Pro (Caroline), TPM 1.2 (SLB 9670) Fixes: a3fbfae82b4c ("tpm: take TPM chip power gating out of tpm_transmit()") Signed-off-by: Lukasz Majczak Reviewed-by: Guenter Roeck --- Hi I have tried to clean all the pointed issues, but decided to stay with tpm_request/relinquish_locality() calls instead of using tpm_chip_start/stop(), the rationale behind this is that, in this case only locality is requested, there is no need to enable/disable the clock, the similar case is present in the probe_itpm() function. One more clarification is that, the TPM present on my test machine is the SLB 9670 (not Cr50). Best regards, Lukasz Changes: v4->v5: * Fixed style, typos, clarified commit message drivers/char/tpm/tpm-chip.c | 6 ++++-- drivers/char/tpm/tpm-interface.c | 13 ++++++++++--- drivers/char/tpm/tpm.h | 2 ++ drivers/char/tpm/tpm_tis_core.c | 14 +++++++++++--- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index ddaeceb7e109..ce9c2650fbe5 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -32,7 +32,7 @@ struct class *tpm_class; struct class *tpmrm_class; dev_t tpm_devt; -static int tpm_request_locality(struct tpm_chip *chip) +int tpm_request_locality(struct tpm_chip *chip) { int rc; @@ -46,8 +46,9 @@ static int tpm_request_locality(struct tpm_chip *chip) chip->locality = rc; return 0; } +EXPORT_SYMBOL_GPL(tpm_request_locality); -static void tpm_relinquish_locality(struct tpm_chip *chip) +void tpm_relinquish_locality(struct tpm_chip *chip) { int rc; @@ -60,6 +61,7 @@ static void tpm_relinquish_locality(struct tpm_chip *chip) chip->locality = -1; } +EXPORT_SYMBOL_GPL(tpm_relinquish_locality); static int tpm_cmd_ready(struct tpm_chip *chip) { diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 1621ce818705..2a9001d329f2 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -241,10 +241,17 @@ int tpm_get_timeouts(struct tpm_chip *chip) if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS) return 0; - if (chip->flags & TPM_CHIP_FLAG_TPM2) + if (chip->flags & TPM_CHIP_FLAG_TPM2) { return tpm2_get_timeouts(chip); - else - return tpm1_get_timeouts(chip); + } else { + ssize_t ret = tpm_request_locality(chip); + + if (ret) + return ret; + ret = tpm1_get_timeouts(chip); + tpm_relinquish_locality(chip); + return ret; + } } EXPORT_SYMBOL_GPL(tpm_get_timeouts); diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 947d1db0a5cc..8c13008437dd 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -193,6 +193,8 @@ static inline void tpm_msleep(unsigned int delay_msec) int tpm_chip_start(struct tpm_chip *chip); void tpm_chip_stop(struct tpm_chip *chip); +int tpm_request_locality(struct tpm_chip *chip); +void tpm_relinquish_locality(struct tpm_chip *chip); struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip); __must_check int tpm_try_get_ops(struct tpm_chip *chip); void tpm_put_ops(struct tpm_chip *chip); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 431919d5f48a..d4f381d6356e 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -708,11 +708,19 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) u32 cap2; cap_t cap; - if (chip->flags & TPM_CHIP_FLAG_TPM2) + if (chip->flags & TPM_CHIP_FLAG_TPM2) { return tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); - else - return tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, + } else { + ssize_t ret = tpm_request_locality(chip); + + if (ret) + return ret; + ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + tpm_relinquish_locality(chip); + return ret; + } + } /* Register the IRQ and issue a command that will cause an interrupt. If an -- 2.25.1