Re: [PATCH net-next 09/10] nvme-tcp: use crc32c() and skb_copy_and_crc32c_datagram_iter()

From: Christoph Hellwig
Date: Fri May 16 2025 - 00:36:19 EST


On Sat, May 10, 2025 at 05:41:09PM -0700, Eric Biggers wrote:
> +static inline void nvme_tcp_ddgst_init(u32 *crcp)
> {
> + *crcp = ~0;
> }

This helper looks really odd. It coud just return the value, or
we could just assign it there using a seed define, e.g. this is what
XFS does:

#define XFS_CRC_SEED (~(uint32_t)0)

nd that might in fact be worth lifting to common code with a good
comment on why all-d is used as the typical crc32 seed.

> +static inline void nvme_tcp_ddgst_final(u32 *crcp, __le32 *ddgst)
> {
> + *ddgst = cpu_to_le32(~*crcp);
> +}

Just return the big endian version calculated here?

> +static inline void nvme_tcp_hdgst(void *pdu, size_t len)
> +{
> + put_unaligned_le32(~crc32c(~0, pdu, len), pdu + len);
> }

This could also use the seed define mentioned above.

> recv_digest = *(__le32 *)(pdu + hdr->hlen);
> - nvme_tcp_hdgst(queue->rcv_hash, pdu, pdu_len);
> + nvme_tcp_hdgst(pdu, pdu_len);
> exp_digest = *(__le32 *)(pdu + hdr->hlen);
> if (recv_digest != exp_digest) {

This code looks really weird, as it samples the on-the-wire digest
first and then overwrites it. I'd expect to just check the on-the-wire
on against one calculated in a local variable.

Sagi, any idea what is going on here?

Otherwise this looks great. It's always good to get rid of the
horrendous crypto API calls.