Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1443868 > unrolled thread
| Started by | Andrey Pronin <apronin@chromium.org> |
|---|---|
| First post | 2016-07-15 04:00 +0200 |
| Last post | 2016-07-18 21:20 +0200 |
| Articles | 7 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 1/2] tpm: add sysfs attributes for tpm2 Andrey Pronin <apronin@chromium.org> - 2016-07-15 04:00 +0200
Re: [PATCH 1/2] tpm: add sysfs attributes for tpm2 Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-07-15 05:30 +0200
Re: [PATCH 1/2] tpm: add sysfs attributes for tpm2 Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-07-15 05:40 +0200
Re: [PATCH 1/2] tpm: add sysfs attributes for tpm2 Andrey Pronin <apronin@chromium.org> - 2016-07-15 19:00 +0200
Re: [PATCH 1/2] tpm: add sysfs attributes for tpm2 Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-07-15 19:10 +0200
Re: [PATCH 1/2] tpm: add sysfs attributes for tpm2 Andrey Pronin <apronin@chromium.org> - 2016-07-15 05:40 +0200
Re: [PATCH 1/2] tpm: add sysfs attributes for tpm2 Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2016-07-18 21:20 +0200
| From | Andrey Pronin <apronin@chromium.org> |
|---|---|
| Date | 2016-07-15 04:00 +0200 |
| Subject | [PATCH 1/2] tpm: add sysfs attributes for tpm2 |
| Message-ID | <rV0A1-xW-1@gated-at.bofh.it> |
Break sysfs attributes into common and TPM 1.2/2.0-specific, and
create sysfs groups for TPM2.0.
Signed-off-by: Andrey Pronin <apronin@chromium.org>
---
drivers/char/tpm/tpm-chip.c | 48 ++++++++++++++++++++++++++++----------------
drivers/char/tpm/tpm-sysfs.c | 24 ++++++++++++++++++++--
2 files changed, 53 insertions(+), 19 deletions(-)
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 5a2f043..6c72671 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -281,8 +281,6 @@ static int tpm1_chip_register(struct tpm_chip *chip)
if (chip->flags & TPM_CHIP_FLAG_TPM2)
return 0;
- tpm_sysfs_add_device(chip);
-
chip->bios_dir = tpm_bios_log_setup(dev_name(&chip->dev));
return 0;
@@ -300,14 +298,21 @@ static void tpm1_chip_unregister(struct tpm_chip *chip)
static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
{
struct attribute **i;
+ int ngrp;
- if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))
+ if (chip->flags & TPM_CHIP_FLAG_VIRTUAL)
return;
- sysfs_remove_link(&chip->dev.parent->kobj, "ppi");
-
- for (i = chip->groups[0]->attrs; *i != NULL; ++i)
- sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name);
+ for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) {
+ if (chip->groups[ngrp]->name) {
+ sysfs_remove_link(&chip->dev.parent->kobj,
+ chip->groups[ngrp]->name);
+ } else {
+ for (i = chip->groups[ngrp]->attrs; *i != NULL; ++i)
+ sysfs_remove_link(&chip->dev.parent->kobj,
+ (*i)->name);
+ }
+ }
}
/* For compatibility with legacy sysfs paths we provide symlinks from the
@@ -317,20 +322,27 @@ static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
{
struct attribute **i;
- int rc;
+ int rc = 0;
+ int ngrp;
- if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))
+ if (chip->flags & TPM_CHIP_FLAG_VIRTUAL)
return 0;
- rc = __compat_only_sysfs_link_entry_to_kobj(
- &chip->dev.parent->kobj, &chip->dev.kobj, "ppi");
- if (rc && rc != -ENOENT)
- return rc;
-
/* All the names from tpm-sysfs */
- for (i = chip->groups[0]->attrs; *i != NULL; ++i) {
- rc = __compat_only_sysfs_link_entry_to_kobj(
- &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name);
+ for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) {
+ if (chip->groups[ngrp]->name) {
+ rc = __compat_only_sysfs_link_entry_to_kobj(
+ &chip->dev.parent->kobj, &chip->dev.kobj,
+ chip->groups[ngrp]->name);
+ } else {
+ for (i = chip->groups[ngrp]->attrs;
+ (*i != NULL) && !rc;
+ ++i)
+ rc = __compat_only_sysfs_link_entry_to_kobj(
+ &chip->dev.parent->kobj,
+ &chip->dev.kobj,
+ (*i)->name);
+ }
if (rc) {
tpm_del_legacy_sysfs(chip);
return rc;
@@ -354,6 +366,8 @@ int tpm_chip_register(struct tpm_chip *chip)
{
int rc;
+ tpm_sysfs_add_device(chip);
+
rc = tpm1_chip_register(chip);
if (rc)
return rc;
diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index b46cf70..95ce90d 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -265,6 +265,12 @@ static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr,
static DEVICE_ATTR_RO(timeouts);
static struct attribute *tpm_dev_attrs[] = {
+ &dev_attr_durations.attr,
+ &dev_attr_timeouts.attr,
+ NULL,
+};
+
+static struct attribute *tpm1_dev_attrs[] = {
&dev_attr_pubek.attr,
&dev_attr_pcrs.attr,
&dev_attr_enabled.attr,
@@ -273,8 +279,10 @@ static struct attribute *tpm_dev_attrs[] = {
&dev_attr_temp_deactivated.attr,
&dev_attr_caps.attr,
&dev_attr_cancel.attr,
- &dev_attr_durations.attr,
- &dev_attr_timeouts.attr,
+ NULL,
+};
+
+static struct attribute *tpm2_dev_attrs[] = {
NULL,
};
@@ -282,6 +290,14 @@ static const struct attribute_group tpm_dev_group = {
.attrs = tpm_dev_attrs,
};
+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)
{
/* The sysfs routines rely on an implicit tpm_try_get_ops, device_del
@@ -290,4 +306,8 @@ void tpm_sysfs_add_device(struct tpm_chip *chip)
*/
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;
}
--
2.6.6
[toc] | [next] | [standalone]
| From | Jason Gunthorpe <jgunthorpe@obsidianresearch.com> |
|---|---|
| Date | 2016-07-15 05:30 +0200 |
| Message-ID | <rV1Z7-1DV-5@gated-at.bofh.it> |
| In reply to | #1443868 |
On Thu, Jul 14, 2016 at 06:51:35PM -0700, Andrey Pronin wrote:
> - sysfs_remove_link(&chip->dev.parent->kobj, "ppi");
> -
> - for (i = chip->groups[0]->attrs; *i != NULL; ++i)
> - sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name);
> + for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) {
> + if (chip->groups[ngrp]->name) {
> + sysfs_remove_link(&chip->dev.parent->kobj,
> + chip->groups[ngrp]->name);
> + } else {
> + for (i = chip->groups[ngrp]->attrs; *i != NULL; ++i)
> + sysfs_remove_link(&chip->dev.parent->kobj,
> + (*i)->name);
> + }
> + }
NAK
No new compat symlinks. Only the existing set of links are permitted.
Any new sysfs entries must use only the new location.
> +static struct attribute *tpm2_dev_attrs[] = {
> NULL,
> };
> +static const struct attribute_group tpm2_dev_group = {
> + .attrs = tpm2_dev_attrs,
> +};
Don't add dead code, add this and related in the patch that requires it.
> void tpm_sysfs_add_device(struct tpm_chip *chip)
> {
> /* The sysfs routines rely on an implicit tpm_try_get_ops, device_del
> @@ -290,4 +306,8 @@ void tpm_sysfs_add_device(struct tpm_chip *chip)
> */
> 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;
.. and this can't really happen either..
To make things simple you can just have tpm2 not ever create any links
for any files by never using groups[0]. There is no need to try and
create a shared 'tpm_dev_group'.
Jason
[toc] | [prev] | [next] | [standalone]
| From | Jason Gunthorpe <jgunthorpe@obsidianresearch.com> |
|---|---|
| Date | 2016-07-15 05:40 +0200 |
| Message-ID | <rV28N-1GW-13@gated-at.bofh.it> |
| In reply to | #1443914 |
On Thu, Jul 14, 2016 at 08:32:01PM -0700, Andrey Pronin wrote: > tpm2 shares some of the attributes with tpm1 (e.g. timeouts). Do I still > just add those separately for tpm2 to groups[1] and keep groups[0] empty? I think so. Since the file never exists for tpm2, nothing coded for tpm2 will ever look in the old location. Jason
[toc] | [prev] | [next] | [standalone]
| From | Andrey Pronin <apronin@chromium.org> |
|---|---|
| Date | 2016-07-15 19:00 +0200 |
| Message-ID | <rVeCZ-QX-3@gated-at.bofh.it> |
| In reply to | #1443921 |
On Thu, Jul 14, 2016 at 09:34:39PM -0600, Jason Gunthorpe wrote: > On Thu, Jul 14, 2016 at 08:32:01PM -0700, Andrey Pronin wrote: > > > tpm2 shares some of the attributes with tpm1 (e.g. timeouts). Do I still > > just add those separately for tpm2 to groups[1] and keep groups[0] empty? Just realized that if we keep tpm_add_legacy_sysfs() intact, it doesn't create symlinks for tpm2 case for any of the groups, including groups[0]. So, in tpm_sysfs_add_device() can just do smth like: if (chip->flags & TPM_CHIP_FLAG_TPM2) chip->groups[chip->groups_cnt++] = &tpm2_dev_group; else chip->groups[chip->groups_cnt++] = &tpm_dev_group; Is that acceptable? Will submit the next version along those lines. > > I think so. Since the file never exists for tpm2, nothing coded for > tpm2 will ever look in the old location. > There can be a common code working with tpm1.2 that will just continue working with tpm2 if the common attributes are in the same place. So, some part of code can be re-used as is, but I agree that there are not too many common attributes. Will drop for now. Can be addressed later if the clear need arises.
[toc] | [prev] | [next] | [standalone]
| From | Jason Gunthorpe <jgunthorpe@obsidianresearch.com> |
|---|---|
| Date | 2016-07-15 19:10 +0200 |
| Message-ID | <rVeMF-19a-19@gated-at.bofh.it> |
| In reply to | #1444446 |
On Fri, Jul 15, 2016 at 09:56:58AM -0700, Andrey Pronin wrote: > On Thu, Jul 14, 2016 at 09:34:39PM -0600, Jason Gunthorpe wrote: > > On Thu, Jul 14, 2016 at 08:32:01PM -0700, Andrey Pronin wrote: > > > > > tpm2 shares some of the attributes with tpm1 (e.g. timeouts). Do I still > > > just add those separately for tpm2 to groups[1] and keep groups[0] empty? > > Just realized that if we keep tpm_add_legacy_sysfs() intact, it doesn't > create symlinks for tpm2 case for any of the groups, including groups[0]. > So, in tpm_sysfs_add_device() can just do smth like: > > if (chip->flags & TPM_CHIP_FLAG_TPM2) > chip->groups[chip->groups_cnt++] = &tpm2_dev_group; > else > chip->groups[chip->groups_cnt++] = &tpm_dev_group; > > Is that acceptable? Will submit the next version along those lines. Sure, as long as there are no links for TPM2 that sounds fine. > > I think so. Since the file never exists for tpm2, nothing coded for > > tpm2 will ever look in the old location. > There can be a common code working with tpm1.2 that will just > continue working with tpm2 if the common attributes are in the same > place. So, some part of code can be re-used as is, but I agree that > there are not too many common attributes. Will drop for now. Can be > addressed later if the clear need arises. Well, we expect people to test & migrate the common code when testing new tpm2 deployments.. Jason
[toc] | [prev] | [next] | [standalone]
| From | Andrey Pronin <apronin@chromium.org> |
|---|---|
| Date | 2016-07-15 05:40 +0200 |
| Message-ID | <rV28N-1GW-15@gated-at.bofh.it> |
| In reply to | #1443914 |
On Thu, Jul 14, 2016 at 09:21:45PM -0600, Jason Gunthorpe wrote:
> On Thu, Jul 14, 2016 at 06:51:35PM -0700, Andrey Pronin wrote:
> > - sysfs_remove_link(&chip->dev.parent->kobj, "ppi");
> > -
> > - for (i = chip->groups[0]->attrs; *i != NULL; ++i)
> > - sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name);
> > + for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) {
> > + if (chip->groups[ngrp]->name) {
> > + sysfs_remove_link(&chip->dev.parent->kobj,
> > + chip->groups[ngrp]->name);
> > + } else {
> > + for (i = chip->groups[ngrp]->attrs; *i != NULL; ++i)
> > + sysfs_remove_link(&chip->dev.parent->kobj,
> > + (*i)->name);
> > + }
> > + }
>
> NAK
>
> No new compat symlinks. Only the existing set of links are permitted.
>
> Any new sysfs entries must use only the new location.
>
> > +static struct attribute *tpm2_dev_attrs[] = {
> > NULL,
> > };
>
> > +static const struct attribute_group tpm2_dev_group = {
> > + .attrs = tpm2_dev_attrs,
> > +};
>
> Don't add dead code, add this and related in the patch that requires it.
>
> > void tpm_sysfs_add_device(struct tpm_chip *chip)
> > {
> > /* The sysfs routines rely on an implicit tpm_try_get_ops, device_del
> > @@ -290,4 +306,8 @@ void tpm_sysfs_add_device(struct tpm_chip *chip)
> > */
> > 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;
>
> .. and this can't really happen either..
>
> To make things simple you can just have tpm2 not ever create any links
> for any files by never using groups[0]. There is no need to try and
> create a shared 'tpm_dev_group'.
>
> Jason
Hi Jason,
Mostly understood. One question.
tpm2 shares some of the attributes with tpm1 (e.g. timeouts). Do I still
just add those separately for tpm2 to groups[1] and keep groups[0] empty?
Andrey
[toc] | [prev] | [next] | [standalone]
| From | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> |
|---|---|
| Date | 2016-07-18 21:20 +0200 |
| Message-ID | <rWmf9-1SQ-59@gated-at.bofh.it> |
| In reply to | #1443868 |
On Thu, Jul 14, 2016 at 06:51:35PM -0700, Andrey Pronin wrote:
> Break sysfs attributes into common and TPM 1.2/2.0-specific, and
> create sysfs groups for TPM2.0.
I agree with Jasons comments and wait for revised version.
/Jarkko
> Signed-off-by: Andrey Pronin <apronin@chromium.org>
> ---
> drivers/char/tpm/tpm-chip.c | 48 ++++++++++++++++++++++++++++----------------
> drivers/char/tpm/tpm-sysfs.c | 24 ++++++++++++++++++++--
> 2 files changed, 53 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index 5a2f043..6c72671 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -281,8 +281,6 @@ static int tpm1_chip_register(struct tpm_chip *chip)
> if (chip->flags & TPM_CHIP_FLAG_TPM2)
> return 0;
>
> - tpm_sysfs_add_device(chip);
> -
> chip->bios_dir = tpm_bios_log_setup(dev_name(&chip->dev));
>
> return 0;
> @@ -300,14 +298,21 @@ static void tpm1_chip_unregister(struct tpm_chip *chip)
> static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
> {
> struct attribute **i;
> + int ngrp;
>
> - if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))
> + if (chip->flags & TPM_CHIP_FLAG_VIRTUAL)
> return;
>
> - sysfs_remove_link(&chip->dev.parent->kobj, "ppi");
> -
> - for (i = chip->groups[0]->attrs; *i != NULL; ++i)
> - sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name);
> + for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) {
> + if (chip->groups[ngrp]->name) {
> + sysfs_remove_link(&chip->dev.parent->kobj,
> + chip->groups[ngrp]->name);
> + } else {
> + for (i = chip->groups[ngrp]->attrs; *i != NULL; ++i)
> + sysfs_remove_link(&chip->dev.parent->kobj,
> + (*i)->name);
> + }
> + }
> }
>
> /* For compatibility with legacy sysfs paths we provide symlinks from the
> @@ -317,20 +322,27 @@ static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
> static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
> {
> struct attribute **i;
> - int rc;
> + int rc = 0;
> + int ngrp;
>
> - if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))
> + if (chip->flags & TPM_CHIP_FLAG_VIRTUAL)
> return 0;
>
> - rc = __compat_only_sysfs_link_entry_to_kobj(
> - &chip->dev.parent->kobj, &chip->dev.kobj, "ppi");
> - if (rc && rc != -ENOENT)
> - return rc;
> -
> /* All the names from tpm-sysfs */
> - for (i = chip->groups[0]->attrs; *i != NULL; ++i) {
> - rc = __compat_only_sysfs_link_entry_to_kobj(
> - &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name);
> + for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) {
> + if (chip->groups[ngrp]->name) {
> + rc = __compat_only_sysfs_link_entry_to_kobj(
> + &chip->dev.parent->kobj, &chip->dev.kobj,
> + chip->groups[ngrp]->name);
> + } else {
> + for (i = chip->groups[ngrp]->attrs;
> + (*i != NULL) && !rc;
> + ++i)
> + rc = __compat_only_sysfs_link_entry_to_kobj(
> + &chip->dev.parent->kobj,
> + &chip->dev.kobj,
> + (*i)->name);
> + }
> if (rc) {
> tpm_del_legacy_sysfs(chip);
> return rc;
> @@ -354,6 +366,8 @@ int tpm_chip_register(struct tpm_chip *chip)
> {
> int rc;
>
> + tpm_sysfs_add_device(chip);
> +
> rc = tpm1_chip_register(chip);
> if (rc)
> return rc;
> diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
> index b46cf70..95ce90d 100644
> --- a/drivers/char/tpm/tpm-sysfs.c
> +++ b/drivers/char/tpm/tpm-sysfs.c
> @@ -265,6 +265,12 @@ static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr,
> static DEVICE_ATTR_RO(timeouts);
>
> static struct attribute *tpm_dev_attrs[] = {
> + &dev_attr_durations.attr,
> + &dev_attr_timeouts.attr,
> + NULL,
> +};
> +
> +static struct attribute *tpm1_dev_attrs[] = {
> &dev_attr_pubek.attr,
> &dev_attr_pcrs.attr,
> &dev_attr_enabled.attr,
> @@ -273,8 +279,10 @@ static struct attribute *tpm_dev_attrs[] = {
> &dev_attr_temp_deactivated.attr,
> &dev_attr_caps.attr,
> &dev_attr_cancel.attr,
> - &dev_attr_durations.attr,
> - &dev_attr_timeouts.attr,
> + NULL,
> +};
> +
> +static struct attribute *tpm2_dev_attrs[] = {
> NULL,
> };
>
> @@ -282,6 +290,14 @@ static const struct attribute_group tpm_dev_group = {
> .attrs = tpm_dev_attrs,
> };
>
> +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)
> {
> /* The sysfs routines rely on an implicit tpm_try_get_ops, device_del
> @@ -290,4 +306,8 @@ void tpm_sysfs_add_device(struct tpm_chip *chip)
> */
> 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;
> }
> --
> 2.6.6
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web