Skip to contentSkip to conversation

tpm: Add major_version sysfs file

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

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

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

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

---
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..c6bd02bafafd 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/major_version
+Date:		October 2019
+KernelVersion:	5.5
+Contact:	[email protected]
+Description:	The "major_version" property shows the TCG spec version
+		implemented by the TPM device.
+
+		Example output:
+
+		2.0
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
#1 lore raw

drivers/char/tpm/tpm-sysfs.c static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr, · line 318

Quoted 2 lines · Jerry Snitselaar
drivers/char/tpm/tpm-sysfs.c +2 -0
+	return sprintf(buf, "%s\n", chip->flags & TPM_CHIP_FLAG_TPM2
+		       ? "2.0" : "1.2");

This is not right. Should be either "1" or "2".

/Jarkko

#2 lore raw
Quoted 7 lines · Jarkko Sakkinen

drivers/char/tpm/tpm-sysfs.c static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr, · line 318

Quoted 2 lines · Jerry Snitselaar
drivers/char/tpm/tpm-sysfs.c +2 -0
+	return sprintf(buf, "%s\n", chip->flags & TPM_CHIP_FLAG_TPM2
+		       ? "2.0" : "1.2");

This is not right. Should be either "1" or "2".

/Jarkko

Okay I will fix that up. Do we have a final decision on the file name, major_version versus version_major?

#3 lore raw
Quoted 11 lines · Jerry Snitselaar
Quoted 7 lines · Jarkko Sakkinen

drivers/char/tpm/tpm-sysfs.c static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr, · line 318

Quoted 2 lines · Jerry Snitselaar
drivers/char/tpm/tpm-sysfs.c +2 -0
+	return sprintf(buf, "%s\n", chip->flags & TPM_CHIP_FLAG_TPM2
+		       ? "2.0" : "1.2");

This is not right. Should be either "1" or "2".

/Jarkko

Okay I will fix that up. Do we have a final decision on the file name, major_version versus version_major?

Well, I don't see how major_version would make any sense. It is not as future proof as version_major. Still waiting for Jason's feedback for this.

/Jarkko

#4 lore raw
Quoted 8 lines · Jarkko Sakkinen
Quoted 7 lines · Jerry Snitselaar
Quoted 6 lines · Jarkko Sakkinen

drivers/char/tpm/tpm-sysfs.c static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr, · line 318

Quoted 2 lines · Jerry Snitselaar
drivers/char/tpm/tpm-sysfs.c +2 -0
+	return sprintf(buf, "%s\n", chip->flags & TPM_CHIP_FLAG_TPM2
+		       ? "2.0" : "1.2");

This is not right. Should be either "1" or "2".

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/Jarkko

Okay I will fix that up. Do we have a final decision on the file name, major_version versus version_major?

Well, I don't see how major_version would make any sense. It is not as future proof as version_major. Still waiting for Jason's feedback for this.

$ find /sys/ -name  "*version*"
/sys/devices/pci0000:00/0000:00:17.0/ata1/host0/scsi_host/host0/ahci_host_version
/sys/devices/virtual/net/docker0/bridge/multicast_mld_version
/sys/devices/virtual/net/docker0/bridge/multicast_igmp_version
/sys/firmware/efi/esrt/entries/entry0/lowest_supported_fw_version
/sys/firmware/efi/esrt/entries/entry0/last_attempt_version
/sys/firmware/efi/esrt/entries/entry0/fw_version
/sys/module/acpi/parameters/acpica_version

etc..

Not a single example of the backward version.

Most likely it should be called 'tpm_version'

Jason

#5 lore raw
Quoted 27 lines · Jason Gunthorpe
Quoted 8 lines · Jarkko Sakkinen
Quoted 7 lines · Jerry Snitselaar
Quoted 6 lines · Jarkko Sakkinen

drivers/char/tpm/tpm-sysfs.c static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr, · line 318

Quoted 2 lines · Jerry Snitselaar
drivers/char/tpm/tpm-sysfs.c +2 -0
+	return sprintf(buf, "%s\n", chip->flags & TPM_CHIP_FLAG_TPM2
+		       ? "2.0" : "1.2");

This is not right. Should be either "1" or "2".

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/Jarkko

Okay I will fix that up. Do we have a final decision on the file name, major_version versus version_major?

Well, I don't see how major_version would make any sense. It is not as future proof as version_major. Still waiting for Jason's feedback for this.

$ find /sys/ -name  "*version*"
/sys/devices/pci0000:00/0000:00:17.0/ata1/host0/scsi_host/host0/ahci_host_version
/sys/devices/virtual/net/docker0/bridge/multicast_mld_version
/sys/devices/virtual/net/docker0/bridge/multicast_igmp_version
/sys/firmware/efi/esrt/entries/entry0/lowest_supported_fw_version
/sys/firmware/efi/esrt/entries/entry0/last_attempt_version
/sys/firmware/efi/esrt/entries/entry0/fw_version
/sys/module/acpi/parameters/acpica_version
Quoted 5 lines

etc..

Not a single example of the backward version.

Most likely it should be called 'tpm_version'

The postfix gives tells the part of the version number that the file reports. If you really want to add the prefix, then the appropriate name would be tpm_version_major.

I'd still go with just version_major as tpm_ prefix is somewhat redundant.

/Jarkko

maintainer
#6 lore raw
Quoted 36 lines · Jarkko Sakkinen
Quoted 35 lines · Jason Gunthorpe
Quoted 12 lines · Jarkko Sakkinen
Quoted 11 lines · Jerry Snitselaar
Quoted 9 lines · Jarkko Sakkinen

drivers/char/tpm/tpm-sysfs.c static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr, · line 318

Quoted 3 lines · Jerry Snitselaar
(quoted diff) +1 -0
+	return sprintf(buf, "%s\n", chip->flags &

TPM_CHIP_FLAG_TPM2

drivers/char/tpm/tpm-sysfs.c +1 -0
+		       ? "2.0" : "1.2");

This is not right. Should be either "1" or "2".

/Jarkko

Quoted 7 lines
Quoted 3 lines

Okay I will fix that up. Do we have a final decision on the file name,
major_version versus version_major?

Well, I don't see how major_version would make any sense. It is not as future proof as version_major. Still waiting for Jason's feedback for this.

$ find /sys/ -name  "*version*"
/sys/devices/pci0000:00/0000:00:17.0/ata1/host0/scsi_host/host0/ahc
i_host_version
/sys/devices/virtual/net/docker0/bridge/multicast_mld_version
/sys/devices/virtual/net/docker0/bridge/multicast_igmp_version
/sys/firmware/efi/esrt/entries/entry0/lowest_supported_fw_version
/sys/firmware/efi/esrt/entries/entry0/last_attempt_version
/sys/firmware/efi/esrt/entries/entry0/fw_version
/sys/module/acpi/parameters/acpica_version

etc..

Not a single example of the backward version.

Quoted 8 lines
Quoted 1 line

Most likely it should be called 'tpm_version'

The postfix gives tells the part of the version number that the file reports. If you really want to add the prefix, then the appropriate name would be tpm_version_major.

I'd still go with just version_major as tpm_ prefix is somewhat redundant.

You have to be careful with overly generic names in sysfs ... this is what happened to us in SCSI:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=42caa0edabd6a0a392ec36a5f0943924e4954311

That's not to say version_major is wrong ... plenty of sysfs files have generic names like this, it's just that tpm_version_major might be more future proof.

James

#7 lore raw
Quoted 46 lines · James Bottomley
Quoted 36 lines · Jarkko Sakkinen
Quoted 35 lines · Jason Gunthorpe
Quoted 12 lines · Jarkko Sakkinen
Quoted 11 lines · Jerry Snitselaar
Quoted 9 lines · Jarkko Sakkinen

Review

Quoted 3 lines · Jerry Snitselaar
(quoted diff) +1 -0
+	return sprintf(buf, "%s\n", chip->flags &

TPM_CHIP_FLAG_TPM2

(quoted diff) +1 -0
+		       ? "2.0" : "1.2");

This is not right. Should be either "1" or "2".

/Jarkko

Quoted 7 lines
Quoted 3 lines

Okay I will fix that up. Do we have a final decision on the file name,
major_version versus version_major?

Well, I don't see how major_version would make any sense. It is not as future proof as version_major. Still waiting for Jason's feedback for this.

$ find /sys/ -name  "*version*"
/sys/devices/pci0000:00/0000:00:17.0/ata1/host0/scsi_host/host0/ahc
i_host_version
/sys/devices/virtual/net/docker0/bridge/multicast_mld_version
/sys/devices/virtual/net/docker0/bridge/multicast_igmp_version
/sys/firmware/efi/esrt/entries/entry0/lowest_supported_fw_version
/sys/firmware/efi/esrt/entries/entry0/last_attempt_version
/sys/firmware/efi/esrt/entries/entry0/fw_version
/sys/module/acpi/parameters/acpica_version

etc..

Not a single example of the backward version.

Quoted 8 lines
Quoted 1 line

Most likely it should be called 'tpm_version'

The postfix gives tells the part of the version number that the file reports. If you really want to add the prefix, then the appropriate name would be tpm_version_major.

I'd still go with just version_major as tpm_ prefix is somewhat redundant.

Quoted 8 lines

You have to be careful with overly generic names in sysfs ... this is what happened to us in SCSI:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=42caa0edabd6a0a392ec36a5f0943924e4954311

That's not to say version_major is wrong ... plenty of sysfs files have generic names like this, it's just that tpm_version_major might be more future proof.

Indeed, it is a bit a global namespace, so nothing wrong with adding tpm_

Jason

#8 lore raw
Quoted 52 lines · Jason Gunthorpe
Quoted 51 lines · James Bottomley
Quoted 36 lines · Jarkko Sakkinen
Quoted 35 lines · Jason Gunthorpe
Quoted 12 lines · Jarkko Sakkinen
Quoted 11 lines · Jerry Snitselaar
Quoted 9 lines · Jarkko Sakkinen

Review

Quoted 3 lines · Jerry Snitselaar
(quoted diff) +1 -0
+	return sprintf(buf, "%s\n", chip->flags &

TPM_CHIP_FLAG_TPM2

(quoted diff) +1 -0
+		       ? "2.0" : "1.2");

This is not right. Should be either "1" or "2".

/Jarkko

Quoted 7 lines
Quoted 3 lines

Okay I will fix that up. Do we have a final decision on the file name,
major_version versus version_major?

Well, I don't see how major_version would make any sense. It is not as future proof as version_major. Still waiting for Jason's feedback for this.

$ find /sys/ -name  "*version*"
/sys/devices/pci0000:00/0000:00:17.0/ata1/host0/scsi_host/host0/ahc
i_host_version
/sys/devices/virtual/net/docker0/bridge/multicast_mld_version
/sys/devices/virtual/net/docker0/bridge/multicast_igmp_version
/sys/firmware/efi/esrt/entries/entry0/lowest_supported_fw_version
/sys/firmware/efi/esrt/entries/entry0/last_attempt_version
/sys/firmware/efi/esrt/entries/entry0/fw_version
/sys/module/acpi/parameters/acpica_version

etc..

Not a single example of the backward version.

Quoted 8 lines
Quoted 1 line

Most likely it should be called 'tpm_version'

The postfix gives tells the part of the version number that the file reports. If you really want to add the prefix, then the appropriate name would be tpm_version_major.

I'd still go with just version_major as tpm_ prefix is somewhat redundant.

You have to be careful with overly generic names in sysfs ... this is what happened to us in SCSI:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=42caa0edabd6a0a392ec36a5f0943924e4954311

Quoted 8 lines
Quoted 3 lines

That's not to say version_major is wrong ... plenty of sysfs files have generic names like this, it's just that tpm_version_major might be more future proof.

Indeed, it is a bit a global namespace, so nothing wrong with adding tpm_

Jason

So tpm_version_major?

#9 lore raw
In reply to James Bottomley
Quoted 46 lines · James Bottomley
Quoted 36 lines · Jarkko Sakkinen
Quoted 35 lines · Jason Gunthorpe
Quoted 12 lines · Jarkko Sakkinen
Quoted 11 lines · Jerry Snitselaar
Quoted 9 lines · Jarkko Sakkinen

Review

Quoted 3 lines · Jerry Snitselaar
(quoted diff) +1 -0
+	return sprintf(buf, "%s\n", chip->flags &

TPM_CHIP_FLAG_TPM2

(quoted diff) +1 -0
+		       ? "2.0" : "1.2");

This is not right. Should be either "1" or "2".

/Jarkko

Quoted 7 lines
Quoted 3 lines

Okay I will fix that up. Do we have a final decision on the file name,
major_version versus version_major?

Well, I don't see how major_version would make any sense. It is not as future proof as version_major. Still waiting for Jason's feedback for this.

$ find /sys/ -name  "*version*"
/sys/devices/pci0000:00/0000:00:17.0/ata1/host0/scsi_host/host0/ahc
i_host_version
/sys/devices/virtual/net/docker0/bridge/multicast_mld_version
/sys/devices/virtual/net/docker0/bridge/multicast_igmp_version
/sys/firmware/efi/esrt/entries/entry0/lowest_supported_fw_version
/sys/firmware/efi/esrt/entries/entry0/last_attempt_version
/sys/firmware/efi/esrt/entries/entry0/fw_version
/sys/module/acpi/parameters/acpica_version

etc..

Not a single example of the backward version.

Quoted 8 lines
Quoted 1 line

Most likely it should be called 'tpm_version'

The postfix gives tells the part of the version number that the file reports. If you really want to add the prefix, then the appropriate name would be tpm_version_major.

I'd still go with just version_major as tpm_ prefix is somewhat redundant.

Quoted 8 lines

You have to be careful with overly generic names in sysfs ... this is what happened to us in SCSI:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=42caa0edabd6a0a392ec36a5f0943924e4954311

That's not to say version_major is wrong ... plenty of sysfs files have generic names like this, it's just that tpm_version_major might be more future proof.

I'm cool with that name as long as the postfix also stays.

/Jarkko