diff mbox series

KVM: arm64: Convert kvm_mpidr_index() to bitmap_gather()

Message ID 20240502154247.3012042-1-maz@kernel.org (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: Convert kvm_mpidr_index() to bitmap_gather() | expand

Commit Message

Marc Zyngier May 2, 2024, 3:42 p.m. UTC
Linux 6.9 has introduced new bitmap manipulation helpers, with
bitmap_gather() being of special interest, as it does exactly
what kvm_mpidr_index() is already doing.

Make the latter a wrapper around the former.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/include/asm/kvm_host.h | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

Comments

Oliver Upton May 2, 2024, 5:06 p.m. UTC | #1
On Thu, May 02, 2024 at 04:42:47PM +0100, Marc Zyngier wrote:
> Linux 6.9 has introduced new bitmap manipulation helpers, with
> bitmap_gather() being of special interest, as it does exactly
> what kvm_mpidr_index() is already doing.

Ooo, that's a handy one!

> Make the latter a wrapper around the former.
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>

Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Marc Zyngier May 3, 2024, 1:35 p.m. UTC | #2
On Thu, 02 May 2024 16:42:47 +0100, Marc Zyngier wrote:
> Linux 6.9 has introduced new bitmap manipulation helpers, with
> bitmap_gather() being of special interest, as it does exactly
> what kvm_mpidr_index() is already doing.
> 
> Make the latter a wrapper around the former.
> 
> 
> [...]

Applied to next, thanks!

[1/1] KVM: arm64: Convert kvm_mpidr_index() to bitmap_gather()
      commit: 838d992b84486311e6039170d28b79a7a0633f06

Cheers,

	M.
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 23a117cb3e50..fe94e96dced8 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -221,20 +221,10 @@  struct kvm_mpidr_data {
 
 static inline u16 kvm_mpidr_index(struct kvm_mpidr_data *data, u64 mpidr)
 {
-	unsigned long mask = data->mpidr_mask;
-	u64 aff = mpidr & MPIDR_HWID_BITMASK;
-	int nbits, bit, bit_idx = 0;
-	u16 index = 0;
+	unsigned long index = 0, mask = data->mpidr_mask;
+	unsigned long aff = mpidr & MPIDR_HWID_BITMASK;
 
-	/*
-	 * If this looks like RISC-V's BEXT or x86's PEXT
-	 * instructions, it isn't by accident.
-	 */
-	nbits = fls(mask);
-	for_each_set_bit(bit, &mask, nbits) {
-		index |= (aff & BIT(bit)) >> (bit - bit_idx);
-		bit_idx++;
-	}
+	bitmap_gather(&index, &aff, &mask, fls(mask));
 
 	return index;
 }