Re: [tpmdd-devel] [PATCH v3] tpm_crb: request and relinquish locality 0

2017-03-15 Thread Jerry Snitselaar

Jarkko Sakkinen @ 2017-03-15 05:57 GMT:

> From: Jarkko Sakkinen 
>
> This commit adds support for requesting and relinquishing locality 0 in
> tpm_crb for the course of command transmission.
>
> In order to achieve this, two new callbacks are added to struct
> tpm_class_ops:
>
> - request_locality
> - relinquish_locality
>
> These are called before sending and receiving data from the TPM.  We
> update also tpm_tis_core to use these callbacks. A small modification to
> request_locality() is done so that it returns -EBUSY instead of locality
> number when check_locality() fails in order to return something
> meaningful to the user space.
>
> With CRB interface you first set either requestAccess or relinquish bit
> from TPM_LOC_CTRL_x register and then wait for locAssigned and
> tpmRegValidSts bits to be set in the TPM_LOC_STATE_x register.
>
> The reason why were are doing this is to make sure that the driver
> will work properly with Intel TXT that uses locality 2. There's no
> explicit guarantee that it would relinquish this locality. In more
> general sense this commit enables tpm_crb to be a well behaving
> citizen in a multi locality environment.
>
> Signed-off-by: Jarkko Sakkinen 
> ---
> v2:
> - TPM driver level calllbacks
> v3:
> - Call ops->relinquish_locality only if ops->request_locality has been
>   successful.
> - Do not reserve locality in nested tpm_transmit calls.
> - Check for tpmRegValidSts to make sure that the value in TPM_LOC_STATE_x is
>   stable.
>  drivers/char/tpm/tpm-interface.c | 10 ++
>  drivers/char/tpm/tpm.h   |  3 ++-
>  drivers/char/tpm/tpm2-space.c| 15 +--
>  drivers/char/tpm/tpm_crb.c   | 41 
> 
>  drivers/char/tpm/tpm_tis_core.c  | 12 
>  include/linux/tpm.h  |  3 ++-
>  6 files changed, 68 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c 
> b/drivers/char/tpm/tpm-interface.c
> index 95c6f98..4cd216f 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -384,6 +384,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct 
> tpm_space *space,
>   ssize_t len = 0;
>   u32 count, ordinal;
>   unsigned long stop;
> + bool no_locality = !(flags & TPM_TRANSMIT_HAS_LOCALITY);
>
>   if (!tpm_validate_command(chip, buf, bufsiz))
>   return -EINVAL;
> @@ -407,6 +408,12 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct 
> tpm_space *space,
>   if (chip->dev.parent)
>   pm_runtime_get_sync(chip->dev.parent);
>
> + if (no_locality && chip->ops->request_locality)  {
> + rc = chip->ops->request_locality(chip, 0);
> + if (rc)
> + goto out_no_locality;
> + }
> +
>   rc = tpm2_prepare_space(chip, space, ordinal, buf);
>   if (rc)
>   goto out;
> @@ -466,6 +473,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct 
> tpm_space *space,
>   rc = tpm2_commit_space(chip, space, ordinal, buf, );
>
>  out:
> + if (no_locality && chip->ops->relinquish_locality)
> + chip->ops->relinquish_locality(chip, 0, false);
> +out_no_locality:
>   if (chip->dev.parent)
>   pm_runtime_put_sync(chip->dev.parent);
>
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 5eacb3f..ba2c00d 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -521,7 +521,8 @@ extern const struct file_operations tpmrm_fops;
>  extern struct idr dev_nums_idr;
>
>  enum tpm_transmit_flags {
> - TPM_TRANSMIT_UNLOCKED   = BIT(0),
> + TPM_TRANSMIT_UNLOCKED   = BIT(0),
> + TPM_TRANSMIT_HAS_LOCALITY   = BIT(1),
>  };
>
>  ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
> diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
> index d36d81e..43d05ab 100644
> --- a/drivers/char/tpm/tpm2-space.c
> +++ b/drivers/char/tpm/tpm2-space.c
> @@ -19,6 +19,9 @@
>  #include 
>  #include "tpm.h"
>
> +#define TPM_TRANSMIT_NESTED \
> + (TPM_TRANSMIT_UNLOCKED | TPM_TRANSMIT_HAS_LOCALITY)
> +
>  enum tpm2_handle_types {
>   TPM2_HT_HMAC_SESSION= 0x0200,
>   TPM2_HT_POLICY_SESSION  = 0x0300,
> @@ -39,7 +42,7 @@ static void tpm2_flush_sessions(struct tpm_chip *chip, 
> struct tpm_space *space)
>   for (i = 0; i < ARRAY_SIZE(space->session_tbl); i++) {
>   if (space->session_tbl[i])
>   tpm2_flush_context_cmd(chip, space->session_tbl[i],
> -TPM_TRANSMIT_UNLOCKED);
> +TPM_TRANSMIT_NESTED);
>   }
>  }
>
> @@ -84,7 +87,7 @@ static int tpm2_load_context(struct tpm_chip *chip, u8 *buf,
>   tpm_buf_append(, [*offset], body_size);
>
>   rc = tpm_transmit_cmd(chip, NULL, tbuf.data, PAGE_SIZE, 4,
> - 

Re: [tpmdd-devel] [PATCH v1] tpm/st33zp24: Add GPIO ACPI mapping table

2017-03-15 Thread Jerry Snitselaar
Andy Shevchenko @ 2017-03-13 19:38 +0200:

> In order to make GPIO ACPI library stricter prepare users of
> gpiod_get_index() to correctly behave when there no mapping is
> provided by firmware.
>
> Here we add explicit mapping between _CRS GpioIo() resources and
> their names used in the driver.
>
> Signed-off-by: Andy Shevchenko 
> ---
>  drivers/char/tpm/st33zp24/i2c.c | 23 ---
>  drivers/char/tpm/st33zp24/spi.c | 23 ---
>  2 files changed, 40 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c
> index 028a9cd76b63..349fc72447a1 100644
> --- a/drivers/char/tpm/st33zp24/i2c.c
> +++ b/drivers/char/tpm/st33zp24/i2c.c
> @@ -111,6 +111,13 @@ static const struct st33zp24_phy_ops i2c_phy_ops = {
>   .recv = st33zp24_i2c_recv,
>  };
>  
> +static const struct acpi_gpio_params lpcpd_gpios = { 1, 0, false };
> +
> +static const struct acpi_gpio_mapping acpi_st33zp24_gpios[] = {
> + { "lpcpd-gpios", _gpios, 1 },
> + {},
> +};
> +
>  static int st33zp24_i2c_acpi_request_resources(struct i2c_client *client)
>  {
>   struct tpm_chip *chip = i2c_get_clientdata(client);
> @@ -118,10 +125,14 @@ static int st33zp24_i2c_acpi_request_resources(struct 
> i2c_client *client)
>   struct st33zp24_i2c_phy *phy = tpm_dev->phy_id;
>   struct gpio_desc *gpiod_lpcpd;
>   struct device *dev = >dev;
> + int ret;
> +
> + ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), 
> acpi_st33zp24_gpios);
> + if (ret)
> + return ret;
>  
>   /* Get LPCPD GPIO from ACPI */
> - gpiod_lpcpd = devm_gpiod_get_index(dev, "TPM IO LPCPD", 1,
> -GPIOD_OUT_HIGH);
> + gpiod_lpcpd = devm_gpiod_get(dev, "lpcpd", GPIOD_OUT_HIGH);
>   if (IS_ERR(gpiod_lpcpd)) {
>   dev_err(>dev,
>   "Failed to retrieve lpcpd-gpios from acpi.\n");
> @@ -268,8 +279,14 @@ static int st33zp24_i2c_probe(struct i2c_client *client,
>  static int st33zp24_i2c_remove(struct i2c_client *client)
>  {
>   struct tpm_chip *chip = i2c_get_clientdata(client);
> + int ret;
>  
> - return st33zp24_remove(chip);
> + ret = st33zp24_remove(chip);
> + if (ret)
> + return ret;
> +
> + acpi_dev_remove_driver_gpios(ACPI_COMPANION(>dev));
> + return 0;
>  }

>dev instead of >dev ?


--
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


Re: [tpmdd-devel] [PATCH v1 1/2] tpm: msleep() delays - replace with usleep_range() in i2c nuvoton driver

2017-03-15 Thread Jarkko Sakkinen
On Wed, Mar 15, 2017 at 09:51:47PM +0530, Nayna wrote:
> 
> 
> On 03/15/2017 09:22 PM, Jarkko Sakkinen wrote:
> > On Fri, Mar 10, 2017 at 01:45:53PM -0500, Nayna Jain wrote:
> > > Commit 500462a9de65 "timers: Switch to a non-cascading wheel" replaced
> > > the 'classic' timer wheel, which aimed for near 'exact' expiry of the
> > > timers.  Their analysis was that the vast majority of timeout timers
> > > are used as safeguards, not as real timers, and are cancelled or
> > > rearmed before expiration.  The only exception noted to this were
> > > networking timers with a small expiry time.
> > > 
> > > Not included in the analysis was the TPM polling timer, which resulted
> > > in a longer normal delay and, every so often, a very long delay.  The
> > > non-cascading wheel delay is based on CONFIG_HZ.  For a description of
> > > the different rings and their delays, refer to the comments in
> > > kernel/time/timer.c.
> > > 
> > > Below are the delays given for rings 0 - 2, which explains the longer
> > > "normal" delays and the very, long delays as seen on systems with
> > > CONFIG_HZ 250.
> > > 
> > > * HZ 1000 steps
> > >   * Level Offset  GranularityRange
> > >   *  0  0 1 ms0 ms - 63 ms
> > >   *  1 64 8 ms   64 ms - 511 ms
> > >   *  212864 ms  512 ms - 4095 ms (512ms - ~4s)
> > > 
> > > * HZ  250
> > >   * Level Offset  GranularityRange
> > >   *  0  0 4 ms0 ms - 255 ms
> > >   *  1 6432 ms  256 ms - 2047 ms (256ms - ~2s)
> > >   *  2128   256 ms 2048 ms - 16383 ms (~2s - ~16s)
> > > 
> > > Below is a comparison of extending the TPM with 1000 measurements,
> > > using msleep() vs. usleep_delay() when configured for 1000 hz vs. 250
> > > hz, before and after commit 500462a9de65.
> > > 
> > > linux-4.7 | msleep() usleep_range()
> > > 1000 hz: 0m44.628s | 1m34.497s 29.243s
> > > 250 hz: 1m28.510s | 4m49.269s 32.386s
> > > 
> > > linux-4.7  | min-max (msleep)  min-max (usleep_range)
> > > 1000 hz: 0:017 - 2:760s | 0:015 - 3:967s0:014 - 0:418s
> > > 250 hz: 0:028 - 1:954s | 0:040 - 4:096s0:016 - 0:816s
> > > 
> > > This patch replaces the msleep() with usleep_range() calls in the
> > > i2c nuvoton driver with a consistent max range value.
> > > 
> > > Signed-of-by: Mimi Zohar 
> > > Cc: sta...@vger.kernel.org (linux-4.8)
> > > Signed-off-by: Nayna Jain 
> > > ---
> > > Changelog v1:
> > > 
> > > - Included Jason's feedbacks related to #defines.
> > 
> > What was changed?
> > 
> 
> Changelog v1:
> >>
> >> - Included Jason's feedbacks related to #defines.
> 
> Based on Jason's review:
> - Added () in #define
> - Replaced hardcoded maximum range value with defined name.
> 
> Hmm.. could have included exact details.
> 
> Thanks & Regards,
> - Nayna
> 
> > /Jarkko
> > 

OK, I'll replace the original patch with this. Thanks.

/Jarkko

--
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


Re: [tpmdd-devel] [PATCH] tpm: select CONFIG_CRYPTO

2017-03-15 Thread Jarkko Sakkinen
On Wed, Mar 15, 2017 at 12:39:16PM +0100, Arnd Bergmann wrote:
> On Wed, Mar 15, 2017 at 9:30 AM, Jarkko Sakkinen
>  wrote:
> > Arnd,
> >
> > On Tue, Mar 14, 2017 at 10:40:24PM +0100, Arnd Bergmann wrote:
> >> As we need the CRYPTO_HASH_INFO implementation, we should also
> >> select CRYPTO itself to avoid this build warning:
> >>
> >> warning: (TCG_TPM && TRUSTED_KEYS && IMA) selects CRYPTO_HASH_INFO which 
> >> has unmet direct dependencies (CRYPTO)
> >>
> >> Fixes: c1f92b4b04ad ("tpm: enhance TPM 2.0 PCR extend to support multiple 
> >> banks")
> >> Signed-off-by: Arnd Bergmann 
> >
> > I've already merged this and put to my next branch.
> 
> Ah, I see my mistake: I had made an identical patch earlier, which you merged
> into linux-next, and I dropped it from my series after rebasing on
> -next, but then
> rebased again on mainline and did the new patch without checking whether
> it was already fixed in -next.
> 
> I guess the warning is rare enough that we don't really need this in v4.11
> even though it does apply there.
> 
> Arnd

Ah. Right, now that I remember that was my conclusion. I'm sorry that
I did not remember to respond :-) If you think this would make sense
for 4.11 I could send it to stable.

/Jarkko

--
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


Re: [tpmdd-devel] [PATCH v2] vTPM: Fix missing NULL check

2017-03-15 Thread Jarkko Sakkinen
On Wed, Mar 15, 2017 at 01:28:07AM -0400, Hon Ching(Vicky) Lo wrote:
> The current code passes the address of tpm_chip as the argument to
> dev_get_drvdata() without prior NULL check in
> tpm_ibmvtpm_get_desired_dma.  This resulted an oops during kernel
> boot when vTPM is enabled in Power partition configured in active
> memory sharing mode.
> 
> The vio_driver's get_desired_dma() is called before the probe(), which
> for vtpm is tpm_ibmvtpm_probe, and it's this latter function that
> initializes the driver and set data.  Attempting to get data before
> the probe() caused the problem.
> 
> This patch adds a NULL check to the tpm_ibmvtpm_get_desired_dma.
> 
> fixes: 9e0d39d8a6a0 ("tpm: Remove useless priv field in struct 
> tpm_vendor_specific")
> Cc: 
> Signed-off-by: Hon Ching(Vicky) Lo 

Reviewed-by: Jarkko Sakkine 

/Jarkko

> ---
>  drivers/char/tpm/tpm_ibmvtpm.c |8 ++--
>  1 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
> index 1b9d61f..f01d083 100644
> --- a/drivers/char/tpm/tpm_ibmvtpm.c
> +++ b/drivers/char/tpm/tpm_ibmvtpm.c
> @@ -299,6 +299,8 @@ static int tpm_ibmvtpm_remove(struct vio_dev *vdev)
>   }
>  
>   kfree(ibmvtpm);
> + /* For tpm_ibmvtpm_get_desired_dma */
> + dev_set_drvdata(>dev, NULL);
>  
>   return 0;
>  }
> @@ -313,14 +315,16 @@ static int tpm_ibmvtpm_remove(struct vio_dev *vdev)
>  static unsigned long tpm_ibmvtpm_get_desired_dma(struct vio_dev *vdev)
>  {
>   struct tpm_chip *chip = dev_get_drvdata(>dev);
> - struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(>dev);
> + struct ibmvtpm_dev *ibmvtpm;
>  
>   /*
>* ibmvtpm initializes at probe time, so the data we are
>* asking for may not be set yet. Estimate that 4K required
>* for TCE-mapped buffer in addition to CRQ.
>*/
> - if (!ibmvtpm)
> + if (chip)
> + ibmvtpm = dev_get_drvdata(>dev);
> + else
>   return CRQ_RES_BUF_SIZE + PAGE_SIZE;
>  
>   return CRQ_RES_BUF_SIZE + ibmvtpm->rtce_size;
> -- 
> 1.7.1
> 

--
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


Re: [tpmdd-devel] [PATCH v1 1/2] tpm: msleep() delays - replace with usleep_range() in i2c nuvoton driver

2017-03-15 Thread Nayna


On 03/15/2017 09:22 PM, Jarkko Sakkinen wrote:
> On Fri, Mar 10, 2017 at 01:45:53PM -0500, Nayna Jain wrote:
>> Commit 500462a9de65 "timers: Switch to a non-cascading wheel" replaced
>> the 'classic' timer wheel, which aimed for near 'exact' expiry of the
>> timers.  Their analysis was that the vast majority of timeout timers
>> are used as safeguards, not as real timers, and are cancelled or
>> rearmed before expiration.  The only exception noted to this were
>> networking timers with a small expiry time.
>>
>> Not included in the analysis was the TPM polling timer, which resulted
>> in a longer normal delay and, every so often, a very long delay.  The
>> non-cascading wheel delay is based on CONFIG_HZ.  For a description of
>> the different rings and their delays, refer to the comments in
>> kernel/time/timer.c.
>>
>> Below are the delays given for rings 0 - 2, which explains the longer
>> "normal" delays and the very, long delays as seen on systems with
>> CONFIG_HZ 250.
>>
>> * HZ 1000 steps
>>   * Level Offset  GranularityRange
>>   *  0  0 1 ms0 ms - 63 ms
>>   *  1 64 8 ms   64 ms - 511 ms
>>   *  212864 ms  512 ms - 4095 ms (512ms - ~4s)
>>
>> * HZ  250
>>   * Level Offset  GranularityRange
>>   *  0  0 4 ms0 ms - 255 ms
>>   *  1 6432 ms  256 ms - 2047 ms (256ms - ~2s)
>>   *  2128   256 ms 2048 ms - 16383 ms (~2s - ~16s)
>>
>> Below is a comparison of extending the TPM with 1000 measurements,
>> using msleep() vs. usleep_delay() when configured for 1000 hz vs. 250
>> hz, before and after commit 500462a9de65.
>>
>> linux-4.7 | msleep() usleep_range()
>> 1000 hz: 0m44.628s | 1m34.497s 29.243s
>> 250 hz: 1m28.510s | 4m49.269s 32.386s
>>
>> linux-4.7  | min-max (msleep)  min-max (usleep_range)
>> 1000 hz: 0:017 - 2:760s | 0:015 - 3:967s0:014 - 0:418s
>> 250 hz: 0:028 - 1:954s | 0:040 - 4:096s0:016 - 0:816s
>>
>> This patch replaces the msleep() with usleep_range() calls in the
>> i2c nuvoton driver with a consistent max range value.
>>
>> Signed-of-by: Mimi Zohar 
>> Cc: sta...@vger.kernel.org (linux-4.8)
>> Signed-off-by: Nayna Jain 
>> ---
>> Changelog v1:
>>
>> - Included Jason's feedbacks related to #defines.
>
> What was changed?
>

Changelog v1:
 >>
 >> - Included Jason's feedbacks related to #defines.

Based on Jason's review:
- Added () in #define
- Replaced hardcoded maximum range value with defined name.

Hmm.. could have included exact details.

Thanks & Regards,
- Nayna

> /Jarkko
>


--
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


Re: [tpmdd-devel] [PATCH v2 1/2] ACPICA: Update TPM2 ACPI table

2017-03-15 Thread Jarkko Sakkinen
On Tue, Mar 14, 2017 at 08:32:32PM -0500, Jiandi An wrote:
> TCG ACPI Specification Family "1.2" and "2.0" Version 1.2
> Revision 8 introduces new start method for ARM SMC.
> 
> - Add new start method (type 11) for ARM SMC
> - Add start method specific parameters for ARM SMC start method
> 
> Signed-off-by: Jiandi An 
> ---
>  drivers/char/tpm/tpm_crb.c |  6 +-
>  drivers/char/tpm/tpm_tis.c |  6 +-
>  include/acpi/actbl2.h  | 12 
>  3 files changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> index cb6fb13..089fcf8 100644
> --- a/drivers/char/tpm/tpm_crb.c
> +++ b/drivers/char/tpm/tpm_crb.c
> @@ -410,12 +410,16 @@ static int crb_acpi_add(struct acpi_device *device)
>   struct tpm_chip *chip;
>   struct device *dev = >dev;
>   acpi_status status;
> + u32 default_len;
>   u32 sm;
>   int rc;
>  
> + default_len = sizeof(struct acpi_table_tpm2) -
> +   sizeof(union platform_params);

Maybe you should consider not putting struct crb_smc to actbl2.h. This
makes tpm_crb.c a mess.

> +
>   status = acpi_get_table(ACPI_SIG_TPM2, 1,
>   (struct acpi_table_header **) );
> - if (ACPI_FAILURE(status) || buf->header.length < sizeof(*buf)) {
> + if (ACPI_FAILURE(status) || buf->header.length < default_len) {
>   dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
>   return -EINVAL;
>   }
> diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
> index c7e1384..0e2e5f6 100644
> --- a/drivers/char/tpm/tpm_tis.c
> +++ b/drivers/char/tpm/tpm_tis.c
> @@ -253,11 +253,15 @@ static int tpm_tis_acpi_init(struct acpi_device 
> *acpi_dev)
>   acpi_status st;
>   struct list_head resources;
>   struct tpm_info tpm_info = {};
> + u32 default_len;
>   int ret;
>  
> + default_len = sizeof(struct acpi_table_tpm2) -
> +   sizeof(union platform_params);
> +

And more clutter.

>   st = acpi_get_table(ACPI_SIG_TPM2, 1,
>   (struct acpi_table_header **) );
> - if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) {
> + if (ACPI_FAILURE(st) || tbl->header.length < default_len) {
>   dev_err(_dev->dev,
>   FW_BUG "failed to get TPM2 ACPI table\n");
>   return -EINVAL;
> diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h
> index 7aee9fb..9612049 100644
> --- a/include/acpi/actbl2.h
> +++ b/include/acpi/actbl2.h
> @@ -1277,6 +1277,14 @@ struct acpi_table_tcpa_server {
>   *
>   
> **/
>  
> +struct tpm2_crb_smc {
> + u32 interrupt;
> + u8 interrupt_flags;
> + u8 op_flags;
> + u16 reserved2;
> + u32 smc_func_id;
> +};
> +
>  struct acpi_table_tpm2 {
>   struct acpi_table_header header;/* Common ACPI table header */
>   u16 platform_class;
> @@ -1285,6 +1293,9 @@ struct acpi_table_tpm2 {
>   u32 start_method;
>  
>   /* Platform-specific data follows */
> + union platform_params {
> + struct tpm2_crb_smc smc_params;
> + } platform_data;

Why the union type is not anonymous? ACPICA change should be its
own commit.

/Jarkko

--
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


Re: [tpmdd-devel] [PATCH v1 1/2] tpm: msleep() delays - replace with usleep_range() in i2c nuvoton driver

2017-03-15 Thread Jarkko Sakkinen
On Fri, Mar 10, 2017 at 01:45:53PM -0500, Nayna Jain wrote:
> Commit 500462a9de65 "timers: Switch to a non-cascading wheel" replaced
> the 'classic' timer wheel, which aimed for near 'exact' expiry of the
> timers.  Their analysis was that the vast majority of timeout timers
> are used as safeguards, not as real timers, and are cancelled or
> rearmed before expiration.  The only exception noted to this were
> networking timers with a small expiry time.
> 
> Not included in the analysis was the TPM polling timer, which resulted
> in a longer normal delay and, every so often, a very long delay.  The
> non-cascading wheel delay is based on CONFIG_HZ.  For a description of
> the different rings and their delays, refer to the comments in
> kernel/time/timer.c.
> 
> Below are the delays given for rings 0 - 2, which explains the longer
> "normal" delays and the very, long delays as seen on systems with
> CONFIG_HZ 250.
> 
> * HZ 1000 steps
>  * Level Offset  GranularityRange
>  *  0  0 1 ms0 ms - 63 ms
>  *  1 64 8 ms   64 ms - 511 ms
>  *  212864 ms  512 ms - 4095 ms (512ms - ~4s)
> 
> * HZ  250
>  * Level Offset  GranularityRange
>  *  0  0 4 ms0 ms - 255 ms
>  *  1 6432 ms  256 ms - 2047 ms (256ms - ~2s)
>  *  2128   256 ms 2048 ms - 16383 ms (~2s - ~16s)
> 
> Below is a comparison of extending the TPM with 1000 measurements,
> using msleep() vs. usleep_delay() when configured for 1000 hz vs. 250
> hz, before and after commit 500462a9de65.
> 
> linux-4.7 | msleep() usleep_range()
> 1000 hz: 0m44.628s | 1m34.497s 29.243s
> 250 hz: 1m28.510s | 4m49.269s 32.386s
> 
> linux-4.7  | min-max (msleep)  min-max (usleep_range)
> 1000 hz: 0:017 - 2:760s | 0:015 - 3:967s0:014 - 0:418s
> 250 hz: 0:028 - 1:954s | 0:040 - 4:096s0:016 - 0:816s
> 
> This patch replaces the msleep() with usleep_range() calls in the
> i2c nuvoton driver with a consistent max range value.
> 
> Signed-of-by: Mimi Zohar 
> Cc: sta...@vger.kernel.org (linux-4.8)
> Signed-off-by: Nayna Jain 
> ---
> Changelog v1:
> 
> - Included Jason's feedbacks related to #defines.

What was changed?

/Jarkko

--
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


Re: [tpmdd-devel] [PATCH] tpm: select CONFIG_CRYPTO

2017-03-15 Thread Arnd Bergmann
On Wed, Mar 15, 2017 at 9:30 AM, Jarkko Sakkinen
 wrote:
> Arnd,
>
> On Tue, Mar 14, 2017 at 10:40:24PM +0100, Arnd Bergmann wrote:
>> As we need the CRYPTO_HASH_INFO implementation, we should also
>> select CRYPTO itself to avoid this build warning:
>>
>> warning: (TCG_TPM && TRUSTED_KEYS && IMA) selects CRYPTO_HASH_INFO which has 
>> unmet direct dependencies (CRYPTO)
>>
>> Fixes: c1f92b4b04ad ("tpm: enhance TPM 2.0 PCR extend to support multiple 
>> banks")
>> Signed-off-by: Arnd Bergmann 
>
> I've already merged this and put to my next branch.

Ah, I see my mistake: I had made an identical patch earlier, which you merged
into linux-next, and I dropped it from my series after rebasing on
-next, but then
rebased again on mainline and did the new patch without checking whether
it was already fixed in -next.

I guess the warning is rare enough that we don't really need this in v4.11
even though it does apply there.

Arnd

--
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


Re: [tpmdd-devel] [PATCH] tpm: select CONFIG_CRYPTO

2017-03-15 Thread Jarkko Sakkinen
Arnd,

On Tue, Mar 14, 2017 at 10:40:24PM +0100, Arnd Bergmann wrote:
> As we need the CRYPTO_HASH_INFO implementation, we should also
> select CRYPTO itself to avoid this build warning:
> 
> warning: (TCG_TPM && TRUSTED_KEYS && IMA) selects CRYPTO_HASH_INFO which has 
> unmet direct dependencies (CRYPTO)
> 
> Fixes: c1f92b4b04ad ("tpm: enhance TPM 2.0 PCR extend to support multiple 
> banks")
> Signed-off-by: Arnd Bergmann 

I've already merged this and put to my next branch.

/Jarkko

> ---
>  drivers/char/tpm/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
> index af985cca413c..d520ac51c11c 100644
> --- a/drivers/char/tpm/Kconfig
> +++ b/drivers/char/tpm/Kconfig
> @@ -6,6 +6,7 @@ menuconfig TCG_TPM
>   tristate "TPM Hardware Support"
>   depends on HAS_IOMEM
>   select SECURITYFS
> + select CRYPTO
>   select CRYPTO_HASH_INFO
>   ---help---
> If you have a TPM security chip in your system, which
> -- 
> 2.9.0
> 

--
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


Re: [tpmdd-devel] [PATCH v1] tpm/st33zp24: Add GPIO ACPI mapping table

2017-03-15 Thread Jarkko Sakkinen
On Mon, Mar 13, 2017 at 07:38:11PM +0200, Andy Shevchenko wrote:
> In order to make GPIO ACPI library stricter prepare users of
> gpiod_get_index() to correctly behave when there no mapping is
> provided by firmware.
> 
> Here we add explicit mapping between _CRS GpioIo() resources and
> their names used in the driver.
> 
> Signed-off-by: Andy Shevchenko 

Reviewed-by: Jarkko Sakkinen 

I do not have means to test this though.

/Jarkko

> ---
>  drivers/char/tpm/st33zp24/i2c.c | 23 ---
>  drivers/char/tpm/st33zp24/spi.c | 23 ---
>  2 files changed, 40 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c
> index 028a9cd76b63..349fc72447a1 100644
> --- a/drivers/char/tpm/st33zp24/i2c.c
> +++ b/drivers/char/tpm/st33zp24/i2c.c
> @@ -111,6 +111,13 @@ static const struct st33zp24_phy_ops i2c_phy_ops = {
>   .recv = st33zp24_i2c_recv,
>  };
>  
> +static const struct acpi_gpio_params lpcpd_gpios = { 1, 0, false };
> +
> +static const struct acpi_gpio_mapping acpi_st33zp24_gpios[] = {
> + { "lpcpd-gpios", _gpios, 1 },
> + {},
> +};
> +
>  static int st33zp24_i2c_acpi_request_resources(struct i2c_client *client)
>  {
>   struct tpm_chip *chip = i2c_get_clientdata(client);
> @@ -118,10 +125,14 @@ static int st33zp24_i2c_acpi_request_resources(struct 
> i2c_client *client)
>   struct st33zp24_i2c_phy *phy = tpm_dev->phy_id;
>   struct gpio_desc *gpiod_lpcpd;
>   struct device *dev = >dev;
> + int ret;
> +
> + ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), 
> acpi_st33zp24_gpios);
> + if (ret)
> + return ret;
>  
>   /* Get LPCPD GPIO from ACPI */
> - gpiod_lpcpd = devm_gpiod_get_index(dev, "TPM IO LPCPD", 1,
> -GPIOD_OUT_HIGH);
> + gpiod_lpcpd = devm_gpiod_get(dev, "lpcpd", GPIOD_OUT_HIGH);
>   if (IS_ERR(gpiod_lpcpd)) {
>   dev_err(>dev,
>   "Failed to retrieve lpcpd-gpios from acpi.\n");
> @@ -268,8 +279,14 @@ static int st33zp24_i2c_probe(struct i2c_client *client,
>  static int st33zp24_i2c_remove(struct i2c_client *client)
>  {
>   struct tpm_chip *chip = i2c_get_clientdata(client);
> + int ret;
>  
> - return st33zp24_remove(chip);
> + ret = st33zp24_remove(chip);
> + if (ret)
> + return ret;
> +
> + acpi_dev_remove_driver_gpios(ACPI_COMPANION(>dev));
> + return 0;
>  }
>  
>  static const struct i2c_device_id st33zp24_i2c_id[] = {
> diff --git a/drivers/char/tpm/st33zp24/spi.c b/drivers/char/tpm/st33zp24/spi.c
> index 9f5a0117098c..c69d15198f84 100644
> --- a/drivers/char/tpm/st33zp24/spi.c
> +++ b/drivers/char/tpm/st33zp24/spi.c
> @@ -230,6 +230,13 @@ static const struct st33zp24_phy_ops spi_phy_ops = {
>   .recv = st33zp24_spi_recv,
>  };
>  
> +static const struct acpi_gpio_params lpcpd_gpios = { 1, 0, false };
> +
> +static const struct acpi_gpio_mapping acpi_st33zp24_gpios[] = {
> + { "lpcpd-gpios", _gpios, 1 },
> + {},
> +};
> +
>  static int st33zp24_spi_acpi_request_resources(struct spi_device *spi_dev)
>  {
>   struct tpm_chip *chip = spi_get_drvdata(spi_dev);
> @@ -237,10 +244,14 @@ static int st33zp24_spi_acpi_request_resources(struct 
> spi_device *spi_dev)
>   struct st33zp24_spi_phy *phy = tpm_dev->phy_id;
>   struct gpio_desc *gpiod_lpcpd;
>   struct device *dev = _dev->dev;
> + int ret;
> +
> + ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), 
> acpi_st33zp24_gpios);
> + if (ret)
> + return ret;
>  
>   /* Get LPCPD GPIO from ACPI */
> - gpiod_lpcpd = devm_gpiod_get_index(dev, "TPM IO LPCPD", 1,
> -GPIOD_OUT_HIGH);
> + gpiod_lpcpd = devm_gpiod_get(dev, "lpcpd", GPIOD_OUT_HIGH);
>   if (IS_ERR(gpiod_lpcpd)) {
>   dev_err(dev, "Failed to retrieve lpcpd-gpios from acpi.\n");
>   phy->io_lpcpd = -1;
> @@ -385,8 +396,14 @@ static int st33zp24_spi_probe(struct spi_device *dev)
>  static int st33zp24_spi_remove(struct spi_device *dev)
>  {
>   struct tpm_chip *chip = spi_get_drvdata(dev);
> + int ret;
>  
> - return st33zp24_remove(chip);
> + ret = st33zp24_remove(chip);
> + if (ret)
> + return ret;
> +
> + acpi_dev_remove_driver_gpios(ACPI_COMPANION(>dev));
> + return 0;
>  }
>  
>  static const struct spi_device_id st33zp24_spi_id[] = {
> -- 
> 2.11.0
> 

--
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