Commit 47bc2ac9 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Eric Biggers
Browse files

fsverity: push out fsverity_info lookup



Pass a struct fsverity_info to the verification and readahead helpers,
and push the lookup into the callers.  Right now this is a very dumb
almost mechanic move that open codes a lot of fsverity_info_addr() calls
in the file systems.  The subsequent patches will clean this up.

This prepares for reducing the number of fsverity_info lookups, which
will allow to amortize them better when using a more expensive lookup
method.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
Acked-by: David Sterba <dsterba@suse.com> # btrfs
Link: https://lore.kernel.org/r/20260202060754.270269-7-hch@lst.de


Signed-off-by: default avatarEric Biggers <ebiggers@kernel.org>
parent 7e36e044
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -484,7 +484,8 @@ static bool btrfs_verify_folio(struct folio *folio, u64 start, u32 len)
	    btrfs_folio_test_uptodate(fs_info, folio, start, len) ||
	    start >= i_size_read(folio->mapping->host))
		return true;
	return fsverity_verify_folio(folio);
	return fsverity_verify_folio(*fsverity_info_addr(folio->mapping->host),
			folio);
}

static void end_folio_read(struct folio *folio, bool uptodate, u64 start, u32 len)
+3 −1
Original line number Diff line number Diff line
@@ -309,9 +309,11 @@ static void verify_bh(struct work_struct *work)
	struct postprocess_bh_ctx *ctx =
		container_of(work, struct postprocess_bh_ctx, work);
	struct buffer_head *bh = ctx->bh;
	struct inode *inode = bh->b_folio->mapping->host;
	bool valid;

	valid = fsverity_verify_blocks(bh->b_folio, bh->b_size, bh_offset(bh));
	valid = fsverity_verify_blocks(*fsverity_info_addr(inode), bh->b_folio,
				       bh->b_size, bh_offset(bh));
	end_buffer_async_read(bh, valid);
	kfree(ctx);
}
+9 −5
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ static void verity_work(struct work_struct *work)
	struct bio_post_read_ctx *ctx =
		container_of(work, struct bio_post_read_ctx, work);
	struct bio *bio = ctx->bio;
	struct inode *inode = bio_first_folio_all(bio)->mapping->host;

	/*
	 * fsverity_verify_bio() may call readahead() again, and although verity
@@ -109,7 +110,7 @@ static void verity_work(struct work_struct *work)
	mempool_free(ctx, bio_post_read_ctx_pool);
	bio->bi_private = NULL;

	fsverity_verify_bio(bio);
	fsverity_verify_bio(*fsverity_info_addr(inode), bio);

	__read_end_io(bio);
}
@@ -331,7 +332,9 @@ static int ext4_mpage_readpages(struct inode *inode,
					  folio_size(folio));
			if (first_hole == 0) {
				if (ext4_need_verity(inode, folio->index) &&
				    !fsverity_verify_folio(folio))
				    !fsverity_verify_folio(
						*fsverity_info_addr(inode),
						folio))
					goto set_error_page;
				folio_end_read(folio, true);
				continue;
@@ -409,7 +412,8 @@ int ext4_read_folio(struct file *file, struct folio *folio)
	}

	if (ext4_need_verity(inode, folio->index))
		fsverity_readahead(inode, folio->index, folio_nr_pages(folio));
		fsverity_readahead(*fsverity_info_addr(inode), folio->index,
				   folio_nr_pages(folio));
	return ext4_mpage_readpages(inode, NULL, folio);
}

@@ -422,8 +426,8 @@ void ext4_readahead(struct readahead_control *rac)
		return;

	if (ext4_need_verity(inode, readahead_index(rac)))
		fsverity_readahead(inode, readahead_index(rac),
				   readahead_count(rac));
		fsverity_readahead(*fsverity_info_addr(inode),
				   readahead_index(rac), readahead_count(rac));
	ext4_mpage_readpages(inode, rac, NULL);
}

+3 −1
Original line number Diff line number Diff line
@@ -1814,7 +1814,9 @@ static void f2fs_verify_cluster(struct work_struct *work)
		if (!rpage)
			continue;

		if (fsverity_verify_page(rpage))
		if (fsverity_verify_page(
				*fsverity_info_addr(rpage->mapping->host),
				rpage))
			SetPageUptodate(rpage);
		else
			ClearPageUptodate(rpage);
+13 −6
Original line number Diff line number Diff line
@@ -185,15 +185,19 @@ static void f2fs_verify_bio(struct work_struct *work)

		bio_for_each_folio_all(fi, bio) {
			struct folio *folio = fi.folio;
			struct fsverity_info *vi =
				*fsverity_info_addr(folio->mapping->host);

			if (!f2fs_is_compressed_page(folio) &&
			    !fsverity_verify_page(&folio->page)) {
			    !fsverity_verify_page(vi, &folio->page)) {
				bio->bi_status = BLK_STS_IOERR;
				break;
			}
		}
	} else {
		fsverity_verify_bio(bio);
		struct inode *inode = bio_first_folio_all(bio)->mapping->host;

		fsverity_verify_bio(*fsverity_info_addr(inode), bio);
	}

	f2fs_finish_read_bio(bio, true);
@@ -2121,7 +2125,9 @@ static int f2fs_read_single_page(struct inode *inode, struct folio *folio,
zero_out:
		folio_zero_segment(folio, 0, folio_size(folio));
		if (f2fs_need_verity(inode, index) &&
		    !fsverity_verify_folio(folio)) {
		    !fsverity_verify_folio(
				*fsverity_info_addr(folio->mapping->host),
				folio)) {
			ret = -EIO;
			goto out;
		}
@@ -2475,7 +2481,8 @@ static int f2fs_read_data_folio(struct file *file, struct folio *folio)
	}

	if (f2fs_need_verity(inode, folio->index))
		fsverity_readahead(inode, folio->index, folio_nr_pages(folio));
		fsverity_readahead(*fsverity_info_addr(inode), folio->index,
				   folio_nr_pages(folio));
	return f2fs_mpage_readpages(inode, NULL, folio);
}

@@ -2493,8 +2500,8 @@ static void f2fs_readahead(struct readahead_control *rac)
		return;

	if (f2fs_need_verity(inode, readahead_index(rac)))
		fsverity_readahead(inode, readahead_index(rac),
				   readahead_count(rac));
		fsverity_readahead(*fsverity_info_addr(inode),
				   readahead_index(rac), readahead_count(rac));
	f2fs_mpage_readpages(inode, rac, NULL);
}

Loading