linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up
@ 2020-09-25 14:06 Yang Shen
  2020-09-25 14:06 ` [PATCH RESEND 1/4] crypto: hisilicon/zip - fix the uncleared debug registers Yang Shen
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Yang Shen @ 2020-09-25 14: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

Resend this patch series because it depends on
https://patchwork.kernel.org/cover/11760159/
(crypto: hisilicon/zip - misc clean up).
Now the patch series has been applied.

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 | 26 +++++++++++++++++++-------
 drivers/crypto/hisilicon/zip/zip_main.c   | 19 +++++++++++++++++++
 2 files changed, 38 insertions(+), 7 deletions(-)

--
2.7.4


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

* [PATCH RESEND 1/4] crypto: hisilicon/zip - fix the uncleared debug registers
  2020-09-25 14:06 [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up Yang Shen
@ 2020-09-25 14:06 ` Yang Shen
  2020-09-25 14:06 ` [PATCH RESEND 2/4] crypto: hisilicon/zip - fix zero length input in GZIP decompress Yang Shen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Yang Shen @ 2020-09-25 14: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 bd53ee7..f10bf99 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;
 
@@ -604,10 +609,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 related	[flat|nested] 6+ messages in thread

* [PATCH RESEND 2/4] crypto: hisilicon/zip - fix zero length input in GZIP decompress
  2020-09-25 14:06 [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up Yang Shen
  2020-09-25 14:06 ` [PATCH RESEND 1/4] crypto: hisilicon/zip - fix the uncleared debug registers Yang Shen
@ 2020-09-25 14:06 ` Yang Shen
  2020-09-25 14:06 ` [PATCH RESEND 3/4] crypto: hisilicon/zip - fix the return value when device is busy Yang Shen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Yang Shen @ 2020-09-25 14: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 | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index 38f92d4..48dc2fd 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;
@@ -606,10 +613,14 @@ 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 ret;
+	int head_size, 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, "failed to get comp head size (%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 related	[flat|nested] 6+ messages in thread

* [PATCH RESEND 3/4] crypto: hisilicon/zip - fix the return value when device is busy
  2020-09-25 14:06 [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up Yang Shen
  2020-09-25 14:06 ` [PATCH RESEND 1/4] crypto: hisilicon/zip - fix the uncleared debug registers Yang Shen
  2020-09-25 14:06 ` [PATCH RESEND 2/4] crypto: hisilicon/zip - fix zero length input in GZIP decompress Yang Shen
@ 2020-09-25 14:06 ` Yang Shen
  2020-09-25 14:06 ` [PATCH RESEND 4/4] crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num' Yang Shen
  2020-10-02 11:55 ` [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up Herbert Xu
  4 siblings, 0 replies; 6+ messages in thread
From: Yang Shen @ 2020-09-25 14: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 48dc2fd..08b4660 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);
 
@@ -564,6 +564,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, "failed to send request!\n");
 		goto err_unmap_output;
 	}
-- 
2.7.4


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

* [PATCH RESEND 4/4] crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num'
  2020-09-25 14:06 [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up Yang Shen
                   ` (2 preceding siblings ...)
  2020-09-25 14:06 ` [PATCH RESEND 3/4] crypto: hisilicon/zip - fix the return value when device is busy Yang Shen
@ 2020-09-25 14:06 ` Yang Shen
  2020-10-02 11:55 ` [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up Herbert Xu
  4 siblings, 0 replies; 6+ messages in thread
From: Yang Shen @ 2020-09-25 14: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 f10bf99..4bd2c81 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -760,6 +760,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 related	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up
  2020-09-25 14:06 [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up Yang Shen
                   ` (3 preceding siblings ...)
  2020-09-25 14:06 ` [PATCH RESEND 4/4] crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num' Yang Shen
@ 2020-10-02 11:55 ` Herbert Xu
  4 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2020-10-02 11:55 UTC (permalink / raw)
  To: Yang Shen; +Cc: davem, linux-kernel, linux-crypto, xuzaibo, wangzhou1

On Fri, Sep 25, 2020 at 10:06:13PM +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
> 
> Resend this patch series because it depends on
> https://patchwork.kernel.org/cover/11760159/
> (crypto: hisilicon/zip - misc clean up).
> Now the patch series has been applied.
> 
> 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 | 26 +++++++++++++++++++-------
>  drivers/crypto/hisilicon/zip/zip_main.c   | 19 +++++++++++++++++++
>  2 files changed, 38 insertions(+), 7 deletions(-)

All applied.  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] 6+ messages in thread

end of thread, other threads:[~2020-10-02 11:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 14:06 [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up Yang Shen
2020-09-25 14:06 ` [PATCH RESEND 1/4] crypto: hisilicon/zip - fix the uncleared debug registers Yang Shen
2020-09-25 14:06 ` [PATCH RESEND 2/4] crypto: hisilicon/zip - fix zero length input in GZIP decompress Yang Shen
2020-09-25 14:06 ` [PATCH RESEND 3/4] crypto: hisilicon/zip - fix the return value when device is busy Yang Shen
2020-09-25 14:06 ` [PATCH RESEND 4/4] crypto: hisilicon/zip - fix the uninitalized 'curr_qm_qp_num' Yang Shen
2020-10-02 11:55 ` [PATCH RESEND 0/4] crypto: hisilicon/zip - misc clean up 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).