From mboxrd@z Thu Jan 1 00:00:00 1970 From: Clemens Gruber Date: Fri, 5 Jan 2018 14:02:15 +0100 Subject: [U-Boot] [PATCH v2] crypto/fsl: fix BLOB encapsulation and decapsulation In-Reply-To: References: <1515103017-21433-1-git-send-email-festevam@gmail.com> Message-ID: <20180105130215.GA18316@archie.localdomain> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Sumit, Fabio, York, On Fri, Jan 05, 2018 at 06:47:36AM +0000, Sumit Garg wrote: > Hi Clemens, York, Fabio, > > > -----Original Message----- > > From: U-Boot [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Fabio > > Estevam > > Sent: Friday, January 05, 2018 3:27 AM > > To: York Sun > > Cc: Breno Matheus Lima ; u-boot at lists.denx.de; > > clemens.gruber at pqgruber.com; Fabio Estevam > > Subject: [U-Boot] [PATCH v2] crypto/fsl: fix BLOB encapsulation and > > decapsulation > > > > > > > > > int blob_decap(u8 *key_mod, u8 *src, u8 *dst, u32 len) { > > - int ret, i = 0; > > + ALLOC_CACHE_ALIGN_BUFFER(u8, aligned_key_mod, 16); > > + u8 *aligned_src, *aligned_dst; > > + int ret, size, i = 0; > > u32 *desc; > > > > printf("\nDecapsulating blob to get data\n"); > > - desc = malloc(sizeof(int) * MAX_CAAM_DESCSIZE); > > + desc = malloc_cache_aligned(sizeof(int) * MAX_CAAM_DESCSIZE); > > if (!desc) { > > debug("Not enough memory for descriptor allocation\n"); > > - return -1; > > + return -ENOMEM; > > } > > > > - inline_cnstr_jobdesc_blob_decap(desc, key_mod, src, dst, len); > > + aligned_src = malloc_cache_aligned(BLOB_SIZE(len)); > > + aligned_dst = malloc_cache_aligned(len); > > Please don't use malloc here as these blob_encap and blob_decap commands are used to blobify or deblobify images of maximum sizes upto 32 MB. > > But u-boot malloc pool is of size: > > /* Size of malloc() pool */ > #define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + 2048 * 1024) > > So please remove malloc from this patch for source and destination images as it will fail for larger images. I could use ALLOC_CACHE_ALIGN_BUFFER to store the aligned_src and _dst buffers on the stack instead of the malloc pool. Or would you rather remove the copying and require the caller of blob_encap/_decap to pass correctly aligned addresses? York: Should I send a v3 or a fixup patch ontop of v2. Thanks, Clemens