From de71a76a469fa764509c52f41fade1b60c6a8cb2 Mon Sep 17 00:00:00 2001 From: Ted Shaowang Date: Thu, 14 May 2026 18:27:58 +0000 Subject: [PATCH 1/2] libibverbs: Optimize IP version check in ibv_init_ah_from_wc Add IBV_WC_WITH_NETWORK_HDR_TYPE and IBV_WC_NETWORK_HDR_IPV6 flags to enum ibv_wc_flags. This provides a user-space equivalent to the kernel's network header type reporting, optimizing address handle creation from work completions. Currently, ibv_init_ah_from_wc() relies on parsing the GRH and potentially performing expensive checksum calculations (via get_grh_header_version) to determine if an incoming packet is IPv4 or IPv6. This patch allows providers that extract IP version information directly from the hardware CQE to set these flags in wc->wc_flags. The core library can then cheaply evaluate the bitmask to bypass the fallback GRH payload check entirely. Signed-off-by: Ted Shaowang --- libibverbs/verbs.c | 5 ++++- libibverbs/verbs.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c index c65176ccf..88e80fac3 100644 --- a/libibverbs/verbs.c +++ b/libibverbs/verbs.c @@ -1009,7 +1009,10 @@ int ibv_init_ah_from_wc(struct ibv_context *context, uint8_t port_num, if (wc->wc_flags & IBV_WC_GRH) { ah_attr->is_global = 1; - version = get_grh_header_version(grh); + if (wc->wc_flags & IBV_WC_WITH_NETWORK_HDR_TYPE) + version = (wc->wc_flags & IBV_WC_NETWORK_HDR_IPV6) ? 6 : 4; + else + version = get_grh_header_version(grh); if (version == 4) ret = set_ah_attr_by_ipv4(context, ah_attr, diff --git a/libibverbs/verbs.h b/libibverbs/verbs.h index 36d120eec..b3729ea8b 100644 --- a/libibverbs/verbs.h +++ b/libibverbs/verbs.h @@ -587,6 +587,8 @@ enum ibv_wc_flags { IBV_WC_TM_SYNC_REQ = 1 << 4, IBV_WC_TM_MATCH = 1 << 5, IBV_WC_TM_DATA_VALID = 1 << 6, + IBV_WC_WITH_NETWORK_HDR_TYPE = 1 << 7, + IBV_WC_NETWORK_HDR_IPV6 = 1 << 8, }; struct ibv_wc { From 89296b078f66ab8158f991e1c833ffca9cd3f58f Mon Sep 17 00:00:00 2001 From: Ted Shaowang Date: Thu, 14 May 2026 18:31:39 +0000 Subject: [PATCH 2/2] irdma: Report network header type in UD work completions Leverage the newly introduced IBV_WC_WITH_NETWORK_HDR_TYPE and IBV_WC_NETWORK_HDR_IPV6 flags when processing Completion Queue Entries (CQEs) for Unreliable Datagram (UD) QPs. The irdma hardware natively parses the IP version and reports it via the 'ipv4' field in the CQE. Translating this state into wc_flags enables the core libibverbs layer to skip expensive software GRH parsing and checksum verifications during address handle creation. Beyond the performance benefits of bypassing payload memory reads, this ensures correct IP version identification. Since some hardware zeroes out the IPv4 header checksum in the buffer, a non-zero checksum calculated in get_grh_header_version() could fail the verification against the buffer's zeroed field, and wrongly misclassify valid IPv4 packets as IPv6. Relying on the explicit CQE state resolves this correctness issue. Signed-off-by: Ted Shaowang --- providers/irdma/uverbs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/providers/irdma/uverbs.c b/providers/irdma/uverbs.c index 76400aa9f..b53c19ac9 100644 --- a/providers/irdma/uverbs.c +++ b/providers/irdma/uverbs.c @@ -923,7 +923,9 @@ static void irdma_process_cqe(struct ibv_wc *entry, struct irdma_cq_poll_info *c if (ib_qp->qp_type == IBV_QPT_UD) { entry->src_qp = cur_cqe->ud_src_qpn; - entry->wc_flags |= IBV_WC_GRH; + entry->wc_flags |= (IBV_WC_GRH | IBV_WC_WITH_NETWORK_HDR_TYPE); + if (!cur_cqe->ipv4) + entry->wc_flags |= IBV_WC_NETWORK_HDR_IPV6; } else { entry->src_qp = cur_cqe->qp_id; }