Whamcloud - gitweb
LU-17248 kernel: wait for pages under writeback for bdev 22/52922/6
authorLi Dongyang <dongyangli@ddn.com>
Wed, 1 Nov 2023 11:36:10 +0000 (22:36 +1100)
committerOleg Drokin <green@whamcloud.com>
Sat, 23 Mar 2024 05:52:59 +0000 (05:52 +0000)
Since RHEL 8.6 wait_for_stable_page() is controlled by
a new flag SB_I_STABLE_WRITES on the super block.

However the new flag is not set on the bdev pseudo sb,
which mean when doing write directly to the block device
we are not waiting on page writeback, this could trigger
false block integrity errors, as page could be modified
again when under writeback, the integrity checksum does
not match the new data any more.

Upstream has a pending patch
https://lore.kernel.org/linux-mm/20231025141020.192413-1-hch@lst.de/
which works for RHEL 9 kernels.

For RHEL 8 kernels the changes for bdev made it difficult
to backport, a different patch is used to check and wait
for bdev stable_pages.

Change-Id: Ie088abf29f40b294c31f993bcfad56d6081a3fce
Test-Parameters: trivial
Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52922
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/kernel_patches/patches/add-and-use-a-per-mapping-stable-writes-flag-rhel9.patch [new file with mode: 0644]
lustre/kernel_patches/patches/mm-wait_for_stable_page-should-check-for-bdev-rhel8.6.patch [new file with mode: 0644]
lustre/kernel_patches/series/4.18-rhel8.6.series
lustre/kernel_patches/series/4.18-rhel8.7.series
lustre/kernel_patches/series/4.18-rhel8.8.series
lustre/kernel_patches/series/4.18-rhel8.9.series
lustre/kernel_patches/series/5.14-rhel9.1.series
lustre/kernel_patches/series/5.14-rhel9.2.series
lustre/kernel_patches/series/5.14-rhel9.3.series

diff --git a/lustre/kernel_patches/patches/add-and-use-a-per-mapping-stable-writes-flag-rhel9.patch b/lustre/kernel_patches/patches/add-and-use-a-per-mapping-stable-writes-flag-rhel9.patch
new file mode 100644 (file)
index 0000000..b74b27d
--- /dev/null
@@ -0,0 +1,74 @@
+Index: linux-5.14.0-162.23.1.el9_1/block/bdev.c
+===================================================================
+--- linux-5.14.0-162.23.1.el9_1.orig/block/bdev.c
++++ linux-5.14.0-162.23.1.el9_1/block/bdev.c
+@@ -506,6 +506,8 @@ struct block_device *bdev_alloc(struct g
+ void bdev_add(struct block_device *bdev, dev_t dev)
+ {
++      if (bdev_stable_writes(bdev))
++              mapping_set_stable_writes(bdev->bd_inode->i_mapping);
+       bdev->bd_dev = dev;
+       bdev->bd_inode->i_rdev = dev;
+       bdev->bd_inode->i_ino = dev;
+Index: linux-5.14.0-162.23.1.el9_1/fs/inode.c
+===================================================================
+--- linux-5.14.0-162.23.1.el9_1.orig/fs/inode.c
++++ linux-5.14.0-162.23.1.el9_1/fs/inode.c
+@@ -192,6 +192,8 @@ int inode_init_always(struct super_block
+       lockdep_set_class_and_name(&mapping->invalidate_lock,
+                                  &sb->s_type->invalidate_lock_key,
+                                  "mapping.invalidate_lock");
++      if (sb->s_iflags & SB_I_STABLE_WRITES)
++              mapping_set_stable_writes(mapping);
+       inode->i_private = NULL;
+       inode->i_mapping = mapping;
+       INIT_HLIST_HEAD(&inode->i_dentry);      /* buggered by rcu freeing */
+Index: linux-5.14.0-162.23.1.el9_1/include/linux/pagemap.h
+===================================================================
+--- linux-5.14.0-162.23.1.el9_1.orig/include/linux/pagemap.h
++++ linux-5.14.0-162.23.1.el9_1/include/linux/pagemap.h
+@@ -147,6 +147,8 @@ enum mapping_flags {
+       /* writeback related tags are not used */
+       AS_NO_WRITEBACK_TAGS = 5,
+       AS_LARGE_FOLIO_SUPPORT = 6,
++      AS_STABLE_WRITES,       /* must wait for writeback before modifying
++                                 folio contents */
+ };
+ /**
+@@ -217,6 +219,21 @@ static inline int mapping_use_writeback_
+       return !test_bit(AS_NO_WRITEBACK_TAGS, &mapping->flags);
+ }
++static inline bool mapping_stable_writes(const struct address_space *mapping)
++{
++      return test_bit(AS_STABLE_WRITES, &mapping->flags);
++}
++
++static inline void mapping_set_stable_writes(struct address_space *mapping)
++{
++      set_bit(AS_STABLE_WRITES, &mapping->flags);
++}
++
++static inline void mapping_clear_stable_writes(struct address_space *mapping)
++{
++      clear_bit(AS_STABLE_WRITES, &mapping->flags);
++}
++
+ static inline gfp_t mapping_gfp_mask(struct address_space * mapping)
+ {
+       return mapping->gfp_mask;
+Index: linux-5.14.0-162.23.1.el9_1/mm/page-writeback.c
+===================================================================
+--- linux-5.14.0-162.23.1.el9_1.orig/mm/page-writeback.c
++++ linux-5.14.0-162.23.1.el9_1/mm/page-writeback.c
+@@ -2965,7 +2965,7 @@ EXPORT_SYMBOL_GPL(folio_wait_writeback_k
+  */
+ void folio_wait_stable(struct folio *folio)
+ {
+-      if (folio_inode(folio)->i_sb->s_iflags & SB_I_STABLE_WRITES)
++      if (mapping_stable_writes(folio_mapping(folio)))
+               folio_wait_writeback(folio);
+ }
+ EXPORT_SYMBOL_GPL(folio_wait_stable);
diff --git a/lustre/kernel_patches/patches/mm-wait_for_stable_page-should-check-for-bdev-rhel8.6.patch b/lustre/kernel_patches/patches/mm-wait_for_stable_page-should-check-for-bdev-rhel8.6.patch
new file mode 100644 (file)
index 0000000..9b03738
--- /dev/null
@@ -0,0 +1,18 @@
+Index: linux-4.18.0-372.32.1.el8_6/mm/page-writeback.c
+===================================================================
+--- linux-4.18.0-372.32.1.el8_6.orig/mm/page-writeback.c
++++ linux-4.18.0-372.32.1.el8_6/mm/page-writeback.c
+@@ -2894,7 +2894,12 @@ EXPORT_SYMBOL_GPL(wait_on_page_writeback
+  */
+ void wait_for_stable_page(struct page *page)
+ {
+-      if (page->mapping->host->i_sb->s_iflags & SB_I_STABLE_WRITES)
++      struct inode *inode = page->mapping->host;
++      struct super_block *sb = inode->i_sb;
++
++      if ((sb->s_iflags & SB_I_STABLE_WRITES) ||
++          (sb_is_blkdev_sb(sb) &&
++           blk_queue_stable_writes(I_BDEV(inode)->bd_disk->queue)))
+               wait_on_page_writeback(page);
+ }
+ EXPORT_SYMBOL_GPL(wait_for_stable_page);
index 0719776..8d9a7f7 100644 (file)
@@ -2,3 +2,4 @@ block-bio-integrity-Advance-seed-correctly-for-large.patch
 block-integrity-allow-optional-integrity-functions-rhel8.3.patch
 block-pass-bio-into-integrity_processing_fn-rhel8.patch
 jbd2-revoke-rhashtable-rhel8.4.patch
+mm-wait_for_stable_page-should-check-for-bdev-rhel8.6.patch
index 4b95dad..04cc58e 100644 (file)
@@ -1,3 +1,4 @@
 block-integrity-allow-optional-integrity-functions-rhel8.3.patch
 block-pass-bio-into-integrity_processing_fn-rhel8.patch
 jbd2-revoke-rhashtable-rhel8.4.patch
+mm-wait_for_stable_page-should-check-for-bdev-rhel8.6.patch
index 4b95dad..04cc58e 100644 (file)
@@ -1,3 +1,4 @@
 block-integrity-allow-optional-integrity-functions-rhel8.3.patch
 block-pass-bio-into-integrity_processing_fn-rhel8.patch
 jbd2-revoke-rhashtable-rhel8.4.patch
+mm-wait_for_stable_page-should-check-for-bdev-rhel8.6.patch
index 4b95dad..04cc58e 100644 (file)
@@ -1,3 +1,4 @@
 block-integrity-allow-optional-integrity-functions-rhel8.3.patch
 block-pass-bio-into-integrity_processing_fn-rhel8.patch
 jbd2-revoke-rhashtable-rhel8.4.patch
+mm-wait_for_stable_page-should-check-for-bdev-rhel8.6.patch
index e32e8f0..a3c8f85 100644 (file)
@@ -1,3 +1,4 @@
 block-integrity-allow-optional-integrity-functions-rhel9.1.patch
 block-pass-bio-into-integrity_processing_fn-rhel9.patch
 jbd2-revoke-rhashtable-rhel8.4.patch
+add-and-use-a-per-mapping-stable-writes-flag-rhel9.patch
index e32e8f0..a3c8f85 100644 (file)
@@ -1,3 +1,4 @@
 block-integrity-allow-optional-integrity-functions-rhel9.1.patch
 block-pass-bio-into-integrity_processing_fn-rhel9.patch
 jbd2-revoke-rhashtable-rhel8.4.patch
+add-and-use-a-per-mapping-stable-writes-flag-rhel9.patch
index 2102438..c737f7f 100644 (file)
@@ -1,3 +1,4 @@
 block-integrity-allow-optional-integrity-functions-rhel9.3.patch
 block-pass-bio-into-integrity_processing_fn-rhel9.patch
 jbd2-revoke-rhashtable-rhel8.4.patch
+add-and-use-a-per-mapping-stable-writes-flag-rhel9.patch