Skip to content

Commit 2bc0576

Browse files
committed
block: don't make REQ_POLLED imply REQ_NOWAIT
Normally these two flags do go together, as the issuer of polled IO generally cannot wait for resources that will get freed as part of IO completion. This is because that very task is the one that will complete the request and free those resources, hence that would introduce a deadlock. But it is possible to have someone else issue the polled IO, eg via io_uring if the request is punted to io-wq. For that case, it's fine to have the task block on IO submission, as it is not the same task that will be completing the IO. It's completely up to the caller to ask for both polled and nowait IO separately! If we don't allow polled IO where IOCB_NOWAIT isn't set in the kiocb, then we can run into repeated -EAGAIN submissions and not make any progress. Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d74f714 commit 2bc0576

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

block/fops.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,14 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
358358
task_io_account_write(bio->bi_iter.bi_size);
359359
}
360360

361+
if (iocb->ki_flags & IOCB_NOWAIT)
362+
bio->bi_opf |= REQ_NOWAIT;
363+
361364
if (iocb->ki_flags & IOCB_HIPRI) {
362-
bio->bi_opf |= REQ_POLLED | REQ_NOWAIT;
365+
bio->bi_opf |= REQ_POLLED;
363366
submit_bio(bio);
364367
WRITE_ONCE(iocb->private, bio);
365368
} else {
366-
if (iocb->ki_flags & IOCB_NOWAIT)
367-
bio->bi_opf |= REQ_NOWAIT;
368369
submit_bio(bio);
369370
}
370371
return -EIOCBQUEUED;

include/linux/bio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ static inline int bio_integrity_add_page(struct bio *bio, struct page *page,
791791
static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb)
792792
{
793793
bio->bi_opf |= REQ_POLLED;
794-
if (!is_sync_kiocb(kiocb))
794+
if (kiocb->ki_flags & IOCB_NOWAIT)
795795
bio->bi_opf |= REQ_NOWAIT;
796796
}
797797

0 commit comments

Comments
 (0)