From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: sashiko-reviews@lists.linux.dev,
Heming Zhao <heming.zhao@suse.com>,
Christoph Hellwig <hch@lst.de>
Cc: Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
Andrew Morton <akpm@linux-foundation.org>,
"ocfs2-devel@lists.linux.dev" <ocfs2-devel@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH v13 06/10] ocfs2: rework the direct write context for multi-cluster mappings
Date: Mon, 30 Nov 2026 20:00:03 +0800 [thread overview]
Message-ID: <15805f4a-7a23-4538-a7af-4e2c1111afe3@linux.alibaba.com> (raw)
In-Reply-To: <sashiko-outbox-240858@kernel.org>
On 11/30/26 6:28 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [High] ocfs2: short direct write marks unzeroed partial cluster
> written in ocfs2_dio_end_io_write()
> --
>
> commit 25ecce6352ba3b041ae3cd99d8a7842789bba66e
> Author: Heming Zhao <heming.zhao@suse.com>
>
> ocfs2: rework the direct write context for multi-cluster mappings
>
> This commit reworks ocfs2_write_ctxt and unwritten extent tracking to
> handle multi-cluster ranges for direct writes instead of mapping one
> cluster at a time.
>
>> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
>> index 21cdc5c29331d..e3e28584e7410 100644
>> --- a/fs/ocfs2/aops.c
>> +++ b/fs/ocfs2/aops.c
> [ ... ]
>> @@ -1084,7 +1182,85 @@ static int ocfs2_prepare_folio_for_write(struct inode *inode, u64 *p_blkno,
> [ ... ]
>> +static int ocfs2_grab_folios_direct(struct address_space *mapping,
>> + struct ocfs2_write_ctxt *wc, loff_t user_pos, unsigned user_len)
>> +{
> [ ... ]
>> + for (i = 0; i < ppc; i++) {
>> + unsigned long index = start + i;
>> + struct folio *folio;
>> +
>> + if (index >= last_index)
>> + break;
>> +
>> + /* Track the slots in use, for the unlock/commit loops. */
>> + wc->w_num_folios = max_t(unsigned int, wc->w_num_folios,
>> + win * ppc + i + 1);
>> +
>> + /* The direct io target has no page cache page here. */
>> + if (index >= target_index && index <= end_index)
>> + continue;
> [ ... ]
>> @@ -2151,9 +2747,222 @@ static int ocfs2_write_end(const struct kiocb *iocb,
>> return ret;
>> }
>>
>> +/*
>> + * Convert the unwritten extents of a direct write, which is finished,
>> + * and change the file size if it has been extended.
>> + *
>> + * @head are the clusters the write has zeroed or allocated, recorded by
>> + * ocfs2_dio_wr_map_blocks(). Those which are not covered by the data
>> + * written, [offset, offset + bytes), are left unwritten.
>> + */
>> +static int ocfs2_dio_end_io_write(struct inode *inode,
>> + loff_t offset,
>> + ssize_t bytes,
>> + struct list_head *head)
>> +{
>> + struct ocfs2_cached_dealloc_ctxt dealloc;
>> + struct ocfs2_extent_tree et;
>> + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
>> + struct ocfs2_inode_info *oi = OCFS2_I(inode);
>> + struct ocfs2_unwritten_extent *ue;
>> + struct buffer_head *di_bh = NULL;
>> + struct ocfs2_dinode *di;
>> + struct ocfs2_alloc_context *data_ac = NULL;
>> + struct ocfs2_alloc_context *meta_ac = NULL;
>> + handle_t *handle = NULL;
>> + loff_t end = offset + bytes;
>> + int ret = 0, credits = 0, batch = 0, pass;
>> + u32 first_cpos, last_cpos;
>> + u32 extents_to_split = 0;
>> +
>> + first_cpos = offset >> osb->s_clustersize_bits;
>> + last_cpos = ocfs2_clusters_for_bytes(inode->i_sb, end);
>
> [Severity: High]
> Can a short direct write to a hole or unwritten extent within i_size cause
> ocfs2_dio_end_io_write() to mark an unzeroed partial cluster as written,
> exposing stale disk blocks?
>
> When s_clustersize > PAGE_SIZE, ocfs2_grab_folios_direct() skips zeroing
> all pages in [target_index, end_index] and all middle clusters, assuming
> direct I/O will overwrite the entire mapped range [user_pos, user_pos +
> user_len). If the write stops short (for example, pwritev() faults on a
> later iovec after submitting the first page of a cluster), the remaining
> blocks of that cluster in [end, user_pos + user_len) are neither written
> by direct I/O nor zeroed through the page cache. Rounding end up with
> ocfs2_clusters_for_bytes() into last_cpos then converts the entire cluster
> containing end - 1 from OCFS2_EXT_UNWRITTEN to written.
>
This seems a false postive finding.
In this patch the direct write path is still the buffer_head one:
ocfs2_direct_IO() calls __blockdev_direct_IO(), and that core already
zeroes the outstanding mapped blocks when a write faults partway through
a mapping.
Thanks,
Joseph
next prev parent reply other threads:[~2026-11-30 12:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 10:01 [RFC PATCH v13 00/10] migrate ocfs2 DIO from buffer_head to iomap Joseph Qi
2026-11-30 10:01 ` [RFC PATCH v13 01/10] ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature Joseph Qi
2026-11-30 10:01 ` [RFC PATCH v13 02/10] ocfs2: switch DIO read path from buffer_head to iomap Joseph Qi
2026-11-30 10:01 ` [RFC PATCH v13 03/10] ocfs2: add ocfs2_get_clusters_uncached() Joseph Qi
2026-11-30 10:01 ` [RFC PATCH v13 04/10] ocfs2: refactor ocfs2_lock_allocators() and add a dio variant Joseph Qi
2026-11-30 10:01 ` [RFC PATCH v13 05/10] ocfs2: record the fsync transaction when CoW makes clusters writable Joseph Qi
2026-11-30 10:01 ` [RFC PATCH v13 06/10] ocfs2: rework the direct write context for multi-cluster mappings Joseph Qi
[not found] ` <sashiko-outbox-240858@kernel.org>
2026-11-30 12:00 ` Joseph Qi [this message]
2026-11-30 10:02 ` [RFC PATCH v13 07/10] ocfs2: switch dio write path from buffer_head to iomap Joseph Qi
2026-11-30 10:02 ` [RFC PATCH v13 08/10] ocfs2: keep sub-page overwrites of written blocks on direct I/O Joseph Qi
2026-11-30 10:02 ` [RFC PATCH v13 09/10] ocfs2: write the dio zeroed head/tail buffers out before completion Joseph Qi
2026-11-30 10:02 ` [RFC PATCH v13 10/10] ocfs2: make buffered writes wait for in-flight direct writes Joseph Qi
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=15805f4a-7a23-4538-a7af-4e2c1111afe3@linux.alibaba.com \
--to=joseph.qi@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=heming.zhao@suse.com \
--cc=jlbec@evilplan.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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
all inboxes | Powered by JetHome®