Linux-Crypto Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/4] crypto: hisilicon/zip - misc bugfix
@ 2020-07-25  6:06 Yang Shen
  2020-07-25  6:06 ` [PATCH 1/4] crypto: hisilicon/zip - fix the uncleared debug registers Yang Shen
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Yang Shen @ 2020-07-25  6:06 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1

This patchset fix some bug:
patch 1:clear the debug registers when remove driver
patch 2:intercept invalid input when using decompress
patch 3:replace the return value '-EBUSY' with '-EAGAIN' when
    device is busy
patch 4:initialize the 'curr_qm_qp_num' when probe device

This patchset depends on:
https://patchwork.kernel.org/cover/11684785/

Hao Fang (1):
  crypto: hisilicon/zip - fix the uncleared debug registers

Sihang Chen (1):
  crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num'

Yang Shen (1):
  crypto: hisilicon/zip - fix the return value when device is busy

Zhou Wang (1):
  crypto: hisilicon/zip - fix zero length input in GZIP decompress

 drivers/crypto/hisilicon/zip/zip_crypto.c | 25 +++++++++++++++++++------
 drivers/crypto/hisilicon/zip/zip_main.c   | 19 +++++++++++++++++++
 2 files changed, 38 insertions(+), 6 deletions(-)

--
2.7.4


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

* [PATCH 1/4] crypto: hisilicon/zip - fix the uncleared debug registers
  2020-07-25  6:06 [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Yang Shen
@ 2020-07-25  6:06 ` Yang Shen
  2020-07-25  6:06 ` [PATCH 2/4] crypto: hisilicon/zip - fix zero length input in GZIP decompress Yang Shen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Yang Shen @ 2020-07-25  6:06 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1

From: Hao Fang <fanghao11@huawei.com>

ZIP debug registers aren't cleared even if its driver is removed,
so add a clearing operation when remove driver.

Signed-off-by: Hao Fang <fanghao11@huawei.com>
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
 drivers/crypto/hisilicon/zip/zip_main.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 8bbae28..cc4a829 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -91,6 +91,11 @@
 #define HZIP_SQE_MASK_OFFSET		64
 #define HZIP_SQE_MASK_LEN		48

+#define HZIP_CNT_CLR_CE_EN		BIT(0)
+#define HZIP_RO_CNT_CLR_CE_EN		BIT(2)
+#define HZIP_RD_CNT_CLR_CE_EN		(HZIP_CNT_CLR_CE_EN | \
+					 HZIP_RO_CNT_CLR_CE_EN)
+
 static const char hisi_zip_name[] = "hisi_zip";
 static struct dentry *hzip_debugfs_root;

@@ -606,10 +611,23 @@ static int hisi_zip_debugfs_init(struct hisi_qm *qm)
 	return ret;
 }

+/* hisi_zip_debug_regs_clear() - clear the zip debug regs */
 static void hisi_zip_debug_regs_clear(struct hisi_qm *qm)
 {
+	int i, j;
+
+	/* clear current_qm */
 	writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF);
 	writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF);
+
+	/* enable register read_clear bit */
+	writel(HZIP_RD_CNT_CLR_CE_EN, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);
+	for (i = 0; i < ARRAY_SIZE(core_offsets); i++)
+		for (j = 0; j < ARRAY_SIZE(hzip_dfx_regs); j++)
+			readl(qm->io_base + core_offsets[i] +
+			      hzip_dfx_regs[j].offset);
+
+	/* disable register read_clear bit */
 	writel(0x0, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);

 	hisi_qm_debug_regs_clear(qm);
--
2.7.4


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

* [PATCH 2/4] crypto: hisilicon/zip - fix zero length input in GZIP decompress
  2020-07-25  6:06 [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Yang Shen
  2020-07-25  6:06 ` [PATCH 1/4] crypto: hisilicon/zip - fix the uncleared debug registers Yang Shen
@ 2020-07-25  6:06 ` Yang Shen
  2020-07-25  6:06 ` [PATCH 3/4] crypto: hisilicon/zip - fix the return value when device is busy Yang Shen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Yang Shen @ 2020-07-25  6:06 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1

From: Zhou Wang <wangzhou1@hisilicon.com>

The zero length input will cause a call trace when use GZIP decompress
like this:
	Unable to handle kernel paging request at virtual address
	...
	lr : get_gzip_head_size+0x7c/0xd0 [hisi_zip]

Judge the input length and return '-EINVAL' when input is invalid.

Fixes: 62c455ca853e("crypto: hisilicon - add HiSilicon ZIP...")
Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com>
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
 drivers/crypto/hisilicon/zip/zip_crypto.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index 10b7adb..a1703eb 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -454,7 +454,7 @@ static int add_comp_head(struct scatterlist *dst, u8 req_type)
 	return head_size;
 }

-static size_t get_gzip_head_size(struct scatterlist *sgl)
+static size_t __maybe_unused get_gzip_head_size(struct scatterlist *sgl)
 {
 	char buf[HZIP_GZIP_HEAD_BUF];

@@ -463,13 +463,20 @@ static size_t get_gzip_head_size(struct scatterlist *sgl)
 	return __get_gzip_head_size(buf);
 }

-static size_t get_comp_head_size(struct scatterlist *src, u8 req_type)
+static int get_comp_head_size(struct acomp_req *acomp_req, u8 req_type)
 {
+	if (!acomp_req->src || !acomp_req->slen)
+		return -EINVAL;
+
+	if ((req_type == HZIP_ALG_TYPE_GZIP) &&
+	    (acomp_req->slen < GZIP_HEAD_FEXTRA_SHIFT))
+		return -EINVAL;
+
 	switch (req_type) {
 	case HZIP_ALG_TYPE_ZLIB:
 		return TO_HEAD_SIZE(HZIP_ALG_TYPE_ZLIB);
 	case HZIP_ALG_TYPE_GZIP:
-		return get_gzip_head_size(src);
+		return TO_HEAD_SIZE(HZIP_ALG_TYPE_GZIP);
 	default:
 		pr_err("Request type does not support!\n");
 		return -EINVAL;
@@ -609,10 +616,15 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req)
 	struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP];
 	struct device *dev = &qp_ctx->qp->qm->pdev->dev;
 	struct hisi_zip_req *req;
-	size_t head_size;
+	int head_size;
 	int ret;

-	head_size = get_comp_head_size(acomp_req->src, qp_ctx->qp->req_type);
+	head_size = get_comp_head_size(acomp_req, qp_ctx->qp->req_type);
+	if (head_size < 0) {
+		dev_err_ratelimited(dev, "Get comp head size failed (%d)!\n",
+				    head_size);
+		return head_size;
+	}

 	req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, false);
 	if (IS_ERR(req)) {
--
2.7.4


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

* [PATCH 3/4] crypto: hisilicon/zip - fix the return value when device is busy
  2020-07-25  6:06 [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Yang Shen
  2020-07-25  6:06 ` [PATCH 1/4] crypto: hisilicon/zip - fix the uncleared debug registers Yang Shen
  2020-07-25  6:06 ` [PATCH 2/4] crypto: hisilicon/zip - fix zero length input in GZIP decompress Yang Shen
@ 2020-07-25  6:06 ` Yang Shen
  2020-07-25  6:06 ` [PATCH 4/4] crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num' Yang Shen
  2020-07-31  8:28 ` [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Herbert Xu
  4 siblings, 0 replies; 7+ messages in thread
From: Yang Shen @ 2020-07-25  6:06 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1

As before, when the ZIP device is too busy to creat a request, it will
return '-EBUSY'. But the crypto process think the '-EBUSY' means a
successful request and wait for its completion.

So replace '-EBUSY' with '-EAGAIN' to show crypto this request is failed.

Fixes: 62c455ca853e("crypto: hisilicon - add HiSilicon ZIP...")
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
 drivers/crypto/hisilicon/zip/zip_crypto.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index a1703eb..f88edf4 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -498,7 +498,7 @@ static struct hisi_zip_req *hisi_zip_create_req(struct acomp_req *req,
 	if (req_id >= req_q->size) {
 		write_unlock(&req_q->req_lock);
 		dev_dbg(&qp_ctx->qp->qm->pdev->dev, "Req cache is full!\n");
-		return ERR_PTR(-EBUSY);
+		return ERR_PTR(-EAGAIN);
 	}
 	set_bit(req_id, req_q->req_bitmap);

@@ -563,6 +563,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
 	ret = hisi_qp_send(qp, &zip_sqe);
 	if (ret < 0) {
 		atomic64_inc(&dfx->send_busy_cnt);
+		ret = -EAGAIN;
 		dev_dbg_ratelimited(dev, "Send task message failed!\n");
 		goto err_unmap_output;
 	}
--
2.7.4


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

* [PATCH 4/4] crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num'
  2020-07-25  6:06 [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Yang Shen
                   ` (2 preceding siblings ...)
  2020-07-25  6:06 ` [PATCH 3/4] crypto: hisilicon/zip - fix the return value when device is busy Yang Shen
@ 2020-07-25  6:06 ` Yang Shen
  2020-07-31  8:28 ` [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Herbert Xu
  4 siblings, 0 replies; 7+ messages in thread
From: Yang Shen @ 2020-07-25  6:06 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1

From: Sihang Chen <chensihang1@hisilicon.com>

The 'qm->curr_qm_qp_num' is not initialized, which will result in failure
to write the current_q file.

Signed-off-by: Sihang Chen <chensihang1@hisilicon.com>
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
 drivers/crypto/hisilicon/zip/zip_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index cc4a829..47efc2f 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -762,6 +762,7 @@ static int hisi_zip_qm_init(struct hisi_qm *qm, struct pci_dev *pdev)
 	if (qm->fun_type == QM_HW_PF) {
 		qm->qp_base = HZIP_PF_DEF_Q_BASE;
 		qm->qp_num = pf_q_num;
+		qm->debug.curr_qm_qp_num = pf_q_num;
 		qm->qm_list = &zip_devices;
 	} else if (qm->fun_type == QM_HW_VF && qm->ver == QM_HW_V1) {
 		/*
--
2.7.4


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

* Re: [PATCH 0/4] crypto: hisilicon/zip - misc bugfix
  2020-07-25  6:06 [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Yang Shen
                   ` (3 preceding siblings ...)
  2020-07-25  6:06 ` [PATCH 4/4] crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num' Yang Shen
@ 2020-07-31  8:28 ` Herbert Xu
  2020-07-31  8:47   ` shenyang (M)
  4 siblings, 1 reply; 7+ messages in thread
From: Herbert Xu @ 2020-07-31  8:28 UTC (permalink / raw)
  To: Yang Shen; +Cc: davem, linux-kernel, linux-crypto, xuzaibo, wangzhou1

On Sat, Jul 25, 2020 at 02:06:46PM +0800, Yang Shen wrote:
> This patchset fix some bug:
> patch 1:clear the debug registers when remove driver
> patch 2:intercept invalid input when using decompress
> patch 3:replace the return value '-EBUSY' with '-EAGAIN' when
>     device is busy
> patch 4:initialize the 'curr_qm_qp_num' when probe device
> 
> This patchset depends on:
> https://patchwork.kernel.org/cover/11684785/
> 
> Hao Fang (1):
>   crypto: hisilicon/zip - fix the uncleared debug registers
> 
> Sihang Chen (1):
>   crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num'
> 
> Yang Shen (1):
>   crypto: hisilicon/zip - fix the return value when device is busy
> 
> Zhou Wang (1):
>   crypto: hisilicon/zip - fix zero length input in GZIP decompress
> 
>  drivers/crypto/hisilicon/zip/zip_crypto.c | 25 +++++++++++++++++++------
>  drivers/crypto/hisilicon/zip/zip_main.c   | 19 +++++++++++++++++++
>  2 files changed, 38 insertions(+), 6 deletions(-)

This patch series doesn't apply against cryptodev.

Cheers,
-- 
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] 7+ messages in thread

* Re: [PATCH 0/4] crypto: hisilicon/zip - misc bugfix
  2020-07-31  8:28 ` [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Herbert Xu
@ 2020-07-31  8:47   ` shenyang (M)
  0 siblings, 0 replies; 7+ messages in thread
From: shenyang (M) @ 2020-07-31  8:47 UTC (permalink / raw)
  To: Herbert Xu; +Cc: davem, linux-kernel, linux-crypto, xuzaibo, wangzhou1



On 2020/7/31 16:28, Herbert Xu wrote:
> On Sat, Jul 25, 2020 at 02:06:46PM +0800, Yang Shen wrote:
>> This patchset fix some bug:
>> patch 1:clear the debug registers when remove driver
>> patch 2:intercept invalid input when using decompress
>> patch 3:replace the return value '-EBUSY' with '-EAGAIN' when
>>     device is busy
>> patch 4:initialize the 'curr_qm_qp_num' when probe device
>>
>> This patchset depends on:
>> https://patchwork.kernel.org/cover/11684785/
>>
>> Hao Fang (1):
>>   crypto: hisilicon/zip - fix the uncleared debug registers
>>
>> Sihang Chen (1):
>>   crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num'
>>
>> Yang Shen (1):
>>   crypto: hisilicon/zip - fix the return value when device is busy
>>
>> Zhou Wang (1):
>>   crypto: hisilicon/zip - fix zero length input in GZIP decompress
>>
>>  drivers/crypto/hisilicon/zip/zip_crypto.c | 25 +++++++++++++++++++------
>>  drivers/crypto/hisilicon/zip/zip_main.c   | 19 +++++++++++++++++++
>>  2 files changed, 38 insertions(+), 6 deletions(-)
>
> This patch series doesn't apply against cryptodev.
>
> Cheers,
>

Sorry, this patchset depends on
https://patchwork.kernel.org/cover/11684785/
which cover letter is '[PATCH 00/10] crypto: hisilicon/zip - misc clean
up'

Sorry for troubling you again.

Thanks,


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

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-25  6:06 [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Yang Shen
2020-07-25  6:06 ` [PATCH 1/4] crypto: hisilicon/zip - fix the uncleared debug registers Yang Shen
2020-07-25  6:06 ` [PATCH 2/4] crypto: hisilicon/zip - fix zero length input in GZIP decompress Yang Shen
2020-07-25  6:06 ` [PATCH 3/4] crypto: hisilicon/zip - fix the return value when device is busy Yang Shen
2020-07-25  6:06 ` [PATCH 4/4] crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num' Yang Shen
2020-07-31  8:28 ` [PATCH 0/4] crypto: hisilicon/zip - misc bugfix Herbert Xu
2020-07-31  8:47   ` shenyang (M)

Linux-Crypto Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-crypto/0 linux-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-crypto linux-crypto/ https://lore.kernel.org/linux-crypto \
		linux-crypto@vger.kernel.org
	public-inbox-index linux-crypto

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git