Helper to pre-fill folio with hashes of empty blocks. This will be used by iomap to synthesize blocks full of zero hashes on the fly. Signed-off-by: Andrey Albershteyn --- fs/verity/pagecache.c | 22 ++++++++++++++++++++++ include/linux/fsverity.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/fs/verity/pagecache.c b/fs/verity/pagecache.c index 1819314ecaa3..1d94bf73f38c 100644 --- a/fs/verity/pagecache.c +++ b/fs/verity/pagecache.c @@ -2,6 +2,7 @@ /* * Copyright 2019 Google LLC */ +#include "fsverity_private.h" #include #include @@ -56,3 +57,24 @@ void generic_readahead_merkle_tree(struct inode *inode, pgoff_t index, folio_put(folio); } EXPORT_SYMBOL_GPL(generic_readahead_merkle_tree); + +/** + * fsverity_folio_zero_hash() - fill folio with hashes of zero data block + * @folio: folio to fill + * @poff: offset in the folio to start + * @plen: length of the range to fill with hashes + * @vi: fsverity info + */ +void fsverity_folio_zero_hash(struct folio *folio, size_t poff, size_t plen, + struct fsverity_info *vi) +{ + size_t offset = poff; + + WARN_ON_ONCE(!IS_ALIGNED(poff, vi->tree_params.digest_size)); + WARN_ON_ONCE(!IS_ALIGNED(plen, vi->tree_params.digest_size)); + + for (; offset < (poff + plen); offset += vi->tree_params.digest_size) + memcpy_to_folio(folio, offset, vi->tree_params.zero_digest, + vi->tree_params.digest_size); +} +EXPORT_SYMBOL_GPL(fsverity_folio_zero_hash); diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index 8ba7806b225e..b490b2c8a393 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -321,5 +321,7 @@ void fsverity_cleanup_inode(struct inode *inode); struct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index); void generic_readahead_merkle_tree(struct inode *inode, pgoff_t index, unsigned long nr_pages); +void fsverity_folio_zero_hash(struct folio *folio, size_t poff, size_t plen, + struct fsverity_info *vi); #endif /* _LINUX_FSVERITY_H */ -- 2.51.2