Skip to contentSkip to conversation

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

PATCH Applied Clément Léger 3 participants 4 messages Feb 10, 2025 – Feb 13, 2025 RISC-V

lore
Share & tools
lore
#0 lore raw

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
index c6ba750536c3..40ac72e407b6 100644
@@ -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
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Clément,

Quoted 13 lines · Clément Léger

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 +0 -0
index c6ba750536c3..40ac72e407b6 100644

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:

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

You can also add:

Thanks,

Alex

#2 lore raw
Quoted 34 lines · Alexandre Ghiti

Hi Clément,

Quoted 22 lines · Clément Léger

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/ renamed from arch/riscv/kernel/cpufeature.c +0 -0

cpufeature.c
index c6ba750536c3..40ac72e407b6 100644

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));
Quoted 3 lines

  }
    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:

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:

Thanks !

Clément

Quoted 5 lines

Thanks,

Alex

#3 lore raw
In reply to Clément Léger
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(), not memcmp(), use the former one to compare isa bitmaps.

---
 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