Skip to contentSkip to conversation

tpm: separate cmd_ready/go_idle from runtime_pm

PATCH Superseded Tomas Winkler 2 participants 2 messages Mar 24, 2018 – Mar 26, 2018

Subsystems (3)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 tpm: separate cmd_ready/go_idle from runtime_pm

From: "Winkler, Tomas" <[email protected]>

We cannot use go_idle cmd_ready commands via runtime_pm handles as with the introduction of localities this is no longer an optional feature, while runtime pm can be not enabled.
Though cmd_ready/go_idle provides power saving feature, it's also part of TPM2 protocol and should be called explicitly.
This patch exposes cmd_read/go_idle via tpm class ops and removes runtime pm support as it is not used by any driver.

tpm_crb no longer needs own power saving functions and can drop using tpm_pm_suspend/resume.

---
V2-3:resent
V4: 1. Use tpm_pm_suspend/resume in tpm_crb
2. Drop cmd_ready/go_idle around tpm_chip_register, as there is no usage counter like in runtime_pm.

 drivers/char/tpm/tpm-interface.c |  15 ++++--
 drivers/char/tpm/tpm_crb.c       | 100 ++++++++++-----------------------------
 include/linux/tpm.h              |   2 +
 3 files changed, 38 insertions(+), 79 deletions(-)
drivers/char/tpm/tpm-interface.c +10 -5
index c43a9e28995e..1dc4961c42c6 100644
@@ -29,7 +29,6 @@
 #include <linux/mutex.h>
 #include <linux/spinlock.h>
 #include <linux/freezer.h>
-#include <linux/pm_runtime.h>
 #include <linux/tpm_eventlog.h>
 
 #include "tpm.h"
@@ -455,8 +454,11 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,
 			goto out_no_locality;
 	}
 
-	if (chip->dev.parent)
-		pm_runtime_get_sync(chip->dev.parent);
+	if (chip->ops->cmd_ready) {
+		rc = chip->ops->cmd_ready(chip);
+		if (rc)
+			goto out;
+	}
 
 	rc = tpm2_prepare_space(chip, space, ordinal, buf);
 	if (rc)
@@ -518,8 +520,11 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,
 	rc = tpm2_commit_space(chip, space, ordinal, buf, &len);
 
 out:
-	if (chip->dev.parent)
-		pm_runtime_put_sync(chip->dev.parent);
+	if (chip->ops->go_idle) {
+		rc = chip->ops->go_idle(chip);
+		if (rc)
+			goto out;
+	}
 
 	if (need_locality)
 		tpm_relinquish_locality(chip);
drivers/char/tpm/tpm_crb.c +26 -74

165 lines not on this page · raw message

include/linux/tpm.h +2 -0
index 06639fb6ab85..8eb5e5ebe136 100644
@@ -43,6 +43,8 @@ struct tpm_class_ops {
 	u8 (*status) (struct tpm_chip *chip);
 	bool (*update_timeouts)(struct tpm_chip *chip,
 				unsigned long *timeout_cap);
+	int (*go_idle)(struct tpm_chip *chip);
+	int (*cmd_ready)(struct tpm_chip *chip);
 	int (*request_locality)(struct tpm_chip *chip, int loc);
 	int (*relinquish_locality)(struct tpm_chip *chip, int loc);
 	void (*clk_enable)(struct tpm_chip *chip, bool value);
Signature · 6 lines
2.14.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
#1 lore raw
Quoted 10 lines · Tomas Winkler

From: "Winkler, Tomas" <[email protected]>

We cannot use go_idle cmd_ready commands via runtime_pm handles as with the introduction of localities this is no longer an optional feature, while runtime pm can be not enabled.
Though cmd_ready/go_idle provides power saving feature, it's also part of TPM2 protocol and should be called explicitly.
This patch exposes cmd_read/go_idle via tpm class ops and removes runtime pm support as it is not used by any driver.

Quoted 4 lines

tpm_crb no longer needs own power saving functions and can drop using tpm_pm_suspend/resume.

Still fails on Kabylake exactly the same way. With this I get RC_UNBALANCED in these four test cases:

test_flush_context (tpm2_smoke.SpaceTest) ... ERROR test_get_handles (tpm2_smoke.SpaceTest) ... ERROR test_make_two_spaces (tpm2_smoke.SpaceTest) ... ERROR

Without this patch applied these errors do not occur.

/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