mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: tpmdd-devel@lists.sourceforge.net,
	Peter Huewe <peterhuewe@gmx.de>,
	Marcel Selhorst <tpmdd@selhorst.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 12/12] tpm: TPM2 sysfs attributes
Date: Wed, 24 Sep 2014 11:13:38 -0600	[thread overview]
Message-ID: <20140924171338.GG8898@obsidianresearch.com> (raw)
In-Reply-To: <1411549562-24242-13-git-send-email-jarkko.sakkinen@linux.intel.com>

On Wed, Sep 24, 2014 at 12:06:02PM +0300, Jarkko Sakkinen wrote:
> Added tpm2-sysfs.c that implements sysfs attributes for a TPM2
> device.

You need to document in Documentation every new sysfs that is added.

The existing ones are not documented :(

> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -899,6 +899,7 @@ void tpm_remove_hardware(struct device *dev)
>  
>  	tpm_chip_unregister(chip);
>  
> +
>  	/* write it this way to be explicit (chip->dev == dev) */
>  	put_device(chip->dev);
>  }

Hunk does not belong in this patch

> diff --git a/drivers/char/tpm/tpm2-commands.c b/drivers/char/tpm/tpm2-commands.c
> index a21dfd5..6365087 100644
> +++ b/drivers/char/tpm/tpm2-commands.c
> @@ -195,7 +195,7 @@ ssize_t tpm2_get_tpm_pt(struct device *dev, u32 property_id,  u32* value,
>  	cmd.header.in = tpm2_get_tpm_pt_header;
>  	cmd.params.tpm2_get_tpm_pt_in.cap_id =
>  		cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
> -	cmd.params.tpm2_get_tpm_pt_in.property_id = property_id;
> +	cmd.params.tpm2_get_tpm_pt_in.property_id = cpu_to_be32(property_id);
>  	cmd.params.tpm2_get_tpm_pt_in.property_cnt = cpu_to_be32(1);

Hunk does not belong in this patch

> +static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{

The pcrs file never conformed to the sysfs rules, if TPM2 is getting a
whole new file set, I wouldn't mind seeing it not include the
non-conformant ones. What do you think?

> +static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{

Ditto.. The manfacturer number should probably be its own file

> +static ssize_t durations_show(struct device *dev, struct device_attribute *attr,
> +			      char *buf)
> +{
> +	struct tpm_chip *chip = dev_get_drvdata(dev);
> +
> +	if (chip->vendor.duration[TPM_LONG] == 0)
> +		return 0;
> +
> +	return sprintf(buf, "%d %d %d [%s]\n",
> +		       jiffies_to_usecs(chip->vendor.duration[TPM_SHORT]),
> +		       jiffies_to_usecs(chip->vendor.duration[TPM_MEDIUM]),
> +		       jiffies_to_usecs(chip->vendor.duration[TPM_LONG]),
> +		       chip->vendor.duration_adjusted
> +		       ? "adjusted" : "original");
> +}
> +static DEVICE_ATTR_RO(durations);

Seem useless since the durations are constant, drop it?

> +static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr,
> +			     char *buf)
> +{
> +	struct tpm_chip *chip = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%d %d %d %d [%s]\n",
> +		       jiffies_to_usecs(chip->vendor.timeout_a),
> +		       jiffies_to_usecs(chip->vendor.timeout_b),
> +		       jiffies_to_usecs(chip->vendor.timeout_c),
> +		       jiffies_to_usecs(chip->vendor.timeout_d),
> +		       chip->vendor.timeout_adjusted
> +		       ? "adjusted" : "original");
> +}
> +static DEVICE_ATTR_RO(timeouts);

Ditto

> +static ssize_t version_show(struct device *dev, struct device_attribute *attr,
> +			   char *buf)
> +{
> +	char *str = buf;
> +
> +	str += sprintf(str, "2.0\n");
> +
> +	return str - buf;
> +}
> +
> +static DEVICE_ATTR_RO(version);
> +
> +
> +static ssize_t tpm2_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct tpm_chip *chip = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%d\n", chip->tpm2);
> +}
> +static DEVICE_ATTR_RO(tpm2);

Two things for the same report? Drop one?

Also, I think some thought is needed for the char interface - some
kind of ioctl to enter TPM2 mode and EINVAL access until that is done?

Finally, this is in the wrong place in sysfs, I suspect it should be
attached to the char device node, not the platform device node? We
should at least investigate this...

> +struct tpm2_permanent {
> +	unsigned int owner_auth_set		: 1;
> +	unsigned int endorsement_auth_set	: 1;
> +	unsigned int lockout_auth_set		: 1;
> +	unsigned int reserved1			: 5;
> +	unsigned int disable_clear		: 1;
> +	unsigned int in_lockout			: 1;
> +	unsigned int tpm_generated_eps		: 1;
> +	unsigned int reserved2			: 21;
> +};
> +
> +struct tpm2_startup_clear {
> +	unsigned int ph_enable			: 1;
> +	unsigned int sh_enable			: 1;
> +	unsigned int eh_enable			: 1;
> +	unsigned int ph_enable_nv		: 1;
> +	unsigned int reserved			: 27;
> +	unsigned int orderly			: 1;
> +};

This idea is not portable, you cannot use bitfields to index bits in a
word like this. Please use constants defined with BIT(xx)

Next posting can you include a github link? Thanks

Jason

  reply	other threads:[~2014-09-24 17:13 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-24  9:05 [PATCH v1 00/12] tpm: TPM2 support Jarkko Sakkinen
2014-09-24  9:05 ` [PATCH v1 01/12] tpm: prepare TPM driver for adding " Jarkko Sakkinen
2014-09-24 16:49   ` Jason Gunthorpe
2014-09-24  9:05 ` [PATCH v1 02/12] tpm: TPM2 support for tpm_calc_ordinal_durations() Jarkko Sakkinen
2014-09-24  9:05 ` [PATCH v1 03/12] tpm: TPM2 support for tpm_pcr_read() Jarkko Sakkinen
2014-09-24 16:53   ` Jason Gunthorpe
2014-09-24 19:43     ` Jarkko Sakkinen
2014-09-24 20:14       ` Peter Hüwe
2014-09-24 20:16       ` Jason Gunthorpe
2014-09-24  9:05 ` [PATCH v1 04/12] tpm: TPM2 support for tpm_do_selftest() Jarkko Sakkinen
2014-09-24  9:05 ` [PATCH v1 05/12] tpm: added tpm2_get_tpm_pt() Jarkko Sakkinen
2014-09-24  9:05 ` [PATCH v1 06/12] tpm: TPM2 support for tpm_pcr_extend() Jarkko Sakkinen
2014-09-24  9:05 ` [PATCH v1 07/12] tpm: TPM2 support for tpm_get_random() Jarkko Sakkinen
2014-09-24  9:05 ` [PATCH v1 08/12] tpm: TPM2 support for tpm_startup() Jarkko Sakkinen
2014-09-24  9:05 ` [PATCH v1 09/12] tpm: TPM2 support for tpm_gen_interrupt() Jarkko Sakkinen
2014-09-24  9:06 ` [PATCH v1 10/12] tpm: TPM 2.0 FIFO Interface Jarkko Sakkinen
2014-09-24 16:59   ` Jason Gunthorpe
2014-09-24 19:30     ` Jarkko Sakkinen
2014-09-24  9:06 ` [PATCH v1 11/12] tpm: Driver for TPM 2.0 CRB Interface Jarkko Sakkinen
2014-09-24 17:05   ` Jason Gunthorpe
2014-09-24 19:28     ` Jarkko Sakkinen
2014-09-25 13:56     ` Jarkko Sakkinen
2014-09-24  9:06 ` [PATCH v1 12/12] tpm: TPM2 sysfs attributes Jarkko Sakkinen
2014-09-24 17:13   ` Jason Gunthorpe [this message]
2014-09-24 17:34     ` [tpmdd-devel] " Stefan Berger
2014-09-24 17:59       ` Jason Gunthorpe
2014-09-24 18:50         ` Jarkko Sakkinen
2014-09-24 20:39         ` Peter Hüwe
2014-09-24 20:50           ` Jason Gunthorpe
2014-09-24 18:36     ` Peter Hüwe
2014-09-24 19:02     ` Jarkko Sakkinen
2014-09-24 20:19       ` Jason Gunthorpe
2014-09-24 20:35         ` Peter Hüwe
2014-09-24 20:46           ` Jason Gunthorpe
2014-09-26 17:19             ` Jarkko Sakkinen
2014-09-30 20:07               ` [tpmdd-devel] " Jarkko Sakkinen
2014-09-30 20:12                 ` Jason Gunthorpe
2014-10-02 12:30                   ` Jarkko Sakkinen
2014-09-24 17:28 ` [PATCH v1 00/12] tpm: TPM2 support Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140924171338.GG8898@obsidianresearch.com \
    --to=jgunthorpe@obsidianresearch.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=tpmdd-devel@lists.sourceforge.net \
    --cc=tpmdd@selhorst.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome