diff mbox series

mm: folio_wait_stable() should check for bdev

Message ID 20231103050949.480892-1-dongyangli@ddn.com (mailing list archive)
State New, archived
Headers show
Series mm: folio_wait_stable() should check for bdev | expand

Commit Message

Li Dongyang Nov. 3, 2023, 5:09 a.m. UTC
folio_wait_stable() now checks SB_I_STABLE_WRITES
flag on the superblock instead of backing_dev_info,
this could trigger a false block integrity error when
doing buffered write directly to the block device,
as folio_wait_stable() is a noop for bdev and the
content could be modified during writeback.

Check if the folio's superblock is bdev and wait for
writeback if the backing device requires stables_writes.

Fixes: 1cb039f3dc16 ("bdi: replace BDI_CAP_STABLE_WRITES with a queue and a sb flag")
Signed-off-by: Li Dongyang <dongyangli@ddn.com>
---
This patch supersedes the previous
block: add SB_I_STABLE_WRITES to bdev sb flag
---
---
 mm/page-writeback.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig Nov. 3, 2023, 8:11 a.m. UTC | #1
On Fri, Nov 03, 2023 at 04:09:49PM +1100, Li Dongyang wrote:
> folio_wait_stable() now checks SB_I_STABLE_WRITES
> flag on the superblock instead of backing_dev_info,
> this could trigger a false block integrity error when
> doing buffered write directly to the block device,
> as folio_wait_stable() is a noop for bdev and the
> content could be modified during writeback.
> 
> Check if the folio's superblock is bdev and wait for
> writeback if the backing device requires stables_writes.

https://lore.kernel.org/lkml/CAOi1vP9Zit-A9rRk9jy+d1itaBzUSBzFBuhXE+EDfBtF-Mf0og@mail.gmail.com/T/#t

https://lore.kernel.org/all/20231024064416.897956-1-hch@lst.de/
diff mbox series

Patch

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index b8d3d7040a50..a236f93347a1 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -3110,7 +3110,11 @@  EXPORT_SYMBOL_GPL(folio_wait_writeback_killable);
  */
 void folio_wait_stable(struct folio *folio)
 {
-	if (folio_inode(folio)->i_sb->s_iflags & SB_I_STABLE_WRITES)
+	struct inode *inode = folio_inode(folio);
+
+	if (inode->i_sb->s_iflags & SB_I_STABLE_WRITES ||
+	    (sb_is_blkdev_sb(inode->i_sb) &&
+	     bdev_stable_writes(I_BDEV(inode))))
 		folio_wait_writeback(folio);
 }
 EXPORT_SYMBOL_GPL(folio_wait_stable);