All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] crypto: qat - fix firmware loader
@ 2021-05-17  9:13 Jack Xu
  2021-05-17  9:13 ` [PATCH 1/5] crypto: qat - return error when failing to map FW Jack Xu
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Jack Xu @ 2021-05-17  9:13 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, qat-linux, Jack Xu

This patchset is to fix some issues in the QAT firmware loader:
* Patches #1 to #3, check the MMP binary size and return error if too large
* Patch #4 fixes a problem detected by clang static
* Patch #5 fixes a compiling warnings when building with clang


Jack Xu (5):
  crypto: qat - return error when failing to map FW
  crypto: qat - check MMP size before writing to the SRAM
  crypto: qat - report an error if MMP file size is too large
  crypto: qat - check return code of qat_hal_rd_rel_reg()
  crypto: qat - remove unused macro in FW loader

 .../qat/qat_common/icp_qat_fw_loader_handle.h      |  2 +-
 drivers/crypto/qat/qat_common/qat_hal.c            | 14 +++++++++-----
 drivers/crypto/qat/qat_common/qat_uclo.c           | 12 +++++-------
 3 files changed, 15 insertions(+), 13 deletions(-)

-- 
2.31.1


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

* [PATCH 1/5] crypto: qat - return error when failing to map FW
  2021-05-17  9:13 [PATCH 0/5] crypto: qat - fix firmware loader Jack Xu
@ 2021-05-17  9:13 ` Jack Xu
  2021-05-17  9:13 ` [PATCH 2/5] crypto: qat - check MMP size before writing to the SRAM Jack Xu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jack Xu @ 2021-05-17  9:13 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, qat-linux, Jack Xu, Zhehui Xiang, Giovanni Cabiddu

Save the return value of qat_uclo_map_auth_fw() function so that the
function qat_uclo_wr_mimage() could return the correct value.
This way, the procedure of adf_gen2_ae_fw_load() function could stop
and exit properly by checking the return value of qat_uclo_wr_mimage().

Signed-off-by: Jack Xu <jack.xu@intel.com>
Co-developed-by: Zhehui Xiang <zhehui.xiang@intel.com>
Signed-off-by: Zhehui Xiang <zhehui.xiang@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
---
 drivers/crypto/qat/qat_common/qat_uclo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/qat/qat_common/qat_uclo.c b/drivers/crypto/qat/qat_common/qat_uclo.c
index 1fb5fc852f6b..d2c2db58c93f 100644
--- a/drivers/crypto/qat/qat_common/qat_uclo.c
+++ b/drivers/crypto/qat/qat_common/qat_uclo.c
@@ -1546,7 +1546,8 @@ int qat_uclo_wr_mimage(struct icp_qat_fw_loader_handle *handle,
 	int status = 0;
 
 	if (handle->chip_info->fw_auth) {
-		if (!qat_uclo_map_auth_fw(handle, addr_ptr, mem_size, &desc))
+		status = qat_uclo_map_auth_fw(handle, addr_ptr, mem_size, &desc);
+		if (!status)
 			status = qat_uclo_auth_fw(handle, desc);
 		qat_uclo_ummap_auth_fw(handle, &desc);
 	} else {
-- 
2.31.1


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

* [PATCH 2/5] crypto: qat - check MMP size before writing to the SRAM
  2021-05-17  9:13 [PATCH 0/5] crypto: qat - fix firmware loader Jack Xu
  2021-05-17  9:13 ` [PATCH 1/5] crypto: qat - return error when failing to map FW Jack Xu
@ 2021-05-17  9:13 ` Jack Xu
  2021-05-17  9:13 ` [PATCH 3/5] crypto: qat - report an error if MMP file size is too large Jack Xu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jack Xu @ 2021-05-17  9:13 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, qat-linux, Jack Xu, Zhehui Xiang, Giovanni Cabiddu

Change "sram_visible" to "mmp_sram_size" and compare it with the MMP
size to prevent an overly large MMP file being written to SRAM.

Signed-off-by: Jack Xu <jack.xu@intel.com>
Co-developed-by: Zhehui Xiang <zhehui.xiang@intel.com>
Signed-off-by: Zhehui Xiang <zhehui.xiang@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
---
 drivers/crypto/qat/qat_common/icp_qat_fw_loader_handle.h | 2 +-
 drivers/crypto/qat/qat_common/qat_hal.c                  | 8 ++++----
 drivers/crypto/qat/qat_common/qat_uclo.c                 | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/qat/qat_common/icp_qat_fw_loader_handle.h b/drivers/crypto/qat/qat_common/icp_qat_fw_loader_handle.h
index b8f3463be6ef..7eb5daef4f88 100644
--- a/drivers/crypto/qat/qat_common/icp_qat_fw_loader_handle.h
+++ b/drivers/crypto/qat/qat_common/icp_qat_fw_loader_handle.h
@@ -24,7 +24,7 @@ struct icp_qat_fw_loader_hal_handle {
 };
 
 struct icp_qat_fw_loader_chip_info {
-	bool sram_visible;
+	int mmp_sram_size;
 	bool nn;
 	bool lm2lm3;
 	u32 lm_size;
diff --git a/drivers/crypto/qat/qat_common/qat_hal.c b/drivers/crypto/qat/qat_common/qat_hal.c
index bd3028126cbe..ed9b81347144 100644
--- a/drivers/crypto/qat/qat_common/qat_hal.c
+++ b/drivers/crypto/qat/qat_common/qat_hal.c
@@ -696,7 +696,7 @@ static int qat_hal_chip_init(struct icp_qat_fw_loader_handle *handle,
 	handle->pci_dev = pci_info->pci_dev;
 	switch (handle->pci_dev->device) {
 	case ADF_4XXX_PCI_DEVICE_ID:
-		handle->chip_info->sram_visible = false;
+		handle->chip_info->mmp_sram_size = 0;
 		handle->chip_info->nn = false;
 		handle->chip_info->lm2lm3 = true;
 		handle->chip_info->lm_size = ICP_QAT_UCLO_MAX_LMEM_REG_2X;
@@ -730,7 +730,7 @@ static int qat_hal_chip_init(struct icp_qat_fw_loader_handle *handle,
 		break;
 	case PCI_DEVICE_ID_INTEL_QAT_C62X:
 	case PCI_DEVICE_ID_INTEL_QAT_C3XXX:
-		handle->chip_info->sram_visible = false;
+		handle->chip_info->mmp_sram_size = 0;
 		handle->chip_info->nn = true;
 		handle->chip_info->lm2lm3 = false;
 		handle->chip_info->lm_size = ICP_QAT_UCLO_MAX_LMEM_REG;
@@ -763,7 +763,7 @@ static int qat_hal_chip_init(struct icp_qat_fw_loader_handle *handle,
 			+ LOCAL_TO_XFER_REG_OFFSET);
 		break;
 	case PCI_DEVICE_ID_INTEL_QAT_DH895XCC:
-		handle->chip_info->sram_visible = true;
+		handle->chip_info->mmp_sram_size = 0x40000;
 		handle->chip_info->nn = true;
 		handle->chip_info->lm2lm3 = false;
 		handle->chip_info->lm_size = ICP_QAT_UCLO_MAX_LMEM_REG;
@@ -800,7 +800,7 @@ static int qat_hal_chip_init(struct icp_qat_fw_loader_handle *handle,
 		goto out_err;
 	}
 
-	if (handle->chip_info->sram_visible) {
+	if (handle->chip_info->mmp_sram_size > 0) {
 		sram_bar =
 			&pci_info->pci_bars[hw_data->get_sram_bar_id(hw_data)];
 		handle->hal_sram_addr_v = sram_bar->virt_addr;
diff --git a/drivers/crypto/qat/qat_common/qat_uclo.c b/drivers/crypto/qat/qat_common/qat_uclo.c
index d2c2db58c93f..8adf25769128 100644
--- a/drivers/crypto/qat/qat_common/qat_uclo.c
+++ b/drivers/crypto/qat/qat_common/qat_uclo.c
@@ -1551,7 +1551,7 @@ int qat_uclo_wr_mimage(struct icp_qat_fw_loader_handle *handle,
 			status = qat_uclo_auth_fw(handle, desc);
 		qat_uclo_ummap_auth_fw(handle, &desc);
 	} else {
-		if (!handle->chip_info->sram_visible) {
+		if (handle->chip_info->mmp_sram_size < mem_size) {
 			dev_dbg(&handle->pci_dev->dev,
 				"QAT MMP fw not loaded for device 0x%x",
 				handle->pci_dev->device);
-- 
2.31.1


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

* [PATCH 3/5] crypto: qat - report an error if MMP file size is too large
  2021-05-17  9:13 [PATCH 0/5] crypto: qat - fix firmware loader Jack Xu
  2021-05-17  9:13 ` [PATCH 1/5] crypto: qat - return error when failing to map FW Jack Xu
  2021-05-17  9:13 ` [PATCH 2/5] crypto: qat - check MMP size before writing to the SRAM Jack Xu
@ 2021-05-17  9:13 ` Jack Xu
  2021-05-17  9:13 ` [PATCH 4/5] crypto: qat - check return code of qat_hal_rd_rel_reg() Jack Xu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jack Xu @ 2021-05-17  9:13 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, qat-linux, Jack Xu, Zhehui Xiang, Giovanni Cabiddu

Change the return status to error if MMP file size is too large so the
driver load fails early if a large MMP firmware is loaded.

Signed-off-by: Jack Xu <jack.xu@intel.com>
Co-developed-by: Zhehui Xiang <zhehui.xiang@intel.com>
Signed-off-by: Zhehui Xiang <zhehui.xiang@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
---
 drivers/crypto/qat/qat_common/qat_uclo.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/qat/qat_common/qat_uclo.c b/drivers/crypto/qat/qat_common/qat_uclo.c
index 8adf25769128..ed1343bb36ac 100644
--- a/drivers/crypto/qat/qat_common/qat_uclo.c
+++ b/drivers/crypto/qat/qat_common/qat_uclo.c
@@ -1552,10 +1552,8 @@ int qat_uclo_wr_mimage(struct icp_qat_fw_loader_handle *handle,
 		qat_uclo_ummap_auth_fw(handle, &desc);
 	} else {
 		if (handle->chip_info->mmp_sram_size < mem_size) {
-			dev_dbg(&handle->pci_dev->dev,
-				"QAT MMP fw not loaded for device 0x%x",
-				handle->pci_dev->device);
-			return status;
+			pr_err("QAT: MMP size is too large: 0x%x\n", mem_size);
+			return -EFBIG;
 		}
 		qat_uclo_wr_sram_by_words(handle, 0, addr_ptr, mem_size);
 	}
-- 
2.31.1


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

* [PATCH 4/5] crypto: qat - check return code of qat_hal_rd_rel_reg()
  2021-05-17  9:13 [PATCH 0/5] crypto: qat - fix firmware loader Jack Xu
                   ` (2 preceding siblings ...)
  2021-05-17  9:13 ` [PATCH 3/5] crypto: qat - report an error if MMP file size is too large Jack Xu
@ 2021-05-17  9:13 ` Jack Xu
  2021-05-17  9:13 ` [PATCH 5/5] crypto: qat - remove unused macro in FW loader Jack Xu
  2021-05-28  7:24 ` [PATCH 0/5] crypto: qat - fix firmware loader Herbert Xu
  5 siblings, 0 replies; 7+ messages in thread
From: Jack Xu @ 2021-05-17  9:13 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, qat-linux, Jack Xu, Zhehui Xiang, Giovanni Cabiddu

Check the return code of the function qat_hal_rd_rel_reg() and return it
to the caller.

This is to fix the following warning when compiling the driver with
clang scan-build:

    drivers/crypto/qat/qat_common/qat_hal.c:1436:2: warning: 6th function call argument is an uninitialized value

Signed-off-by: Jack Xu <jack.xu@intel.com>
Co-developed-by: Zhehui Xiang <zhehui.xiang@intel.com>
Signed-off-by: Zhehui Xiang <zhehui.xiang@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
---
 drivers/crypto/qat/qat_common/qat_hal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/qat/qat_common/qat_hal.c b/drivers/crypto/qat/qat_common/qat_hal.c
index ed9b81347144..12ca6b8764aa 100644
--- a/drivers/crypto/qat/qat_common/qat_hal.c
+++ b/drivers/crypto/qat/qat_common/qat_hal.c
@@ -1417,7 +1417,11 @@ static int qat_hal_put_rel_wr_xfer(struct icp_qat_fw_loader_handle *handle,
 		pr_err("QAT: bad xfrAddr=0x%x\n", xfr_addr);
 		return -EINVAL;
 	}
-	qat_hal_rd_rel_reg(handle, ae, ctx, ICP_GPB_REL, gprnum, &gprval);
+	status = qat_hal_rd_rel_reg(handle, ae, ctx, ICP_GPB_REL, gprnum, &gprval);
+	if (status) {
+		pr_err("QAT: failed to read register");
+		return status;
+	}
 	gpr_addr = qat_hal_get_reg_addr(ICP_GPB_REL, gprnum);
 	data16low = 0xffff & data;
 	data16hi = 0xffff & (data >> 0x10);
-- 
2.31.1


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

* [PATCH 5/5] crypto: qat - remove unused macro in FW loader
  2021-05-17  9:13 [PATCH 0/5] crypto: qat - fix firmware loader Jack Xu
                   ` (3 preceding siblings ...)
  2021-05-17  9:13 ` [PATCH 4/5] crypto: qat - check return code of qat_hal_rd_rel_reg() Jack Xu
@ 2021-05-17  9:13 ` Jack Xu
  2021-05-28  7:24 ` [PATCH 0/5] crypto: qat - fix firmware loader Herbert Xu
  5 siblings, 0 replies; 7+ messages in thread
From: Jack Xu @ 2021-05-17  9:13 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, qat-linux, Jack Xu, Zhehui Xiang, Giovanni Cabiddu

Remove the unused macro ICP_DH895XCC_PESRAM_BAR_SIZE in the firmware
loader.

This is to fix the following warning when compiling the driver using the
clang compiler with CC=clang W=2:

    drivers/crypto/qat/qat_common/qat_uclo.c:345:9: warning: macro is not used [-Wunused-macros]

Signed-off-by: Jack Xu <jack.xu@intel.com>
Co-developed-by: Zhehui Xiang <zhehui.xiang@intel.com>
Signed-off-by: Zhehui Xiang <zhehui.xiang@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
---
 drivers/crypto/qat/qat_common/qat_uclo.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/crypto/qat/qat_common/qat_uclo.c b/drivers/crypto/qat/qat_common/qat_uclo.c
index ed1343bb36ac..2026cc6be8f0 100644
--- a/drivers/crypto/qat/qat_common/qat_uclo.c
+++ b/drivers/crypto/qat/qat_common/qat_uclo.c
@@ -342,7 +342,6 @@ static int qat_uclo_init_umem_seg(struct icp_qat_fw_loader_handle *handle,
 	return 0;
 }
 
-#define ICP_DH895XCC_PESRAM_BAR_SIZE 0x80000
 static int qat_uclo_init_ae_memory(struct icp_qat_fw_loader_handle *handle,
 				   struct icp_qat_uof_initmem *init_mem)
 {
-- 
2.31.1


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

* Re: [PATCH 0/5] crypto: qat - fix firmware loader
  2021-05-17  9:13 [PATCH 0/5] crypto: qat - fix firmware loader Jack Xu
                   ` (4 preceding siblings ...)
  2021-05-17  9:13 ` [PATCH 5/5] crypto: qat - remove unused macro in FW loader Jack Xu
@ 2021-05-28  7:24 ` Herbert Xu
  5 siblings, 0 replies; 7+ messages in thread
From: Herbert Xu @ 2021-05-28  7:24 UTC (permalink / raw)
  To: Jack Xu; +Cc: linux-crypto, qat-linux

On Mon, May 17, 2021 at 05:13:11AM -0400, Jack Xu wrote:
> This patchset is to fix some issues in the QAT firmware loader:
> * Patches #1 to #3, check the MMP binary size and return error if too large
> * Patch #4 fixes a problem detected by clang static
> * Patch #5 fixes a compiling warnings when building with clang
> 
> 
> Jack Xu (5):
>   crypto: qat - return error when failing to map FW
>   crypto: qat - check MMP size before writing to the SRAM
>   crypto: qat - report an error if MMP file size is too large
>   crypto: qat - check return code of qat_hal_rd_rel_reg()
>   crypto: qat - remove unused macro in FW loader
> 
>  .../qat/qat_common/icp_qat_fw_loader_handle.h      |  2 +-
>  drivers/crypto/qat/qat_common/qat_hal.c            | 14 +++++++++-----
>  drivers/crypto/qat/qat_common/qat_uclo.c           | 12 +++++-------
>  3 files changed, 15 insertions(+), 13 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] 7+ messages in thread

end of thread, other threads:[~2021-05-28  7:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17  9:13 [PATCH 0/5] crypto: qat - fix firmware loader Jack Xu
2021-05-17  9:13 ` [PATCH 1/5] crypto: qat - return error when failing to map FW Jack Xu
2021-05-17  9:13 ` [PATCH 2/5] crypto: qat - check MMP size before writing to the SRAM Jack Xu
2021-05-17  9:13 ` [PATCH 3/5] crypto: qat - report an error if MMP file size is too large Jack Xu
2021-05-17  9:13 ` [PATCH 4/5] crypto: qat - check return code of qat_hal_rd_rel_reg() Jack Xu
2021-05-17  9:13 ` [PATCH 5/5] crypto: qat - remove unused macro in FW loader Jack Xu
2021-05-28  7:24 ` [PATCH 0/5] crypto: qat - fix firmware loader Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.