summaryrefslogtreecommitdiff
path: root/fs/verity/verify.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2019-12-31 11:55:45 -0600
committerEric Biggers <ebiggers@google.com>2020-01-14 13:28:05 -0800
commit439bea104c3d212def0216aa8c0820872266c5b3 (patch)
tree1de5689485baeaac6b66822c57a519021a203469 /fs/verity/verify.c
parentfd39073dba8632575b920edefba2577e1b84262a (diff)
fs-verity: use mempool for hash requests
When initializing an fs-verity hash algorithm, also initialize a mempool that contains a single preallocated hash request object. Then replace the direct calls to ahash_request_alloc() and ahash_request_free() with allocating and freeing from this mempool. This eliminates the possibility of the allocation failing, which is desirable for the I/O path. This doesn't cause deadlocks because there's no case where multiple hash requests are needed at a time to make forward progress. Link: https://lore.kernel.org/r/20191231175545.20709-1-ebiggers@kernel.org Reviewed-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Eric Biggers <ebiggers@google.com>
Diffstat (limited to 'fs/verity/verify.c')
-rw-r--r--fs/verity/verify.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/fs/verity/verify.c b/fs/verity/verify.c
index 7fa561c343c2..e0cb62da3864 100644
--- a/fs/verity/verify.c
+++ b/fs/verity/verify.c
@@ -192,13 +192,12 @@ bool fsverity_verify_page(struct page *page)
struct ahash_request *req;
bool valid;
- req = ahash_request_alloc(vi->tree_params.hash_alg->tfm, GFP_NOFS);
- if (unlikely(!req))
- return false;
+ /* This allocation never fails, since it's mempool-backed. */
+ req = fsverity_alloc_hash_request(vi->tree_params.hash_alg, GFP_NOFS);
valid = verify_page(inode, vi, req, page, 0);
- ahash_request_free(req);
+ fsverity_free_hash_request(vi->tree_params.hash_alg, req);
return valid;
}
@@ -229,12 +228,8 @@ void fsverity_verify_bio(struct bio *bio)
struct bvec_iter_all iter_all;
unsigned long max_ra_pages = 0;
- req = ahash_request_alloc(params->hash_alg->tfm, GFP_NOFS);
- if (unlikely(!req)) {
- bio_for_each_segment_all(bv, bio, iter_all)
- SetPageError(bv->bv_page);
- return;
- }
+ /* This allocation never fails, since it's mempool-backed. */
+ req = fsverity_alloc_hash_request(params->hash_alg, GFP_NOFS);
if (bio->bi_opf & REQ_RAHEAD) {
/*
@@ -262,7 +257,7 @@ void fsverity_verify_bio(struct bio *bio)
SetPageError(page);
}
- ahash_request_free(req);
+ fsverity_free_hash_request(params->hash_alg, req);
}
EXPORT_SYMBOL_GPL(fsverity_verify_bio);
#endif /* CONFIG_BLOCK */