Re: [PATCH v2 1/9] RDMA/rxe: Move ICRC checking to a subroutine
From: Jason Gunthorpe <jgg@nvidia.com>
Date: 2021-07-16 15:56:00
On Tue, Jul 06, 2021 at 11:00:33PM -0500, Bob Pearson wrote:
quoted hunk ↗ jump to hunk
Move the code in rxe_recv() that checks the ICRC on incoming packets to a subroutine rxe_check_icrc() and move that to rxe_icrc.c. Signed-off-by: Bob Pearson <redacted> Reviewed-by: Zhu Yanjun <zyjzyj2000@gmail.com> drivers/infiniband/sw/rxe/rxe_icrc.c | 38 ++++++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe_loc.h | 2 ++ drivers/infiniband/sw/rxe/rxe_recv.c | 23 ++--------------- 3 files changed, 42 insertions(+), 21 deletions(-)diff --git a/drivers/infiniband/sw/rxe/rxe_icrc.c b/drivers/infiniband/sw/rxe/rxe_icrc.c index 66b2aad54bb7..d067841214be 100644 +++ b/drivers/infiniband/sw/rxe/rxe_icrc.c@@ -67,3 +67,41 @@ u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb) rxe_opcode[pkt->opcode].length - RXE_BTH_BYTES); return crc; } + +/** + * rxe_icrc_check() - Compute ICRC for a packet and compare to the ICRC + * delivered in the packet. + * @skb: packet buffer + * @pkt: packet info + * + * Return: 0 if the values match else an error + */ +int rxe_icrc_check(struct sk_buff *skb, struct rxe_pkt_info *pkt) +{ + __be32 *icrcp; + u32 pkt_icrc; + u32 icrc; + + icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE); + pkt_icrc = be32_to_cpu(*icrcp); + + icrc = rxe_icrc_hdr(pkt, skb); + icrc = rxe_crc32(pkt->rxe, icrc, (u8 *)payload_addr(pkt), + payload_size(pkt) + bth_pad(pkt)); + icrc = (__force u32)cpu_to_be32(~icrc);
This isn't right, the return value of rxe_crc32 is a __b32 so icrc here should be a __b32 too
+ if (unlikely(icrc != pkt_icrc)) {
And this should be written
if (unlikely(be32_to_cpu(~icrc) != pkt_icrc)) {
Or, alternatively you can skip both of the be32_to_cpu's and just
directly compare the __be32 types
Also, I'm not sure the rxe_crc32 byteswapping is right either, the
crc32 shash implementation is storing a __le32 in the shash_desc_ctx()
but this code reads it out as a __be32 ? On BE that will gain a
byteswap, is it OK?
Jason