Skip to contentSkip to conversation

fs-verity: use memcpy_from_page()

PATCH In review Eric Biggers 2 participants 2 messages Aug 18, 2022 – Aug 19, 2022

Subsystems (4)
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH 1/1 fs-verity: use memcpy_from_page()

From: Eric Biggers <[email protected]>

Replace extract_hash() with the memcpy_from_page() helper function.

This is simpler, and it has the side effect of replacing the use of kmap_atomic() with its recommended replacement kmap_local_page().

---
 fs/verity/verify.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
fs/verity/verify.c +2 -12
index 14e2fb49cff561..bde8c9b7d25f64 100644
@@ -39,16 +39,6 @@ static void hash_at_level(const struct merkle_tree_params *params,
 		   (params->log_blocksize - params->log_arity);
 }
 
-/* Extract a hash from a hash page */
-static void extract_hash(struct page *hpage, unsigned int hoffset,
-			 unsigned int hsize, u8 *out)
-{
-	void *virt = kmap_atomic(hpage);
-
-	memcpy(out, virt + hoffset, hsize);
-	kunmap_atomic(virt);
-}
-
 static inline int cmp_hashes(const struct fsverity_info *vi,
 			     const u8 *want_hash, const u8 *real_hash,
 			     pgoff_t index, int level)
@@ -129,7 +119,7 @@ static bool verify_page(struct inode *inode, const struct fsverity_info *vi,
 		}
 
 		if (PageChecked(hpage)) {
-			extract_hash(hpage, hoffset, hsize, _want_hash);
+			memcpy_from_page(_want_hash, hpage, hoffset, hsize);
 			want_hash = _want_hash;
 			put_page(hpage);
 			pr_debug_ratelimited("Hash page already checked, want %s:%*phN\n",
@@ -158,7 +148,7 @@ static bool verify_page(struct inode *inode, const struct fsverity_info *vi,
 		if (err)
 			goto out;
 		SetPageChecked(hpage);
-		extract_hash(hpage, hoffset, hsize, _want_hash);
+		memcpy_from_page(_want_hash, hpage, hoffset, hsize);
 		want_hash = _want_hash;
 		put_page(hpage);
 		pr_debug("Verified hash page at level %d, now want %s:%*phN\n",

base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868

Signature · 1 line
2.37.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · CEST Eric Biggers

From: Eric Biggers <[email protected]>

Replace extract_hash() with the memcpy_from_page() helper function.

Quoted 8 lines

This is simpler, and it has the side effect of replacing the use of kmap_atomic() with its recommended replacement kmap_local_page().

---
 fs/verity/verify.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

It looks good to me...

Thanks,

Fabio

fs/verity/verify.c static void hash_at_level(const struct merkle_tree_params

Quoted 5 lines
fs/verity/verify.c +0 -0
index 14e2fb49cff561..bde8c9b7d25f64 100644
@@ -39,16 +39,6 @@ static void hash_at_level(const struct merkle_tree_params 

*params,

Quoted 5 lines
fs/verity/verify.c +0 -2
 		   (params->log_blocksize - params->log_arity);
 }
 
-/* Extract a hash from a hash page */
-static void extract_hash(struct page *hpage, unsigned int hoffset,

fs/verity/verify.c static void hash_at_level(const struct merkle_tree_params *params,

Quoted 10 lines
fs/verity/verify.c +0 -8
-			 unsigned int hsize, u8 *out)
-{
-	void *virt = kmap_atomic(hpage);
-
-	memcpy(out, virt + hoffset, hsize);
-	kunmap_atomic(virt);
-}
-
 static inline int cmp_hashes(const struct fsverity_info *vi,
 			     const u8 *want_hash, const u8 

*real_hash,

fs/verity/verify.c static bool verify_page(struct inode *inode, const

Quoted 2 lines
fs/verity/verify.c +0 -0
 			     pgoff_t index, int level)
@@ -129,7 +119,7 @@ static bool verify_page(struct inode *inode, const 

struct fsverity_info *vi,

fs/verity/verify.c static bool verify_page(struct inode *inode, const struct fsverity_info *vi,

Quoted 4 lines
fs/verity/verify.c +0 -1
 		}
 
 		if (PageChecked(hpage)) {
-			extract_hash(hpage, hoffset, hsize, 

_want_hash);

fs/verity/verify.c static bool verify_page(struct inode *inode, const · line 122

Quoted 1 line
fs/verity/verify.c +1 -0
+			memcpy_from_page(_want_hash, hpage, hoffset, 

hsize);

fs/verity/verify.c static bool verify_page(struct inode *inode, const struct fsverity_info *vi,

Quoted 3 lines
fs/verity/verify.c +0 -0
 			want_hash = _want_hash;
 			put_page(hpage);
 			pr_debug_ratelimited("Hash page already 

checked, want %s:%*phN\n",

fs/verity/verify.c static bool verify_page(struct inode *inode, const

Quoted 1 line
fs/verity/verify.c +0 -0
@@ -158,7 +148,7 @@ static bool verify_page(struct inode *inode, const 

struct fsverity_info *vi,

fs/verity/verify.c static bool verify_page(struct inode *inode, const struct fsverity_info *vi,

Quoted 8 lines
fs/verity/verify.c +1 -1
 		if (err)
 			goto out;
 		SetPageChecked(hpage);
-		extract_hash(hpage, hoffset, hsize, _want_hash);
+		memcpy_from_page(_want_hash, hpage, hoffset, hsize);
 		want_hash = _want_hash;
 		put_page(hpage);
 		pr_debug("Verified hash page at level %d, now want %s:

%*phN\n",

Quoted 6 lines

base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868

Signature · 1 line
2.37.1