lkml.org 
[lkml]   [2022]   [Oct]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v8 08/11] tpm, tpm: Implement usage counter for locality
On Tue, Oct 18, 2022 at 01:57:29AM +0200, Lino Sanfilippo wrote:
> Implement a usage counter for the (default) locality used by the TPM TIS
> driver:
> Request the locality from the TPM if it has not been claimed yet, otherwise
> only increment the counter. Also release the locality if the counter is 0
> otherwise only decrement the counter. Ensure thread-safety by protecting
> the counter with a mutex.
>
> This allows to request and release the locality from a thread and the
> interrupt handler at the same time without the danger to interfere with
> each other.
[...]
> +static int tpm_tis_release_locality(struct tpm_chip *chip, int l)
> {
> struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>
> - tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY);
> + mutex_lock(&priv->locality_count_mutex);
> + priv->locality_count--;
> + if (priv->locality_count == 0)
> + tpm_tis_release_locality_locked(priv, l);
> + mutex_unlock(&priv->locality_count_mutex);
>
> return 0;
> }

Hm, any reason not to use struct kref for the locality counter?
Provides correct memory ordering (no mutex needed) and allows for
calling a release function too upon reaching 0.

Thanks,

Lukas

\
 
 \ /
  Last update: 2022-10-18 08:25    [W:0.154 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site