All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: x86: simplify kvm_vector_to_index()
@ 2025-07-20  1:58 Yury Norov
  2025-08-19 23:12 ` Sean Christopherson
  0 siblings, 1 reply; 6+ messages in thread
From: Yury Norov @ 2025-07-20  1:58 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, H. Peter Anvin, x86, kvm,
	linux-kernel
  Cc: Yury Norov

Use find_nth_bit() and make the function almost a one-liner.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 arch/x86/kvm/lapic.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 73418dc0ebb2..6c4ec016de6a 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1106,16 +1106,10 @@ EXPORT_SYMBOL_GPL(kvm_apic_match_dest);
 int kvm_vector_to_index(u32 vector, u32 dest_vcpus,
 		       const unsigned long *bitmap, u32 bitmap_size)
 {
-	u32 mod;
-	int i, idx = -1;
-
-	mod = vector % dest_vcpus;
-
-	for (i = 0; i <= mod; i++) {
-		idx = find_next_bit(bitmap, bitmap_size, idx + 1);
-		BUG_ON(idx == bitmap_size);
-	}
+	u32 mod = vector % dest_vcpus;
+	int idx = find_nth_bit(bitmap, bitmap_size, mod);
 
+	BUG_ON(idx >= bitmap_size);
 	return idx;
 }
 
-- 
2.43.0


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

end of thread, other threads:[~2025-08-20 14:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-20  1:58 [PATCH] kvm: x86: simplify kvm_vector_to_index() Yury Norov
2025-08-19 23:12 ` Sean Christopherson
2025-08-20 13:42   ` Yury Norov
2025-08-20 14:01     ` Juergen Gross
2025-08-20 14:12       ` Yury Norov
2025-08-20 14:19         ` Jürgen Groß

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.