diff mbox series

riscv: cpufeature: use bitmap_equal() instead of memcmp()

Message ID 20250210155615.1545738-1-cleger@rivosinc.com (mailing list archive)
State Accepted
Commit 1508ead3d2292555c02550f5512c9b0ff537aeb6
Headers show
Series riscv: cpufeature: use bitmap_equal() instead of memcmp() | expand

Checks

Context Check Description
bjorn/pre-ci_am success Success
bjorn/build-rv32-defconfig success build-rv32-defconfig
bjorn/build-rv64-clang-allmodconfig success build-rv64-clang-allmodconfig
bjorn/build-rv64-gcc-allmodconfig success build-rv64-gcc-allmodconfig
bjorn/build-rv64-nommu-k210-defconfig success build-rv64-nommu-k210-defconfig
bjorn/build-rv64-nommu-k210-virt success build-rv64-nommu-k210-virt
bjorn/checkpatch success checkpatch
bjorn/dtb-warn-rv64 success dtb-warn-rv64
bjorn/header-inline success header-inline
bjorn/kdoc success kdoc
bjorn/module-param success module-param
bjorn/verify-fixes success verify-fixes
bjorn/verify-signedoff success verify-signedoff

Commit Message

Clément Léger Feb. 10, 2025, 3:56 p.m. UTC
Comparison of bitmaps should be done using bitmap_equal(), not memcmp(),
use the former one to compare isa bitmaps.

Signed-off-by: Clément Léger <cleger@rivosinc.com>
---
 arch/riscv/kernel/cpufeature.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alexandre Ghiti Feb. 11, 2025, 7:41 a.m. UTC | #1
Hi Clément,

On 10/02/2025 16:56, Clément Léger wrote:
> Comparison of bitmaps should be done using bitmap_equal(), not memcmp(),
> use the former one to compare isa bitmaps.
>
> Signed-off-by: Clément Léger <cleger@rivosinc.com>
> ---
>   arch/riscv/kernel/cpufeature.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
> index c6ba750536c3..40ac72e407b6 100644
> --- a/arch/riscv/kernel/cpufeature.c
> +++ b/arch/riscv/kernel/cpufeature.c
> @@ -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:

Fixes: 625034abd52a8c ("riscv: add ISA extensions validation callback")

You can also add:

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Thanks,

Alex
Clément Léger Feb. 11, 2025, 8:15 a.m. UTC | #2
On 11/02/2025 08:41, Alexandre Ghiti wrote:
> Hi Clément,
> 
> On 10/02/2025 16:56, Clément Léger wrote:
>> Comparison of bitmaps should be done using bitmap_equal(), not memcmp(),
>> use the former one to compare isa bitmaps.
>>
>> Signed-off-by: Clément Léger <cleger@rivosinc.com>
>> ---
>>   arch/riscv/kernel/cpufeature.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/
>> cpufeature.c
>> index c6ba750536c3..40ac72e407b6 100644
>> --- a/arch/riscv/kernel/cpufeature.c
>> +++ b/arch/riscv/kernel/cpufeature.c
>> @@ -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:
> 
> 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.

> 
> You can also add:
> 
> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Thanks !

Clément

> 
> Thanks,
> 
> Alex
>
patchwork-bot+linux-riscv@kernel.org Feb. 13, 2025, 6:30 p.m. UTC | #3
Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Mon, 10 Feb 2025 16:56:14 +0100 you wrote:
> Comparison of bitmaps should be done using bitmap_equal(), not memcmp(),
> use the former one to compare isa bitmaps.
> 
> Signed-off-by: Clément Léger <cleger@rivosinc.com>
> ---
>  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!
diff mbox series

Patch

diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
index c6ba750536c3..40ac72e407b6 100644
--- a/arch/riscv/kernel/cpufeature.c
+++ b/arch/riscv/kernel/cpufeature.c
@@ -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)