* [PATCH RESEND 01/10] crypto: hisilicon/zip - remove some useless parameters
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 02/10] crypto: hisilicon/zip - unify naming style for functions and macros Yang Shen
` (9 subsequent siblings)
10 siblings, 0 replies; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
1.Remove the macro 'HZIP_VF_NUM'.
2.Remove 'list' of the struct 'hisi_zip'
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip.h | 1 -
drivers/crypto/hisilicon/zip/zip_main.c | 1 -
2 files changed, 2 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip.h b/drivers/crypto/hisilicon/zip/zip.h
index 4484be1..4b3aae8 100644
--- a/drivers/crypto/hisilicon/zip/zip.h
+++ b/drivers/crypto/hisilicon/zip/zip.h
@@ -39,7 +39,6 @@ struct hisi_zip_ctrl;
struct hisi_zip {
struct hisi_qm qm;
- struct list_head list;
struct hisi_zip_ctrl *ctrl;
struct hisi_zip_dfx dfx;
};
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 7e86b0f..445db04 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -17,7 +17,6 @@
#define PCI_DEVICE_ID_ZIP_PF 0xa250
#define PCI_DEVICE_ID_ZIP_VF 0xa251
-#define HZIP_VF_NUM 63
#define HZIP_QUEUE_NUM_V1 4096
#define HZIP_QUEUE_NUM_V2 1024
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH RESEND 02/10] crypto: hisilicon/zip - unify naming style for functions and macros
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 01/10] crypto: hisilicon/zip - remove some useless parameters Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 03/10] crypto: hisilicon/zip - modify debugfs interface parameters Yang Shen
` (8 subsequent siblings)
10 siblings, 0 replies; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
1.Add prefix 'HZIP' for some macros
2.Add prefix 'hisi_zip' for some functions
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip_main.c | 35 +++++++++++++++++----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 445db04..058f744 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -29,18 +29,18 @@
#define DECOMP3_ENABLE BIT(5)
#define DECOMP4_ENABLE BIT(6)
#define DECOMP5_ENABLE BIT(7)
-#define ALL_COMP_DECOMP_EN (COMP0_ENABLE | COMP1_ENABLE | \
+#define HZIP_ALL_COMP_DECOMP_EN (COMP0_ENABLE | COMP1_ENABLE | \
DECOMP0_ENABLE | DECOMP1_ENABLE | \
DECOMP2_ENABLE | DECOMP3_ENABLE | \
DECOMP4_ENABLE | DECOMP5_ENABLE)
-#define DECOMP_CHECK_ENABLE BIT(16)
+#define HZIP_DECOMP_CHECK_ENABLE BIT(16)
#define HZIP_FSM_MAX_CNT 0x301008
#define HZIP_PORT_ARCA_CHE_0 0x301040
#define HZIP_PORT_ARCA_CHE_1 0x301044
#define HZIP_PORT_AWCA_CHE_0 0x301060
#define HZIP_PORT_AWCA_CHE_1 0x301064
-#define CACHE_ALL_EN 0xffffffff
+#define HZIP_CACHE_ALL_EN 0xffffffff
#define HZIP_BD_RUSER_32_63 0x301110
#define HZIP_SGL_RUSER_32_63 0x30111c
@@ -82,7 +82,7 @@
#define HZIP_PF_DEF_Q_BASE 0
#define HZIP_SOFT_CTRL_CNT_CLR_CE 0x301000
-#define SOFT_CTRL_CNT_CLR_CE_BIT BIT(0)
+#define HZIP_SOFT_CTRL_CNT_CLR_CE_BIT BIT(0)
#define HZIP_SOFT_CTRL_ZIP_CONTROL 0x30100C
#define HZIP_AXI_SHUTDOWN_ENABLE BIT(14)
#define HZIP_WR_PORT BIT(11)
@@ -264,10 +264,10 @@ static int hisi_zip_set_user_domain_and_cache(struct hisi_qm *qm)
writel(PEH_AXUSER_CFG_ENABLE, base + QM_PEH_AXUSER_CFG_ENABLE);
/* cache */
- writel(CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_0);
- writel(CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_1);
- writel(CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_0);
- writel(CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_1);
+ writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_0);
+ writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_1);
+ writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_0);
+ writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_1);
/* user domain configurations */
writel(AXUSER_BASE, base + HZIP_BD_RUSER_32_63);
@@ -283,7 +283,7 @@ static int hisi_zip_set_user_domain_and_cache(struct hisi_qm *qm)
}
/* let's open all compression/decompression cores */
- writel(DECOMP_CHECK_ENABLE | ALL_COMP_DECOMP_EN,
+ writel(HZIP_DECOMP_CHECK_ENABLE | HZIP_ALL_COMP_DECOMP_EN,
base + HZIP_CLOCK_GATE_CTRL);
/* enable sqc writeback */
@@ -390,7 +390,7 @@ static u32 clear_enable_read(struct ctrl_debug_file *file)
struct hisi_qm *qm = file_to_qm(file);
return readl(qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE) &
- SOFT_CTRL_CNT_CLR_CE_BIT;
+ HZIP_SOFT_CTRL_CNT_CLR_CE_BIT;
}
static int clear_enable_write(struct ctrl_debug_file *file, u32 val)
@@ -402,14 +402,14 @@ static int clear_enable_write(struct ctrl_debug_file *file, u32 val)
return -EINVAL;
tmp = (readl(qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE) &
- ~SOFT_CTRL_CNT_CLR_CE_BIT) | val;
+ ~HZIP_SOFT_CTRL_CNT_CLR_CE_BIT) | val;
writel(tmp, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);
return 0;
}
-static ssize_t ctrl_debug_read(struct file *filp, char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
+ size_t count, loff_t *pos)
{
struct ctrl_debug_file *file = filp->private_data;
char tbuf[HZIP_BUF_SIZE];
@@ -433,8 +433,9 @@ static ssize_t ctrl_debug_read(struct file *filp, char __user *buf,
return simple_read_from_buffer(buf, count, pos, tbuf, ret);
}
-static ssize_t ctrl_debug_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_write(struct file *filp,
+ const char __user *buf,
+ size_t count, loff_t *pos)
{
struct ctrl_debug_file *file = filp->private_data;
char tbuf[HZIP_BUF_SIZE];
@@ -483,8 +484,8 @@ static ssize_t ctrl_debug_write(struct file *filp, const char __user *buf,
static const struct file_operations ctrl_debug_fops = {
.owner = THIS_MODULE,
.open = simple_open,
- .read = ctrl_debug_read,
- .write = ctrl_debug_write,
+ .read = hisi_zip_ctrl_debug_read,
+ .write = hisi_zip_ctrl_debug_write,
};
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH RESEND 03/10] crypto: hisilicon/zip - modify debugfs interface parameters
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 01/10] crypto: hisilicon/zip - remove some useless parameters Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 02/10] crypto: hisilicon/zip - unify naming style for functions and macros Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf' Yang Shen
` (7 subsequent siblings)
10 siblings, 0 replies; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
From: Shukun Tan <tanshukun1@huawei.com>
Update debugfs interface parameters
Signed-off-by: Shukun Tan <tanshukun1@huawei.com>
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip_main.c | 55 ++++++++++++++-------------------
1 file changed, 24 insertions(+), 31 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 058f744..df1a16f 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -156,7 +156,6 @@ struct ctrl_debug_file {
*/
struct hisi_zip_ctrl {
struct hisi_zip *hisi_zip;
- struct dentry *debug_root;
struct ctrl_debug_file files[HZIP_DEBUG_FILE_NUM];
};
@@ -509,10 +508,8 @@ static int zip_debugfs_atomic64_get(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(zip_atomic64_ops, zip_debugfs_atomic64_get,
zip_debugfs_atomic64_set, "%llu\n");
-static int hisi_zip_core_debug_init(struct hisi_zip_ctrl *ctrl)
+static int hisi_zip_core_debug_init(struct hisi_qm *qm)
{
- struct hisi_zip *hisi_zip = ctrl->hisi_zip;
- struct hisi_qm *qm = &hisi_zip->qm;
struct device *dev = &qm->pdev->dev;
struct debugfs_regset32 *regset;
struct dentry *tmp_d;
@@ -533,7 +530,7 @@ static int hisi_zip_core_debug_init(struct hisi_zip_ctrl *ctrl)
regset->nregs = ARRAY_SIZE(hzip_dfx_regs);
regset->base = qm->io_base + core_offsets[i];
- tmp_d = debugfs_create_dir(buf, ctrl->debug_root);
+ tmp_d = debugfs_create_dir(buf, qm->debug.debug_root);
debugfs_create_regset32("regs", 0444, tmp_d, regset);
}
@@ -552,33 +549,32 @@ static void hisi_zip_dfx_debug_init(struct hisi_qm *qm)
for (i = 0; i < ARRAY_SIZE(zip_dfx_files); i++) {
data = (atomic64_t *)((uintptr_t)dfx + zip_dfx_files[i].offset);
debugfs_create_file(zip_dfx_files[i].name,
- 0644,
- tmp_dir,
- data,
- &zip_atomic64_ops);
+ 0644, tmp_dir, data,
+ &zip_atomic64_ops);
}
}
-static int hisi_zip_ctrl_debug_init(struct hisi_zip_ctrl *ctrl)
+static int hisi_zip_ctrl_debug_init(struct hisi_qm *qm)
{
+ struct hisi_zip *zip = container_of(qm, struct hisi_zip, qm);
int i;
for (i = HZIP_CURRENT_QM; i < HZIP_DEBUG_FILE_NUM; i++) {
- spin_lock_init(&ctrl->files[i].lock);
- ctrl->files[i].ctrl = ctrl;
- ctrl->files[i].index = i;
+ spin_lock_init(&zip->ctrl->files[i].lock);
+ zip->ctrl->files[i].ctrl = zip->ctrl;
+ zip->ctrl->files[i].index = i;
debugfs_create_file(ctrl_debug_file_name[i], 0600,
- ctrl->debug_root, ctrl->files + i,
+ qm->debug.debug_root,
+ zip->ctrl->files + i,
&ctrl_debug_fops);
}
- return hisi_zip_core_debug_init(ctrl);
+ return hisi_zip_core_debug_init(qm);
}
-static int hisi_zip_debugfs_init(struct hisi_zip *hisi_zip)
+static int hisi_zip_debugfs_init(struct hisi_qm *qm)
{
- struct hisi_qm *qm = &hisi_zip->qm;
struct device *dev = &qm->pdev->dev;
struct dentry *dev_d;
int ret;
@@ -593,8 +589,7 @@ static int hisi_zip_debugfs_init(struct hisi_zip *hisi_zip)
goto failed_to_create;
if (qm->fun_type == QM_HW_PF) {
- hisi_zip->ctrl->debug_root = dev_d;
- ret = hisi_zip_ctrl_debug_init(hisi_zip->ctrl);
+ ret = hisi_zip_ctrl_debug_init(qm);
if (ret)
goto failed_to_create;
}
@@ -608,10 +603,8 @@ static int hisi_zip_debugfs_init(struct hisi_zip *hisi_zip)
return ret;
}
-static void hisi_zip_debug_regs_clear(struct hisi_zip *hisi_zip)
+static void hisi_zip_debug_regs_clear(struct hisi_qm *qm)
{
- struct hisi_qm *qm = &hisi_zip->qm;
-
writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF);
writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF);
writel(0x0, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);
@@ -619,14 +612,14 @@ static void hisi_zip_debug_regs_clear(struct hisi_zip *hisi_zip)
hisi_qm_debug_regs_clear(qm);
}
-static void hisi_zip_debugfs_exit(struct hisi_zip *hisi_zip)
+static void hisi_zip_debugfs_exit(struct hisi_qm *qm)
{
- struct hisi_qm *qm = &hisi_zip->qm;
-
debugfs_remove_recursive(qm->debug.debug_root);
- if (qm->fun_type == QM_HW_PF)
- hisi_zip_debug_regs_clear(hisi_zip);
+ if (qm->fun_type == QM_HW_PF) {
+ hisi_zip_debug_regs_clear(qm);
+ qm->debug.curr_qm_qp_num = 0;
+ }
}
static void hisi_zip_log_hw_error(struct hisi_qm *qm, u32 err_sts)
@@ -733,7 +726,7 @@ static int hisi_zip_pf_probe_init(struct hisi_zip *hisi_zip)
hisi_zip_set_user_domain_and_cache(qm);
hisi_qm_dev_err_init(qm);
- hisi_zip_debug_regs_clear(hisi_zip);
+ hisi_zip_debug_regs_clear(qm);
return 0;
}
@@ -809,7 +802,7 @@ static int hisi_zip_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (ret)
goto err_dev_err_uninit;
- ret = hisi_zip_debugfs_init(hisi_zip);
+ ret = hisi_zip_debugfs_init(qm);
if (ret)
dev_err(&pdev->dev, "Failed to init debugfs (%d)!\n", ret);
@@ -837,7 +830,7 @@ static int hisi_zip_probe(struct pci_dev *pdev, const struct pci_device_id *id)
hisi_qm_alg_unregister(qm, &zip_devices);
err_qm_stop:
- hisi_zip_debugfs_exit(hisi_zip);
+ hisi_zip_debugfs_exit(qm);
hisi_qm_stop(qm, QM_NORMAL);
err_dev_err_uninit:
@@ -860,7 +853,7 @@ static void hisi_zip_remove(struct pci_dev *pdev)
if (qm->fun_type == QM_HW_PF && qm->vfs_num)
hisi_qm_sriov_disable(pdev, qm->is_frozen);
- hisi_zip_debugfs_exit(hisi_zip);
+ hisi_zip_debugfs_exit(qm);
hisi_qm_stop(qm, QM_NORMAL);
hisi_qm_dev_err_uninit(qm);
hisi_qm_uninit(qm);
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf'
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
` (2 preceding siblings ...)
2020-08-24 3:11 ` [PATCH RESEND 03/10] crypto: hisilicon/zip - modify debugfs interface parameters Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-08-24 8:29 ` David Laight
2020-08-24 3:11 ` [PATCH RESEND 05/10] crypto: hisilicon/zip - use a enum parameter instead of some macros Yang Shen
` (6 subsequent siblings)
10 siblings, 1 reply; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
Replace 'sprintf' with 'scnprintf' to avoid overrun.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip_main.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index df1a16f..1883d1b 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -428,7 +428,7 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
return -EINVAL;
}
spin_unlock_irq(&file->lock);
- ret = sprintf(tbuf, "%u\n", val);
+ ret = scnprintf(tbuf, HZIP_BUF_SIZE, "%u\n", val);
return simple_read_from_buffer(buf, count, pos, tbuf, ret);
}
@@ -514,13 +514,16 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm)
struct debugfs_regset32 *regset;
struct dentry *tmp_d;
char buf[HZIP_BUF_SIZE];
- int i;
+ int i, ret;
for (i = 0; i < HZIP_CORE_NUM; i++) {
if (i < HZIP_COMP_CORE_NUM)
- sprintf(buf, "comp_core%d", i);
+ ret = scnprintf(buf, HZIP_BUF_SIZE, "comp_core%d", i);
else
- sprintf(buf, "decomp_core%d", i - HZIP_COMP_CORE_NUM);
+ ret = scnprintf(buf, HZIP_BUF_SIZE, "decomp_core%d",
+ i - HZIP_COMP_CORE_NUM);
+ if (!ret)
+ return -ENOMEM;
regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL);
if (!regset)
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* RE: [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf'
2020-08-24 3:11 ` [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf' Yang Shen
@ 2020-08-24 8:29 ` David Laight
2020-08-26 8:56 ` shenyang (M)
0 siblings, 1 reply; 16+ messages in thread
From: David Laight @ 2020-08-24 8:29 UTC (permalink / raw)
To: 'Yang Shen', herbert, davem
Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
From: Yang Shen
> Sent: 24 August 2020 04:12
>
> Replace 'sprintf' with 'scnprintf' to avoid overrun.
>
> Signed-off-by: Yang Shen <shenyang39@huawei.com>
> Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
> ---
> drivers/crypto/hisilicon/zip/zip_main.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
> index df1a16f..1883d1b 100644
> --- a/drivers/crypto/hisilicon/zip/zip_main.c
> +++ b/drivers/crypto/hisilicon/zip/zip_main.c
> @@ -428,7 +428,7 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
> return -EINVAL;
> }
> spin_unlock_irq(&file->lock);
> - ret = sprintf(tbuf, "%u\n", val);
> + ret = scnprintf(tbuf, HZIP_BUF_SIZE, "%u\n", val);
Should that be sizeof (tbuf).
> return simple_read_from_buffer(buf, count, pos, tbuf, ret);
> }
>
> @@ -514,13 +514,16 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm)
> struct debugfs_regset32 *regset;
> struct dentry *tmp_d;
> char buf[HZIP_BUF_SIZE];
> - int i;
> + int i, ret;
>
> for (i = 0; i < HZIP_CORE_NUM; i++) {
> if (i < HZIP_COMP_CORE_NUM)
> - sprintf(buf, "comp_core%d", i);
> + ret = scnprintf(buf, HZIP_BUF_SIZE, "comp_core%d", i);
> else
> - sprintf(buf, "decomp_core%d", i - HZIP_COMP_CORE_NUM);
> + ret = scnprintf(buf, HZIP_BUF_SIZE, "decomp_core%d",
> + i - HZIP_COMP_CORE_NUM);
> + if (!ret)
> + return -ENOMEM;
and that is just so wrong - did you even try to test
the 'buffer too small' code path?
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf'
2020-08-24 8:29 ` David Laight
@ 2020-08-26 8:56 ` shenyang (M)
2020-09-04 7:40 ` Herbert Xu
0 siblings, 1 reply; 16+ messages in thread
From: shenyang (M) @ 2020-08-26 8:56 UTC (permalink / raw)
To: David Laight, herbert, davem
Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
On 2020/8/24 16:29, David Laight wrote:
> From: Yang Shen
>> Sent: 24 August 2020 04:12
>>
>> Replace 'sprintf' with 'scnprintf' to avoid overrun.
>>
>> Signed-off-by: Yang Shen <shenyang39@huawei.com>
>> Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
>> ---
>> drivers/crypto/hisilicon/zip/zip_main.c | 11 +++++++----
>> 1 file changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
>> index df1a16f..1883d1b 100644
>> --- a/drivers/crypto/hisilicon/zip/zip_main.c
>> +++ b/drivers/crypto/hisilicon/zip/zip_main.c
>> @@ -428,7 +428,7 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
>> return -EINVAL;
>> }
>> spin_unlock_irq(&file->lock);
>> - ret = sprintf(tbuf, "%u\n", val);
>> + ret = scnprintf(tbuf, HZIP_BUF_SIZE, "%u\n", val);
>
> Should that be sizeof (tbuf).
>
>> return simple_read_from_buffer(buf, count, pos, tbuf, ret);
>> }
>>
>> @@ -514,13 +514,16 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm)
>> struct debugfs_regset32 *regset;
>> struct dentry *tmp_d;
>> char buf[HZIP_BUF_SIZE];
>> - int i;
>> + int i, ret;
>>
>> for (i = 0; i < HZIP_CORE_NUM; i++) {
>> if (i < HZIP_COMP_CORE_NUM)
>> - sprintf(buf, "comp_core%d", i);
>> + ret = scnprintf(buf, HZIP_BUF_SIZE, "comp_core%d", i);
>> else
>> - sprintf(buf, "decomp_core%d", i - HZIP_COMP_CORE_NUM);
>> + ret = scnprintf(buf, HZIP_BUF_SIZE, "decomp_core%d",
>> + i - HZIP_COMP_CORE_NUM);
>> + if (!ret)
>> + return -ENOMEM;
>
> and that is just so wrong - did you even try to test
> the 'buffer too small' code path?
>
> David
>
Do you means the check is unnecessary?
Yang
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
>
> .
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf'
2020-08-26 8:56 ` shenyang (M)
@ 2020-09-04 7:40 ` Herbert Xu
2020-09-04 8:43 ` shenyang (M)
0 siblings, 1 reply; 16+ messages in thread
From: Herbert Xu @ 2020-09-04 7:40 UTC (permalink / raw)
To: shenyang (M)
Cc: David Laight, davem, linux-kernel, linux-crypto, xuzaibo, wangzhou1
On Wed, Aug 26, 2020 at 04:56:40PM +0800, shenyang (M) wrote:
>
> > > @@ -514,13 +514,16 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm)
> > > struct debugfs_regset32 *regset;
> > > struct dentry *tmp_d;
> > > char buf[HZIP_BUF_SIZE];
> > > - int i;
> > > + int i, ret;
> > >
> > > for (i = 0; i < HZIP_CORE_NUM; i++) {
> > > if (i < HZIP_COMP_CORE_NUM)
> > > - sprintf(buf, "comp_core%d", i);
> > > + ret = scnprintf(buf, HZIP_BUF_SIZE, "comp_core%d", i);
> > > else
> > > - sprintf(buf, "decomp_core%d", i - HZIP_COMP_CORE_NUM);
> > > + ret = scnprintf(buf, HZIP_BUF_SIZE, "decomp_core%d",
> > > + i - HZIP_COMP_CORE_NUM);
> > > + if (!ret)
> > > + return -ENOMEM;
> >
> > and that is just so wrong - did you even try to test
> > the 'buffer too small' code path?
>
> Do you means the check is unnecessary?
No he's saying that your patch does the wrong thing when the string
is truncated.
Also ENOMEM is a strange error for that case.
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] 16+ messages in thread
* Re: [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf'
2020-09-04 7:40 ` Herbert Xu
@ 2020-09-04 8:43 ` shenyang (M)
0 siblings, 0 replies; 16+ messages in thread
From: shenyang (M) @ 2020-09-04 8:43 UTC (permalink / raw)
To: Herbert Xu
Cc: David Laight, davem, linux-kernel, linux-crypto, xuzaibo, wangzhou1
On 2020/9/4 15:40, Herbert Xu wrote:
> On Wed, Aug 26, 2020 at 04:56:40PM +0800, shenyang (M) wrote:
>>
>>>> @@ -514,13 +514,16 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm)
>>>> struct debugfs_regset32 *regset;
>>>> struct dentry *tmp_d;
>>>> char buf[HZIP_BUF_SIZE];
>>>> - int i;
>>>> + int i, ret;
>>>>
>>>> for (i = 0; i < HZIP_CORE_NUM; i++) {
>>>> if (i < HZIP_COMP_CORE_NUM)
>>>> - sprintf(buf, "comp_core%d", i);
>>>> + ret = scnprintf(buf, HZIP_BUF_SIZE, "comp_core%d", i);
>>>> else
>>>> - sprintf(buf, "decomp_core%d", i - HZIP_COMP_CORE_NUM);
>>>> + ret = scnprintf(buf, HZIP_BUF_SIZE, "decomp_core%d",
>>>> + i - HZIP_COMP_CORE_NUM);
>>>> + if (!ret)
>>>> + return -ENOMEM;
>>>
>>> and that is just so wrong - did you even try to test
>>> the 'buffer too small' code path?
>>
>> Do you means the check is unnecessary?
>
> No he's saying that your patch does the wrong thing when the string
> is truncated.
>
> Also ENOMEM is a strange error for that case.
>
> Cheers,
>
Here 'HZIP_BUF_SIZE' is 22, so the buf is enough for the string.
The check for the return is really unnecessary, I will remove it in the
next version.
Thanks,
Yang
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH RESEND 05/10] crypto: hisilicon/zip - use a enum parameter instead of some macros
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
` (3 preceding siblings ...)
2020-08-24 3:11 ` [PATCH RESEND 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf' Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 06/10] crypto: hisilicon/zip - add print for error branch Yang Shen
` (5 subsequent siblings)
10 siblings, 0 replies; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
Macros 'QPC_COMP', 'QPC_DECOMP' and 'HZIP_CTX_Q_NUM' are relative and
incremental. So, use an enum instead.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip_crypto.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index aba1600..c2ea849 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -19,7 +19,6 @@
#define GZIP_HEAD_FEXTRA_XLEN 2
#define GZIP_HEAD_FHCRC_SIZE 2
-#define HZIP_CTX_Q_NUM 2
#define HZIP_GZIP_HEAD_BUF 256
#define HZIP_ALG_PRIORITY 300
#define HZIP_SGL_SGE_NR 10
@@ -32,6 +31,12 @@ enum hisi_zip_alg_type {
HZIP_ALG_TYPE_DECOMP = 1,
};
+enum {
+ HZIP_QPC_COMP,
+ HZIP_QPC_DECOMP,
+ HZIP_CTX_Q_NUM
+};
+
#define COMP_NAME_TO_TYPE(alg_name) \
(!strcmp((alg_name), "zlib-deflate") ? HZIP_ALG_TYPE_ZLIB : \
!strcmp((alg_name), "gzip") ? HZIP_ALG_TYPE_GZIP : 0) \
@@ -71,8 +76,6 @@ struct hisi_zip_qp_ctx {
};
struct hisi_zip_ctx {
-#define QPC_COMP 0
-#define QPC_DECOMP 1
struct hisi_zip_qp_ctx qp_ctx[HZIP_CTX_Q_NUM];
};
@@ -264,11 +267,11 @@ static int hisi_zip_create_req_q(struct hisi_zip_ctx *ctx)
return 0;
err_free_loop1:
- kfree(ctx->qp_ctx[QPC_DECOMP].req_q.req_bitmap);
+ kfree(ctx->qp_ctx[HZIP_QPC_DECOMP].req_q.req_bitmap);
err_free_loop0:
- kfree(ctx->qp_ctx[QPC_COMP].req_q.q);
+ kfree(ctx->qp_ctx[HZIP_QPC_COMP].req_q.q);
err_free_bitmap:
- kfree(ctx->qp_ctx[QPC_COMP].req_q.req_bitmap);
+ kfree(ctx->qp_ctx[HZIP_QPC_COMP].req_q.req_bitmap);
return ret;
}
@@ -303,8 +306,8 @@ static int hisi_zip_create_sgl_pool(struct hisi_zip_ctx *ctx)
return 0;
err_free_sgl_pool0:
- hisi_acc_free_sgl_pool(&ctx->qp_ctx[QPC_COMP].qp->qm->pdev->dev,
- ctx->qp_ctx[QPC_COMP].sgl_pool);
+ hisi_acc_free_sgl_pool(&ctx->qp_ctx[HZIP_QPC_COMP].qp->qm->pdev->dev,
+ ctx->qp_ctx[HZIP_QPC_COMP].sgl_pool);
return -ENOMEM;
}
@@ -539,7 +542,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
static int hisi_zip_acompress(struct acomp_req *acomp_req)
{
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
- struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[QPC_COMP];
+ struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP];
struct hisi_zip_req *req;
int head_size;
int ret;
@@ -563,7 +566,7 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)
static int hisi_zip_adecompress(struct acomp_req *acomp_req)
{
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
- struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[QPC_DECOMP];
+ struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP];
struct hisi_zip_req *req;
size_t head_size;
int ret;
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH RESEND 06/10] crypto: hisilicon/zip - add print for error branch
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
` (4 preceding siblings ...)
2020-08-24 3:11 ` [PATCH RESEND 05/10] crypto: hisilicon/zip - use a enum parameter instead of some macros Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 07/10] crypto: hisilicon/zip - fix static check warning Yang Shen
` (4 subsequent siblings)
10 siblings, 0 replies; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
Add print for some error branches.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip_crypto.c | 68 +++++++++++++++++++++++--------
drivers/crypto/hisilicon/zip/zip_main.c | 8 ++--
2 files changed, 56 insertions(+), 20 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index c2ea849..7aa8a55 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -146,7 +146,7 @@ static int hisi_zip_start_qp(struct hisi_qp *qp, struct hisi_zip_qp_ctx *ctx,
ret = hisi_qm_start_qp(qp, 0);
if (ret < 0) {
- dev_err(dev, "start qp failed!\n");
+ dev_err(dev, "Start qp failed (%d)!\n", ret);
return ret;
}
@@ -169,7 +169,7 @@ static int hisi_zip_ctx_init(struct hisi_zip_ctx *hisi_zip_ctx, u8 req_type, int
ret = zip_create_qps(qps, HZIP_CTX_Q_NUM, node);
if (ret) {
- pr_err("Can not create zip qps!\n");
+ pr_err("Can not create zip qps (%d)!\n", ret);
return -ENODEV;
}
@@ -380,19 +380,28 @@ static int hisi_zip_acomp_init(struct crypto_acomp *tfm)
{
const char *alg_name = crypto_tfm_alg_name(&tfm->base);
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(&tfm->base);
+ struct device *dev;
int ret;
ret = hisi_zip_ctx_init(ctx, COMP_NAME_TO_TYPE(alg_name), tfm->base.node);
- if (ret)
+ if (ret) {
+ pr_err("Init ctx failed (%d)!\n", ret);
return ret;
+ }
+
+ dev = &ctx->qp_ctx[0].qp->qm->pdev->dev;
ret = hisi_zip_create_req_q(ctx);
- if (ret)
+ if (ret) {
+ dev_err(dev, "Create request queue failed (%d)!\n", ret);
goto err_ctx_exit;
+ }
ret = hisi_zip_create_sgl_pool(ctx);
- if (ret)
+ if (ret) {
+ dev_err(dev, "Create sgl pool failed (%d)!\n", ret);
goto err_release_req_q;
+ }
hisi_zip_set_acomp_cb(ctx, hisi_zip_acomp_cb);
@@ -422,8 +431,10 @@ static int add_comp_head(struct scatterlist *dst, u8 req_type)
int ret;
ret = sg_copy_from_buffer(dst, sg_nents(dst), head, head_size);
- if (ret != head_size)
+ if (ret != head_size) {
+ pr_err("The head size of buffer is wrong (%d)!\n", ret);
return -ENOMEM;
+ }
return head_size;
}
@@ -445,7 +456,7 @@ static size_t get_comp_head_size(struct scatterlist *src, u8 req_type)
case HZIP_ALG_TYPE_GZIP:
return get_gzip_head_size(src);
default:
- pr_err("request type does not support!\n");
+ pr_err("Request type does not support!\n");
return -EINVAL;
}
}
@@ -464,7 +475,7 @@ static struct hisi_zip_req *hisi_zip_create_req(struct acomp_req *req,
req_id = find_first_zero_bit(req_q->req_bitmap, req_q->size);
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");
+ dev_dbg(&qp_ctx->qp->qm->pdev->dev, "Req cache is full!\n");
return ERR_PTR(-EBUSY);
}
set_bit(req_id, req_q->req_bitmap);
@@ -504,14 +515,19 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
req->hw_src = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->src, pool,
req->req_id << 1, &input);
- if (IS_ERR(req->hw_src))
+ if (IS_ERR(req->hw_src)) {
+ dev_err(dev, "The src map to hw SGL failed (%ld)!\n",
+ PTR_ERR(req->hw_src));
return PTR_ERR(req->hw_src);
+ }
req->dma_src = input;
req->hw_dst = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_req->dst, pool,
(req->req_id << 1) + 1,
&output);
if (IS_ERR(req->hw_dst)) {
+ dev_err(dev, "The dst map to hw SGL failed (%ld)!\n",
+ PTR_ERR(req->hw_dst));
ret = PTR_ERR(req->hw_dst);
goto err_unmap_input;
}
@@ -527,6 +543,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);
+ dev_dbg_ratelimited(dev, "Send task message failed!\n");
goto err_unmap_output;
}
@@ -543,22 +560,32 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)
{
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP];
+ struct device *dev = &qp_ctx->qp->qm->pdev->dev;
struct hisi_zip_req *req;
int head_size;
int ret;
/* let's output compression head now */
head_size = add_comp_head(acomp_req->dst, qp_ctx->qp->req_type);
- if (head_size < 0)
- return -ENOMEM;
+ if (head_size < 0) {
+ dev_err_ratelimited(dev, "Add comp head failed (%d)!\n",
+ head_size);
+ return head_size;
+ }
req = hisi_zip_create_req(acomp_req, qp_ctx, (size_t)head_size, true);
- if (IS_ERR(req))
+ if (IS_ERR(req)) {
+ dev_err_ratelimited(dev, "Create request before compress failed (%ld)!\n",
+ PTR_ERR(req));
return PTR_ERR(req);
+ }
ret = hisi_zip_do_work(req, qp_ctx);
- if (ret != -EINPROGRESS)
+ if (ret != -EINPROGRESS) {
+ dev_err_ratelimited(dev, "Do compress work failed (%d)!\n",
+ ret);
hisi_zip_remove_req(qp_ctx, req);
+ }
return ret;
}
@@ -567,6 +594,7 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req)
{
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
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;
@@ -574,12 +602,18 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req)
head_size = get_comp_head_size(acomp_req->src, qp_ctx->qp->req_type);
req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, false);
- if (IS_ERR(req))
+ if (IS_ERR(req)) {
+ dev_err_ratelimited(dev, "Create request before decompress failed (%ld)!\n",
+ PTR_ERR(req));
return PTR_ERR(req);
+ }
ret = hisi_zip_do_work(req, qp_ctx);
- if (ret != -EINPROGRESS)
+ if (ret != -EINPROGRESS) {
+ dev_err_ratelimited(dev, "Do decompress work failed (%d)!\n",
+ ret);
hisi_zip_remove_req(qp_ctx, req);
+ }
return ret;
}
@@ -618,13 +652,13 @@ int hisi_zip_register_to_crypto(void)
ret = crypto_register_acomp(&hisi_zip_acomp_zlib);
if (ret) {
- pr_err("Zlib acomp algorithm registration failed\n");
+ pr_err("Zlib acomp algorithm registration failed (%d)!\n", ret);
return ret;
}
ret = crypto_register_acomp(&hisi_zip_acomp_gzip);
if (ret) {
- pr_err("Gzip acomp algorithm registration failed\n");
+ pr_err("Gzip acomp algorithm registration failed (%d)!\n", ret);
crypto_unregister_acomp(&hisi_zip_acomp_zlib);
}
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 1883d1b..7697fa5 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -807,18 +807,20 @@ static int hisi_zip_probe(struct pci_dev *pdev, const struct pci_device_id *id)
ret = hisi_zip_debugfs_init(qm);
if (ret)
- dev_err(&pdev->dev, "Failed to init debugfs (%d)!\n", ret);
+ pci_err(pdev, "Failed to init debugfs (%d)!\n", ret);
ret = hisi_qm_alg_register(qm, &zip_devices);
if (ret < 0) {
- pci_err(pdev, "Failed to register driver to crypto.\n");
+ pci_err(pdev, "Failed to register driver to crypto!\n");
goto err_qm_stop;
}
if (qm->uacce) {
ret = uacce_register(qm->uacce);
- if (ret)
+ if (ret) {
+ pci_err(pdev, "Failed to register uacce (%d)!\n", ret);
goto err_qm_alg_unregister;
+ }
}
if (qm->fun_type == QM_HW_PF && vfs_num > 0) {
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH RESEND 07/10] crypto: hisilicon/zip - fix static check warning
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
` (5 preceding siblings ...)
2020-08-24 3:11 ` [PATCH RESEND 06/10] crypto: hisilicon/zip - add print for error branch Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 08/10] crypto: hisilicon/zip - move some private macros from 'zip.h' to 'zip_crypto.c' Yang Shen
` (3 subsequent siblings)
10 siblings, 0 replies; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
Fix some code for PClint warning:
Warning - Suspicious Cast
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip_crypto.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index 7aa8a55..fdc5bd3 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -16,7 +16,7 @@
#define GZIP_HEAD_FLG_SHIFT 3
#define GZIP_HEAD_FEXTRA_SHIFT 10
-#define GZIP_HEAD_FEXTRA_XLEN 2
+#define GZIP_HEAD_FEXTRA_XLEN 2UL
#define GZIP_HEAD_FHCRC_SIZE 2
#define HZIP_GZIP_HEAD_BUF 256
@@ -51,13 +51,13 @@ enum {
struct hisi_zip_req {
struct acomp_req *req;
- int sskip;
- int dskip;
+ u32 sskip;
+ u32 dskip;
struct hisi_acc_hw_sgl *hw_src;
struct hisi_acc_hw_sgl *hw_dst;
dma_addr_t dma_src;
dma_addr_t dma_dst;
- int req_id;
+ u16 req_id;
};
struct hisi_zip_req_q {
@@ -119,7 +119,7 @@ static void hisi_zip_config_tag(struct hisi_zip_sqe *sqe, u32 tag)
static void hisi_zip_fill_sqe(struct hisi_zip_sqe *sqe, u8 req_type,
dma_addr_t s_addr, dma_addr_t d_addr, u32 slen,
- u32 dlen, int sskip, int dskip)
+ u32 dlen, u32 sskip, u32 dskip)
{
memset(sqe, 0, sizeof(struct hisi_zip_sqe));
@@ -573,7 +573,7 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)
return head_size;
}
- req = hisi_zip_create_req(acomp_req, qp_ctx, (size_t)head_size, true);
+ req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, true);
if (IS_ERR(req)) {
dev_err_ratelimited(dev, "Create request before compress failed (%ld)!\n",
PTR_ERR(req));
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH RESEND 08/10] crypto: hisilicon/zip - move some private macros from 'zip.h' to 'zip_crypto.c'
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
` (6 preceding siblings ...)
2020-08-24 3:11 ` [PATCH RESEND 07/10] crypto: hisilicon/zip - fix static check warning Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 09/10] crypto: hisilicon/zip - supplement some comments Yang Shen
` (2 subsequent siblings)
10 siblings, 0 replies; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
Some macros which are defined in 'zip.h' are related to the struct
'hisi_zip_sqe' and are only used in 'zip_crypto.c'. So move them from
'zip.h' to 'zip_crypto.c'.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip.h | 14 --------------
drivers/crypto/hisilicon/zip/zip_crypto.c | 14 ++++++++++++++
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip.h b/drivers/crypto/hisilicon/zip/zip.h
index 4b3aae8..92397f9 100644
--- a/drivers/crypto/hisilicon/zip/zip.h
+++ b/drivers/crypto/hisilicon/zip/zip.h
@@ -9,20 +9,6 @@
#include <linux/list.h>
#include "../qm.h"
-/* hisi_zip_sqe dw3 */
-#define HZIP_BD_STATUS_M GENMASK(7, 0)
-/* hisi_zip_sqe dw7 */
-#define HZIP_IN_SGE_DATA_OFFSET_M GENMASK(23, 0)
-/* hisi_zip_sqe dw8 */
-#define HZIP_OUT_SGE_DATA_OFFSET_M GENMASK(23, 0)
-/* hisi_zip_sqe dw9 */
-#define HZIP_REQ_TYPE_M GENMASK(7, 0)
-#define HZIP_ALG_TYPE_ZLIB 0x02
-#define HZIP_ALG_TYPE_GZIP 0x03
-#define HZIP_BUF_TYPE_M GENMASK(11, 8)
-#define HZIP_PBUFFER 0x0
-#define HZIP_SGL 0x1
-
enum hisi_zip_error_type {
/* negative compression */
HZIP_NC_ERR = 0x0d,
diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index fdc5bd3..7757e33 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -6,6 +6,20 @@
#include <linux/scatterlist.h>
#include "zip.h"
+/* hisi_zip_sqe dw3 */
+#define HZIP_BD_STATUS_M GENMASK(7, 0)
+/* hisi_zip_sqe dw7 */
+#define HZIP_IN_SGE_DATA_OFFSET_M GENMASK(23, 0)
+/* hisi_zip_sqe dw8 */
+#define HZIP_OUT_SGE_DATA_OFFSET_M GENMASK(23, 0)
+/* hisi_zip_sqe dw9 */
+#define HZIP_REQ_TYPE_M GENMASK(7, 0)
+#define HZIP_ALG_TYPE_ZLIB 0x02
+#define HZIP_ALG_TYPE_GZIP 0x03
+#define HZIP_BUF_TYPE_M GENMASK(11, 8)
+#define HZIP_PBUFFER 0x0
+#define HZIP_SGL 0x1
+
#define HZIP_ZLIB_HEAD_SIZE 2
#define HZIP_GZIP_HEAD_SIZE 10
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH RESEND 09/10] crypto: hisilicon/zip - supplement some comments
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
` (7 preceding siblings ...)
2020-08-24 3:11 ` [PATCH RESEND 08/10] crypto: hisilicon/zip - move some private macros from 'zip.h' to 'zip_crypto.c' Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-08-24 3:11 ` [PATCH RESEND 10/10] crypto: hisilicon/zip - fix some coding styles Yang Shen
2020-09-02 9:36 ` [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up shenyang (M)
10 siblings, 0 replies; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
Supplement some comments.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 7697fa5..49fad18 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -285,7 +285,7 @@ static int hisi_zip_set_user_domain_and_cache(struct hisi_qm *qm)
writel(HZIP_DECOMP_CHECK_ENABLE | HZIP_ALL_COMP_DECOMP_EN,
base + HZIP_CLOCK_GATE_CTRL);
- /* enable sqc writeback */
+ /* enable sqc,cqc writeback */
writel(SQC_CACHE_ENABLE | CQC_CACHE_ENABLE | SQC_CACHE_WB_ENABLE |
CQC_CACHE_WB_ENABLE | FIELD_PREP(SQC_CACHE_WB_THRD, 1) |
FIELD_PREP(CQC_CACHE_WB_THRD, 1), base + QM_CACHE_CTL);
@@ -358,7 +358,7 @@ static int current_qm_write(struct ctrl_debug_file *file, u32 val)
if (val > qm->vfs_num)
return -EINVAL;
- /* Calculate curr_qm_qp_num and store */
+ /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */
if (val == 0) {
qm->debug.curr_qm_qp_num = qm->qp_num;
} else {
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH RESEND 10/10] crypto: hisilicon/zip - fix some coding styles
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
` (8 preceding siblings ...)
2020-08-24 3:11 ` [PATCH RESEND 09/10] crypto: hisilicon/zip - supplement some comments Yang Shen
@ 2020-08-24 3:11 ` Yang Shen
2020-09-02 9:36 ` [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up shenyang (M)
10 siblings, 0 replies; 16+ messages in thread
From: Yang Shen @ 2020-08-24 3:11 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
1.Unified alignment styles
2.Remove unnecessary goto branch
3.Remove address printf
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
---
drivers/crypto/hisilicon/zip/zip_crypto.c | 13 ++++++-------
drivers/crypto/hisilicon/zip/zip_main.c | 16 ++++------------
2 files changed, 10 insertions(+), 19 deletions(-)
diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index 7757e33..10b7adb 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -38,8 +38,10 @@
#define HZIP_SGL_SGE_NR 10
static const u8 zlib_head[HZIP_ZLIB_HEAD_SIZE] = {0x78, 0x9c};
-static const u8 gzip_head[HZIP_GZIP_HEAD_SIZE] = {0x1f, 0x8b, 0x08, 0x0, 0x0,
- 0x0, 0x0, 0x0, 0x0, 0x03};
+static const u8 gzip_head[HZIP_GZIP_HEAD_SIZE] = {
+ 0x1f, 0x8b, 0x08, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x03
+};
+
enum hisi_zip_alg_type {
HZIP_ALG_TYPE_COMP = 0,
HZIP_ALG_TYPE_DECOMP = 1,
@@ -359,7 +361,6 @@ static void hisi_zip_acomp_cb(struct hisi_qp *qp, void *data)
atomic64_inc(&dfx->recv_cnt);
status = sqe->dw3 & HZIP_BD_STATUS_M;
-
if (status != 0 && status != HZIP_NC_ERR) {
dev_err(dev, "%scompress fail in qp%u: %u, output: %u\n",
(qp->alg_type == 0) ? "" : "de", qp->qp_id, status,
@@ -520,8 +521,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool;
struct hisi_zip_dfx *dfx = &qp_ctx->zip_dev->dfx;
struct hisi_zip_sqe zip_sqe;
- dma_addr_t input;
- dma_addr_t output;
+ dma_addr_t input, output;
int ret;
if (!a_req->src || !a_req->slen || !a_req->dst || !a_req->dlen)
@@ -540,9 +540,8 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
(req->req_id << 1) + 1,
&output);
if (IS_ERR(req->hw_dst)) {
- dev_err(dev, "The dst map to hw SGL failed (%ld)!\n",
- PTR_ERR(req->hw_dst));
ret = PTR_ERR(req->hw_dst);
+ dev_err(dev, "The dst map to hw SGL failed (%d)!\n", ret);
goto err_unmap_input;
}
req->dma_dst = output;
diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 49fad18..8bbae28 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -258,6 +258,7 @@ static int hisi_zip_set_user_domain_and_cache(struct hisi_qm *qm)
/* qm cache */
writel(AXI_M_CFG, base + QM_AXI_M_CFG);
writel(AXI_M_CFG_ENABLE, base + QM_AXI_M_CFG_ENABLE);
+
/* disable FLR triggered by BME(bus master enable) */
writel(PEH_AXUSER_CFG, base + QM_PEH_AXUSER_CFG);
writel(PEH_AXUSER_CFG_ENABLE, base + QM_PEH_AXUSER_CFG_ENABLE);
@@ -311,7 +312,7 @@ static void hisi_zip_hw_error_enable(struct hisi_qm *qm)
writel(0x1, qm->io_base + HZIP_CORE_INT_RAS_CE_ENB);
writel(0x0, qm->io_base + HZIP_CORE_INT_RAS_FE_ENB);
writel(HZIP_CORE_INT_RAS_NFE_ENABLE,
- qm->io_base + HZIP_CORE_INT_RAS_NFE_ENB);
+ qm->io_base + HZIP_CORE_INT_RAS_NFE_ENB);
/* enable ZIP hw error interrupts */
writel(0, qm->io_base + HZIP_CORE_INT_MASK_REG);
@@ -487,7 +488,6 @@ static const struct file_operations ctrl_debug_fops = {
.write = hisi_zip_ctrl_debug_write,
};
-
static int zip_debugfs_atomic64_set(void *data, u64 val)
{
if (val)
@@ -634,7 +634,7 @@ static void hisi_zip_log_hw_error(struct hisi_qm *qm, u32 err_sts)
while (err->msg) {
if (err->int_msk & err_sts) {
dev_err(dev, "%s [error status=0x%x] found\n",
- err->msg, err->int_msk);
+ err->msg, err->int_msk);
if (err->int_msk & HZIP_CORE_INT_STATUS_M_ECC) {
err_val = readl(qm->io_base +
@@ -642,9 +642,6 @@ static void hisi_zip_log_hw_error(struct hisi_qm *qm, u32 err_sts)
dev_err(dev, "hisi-zip multi ecc sram num=0x%x\n",
((err_val >>
HZIP_SRAM_ECC_ERR_NUM_SHIFT) & 0xFF));
- dev_err(dev, "hisi-zip multi ecc sram addr=0x%x\n",
- (err_val >>
- HZIP_SRAM_ECC_ERR_ADDR_SHIFT));
}
}
err++;
@@ -904,15 +901,10 @@ static int __init hisi_zip_init(void)
ret = pci_register_driver(&hisi_zip_pci_driver);
if (ret < 0) {
+ hisi_zip_unregister_debugfs();
pr_err("Failed to register pci driver.\n");
- goto err_pci;
}
- return 0;
-
-err_pci:
- hisi_zip_unregister_debugfs();
-
return ret;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up
2020-08-24 3:11 [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up Yang Shen
` (9 preceding siblings ...)
2020-08-24 3:11 ` [PATCH RESEND 10/10] crypto: hisilicon/zip - fix some coding styles Yang Shen
@ 2020-09-02 9:36 ` shenyang (M)
10 siblings, 0 replies; 16+ messages in thread
From: shenyang (M) @ 2020-09-02 9:36 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-kernel, linux-crypto, xuzaibo, wangzhou1
any comment?
Thanks,
Yang
On 2020/8/24 11:11, Yang Shen wrote:
> This patchset make some clean up:
> patch 1:remove useless parameters
> patch 4:replace 'sprintf' with 'scnprintf'
> patch 7:fix static check warning
> and the rest patch fix some coding style
>
> Resend this patch series because it depends on
> https://patchwork.kernel.org/cover/11715927/
> (crypto: hisilicon/qm - misc fixes).
> Now the patch series(crypto: hisilicon/qm - misc fixes) has been applied.
> So this patch series will apply against cryptodev.
>
> Shukun Tan (1):
> crypto: hisilicon/zip - modify debugfs interface parameters
>
> Yang Shen (9):
> crypto: hisilicon/zip - remove some useless parameters
> crypto: hisilicon/zip - unify naming style for functions and macros
> crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf'
> crypto: hisilicon/zip - use a enum parameter instead of some macros
> crypto: hisilicon/zip - add print for error branch
> crypto: hisilicon/zip - fix static check warning
> crypto: hisilicon/zip - move some private macros from 'zip.h' to
> 'zip_crypto.c'
> crypto: hisilicon/zip - supplement some comments
> crypto: hisilicon/zip - fix some coding styles
>
> drivers/crypto/hisilicon/zip/zip.h | 15 ----
> drivers/crypto/hisilicon/zip/zip_crypto.c | 126 ++++++++++++++++++++---------
> drivers/crypto/hisilicon/zip/zip_main.c | 130 ++++++++++++++----------------
> 3 files changed, 148 insertions(+), 123 deletions(-)
>
> --
> 2.7.4
>
>
> .
>
^ permalink raw reply [flat|nested] 16+ messages in thread