Skip to content

Commit 10eb3a0

Browse files
bmarzinsMike Snitzer
authored andcommitted
dm: fix race in dm_start_io_acct
After commit 82f6cdc ("dm: switch dm_io booleans over to proper flags") dm_start_io_acct stopped atomically checking and setting was_accounted, which turned into the DM_IO_ACCOUNTED flag. This opened the possibility for a race where IO accounting is started twice for duplicate bios. To remove the race, check the flag while holding the io->lock. Fixes: 82f6cdc ("dm: switch dm_io booleans over to proper flags") Cc: stable@vger.kernel.org Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent b13bacc commit 10eb3a0

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/md/dm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ static void dm_start_io_acct(struct dm_io *io, struct bio *clone)
555555
unsigned long flags;
556556
/* Can afford locking given DM_TIO_IS_DUPLICATE_BIO */
557557
spin_lock_irqsave(&io->lock, flags);
558+
if (dm_io_flagged(io, DM_IO_ACCOUNTED)) {
559+
spin_unlock_irqrestore(&io->lock, flags);
560+
return;
561+
}
558562
dm_io_set_flag(io, DM_IO_ACCOUNTED);
559563
spin_unlock_irqrestore(&io->lock, flags);
560564
}

0 commit comments

Comments
 (0)