aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorJieqiang Wang <jieqiang.wang@arm.com>2022-11-25 15:26:55 +0800
committerBeno�t Ganne <bganne@cisco.com>2022-11-29 12:58:51 +0000
commit6db2758611dd5f1cf82c0bf78cfb95230ed2786f (patch)
treee150ae122bf34db9ae17231c5a74a831fdc1e582 /src/plugins
parent520cde406797eb076591797fbf9978b959e6cf17 (diff)
rdma: fix for-loop initialization in scalar path
When n_rx_packets is less then 16(VEC256) or 8(VEC128), code execution will fall into scalar path of processing packets. But with a wrong initialization value for n_left set to zero, i in the for-loop will equal to n_rx_packets. This leads to the bypass of required ip4 checksum validation and byte count endianness conversion in scalar path. Besides, refactor the code using while instead of for-loop to keep consistency with VPP code style. Type: fix Fixes: bf93670c515d ("rdma: fix ipv4 checksum check in rdma-input node") Signed-off-by: Lijian Zhang <lijian.zhang@arm.com> Signed-off-by: Jieqiang Wang <jieqiang.wang@arm.com> Change-Id: Ib4e8cb5202735f8b060c99caddf26035657551e1
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/rdma/input.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/plugins/rdma/input.c b/src/plugins/rdma/input.c
index 5f2c0bbf31f..827fc577484 100644
--- a/src/plugins/rdma/input.c
+++ b/src/plugins/rdma/input.c
@@ -681,51 +681,66 @@ rdma_device_mlx5dv_l3_validate_and_swap_bc (rdma_per_thread_data_t
/* verify that all ip4 packets have l3_ok flag set and convert packet
length from network to host byte order */
int skip_ip4_cksum = 1;
- int n_left = 0;
+ int n_left = n_rx_packets;
+ u16 *cqe_flags = ptd->cqe_flags;
#if defined CLIB_HAVE_VEC256
- if (n_rx_packets >= 16)
+ if (n_left >= 16)
{
u16x16 mask16 = u16x16_splat (mask);
u16x16 match16 = u16x16_splat (match);
u16x16 r16 = {};
- n_left = n_rx_packets % 16;
+ while (n_left >= 16)
+ {
+ r16 |= (*(u16x16 *) cqe_flags & mask16) != match16;
+
+ *(u32x8 *) bc = u32x8_byte_swap (*(u32x8 *) bc);
+ *(u32x8 *) (bc + 8) = u32x8_byte_swap (*(u32x8 *) (bc + 8));
- for (int i = 0; i < n_rx_packets / 16; i++)
- r16 |= (ptd->cqe_flags16[i] & mask16) != match16;
+ cqe_flags += 16;
+ bc += 16;
+ n_left -= 16;
+ }
if (!u16x16_is_all_zero (r16))
skip_ip4_cksum = 0;
-
- for (int i = 0; i < (n_rx_packets - n_left); i += 8)
- *(u32x8 *) (bc + i) = u32x8_byte_swap (*(u32x8 *) (bc + i));
}
#elif defined CLIB_HAVE_VEC128
- if (n_rx_packets >= 8)
+ if (n_left >= 8)
{
u16x8 mask8 = u16x8_splat (mask);
u16x8 match8 = u16x8_splat (match);
u16x8 r8 = {};
- n_left = n_rx_packets % 8;
+ while (n_left >= 8)
+ {
+ r8 |= (*(u16x8 *) cqe_flags & mask8) != match8;
+
+ *(u32x4 *) bc = u32x4_byte_swap (*(u32x4 *) bc);
+ *(u32x4 *) (bc + 4) = u32x4_byte_swap (*(u32x4 *) (bc + 4));
- for (int i = 0; i < n_rx_packets / 8; i++)
- r8 |= (ptd->cqe_flags8[i] & mask8) != match8;
+ cqe_flags += 8;
+ bc += 8;
+ n_left -= 8;
+ }
if (!u16x8_is_all_zero (r8))
skip_ip4_cksum = 0;
-
- for (int i = 0; i < (n_rx_packets - n_left); i += 4)
- *(u32x4 *) (bc + i) = u32x4_byte_swap (*(u32x4 *) (bc + i));
}
#endif
- for (int i = (n_rx_packets - n_left); i < n_rx_packets; i++)
- if ((ptd->cqe_flags[i] & mask) != match)
- skip_ip4_cksum = 0;
- for (int i = (n_rx_packets - n_left); i < n_rx_packets; i++)
- bc[i] = clib_net_to_host_u32 (bc[i]);
+ while (n_left >= 1)
+ {
+ if ((cqe_flags[0] & mask) != match)
+ skip_ip4_cksum = 0;
+
+ bc[0] = clib_net_to_host_u32 (bc[0]);
+
+ cqe_flags += 1;
+ bc += 1;
+ n_left -= 1;
+ }
return skip_ip4_cksum;
}