All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs-verity: use memcpy_from_page()
@ 2022-08-18 22:39 Eric Biggers
  2022-08-19 11:16 ` Fabio M. De Francesco
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2022-08-18 22:39 UTC (permalink / raw)
  To: linux-fscrypt; +Cc: linux-fsdevel, linux-mm, Fabio M . De Francesco

From: Eric Biggers <ebiggers@google.com>

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().

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/verity/verify.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/fs/verity/verify.c b/fs/verity/verify.c
index 14e2fb49cff561..bde8c9b7d25f64 100644
--- a/fs/verity/verify.c
+++ b/fs/verity/verify.c
@@ -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
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs-verity: use memcpy_from_page()
  2022-08-18 22:39 [PATCH] fs-verity: use memcpy_from_page() Eric Biggers
@ 2022-08-19 11:16 ` Fabio M. De Francesco
  0 siblings, 0 replies; 2+ messages in thread
From: Fabio M. De Francesco @ 2022-08-19 11:16 UTC (permalink / raw)
  To: linux-fscrypt, Eric Biggers; +Cc: linux-fsdevel, linux-mm

On Friday, August 19, 2022 12:39:03 AM CEST Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> 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().
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>  fs/verity/verify.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)
> 

It looks good to me...

Reviewed-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>

Thanks,

Fabio

> diff --git a/fs/verity/verify.c b/fs/verity/verify.c
> index 14e2fb49cff561..bde8c9b7d25f64 100644
> --- a/fs/verity/verify.c
> +++ b/fs/verity/verify.c
> @@ -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
> -- 
> 2.37.1
> 
> 





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-19 11:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-18 22:39 [PATCH] fs-verity: use memcpy_from_page() Eric Biggers
2022-08-19 11:16 ` Fabio M. De Francesco

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.