* [PATCH] crypto: fsl_hash: fix flush dcache alignment in caam_hash()
@ 2025-02-21 7:05 blemouzy.ml
2025-02-28 4:17 ` Peng Fan
0 siblings, 1 reply; 4+ messages in thread
From: blemouzy.ml @ 2025-02-21 7:05 UTC (permalink / raw)
To: u-boot; +Cc: gaurav.jain, trini, Benjamin Lemouzy
From: Benjamin Lemouzy <blemouzy@centralp.fr>
Loading a FIT kernel image with hash hardware acceleration enabled
(CONFIG_SHA_HW_ACCEL=y) displays the following CACHE warning:
[...]
Trying 'kernel-1' kernel subimage
[...]
Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
range [16000128, 1673fae8]
[...]
Trying 'ramdisk-1' ramdisk subimage
[...]
Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
range [1676d6d4, 1737a5d4]
[...]
Trying 'fdt-imx6q-xxx.dtb' fdt subimage
[...]
Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
range [1673fbdc, 1674b0dc]
[...]
This patch fixes it.
Tested on:
- i.MX 6 custom board
- LS1021A custom board
Signed-off-by: Benjamin Lemouzy <blemouzy@centralp.fr>
---
drivers/crypto/fsl/fsl_hash.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/fsl/fsl_hash.c b/drivers/crypto/fsl/fsl_hash.c
index 79b32e2627..b721c86609 100644
--- a/drivers/crypto/fsl/fsl_hash.c
+++ b/drivers/crypto/fsl/fsl_hash.c
@@ -183,6 +183,7 @@ int caam_hash(const unsigned char *pbuf, unsigned int buf_len,
{
int ret = 0;
uint32_t *desc;
+ unsigned long pbuf_aligned;
unsigned int size;
desc = malloc_cache_aligned(sizeof(int) * MAX_CAAM_DESCSIZE);
@@ -191,8 +192,9 @@ int caam_hash(const unsigned char *pbuf, unsigned int buf_len,
return -ENOMEM;
}
- size = ALIGN(buf_len, ARCH_DMA_MINALIGN);
- flush_dcache_range((unsigned long)pbuf, (unsigned long)pbuf + size);
+ pbuf_aligned = ALIGN_DOWN((unsigned long)pbuf, ARCH_DMA_MINALIGN);
+ size = ALIGN(buf_len + ((unsigned long)pbuf - pbuf_aligned), ARCH_DMA_MINALIGN);
+ flush_dcache_range(pbuf_aligned, pbuf_aligned + size);
inline_cnstr_jobdesc_hash(desc, pbuf, buf_len, pout,
driver_hash[algo].alg_type,
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] crypto: fsl_hash: fix flush dcache alignment in caam_hash()
2025-02-21 7:05 [PATCH] crypto: fsl_hash: fix flush dcache alignment in caam_hash() blemouzy.ml
@ 2025-02-28 4:17 ` Peng Fan
2025-02-28 8:00 ` Benjamin Lemouzy
0 siblings, 1 reply; 4+ messages in thread
From: Peng Fan @ 2025-02-28 4:17 UTC (permalink / raw)
To: blemouzy.ml; +Cc: u-boot, gaurav.jain, trini, Benjamin Lemouzy
Hi Benjamin,
On Fri, Feb 21, 2025 at 08:05:01AM +0100, blemouzy.ml@gmail.com wrote:
>From: Benjamin Lemouzy <blemouzy@centralp.fr>
>
>Loading a FIT kernel image with hash hardware acceleration enabled
>(CONFIG_SHA_HW_ACCEL=y) displays the following CACHE warning:
Sorry for my lazyness, the following patch should be able to solve your issue.
I will prepare a PR soon.
https://patchwork.ozlabs.org/project/uboot/patch/1bd862e53b50825f6030bf9f212127c776fff881.camel@googlemail.com/
Thanks,
Peng
>
> [...]
> Trying 'kernel-1' kernel subimage
> [...]
> Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
>range [16000128, 1673fae8]
> [...]
> Trying 'ramdisk-1' ramdisk subimage
> [...]
> Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
>range [1676d6d4, 1737a5d4]
> [...]
> Trying 'fdt-imx6q-xxx.dtb' fdt subimage
> [...]
> Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
>range [1673fbdc, 1674b0dc]
> [...]
>
>This patch fixes it.
>
>Tested on:
>- i.MX 6 custom board
>- LS1021A custom board
>
>Signed-off-by: Benjamin Lemouzy <blemouzy@centralp.fr>
>---
> drivers/crypto/fsl/fsl_hash.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/crypto/fsl/fsl_hash.c b/drivers/crypto/fsl/fsl_hash.c
>index 79b32e2627..b721c86609 100644
>--- a/drivers/crypto/fsl/fsl_hash.c
>+++ b/drivers/crypto/fsl/fsl_hash.c
>@@ -183,6 +183,7 @@ int caam_hash(const unsigned char *pbuf, unsigned int buf_len,
> {
> int ret = 0;
> uint32_t *desc;
>+ unsigned long pbuf_aligned;
> unsigned int size;
>
> desc = malloc_cache_aligned(sizeof(int) * MAX_CAAM_DESCSIZE);
>@@ -191,8 +192,9 @@ int caam_hash(const unsigned char *pbuf, unsigned int buf_len,
> return -ENOMEM;
> }
>
>- size = ALIGN(buf_len, ARCH_DMA_MINALIGN);
>- flush_dcache_range((unsigned long)pbuf, (unsigned long)pbuf + size);
>+ pbuf_aligned = ALIGN_DOWN((unsigned long)pbuf, ARCH_DMA_MINALIGN);
>+ size = ALIGN(buf_len + ((unsigned long)pbuf - pbuf_aligned), ARCH_DMA_MINALIGN);
>+ flush_dcache_range(pbuf_aligned, pbuf_aligned + size);
>
> inline_cnstr_jobdesc_hash(desc, pbuf, buf_len, pout,
> driver_hash[algo].alg_type,
>--
>2.43.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] crypto: fsl_hash: fix flush dcache alignment in caam_hash()
2025-02-28 4:17 ` Peng Fan
@ 2025-02-28 8:00 ` Benjamin Lemouzy
2025-03-03 4:03 ` Peng Fan
0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Lemouzy @ 2025-02-28 8:00 UTC (permalink / raw)
To: Peng Fan; +Cc: u-boot, gaurav.jain, trini, Benjamin Lemouzy
Hi Peng,
On Fri, 28 Feb 2025 12:17:56 +0800
Peng Fan <peng.fan@oss.nxp.com> wrote:
> Hi Benjamin,
>
> On Fri, Feb 21, 2025 at 08:05:01AM +0100, blemouzy.ml@gmail.com wrote:
> >From: Benjamin Lemouzy <blemouzy@centralp.fr>
> >
> >Loading a FIT kernel image with hash hardware acceleration enabled
> >(CONFIG_SHA_HW_ACCEL=y) displays the following CACHE warning:
>
> Sorry for my lazyness, the following patch should be able to solve
> your issue. I will prepare a PR soon.
> https://patchwork.ozlabs.org/project/uboot/patch/1bd862e53b50825f6030bf9f212127c776fff881.camel@googlemail.com/
I just tested the suggested patch and it's not working:
## Loading kernel from FIT Image at 16000000 ...
Using 'conf-imx6q-xxx.dtb' configuration
Trying 'kernel-1' kernel subimage
Description: Linux kernel
Type: Kernel Image
Compression: uncompressed
Data Start: 0x16000128
Data Size: 7600544 Bytes = 7.2 MiB
Architecture: ARM
OS: Linux
Load Address: 0x10008000
Entry Point: 0x10008000
Hash algo: sha256
Hash value: a664f6c4d4ac97e2d867b8ee4f38cf934a48f99c65f19f824162b7ca077cb0d9
Verifying Hash Integrity ... sha256+ OK
## Loading ramdisk from FIT Image at 16000000 ...
Using 'conf-imx6q-xxx.dtb' configuration
Trying 'ramdisk-1' ramdisk subimage
Description: ctp-image-base-initramfs
Type: RAMDisk Image
Compression: uncompressed
Data Start: 0x1676d6d4
Data Size: 12635898 Bytes = 12.1 MiB
Architecture: ARM
OS: Linux
Load Address: 0x13000000
Entry Point: unavailable
Hash algo: sha256
Hash value: e1fe9087261f33679b95cd82b387317fa31b58f6365406fad1df1f27d46923e9
Verifying Hash Integrity ... sha256CAAM was not setup properly or it is faulty
error!
Bad hash value for 'hash-1' hash node in 'ramdisk-1' image node
Bad Data Hash
Ramdisk image is corrupt or invalid
Benjamin
> Thanks,
> Peng
> >
> > [...]
> > Trying 'kernel-1' kernel subimage
> > [...]
> > Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
> >range [16000128, 1673fae8]
> > [...]
> > Trying 'ramdisk-1' ramdisk subimage
> > [...]
> > Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
> >range [1676d6d4, 1737a5d4]
> > [...]
> > Trying 'fdt-imx6q-xxx.dtb' fdt subimage
> > [...]
> > Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
> >range [1673fbdc, 1674b0dc]
> > [...]
> >
> >This patch fixes it.
> >
> >Tested on:
> >- i.MX 6 custom board
> >- LS1021A custom board
> >
> >Signed-off-by: Benjamin Lemouzy <blemouzy@centralp.fr>
> >---
> > drivers/crypto/fsl/fsl_hash.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> >diff --git a/drivers/crypto/fsl/fsl_hash.c
> >b/drivers/crypto/fsl/fsl_hash.c index 79b32e2627..b721c86609 100644
> >--- a/drivers/crypto/fsl/fsl_hash.c
> >+++ b/drivers/crypto/fsl/fsl_hash.c
> >@@ -183,6 +183,7 @@ int caam_hash(const unsigned char *pbuf,
> >unsigned int buf_len,
> > {
> > int ret = 0;
> > uint32_t *desc;
> >+ unsigned long pbuf_aligned;
> > unsigned int size;
> >
> > desc = malloc_cache_aligned(sizeof(int) *
> > MAX_CAAM_DESCSIZE);
> >@@ -191,8 +192,9 @@ int caam_hash(const unsigned char *pbuf,
> >unsigned int buf_len,
> > return -ENOMEM;
> > }
> >
> >- size = ALIGN(buf_len, ARCH_DMA_MINALIGN);
> >- flush_dcache_range((unsigned long)pbuf, (unsigned long)pbuf
> >+ size);
> >+ pbuf_aligned = ALIGN_DOWN((unsigned long)pbuf,
> >ARCH_DMA_MINALIGN);
> >+ size = ALIGN(buf_len + ((unsigned long)pbuf -
> >pbuf_aligned), ARCH_DMA_MINALIGN);
> >+ flush_dcache_range(pbuf_aligned, pbuf_aligned + size);
> >
> > inline_cnstr_jobdesc_hash(desc, pbuf, buf_len, pout,
> > driver_hash[algo].alg_type,
> >--
> >2.43.0
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] crypto: fsl_hash: fix flush dcache alignment in caam_hash()
2025-02-28 8:00 ` Benjamin Lemouzy
@ 2025-03-03 4:03 ` Peng Fan
0 siblings, 0 replies; 4+ messages in thread
From: Peng Fan @ 2025-03-03 4:03 UTC (permalink / raw)
To: Benjamin Lemouzy; +Cc: u-boot, gaurav.jain, trini, Benjamin Lemouzy
On Fri, Feb 28, 2025 at 09:00:28AM +0100, Benjamin Lemouzy wrote:
>Hi Peng,
>
>On Fri, 28 Feb 2025 12:17:56 +0800
>Peng Fan <peng.fan@oss.nxp.com> wrote:
>
>> Hi Benjamin,
>>
>> On Fri, Feb 21, 2025 at 08:05:01AM +0100, blemouzy.ml@gmail.com wrote:
>> >From: Benjamin Lemouzy <blemouzy@centralp.fr>
>> >
>> >Loading a FIT kernel image with hash hardware acceleration enabled
>> >(CONFIG_SHA_HW_ACCEL=y) displays the following CACHE warning:
>>
>> Sorry for my lazyness, the following patch should be able to solve
>> your issue. I will prepare a PR soon.
>> https://patchwork.ozlabs.org/project/uboot/patch/1bd862e53b50825f6030bf9f212127c776fff881.camel@googlemail.com/
>
>I just tested the suggested patch and it's not working:
Thanks for help testing.
Thanks,
Peng
>
> ## Loading kernel from FIT Image at 16000000 ...
> Using 'conf-imx6q-xxx.dtb' configuration
> Trying 'kernel-1' kernel subimage
> Description: Linux kernel
> Type: Kernel Image
> Compression: uncompressed
> Data Start: 0x16000128
> Data Size: 7600544 Bytes = 7.2 MiB
> Architecture: ARM
> OS: Linux
> Load Address: 0x10008000
> Entry Point: 0x10008000
> Hash algo: sha256
> Hash value: a664f6c4d4ac97e2d867b8ee4f38cf934a48f99c65f19f824162b7ca077cb0d9
> Verifying Hash Integrity ... sha256+ OK
> ## Loading ramdisk from FIT Image at 16000000 ...
> Using 'conf-imx6q-xxx.dtb' configuration
> Trying 'ramdisk-1' ramdisk subimage
> Description: ctp-image-base-initramfs
> Type: RAMDisk Image
> Compression: uncompressed
> Data Start: 0x1676d6d4
> Data Size: 12635898 Bytes = 12.1 MiB
> Architecture: ARM
> OS: Linux
> Load Address: 0x13000000
> Entry Point: unavailable
> Hash algo: sha256
> Hash value: e1fe9087261f33679b95cd82b387317fa31b58f6365406fad1df1f27d46923e9
> Verifying Hash Integrity ... sha256CAAM was not setup properly or it is faulty
> error!
> Bad hash value for 'hash-1' hash node in 'ramdisk-1' image node
> Bad Data Hash
> Ramdisk image is corrupt or invalid
>
>Benjamin
>
>> Thanks,
>> Peng
>> >
>> > [...]
>> > Trying 'kernel-1' kernel subimage
>> > [...]
>> > Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
>> >range [16000128, 1673fae8]
>> > [...]
>> > Trying 'ramdisk-1' ramdisk subimage
>> > [...]
>> > Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
>> >range [1676d6d4, 1737a5d4]
>> > [...]
>> > Trying 'fdt-imx6q-xxx.dtb' fdt subimage
>> > [...]
>> > Verifying Hash Integrity ... sha256CACHE: Misaligned operation at
>> >range [1673fbdc, 1674b0dc]
>> > [...]
>> >
>> >This patch fixes it.
>> >
>> >Tested on:
>> >- i.MX 6 custom board
>> >- LS1021A custom board
>> >
>> >Signed-off-by: Benjamin Lemouzy <blemouzy@centralp.fr>
>> >---
>> > drivers/crypto/fsl/fsl_hash.c | 6 ++++--
>> > 1 file changed, 4 insertions(+), 2 deletions(-)
>> >
>> >diff --git a/drivers/crypto/fsl/fsl_hash.c
>> >b/drivers/crypto/fsl/fsl_hash.c index 79b32e2627..b721c86609 100644
>> >--- a/drivers/crypto/fsl/fsl_hash.c
>> >+++ b/drivers/crypto/fsl/fsl_hash.c
>> >@@ -183,6 +183,7 @@ int caam_hash(const unsigned char *pbuf,
>> >unsigned int buf_len,
>> > {
>> > int ret = 0;
>> > uint32_t *desc;
>> >+ unsigned long pbuf_aligned;
>> > unsigned int size;
>> >
>> > desc = malloc_cache_aligned(sizeof(int) *
>> > MAX_CAAM_DESCSIZE);
>> >@@ -191,8 +192,9 @@ int caam_hash(const unsigned char *pbuf,
>> >unsigned int buf_len,
>> > return -ENOMEM;
>> > }
>> >
>> >- size = ALIGN(buf_len, ARCH_DMA_MINALIGN);
>> >- flush_dcache_range((unsigned long)pbuf, (unsigned long)pbuf
>> >+ size);
>> >+ pbuf_aligned = ALIGN_DOWN((unsigned long)pbuf,
>> >ARCH_DMA_MINALIGN);
>> >+ size = ALIGN(buf_len + ((unsigned long)pbuf -
>> >pbuf_aligned), ARCH_DMA_MINALIGN);
>> >+ flush_dcache_range(pbuf_aligned, pbuf_aligned + size);
>> >
>> > inline_cnstr_jobdesc_hash(desc, pbuf, buf_len, pout,
>> > driver_hash[algo].alg_type,
>> >--
>> >2.43.0
>> >
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-03 2:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-21 7:05 [PATCH] crypto: fsl_hash: fix flush dcache alignment in caam_hash() blemouzy.ml
2025-02-28 4:17 ` Peng Fan
2025-02-28 8:00 ` Benjamin Lemouzy
2025-03-03 4:03 ` Peng Fan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.