diff mbox series

[v2,2/2] btrfs: zoned: fix critical section of relocation inode writeback

Message ID 668df7d610ddae48ffd260ae08f433cc3b3d7ecd.1654585425.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: zoned: fixes for data relocation | expand

Commit Message

Naohiro Aota June 7, 2022, 7:08 a.m. UTC
We use btrfs_zoned_data_reloc_{lock,unlock} to allow only one process to
write out to the relocation inode. That critical section must include all
the IO submission for the inode. However, flush_write_bio() in
extent_writepages() is out of the critical section, causing an IO
submission outside of the lock. This leads to an out of the order IO
submission and fail the relocation process.

Fix it by extending the critical section.

Fixes: 35156d852762 ("btrfs: zoned: only allow one process to add pages to a relocation inode")
CC: stable@vger.kernel.org # 5.16+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/extent_io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Johannes Thumshirn June 7, 2022, 8:19 a.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Naohiro Aota June 7, 2022, 8:52 a.m. UTC | #2
Sorry. I forgot to rebase the series, and this patch looks conflict with
the commit "btrfs: merge end_write_bio and flush_write_bio." We need to
place btrfs_zoned_data_reloc_unlock() after submit_write_bio().

On Tue, Jun 07, 2022 at 04:08:30PM +0900, Naohiro Aota wrote:
> We use btrfs_zoned_data_reloc_{lock,unlock} to allow only one process to
> write out to the relocation inode. That critical section must include all
> the IO submission for the inode. However, flush_write_bio() in
> extent_writepages() is out of the critical section, causing an IO
> submission outside of the lock. This leads to an out of the order IO
> submission and fail the relocation process.
> 
> Fix it by extending the critical section.
> 
> Fixes: 35156d852762 ("btrfs: zoned: only allow one process to add pages to a relocation inode")
> CC: stable@vger.kernel.org # 5.16+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> ---
>  fs/btrfs/extent_io.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 4847e0471dbf..7a125b319a9f 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -5227,13 +5227,14 @@ int extent_writepages(struct address_space *mapping,
>  	 */
>  	btrfs_zoned_data_reloc_lock(BTRFS_I(inode));
>  	ret = extent_write_cache_pages(mapping, wbc, &epd);
> -	btrfs_zoned_data_reloc_unlock(BTRFS_I(inode));
>  	ASSERT(ret <= 0);
>  	if (ret < 0) {
> +		btrfs_zoned_data_reloc_unlock(BTRFS_I(inode));
>  		end_write_bio(&epd, ret);
>  		return ret;
>  	}
>  	flush_write_bio(&epd);
> +	btrfs_zoned_data_reloc_unlock(BTRFS_I(inode));
>  	return ret;
>  }
>  
> -- 
> 2.35.1
>
David Sterba June 7, 2022, 4:22 p.m. UTC | #3
On Tue, Jun 07, 2022 at 08:52:37AM +0000, Naohiro Aota wrote:
> Sorry. I forgot to rebase the series, and this patch looks conflict with
> the commit "btrfs: merge end_write_bio and flush_write_bio." We need to
> place btrfs_zoned_data_reloc_unlock() after submit_write_bio().

No problem, the cleanup patches tend to collide with fixes, also I'm
going to send the zoned fixes during some rc, so the original version
will be applied and the cleanup updated eventually.
diff mbox series

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 4847e0471dbf..7a125b319a9f 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -5227,13 +5227,14 @@  int extent_writepages(struct address_space *mapping,
 	 */
 	btrfs_zoned_data_reloc_lock(BTRFS_I(inode));
 	ret = extent_write_cache_pages(mapping, wbc, &epd);
-	btrfs_zoned_data_reloc_unlock(BTRFS_I(inode));
 	ASSERT(ret <= 0);
 	if (ret < 0) {
+		btrfs_zoned_data_reloc_unlock(BTRFS_I(inode));
 		end_write_bio(&epd, ret);
 		return ret;
 	}
 	flush_write_bio(&epd);
+	btrfs_zoned_data_reloc_unlock(BTRFS_I(inode));
 	return ret;
 }