All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ata: ata_piix: Fix a possible data race in piix_pci_device_resume
@ 2018-05-08  3:46 Jia-Ju Bai
  2018-05-08 14:20 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2018-05-08  3:46 UTC (permalink / raw)
  To: tj; +Cc: linux-ide, linux-kernel, Jia-Ju Bai

The write operation to "host->flags" is protected by
the lock on line 1048, but the read operation to
this data on line 1046 is not protected by the lock.
Thus, there may exist a data race for "host->flags".

To fix this data race, the read operation to "host->flags" 
should be also protected by the lock.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/ata/ata_piix.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 7ecb1322a514..c99fdf473dee 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -1043,8 +1043,8 @@ static int piix_pci_device_resume(struct pci_dev *pdev)
 	unsigned long flags;
 	int rc;
 
+	spin_lock_irqsave(&host->lock, flags);
 	if (host->flags & PIIX_HOST_BROKEN_SUSPEND) {
-		spin_lock_irqsave(&host->lock, flags);
 		host->flags &= ~PIIX_HOST_BROKEN_SUSPEND;
 		spin_unlock_irqrestore(&host->lock, flags);
 
@@ -1060,8 +1060,10 @@ static int piix_pci_device_resume(struct pci_dev *pdev)
 			dev_err(&pdev->dev,
 				"failed to enable device after resume (%d)\n",
 				rc);
-	} else
+	} else {
+		spin_unlock_irqrestore(&host->lock, flags);
 		rc = ata_pci_device_do_resume(pdev);
+	}
 
 	if (rc == 0)
 		ata_host_resume(host);
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ata: ata_piix: Fix a possible data race in piix_pci_device_resume
  2018-05-08  3:46 [PATCH] ata: ata_piix: Fix a possible data race in piix_pci_device_resume Jia-Ju Bai
@ 2018-05-08 14:20 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2018-05-08 14:20 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: linux-ide, linux-kernel

Hello,

On Tue, May 08, 2018 at 11:46:13AM +0800, Jia-Ju Bai wrote:
> The write operation to "host->flags" is protected by
> the lock on line 1048, but the read operation to
> this data on line 1046 is not protected by the lock.
> Thus, there may exist a data race for "host->flags".
> 
> To fix this data race, the read operation to "host->flags" 
> should be also protected by the lock.

This isn't necessarily wrong.  It isn't different from atomic bitops -
the modifications are synchronized but what the reads get is
determined by memory ordering or other synchronization.  Here, the
whole suspend / resume paths are always synchronized and the spinlocks
are there just in case there are other writers to the field.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-08 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-08  3:46 [PATCH] ata: ata_piix: Fix a possible data race in piix_pci_device_resume Jia-Ju Bai
2018-05-08 14:20 ` Tejun Heo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.