Skip to content

Commit cba5826

Browse files
committed
Merge tag 'tpmdd-v6.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull tpm fixes from Jarkko Sakkinen: "Three bug fixes for recently discovered issues" * tag 'tpmdd-v6.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: tpm/tpm_tis: Disable interrupts for more Lenovo devices tpm: Prevent hwrng from activating during resume tpm_tis: Use tpm_chip_{start,stop} decoration inside tpm_tis_resume
2 parents a18ef64 + e7d3e5c commit cba5826

File tree

5 files changed

+50
-24
lines changed

5 files changed

+50
-24
lines changed

drivers/char/tpm/tpm-chip.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
571571
{
572572
struct tpm_chip *chip = container_of(rng, struct tpm_chip, hwrng);
573573

574+
/* Give back zero bytes, as TPM chip has not yet fully resumed: */
575+
if (chip->flags & TPM_CHIP_FLAG_SUSPENDED)
576+
return 0;
577+
574578
return tpm_get_random(chip, data, max);
575579
}
576580

drivers/char/tpm/tpm-interface.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ int tpm_pm_suspend(struct device *dev)
412412
}
413413

414414
suspended:
415+
chip->flags |= TPM_CHIP_FLAG_SUSPENDED;
416+
415417
if (rc)
416418
dev_err(dev, "Ignoring error %d while suspending\n", rc);
417419
return 0;
@@ -429,6 +431,14 @@ int tpm_pm_resume(struct device *dev)
429431
if (chip == NULL)
430432
return -ENODEV;
431433

434+
chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED;
435+
436+
/*
437+
* Guarantee that SUSPENDED is written last, so that hwrng does not
438+
* activate before the chip has been fully resumed.
439+
*/
440+
wmb();
441+
432442
return 0;
433443
}
434444
EXPORT_SYMBOL_GPL(tpm_pm_resume);

drivers/char/tpm/tpm_tis.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ static const struct dmi_system_id tpm_tis_dmi_table[] = {
122122
DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T490s"),
123123
},
124124
},
125+
{
126+
.callback = tpm_tis_disable_irq,
127+
.ident = "ThinkStation P360 Tiny",
128+
.matches = {
129+
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
130+
DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkStation P360 Tiny"),
131+
},
132+
},
133+
{
134+
.callback = tpm_tis_disable_irq,
135+
.ident = "ThinkPad L490",
136+
.matches = {
137+
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
138+
DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad L490"),
139+
},
140+
},
125141
{}
126142
};
127143

drivers/char/tpm/tpm_tis_core.c

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,53 +1209,48 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip)
12091209
u32 intmask;
12101210
int rc;
12111211

1212-
if (chip->ops->clk_enable != NULL)
1213-
chip->ops->clk_enable(chip, true);
1214-
1215-
/* reenable interrupts that device may have lost or
1216-
* BIOS/firmware may have disabled
1212+
/*
1213+
* Re-enable interrupts that device may have lost or BIOS/firmware may
1214+
* have disabled.
12171215
*/
12181216
rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), priv->irq);
1219-
if (rc < 0)
1220-
goto out;
1217+
if (rc < 0) {
1218+
dev_err(&chip->dev, "Setting IRQ failed.\n");
1219+
return;
1220+
}
12211221

12221222
intmask = priv->int_mask | TPM_GLOBAL_INT_ENABLE;
1223-
1224-
tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
1225-
1226-
out:
1227-
if (chip->ops->clk_enable != NULL)
1228-
chip->ops->clk_enable(chip, false);
1229-
1230-
return;
1223+
rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
1224+
if (rc < 0)
1225+
dev_err(&chip->dev, "Enabling interrupts failed.\n");
12311226
}
12321227

12331228
int tpm_tis_resume(struct device *dev)
12341229
{
12351230
struct tpm_chip *chip = dev_get_drvdata(dev);
12361231
int ret;
12371232

1238-
ret = tpm_tis_request_locality(chip, 0);
1239-
if (ret < 0)
1233+
ret = tpm_chip_start(chip);
1234+
if (ret)
12401235
return ret;
12411236

12421237
if (chip->flags & TPM_CHIP_FLAG_IRQ)
12431238
tpm_tis_reenable_interrupts(chip);
12441239

1245-
ret = tpm_pm_resume(dev);
1246-
if (ret)
1247-
goto out;
1248-
12491240
/*
12501241
* TPM 1.2 requires self-test on resume. This function actually returns
12511242
* an error code but for unknown reason it isn't handled.
12521243
*/
12531244
if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
12541245
tpm1_do_selftest(chip);
1255-
out:
1256-
tpm_tis_relinquish_locality(chip, 0);
12571246

1258-
return ret;
1247+
tpm_chip_stop(chip);
1248+
1249+
ret = tpm_pm_resume(dev);
1250+
if (ret)
1251+
return ret;
1252+
1253+
return 0;
12591254
}
12601255
EXPORT_SYMBOL_GPL(tpm_tis_resume);
12611256
#endif

include/linux/tpm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ enum tpm_chip_flags {
282282
TPM_CHIP_FLAG_ALWAYS_POWERED = BIT(5),
283283
TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED = BIT(6),
284284
TPM_CHIP_FLAG_FIRMWARE_UPGRADE = BIT(7),
285+
TPM_CHIP_FLAG_SUSPENDED = BIT(8),
285286
};
286287

287288
#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)

0 commit comments

Comments
 (0)