The read IO path provides callout for configuring ioend. This allows
filesystem to add verification of completed BIOs. The
xfs_prepare_read_ioend() configures bio->bi_end_io which places
verification task in the workqueue. The task does fs-verity
verification and then call back to the iomap to finish IO.

This patch add callouts implementation to verify pages with
fs-verity. Also implements folio operation .verify_folio for direct
folio verification by fs-verity.

Signed-off-by: Andrey Albershteyn <aalbe...@redhat.com>
---
 fs/xfs/xfs_aops.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_iomap.c | 11 +++++++++++
 fs/xfs/xfs_linux.h |  1 +
 3 files changed, 57 insertions(+)

diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index daa0dd4768fb..2a3ab5afd665 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -548,6 +548,49 @@ xfs_vm_bmap(
        return iomap_bmap(mapping, block, &xfs_read_iomap_ops);
 }
 
+static void
+xfs_read_work_end_io(
+       struct work_struct *work)
+{
+       struct iomap_read_ioend *ioend =
+               container_of(work, struct iomap_read_ioend, work);
+       struct bio *bio = &ioend->read_inline_bio;
+
+       fsverity_verify_bio(bio);
+       iomap_read_end_io(bio);
+       /*
+        * The iomap_read_ioend has been freed by bio_put() in
+        * iomap_read_end_io()
+        */
+}
+
+static void
+xfs_read_end_io(
+       struct bio *bio)
+{
+       struct iomap_read_ioend *ioend =
+               container_of(bio, struct iomap_read_ioend, read_inline_bio);
+       struct xfs_inode        *ip = XFS_I(ioend->io_inode);
+
+       WARN_ON_ONCE(!queue_work(ip->i_mount->m_postread_workqueue,
+                                       &ioend->work));
+}
+
+static void
+xfs_prepare_read_ioend(
+       struct iomap_read_ioend *ioend)
+{
+       if (!fsverity_active(ioend->io_inode))
+               return;
+
+       INIT_WORK(&ioend->work, &xfs_read_work_end_io);
+       ioend->read_inline_bio.bi_end_io = &xfs_read_end_io;
+}
+
+static const struct iomap_readpage_ops xfs_readpage_ops = {
+       .prepare_ioend          = &xfs_prepare_read_ioend,
+};
+
 STATIC int
 xfs_vm_read_folio(
        struct file                     *unused,
@@ -555,6 +598,7 @@ xfs_vm_read_folio(
 {
        struct iomap_readpage_ctx       ctx = {
                .cur_folio              = folio,
+               .ops                    = &xfs_readpage_ops,
        };
 
        return iomap_read_folio(&ctx, &xfs_read_iomap_ops);
@@ -566,6 +610,7 @@ xfs_vm_readahead(
 {
        struct iomap_readpage_ctx       ctx = {
                .rac                    = rac,
+               .ops                    = &xfs_readpage_ops,
        };
 
        iomap_readahead(&ctx, &xfs_read_iomap_ops);
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 285885c308bd..e0f3c5d709f6 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -27,6 +27,7 @@
 #include "xfs_dquot_item.h"
 #include "xfs_dquot.h"
 #include "xfs_reflink.h"
+#include "xfs_verity.h"
 
 #define XFS_ALLOC_ALIGN(mp, off) \
        (((off) >> mp->m_allocsize_log) << mp->m_allocsize_log)
@@ -83,8 +84,18 @@ xfs_iomap_valid(
        return true;
 }
 
+static bool
+xfs_verify_folio(
+       struct folio    *folio,
+       loff_t          pos,
+       unsigned int    len)
+{
+       return fsverity_verify_folio(folio, len, pos);
+}
+
 static const struct iomap_folio_ops xfs_iomap_folio_ops = {
        .iomap_valid            = xfs_iomap_valid,
+       .verify_folio           = xfs_verify_folio,
 };
 
 int
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index e88f18f85e4b..c574fbf4b67d 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -63,6 +63,7 @@ typedef __u32                 xfs_nlink_t;
 #include <linux/rhashtable.h>
 #include <linux/xattr.h>
 #include <linux/mnt_idmapping.h>
+#include <linux/fsverity.h>
 
 #include <asm/page.h>
 #include <asm/div64.h>
-- 
2.38.4



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to