If a direct IO requires bounced pages for stable buffer, it will always allocate memory, and both bio_iov_iter_bounce_write() and bio_iov_iter_bounce_read() are allocating pages using GFP_KERNEL, which can sleep and break NOWAIT requirement. So we need to reject such NOWAIT and BOUNCE direct IO in iomap_dio_bio_iter(). Signed-off-by: Qu Wenruo --- fs/iomap/direct-io.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index b36ee619cdcd..d1601122f0b5 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -412,6 +412,10 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio) unsigned int alignment; ssize_t ret = 0; + /* Bounced direct IO will need to allocate memory, breaking NOWAIT flag. */ + if (unlikely(iter->flags & IOMAP_NOWAIT && dio->flags & IOMAP_DIO_BOUNCE)) + return -EAGAIN; + /* * File systems that write out of place and always allocate new blocks * need each bio to be block aligned as that's the unit of allocation. -- 2.54.0