Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1446898
| From | Andrey Pronin <apronin@chromium.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 1/2] tpm_tis_core: add optional max xfer size check |
| Date | 2016-07-20 04:40 +0200 |
| Message-ID | <rWPAt-3ST-13@gated-at.bofh.it> (permalink) |
| References | <rV0gF-qZ-9@gated-at.bofh.it> <rWPAt-3ST-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
If tpm reports a bigger burstcnt than allowed by the physical protocol,
re-query the burstcnt and correct, if needed, if still too large.
In practice, seen in case of xfer issues (e.g. in spi interface case,
lost header causing flow control issues and wrong values returned on read
from TPM_STS). Without catching, causes the physical layer to reject xfer,
while is easily preventable by re-querying TPM_STS.
Signed-off-by: Andrey Pronin <apronin@chromium.org>
---
drivers/char/tpm/tpm_tis_core.c | 18 ++++++++++++++++--
drivers/char/tpm/tpm_tis_core.h | 1 +
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index d66f51b..ffc1acb 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -158,6 +158,7 @@ static int get_burstcount(struct tpm_chip *chip)
unsigned long stop;
int burstcnt, rc;
u32 value;
+ bool retry_burstcnt = false;
/* wait for burstcount */
/* which timeout value, spec has 2 answers (c & d) */
@@ -168,8 +169,21 @@ static int get_burstcount(struct tpm_chip *chip)
return rc;
burstcnt = (value >> 8) & 0xFFFF;
- if (burstcnt)
- return burstcnt;
+ if (burstcnt) {
+ /* If burstcnt is larger than max allowed xfer
+ * size, retry once - may be a glitch. Return
+ * max_xfer_size on the 2nd try to avoid being
+ * stuck forever.
+ */
+ if ((priv->phy_ops->max_xfer_size == 0) ||
+ (burstcnt <= priv->phy_ops->max_xfer_size))
+ return burstcnt;
+ if (retry_burstcnt)
+ return priv->phy_ops->max_xfer_size;
+ dev_warn(&chip->dev,
+ "Bad burstcnt read: %d\n", burstcnt);
+ retry_burstcnt = true;
+ }
msleep(TPM_TIMEOUT);
} while (time_before(jiffies, stop));
return -EBUSY;
diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h
index 9191aab..58e8b14 100644
--- a/drivers/char/tpm/tpm_tis_core.h
+++ b/drivers/char/tpm/tpm_tis_core.h
@@ -102,6 +102,7 @@ struct tpm_tis_phy_ops {
int (*read16)(struct tpm_tis_data *data, u32 addr, u16 *result);
int (*read32)(struct tpm_tis_data *data, u32 addr, u32 *result);
int (*write32)(struct tpm_tis_data *data, u32 addr, u32 src);
+ u16 max_xfer_size;
};
static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr,
--
2.6.6
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/2] tpm: add optional max xfer size check Andrey Pronin <apronin@chromium.org> - 2016-07-15 03:40 +0200
[PATCH 1/2] tpm_tis_core: add optional max xfer size check Andrey Pronin <apronin@chromium.org> - 2016-07-15 03:40 +0200
Re: [PATCH 1/2] tpm_tis_core: add optional max xfer size check Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-07-15 05:20 +0200
Re: [PATCH 1/2] tpm_tis_core: add optional max xfer size check Andrey Pronin <apronin@chromium.org> - 2016-07-15 05:30 +0200
Re: [PATCH 1/2] tpm_tis_core: add optional max xfer size check Guenter Roeck <groeck@google.com> - 2016-07-15 05:50 +0200
Re: [PATCH 1/2] tpm_tis_core: add optional max xfer size check Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2016-07-18 21:00 +0200
[PATCH 2/2] tpm_tis_spi: add max xfer size Andrey Pronin <apronin@chromium.org> - 2016-07-15 03:40 +0200
[PATCH v2 0/2] tpm: add optional max xfer size check Andrey Pronin <apronin@chromium.org> - 2016-07-20 04:40 +0200
[PATCH v2 2/2] tpm_tis_spi: add max xfer size Andrey Pronin <apronin@chromium.org> - 2016-07-20 04:40 +0200
[PATCH v2 1/2] tpm_tis_core: add optional max xfer size check Andrey Pronin <apronin@chromium.org> - 2016-07-20 04:40 +0200
Re: [PATCH v2 0/2] tpm: add optional max xfer size check Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2016-07-20 17:20 +0200
csiph-web