linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lukasz Majczak <lma@semihalf.com>
To: Guenter Roeck <linux@roeck-us.net>,
	Jarkko Sakkinen <jarkko@kernel.org>,
	James Bottomley <James.Bottomley@hansenpartnership.com>
Cc: Tj <ml.linux@elloe.vision>, Dirk Gouders <dirk@gouders.net>,
	Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
	Radoslaw Biernacki <rad@semihalf.com>,
	Marcin Wojtas <mw@semihalf.com>, Alex Levin <levinale@google.com>
Subject: [PATCH v2] tpm_tis: Add missing tpm_request/relinquish_locality calls
Date: Thu, 28 Jan 2021 14:07:53 +0100	[thread overview]
Message-ID: <20210128130753.1283534-1-lma@semihalf.com> (raw)
In-Reply-To: <20210123014247.989368-1-lma@semihalf.com>

There is a missing call to tpm_request_locality before the call to
the tpm_get_timeouts() and tpm_tis_probe_irq_single(). As the current
approach might work for tpm2, it fails for tpm1.x - in that case
call to tpm_get_timeouts() or tpm_tis_probe_irq_single()
without locality fails and in turn causes tpm_tis_core_init() to fail.
Tested on Samsung Chromebook Pro (Caroline).

Signed-off-by: Lukasz Majczak <lma@semihalf.com>
---
Jarkko, James, Guenter

I’m aware about the other thread, but it seems to be dead for a few months.
Here is the small patch as fixing this specific issue
would allow us to unblock the ChromeOs development. 
We want to upstream all of our patches,
so the ChromeOs will not diverge even more,
so I'm hoping this could be applied, if you see it neat enough.

Best regards,
Lukasz

v1 -> v2:
 - fixed typos
 - as there is no need to enable clock, switched to
   use only tpm_request/relinquish_locality calls
 - narrowed down boundaries of tpm_request/relinquish_locality calls
 
 drivers/char/tpm/tpm-chip.c      |  4 ++--
 drivers/char/tpm/tpm-interface.c | 11 +++++++++--
 drivers/char/tpm/tpm.h           |  2 ++
 drivers/char/tpm/tpm_tis_core.c  | 12 ++++++++++--
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index ddaeceb7e109..5351963a4b19 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;
 
@@ -47,7 +47,7 @@ static int tpm_request_locality(struct tpm_chip *chip)
 	return 0;
 }
 
-static void tpm_relinquish_locality(struct tpm_chip *chip)
+void tpm_relinquish_locality(struct tpm_chip *chip)
 {
 	int rc;
 
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1621ce818705..69309b2bea6a 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -243,8 +243,15 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 
 	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 92c51c6cfd1b..0ae675e8cf2f 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -754,9 +754,17 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip)
 
 	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


  parent reply	other threads:[~2021-01-28 13:10 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-23  1:42 [PATCH] tpm_tis: Add missing start/stop_tpm_chip calls Lukasz Majczak
2021-01-25 17:12 ` Jarkko Sakkinen
2021-01-25 17:18 ` Guenter Roeck
2021-01-26 15:46   ` Łukasz Majczak
2021-01-26 16:46     ` James Bottomley
2021-01-26 18:55       ` Tj (Elloe Linux)
2021-01-28  5:58       ` Jarkko Sakkinen
2021-01-29 22:59     ` Jarkko Sakkinen
2021-01-29 23:00       ` Jarkko Sakkinen
2021-01-30 23:49       ` Guenter Roeck
2021-01-31  0:41         ` James Bottomley
2021-01-31  3:36           ` Guenter Roeck
2021-01-31  4:18             ` James Bottomley
2021-02-02 16:17           ` Jarkko Sakkinen
2021-02-02 15:33         ` Jarkko Sakkinen
2021-01-29 22:49   ` Jarkko Sakkinen
2021-01-29 23:32     ` Guenter Roeck
2021-01-28 13:07 ` Lukasz Majczak [this message]
2021-01-28 17:37   ` [PATCH v2] tpm_tis: Add missing tpm_request/relinquish_locality calls Guenter Roeck
2021-01-30 20:40   ` Jarkko Sakkinen
2021-01-30 20:47     ` Jarkko Sakkinen
     [not found]     ` <ghwnvtwifq.fsf@gouders.net>
2021-02-02 16:29       ` Jarkko Sakkinen
2021-02-02 15:51   ` [PATCH v3] " Lukasz Majczak
2021-02-02 16:29     ` Guenter Roeck
2021-02-02 22:35       ` Jarkko Sakkinen
2021-02-02 18:47     ` Dirk Gouders
2021-02-03 11:46       ` Dirk Gouders
2021-02-03 13:43         ` Lukasz Majczak
2021-02-03 23:24           ` Jarkko Sakkinen
2021-02-02 19:57     ` [PATCH v4] " Lukasz Majczak
2021-02-02 21:49       ` Jarkko Sakkinen
2021-02-02 21:49     ` [PATCH v3] " Jarkko Sakkinen
2021-02-03  0:05       ` Jarkko Sakkinen
2021-02-03  0:07         ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210128130753.1283534-1-lma@semihalf.com \
    --to=lma@semihalf.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=dirk@gouders.net \
    --cc=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=levinale@google.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=ml.linux@elloe.vision \
    --cc=mw@semihalf.com \
    --cc=peterhuewe@gmx.de \
    --cc=rad@semihalf.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).