linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Eric Biggers <ebiggers@kernel.org>,
	George Cherian <gcherian@marvell.com>,
	Wei Xu <xuwei5@hisilicon.com>, Zaibo Xu <xuzaibo@huawei.com>,
	Mike Snitzer <msnitzer@redhat.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	<linux-kernel@vger.kernel.org>, <dm-devel@redhat.com>,
	<linux-crypto@vger.kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Milan Broz <mbroz@redhat.com>
Subject: Re: [dm-devel] [PATCH 2/2] hisilicon-crypto: don't sleep of CRYPTO_TFM_REQ_MAY_SLEEP was not specified
Date: Wed, 17 Jun 2020 15:11:29 +0100	[thread overview]
Message-ID: <20200617151129.0000195f@Huawei.com> (raw)
In-Reply-To: <alpine.LRH.2.02.2006170949010.18714@file01.intranet.prod.int.rdu2.redhat.com>

On Wed, 17 Jun 2020 09:49:52 -0400
Mikulas Patocka <mpatocka@redhat.com> wrote:

> There is this call chain:
> sec_alg_skcipher_encrypt -> sec_alg_skcipher_crypto ->
> sec_alg_alloc_and_calc_split_sizes -> kcalloc
> where we call sleeping allocator function even if CRYPTO_TFM_REQ_MAY_SLEEP
> was not specified.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org	# v4.19+
> Fixes: 915e4e8413da ("crypto: hisilicon - SEC security accelerator driver")

I don't have a board to hand today to check this, but doesn't seem like it
will cause any problems.

Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> 
> ---
>  drivers/crypto/hisilicon/sec/sec_algs.c |   34 ++++++++++++++++----------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
> 
> Index: linux-2.6/drivers/crypto/hisilicon/sec/sec_algs.c
> ===================================================================
> --- linux-2.6.orig/drivers/crypto/hisilicon/sec/sec_algs.c
> +++ linux-2.6/drivers/crypto/hisilicon/sec/sec_algs.c
> @@ -175,7 +175,8 @@ static int sec_alloc_and_fill_hw_sgl(str
>  				     dma_addr_t *psec_sgl,
>  				     struct scatterlist *sgl,
>  				     int count,
> -				     struct sec_dev_info *info)
> +				     struct sec_dev_info *info,
> +				     gfp_t gfp)
>  {
>  	struct sec_hw_sgl *sgl_current = NULL;
>  	struct sec_hw_sgl *sgl_next;
> @@ -190,7 +191,7 @@ static int sec_alloc_and_fill_hw_sgl(str
>  		sge_index = i % SEC_MAX_SGE_NUM;
>  		if (sge_index == 0) {
>  			sgl_next = dma_pool_zalloc(info->hw_sgl_pool,
> -						   GFP_KERNEL, &sgl_next_dma);
> +						   gfp, &sgl_next_dma);
>  			if (!sgl_next) {
>  				ret = -ENOMEM;
>  				goto err_free_hw_sgls;
> @@ -545,14 +546,14 @@ void sec_alg_callback(struct sec_bd_info
>  }
>  
>  static int sec_alg_alloc_and_calc_split_sizes(int length, size_t **split_sizes,
> -					      int *steps)
> +					      int *steps, gfp_t gfp)
>  {
>  	size_t *sizes;
>  	int i;
>  
>  	/* Split into suitable sized blocks */
>  	*steps = roundup(length, SEC_REQ_LIMIT) / SEC_REQ_LIMIT;
> -	sizes = kcalloc(*steps, sizeof(*sizes), GFP_KERNEL);
> +	sizes = kcalloc(*steps, sizeof(*sizes), gfp);
>  	if (!sizes)
>  		return -ENOMEM;
>  
> @@ -568,7 +569,7 @@ static int sec_map_and_split_sg(struct s
>  				int steps, struct scatterlist ***splits,
>  				int **splits_nents,
>  				int sgl_len_in,
> -				struct device *dev)
> +				struct device *dev, gfp_t gfp)
>  {
>  	int ret, count;
>  
> @@ -576,12 +577,12 @@ static int sec_map_and_split_sg(struct s
>  	if (!count)
>  		return -EINVAL;
>  
> -	*splits = kcalloc(steps, sizeof(struct scatterlist *), GFP_KERNEL);
> +	*splits = kcalloc(steps, sizeof(struct scatterlist *), gfp);
>  	if (!*splits) {
>  		ret = -ENOMEM;
>  		goto err_unmap_sg;
>  	}
> -	*splits_nents = kcalloc(steps, sizeof(int), GFP_KERNEL);
> +	*splits_nents = kcalloc(steps, sizeof(int), gfp);
>  	if (!*splits_nents) {
>  		ret = -ENOMEM;
>  		goto err_free_splits;
> @@ -589,7 +590,7 @@ static int sec_map_and_split_sg(struct s
>  
>  	/* output the scatter list before and after this */
>  	ret = sg_split(sgl, count, 0, steps, split_sizes,
> -		       *splits, *splits_nents, GFP_KERNEL);
> +		       *splits, *splits_nents, gfp);
>  	if (ret) {
>  		ret = -ENOMEM;
>  		goto err_free_splits_nents;
> @@ -630,13 +631,13 @@ static struct sec_request_el
>  			   int el_size, bool different_dest,
>  			   struct scatterlist *sgl_in, int n_ents_in,
>  			   struct scatterlist *sgl_out, int n_ents_out,
> -			   struct sec_dev_info *info)
> +			   struct sec_dev_info *info, gfp_t gfp)
>  {
>  	struct sec_request_el *el;
>  	struct sec_bd_info *req;
>  	int ret;
>  
> -	el = kzalloc(sizeof(*el), GFP_KERNEL);
> +	el = kzalloc(sizeof(*el), gfp);
>  	if (!el)
>  		return ERR_PTR(-ENOMEM);
>  	el->el_length = el_size;
> @@ -668,7 +669,7 @@ static struct sec_request_el
>  	el->sgl_in = sgl_in;
>  
>  	ret = sec_alloc_and_fill_hw_sgl(&el->in, &el->dma_in, el->sgl_in,
> -					n_ents_in, info);
> +					n_ents_in, info, gfp);
>  	if (ret)
>  		goto err_free_el;
>  
> @@ -679,7 +680,7 @@ static struct sec_request_el
>  		el->sgl_out = sgl_out;
>  		ret = sec_alloc_and_fill_hw_sgl(&el->out, &el->dma_out,
>  						el->sgl_out,
> -						n_ents_out, info);
> +						n_ents_out, info, gfp);
>  		if (ret)
>  			goto err_free_hw_sgl_in;
>  
> @@ -720,6 +721,7 @@ static int sec_alg_skcipher_crypto(struc
>  	int *splits_out_nents = NULL;
>  	struct sec_request_el *el, *temp;
>  	bool split = skreq->src != skreq->dst;
> +	gfp_t gfp = skreq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC;
>  
>  	mutex_init(&sec_req->lock);
>  	sec_req->req_base = &skreq->base;
> @@ -728,13 +730,13 @@ static int sec_alg_skcipher_crypto(struc
>  	sec_req->len_in = sg_nents(skreq->src);
>  
>  	ret = sec_alg_alloc_and_calc_split_sizes(skreq->cryptlen, &split_sizes,
> -						 &steps);
> +						 &steps, gfp);
>  	if (ret)
>  		return ret;
>  	sec_req->num_elements = steps;
>  	ret = sec_map_and_split_sg(skreq->src, split_sizes, steps, &splits_in,
>  				   &splits_in_nents, sec_req->len_in,
> -				   info->dev);
> +				   info->dev, gfp);
>  	if (ret)
>  		goto err_free_split_sizes;
>  
> @@ -742,7 +744,7 @@ static int sec_alg_skcipher_crypto(struc
>  		sec_req->len_out = sg_nents(skreq->dst);
>  		ret = sec_map_and_split_sg(skreq->dst, split_sizes, steps,
>  					   &splits_out, &splits_out_nents,
> -					   sec_req->len_out, info->dev);
> +					   sec_req->len_out, info->dev, gfp);
>  		if (ret)
>  			goto err_unmap_in_sg;
>  	}
> @@ -775,7 +777,7 @@ static int sec_alg_skcipher_crypto(struc
>  					       splits_in[i], splits_in_nents[i],
>  					       split ? splits_out[i] : NULL,
>  					       split ? splits_out_nents[i] : 0,
> -					       info);
> +					       info, gfp);
>  		if (IS_ERR(el)) {
>  			ret = PTR_ERR(el);
>  			goto err_free_elements;
> 
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel
> 



      reply	other threads:[~2020-06-17 14:12 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-09 17:11 crypto API and GFP_ATOMIC Mikulas Patocka
2020-06-10  1:04 ` Herbert Xu
2020-06-10 12:02   ` Mikulas Patocka
2020-06-10 12:11     ` Herbert Xu
2020-06-16 15:01       ` Mikulas Patocka
2020-06-16 15:01         ` [PATCH 1/4] crypto: introduce CRYPTO_ALG_ALLOCATES_MEMORY Mikulas Patocka
2020-06-16 17:36           ` [dm-devel] " Eric Biggers
2020-06-17 15:08             ` Mikulas Patocka
2020-06-17 15:09               ` [PATCH 1/3] crypto: pass the flag CRYPTO_ALG_ALLOCATES_MEMORY Mikulas Patocka
2020-06-26  4:45                 ` Herbert Xu
2020-06-26 15:17                   ` Mikulas Patocka
2020-06-26 16:16                     ` [PATCH 1/3 v2] crypto: introduce " Mikulas Patocka
2020-06-26 16:46                       ` Eric Biggers
2020-06-26 17:00                         ` [dm-devel] " Eric Biggers
2020-06-28 19:07                           ` Mikulas Patocka
2020-06-28 19:50                             ` Eric Biggers
2020-06-30 13:57                               ` Mikulas Patocka
2020-06-28 20:00                             ` Eric Biggers
2020-06-29 13:17                               ` Mikulas Patocka
2020-06-30 13:45                                 ` Mikulas Patocka
2020-06-28 19:04                         ` Mikulas Patocka
2020-06-28 19:46                           ` Eric Biggers
2020-06-28 19:05                         ` [PATCH 1/3 v3] " Mikulas Patocka
2020-06-30 13:56                           ` [PATCH 1/3 v4] " Mikulas Patocka
2020-06-30 16:35                             ` [dm-devel] " Eric Biggers
2020-06-30 17:01                               ` Mikulas Patocka
2020-06-30 17:02                                 ` [PATCH 1/3 v5] " Mikulas Patocka
2020-06-30 17:57                                 ` [dm-devel] [PATCH 1/3 v4] " Eric Biggers
2020-06-30 18:14                                   ` Mikulas Patocka
2020-06-30 18:15                                     ` [PATCH 1/3 v6] " Mikulas Patocka
2020-07-01  1:49                                       ` Herbert Xu
2020-06-17 15:10               ` [PATCH 2/3] crypto: set " Mikulas Patocka
2020-06-17 15:11               ` [PATCH 3/3] dm-crypt: don't use drivers that have CRYPTO_ALG_ALLOCATES_MEMORY Mikulas Patocka
2020-06-16 15:01         ` [PATCH 2/4] crypto: pass the flag CRYPTO_ALG_ALLOCATES_MEMORY Mikulas Patocka
2020-06-16 17:42           ` [dm-devel] " Eric Biggers
2020-06-16 15:02         ` [PATCH 3/4] crypto: set " Mikulas Patocka
2020-06-16 17:43           ` [dm-devel] " Eric Biggers
2020-06-16 15:02         ` [PATCH 4/4] crypto: fix the drivers that don't respect CRYPTO_TFM_REQ_MAY_SLEEP Mikulas Patocka
2020-06-16 17:50           ` [dm-devel] " Eric Biggers
2020-06-16 18:18             ` Mikulas Patocka
2020-06-16 18:23               ` Eric Biggers
2020-06-17 13:46                 ` Mikulas Patocka
2020-06-17 13:48                   ` [PATCH 1/2] cpt-crypto: don't sleep of CRYPTO_TFM_REQ_MAY_SLEEP was not specified Mikulas Patocka
2020-06-26  6:07                     ` Herbert Xu
2020-06-17 13:49                   ` [PATCH 2/2] hisilicon-crypto: " Mikulas Patocka
2020-06-17 14:11                     ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200617151129.0000195f@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=davem@davemloft.net \
    --cc=dm-devel@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=gcherian@marvell.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbroz@redhat.com \
    --cc=mpatocka@redhat.com \
    --cc=msnitzer@redhat.com \
    --cc=xuwei5@hisilicon.com \
    --cc=xuzaibo@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).