summaryrefslogtreecommitdiffstats
path: root/fs/verity/enable.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/enable.c
parentfd39073dba8632575b920edefba2577e1b84262a (diff)
downloadlinux-439bea104c3d212def0216aa8c0820872266c5b3.tar.gz
linux-439bea104c3d212def0216aa8c0820872266c5b3.tar.bz2
linux-439bea104c3d212def0216aa8c0820872266c5b3.zip
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/enable.c')
-rw-r--r--fs/verity/enable.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/fs/verity/enable.c b/fs/verity/enable.c
index efc79a2cedf2..f8535732905f 100644
--- a/fs/verity/enable.c
+++ b/fs/verity/enable.c
@@ -165,9 +165,11 @@ static int build_merkle_tree(struct file *filp,
return 0;
}
+ /* This allocation never fails, since it's mempool-backed. */
+ req = fsverity_alloc_hash_request(params->hash_alg, GFP_KERNEL);
+
pending_hashes = kmalloc(params->block_size, GFP_KERNEL);
- req = ahash_request_alloc(params->hash_alg->tfm, GFP_KERNEL);
- if (!pending_hashes || !req)
+ if (!pending_hashes)
goto out;
/*
@@ -189,7 +191,7 @@ static int build_merkle_tree(struct file *filp,
err = 0;
out:
kfree(pending_hashes);
- ahash_request_free(req);
+ fsverity_free_hash_request(params->hash_alg, req);
return err;
}