diff mbox series

[5/5] RDMA/rxe: Move crc32 init code to rxe_icrc.c

Message ID 20210629201412.28306-6-rpearsonhpe@gmail.com (mailing list archive)
State Superseded
Headers show
Series RDMA/rxe: Cleanup ICRC | expand

Commit Message

Bob Pearson June 29, 2021, 8:14 p.m. UTC
This patch collects the code from rxe_register_device() that sets
up the crc32 calculation into a subroutine rxe_icrc_init() in
rxe_icrc.c. This completes collecting all the code specific to computing
ICRC into one file with a simple set of APIs.
Minor cleanups in rxe_icrc.c to
  Comments
  byte order types

Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
---
 drivers/infiniband/sw/rxe/rxe.h       |  1 -
 drivers/infiniband/sw/rxe/rxe_icrc.c  | 75 +++++++++++++++++----------
 drivers/infiniband/sw/rxe/rxe_loc.h   |  1 +
 drivers/infiniband/sw/rxe/rxe_verbs.c | 11 ++--
 4 files changed, 53 insertions(+), 35 deletions(-)

Comments

Zhu Yanjun June 30, 2021, 4:09 a.m. UTC | #1
On Wed, Jun 30, 2021 at 4:14 AM Bob Pearson <rpearsonhpe@gmail.com> wrote:
>
> This patch collects the code from rxe_register_device() that sets
> up the crc32 calculation into a subroutine rxe_icrc_init() in
> rxe_icrc.c. This completes collecting all the code specific to computing
> ICRC into one file with a simple set of APIs.
> Minor cleanups in rxe_icrc.c to
>   Comments
>   byte order types
>
> Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>

Why are the same patch series sent twice?

Which one is official? "[for-next,resending,1/5] RDMA/rxe: Move ICRC
checking to a subroutine" is official? or this one?

Zhu Yanjun

> ---
>  drivers/infiniband/sw/rxe/rxe.h       |  1 -
>  drivers/infiniband/sw/rxe/rxe_icrc.c  | 75 +++++++++++++++++----------
>  drivers/infiniband/sw/rxe/rxe_loc.h   |  1 +
>  drivers/infiniband/sw/rxe/rxe_verbs.c | 11 ++--
>  4 files changed, 53 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rxe/rxe.h b/drivers/infiniband/sw/rxe/rxe.h
> index 65a73c1c8b35..1bb3fb618bf5 100644
> --- a/drivers/infiniband/sw/rxe/rxe.h
> +++ b/drivers/infiniband/sw/rxe/rxe.h
> @@ -14,7 +14,6 @@
>
>  #include <linux/module.h>
>  #include <linux/skbuff.h>
> -#include <linux/crc32.h>
>
>  #include <rdma/ib_verbs.h>
>  #include <rdma/ib_user_verbs.h>
> diff --git a/drivers/infiniband/sw/rxe/rxe_icrc.c b/drivers/infiniband/sw/rxe/rxe_icrc.c
> index e116c63d7b84..4f311798d682 100644
> --- a/drivers/infiniband/sw/rxe/rxe_icrc.c
> +++ b/drivers/infiniband/sw/rxe/rxe_icrc.c
> @@ -4,34 +4,59 @@
>   * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
>   */
>
> +#include <linux/crc32.h>
>  #include "rxe.h"
>  #include "rxe_loc.h"
>
>  /**
> - * rxe_crc32 - Compute incremental crc32 for a contiguous segment
> + * rxe_icrc_init - Initialize crypto function for computing crc32
> + * @rxe: rdma_rxe device object
> + *
> + * Returns 0 on success else an error
> + */
> +int rxe_icrc_init(struct rxe_dev *rxe)
> +{
> +       struct crypto_shash *tfm;
> +
> +       tfm = crypto_alloc_shash("crc32", 0, 0);
> +       if (IS_ERR(tfm)) {
> +               pr_err("failed to init crc32 algorithm err:%ld\n",
> +                              PTR_ERR(tfm));
> +               return PTR_ERR(tfm);
> +       }
> +
> +       rxe->tfm = tfm;
> +
> +       return 0;
> +}
> +
> +/**
> + * rxe_crc32 - Compute cumulative crc32 for a contiguous segment
>   * @rxe: rdma_rxe device object
>   * @crc: starting crc32 value from previous segments
>   * @addr: starting address of segment
>   * @len: length of the segment in bytes
>   *
> - * Returns the crc32 checksum of the segment starting from crc.
> + * Returns the crc32 cumulative checksum including the segment starting
> + * from crc.
>   */
> -static u32 rxe_crc32(struct rxe_dev *rxe, u32 crc, void *addr, size_t len)
> +static __be32 rxe_crc32(struct rxe_dev *rxe, __be32 crc, void *addr,
> +                       size_t len)
>  {
> -       u32 icrc;
> +       __be32 icrc;
>         int err;
>
>         SHASH_DESC_ON_STACK(shash, rxe->tfm);
>
>         shash->tfm = rxe->tfm;
> -       *(u32 *)shash_desc_ctx(shash) = crc;
> +       *(__be32 *)shash_desc_ctx(shash) = crc;
>         err = crypto_shash_update(shash, addr, len);
>         if (unlikely(err)) {
>                 pr_warn_ratelimited("failed crc calculation, err: %d\n", err);
>                 return crc32_le(crc, addr, len);
>         }
>
> -       icrc = *(u32 *)shash_desc_ctx(shash);
> +       icrc = *(__be32 *)shash_desc_ctx(shash);
>         barrier_data(shash_desc_ctx(shash));
>
>         return icrc;
> @@ -39,19 +64,16 @@ static u32 rxe_crc32(struct rxe_dev *rxe, u32 crc, void *addr, size_t len)
>
>  /**
>   * rxe_icrc_hdr - Compute a partial ICRC for the IB transport headers.
> - * @pkt: Information about the current packet
> - * @skb: The packet buffer
> + * @pkt: packet information
> + * @skb: packet buffer
>   *
>   * Returns the partial ICRC
>   */
>  static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>  {
> -       unsigned int bth_offset = 0;
> -       struct iphdr *ip4h = NULL;
> -       struct ipv6hdr *ip6h = NULL;
>         struct udphdr *udph;
>         struct rxe_bth *bth;
> -       int crc;
> +       __be32 crc;
>         int length;
>         int hdr_size = sizeof(struct udphdr) +
>                 (skb->protocol == htons(ETH_P_IP) ?
> @@ -69,6 +91,8 @@ static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>         crc = 0xdebb20e3;
>
>         if (skb->protocol == htons(ETH_P_IP)) { /* IPv4 */
> +               struct iphdr *ip4h = NULL;
> +
>                 memcpy(pshdr, ip_hdr(skb), hdr_size);
>                 ip4h = (struct iphdr *)pshdr;
>                 udph = (struct udphdr *)(ip4h + 1);
> @@ -77,6 +101,8 @@ static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>                 ip4h->check = CSUM_MANGLED_0;
>                 ip4h->tos = 0xff;
>         } else {                                /* IPv6 */
> +               struct ipv6hdr *ip6h = NULL;
> +
>                 memcpy(pshdr, ipv6_hdr(skb), hdr_size);
>                 ip6h = (struct ipv6hdr *)pshdr;
>                 udph = (struct udphdr *)(ip6h + 1);
> @@ -85,12 +111,9 @@ static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>                 ip6h->priority = 0xf;
>                 ip6h->hop_limit = 0xff;
>         }
> -       udph->check = CSUM_MANGLED_0;
> -
> -       bth_offset += hdr_size;
>
> -       memcpy(&pshdr[bth_offset], pkt->hdr, RXE_BTH_BYTES);
> -       bth = (struct rxe_bth *)&pshdr[bth_offset];
> +       bth = (struct rxe_bth *)(udph + 1);
> +       memcpy(bth, pkt->hdr, RXE_BTH_BYTES);
>
>         /* exclude bth.resv8a */
>         bth->qpn |= cpu_to_be32(~BTH_QPN_MASK);
> @@ -115,18 +138,18 @@ int rxe_icrc_check(struct sk_buff *skb)
>  {
>         struct rxe_pkt_info *pkt = SKB_TO_PKT(skb);
>         __be32 *icrcp;
> -       u32 pkt_icrc;
> -       u32 icrc;
> +       __be32 packet_icrc;
> +       __be32 computed_icrc;
>
>         icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
> -       pkt_icrc = be32_to_cpu(*icrcp);
> +       packet_icrc = *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);
> +       computed_icrc = rxe_icrc_hdr(pkt, skb);
> +       computed_icrc = rxe_crc32(pkt->rxe, computed_icrc,
> +               (u8 *)payload_addr(pkt), payload_size(pkt) + bth_pad(pkt));
> +       computed_icrc = ~computed_icrc;
>
> -       if (unlikely(icrc != pkt_icrc)) {
> +       if (unlikely(computed_icrc != packet_icrc)) {
>                 if (skb->protocol == htons(ETH_P_IPV6))
>                         pr_warn_ratelimited("bad ICRC from %pI6c\n",
>                                             &ipv6_hdr(skb)->saddr);
> @@ -150,7 +173,7 @@ int rxe_icrc_check(struct sk_buff *skb)
>  void rxe_icrc_generate(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>  {
>         __be32 *icrcp;
> -       u32 icrc;
> +       __be32 icrc;
>
>         icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
>         icrc = rxe_icrc_hdr(pkt, skb);
> diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h
> index b08689b664ec..f98378f8ff31 100644
> --- a/drivers/infiniband/sw/rxe/rxe_loc.h
> +++ b/drivers/infiniband/sw/rxe/rxe_loc.h
> @@ -193,6 +193,7 @@ int rxe_requester(void *arg);
>  int rxe_responder(void *arg);
>
>  /* rxe_icrc.c */
> +int rxe_icrc_init(struct rxe_dev *rxe);
>  int rxe_icrc_check(struct sk_buff *skb);
>  void rxe_icrc_generate(struct rxe_pkt_info *pkt, struct sk_buff *skb);
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
> index c223959ac174..f7b1a1f64c13 100644
> --- a/drivers/infiniband/sw/rxe/rxe_verbs.c
> +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
> @@ -1154,7 +1154,6 @@ int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
>  {
>         int err;
>         struct ib_device *dev = &rxe->ib_dev;
> -       struct crypto_shash *tfm;
>
>         strscpy(dev->node_desc, "rxe", sizeof(dev->node_desc));
>
> @@ -1173,13 +1172,9 @@ int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
>         if (err)
>                 return err;
>
> -       tfm = crypto_alloc_shash("crc32", 0, 0);
> -       if (IS_ERR(tfm)) {
> -               pr_err("failed to allocate crc algorithm err:%ld\n",
> -                      PTR_ERR(tfm));
> -               return PTR_ERR(tfm);
> -       }
> -       rxe->tfm = tfm;
> +       err = rxe_icrc_init(rxe);
> +       if (err)
> +               return err;
>
>         err = ib_register_device(dev, ibdev_name, NULL);
>         if (err)
> --
> 2.30.2
>
Pearson, Robert B June 30, 2021, 4:13 a.m. UTC | #2
The second one. i.e. the resent one. When I sent it the first time things got confused. 
They are exactly the same except: in the cover letter the first time it had 0/7 should have been 0/5.
The resent one got that right. Also the first time it sent patches 6/7 and 7/7 which was not what I wanted to do.

Thanks

Bob

-----Original Message-----
From: Zhu Yanjun <zyjzyj2000@gmail.com> 
Sent: Tuesday, June 29, 2021 11:09 PM
To: Bob Pearson <rpearsonhpe@gmail.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>; RDMA mailing list <linux-rdma@vger.kernel.org>
Subject: Re: [PATCH 5/5] RDMA/rxe: Move crc32 init code to rxe_icrc.c

On Wed, Jun 30, 2021 at 4:14 AM Bob Pearson <rpearsonhpe@gmail.com> wrote:
>
> This patch collects the code from rxe_register_device() that sets up 
> the crc32 calculation into a subroutine rxe_icrc_init() in rxe_icrc.c. 
> This completes collecting all the code specific to computing ICRC into 
> one file with a simple set of APIs.
> Minor cleanups in rxe_icrc.c to
>   Comments
>   byte order types
>
> Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>

Why are the same patch series sent twice?

Which one is official? "[for-next,resending,1/5] RDMA/rxe: Move ICRC checking to a subroutine" is official? or this one?

Zhu Yanjun

> ---
>  drivers/infiniband/sw/rxe/rxe.h       |  1 -
>  drivers/infiniband/sw/rxe/rxe_icrc.c  | 75 +++++++++++++++++----------
>  drivers/infiniband/sw/rxe/rxe_loc.h   |  1 +
>  drivers/infiniband/sw/rxe/rxe_verbs.c | 11 ++--
>  4 files changed, 53 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rxe/rxe.h 
> b/drivers/infiniband/sw/rxe/rxe.h index 65a73c1c8b35..1bb3fb618bf5 
> 100644
> --- a/drivers/infiniband/sw/rxe/rxe.h
> +++ b/drivers/infiniband/sw/rxe/rxe.h
> @@ -14,7 +14,6 @@
>
>  #include <linux/module.h>
>  #include <linux/skbuff.h>
> -#include <linux/crc32.h>
>
>  #include <rdma/ib_verbs.h>
>  #include <rdma/ib_user_verbs.h>
> diff --git a/drivers/infiniband/sw/rxe/rxe_icrc.c 
> b/drivers/infiniband/sw/rxe/rxe_icrc.c
> index e116c63d7b84..4f311798d682 100644
> --- a/drivers/infiniband/sw/rxe/rxe_icrc.c
> +++ b/drivers/infiniband/sw/rxe/rxe_icrc.c
> @@ -4,34 +4,59 @@
>   * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
>   */
>
> +#include <linux/crc32.h>
>  #include "rxe.h"
>  #include "rxe_loc.h"
>
>  /**
> - * rxe_crc32 - Compute incremental crc32 for a contiguous segment
> + * rxe_icrc_init - Initialize crypto function for computing crc32
> + * @rxe: rdma_rxe device object
> + *
> + * Returns 0 on success else an error  */ int rxe_icrc_init(struct 
> +rxe_dev *rxe) {
> +       struct crypto_shash *tfm;
> +
> +       tfm = crypto_alloc_shash("crc32", 0, 0);
> +       if (IS_ERR(tfm)) {
> +               pr_err("failed to init crc32 algorithm err:%ld\n",
> +                              PTR_ERR(tfm));
> +               return PTR_ERR(tfm);
> +       }
> +
> +       rxe->tfm = tfm;
> +
> +       return 0;
> +}
> +
> +/**
> + * rxe_crc32 - Compute cumulative crc32 for a contiguous segment
>   * @rxe: rdma_rxe device object
>   * @crc: starting crc32 value from previous segments
>   * @addr: starting address of segment
>   * @len: length of the segment in bytes
>   *
> - * Returns the crc32 checksum of the segment starting from crc.
> + * Returns the crc32 cumulative checksum including the segment 
> + starting
> + * from crc.
>   */
> -static u32 rxe_crc32(struct rxe_dev *rxe, u32 crc, void *addr, size_t 
> len)
> +static __be32 rxe_crc32(struct rxe_dev *rxe, __be32 crc, void *addr,
> +                       size_t len)
>  {
> -       u32 icrc;
> +       __be32 icrc;
>         int err;
>
>         SHASH_DESC_ON_STACK(shash, rxe->tfm);
>
>         shash->tfm = rxe->tfm;
> -       *(u32 *)shash_desc_ctx(shash) = crc;
> +       *(__be32 *)shash_desc_ctx(shash) = crc;
>         err = crypto_shash_update(shash, addr, len);
>         if (unlikely(err)) {
>                 pr_warn_ratelimited("failed crc calculation, err: %d\n", err);
>                 return crc32_le(crc, addr, len);
>         }
>
> -       icrc = *(u32 *)shash_desc_ctx(shash);
> +       icrc = *(__be32 *)shash_desc_ctx(shash);
>         barrier_data(shash_desc_ctx(shash));
>
>         return icrc;
> @@ -39,19 +64,16 @@ static u32 rxe_crc32(struct rxe_dev *rxe, u32 crc, 
> void *addr, size_t len)
>
>  /**
>   * rxe_icrc_hdr - Compute a partial ICRC for the IB transport headers.
> - * @pkt: Information about the current packet
> - * @skb: The packet buffer
> + * @pkt: packet information
> + * @skb: packet buffer
>   *
>   * Returns the partial ICRC
>   */
>  static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff 
> *skb)  {
> -       unsigned int bth_offset = 0;
> -       struct iphdr *ip4h = NULL;
> -       struct ipv6hdr *ip6h = NULL;
>         struct udphdr *udph;
>         struct rxe_bth *bth;
> -       int crc;
> +       __be32 crc;
>         int length;
>         int hdr_size = sizeof(struct udphdr) +
>                 (skb->protocol == htons(ETH_P_IP) ?
> @@ -69,6 +91,8 @@ static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>         crc = 0xdebb20e3;
>
>         if (skb->protocol == htons(ETH_P_IP)) { /* IPv4 */
> +               struct iphdr *ip4h = NULL;
> +
>                 memcpy(pshdr, ip_hdr(skb), hdr_size);
>                 ip4h = (struct iphdr *)pshdr;
>                 udph = (struct udphdr *)(ip4h + 1); @@ -77,6 +101,8 @@ 
> static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>                 ip4h->check = CSUM_MANGLED_0;
>                 ip4h->tos = 0xff;
>         } else {                                /* IPv6 */
> +               struct ipv6hdr *ip6h = NULL;
> +
>                 memcpy(pshdr, ipv6_hdr(skb), hdr_size);
>                 ip6h = (struct ipv6hdr *)pshdr;
>                 udph = (struct udphdr *)(ip6h + 1); @@ -85,12 +111,9 
> @@ static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
>                 ip6h->priority = 0xf;
>                 ip6h->hop_limit = 0xff;
>         }
> -       udph->check = CSUM_MANGLED_0;
> -
> -       bth_offset += hdr_size;
>
> -       memcpy(&pshdr[bth_offset], pkt->hdr, RXE_BTH_BYTES);
> -       bth = (struct rxe_bth *)&pshdr[bth_offset];
> +       bth = (struct rxe_bth *)(udph + 1);
> +       memcpy(bth, pkt->hdr, RXE_BTH_BYTES);
>
>         /* exclude bth.resv8a */
>         bth->qpn |= cpu_to_be32(~BTH_QPN_MASK); @@ -115,18 +138,18 @@ 
> int rxe_icrc_check(struct sk_buff *skb)  {
>         struct rxe_pkt_info *pkt = SKB_TO_PKT(skb);
>         __be32 *icrcp;
> -       u32 pkt_icrc;
> -       u32 icrc;
> +       __be32 packet_icrc;
> +       __be32 computed_icrc;
>
>         icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
> -       pkt_icrc = be32_to_cpu(*icrcp);
> +       packet_icrc = *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);
> +       computed_icrc = rxe_icrc_hdr(pkt, skb);
> +       computed_icrc = rxe_crc32(pkt->rxe, computed_icrc,
> +               (u8 *)payload_addr(pkt), payload_size(pkt) + bth_pad(pkt));
> +       computed_icrc = ~computed_icrc;
>
> -       if (unlikely(icrc != pkt_icrc)) {
> +       if (unlikely(computed_icrc != packet_icrc)) {
>                 if (skb->protocol == htons(ETH_P_IPV6))
>                         pr_warn_ratelimited("bad ICRC from %pI6c\n",
>                                             &ipv6_hdr(skb)->saddr); @@ 
> -150,7 +173,7 @@ int rxe_icrc_check(struct sk_buff *skb)  void 
> rxe_icrc_generate(struct rxe_pkt_info *pkt, struct sk_buff *skb)  {
>         __be32 *icrcp;
> -       u32 icrc;
> +       __be32 icrc;
>
>         icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
>         icrc = rxe_icrc_hdr(pkt, skb); diff --git 
> a/drivers/infiniband/sw/rxe/rxe_loc.h 
> b/drivers/infiniband/sw/rxe/rxe_loc.h
> index b08689b664ec..f98378f8ff31 100644
> --- a/drivers/infiniband/sw/rxe/rxe_loc.h
> +++ b/drivers/infiniband/sw/rxe/rxe_loc.h
> @@ -193,6 +193,7 @@ int rxe_requester(void *arg);  int 
> rxe_responder(void *arg);
>
>  /* rxe_icrc.c */
> +int rxe_icrc_init(struct rxe_dev *rxe);
>  int rxe_icrc_check(struct sk_buff *skb);  void 
> rxe_icrc_generate(struct rxe_pkt_info *pkt, struct sk_buff *skb);
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c 
> b/drivers/infiniband/sw/rxe/rxe_verbs.c
> index c223959ac174..f7b1a1f64c13 100644
> --- a/drivers/infiniband/sw/rxe/rxe_verbs.c
> +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
> @@ -1154,7 +1154,6 @@ int rxe_register_device(struct rxe_dev *rxe, 
> const char *ibdev_name)  {
>         int err;
>         struct ib_device *dev = &rxe->ib_dev;
> -       struct crypto_shash *tfm;
>
>         strscpy(dev->node_desc, "rxe", sizeof(dev->node_desc));
>
> @@ -1173,13 +1172,9 @@ int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
>         if (err)
>                 return err;
>
> -       tfm = crypto_alloc_shash("crc32", 0, 0);
> -       if (IS_ERR(tfm)) {
> -               pr_err("failed to allocate crc algorithm err:%ld\n",
> -                      PTR_ERR(tfm));
> -               return PTR_ERR(tfm);
> -       }
> -       rxe->tfm = tfm;
> +       err = rxe_icrc_init(rxe);
> +       if (err)
> +               return err;
>
>         err = ib_register_device(dev, ibdev_name, NULL);
>         if (err)
> --
> 2.30.2
>
kernel test robot July 1, 2021, 3:38 a.m. UTC | #3
Hi Bob,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on rdma/for-next]
[also build test WARNING on next-20210630]
[cannot apply to v5.13]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Bob-Pearson/RDMA-rxe-Move-ICRC-checking-to-a-subroutine/20210630-051423
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git for-next
config: riscv-randconfig-s032-20210630 (attached as .config)
compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/e231ff2c1bb74fd5f86e9e1a7d43770a98209bf9
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Bob-Pearson/RDMA-rxe-Move-ICRC-checking-to-a-subroutine/20210630-051423
        git checkout e231ff2c1bb74fd5f86e9e1a7d43770a98209bf9
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=riscv 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
>> drivers/infiniband/sw/rxe/rxe_icrc.c:56:33: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected unsigned int [usertype] crc @@     got restricted __be32 [usertype] crc @@
   drivers/infiniband/sw/rxe/rxe_icrc.c:56:33: sparse:     expected unsigned int [usertype] crc
   drivers/infiniband/sw/rxe/rxe_icrc.c:56:33: sparse:     got restricted __be32 [usertype] crc
>> drivers/infiniband/sw/rxe/rxe_icrc.c:56:32: sparse: sparse: incorrect type in return expression (different base types) @@     expected restricted __be32 @@     got unsigned int @@
   drivers/infiniband/sw/rxe/rxe_icrc.c:56:32: sparse:     expected restricted __be32
   drivers/infiniband/sw/rxe/rxe_icrc.c:56:32: sparse:     got unsigned int
>> drivers/infiniband/sw/rxe/rxe_icrc.c:91:13: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be32 [usertype] crc @@     got unsigned int @@
   drivers/infiniband/sw/rxe/rxe_icrc.c:91:13: sparse:     expected restricted __be32 [usertype] crc
   drivers/infiniband/sw/rxe/rxe_icrc.c:91:13: sparse:     got unsigned int
>> drivers/infiniband/sw/rxe/rxe_icrc.c:127:16: sparse: sparse: incorrect type in return expression (different base types) @@     expected unsigned int @@     got restricted __be32 [assigned] [usertype] crc @@
   drivers/infiniband/sw/rxe/rxe_icrc.c:127:16: sparse:     expected unsigned int
   drivers/infiniband/sw/rxe/rxe_icrc.c:127:16: sparse:     got restricted __be32 [assigned] [usertype] crc
>> drivers/infiniband/sw/rxe/rxe_icrc.c:147:23: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be32 [usertype] computed_icrc @@     got unsigned int @@
   drivers/infiniband/sw/rxe/rxe_icrc.c:147:23: sparse:     expected restricted __be32 [usertype] computed_icrc
   drivers/infiniband/sw/rxe/rxe_icrc.c:147:23: sparse:     got unsigned int
>> drivers/infiniband/sw/rxe/rxe_icrc.c:179:14: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be32 [usertype] icrc @@     got unsigned int @@
   drivers/infiniband/sw/rxe/rxe_icrc.c:179:14: sparse:     expected restricted __be32 [usertype] icrc
   drivers/infiniband/sw/rxe/rxe_icrc.c:179:14: sparse:     got unsigned int

vim +56 drivers/infiniband/sw/rxe/rxe_icrc.c

e231ff2c1bb74fd5 Bob Pearson 2021-06-29   32  
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   33  /**
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   34   * rxe_crc32 - Compute cumulative crc32 for a contiguous segment
46bb188d442e9494 Bob Pearson 2021-06-29   35   * @rxe: rdma_rxe device object
46bb188d442e9494 Bob Pearson 2021-06-29   36   * @crc: starting crc32 value from previous segments
46bb188d442e9494 Bob Pearson 2021-06-29   37   * @addr: starting address of segment
46bb188d442e9494 Bob Pearson 2021-06-29   38   * @len: length of the segment in bytes
46bb188d442e9494 Bob Pearson 2021-06-29   39   *
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   40   * Returns the crc32 cumulative checksum including the segment starting
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   41   * from crc.
46bb188d442e9494 Bob Pearson 2021-06-29   42   */
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   43  static __be32 rxe_crc32(struct rxe_dev *rxe, __be32 crc, void *addr,
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   44  			size_t len)
46bb188d442e9494 Bob Pearson 2021-06-29   45  {
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   46  	__be32 icrc;
46bb188d442e9494 Bob Pearson 2021-06-29   47  	int err;
46bb188d442e9494 Bob Pearson 2021-06-29   48  
46bb188d442e9494 Bob Pearson 2021-06-29   49  	SHASH_DESC_ON_STACK(shash, rxe->tfm);
46bb188d442e9494 Bob Pearson 2021-06-29   50  
46bb188d442e9494 Bob Pearson 2021-06-29   51  	shash->tfm = rxe->tfm;
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   52  	*(__be32 *)shash_desc_ctx(shash) = crc;
46bb188d442e9494 Bob Pearson 2021-06-29   53  	err = crypto_shash_update(shash, addr, len);
46bb188d442e9494 Bob Pearson 2021-06-29   54  	if (unlikely(err)) {
46bb188d442e9494 Bob Pearson 2021-06-29   55  		pr_warn_ratelimited("failed crc calculation, err: %d\n", err);
46bb188d442e9494 Bob Pearson 2021-06-29  @56  		return crc32_le(crc, addr, len);
46bb188d442e9494 Bob Pearson 2021-06-29   57  	}
46bb188d442e9494 Bob Pearson 2021-06-29   58  
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   59  	icrc = *(__be32 *)shash_desc_ctx(shash);
46bb188d442e9494 Bob Pearson 2021-06-29   60  	barrier_data(shash_desc_ctx(shash));
46bb188d442e9494 Bob Pearson 2021-06-29   61  
46bb188d442e9494 Bob Pearson 2021-06-29   62  	return icrc;
46bb188d442e9494 Bob Pearson 2021-06-29   63  }
46bb188d442e9494 Bob Pearson 2021-06-29   64  
46bb188d442e9494 Bob Pearson 2021-06-29   65  /**
46bb188d442e9494 Bob Pearson 2021-06-29   66   * rxe_icrc_hdr - Compute a partial ICRC for the IB transport headers.
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   67   * @pkt: packet information
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   68   * @skb: packet buffer
46bb188d442e9494 Bob Pearson 2021-06-29   69   *
46bb188d442e9494 Bob Pearson 2021-06-29   70   * Returns the partial ICRC
46bb188d442e9494 Bob Pearson 2021-06-29   71   */
46bb188d442e9494 Bob Pearson 2021-06-29   72  static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
8700e3e7c4857d28 Moni Shoua  2016-06-16   73  {
8700e3e7c4857d28 Moni Shoua  2016-06-16   74  	struct udphdr *udph;
8700e3e7c4857d28 Moni Shoua  2016-06-16   75  	struct rxe_bth *bth;
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   76  	__be32 crc;
8700e3e7c4857d28 Moni Shoua  2016-06-16   77  	int length;
8700e3e7c4857d28 Moni Shoua  2016-06-16   78  	int hdr_size = sizeof(struct udphdr) +
8700e3e7c4857d28 Moni Shoua  2016-06-16   79  		(skb->protocol == htons(ETH_P_IP) ?
8700e3e7c4857d28 Moni Shoua  2016-06-16   80  		sizeof(struct iphdr) : sizeof(struct ipv6hdr));
8700e3e7c4857d28 Moni Shoua  2016-06-16   81  	/* pseudo header buffer size is calculate using ipv6 header size since
8700e3e7c4857d28 Moni Shoua  2016-06-16   82  	 * it is bigger than ipv4
8700e3e7c4857d28 Moni Shoua  2016-06-16   83  	 */
8700e3e7c4857d28 Moni Shoua  2016-06-16   84  	u8 pshdr[sizeof(struct udphdr) +
8700e3e7c4857d28 Moni Shoua  2016-06-16   85  		sizeof(struct ipv6hdr) +
8700e3e7c4857d28 Moni Shoua  2016-06-16   86  		RXE_BTH_BYTES];
8700e3e7c4857d28 Moni Shoua  2016-06-16   87  
8700e3e7c4857d28 Moni Shoua  2016-06-16   88  	/* This seed is the result of computing a CRC with a seed of
8700e3e7c4857d28 Moni Shoua  2016-06-16   89  	 * 0xfffffff and 8 bytes of 0xff representing a masked LRH.
8700e3e7c4857d28 Moni Shoua  2016-06-16   90  	 */
8700e3e7c4857d28 Moni Shoua  2016-06-16  @91  	crc = 0xdebb20e3;
8700e3e7c4857d28 Moni Shoua  2016-06-16   92  
8700e3e7c4857d28 Moni Shoua  2016-06-16   93  	if (skb->protocol == htons(ETH_P_IP)) { /* IPv4 */
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   94  		struct iphdr *ip4h = NULL;
e231ff2c1bb74fd5 Bob Pearson 2021-06-29   95  
8700e3e7c4857d28 Moni Shoua  2016-06-16   96  		memcpy(pshdr, ip_hdr(skb), hdr_size);
8700e3e7c4857d28 Moni Shoua  2016-06-16   97  		ip4h = (struct iphdr *)pshdr;
8700e3e7c4857d28 Moni Shoua  2016-06-16   98  		udph = (struct udphdr *)(ip4h + 1);
8700e3e7c4857d28 Moni Shoua  2016-06-16   99  
8700e3e7c4857d28 Moni Shoua  2016-06-16  100  		ip4h->ttl = 0xff;
8700e3e7c4857d28 Moni Shoua  2016-06-16  101  		ip4h->check = CSUM_MANGLED_0;
8700e3e7c4857d28 Moni Shoua  2016-06-16  102  		ip4h->tos = 0xff;
8700e3e7c4857d28 Moni Shoua  2016-06-16  103  	} else {				/* IPv6 */
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  104  		struct ipv6hdr *ip6h = NULL;
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  105  
8700e3e7c4857d28 Moni Shoua  2016-06-16  106  		memcpy(pshdr, ipv6_hdr(skb), hdr_size);
8700e3e7c4857d28 Moni Shoua  2016-06-16  107  		ip6h = (struct ipv6hdr *)pshdr;
8700e3e7c4857d28 Moni Shoua  2016-06-16  108  		udph = (struct udphdr *)(ip6h + 1);
8700e3e7c4857d28 Moni Shoua  2016-06-16  109  
8700e3e7c4857d28 Moni Shoua  2016-06-16  110  		memset(ip6h->flow_lbl, 0xff, sizeof(ip6h->flow_lbl));
8700e3e7c4857d28 Moni Shoua  2016-06-16  111  		ip6h->priority = 0xf;
8700e3e7c4857d28 Moni Shoua  2016-06-16  112  		ip6h->hop_limit = 0xff;
8700e3e7c4857d28 Moni Shoua  2016-06-16  113  	}
8700e3e7c4857d28 Moni Shoua  2016-06-16  114  
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  115  	bth = (struct rxe_bth *)(udph + 1);
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  116  	memcpy(bth, pkt->hdr, RXE_BTH_BYTES);
8700e3e7c4857d28 Moni Shoua  2016-06-16  117  
8700e3e7c4857d28 Moni Shoua  2016-06-16  118  	/* exclude bth.resv8a */
8700e3e7c4857d28 Moni Shoua  2016-06-16  119  	bth->qpn |= cpu_to_be32(~BTH_QPN_MASK);
8700e3e7c4857d28 Moni Shoua  2016-06-16  120  
8700e3e7c4857d28 Moni Shoua  2016-06-16  121  	length = hdr_size + RXE_BTH_BYTES;
cee2688e3cd60e0d yonatanc    2017-04-20  122  	crc = rxe_crc32(pkt->rxe, crc, pshdr, length);
8700e3e7c4857d28 Moni Shoua  2016-06-16  123  
8700e3e7c4857d28 Moni Shoua  2016-06-16  124  	/* And finish to compute the CRC on the remainder of the headers. */
cee2688e3cd60e0d yonatanc    2017-04-20  125  	crc = rxe_crc32(pkt->rxe, crc, pkt->hdr + RXE_BTH_BYTES,
8700e3e7c4857d28 Moni Shoua  2016-06-16  126  			rxe_opcode[pkt->opcode].length - RXE_BTH_BYTES);
8700e3e7c4857d28 Moni Shoua  2016-06-16 @127  	return crc;
8700e3e7c4857d28 Moni Shoua  2016-06-16  128  }
0ce4db51163d271a Bob Pearson 2021-06-29  129  
0ce4db51163d271a Bob Pearson 2021-06-29  130  /**
0ce4db51163d271a Bob Pearson 2021-06-29  131   * rxe_icrc_check - Compute ICRC for a packet and compare to the ICRC
0ce4db51163d271a Bob Pearson 2021-06-29  132   *		    delivered in the packet.
46bb188d442e9494 Bob Pearson 2021-06-29  133   * @skb: packet buffer with packet info in skb->cb[] (receive path)
0ce4db51163d271a Bob Pearson 2021-06-29  134   *
46bb188d442e9494 Bob Pearson 2021-06-29  135   * Returns 0 if the ICRCs match or an error on failure
0ce4db51163d271a Bob Pearson 2021-06-29  136   */
0ce4db51163d271a Bob Pearson 2021-06-29  137  int rxe_icrc_check(struct sk_buff *skb)
0ce4db51163d271a Bob Pearson 2021-06-29  138  {
0ce4db51163d271a Bob Pearson 2021-06-29  139  	struct rxe_pkt_info *pkt = SKB_TO_PKT(skb);
0ce4db51163d271a Bob Pearson 2021-06-29  140  	__be32 *icrcp;
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  141  	__be32 packet_icrc;
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  142  	__be32 computed_icrc;
0ce4db51163d271a Bob Pearson 2021-06-29  143  
0ce4db51163d271a Bob Pearson 2021-06-29  144  	icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  145  	packet_icrc = *icrcp;
0ce4db51163d271a Bob Pearson 2021-06-29  146  
e231ff2c1bb74fd5 Bob Pearson 2021-06-29 @147  	computed_icrc = rxe_icrc_hdr(pkt, skb);
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  148  	computed_icrc = rxe_crc32(pkt->rxe, computed_icrc,
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  149  		(u8 *)payload_addr(pkt), payload_size(pkt) + bth_pad(pkt));
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  150  	computed_icrc = ~computed_icrc;
0ce4db51163d271a Bob Pearson 2021-06-29  151  
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  152  	if (unlikely(computed_icrc != packet_icrc)) {
0ce4db51163d271a Bob Pearson 2021-06-29  153  		if (skb->protocol == htons(ETH_P_IPV6))
0ce4db51163d271a Bob Pearson 2021-06-29  154  			pr_warn_ratelimited("bad ICRC from %pI6c\n",
0ce4db51163d271a Bob Pearson 2021-06-29  155  					    &ipv6_hdr(skb)->saddr);
0ce4db51163d271a Bob Pearson 2021-06-29  156  		else if (skb->protocol == htons(ETH_P_IP))
0ce4db51163d271a Bob Pearson 2021-06-29  157  			pr_warn_ratelimited("bad ICRC from %pI4\n",
0ce4db51163d271a Bob Pearson 2021-06-29  158  					    &ip_hdr(skb)->saddr);
0ce4db51163d271a Bob Pearson 2021-06-29  159  		else
0ce4db51163d271a Bob Pearson 2021-06-29  160  			pr_warn_ratelimited("bad ICRC from unknown\n");
0ce4db51163d271a Bob Pearson 2021-06-29  161  
0ce4db51163d271a Bob Pearson 2021-06-29  162  		return -EINVAL;
0ce4db51163d271a Bob Pearson 2021-06-29  163  	}
0ce4db51163d271a Bob Pearson 2021-06-29  164  
0ce4db51163d271a Bob Pearson 2021-06-29  165  	return 0;
0ce4db51163d271a Bob Pearson 2021-06-29  166  }
a142747477c2d184 Bob Pearson 2021-06-29  167  
46bb188d442e9494 Bob Pearson 2021-06-29  168  /**
46bb188d442e9494 Bob Pearson 2021-06-29  169   * rxe_icrc_generate - Compute ICRC for a packet.
46bb188d442e9494 Bob Pearson 2021-06-29  170   * @pkt: packet information
46bb188d442e9494 Bob Pearson 2021-06-29  171   * @skb: packet buffer
46bb188d442e9494 Bob Pearson 2021-06-29  172   */
a142747477c2d184 Bob Pearson 2021-06-29  173  void rxe_icrc_generate(struct rxe_pkt_info *pkt, struct sk_buff *skb)
a142747477c2d184 Bob Pearson 2021-06-29  174  {
a142747477c2d184 Bob Pearson 2021-06-29  175  	__be32 *icrcp;
e231ff2c1bb74fd5 Bob Pearson 2021-06-29  176  	__be32 icrc;
a142747477c2d184 Bob Pearson 2021-06-29  177  
a142747477c2d184 Bob Pearson 2021-06-29  178  	icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
a142747477c2d184 Bob Pearson 2021-06-29 @179  	icrc = rxe_icrc_hdr(pkt, skb);

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/rxe/rxe.h b/drivers/infiniband/sw/rxe/rxe.h
index 65a73c1c8b35..1bb3fb618bf5 100644
--- a/drivers/infiniband/sw/rxe/rxe.h
+++ b/drivers/infiniband/sw/rxe/rxe.h
@@ -14,7 +14,6 @@ 
 
 #include <linux/module.h>
 #include <linux/skbuff.h>
-#include <linux/crc32.h>
 
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_user_verbs.h>
diff --git a/drivers/infiniband/sw/rxe/rxe_icrc.c b/drivers/infiniband/sw/rxe/rxe_icrc.c
index e116c63d7b84..4f311798d682 100644
--- a/drivers/infiniband/sw/rxe/rxe_icrc.c
+++ b/drivers/infiniband/sw/rxe/rxe_icrc.c
@@ -4,34 +4,59 @@ 
  * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
  */
 
+#include <linux/crc32.h>
 #include "rxe.h"
 #include "rxe_loc.h"
 
 /**
- * rxe_crc32 - Compute incremental crc32 for a contiguous segment
+ * rxe_icrc_init - Initialize crypto function for computing crc32
+ * @rxe: rdma_rxe device object
+ *
+ * Returns 0 on success else an error
+ */
+int rxe_icrc_init(struct rxe_dev *rxe)
+{
+	struct crypto_shash *tfm;
+
+	tfm = crypto_alloc_shash("crc32", 0, 0);
+	if (IS_ERR(tfm)) {
+		pr_err("failed to init crc32 algorithm err:%ld\n",
+			       PTR_ERR(tfm));
+		return PTR_ERR(tfm);
+	}
+
+	rxe->tfm = tfm;
+
+	return 0;
+}
+
+/**
+ * rxe_crc32 - Compute cumulative crc32 for a contiguous segment
  * @rxe: rdma_rxe device object
  * @crc: starting crc32 value from previous segments
  * @addr: starting address of segment
  * @len: length of the segment in bytes
  *
- * Returns the crc32 checksum of the segment starting from crc.
+ * Returns the crc32 cumulative checksum including the segment starting
+ * from crc.
  */
-static u32 rxe_crc32(struct rxe_dev *rxe, u32 crc, void *addr, size_t len)
+static __be32 rxe_crc32(struct rxe_dev *rxe, __be32 crc, void *addr,
+			size_t len)
 {
-	u32 icrc;
+	__be32 icrc;
 	int err;
 
 	SHASH_DESC_ON_STACK(shash, rxe->tfm);
 
 	shash->tfm = rxe->tfm;
-	*(u32 *)shash_desc_ctx(shash) = crc;
+	*(__be32 *)shash_desc_ctx(shash) = crc;
 	err = crypto_shash_update(shash, addr, len);
 	if (unlikely(err)) {
 		pr_warn_ratelimited("failed crc calculation, err: %d\n", err);
 		return crc32_le(crc, addr, len);
 	}
 
-	icrc = *(u32 *)shash_desc_ctx(shash);
+	icrc = *(__be32 *)shash_desc_ctx(shash);
 	barrier_data(shash_desc_ctx(shash));
 
 	return icrc;
@@ -39,19 +64,16 @@  static u32 rxe_crc32(struct rxe_dev *rxe, u32 crc, void *addr, size_t len)
 
 /**
  * rxe_icrc_hdr - Compute a partial ICRC for the IB transport headers.
- * @pkt: Information about the current packet
- * @skb: The packet buffer
+ * @pkt: packet information
+ * @skb: packet buffer
  *
  * Returns the partial ICRC
  */
 static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
 {
-	unsigned int bth_offset = 0;
-	struct iphdr *ip4h = NULL;
-	struct ipv6hdr *ip6h = NULL;
 	struct udphdr *udph;
 	struct rxe_bth *bth;
-	int crc;
+	__be32 crc;
 	int length;
 	int hdr_size = sizeof(struct udphdr) +
 		(skb->protocol == htons(ETH_P_IP) ?
@@ -69,6 +91,8 @@  static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
 	crc = 0xdebb20e3;
 
 	if (skb->protocol == htons(ETH_P_IP)) { /* IPv4 */
+		struct iphdr *ip4h = NULL;
+
 		memcpy(pshdr, ip_hdr(skb), hdr_size);
 		ip4h = (struct iphdr *)pshdr;
 		udph = (struct udphdr *)(ip4h + 1);
@@ -77,6 +101,8 @@  static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
 		ip4h->check = CSUM_MANGLED_0;
 		ip4h->tos = 0xff;
 	} else {				/* IPv6 */
+		struct ipv6hdr *ip6h = NULL;
+
 		memcpy(pshdr, ipv6_hdr(skb), hdr_size);
 		ip6h = (struct ipv6hdr *)pshdr;
 		udph = (struct udphdr *)(ip6h + 1);
@@ -85,12 +111,9 @@  static u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb)
 		ip6h->priority = 0xf;
 		ip6h->hop_limit = 0xff;
 	}
-	udph->check = CSUM_MANGLED_0;
-
-	bth_offset += hdr_size;
 
-	memcpy(&pshdr[bth_offset], pkt->hdr, RXE_BTH_BYTES);
-	bth = (struct rxe_bth *)&pshdr[bth_offset];
+	bth = (struct rxe_bth *)(udph + 1);
+	memcpy(bth, pkt->hdr, RXE_BTH_BYTES);
 
 	/* exclude bth.resv8a */
 	bth->qpn |= cpu_to_be32(~BTH_QPN_MASK);
@@ -115,18 +138,18 @@  int rxe_icrc_check(struct sk_buff *skb)
 {
 	struct rxe_pkt_info *pkt = SKB_TO_PKT(skb);
 	__be32 *icrcp;
-	u32 pkt_icrc;
-	u32 icrc;
+	__be32 packet_icrc;
+	__be32 computed_icrc;
 
 	icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
-	pkt_icrc = be32_to_cpu(*icrcp);
+	packet_icrc = *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);
+	computed_icrc = rxe_icrc_hdr(pkt, skb);
+	computed_icrc = rxe_crc32(pkt->rxe, computed_icrc,
+		(u8 *)payload_addr(pkt), payload_size(pkt) + bth_pad(pkt));
+	computed_icrc = ~computed_icrc;
 
-	if (unlikely(icrc != pkt_icrc)) {
+	if (unlikely(computed_icrc != packet_icrc)) {
 		if (skb->protocol == htons(ETH_P_IPV6))
 			pr_warn_ratelimited("bad ICRC from %pI6c\n",
 					    &ipv6_hdr(skb)->saddr);
@@ -150,7 +173,7 @@  int rxe_icrc_check(struct sk_buff *skb)
 void rxe_icrc_generate(struct rxe_pkt_info *pkt, struct sk_buff *skb)
 {
 	__be32 *icrcp;
-	u32 icrc;
+	__be32 icrc;
 
 	icrcp = (__be32 *)(pkt->hdr + pkt->paylen - RXE_ICRC_SIZE);
 	icrc = rxe_icrc_hdr(pkt, skb);
diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h
index b08689b664ec..f98378f8ff31 100644
--- a/drivers/infiniband/sw/rxe/rxe_loc.h
+++ b/drivers/infiniband/sw/rxe/rxe_loc.h
@@ -193,6 +193,7 @@  int rxe_requester(void *arg);
 int rxe_responder(void *arg);
 
 /* rxe_icrc.c */
+int rxe_icrc_init(struct rxe_dev *rxe);
 int rxe_icrc_check(struct sk_buff *skb);
 void rxe_icrc_generate(struct rxe_pkt_info *pkt, struct sk_buff *skb);
 
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
index c223959ac174..f7b1a1f64c13 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
@@ -1154,7 +1154,6 @@  int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
 {
 	int err;
 	struct ib_device *dev = &rxe->ib_dev;
-	struct crypto_shash *tfm;
 
 	strscpy(dev->node_desc, "rxe", sizeof(dev->node_desc));
 
@@ -1173,13 +1172,9 @@  int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
 	if (err)
 		return err;
 
-	tfm = crypto_alloc_shash("crc32", 0, 0);
-	if (IS_ERR(tfm)) {
-		pr_err("failed to allocate crc algorithm err:%ld\n",
-		       PTR_ERR(tfm));
-		return PTR_ERR(tfm);
-	}
-	rxe->tfm = tfm;
+	err = rxe_icrc_init(rxe);
+	if (err)
+		return err;
 
 	err = ib_register_device(dev, ibdev_name, NULL);
 	if (err)