Re: [PATCH] fs: Fix jfs_fsync() Sleeping in Invalid Context
From: Matthew Wilcox
Date: Tue Mar 25 2025 - 14:16:16 EST
On Tue, Mar 25, 2025 at 11:03:36PM +0530, Purva Yeshi wrote:
> +++ b/fs/direct-io.c
> @@ -356,13 +356,9 @@ static void dio_bio_end_aio(struct bio *bio)
> defer_completion = dio->defer_completion ||
> (dio_op == REQ_OP_WRITE &&
> dio->inode->i_mapping->nrpages);
> - if (defer_completion) {
> - INIT_WORK(&dio->complete_work, dio_aio_complete_work);
> - queue_work(dio->inode->i_sb->s_dio_done_wq,
> - &dio->complete_work);
> - } else {
> - dio_complete(dio, 0, DIO_COMPLETE_ASYNC);
> - }
> +
> + INIT_WORK(&dio->complete_work, dio_aio_complete_work);
> + queue_work(dio->inode->i_sb->s_dio_done_wq, &dio->complete_work);
This patch is definitely wrong. If it were the right thing to do, then
since defer_completion is now un-read, we should stop calculating it.
I'm not sure what the right solution is; should we simply do:
defer_completion = dio->defer_completion ||
+ in_atomic() ||
(dio_op == REQ_OP_WRITE &&
dio->inode->i_mapping->nrpages);
I'm kind of surprised this problem hasn't cropped up before now ...