crypto: hisilicon - Optimize and fix some driver processes
Subsystems (5)
Chenghai Huang
maintainerv2 cover crypto: hisilicon - Optimize and fix some driver processes
This patch series is mainly used to fix and optimize some problems of hisilicon.
v1 -> v2
- fixed codecheck warnings about unused variable
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Chenghai Huang (9):
crypto: hisilicon/sec - Add the condition for configuring the sriov
function
crypto: hisilicon/debugfs - Fix debugfs uninit process issue
crypto: hisilicon/sgl - Delete redundant parameter verification
crypto: hisilicon/debugfs - Fix the processing logic issue in the
debugfs creation
crypto: hisilicon/qm - Add the default processing branch
crypto: hisilicon - Adjust debugfs creation and release order
crypto: hisilicon/sec - Fix memory leak for sec resource release
crypto: hisilicon/debugfs - Resolve the problem of applying for
redundant space in sq dump
crypto: hisilicon/qm - Add the err memory release process to qm uninit
drivers/crypto/hisilicon/debugfs.c | 38 +++++++++++++++------- drivers/crypto/hisilicon/hpre/hpre_main.c | 21 ++++++------ drivers/crypto/hisilicon/qm.c | 8 ++--- drivers/crypto/hisilicon/sec2/sec_crypto.c | 4 ++- drivers/crypto/hisilicon/sec2/sec_main.c | 26 +++++++-------- drivers/crypto/hisilicon/sgl.c | 5 +-- drivers/crypto/hisilicon/zip/zip_main.c | 24 +++++++------- 7 files changed, 68 insertions(+), 58 deletions(-)
Signature · 1 line
2.30.0
Chenghai Huang
maintainerPATCH v2 1/9 crypto: hisilicon/sec - Add the condition for configuring the sriov function
When CONFIG_PCI_IOV is disabled, the SRIOV configuration function is not required. An error occurs if this function is incorrectly called.
Consistent with other modules, add the condition for configuring the sriov function of sec_pci_driver.
--- drivers/crypto/hisilicon/sec2/sec_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/hisilicon/sec2/sec_main.c +2 -1
@@ -1324,7 +1324,8 @@ static struct pci_driver sec_pci_driver = { .probe = sec_probe, .remove = sec_remove, .err_handler = &sec_err_handler, - .sriov_configure = hisi_qm_sriov_configure, + .sriov_configure = IS_ENABLED(CONFIG_PCI_IOV) ? + hisi_qm_sriov_configure : NULL, .shutdown = hisi_qm_dev_shutdown, .driver.pm = &sec_pm_ops, };
Signature · 1 line
2.30.0
Chenghai Huang
maintainerPATCH v2 2/9 crypto: hisilicon/debugfs - Fix debugfs uninit process issue
In reply to Chenghai HuangDuring the zip probe process, the debugfs failure does not stop the probe. When debugfs initialization fails, jumping to the error branch will also release regs, in addition to its own rollback operation.
As a result, it may be released repeatedly during the regs uninit process. Therefore, the null check needs to be added to the regs uninit process.
--- drivers/crypto/hisilicon/debugfs.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/crypto/hisilicon/debugfs.c +18 -3
@@ -809,8 +809,14 @@ static void dfx_regs_uninit(struct hisi_qm *qm, {int i; +if (!dregs) +return ; +/* Setting the pointer is NULL to prevent double free */ for (i =0 ; i < reg_len; i++) { +if (!dregs[i].regs) +continue ; +kfree (dregs[i].regs); dregs[i].regs =NULL ; }
@@ -860,14 +866,21 @@ static struct dfx_diff_registers *dfx_regs_init(struct hisi_qm *qm,static int qm_diff_regs_init (struct hisi_qm *qm,struct dfx_diff_registers *dregs,u32 reg_len) { +int ret; + qm->debug.qm_diff_regs =dfx_regs_init (qm, qm_diff_regs,ARRAY_SIZE (qm_diff_regs)); -if (IS_ERR (qm->debug.qm_diff_regs)) -return PTR_ERR (qm->debug.qm_diff_regs); +if (IS_ERR (qm->debug.qm_diff_regs)) { + ret =PTR_ERR (qm->debug.qm_diff_regs); + qm->debug.qm_diff_regs =NULL ; +return ret; + } qm->debug.acc_diff_regs =dfx_regs_init (qm, dregs, reg_len);if (IS_ERR (qm->debug.acc_diff_regs)) {dfx_regs_uninit (qm, qm->debug.qm_diff_regs,ARRAY_SIZE (qm_diff_regs)); -return PTR_ERR (qm->debug.acc_diff_regs); + ret =PTR_ERR (qm->debug.acc_diff_regs); + qm->debug.acc_diff_regs =NULL ; +return ret; }return 0 ;
@@ -908,7 +921,9 @@ static int qm_last_regs_init(struct hisi_qm *qm)static void qm_diff_regs_uninit (struct hisi_qm *qm,u32 reg_len) {dfx_regs_uninit (qm, qm->debug.acc_diff_regs, reg_len); + qm->debug.acc_diff_regs =NULL ;dfx_regs_uninit (qm, qm->debug.qm_diff_regs,ARRAY_SIZE (qm_diff_regs)); + qm->debug.qm_diff_regs =NULL ; }/**
Signature · 1 line
2.30.0
Chenghai Huang
maintainerPATCH v2 3/9 crypto: hisilicon/sgl - Delete redundant parameter verification
In reply to Chenghai HuangThe input parameter check in acc_get_sgl is redundant. The caller has been verified once. When the check is performed for multiple times, the performance deteriorates.
So the redundant parameter verification is deleted, and the index verification is changed to the module entry function for verification.
--- drivers/crypto/hisilicon/sgl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/crypto/hisilicon/sgl.c +1 -4
@@ -161,9 +161,6 @@ static struct hisi_acc_hw_sgl *acc_get_sgl(struct hisi_acc_sgl_pool *pool,struct mem_block *block;u32 block_index, offset; -if (!pool || !hw_sgl_dma || index >= pool->count) -return ERR_PTR (-EINVAL ); - block = pool->mem_block; block_index = index / pool->sgl_num_per_block; offset = index % pool->sgl_num_per_block;
@@ -230,7 +227,7 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,struct scatterlist *sg;int sg_n; -if (!dev || !sgl || !pool || !hw_sgl_dma) +if (!dev || !sgl || !pool || !hw_sgl_dma || index >= pool->count)return ERR_PTR (-EINVAL ); sg_n =sg_nents (sgl);
Signature · 1 line
2.30.0
Chenghai Huang
maintainerPATCH v2 4/9 crypto: hisilicon/debugfs - Fix the processing logic issue in the debugfs creation
In reply to Chenghai HuangThere is a scenario where the file directory is created but the file attribute is not set. In this case, if a user accesses the file, an error occurs.
So adjust the processing logic in the debugfs creation to prevent the file from being accessed before the file attributes such as the index are set.
--- drivers/crypto/hisilicon/debugfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/hisilicon/debugfs.c +3 -3
@@ -1090,12 +1090,12 @@ static void qm_create_debugfs_file(struct hisi_qm *qm, struct dentry *dir, {struct debugfs_file *file = qm->debug.files + index; -debugfs_create_file (qm_debug_file_name[index],0600 , dir, file, - &qm_debug_fops); - file->index = index;mutex_init (&file->lock); file->debug = &qm->debug; + +debugfs_create_file (qm_debug_file_name[index],0600 , dir, file, + &qm_debug_fops); }static int qm_debugfs_atomic64_set (void *data,u64 val)
Signature · 1 line
2.30.0
Chenghai Huang
maintainerPATCH v2 5/9 crypto: hisilicon/qm - Add the default processing branch
In reply to Chenghai HuangThe cmd type can be extended. Currently, only four types of cmd can be processed. Therefor, add the default processing branch to intercept incorrect parameter input.
--- drivers/crypto/hisilicon/qm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/crypto/hisilicon/qm.c +3 -0
@@ -645,6 +645,9 @@ int qm_set_and_get_xqc(struct hisi_qm *qm, u8 cmd, void *xqc, u32 qp_id, bool op tmp_xqc = qm->xqc_buf.aeqc; xqc_dma = qm->xqc_buf.aeqc_dma;break ; +default : +dev_err (&qm->pdev->dev,"unknown mailbox cmd %u\n" , cmd); +return -EINVAL ; }/* Setting xqc will fail if master OOO is blocked. */
Signature · 1 line
2.30.0
Chenghai Huang
maintainerPATCH v2 6/9 crypto: hisilicon - Adjust debugfs creation and release order
In reply to Chenghai HuangThere is a scenario where the file directory is created but the file memory is not set. In this case, if a user accesses the file, an error occurs.
So during the creation process of debugfs, memory should be allocated first before creating the directory. In the release process, the directory should be deleted first before releasing the memory to avoid the situation where the memory does not exist when accessing the directory.
In addition, the directory released by the debugfs is a global variable. When the debugfs of an accelerator fails to be initialized, releasing the directory of the global variable affects the debugfs initialization of other accelerators. The debugfs root directory released by debugfs init should be a member of qm, not a global variable.
--- drivers/crypto/hisilicon/hpre/hpre_main.c | 21 ++++++++++---------- drivers/crypto/hisilicon/sec2/sec_main.c | 23 +++++++++++----------- drivers/crypto/hisilicon/zip/zip_main.c | 24 +++++++++++------------ 3 files changed, 32 insertions(+), 36 deletions(-)
drivers/crypto/hisilicon/hpre/hpre_main.c +10 -11
@@ -1074,41 +1074,40 @@ static int hpre_debugfs_init(struct hisi_qm *qm)struct device *dev = &qm->pdev->dev;int ret; - qm->debug.debug_root =debugfs_create_dir (dev_name (dev), - hpre_debugfs_root); - - qm->debug.sqe_mask_offset =HPRE_SQE_MASK_OFFSET ; - qm->debug.sqe_mask_len =HPRE_SQE_MASK_LEN ; ret =hisi_qm_regs_debugfs_init (qm, hpre_diff_regs,ARRAY_SIZE (hpre_diff_regs));if (ret) {dev_warn (dev,"Failed to init HPRE diff regs!\n" ); - goto debugfs_remove; +return ret; } + qm->debug.debug_root =debugfs_create_dir (dev_name (dev), + hpre_debugfs_root); + qm->debug.sqe_mask_offset =HPRE_SQE_MASK_OFFSET ; + qm->debug.sqe_mask_len =HPRE_SQE_MASK_LEN ; +hisi_qm_debug_init (qm);if (qm->pdev->device ==PCI_DEVICE_ID_HUAWEI_HPRE_PF ) { ret =hpre_ctrl_debug_init (qm);if (ret) - goto failed_to_create; + goto debugfs_remove; }hpre_dfx_debug_init (qm);return 0 ; -failed_to_create: -hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (hpre_diff_regs)); debugfs_remove:debugfs_remove_recursive (qm->debug.debug_root); +hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (hpre_diff_regs));return ret; }static void hpre_debugfs_exit (struct hisi_qm *qm) { -hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (hpre_diff_regs)); -debugfs_remove_recursive (qm->debug.debug_root); + +hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (hpre_diff_regs)); }static int hpre_pre_store_cap_reg (struct hisi_qm *qm)
drivers/crypto/hisilicon/sec2/sec_main.c +11 -12
@@ -901,37 +901,36 @@ static int sec_debugfs_init(struct hisi_qm *qm)struct device *dev = &qm->pdev->dev;int ret; - qm->debug.debug_root =debugfs_create_dir (dev_name (dev), - sec_debugfs_root); - qm->debug.sqe_mask_offset =SEC_SQE_MASK_OFFSET ; - qm->debug.sqe_mask_len =SEC_SQE_MASK_LEN ; - ret =hisi_qm_regs_debugfs_init (qm, sec_diff_regs,ARRAY_SIZE (sec_diff_regs));if (ret) {dev_warn (dev,"Failed to init SEC diff regs!\n" ); - goto debugfs_remove; +return ret; } + qm->debug.debug_root =debugfs_create_dir (dev_name (dev), + sec_debugfs_root); + qm->debug.sqe_mask_offset =SEC_SQE_MASK_OFFSET ; + qm->debug.sqe_mask_len =SEC_SQE_MASK_LEN ; +hisi_qm_debug_init (qm); ret =sec_debug_init (qm);if (ret) - goto failed_to_create; + goto debugfs_remove;return 0 ; -failed_to_create: -hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (sec_diff_regs)); debugfs_remove: -debugfs_remove_recursive (sec_debugfs_root); +debugfs_remove_recursive (qm->debug.debug_root); +hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (sec_diff_regs));return ret; }static void sec_debugfs_exit (struct hisi_qm *qm) { -hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (sec_diff_regs)); -debugfs_remove_recursive (qm->debug.debug_root); + +hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (sec_diff_regs)); }static int sec_show_last_regs_init (struct hisi_qm *qm)
drivers/crypto/hisilicon/zip/zip_main.c +11 -13
@@ -886,36 +886,34 @@ static int hisi_zip_ctrl_debug_init(struct hisi_qm *qm)static int hisi_zip_debugfs_init (struct hisi_qm *qm) {struct device *dev = &qm->pdev->dev; -struct dentry *dev_d;int ret; - dev_d =debugfs_create_dir (dev_name (dev), hzip_debugfs_root); - - qm->debug.sqe_mask_offset =HZIP_SQE_MASK_OFFSET ; - qm->debug.sqe_mask_len =HZIP_SQE_MASK_LEN ; - qm->debug.debug_root = dev_d; ret =hisi_qm_regs_debugfs_init (qm, hzip_diff_regs,ARRAY_SIZE (hzip_diff_regs));if (ret) {dev_warn (dev,"Failed to init ZIP diff regs!\n" ); - goto debugfs_remove; +return ret; } + qm->debug.sqe_mask_offset =HZIP_SQE_MASK_OFFSET ; + qm->debug.sqe_mask_len =HZIP_SQE_MASK_LEN ; + qm->debug.debug_root =debugfs_create_dir (dev_name (dev), + hzip_debugfs_root); +hisi_qm_debug_init (qm);if (qm->fun_type ==QM_HW_PF ) { ret =hisi_zip_ctrl_debug_init (qm);if (ret) - goto failed_to_create; + goto debugfs_remove; }hisi_zip_dfx_debug_init (qm);return 0 ; -failed_to_create: -hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (hzip_diff_regs)); debugfs_remove: -debugfs_remove_recursive (hzip_debugfs_root); +debugfs_remove_recursive (qm->debug.debug_root); +hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (hzip_diff_regs));return ret; }
@@ -939,10 +937,10 @@ static void hisi_zip_debug_regs_clear(struct hisi_qm *qm)static void hisi_zip_debugfs_exit (struct hisi_qm *qm) { -hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (hzip_diff_regs)); -debugfs_remove_recursive (qm->debug.debug_root); +hisi_qm_regs_debugfs_uninit (qm,ARRAY_SIZE (hzip_diff_regs)); +if (qm->fun_type ==QM_HW_PF ) {hisi_zip_debug_regs_clear (qm); qm->debug.curr_qm_qp_num =0 ;
Signature · 1 line
2.30.0
Chenghai Huang
maintainerPATCH v2 7/9 crypto: hisilicon/sec - Fix memory leak for sec resource release
In reply to Chenghai HuangThe AIV is one of the SEC resources. When releasing resources, it need to release the AIV resources at the same time. Otherwise, memory leakage occurs.
The aiv resource release is added to the sec resource release function.
--- drivers/crypto/hisilicon/sec2/sec_crypto.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/crypto/hisilicon/sec2/sec_crypto.c +3 -1
@@ -481,8 +481,10 @@ static void sec_alg_resource_free(struct sec_ctx *ctx,if (ctx->pbuf_supported)sec_free_pbuf_resource (dev, qp_ctx->res); -if (ctx->alg_type ==SEC_AEAD ) +if (ctx->alg_type ==SEC_AEAD ) {sec_free_mac_resource (dev, qp_ctx->res); +sec_free_aiv_resource (dev, qp_ctx->res); + } }static int sec_alloc_qp_ctx_resource (struct sec_ctx *ctx,struct sec_qp_ctx *qp_ctx)
Signature · 1 line
2.30.0
Chenghai Huang
maintainerPATCH v2 8/9 crypto: hisilicon/debugfs - Resolve the problem of applying for redundant space in sq dump
In reply to Chenghai HuangWhen dumping SQ, only the corresponding ID's SQE needs to be dumped, and there is no need to apply for the entire SQE memory. This is because excessive dump operations can lead to memory resource waste.
Therefor apply for the space corresponding to sqe_id separately to avoid space waste.
---
v1 -> v2
- fixed codecheck warnings about unused variable
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
--- drivers/crypto/hisilicon/debugfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/crypto/hisilicon/debugfs.c +5 -6
@@ -311,7 +311,7 @@ static int q_dump_param_parse(struct hisi_qm *qm, char *s,static int qm_sq_dump (struct hisi_qm *qm,char *s,char *name) {u16 sq_depth = qm->qp_array->cq_depth; -void *sqe, *sqe_curr; +void *sqe;struct hisi_qp *qp;u32 qp_id, sqe_id;int ret;
@@ -320,17 +320,16 @@ static int qm_sq_dump(struct hisi_qm *qm, char *s, char *name)if (ret)return ret; - sqe =kzalloc (qm->sqe_size * sq_depth,GFP_KERNEL ); + sqe =kzalloc (qm->sqe_size,GFP_KERNEL );if (!sqe)return -ENOMEM ; qp = &qm->qp_array[qp_id]; -memcpy (sqe, qp->sqe, qm->sqe_size * sq_depth); - sqe_curr = sqe + (u32)(sqe_id * qm->sqe_size); -memset (sqe_curr + qm->debug.sqe_mask_offset,QM_SQE_ADDR_MASK , +memcpy (sqe, qp->sqe + sqe_id * qm->sqe_size, qm->sqe_size); +memset (sqe + qm->debug.sqe_mask_offset,QM_SQE_ADDR_MASK , qm->debug.sqe_mask_len); -dump_show (qm, sqe_curr, qm->sqe_size, name); +dump_show (qm, sqe, qm->sqe_size, name);kfree (sqe);
Signature · 1 line
2.30.0
Chenghai Huang
maintainerPATCH v2 9/9 crypto: hisilicon/qm - Add the err memory release process to qm uninit
In reply to Chenghai HuangWhen the qm uninit command is executed, the err data needs to be released to prevent memory leakage. The error information release operation and uacce_remove are integrated in qm_remove_uacce.
So add the qm_remove_uacce to qm uninit to avoid err memory leakage.
--- drivers/crypto/hisilicon/qm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/crypto/hisilicon/qm.c +1 -4
@@ -2896,12 +2896,9 @@ void hisi_qm_uninit(struct hisi_qm *qm)hisi_qm_set_state (qm,QM_NOT_READY );up_write (&qm->qps_lock); +qm_remove_uacce (qm);qm_irqs_unregister (qm);hisi_qm_pci_uninit (qm); -if (qm->use_sva) { -uacce_remove (qm->uacce); - qm->uacce =NULL ; - } }EXPORT_SYMBOL_GPL (hisi_qm_uninit);
Signature · 1 line
2.30.0
Herbert Xu
maintainerQuoted 22 lines · Chenghai Huang
This patch series is mainly used to fix and optimize some problems of hisilicon.
v1 -> v2
- fixed codecheck warnings about unused variable
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/Chenghai Huang (9):
crypto: hisilicon/sec - Add the condition for configuring the sriov
function
crypto: hisilicon/debugfs - Fix debugfs uninit process issue
crypto: hisilicon/sgl - Delete redundant parameter verification
crypto: hisilicon/debugfs - Fix the processing logic issue in the
debugfs creation
crypto: hisilicon/qm - Add the default processing branch
crypto: hisilicon - Adjust debugfs creation and release order
crypto: hisilicon/sec - Fix memory leak for sec resource release
crypto: hisilicon/debugfs - Resolve the problem of applying for
redundant space in sq dump
crypto: hisilicon/qm - Add the err memory release process to qm uninit
Quoted 11 lines
drivers/crypto/hisilicon/debugfs.c | 38 +++++++++++++++------- drivers/crypto/hisilicon/hpre/hpre_main.c | 21 ++++++------ drivers/crypto/hisilicon/qm.c | 8 ++--- drivers/crypto/hisilicon/sec2/sec_crypto.c | 4 ++- drivers/crypto/hisilicon/sec2/sec_main.c | 26 +++++++-------- drivers/crypto/hisilicon/sgl.c | 5 +-- drivers/crypto/hisilicon/zip/zip_main.c | 24 +++++++------- 7 files changed, 68 insertions(+), 58 deletions(-)Signature · 1 line
2.30.0
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt