[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aC2406qOlaI17_f3@gondor.apana.org.au>
Date: Wed, 21 May 2025 19:28:19 +0800
From: Herbert Xu <herbert@...dor.apana.org.au>
To: Bharat Bhushan <bbhushan2@...vell.com>
Cc: bbrezillon@...nel.org, schalla@...vell.com, davem@...emloft.net,
giovanni.cabiddu@...el.com, linux@...blig.org,
bharatb.linux@...il.com, linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org, stable@...r.kernel.org
Subject: Re: [PATCH 3/4 v3] crypto: octeontx2: Fix address alignment on CN10K
A0/A1 and OcteonTX2
On Wed, May 21, 2025 at 03:34:46PM +0530, Bharat Bhushan wrote:
>
> @@ -429,22 +431,51 @@ otx2_sg_info_create(struct pci_dev *pdev, struct otx2_cpt_req_info *req,
> return NULL;
> }
>
> - g_sz_bytes = ((req->in_cnt + 3) / 4) *
> - sizeof(struct otx2_cpt_sglist_component);
> - s_sz_bytes = ((req->out_cnt + 3) / 4) *
> - sizeof(struct otx2_cpt_sglist_component);
> + /* Allocate memory to meet below alignment requirement:
> + * ----------------------------------
> + * | struct otx2_cpt_inst_info |
> + * | (No alignment required) |
> + * | -----------------------------|
> + * | | padding for 8B alignment |
> + * |----------------------------------|
This should be updated to show that everything following this
is on an 128-byte boundary.
> + * | SG List Gather/Input memory |
> + * | Length = multiple of 32Bytes |
> + * | Alignment = 8Byte |
> + * |----------------------------------|
> + * | SG List Scatter/Output memory |
> + * | Length = multiple of 32Bytes |
> + * | Alignment = 8Byte |
> + * | (padding for below alignment) |
> + * | -----------------------------|
> + * | | padding for 32B alignment |
> + * |----------------------------------|
> + * | Result response memory |
> + * ----------------------------------
> + */
>
> - dlen = g_sz_bytes + s_sz_bytes + SG_LIST_HDR_SIZE;
> - align_dlen = ALIGN(dlen, align);
> - info_len = ALIGN(sizeof(*info), align);
> - total_mem_len = align_dlen + info_len + sizeof(union otx2_cpt_res_s);
> + info_len = sizeof(*info);
> +
> + g_len = ((req->in_cnt + 3) / 4) *
> + sizeof(struct otx2_cpt_sglist_component);
> + s_len = ((req->out_cnt + 3) / 4) *
> + sizeof(struct otx2_cpt_sglist_component);
> +
> + dlen = g_len + s_len + SG_LIST_HDR_SIZE;
> +
> + /* Allocate extra memory for SG and response address alignment */
> + total_mem_len = ALIGN(info_len, ARCH_DMA_MINALIGN) + dlen;
> + total_mem_len = ALIGN(total_mem_len, OTX2_CPT_DPTR_RPTR_ALIGN);
> + total_mem_len += (OTX2_CPT_RES_ADDR_ALIGN - 1) &
> + ~(OTX2_CPT_DPTR_RPTR_ALIGN - 1);
> + total_mem_len += sizeof(union otx2_cpt_res_s);
This calculation is wrong again. It should be:
total_mem_len = ALIGN(info_len, OTX2_CPT_DPTR_RPTR_ALIGN);
total_mem_len += (ARCH_DMA_MINALIGN - 1) &
~(OTX2_CPT_DPTR_RPTR_ALIGN - 1);
total_mem_len += ALIGN(dlen, OTX2_CPT_RES_ADDR_ALIGN);
total_mem_len += sizeof(union otx2_cpt_res_s);
Remember ALIGN may not actually give you extra memory. So if you
need to add memory for alignment padding, you will need to do it
by hand.
Cheers,
--
Email: Herbert Xu <herbert@...dor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Powered by blists - more mailing lists