All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	"ocfs2-devel@lists.linux.dev" <ocfs2-devel@lists.linux.dev>
Subject: Re: [RFC PATCH v15 06/10] ocfs2: rework the direct write context for multi-cluster mappings
Date: Thu, 3 Dec 2026 13:40:02 +0800	[thread overview]
Message-ID: <f99becef-ff2c-4ab7-93ca-630cd718511c@linux.alibaba.com> (raw)
In-Reply-To: <sashiko-outbox-246035@kernel.org>



On 12/2/26 11:01 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] ocfs2: mapped non-uptodate buffers left on folio if
>   ocfs2_dio_add_unwritten() fails
> --
> 
> commit 011a09c7a7cba976cdcd3c888f0ffb4ea345272b
> Author: Heming Zhao <heming.zhao@suse.com>
> 
> ocfs2: rework the direct write context for multi-cluster mappings
> 
> This commit reworks the direct write context and unwritten extent tracking
> to support multi-cluster mappings.
> 
>> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
>> index 21cdc5c29331d..4b76be5909689 100644
>> --- a/fs/ocfs2/aops.c
>> +++ b/fs/ocfs2/aops.c
> [ ... ]
>> @@ -1881,11 +2438,34 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
>>  
>>  	ret = ocfs2_write_cluster_by_desc(mapping, data_ac, meta_ac, wc, pos,
>>  					  len);
>> +	if (wc->w_clusters_unused) {
>> +		/* A direct write got a shorter chunk than reserved. */
>> +		dquot_free_space(inode,
>> +			ocfs2_clusters_to_bytes(osb->sb, wc->w_clusters_unused));
>> +		clusters_to_alloc -= wc->w_clusters_unused;
>> +		wc->w_clusters_unused = 0;
>> +	}
>> +	/*
>> +	 * w_clen is final now, so this is the range whose head and tail
>> +	 * folios may have been zeroed, whether or not the write succeeded.
>> +	 * The caller needs it to clean up behind the locks.
>> +	 */
>> +	if (touched_end)
>> +		*touched_end = ocfs2_clusters_to_bytes(inode->i_sb,
>> +						       wc->w_cpos + wc->w_clen);
>>  	if (ret) {
>>  		mlog_errno(ret);
>>  		goto out_quota;
>>  	}
>>  
>> +	if (type == OCFS2_WRITE_DIRECT) {
>> +		ret = ocfs2_dio_add_unwritten(inode, wc);
>> +		if (ret) {
>> +			mlog_errno(ret);
>> +			goto out_quota;
>> +		}
>> +	}
> 
> [Severity: Medium]
> If ocfs2_dio_add_unwritten() fails with -ENOMEM here, does the error path
> leave BH_Mapped and !BH_Uptodate buffer_heads on the head and tail folios
> in wc->w_folios[]?
> 
> When cluster size exceeds page size, ocfs2_write_cluster_by_desc() ->
> ocfs2_write_clusters_direct() -> ocfs2_prepare_cluster_folios() ->
> ocfs2_prepare_folio_for_write() -> ocfs2_map_folio_blocks() attaches
> buffer_heads to non-uptodate head or tail folios and maps them to the
> physical blocks of the OCFS2_EXT_UNWRITTEN extent, leaving BH_Uptodate
> clear until block_commit_write() in ocfs2_write_end_nolock().  Jumping to
> out_quota commits the transaction and calls ocfs2_free_write_ctxt(), which
> unlocks those folios without committing or invalidating their buffers
> (and ocfs2_dio_wr_get_block() passes touched_end = NULL, performing no
> folio cleanup).  A subsequent buffered read within i_size via
> block_read_full_folio() will see buffer_mapped(bh) && !buffer_uptodate(bh),
> skip ocfs2_get_block(), and read the uninitialized disk blocks of the
> unwritten extent into the page cache.
> 
> Even once commit "ocfs2: switch dio write path from buffer_head to iomap"
> adds ocfs2_dio_cleanup_clusters(), that cleanup runs after
> ocfs2_free_write_ctxt() has unlocked the folios and after ip_alloc_sem and
> the inode lock have been dropped, leaving a window for a concurrent
> buffered read to issue a read bio on the mapped buffer before
> truncate_inode_pages_range() runs.
> 

It looks real, will fix it in next version.

Thanks,
Joseph


  parent reply	other threads:[~2026-12-03  5:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 14:34 [RFC PATCH v15 00/10] migrate ocfs2 DIO from buffer_head to iomap Joseph Qi
2026-12-02 14:34 ` [RFC PATCH v15 01/10] ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature Joseph Qi
2026-12-02 14:34 ` [RFC PATCH v15 02/10] ocfs2: switch DIO read path from buffer_head to iomap Joseph Qi
2026-12-02 14:35 ` [RFC PATCH v15 03/10] ocfs2: add ocfs2_get_clusters_uncached() Joseph Qi
2026-12-02 16:16   ` Christoph Hellwig
2026-12-02 14:35 ` [RFC PATCH v15 04/10] ocfs2: refactor ocfs2_lock_allocators() and add a dio variant Joseph Qi
2026-12-02 14:35 ` [RFC PATCH v15 05/10] ocfs2: record the fsync transaction when CoW makes clusters writable Joseph Qi
2026-12-02 14:35 ` [RFC PATCH v15 06/10] ocfs2: rework the direct write context for multi-cluster mappings Joseph Qi
     [not found]   ` <sashiko-outbox-246035@kernel.org>
2026-12-03  5:40     ` Joseph Qi [this message]
2026-12-02 14:35 ` [RFC PATCH v15 07/10] ocfs2: switch dio write path from buffer_head to iomap Joseph Qi
     [not found]   ` <sashiko-outbox-246055@kernel.org>
2026-12-03  5:43     ` Joseph Qi
2026-12-03  7:49   ` Heming Zhao
2026-12-03  8:55     ` Joseph Qi
2026-12-02 14:35 ` [RFC PATCH v15 08/10] ocfs2: keep sub-page overwrites of written blocks on direct I/O Joseph Qi
2026-12-02 14:35 ` [RFC PATCH v15 09/10] ocfs2: write the dio zeroed head/tail buffers out before completion Joseph Qi
2026-12-02 14:35 ` [RFC PATCH v15 10/10] ocfs2: make buffered writes wait for in-flight direct writes Joseph Qi
2026-12-02 16:17 ` [RFC PATCH v15 00/10] migrate ocfs2 DIO from buffer_head to iomap Christoph Hellwig

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=f99becef-ff2c-4ab7-93ca-630cd718511c@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=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 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.