From: JiangShui Yang yangjiangshui@h-partners.com
driver inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I94L2V CVE: NA
----------------------------------------------------------------------
Added the function is_iommu_used() for obtaining the IOMMU type in qm.c. Driver checks the IOMMU type before registering to the UACCE subsystem. If the IOMMU is disabled, the device does not register to the UACCE subsystem in SVA mode.
In addition, the function sec_iommu_used_check() in sec_main.c for obtaining the IOMMU type is deleted to avoid repeated function.
Signed-off-by: JiangShui Yang yangjiangshui@h-partners.com Signed-off-by: Weili Qian qianweili@huawei.com --- drivers/crypto/hisilicon/qm.c | 16 ++++++++++++++++ drivers/crypto/hisilicon/sec2/sec_crypto.c | 2 +- drivers/crypto/hisilicon/sec2/sec_main.c | 18 ------------------ include/linux/hisi_acc_qm.h | 1 + 4 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 92f0a1d9b4a6..543074742db5 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -6,6 +6,7 @@ #include <linux/dma-mapping.h> #include <linux/idr.h> #include <linux/io.h> +#include <linux/iommu.h> #include <linux/irqreturn.h> #include <linux/log2.h> #include <linux/pm_runtime.h> @@ -2771,6 +2772,20 @@ static int hisi_qp_memory_init(struct hisi_qm *qm, size_t dma_size, int id, return ret; }
+static inline bool is_iommu_used(struct device *dev) +{ + struct iommu_domain *domain; + + domain = iommu_get_domain_for_dev(dev); + if (domain) { + dev_info(dev, "iommu domain type = %u\n", domain->type); + if (domain->type & __IOMMU_DOMAIN_PAGING) + return true; + } + + return false; +} + static void hisi_qm_pre_init(struct hisi_qm *qm) { struct pci_dev *pdev = qm->pdev; @@ -2786,6 +2801,7 @@ static void hisi_qm_pre_init(struct hisi_qm *qm) mutex_init(&qm->mailbox_lock); init_rwsem(&qm->qps_lock); qm->qp_in_used = 0; + qm->use_iommu = is_iommu_used(&pdev->dev); if (test_bit(QM_SUPPORT_RPM, &qm->caps)) { if (!acpi_device_power_manageable(ACPI_COMPANION(&pdev->dev))) dev_info(&pdev->dev, "_PS0 and _PR0 are not defined"); diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c index 93a972fcbf63..a2fd43f2e883 100644 --- a/drivers/crypto/hisilicon/sec2/sec_crypto.c +++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c @@ -600,7 +600,7 @@ static int sec_ctx_base_init(struct sec_ctx *ctx) ctx->dev = &sec->qm.pdev->dev; ctx->hlf_q_num = sec->ctx_q_num >> 1;
- ctx->pbuf_supported = ctx->sec->iommu_used; + ctx->pbuf_supported = sec->qm.use_iommu;
/* Half of queue depth is taken as fake requests limit in the queue. */ ctx->fake_req_limit = ctx->qps[0]->sq_depth >> 1; diff --git a/drivers/crypto/hisilicon/sec2/sec_main.c b/drivers/crypto/hisilicon/sec2/sec_main.c index c290d8937b19..377c58bef466 100644 --- a/drivers/crypto/hisilicon/sec2/sec_main.c +++ b/drivers/crypto/hisilicon/sec2/sec_main.c @@ -1190,23 +1190,6 @@ static void sec_probe_uninit(struct hisi_qm *qm) hisi_qm_dev_err_uninit(qm); }
-static void sec_iommu_used_check(struct sec_dev *sec) -{ - struct iommu_domain *domain; - struct device *dev = &sec->qm.pdev->dev; - - domain = iommu_get_domain_for_dev(dev); - - /* Check if iommu is used */ - sec->iommu_used = false; - if (domain) { - if (domain->type & __IOMMU_DOMAIN_PAGING) - sec->iommu_used = true; - dev_info(dev, "SMMU Opened, the iommu type = %u\n", - domain->type); - } -} - static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct sec_dev *sec; @@ -1225,7 +1208,6 @@ static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id) }
sec->ctx_q_num = ctx_q_num; - sec_iommu_used_check(sec);
ret = sec_probe_init(sec); if (ret) { diff --git a/include/linux/hisi_acc_qm.h b/include/linux/hisi_acc_qm.h index 9d7754ad5e9b..773e0f1c67dc 100644 --- a/include/linux/hisi_acc_qm.h +++ b/include/linux/hisi_acc_qm.h @@ -385,6 +385,7 @@ struct hisi_qm { struct work_struct cmd_process;
bool use_sva; + bool use_iommu;
resource_size_t phys_base; resource_size_t db_phys_base;