All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/4] additional TPM performance improvements
@ 2017-10-17 20:32 ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, jgunthorpe, patrickc, Nayna Jain

After further discussions with the TCG Device Driver working group (ddwg),
the following changes were made: 

* Check for burstcount at least once to confirm the TPM is ready to accept
the data. Similarly, query for the TPM Expect status as sanity check at
the end.

* Make the sleep for status check in the loop less than 5msec.

* Make the sleep in the loop while querying for burstcount less than
5msec.

Below is the list of patches along with the performance improvements
seen with a TPM 1.2 with an 8 byte burstcount for 1000 extends: 

Patch                                        |Improvement(time in sec)

tpm: ignore burstcount to improve tpm_tis    | ~41 - ~14
send() performance.

tpm: reduce polling delay in tpm_tis_core    | ~14 - ~9 

tpm: modify tpm_msleep() function to have    | ~9 - ~8
max range

Changelog v4:
* Include Jarkko's feedback on merging two patches reducing sleep
time during polling to TPM.
* Include Jarkko's feedback to clean up the burstcount change
patch and add comment for new #define.

Changelog v3:

* Include Jarkko's feedback to move wait_for_tpm_stat() from
tpm-interface.c to respective driver files tpm_tis_core.c and
xen-tpmfront.c.
* Remove use of module parameter ignore_burst_count and is
now alwaysed ignored in tpm tis send() operation.
* Reduce sleep() time during polling in wait_for_tpm_stat() from
5msec to 1msec for both recv() and send() operation. Version
2 of the patches  had it only for send() operation.

Changelog v2:

* Add module parameter to handle ignoring of burst count during
tpm tis send() operation.
* Add improvements over sleep time to reduce delays.

Nayna Jain (4):
  tpm: move wait_for_tpm_stat() to respective driver files
  tpm: ignore burstcount to improve tpm_tis send() performance
  tpm: reduce tpm polling delay in tpm_tis_core
  tpm: use tpm_msleep() value as max delay

 drivers/char/tpm/tpm-interface.c |  60 ---------------------
 drivers/char/tpm/tpm.h           |   6 +--
 drivers/char/tpm/tpm_tis_core.c  | 110 +++++++++++++++++++++++++++++----------
 drivers/char/tpm/xen-tpmfront.c  |  60 +++++++++++++++++++++
 4 files changed, 144 insertions(+), 92 deletions(-)

-- 
2.13.3

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 0/4] additional TPM performance improvements
@ 2017-10-17 20:32 ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-security-module

After further discussions with the TCG Device Driver working group (ddwg),
the following changes were made: 

* Check for burstcount at least once to confirm the TPM is ready to accept
the data. Similarly, query for the TPM Expect status as sanity check at
the end.

* Make the sleep for status check in the loop less than 5msec.

* Make the sleep in the loop while querying for burstcount less than
5msec.

Below is the list of patches along with the performance improvements
seen with a TPM 1.2 with an 8 byte burstcount for 1000 extends: 

Patch                                        |Improvement(time in sec)

tpm: ignore burstcount to improve tpm_tis    | ~41 - ~14
send() performance.

tpm: reduce polling delay in tpm_tis_core    | ~14 - ~9 

tpm: modify tpm_msleep() function to have    | ~9 - ~8
max range

Changelog v4:
* Include Jarkko's feedback on merging two patches reducing sleep
time during polling to TPM.
* Include Jarkko's feedback to clean up the burstcount change
patch and add comment for new #define.

Changelog v3:

* Include Jarkko's feedback to move wait_for_tpm_stat() from
tpm-interface.c to respective driver files tpm_tis_core.c and
xen-tpmfront.c.
* Remove use of module parameter ignore_burst_count and is
now alwaysed ignored in tpm tis send() operation.
* Reduce sleep() time during polling in wait_for_tpm_stat() from
5msec to 1msec for both recv() and send() operation. Version
2 of the patches  had it only for send() operation.

Changelog v2:

* Add module parameter to handle ignoring of burst count during
tpm tis send() operation.
* Add improvements over sleep time to reduce delays.

Nayna Jain (4):
  tpm: move wait_for_tpm_stat() to respective driver files
  tpm: ignore burstcount to improve tpm_tis send() performance
  tpm: reduce tpm polling delay in tpm_tis_core
  tpm: use tpm_msleep() value as max delay

 drivers/char/tpm/tpm-interface.c |  60 ---------------------
 drivers/char/tpm/tpm.h           |   6 +--
 drivers/char/tpm/tpm_tis_core.c  | 110 +++++++++++++++++++++++++++++----------
 drivers/char/tpm/xen-tpmfront.c  |  60 +++++++++++++++++++++
 4 files changed, 144 insertions(+), 92 deletions(-)

-- 
2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
  2017-10-17 20:32 ` Nayna Jain
@ 2017-10-17 20:32   ` Nayna Jain
  -1 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, jgunthorpe, patrickc, Nayna Jain

The function wait_for_tpm_stat() is currently defined in
tpm-interface file. It is a hardware specific function used
only by tpm_tis and xen-tpmfront, so it is removed from
tpm-interface.c and defined in respective driver files.

Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
 drivers/char/tpm/tpm.h           |  2 --
 drivers/char/tpm/tpm_tis_core.c  | 60 ++++++++++++++++++++++++++++++++++++++++
 drivers/char/tpm/xen-tpmfront.c  | 60 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 120 insertions(+), 62 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1d6729be4cd6..313f7618d569 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t buflen)
 }
 EXPORT_SYMBOL_GPL(tpm_send);
 
-static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
-					bool check_cancel, bool *canceled)
-{
-	u8 status = chip->ops->status(chip);
-
-	*canceled = false;
-	if ((status & mask) == mask)
-		return true;
-	if (check_cancel && chip->ops->req_canceled(chip, status)) {
-		*canceled = true;
-		return true;
-	}
-	return false;
-}
-
-int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
-		      wait_queue_head_t *queue, bool check_cancel)
-{
-	unsigned long stop;
-	long rc;
-	u8 status;
-	bool canceled = false;
-
-	/* check current status */
-	status = chip->ops->status(chip);
-	if ((status & mask) == mask)
-		return 0;
-
-	stop = jiffies + timeout;
-
-	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
-again:
-		timeout = stop - jiffies;
-		if ((long)timeout <= 0)
-			return -ETIME;
-		rc = wait_event_interruptible_timeout(*queue,
-			wait_for_tpm_stat_cond(chip, mask, check_cancel,
-					       &canceled),
-			timeout);
-		if (rc > 0) {
-			if (canceled)
-				return -ECANCELED;
-			return 0;
-		}
-		if (rc == -ERESTARTSYS && freezing(current)) {
-			clear_thread_flag(TIF_SIGPENDING);
-			goto again;
-		}
-	} else {
-		do {
-			tpm_msleep(TPM_TIMEOUT);
-			status = chip->ops->status(chip);
-			if ((status & mask) == mask)
-				return 0;
-		} while (time_before(jiffies, stop));
-	}
-	return -ETIME;
-}
-EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
-
 #define TPM_ORD_SAVESTATE 152
 #define SAVESTATE_RESULT_SIZE 10
 
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 2d5466a72e40..4fc83ac7abeb 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
 int tpm_pm_suspend(struct device *dev);
 int tpm_pm_resume(struct device *dev);
-int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
-		      wait_queue_head_t *queue, bool check_cancel);
 
 static inline void tpm_msleep(unsigned int delay_msec)
 {
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 63bc6c3b949e..b33126a35694 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -31,6 +31,66 @@
 #include "tpm.h"
 #include "tpm_tis_core.h"
 
+static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
+					bool check_cancel, bool *canceled)
+{
+	u8 status = chip->ops->status(chip);
+
+	*canceled = false;
+	if ((status & mask) == mask)
+		return true;
+	if (check_cancel && chip->ops->req_canceled(chip, status)) {
+		*canceled = true;
+		return true;
+	}
+	return false;
+}
+
+static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
+		unsigned long timeout, wait_queue_head_t *queue,
+		bool check_cancel)
+{
+	unsigned long stop;
+	long rc;
+	u8 status;
+	bool canceled = false;
+
+	/* check current status */
+	status = chip->ops->status(chip);
+	if ((status & mask) == mask)
+		return 0;
+
+	stop = jiffies + timeout;
+
+	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
+again:
+		timeout = stop - jiffies;
+		if ((long)timeout <= 0)
+			return -ETIME;
+		rc = wait_event_interruptible_timeout(*queue,
+			wait_for_tpm_stat_cond(chip, mask, check_cancel,
+					       &canceled),
+			timeout);
+		if (rc > 0) {
+			if (canceled)
+				return -ECANCELED;
+			return 0;
+		}
+		if (rc == -ERESTARTSYS && freezing(current)) {
+			clear_thread_flag(TIF_SIGPENDING);
+			goto again;
+		}
+	} else {
+		do {
+			tpm_msleep(TPM_TIMEOUT);
+			status = chip->ops->status(chip);
+			if ((status & mask) == mask)
+				return 0;
+		} while (time_before(jiffies, stop));
+	}
+	return -ETIME;
+}
+
 /* Before we attempt to access the TPM we must see that the valid bit is set.
  * The specification says that this bit is 0 at reset and remains 0 until the
  * 'TPM has gone through its self test and initialization and has established
diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
index 656e8af95d52..d20a0a9ded27 100644
--- a/drivers/char/tpm/xen-tpmfront.c
+++ b/drivers/char/tpm/xen-tpmfront.c
@@ -39,6 +39,66 @@ enum status_bits {
 	VTPM_STATUS_CANCELED = 0x8,
 };
 
+static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
+					bool check_cancel, bool *canceled)
+{
+	u8 status = chip->ops->status(chip);
+
+	*canceled = false;
+	if ((status & mask) == mask)
+		return true;
+	if (check_cancel && chip->ops->req_canceled(chip, status)) {
+		*canceled = true;
+		return true;
+	}
+	return false;
+}
+
+static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
+		unsigned long timeout, wait_queue_head_t *queue,
+		bool check_cancel)
+{
+	unsigned long stop;
+	long rc;
+	u8 status;
+	bool canceled = false;
+
+	/* check current status */
+	status = chip->ops->status(chip);
+	if ((status & mask) == mask)
+		return 0;
+
+	stop = jiffies + timeout;
+
+	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
+again:
+		timeout = stop - jiffies;
+		if ((long)timeout <= 0)
+			return -ETIME;
+		rc = wait_event_interruptible_timeout(*queue,
+			wait_for_tpm_stat_cond(chip, mask, check_cancel,
+					       &canceled),
+			timeout);
+		if (rc > 0) {
+			if (canceled)
+				return -ECANCELED;
+			return 0;
+		}
+		if (rc == -ERESTARTSYS && freezing(current)) {
+			clear_thread_flag(TIF_SIGPENDING);
+			goto again;
+		}
+	} else {
+		do {
+			tpm_msleep(TPM_TIMEOUT);
+			status = chip->ops->status(chip);
+			if ((status & mask) == mask)
+				return 0;
+		} while (time_before(jiffies, stop));
+	}
+	return -ETIME;
+}
+
 static u8 vtpm_status(struct tpm_chip *chip)
 {
 	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
-- 
2.13.3

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
@ 2017-10-17 20:32   ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-security-module

The function wait_for_tpm_stat() is currently defined in
tpm-interface file. It is a hardware specific function used
only by tpm_tis and xen-tpmfront, so it is removed from
tpm-interface.c and defined in respective driver files.

Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
 drivers/char/tpm/tpm.h           |  2 --
 drivers/char/tpm/tpm_tis_core.c  | 60 ++++++++++++++++++++++++++++++++++++++++
 drivers/char/tpm/xen-tpmfront.c  | 60 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 120 insertions(+), 62 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1d6729be4cd6..313f7618d569 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t buflen)
 }
 EXPORT_SYMBOL_GPL(tpm_send);
 
-static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
-					bool check_cancel, bool *canceled)
-{
-	u8 status = chip->ops->status(chip);
-
-	*canceled = false;
-	if ((status & mask) == mask)
-		return true;
-	if (check_cancel && chip->ops->req_canceled(chip, status)) {
-		*canceled = true;
-		return true;
-	}
-	return false;
-}
-
-int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
-		      wait_queue_head_t *queue, bool check_cancel)
-{
-	unsigned long stop;
-	long rc;
-	u8 status;
-	bool canceled = false;
-
-	/* check current status */
-	status = chip->ops->status(chip);
-	if ((status & mask) == mask)
-		return 0;
-
-	stop = jiffies + timeout;
-
-	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
-again:
-		timeout = stop - jiffies;
-		if ((long)timeout <= 0)
-			return -ETIME;
-		rc = wait_event_interruptible_timeout(*queue,
-			wait_for_tpm_stat_cond(chip, mask, check_cancel,
-					       &canceled),
-			timeout);
-		if (rc > 0) {
-			if (canceled)
-				return -ECANCELED;
-			return 0;
-		}
-		if (rc == -ERESTARTSYS && freezing(current)) {
-			clear_thread_flag(TIF_SIGPENDING);
-			goto again;
-		}
-	} else {
-		do {
-			tpm_msleep(TPM_TIMEOUT);
-			status = chip->ops->status(chip);
-			if ((status & mask) == mask)
-				return 0;
-		} while (time_before(jiffies, stop));
-	}
-	return -ETIME;
-}
-EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
-
 #define TPM_ORD_SAVESTATE 152
 #define SAVESTATE_RESULT_SIZE 10
 
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 2d5466a72e40..4fc83ac7abeb 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
 int tpm_pm_suspend(struct device *dev);
 int tpm_pm_resume(struct device *dev);
-int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
-		      wait_queue_head_t *queue, bool check_cancel);
 
 static inline void tpm_msleep(unsigned int delay_msec)
 {
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 63bc6c3b949e..b33126a35694 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -31,6 +31,66 @@
 #include "tpm.h"
 #include "tpm_tis_core.h"
 
+static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
+					bool check_cancel, bool *canceled)
+{
+	u8 status = chip->ops->status(chip);
+
+	*canceled = false;
+	if ((status & mask) == mask)
+		return true;
+	if (check_cancel && chip->ops->req_canceled(chip, status)) {
+		*canceled = true;
+		return true;
+	}
+	return false;
+}
+
+static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
+		unsigned long timeout, wait_queue_head_t *queue,
+		bool check_cancel)
+{
+	unsigned long stop;
+	long rc;
+	u8 status;
+	bool canceled = false;
+
+	/* check current status */
+	status = chip->ops->status(chip);
+	if ((status & mask) == mask)
+		return 0;
+
+	stop = jiffies + timeout;
+
+	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
+again:
+		timeout = stop - jiffies;
+		if ((long)timeout <= 0)
+			return -ETIME;
+		rc = wait_event_interruptible_timeout(*queue,
+			wait_for_tpm_stat_cond(chip, mask, check_cancel,
+					       &canceled),
+			timeout);
+		if (rc > 0) {
+			if (canceled)
+				return -ECANCELED;
+			return 0;
+		}
+		if (rc == -ERESTARTSYS && freezing(current)) {
+			clear_thread_flag(TIF_SIGPENDING);
+			goto again;
+		}
+	} else {
+		do {
+			tpm_msleep(TPM_TIMEOUT);
+			status = chip->ops->status(chip);
+			if ((status & mask) == mask)
+				return 0;
+		} while (time_before(jiffies, stop));
+	}
+	return -ETIME;
+}
+
 /* Before we attempt to access the TPM we must see that the valid bit is set.
  * The specification says that this bit is 0 at reset and remains 0 until the
  * 'TPM has gone through its self test and initialization and has established
diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
index 656e8af95d52..d20a0a9ded27 100644
--- a/drivers/char/tpm/xen-tpmfront.c
+++ b/drivers/char/tpm/xen-tpmfront.c
@@ -39,6 +39,66 @@ enum status_bits {
 	VTPM_STATUS_CANCELED = 0x8,
 };
 
+static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
+					bool check_cancel, bool *canceled)
+{
+	u8 status = chip->ops->status(chip);
+
+	*canceled = false;
+	if ((status & mask) == mask)
+		return true;
+	if (check_cancel && chip->ops->req_canceled(chip, status)) {
+		*canceled = true;
+		return true;
+	}
+	return false;
+}
+
+static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
+		unsigned long timeout, wait_queue_head_t *queue,
+		bool check_cancel)
+{
+	unsigned long stop;
+	long rc;
+	u8 status;
+	bool canceled = false;
+
+	/* check current status */
+	status = chip->ops->status(chip);
+	if ((status & mask) == mask)
+		return 0;
+
+	stop = jiffies + timeout;
+
+	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
+again:
+		timeout = stop - jiffies;
+		if ((long)timeout <= 0)
+			return -ETIME;
+		rc = wait_event_interruptible_timeout(*queue,
+			wait_for_tpm_stat_cond(chip, mask, check_cancel,
+					       &canceled),
+			timeout);
+		if (rc > 0) {
+			if (canceled)
+				return -ECANCELED;
+			return 0;
+		}
+		if (rc == -ERESTARTSYS && freezing(current)) {
+			clear_thread_flag(TIF_SIGPENDING);
+			goto again;
+		}
+	} else {
+		do {
+			tpm_msleep(TPM_TIMEOUT);
+			status = chip->ops->status(chip);
+			if ((status & mask) == mask)
+				return 0;
+		} while (time_before(jiffies, stop));
+	}
+	return -ETIME;
+}
+
 static u8 vtpm_status(struct tpm_chip *chip)
 {
 	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
-- 
2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-10-17 20:32 ` Nayna Jain
@ 2017-10-17 20:32   ` Nayna Jain
  -1 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, jgunthorpe, patrickc, Nayna Jain

The TPM burstcount status indicates the number of bytes that can
be sent to the TPM without causing bus wait states.  Effectively,
it is the number of empty bytes in the command FIFO.

This patch optimizes the tpm_tis_send_data() function by checking
the burstcount only once. And if the burstcount is valid, it writes
all the bytes at once, permitting wait state.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~41sec to ~14sec.

Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
conjunction with the TPM Device Driver work group.
Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++--------------------------
 1 file changed, 15 insertions(+), 27 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index b33126a35694..993328ae988c 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
 {
 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
 	int rc, status, burstcnt;
-	size_t count = 0;
 	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
 
 	status = tpm_tis_status(chip);
@@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
 		}
 	}
 
-	while (count < len - 1) {
-		burstcnt = get_burstcount(chip);
-		if (burstcnt < 0) {
-			dev_err(&chip->dev, "Unable to read burstcount\n");
-			rc = burstcnt;
-			goto out_err;
-		}
-		burstcnt = min_t(int, burstcnt, len - count - 1);
-		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
-					 burstcnt, buf + count);
-		if (rc < 0)
-			goto out_err;
-
-		count += burstcnt;
-
-		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-					&priv->int_queue, false) < 0) {
-			rc = -ETIME;
-			goto out_err;
-		}
-		status = tpm_tis_status(chip);
-		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
-			rc = -EIO;
-			goto out_err;
-		}
+	/*
+	 * Get the initial burstcount to ensure TPM is ready to
+	 * accept data.
+	 */
+	burstcnt = get_burstcount(chip);
+	if (burstcnt < 0) {
+		dev_err(&chip->dev, "Unable to read burstcount\n");
+		rc = burstcnt;
+		goto out_err;
 	}
 
+	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
+			len - 1, buf);
+	if (rc < 0)
+		goto out_err;
+
 	/* write last byte */
-	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
+	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-1]);
 	if (rc < 0)
 		goto out_err;
 
-- 
2.13.3

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-10-17 20:32   ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-security-module

The TPM burstcount status indicates the number of bytes that can
be sent to the TPM without causing bus wait states.  Effectively,
it is the number of empty bytes in the command FIFO.

This patch optimizes the tpm_tis_send_data() function by checking
the burstcount only once. And if the burstcount is valid, it writes
all the bytes at once, permitting wait state.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~41sec to ~14sec.

Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
conjunction with the TPM Device Driver work group.
Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++--------------------------
 1 file changed, 15 insertions(+), 27 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index b33126a35694..993328ae988c 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
 {
 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
 	int rc, status, burstcnt;
-	size_t count = 0;
 	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
 
 	status = tpm_tis_status(chip);
@@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
 		}
 	}
 
-	while (count < len - 1) {
-		burstcnt = get_burstcount(chip);
-		if (burstcnt < 0) {
-			dev_err(&chip->dev, "Unable to read burstcount\n");
-			rc = burstcnt;
-			goto out_err;
-		}
-		burstcnt = min_t(int, burstcnt, len - count - 1);
-		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
-					 burstcnt, buf + count);
-		if (rc < 0)
-			goto out_err;
-
-		count += burstcnt;
-
-		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-					&priv->int_queue, false) < 0) {
-			rc = -ETIME;
-			goto out_err;
-		}
-		status = tpm_tis_status(chip);
-		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
-			rc = -EIO;
-			goto out_err;
-		}
+	/*
+	 * Get the initial burstcount to ensure TPM is ready to
+	 * accept data.
+	 */
+	burstcnt = get_burstcount(chip);
+	if (burstcnt < 0) {
+		dev_err(&chip->dev, "Unable to read burstcount\n");
+		rc = burstcnt;
+		goto out_err;
 	}
 
+	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
+			len - 1, buf);
+	if (rc < 0)
+		goto out_err;
+
 	/* write last byte */
-	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
+	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-1]);
 	if (rc < 0)
 		goto out_err;
 
-- 
2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info@ http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 3/4] tpm: reduce tpm polling delay in tpm_tis_core
  2017-10-17 20:32 ` Nayna Jain
@ 2017-10-17 20:32   ` Nayna Jain
  -1 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, jgunthorpe, patrickc, Nayna Jain

The existing wait_for_tpm_stat() polls for the chip status after
5msec sleep. As per TCG ddwg input, it is expected that tpm might
return status in few usec. So, reducing the delay in polling to
1msec.
Similarly, get_burstcount() function sleeps for 5msec before
retrying for next query to burstcount in a loop. If it takes
lesser time for TPM to return, this 5msec delay is longer than
necessary.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~14sec to ~9sec.

Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_tis_core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 993328ae988c..8b55fdaa67f2 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -31,6 +31,12 @@
 #include "tpm.h"
 #include "tpm_tis_core.h"
 
+/* This is a polling delay to check for status and burstcount.
+ * As per ddwg input, expectation is that status check and burstcount
+ * check should return within few usecs.
+ */
+#define TPM_POLL_SLEEP	1  /* msec */
+
 static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
 					bool check_cancel, bool *canceled)
 {
@@ -82,7 +88,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
 		}
 	} else {
 		do {
-			tpm_msleep(TPM_TIMEOUT);
+			tpm_msleep(TPM_POLL_SLEEP);
 			status = chip->ops->status(chip);
 			if ((status & mask) == mask)
 				return 0;
@@ -224,7 +230,7 @@ static int get_burstcount(struct tpm_chip *chip)
 		burstcnt = (value >> 8) & 0xFFFF;
 		if (burstcnt)
 			return burstcnt;
-		tpm_msleep(TPM_TIMEOUT);
+		tpm_msleep(TPM_POLL_SLEEP);
 	} while (time_before(jiffies, stop));
 	return -EBUSY;
 }
-- 
2.13.3

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 3/4] tpm: reduce tpm polling delay in tpm_tis_core
@ 2017-10-17 20:32   ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-security-module

The existing wait_for_tpm_stat() polls for the chip status after
5msec sleep. As per TCG ddwg input, it is expected that tpm might
return status in few usec. So, reducing the delay in polling to
1msec.
Similarly, get_burstcount() function sleeps for 5msec before
retrying for next query to burstcount in a loop. If it takes
lesser time for TPM to return, this 5msec delay is longer than
necessary.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~14sec to ~9sec.

Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm_tis_core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 993328ae988c..8b55fdaa67f2 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -31,6 +31,12 @@
 #include "tpm.h"
 #include "tpm_tis_core.h"
 
+/* This is a polling delay to check for status and burstcount.
+ * As per ddwg input, expectation is that status check and burstcount
+ * check should return within few usecs.
+ */
+#define TPM_POLL_SLEEP	1  /* msec */
+
 static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
 					bool check_cancel, bool *canceled)
 {
@@ -82,7 +88,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
 		}
 	} else {
 		do {
-			tpm_msleep(TPM_TIMEOUT);
+			tpm_msleep(TPM_POLL_SLEEP);
 			status = chip->ops->status(chip);
 			if ((status & mask) == mask)
 				return 0;
@@ -224,7 +230,7 @@ static int get_burstcount(struct tpm_chip *chip)
 		burstcnt = (value >> 8) & 0xFFFF;
 		if (burstcnt)
 			return burstcnt;
-		tpm_msleep(TPM_TIMEOUT);
+		tpm_msleep(TPM_POLL_SLEEP);
 	} while (time_before(jiffies, stop));
 	return -EBUSY;
 }
-- 
2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 4/4] tpm: use tpm_msleep() value as max delay
  2017-10-17 20:32 ` Nayna Jain
@ 2017-10-17 20:32   ` Nayna Jain
  -1 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, jgunthorpe, patrickc, Nayna Jain

Currently, tpm_msleep() uses delay_msec as the minimum value in
usleep_range. However, that is the maximum time we want to wait.
The function is modified to use the delay_msec as the maximum
value, not the minimum value.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~9sec to ~8sec.

Fixes: 3b9af007869("tpm: replace msleep() with usleep_range() in TPM 1.2/
2.0 generic drivers")

Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 4fc83ac7abeb..644de70de2cc 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -528,8 +528,8 @@ int tpm_pm_resume(struct device *dev);
 
 static inline void tpm_msleep(unsigned int delay_msec)
 {
-	usleep_range(delay_msec * 1000,
-		     (delay_msec * 1000) + TPM_TIMEOUT_RANGE_US);
+	usleep_range((delay_msec * 1000) - TPM_TIMEOUT_RANGE_US,
+		     delay_msec * 1000);
 };
 
 struct tpm_chip *tpm_chip_find_get(int chip_num);
-- 
2.13.3

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* [PATCH v4 4/4] tpm: use tpm_msleep() value as max delay
@ 2017-10-17 20:32   ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-17 20:32 UTC (permalink / raw)
  To: linux-security-module

Currently, tpm_msleep() uses delay_msec as the minimum value in
usleep_range. However, that is the maximum time we want to wait.
The function is modified to use the delay_msec as the maximum
value, not the minimum value.

After this change, performance on a TPM 1.2 with an 8 byte
burstcount for 1000 extends improved from ~9sec to ~8sec.

Fixes: 3b9af007869("tpm: replace msleep() with usleep_range() in TPM 1.2/
2.0 generic drivers")

Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 4fc83ac7abeb..644de70de2cc 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -528,8 +528,8 @@ int tpm_pm_resume(struct device *dev);
 
 static inline void tpm_msleep(unsigned int delay_msec)
 {
-	usleep_range(delay_msec * 1000,
-		     (delay_msec * 1000) + TPM_TIMEOUT_RANGE_US);
+	usleep_range((delay_msec * 1000) - TPM_TIMEOUT_RANGE_US,
+		     delay_msec * 1000);
 };
 
 struct tpm_chip *tpm_chip_find_get(int chip_num);
-- 
2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 3/4] tpm: reduce tpm polling delay in tpm_tis_core
  2017-10-17 20:32   ` Nayna Jain
@ 2017-10-18 15:24     ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-18 15:24 UTC (permalink / raw)
  To: Nayna Jain
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, tpmdd, jgunthorpe, patrickc

On Tue, Oct 17, 2017 at 04:32:31PM -0400, Nayna Jain wrote:
> The existing wait_for_tpm_stat() polls for the chip status after
> 5msec sleep. As per TCG ddwg input, it is expected that tpm might
> return status in few usec. So, reducing the delay in polling to
> 1msec.
> Similarly, get_burstcount() function sleeps for 5msec before
> retrying for next query to burstcount in a loop. If it takes
> lesser time for TPM to return, this 5msec delay is longer than
> necessary.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~14sec to ~9sec.
> 
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  drivers/char/tpm/tpm_tis_core.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index 993328ae988c..8b55fdaa67f2 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -31,6 +31,12 @@
>  #include "tpm.h"
>  #include "tpm_tis_core.h"
>  
> +/* This is a polling delay to check for status and burstcount.
> + * As per ddwg input, expectation is that status check and burstcount
> + * check should return within few usecs.
> + */
> +#define TPM_POLL_SLEEP	1  /* msec */
> +
>  static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>  					bool check_cancel, bool *canceled)
>  {
> @@ -82,7 +88,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
>  		}
>  	} else {
>  		do {
> -			tpm_msleep(TPM_TIMEOUT);
> +			tpm_msleep(TPM_POLL_SLEEP);
>  			status = chip->ops->status(chip);
>  			if ((status & mask) == mask)
>  				return 0;
> @@ -224,7 +230,7 @@ static int get_burstcount(struct tpm_chip *chip)
>  		burstcnt = (value >> 8) & 0xFFFF;
>  		if (burstcnt)
>  			return burstcnt;
> -		tpm_msleep(TPM_TIMEOUT);
> +		tpm_msleep(TPM_POLL_SLEEP);
>  	} while (time_before(jiffies, stop));
>  	return -EBUSY;
>  }
> -- 
> 2.13.3
> 

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 3/4] tpm: reduce tpm polling delay in tpm_tis_core
@ 2017-10-18 15:24     ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-18 15:24 UTC (permalink / raw)
  To: linux-security-module

On Tue, Oct 17, 2017 at 04:32:31PM -0400, Nayna Jain wrote:
> The existing wait_for_tpm_stat() polls for the chip status after
> 5msec sleep. As per TCG ddwg input, it is expected that tpm might
> return status in few usec. So, reducing the delay in polling to
> 1msec.
> Similarly, get_burstcount() function sleeps for 5msec before
> retrying for next query to burstcount in a loop. If it takes
> lesser time for TPM to return, this 5msec delay is longer than
> necessary.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~14sec to ~9sec.
> 
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  drivers/char/tpm/tpm_tis_core.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index 993328ae988c..8b55fdaa67f2 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -31,6 +31,12 @@
>  #include "tpm.h"
>  #include "tpm_tis_core.h"
>  
> +/* This is a polling delay to check for status and burstcount.
> + * As per ddwg input, expectation is that status check and burstcount
> + * check should return within few usecs.
> + */
> +#define TPM_POLL_SLEEP	1  /* msec */
> +
>  static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>  					bool check_cancel, bool *canceled)
>  {
> @@ -82,7 +88,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
>  		}
>  	} else {
>  		do {
> -			tpm_msleep(TPM_TIMEOUT);
> +			tpm_msleep(TPM_POLL_SLEEP);
>  			status = chip->ops->status(chip);
>  			if ((status & mask) == mask)
>  				return 0;
> @@ -224,7 +230,7 @@ static int get_burstcount(struct tpm_chip *chip)
>  		burstcnt = (value >> 8) & 0xFFFF;
>  		if (burstcnt)
>  			return burstcnt;
> -		tpm_msleep(TPM_TIMEOUT);
> +		tpm_msleep(TPM_POLL_SLEEP);
>  	} while (time_before(jiffies, stop));
>  	return -EBUSY;
>  }
> -- 
> 2.13.3
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-10-17 20:32   ` Nayna Jain
@ 2017-10-18 15:25     ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-18 15:25 UTC (permalink / raw)
  To: Nayna Jain
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, tpmdd, jgunthorpe, patrickc

On Tue, Oct 17, 2017 at 04:32:30PM -0400, Nayna Jain wrote:
> The TPM burstcount status indicates the number of bytes that can
> be sent to the TPM without causing bus wait states.  Effectively,
> it is the number of empty bytes in the command FIFO.
> 
> This patch optimizes the tpm_tis_send_data() function by checking
> the burstcount only once. And if the burstcount is valid, it writes
> all the bytes at once, permitting wait state.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~41sec to ~14sec.
> 
> Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
> conjunction with the TPM Device Driver work group.
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++--------------------------
>  1 file changed, 15 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index b33126a35694..993328ae988c 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
>  {
>  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>  	int rc, status, burstcnt;
> -	size_t count = 0;
>  	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
>  
>  	status = tpm_tis_status(chip);
> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
>  		}
>  	}
>  
> -	while (count < len - 1) {
> -		burstcnt = get_burstcount(chip);
> -		if (burstcnt < 0) {
> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> -			rc = burstcnt;
> -			goto out_err;
> -		}
> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> -					 burstcnt, buf + count);
> -		if (rc < 0)
> -			goto out_err;
> -
> -		count += burstcnt;
> -
> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
> -					&priv->int_queue, false) < 0) {
> -			rc = -ETIME;
> -			goto out_err;
> -		}
> -		status = tpm_tis_status(chip);
> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> -			rc = -EIO;
> -			goto out_err;
> -		}
> +	/*
> +	 * Get the initial burstcount to ensure TPM is ready to
> +	 * accept data.
> +	 */
> +	burstcnt = get_burstcount(chip);
> +	if (burstcnt < 0) {
> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> +		rc = burstcnt;
> +		goto out_err;
>  	}
>  
> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> +			len - 1, buf);
> +	if (rc < 0)
> +		goto out_err;
> +
>  	/* write last byte */
> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-1]);
>  	if (rc < 0)
>  		goto out_err;
>  
> -- 
> 2.13.3
> 

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-10-18 15:25     ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-18 15:25 UTC (permalink / raw)
  To: linux-security-module

On Tue, Oct 17, 2017 at 04:32:30PM -0400, Nayna Jain wrote:
> The TPM burstcount status indicates the number of bytes that can
> be sent to the TPM without causing bus wait states.  Effectively,
> it is the number of empty bytes in the command FIFO.
> 
> This patch optimizes the tpm_tis_send_data() function by checking
> the burstcount only once. And if the burstcount is valid, it writes
> all the bytes at once, permitting wait state.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~41sec to ~14sec.
> 
> Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
> conjunction with the TPM Device Driver work group.
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++--------------------------
>  1 file changed, 15 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index b33126a35694..993328ae988c 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
>  {
>  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>  	int rc, status, burstcnt;
> -	size_t count = 0;
>  	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
>  
>  	status = tpm_tis_status(chip);
> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
>  		}
>  	}
>  
> -	while (count < len - 1) {
> -		burstcnt = get_burstcount(chip);
> -		if (burstcnt < 0) {
> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> -			rc = burstcnt;
> -			goto out_err;
> -		}
> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> -					 burstcnt, buf + count);
> -		if (rc < 0)
> -			goto out_err;
> -
> -		count += burstcnt;
> -
> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
> -					&priv->int_queue, false) < 0) {
> -			rc = -ETIME;
> -			goto out_err;
> -		}
> -		status = tpm_tis_status(chip);
> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> -			rc = -EIO;
> -			goto out_err;
> -		}
> +	/*
> +	 * Get the initial burstcount to ensure TPM is ready to
> +	 * accept data.
> +	 */
> +	burstcnt = get_burstcount(chip);
> +	if (burstcnt < 0) {
> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> +		rc = burstcnt;
> +		goto out_err;
>  	}
>  
> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> +			len - 1, buf);
> +	if (rc < 0)
> +		goto out_err;
> +
>  	/* write last byte */
> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-1]);
>  	if (rc < 0)
>  		goto out_err;
>  
> -- 
> 2.13.3
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
  2017-10-17 20:32   ` Nayna Jain
@ 2017-10-19 14:21     ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-19 14:21 UTC (permalink / raw)
  To: Nayna Jain
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, tpmdd, jgunthorpe, patrickc

On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
> The function wait_for_tpm_stat() is currently defined in
> tpm-interface file. It is a hardware specific function used
> only by tpm_tis and xen-tpmfront, so it is removed from
> tpm-interface.c and defined in respective driver files.
> 
> Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
>  drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
>  drivers/char/tpm/tpm.h           |  2 --
>  drivers/char/tpm/tpm_tis_core.c  | 60 ++++++++++++++++++++++++++++++++++++++++
>  drivers/char/tpm/xen-tpmfront.c  | 60 ++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 120 insertions(+), 62 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 1d6729be4cd6..313f7618d569 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t buflen)
>  }
>  EXPORT_SYMBOL_GPL(tpm_send);
>  
> -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> -					bool check_cancel, bool *canceled)
> -{
> -	u8 status = chip->ops->status(chip);
> -
> -	*canceled = false;
> -	if ((status & mask) == mask)
> -		return true;
> -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> -		*canceled = true;
> -		return true;
> -	}
> -	return false;
> -}
> -
> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
> -		      wait_queue_head_t *queue, bool check_cancel)
> -{
> -	unsigned long stop;
> -	long rc;
> -	u8 status;
> -	bool canceled = false;
> -
> -	/* check current status */
> -	status = chip->ops->status(chip);
> -	if ((status & mask) == mask)
> -		return 0;
> -
> -	stop = jiffies + timeout;
> -
> -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> -again:
> -		timeout = stop - jiffies;
> -		if ((long)timeout <= 0)
> -			return -ETIME;
> -		rc = wait_event_interruptible_timeout(*queue,
> -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> -					       &canceled),
> -			timeout);
> -		if (rc > 0) {
> -			if (canceled)
> -				return -ECANCELED;
> -			return 0;
> -		}
> -		if (rc == -ERESTARTSYS && freezing(current)) {
> -			clear_thread_flag(TIF_SIGPENDING);
> -			goto again;
> -		}
> -	} else {
> -		do {
> -			tpm_msleep(TPM_TIMEOUT);
> -			status = chip->ops->status(chip);
> -			if ((status & mask) == mask)
> -				return 0;
> -		} while (time_before(jiffies, stop));
> -	}
> -	return -ETIME;
> -}
> -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
> -
>  #define TPM_ORD_SAVESTATE 152
>  #define SAVESTATE_RESULT_SIZE 10
>  
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 2d5466a72e40..4fc83ac7abeb 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
>  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
>  int tpm_pm_suspend(struct device *dev);
>  int tpm_pm_resume(struct device *dev);
> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
> -		      wait_queue_head_t *queue, bool check_cancel);
>  
>  static inline void tpm_msleep(unsigned int delay_msec)
>  {
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index 63bc6c3b949e..b33126a35694 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -31,6 +31,66 @@
>  #include "tpm.h"
>  #include "tpm_tis_core.h"
>  
> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> +					bool check_cancel, bool *canceled)
> +{
> +	u8 status = chip->ops->status(chip);
> +
> +	*canceled = false;
> +	if ((status & mask) == mask)
> +		return true;
> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> +		*canceled = true;
> +		return true;
> +	}
> +	return false;
> +}
> +
> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> +		unsigned long timeout, wait_queue_head_t *queue,
> +		bool check_cancel)
> +{
> +	unsigned long stop;
> +	long rc;
> +	u8 status;
> +	bool canceled = false;
> +
> +	/* check current status */
> +	status = chip->ops->status(chip);
> +	if ((status & mask) == mask)
> +		return 0;
> +
> +	stop = jiffies + timeout;
> +
> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> +again:
> +		timeout = stop - jiffies;
> +		if ((long)timeout <= 0)
> +			return -ETIME;
> +		rc = wait_event_interruptible_timeout(*queue,
> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> +					       &canceled),
> +			timeout);
> +		if (rc > 0) {
> +			if (canceled)
> +				return -ECANCELED;
> +			return 0;
> +		}
> +		if (rc == -ERESTARTSYS && freezing(current)) {
> +			clear_thread_flag(TIF_SIGPENDING);
> +			goto again;
> +		}
> +	} else {
> +		do {
> +			tpm_msleep(TPM_TIMEOUT);
> +			status = chip->ops->status(chip);
> +			if ((status & mask) == mask)
> +				return 0;
> +		} while (time_before(jiffies, stop));
> +	}
> +	return -ETIME;
> +}
> +
>  /* Before we attempt to access the TPM we must see that the valid bit is set.
>   * The specification says that this bit is 0 at reset and remains 0 until the
>   * 'TPM has gone through its self test and initialization and has established
> diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
> index 656e8af95d52..d20a0a9ded27 100644
> --- a/drivers/char/tpm/xen-tpmfront.c
> +++ b/drivers/char/tpm/xen-tpmfront.c
> @@ -39,6 +39,66 @@ enum status_bits {
>  	VTPM_STATUS_CANCELED = 0x8,
>  };
>  
> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> +					bool check_cancel, bool *canceled)
> +{
> +	u8 status = chip->ops->status(chip);
> +
> +	*canceled = false;
> +	if ((status & mask) == mask)
> +		return true;
> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> +		*canceled = true;
> +		return true;
> +	}
> +	return false;
> +}
> +
> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> +		unsigned long timeout, wait_queue_head_t *queue,
> +		bool check_cancel)
> +{
> +	unsigned long stop;
> +	long rc;
> +	u8 status;
> +	bool canceled = false;
> +
> +	/* check current status */
> +	status = chip->ops->status(chip);
> +	if ((status & mask) == mask)
> +		return 0;
> +
> +	stop = jiffies + timeout;
> +
> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> +again:
> +		timeout = stop - jiffies;
> +		if ((long)timeout <= 0)
> +			return -ETIME;
> +		rc = wait_event_interruptible_timeout(*queue,
> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> +					       &canceled),
> +			timeout);
> +		if (rc > 0) {
> +			if (canceled)
> +				return -ECANCELED;
> +			return 0;
> +		}
> +		if (rc == -ERESTARTSYS && freezing(current)) {
> +			clear_thread_flag(TIF_SIGPENDING);
> +			goto again;
> +		}
> +	} else {
> +		do {
> +			tpm_msleep(TPM_TIMEOUT);
> +			status = chip->ops->status(chip);
> +			if ((status & mask) == mask)
> +				return 0;
> +		} while (time_before(jiffies, stop));
> +	}
> +	return -ETIME;
> +}
> +
>  static u8 vtpm_status(struct tpm_chip *chip)
>  {
>  	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
> -- 
> 2.13.3
> 

This commit caused a compiler warning because freezer.h was not included
to xen-tpmfront.c. I manually fixed it.

Reviewed-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
@ 2017-10-19 14:21     ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-19 14:21 UTC (permalink / raw)
  To: linux-security-module

On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
> The function wait_for_tpm_stat() is currently defined in
> tpm-interface file. It is a hardware specific function used
> only by tpm_tis and xen-tpmfront, so it is removed from
> tpm-interface.c and defined in respective driver files.
> 
> Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
>  drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
>  drivers/char/tpm/tpm.h           |  2 --
>  drivers/char/tpm/tpm_tis_core.c  | 60 ++++++++++++++++++++++++++++++++++++++++
>  drivers/char/tpm/xen-tpmfront.c  | 60 ++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 120 insertions(+), 62 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 1d6729be4cd6..313f7618d569 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t buflen)
>  }
>  EXPORT_SYMBOL_GPL(tpm_send);
>  
> -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> -					bool check_cancel, bool *canceled)
> -{
> -	u8 status = chip->ops->status(chip);
> -
> -	*canceled = false;
> -	if ((status & mask) == mask)
> -		return true;
> -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> -		*canceled = true;
> -		return true;
> -	}
> -	return false;
> -}
> -
> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
> -		      wait_queue_head_t *queue, bool check_cancel)
> -{
> -	unsigned long stop;
> -	long rc;
> -	u8 status;
> -	bool canceled = false;
> -
> -	/* check current status */
> -	status = chip->ops->status(chip);
> -	if ((status & mask) == mask)
> -		return 0;
> -
> -	stop = jiffies + timeout;
> -
> -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> -again:
> -		timeout = stop - jiffies;
> -		if ((long)timeout <= 0)
> -			return -ETIME;
> -		rc = wait_event_interruptible_timeout(*queue,
> -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> -					       &canceled),
> -			timeout);
> -		if (rc > 0) {
> -			if (canceled)
> -				return -ECANCELED;
> -			return 0;
> -		}
> -		if (rc == -ERESTARTSYS && freezing(current)) {
> -			clear_thread_flag(TIF_SIGPENDING);
> -			goto again;
> -		}
> -	} else {
> -		do {
> -			tpm_msleep(TPM_TIMEOUT);
> -			status = chip->ops->status(chip);
> -			if ((status & mask) == mask)
> -				return 0;
> -		} while (time_before(jiffies, stop));
> -	}
> -	return -ETIME;
> -}
> -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
> -
>  #define TPM_ORD_SAVESTATE 152
>  #define SAVESTATE_RESULT_SIZE 10
>  
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 2d5466a72e40..4fc83ac7abeb 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
>  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
>  int tpm_pm_suspend(struct device *dev);
>  int tpm_pm_resume(struct device *dev);
> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
> -		      wait_queue_head_t *queue, bool check_cancel);
>  
>  static inline void tpm_msleep(unsigned int delay_msec)
>  {
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index 63bc6c3b949e..b33126a35694 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -31,6 +31,66 @@
>  #include "tpm.h"
>  #include "tpm_tis_core.h"
>  
> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> +					bool check_cancel, bool *canceled)
> +{
> +	u8 status = chip->ops->status(chip);
> +
> +	*canceled = false;
> +	if ((status & mask) == mask)
> +		return true;
> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> +		*canceled = true;
> +		return true;
> +	}
> +	return false;
> +}
> +
> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> +		unsigned long timeout, wait_queue_head_t *queue,
> +		bool check_cancel)
> +{
> +	unsigned long stop;
> +	long rc;
> +	u8 status;
> +	bool canceled = false;
> +
> +	/* check current status */
> +	status = chip->ops->status(chip);
> +	if ((status & mask) == mask)
> +		return 0;
> +
> +	stop = jiffies + timeout;
> +
> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> +again:
> +		timeout = stop - jiffies;
> +		if ((long)timeout <= 0)
> +			return -ETIME;
> +		rc = wait_event_interruptible_timeout(*queue,
> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> +					       &canceled),
> +			timeout);
> +		if (rc > 0) {
> +			if (canceled)
> +				return -ECANCELED;
> +			return 0;
> +		}
> +		if (rc == -ERESTARTSYS && freezing(current)) {
> +			clear_thread_flag(TIF_SIGPENDING);
> +			goto again;
> +		}
> +	} else {
> +		do {
> +			tpm_msleep(TPM_TIMEOUT);
> +			status = chip->ops->status(chip);
> +			if ((status & mask) == mask)
> +				return 0;
> +		} while (time_before(jiffies, stop));
> +	}
> +	return -ETIME;
> +}
> +
>  /* Before we attempt to access the TPM we must see that the valid bit is set.
>   * The specification says that this bit is 0 at reset and remains 0 until the
>   * 'TPM has gone through its self test and initialization and has established
> diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
> index 656e8af95d52..d20a0a9ded27 100644
> --- a/drivers/char/tpm/xen-tpmfront.c
> +++ b/drivers/char/tpm/xen-tpmfront.c
> @@ -39,6 +39,66 @@ enum status_bits {
>  	VTPM_STATUS_CANCELED = 0x8,
>  };
>  
> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> +					bool check_cancel, bool *canceled)
> +{
> +	u8 status = chip->ops->status(chip);
> +
> +	*canceled = false;
> +	if ((status & mask) == mask)
> +		return true;
> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> +		*canceled = true;
> +		return true;
> +	}
> +	return false;
> +}
> +
> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> +		unsigned long timeout, wait_queue_head_t *queue,
> +		bool check_cancel)
> +{
> +	unsigned long stop;
> +	long rc;
> +	u8 status;
> +	bool canceled = false;
> +
> +	/* check current status */
> +	status = chip->ops->status(chip);
> +	if ((status & mask) == mask)
> +		return 0;
> +
> +	stop = jiffies + timeout;
> +
> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> +again:
> +		timeout = stop - jiffies;
> +		if ((long)timeout <= 0)
> +			return -ETIME;
> +		rc = wait_event_interruptible_timeout(*queue,
> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> +					       &canceled),
> +			timeout);
> +		if (rc > 0) {
> +			if (canceled)
> +				return -ECANCELED;
> +			return 0;
> +		}
> +		if (rc == -ERESTARTSYS && freezing(current)) {
> +			clear_thread_flag(TIF_SIGPENDING);
> +			goto again;
> +		}
> +	} else {
> +		do {
> +			tpm_msleep(TPM_TIMEOUT);
> +			status = chip->ops->status(chip);
> +			if ((status & mask) == mask)
> +				return 0;
> +		} while (time_before(jiffies, stop));
> +	}
> +	return -ETIME;
> +}
> +
>  static u8 vtpm_status(struct tpm_chip *chip)
>  {
>  	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
> -- 
> 2.13.3
> 

This commit caused a compiler warning because freezer.h was not included
to xen-tpmfront.c. I manually fixed it.

Reviewed-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 4/4] tpm: use tpm_msleep() value as max delay
  2017-10-17 20:32   ` Nayna Jain
@ 2017-10-19 14:22     ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-19 14:22 UTC (permalink / raw)
  To: Nayna Jain
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, tpmdd, jgunthorpe, patrickc

On Tue, Oct 17, 2017 at 04:32:32PM -0400, Nayna Jain wrote:
> Currently, tpm_msleep() uses delay_msec as the minimum value in
> usleep_range. However, that is the maximum time we want to wait.
> The function is modified to use the delay_msec as the maximum
> value, not the minimum value.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~9sec to ~8sec.
> 
> Fixes: 3b9af007869("tpm: replace msleep() with usleep_range() in TPM 1.2/
> 2.0 generic drivers")
> 
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
>  drivers/char/tpm/tpm.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 4fc83ac7abeb..644de70de2cc 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -528,8 +528,8 @@ int tpm_pm_resume(struct device *dev);
>  
>  static inline void tpm_msleep(unsigned int delay_msec)
>  {
> -	usleep_range(delay_msec * 1000,
> -		     (delay_msec * 1000) + TPM_TIMEOUT_RANGE_US);
> +	usleep_range((delay_msec * 1000) - TPM_TIMEOUT_RANGE_US,
> +		     delay_msec * 1000);
>  };
>  
>  struct tpm_chip *tpm_chip_find_get(int chip_num);
> -- 
> 2.13.3
> 

Tested-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 4/4] tpm: use tpm_msleep() value as max delay
@ 2017-10-19 14:22     ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-19 14:22 UTC (permalink / raw)
  To: linux-security-module

On Tue, Oct 17, 2017 at 04:32:32PM -0400, Nayna Jain wrote:
> Currently, tpm_msleep() uses delay_msec as the minimum value in
> usleep_range. However, that is the maximum time we want to wait.
> The function is modified to use the delay_msec as the maximum
> value, not the minimum value.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~9sec to ~8sec.
> 
> Fixes: 3b9af007869("tpm: replace msleep() with usleep_range() in TPM 1.2/
> 2.0 generic drivers")
> 
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
>  drivers/char/tpm/tpm.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 4fc83ac7abeb..644de70de2cc 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -528,8 +528,8 @@ int tpm_pm_resume(struct device *dev);
>  
>  static inline void tpm_msleep(unsigned int delay_msec)
>  {
> -	usleep_range(delay_msec * 1000,
> -		     (delay_msec * 1000) + TPM_TIMEOUT_RANGE_US);
> +	usleep_range((delay_msec * 1000) - TPM_TIMEOUT_RANGE_US,
> +		     delay_msec * 1000);
>  };
>  
>  struct tpm_chip *tpm_chip_find_get(int chip_num);
> -- 
> 2.13.3
> 

Tested-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 3/4] tpm: reduce tpm polling delay in tpm_tis_core
  2017-10-18 15:24     ` Jarkko Sakkinen
@ 2017-10-19 14:22       ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-19 14:22 UTC (permalink / raw)
  To: Nayna Jain
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, tpmdd, jgunthorpe, patrickc

On Wed, Oct 18, 2017 at 06:24:47PM +0300, Jarkko Sakkinen wrote:
> On Tue, Oct 17, 2017 at 04:32:31PM -0400, Nayna Jain wrote:
> > The existing wait_for_tpm_stat() polls for the chip status after
> > 5msec sleep. As per TCG ddwg input, it is expected that tpm might
> > return status in few usec. So, reducing the delay in polling to
> > 1msec.
> > Similarly, get_burstcount() function sleeps for 5msec before
> > retrying for next query to burstcount in a loop. If it takes
> > lesser time for TPM to return, this 5msec delay is longer than
> > necessary.
> > 
> > After this change, performance on a TPM 1.2 with an 8 byte
> > burstcount for 1000 extends improved from ~14sec to ~9sec.
> > 
> > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> 
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

Tested-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 3/4] tpm: reduce tpm polling delay in tpm_tis_core
@ 2017-10-19 14:22       ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-19 14:22 UTC (permalink / raw)
  To: linux-security-module

On Wed, Oct 18, 2017 at 06:24:47PM +0300, Jarkko Sakkinen wrote:
> On Tue, Oct 17, 2017 at 04:32:31PM -0400, Nayna Jain wrote:
> > The existing wait_for_tpm_stat() polls for the chip status after
> > 5msec sleep. As per TCG ddwg input, it is expected that tpm might
> > return status in few usec. So, reducing the delay in polling to
> > 1msec.
> > Similarly, get_burstcount() function sleeps for 5msec before
> > retrying for next query to burstcount in a loop. If it takes
> > lesser time for TPM to return, this 5msec delay is longer than
> > necessary.
> > 
> > After this change, performance on a TPM 1.2 with an 8 byte
> > burstcount for 1000 extends improved from ~14sec to ~9sec.
> > 
> > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> 
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

Tested-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-10-17 20:32   ` Nayna Jain
@ 2017-10-19 14:23     ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-19 14:23 UTC (permalink / raw)
  To: Nayna Jain
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, tpmdd, jgunthorpe, patrickc

On Tue, Oct 17, 2017 at 04:32:30PM -0400, Nayna Jain wrote:
> The TPM burstcount status indicates the number of bytes that can
> be sent to the TPM without causing bus wait states.  Effectively,
> it is the number of empty bytes in the command FIFO.
> 
> This patch optimizes the tpm_tis_send_data() function by checking
> the burstcount only once. And if the burstcount is valid, it writes
> all the bytes at once, permitting wait state.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~41sec to ~14sec.
> 
> Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
> conjunction with the TPM Device Driver work group.
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> ---
>  drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++--------------------------
>  1 file changed, 15 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index b33126a35694..993328ae988c 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
>  {
>  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>  	int rc, status, burstcnt;
> -	size_t count = 0;
>  	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
>  
>  	status = tpm_tis_status(chip);
> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
>  		}
>  	}
>  
> -	while (count < len - 1) {
> -		burstcnt = get_burstcount(chip);
> -		if (burstcnt < 0) {
> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> -			rc = burstcnt;
> -			goto out_err;
> -		}
> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> -					 burstcnt, buf + count);
> -		if (rc < 0)
> -			goto out_err;
> -
> -		count += burstcnt;
> -
> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
> -					&priv->int_queue, false) < 0) {
> -			rc = -ETIME;
> -			goto out_err;
> -		}
> -		status = tpm_tis_status(chip);
> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> -			rc = -EIO;
> -			goto out_err;
> -		}
> +	/*
> +	 * Get the initial burstcount to ensure TPM is ready to
> +	 * accept data.
> +	 */
> +	burstcnt = get_burstcount(chip);
> +	if (burstcnt < 0) {
> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> +		rc = burstcnt;
> +		goto out_err;
>  	}
>  
> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> +			len - 1, buf);
> +	if (rc < 0)
> +		goto out_err;
> +
>  	/* write last byte */
> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-1]);
>  	if (rc < 0)
>  		goto out_err;
>  
> -- 
> 2.13.3
> 

Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-10-19 14:23     ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-19 14:23 UTC (permalink / raw)
  To: linux-security-module

On Tue, Oct 17, 2017 at 04:32:30PM -0400, Nayna Jain wrote:
> The TPM burstcount status indicates the number of bytes that can
> be sent to the TPM without causing bus wait states.  Effectively,
> it is the number of empty bytes in the command FIFO.
> 
> This patch optimizes the tpm_tis_send_data() function by checking
> the burstcount only once. And if the burstcount is valid, it writes
> all the bytes at once, permitting wait state.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~41sec to ~14sec.
> 
> Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
> conjunction with the TPM Device Driver work group.
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> ---
>  drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++--------------------------
>  1 file changed, 15 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index b33126a35694..993328ae988c 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
>  {
>  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>  	int rc, status, burstcnt;
> -	size_t count = 0;
>  	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
>  
>  	status = tpm_tis_status(chip);
> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
>  		}
>  	}
>  
> -	while (count < len - 1) {
> -		burstcnt = get_burstcount(chip);
> -		if (burstcnt < 0) {
> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> -			rc = burstcnt;
> -			goto out_err;
> -		}
> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> -					 burstcnt, buf + count);
> -		if (rc < 0)
> -			goto out_err;
> -
> -		count += burstcnt;
> -
> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
> -					&priv->int_queue, false) < 0) {
> -			rc = -ETIME;
> -			goto out_err;
> -		}
> -		status = tpm_tis_status(chip);
> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> -			rc = -EIO;
> -			goto out_err;
> -		}
> +	/*
> +	 * Get the initial burstcount to ensure TPM is ready to
> +	 * accept data.
> +	 */
> +	burstcnt = get_burstcount(chip);
> +	if (burstcnt < 0) {
> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> +		rc = burstcnt;
> +		goto out_err;
>  	}
>  
> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> +			len - 1, buf);
> +	if (rc < 0)
> +		goto out_err;
> +
>  	/* write last byte */
> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-1]);
>  	if (rc < 0)
>  		goto out_err;
>  
> -- 
> 2.13.3
> 

Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* RE: [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
  2017-10-19 14:21     ` Jarkko Sakkinen
@ 2017-10-19 17:00       ` Alexander.Steffen at infineon.com
  -1 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen @ 2017-10-19 17:00 UTC (permalink / raw)
  To: jarkko.sakkinen, nayna
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, tpmdd, jgunthorpe, patrickc

> On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
> > The function wait_for_tpm_stat() is currently defined in
> > tpm-interface file. It is a hardware specific function used
> > only by tpm_tis and xen-tpmfront, so it is removed from
> > tpm-interface.c and defined in respective driver files.
> >
> > Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > ---
> >  drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
> >  drivers/char/tpm/tpm.h           |  2 --
> >  drivers/char/tpm/tpm_tis_core.c  | 60
> ++++++++++++++++++++++++++++++++++++++++
> >  drivers/char/tpm/xen-tpmfront.c  | 60
> ++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 120 insertions(+), 62 deletions(-)
> >
> > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
> interface.c
> > index 1d6729be4cd6..313f7618d569 100644
> > --- a/drivers/char/tpm/tpm-interface.c
> > +++ b/drivers/char/tpm/tpm-interface.c
> > @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t
> buflen)
> >  }
> >  EXPORT_SYMBOL_GPL(tpm_send);
> >
> > -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > -					bool check_cancel, bool *canceled)
> > -{
> > -	u8 status = chip->ops->status(chip);
> > -
> > -	*canceled = false;
> > -	if ((status & mask) == mask)
> > -		return true;
> > -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > -		*canceled = true;
> > -		return true;
> > -	}
> > -	return false;
> > -}
> > -
> > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> timeout,
> > -		      wait_queue_head_t *queue, bool check_cancel)
> > -{
> > -	unsigned long stop;
> > -	long rc;
> > -	u8 status;
> > -	bool canceled = false;
> > -
> > -	/* check current status */
> > -	status = chip->ops->status(chip);
> > -	if ((status & mask) == mask)
> > -		return 0;
> > -
> > -	stop = jiffies + timeout;
> > -
> > -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > -again:
> > -		timeout = stop - jiffies;
> > -		if ((long)timeout <= 0)
> > -			return -ETIME;
> > -		rc = wait_event_interruptible_timeout(*queue,
> > -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > -					       &canceled),
> > -			timeout);
> > -		if (rc > 0) {
> > -			if (canceled)
> > -				return -ECANCELED;
> > -			return 0;
> > -		}
> > -		if (rc == -ERESTARTSYS && freezing(current)) {
> > -			clear_thread_flag(TIF_SIGPENDING);
> > -			goto again;
> > -		}
> > -	} else {
> > -		do {
> > -			tpm_msleep(TPM_TIMEOUT);
> > -			status = chip->ops->status(chip);
> > -			if ((status & mask) == mask)
> > -				return 0;
> > -		} while (time_before(jiffies, stop));
> > -	}
> > -	return -ETIME;
> > -}
> > -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
> > -
> >  #define TPM_ORD_SAVESTATE 152
> >  #define SAVESTATE_RESULT_SIZE 10
> >
> > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> > index 2d5466a72e40..4fc83ac7abeb 100644
> > --- a/drivers/char/tpm/tpm.h
> > +++ b/drivers/char/tpm/tpm.h
> > @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
> >  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32
> ordinal);
> >  int tpm_pm_suspend(struct device *dev);
> >  int tpm_pm_resume(struct device *dev);
> > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> timeout,
> > -		      wait_queue_head_t *queue, bool check_cancel);
> >
> >  static inline void tpm_msleep(unsigned int delay_msec)
> >  {
> > diff --git a/drivers/char/tpm/tpm_tis_core.c
> b/drivers/char/tpm/tpm_tis_core.c
> > index 63bc6c3b949e..b33126a35694 100644
> > --- a/drivers/char/tpm/tpm_tis_core.c
> > +++ b/drivers/char/tpm/tpm_tis_core.c
> > @@ -31,6 +31,66 @@
> >  #include "tpm.h"
> >  #include "tpm_tis_core.h"
> >
> > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > +					bool check_cancel, bool *canceled)
> > +{
> > +	u8 status = chip->ops->status(chip);
> > +
> > +	*canceled = false;
> > +	if ((status & mask) == mask)
> > +		return true;
> > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > +		*canceled = true;
> > +		return true;
> > +	}
> > +	return false;
> > +}
> > +
> > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > +		unsigned long timeout, wait_queue_head_t *queue,
> > +		bool check_cancel)
> > +{
> > +	unsigned long stop;
> > +	long rc;
> > +	u8 status;
> > +	bool canceled = false;
> > +
> > +	/* check current status */
> > +	status = chip->ops->status(chip);
> > +	if ((status & mask) == mask)
> > +		return 0;
> > +
> > +	stop = jiffies + timeout;
> > +
> > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > +again:
> > +		timeout = stop - jiffies;
> > +		if ((long)timeout <= 0)
> > +			return -ETIME;
> > +		rc = wait_event_interruptible_timeout(*queue,
> > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > +					       &canceled),
> > +			timeout);
> > +		if (rc > 0) {
> > +			if (canceled)
> > +				return -ECANCELED;
> > +			return 0;
> > +		}
> > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > +			clear_thread_flag(TIF_SIGPENDING);
> > +			goto again;
> > +		}
> > +	} else {
> > +		do {
> > +			tpm_msleep(TPM_TIMEOUT);
> > +			status = chip->ops->status(chip);
> > +			if ((status & mask) == mask)
> > +				return 0;
> > +		} while (time_before(jiffies, stop));
> > +	}
> > +	return -ETIME;
> > +}
> > +
> >  /* Before we attempt to access the TPM we must see that the valid bit is
> set.
> >   * The specification says that this bit is 0 at reset and remains 0 until the
> >   * 'TPM has gone through its self test and initialization and has established
> > diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-
> tpmfront.c
> > index 656e8af95d52..d20a0a9ded27 100644
> > --- a/drivers/char/tpm/xen-tpmfront.c
> > +++ b/drivers/char/tpm/xen-tpmfront.c
> > @@ -39,6 +39,66 @@ enum status_bits {
> >  	VTPM_STATUS_CANCELED = 0x8,
> >  };
> >
> > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > +					bool check_cancel, bool *canceled)
> > +{
> > +	u8 status = chip->ops->status(chip);
> > +
> > +	*canceled = false;
> > +	if ((status & mask) == mask)
> > +		return true;
> > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > +		*canceled = true;
> > +		return true;
> > +	}
> > +	return false;
> > +}
> > +
> > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > +		unsigned long timeout, wait_queue_head_t *queue,
> > +		bool check_cancel)
> > +{
> > +	unsigned long stop;
> > +	long rc;
> > +	u8 status;
> > +	bool canceled = false;
> > +
> > +	/* check current status */
> > +	status = chip->ops->status(chip);
> > +	if ((status & mask) == mask)
> > +		return 0;
> > +
> > +	stop = jiffies + timeout;
> > +
> > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > +again:
> > +		timeout = stop - jiffies;
> > +		if ((long)timeout <= 0)
> > +			return -ETIME;
> > +		rc = wait_event_interruptible_timeout(*queue,
> > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > +					       &canceled),
> > +			timeout);
> > +		if (rc > 0) {
> > +			if (canceled)
> > +				return -ECANCELED;
> > +			return 0;
> > +		}
> > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > +			clear_thread_flag(TIF_SIGPENDING);
> > +			goto again;
> > +		}
> > +	} else {
> > +		do {
> > +			tpm_msleep(TPM_TIMEOUT);
> > +			status = chip->ops->status(chip);
> > +			if ((status & mask) == mask)
> > +				return 0;
> > +		} while (time_before(jiffies, stop));
> > +	}
> > +	return -ETIME;
> > +}
> > +
> >  static u8 vtpm_status(struct tpm_chip *chip)
> >  {
> >  	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
> > --
> > 2.13.3
> >
> 
> This commit caused a compiler warning because freezer.h was not included
> to xen-tpmfront.c. I manually fixed it.

Yep, and checkpatch.pl still complains about some stuff (mostly whitespace) in both patch 1/4 and 2/4. When fixed patches are available, I can run them again through my automation.

> Reviewed-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>
> Tested-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>
> 
> /Jarkko

Alexander

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
@ 2017-10-19 17:00       ` Alexander.Steffen at infineon.com
  0 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen at infineon.com @ 2017-10-19 17:00 UTC (permalink / raw)
  To: linux-security-module

> On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
> > The function wait_for_tpm_stat() is currently defined in
> > tpm-interface file. It is a hardware specific function used
> > only by tpm_tis and xen-tpmfront, so it is removed from
> > tpm-interface.c and defined in respective driver files.
> >
> > Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > ---
> >  drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
> >  drivers/char/tpm/tpm.h           |  2 --
> >  drivers/char/tpm/tpm_tis_core.c  | 60
> ++++++++++++++++++++++++++++++++++++++++
> >  drivers/char/tpm/xen-tpmfront.c  | 60
> ++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 120 insertions(+), 62 deletions(-)
> >
> > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
> interface.c
> > index 1d6729be4cd6..313f7618d569 100644
> > --- a/drivers/char/tpm/tpm-interface.c
> > +++ b/drivers/char/tpm/tpm-interface.c
> > @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t
> buflen)
> >  }
> >  EXPORT_SYMBOL_GPL(tpm_send);
> >
> > -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > -					bool check_cancel, bool *canceled)
> > -{
> > -	u8 status = chip->ops->status(chip);
> > -
> > -	*canceled = false;
> > -	if ((status & mask) == mask)
> > -		return true;
> > -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > -		*canceled = true;
> > -		return true;
> > -	}
> > -	return false;
> > -}
> > -
> > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> timeout,
> > -		      wait_queue_head_t *queue, bool check_cancel)
> > -{
> > -	unsigned long stop;
> > -	long rc;
> > -	u8 status;
> > -	bool canceled = false;
> > -
> > -	/* check current status */
> > -	status = chip->ops->status(chip);
> > -	if ((status & mask) == mask)
> > -		return 0;
> > -
> > -	stop = jiffies + timeout;
> > -
> > -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > -again:
> > -		timeout = stop - jiffies;
> > -		if ((long)timeout <= 0)
> > -			return -ETIME;
> > -		rc = wait_event_interruptible_timeout(*queue,
> > -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > -					       &canceled),
> > -			timeout);
> > -		if (rc > 0) {
> > -			if (canceled)
> > -				return -ECANCELED;
> > -			return 0;
> > -		}
> > -		if (rc == -ERESTARTSYS && freezing(current)) {
> > -			clear_thread_flag(TIF_SIGPENDING);
> > -			goto again;
> > -		}
> > -	} else {
> > -		do {
> > -			tpm_msleep(TPM_TIMEOUT);
> > -			status = chip->ops->status(chip);
> > -			if ((status & mask) == mask)
> > -				return 0;
> > -		} while (time_before(jiffies, stop));
> > -	}
> > -	return -ETIME;
> > -}
> > -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
> > -
> >  #define TPM_ORD_SAVESTATE 152
> >  #define SAVESTATE_RESULT_SIZE 10
> >
> > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> > index 2d5466a72e40..4fc83ac7abeb 100644
> > --- a/drivers/char/tpm/tpm.h
> > +++ b/drivers/char/tpm/tpm.h
> > @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
> >  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32
> ordinal);
> >  int tpm_pm_suspend(struct device *dev);
> >  int tpm_pm_resume(struct device *dev);
> > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> timeout,
> > -		      wait_queue_head_t *queue, bool check_cancel);
> >
> >  static inline void tpm_msleep(unsigned int delay_msec)
> >  {
> > diff --git a/drivers/char/tpm/tpm_tis_core.c
> b/drivers/char/tpm/tpm_tis_core.c
> > index 63bc6c3b949e..b33126a35694 100644
> > --- a/drivers/char/tpm/tpm_tis_core.c
> > +++ b/drivers/char/tpm/tpm_tis_core.c
> > @@ -31,6 +31,66 @@
> >  #include "tpm.h"
> >  #include "tpm_tis_core.h"
> >
> > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > +					bool check_cancel, bool *canceled)
> > +{
> > +	u8 status = chip->ops->status(chip);
> > +
> > +	*canceled = false;
> > +	if ((status & mask) == mask)
> > +		return true;
> > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > +		*canceled = true;
> > +		return true;
> > +	}
> > +	return false;
> > +}
> > +
> > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > +		unsigned long timeout, wait_queue_head_t *queue,
> > +		bool check_cancel)
> > +{
> > +	unsigned long stop;
> > +	long rc;
> > +	u8 status;
> > +	bool canceled = false;
> > +
> > +	/* check current status */
> > +	status = chip->ops->status(chip);
> > +	if ((status & mask) == mask)
> > +		return 0;
> > +
> > +	stop = jiffies + timeout;
> > +
> > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > +again:
> > +		timeout = stop - jiffies;
> > +		if ((long)timeout <= 0)
> > +			return -ETIME;
> > +		rc = wait_event_interruptible_timeout(*queue,
> > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > +					       &canceled),
> > +			timeout);
> > +		if (rc > 0) {
> > +			if (canceled)
> > +				return -ECANCELED;
> > +			return 0;
> > +		}
> > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > +			clear_thread_flag(TIF_SIGPENDING);
> > +			goto again;
> > +		}
> > +	} else {
> > +		do {
> > +			tpm_msleep(TPM_TIMEOUT);
> > +			status = chip->ops->status(chip);
> > +			if ((status & mask) == mask)
> > +				return 0;
> > +		} while (time_before(jiffies, stop));
> > +	}
> > +	return -ETIME;
> > +}
> > +
> >  /* Before we attempt to access the TPM we must see that the valid bit is
> set.
> >   * The specification says that this bit is 0 at reset and remains 0 until the
> >   * 'TPM has gone through its self test and initialization and has established
> > diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-
> tpmfront.c
> > index 656e8af95d52..d20a0a9ded27 100644
> > --- a/drivers/char/tpm/xen-tpmfront.c
> > +++ b/drivers/char/tpm/xen-tpmfront.c
> > @@ -39,6 +39,66 @@ enum status_bits {
> >  	VTPM_STATUS_CANCELED = 0x8,
> >  };
> >
> > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > +					bool check_cancel, bool *canceled)
> > +{
> > +	u8 status = chip->ops->status(chip);
> > +
> > +	*canceled = false;
> > +	if ((status & mask) == mask)
> > +		return true;
> > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > +		*canceled = true;
> > +		return true;
> > +	}
> > +	return false;
> > +}
> > +
> > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > +		unsigned long timeout, wait_queue_head_t *queue,
> > +		bool check_cancel)
> > +{
> > +	unsigned long stop;
> > +	long rc;
> > +	u8 status;
> > +	bool canceled = false;
> > +
> > +	/* check current status */
> > +	status = chip->ops->status(chip);
> > +	if ((status & mask) == mask)
> > +		return 0;
> > +
> > +	stop = jiffies + timeout;
> > +
> > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > +again:
> > +		timeout = stop - jiffies;
> > +		if ((long)timeout <= 0)
> > +			return -ETIME;
> > +		rc = wait_event_interruptible_timeout(*queue,
> > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > +					       &canceled),
> > +			timeout);
> > +		if (rc > 0) {
> > +			if (canceled)
> > +				return -ECANCELED;
> > +			return 0;
> > +		}
> > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > +			clear_thread_flag(TIF_SIGPENDING);
> > +			goto again;
> > +		}
> > +	} else {
> > +		do {
> > +			tpm_msleep(TPM_TIMEOUT);
> > +			status = chip->ops->status(chip);
> > +			if ((status & mask) == mask)
> > +				return 0;
> > +		} while (time_before(jiffies, stop));
> > +	}
> > +	return -ETIME;
> > +}
> > +
> >  static u8 vtpm_status(struct tpm_chip *chip)
> >  {
> >  	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
> > --
> > 2.13.3
> >
> 
> This commit caused a compiler warning because freezer.h was not included
> to xen-tpmfront.c. I manually fixed it.

Yep, and checkpatch.pl still complains about some stuff (mostly whitespace) in both patch 1/4 and 2/4. When fixed patches are available, I can run them again through my automation.

> Reviewed-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>
> Tested-by: Jarkko Sakkinen <jarkkko.sakkinen@linux.intel.com>
> 
> /Jarkko

Alexander
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
  2017-10-19 17:00       ` Alexander.Steffen at infineon.com
@ 2017-10-20  8:56         ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-20  8:56 UTC (permalink / raw)
  To: Alexander.Steffen
  Cc: nayna, linux-integrity, zohar, linux-security-module,
	linux-kernel, peterhuewe, tpmdd, jgunthorpe, patrickc

On Thu, Oct 19, 2017 at 05:00:29PM +0000, Alexander.Steffen@infineon.com wrote:
> > On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
> > > The function wait_for_tpm_stat() is currently defined in
> > > tpm-interface file. It is a hardware specific function used
> > > only by tpm_tis and xen-tpmfront, so it is removed from
> > > tpm-interface.c and defined in respective driver files.
> > >
> > > Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > ---
> > >  drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
> > >  drivers/char/tpm/tpm.h           |  2 --
> > >  drivers/char/tpm/tpm_tis_core.c  | 60
> > ++++++++++++++++++++++++++++++++++++++++
> > >  drivers/char/tpm/xen-tpmfront.c  | 60
> > ++++++++++++++++++++++++++++++++++++++++
> > >  4 files changed, 120 insertions(+), 62 deletions(-)
> > >
> > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
> > interface.c
> > > index 1d6729be4cd6..313f7618d569 100644
> > > --- a/drivers/char/tpm/tpm-interface.c
> > > +++ b/drivers/char/tpm/tpm-interface.c
> > > @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t
> > buflen)
> > >  }
> > >  EXPORT_SYMBOL_GPL(tpm_send);
> > >
> > > -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > -					bool check_cancel, bool *canceled)
> > > -{
> > > -	u8 status = chip->ops->status(chip);
> > > -
> > > -	*canceled = false;
> > > -	if ((status & mask) == mask)
> > > -		return true;
> > > -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > -		*canceled = true;
> > > -		return true;
> > > -	}
> > > -	return false;
> > > -}
> > > -
> > > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> > timeout,
> > > -		      wait_queue_head_t *queue, bool check_cancel)
> > > -{
> > > -	unsigned long stop;
> > > -	long rc;
> > > -	u8 status;
> > > -	bool canceled = false;
> > > -
> > > -	/* check current status */
> > > -	status = chip->ops->status(chip);
> > > -	if ((status & mask) == mask)
> > > -		return 0;
> > > -
> > > -	stop = jiffies + timeout;
> > > -
> > > -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > -again:
> > > -		timeout = stop - jiffies;
> > > -		if ((long)timeout <= 0)
> > > -			return -ETIME;
> > > -		rc = wait_event_interruptible_timeout(*queue,
> > > -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > -					       &canceled),
> > > -			timeout);
> > > -		if (rc > 0) {
> > > -			if (canceled)
> > > -				return -ECANCELED;
> > > -			return 0;
> > > -		}
> > > -		if (rc == -ERESTARTSYS && freezing(current)) {
> > > -			clear_thread_flag(TIF_SIGPENDING);
> > > -			goto again;
> > > -		}
> > > -	} else {
> > > -		do {
> > > -			tpm_msleep(TPM_TIMEOUT);
> > > -			status = chip->ops->status(chip);
> > > -			if ((status & mask) == mask)
> > > -				return 0;
> > > -		} while (time_before(jiffies, stop));
> > > -	}
> > > -	return -ETIME;
> > > -}
> > > -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
> > > -
> > >  #define TPM_ORD_SAVESTATE 152
> > >  #define SAVESTATE_RESULT_SIZE 10
> > >
> > > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> > > index 2d5466a72e40..4fc83ac7abeb 100644
> > > --- a/drivers/char/tpm/tpm.h
> > > +++ b/drivers/char/tpm/tpm.h
> > > @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
> > >  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32
> > ordinal);
> > >  int tpm_pm_suspend(struct device *dev);
> > >  int tpm_pm_resume(struct device *dev);
> > > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> > timeout,
> > > -		      wait_queue_head_t *queue, bool check_cancel);
> > >
> > >  static inline void tpm_msleep(unsigned int delay_msec)
> > >  {
> > > diff --git a/drivers/char/tpm/tpm_tis_core.c
> > b/drivers/char/tpm/tpm_tis_core.c
> > > index 63bc6c3b949e..b33126a35694 100644
> > > --- a/drivers/char/tpm/tpm_tis_core.c
> > > +++ b/drivers/char/tpm/tpm_tis_core.c
> > > @@ -31,6 +31,66 @@
> > >  #include "tpm.h"
> > >  #include "tpm_tis_core.h"
> > >
> > > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > +					bool check_cancel, bool *canceled)
> > > +{
> > > +	u8 status = chip->ops->status(chip);
> > > +
> > > +	*canceled = false;
> > > +	if ((status & mask) == mask)
> > > +		return true;
> > > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > +		*canceled = true;
> > > +		return true;
> > > +	}
> > > +	return false;
> > > +}
> > > +
> > > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > > +		unsigned long timeout, wait_queue_head_t *queue,
> > > +		bool check_cancel)
> > > +{
> > > +	unsigned long stop;
> > > +	long rc;
> > > +	u8 status;
> > > +	bool canceled = false;
> > > +
> > > +	/* check current status */
> > > +	status = chip->ops->status(chip);
> > > +	if ((status & mask) == mask)
> > > +		return 0;
> > > +
> > > +	stop = jiffies + timeout;
> > > +
> > > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > +again:
> > > +		timeout = stop - jiffies;
> > > +		if ((long)timeout <= 0)
> > > +			return -ETIME;
> > > +		rc = wait_event_interruptible_timeout(*queue,
> > > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > +					       &canceled),
> > > +			timeout);
> > > +		if (rc > 0) {
> > > +			if (canceled)
> > > +				return -ECANCELED;
> > > +			return 0;
> > > +		}
> > > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > > +			clear_thread_flag(TIF_SIGPENDING);
> > > +			goto again;
> > > +		}
> > > +	} else {
> > > +		do {
> > > +			tpm_msleep(TPM_TIMEOUT);
> > > +			status = chip->ops->status(chip);
> > > +			if ((status & mask) == mask)
> > > +				return 0;
> > > +		} while (time_before(jiffies, stop));
> > > +	}
> > > +	return -ETIME;
> > > +}
> > > +
> > >  /* Before we attempt to access the TPM we must see that the valid bit is
> > set.
> > >   * The specification says that this bit is 0 at reset and remains 0 until the
> > >   * 'TPM has gone through its self test and initialization and has established
> > > diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-
> > tpmfront.c
> > > index 656e8af95d52..d20a0a9ded27 100644
> > > --- a/drivers/char/tpm/xen-tpmfront.c
> > > +++ b/drivers/char/tpm/xen-tpmfront.c
> > > @@ -39,6 +39,66 @@ enum status_bits {
> > >  	VTPM_STATUS_CANCELED = 0x8,
> > >  };
> > >
> > > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > +					bool check_cancel, bool *canceled)
> > > +{
> > > +	u8 status = chip->ops->status(chip);
> > > +
> > > +	*canceled = false;
> > > +	if ((status & mask) == mask)
> > > +		return true;
> > > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > +		*canceled = true;
> > > +		return true;
> > > +	}
> > > +	return false;
> > > +}
> > > +
> > > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > > +		unsigned long timeout, wait_queue_head_t *queue,
> > > +		bool check_cancel)
> > > +{
> > > +	unsigned long stop;
> > > +	long rc;
> > > +	u8 status;
> > > +	bool canceled = false;
> > > +
> > > +	/* check current status */
> > > +	status = chip->ops->status(chip);
> > > +	if ((status & mask) == mask)
> > > +		return 0;
> > > +
> > > +	stop = jiffies + timeout;
> > > +
> > > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > +again:
> > > +		timeout = stop - jiffies;
> > > +		if ((long)timeout <= 0)
> > > +			return -ETIME;
> > > +		rc = wait_event_interruptible_timeout(*queue,
> > > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > +					       &canceled),
> > > +			timeout);
> > > +		if (rc > 0) {
> > > +			if (canceled)
> > > +				return -ECANCELED;
> > > +			return 0;
> > > +		}
> > > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > > +			clear_thread_flag(TIF_SIGPENDING);
> > > +			goto again;
> > > +		}
> > > +	} else {
> > > +		do {
> > > +			tpm_msleep(TPM_TIMEOUT);
> > > +			status = chip->ops->status(chip);
> > > +			if ((status & mask) == mask)
> > > +				return 0;
> > > +		} while (time_before(jiffies, stop));
> > > +	}
> > > +	return -ETIME;
> > > +}
> > > +
> > >  static u8 vtpm_status(struct tpm_chip *chip)
> > >  {
> > >  	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
> > > --
> > > 2.13.3
> > >
> > 
> > This commit caused a compiler warning because freezer.h was not included
> > to xen-tpmfront.c. I manually fixed it.
> 
> Yep, and checkpatch.pl still complains about some stuff (mostly
> whitespace) in both patch 1/4 and 2/4. When fixed patches are
> available, I can run them again through my automation.
> Alexander

I'll fix these manually (weird, I run sparse and checkpatch, must have
done some mistake).

Thank you!

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
@ 2017-10-20  8:56         ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-20  8:56 UTC (permalink / raw)
  To: linux-security-module

On Thu, Oct 19, 2017 at 05:00:29PM +0000, Alexander.Steffen at infineon.com wrote:
> > On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
> > > The function wait_for_tpm_stat() is currently defined in
> > > tpm-interface file. It is a hardware specific function used
> > > only by tpm_tis and xen-tpmfront, so it is removed from
> > > tpm-interface.c and defined in respective driver files.
> > >
> > > Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > ---
> > >  drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
> > >  drivers/char/tpm/tpm.h           |  2 --
> > >  drivers/char/tpm/tpm_tis_core.c  | 60
> > ++++++++++++++++++++++++++++++++++++++++
> > >  drivers/char/tpm/xen-tpmfront.c  | 60
> > ++++++++++++++++++++++++++++++++++++++++
> > >  4 files changed, 120 insertions(+), 62 deletions(-)
> > >
> > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
> > interface.c
> > > index 1d6729be4cd6..313f7618d569 100644
> > > --- a/drivers/char/tpm/tpm-interface.c
> > > +++ b/drivers/char/tpm/tpm-interface.c
> > > @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t
> > buflen)
> > >  }
> > >  EXPORT_SYMBOL_GPL(tpm_send);
> > >
> > > -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > -					bool check_cancel, bool *canceled)
> > > -{
> > > -	u8 status = chip->ops->status(chip);
> > > -
> > > -	*canceled = false;
> > > -	if ((status & mask) == mask)
> > > -		return true;
> > > -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > -		*canceled = true;
> > > -		return true;
> > > -	}
> > > -	return false;
> > > -}
> > > -
> > > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> > timeout,
> > > -		      wait_queue_head_t *queue, bool check_cancel)
> > > -{
> > > -	unsigned long stop;
> > > -	long rc;
> > > -	u8 status;
> > > -	bool canceled = false;
> > > -
> > > -	/* check current status */
> > > -	status = chip->ops->status(chip);
> > > -	if ((status & mask) == mask)
> > > -		return 0;
> > > -
> > > -	stop = jiffies + timeout;
> > > -
> > > -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > -again:
> > > -		timeout = stop - jiffies;
> > > -		if ((long)timeout <= 0)
> > > -			return -ETIME;
> > > -		rc = wait_event_interruptible_timeout(*queue,
> > > -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > -					       &canceled),
> > > -			timeout);
> > > -		if (rc > 0) {
> > > -			if (canceled)
> > > -				return -ECANCELED;
> > > -			return 0;
> > > -		}
> > > -		if (rc == -ERESTARTSYS && freezing(current)) {
> > > -			clear_thread_flag(TIF_SIGPENDING);
> > > -			goto again;
> > > -		}
> > > -	} else {
> > > -		do {
> > > -			tpm_msleep(TPM_TIMEOUT);
> > > -			status = chip->ops->status(chip);
> > > -			if ((status & mask) == mask)
> > > -				return 0;
> > > -		} while (time_before(jiffies, stop));
> > > -	}
> > > -	return -ETIME;
> > > -}
> > > -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
> > > -
> > >  #define TPM_ORD_SAVESTATE 152
> > >  #define SAVESTATE_RESULT_SIZE 10
> > >
> > > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> > > index 2d5466a72e40..4fc83ac7abeb 100644
> > > --- a/drivers/char/tpm/tpm.h
> > > +++ b/drivers/char/tpm/tpm.h
> > > @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
> > >  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32
> > ordinal);
> > >  int tpm_pm_suspend(struct device *dev);
> > >  int tpm_pm_resume(struct device *dev);
> > > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> > timeout,
> > > -		      wait_queue_head_t *queue, bool check_cancel);
> > >
> > >  static inline void tpm_msleep(unsigned int delay_msec)
> > >  {
> > > diff --git a/drivers/char/tpm/tpm_tis_core.c
> > b/drivers/char/tpm/tpm_tis_core.c
> > > index 63bc6c3b949e..b33126a35694 100644
> > > --- a/drivers/char/tpm/tpm_tis_core.c
> > > +++ b/drivers/char/tpm/tpm_tis_core.c
> > > @@ -31,6 +31,66 @@
> > >  #include "tpm.h"
> > >  #include "tpm_tis_core.h"
> > >
> > > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > +					bool check_cancel, bool *canceled)
> > > +{
> > > +	u8 status = chip->ops->status(chip);
> > > +
> > > +	*canceled = false;
> > > +	if ((status & mask) == mask)
> > > +		return true;
> > > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > +		*canceled = true;
> > > +		return true;
> > > +	}
> > > +	return false;
> > > +}
> > > +
> > > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > > +		unsigned long timeout, wait_queue_head_t *queue,
> > > +		bool check_cancel)
> > > +{
> > > +	unsigned long stop;
> > > +	long rc;
> > > +	u8 status;
> > > +	bool canceled = false;
> > > +
> > > +	/* check current status */
> > > +	status = chip->ops->status(chip);
> > > +	if ((status & mask) == mask)
> > > +		return 0;
> > > +
> > > +	stop = jiffies + timeout;
> > > +
> > > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > +again:
> > > +		timeout = stop - jiffies;
> > > +		if ((long)timeout <= 0)
> > > +			return -ETIME;
> > > +		rc = wait_event_interruptible_timeout(*queue,
> > > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > +					       &canceled),
> > > +			timeout);
> > > +		if (rc > 0) {
> > > +			if (canceled)
> > > +				return -ECANCELED;
> > > +			return 0;
> > > +		}
> > > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > > +			clear_thread_flag(TIF_SIGPENDING);
> > > +			goto again;
> > > +		}
> > > +	} else {
> > > +		do {
> > > +			tpm_msleep(TPM_TIMEOUT);
> > > +			status = chip->ops->status(chip);
> > > +			if ((status & mask) == mask)
> > > +				return 0;
> > > +		} while (time_before(jiffies, stop));
> > > +	}
> > > +	return -ETIME;
> > > +}
> > > +
> > >  /* Before we attempt to access the TPM we must see that the valid bit is
> > set.
> > >   * The specification says that this bit is 0 at reset and remains 0 until the
> > >   * 'TPM has gone through its self test and initialization and has established
> > > diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-
> > tpmfront.c
> > > index 656e8af95d52..d20a0a9ded27 100644
> > > --- a/drivers/char/tpm/xen-tpmfront.c
> > > +++ b/drivers/char/tpm/xen-tpmfront.c
> > > @@ -39,6 +39,66 @@ enum status_bits {
> > >  	VTPM_STATUS_CANCELED = 0x8,
> > >  };
> > >
> > > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > +					bool check_cancel, bool *canceled)
> > > +{
> > > +	u8 status = chip->ops->status(chip);
> > > +
> > > +	*canceled = false;
> > > +	if ((status & mask) == mask)
> > > +		return true;
> > > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > +		*canceled = true;
> > > +		return true;
> > > +	}
> > > +	return false;
> > > +}
> > > +
> > > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > > +		unsigned long timeout, wait_queue_head_t *queue,
> > > +		bool check_cancel)
> > > +{
> > > +	unsigned long stop;
> > > +	long rc;
> > > +	u8 status;
> > > +	bool canceled = false;
> > > +
> > > +	/* check current status */
> > > +	status = chip->ops->status(chip);
> > > +	if ((status & mask) == mask)
> > > +		return 0;
> > > +
> > > +	stop = jiffies + timeout;
> > > +
> > > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > +again:
> > > +		timeout = stop - jiffies;
> > > +		if ((long)timeout <= 0)
> > > +			return -ETIME;
> > > +		rc = wait_event_interruptible_timeout(*queue,
> > > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > +					       &canceled),
> > > +			timeout);
> > > +		if (rc > 0) {
> > > +			if (canceled)
> > > +				return -ECANCELED;
> > > +			return 0;
> > > +		}
> > > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > > +			clear_thread_flag(TIF_SIGPENDING);
> > > +			goto again;
> > > +		}
> > > +	} else {
> > > +		do {
> > > +			tpm_msleep(TPM_TIMEOUT);
> > > +			status = chip->ops->status(chip);
> > > +			if ((status & mask) == mask)
> > > +				return 0;
> > > +		} while (time_before(jiffies, stop));
> > > +	}
> > > +	return -ETIME;
> > > +}
> > > +
> > >  static u8 vtpm_status(struct tpm_chip *chip)
> > >  {
> > >  	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
> > > --
> > > 2.13.3
> > >
> > 
> > This commit caused a compiler warning because freezer.h was not included
> > to xen-tpmfront.c. I manually fixed it.
> 
> Yep, and checkpatch.pl still complains about some stuff (mostly
> whitespace) in both patch 1/4 and 2/4. When fixed patches are
> available, I can run them again through my automation.
> Alexander

I'll fix these manually (weird, I run sparse and checkpatch, must have
done some mistake).

Thank you!

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* RE: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-10-17 20:32   ` Nayna Jain
@ 2017-10-20 14:42     ` Alexander.Steffen at infineon.com
  -1 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen @ 2017-10-20 14:42 UTC (permalink / raw)
  To: nayna, linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, jgunthorpe, patrickc

> The TPM burstcount status indicates the number of bytes that can
> be sent to the TPM without causing bus wait states.  Effectively,
> it is the number of empty bytes in the command FIFO.
> 
> This patch optimizes the tpm_tis_send_data() function by checking
> the burstcount only once. And if the burstcount is valid, it writes
> all the bytes at once, permitting wait state.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~41sec to ~14sec.
> 
> Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
> conjunction with the TPM Device Driver work group.
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> ---
>  drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++----------------------
> ----
>  1 file changed, 15 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c
> b/drivers/char/tpm/tpm_tis_core.c
> index b33126a35694..993328ae988c 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
> u8 *buf, size_t len)
>  {
>  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>  	int rc, status, burstcnt;
> -	size_t count = 0;
>  	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> 
>  	status = tpm_tis_status(chip);
> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
> u8 *buf, size_t len)
>  		}
>  	}
> 
> -	while (count < len - 1) {
> -		burstcnt = get_burstcount(chip);
> -		if (burstcnt < 0) {
> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> -			rc = burstcnt;
> -			goto out_err;
> -		}
> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> >locality),
> -					 burstcnt, buf + count);
> -		if (rc < 0)
> -			goto out_err;
> -
> -		count += burstcnt;
> -
> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> >timeout_c,
> -					&priv->int_queue, false) < 0) {
> -			rc = -ETIME;
> -			goto out_err;
> -		}
> -		status = tpm_tis_status(chip);
> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> -			rc = -EIO;
> -			goto out_err;
> -		}
> +	/*
> +	 * Get the initial burstcount to ensure TPM is ready to
> +	 * accept data.
> +	 */
> +	burstcnt = get_burstcount(chip);
> +	if (burstcnt < 0) {
> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> +		rc = burstcnt;
> +		goto out_err;
>  	}
> 
> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> +			len - 1, buf);
> +	if (rc < 0)
> +		goto out_err;
> +
>  	/* write last byte */
> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> buf[count]);
> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
> 1]);
>  	if (rc < 0)
>  		goto out_err;
> 
> --
> 2.13.3

This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to send large amounts of data, e.g. with TPM2_Hash, and subsequent tests seem to take an unusual amount of time. More analysis probably has to wait until November, since I am going to be in Prague next week.

Alexander

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-10-20 14:42     ` Alexander.Steffen at infineon.com
  0 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen at infineon.com @ 2017-10-20 14:42 UTC (permalink / raw)
  To: linux-security-module

> The TPM burstcount status indicates the number of bytes that can
> be sent to the TPM without causing bus wait states.  Effectively,
> it is the number of empty bytes in the command FIFO.
> 
> This patch optimizes the tpm_tis_send_data() function by checking
> the burstcount only once. And if the burstcount is valid, it writes
> all the bytes at once, permitting wait state.
> 
> After this change, performance on a TPM 1.2 with an 8 byte
> burstcount for 1000 extends improved from ~41sec to ~14sec.
> 
> Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
> conjunction with the TPM Device Driver work group.
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> ---
>  drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++----------------------
> ----
>  1 file changed, 15 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c
> b/drivers/char/tpm/tpm_tis_core.c
> index b33126a35694..993328ae988c 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
> u8 *buf, size_t len)
>  {
>  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>  	int rc, status, burstcnt;
> -	size_t count = 0;
>  	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> 
>  	status = tpm_tis_status(chip);
> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
> u8 *buf, size_t len)
>  		}
>  	}
> 
> -	while (count < len - 1) {
> -		burstcnt = get_burstcount(chip);
> -		if (burstcnt < 0) {
> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> -			rc = burstcnt;
> -			goto out_err;
> -		}
> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> >locality),
> -					 burstcnt, buf + count);
> -		if (rc < 0)
> -			goto out_err;
> -
> -		count += burstcnt;
> -
> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> >timeout_c,
> -					&priv->int_queue, false) < 0) {
> -			rc = -ETIME;
> -			goto out_err;
> -		}
> -		status = tpm_tis_status(chip);
> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> -			rc = -EIO;
> -			goto out_err;
> -		}
> +	/*
> +	 * Get the initial burstcount to ensure TPM is ready to
> +	 * accept data.
> +	 */
> +	burstcnt = get_burstcount(chip);
> +	if (burstcnt < 0) {
> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> +		rc = burstcnt;
> +		goto out_err;
>  	}
> 
> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> +			len - 1, buf);
> +	if (rc < 0)
> +		goto out_err;
> +
>  	/* write last byte */
> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> buf[count]);
> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
> 1]);
>  	if (rc < 0)
>  		goto out_err;
> 
> --
> 2.13.3

This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to send large amounts of data, e.g. with TPM2_Hash, and subsequent tests seem to take an unusual amount of time. More analysis probably has to wait until November, since I am going to be in Prague next week.

Alexander
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-10-20 14:42     ` Alexander.Steffen at infineon.com
@ 2017-10-20 18:02       ` Ken Goldman
  -1 siblings, 0 replies; 63+ messages in thread
From: Ken Goldman @ 2017-10-20 18:02 UTC (permalink / raw)
  To: linux-security-module

On 10/20/2017 10:42 AM, Alexander.Steffen at infineon.com wrote:
> 
> This seems to fail reliably with my SPI TPM 2.0. I get EIO when
> trying to send large amounts of data, e.g. with TPM2_Hash, and
> subsequent tests seem to take an unusual amount of time. More
> analysis probably has to wait until November, since I am going to be
> in Prague next week.

I have a guess as to the cause of the failure.  Would it be possible for 
you to test it?

1 - My guess is that EIO is coming from here:

static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
...
	/* write last byte */
	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
	if (rc < 0)
		goto out_err;

	if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
				&priv->int_queue, false) < 0) {
		rc = -ETIME;
		goto out_err;
	}
	status = tpm_tis_status(chip);
	if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) {
		rc = -EIO;
		goto out_err;
	}
...

Can you verify that this is the cause.

2 - If that's the cause, I believe that there is a latent bug.  Expect 
is not guaranteed to become false immediately.  It only occurs after the 
TPM firmware has emptied the FIFO.  Thus, the tpm_tis_status() really 
should be something like "wait_for_tpm_expect_false()", with a sleep loop.

This missing wait has been in the code for a while.  If may just surface 
now because the patch causes data to be written faster, and thus it 
takes longer for the TPM to empty the FIFO and clear Expect.

It also makes sense that it would occur more often on long commands.

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info@ http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-10-20 18:02       ` Ken Goldman
  0 siblings, 0 replies; 63+ messages in thread
From: Ken Goldman @ 2017-10-20 18:02 UTC (permalink / raw)
  To: Alexander.Steffen, linux-integrity; +Cc: linux-security-module

On 10/20/2017 10:42 AM, Alexander.Steffen@infineon.com wrote:
> 
> This seems to fail reliably with my SPI TPM 2.0. I get EIO when
> trying to send large amounts of data, e.g. with TPM2_Hash, and
> subsequent tests seem to take an unusual amount of time. More
> analysis probably has to wait until November, since I am going to be
> in Prague next week.

I have a guess as to the cause of the failure.  Would it be possible for 
you to test it?

1 - My guess is that EIO is coming from here:

static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
...
	/* write last byte */
	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
	if (rc < 0)
		goto out_err;

	if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
				&priv->int_queue, false) < 0) {
		rc = -ETIME;
		goto out_err;
	}
	status = tpm_tis_status(chip);
	if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) {
		rc = -EIO;
		goto out_err;
	}
...

Can you verify that this is the cause.

2 - If that's the cause, I believe that there is a latent bug.  Expect 
is not guaranteed to become false immediately.  It only occurs after the 
TPM firmware has emptied the FIFO.  Thus, the tpm_tis_status() really 
should be something like "wait_for_tpm_expect_false()", with a sleep loop.

This missing wait has been in the code for a while.  If may just surface 
now because the patch causes data to be written faster, and thus it 
takes longer for the TPM to empty the FIFO and clear Expect.

It also makes sense that it would occur more often on long commands.

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-10-20 14:42     ` Alexander.Steffen at infineon.com
@ 2017-10-23  2:57       ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-23  2:57 UTC (permalink / raw)
  To: Alexander.Steffen
  Cc: nayna, linux-integrity, zohar, linux-security-module,
	linux-kernel, peterhuewe, tpmdd, jgunthorpe, patrickc

On Fri, Oct 20, 2017 at 02:42:54PM +0000, Alexander.Steffen@infineon.com wrote:
> > The TPM burstcount status indicates the number of bytes that can
> > be sent to the TPM without causing bus wait states.  Effectively,
> > it is the number of empty bytes in the command FIFO.
> > 
> > This patch optimizes the tpm_tis_send_data() function by checking
> > the burstcount only once. And if the burstcount is valid, it writes
> > all the bytes at once, permitting wait state.
> > 
> > After this change, performance on a TPM 1.2 with an 8 byte
> > burstcount for 1000 extends improved from ~41sec to ~14sec.
> > 
> > Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
> > conjunction with the TPM Device Driver work group.
> > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> > Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> > ---
> >  drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++----------------------
> > ----
> >  1 file changed, 15 insertions(+), 27 deletions(-)
> > 
> > diff --git a/drivers/char/tpm/tpm_tis_core.c
> > b/drivers/char/tpm/tpm_tis_core.c
> > index b33126a35694..993328ae988c 100644
> > --- a/drivers/char/tpm/tpm_tis_core.c
> > +++ b/drivers/char/tpm/tpm_tis_core.c
> > @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
> > u8 *buf, size_t len)
> >  {
> >  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
> >  	int rc, status, burstcnt;
> > -	size_t count = 0;
> >  	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> > 
> >  	status = tpm_tis_status(chip);
> > @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
> > u8 *buf, size_t len)
> >  		}
> >  	}
> > 
> > -	while (count < len - 1) {
> > -		burstcnt = get_burstcount(chip);
> > -		if (burstcnt < 0) {
> > -			dev_err(&chip->dev, "Unable to read burstcount\n");
> > -			rc = burstcnt;
> > -			goto out_err;
> > -		}
> > -		burstcnt = min_t(int, burstcnt, len - count - 1);
> > -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> > >locality),
> > -					 burstcnt, buf + count);
> > -		if (rc < 0)
> > -			goto out_err;
> > -
> > -		count += burstcnt;
> > -
> > -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> > >timeout_c,
> > -					&priv->int_queue, false) < 0) {
> > -			rc = -ETIME;
> > -			goto out_err;
> > -		}
> > -		status = tpm_tis_status(chip);
> > -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> > -			rc = -EIO;
> > -			goto out_err;
> > -		}
> > +	/*
> > +	 * Get the initial burstcount to ensure TPM is ready to
> > +	 * accept data.
> > +	 */
> > +	burstcnt = get_burstcount(chip);
> > +	if (burstcnt < 0) {
> > +		dev_err(&chip->dev, "Unable to read burstcount\n");
> > +		rc = burstcnt;
> > +		goto out_err;
> >  	}
> > 
> > +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> > +			len - 1, buf);
> > +	if (rc < 0)
> > +		goto out_err;
> > +
> >  	/* write last byte */
> > -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> > buf[count]);
> > +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
> > 1]);
> >  	if (rc < 0)
> >  		goto out_err;
> > 
> > --
> > 2.13.3
> 
> This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying
> to send large amounts of data, e.g. with TPM2_Hash, and subsequent
> tests seem to take an unusual amount of time. More analysis probably
> has to wait until November, since I am going to be in Prague next
> week.
> 
> Alexander

For the time being I'll drop this patch from the next branch and keep it
in the master branch.

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-10-23  2:57       ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-23  2:57 UTC (permalink / raw)
  To: linux-security-module

On Fri, Oct 20, 2017 at 02:42:54PM +0000, Alexander.Steffen at infineon.com wrote:
> > The TPM burstcount status indicates the number of bytes that can
> > be sent to the TPM without causing bus wait states.  Effectively,
> > it is the number of empty bytes in the command FIFO.
> > 
> > This patch optimizes the tpm_tis_send_data() function by checking
> > the burstcount only once. And if the burstcount is valid, it writes
> > all the bytes at once, permitting wait state.
> > 
> > After this change, performance on a TPM 1.2 with an 8 byte
> > burstcount for 1000 extends improved from ~41sec to ~14sec.
> > 
> > Suggested-by: Ken Goldman <kgold@linux.vnet.ibm.com> in
> > conjunction with the TPM Device Driver work group.
> > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> > Acked-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> > ---
> >  drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++----------------------
> > ----
> >  1 file changed, 15 insertions(+), 27 deletions(-)
> > 
> > diff --git a/drivers/char/tpm/tpm_tis_core.c
> > b/drivers/char/tpm/tpm_tis_core.c
> > index b33126a35694..993328ae988c 100644
> > --- a/drivers/char/tpm/tpm_tis_core.c
> > +++ b/drivers/char/tpm/tpm_tis_core.c
> > @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
> > u8 *buf, size_t len)
> >  {
> >  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
> >  	int rc, status, burstcnt;
> > -	size_t count = 0;
> >  	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> > 
> >  	status = tpm_tis_status(chip);
> > @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
> > u8 *buf, size_t len)
> >  		}
> >  	}
> > 
> > -	while (count < len - 1) {
> > -		burstcnt = get_burstcount(chip);
> > -		if (burstcnt < 0) {
> > -			dev_err(&chip->dev, "Unable to read burstcount\n");
> > -			rc = burstcnt;
> > -			goto out_err;
> > -		}
> > -		burstcnt = min_t(int, burstcnt, len - count - 1);
> > -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> > >locality),
> > -					 burstcnt, buf + count);
> > -		if (rc < 0)
> > -			goto out_err;
> > -
> > -		count += burstcnt;
> > -
> > -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> > >timeout_c,
> > -					&priv->int_queue, false) < 0) {
> > -			rc = -ETIME;
> > -			goto out_err;
> > -		}
> > -		status = tpm_tis_status(chip);
> > -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> > -			rc = -EIO;
> > -			goto out_err;
> > -		}
> > +	/*
> > +	 * Get the initial burstcount to ensure TPM is ready to
> > +	 * accept data.
> > +	 */
> > +	burstcnt = get_burstcount(chip);
> > +	if (burstcnt < 0) {
> > +		dev_err(&chip->dev, "Unable to read burstcount\n");
> > +		rc = burstcnt;
> > +		goto out_err;
> >  	}
> > 
> > +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> > +			len - 1, buf);
> > +	if (rc < 0)
> > +		goto out_err;
> > +
> >  	/* write last byte */
> > -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> > buf[count]);
> > +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
> > 1]);
> >  	if (rc < 0)
> >  		goto out_err;
> > 
> > --
> > 2.13.3
> 
> This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying
> to send large amounts of data, e.g. with TPM2_Hash, and subsequent
> tests seem to take an unusual amount of time. More analysis probably
> has to wait until November, since I am going to be in Prague next
> week.
> 
> Alexander

For the time being I'll drop this patch from the next branch and keep it
in the master branch.

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
  2017-10-20  8:56         ` Jarkko Sakkinen
  (?)
@ 2017-10-23 13:32           ` Nayna Jain
  -1 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-23 13:32 UTC (permalink / raw)
  To: Jarkko Sakkinen, Alexander.Steffen
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, tpmdd, jgunthorpe, patrickc



On 10/20/2017 02:26 PM, Jarkko Sakkinen wrote:
> On Thu, Oct 19, 2017 at 05:00:29PM +0000, Alexander.Steffen@infineon.com wrote:
>>> On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
>>>> The function wait_for_tpm_stat() is currently defined in
>>>> tpm-interface file. It is a hardware specific function used
>>>> only by tpm_tis and xen-tpmfront, so it is removed from
>>>> tpm-interface.c and defined in respective driver files.
>>>>
>>>> Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>>>> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
>>>> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>>>> ---
>>>>   drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
>>>>   drivers/char/tpm/tpm.h           |  2 --
>>>>   drivers/char/tpm/tpm_tis_core.c  | 60
>>> ++++++++++++++++++++++++++++++++++++++++
>>>>   drivers/char/tpm/xen-tpmfront.c  | 60
>>> ++++++++++++++++++++++++++++++++++++++++
>>>>   4 files changed, 120 insertions(+), 62 deletions(-)
>>>>
>>>> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
>>> interface.c
>>>> index 1d6729be4cd6..313f7618d569 100644
>>>> --- a/drivers/char/tpm/tpm-interface.c
>>>> +++ b/drivers/char/tpm/tpm-interface.c
>>>> @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t
>>> buflen)
>>>>   }
>>>>   EXPORT_SYMBOL_GPL(tpm_send);
>>>>
>>>> -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>>>> -					bool check_cancel, bool *canceled)
>>>> -{
>>>> -	u8 status = chip->ops->status(chip);
>>>> -
>>>> -	*canceled = false;
>>>> -	if ((status & mask) == mask)
>>>> -		return true;
>>>> -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
>>>> -		*canceled = true;
>>>> -		return true;
>>>> -	}
>>>> -	return false;
>>>> -}
>>>> -
>>>> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
>>> timeout,
>>>> -		      wait_queue_head_t *queue, bool check_cancel)
>>>> -{
>>>> -	unsigned long stop;
>>>> -	long rc;
>>>> -	u8 status;
>>>> -	bool canceled = false;
>>>> -
>>>> -	/* check current status */
>>>> -	status = chip->ops->status(chip);
>>>> -	if ((status & mask) == mask)
>>>> -		return 0;
>>>> -
>>>> -	stop = jiffies + timeout;
>>>> -
>>>> -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
>>>> -again:
>>>> -		timeout = stop - jiffies;
>>>> -		if ((long)timeout <= 0)
>>>> -			return -ETIME;
>>>> -		rc = wait_event_interruptible_timeout(*queue,
>>>> -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
>>>> -					       &canceled),
>>>> -			timeout);
>>>> -		if (rc > 0) {
>>>> -			if (canceled)
>>>> -				return -ECANCELED;
>>>> -			return 0;
>>>> -		}
>>>> -		if (rc == -ERESTARTSYS && freezing(current)) {
>>>> -			clear_thread_flag(TIF_SIGPENDING);
>>>> -			goto again;
>>>> -		}
>>>> -	} else {
>>>> -		do {
>>>> -			tpm_msleep(TPM_TIMEOUT);
>>>> -			status = chip->ops->status(chip);
>>>> -			if ((status & mask) == mask)
>>>> -				return 0;
>>>> -		} while (time_before(jiffies, stop));
>>>> -	}
>>>> -	return -ETIME;
>>>> -}
>>>> -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
>>>> -
>>>>   #define TPM_ORD_SAVESTATE 152
>>>>   #define SAVESTATE_RESULT_SIZE 10
>>>>
>>>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>>>> index 2d5466a72e40..4fc83ac7abeb 100644
>>>> --- a/drivers/char/tpm/tpm.h
>>>> +++ b/drivers/char/tpm/tpm.h
>>>> @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
>>>>   unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32
>>> ordinal);
>>>>   int tpm_pm_suspend(struct device *dev);
>>>>   int tpm_pm_resume(struct device *dev);
>>>> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
>>> timeout,
>>>> -		      wait_queue_head_t *queue, bool check_cancel);
>>>>
>>>>   static inline void tpm_msleep(unsigned int delay_msec)
>>>>   {
>>>> diff --git a/drivers/char/tpm/tpm_tis_core.c
>>> b/drivers/char/tpm/tpm_tis_core.c
>>>> index 63bc6c3b949e..b33126a35694 100644
>>>> --- a/drivers/char/tpm/tpm_tis_core.c
>>>> +++ b/drivers/char/tpm/tpm_tis_core.c
>>>> @@ -31,6 +31,66 @@
>>>>   #include "tpm.h"
>>>>   #include "tpm_tis_core.h"
>>>>
>>>> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>>>> +					bool check_cancel, bool *canceled)
>>>> +{
>>>> +	u8 status = chip->ops->status(chip);
>>>> +
>>>> +	*canceled = false;
>>>> +	if ((status & mask) == mask)
>>>> +		return true;
>>>> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
>>>> +		*canceled = true;
>>>> +		return true;
>>>> +	}
>>>> +	return false;
>>>> +}
>>>> +
>>>> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
>>>> +		unsigned long timeout, wait_queue_head_t *queue,
>>>> +		bool check_cancel)
>>>> +{
>>>> +	unsigned long stop;
>>>> +	long rc;
>>>> +	u8 status;
>>>> +	bool canceled = false;
>>>> +
>>>> +	/* check current status */
>>>> +	status = chip->ops->status(chip);
>>>> +	if ((status & mask) == mask)
>>>> +		return 0;
>>>> +
>>>> +	stop = jiffies + timeout;
>>>> +
>>>> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
>>>> +again:
>>>> +		timeout = stop - jiffies;
>>>> +		if ((long)timeout <= 0)
>>>> +			return -ETIME;
>>>> +		rc = wait_event_interruptible_timeout(*queue,
>>>> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
>>>> +					       &canceled),
>>>> +			timeout);
>>>> +		if (rc > 0) {
>>>> +			if (canceled)
>>>> +				return -ECANCELED;
>>>> +			return 0;
>>>> +		}
>>>> +		if (rc == -ERESTARTSYS && freezing(current)) {
>>>> +			clear_thread_flag(TIF_SIGPENDING);
>>>> +			goto again;
>>>> +		}
>>>> +	} else {
>>>> +		do {
>>>> +			tpm_msleep(TPM_TIMEOUT);
>>>> +			status = chip->ops->status(chip);
>>>> +			if ((status & mask) == mask)
>>>> +				return 0;
>>>> +		} while (time_before(jiffies, stop));
>>>> +	}
>>>> +	return -ETIME;
>>>> +}
>>>> +
>>>>   /* Before we attempt to access the TPM we must see that the valid bit is
>>> set.
>>>>    * The specification says that this bit is 0 at reset and remains 0 until the
>>>>    * 'TPM has gone through its self test and initialization and has established
>>>> diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-
>>> tpmfront.c
>>>> index 656e8af95d52..d20a0a9ded27 100644
>>>> --- a/drivers/char/tpm/xen-tpmfront.c
>>>> +++ b/drivers/char/tpm/xen-tpmfront.c
>>>> @@ -39,6 +39,66 @@ enum status_bits {
>>>>   	VTPM_STATUS_CANCELED = 0x8,
>>>>   };
>>>>
>>>> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>>>> +					bool check_cancel, bool *canceled)
>>>> +{
>>>> +	u8 status = chip->ops->status(chip);
>>>> +
>>>> +	*canceled = false;
>>>> +	if ((status & mask) == mask)
>>>> +		return true;
>>>> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
>>>> +		*canceled = true;
>>>> +		return true;
>>>> +	}
>>>> +	return false;
>>>> +}
>>>> +
>>>> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
>>>> +		unsigned long timeout, wait_queue_head_t *queue,
>>>> +		bool check_cancel)
>>>> +{
>>>> +	unsigned long stop;
>>>> +	long rc;
>>>> +	u8 status;
>>>> +	bool canceled = false;
>>>> +
>>>> +	/* check current status */
>>>> +	status = chip->ops->status(chip);
>>>> +	if ((status & mask) == mask)
>>>> +		return 0;
>>>> +
>>>> +	stop = jiffies + timeout;
>>>> +
>>>> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
>>>> +again:
>>>> +		timeout = stop - jiffies;
>>>> +		if ((long)timeout <= 0)
>>>> +			return -ETIME;
>>>> +		rc = wait_event_interruptible_timeout(*queue,
>>>> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
>>>> +					       &canceled),
>>>> +			timeout);
>>>> +		if (rc > 0) {
>>>> +			if (canceled)
>>>> +				return -ECANCELED;
>>>> +			return 0;
>>>> +		}
>>>> +		if (rc == -ERESTARTSYS && freezing(current)) {
>>>> +			clear_thread_flag(TIF_SIGPENDING);
>>>> +			goto again;
>>>> +		}
>>>> +	} else {
>>>> +		do {
>>>> +			tpm_msleep(TPM_TIMEOUT);
>>>> +			status = chip->ops->status(chip);
>>>> +			if ((status & mask) == mask)
>>>> +				return 0;
>>>> +		} while (time_before(jiffies, stop));
>>>> +	}
>>>> +	return -ETIME;
>>>> +}
>>>> +
>>>>   static u8 vtpm_status(struct tpm_chip *chip)
>>>>   {
>>>>   	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
>>>> --
>>>> 2.13.3
>>>>
>>> This commit caused a compiler warning because freezer.h was not included
>>> to xen-tpmfront.c. I manually fixed it.
>> Yep, and checkpatch.pl still complains about some stuff (mostly
>> whitespace) in both patch 1/4 and 2/4. When fixed patches are
>> available, I can run them again through my automation.
>> Alexander

Sorry for delay in response.. I was on vacation for last few days.
Thanks for informing. I am wondering these didn't show up when I ran 
checkpatch.pl.

> I'll fix these manually (weird, I run sparse and checkpatch, must have
> done some mistake).
Thanks Jarkko.

Thanks & Regards,
     - Nayna

> Thank you!
>
> /Jarkko
>

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
@ 2017-10-23 13:32           ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-23 13:32 UTC (permalink / raw)
  To: linux-security-module



On 10/20/2017 02:26 PM, Jarkko Sakkinen wrote:
> On Thu, Oct 19, 2017 at 05:00:29PM +0000, Alexander.Steffen at infineon.com wrote:
>>> On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
>>>> The function wait_for_tpm_stat() is currently defined in
>>>> tpm-interface file. It is a hardware specific function used
>>>> only by tpm_tis and xen-tpmfront, so it is removed from
>>>> tpm-interface.c and defined in respective driver files.
>>>>
>>>> Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>>>> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
>>>> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>>>> ---
>>>>   drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
>>>>   drivers/char/tpm/tpm.h           |  2 --
>>>>   drivers/char/tpm/tpm_tis_core.c  | 60
>>> ++++++++++++++++++++++++++++++++++++++++
>>>>   drivers/char/tpm/xen-tpmfront.c  | 60
>>> ++++++++++++++++++++++++++++++++++++++++
>>>>   4 files changed, 120 insertions(+), 62 deletions(-)
>>>>
>>>> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
>>> interface.c
>>>> index 1d6729be4cd6..313f7618d569 100644
>>>> --- a/drivers/char/tpm/tpm-interface.c
>>>> +++ b/drivers/char/tpm/tpm-interface.c
>>>> @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t
>>> buflen)
>>>>   }
>>>>   EXPORT_SYMBOL_GPL(tpm_send);
>>>>
>>>> -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>>>> -					bool check_cancel, bool *canceled)
>>>> -{
>>>> -	u8 status = chip->ops->status(chip);
>>>> -
>>>> -	*canceled = false;
>>>> -	if ((status & mask) == mask)
>>>> -		return true;
>>>> -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
>>>> -		*canceled = true;
>>>> -		return true;
>>>> -	}
>>>> -	return false;
>>>> -}
>>>> -
>>>> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
>>> timeout,
>>>> -		      wait_queue_head_t *queue, bool check_cancel)
>>>> -{
>>>> -	unsigned long stop;
>>>> -	long rc;
>>>> -	u8 status;
>>>> -	bool canceled = false;
>>>> -
>>>> -	/* check current status */
>>>> -	status = chip->ops->status(chip);
>>>> -	if ((status & mask) == mask)
>>>> -		return 0;
>>>> -
>>>> -	stop = jiffies + timeout;
>>>> -
>>>> -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
>>>> -again:
>>>> -		timeout = stop - jiffies;
>>>> -		if ((long)timeout <= 0)
>>>> -			return -ETIME;
>>>> -		rc = wait_event_interruptible_timeout(*queue,
>>>> -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
>>>> -					       &canceled),
>>>> -			timeout);
>>>> -		if (rc > 0) {
>>>> -			if (canceled)
>>>> -				return -ECANCELED;
>>>> -			return 0;
>>>> -		}
>>>> -		if (rc == -ERESTARTSYS && freezing(current)) {
>>>> -			clear_thread_flag(TIF_SIGPENDING);
>>>> -			goto again;
>>>> -		}
>>>> -	} else {
>>>> -		do {
>>>> -			tpm_msleep(TPM_TIMEOUT);
>>>> -			status = chip->ops->status(chip);
>>>> -			if ((status & mask) == mask)
>>>> -				return 0;
>>>> -		} while (time_before(jiffies, stop));
>>>> -	}
>>>> -	return -ETIME;
>>>> -}
>>>> -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
>>>> -
>>>>   #define TPM_ORD_SAVESTATE 152
>>>>   #define SAVESTATE_RESULT_SIZE 10
>>>>
>>>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>>>> index 2d5466a72e40..4fc83ac7abeb 100644
>>>> --- a/drivers/char/tpm/tpm.h
>>>> +++ b/drivers/char/tpm/tpm.h
>>>> @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
>>>>   unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32
>>> ordinal);
>>>>   int tpm_pm_suspend(struct device *dev);
>>>>   int tpm_pm_resume(struct device *dev);
>>>> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
>>> timeout,
>>>> -		      wait_queue_head_t *queue, bool check_cancel);
>>>>
>>>>   static inline void tpm_msleep(unsigned int delay_msec)
>>>>   {
>>>> diff --git a/drivers/char/tpm/tpm_tis_core.c
>>> b/drivers/char/tpm/tpm_tis_core.c
>>>> index 63bc6c3b949e..b33126a35694 100644
>>>> --- a/drivers/char/tpm/tpm_tis_core.c
>>>> +++ b/drivers/char/tpm/tpm_tis_core.c
>>>> @@ -31,6 +31,66 @@
>>>>   #include "tpm.h"
>>>>   #include "tpm_tis_core.h"
>>>>
>>>> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>>>> +					bool check_cancel, bool *canceled)
>>>> +{
>>>> +	u8 status = chip->ops->status(chip);
>>>> +
>>>> +	*canceled = false;
>>>> +	if ((status & mask) == mask)
>>>> +		return true;
>>>> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
>>>> +		*canceled = true;
>>>> +		return true;
>>>> +	}
>>>> +	return false;
>>>> +}
>>>> +
>>>> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
>>>> +		unsigned long timeout, wait_queue_head_t *queue,
>>>> +		bool check_cancel)
>>>> +{
>>>> +	unsigned long stop;
>>>> +	long rc;
>>>> +	u8 status;
>>>> +	bool canceled = false;
>>>> +
>>>> +	/* check current status */
>>>> +	status = chip->ops->status(chip);
>>>> +	if ((status & mask) == mask)
>>>> +		return 0;
>>>> +
>>>> +	stop = jiffies + timeout;
>>>> +
>>>> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
>>>> +again:
>>>> +		timeout = stop - jiffies;
>>>> +		if ((long)timeout <= 0)
>>>> +			return -ETIME;
>>>> +		rc = wait_event_interruptible_timeout(*queue,
>>>> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
>>>> +					       &canceled),
>>>> +			timeout);
>>>> +		if (rc > 0) {
>>>> +			if (canceled)
>>>> +				return -ECANCELED;
>>>> +			return 0;
>>>> +		}
>>>> +		if (rc == -ERESTARTSYS && freezing(current)) {
>>>> +			clear_thread_flag(TIF_SIGPENDING);
>>>> +			goto again;
>>>> +		}
>>>> +	} else {
>>>> +		do {
>>>> +			tpm_msleep(TPM_TIMEOUT);
>>>> +			status = chip->ops->status(chip);
>>>> +			if ((status & mask) == mask)
>>>> +				return 0;
>>>> +		} while (time_before(jiffies, stop));
>>>> +	}
>>>> +	return -ETIME;
>>>> +}
>>>> +
>>>>   /* Before we attempt to access the TPM we must see that the valid bit is
>>> set.
>>>>    * The specification says that this bit is 0 at reset and remains 0 until the
>>>>    * 'TPM has gone through its self test and initialization and has established
>>>> diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-
>>> tpmfront.c
>>>> index 656e8af95d52..d20a0a9ded27 100644
>>>> --- a/drivers/char/tpm/xen-tpmfront.c
>>>> +++ b/drivers/char/tpm/xen-tpmfront.c
>>>> @@ -39,6 +39,66 @@ enum status_bits {
>>>>   	VTPM_STATUS_CANCELED = 0x8,
>>>>   };
>>>>
>>>> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>>>> +					bool check_cancel, bool *canceled)
>>>> +{
>>>> +	u8 status = chip->ops->status(chip);
>>>> +
>>>> +	*canceled = false;
>>>> +	if ((status & mask) == mask)
>>>> +		return true;
>>>> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
>>>> +		*canceled = true;
>>>> +		return true;
>>>> +	}
>>>> +	return false;
>>>> +}
>>>> +
>>>> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
>>>> +		unsigned long timeout, wait_queue_head_t *queue,
>>>> +		bool check_cancel)
>>>> +{
>>>> +	unsigned long stop;
>>>> +	long rc;
>>>> +	u8 status;
>>>> +	bool canceled = false;
>>>> +
>>>> +	/* check current status */
>>>> +	status = chip->ops->status(chip);
>>>> +	if ((status & mask) == mask)
>>>> +		return 0;
>>>> +
>>>> +	stop = jiffies + timeout;
>>>> +
>>>> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
>>>> +again:
>>>> +		timeout = stop - jiffies;
>>>> +		if ((long)timeout <= 0)
>>>> +			return -ETIME;
>>>> +		rc = wait_event_interruptible_timeout(*queue,
>>>> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
>>>> +					       &canceled),
>>>> +			timeout);
>>>> +		if (rc > 0) {
>>>> +			if (canceled)
>>>> +				return -ECANCELED;
>>>> +			return 0;
>>>> +		}
>>>> +		if (rc == -ERESTARTSYS && freezing(current)) {
>>>> +			clear_thread_flag(TIF_SIGPENDING);
>>>> +			goto again;
>>>> +		}
>>>> +	} else {
>>>> +		do {
>>>> +			tpm_msleep(TPM_TIMEOUT);
>>>> +			status = chip->ops->status(chip);
>>>> +			if ((status & mask) == mask)
>>>> +				return 0;
>>>> +		} while (time_before(jiffies, stop));
>>>> +	}
>>>> +	return -ETIME;
>>>> +}
>>>> +
>>>>   static u8 vtpm_status(struct tpm_chip *chip)
>>>>   {
>>>>   	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
>>>> --
>>>> 2.13.3
>>>>
>>> This commit caused a compiler warning because freezer.h was not included
>>> to xen-tpmfront.c. I manually fixed it.
>> Yep, and checkpatch.pl still complains about some stuff (mostly
>> whitespace) in both patch 1/4 and 2/4. When fixed patches are
>> available, I can run them again through my automation.
>> Alexander

Sorry for delay in response.. I was on vacation for last few days.
Thanks for informing. I am wondering these didn't show up when I ran 
checkpatch.pl.

> I'll fix these manually (weird, I run sparse and checkpatch, must have
> done some mistake).
Thanks Jarkko.

Thanks & Regards,
 ??? - Nayna

> Thank you!
>
> /Jarkko
>

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
@ 2017-10-23 13:32           ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-10-23 13:32 UTC (permalink / raw)
  To: Jarkko Sakkinen, Alexander.Steffen
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, tpmdd, jgunthorpe, patrickc



On 10/20/2017 02:26 PM, Jarkko Sakkinen wrote:
> On Thu, Oct 19, 2017 at 05:00:29PM +0000, Alexander.Steffen@infineon.com wrote:
>>> On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
>>>> The function wait_for_tpm_stat() is currently defined in
>>>> tpm-interface file. It is a hardware specific function used
>>>> only by tpm_tis and xen-tpmfront, so it is removed from
>>>> tpm-interface.c and defined in respective driver files.
>>>>
>>>> Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>>>> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
>>>> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>>>> ---
>>>>   drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
>>>>   drivers/char/tpm/tpm.h           |  2 --
>>>>   drivers/char/tpm/tpm_tis_core.c  | 60
>>> ++++++++++++++++++++++++++++++++++++++++
>>>>   drivers/char/tpm/xen-tpmfront.c  | 60
>>> ++++++++++++++++++++++++++++++++++++++++
>>>>   4 files changed, 120 insertions(+), 62 deletions(-)
>>>>
>>>> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
>>> interface.c
>>>> index 1d6729be4cd6..313f7618d569 100644
>>>> --- a/drivers/char/tpm/tpm-interface.c
>>>> +++ b/drivers/char/tpm/tpm-interface.c
>>>> @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t
>>> buflen)
>>>>   }
>>>>   EXPORT_SYMBOL_GPL(tpm_send);
>>>>
>>>> -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>>>> -					bool check_cancel, bool *canceled)
>>>> -{
>>>> -	u8 status = chip->ops->status(chip);
>>>> -
>>>> -	*canceled = false;
>>>> -	if ((status & mask) == mask)
>>>> -		return true;
>>>> -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
>>>> -		*canceled = true;
>>>> -		return true;
>>>> -	}
>>>> -	return false;
>>>> -}
>>>> -
>>>> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
>>> timeout,
>>>> -		      wait_queue_head_t *queue, bool check_cancel)
>>>> -{
>>>> -	unsigned long stop;
>>>> -	long rc;
>>>> -	u8 status;
>>>> -	bool canceled = false;
>>>> -
>>>> -	/* check current status */
>>>> -	status = chip->ops->status(chip);
>>>> -	if ((status & mask) == mask)
>>>> -		return 0;
>>>> -
>>>> -	stop = jiffies + timeout;
>>>> -
>>>> -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
>>>> -again:
>>>> -		timeout = stop - jiffies;
>>>> -		if ((long)timeout <= 0)
>>>> -			return -ETIME;
>>>> -		rc = wait_event_interruptible_timeout(*queue,
>>>> -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
>>>> -					       &canceled),
>>>> -			timeout);
>>>> -		if (rc > 0) {
>>>> -			if (canceled)
>>>> -				return -ECANCELED;
>>>> -			return 0;
>>>> -		}
>>>> -		if (rc == -ERESTARTSYS && freezing(current)) {
>>>> -			clear_thread_flag(TIF_SIGPENDING);
>>>> -			goto again;
>>>> -		}
>>>> -	} else {
>>>> -		do {
>>>> -			tpm_msleep(TPM_TIMEOUT);
>>>> -			status = chip->ops->status(chip);
>>>> -			if ((status & mask) == mask)
>>>> -				return 0;
>>>> -		} while (time_before(jiffies, stop));
>>>> -	}
>>>> -	return -ETIME;
>>>> -}
>>>> -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
>>>> -
>>>>   #define TPM_ORD_SAVESTATE 152
>>>>   #define SAVESTATE_RESULT_SIZE 10
>>>>
>>>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>>>> index 2d5466a72e40..4fc83ac7abeb 100644
>>>> --- a/drivers/char/tpm/tpm.h
>>>> +++ b/drivers/char/tpm/tpm.h
>>>> @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
>>>>   unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32
>>> ordinal);
>>>>   int tpm_pm_suspend(struct device *dev);
>>>>   int tpm_pm_resume(struct device *dev);
>>>> -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
>>> timeout,
>>>> -		      wait_queue_head_t *queue, bool check_cancel);
>>>>
>>>>   static inline void tpm_msleep(unsigned int delay_msec)
>>>>   {
>>>> diff --git a/drivers/char/tpm/tpm_tis_core.c
>>> b/drivers/char/tpm/tpm_tis_core.c
>>>> index 63bc6c3b949e..b33126a35694 100644
>>>> --- a/drivers/char/tpm/tpm_tis_core.c
>>>> +++ b/drivers/char/tpm/tpm_tis_core.c
>>>> @@ -31,6 +31,66 @@
>>>>   #include "tpm.h"
>>>>   #include "tpm_tis_core.h"
>>>>
>>>> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>>>> +					bool check_cancel, bool *canceled)
>>>> +{
>>>> +	u8 status = chip->ops->status(chip);
>>>> +
>>>> +	*canceled = false;
>>>> +	if ((status & mask) == mask)
>>>> +		return true;
>>>> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
>>>> +		*canceled = true;
>>>> +		return true;
>>>> +	}
>>>> +	return false;
>>>> +}
>>>> +
>>>> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
>>>> +		unsigned long timeout, wait_queue_head_t *queue,
>>>> +		bool check_cancel)
>>>> +{
>>>> +	unsigned long stop;
>>>> +	long rc;
>>>> +	u8 status;
>>>> +	bool canceled = false;
>>>> +
>>>> +	/* check current status */
>>>> +	status = chip->ops->status(chip);
>>>> +	if ((status & mask) == mask)
>>>> +		return 0;
>>>> +
>>>> +	stop = jiffies + timeout;
>>>> +
>>>> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
>>>> +again:
>>>> +		timeout = stop - jiffies;
>>>> +		if ((long)timeout <= 0)
>>>> +			return -ETIME;
>>>> +		rc = wait_event_interruptible_timeout(*queue,
>>>> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
>>>> +					       &canceled),
>>>> +			timeout);
>>>> +		if (rc > 0) {
>>>> +			if (canceled)
>>>> +				return -ECANCELED;
>>>> +			return 0;
>>>> +		}
>>>> +		if (rc == -ERESTARTSYS && freezing(current)) {
>>>> +			clear_thread_flag(TIF_SIGPENDING);
>>>> +			goto again;
>>>> +		}
>>>> +	} else {
>>>> +		do {
>>>> +			tpm_msleep(TPM_TIMEOUT);
>>>> +			status = chip->ops->status(chip);
>>>> +			if ((status & mask) == mask)
>>>> +				return 0;
>>>> +		} while (time_before(jiffies, stop));
>>>> +	}
>>>> +	return -ETIME;
>>>> +}
>>>> +
>>>>   /* Before we attempt to access the TPM we must see that the valid bit is
>>> set.
>>>>    * The specification says that this bit is 0 at reset and remains 0 until the
>>>>    * 'TPM has gone through its self test and initialization and has established
>>>> diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-
>>> tpmfront.c
>>>> index 656e8af95d52..d20a0a9ded27 100644
>>>> --- a/drivers/char/tpm/xen-tpmfront.c
>>>> +++ b/drivers/char/tpm/xen-tpmfront.c
>>>> @@ -39,6 +39,66 @@ enum status_bits {
>>>>   	VTPM_STATUS_CANCELED = 0x8,
>>>>   };
>>>>
>>>> +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
>>>> +					bool check_cancel, bool *canceled)
>>>> +{
>>>> +	u8 status = chip->ops->status(chip);
>>>> +
>>>> +	*canceled = false;
>>>> +	if ((status & mask) == mask)
>>>> +		return true;
>>>> +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
>>>> +		*canceled = true;
>>>> +		return true;
>>>> +	}
>>>> +	return false;
>>>> +}
>>>> +
>>>> +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
>>>> +		unsigned long timeout, wait_queue_head_t *queue,
>>>> +		bool check_cancel)
>>>> +{
>>>> +	unsigned long stop;
>>>> +	long rc;
>>>> +	u8 status;
>>>> +	bool canceled = false;
>>>> +
>>>> +	/* check current status */
>>>> +	status = chip->ops->status(chip);
>>>> +	if ((status & mask) == mask)
>>>> +		return 0;
>>>> +
>>>> +	stop = jiffies + timeout;
>>>> +
>>>> +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
>>>> +again:
>>>> +		timeout = stop - jiffies;
>>>> +		if ((long)timeout <= 0)
>>>> +			return -ETIME;
>>>> +		rc = wait_event_interruptible_timeout(*queue,
>>>> +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
>>>> +					       &canceled),
>>>> +			timeout);
>>>> +		if (rc > 0) {
>>>> +			if (canceled)
>>>> +				return -ECANCELED;
>>>> +			return 0;
>>>> +		}
>>>> +		if (rc == -ERESTARTSYS && freezing(current)) {
>>>> +			clear_thread_flag(TIF_SIGPENDING);
>>>> +			goto again;
>>>> +		}
>>>> +	} else {
>>>> +		do {
>>>> +			tpm_msleep(TPM_TIMEOUT);
>>>> +			status = chip->ops->status(chip);
>>>> +			if ((status & mask) == mask)
>>>> +				return 0;
>>>> +		} while (time_before(jiffies, stop));
>>>> +	}
>>>> +	return -ETIME;
>>>> +}
>>>> +
>>>>   static u8 vtpm_status(struct tpm_chip *chip)
>>>>   {
>>>>   	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
>>>> --
>>>> 2.13.3
>>>>
>>> This commit caused a compiler warning because freezer.h was not included
>>> to xen-tpmfront.c. I manually fixed it.
>> Yep, and checkpatch.pl still complains about some stuff (mostly
>> whitespace) in both patch 1/4 and 2/4. When fixed patches are
>> available, I can run them again through my automation.
>> Alexander

Sorry for delay in response.. I was on vacation for last few days.
Thanks for informing. I am wondering these didn't show up when I ran 
checkpatch.pl.

> I'll fix these manually (weird, I run sparse and checkpatch, must have
> done some mistake).
Thanks Jarkko.

Thanks & Regards,
     - Nayna

> Thank you!
>
> /Jarkko
>

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
  2017-10-23 13:32           ` Nayna Jain
@ 2017-10-24 13:45             ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-24 13:45 UTC (permalink / raw)
  To: Nayna Jain
  Cc: Alexander.Steffen, linux-integrity, zohar, linux-security-module,
	linux-kernel, peterhuewe, tpmdd, jgunthorpe, patrickc

On Mon, Oct 23, 2017 at 07:02:18PM +0530, Nayna Jain wrote:
> 
> 
> On 10/20/2017 02:26 PM, Jarkko Sakkinen wrote:
> > On Thu, Oct 19, 2017 at 05:00:29PM +0000, Alexander.Steffen@infineon.com wrote:
> > > > On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
> > > > > The function wait_for_tpm_stat() is currently defined in
> > > > > tpm-interface file. It is a hardware specific function used
> > > > > only by tpm_tis and xen-tpmfront, so it is removed from
> > > > > tpm-interface.c and defined in respective driver files.
> > > > > 
> > > > > Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> > > > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > > ---
> > > > >   drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
> > > > >   drivers/char/tpm/tpm.h           |  2 --
> > > > >   drivers/char/tpm/tpm_tis_core.c  | 60
> > > > ++++++++++++++++++++++++++++++++++++++++
> > > > >   drivers/char/tpm/xen-tpmfront.c  | 60
> > > > ++++++++++++++++++++++++++++++++++++++++
> > > > >   4 files changed, 120 insertions(+), 62 deletions(-)
> > > > > 
> > > > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
> > > > interface.c
> > > > > index 1d6729be4cd6..313f7618d569 100644
> > > > > --- a/drivers/char/tpm/tpm-interface.c
> > > > > +++ b/drivers/char/tpm/tpm-interface.c
> > > > > @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t
> > > > buflen)
> > > > >   }
> > > > >   EXPORT_SYMBOL_GPL(tpm_send);
> > > > > 
> > > > > -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > > > -					bool check_cancel, bool *canceled)
> > > > > -{
> > > > > -	u8 status = chip->ops->status(chip);
> > > > > -
> > > > > -	*canceled = false;
> > > > > -	if ((status & mask) == mask)
> > > > > -		return true;
> > > > > -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > > > -		*canceled = true;
> > > > > -		return true;
> > > > > -	}
> > > > > -	return false;
> > > > > -}
> > > > > -
> > > > > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> > > > timeout,
> > > > > -		      wait_queue_head_t *queue, bool check_cancel)
> > > > > -{
> > > > > -	unsigned long stop;
> > > > > -	long rc;
> > > > > -	u8 status;
> > > > > -	bool canceled = false;
> > > > > -
> > > > > -	/* check current status */
> > > > > -	status = chip->ops->status(chip);
> > > > > -	if ((status & mask) == mask)
> > > > > -		return 0;
> > > > > -
> > > > > -	stop = jiffies + timeout;
> > > > > -
> > > > > -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > > > -again:
> > > > > -		timeout = stop - jiffies;
> > > > > -		if ((long)timeout <= 0)
> > > > > -			return -ETIME;
> > > > > -		rc = wait_event_interruptible_timeout(*queue,
> > > > > -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > > > -					       &canceled),
> > > > > -			timeout);
> > > > > -		if (rc > 0) {
> > > > > -			if (canceled)
> > > > > -				return -ECANCELED;
> > > > > -			return 0;
> > > > > -		}
> > > > > -		if (rc == -ERESTARTSYS && freezing(current)) {
> > > > > -			clear_thread_flag(TIF_SIGPENDING);
> > > > > -			goto again;
> > > > > -		}
> > > > > -	} else {
> > > > > -		do {
> > > > > -			tpm_msleep(TPM_TIMEOUT);
> > > > > -			status = chip->ops->status(chip);
> > > > > -			if ((status & mask) == mask)
> > > > > -				return 0;
> > > > > -		} while (time_before(jiffies, stop));
> > > > > -	}
> > > > > -	return -ETIME;
> > > > > -}
> > > > > -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
> > > > > -
> > > > >   #define TPM_ORD_SAVESTATE 152
> > > > >   #define SAVESTATE_RESULT_SIZE 10
> > > > > 
> > > > > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> > > > > index 2d5466a72e40..4fc83ac7abeb 100644
> > > > > --- a/drivers/char/tpm/tpm.h
> > > > > +++ b/drivers/char/tpm/tpm.h
> > > > > @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
> > > > >   unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32
> > > > ordinal);
> > > > >   int tpm_pm_suspend(struct device *dev);
> > > > >   int tpm_pm_resume(struct device *dev);
> > > > > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> > > > timeout,
> > > > > -		      wait_queue_head_t *queue, bool check_cancel);
> > > > > 
> > > > >   static inline void tpm_msleep(unsigned int delay_msec)
> > > > >   {
> > > > > diff --git a/drivers/char/tpm/tpm_tis_core.c
> > > > b/drivers/char/tpm/tpm_tis_core.c
> > > > > index 63bc6c3b949e..b33126a35694 100644
> > > > > --- a/drivers/char/tpm/tpm_tis_core.c
> > > > > +++ b/drivers/char/tpm/tpm_tis_core.c
> > > > > @@ -31,6 +31,66 @@
> > > > >   #include "tpm.h"
> > > > >   #include "tpm_tis_core.h"
> > > > > 
> > > > > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > > > +					bool check_cancel, bool *canceled)
> > > > > +{
> > > > > +	u8 status = chip->ops->status(chip);
> > > > > +
> > > > > +	*canceled = false;
> > > > > +	if ((status & mask) == mask)
> > > > > +		return true;
> > > > > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > > > +		*canceled = true;
> > > > > +		return true;
> > > > > +	}
> > > > > +	return false;
> > > > > +}
> > > > > +
> > > > > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > > > > +		unsigned long timeout, wait_queue_head_t *queue,
> > > > > +		bool check_cancel)
> > > > > +{
> > > > > +	unsigned long stop;
> > > > > +	long rc;
> > > > > +	u8 status;
> > > > > +	bool canceled = false;
> > > > > +
> > > > > +	/* check current status */
> > > > > +	status = chip->ops->status(chip);
> > > > > +	if ((status & mask) == mask)
> > > > > +		return 0;
> > > > > +
> > > > > +	stop = jiffies + timeout;
> > > > > +
> > > > > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > > > +again:
> > > > > +		timeout = stop - jiffies;
> > > > > +		if ((long)timeout <= 0)
> > > > > +			return -ETIME;
> > > > > +		rc = wait_event_interruptible_timeout(*queue,
> > > > > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > > > +					       &canceled),
> > > > > +			timeout);
> > > > > +		if (rc > 0) {
> > > > > +			if (canceled)
> > > > > +				return -ECANCELED;
> > > > > +			return 0;
> > > > > +		}
> > > > > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > > > > +			clear_thread_flag(TIF_SIGPENDING);
> > > > > +			goto again;
> > > > > +		}
> > > > > +	} else {
> > > > > +		do {
> > > > > +			tpm_msleep(TPM_TIMEOUT);
> > > > > +			status = chip->ops->status(chip);
> > > > > +			if ((status & mask) == mask)
> > > > > +				return 0;
> > > > > +		} while (time_before(jiffies, stop));
> > > > > +	}
> > > > > +	return -ETIME;
> > > > > +}
> > > > > +
> > > > >   /* Before we attempt to access the TPM we must see that the valid bit is
> > > > set.
> > > > >    * The specification says that this bit is 0 at reset and remains 0 until the
> > > > >    * 'TPM has gone through its self test and initialization and has established
> > > > > diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-
> > > > tpmfront.c
> > > > > index 656e8af95d52..d20a0a9ded27 100644
> > > > > --- a/drivers/char/tpm/xen-tpmfront.c
> > > > > +++ b/drivers/char/tpm/xen-tpmfront.c
> > > > > @@ -39,6 +39,66 @@ enum status_bits {
> > > > >   	VTPM_STATUS_CANCELED = 0x8,
> > > > >   };
> > > > > 
> > > > > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > > > +					bool check_cancel, bool *canceled)
> > > > > +{
> > > > > +	u8 status = chip->ops->status(chip);
> > > > > +
> > > > > +	*canceled = false;
> > > > > +	if ((status & mask) == mask)
> > > > > +		return true;
> > > > > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > > > +		*canceled = true;
> > > > > +		return true;
> > > > > +	}
> > > > > +	return false;
> > > > > +}
> > > > > +
> > > > > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > > > > +		unsigned long timeout, wait_queue_head_t *queue,
> > > > > +		bool check_cancel)
> > > > > +{
> > > > > +	unsigned long stop;
> > > > > +	long rc;
> > > > > +	u8 status;
> > > > > +	bool canceled = false;
> > > > > +
> > > > > +	/* check current status */
> > > > > +	status = chip->ops->status(chip);
> > > > > +	if ((status & mask) == mask)
> > > > > +		return 0;
> > > > > +
> > > > > +	stop = jiffies + timeout;
> > > > > +
> > > > > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > > > +again:
> > > > > +		timeout = stop - jiffies;
> > > > > +		if ((long)timeout <= 0)
> > > > > +			return -ETIME;
> > > > > +		rc = wait_event_interruptible_timeout(*queue,
> > > > > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > > > +					       &canceled),
> > > > > +			timeout);
> > > > > +		if (rc > 0) {
> > > > > +			if (canceled)
> > > > > +				return -ECANCELED;
> > > > > +			return 0;
> > > > > +		}
> > > > > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > > > > +			clear_thread_flag(TIF_SIGPENDING);
> > > > > +			goto again;
> > > > > +		}
> > > > > +	} else {
> > > > > +		do {
> > > > > +			tpm_msleep(TPM_TIMEOUT);
> > > > > +			status = chip->ops->status(chip);
> > > > > +			if ((status & mask) == mask)
> > > > > +				return 0;
> > > > > +		} while (time_before(jiffies, stop));
> > > > > +	}
> > > > > +	return -ETIME;
> > > > > +}
> > > > > +
> > > > >   static u8 vtpm_status(struct tpm_chip *chip)
> > > > >   {
> > > > >   	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
> > > > > --
> > > > > 2.13.3
> > > > > 
> > > > This commit caused a compiler warning because freezer.h was not included
> > > > to xen-tpmfront.c. I manually fixed it.
> > > Yep, and checkpatch.pl still complains about some stuff (mostly
> > > whitespace) in both patch 1/4 and 2/4. When fixed patches are
> > > available, I can run them again through my automation.
> > > Alexander
> 
> Sorry for delay in response.. I was on vacation for last few days.
> Thanks for informing. I am wondering these didn't show up when I ran
> checkpatch.pl.

I also did run checkpatch.pl. Haven't had time to recheck yet but I will
do that since there's always chance for human error.

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files
@ 2017-10-24 13:45             ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-10-24 13:45 UTC (permalink / raw)
  To: linux-security-module

On Mon, Oct 23, 2017 at 07:02:18PM +0530, Nayna Jain wrote:
> 
> 
> On 10/20/2017 02:26 PM, Jarkko Sakkinen wrote:
> > On Thu, Oct 19, 2017 at 05:00:29PM +0000, Alexander.Steffen at infineon.com wrote:
> > > > On Tue, Oct 17, 2017 at 04:32:29PM -0400, Nayna Jain wrote:
> > > > > The function wait_for_tpm_stat() is currently defined in
> > > > > tpm-interface file. It is a hardware specific function used
> > > > > only by tpm_tis and xen-tpmfront, so it is removed from
> > > > > tpm-interface.c and defined in respective driver files.
> > > > > 
> > > > > Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > > Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> > > > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > > ---
> > > > >   drivers/char/tpm/tpm-interface.c | 60 ----------------------------------------
> > > > >   drivers/char/tpm/tpm.h           |  2 --
> > > > >   drivers/char/tpm/tpm_tis_core.c  | 60
> > > > ++++++++++++++++++++++++++++++++++++++++
> > > > >   drivers/char/tpm/xen-tpmfront.c  | 60
> > > > ++++++++++++++++++++++++++++++++++++++++
> > > > >   4 files changed, 120 insertions(+), 62 deletions(-)
> > > > > 
> > > > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-
> > > > interface.c
> > > > > index 1d6729be4cd6..313f7618d569 100644
> > > > > --- a/drivers/char/tpm/tpm-interface.c
> > > > > +++ b/drivers/char/tpm/tpm-interface.c
> > > > > @@ -1035,66 +1035,6 @@ int tpm_send(u32 chip_num, void *cmd, size_t
> > > > buflen)
> > > > >   }
> > > > >   EXPORT_SYMBOL_GPL(tpm_send);
> > > > > 
> > > > > -static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > > > -					bool check_cancel, bool *canceled)
> > > > > -{
> > > > > -	u8 status = chip->ops->status(chip);
> > > > > -
> > > > > -	*canceled = false;
> > > > > -	if ((status & mask) == mask)
> > > > > -		return true;
> > > > > -	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > > > -		*canceled = true;
> > > > > -		return true;
> > > > > -	}
> > > > > -	return false;
> > > > > -}
> > > > > -
> > > > > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> > > > timeout,
> > > > > -		      wait_queue_head_t *queue, bool check_cancel)
> > > > > -{
> > > > > -	unsigned long stop;
> > > > > -	long rc;
> > > > > -	u8 status;
> > > > > -	bool canceled = false;
> > > > > -
> > > > > -	/* check current status */
> > > > > -	status = chip->ops->status(chip);
> > > > > -	if ((status & mask) == mask)
> > > > > -		return 0;
> > > > > -
> > > > > -	stop = jiffies + timeout;
> > > > > -
> > > > > -	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > > > -again:
> > > > > -		timeout = stop - jiffies;
> > > > > -		if ((long)timeout <= 0)
> > > > > -			return -ETIME;
> > > > > -		rc = wait_event_interruptible_timeout(*queue,
> > > > > -			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > > > -					       &canceled),
> > > > > -			timeout);
> > > > > -		if (rc > 0) {
> > > > > -			if (canceled)
> > > > > -				return -ECANCELED;
> > > > > -			return 0;
> > > > > -		}
> > > > > -		if (rc == -ERESTARTSYS && freezing(current)) {
> > > > > -			clear_thread_flag(TIF_SIGPENDING);
> > > > > -			goto again;
> > > > > -		}
> > > > > -	} else {
> > > > > -		do {
> > > > > -			tpm_msleep(TPM_TIMEOUT);
> > > > > -			status = chip->ops->status(chip);
> > > > > -			if ((status & mask) == mask)
> > > > > -				return 0;
> > > > > -		} while (time_before(jiffies, stop));
> > > > > -	}
> > > > > -	return -ETIME;
> > > > > -}
> > > > > -EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
> > > > > -
> > > > >   #define TPM_ORD_SAVESTATE 152
> > > > >   #define SAVESTATE_RESULT_SIZE 10
> > > > > 
> > > > > diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> > > > > index 2d5466a72e40..4fc83ac7abeb 100644
> > > > > --- a/drivers/char/tpm/tpm.h
> > > > > +++ b/drivers/char/tpm/tpm.h
> > > > > @@ -525,8 +525,6 @@ int tpm_do_selftest(struct tpm_chip *chip);
> > > > >   unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32
> > > > ordinal);
> > > > >   int tpm_pm_suspend(struct device *dev);
> > > > >   int tpm_pm_resume(struct device *dev);
> > > > > -int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long
> > > > timeout,
> > > > > -		      wait_queue_head_t *queue, bool check_cancel);
> > > > > 
> > > > >   static inline void tpm_msleep(unsigned int delay_msec)
> > > > >   {
> > > > > diff --git a/drivers/char/tpm/tpm_tis_core.c
> > > > b/drivers/char/tpm/tpm_tis_core.c
> > > > > index 63bc6c3b949e..b33126a35694 100644
> > > > > --- a/drivers/char/tpm/tpm_tis_core.c
> > > > > +++ b/drivers/char/tpm/tpm_tis_core.c
> > > > > @@ -31,6 +31,66 @@
> > > > >   #include "tpm.h"
> > > > >   #include "tpm_tis_core.h"
> > > > > 
> > > > > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > > > +					bool check_cancel, bool *canceled)
> > > > > +{
> > > > > +	u8 status = chip->ops->status(chip);
> > > > > +
> > > > > +	*canceled = false;
> > > > > +	if ((status & mask) == mask)
> > > > > +		return true;
> > > > > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > > > +		*canceled = true;
> > > > > +		return true;
> > > > > +	}
> > > > > +	return false;
> > > > > +}
> > > > > +
> > > > > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > > > > +		unsigned long timeout, wait_queue_head_t *queue,
> > > > > +		bool check_cancel)
> > > > > +{
> > > > > +	unsigned long stop;
> > > > > +	long rc;
> > > > > +	u8 status;
> > > > > +	bool canceled = false;
> > > > > +
> > > > > +	/* check current status */
> > > > > +	status = chip->ops->status(chip);
> > > > > +	if ((status & mask) == mask)
> > > > > +		return 0;
> > > > > +
> > > > > +	stop = jiffies + timeout;
> > > > > +
> > > > > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > > > +again:
> > > > > +		timeout = stop - jiffies;
> > > > > +		if ((long)timeout <= 0)
> > > > > +			return -ETIME;
> > > > > +		rc = wait_event_interruptible_timeout(*queue,
> > > > > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > > > +					       &canceled),
> > > > > +			timeout);
> > > > > +		if (rc > 0) {
> > > > > +			if (canceled)
> > > > > +				return -ECANCELED;
> > > > > +			return 0;
> > > > > +		}
> > > > > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > > > > +			clear_thread_flag(TIF_SIGPENDING);
> > > > > +			goto again;
> > > > > +		}
> > > > > +	} else {
> > > > > +		do {
> > > > > +			tpm_msleep(TPM_TIMEOUT);
> > > > > +			status = chip->ops->status(chip);
> > > > > +			if ((status & mask) == mask)
> > > > > +				return 0;
> > > > > +		} while (time_before(jiffies, stop));
> > > > > +	}
> > > > > +	return -ETIME;
> > > > > +}
> > > > > +
> > > > >   /* Before we attempt to access the TPM we must see that the valid bit is
> > > > set.
> > > > >    * The specification says that this bit is 0 at reset and remains 0 until the
> > > > >    * 'TPM has gone through its self test and initialization and has established
> > > > > diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-
> > > > tpmfront.c
> > > > > index 656e8af95d52..d20a0a9ded27 100644
> > > > > --- a/drivers/char/tpm/xen-tpmfront.c
> > > > > +++ b/drivers/char/tpm/xen-tpmfront.c
> > > > > @@ -39,6 +39,66 @@ enum status_bits {
> > > > >   	VTPM_STATUS_CANCELED = 0x8,
> > > > >   };
> > > > > 
> > > > > +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
> > > > > +					bool check_cancel, bool *canceled)
> > > > > +{
> > > > > +	u8 status = chip->ops->status(chip);
> > > > > +
> > > > > +	*canceled = false;
> > > > > +	if ((status & mask) == mask)
> > > > > +		return true;
> > > > > +	if (check_cancel && chip->ops->req_canceled(chip, status)) {
> > > > > +		*canceled = true;
> > > > > +		return true;
> > > > > +	}
> > > > > +	return false;
> > > > > +}
> > > > > +
> > > > > +static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
> > > > > +		unsigned long timeout, wait_queue_head_t *queue,
> > > > > +		bool check_cancel)
> > > > > +{
> > > > > +	unsigned long stop;
> > > > > +	long rc;
> > > > > +	u8 status;
> > > > > +	bool canceled = false;
> > > > > +
> > > > > +	/* check current status */
> > > > > +	status = chip->ops->status(chip);
> > > > > +	if ((status & mask) == mask)
> > > > > +		return 0;
> > > > > +
> > > > > +	stop = jiffies + timeout;
> > > > > +
> > > > > +	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
> > > > > +again:
> > > > > +		timeout = stop - jiffies;
> > > > > +		if ((long)timeout <= 0)
> > > > > +			return -ETIME;
> > > > > +		rc = wait_event_interruptible_timeout(*queue,
> > > > > +			wait_for_tpm_stat_cond(chip, mask, check_cancel,
> > > > > +					       &canceled),
> > > > > +			timeout);
> > > > > +		if (rc > 0) {
> > > > > +			if (canceled)
> > > > > +				return -ECANCELED;
> > > > > +			return 0;
> > > > > +		}
> > > > > +		if (rc == -ERESTARTSYS && freezing(current)) {
> > > > > +			clear_thread_flag(TIF_SIGPENDING);
> > > > > +			goto again;
> > > > > +		}
> > > > > +	} else {
> > > > > +		do {
> > > > > +			tpm_msleep(TPM_TIMEOUT);
> > > > > +			status = chip->ops->status(chip);
> > > > > +			if ((status & mask) == mask)
> > > > > +				return 0;
> > > > > +		} while (time_before(jiffies, stop));
> > > > > +	}
> > > > > +	return -ETIME;
> > > > > +}
> > > > > +
> > > > >   static u8 vtpm_status(struct tpm_chip *chip)
> > > > >   {
> > > > >   	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
> > > > > --
> > > > > 2.13.3
> > > > > 
> > > > This commit caused a compiler warning because freezer.h was not included
> > > > to xen-tpmfront.c. I manually fixed it.
> > > Yep, and checkpatch.pl still complains about some stuff (mostly
> > > whitespace) in both patch 1/4 and 2/4. When fixed patches are
> > > available, I can run them again through my automation.
> > > Alexander
> 
> Sorry for delay in response.. I was on vacation for last few days.
> Thanks for informing. I am wondering these didn't show up when I ran
> checkpatch.pl.

I also did run checkpatch.pl. Haven't had time to recheck yet but I will
do that since there's always chance for human error.

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-10-20 14:42     ` Alexander.Steffen at infineon.com
  (?)
@ 2017-11-07 18:29       ` Nayna Jain
  -1 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-11-07 18:29 UTC (permalink / raw)
  To: Alexander.Steffen, linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, jgunthorpe, patrickc



On 10/20/2017 08:12 PM, Alexander.Steffen@infineon.com wrote:
>> The TPM burstcount status indicates the number of bytes that can
>> be sent to the TPM without causing bus wait states.  Effectively,
>> it is the number of empty bytes in the command FIFO.
>>
>> This patch optimizes the tpm_tis_send_data() function by checking
>> the burstcount only once. And if the burstcount is valid, it writes
>> all the bytes at once, permitting wait state.
>>
>> After this change, performance on a TPM 1.2 with an 8 byte
>> burstcount for 1000 extends improved from ~41sec to ~14sec.
>>
>> Suggested-by: Ken Goldman<kgold@linux.vnet.ibm.com>  in
>> conjunction with the TPM Device Driver work group.
>> Signed-off-by: Nayna Jain<nayna@linux.vnet.ibm.com>
>> Acked-by: Mimi Zohar<zohar@linux.vnet.ibm.com>
>> ---
>>   drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++----------------------
>> ----
>>   1 file changed, 15 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm_tis_core.c
>> b/drivers/char/tpm/tpm_tis_core.c
>> index b33126a35694..993328ae988c 100644
>> --- a/drivers/char/tpm/tpm_tis_core.c
>> +++ b/drivers/char/tpm/tpm_tis_core.c
>> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
>> u8 *buf, size_t len)
>>   {
>>   	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>>   	int rc, status, burstcnt;
>> -	size_t count = 0;
>>   	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
>>
>>   	status = tpm_tis_status(chip);
>> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
>> u8 *buf, size_t len)
>>   		}
>>   	}
>>
>> -	while (count < len - 1) {
>> -		burstcnt = get_burstcount(chip);
>> -		if (burstcnt < 0) {
>> -			dev_err(&chip->dev, "Unable to read burstcount\n");
>> -			rc = burstcnt;
>> -			goto out_err;
>> -		}
>> -		burstcnt = min_t(int, burstcnt, len - count - 1);
>> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
>>> locality),
>> -					 burstcnt, buf + count);
>> -		if (rc < 0)
>> -			goto out_err;
>> -
>> -		count += burstcnt;
>> -
>> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
>>> timeout_c,
>> -					&priv->int_queue, false) < 0) {
>> -			rc = -ETIME;
>> -			goto out_err;
>> -		}
>> -		status = tpm_tis_status(chip);
>> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
>> -			rc = -EIO;
>> -			goto out_err;
>> -		}
>> +	/*
>> +	 * Get the initial burstcount to ensure TPM is ready to
>> +	 * accept data.
>> +	 */
>> +	burstcnt = get_burstcount(chip);
>> +	if (burstcnt < 0) {
>> +		dev_err(&chip->dev, "Unable to read burstcount\n");
>> +		rc = burstcnt;
>> +		goto out_err;
>>   	}
>>
>> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
>> +			len - 1, buf);
>> +	if (rc < 0)
>> +		goto out_err;
>> +
>>   	/* write last byte */
>> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
>> buf[count]);
>> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
>> 1]);
>>   	if (rc < 0)
>>   		goto out_err;
>>
>> --
>> 2.13.3
> This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to send large amounts of data, e.g. with TPM2_Hash, and subsequent tests seem to take an unusual amount of time. More analysis probably has to wait until November, since I am going to be in Prague next week.

Thanks Alex for testing these.. Did you get the chance to do any further 
analysis ?

Thanks & Regards,
        - Nayna

> Alexander
>

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-07 18:29       ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-11-07 18:29 UTC (permalink / raw)
  To: linux-security-module



On 10/20/2017 08:12 PM, Alexander.Steffen at infineon.com wrote:
>> The TPM burstcount status indicates the number of bytes that can
>> be sent to the TPM without causing bus wait states.  Effectively,
>> it is the number of empty bytes in the command FIFO.
>>
>> This patch optimizes the tpm_tis_send_data() function by checking
>> the burstcount only once. And if the burstcount is valid, it writes
>> all the bytes at once, permitting wait state.
>>
>> After this change, performance on a TPM 1.2 with an 8 byte
>> burstcount for 1000 extends improved from ~41sec to ~14sec.
>>
>> Suggested-by: Ken Goldman<kgold@linux.vnet.ibm.com>  in
>> conjunction with the TPM Device Driver work group.
>> Signed-off-by: Nayna Jain<nayna@linux.vnet.ibm.com>
>> Acked-by: Mimi Zohar<zohar@linux.vnet.ibm.com>
>> ---
>>   drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++----------------------
>> ----
>>   1 file changed, 15 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm_tis_core.c
>> b/drivers/char/tpm/tpm_tis_core.c
>> index b33126a35694..993328ae988c 100644
>> --- a/drivers/char/tpm/tpm_tis_core.c
>> +++ b/drivers/char/tpm/tpm_tis_core.c
>> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
>> u8 *buf, size_t len)
>>   {
>>   	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>>   	int rc, status, burstcnt;
>> -	size_t count = 0;
>>   	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
>>
>>   	status = tpm_tis_status(chip);
>> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
>> u8 *buf, size_t len)
>>   		}
>>   	}
>>
>> -	while (count < len - 1) {
>> -		burstcnt = get_burstcount(chip);
>> -		if (burstcnt < 0) {
>> -			dev_err(&chip->dev, "Unable to read burstcount\n");
>> -			rc = burstcnt;
>> -			goto out_err;
>> -		}
>> -		burstcnt = min_t(int, burstcnt, len - count - 1);
>> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
>>> locality),
>> -					 burstcnt, buf + count);
>> -		if (rc < 0)
>> -			goto out_err;
>> -
>> -		count += burstcnt;
>> -
>> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
>>> timeout_c,
>> -					&priv->int_queue, false) < 0) {
>> -			rc = -ETIME;
>> -			goto out_err;
>> -		}
>> -		status = tpm_tis_status(chip);
>> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
>> -			rc = -EIO;
>> -			goto out_err;
>> -		}
>> +	/*
>> +	 * Get the initial burstcount to ensure TPM is ready to
>> +	 * accept data.
>> +	 */
>> +	burstcnt = get_burstcount(chip);
>> +	if (burstcnt < 0) {
>> +		dev_err(&chip->dev, "Unable to read burstcount\n");
>> +		rc = burstcnt;
>> +		goto out_err;
>>   	}
>>
>> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
>> +			len - 1, buf);
>> +	if (rc < 0)
>> +		goto out_err;
>> +
>>   	/* write last byte */
>> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
>> buf[count]);
>> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
>> 1]);
>>   	if (rc < 0)
>>   		goto out_err;
>>
>> --
>> 2.13.3
> This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to send large amounts of data, e.g. with TPM2_Hash, and subsequent tests seem to take an unusual amount of time. More analysis probably has to wait until November, since I am going to be in Prague next week.

Thanks Alex for testing these.. Did you get the chance to do any further 
analysis ?

Thanks & Regards,
 ?????? - Nayna

> Alexander
>

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-07 18:29       ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-11-07 18:29 UTC (permalink / raw)
  To: Alexander.Steffen, linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, jgunthorpe, patrickc



On 10/20/2017 08:12 PM, Alexander.Steffen@infineon.com wrote:
>> The TPM burstcount status indicates the number of bytes that can
>> be sent to the TPM without causing bus wait states.  Effectively,
>> it is the number of empty bytes in the command FIFO.
>>
>> This patch optimizes the tpm_tis_send_data() function by checking
>> the burstcount only once. And if the burstcount is valid, it writes
>> all the bytes at once, permitting wait state.
>>
>> After this change, performance on a TPM 1.2 with an 8 byte
>> burstcount for 1000 extends improved from ~41sec to ~14sec.
>>
>> Suggested-by: Ken Goldman<kgold@linux.vnet.ibm.com>  in
>> conjunction with the TPM Device Driver work group.
>> Signed-off-by: Nayna Jain<nayna@linux.vnet.ibm.com>
>> Acked-by: Mimi Zohar<zohar@linux.vnet.ibm.com>
>> ---
>>   drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++----------------------
>> ----
>>   1 file changed, 15 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm_tis_core.c
>> b/drivers/char/tpm/tpm_tis_core.c
>> index b33126a35694..993328ae988c 100644
>> --- a/drivers/char/tpm/tpm_tis_core.c
>> +++ b/drivers/char/tpm/tpm_tis_core.c
>> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
>> u8 *buf, size_t len)
>>   {
>>   	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>>   	int rc, status, burstcnt;
>> -	size_t count = 0;
>>   	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
>>
>>   	status = tpm_tis_status(chip);
>> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip,
>> u8 *buf, size_t len)
>>   		}
>>   	}
>>
>> -	while (count < len - 1) {
>> -		burstcnt = get_burstcount(chip);
>> -		if (burstcnt < 0) {
>> -			dev_err(&chip->dev, "Unable to read burstcount\n");
>> -			rc = burstcnt;
>> -			goto out_err;
>> -		}
>> -		burstcnt = min_t(int, burstcnt, len - count - 1);
>> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
>>> locality),
>> -					 burstcnt, buf + count);
>> -		if (rc < 0)
>> -			goto out_err;
>> -
>> -		count += burstcnt;
>> -
>> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
>>> timeout_c,
>> -					&priv->int_queue, false) < 0) {
>> -			rc = -ETIME;
>> -			goto out_err;
>> -		}
>> -		status = tpm_tis_status(chip);
>> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
>> -			rc = -EIO;
>> -			goto out_err;
>> -		}
>> +	/*
>> +	 * Get the initial burstcount to ensure TPM is ready to
>> +	 * accept data.
>> +	 */
>> +	burstcnt = get_burstcount(chip);
>> +	if (burstcnt < 0) {
>> +		dev_err(&chip->dev, "Unable to read burstcount\n");
>> +		rc = burstcnt;
>> +		goto out_err;
>>   	}
>>
>> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
>> +			len - 1, buf);
>> +	if (rc < 0)
>> +		goto out_err;
>> +
>>   	/* write last byte */
>> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
>> buf[count]);
>> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
>> 1]);
>>   	if (rc < 0)
>>   		goto out_err;
>>
>> --
>> 2.13.3
> This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to send large amounts of data, e.g. with TPM2_Hash, and subsequent tests seem to take an unusual amount of time. More analysis probably has to wait until November, since I am going to be in Prague next week.

Thanks Alex for testing these.. Did you get the chance to do any further 
analysis ?

Thanks & Regards,
        - Nayna

> Alexander
>

^ permalink raw reply	[flat|nested] 63+ messages in thread

* RE: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-07 18:29       ` Nayna Jain
@ 2017-11-08 11:32         ` Alexander.Steffen at infineon.com
  -1 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen @ 2017-11-08 11:32 UTC (permalink / raw)
  To: nayna, linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, jgunthorpe, patrickc

> On 10/20/2017 08:12 PM, Alexander.Steffen@infineon.com wrote:
> >> The TPM burstcount status indicates the number of bytes that can
> >> be sent to the TPM without causing bus wait states.  Effectively,
> >> it is the number of empty bytes in the command FIFO.
> >>
> >> This patch optimizes the tpm_tis_send_data() function by checking
> >> the burstcount only once. And if the burstcount is valid, it writes
> >> all the bytes at once, permitting wait state.
> >>
> >> After this change, performance on a TPM 1.2 with an 8 byte
> >> burstcount for 1000 extends improved from ~41sec to ~14sec.
> >>
> >> Suggested-by: Ken Goldman<kgold@linux.vnet.ibm.com>  in
> >> conjunction with the TPM Device Driver work group.
> >> Signed-off-by: Nayna Jain<nayna@linux.vnet.ibm.com>
> >> Acked-by: Mimi Zohar<zohar@linux.vnet.ibm.com>
> >> ---
> >>   drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++------------------
> ----
> >> ----
> >>   1 file changed, 15 insertions(+), 27 deletions(-)
> >>
> >> diff --git a/drivers/char/tpm/tpm_tis_core.c
> >> b/drivers/char/tpm/tpm_tis_core.c
> >> index b33126a35694..993328ae988c 100644
> >> --- a/drivers/char/tpm/tpm_tis_core.c
> >> +++ b/drivers/char/tpm/tpm_tis_core.c
> >> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip
> *chip,
> >> u8 *buf, size_t len)
> >>   {
> >>   	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
> >>   	int rc, status, burstcnt;
> >> -	size_t count = 0;
> >>   	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> >>
> >>   	status = tpm_tis_status(chip);
> >> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip
> *chip,
> >> u8 *buf, size_t len)
> >>   		}
> >>   	}
> >>
> >> -	while (count < len - 1) {
> >> -		burstcnt = get_burstcount(chip);
> >> -		if (burstcnt < 0) {
> >> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> >> -			rc = burstcnt;
> >> -			goto out_err;
> >> -		}
> >> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> >> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> >>> locality),
> >> -					 burstcnt, buf + count);
> >> -		if (rc < 0)
> >> -			goto out_err;
> >> -
> >> -		count += burstcnt;
> >> -
> >> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> >>> timeout_c,
> >> -					&priv->int_queue, false) < 0) {
> >> -			rc = -ETIME;
> >> -			goto out_err;
> >> -		}
> >> -		status = tpm_tis_status(chip);
> >> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> >> -			rc = -EIO;
> >> -			goto out_err;
> >> -		}
> >> +	/*
> >> +	 * Get the initial burstcount to ensure TPM is ready to
> >> +	 * accept data.
> >> +	 */
> >> +	burstcnt = get_burstcount(chip);
> >> +	if (burstcnt < 0) {
> >> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> >> +		rc = burstcnt;
> >> +		goto out_err;
> >>   	}
> >>
> >> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> >> +			len - 1, buf);
> >> +	if (rc < 0)
> >> +		goto out_err;
> >> +
> >>   	/* write last byte */
> >> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> >> buf[count]);
> >> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
> >> 1]);
> >>   	if (rc < 0)
> >>   		goto out_err;
> >>
> >> --
> >> 2.13.3
> > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to
> send large amounts of data, e.g. with TPM2_Hash, and subsequent tests
> seem to take an unusual amount of time. More analysis probably has to wait
> until November, since I am going to be in Prague next week.
> 
> Thanks Alex for testing these.. Did you get the chance to do any further
> analysis ?

I am working on that now. Ken's suggestion seems reasonable, so I am going to test whether correctly waiting for the flags to change fixes the problem. If it does, I'll send the patches.

Alexander

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-08 11:32         ` Alexander.Steffen at infineon.com
  0 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen at infineon.com @ 2017-11-08 11:32 UTC (permalink / raw)
  To: linux-security-module

> On 10/20/2017 08:12 PM, Alexander.Steffen at infineon.com wrote:
> >> The TPM burstcount status indicates the number of bytes that can
> >> be sent to the TPM without causing bus wait states.  Effectively,
> >> it is the number of empty bytes in the command FIFO.
> >>
> >> This patch optimizes the tpm_tis_send_data() function by checking
> >> the burstcount only once. And if the burstcount is valid, it writes
> >> all the bytes at once, permitting wait state.
> >>
> >> After this change, performance on a TPM 1.2 with an 8 byte
> >> burstcount for 1000 extends improved from ~41sec to ~14sec.
> >>
> >> Suggested-by: Ken Goldman<kgold@linux.vnet.ibm.com>  in
> >> conjunction with the TPM Device Driver work group.
> >> Signed-off-by: Nayna Jain<nayna@linux.vnet.ibm.com>
> >> Acked-by: Mimi Zohar<zohar@linux.vnet.ibm.com>
> >> ---
> >>   drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++------------------
> ----
> >> ----
> >>   1 file changed, 15 insertions(+), 27 deletions(-)
> >>
> >> diff --git a/drivers/char/tpm/tpm_tis_core.c
> >> b/drivers/char/tpm/tpm_tis_core.c
> >> index b33126a35694..993328ae988c 100644
> >> --- a/drivers/char/tpm/tpm_tis_core.c
> >> +++ b/drivers/char/tpm/tpm_tis_core.c
> >> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip
> *chip,
> >> u8 *buf, size_t len)
> >>   {
> >>   	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
> >>   	int rc, status, burstcnt;
> >> -	size_t count = 0;
> >>   	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> >>
> >>   	status = tpm_tis_status(chip);
> >> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip
> *chip,
> >> u8 *buf, size_t len)
> >>   		}
> >>   	}
> >>
> >> -	while (count < len - 1) {
> >> -		burstcnt = get_burstcount(chip);
> >> -		if (burstcnt < 0) {
> >> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> >> -			rc = burstcnt;
> >> -			goto out_err;
> >> -		}
> >> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> >> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> >>> locality),
> >> -					 burstcnt, buf + count);
> >> -		if (rc < 0)
> >> -			goto out_err;
> >> -
> >> -		count += burstcnt;
> >> -
> >> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> >>> timeout_c,
> >> -					&priv->int_queue, false) < 0) {
> >> -			rc = -ETIME;
> >> -			goto out_err;
> >> -		}
> >> -		status = tpm_tis_status(chip);
> >> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> >> -			rc = -EIO;
> >> -			goto out_err;
> >> -		}
> >> +	/*
> >> +	 * Get the initial burstcount to ensure TPM is ready to
> >> +	 * accept data.
> >> +	 */
> >> +	burstcnt = get_burstcount(chip);
> >> +	if (burstcnt < 0) {
> >> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> >> +		rc = burstcnt;
> >> +		goto out_err;
> >>   	}
> >>
> >> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> >> +			len - 1, buf);
> >> +	if (rc < 0)
> >> +		goto out_err;
> >> +
> >>   	/* write last byte */
> >> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> >> buf[count]);
> >> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
> >> 1]);
> >>   	if (rc < 0)
> >>   		goto out_err;
> >>
> >> --
> >> 2.13.3
> > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to
> send large amounts of data, e.g. with TPM2_Hash, and subsequent tests
> seem to take an unusual amount of time. More analysis probably has to wait
> until November, since I am going to be in Prague next week.
> 
> Thanks Alex for testing these.. Did you get the chance to do any further
> analysis ?

I am working on that now. Ken's suggestion seems reasonable, so I am going to test whether correctly waiting for the flags to change fixes the problem. If it does, I'll send the patches.

Alexander
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* RE: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-07 18:29       ` Nayna Jain
@ 2017-11-16 14:34         ` Alexander.Steffen at infineon.com
  -1 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen @ 2017-11-16 14:34 UTC (permalink / raw)
  To: nayna, linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, patrickc

> > On 10/20/2017 08:12 PM, Alexander.Steffen@infineon.com wrote:
> > >> The TPM burstcount status indicates the number of bytes that can
> > >> be sent to the TPM without causing bus wait states.  Effectively,
> > >> it is the number of empty bytes in the command FIFO.
> > >>
> > >> This patch optimizes the tpm_tis_send_data() function by checking
> > >> the burstcount only once. And if the burstcount is valid, it writes
> > >> all the bytes at once, permitting wait state.
> > >>
> > >> After this change, performance on a TPM 1.2 with an 8 byte
> > >> burstcount for 1000 extends improved from ~41sec to ~14sec.
> > >>
> > >> Suggested-by: Ken Goldman<kgold@linux.vnet.ibm.com>  in
> > >> conjunction with the TPM Device Driver work group.
> > >> Signed-off-by: Nayna Jain<nayna@linux.vnet.ibm.com>
> > >> Acked-by: Mimi Zohar<zohar@linux.vnet.ibm.com>
> > >> ---
> > >>   drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++----------------
> --
> > ----
> > >> ----
> > >>   1 file changed, 15 insertions(+), 27 deletions(-)
> > >>
> > >> diff --git a/drivers/char/tpm/tpm_tis_core.c
> > >> b/drivers/char/tpm/tpm_tis_core.c
> > >> index b33126a35694..993328ae988c 100644
> > >> --- a/drivers/char/tpm/tpm_tis_core.c
> > >> +++ b/drivers/char/tpm/tpm_tis_core.c
> > >> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip
> > *chip,
> > >> u8 *buf, size_t len)
> > >>   {
> > >>   	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
> > >>   	int rc, status, burstcnt;
> > >> -	size_t count = 0;
> > >>   	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> > >>
> > >>   	status = tpm_tis_status(chip);
> > >> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip
> > *chip,
> > >> u8 *buf, size_t len)
> > >>   		}
> > >>   	}
> > >>
> > >> -	while (count < len - 1) {
> > >> -		burstcnt = get_burstcount(chip);
> > >> -		if (burstcnt < 0) {
> > >> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> > >> -			rc = burstcnt;
> > >> -			goto out_err;
> > >> -		}
> > >> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> > >> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> > >>> locality),
> > >> -					 burstcnt, buf + count);
> > >> -		if (rc < 0)
> > >> -			goto out_err;
> > >> -
> > >> -		count += burstcnt;
> > >> -
> > >> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> > >>> timeout_c,
> > >> -					&priv->int_queue, false) < 0) {
> > >> -			rc = -ETIME;
> > >> -			goto out_err;
> > >> -		}
> > >> -		status = tpm_tis_status(chip);
> > >> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> > >> -			rc = -EIO;
> > >> -			goto out_err;
> > >> -		}
> > >> +	/*
> > >> +	 * Get the initial burstcount to ensure TPM is ready to
> > >> +	 * accept data.
> > >> +	 */
> > >> +	burstcnt = get_burstcount(chip);
> > >> +	if (burstcnt < 0) {
> > >> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> > >> +		rc = burstcnt;
> > >> +		goto out_err;
> > >>   	}
> > >>
> > >> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> > >> +			len - 1, buf);
> > >> +	if (rc < 0)
> > >> +		goto out_err;
> > >> +
> > >>   	/* write last byte */
> > >> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> > >> buf[count]);
> > >> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
> > >> 1]);
> > >>   	if (rc < 0)
> > >>   		goto out_err;
> > >>
> > >> --
> > >> 2.13.3
> > > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to
> > send large amounts of data, e.g. with TPM2_Hash, and subsequent tests
> > seem to take an unusual amount of time. More analysis probably has to
> wait
> > until November, since I am going to be in Prague next week.
> >
> > Thanks Alex for testing these.. Did you get the chance to do any further
> > analysis ?
> 
> I am working on that now. Ken's suggestion seems reasonable, so I am going
> to test whether correctly waiting for the flags to change fixes the problem. If
> it does, I'll send the patches.

Sorry for the delay, I had to take care of some device tree changes in v4.14 that broke my ARM test machines.

I've implemented some patches that fix the issue that Ken pointed out and rebased your patch 2/4 ("ignore burstcount") on top. While doing this I noticed that your original patch does not, as the commit message says, write all the bytes at once, but still unnecessarily splits all commands into at least two transfers (as did the original code). I've fixed this as well in my patches, so that all bytes are indeed sent in a single call, without special handling for the last byte. This should speed up things further, especially for small commands and drivers like tpm_tis_spi, where writing a single byte translates into additional SPI transfers.

Unfortunately, even with those changes the problem persists. But I've got more detailed logs now and will try to understand and hopefully fix the issue. I'll follow up with more details and/or patches once I know more.

Alexander

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-16 14:34         ` Alexander.Steffen at infineon.com
  0 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen at infineon.com @ 2017-11-16 14:34 UTC (permalink / raw)
  To: linux-security-module

> > On 10/20/2017 08:12 PM, Alexander.Steffen at infineon.com wrote:
> > >> The TPM burstcount status indicates the number of bytes that can
> > >> be sent to the TPM without causing bus wait states.  Effectively,
> > >> it is the number of empty bytes in the command FIFO.
> > >>
> > >> This patch optimizes the tpm_tis_send_data() function by checking
> > >> the burstcount only once. And if the burstcount is valid, it writes
> > >> all the bytes at once, permitting wait state.
> > >>
> > >> After this change, performance on a TPM 1.2 with an 8 byte
> > >> burstcount for 1000 extends improved from ~41sec to ~14sec.
> > >>
> > >> Suggested-by: Ken Goldman<kgold@linux.vnet.ibm.com>  in
> > >> conjunction with the TPM Device Driver work group.
> > >> Signed-off-by: Nayna Jain<nayna@linux.vnet.ibm.com>
> > >> Acked-by: Mimi Zohar<zohar@linux.vnet.ibm.com>
> > >> ---
> > >>   drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++----------------
> --
> > ----
> > >> ----
> > >>   1 file changed, 15 insertions(+), 27 deletions(-)
> > >>
> > >> diff --git a/drivers/char/tpm/tpm_tis_core.c
> > >> b/drivers/char/tpm/tpm_tis_core.c
> > >> index b33126a35694..993328ae988c 100644
> > >> --- a/drivers/char/tpm/tpm_tis_core.c
> > >> +++ b/drivers/char/tpm/tpm_tis_core.c
> > >> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip
> > *chip,
> > >> u8 *buf, size_t len)
> > >>   {
> > >>   	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
> > >>   	int rc, status, burstcnt;
> > >> -	size_t count = 0;
> > >>   	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> > >>
> > >>   	status = tpm_tis_status(chip);
> > >> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct tpm_chip
> > *chip,
> > >> u8 *buf, size_t len)
> > >>   		}
> > >>   	}
> > >>
> > >> -	while (count < len - 1) {
> > >> -		burstcnt = get_burstcount(chip);
> > >> -		if (burstcnt < 0) {
> > >> -			dev_err(&chip->dev, "Unable to read burstcount\n");
> > >> -			rc = burstcnt;
> > >> -			goto out_err;
> > >> -		}
> > >> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> > >> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> > >>> locality),
> > >> -					 burstcnt, buf + count);
> > >> -		if (rc < 0)
> > >> -			goto out_err;
> > >> -
> > >> -		count += burstcnt;
> > >> -
> > >> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> > >>> timeout_c,
> > >> -					&priv->int_queue, false) < 0) {
> > >> -			rc = -ETIME;
> > >> -			goto out_err;
> > >> -		}
> > >> -		status = tpm_tis_status(chip);
> > >> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
> > >> -			rc = -EIO;
> > >> -			goto out_err;
> > >> -		}
> > >> +	/*
> > >> +	 * Get the initial burstcount to ensure TPM is ready to
> > >> +	 * accept data.
> > >> +	 */
> > >> +	burstcnt = get_burstcount(chip);
> > >> +	if (burstcnt < 0) {
> > >> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> > >> +		rc = burstcnt;
> > >> +		goto out_err;
> > >>   	}
> > >>
> > >> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
> > >> +			len - 1, buf);
> > >> +	if (rc < 0)
> > >> +		goto out_err;
> > >> +
> > >>   	/* write last byte */
> > >> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> > >> buf[count]);
> > >> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[len-
> > >> 1]);
> > >>   	if (rc < 0)
> > >>   		goto out_err;
> > >>
> > >> --
> > >> 2.13.3
> > > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to
> > send large amounts of data, e.g. with TPM2_Hash, and subsequent tests
> > seem to take an unusual amount of time. More analysis probably has to
> wait
> > until November, since I am going to be in Prague next week.
> >
> > Thanks Alex for testing these.. Did you get the chance to do any further
> > analysis ?
> 
> I am working on that now. Ken's suggestion seems reasonable, so I am going
> to test whether correctly waiting for the flags to change fixes the problem. If
> it does, I'll send the patches.

Sorry for the delay, I had to take care of some device tree changes in v4.14 that broke my ARM test machines.

I've implemented some patches that fix the issue that Ken pointed out and rebased your patch 2/4 ("ignore burstcount") on top. While doing this I noticed that your original patch does not, as the commit message says, write all the bytes at once, but still unnecessarily splits all commands into at least two transfers (as did the original code). I've fixed this as well in my patches, so that all bytes are indeed sent in a single call, without special handling for the last byte. This should speed up things further, especially for small commands and drivers like tpm_tis_spi, where writing a single byte translates into additional SPI transfers.

Unfortunately, even with those changes the problem persists. But I've got more detailed logs now and will try to understand and hopefully fix the issue. I'll follow up with more details and/or patches once I know more.

Alexander
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* RE: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-07 18:29       ` Nayna Jain
@ 2017-11-22  6:52         ` Alexander.Steffen at infineon.com
  -1 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen @ 2017-11-22  6:52 UTC (permalink / raw)
  To: nayna, linux-integrity
  Cc: zohar, linux-security-module, linux-kernel, peterhuewe,
	jarkko.sakkinen, tpmdd, patrickc

> > > On 10/20/2017 08:12 PM, Alexander.Steffen@infineon.com wrote:
> > > >> The TPM burstcount status indicates the number of bytes that can
> > > >> be sent to the TPM without causing bus wait states.  Effectively,
> > > >> it is the number of empty bytes in the command FIFO.
> > > >>
> > > >> This patch optimizes the tpm_tis_send_data() function by checking
> > > >> the burstcount only once. And if the burstcount is valid, it writes
> > > >> all the bytes at once, permitting wait state.
> > > >>
> > > >> After this change, performance on a TPM 1.2 with an 8 byte
> > > >> burstcount for 1000 extends improved from ~41sec to ~14sec.
> > > >>
> > > >> Suggested-by: Ken Goldman<kgold@linux.vnet.ibm.com>  in
> > > >> conjunction with the TPM Device Driver work group.
> > > >> Signed-off-by: Nayna Jain<nayna@linux.vnet.ibm.com>
> > > >> Acked-by: Mimi Zohar<zohar@linux.vnet.ibm.com>
> > > >> ---
> > > >>   drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++--------------
> --
> > --
> > > ----
> > > >> ----
> > > >>   1 file changed, 15 insertions(+), 27 deletions(-)
> > > >>
> > > >> diff --git a/drivers/char/tpm/tpm_tis_core.c
> > > >> b/drivers/char/tpm/tpm_tis_core.c
> > > >> index b33126a35694..993328ae988c 100644
> > > >> --- a/drivers/char/tpm/tpm_tis_core.c
> > > >> +++ b/drivers/char/tpm/tpm_tis_core.c
> > > >> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip
> > > *chip,
> > > >> u8 *buf, size_t len)
> > > >>   {
> > > >>   	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
> > > >>   	int rc, status, burstcnt;
> > > >> -	size_t count = 0;
> > > >>   	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> > > >>
> > > >>   	status = tpm_tis_status(chip);
> > > >> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct
> tpm_chip
> > > *chip,
> > > >> u8 *buf, size_t len)
> > > >>   		}
> > > >>   	}
> > > >>
> > > >> -	while (count < len - 1) {
> > > >> -		burstcnt = get_burstcount(chip);
> > > >> -		if (burstcnt < 0) {
> > > >> -			dev_err(&chip->dev, "Unable to read
> burstcount\n");
> > > >> -			rc = burstcnt;
> > > >> -			goto out_err;
> > > >> -		}
> > > >> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> > > >> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> > > >>> locality),
> > > >> -					 burstcnt, buf + count);
> > > >> -		if (rc < 0)
> > > >> -			goto out_err;
> > > >> -
> > > >> -		count += burstcnt;
> > > >> -
> > > >> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> > > >>> timeout_c,
> > > >> -					&priv->int_queue, false) < 0) {
> > > >> -			rc = -ETIME;
> > > >> -			goto out_err;
> > > >> -		}
> > > >> -		status = tpm_tis_status(chip);
> > > >> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0)
> {
> > > >> -			rc = -EIO;
> > > >> -			goto out_err;
> > > >> -		}
> > > >> +	/*
> > > >> +	 * Get the initial burstcount to ensure TPM is ready to
> > > >> +	 * accept data.
> > > >> +	 */
> > > >> +	burstcnt = get_burstcount(chip);
> > > >> +	if (burstcnt < 0) {
> > > >> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> > > >> +		rc = burstcnt;
> > > >> +		goto out_err;
> > > >>   	}
> > > >>
> > > >> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> >locality),
> > > >> +			len - 1, buf);
> > > >> +	if (rc < 0)
> > > >> +		goto out_err;
> > > >> +
> > > >>   	/* write last byte */
> > > >> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> > > >> buf[count]);
> > > >> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> buf[len-
> > > >> 1]);
> > > >>   	if (rc < 0)
> > > >>   		goto out_err;
> > > >>
> > > >> --
> > > >> 2.13.3
> > > > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to
> > > send large amounts of data, e.g. with TPM2_Hash, and subsequent tests
> > > seem to take an unusual amount of time. More analysis probably has to
> > wait
> > > until November, since I am going to be in Prague next week.
> > >
> > > Thanks Alex for testing these.. Did you get the chance to do any further
> > > analysis ?
> >
> > I am working on that now. Ken's suggestion seems reasonable, so I am
> going
> > to test whether correctly waiting for the flags to change fixes the problem.
> If
> > it does, I'll send the patches.
> 
> Sorry for the delay, I had to take care of some device tree changes in v4.14
> that broke my ARM test machines.
> 
> I've implemented some patches that fix the issue that Ken pointed out and
> rebased your patch 2/4 ("ignore burstcount") on top. While doing this I
> noticed that your original patch does not, as the commit message says, write
> all the bytes at once, but still unnecessarily splits all commands into at least
> two transfers (as did the original code). I've fixed this as well in my patches,
> so that all bytes are indeed sent in a single call, without special handling for
> the last byte. This should speed up things further, especially for small
> commands and drivers like tpm_tis_spi, where writing a single byte
> translates into additional SPI transfers.
> 
> Unfortunately, even with those changes the problem persists. But I've got
> more detailed logs now and will try to understand and hopefully fix the issue.
> I'll follow up with more details and/or patches once I know more.

Okay, so the problem seems to be that at some point the TPM starts inserting wait states for the FIFO access. The driver tries to handle this, but fails since even the 50 retries that are currently used do not seem to be enough. Adding small (millisecond) delays between the attempts did not help so far.

Is there any limit in the specification for how many wait states the TPM may generate or for how long it may do so? I could not find anything, but we need to use something there to prevent a faulty TPM from blocking the kernel forever.

Alexander

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-22  6:52         ` Alexander.Steffen at infineon.com
  0 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen at infineon.com @ 2017-11-22  6:52 UTC (permalink / raw)
  To: linux-security-module

> > > On 10/20/2017 08:12 PM, Alexander.Steffen at infineon.com wrote:
> > > >> The TPM burstcount status indicates the number of bytes that can
> > > >> be sent to the TPM without causing bus wait states.  Effectively,
> > > >> it is the number of empty bytes in the command FIFO.
> > > >>
> > > >> This patch optimizes the tpm_tis_send_data() function by checking
> > > >> the burstcount only once. And if the burstcount is valid, it writes
> > > >> all the bytes at once, permitting wait state.
> > > >>
> > > >> After this change, performance on a TPM 1.2 with an 8 byte
> > > >> burstcount for 1000 extends improved from ~41sec to ~14sec.
> > > >>
> > > >> Suggested-by: Ken Goldman<kgold@linux.vnet.ibm.com>  in
> > > >> conjunction with the TPM Device Driver work group.
> > > >> Signed-off-by: Nayna Jain<nayna@linux.vnet.ibm.com>
> > > >> Acked-by: Mimi Zohar<zohar@linux.vnet.ibm.com>
> > > >> ---
> > > >>   drivers/char/tpm/tpm_tis_core.c | 42 +++++++++++++++--------------
> --
> > --
> > > ----
> > > >> ----
> > > >>   1 file changed, 15 insertions(+), 27 deletions(-)
> > > >>
> > > >> diff --git a/drivers/char/tpm/tpm_tis_core.c
> > > >> b/drivers/char/tpm/tpm_tis_core.c
> > > >> index b33126a35694..993328ae988c 100644
> > > >> --- a/drivers/char/tpm/tpm_tis_core.c
> > > >> +++ b/drivers/char/tpm/tpm_tis_core.c
> > > >> @@ -316,7 +316,6 @@ static int tpm_tis_send_data(struct tpm_chip
> > > *chip,
> > > >> u8 *buf, size_t len)
> > > >>   {
> > > >>   	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
> > > >>   	int rc, status, burstcnt;
> > > >> -	size_t count = 0;
> > > >>   	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
> > > >>
> > > >>   	status = tpm_tis_status(chip);
> > > >> @@ -330,35 +329,24 @@ static int tpm_tis_send_data(struct
> tpm_chip
> > > *chip,
> > > >> u8 *buf, size_t len)
> > > >>   		}
> > > >>   	}
> > > >>
> > > >> -	while (count < len - 1) {
> > > >> -		burstcnt = get_burstcount(chip);
> > > >> -		if (burstcnt < 0) {
> > > >> -			dev_err(&chip->dev, "Unable to read
> burstcount\n");
> > > >> -			rc = burstcnt;
> > > >> -			goto out_err;
> > > >> -		}
> > > >> -		burstcnt = min_t(int, burstcnt, len - count - 1);
> > > >> -		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> > > >>> locality),
> > > >> -					 burstcnt, buf + count);
> > > >> -		if (rc < 0)
> > > >> -			goto out_err;
> > > >> -
> > > >> -		count += burstcnt;
> > > >> -
> > > >> -		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip-
> > > >>> timeout_c,
> > > >> -					&priv->int_queue, false) < 0) {
> > > >> -			rc = -ETIME;
> > > >> -			goto out_err;
> > > >> -		}
> > > >> -		status = tpm_tis_status(chip);
> > > >> -		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0)
> {
> > > >> -			rc = -EIO;
> > > >> -			goto out_err;
> > > >> -		}
> > > >> +	/*
> > > >> +	 * Get the initial burstcount to ensure TPM is ready to
> > > >> +	 * accept data.
> > > >> +	 */
> > > >> +	burstcnt = get_burstcount(chip);
> > > >> +	if (burstcnt < 0) {
> > > >> +		dev_err(&chip->dev, "Unable to read burstcount\n");
> > > >> +		rc = burstcnt;
> > > >> +		goto out_err;
> > > >>   	}
> > > >>
> > > >> +	rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv-
> >locality),
> > > >> +			len - 1, buf);
> > > >> +	if (rc < 0)
> > > >> +		goto out_err;
> > > >> +
> > > >>   	/* write last byte */
> > > >> -	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> > > >> buf[count]);
> > > >> +	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality),
> buf[len-
> > > >> 1]);
> > > >>   	if (rc < 0)
> > > >>   		goto out_err;
> > > >>
> > > >> --
> > > >> 2.13.3
> > > > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to
> > > send large amounts of data, e.g. with TPM2_Hash, and subsequent tests
> > > seem to take an unusual amount of time. More analysis probably has to
> > wait
> > > until November, since I am going to be in Prague next week.
> > >
> > > Thanks Alex for testing these.. Did you get the chance to do any further
> > > analysis ?
> >
> > I am working on that now. Ken's suggestion seems reasonable, so I am
> going
> > to test whether correctly waiting for the flags to change fixes the problem.
> If
> > it does, I'll send the patches.
> 
> Sorry for the delay, I had to take care of some device tree changes in v4.14
> that broke my ARM test machines.
> 
> I've implemented some patches that fix the issue that Ken pointed out and
> rebased your patch 2/4 ("ignore burstcount") on top. While doing this I
> noticed that your original patch does not, as the commit message says, write
> all the bytes at once, but still unnecessarily splits all commands into at least
> two transfers (as did the original code). I've fixed this as well in my patches,
> so that all bytes are indeed sent in a single call, without special handling for
> the last byte. This should speed up things further, especially for small
> commands and drivers like tpm_tis_spi, where writing a single byte
> translates into additional SPI transfers.
> 
> Unfortunately, even with those changes the problem persists. But I've got
> more detailed logs now and will try to understand and hopefully fix the issue.
> I'll follow up with more details and/or patches once I know more.

Okay, so the problem seems to be that at some point the TPM starts inserting wait states for the FIFO access. The driver tries to handle this, but fails since even the 50 retries that are currently used do not seem to be enough. Adding small (millisecond) delays between the attempts did not help so far.

Is there any limit in the specification for how many wait states the TPM may generate or for how long it may do so? I could not find anything, but we need to use something there to prevent a faulty TPM from blocking the kernel forever.

Alexander
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-22  6:52         ` Alexander.Steffen at infineon.com
@ 2017-11-23 14:47           ` Nayna Jain
  -1 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-11-23 14:47 UTC (permalink / raw)
  To: Alexander.Steffen
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, jarkko.sakkinen, tpmdd, patrickc

On Wed, Nov 22, 2017 at 06:52:03AM +0000, Alexander.Steffen@infineon.com wrote:
> > > > > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to
> > > > send large amounts of data, e.g. with TPM2_Hash, and subsequent tests
> > > > seem to take an unusual amount of time. More analysis probably has to
> > > wait
> > > > until November, since I am going to be in Prague next week.
> > > >
> > > > Thanks Alex for testing these.. Did you get the chance to do any further
> > > > analysis ?
> > >
> > > I am working on that now. Ken's suggestion seems reasonable, so I am
> > going
> > > to test whether correctly waiting for the flags to change fixes the problem.
> > If
> > > it does, I'll send the patches.
> > 
> > Sorry for the delay, I had to take care of some device tree changes in v4.14
> > that broke my ARM test machines.
> > 
> > I've implemented some patches that fix the issue that Ken pointed out and
> > rebased your patch 2/4 ("ignore burstcount") on top. While doing this I
> > noticed that your original patch does not, as the commit message says, write
> > all the bytes at once, but still unnecessarily splits all commands into at least
> > two transfers (as did the original code). I've fixed this as well in my patches,
> > so that all bytes are indeed sent in a single call, without special handling for
> > the last byte. This should speed up things further, especially for small
> > commands and drivers like tpm_tis_spi, where writing a single byte
> > translates into additional SPI transfers.

Thanks Alex, for digging into.

Yeah, you are right, the first version of this patch sent all the bytes together, but after hearing ddwg inputs,
i.e. "The last byte was introduced for error checking purposes (history).", I reverted back to original to be safe.

It seems that the last byte was sent from the beginning (27084ef [PATCH] tpm: driver for next generation TPM chips,),
does anyone remember the reason ?

> > 
> > Unfortunately, even with those changes the problem persists. But I've got
> > more detailed logs now and will try to understand and hopefully fix the issue.
> > I'll follow up with more details and/or patches once I know more.
> 
> Okay, so the problem seems to be that at some point the TPM starts inserting wait states for the FIFO access. The driver tries to handle this, but fails since even the 50 retries that are currently used do not seem to be enough. Adding small (millisecond) delays between the attempts did not help so far.
> 
> Is there any limit in the specification for how many wait states the TPM may generate or for how long it may do so? I could not find anything, but we need to use something there to prevent a faulty TPM from blocking the kernel forever.
> 

I have been thinking on this, so was wondering:

1. As you said the problem started while sending large amounts of data for TPM2_Hash, how large is "large" ? I mean did it work for some specific large values before failing.
2. Are these wait states limited to SPI, or does it happen on LPC as well?

Thanks & Regards,
   - Nayna


> Alexander
> 

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-23 14:47           ` Nayna Jain
  0 siblings, 0 replies; 63+ messages in thread
From: Nayna Jain @ 2017-11-23 14:47 UTC (permalink / raw)
  To: linux-security-module

On Wed, Nov 22, 2017 at 06:52:03AM +0000, Alexander.Steffen at infineon.com wrote:
> > > > > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying to
> > > > send large amounts of data, e.g. with TPM2_Hash, and subsequent tests
> > > > seem to take an unusual amount of time. More analysis probably has to
> > > wait
> > > > until November, since I am going to be in Prague next week.
> > > >
> > > > Thanks Alex for testing these.. Did you get the chance to do any further
> > > > analysis ?
> > >
> > > I am working on that now. Ken's suggestion seems reasonable, so I am
> > going
> > > to test whether correctly waiting for the flags to change fixes the problem.
> > If
> > > it does, I'll send the patches.
> > 
> > Sorry for the delay, I had to take care of some device tree changes in v4.14
> > that broke my ARM test machines.
> > 
> > I've implemented some patches that fix the issue that Ken pointed out and
> > rebased your patch 2/4 ("ignore burstcount") on top. While doing this I
> > noticed that your original patch does not, as the commit message says, write
> > all the bytes at once, but still unnecessarily splits all commands into at least
> > two transfers (as did the original code). I've fixed this as well in my patches,
> > so that all bytes are indeed sent in a single call, without special handling for
> > the last byte. This should speed up things further, especially for small
> > commands and drivers like tpm_tis_spi, where writing a single byte
> > translates into additional SPI transfers.

Thanks Alex, for digging into.

Yeah, you are right, the first version of this patch sent all the bytes together, but after hearing ddwg inputs,
i.e. "The last byte was introduced for error checking purposes (history).", I reverted back to original to be safe.

It seems that the last byte was sent from the beginning (27084ef [PATCH] tpm: driver for next generation TPM chips,),
does anyone remember the reason ?

> > 
> > Unfortunately, even with those changes the problem persists. But I've got
> > more detailed logs now and will try to understand and hopefully fix the issue.
> > I'll follow up with more details and/or patches once I know more.
> 
> Okay, so the problem seems to be that at some point the TPM starts inserting wait states for the FIFO access. The driver tries to handle this, but fails since even the 50 retries that are currently used do not seem to be enough. Adding small (millisecond) delays between the attempts did not help so far.
> 
> Is there any limit in the specification for how many wait states the TPM may generate or for how long it may do so? I could not find anything, but we need to use something there to prevent a faulty TPM from blocking the kernel forever.
> 

I have been thinking on this, so was wondering:

1. As you said the problem started while sending large amounts of data for TPM2_Hash, how large is "large" ? I mean did it work for some specific large values before failing.
2. Are these wait states limited to SPI, or does it happen on LPC as well?

Thanks & Regards,
   - Nayna


> Alexander
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* RE: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-23 14:47           ` Nayna Jain
@ 2017-11-23 16:19             ` Alexander.Steffen at infineon.com
  -1 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen @ 2017-11-23 16:19 UTC (permalink / raw)
  To: nayna
  Cc: linux-integrity, zohar, linux-security-module, linux-kernel,
	peterhuewe, jarkko.sakkinen, tpmdd, patrickc

> On Wed, Nov 22, 2017 at 06:52:03AM +0000,
> Alexander.Steffen@infineon.com wrote:
> > > > > > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying
> to
> > > > > send large amounts of data, e.g. with TPM2_Hash, and subsequent
> tests
> > > > > seem to take an unusual amount of time. More analysis probably has
> to
> > > > wait
> > > > > until November, since I am going to be in Prague next week.
> > > > >
> > > > > Thanks Alex for testing these.. Did you get the chance to do any
> further
> > > > > analysis ?
> > > >
> > > > I am working on that now. Ken's suggestion seems reasonable, so I am
> > > going
> > > > to test whether correctly waiting for the flags to change fixes the
> problem.
> > > If
> > > > it does, I'll send the patches.
> > >
> > > Sorry for the delay, I had to take care of some device tree changes in
> v4.14
> > > that broke my ARM test machines.
> > >
> > > I've implemented some patches that fix the issue that Ken pointed out
> and
> > > rebased your patch 2/4 ("ignore burstcount") on top. While doing this I
> > > noticed that your original patch does not, as the commit message says,
> write
> > > all the bytes at once, but still unnecessarily splits all commands into at
> least
> > > two transfers (as did the original code). I've fixed this as well in my
> patches,
> > > so that all bytes are indeed sent in a single call, without special handling
> for
> > > the last byte. This should speed up things further, especially for small
> > > commands and drivers like tpm_tis_spi, where writing a single byte
> > > translates into additional SPI transfers.
> 
> Thanks Alex, for digging into.
> 
> Yeah, you are right, the first version of this patch sent all the bytes together,
> but after hearing ddwg inputs,
> i.e. "The last byte was introduced for error checking purposes (history).", I
> reverted back to original to be safe.
> 
> It seems that the last byte was sent from the beginning (27084ef [PATCH]
> tpm: driver for next generation TPM chips,),
> does anyone remember the reason ?

The intention seems to be to make extra sure that the TPM has correctly understood the command by observing the Expect flag flipping from 1 to 0 when writing the last byte.

But following Ken's arguments, this does not work as intended, because the Expect flag will change not when writing the last byte to the FIFO, but when the TPM reads the last byte from the FIFO. Since there is no "FIFO empty" indication, just observing the Expect flag to be 1 before writing the last byte, cannot reliably tell us anything (there might be enough data left in the FIFO for the Expect flag to flip to 0 without writing the last byte).

Also, I'd argue that this check is not necessary, because if the Expect flag is 0 after all bytes have been written to the FIFO, then the TPM has correctly received the command and is ready to execute it. According to TIS/PTP the TPM is required to throw away all extra bytes that were not announced in the header, and in addition the kernel driver already ensures not to send more data. That are enough safeguards, I'd say.

> 
> > >
> > > Unfortunately, even with those changes the problem persists. But I've
> got
> > > more detailed logs now and will try to understand and hopefully fix the
> issue.
> > > I'll follow up with more details and/or patches once I know more.
> >
> > Okay, so the problem seems to be that at some point the TPM starts
> inserting wait states for the FIFO access. The driver tries to handle this, but
> fails since even the 50 retries that are currently used do not seem to be
> enough. Adding small (millisecond) delays between the attempts did not
> help so far.
> >
> > Is there any limit in the specification for how many wait states the TPM may
> generate or for how long it may do so? I could not find anything, but we need
> to use something there to prevent a faulty TPM from blocking the kernel
> forever.
> >
> 
> I have been thinking on this, so was wondering:
> 
> 1. As you said the problem started while sending large amounts of data for
> TPM2_Hash, how large is "large" ? I mean did it work for some specific large
> values before failing.

Around 1k of data (the exact values are chosen randomly, and it failed many times), but I did not try to find a specific boundary. The interesting thing was that for this long command all SPI frames with the maximum payload of 64 bytes were accepted without wait states, but the last frame (with less than 64 bytes) caused the wait states.

> 2. Are these wait states limited to SPI, or does it happen on LPC as well?

I do not know for LPC because there the wait states are handled in hardware and I cannot trace the LPC signals.

> Thanks & Regards,
>    - Nayna
> 
> 
> > Alexander
> >
> 

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-23 16:19             ` Alexander.Steffen at infineon.com
  0 siblings, 0 replies; 63+ messages in thread
From: Alexander.Steffen at infineon.com @ 2017-11-23 16:19 UTC (permalink / raw)
  To: linux-security-module

> On Wed, Nov 22, 2017 at 06:52:03AM +0000,
> Alexander.Steffen at infineon.com wrote:
> > > > > > This seems to fail reliably with my SPI TPM 2.0. I get EIO when trying
> to
> > > > > send large amounts of data, e.g. with TPM2_Hash, and subsequent
> tests
> > > > > seem to take an unusual amount of time. More analysis probably has
> to
> > > > wait
> > > > > until November, since I am going to be in Prague next week.
> > > > >
> > > > > Thanks Alex for testing these.. Did you get the chance to do any
> further
> > > > > analysis ?
> > > >
> > > > I am working on that now. Ken's suggestion seems reasonable, so I am
> > > going
> > > > to test whether correctly waiting for the flags to change fixes the
> problem.
> > > If
> > > > it does, I'll send the patches.
> > >
> > > Sorry for the delay, I had to take care of some device tree changes in
> v4.14
> > > that broke my ARM test machines.
> > >
> > > I've implemented some patches that fix the issue that Ken pointed out
> and
> > > rebased your patch 2/4 ("ignore burstcount") on top. While doing this I
> > > noticed that your original patch does not, as the commit message says,
> write
> > > all the bytes at once, but still unnecessarily splits all commands into at
> least
> > > two transfers (as did the original code). I've fixed this as well in my
> patches,
> > > so that all bytes are indeed sent in a single call, without special handling
> for
> > > the last byte. This should speed up things further, especially for small
> > > commands and drivers like tpm_tis_spi, where writing a single byte
> > > translates into additional SPI transfers.
> 
> Thanks Alex, for digging into.
> 
> Yeah, you are right, the first version of this patch sent all the bytes together,
> but after hearing ddwg inputs,
> i.e. "The last byte was introduced for error checking purposes (history).", I
> reverted back to original to be safe.
> 
> It seems that the last byte was sent from the beginning (27084ef [PATCH]
> tpm: driver for next generation TPM chips,),
> does anyone remember the reason ?

The intention seems to be to make extra sure that the TPM has correctly understood the command by observing the Expect flag flipping from 1 to 0 when writing the last byte.

But following Ken's arguments, this does not work as intended, because the Expect flag will change not when writing the last byte to the FIFO, but when the TPM reads the last byte from the FIFO. Since there is no "FIFO empty" indication, just observing the Expect flag to be 1 before writing the last byte, cannot reliably tell us anything (there might be enough data left in the FIFO for the Expect flag to flip to 0 without writing the last byte).

Also, I'd argue that this check is not necessary, because if the Expect flag is 0 after all bytes have been written to the FIFO, then the TPM has correctly received the command and is ready to execute it. According to TIS/PTP the TPM is required to throw away all extra bytes that were not announced in the header, and in addition the kernel driver already ensures not to send more data. That are enough safeguards, I'd say.

> 
> > >
> > > Unfortunately, even with those changes the problem persists. But I've
> got
> > > more detailed logs now and will try to understand and hopefully fix the
> issue.
> > > I'll follow up with more details and/or patches once I know more.
> >
> > Okay, so the problem seems to be that at some point the TPM starts
> inserting wait states for the FIFO access. The driver tries to handle this, but
> fails since even the 50 retries that are currently used do not seem to be
> enough. Adding small (millisecond) delays between the attempts did not
> help so far.
> >
> > Is there any limit in the specification for how many wait states the TPM may
> generate or for how long it may do so? I could not find anything, but we need
> to use something there to prevent a faulty TPM from blocking the kernel
> forever.
> >
> 
> I have been thinking on this, so was wondering:
> 
> 1. As you said the problem started while sending large amounts of data for
> TPM2_Hash, how large is "large" ? I mean did it work for some specific large
> values before failing.

Around 1k of data (the exact values are chosen randomly, and it failed many times), but I did not try to find a specific boundary. The interesting thing was that for this long command all SPI frames with the maximum payload of 64 bytes were accepted without wait states, but the last frame (with less than 64 bytes) caused the wait states.

> 2. Are these wait states limited to SPI, or does it happen on LPC as well?

I do not know for LPC because there the wait states are handled in hardware and I cannot trace the LPC signals.

> Thanks & Regards,
>    - Nayna
> 
> 
> > Alexander
> >
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-23 14:47           ` Nayna Jain
@ 2017-11-26 15:22             ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-11-26 15:22 UTC (permalink / raw)
  To: Nayna Jain
  Cc: Alexander.Steffen, linux-integrity, zohar, linux-security-module,
	linux-kernel, peterhuewe, tpmdd, patrickc

On Thu, Nov 23, 2017 at 08:17:42PM +0530, Nayna Jain wrote:
> Yeah, you are right, the first version of this patch sent all the
> bytes together, but after hearing ddwg inputs, i.e. "The last byte was
> introduced for error checking purposes (history).", I reverted back to
> original to be safe.

What does that mean ie error checking purposes?

> It seems that the last byte was sent from the beginning (27084ef
> [PATCH] tpm: driver for next generation TPM chips,), does anyone
> remember the reason ?

Sent from the beginning?

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-26 15:22             ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-11-26 15:22 UTC (permalink / raw)
  To: linux-security-module

On Thu, Nov 23, 2017 at 08:17:42PM +0530, Nayna Jain wrote:
> Yeah, you are right, the first version of this patch sent all the
> bytes together, but after hearing ddwg inputs, i.e. "The last byte was
> introduced for error checking purposes (history).", I reverted back to
> original to be safe.

What does that mean ie error checking purposes?

> It seems that the last byte was sent from the beginning (27084ef
> [PATCH] tpm: driver for next generation TPM chips,), does anyone
> remember the reason ?

Sent from the beginning?

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-26 15:22             ` Jarkko Sakkinen
@ 2017-11-26 16:37               ` Mimi Zohar
  -1 siblings, 0 replies; 63+ messages in thread
From: Mimi Zohar @ 2017-11-26 16:37 UTC (permalink / raw)
  To: Jarkko Sakkinen, Nayna Jain
  Cc: Alexander.Steffen, linux-integrity, linux-security-module,
	linux-kernel, peterhuewe, tpmdd, patrickc, Safford,
	David (GE Global Research, US),
	leendert

[Cc'ing Dave and Leendeert]

Hi Jarkko,

> > It seems that the last byte was sent from the beginning (27084ef
> > [PATCH] tpm: driver for next generation TPM chips,), does anyone
> > remember the reason ?
> 
> Sent from the beginning?

I went through the commit logs to see if any of the patch descriptions
have an explanation for sending the last byte separately. Based on
commit 27084efee0c3 "[PATCH] tpm: driver for next generation TPM
chips", it seems it's been there since the beginning.

Dave, Leendert, Do either of you remember the reason for
tpm_tis_send_data() sending the last byte separately?

thanks,

Mimi

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-26 16:37               ` Mimi Zohar
  0 siblings, 0 replies; 63+ messages in thread
From: Mimi Zohar @ 2017-11-26 16:37 UTC (permalink / raw)
  To: linux-security-module

[Cc'ing Dave and Leendeert]

Hi Jarkko,

> > It seems that the last byte was sent from the beginning (27084ef
> > [PATCH] tpm: driver for next generation TPM chips,), does anyone
> > remember the reason ?
> 
> Sent from the beginning?

I went through the commit logs to see if any of the patch descriptions
have an explanation for sending the last byte separately. Based on
commit 27084efee0c3 "[PATCH] tpm: driver for next generation TPM
chips", it seems it's been there since the beginning.

Dave, Leendert, Do either of you remember the reason for
tpm_tis_send_data() sending the last byte separately?

thanks,

Mimi


--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-26 16:37               ` Mimi Zohar
  (?)
@ 2017-11-27  7:08                 ` Leendert van Doorn
  -1 siblings, 0 replies; 63+ messages in thread
From: Leendert van Doorn @ 2017-11-27  7:08 UTC (permalink / raw)
  To: Mimi Zohar, Jarkko Sakkinen, Nayna Jain
  Cc: Alexander.Steffen, linux-integrity, linux-security-module,
	linux-kernel, peterhuewe, tpmdd, patrickc, Safford,
	David (GE Global Research, US)

Hmm, this is almost 20 years old code (

I think the original code did a burst write and didn't check for error conditions until the very last byte write. I seem to remember that there was some text in the original standard to that effect (this may have gone back as far as IBM's ESS spec).

The current code does check for error conditions after each write byte(s) so I don't think there is any reason for this anymore. Changing the while condition to count < len and setting burstcnt = min_t(int, burstcnt, len - count) and remove the tpm_tis_write8/wait_for_tpm_stat/tpm_tis_status clauses after the while loop should be sufficient.

	Leendert

On 11/26/17, 8:37 AM, "Mimi Zohar" <zohar@linux.vnet.ibm.com> wrote:

    [Cc'ing Dave and Leendeert]
    
    Hi Jarkko,
    
    > > It seems that the last byte was sent from the beginning (27084ef
    > > [PATCH] tpm: driver for next generation TPM chips,), does anyone
    > > remember the reason ?
    > 
    > Sent from the beginning?
    
    I went through the commit logs to see if any of the patch descriptions
    have an explanation for sending the last byte separately. Based on
    commit 27084efee0c3 "[PATCH] tpm: driver for next generation TPM
    chips", it seems it's been there since the beginning.
    
    Dave, Leendert, Do either of you remember the reason for
    tpm_tis_send_data() sending the last byte separately?
    
    thanks,
    
    Mimi
    
    
    

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-27  7:08                 ` Leendert van Doorn
  0 siblings, 0 replies; 63+ messages in thread
From: Leendert van Doorn @ 2017-11-27  7:08 UTC (permalink / raw)
  To: linux-security-module

Hmm, this is almost 20 years old code (

I think the original code did a burst write and didn't check for error conditions until the very last byte write. I seem to remember that there was some text in the original standard to that effect (this may have gone back as far as IBM's ESS spec).

The current code does check for error conditions after each write byte(s) so I don't think there is any reason for this anymore. Changing the while condition to count < len and setting burstcnt = min_t(int, burstcnt, len - count) and remove the tpm_tis_write8/wait_for_tpm_stat/tpm_tis_status clauses after the while loop should be sufficient.

	Leendert

???On 11/26/17, 8:37 AM, "Mimi Zohar" <zohar@linux.vnet.ibm.com> wrote:

    [Cc'ing Dave and Leendeert]
    
    Hi Jarkko,
    
    > > It seems that the last byte was sent from the beginning (27084ef
    > > [PATCH] tpm: driver for next generation TPM chips,), does anyone
    > > remember the reason ?
    > 
    > Sent from the beginning?
    
    I went through the commit logs to see if any of the patch descriptions
    have an explanation for sending the last byte separately. Based on
    commit 27084efee0c3 "[PATCH] tpm: driver for next generation TPM
    chips", it seems it's been there since the beginning.
    
    Dave, Leendert, Do either of you remember the reason for
    tpm_tis_send_data() sending the last byte separately?
    
    thanks,
    
    Mimi
    
    
    

????{.n?+???????+%???????\x17??w??{.n?+????{??????????v?^?)????w*\x1fjg???\x1e???????j??\a??G??????\f???j:+v???w?j?m?????\x1e??\x1e?w?????f???h?????????

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-27  7:08                 ` Leendert van Doorn
  0 siblings, 0 replies; 63+ messages in thread
From: Leendert van Doorn @ 2017-11-27  7:08 UTC (permalink / raw)
  To: Mimi Zohar, Jarkko Sakkinen, Nayna Jain
  Cc: Alexander.Steffen, linux-integrity, linux-security-module,
	linux-kernel, peterhuewe, tpmdd, patrickc, Safford,
	David (GE Global Research, US)

Hmm, this is almost 20 years old code (

I think the original code did a burst write and didn't check for error conditions until the very last byte write. I seem to remember that there was some text in the original standard to that effect (this may have gone back as far as IBM's ESS spec).

The current code does check for error conditions after each write byte(s) so I don't think there is any reason for this anymore. Changing the while condition to count < len and setting burstcnt = min_t(int, burstcnt, len - count) and remove the tpm_tis_write8/wait_for_tpm_stat/tpm_tis_status clauses after the while loop should be sufficient.

	Leendert

On 11/26/17, 8:37 AM, "Mimi Zohar" <zohar@linux.vnet.ibm.com> wrote:

    [Cc'ing Dave and Leendeert]
    
    Hi Jarkko,
    
    > > It seems that the last byte was sent from the beginning (27084ef
    > > [PATCH] tpm: driver for next generation TPM chips,), does anyone
    > > remember the reason ?
    > 
    > Sent from the beginning?
    
    I went through the commit logs to see if any of the patch descriptions
    have an explanation for sending the last byte separately. Based on
    commit 27084efee0c3 "[PATCH] tpm: driver for next generation TPM
    chips", it seems it's been there since the beginning.
    
    Dave, Leendert, Do either of you remember the reason for
    tpm_tis_send_data() sending the last byte separately?
    
    thanks,
    
    Mimi
    
    
    

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-27  7:08                 ` Leendert van Doorn
  (?)
@ 2017-11-27 13:22                   ` Mimi Zohar
  -1 siblings, 0 replies; 63+ messages in thread
From: Mimi Zohar @ 2017-11-27 13:22 UTC (permalink / raw)
  To: Leendert van Doorn, Jarkko Sakkinen, Nayna Jain
  Cc: Alexander.Steffen, linux-integrity, linux-security-module,
	linux-kernel, peterhuewe, tpmdd, patrickc, Safford,
	David (GE Global Research, US)

Hi, Leendert!

On Mon, 2017-11-27 at 07:08 +0000, Leendert van Doorn wrote:
> Hmm, this is almost 20 years old code (
> 
> I think the original code did a burst write and didn't check for
> error conditions until the very last byte write. I seem to remember
> that there was some text in the original standard to that effect
> (this may have gone back as far as IBM's ESS spec).

I really appreciate your responding with your recollections.

> The current code does check for error conditions after each write
> byte(s) so I don't think there is any reason for this anymore.
> Changing the while condition to count < len and setting burstcnt =
> min_t(int, burstcnt, len - count) and remove the
> tpm_tis_write8/wait_for_tpm_stat/tpm_tis_status clauses after the
> while loop should be sufficient.

The context for my question was about removing the while loop and
sending all of the data at once, relying on the bus wait states.
 Before making the change, I wanted to make sure there wasn't anything
special about the last byte.

thanks,

Mimi

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-27 13:22                   ` Mimi Zohar
  0 siblings, 0 replies; 63+ messages in thread
From: Mimi Zohar @ 2017-11-27 13:22 UTC (permalink / raw)
  To: linux-security-module

Hi, Leendert!

On Mon, 2017-11-27 at 07:08 +0000, Leendert van Doorn wrote:
> Hmm, this is almost 20 years old code (
> 
> I think the original code did a burst write and didn't check for
> error conditions until the very last byte write. I seem to remember
> that there was some text in the original standard to that effect
> (this may have gone back as far as IBM's ESS spec).

I really appreciate your responding with your recollections.

> The current code does check for error conditions after each write
> byte(s) so I don't think there is any reason for this anymore.
> Changing the while condition to count < len and setting burstcnt =
> min_t(int, burstcnt, len - count) and remove the
> tpm_tis_write8/wait_for_tpm_stat/tpm_tis_status clauses after the
> while loop should be sufficient.

The context for my question was about removing the while loop and
sending all of the data at once, relying on the bus wait states.
?Before making the change, I wanted to make sure there wasn't anything
special about the last byte.

thanks,

Mimi

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-27 13:22                   ` Mimi Zohar
  0 siblings, 0 replies; 63+ messages in thread
From: Mimi Zohar @ 2017-11-27 13:22 UTC (permalink / raw)
  To: Leendert van Doorn, Jarkko Sakkinen, Nayna Jain
  Cc: Alexander.Steffen, linux-integrity, linux-security-module,
	linux-kernel, peterhuewe, tpmdd, patrickc, Safford,
	David (GE Global Research, US)

Hi, Leendert!

On Mon, 2017-11-27 at 07:08 +0000, Leendert van Doorn wrote:
> Hmm, this is almost 20 years old code (
> 
> I think the original code did a burst write and didn't check for
> error conditions until the very last byte write. I seem to remember
> that there was some text in the original standard to that effect
> (this may have gone back as far as IBM's ESS spec).

I really appreciate your responding with your recollections.

> The current code does check for error conditions after each write
> byte(s) so I don't think there is any reason for this anymore.
> Changing the while condition to count < len and setting burstcnt =
> min_t(int, burstcnt, len - count) and remove the
> tpm_tis_write8/wait_for_tpm_stat/tpm_tis_status clauses after the
> while loop should be sufficient.

The context for my question was about removing the while loop and
sending all of the data at once, relying on the bus wait states.
 Before making the change, I wanted to make sure there wasn't anything
special about the last byte.

thanks,

Mimi

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
  2017-11-27  7:08                 ` Leendert van Doorn
  (?)
@ 2017-11-28 20:19                   ` Jarkko Sakkinen
  -1 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-11-28 20:19 UTC (permalink / raw)
  To: Leendert van Doorn
  Cc: Mimi Zohar, Nayna Jain, Alexander.Steffen, linux-integrity,
	linux-security-module, linux-kernel, peterhuewe, tpmdd, patrickc,
	Safford, David (GE Global Research, US)

On Mon, Nov 27, 2017 at 07:08:51AM +0000, Leendert van Doorn wrote:
> Hmm, this is almost 20 years old code (
> 
> I think the original code did a burst write and didn't check for error
> conditions until the very last byte write. I seem to remember that
> there was some text in the original standard to that effect (this may
> have gone back as far as IBM's ESS spec).
> 
> The current code does check for error conditions after each write
> byte(s) so I don't think there is any reason for this anymore.
> Changing the while condition to count < len and setting burstcnt =
> min_t(int, burstcnt, len - count) and remove the
> tpm_tis_write8/wait_for_tpm_stat/tpm_tis_status clauses after the
> while loop should be sufficient.

Thank you for sharing this!

> 	Leendert

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

* [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-28 20:19                   ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-11-28 20:19 UTC (permalink / raw)
  To: linux-security-module

On Mon, Nov 27, 2017 at 07:08:51AM +0000, Leendert van Doorn wrote:
> Hmm, this is almost 20 years old code (
> 
> I think the original code did a burst write and didn't check for error
> conditions until the very last byte write. I seem to remember that
> there was some text in the original standard to that effect (this may
> have gone back as far as IBM's ESS spec).
> 
> The current code does check for error conditions after each write
> byte(s) so I don't think there is any reason for this anymore.
> Changing the while condition to count < len and setting burstcnt =
> min_t(int, burstcnt, len - count) and remove the
> tpm_tis_write8/wait_for_tpm_stat/tpm_tis_status clauses after the
> while loop should be sufficient.

Thank you for sharing this!

> 	Leendert

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 63+ messages in thread

* Re: [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance
@ 2017-11-28 20:19                   ` Jarkko Sakkinen
  0 siblings, 0 replies; 63+ messages in thread
From: Jarkko Sakkinen @ 2017-11-28 20:19 UTC (permalink / raw)
  To: Leendert van Doorn
  Cc: Mimi Zohar, Nayna Jain, Alexander.Steffen, linux-integrity,
	linux-security-module, linux-kernel, peterhuewe, tpmdd, patrickc,
	Safford, David (GE Global Research, US)

On Mon, Nov 27, 2017 at 07:08:51AM +0000, Leendert van Doorn wrote:
> Hmm, this is almost 20 years old code (
> 
> I think the original code did a burst write and didn't check for error
> conditions until the very last byte write. I seem to remember that
> there was some text in the original standard to that effect (this may
> have gone back as far as IBM's ESS spec).
> 
> The current code does check for error conditions after each write
> byte(s) so I don't think there is any reason for this anymore.
> Changing the while condition to count < len and setting burstcnt =
> min_t(int, burstcnt, len - count) and remove the
> tpm_tis_write8/wait_for_tpm_stat/tpm_tis_status clauses after the
> while loop should be sufficient.

Thank you for sharing this!

> 	Leendert

/Jarkko

^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2017-11-28 20:19 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-17 20:32 [PATCH v4 0/4] additional TPM performance improvements Nayna Jain
2017-10-17 20:32 ` Nayna Jain
2017-10-17 20:32 ` [PATCH v4 1/4] tpm: move wait_for_tpm_stat() to respective driver files Nayna Jain
2017-10-17 20:32   ` Nayna Jain
2017-10-19 14:21   ` Jarkko Sakkinen
2017-10-19 14:21     ` Jarkko Sakkinen
2017-10-19 17:00     ` Alexander.Steffen
2017-10-19 17:00       ` Alexander.Steffen at infineon.com
2017-10-20  8:56       ` Jarkko Sakkinen
2017-10-20  8:56         ` Jarkko Sakkinen
2017-10-23 13:32         ` Nayna Jain
2017-10-23 13:32           ` Nayna Jain
2017-10-23 13:32           ` Nayna Jain
2017-10-24 13:45           ` Jarkko Sakkinen
2017-10-24 13:45             ` Jarkko Sakkinen
2017-10-17 20:32 ` [PATCH v4 2/4] tpm: ignore burstcount to improve tpm_tis send() performance Nayna Jain
2017-10-17 20:32   ` Nayna Jain
2017-10-18 15:25   ` Jarkko Sakkinen
2017-10-18 15:25     ` Jarkko Sakkinen
2017-10-19 14:23   ` Jarkko Sakkinen
2017-10-19 14:23     ` Jarkko Sakkinen
2017-10-20 14:42   ` Alexander.Steffen
2017-10-20 14:42     ` Alexander.Steffen at infineon.com
2017-10-20 18:02     ` Ken Goldman
2017-10-20 18:02       ` Ken Goldman
2017-10-23  2:57     ` Jarkko Sakkinen
2017-10-23  2:57       ` Jarkko Sakkinen
2017-11-07 18:29     ` Nayna Jain
2017-11-07 18:29       ` Nayna Jain
2017-11-07 18:29       ` Nayna Jain
2017-11-08 11:32       ` Alexander.Steffen
2017-11-08 11:32         ` Alexander.Steffen at infineon.com
2017-11-16 14:34       ` Alexander.Steffen
2017-11-16 14:34         ` Alexander.Steffen at infineon.com
2017-11-22  6:52       ` Alexander.Steffen
2017-11-22  6:52         ` Alexander.Steffen at infineon.com
2017-11-23 14:47         ` Nayna Jain
2017-11-23 14:47           ` Nayna Jain
2017-11-23 16:19           ` Alexander.Steffen
2017-11-23 16:19             ` Alexander.Steffen at infineon.com
2017-11-26 15:22           ` Jarkko Sakkinen
2017-11-26 15:22             ` Jarkko Sakkinen
2017-11-26 16:37             ` Mimi Zohar
2017-11-26 16:37               ` Mimi Zohar
2017-11-27  7:08               ` Leendert van Doorn
2017-11-27  7:08                 ` Leendert van Doorn
2017-11-27  7:08                 ` Leendert van Doorn
2017-11-27 13:22                 ` Mimi Zohar
2017-11-27 13:22                   ` Mimi Zohar
2017-11-27 13:22                   ` Mimi Zohar
2017-11-28 20:19                 ` Jarkko Sakkinen
2017-11-28 20:19                   ` Jarkko Sakkinen
2017-11-28 20:19                   ` Jarkko Sakkinen
2017-10-17 20:32 ` [PATCH v4 3/4] tpm: reduce tpm polling delay in tpm_tis_core Nayna Jain
2017-10-17 20:32   ` Nayna Jain
2017-10-18 15:24   ` Jarkko Sakkinen
2017-10-18 15:24     ` Jarkko Sakkinen
2017-10-19 14:22     ` Jarkko Sakkinen
2017-10-19 14:22       ` Jarkko Sakkinen
2017-10-17 20:32 ` [PATCH v4 4/4] tpm: use tpm_msleep() value as max delay Nayna Jain
2017-10-17 20:32   ` Nayna Jain
2017-10-19 14:22   ` Jarkko Sakkinen
2017-10-19 14:22     ` Jarkko Sakkinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.