riscv: cpufeature: use bitmap_equal() instead of memcmp()
PATCH 1/1 riscv: cpufeature: use bitmap_equal() instead of memcmp()
Comparison of bitmaps should be done using bitmap_equal(), not memcmp(), use the former one to compare isa bitmaps.
--- arch/riscv/kernel/cpufeature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cpufeature.c +1 -1
@@ -479,7 +479,7 @@ static void __init riscv_resolve_isa(unsigned long *source_isa,if (bit <RISCV_ISA_EXT_BASE ) *this_hwcap |= isa2hwcap[bit]; } - }while (loop &&memcmp (prev_resolved_isa, resolved_isa,sizeof (prev_resolved_isa))); + }while (loop && !bitmap_equal (prev_resolved_isa, resolved_isa,RISCV_ISA_EXT_MAX )); }static void __init match_isa_ext (const char *name,const char *name_end,unsigned long *bitmap)
Signature · 1 line
2.47.2
Hi Clément,
Quoted 13 lines · Clément Léger
Comparison of bitmaps should be done using
bitmap_equal(), notmemcmp(), use the former one to compare isa bitmaps.Signed-off-by Clément Léger <[email protected]>--- arch/riscv/kernel/cpufeature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/kernel/cpufeature.c +0
-0
arch/riscv/kernel/cpufeature.c static void __init riscv_resolve_isa(unsigned long *source_isa, · line 485
Quoted 8 lines
arch/riscv/kernel/cpufeature.c +1
-1@@ -479,7 +479,7 @@ static void __init riscv_resolve_isa(unsigned long *source_isa,if (bit <RISCV_ISA_EXT_BASE ) *this_hwcap |= isa2hwcap[bit]; } - }while (loop &&memcmp (prev_resolved_isa, resolved_isa,sizeof (prev_resolved_isa))); + }while (loop && !bitmap_equal (prev_resolved_isa, resolved_isa,RISCV_ISA_EXT_MAX )); }static void __init match_isa_ext (const char *name,const char *name_end,unsigned long *bitmap)
Since bitmap does not guarantee the value of the 'extra' bits (https://elixir.bootlin.com/linux/v6.13.1/source/lib/bitmap.c#L24), this is a fix so I would add a Fixes tag:
You can also add:
Thanks,
Alex
Quoted 34 lines · Alexandre Ghiti
Hi Clément,
Quoted 22 lines · Clément Léger
Comparison of bitmaps should be done using
bitmap_equal(), notmemcmp(), use the former one to compare isa bitmaps.Signed-off-by Clément Léger <[email protected]>---
arch/riscv/kernel/cpufeature.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/kernel/ renamed from arch/riscv/kernel/cpufeature.c +0
-0
cpufeature.c
indexc6ba750536c3..40ac72e407b6100644arch/riscv/kernel/cpufeature.c +1
-1@@ -479,7 +479,7 @@ static void __init riscv_resolve_isa(unsigned long *source_isa, if (bit < RISCV_ISA_EXT_BASE) *this_hwcap |= isa2hwcap[bit]; } - } while (loop && memcmp(prev_resolved_isa, resolved_isa, sizeof(prev_resolved_isa))); + } while (loop && !bitmap_equal(prev_resolved_isa, resolved_isa,RISCV_ISA_EXT_MAX ));Quoted 3 lines
}
static void__initmatch_isa_ext(const char *name, const char *name_end, unsigned long *bitmap)Since bitmap does not guarantee the value of the 'extra' bits (https://
elixir.bootlin.com/linux/v6.13.1/source/lib/bitmap.c#L24), this is a fix so I would add a Fixes tag:
Quoted 1 line
Fixes 625034abd52a8c ("riscv: add ISA extensions validation callback")
Yeah, I wasn't sure since it does not fix anything per se. We aligned the ISA size to a multiple of 64 (128) so we actually do not have any extra undefined bits. But I agree that it's better to track it correctly as a fix.
That makes me think that we could actually size RISCV_ISA_EXT_MAX to be exactly the number of ISA extensions we support rather than a larger arbitrary value.
Quoted 4 lines
You can also add:
Reviewed-by Alexandre Ghiti <[email protected]>
Thanks !
Clément
Quoted 5 lines
Thanks,
Alex
This patch was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <[email protected]>:
Quoted 7 lines · On Mon, 10 Feb 2025 16:56:14 +0100 you wrote:
Comparison of bitmaps should be done using
bitmap_equal(), notmemcmp(), use the former one to compare isa bitmaps.Signed-off-by Clément Léger <[email protected]>--- arch/riscv/kernel/cpufeature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Here is the summary with links:
- riscv: cpufeature: use bitmap_equal() instead of memcmp()
https://git.kernel.org/riscv/c/1508ead3d229
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html