Skip to content

Commit 15b81ce

Browse files
a-darwishaxboe
authored andcommitted
block: nr_sects_write(): Disable preemption on seqcount write
For optimized block readers not holding a mutex, the "number of sectors" 64-bit value is protected from tearing on 32-bit architectures by a sequence counter. Disable preemption before entering that sequence counter's write side critical section. Otherwise, the read side can preempt the write side section and spin for the entire scheduler tick. If the reader belongs to a real-time scheduling class, it can spin forever and the kernel will livelock. Fixes: c83f6bf ("block: add partition resize function to blkpg ioctl") Cc: <[email protected]> Signed-off-by: Ahmed S. Darwish <[email protected]> Reviewed-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent d24de76 commit 15b81ce

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

block/blk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,11 @@ static inline sector_t part_nr_sects_read(struct hd_struct *part)
420420
static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
421421
{
422422
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
423+
preempt_disable();
423424
write_seqcount_begin(&part->nr_sects_seq);
424425
part->nr_sects = size;
425426
write_seqcount_end(&part->nr_sects_seq);
427+
preempt_enable();
426428
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
427429
preempt_disable();
428430
part->nr_sects = size;

0 commit comments

Comments
 (0)