All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baokun Li <libaokun@linux.alibaba.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz,
	yi.zhang@huawei.com, ojaswin@linux.ibm.com,
	ritesh.list@gmail.com, peng_wang@linux.alibaba.com,
	Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v4 6/6] ext4: fix NOWAIT semantic violation in DAX extending writes
Date: Mon, 29 Jun 2026 19:38:27 +0800	[thread overview]
Message-ID: <20260629113827.4074335-7-libaokun@linux.alibaba.com> (raw)
In-Reply-To: <20260629113827.4074335-1-libaokun@linux.alibaba.com>

When a DAX write starts before EOF but extends past i_disksize,
ext4_write_checks() skips the IOCB_NOWAIT check because
iocb->ki_pos <= old_size. However, ext4_dax_write_iter() later calls
ext4_journal_start() to prepare for inode extension, which can sleep
waiting for journal space or transaction commit.

This violates NOWAIT semantics and can stall asynchronous I/O frameworks
like io_uring that rely on non-blocking behavior.

Fix this by checking IOCB_NOWAIT before calling ext4_journal_start()
in the extending write path. If NOWAIT is set and extension is needed,
return -EAGAIN so the caller can retry in blocking context.

Example scenario:
  - File: i_size = 1000, i_disksize = 1000
  - DAX NOWAIT write: offset = 500, count = 2000
  - ext4_write_checks(): ki_pos (500) <= old_size (1000), skip NOWAIT check
  - ext4_dax_write_iter(): offset + count (2500) > i_disksize (1000)
  - ext4_journal_start() → may sleep → violates NOWAIT

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260618125735.4156639-1-libaokun@linux.alibaba.com?part=5
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Baokun Li <libaokun@linux.alibaba.com>
---
 fs/ext4/file.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 0e9448a110dc..9a16071b719d 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -725,6 +725,11 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	count = iov_iter_count(from);
 
 	if (offset + count > EXT4_I(inode)->i_disksize) {
+		if (iocb->ki_flags & IOCB_NOWAIT) {
+			ret = -EAGAIN;
+			goto out;
+		}
+
 		handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
 		if (IS_ERR(handle)) {
 			ret = PTR_ERR(handle);
-- 
2.43.7


  parent reply	other threads:[~2026-06-29 11:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 11:38 [PATCH v4 0/6] ext4: allow more DIO writes under shared i_rwsem Baokun Li
2026-06-29 11:38 ` [PATCH v4 1/6] ext4: prevent sleeping allocation in NOWAIT write path Baokun Li
2026-06-29 11:38 ` [PATCH v4 2/6] ext4: drain in-flight DIO before buffered write fallback Baokun Li
2026-06-29 11:38 ` [PATCH v4 3/6] ext4: skip overwrite check for aligned non-extending DIO writes Baokun Li
2026-06-29 11:38 ` [PATCH v4 4/6] ext4: base unaligned DIO lock decision on partial block zeroing Baokun Li
2026-06-29 11:38 ` [PATCH v4 5/6] ext4: use kiocb_modified instead of file_modified in DIO/DAX write path Baokun Li
2026-06-29 11:38 ` Baokun Li [this message]
2026-06-30  1:08   ` [PATCH v4 6/6] ext4: fix NOWAIT semantic violation in DAX extending writes Zhang Yi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260629113827.4074335-7-libaokun@linux.alibaba.com \
    --to=libaokun@linux.alibaba.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=peng_wang@linux.alibaba.com \
    --cc=ritesh.list@gmail.com \
    --cc=sashiko-bot@kernel.org \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.