tpmdd-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH] tpm: Add sysfs interface to show TPM hardware version
@ 2017-03-13  5:21 Meng.Li
       [not found] ` <1489382517-9078-1-git-send-email-Meng.Li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
  2017-03-13 11:48 ` Jarkko Sakkinen
  0 siblings, 2 replies; 10+ messages in thread
From: Meng.Li @ 2017-03-13  5:21 UTC (permalink / raw)
  To: linux-kernel; +Cc: peterhuewe, tpmdd, jarkko.sakkinen, jgunthorpe, tpmdd-devel

From: Limeng <Meng.Li@windriver.com>

So far, there is not a sysfs interface for user space code to
check the TPM hardware version(TPM1.x or TPM2). So, add a
file named description in /sys/class/tpm/tpmX/ to show it.

Signed-off-by: Meng Li <Meng.Li@windriver.com>
---
 drivers/char/tpm/tpm-chip.c |   85 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index c406343..da2cd69 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -36,6 +36,83 @@
 dev_t tpm_devt;
 
 /**
+ * show_description - sysfs interface for checking current TPM hardware version.
+ * @dev:	pointer to tpm chip device
+ * @attr:	unused
+ * @buf:	char buffer to be filled with TPM hardware version info
+ *
+ * Provides sysfs interface for showing current TPM hardware version.
+ */
+static ssize_t show_description(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct tpm_chip *chip = (struct tpm_chip *)container_of(dev,struct tpm_chip,dev);
+	int ret;
+
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		ret = sprintf(buf, "TPM 2.0");
+	else
+		ret = sprintf(buf, "TPM 1.x");
+
+	return ret;
+}
+
+/**
+ * store_description - interface for manually setting data.
+ * @dev:	unused
+ * @attr:	unused
+ * @buf:	unused
+ * @count:	unused
+ *
+ * There is not any process in this function, reserve for feature.
+ */
+static ssize_t store_description(struct device *dev, struct device_attribute *attr,
+		const char *buf, size_t count)
+{
+	return count;
+}
+
+static struct device_attribute tpm_attrs[] = {
+	__ATTR(description, S_IRUGO | S_IWUSR, show_description, store_description),
+};
+
+/**
+ * tpm_create_sysfs - Create tpm sysfs interface.
+ * @dev:	pointer to tpm chip device
+ *
+ * Create sysfs interface for checking current TPM hardware version.
+ */
+static int tpm_create_sysfs(struct device *dev)
+{
+	int r, t;
+
+	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
+		r = device_create_file(dev, &tpm_attrs[t]);
+		if (r) {
+			dev_err(dev, "failed to create sysfs file\n");
+			return r;
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * tpm_remove_sysfs - Remove tpm sysfs interface.
+ * @dev:	pointer to tpm chip device
+ *
+ * Remove sysfs interface for checking current TPM hardware version.
+ */
+static void tpm_remove_sysfs(struct device *dev)
+{
+	int  t;
+
+	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
+		device_remove_file(dev, &tpm_attrs[t]);
+	}
+}
+
+/**
  * tpm_try_get_ops() - Get a ref to the tpm_chip
  * @chip: Chip to ref
  *
@@ -363,6 +440,13 @@ int tpm_chip_register(struct tpm_chip *chip)
 		return rc;
 	}
 
+	rc = tpm_create_sysfs(&chip->dev);
+	if (rc) {
+		tpm_del_legacy_sysfs(chip);
+		tpm_chip_unregister(chip);
+		return rc;
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(tpm_chip_register);
@@ -382,6 +466,7 @@ int tpm_chip_register(struct tpm_chip *chip)
  */
 void tpm_chip_unregister(struct tpm_chip *chip)
 {
+	tpm_remove_sysfs(&chip->dev);
 	tpm_del_legacy_sysfs(chip);
 	tpm_bios_log_teardown(chip);
 	tpm_del_char_device(chip);
-- 
1.7.9.5

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

* Re: [PATCH] tpm: Add sysfs interface to show TPM hardware version
       [not found] ` <1489382517-9078-1-git-send-email-Meng.Li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
@ 2017-03-13  7:10   ` Peter Huewe
  2017-03-13  7:47     ` Li, Meng
  2017-03-14 18:18     ` [tpmdd-devel] " Ken Goldman
  0 siblings, 2 replies; 10+ messages in thread
From: Peter Huewe @ 2017-03-13  7:10 UTC (permalink / raw)
  To: Meng.Li-CWA4WttNNZF54TAoqtyWWQ, linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Hi,
Thanks for your patch.

Am 13. März 2017 06:21:57 MEZ schrieb Meng.Li@windriver.com:
>From: Limeng <Meng.Li@windriver.com>
>
>So far, there is not a sysfs interface for user space code to
>check the TPM hardware version(TPM1.x or TPM2). So, add a
>file named description in /sys/class/tpm/tpmX/ to show it.
It's not really the hardware version but the "TPM Family" according to tcg.

And yes you are right there is currently no way, except for trial and error, for the userspace to determine this.
So an interface to get this information makes sense to me.
>
>Signed-off-by: Meng Li <Meng.Li@windriver.com>
>---
>drivers/char/tpm/tpm-chip.c |   85
>+++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 85 insertions(+)
>
>diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
>index c406343..da2cd69 100644
>--- a/drivers/char/tpm/tpm-chip.c
>+++ b/drivers/char/tpm/tpm-chip.c
>@@ -36,6 +36,83 @@
> dev_t tpm_devt;
> 
> /**
>+ * show_description - sysfs interface for checking current TPM
>hardware version.
>+ * @dev:	pointer to tpm chip device
>+ * @attr:	unused
>+ * @buf:	char buffer to be filled with TPM hardware version info
>+ *
>+ * Provides sysfs interface for showing current TPM hardware version.
>+ */
>+static ssize_t show_description(struct device *dev,
>+		struct device_attribute *attr, char *buf)
>+{
>+	struct tpm_chip *chip = (struct tpm_chip *)container_of(dev,struct
>tpm_chip,dev);
>+	int ret;
>+
>+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
>+		ret = sprintf(buf, "TPM 2.0");
>+	else
>+		ret = sprintf(buf, "TPM 1.x");
>+
>+	return ret;
>+}
>+
>+/**
>+ * store_description - interface for manually setting data.
>+ * @dev:	unused
>+ * @attr:	unused
>+ * @buf:	unused
>+ * @count:	unused
>+ *
>+ * There is not any process in this function, reserve for feature.
>+ */
>+static ssize_t store_description(struct device *dev, struct
>device_attribute *attr,
>+		const char *buf, size_t count)
>+{
>+	return count;
>+}
Since it does not do anything
I would not create this function and leave the sysfs node as S_IRUGO.

>+
>+static struct device_attribute tpm_attrs[] = {
>+	__ATTR(description, S_IRUGO | S_IWUSR, show_description,
>store_description),
>+};
>+
>+/**
>+ * tpm_create_sysfs - Create tpm sysfs interface.
>+ * @dev:	pointer to tpm chip device
>+ *
>+ * Create sysfs interface for checking current TPM hardware version.
>+ */
>+static int tpm_create_sysfs(struct device *dev)
>+{
>+	int r, t;
>+
>+	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
>+		r = device_create_file(dev, &tpm_attrs[t]);
>+		if (r) {
>+			dev_err(dev, "failed to create sysfs file\n");
>+			return r;
>+		}
>+	}
>+
>+	return 0;
>+}
>+
>+/**
>+ * tpm_remove_sysfs - Remove tpm sysfs interface.
>+ * @dev:	pointer to tpm chip device
>+ *
>+ * Remove sysfs interface for checking current TPM hardware version.
>+ */
>+static void tpm_remove_sysfs(struct device *dev)
>+{
>+	int  t;
>+
>+	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
>+		device_remove_file(dev, &tpm_attrs[t]);
>+	}
>+}
>+
>+/**
>  * tpm_try_get_ops() - Get a ref to the tpm_chip
>  * @chip: Chip to ref
>  *
>@@ -363,6 +440,13 @@ int tpm_chip_register(struct tpm_chip *chip)
> 		return rc;
> 	}
> 
>+	rc = tpm_create_sysfs(&chip->dev);
>+	if (rc) {
>+		tpm_del_legacy_sysfs(chip);
>+		tpm_chip_unregister(chip);
>+		return rc;
>+	}
>+
> 	return 0;
> }
> EXPORT_SYMBOL_GPL(tpm_chip_register);
>@@ -382,6 +466,7 @@ int tpm_chip_register(struct tpm_chip *chip)
>  */
> void tpm_chip_unregister(struct tpm_chip *chip)
> {
>+	tpm_remove_sysfs(&chip->dev);
> 	tpm_del_legacy_sysfs(chip);
> 	tpm_bios_log_teardown(chip);
> 	tpm_del_char_device(chip);

-- 
Sent from my mobile

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

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

* RE: [PATCH] tpm: Add sysfs interface to show TPM hardware version
  2017-03-13  7:10   ` Peter Huewe
@ 2017-03-13  7:47     ` Li, Meng
  2017-03-14 18:18     ` [tpmdd-devel] " Ken Goldman
  1 sibling, 0 replies; 10+ messages in thread
From: Li, Meng @ 2017-03-13  7:47 UTC (permalink / raw)
  To: Peter Huewe, linux-kernel; +Cc: tpmdd, jarkko.sakkinen, jgunthorpe, tpmdd-devel



> -----Original Message-----
> From: Peter Huewe [mailto:peterhuewe@gmx.de]
> Sent: Monday, March 13, 2017 3:11 PM
> To: Li, Meng; linux-kernel@vger.kernel.org
> Cc: tpmdd@selhorst.net; jarkko.sakkinen@linux.intel.com;
> jgunthorpe@obsidianresearch.com; tpmdd-devel@lists.sourceforge.net
> Subject: Re: [PATCH] tpm: Add sysfs interface to show TPM hardware
> version
> 
> Hi,
> Thanks for your patch.

Hi Peter,

Thanks for reviewing this patch in your busy time.
I will do modification according to your comment and then send the next patch reviewing.

Thanks,
Limeng

> 
> Am 13. März 2017 06:21:57 MEZ schrieb Meng.Li@windriver.com:
> >From: Limeng <Meng.Li@windriver.com>
> >
> >So far, there is not a sysfs interface for user space code to check the
> >TPM hardware version(TPM1.x or TPM2). So, add a file named description
> >in /sys/class/tpm/tpmX/ to show it.
> It's not really the hardware version but the "TPM Family" according to tcg.
> 
> And yes you are right there is currently no way, except for trial and error, for
> the userspace to determine this.
> So an interface to get this information makes sense to me.
> >
> >Signed-off-by: Meng Li <Meng.Li@windriver.com>
> >---
> >drivers/char/tpm/tpm-chip.c |   85
> >+++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 85 insertions(+)
> >
> >diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> >index c406343..da2cd69 100644
> >--- a/drivers/char/tpm/tpm-chip.c
> >+++ b/drivers/char/tpm/tpm-chip.c
> >@@ -36,6 +36,83 @@
> > dev_t tpm_devt;
> >
> > /**
> >+ * show_description - sysfs interface for checking current TPM
> >hardware version.
> >+ * @dev:	pointer to tpm chip device
> >+ * @attr:	unused
> >+ * @buf:	char buffer to be filled with TPM hardware version info
> >+ *
> >+ * Provides sysfs interface for showing current TPM hardware version.
> >+ */
> >+static ssize_t show_description(struct device *dev,
> >+		struct device_attribute *attr, char *buf) {
> >+	struct tpm_chip *chip = (struct tpm_chip *)container_of(dev,struct
> >tpm_chip,dev);
> >+	int ret;
> >+
> >+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
> >+		ret = sprintf(buf, "TPM 2.0");
> >+	else
> >+		ret = sprintf(buf, "TPM 1.x");
> >+
> >+	return ret;
> >+}
> >+
> >+/**
> >+ * store_description - interface for manually setting data.
> >+ * @dev:	unused
> >+ * @attr:	unused
> >+ * @buf:	unused
> >+ * @count:	unused
> >+ *
> >+ * There is not any process in this function, reserve for feature.
> >+ */
> >+static ssize_t store_description(struct device *dev, struct
> >device_attribute *attr,
> >+		const char *buf, size_t count)
> >+{
> >+	return count;
> >+}
> Since it does not do anything
> I would not create this function and leave the sysfs node as S_IRUGO.
> 
> >+
> >+static struct device_attribute tpm_attrs[] = {
> >+	__ATTR(description, S_IRUGO | S_IWUSR, show_description,
> >store_description),
> >+};
> >+
> >+/**
> >+ * tpm_create_sysfs - Create tpm sysfs interface.
> >+ * @dev:	pointer to tpm chip device
> >+ *
> >+ * Create sysfs interface for checking current TPM hardware version.
> >+ */
> >+static int tpm_create_sysfs(struct device *dev) {
> >+	int r, t;
> >+
> >+	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
> >+		r = device_create_file(dev, &tpm_attrs[t]);
> >+		if (r) {
> >+			dev_err(dev, "failed to create sysfs file\n");
> >+			return r;
> >+		}
> >+	}
> >+
> >+	return 0;
> >+}
> >+
> >+/**
> >+ * tpm_remove_sysfs - Remove tpm sysfs interface.
> >+ * @dev:	pointer to tpm chip device
> >+ *
> >+ * Remove sysfs interface for checking current TPM hardware version.
> >+ */
> >+static void tpm_remove_sysfs(struct device *dev) {
> >+	int  t;
> >+
> >+	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
> >+		device_remove_file(dev, &tpm_attrs[t]);
> >+	}
> >+}
> >+
> >+/**
> >  * tpm_try_get_ops() - Get a ref to the tpm_chip
> >  * @chip: Chip to ref
> >  *
> >@@ -363,6 +440,13 @@ int tpm_chip_register(struct tpm_chip *chip)
> > 		return rc;
> > 	}
> >
> >+	rc = tpm_create_sysfs(&chip->dev);
> >+	if (rc) {
> >+		tpm_del_legacy_sysfs(chip);
> >+		tpm_chip_unregister(chip);
> >+		return rc;
> >+	}
> >+
> > 	return 0;
> > }
> > EXPORT_SYMBOL_GPL(tpm_chip_register);
> >@@ -382,6 +466,7 @@ int tpm_chip_register(struct tpm_chip *chip)
> >  */
> > void tpm_chip_unregister(struct tpm_chip *chip)  {
> >+	tpm_remove_sysfs(&chip->dev);
> > 	tpm_del_legacy_sysfs(chip);
> > 	tpm_bios_log_teardown(chip);
> > 	tpm_del_char_device(chip);
> 
> --
> Sent from my mobile

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

* Re: [PATCH] tpm: Add sysfs interface to show TPM hardware version
  2017-03-13  5:21 [PATCH] tpm: Add sysfs interface to show TPM hardware version Meng.Li
       [not found] ` <1489382517-9078-1-git-send-email-Meng.Li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
@ 2017-03-13 11:48 ` Jarkko Sakkinen
       [not found]   ` <20170313114852.kmfequmchxi3jams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  1 sibling, 1 reply; 10+ messages in thread
From: Jarkko Sakkinen @ 2017-03-13 11:48 UTC (permalink / raw)
  To: Meng.Li; +Cc: linux-kernel, peterhuewe, tpmdd, jgunthorpe, tpmdd-devel

On Mon, Mar 13, 2017 at 01:21:57PM +0800, Meng.Li@windriver.com wrote:
> From: Limeng <Meng.Li@windriver.com>
> 
> So far, there is not a sysfs interface for user space code to
> check the TPM hardware version(TPM1.x or TPM2). So, add a
> file named description in /sys/class/tpm/tpmX/ to show it.
> 
> Signed-off-by: Meng Li <Meng.Li@windriver.com>
> ---
>  drivers/char/tpm/tpm-chip.c |   85 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 85 insertions(+)
> 
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index c406343..da2cd69 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c

tpm-sysfs.c Probably makes sense to rename legacy group there as tpm1_

> @@ -36,6 +36,83 @@
>  dev_t tpm_devt;
>  
>  /**
> + * show_description - sysfs interface for checking current TPM hardware version.
> + * @dev:	pointer to tpm chip device
> + * @attr:	unused
> + * @buf:	char buffer to be filled with TPM hardware version info
> + *
> + * Provides sysfs interface for showing current TPM hardware version.
> + */
> +static ssize_t show_description(struct device *dev,
> +		struct device_attribute *attr, char *buf)

family

> +{
> +	struct tpm_chip *chip = (struct tpm_chip *)container_of(dev,struct tpm_chip,dev);
> +	int ret;
> +
> +	if (chip->flags & TPM_CHIP_FLAG_TPM2)
> +		ret = sprintf(buf, "TPM 2.0");
> +	else
> +		ret = sprintf(buf, "TPM 1.x");
> +
> +	return ret;
> +}
> +
> +/**
> + * store_description - interface for manually setting data.
> + * @dev:	unused
> + * @attr:	unused
> + * @buf:	unused
> + * @count:	unused
> + *
> + * There is not any process in this function, reserve for feature.
> + */
> +static ssize_t store_description(struct device *dev, struct device_attribute *attr,
> +		const char *buf, size_t count)
> +{
> +	return count;
> +}

What is this??

> +
> +static struct device_attribute tpm_attrs[] = {
> +	__ATTR(description, S_IRUGO | S_IWUSR, show_description, store_description),
> +};
> +
> +/**
> + * tpm_create_sysfs - Create tpm sysfs interface.
> + * @dev:	pointer to tpm chip device
> + *
> + * Create sysfs interface for checking current TPM hardware version.
> + */
> +static int tpm_create_sysfs(struct device *dev)
> +{
> +	int r, t;
> +
> +	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
> +		r = device_create_file(dev, &tpm_attrs[t]);
> +		if (r) {
> +			dev_err(dev, "failed to create sysfs file\n");
> +			return r;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * tpm_remove_sysfs - Remove tpm sysfs interface.
> + * @dev:	pointer to tpm chip device
> + *
> + * Remove sysfs interface for checking current TPM hardware version.
> + */
> +static void tpm_remove_sysfs(struct device *dev)
> +{
> +	int  t;
> +
> +	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
> +		device_remove_file(dev, &tpm_attrs[t]);
> +	}
> +}
> +
> +/**
>   * tpm_try_get_ops() - Get a ref to the tpm_chip
>   * @chip: Chip to ref
>   *
> @@ -363,6 +440,13 @@ int tpm_chip_register(struct tpm_chip *chip)
>  		return rc;
>  	}
>  
> +	rc = tpm_create_sysfs(&chip->dev);
> +	if (rc) {
> +		tpm_del_legacy_sysfs(chip);
> +		tpm_chip_unregister(chip);
> +		return rc;
> +	}
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(tpm_chip_register);
> @@ -382,6 +466,7 @@ int tpm_chip_register(struct tpm_chip *chip)
>   */
>  void tpm_chip_unregister(struct tpm_chip *chip)
>  {
> +	tpm_remove_sysfs(&chip->dev);
>  	tpm_del_legacy_sysfs(chip);
>  	tpm_bios_log_teardown(chip);
>  	tpm_del_char_device(chip);
> -- 
> 1.7.9.5

You should put the attributes to chip->groups instead of racy creation
of them.

/Jarkko

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

* Re: [PATCH] tpm: Add sysfs interface to show TPM hardware version
       [not found]   ` <20170313114852.kmfequmchxi3jams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2017-03-13 12:37     ` Li, Meng
  0 siblings, 0 replies; 10+ messages in thread
From: Li, Meng @ 2017-03-13 12:37 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA



> -----Original Message-----
> From: Jarkko Sakkinen [mailto:jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org]
> Sent: Monday, March 13, 2017 7:49 PM
> To: Li, Meng
> Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; peterhuewe-Mmb7MZpHnFY@public.gmane.org;
> tpmdd-yWjUBOtONefk1uMJSBkQmQ@public.gmane.org; jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org; tpmdd-
> devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> Subject: Re: [PATCH] tpm: Add sysfs interface to show TPM hardware
> version
> 
> On Mon, Mar 13, 2017 at 01:21:57PM +0800, Meng.Li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org wrote:
> > From: Limeng <Meng.Li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
> >
> > So far, there is not a sysfs interface for user space code to check
> > the TPM hardware version(TPM1.x or TPM2). So, add a file named
> > description in /sys/class/tpm/tpmX/ to show it.
> >
> > Signed-off-by: Meng Li <Meng.Li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
> > ---
> >  drivers/char/tpm/tpm-chip.c |   85
> +++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 85 insertions(+)
> >
> > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> > index c406343..da2cd69 100644
> > --- a/drivers/char/tpm/tpm-chip.c
> > +++ b/drivers/char/tpm/tpm-chip.c
> 
> tpm-sysfs.c Probably makes sense to rename legacy group there as tpm1_

Thanks for this advice.

> 
> > @@ -36,6 +36,83 @@
> >  dev_t tpm_devt;
> >
> >  /**
> > + * show_description - sysfs interface for checking current TPM hardware
> version.
> > + * @dev:	pointer to tpm chip device
> > + * @attr:	unused
> > + * @buf:	char buffer to be filled with TPM hardware version info
> > + *
> > + * Provides sysfs interface for showing current TPM hardware version.
> > + */
> > +static ssize_t show_description(struct device *dev,
> > +		struct device_attribute *attr, char *buf)
> 
> family
> 
> > +{
> > +	struct tpm_chip *chip = (struct tpm_chip *)container_of(dev,struct
> tpm_chip,dev);
> > +	int ret;
> > +
> > +	if (chip->flags & TPM_CHIP_FLAG_TPM2)
> > +		ret = sprintf(buf, "TPM 2.0");
> > +	else
> > +		ret = sprintf(buf, "TPM 1.x");
> > +
> > +	return ret;
> > +}
> > +
> > +/**
> > + * store_description - interface for manually setting data.
> > + * @dev:	unused
> > + * @attr:	unused
> > + * @buf:	unused
> > + * @count:	unused
> > + *
> > + * There is not any process in this function, reserve for feature.
> > + */
> > +static ssize_t store_description(struct device *dev, struct
> device_attribute *attr,
> > +		const char *buf, size_t count)
> > +{
> > +	return count;
> > +}
> 
> What is this??
> 
> > +
> > +static struct device_attribute tpm_attrs[] = {
> > +	__ATTR(description, S_IRUGO | S_IWUSR, show_description,
> > +store_description), };
> > +
> > +/**
> > + * tpm_create_sysfs - Create tpm sysfs interface.
> > + * @dev:	pointer to tpm chip device
> > + *
> > + * Create sysfs interface for checking current TPM hardware version.
> > + */
> > +static int tpm_create_sysfs(struct device *dev) {
> > +	int r, t;
> > +
> > +	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
> > +		r = device_create_file(dev, &tpm_attrs[t]);
> > +		if (r) {
> > +			dev_err(dev, "failed to create sysfs file\n");
> > +			return r;
> > +		}
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +/**
> > + * tpm_remove_sysfs - Remove tpm sysfs interface.
> > + * @dev:	pointer to tpm chip device
> > + *
> > + * Remove sysfs interface for checking current TPM hardware version.
> > + */
> > +static void tpm_remove_sysfs(struct device *dev) {
> > +	int  t;
> > +
> > +	for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
> > +		device_remove_file(dev, &tpm_attrs[t]);
> > +	}
> > +}
> > +
> > +/**
> >   * tpm_try_get_ops() - Get a ref to the tpm_chip
> >   * @chip: Chip to ref
> >   *
> > @@ -363,6 +440,13 @@ int tpm_chip_register(struct tpm_chip *chip)
> >  		return rc;
> >  	}
> >
> > +	rc = tpm_create_sysfs(&chip->dev);
> > +	if (rc) {
> > +		tpm_del_legacy_sysfs(chip);
> > +		tpm_chip_unregister(chip);
> > +		return rc;
> > +	}
> > +
> >  	return 0;
> >  }
> >  EXPORT_SYMBOL_GPL(tpm_chip_register);
> > @@ -382,6 +466,7 @@ int tpm_chip_register(struct tpm_chip *chip)
> >   */
> >  void tpm_chip_unregister(struct tpm_chip *chip)  {
> > +	tpm_remove_sysfs(&chip->dev);
> >  	tpm_del_legacy_sysfs(chip);
> >  	tpm_bios_log_teardown(chip);
> >  	tpm_del_char_device(chip);
> > --
> > 1.7.9.5
> 
> You should put the attributes to chip->groups instead of racy creation of
> them.

Thanks for your advice. It is more reasonable in to chip->groups.

Regards,
Limeng

> 
> /Jarkko

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford

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

* Re: [tpmdd-devel] [PATCH] tpm: Add sysfs interface to show TPM hardware version
  2017-03-13  7:10   ` Peter Huewe
  2017-03-13  7:47     ` Li, Meng
@ 2017-03-14 18:18     ` Ken Goldman
       [not found]       ` <9f67321b-50bd-9e6f-61f8-c29ae14f261f-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
  1 sibling, 1 reply; 10+ messages in thread
From: Ken Goldman @ 2017-03-14 18:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: tpmdd-devel

On 3/13/2017 3:10 AM, Peter Huewe wrote:

> And yes you are right there is currently no way, except for trial and
> error, for the userspace to determine this. So an interface to get
> this information makes sense to me.

In practice, I suspect that a single user space application won't
support both TPMs.  It will send the first command, get an error
response code that says it's the wrong TPM, and exit.

Note that, although there is no overlap in the command API, the packet
format is compatible enough that a meaningful response can be returned.

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

* Re: [PATCH] tpm: Add sysfs interface to show TPM hardware version
       [not found]       ` <9f67321b-50bd-9e6f-61f8-c29ae14f261f-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
@ 2017-03-14 18:58         ` Peter Huewe
       [not found]           ` <074515F2-51E7-485B-B1AB-11B913CC4B46-Mmb7MZpHnFY@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Huewe @ 2017-03-14 18:58 UTC (permalink / raw)
  To: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Ken Goldman,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA



Am 14. März 2017 19:18:15 MEZ schrieb Ken Goldman <kgold@linux.vnet.ibm.com>:
>On 3/13/2017 3:10 AM, Peter Huewe wrote:
>
>> And yes you are right there is currently no way, except for trial and
>> error, for the userspace to determine this. So an interface to get
>> this information makes sense to me.
>
>In practice, I suspect that a single user space application won't
>support both TPMs. 
Think of init scripts.
Which daemon should it start?


> It will send the first command, get an error
>response code that says it's the wrong TPM, and exit.
>
>Note that, although there is no overlap in the command API, the packet
>format is compatible enough that a meaningful response can be returned.
>
>
>
>
>------------------------------------------------------------------------------
>Check out the vibrant tech community on one of the world's most
>engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>_______________________________________________
>tpmdd-devel mailing list
>tpmdd-devel@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

-- 
Sent from my mobile

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
tpmdd-devel mailing list
tpmdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

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

* Re: [PATCH] tpm: Add sysfs interface to show TPM hardware version
       [not found]           ` <074515F2-51E7-485B-B1AB-11B913CC4B46-Mmb7MZpHnFY@public.gmane.org>
@ 2017-03-14 21:24             ` Jason Gunthorpe
       [not found]               ` <20170314212425.GA29359-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Jason Gunthorpe @ 2017-03-14 21:24 UTC (permalink / raw)
  To: Peter Huewe
  Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Tue, Mar 14, 2017 at 07:58:37PM +0100, Peter Huewe wrote:

> >In practice, I suspect that a single user space application won't
> >support both TPMs. 
> Think of init scripts.
> Which daemon should it start?

Right, ideally we'd have a udev rule that triggers systemd to start
the userspace daemons when a TPM is detected, as other hardware does.

So whatever format we use has to be compatible with udev's matcher..

Jason

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] tpm: Add sysfs interface to show TPM hardware version
       [not found]               ` <20170314212425.GA29359-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2017-03-14 21:42                 ` James Bottomley
  2017-03-15 17:25                   ` [tpmdd-devel] " Jason Gunthorpe
  0 siblings, 1 reply; 10+ messages in thread
From: James Bottomley @ 2017-03-14 21:42 UTC (permalink / raw)
  To: Jason Gunthorpe, Peter Huewe
  Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Tue, 2017-03-14 at 15:24 -0600, Jason Gunthorpe wrote:
> On Tue, Mar 14, 2017 at 07:58:37PM +0100, Peter Huewe wrote:
> 
> > > In practice, I suspect that a single user space application won't
> > > support both TPMs. 
> > Think of init scripts.
> > Which daemon should it start?
> 
> Right, ideally we'd have a udev rule that triggers systemd to start
> the userspace daemons when a TPM is detected, as other hardware does.
> 
> So whatever format we use has to be compatible with udev's matcher..

Technically, we have that already: my TPM2.0 detection stuff for udev
triggers off the presence of the SUBSYSTEM=="tpmrm"  that matches any
TPM2 device but not a 1.x one.

James



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [tpmdd-devel] [PATCH] tpm: Add sysfs interface to show TPM hardware version
  2017-03-14 21:42                 ` James Bottomley
@ 2017-03-15 17:25                   ` Jason Gunthorpe
  0 siblings, 0 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2017-03-15 17:25 UTC (permalink / raw)
  To: James Bottomley; +Cc: Peter Huewe, tpmdd-devel, linux-kernel

On Tue, Mar 14, 2017 at 02:42:51PM -0700, James Bottomley wrote:
> On Tue, 2017-03-14 at 15:24 -0600, Jason Gunthorpe wrote:
> > On Tue, Mar 14, 2017 at 07:58:37PM +0100, Peter Huewe wrote:
> > 
> > > > In practice, I suspect that a single user space application won't
> > > > support both TPMs. 
> > > Think of init scripts.
> > > Which daemon should it start?
> > 
> > Right, ideally we'd have a udev rule that triggers systemd to start
> > the userspace daemons when a TPM is detected, as other hardware does.
> > 
> > So whatever format we use has to be compatible with udev's matcher..
> 
> Technically, we have that already: my TPM2.0 detection stuff for udev
> triggers off the presence of the SUBSYSTEM=="tpmrm"  that matches any
> TPM2 device but not a 1.x one.

but long term tpmrm won't be TPM2 exclusive..

Jason

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

end of thread, other threads:[~2017-03-15 17:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-13  5:21 [PATCH] tpm: Add sysfs interface to show TPM hardware version Meng.Li
     [not found] ` <1489382517-9078-1-git-send-email-Meng.Li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2017-03-13  7:10   ` Peter Huewe
2017-03-13  7:47     ` Li, Meng
2017-03-14 18:18     ` [tpmdd-devel] " Ken Goldman
     [not found]       ` <9f67321b-50bd-9e6f-61f8-c29ae14f261f-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-03-14 18:58         ` Peter Huewe
     [not found]           ` <074515F2-51E7-485B-B1AB-11B913CC4B46-Mmb7MZpHnFY@public.gmane.org>
2017-03-14 21:24             ` Jason Gunthorpe
     [not found]               ` <20170314212425.GA29359-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-03-14 21:42                 ` James Bottomley
2017-03-15 17:25                   ` [tpmdd-devel] " Jason Gunthorpe
2017-03-13 11:48 ` Jarkko Sakkinen
     [not found]   ` <20170313114852.kmfequmchxi3jams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-03-13 12:37     ` Li, Meng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).