Re: [PATCH 1/3] jbd2: use READ_ONCE for lockless jinode reads

From: Jan Kara

Date: Mon Feb 02 2026 - 11:59:03 EST


On Mon 02-02-26 17:40:45, Jan Kara wrote:
> On Fri 30-01-26 11:12:30, Li Chen wrote:
> > jbd2_inode fields are updated under journal->j_list_lock, but some
> > paths read them without holding the lock (e.g. fast commit
> > helpers and the ordered truncate fast path).
> >
> > Use READ_ONCE() for these lockless reads to correct the
> > concurrency assumptions.
> >
> > Suggested-by: Jan Kara <jack@xxxxxxxx>
> > Signed-off-by: Li Chen <me@linux.beauty>
>
> Just one nit below. With that fixed feel free to add:
>
> Reviewed-by: Jan Kara <jack@xxxxxxx>
>
> > @@ -191,12 +197,30 @@ EXPORT_SYMBOL(jbd2_submit_inode_data);
> >
> > int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode)
> > {
> > - if (!jinode || !(jinode->i_flags & JI_WAIT_DATA) ||
> > - !jinode->i_vfs_inode || !jinode->i_vfs_inode->i_mapping)
> > + struct address_space *mapping;
> > + struct inode *inode;
> > + unsigned long flags;
> > + loff_t start, end;
> > +
> > + if (!jinode)
> > + return 0;
> > +
> > + flags = READ_ONCE(jinode->i_flags);
> > + if (!(flags & JI_WAIT_DATA))
> > + return 0;
> > +
> > + inode = READ_ONCE(jinode->i_vfs_inode);
>
> i_vfs_inode never changes so READ_ONCE is pointless here.

One more note: I've realized that for this to work you also need to make
jbd2_journal_file_inode() use WRITE_ONCE() when updating i_dirty_start,
i_dirty_end and i_flags.

Honza

--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR