Enabling interrupts in QEMU TPM TIS

From: Stefan Berger
Date: Thu Jun 25 2020 - 10:56:50 EST


Hello!

ÂI want to enable IRQs now in QEMU's TPM TIS device model and I need to work with the following patch to Linux TIS. I am wondering whether the changes there look reasonable to you? Windows works with the QEMU modifications as-is, so maybe it's a bug in the TIS code (which I had not run into before).


The point of the loop I need to introduce in the interrupt handler is that while the interrupt handler is running another interrupt may occur/be posted that then does NOT cause the interrupt handler to be invoked again but causes a stall, unless the loop is there.

The 'o' in the dmesg log indicates the original IRQ for which the handler was invoked. The interrupt values have the following meaning.

0x2: STS valid

0x4: locality changed

0x80: command ready

So the first 'looping entry' [in log below] indicates that a locality change interrupt occurred while the interrupt handler was running due to STS_valid + command ready. This sounds reasonable considering that we are frequently acquiring and releasing the locality. The loop then deals with the locality change interrupt and the interrupts then settle.

[Â 210.365129] tpm_tis MSFT0101:00: 2.0 TPM (device-id 0x1, rev-id 1)
[Â 210.367124] looping: 0x4Â (o: 0x82)
[Â 212.375045] looping: 0x80Â (o: 0x2)
[Â 212.389218] looping: 0x4Â (o: 0x82)
[Â 212.404161] looping: 0x80Â (o: 0x2)
[Â 212.526427] looping: 0x4Â (o: 0x82)
[Â 212.595488] looping: 0x4Â (o: 0x82)
[Â 212.614357] looping: 0x80Â (o: 0x2)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 65ab1b027949..f77544563fb1 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -704,7 +704,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id)
Â{
ÂÂÂÂ struct tpm_chip *chip = dev_id;
ÂÂÂÂ struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
-ÂÂÂ u32 interrupt;
+ÂÂÂ u32 interrupt, o;
ÂÂÂÂ int i, rc;

ÂÂÂÂ rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt);
@@ -715,6 +715,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id)
ÂÂÂÂ ÂÂÂ return IRQ_NONE;

ÂÂÂÂ priv->irq_tested = true;
+again:
ÂÂÂÂ if (interrupt & TPM_INTF_DATA_AVAIL_INT)
ÂÂÂÂ ÂÂÂ wake_up_interruptible(&priv->read_queue);
ÂÂÂÂ if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
@@ -731,7 +732,12 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id)
ÂÂÂÂ if (rc < 0)
ÂÂÂÂ ÂÂÂ return IRQ_NONE;

+ÂÂÂ o = interrupt;
ÂÂÂÂ tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt);
+ÂÂÂ if (interrupt != 0) {
+  printk("looping: 0x%x (o: 0x%x)\n", interrupt, o);
+ÂÂÂ ÂÂÂ goto again;
+ÂÂÂ }
ÂÂÂÂ return IRQ_HANDLED;
Â}

@@ -1062,6 +1068,8 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
ÂÂÂÂ ÂÂÂ ÂÂÂ goto out_err;
ÂÂÂÂ ÂÂÂ }

+ÂÂÂ ÂÂÂ tpm_chip_start(chip);
+ÂÂÂ ÂÂÂ chip->flags |= TPM_CHIP_FLAG_IRQ;
ÂÂÂÂ ÂÂÂ if (irq) {
ÂÂÂÂ ÂÂÂ ÂÂÂ tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
ÂÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ Âirq);
@@ -1074,6 +1082,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
ÂÂÂÂ ÂÂÂ } else {
ÂÂÂÂ ÂÂÂ ÂÂÂ tpm_tis_probe_irq(chip, intmask);
ÂÂÂÂ ÂÂÂ }
+ÂÂÂ ÂÂÂ tpm_chip_stop(chip);
ÂÂÂÂ }

ÂÂÂÂ rc = tpm_chip_register(chip);
--
2.26.2

ÂÂ Stefan