Skip to contentSkip to conversation

tpm: Remove ineffective wmb() from tpm_pm_resume()

PATCH Superseded Richard Lyu 2 participants 5 messages Sep 8 – Sep 18

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm: Remove ineffective wmb() from tpm_pm_resume()

The comment above the wmb() in tpm_pm_resume() states that the barrier guarantees TPM_CHIP_FLAG_SUSPENDED is written last, so that hwrng does not activate before the chip has been fully resumed. It cannot do so:
it is placed after the store that clears the flag, and therefore does not order the preceding resume work before that store. It also has nothing to pair with, as tpm_try_get_ops() contains no matching read barrier.

Drop the barrier along with the comment rather than leave a no-op behind. Should such ordering turn out to be needed, it would require paired barriers or locking.

Fixes 99d464506255 ("tpm: Prevent hwrng from activating during resume")
---
 drivers/char/tpm/tpm-interface.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/char/tpm/tpm-interface.c +0 -6
index b4e749e70b02..0bab78c8767c 100644
@@ -497,12 +497,6 @@ int tpm_pm_resume(struct device *dev)
 
 	chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED;
 
-	/*
-	 * Guarantee that SUSPENDED is written last, so that hwrng does not
-	 * activate before the chip has been fully resumed.
-	 */
-	wmb();
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(tpm_pm_resume);
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 8 lines · Richard Lyu

The comment above the wmb() in tpm_pm_resume() states that the barrier guarantees TPM_CHIP_FLAG_SUSPENDED is written last, so that hwrng does not activate before the chip has been fully resumed. It cannot do so:
it is placed after the store that clears the flag, and therefore does not order the preceding resume work before that store. It also has nothing to pair with, as tpm_try_get_ops() contains no matching read barrier.

Quoted 7 lines

Drop the barrier along with the comment rather than leave a no-op behind. Should such ordering turn out to be needed, it would require paired barriers or locking.

Fixes 99d464506255 ("tpm: Prevent hwrng from activating during resume")

I agree that wmb() is necessary but what is the bug here?

Agree with the change but I'm not convinced about fixes tag here.

Quoted 24 lines
---
 drivers/char/tpm/tpm-interface.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/char/tpm/tpm-interface.c +0 -6
index b4e749e70b02..0bab78c8767c 100644
@@ -497,12 +497,6 @@ int tpm_pm_resume(struct device *dev)
 
 	chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED;
 
-	/*
-	 * Guarantee that SUSPENDED is written last, so that hwrng does not
-	 * activate before the chip has been fully resumed.
-	 */
-	wmb();
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(tpm_pm_resume);
Signature · 1 line
2.51.0

BR, Jarkko

#2 lore raw
Quoted 13 lines · Jarkko Sakkinen
Quoted 12 lines · Richard Lyu

The comment above the wmb() in tpm_pm_resume() states that the barrier guarantees TPM_CHIP_FLAG_SUSPENDED is written last, so that hwrng does not activate before the chip has been fully resumed. It cannot do so:
it is placed after the store that clears the flag, and therefore does not order the preceding resume work before that store. It also has nothing to pair with, as tpm_try_get_ops() contains no matching read barrier.

Drop the barrier along with the comment rather than leave a no-op behind. Should such ordering turn out to be needed, it would require paired barriers or locking.

Quoted 7 lines
Quoted 3 lines
Fixes 99d464506255 ("tpm: Prevent hwrng from activating during resume")

I agree that wmb() is necessary but what is the bug here?

Agree with the change but I'm not convinced about fixes tag here.

You're right. There is no actual bug being fixed here, so a Fixes tag is not needed. This patch only removes redundant code. I will send a v2 without the tag.

Best Regards,
Richard Lyu

#3 lore raw

PATCH v2 1/1 tpm: Remove ineffective wmb() from tpm_pm_resume()

The comment above the wmb() in tpm_pm_resume() states that the barrier guarantees TPM_CHIP_FLAG_SUSPENDED is written last, so that hwrng does not activate before the chip has been fully resumed. It cannot do so:
it is placed after the store that clears the flag, and therefore does not order the preceding resume work before that store. It also has nothing to pair with, as tpm_try_get_ops() contains no matching read barrier.

Drop the barrier along with the comment rather than leave a no-op behind. Should such ordering turn out to be needed, it would require paired barriers or locking.

---
v2:
- Drop the Fixes tag: this is a cleanup, not a bug fix.
- Link to v1: https://lore.kernel.org/all/aqIVn0cDBvIYKggE@r1chard/

---
 drivers/char/tpm/tpm-interface.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/char/tpm/tpm-interface.c +0 -6
index b4e749e70b02..0bab78c8767c 100644
@@ -497,12 +497,6 @@ int tpm_pm_resume(struct device *dev)
 
 	chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED;
 
-	/*
-	 * Guarantee that SUSPENDED is written last, so that hwrng does not
-	 * activate before the chip has been fully resumed.
-	 */
-	wmb();
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(tpm_pm_resume);
Signature · 1 line
2.51.0
maintainer Reviewed-by on v2 1/1
#4 lore raw
Quoted 43 lines · Richard Lyu

The comment above the wmb() in tpm_pm_resume() states that the barrier guarantees TPM_CHIP_FLAG_SUSPENDED is written last, so that hwrng does not activate before the chip has been fully resumed. It cannot do so:
it is placed after the store that clears the flag, and therefore does not order the preceding resume work before that store. It also has nothing to pair with, as tpm_try_get_ops() contains no matching read barrier.

Drop the barrier along with the comment rather than leave a no-op behind. Should such ordering turn out to be needed, it would require paired barriers or locking.

---
v2:
- Drop the Fixes tag: this is a cleanup, not a bug fix.
- Link to v1: https://lore.kernel.org/all/aqIVn0cDBvIYKggE@r1chard/

---
 drivers/char/tpm/tpm-interface.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/char/tpm/tpm-interface.c +0 -6
index b4e749e70b02..0bab78c8767c 100644
@@ -497,12 +497,6 @@ int tpm_pm_resume(struct device *dev)
 
 	chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED;
 
-	/*
-	 * Guarantee that SUSPENDED is written last, so that hwrng does not
-	 * activate before the chip has been fully resumed.
-	 */
-	wmb();
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(tpm_pm_resume);
Signature · 1 line
2.51.0

BR, Jarkko