linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: mips/crc32 - fix the CRC32C implementation
@ 2024-10-20 18:02 Eric Biggers
  2024-10-20 18:32 ` Wentao Guan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Biggers @ 2024-10-20 18:02 UTC (permalink / raw)
  To: linux-crypto; +Cc: linux-mips, linux-kernel, Guan Wentao, WangYuli

From: Eric Biggers <ebiggers@google.com>

Commit ca459e5f826f ("crypto: mips/crc32 - Clean up useless assignment
operations") changed crc32c_mips_le_hw() to use the instructions that
use the "regular" CRC32 polynomial instead of the Castagnoli polynomial.
Therefore it can't be computing CRC32C values correctly anymore.

I haven't been successful in running a MIPS kernel in QEMU, but based on
code review this is the fix that is needed.

Fixes: ca459e5f826f ("crypto: mips/crc32 - Clean up useless assignment operations")
Cc: Guan Wentao <guanwentao@uniontech.com>
Cc: WangYuli <wangyuli@uniontech.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---

This is a regression in 6.12, so it should be fixed in a 6.12-rc.

 arch/mips/crypto/crc32-mips.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/mips/crypto/crc32-mips.c b/arch/mips/crypto/crc32-mips.c
index a7a1d43a1b2ca..90eacf00cfc31 100644
--- a/arch/mips/crypto/crc32-mips.c
+++ b/arch/mips/crypto/crc32-mips.c
@@ -121,24 +121,24 @@ static u32 crc32c_mips_le_hw(u32 crc_, const u8 *p, unsigned int len)
 
 	if (IS_ENABLED(CONFIG_64BIT)) {
 		for (; len >= sizeof(u64); p += sizeof(u64), len -= sizeof(u64)) {
 			u64 value = get_unaligned_le64(p);
 
-			CRC32(crc, value, d);
+			CRC32C(crc, value, d);
 		}
 
 		if (len & sizeof(u32)) {
 			u32 value = get_unaligned_le32(p);
 
-			CRC32(crc, value, w);
+			CRC32C(crc, value, w);
 			p += sizeof(u32);
 		}
 	} else {
 		for (; len >= sizeof(u32); len -= sizeof(u32)) {
 			u32 value = get_unaligned_le32(p);
 
-			CRC32(crc, value, w);
+			CRC32C(crc, value, w);
 			p += sizeof(u32);
 		}
 	}
 
 	if (len & sizeof(u16)) {

base-commit: 7fa4be6d6752512278c4cbf2d2745568626e7369
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re:[PATCH] crypto: mips/crc32 - fix the CRC32C implementation
  2024-10-20 18:02 [PATCH] crypto: mips/crc32 - fix the CRC32C implementation Eric Biggers
@ 2024-10-20 18:32 ` Wentao Guan
  2024-10-21  1:47 ` [PATCH] " WangYuli
  2024-10-26  7:04 ` Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Wentao Guan @ 2024-10-20 18:32 UTC (permalink / raw)
  To: Eric Biggers, linux-crypto
  Cc: linux-mips, linux-kernel, 王昱力

Very good catch.
Acked-by: Wentao Guan <guanwentao@uniontech.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: mips/crc32 - fix the CRC32C implementation
  2024-10-20 18:02 [PATCH] crypto: mips/crc32 - fix the CRC32C implementation Eric Biggers
  2024-10-20 18:32 ` Wentao Guan
@ 2024-10-21  1:47 ` WangYuli
  2024-10-26  7:04 ` Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: WangYuli @ 2024-10-21  1:47 UTC (permalink / raw)
  To: Eric Biggers, linux-crypto
  Cc: linux-mips, linux-kernel, Guan Wentao, herbert, davem, tsbogend

On 2024/10/21 02:02, Eric Biggers wrote:

> From: Eric Biggers <ebiggers@google.com>
>
> Commit ca459e5f826f ("crypto: mips/crc32 - Clean up useless assignment
> operations") changed crc32c_mips_le_hw() to use the instructions that
> use the "regular" CRC32 polynomial instead of the Castagnoli polynomial.
> Therefore it can't be computing CRC32C values correctly anymore.
>
> I haven't been successful in running a MIPS kernel in QEMU, but based on
> code review this is the fix that is needed.
>
> Fixes: ca459e5f826f ("crypto: mips/crc32 - Clean up useless assignment operations")
> Cc: Guan Wentao <guanwentao@uniontech.com>
> Cc: WangYuli <wangyuli@uniontech.com>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>
> This is a regression in 6.12, so it should be fixed in a 6.12-rc.
>
>   arch/mips/crypto/crc32-mips.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/mips/crypto/crc32-mips.c b/arch/mips/crypto/crc32-mips.c
> index a7a1d43a1b2ca..90eacf00cfc31 100644
> --- a/arch/mips/crypto/crc32-mips.c
> +++ b/arch/mips/crypto/crc32-mips.c
> @@ -121,24 +121,24 @@ static u32 crc32c_mips_le_hw(u32 crc_, const u8 *p, unsigned int len)
>   
>   	if (IS_ENABLED(CONFIG_64BIT)) {
>   		for (; len >= sizeof(u64); p += sizeof(u64), len -= sizeof(u64)) {
>   			u64 value = get_unaligned_le64(p);
>   
> -			CRC32(crc, value, d);
> +			CRC32C(crc, value, d);
>   		}
>   
>   		if (len & sizeof(u32)) {
>   			u32 value = get_unaligned_le32(p);
>   
> -			CRC32(crc, value, w);
> +			CRC32C(crc, value, w);
>   			p += sizeof(u32);
>   		}
>   	} else {
>   		for (; len >= sizeof(u32); len -= sizeof(u32)) {
>   			u32 value = get_unaligned_le32(p);
>   
> -			CRC32(crc, value, w);
> +			CRC32C(crc, value, w);
>   			p += sizeof(u32);
>   		}
>   	}
>   
>   	if (len & sizeof(u16)) {
>
> base-commit: 7fa4be6d6752512278c4cbf2d2745568626e7369

Ah...I apologize for the oversight that introduced this bug...And it's 
indeed a necessary fix.
Thanks,

Acked-by: WangYuli <wangyuli@uniontech.com>
-- 
WangYuli

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: mips/crc32 - fix the CRC32C implementation
  2024-10-20 18:02 [PATCH] crypto: mips/crc32 - fix the CRC32C implementation Eric Biggers
  2024-10-20 18:32 ` Wentao Guan
  2024-10-21  1:47 ` [PATCH] " WangYuli
@ 2024-10-26  7:04 ` Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2024-10-26  7:04 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-crypto, linux-mips, linux-kernel, guanwentao, wangyuli

Eric Biggers <ebiggers@kernel.org> wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Commit ca459e5f826f ("crypto: mips/crc32 - Clean up useless assignment
> operations") changed crc32c_mips_le_hw() to use the instructions that
> use the "regular" CRC32 polynomial instead of the Castagnoli polynomial.
> Therefore it can't be computing CRC32C values correctly anymore.
> 
> I haven't been successful in running a MIPS kernel in QEMU, but based on
> code review this is the fix that is needed.
> 
> Fixes: ca459e5f826f ("crypto: mips/crc32 - Clean up useless assignment operations")
> Cc: Guan Wentao <guanwentao@uniontech.com>
> Cc: WangYuli <wangyuli@uniontech.com>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> 
> This is a regression in 6.12, so it should be fixed in a 6.12-rc.
> 
> arch/mips/crypto/crc32-mips.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-26  7:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-20 18:02 [PATCH] crypto: mips/crc32 - fix the CRC32C implementation Eric Biggers
2024-10-20 18:32 ` Wentao Guan
2024-10-21  1:47 ` [PATCH] " WangYuli
2024-10-26  7:04 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).