Skip to contentSkip to conversation

tpm: Add tpm_version_major sysfs file

PATCH In review Jerry Snitselaar 3 participants 7 messages Oct 30, 2019 – Jan 13, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 tpm: Add tpm_version_major sysfs file

Easily determining what TCG version a tpm device implements has been a pain point for userspace for a long time, so add a sysfs file to report the TCG major version of a tpm device.

Also add an entry to Documentation/ABI/stable/sysfs-class-tpm describing the new file.

Cc Jarkko Sakkinen <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>

---
v4: - Change file name to tpm_version_major
- Actually display just the major version.
- change structs to tpm1_* & tpm2_*
instead of tpm12_* tpm20_*.
v3: - Change file name to version_major.
v2: - Fix TCG usage in commit message.
- Add entry to sysfs-class-tpm in Documentation/ABI/stable

 Documentation/ABI/stable/sysfs-class-tpm | 11 ++++++++
 drivers/char/tpm/tpm-sysfs.c             | 34 +++++++++++++++++++-----
 2 files changed, 38 insertions(+), 7 deletions(-)
Documentation/ABI/stable/sysfs-class-tpm +11 -0
index c0e23830f56a..5468fedc493c 100644
@@ -183,3 +183,14 @@ Description:	The "timeouts" property shows the 4 vendor-specific values
 		The four timeout values are shown in usecs, with a trailing
 		"[original]" or "[adjusted]" depending on whether the values
 		were scaled by the driver to be reported in usec from msecs.
+
+What:		/sys/class/tpm/tpmX/tpm_version_major
+Date:		October 2019
+KernelVersion:	5.5
+Contact:	[email protected]
+Description:	The "tpm_version_major" property shows the TCG spec major version
+		implemented by the TPM device.
+
+		Example output:
+
+		2
drivers/char/tpm/tpm-sysfs.c +27 -7
index edfa89160010..12da71e72488 100644
@@ -309,7 +309,17 @@ static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(timeouts);
 
-static struct attribute *tpm_dev_attrs[] = {
+static ssize_t tpm_version_major_show(struct device *dev,
+				  struct device_attribute *attr, char *buf)
+{
+	struct tpm_chip *chip = to_tpm_chip(dev);
+
+	return sprintf(buf, "%s\n", chip->flags & TPM_CHIP_FLAG_TPM2
+		       ? "2" : "1");
+}
+static DEVICE_ATTR_RO(tpm_version_major);
+
+static struct attribute *tpm1_dev_attrs[] = {
 	&dev_attr_pubek.attr,
 	&dev_attr_pcrs.attr,
 	&dev_attr_enabled.attr,
@@ -320,18 +330,28 @@ static struct attribute *tpm_dev_attrs[] = {
 	&dev_attr_cancel.attr,
 	&dev_attr_durations.attr,
 	&dev_attr_timeouts.attr,
+	&dev_attr_tpm_version_major.attr,
 	NULL,
 };
 
-static const struct attribute_group tpm_dev_group = {
-	.attrs = tpm_dev_attrs,
+static struct attribute *tpm2_dev_attrs[] = {
+	&dev_attr_tpm_version_major.attr,
+	NULL
+};
+
+static const struct attribute_group tpm1_dev_group = {
+	.attrs = tpm1_dev_attrs,
+};
+
+static const struct attribute_group tpm2_dev_group = {
+	.attrs = tpm2_dev_attrs,
 };
 
 void tpm_sysfs_add_device(struct tpm_chip *chip)
 {
-	if (chip->flags & TPM_CHIP_FLAG_TPM2)
-		return;
-
 	WARN_ON(chip->groups_cnt != 0);
-	chip->groups[chip->groups_cnt++] = &tpm_dev_group;
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		chip->groups[chip->groups_cnt++] = &tpm2_dev_group;
+	else
+		chip->groups[chip->groups_cnt++] = &tpm1_dev_group;
 }
Signature · 1 line
2.23.0
maintainer Reviewed-by on v4 1/1
#1 lore raw
Quoted 7 lines · Jerry Snitselaar

Easily determining what TCG version a tpm device implements has been a pain point for userspace for a long time, so add a sysfs file to report the TCG major version of a tpm device.

Also add an entry to Documentation/ABI/stable/sysfs-class-tpm describing the new file.

Quoted 6 lines
Cc Jarkko Sakkinen <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>

Thanks!

Reviewed-by on v4 1/1
#2 lore raw
In reply to Jerry Snitselaar
Quoted 7 lines · Jerry Snitselaar

Easily determining what TCG version a tpm device implements has been a pain point for userspace for a long time, so add a sysfs file to report the TCG major version of a tpm device.

Also add an entry to Documentation/ABI/stable/sysfs-class-tpm describing the new file.

Quoted 6 lines
Cc Jarkko Sakkinen <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>

/Jarkko

#3 lore raw
In reply to Jerry Snitselaar
Quoted 17 lines · Jerry Snitselaar

Easily determining what TCG version a tpm device implements has been a pain point for userspace for a long time, so add a sysfs file to report the TCG major version of a tpm device.

Also add an entry to Documentation/ABI/stable/sysfs-class-tpm describing the new file.

Cc Jarkko Sakkinen <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>

---
v4: - Change file name to tpm_version_major
- Actually display just the major version.
- change structs to tpm1_* & tpm2_*

Quoted 9 lines
     instead of tpm12_* tpm20_*.

v3: - Change file name to version_major.
v2: - Fix TCG usage in commit message.
- Add entry to sysfs-class-tpm in Documentation/ABI/stable

Documentation/ABI/stable/sysfs-class-tpm | 11 ++++++++
drivers/char/tpm/tpm-sysfs.c | 34 +++++++++++++++++++-----

2 files changed, 38 insertions(+), 7 deletions(-)

Anyone else have feedback?

#4 lore raw
Quoted 23 lines · Jerry Snitselaar
Quoted 22 lines · Jerry Snitselaar

Easily determining what TCG version a tpm device implements has been a pain point for userspace for a long time, so add a sysfs file to report the TCG major version of a tpm device.

Also add an entry to Documentation/ABI/stable/sysfs-class-tpm describing the new file.

Cc Jarkko Sakkinen <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>

---
v4: - Change file name to tpm_version_major
- Actually display just the major version.
- change structs to tpm1_* & tpm2_*

     instead of tpm12_* tpm20_*.

v3: - Change file name to version_major.
v2: - Fix TCG usage in commit message.
- Add entry to sysfs-class-tpm in Documentation/ABI/stable

Quoted 6 lines
Quoted 4 lines

Documentation/ABI/stable/sysfs-class-tpm | 11 ++++++++
drivers/char/tpm/tpm-sysfs.c | 34 +++++++++++++++++++-----

2 files changed, 38 insertions(+), 7 deletions(-)

Anyone else have feedback?

I can apply this after the issues on hand have been sorted out.

/Jarkko

#5 lore raw
Quoted 29 lines · Jarkko Sakkinen
Quoted 28 lines · Jerry Snitselaar
Quoted 26 lines · Jerry Snitselaar

Easily determining what TCG version a tpm device implements has been a pain point for userspace for a long time, so add a sysfs file to report the TCG major version of a tpm device.

Also add an entry to Documentation/ABI/stable/sysfs-class-tpm describing the new file.

Cc Jarkko Sakkinen <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>

---
v4: - Change file name to tpm_version_major
- Actually display just the major version.
- change structs to tpm1_* & tpm2_*

     instead of tpm12_* tpm20_*.

v3: - Change file name to version_major.
v2: - Fix TCG usage in commit message.
- Add entry to sysfs-class-tpm in Documentation/ABI/stable

Documentation/ABI/stable/sysfs-class-tpm | 11 ++++++++
drivers/char/tpm/tpm-sysfs.c | 34 +++++++++++++++++++-----

2 files changed, 38 insertions(+), 7 deletions(-)
Quoted 6 lines
Quoted 1 line

Anyone else have feedback?

I can apply this after the issues on hand have been sorted out.

/Jarkko

Hi Jarkko,

Will this get queued up for 5.6?

Regards,
Jerry

#6 lore raw
Quoted 32 lines · Jerry Snitselaar
Quoted 31 lines · Jarkko Sakkinen
Quoted 29 lines · Jerry Snitselaar
Quoted 17 lines · Jerry Snitselaar

Easily determining what TCG version a tpm device implements has been a pain point for userspace for a long time, so add a sysfs file to report the TCG major version of a tpm device.

Also add an entry to Documentation/ABI/stable/sysfs-class-tpm describing the new file.

Cc Jarkko Sakkinen <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>

---
v4: - Change file name to tpm_version_major
- Actually display just the major version.
- change structs to tpm1_* & tpm2_*

Quoted 9 lines
     instead of tpm12_* tpm20_*.

v3: - Change file name to version_major.
v2: - Fix TCG usage in commit message.
- Add entry to sysfs-class-tpm in Documentation/ABI/stable

Documentation/ABI/stable/sysfs-class-tpm | 11 ++++++++
drivers/char/tpm/tpm-sysfs.c | 34 +++++++++++++++++++-----

2 files changed, 38 insertions(+), 7 deletions(-)

Anyone else have feedback?

Quoted 8 lines
Quoted 4 lines

I can apply this after the issues on hand have been sorted out.

/Jarkko

Hi Jarkko,

Will this get queued up for 5.6?

Thanks for reminding and apologies for forgetting this!

I'll see what I can do.

/Jarkko