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 v3 9/9] ext4: fix NOWAIT semantic violation in DAX extending writes
Date: Fri, 26 Jun 2026 16:35:18 +0800 [thread overview]
Message-ID: <20260626083518.1064517-10-libaokun@linux.alibaba.com> (raw)
In-Reply-To: <20260626083518.1064517-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
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 49074cc13751..610e109fcd36 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -731,6 +731,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
next prev parent reply other threads:[~2026-06-26 8:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 8:35 [PATCH v3 0/9] ext4: allow more DIO writes under shared i_rwsem Baokun Li
2026-06-26 8:35 ` [PATCH v3 1/9] ext4: prevent sleeping allocation in NOWAIT write path Baokun Li
2026-06-26 8:35 ` [PATCH v3 2/9] ext4: drain in-flight DIO before buffered write fallback Baokun Li
2026-06-26 8:35 ` [PATCH v3 3/9] ext4: skip overwrite check for aligned non-extending DIO writes Baokun Li
2026-06-26 8:35 ` [PATCH v3 4/9] ext4: base unaligned DIO lock decision on partial block zeroing Baokun Li
2026-06-26 8:35 ` [PATCH v3 5/9] ext4: use kiocb_modified instead of file_modified in DIO/DAX write path Baokun Li
2026-06-26 8:35 ` [PATCH v3 6/9] ext4: improve EXT4_GET_BLOCKS_CACHED_NOWAIT handling in ext4_map_blocks Baokun Li
[not found] ` <20260626085003.BD4BC1F000E9@smtp.kernel.org>
2026-06-26 10:10 ` Baokun Li
2026-06-26 8:35 ` [PATCH v3 7/9] ext4: handle IOMAP_NOWAIT in ext4_iomap_begin() with cache-only lookup Baokun Li
2026-06-26 8:35 ` [PATCH v3 8/9] ext4: handle IOCB_NOWAIT in ext4_dio_needs_zeroing() " Baokun Li
2026-06-26 8:35 ` Baokun Li [this message]
2026-06-26 14:32 ` [PATCH v3 9/9] ext4: fix NOWAIT semantic violation in DAX extending writes Jan Kara
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=20260626083518.1064517-10-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox