Skip to contentSkip to conversation

tpm: Add major_version sysfs file

PATCH Superseded Jerry Snitselaar 4 participants 10 messages Oct 25, 2019 – Oct 29, 2019

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm: Add major_version 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 version of a tpm device.

Cc Jarkko Sakkinen <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>
---
 drivers/char/tpm/tpm-sysfs.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)
drivers/char/tpm/tpm-sysfs.c +27 -7
index edfa89160010..9372c2d6f0b3 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 major_version_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.0" : "1.2");
+}
+static DEVICE_ATTR_RO(major_version);
+
+static struct attribute *tpm12_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_major_version.attr,
 	NULL,
 };
 
-static const struct attribute_group tpm_dev_group = {
-	.attrs = tpm_dev_attrs,
+static struct attribute *tpm20_dev_attrs[] = {
+	&dev_attr_major_version.attr,
+	NULL
+};
+
+static const struct attribute_group tpm12_dev_group = {
+	.attrs = tpm12_dev_attrs,
+};
+
+static const struct attribute_group tpm20_dev_group = {
+	.attrs = tpm20_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++] = &tpm20_dev_group;
+	else
+		chip->groups[chip->groups_cnt++] = &tpm12_dev_group;
 }
Signature · 1 line
2.23.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 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 version of a tpm device.

Use "TCG" uppercase consistently.

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

thanks!

FYI, on my system(s) the new file is accessible as /sys/class/tpm/tpm0/version_major.  Does this need to be documented anywhere?

Quoted 62 lines
---
 drivers/char/tpm/tpm-sysfs.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)
drivers/char/tpm/tpm-sysfs.c +27 -7
index edfa89160010..9372c2d6f0b3 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 major_version_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.0" : "1.2");
+}
+static DEVICE_ATTR_RO(major_version);
+
+static struct attribute *tpm12_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_major_version.attr,
 	NULL,
 };
 
-static const struct attribute_group tpm_dev_group = {
-	.attrs = tpm_dev_attrs,
+static struct attribute *tpm20_dev_attrs[] = {
+	&dev_attr_major_version.attr,
+	NULL
+};
+
+static const struct attribute_group tpm12_dev_group = {
+	.attrs = tpm12_dev_attrs,
+};
+
+static const struct attribute_group tpm20_dev_group = {
+	.attrs = tpm20_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++] = &tpm20_dev_group;
+	else
+		chip->groups[chip->groups_cnt++] = &tpm12_dev_group;
 }
#2 lore raw
Quoted 14 lines · Mimi Zohar
Quoted 3 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 version of a tpm device.

Use "TCG" uppercase consistently.

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

thanks!

FYI, on my system(s) the new file is accessible as /sys/class/tpm/tpm0/version_major.  Does this need to be documented anywhere?

Yes, there should be an entry added to Documentation/ABI/stable/sysfs-class-tpm.
I will fix that up and the TCG not being uppercase in a v2.

Should Documentation/ABI/stable/sysfs-class-tpm updated in some way to reflect that those are all links under device now and not actually there.

Quoted 63 lines
Quoted 62 lines
---
 drivers/char/tpm/tpm-sysfs.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)
drivers/char/tpm/tpm-sysfs.c +27 -7
index edfa89160010..9372c2d6f0b3 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 major_version_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.0" : "1.2");
+}
+static DEVICE_ATTR_RO(major_version);
+
+static struct attribute *tpm12_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_major_version.attr,
 	NULL,
 };
 
-static const struct attribute_group tpm_dev_group = {
-	.attrs = tpm_dev_attrs,
+static struct attribute *tpm20_dev_attrs[] = {
+	&dev_attr_major_version.attr,
+	NULL
+};
+
+static const struct attribute_group tpm12_dev_group = {
+	.attrs = tpm12_dev_attrs,
+};
+
+static const struct attribute_group tpm20_dev_group = {
+	.attrs = tpm20_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++] = &tpm20_dev_group;
+	else
+		chip->groups[chip->groups_cnt++] = &tpm12_dev_group;
 }
maintainer
#3 lore raw
Quoted 7 lines · Jerry Snitselaar
Quoted 6 lines · Mimi Zohar
Quoted 3 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 version of a tpm device.

Use "TCG" uppercase consistently.

And "TPM"

Quoted 18 lines
Quoted 8 lines

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

thanks!

FYI, on my system(s) the new file is accessible as /sys/class/tpm/tpm0/version_major.  Does this need to be documented anywhere?

Quoted 7 lines

Yes, there should be an entry added to Documentation/ABI/stable/sysfs-class-tpm.
I will fix that up and the TCG not being uppercase in a v2.

Should Documentation/ABI/stable/sysfs-class-tpm updated in some way to reflect that those are all links under device now and not actually there.

The importance is that there is a common file that can be used by userspace applications, instead of having to search for it, not that it is a link per-se.

Mimi

#4 lore raw
In reply to Jerry Snitselaar
Quoted 25 lines · Jerry Snitselaar
Quoted 14 lines · Mimi Zohar
Quoted 3 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 version of a tpm device.

Use "TCG" uppercase consistently.

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

thanks!

FYI, on my system(s) the new file is accessible as /sys/class/tpm/tpm0/version_major.  Does this need to be documented anywhere?

Quoted 7 lines

Yes, there should be an entry added to Documentation/ABI/stable/sysfs-class-tpm.
I will fix that up and the TCG not being uppercase in a v2.

Should Documentation/ABI/stable/sysfs-class-tpm updated in some way to reflect that those are all links under device now and not actually there.

Applications should not use the link version, that path was a mistake. The link is for compatability with old userspace.

Jason

maintainer
#5 lore raw
Quoted 6 lines · Jason Gunthorpe
Quoted 5 lines · Jerry Snitselaar

On Fri Oct 25 19, Mimi Zohar wrote:
Yes, there should be an entry added to Documentation/ABI/stable/sysfs-class-tpm.
I will fix that up and the TCG not being uppercase in a v2.

Quoted 6 lines
Quoted 3 lines

Should Documentation/ABI/stable/sysfs-class-tpm updated in some way to reflect that those are all links under device now and not actually there.

Applications should not use the link version, that path was a mistake. The link is for compatability with old userspace.

Are you suggesting that userspace has to search for the device info? That makes no sense.

Mimi

#6 lore raw
Quoted 11 lines · Mimi Zohar
Quoted 10 lines · Jason Gunthorpe
Quoted 8 lines · Jerry Snitselaar

On Fri Oct 25 19, Mimi Zohar wrote:
Yes, there should be an entry added to Documentation/ABI/stable/sysfs-class-tpm.
I will fix that up and the TCG not being uppercase in a v2.

Should Documentation/ABI/stable/sysfs-class-tpm updated in some way to reflect that those are all links under device now and not actually there.

Quoted 5 lines
Quoted 2 lines

Applications should not use the link version, that path was a mistake. The link is for compatability with old userspace.

Are you suggesting that userspace has to search for the device info? That makes no sense.

Why would it have to search?

Jason

#7 lore raw
In reply to Jerry Snitselaar
Quoted 9 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 version of a tpm device.

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

Please use version_major (e.g. if there is ever version_minor they order nicely alphabetically).

/Jarkko

#8 lore raw
Quoted 5 lines · Jarkko Sakkinen
Quoted 4 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 version of a tpm device.

Quoted 8 lines
Quoted 5 lines
Cc Jarkko Sakkinen <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>

Please use version_major (e.g. if there is ever version_minor they order nicely alphabetically).

That is not the convention in sysfs

Jason

#9 lore raw
Quoted 12 lines · Jason Gunthorpe
Quoted 11 lines · Jarkko Sakkinen
Quoted 9 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 version of a tpm device.

Cc Jarkko Sakkinen <[email protected]>
Cc Peter Huewe <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Quoted 4 lines
Quoted 2 lines

Please use version_major (e.g. if there is ever version_minor they order nicely alphabetically).

That is not the convention in sysfs

What is wrong with that name?

/Jarkko