2021-05-01 14:03:24

by Lino Sanfilippo

[permalink] [raw]
Subject: [PATCH v3 1/4] tpm: Use a threaded interrupt handler

The interrupt handler uses tpm_tis_read32() and tpm_tis_write32() to access
the interrupt status register. In case of SPI those accesses are done with
the spi_bus_lock mutex held. This means that the status register cannot
be read or written in interrupt context.

For this reason request a threaded interrupt handler so that the required
accesses can be done in process context.

Reviewed-by: Stefan Berger <[email protected]>
Signed-off-by: Lino Sanfilippo <[email protected]>
---
drivers/char/tpm/tpm_tis_core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index a2e0395cbe61..a12992ae2a3e 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -737,8 +737,10 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,
int rc;
u32 int_status;

- if (devm_request_irq(chip->dev.parent, irq, tis_int_handler, flags,
- dev_name(&chip->dev), chip) != 0) {
+
+ if (devm_request_threaded_irq(chip->dev.parent, irq, NULL,
+ tis_int_handler, IRQF_ONESHOT | flags,
+ dev_name(&chip->dev), chip) != 0) {
dev_info(&chip->dev, "Unable to request irq: %d for probe\n",
irq);
return -1;
--
2.31.1


2021-05-03 18:11:25

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH v3 1/4] tpm: Use a threaded interrupt handler

On Sat, May 01, 2021 at 03:57:24PM +0200, Lino Sanfilippo wrote:
> The interrupt handler uses tpm_tis_read32() and tpm_tis_write32() to access
> the interrupt status register. In case of SPI those accesses are done with
> the spi_bus_lock mutex held. This means that the status register cannot
> be read or written in interrupt context.
>
> For this reason request a threaded interrupt handler so that the required
> accesses can be done in process context.
>
> Reviewed-by: Stefan Berger <[email protected]>
> Signed-off-by: Lino Sanfilippo <[email protected]>

No fixes tag.

The short summary scopes now the whole TPM subsystem ("tpm:"), but the fix
is targetted *only* for tpm_tis_spi. How about "tpm, tpm_tis_spi: Allow to
sleep in the interrupt handler"?

This also changes the semantics tpm_tis_*, not just tpm_tis_spi, which is
not acceptable. We cannot backport a fix like this.

Probably you should just add a parameter to tpm_tis_core_init() to hint
that threaded IRQ is required, and then only conditionally do so.

/Jarkko

2021-05-04 23:51:23

by Lino Sanfilippo

[permalink] [raw]
Subject: Re: [PATCH v3 1/4] tpm: Use a threaded interrupt handler


Hi,


On 03.05.21 at 17:14, Jarkko Sakkinen wrote:
> On Sat, May 01, 2021 at 03:57:24PM +0200, Lino Sanfilippo wrote:
>> The interrupt handler uses tpm_tis_read32() and tpm_tis_write32() to access
>> the interrupt status register. In case of SPI those accesses are done with
>> the spi_bus_lock mutex held. This means that the status register cannot
>> be read or written in interrupt context.
>>
>> For this reason request a threaded interrupt handler so that the required
>> accesses can be done in process context.
>>
>> Reviewed-by: Stefan Berger <[email protected]>
>> Signed-off-by: Lino Sanfilippo <[email protected]>
>
> No fixes tag.
>
> The short summary scopes now the whole TPM subsystem ("tpm:"), but the fix
> is targetted *only* for tpm_tis_spi. How about "tpm, tpm_tis_spi: Allow to
> sleep in the interrupt handler"?
>
> This also changes the semantics tpm_tis_*, not just tpm_tis_spi, which is
> not acceptable. We cannot backport a fix like this.
>
> Probably you should just add a parameter to tpm_tis_core_init() to hint
> that threaded IRQ is required, and then only conditionally do so.
>

Sure, this is doable although to be honest I dont see the issue with also the
non-SPI code running in the threaded interrupt handler. The functionality should
not change (especially since interrupts are not even working right now) and it would
save us a special treatment of the SPI case.


Regards,
Lino

2021-05-06 01:48:23

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH v3 1/4] tpm: Use a threaded interrupt handler

On Wed, May 05, 2021 at 12:54:37AM +0200, Lino Sanfilippo wrote:
>
> Hi,
>
>
> On 03.05.21 at 17:14, Jarkko Sakkinen wrote:
> > On Sat, May 01, 2021 at 03:57:24PM +0200, Lino Sanfilippo wrote:
> >> The interrupt handler uses tpm_tis_read32() and tpm_tis_write32() to access
> >> the interrupt status register. In case of SPI those accesses are done with
> >> the spi_bus_lock mutex held. This means that the status register cannot
> >> be read or written in interrupt context.
> >>
> >> For this reason request a threaded interrupt handler so that the required
> >> accesses can be done in process context.
> >>
> >> Reviewed-by: Stefan Berger <[email protected]>
> >> Signed-off-by: Lino Sanfilippo <[email protected]>
> >
> > No fixes tag.
> >
> > The short summary scopes now the whole TPM subsystem ("tpm:"), but the fix
> > is targetted *only* for tpm_tis_spi. How about "tpm, tpm_tis_spi: Allow to
> > sleep in the interrupt handler"?
> >
> > This also changes the semantics tpm_tis_*, not just tpm_tis_spi, which is
> > not acceptable. We cannot backport a fix like this.
> >
> > Probably you should just add a parameter to tpm_tis_core_init() to hint
> > that threaded IRQ is required, and then only conditionally do so.
> >
>
> Sure, this is doable although to be honest I dont see the issue with also the
> non-SPI code running in the threaded interrupt handler. The functionality should
> not change (especially since interrupts are not even working right now) and it would
> save us a special treatment of the SPI case.

It's violation of "3) Separate your changes" [*].

E.g. we do not want to introduce "improvements" or "simplifications" to
stable kernels on purpose.

[*] https://www.kernel.org/doc/html/v5.11/process/submitting-patches.html>

/Jarkko