Skip to contentSkip to conversation

RDMA/irdma: switch to using the crc32c library

PATCH Superseded Eric Biggers 2 participants 5 messages Feb 7, 2025 – Feb 10, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 RDMA/irdma: switch to using the crc32c library

From: Eric Biggers <[email protected]>

Now that the crc32c() library function directly takes advantage of architecture-specific optimizations, it is unnecessary to go through the crypto API. Just use crc32c(). This is much simpler, and it improves performance due to eliminating the crypto API overhead.

Note that for crc32c specifically, the correct replacement for crypto_shash_digest() is ~crc32c(~0, ...), since crypto_shash_digest() had before and after inversions built-in whereas crc32c() does not.

---

v2: Resent as standalone patch and improved the commit message.
No code changes.

 drivers/infiniband/hw/irdma/Kconfig |  1 +
 drivers/infiniband/hw/irdma/main.h  |  1 -
 drivers/infiniband/hw/irdma/osdep.h |  6 +---
 drivers/infiniband/hw/irdma/puda.c  | 19 +++++-------
 drivers/infiniband/hw/irdma/puda.h  |  5 +--
 drivers/infiniband/hw/irdma/utils.c | 47 ++---------------------------
 6 files changed, 12 insertions(+), 67 deletions(-)
drivers/infiniband/hw/irdma/Kconfig +1 -0
index b6f9c41bca51d..5f49a58590ed7 100644
@@ -5,8 +5,9 @@ config INFINIBAND_IRDMA
 	depends on IPV6 || !IPV6
 	depends on PCI
 	depends on ICE && I40E
 	select GENERIC_ALLOCATOR
 	select AUXILIARY_BUS
+	select CRC32
 	help
 	  This is an Intel(R) Ethernet Protocol Driver for RDMA driver
 	  that support E810 (iWARP/RoCE) and X722 (iWARP) network devices.
drivers/infiniband/hw/irdma/main.h +0 -1
index 9f0ed6e844711..0705ef3d72a93 100644
@@ -28,11 +28,10 @@
 #ifndef CONFIG_64BIT
 #include <linux/io-64-nonatomic-lo-hi.h>
 #endif
 #include <linux/auxiliary_bus.h>
 #include <linux/net/intel/iidc.h>
-#include <crypto/hash.h>
 #include <rdma/ib_smi.h>
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_pack.h>
 #include <rdma/rdma_cm.h>
 #include <rdma/iw_cm.h>
drivers/infiniband/hw/irdma/osdep.h +1 -5
index ddf02a462efa2..4b4f78288d12e 100644
@@ -4,11 +4,10 @@
 #define IRDMA_OSDEP_H
 
 #include <linux/pci.h>
 #include <linux/bitfield.h>
 #include <linux/net/intel/iidc.h>
-#include <crypto/hash.h>
 #include <rdma/ib_verbs.h>
 
 #define STATS_TIMER_DELAY	60000
 
 struct irdma_dma_info {
@@ -41,19 +40,16 @@ struct ib_device *to_ibdev(struct irdma_sc_dev *dev);
 void irdma_ieq_mpa_crc_ae(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp);
 enum irdma_status_code irdma_vf_wait_vchnl_resp(struct irdma_sc_dev *dev);
 bool irdma_vf_clear_to_send(struct irdma_sc_dev *dev);
 void irdma_add_dev_ref(struct irdma_sc_dev *dev);
 void irdma_put_dev_ref(struct irdma_sc_dev *dev);
-int irdma_ieq_check_mpacrc(struct shash_desc *desc, void *addr, u32 len,
-			   u32 val);
+int irdma_ieq_check_mpacrc(const void *addr, u32 len, u32 val);
 struct irdma_sc_qp *irdma_ieq_get_qp(struct irdma_sc_dev *dev,
 				     struct irdma_puda_buf *buf);
 void irdma_send_ieq_ack(struct irdma_sc_qp *qp);
 void irdma_ieq_update_tcpip_info(struct irdma_puda_buf *buf, u16 len,
 				 u32 seqnum);
-void irdma_free_hash_desc(struct shash_desc *hash_desc);
-int irdma_init_hash_desc(struct shash_desc **hash_desc);
 int irdma_puda_get_tcpip_info(struct irdma_puda_cmpl_info *info,
 			      struct irdma_puda_buf *buf);
 int irdma_cqp_sds_cmd(struct irdma_sc_dev *dev,
 		      struct irdma_update_sds_info *info);
 int irdma_cqp_manage_hmc_fcn_cmd(struct irdma_sc_dev *dev,
drivers/infiniband/hw/irdma/puda.c +7 -12
index 7e3f9bca2c235..694e5a9ed15d0 100644
@@ -921,12 +921,10 @@ void irdma_puda_dele_rsrc(struct irdma_sc_vsi *vsi, enum puda_rsrc_type type,
 		return;
 	}
 
 	switch (rsrc->cmpl) {
 	case PUDA_HASH_CRC_COMPLETE:
-		irdma_free_hash_desc(rsrc->hash_desc);
-		fallthrough;
 	case PUDA_QP_CREATED:
 		irdma_qp_rem_qos(&rsrc->qp);
 
 		if (!reset)
 			irdma_puda_free_qp(rsrc);
@@ -1093,19 +1091,16 @@ int irdma_puda_create_rsrc(struct irdma_sc_vsi *vsi,
 	ret = irdma_puda_replenish_rq(rsrc, true);
 	if (ret)
 		goto error;
 
 	if (info->type == IRDMA_PUDA_RSRC_TYPE_IEQ) {
-		if (!irdma_init_hash_desc(&rsrc->hash_desc)) {
-			rsrc->check_crc = true;
-			rsrc->cmpl = PUDA_HASH_CRC_COMPLETE;
-			ret = 0;
-		}
+		rsrc->check_crc = true;
+		rsrc->cmpl = PUDA_HASH_CRC_COMPLETE;
 	}
 
 	irdma_sc_ccq_arm(&rsrc->cq);
-	return ret;
+	return 0;
 
 error:
 	irdma_puda_dele_rsrc(vsi, info->type, false);
 
 	return ret;
@@ -1394,12 +1389,12 @@ static int irdma_ieq_handle_partial(struct irdma_puda_rsrc *ieq,
 	irdma_ieq_update_tcpip_info(txbuf, fpdu_len, seqnum);
 
 	crcptr = txbuf->data + fpdu_len - 4;
 	mpacrc = *(u32 *)crcptr;
 	if (ieq->check_crc) {
-		status = irdma_ieq_check_mpacrc(ieq->hash_desc, txbuf->data,
-						(fpdu_len - 4), mpacrc);
+		status = irdma_ieq_check_mpacrc(txbuf->data, fpdu_len - 4,
+						mpacrc);
 		if (status) {
 			ibdev_dbg(to_ibdev(ieq->dev), "IEQ: error bad crc\n");
 			goto error;
 		}
 	}
@@ -1463,12 +1458,12 @@ static int irdma_ieq_process_buf(struct irdma_puda_rsrc *ieq,
 			break;
 		}
 		crcptr = datap + fpdu_len - 4;
 		mpacrc = *(u32 *)crcptr;
 		if (ieq->check_crc)
-			ret = irdma_ieq_check_mpacrc(ieq->hash_desc, datap,
-						     fpdu_len - 4, mpacrc);
+			ret = irdma_ieq_check_mpacrc(datap, fpdu_len - 4,
+						     mpacrc);
 		if (ret) {
 			list_add(&buf->list, rxlist);
 			ibdev_dbg(to_ibdev(ieq->dev),
 				  "ERR: IRDMA_ERR_MPA_CRC\n");
 			return -EINVAL;
drivers/infiniband/hw/irdma/puda.h +1 -4
index bc6d9514c9c10..2fc638f2b1434 100644
@@ -117,11 +117,10 @@ struct irdma_puda_rsrc {
 	u64 *rq_wrid_array;
 	u32 compl_rxwqe_idx;
 	u32 rx_wqe_idx;
 	u32 rxq_invalid_cnt;
 	u32 tx_wqe_avail_cnt;
-	struct shash_desc *hash_desc;
 	struct list_head txpend;
 	struct list_head bufpool; /* free buffers pool list for recv and xmit */
 	u32 alloc_buf_count;
 	u32 avail_buf_count; /* snapshot of currently available buffers */
 	spinlock_t bufpool_lock;
@@ -161,14 +160,12 @@ int irdma_puda_poll_cmpl(struct irdma_sc_dev *dev, struct irdma_sc_cq *cq,
 
 struct irdma_sc_qp *irdma_ieq_get_qp(struct irdma_sc_dev *dev,
 				     struct irdma_puda_buf *buf);
 int irdma_puda_get_tcpip_info(struct irdma_puda_cmpl_info *info,
 			      struct irdma_puda_buf *buf);
-int irdma_ieq_check_mpacrc(struct shash_desc *desc, void *addr, u32 len, u32 val);
-int irdma_init_hash_desc(struct shash_desc **desc);
+int irdma_ieq_check_mpacrc(const void *addr, u32 len, u32 val);
 void irdma_ieq_mpa_crc_ae(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp);
-void irdma_free_hash_desc(struct shash_desc *desc);
 void irdma_ieq_update_tcpip_info(struct irdma_puda_buf *buf, u16 len, u32 seqnum);
 int irdma_cqp_qp_create_cmd(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp);
 int irdma_cqp_cq_create_cmd(struct irdma_sc_dev *dev, struct irdma_sc_cq *cq);
 int irdma_cqp_qp_destroy_cmd(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp);
 void irdma_cqp_cq_destroy_cmd(struct irdma_sc_dev *dev, struct irdma_sc_cq *cq);
drivers/infiniband/hw/irdma/utils.c +2 -45

64 lines not on this page · raw message

base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b

Signature · 1 line
2.48.1
#1 lore raw

drivers/infiniband/hw/irdma/utils.c void irdma_ieq_mpa_crc_ae(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp) · line 1288

Quoted 11 lines · Eric Biggers
drivers/infiniband/hw/irdma/utils.c +2 -4
+int irdma_ieq_check_mpacrc(const void *addr, u32 len, u32 val)
 {
-	u32 crc = 0;
-
-	crypto_shash_digest(desc, addr, len, (u8 *)&crc);
-	if (crc != val)
+	if (~crc32c(~0, addr, len) != val)
 		return -EINVAL;
 
 	return 0;
 }

Sorry, I just realized this isn't actually equivalent on big endian CPUs, since the byte array produced by crypto_shash_digest() used little endian byte order, whereas crc32c() just returns a CPU endian value.

And of course this broken subsystem uses u32 for the little endian values instead of __le32 like the result of the kernel.

Not sure it's worth my time to continue to try to fix this subsystem properly.

- Eric

#2 lore raw
Quoted 17 lines · Eric Biggers

drivers/infiniband/hw/irdma/utils.c void irdma_ieq_mpa_crc_ae(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp) · line 1288

Quoted 11 lines · Eric Biggers
drivers/infiniband/hw/irdma/utils.c +2 -4
+int irdma_ieq_check_mpacrc(const void *addr, u32 len, u32 val)
 {
-	u32 crc = 0;
-
-	crypto_shash_digest(desc, addr, len, (u8 *)&crc);
-	if (crc != val)
+	if (~crc32c(~0, addr, len) != val)
 		return -EINVAL;
 
 	return 0;
 }

Sorry, I just realized this isn't actually equivalent on big endian CPUs, since the byte array produced by crypto_shash_digest() used little endian byte order, whereas crc32c() just returns a CPU endian value.

Quoted 4 lines

And of course this broken subsystem uses u32 for the little endian values instead of __le32 like the result of the kernel.

Not sure it's worth my time to continue to try to fix this subsystem properly.

There is no need to be such dramatic. You are not fixing anything by switch to new APIs, there is nothing broken with old API and you are changing specific driver and not subsystem.

So there are at least three mistakes in sentence "... fix broken subsystem ...".

Thanks

Quoted 2 lines

- Eric

#3 lore raw
Quoted 18 lines · Leon Romanovsky
Quoted 17 lines · Eric Biggers

drivers/infiniband/hw/irdma/utils.c void irdma_ieq_mpa_crc_ae(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp) · line 1288

Quoted 11 lines · Eric Biggers
drivers/infiniband/hw/irdma/utils.c +2 -4
+int irdma_ieq_check_mpacrc(const void *addr, u32 len, u32 val)
 {
-	u32 crc = 0;
-
-	crypto_shash_digest(desc, addr, len, (u8 *)&crc);
-	if (crc != val)
+	if (~crc32c(~0, addr, len) != val)
 		return -EINVAL;
 
 	return 0;
 }

Sorry, I just realized this isn't actually equivalent on big endian CPUs, since the byte array produced by crypto_shash_digest() used little endian byte order, whereas crc32c() just returns a CPU endian value.

Quoted 7 lines
Quoted 4 lines

And of course this broken subsystem uses u32 for the little endian values instead of __le32 like the result of the kernel.

Not sure it's worth my time to continue to try to fix this subsystem properly.

There is no need to be such dramatic. You are not fixing anything by switch to new APIs

Exactly. That's because I dropped the patches that actually did fix real endianness bugs, because of the pointless pushback I received -- see
https://lore.kernel.org/linux-rdma/[email protected]/T/#u

- Eric

#4 lore raw
Quoted 22 lines · Eric Biggers
Quoted 21 lines · Leon Romanovsky
Quoted 20 lines · Eric Biggers

drivers/infiniband/hw/irdma/utils.c void irdma_ieq_mpa_crc_ae(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp) · line 1288

Quoted 11 lines · Eric Biggers
drivers/infiniband/hw/irdma/utils.c +2 -4
+int irdma_ieq_check_mpacrc(const void *addr, u32 len, u32 val)
 {
-	u32 crc = 0;
-
-	crypto_shash_digest(desc, addr, len, (u8 *)&crc);
-	if (crc != val)
+	if (~crc32c(~0, addr, len) != val)
 		return -EINVAL;
 
 	return 0;
 }

Sorry, I just realized this isn't actually equivalent on big endian CPUs, since the byte array produced by crypto_shash_digest() used little endian byte order, whereas crc32c() just returns a CPU endian value.

And of course this broken subsystem uses u32 for the little endian values instead of __le32 like the result of the kernel.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Not sure it's worth my time to continue to try to fix this subsystem properly.

There is no need to be such dramatic. You are not fixing anything by switch to new APIs

Exactly. That's because I dropped the patches that actually did fix real endianness bugs, because of the pointless pushback I received -- see
https://lore.kernel.org/linux-rdma/[email protected]/T/#u

Anyway, I already sent v3 of this patch that keeps the cpu_to_le32() to maintain the exact same behavior as the old code, so please consider that if you are interested. Note that I had to add '(__force u32)' to be compatible with this driver's incorrect types, but that was effectively already there before, just hidden by writing bytes into a u32.

- Eric