linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] KVM: PPC: use for_each_set_bit() macro where appropriate
@ 2025-07-17 19:24 Yury Norov
  2025-07-17 19:24 ` [PATCH 1/3] KVM: PPC: simplify kvmppc_core_prepare_to_enter() Yury Norov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Yury Norov @ 2025-07-17 19:24 UTC (permalink / raw)
  To: Madhavan Srinivasan, Nicholas Piggin, Michael Ellerman,
	Christophe Leroy, kvm, linux-kernel
  Cc: Yury Norov

From: Yury Norov (NVIDIA) <yury.norov@gmail.com>

Some functions in KVM/PPC layer opencode for_each_set_bit() macro. Fix
it and simplify the logic. 

Yury Norov (NVIDIA) (3):
  KVM: PPC: simplify kvmppc_core_prepare_to_enter()
  KVM: PPC: simplify kvmppc_core_check_exceptions()
  KVM: PPC: use for_each_set_bit() in IRQ_check()

 arch/powerpc/kvm/book3s.c | 7 +------
 arch/powerpc/kvm/booke.c  | 8 +-------
 arch/powerpc/kvm/mpic.c   | 8 ++------
 3 files changed, 4 insertions(+), 19 deletions(-)

-- 
2.43.0


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

* [PATCH 1/3] KVM: PPC: simplify kvmppc_core_prepare_to_enter()
  2025-07-17 19:24 [PATCH 0/3] KVM: PPC: use for_each_set_bit() macro where appropriate Yury Norov
@ 2025-07-17 19:24 ` Yury Norov
  2025-07-17 19:24 ` [PATCH 2/3] KVM: PPC: simplify kvmppc_core_check_exceptions() Yury Norov
  2025-07-17 19:24 ` [PATCH 3/3] KVM: PPC: use for_each_set_bit() in IRQ_check() Yury Norov
  2 siblings, 0 replies; 5+ messages in thread
From: Yury Norov @ 2025-07-17 19:24 UTC (permalink / raw)
  To: Madhavan Srinivasan, Nicholas Piggin, Michael Ellerman,
	Christophe Leroy, kvm, linux-kernel
  Cc: Yury Norov

From: Yury Norov (NVIDIA) <yury.norov@gmail.com>

The function opencodes for_each_set_bit() macro.

Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 arch/powerpc/kvm/book3s.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index d79c5d1098c0..dc05ea496aad 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -401,17 +401,12 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 	if (vcpu->arch.pending_exceptions)
 		printk(KERN_EMERG "KVM: Check pending: %lx\n", vcpu->arch.pending_exceptions);
 #endif
-	priority = __ffs(*pending);
-	while (priority < BOOK3S_IRQPRIO_MAX) {
+	for_each_set_bit(priority, pending, BOOK3S_IRQPRIO_MAX) {
 		if (kvmppc_book3s_irqprio_deliver(vcpu, priority) &&
 		    clear_irqprio(vcpu, priority)) {
 			clear_bit(priority, &vcpu->arch.pending_exceptions);
 			break;
 		}
-
-		priority = find_next_bit(pending,
-					 BITS_PER_BYTE * sizeof(*pending),
-					 priority + 1);
 	}
 
 	/* Tell the guest about our interrupt status */
-- 
2.43.0


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

* [PATCH 2/3] KVM: PPC: simplify kvmppc_core_check_exceptions()
  2025-07-17 19:24 [PATCH 0/3] KVM: PPC: use for_each_set_bit() macro where appropriate Yury Norov
  2025-07-17 19:24 ` [PATCH 1/3] KVM: PPC: simplify kvmppc_core_prepare_to_enter() Yury Norov
@ 2025-07-17 19:24 ` Yury Norov
  2025-07-17 19:24 ` [PATCH 3/3] KVM: PPC: use for_each_set_bit() in IRQ_check() Yury Norov
  2 siblings, 0 replies; 5+ messages in thread
From: Yury Norov @ 2025-07-17 19:24 UTC (permalink / raw)
  To: Madhavan Srinivasan, Nicholas Piggin, Michael Ellerman,
	Christophe Leroy, kvm, linux-kernel
  Cc: Yury Norov

From: Yury Norov (NVIDIA) <yury.norov@gmail.com>

The function opencodes for_each_set_bit() macro.

Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 arch/powerpc/kvm/booke.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 3401b96be475..1fe2592c2022 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -692,16 +692,10 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu)
 	unsigned long *pending = &vcpu->arch.pending_exceptions;
 	unsigned int priority;
 
-	priority = __ffs(*pending);
-	while (priority < BOOKE_IRQPRIO_MAX) {
+	for_each_set_bit(priority, pending, BOOKE_IRQPRIO_MAX)
 		if (kvmppc_booke_irqprio_deliver(vcpu, priority))
 			break;
 
-		priority = find_next_bit(pending,
-		                         BITS_PER_BYTE * sizeof(*pending),
-		                         priority + 1);
-	}
-
 	/* Tell the guest about our interrupt status */
 	vcpu->arch.shared->int_pending = !!*pending;
 }
-- 
2.43.0


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

* [PATCH 3/3] KVM: PPC: use for_each_set_bit() in IRQ_check()
  2025-07-17 19:24 [PATCH 0/3] KVM: PPC: use for_each_set_bit() macro where appropriate Yury Norov
  2025-07-17 19:24 ` [PATCH 1/3] KVM: PPC: simplify kvmppc_core_prepare_to_enter() Yury Norov
  2025-07-17 19:24 ` [PATCH 2/3] KVM: PPC: simplify kvmppc_core_check_exceptions() Yury Norov
@ 2025-07-17 19:24 ` Yury Norov
  2025-07-22  8:23   ` Jiri Slaby
  2 siblings, 1 reply; 5+ messages in thread
From: Yury Norov @ 2025-07-17 19:24 UTC (permalink / raw)
  To: Madhavan Srinivasan, Nicholas Piggin, Michael Ellerman,
	Christophe Leroy, kvm, linux-kernel
  Cc: Yury Norov

From: Yury Norov (NVIDIA) <yury.norov@gmail.com>

The function opencodes for_each_set_bit() macro.

Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 arch/powerpc/kvm/mpic.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
index 23e9c2bd9f27..ae68b213f0f9 100644
--- a/arch/powerpc/kvm/mpic.c
+++ b/arch/powerpc/kvm/mpic.c
@@ -290,15 +290,11 @@ static inline void IRQ_resetbit(struct irq_queue *q, int n_IRQ)
 
 static void IRQ_check(struct openpic *opp, struct irq_queue *q)
 {
-	int irq = -1;
+	int irq;
 	int next = -1;
 	int priority = -1;
 
-	for (;;) {
-		irq = find_next_bit(q->queue, opp->max_irq, irq + 1);
-		if (irq == opp->max_irq)
-			break;
-
+	for_each_set_bit(irq, q->queue, opp->max_irq) {
 		pr_debug("IRQ_check: irq %d set ivpr_pr=%d pr=%d\n",
 			irq, IVPR_PRIORITY(opp->src[irq].ivpr), priority);
 
-- 
2.43.0


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

* Re: [PATCH 3/3] KVM: PPC: use for_each_set_bit() in IRQ_check()
  2025-07-17 19:24 ` [PATCH 3/3] KVM: PPC: use for_each_set_bit() in IRQ_check() Yury Norov
@ 2025-07-22  8:23   ` Jiri Slaby
  0 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby @ 2025-07-22  8:23 UTC (permalink / raw)
  To: Yury Norov, Madhavan Srinivasan, Nicholas Piggin,
	Michael Ellerman, Christophe Leroy, kvm, linux-kernel

On 17. 07. 25, 21:24, Yury Norov wrote:
> From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> 
> The function opencodes for_each_set_bit() macro.
> 
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> ---
>   arch/powerpc/kvm/mpic.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
> index 23e9c2bd9f27..ae68b213f0f9 100644
> --- a/arch/powerpc/kvm/mpic.c
> +++ b/arch/powerpc/kvm/mpic.c
> @@ -290,15 +290,11 @@ static inline void IRQ_resetbit(struct irq_queue *q, int n_IRQ)
>   
>   static void IRQ_check(struct openpic *opp, struct irq_queue *q)
>   {
> -	int irq = -1;
> +	int irq;

Can be unsigned now, right?

>   	int next = -1;
>   	int priority = -1;
>   
> -	for (;;) {
> -		irq = find_next_bit(q->queue, opp->max_irq, irq + 1);
> -		if (irq == opp->max_irq)
> -			break;
> -
> +	for_each_set_bit(irq, q->queue, opp->max_irq) {
>   		pr_debug("IRQ_check: irq %d set ivpr_pr=%d pr=%d\n",
>   			irq, IVPR_PRIORITY(opp->src[irq].ivpr), priority);
>   

thanks,
-- 
js
suse labs


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

end of thread, other threads:[~2025-07-22  8:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-17 19:24 [PATCH 0/3] KVM: PPC: use for_each_set_bit() macro where appropriate Yury Norov
2025-07-17 19:24 ` [PATCH 1/3] KVM: PPC: simplify kvmppc_core_prepare_to_enter() Yury Norov
2025-07-17 19:24 ` [PATCH 2/3] KVM: PPC: simplify kvmppc_core_check_exceptions() Yury Norov
2025-07-17 19:24 ` [PATCH 3/3] KVM: PPC: use for_each_set_bit() in IRQ_check() Yury Norov
2025-07-22  8:23   ` Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).