Skip to contentSkip to conversation

FAILED: patch "[PATCH] btrfs: fix double inode unlock for direct IO sync writes" failed to apply to 6.10-stable tree

PATCH [email protected] 2 participants 2 messages Aug 12, 2024

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.10.y
git checkout FETCH_HEAD
git cherry-pick -x e0391e92f9ab4fb3dbdeb139c967dcfa7ac4b115
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2024081250-taco-simmering-1043@gregkh' --subject-prefix 'PATCH 6.10.y' HEAD^..

Possible dependencies:

e0391e92f9ab ("btrfs: fix double inode unlock for direct IO sync writes") 56b7169f691c ("btrfs: use a btrfs_inode local variable at btrfs_sync_file()") e641e323abb3 ("btrfs: pass a btrfs_inode to btrfs_wait_ordered_range()")

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From e0391e92f9ab4fb3dbdeb139c967dcfa7ac4b115 Mon Sep 17 00:00:00 2001
From: Filipe Manana <[email protected]>
Date: Fri, 2 Aug 2024 09:38:51 +0100
Subject: [PATCH] btrfs: fix double inode unlock for direct IO sync writes

If we do a direct IO sync write, at btrfs_sync_file(), and we need to skip inode logging or we get an error starting a transaction or an error when flushing delalloc, we end up unlocking the inode when we shouldn't under the 'out_release_extents' label, and then unlock it again at btrfs_direct_write().

Fix that by checking if we have to skip inode unlocking under that label.

Reported-by [email protected]
Fixes 939b656bc8ab ("btrfs: fix corruption after buffer fault in during direct IO append write")
fs/btrfs/file.c +4 -1
index 9f10a9f23fcc..9914419f3b7d 100644
@@ -1868,7 +1868,10 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 
 out_release_extents:
 	btrfs_release_log_ctx_extents(&ctx);
-	btrfs_inode_unlock(inode, BTRFS_ILOCK_MMAP);
+	if (skip_ilock)
+		up_write(&inode->i_mmap_lock);
+	else
+		btrfs_inode_unlock(inode, BTRFS_ILOCK_MMAP);
 	goto out;
 }
 
#1 lore raw
Quoted 16 lines · On Mon, Aug 12, 2024 at 4:07 PM <[email protected]> wrote:

The patch below does not apply to the 6.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.10.y
git checkout FETCH_HEAD
git cherry-pick -x e0391e92f9ab4fb3dbdeb139c967dcfa7ac4b115
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2024081250-taco-simmering-1043@gregkh' --subject-prefix 'PATCH 6.10.y' HEAD^..

Quoted 5 lines

Possible dependencies:

e0391e92f9ab ("btrfs: fix double inode unlock for direct IO sync writes") 56b7169f691c ("btrfs: use a btrfs_inode local variable at btrfs_sync_file()") e641e323abb3 ("btrfs: pass a btrfs_inode to btrfs_wait_ordered_range()")

I have a version of the fix ready and tested for each stable branch, I'll send them out soon with you and stable@ in cc.

Thanks.

Quoted 44 lines

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From e0391e92f9ab4fb3dbdeb139c967dcfa7ac4b115 Mon Sep 17 00:00:00 2001
From: Filipe Manana <[email protected]>
Date: Fri, 2 Aug 2024 09:38:51 +0100
Subject: [PATCH] btrfs: fix double inode unlock for direct IO sync writes

If we do a direct IO sync write, at btrfs_sync_file(), and we need to skip inode logging or we get an error starting a transaction or an error when flushing delalloc, we end up unlocking the inode when we shouldn't under the 'out_release_extents' label, and then unlock it again at btrfs_direct_write().

Fix that by checking if we have to skip inode unlocking under that label.

Reported-by [email protected]
Fixes 939b656bc8ab ("btrfs: fix corruption after buffer fault in during direct IO append write")
fs/btrfs/file.c +4 -1
index 9f10a9f23fcc..9914419f3b7d 100644
@@ -1868,7 +1868,10 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 
 out_release_extents:
        btrfs_release_log_ctx_extents(&ctx);
-       btrfs_inode_unlock(inode, BTRFS_ILOCK_MMAP);
+       if (skip_ilock)
+               up_write(&inode->i_mmap_lock);
+       else
+               btrfs_inode_unlock(inode, BTRFS_ILOCK_MMAP);
        goto out;
 }