[PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount

sashiko-bot at kernel.org sashiko-bot at kernel.org
Tue Nov 17 01:51:20 PST 2026


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 at 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



More information about the linux-mtd mailing list