From 4591e90997765fb9eaa5a382cfc49061a82cac1f Mon Sep 17 00:00:00 2001 From: Weili Qian Date: Mon, 5 Jun 2023 11:05:54 +0800 Subject: [PATCH 1/4] crypto: hisilicon/qm - prevent soft lockup in qm_poll_req_cb()'s loop driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I7AUVE CVE: NA ---------------------------------------------------------------------- The function qm_poll_req_cb() may take a while due to complex req_cb, so soft lockup may occur in kernel with preemption disabled. Add a cond_resched() to prevent that. Signed-off-by: Weili Qian Signed-off-by: JiangShui Yang (cherry picked from commit d07dbb660520043737e001bf0b8e3fa7bddb2a93) --- drivers/crypto/hisilicon/qm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 28ce6ac69d4e..e5819d79bac8 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -869,6 +869,8 @@ static void qm_poll_req_cb(struct hisi_qp *qp) qm_db(qm, qp->qp_id, QM_DOORBELL_CMD_CQ, qp->qp_status.cq_head, 0); atomic_dec(&qp->qp_status.used); + + cond_resched(); } /* set c_flag */ -- Gitee From 388ade40b1250e885fd6ceb2468a366d4d77030e Mon Sep 17 00:00:00 2001 From: Weili Qian Date: Mon, 5 Jun 2023 11:05:55 +0800 Subject: [PATCH 2/4] crypto: hisilicon/hpre - ensure private key less than n driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I7AUVE CVE: NA ---------------------------------------------------------------------- The private key of the curve key size generated by stdrng, which may not be less than n. So the private key with the curve key size minus 1 is generated to ensure that the private key is less than n. Signed-off-by: Weili Qian Signed-off-by: JiangShui Yang (cherry picked from commit 91c618f058168f43da759a7b141aa5ddd8307098) --- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/hisilicon/hpre/hpre_crypto.c b/drivers/crypto/hisilicon/hpre/hpre_crypto.c index 5f6d363c9435..b0a7eb3b6362 100644 --- a/drivers/crypto/hisilicon/hpre/hpre_crypto.c +++ b/drivers/crypto/hisilicon/hpre/hpre_crypto.c @@ -1382,9 +1382,9 @@ static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf, unsigned int len) { struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); + unsigned int sz, sz_shift, curve_sz; struct device *dev = ctx->dev; char key[HPRE_ECC_MAX_KSZ]; - unsigned int sz, sz_shift; struct ecdh params; int ret; @@ -1396,7 +1396,13 @@ static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf, /* Use stdrng to generate private key */ if (!params.key || !params.key_size) { params.key = key; - params.key_size = hpre_ecdh_get_curvesz(ctx->curve_id); + curve_sz = hpre_ecdh_get_curvesz(ctx->curve_id); + if (!curve_sz) { + dev_err(dev, "Invalid curve size!\n"); + return -EINVAL; + } + + params.key_size = curve_sz - 1; ret = ecdh_gen_privkey(ctx, ¶ms); if (ret) return ret; -- Gitee From b0620a52c4343201be2e9e5d5bfe7c60bbd80473 Mon Sep 17 00:00:00 2001 From: Weili Qian Date: Mon, 5 Jun 2023 11:05:56 +0800 Subject: [PATCH 3/4] crypto: hisilicon/qm - stop function and write data to memory driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I7AUVE CVE: NA ---------------------------------------------------------------------- Before the system is shutdown, the accelerator driver needs to stop the device and write data to the memory. This prevents the accelerator from accessing addresses and writing data to the memory after the memory is reclaimed by the system, causing device exceptions and generating NFE errors. Signed-off-by: Weili Qian Signed-off-by: JiangShui Yang (cherry picked from commit 23bdb7d8a3d24b6d02a84c1588127855ed587875) --- drivers/crypto/hisilicon/qm.c | 13 +++++++------ include/linux/hisi_acc_qm.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index e5819d79bac8..0a424aebbfed 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -1021,7 +1021,7 @@ static void qm_reset_function(struct hisi_qm *qm) return; } - ret = hisi_qm_stop(qm, QM_FLR); + ret = hisi_qm_stop(qm, QM_DOWN); if (ret) { dev_err(dev, "failed to stop qm when reset function\n"); goto clear_bit; @@ -3397,7 +3397,7 @@ int hisi_qm_stop(struct hisi_qm *qm, enum qm_stop_reason r) } if (qm->status.stop_reason == QM_SOFT_RESET || - qm->status.stop_reason == QM_FLR) { + qm->status.stop_reason == QM_DOWN) { hisi_qm_set_hw_reset(qm, QM_RESET_STOP_TX_OFFSET); ret = qm_stop_started_qp(qm); if (ret < 0) { @@ -4693,11 +4693,11 @@ void hisi_qm_reset_prepare(struct pci_dev *pdev) if (qm->fun_type == QM_HW_PF) qm_cmd_uninit(qm); - ret = qm_try_stop_vfs(qm, QM_PF_FLR_PREPARE, QM_FLR); + ret = qm_try_stop_vfs(qm, QM_PF_FLR_PREPARE, QM_DOWN); if (ret) pci_err(pdev, "failed to stop vfs by pf in FLR.\n"); - ret = hisi_qm_stop(qm, QM_FLR); + ret = hisi_qm_stop(qm, QM_DOWN); if (ret) { pci_err(pdev, "Failed to stop QM, ret = %d.\n", ret); hisi_qm_set_hw_reset(qm, QM_RESET_STOP_TX_OFFSET); @@ -4795,10 +4795,11 @@ void hisi_qm_dev_shutdown(struct pci_dev *pdev) struct hisi_qm *qm = pci_get_drvdata(pdev); int ret; - ret = hisi_qm_stop(qm, QM_NORMAL); + ret = hisi_qm_stop(qm, QM_DOWN); if (ret) dev_err(&pdev->dev, "Fail to stop qm in shutdown!\n"); + hisi_qm_cache_wb(qm); qm_remove_uacce(qm); } EXPORT_SYMBOL_GPL(hisi_qm_dev_shutdown); @@ -4963,7 +4964,7 @@ static void qm_handle_cmd_msg(struct hisi_qm *qm, u32 fun_num) cmd = msg & QM_MB_CMD_DATA_MASK; switch (cmd) { case QM_PF_FLR_PREPARE: - qm_pf_reset_vf_process(qm, QM_FLR); + qm_pf_reset_vf_process(qm, QM_DOWN); break; case QM_PF_SRST_PREPARE: qm_pf_reset_vf_process(qm, QM_SOFT_RESET); diff --git a/include/linux/hisi_acc_qm.h b/include/linux/hisi_acc_qm.h index 40420a4ef0ae..b434e4f6111c 100644 --- a/include/linux/hisi_acc_qm.h +++ b/include/linux/hisi_acc_qm.h @@ -105,7 +105,7 @@ enum qm_stop_reason { QM_NORMAL, QM_SOFT_RESET, - QM_FLR, + QM_DOWN, }; enum qm_state { -- Gitee From f366751c7811291e3a2b07deb5b1106bc0188ed0 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 5 Jun 2023 11:05:57 +0800 Subject: [PATCH 4/4] crypto: hisilicon/qm - remove unnecessary aer.h include driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I7AUVE CVE: NA ---------------------------------------------------------------------- is unused, so remove it. Signed-off-by: Bjorn Helgaas Cc: Weili Qian Cc: Zhou Wang Acked-by: Longfang Liu Signed-off-by: Herbert Xu Signed-off-by: JiangShui Yang (cherry picked from commit c23d385574896d889ed66e7aea3eb9861898f010) --- drivers/crypto/hisilicon/qm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 0a424aebbfed..443d1edc0de6 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -2,7 +2,6 @@ /* Copyright (c) 2019 HiSilicon Limited. */ #include #include -#include #include #include #include -- Gitee