public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Ritesh Harjani <ritesh.list@gmail.com>
Cc: Zhang Yi <yi.zhang@huawei.com>, Jan Kara <jack@suse.cz>,
	linux-ext4@vger.kernel.org, tytso@mit.edu,
	adilger.kernel@dilger.ca, yukuai3@huawei.com
Subject: Re: [PATCH] ext4: fix warning when submitting superblock in ext4_commit_super()
Date: Thu, 19 May 2022 11:30:35 +0200	[thread overview]
Message-ID: <20220519093035.2kazqodrv4nqauwf@quack3.lan> (raw)
In-Reply-To: <20220519062929.i52y2mwonnrbvr64@riteshh-domain>

On Thu 19-05-22 11:59:29, Ritesh Harjani wrote:
> On 22/05/19 11:13AM, Zhang Yi wrote:
> > On 2022/5/19 1:06, Ritesh Harjani wrote:
> > > On 22/05/18 10:10PM, Zhang Yi wrote:
> > >> We have already check the io_error and uptodate flag before submitting
> > >> the superblock buffer, and re-set the uptodate flag if it has been
> > >> failed to write out. But it was lockless and could be raced by another
> > >> ext4_commit_super(), and finally trigger '!uptodate' WARNING when
> > >> marking buffer dirty. Fix it by submit buffer directly.
> > >
> > > I agree that there could be a race with multiple processes trying to call
> > > ext4_commit_super(). Do you have a easy reproducer for this issue?
> > >
> >
> > Sorry, I don't have a easy reproducer, but we can always reproduce it through
> > inject delay and add filters into the ext4_commit_super().

...
 
> > > Also do you think something like below should fix the problem too?
> > > So if you lock the buffer from checking until marking the buffer dirty, that
> > > should avoid the race too that you are reporting.
> > > Thoughts?
> > >
> >
> > Thanks for your suggestion. I've thought about this solution and yes it's simpler
> > to fix the race, but I think we lock and unlock the sbh several times just for
> > calling standard buffer write helpers is not so good. Opencode the submit
> > procedure looks more clear to me.
> 
> I agree your solution was cleaner since it does not has a lot of lock/unlock.
> My suggestion came in from looking at the history.
> This lock was added here [1] and I think it somehow got removed in this patch[2]
> 
> [1]: https://lore.kernel.org/linux-ext4/1467285150-15977-2-git-send-email-pranjas@gmail.com/
> [2]: https://lore.kernel.org/linux-ext4/20201216101844.22917-5-jack@suse.cz/

So the reason why I've move unlock_buffer() into ext4_update_super() was
mostly so that the function does not return with buffer lock (which is an
odd calling convention) when I was adding another user of it
(flush_stashed_error_work()).

> Rather then solutions, I had few queries :)
> 1. What are the implications of not using
> mark_buffer_dirty()/__sync_dirty_buffer()

Not much. Using submit_bh() directly is fine. Just the duplication of the
checks is somewhat unpleasant.

> 2. In your solution one thing which I was not clear of, was whether we
> should call clear_buffer_dirty() before calling submit_bh(), in case if
> somehow(?) the state of the buffer was already marked dirty? Not sure how
> this can happen, but I see the logic in mark_buffer_dirty() which checks,
> if the buffer is already marked dirty, it simply returns. Then
> __sync_dirty_buffer() clears the buffer dirty state.

It could happen e.g. if there was journalled update of the superblock
before. I guess calling clear_buffer_dirty() before submit_bh() does no
harm.

Otherwise I like Yi's solution.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2022-05-19  9:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18 14:10 [PATCH] ext4: fix warning when submitting superblock in ext4_commit_super() Zhang Yi
2022-05-18 17:06 ` Ritesh Harjani
2022-05-19  3:13   ` Zhang Yi
2022-05-19  6:29     ` Ritesh Harjani
2022-05-19  9:30       ` Jan Kara [this message]
2022-05-19 10:08         ` Ritesh Harjani
2022-05-19 12:33         ` 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=20220519093035.2kazqodrv4nqauwf@quack3.lan \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@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