On Tue, Sep 02, 2025 at 06:27:10PM +0100, Jonathan McDowell wrote: > From: Jonathan McDowell <nood...@meta.com> > > There are situations where userspace might reasonably desire exclusive > access to the TPM, or the kernel's internal context saving + flushing > may cause issues, for example when performing firmware upgrades. Extend > the locking already used for avoiding concurrent userspace access to > prevent internal users of the TPM when /dev/tpm<n> is in use. > > The few internal users who already hold the open_lock are changed to use > tpm_internal_(try_get|put)_ops, with the old tpm_(try_get|put)_ops > functions changing to obtain read access to the open_lock. We return > -EBUSY when another user has exclusive access, rather than adding waits. > > Signed-off-by: Jonathan McDowell <nood...@meta.com> > --- > drivers/char/tpm/tpm-chip.c | 53 +++++++++++++++++++++++++------ > drivers/char/tpm/tpm-dev-common.c | 8 ++--- > drivers/char/tpm/tpm.h | 2 ++ > drivers/char/tpm/tpm2-space.c | 5 ++- > 4 files changed, 52 insertions(+), 16 deletions(-) > > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c > index ba906966721a..3d69ccff4c2a 100644 > --- a/drivers/char/tpm/tpm-chip.c > +++ b/drivers/char/tpm/tpm-chip.c > @@ -144,7 +144,7 @@ void tpm_chip_stop(struct tpm_chip *chip) > EXPORT_SYMBOL_GPL(tpm_chip_stop); > > /** > - * tpm_try_get_ops() - Get a ref to the tpm_chip > + * tpm_internal_try_get_ops() - Get a ref to the tpm_chip > * @chip: Chip to ref > * > * The caller must already have some kind of locking to ensure that chip is > @@ -154,7 +154,7 @@ EXPORT_SYMBOL_GPL(tpm_chip_stop); > * > * Returns -ERRNO if the chip could not be got. > */ > -int tpm_try_get_ops(struct tpm_chip *chip) > +int tpm_internal_try_get_ops(struct tpm_chip *chip)
I'd rather name the new function e.g., tpm_try_get_ops_locked. Like both from the perspective of more localized patch and also that "locked" documents more tan "internal". BR, Jarkko