linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] bug fix and clear coding style
@ 2021-03-30  7:39 Kai Ye
  2021-03-30  7:39 ` [PATCH v2 1/5] crypto: hisilicon/sgl - fixup " Kai Ye
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Kai Ye @ 2021-03-30  7:39 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, wangzhou1, yekai13

fixup coding style such as magic number and unneeded variable
initialization. Clear data operation in sg buf unmap, and other
misc fix.

Kai Ye (5):
  crypto: hisilicon/sgl - fixup coding style
  crypto: hisilicon/sgl - delete unneeded variable initialization
  crypto: hisilicon/sgl - add some dfx logs
  crypto: hisilicon/sgl - fix the soft sg map to hardware sg
  crypto: hisilicon/sgl - fix the sg buf unmap

 drivers/crypto/hisilicon/sgl.c | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

-- 
2.8.1


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

* [PATCH v2 1/5] crypto: hisilicon/sgl - fixup coding style
  2021-03-30  7:39 [PATCH v2 0/5] bug fix and clear coding style Kai Ye
@ 2021-03-30  7:39 ` Kai Ye
  2021-03-30  7:53   ` Joe Perches
  2021-03-30  7:39 ` [PATCH v2 2/5] crypto: hisilicon/sgl - delete unneeded variable initialization Kai Ye
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Kai Ye @ 2021-03-30  7:39 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, wangzhou1, yekai13

use a macro replace of a magic number.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/crypto/hisilicon/sgl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
index 3bff639..bd5ef40 100644
--- a/drivers/crypto/hisilicon/sgl.c
+++ b/drivers/crypto/hisilicon/sgl.c
@@ -9,6 +9,7 @@
 #define HISI_ACC_SGL_NR_MAX		256
 #define HISI_ACC_SGL_ALIGN_SIZE		64
 #define HISI_ACC_MEM_BLOCK_NR		5
+#define HISI_ACC_BLOCK_SIZE_MAX_SHIFT	31
 
 struct acc_hw_sge {
 	dma_addr_t buf;
@@ -67,7 +68,8 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
 	sgl_size = sizeof(struct acc_hw_sge) * sge_nr +
 		   sizeof(struct hisi_acc_hw_sgl);
 	block_size = 1 << (PAGE_SHIFT + MAX_ORDER <= 32 ?
-			   PAGE_SHIFT + MAX_ORDER - 1 : 31);
+			   PAGE_SHIFT + MAX_ORDER - 1 :
+			   HISI_ACC_BLOCK_SIZE_MAX_SHIFT);
 	sgl_num_per_block = block_size / sgl_size;
 	block_num = count / sgl_num_per_block;
 	remain_sgl = count % sgl_num_per_block;
-- 
2.8.1


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

* [PATCH v2 2/5] crypto: hisilicon/sgl - delete unneeded variable initialization
  2021-03-30  7:39 [PATCH v2 0/5] bug fix and clear coding style Kai Ye
  2021-03-30  7:39 ` [PATCH v2 1/5] crypto: hisilicon/sgl - fixup " Kai Ye
@ 2021-03-30  7:39 ` Kai Ye
  2021-03-30  7:39 ` [PATCH v2 3/5] crypto: hisilicon/sgl - add some dfx logs Kai Ye
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Kai Ye @ 2021-03-30  7:39 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, wangzhou1, yekai13

delete unneeded variable initialization

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/crypto/hisilicon/sgl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
index bd5ef40..b816e74 100644
--- a/drivers/crypto/hisilicon/sgl.c
+++ b/drivers/crypto/hisilicon/sgl.c
@@ -57,7 +57,7 @@ struct hisi_acc_sgl_pool {
 struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
 						   u32 count, u32 sge_nr)
 {
-	u32 sgl_size, block_size, sgl_num_per_block, block_num, remain_sgl = 0;
+	u32 sgl_size, block_size, sgl_num_per_block, block_num, remain_sgl;
 	struct hisi_acc_sgl_pool *pool;
 	struct mem_block *block;
 	u32 i, j;
-- 
2.8.1


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

* [PATCH v2 3/5] crypto: hisilicon/sgl - add some dfx logs
  2021-03-30  7:39 [PATCH v2 0/5] bug fix and clear coding style Kai Ye
  2021-03-30  7:39 ` [PATCH v2 1/5] crypto: hisilicon/sgl - fixup " Kai Ye
  2021-03-30  7:39 ` [PATCH v2 2/5] crypto: hisilicon/sgl - delete unneeded variable initialization Kai Ye
@ 2021-03-30  7:39 ` Kai Ye
  2021-03-30  7:56   ` Joe Perches
  2021-03-30  7:39 ` [PATCH v2 4/5] crypto: hisilicon/sgl - fix the soft sg map to hardware sg Kai Ye
  2021-03-30  7:39 ` [PATCH v2 5/5] crypto: hisilicon/sgl - fix the sg buf unmap Kai Ye
  4 siblings, 1 reply; 10+ messages in thread
From: Kai Ye @ 2021-03-30  7:39 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, wangzhou1, yekai13

Add some dfx logs in some abnormal exit situations.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/crypto/hisilicon/sgl.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
index b816e74..4bece3d 100644
--- a/drivers/crypto/hisilicon/sgl.c
+++ b/drivers/crypto/hisilicon/sgl.c
@@ -87,8 +87,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
 		block[i].sgl = dma_alloc_coherent(dev, block_size,
 						  &block[i].sgl_dma,
 						  GFP_KERNEL);
-		if (!block[i].sgl)
+		if (!block[i].sgl) {
+			dev_err(dev, "Fail to allocate hw SG buffer!\n");
 			goto err_free_mem;
+		}
 
 		block[i].size = block_size;
 	}
@@ -97,8 +99,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
 		block[i].sgl = dma_alloc_coherent(dev, remain_sgl * sgl_size,
 						  &block[i].sgl_dma,
 						  GFP_KERNEL);
-		if (!block[i].sgl)
+		if (!block[i].sgl) {
+			dev_err(dev, "Fail to allocate remained hw SG buffer!\n");
 			goto err_free_mem;
+		}
 
 		block[i].size = remain_sgl * sgl_size;
 	}
@@ -213,16 +217,19 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
 	sg_n = sg_nents(sgl);
 
 	sg_n_mapped = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);
-	if (!sg_n_mapped)
+	if (!sg_n_mapped) {
+		dev_err(dev, "DMA mapping for SG error!\n");
 		return ERR_PTR(-EINVAL);
+	}
 
 	if (sg_n_mapped > pool->sge_nr) {
-		dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);
+		dev_err(dev, "the number of entries in input scatterlist is bigger than SGL pool setting.\n");
 		return ERR_PTR(-EINVAL);
 	}
 
 	curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma);
 	if (IS_ERR(curr_hw_sgl)) {
+		dev_err(dev, "Get SGL error!\n");
 		dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);
 		return ERR_PTR(-ENOMEM);
 
-- 
2.8.1


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

* [PATCH v2 4/5] crypto: hisilicon/sgl - fix the soft sg map to hardware sg
  2021-03-30  7:39 [PATCH v2 0/5] bug fix and clear coding style Kai Ye
                   ` (2 preceding siblings ...)
  2021-03-30  7:39 ` [PATCH v2 3/5] crypto: hisilicon/sgl - add some dfx logs Kai Ye
@ 2021-03-30  7:39 ` Kai Ye
  2021-03-30  7:39 ` [PATCH v2 5/5] crypto: hisilicon/sgl - fix the sg buf unmap Kai Ye
  4 siblings, 0 replies; 10+ messages in thread
From: Kai Ye @ 2021-03-30  7:39 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, wangzhou1, yekai13

The buffer of the hardware sge needs to be initialized by
soft sgl.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/crypto/hisilicon/sgl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
index 4bece3d..c618aaf 100644
--- a/drivers/crypto/hisilicon/sgl.c
+++ b/drivers/crypto/hisilicon/sgl.c
@@ -173,6 +173,7 @@ static void sg_map_to_hw_sg(struct scatterlist *sgl,
 {
 	hw_sge->buf = sg_dma_address(sgl);
 	hw_sge->len = cpu_to_le32(sg_dma_len(sgl));
+	hw_sge->page_ctrl = sg_virt(sgl);
 }
 
 static void inc_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl)
-- 
2.8.1


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

* [PATCH v2 5/5] crypto: hisilicon/sgl - fix the sg buf unmap
  2021-03-30  7:39 [PATCH v2 0/5] bug fix and clear coding style Kai Ye
                   ` (3 preceding siblings ...)
  2021-03-30  7:39 ` [PATCH v2 4/5] crypto: hisilicon/sgl - fix the soft sg map to hardware sg Kai Ye
@ 2021-03-30  7:39 ` Kai Ye
  2021-04-09  7:43   ` Herbert Xu
  4 siblings, 1 reply; 10+ messages in thread
From: Kai Ye @ 2021-03-30  7:39 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-kernel, wangzhou1, yekai13

Add clear data operation for sge data.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/crypto/hisilicon/sgl.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
index c618aaf..7a58ab3 100644
--- a/drivers/crypto/hisilicon/sgl.c
+++ b/drivers/crypto/hisilicon/sgl.c
@@ -189,6 +189,18 @@ static void update_hw_sgl_sum_sge(struct hisi_acc_hw_sgl *hw_sgl, u16 sum)
 	hw_sgl->entry_sum_in_chain = cpu_to_le16(sum);
 }
 
+static void clear_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl)
+{
+	struct acc_hw_sge *hw_sge = hw_sgl->sge_entries;
+	int i;
+
+	for (i = 0; i < hw_sgl->entry_sum_in_sgl; i++) {
+		hw_sge[i].page_ctrl = NULL;
+		hw_sge[i].buf = 0;
+		hw_sge[i].len = 0;
+	}
+}
+
 /**
  * hisi_acc_sg_buf_map_to_hw_sgl - Map a scatterlist to a hw sgl.
  * @dev: The device which hw sgl belongs to.
@@ -266,7 +278,7 @@ void hisi_acc_sg_buf_unmap(struct device *dev, struct scatterlist *sgl,
 		return;
 
 	dma_unmap_sg(dev, sgl, sg_nents(sgl), DMA_BIDIRECTIONAL);
-
+	clear_hw_sgl_sge(hw_sgl);
 	hw_sgl->entry_sum_in_chain = 0;
 	hw_sgl->entry_sum_in_sgl = 0;
 	hw_sgl->entry_length_in_sgl = 0;
-- 
2.8.1


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

* Re: [PATCH v2 1/5] crypto: hisilicon/sgl - fixup coding style
  2021-03-30  7:39 ` [PATCH v2 1/5] crypto: hisilicon/sgl - fixup " Kai Ye
@ 2021-03-30  7:53   ` Joe Perches
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2021-03-30  7:53 UTC (permalink / raw)
  To: Kai Ye, herbert; +Cc: linux-crypto, linux-kernel, wangzhou1

On Tue, 2021-03-30 at 15:39 +0800, Kai Ye wrote:
> use a macro replace of a magic number.

Given the use of 32 in the same test, this
seems more obfuscating that useful to me.

> diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
[]
> @@ -9,6 +9,7 @@
>  #define HISI_ACC_SGL_NR_MAX		256
>  #define HISI_ACC_SGL_ALIGN_SIZE		64
>  #define HISI_ACC_MEM_BLOCK_NR		5
> +#define HISI_ACC_BLOCK_SIZE_MAX_SHIFT	31
>  
> 
>  struct acc_hw_sge {
>  	dma_addr_t buf;
> @@ -67,7 +68,8 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
>  	sgl_size = sizeof(struct acc_hw_sge) * sge_nr +
>  		   sizeof(struct hisi_acc_hw_sgl);
>  	block_size = 1 << (PAGE_SHIFT + MAX_ORDER <= 32 ?
> -			   PAGE_SHIFT + MAX_ORDER - 1 : 31);
> +			   PAGE_SHIFT + MAX_ORDER - 1 :
> +			   HISI_ACC_BLOCK_SIZE_MAX_SHIFT);
>  	sgl_num_per_block = block_size / sgl_size;
>  	block_num = count / sgl_num_per_block;
>  	remain_sgl = count % sgl_num_per_block;



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

* Re: [PATCH v2 3/5] crypto: hisilicon/sgl - add some dfx logs
  2021-03-30  7:39 ` [PATCH v2 3/5] crypto: hisilicon/sgl - add some dfx logs Kai Ye
@ 2021-03-30  7:56   ` Joe Perches
  2021-03-30  9:24     ` yekai(A)
  0 siblings, 1 reply; 10+ messages in thread
From: Joe Perches @ 2021-03-30  7:56 UTC (permalink / raw)
  To: Kai Ye, herbert; +Cc: linux-crypto, linux-kernel, wangzhou1

On Tue, 2021-03-30 at 15:39 +0800, Kai Ye wrote:
> Add some dfx logs in some abnormal exit situations.
[]
> diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
[]
> @@ -87,8 +87,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
>  		block[i].sgl = dma_alloc_coherent(dev, block_size,
>  						  &block[i].sgl_dma,
>  						  GFP_KERNEL);
> -		if (!block[i].sgl)
> +		if (!block[i].sgl) {
> +			dev_err(dev, "Fail to allocate hw SG buffer!\n");

This doesn't seem useful as dma_alloc_coherent does a dump_stack
by default on OOM.



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

* Re: [PATCH v2 3/5] crypto: hisilicon/sgl - add some dfx logs
  2021-03-30  7:56   ` Joe Perches
@ 2021-03-30  9:24     ` yekai(A)
  0 siblings, 0 replies; 10+ messages in thread
From: yekai(A) @ 2021-03-30  9:24 UTC (permalink / raw)
  To: Joe Perches, herbert; +Cc: linux-crypto, linux-kernel, wangzhou1

However, I think this log can be used to quickly locate the function or 
module if dma alloc failed.


On 2021/3/30 15:56, Joe Perches wrote:
> On Tue, 2021-03-30 at 15:39 +0800, Kai Ye wrote:
>> Add some dfx logs in some abnormal exit situations.
> []
>> diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
> []
>> @@ -87,8 +87,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
>>   		block[i].sgl = dma_alloc_coherent(dev, block_size,
>>   						  &block[i].sgl_dma,
>>   						  GFP_KERNEL);
>> -		if (!block[i].sgl)
>> +		if (!block[i].sgl) {
>> +			dev_err(dev, "Fail to allocate hw SG buffer!\n");
> This doesn't seem useful as dma_alloc_coherent does a dump_stack
> by default on OOM.
>
>
> .
>


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

* Re: [PATCH v2 5/5] crypto: hisilicon/sgl - fix the sg buf unmap
  2021-03-30  7:39 ` [PATCH v2 5/5] crypto: hisilicon/sgl - fix the sg buf unmap Kai Ye
@ 2021-04-09  7:43   ` Herbert Xu
  0 siblings, 0 replies; 10+ messages in thread
From: Herbert Xu @ 2021-04-09  7:43 UTC (permalink / raw)
  To: Kai Ye; +Cc: linux-crypto, linux-kernel, wangzhou1

On Tue, Mar 30, 2021 at 03:39:06PM +0800, Kai Ye wrote:
> Add clear data operation for sge data.
> 
> Signed-off-by: Kai Ye <yekai13@huawei.com>
> ---
>  drivers/crypto/hisilicon/sgl.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c
> index c618aaf..7a58ab3 100644
> --- a/drivers/crypto/hisilicon/sgl.c
> +++ b/drivers/crypto/hisilicon/sgl.c
> @@ -189,6 +189,18 @@ static void update_hw_sgl_sum_sge(struct hisi_acc_hw_sgl *hw_sgl, u16 sum)
>  	hw_sgl->entry_sum_in_chain = cpu_to_le16(sum);
>  }
>  
> +static void clear_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl)
> +{
> +	struct acc_hw_sge *hw_sge = hw_sgl->sge_entries;
> +	int i;
> +
> +	for (i = 0; i < hw_sgl->entry_sum_in_sgl; i++) {
> +		hw_sge[i].page_ctrl = NULL;
> +		hw_sge[i].buf = 0;
> +		hw_sge[i].len = 0;
> +	}
> +}

This causes a new sparse warning:

  CHECK   ../drivers/crypto/hisilicon/sgl.c
  ../drivers/crypto/hisilicon/sgl.c:200:31: warning: restricted __le16 degrades to integer

Please fix.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2021-04-09  7:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30  7:39 [PATCH v2 0/5] bug fix and clear coding style Kai Ye
2021-03-30  7:39 ` [PATCH v2 1/5] crypto: hisilicon/sgl - fixup " Kai Ye
2021-03-30  7:53   ` Joe Perches
2021-03-30  7:39 ` [PATCH v2 2/5] crypto: hisilicon/sgl - delete unneeded variable initialization Kai Ye
2021-03-30  7:39 ` [PATCH v2 3/5] crypto: hisilicon/sgl - add some dfx logs Kai Ye
2021-03-30  7:56   ` Joe Perches
2021-03-30  9:24     ` yekai(A)
2021-03-30  7:39 ` [PATCH v2 4/5] crypto: hisilicon/sgl - fix the soft sg map to hardware sg Kai Ye
2021-03-30  7:39 ` [PATCH v2 5/5] crypto: hisilicon/sgl - fix the sg buf unmap Kai Ye
2021-04-09  7:43   ` Herbert Xu

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