All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Brauner" <brauner@kernel.org>
Cc: "Jan Kara" <jack@suse.com>,
	linux-ext4@vger.kernel.org, linux-mm@kvack.org,
	linux-efi@vger.kernel.org, linux-mtd@lists.infradead.org,
	dsterba@suse.cz, tytso@mit.edu, "Mark Fasheh" <mark@fasheh.com>,
	"Joel Becker" <jlbec@evilplan.org>,
	"Joseph Qi" <joseph.qi@linux.alibaba.com>
Subject: Re: [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount
Date: Tue, 17 Nov 2026 09:51:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-218534@kernel.org> (raw)
In-Reply-To: <20261116-work-fs-sb_rdonly-fixes-v1-1-95a25ce917ad@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gfs2: race in gfs2_queue_withdraw() lets flush_work() return
  before queue
--

commit 3d2897f8b51331dc6f7b51a37f13ef421ac6739b
Author: Christian Brauner <brauner@kernel.org>

gfs2: don't BUG when remounting read-only after a withdraw during mount

This commit introduces gfs2_queue_withdraw() guarded by SDF_WITHDRAW_QUEUED
and flushes sd_withdraw_work in gfs2_reconfigure() before remounting a
withdrawn filesystem read-only.

> diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
> index 6ec47376aecf2..3bd5702535dfe 100644
> --- a/fs/gfs2/ops_fstype.c
> +++ b/fs/gfs2/ops_fstype.c
> @@ -1590,6 +1590,11 @@ static int gfs2_reconfigure(struct fs_context *fc)
>  
>  	if ((sb->s_flags ^ fc->sb_flags) & SB_RDONLY) {
>  		if (fc->sb_flags & SB_RDONLY) {
> +			/* gfs2_withdraw() doesn't queue the work during mount. */
> +			if (gfs2_withdrawn(sdp)) {
> +				gfs2_queue_withdraw(sdp);
> +				flush_work(&sdp->sd_withdraw_work);
> +			}
>  			gfs2_make_fs_ro(sdp);
>  		} else {
>  			error = gfs2_make_fs_rw(sdp);
> diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
> index 529c3ec37a18a..5558af374994a 100644
> --- a/fs/gfs2/util.c
> +++ b/fs/gfs2/util.c
> @@ -238,6 +238,13 @@ void gfs2_withdraw_func(struct work_struct *work)
>  	fs_err(sdp, "file system withdrawn\n");
>  }
>  
> +/* The withdraw work must only run once. */
> +void gfs2_queue_withdraw(struct gfs2_sbd *sdp)
> +{
> +	if (!test_and_set_bit(SDF_WITHDRAW_QUEUED, &sdp->sd_flags))
> +		schedule_work(&sdp->sd_withdraw_work);
> +}
> +
>  void gfs2_withdraw(struct gfs2_sbd *sdp)
>  {
>  	if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW ||
> @@ -253,7 +260,7 @@ void gfs2_withdraw(struct gfs2_sbd *sdp)
>  		if (!(sdp->sd_vfs->s_flags & SB_BORN))
>  			return;
>  		fs_err(sdp, "about to withdraw this file system\n");
> -		schedule_work(&sdp->sd_withdraw_work);
> +		gfs2_queue_withdraw(sdp);
>  		return;
>  	}

[Severity: Medium]
Can flush_work(&sdp->sd_withdraw_work) in gfs2_reconfigure() return before
a concurrent gfs2_withdraw() has queued sd_withdraw_work?

CPU0                                  CPU1
gfs2_withdraw()
  test_and_set_bit(SDF_WITHDRAWN, ...)
  gfs2_queue_withdraw()
    test_and_set_bit(SDF_WITHDRAW_QUEUED, ...)
                                      gfs2_reconfigure()
                                        if (gfs2_withdrawn(sdp))
                                          gfs2_queue_withdraw()
                                            test_and_set_bit(SDF_WITHDRAW_QUEUED, ...)
                                              --> already set, skips schedule_work()
                                          flush_work(&sdp->sd_withdraw_work)
                                            --> not pending yet, returns false
                                        gfs2_make_fs_ro()
                                          ...
                                          gfs2_quota_cleanup()
                                            --> hits BUG_ON()
    schedule_work(&sdp->sd_withdraw_work)

Because test_and_set_bit(SDF_WITHDRAW_QUEUED, &sdp->sd_flags) runs before
schedule_work() marks sd_withdraw_work pending, CPU1's gfs2_queue_withdraw()
can observe SDF_WITHDRAW_QUEUED already set and return without queuing the
work.  flush_work() then sees an idle work item and returns immediately,
allowing gfs2_make_fs_ro() -> gfs2_quota_cleanup() to proceed with
SDF_JOURNAL_LIVE still set and hit its BUG_ON().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-work-fs-sb_rdonly-fixes-v1-0-95a25ce917ad@kernel.org?part=1

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Christian Brauner" <brauner@kernel.org>
Cc: "Jan Kara" <jack@suse.com>,
	linux-ext4@vger.kernel.org, linux-mm@kvack.org,
	linux-efi@vger.kernel.org, linux-mtd@lists.infradead.org,
	dsterba@suse.cz, tytso@mit.edu, "Mark Fasheh" <mark@fasheh.com>,
	"Joel Becker" <jlbec@evilplan.org>,
	"Joseph Qi" <joseph.qi@linux.alibaba.com>
Subject: Re: [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount
Date: Tue, 17 Nov 2026 09:51:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-218534@kernel.org> (raw)
In-Reply-To: <20261116-work-fs-sb_rdonly-fixes-v1-1-95a25ce917ad@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gfs2: race in gfs2_queue_withdraw() lets flush_work() return
  before queue
--

commit 3d2897f8b51331dc6f7b51a37f13ef421ac6739b
Author: Christian Brauner <brauner@kernel.org>

gfs2: don't BUG when remounting read-only after a withdraw during mount

This commit introduces gfs2_queue_withdraw() guarded by SDF_WITHDRAW_QUEUED
and flushes sd_withdraw_work in gfs2_reconfigure() before remounting a
withdrawn filesystem read-only.

> diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
> index 6ec47376aecf2..3bd5702535dfe 100644
> --- a/fs/gfs2/ops_fstype.c
> +++ b/fs/gfs2/ops_fstype.c
> @@ -1590,6 +1590,11 @@ static int gfs2_reconfigure(struct fs_context *fc)
>  
>  	if ((sb->s_flags ^ fc->sb_flags) & SB_RDONLY) {
>  		if (fc->sb_flags & SB_RDONLY) {
> +			/* gfs2_withdraw() doesn't queue the work during mount. */
> +			if (gfs2_withdrawn(sdp)) {
> +				gfs2_queue_withdraw(sdp);
> +				flush_work(&sdp->sd_withdraw_work);
> +			}
>  			gfs2_make_fs_ro(sdp);
>  		} else {
>  			error = gfs2_make_fs_rw(sdp);
> diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
> index 529c3ec37a18a..5558af374994a 100644
> --- a/fs/gfs2/util.c
> +++ b/fs/gfs2/util.c
> @@ -238,6 +238,13 @@ void gfs2_withdraw_func(struct work_struct *work)
>  	fs_err(sdp, "file system withdrawn\n");
>  }
>  
> +/* The withdraw work must only run once. */
> +void gfs2_queue_withdraw(struct gfs2_sbd *sdp)
> +{
> +	if (!test_and_set_bit(SDF_WITHDRAW_QUEUED, &sdp->sd_flags))
> +		schedule_work(&sdp->sd_withdraw_work);
> +}
> +
>  void gfs2_withdraw(struct gfs2_sbd *sdp)
>  {
>  	if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW ||
> @@ -253,7 +260,7 @@ void gfs2_withdraw(struct gfs2_sbd *sdp)
>  		if (!(sdp->sd_vfs->s_flags & SB_BORN))
>  			return;
>  		fs_err(sdp, "about to withdraw this file system\n");
> -		schedule_work(&sdp->sd_withdraw_work);
> +		gfs2_queue_withdraw(sdp);
>  		return;
>  	}

[Severity: Medium]
Can flush_work(&sdp->sd_withdraw_work) in gfs2_reconfigure() return before
a concurrent gfs2_withdraw() has queued sd_withdraw_work?

CPU0                                  CPU1
gfs2_withdraw()
  test_and_set_bit(SDF_WITHDRAWN, ...)
  gfs2_queue_withdraw()
    test_and_set_bit(SDF_WITHDRAW_QUEUED, ...)
                                      gfs2_reconfigure()
                                        if (gfs2_withdrawn(sdp))
                                          gfs2_queue_withdraw()
                                            test_and_set_bit(SDF_WITHDRAW_QUEUED, ...)
                                              --> already set, skips schedule_work()
                                          flush_work(&sdp->sd_withdraw_work)
                                            --> not pending yet, returns false
                                        gfs2_make_fs_ro()
                                          ...
                                          gfs2_quota_cleanup()
                                            --> hits BUG_ON()
    schedule_work(&sdp->sd_withdraw_work)

Because test_and_set_bit(SDF_WITHDRAW_QUEUED, &sdp->sd_flags) runs before
schedule_work() marks sd_withdraw_work pending, CPU1's gfs2_queue_withdraw()
can observe SDF_WITHDRAW_QUEUED already set and return without queuing the
work.  flush_work() then sees an idle work item and returns immediately,
allowing gfs2_make_fs_ro() -> gfs2_quota_cleanup() to proceed with
SDF_JOURNAL_LIVE still set and hit its BUG_ON().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-work-fs-sb_rdonly-fixes-v1-0-95a25ce917ad@kernel.org?part=1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2026-11-17  9:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  9:28 [PATCH 0/3] fs: pre-existing fixes for the SB_RDONLY series Christian Brauner
2026-11-16  9:28 ` Christian Brauner
2026-11-16  9:28 ` [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount Christian Brauner
2026-11-16  9:28   ` Christian Brauner
2026-11-17  9:51   ` sashiko-bot [this message]
2026-11-17  9:51     ` sashiko-bot
2026-11-16  9:28 ` [PATCH 2/3] exfat: keep the volume marked dirty after a shutdown Christian Brauner
2026-11-16  9:28   ` Christian Brauner
2026-11-17  9:51   ` sashiko-bot
2026-11-17  9:51     ` sashiko-bot
2026-11-16  9:28 ` [PATCH 3/3] jfs: refuse inodes with a negative size Christian Brauner
2026-11-16  9:28   ` Christian Brauner
2026-11-17  9:51   ` sashiko-bot

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=sashiko-outbox-218534@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=brauner@kernel.org \
    --cc=dsterba@suse.cz \
    --cc=jack@suse.com \
    --cc=jlbec@evilplan.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=mark@fasheh.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /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.