linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm/powerpc: Handle errors in secondary thread grabbing
@ 2012-10-16  0:15 Michael Ellerman
  2012-10-16  3:13 ` Paul Mackerras
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Ellerman @ 2012-10-16  0:15 UTC (permalink / raw)
  To: linuxppc-dev, kvm-ppc; +Cc: Paul Mackerras

In the Book3s HV code, kvmppc_run_core() has logic to grab the secondary
threads of the physical core.

If for some reason a thread is stuck, kvmppc_grab_hwthread() can fail,
but currently we ignore the failure and continue into the guest. If the
stuck thread is in the kernel badness ensues.

Instead we should check for failure and bail out.

I've moved the grabbing prior to the startup of runnable threads, to simplify
the error case. AFAICS this is harmless, but I could be missing something
subtle.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---

Or we could just BUG_ON() ?
---
 arch/powerpc/kvm/book3s_hv.c |   22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 721d460..55925cd 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -884,16 +884,30 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
 		if (vcpu->arch.ceded)
 			vcpu->arch.ptid = ptid++;
 
+	/*
+	 * Grab any remaining hw threads so they can't go into the kernel.
+	 * Do this early to simplify the cleanup path if it fails.
+	 */
+	for (i = ptid; i < threads_per_core; ++i) {
+		int j, rc = kvmppc_grab_hwthread(vc->pcpu + i);
+		if (rc) {
+			for (j = i - 1; j ; j--)
+				kvmppc_release_hwthread(vc->pcpu + j);
+
+			list_for_each_entry(vcpu, &vc->runnable_threads,
+					    arch.run_list)
+				vcpu->arch.ret = -EBUSY;
+
+			goto out;
+		}
+	}
+
 	vc->stolen_tb += mftb() - vc->preempt_tb;
 	vc->pcpu = smp_processor_id();
 	list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) {
 		kvmppc_start_thread(vcpu);
 		kvmppc_create_dtl_entry(vcpu, vc);
 	}
-	/* Grab any remaining hw threads so they can't go into the kernel */
-	for (i = ptid; i < threads_per_core; ++i)
-		kvmppc_grab_hwthread(vc->pcpu + i);
-
 	preempt_disable();
 	spin_unlock(&vc->lock);
 
-- 
1.7.9.5

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

* Re: [PATCH] kvm/powerpc: Handle errors in secondary thread grabbing
  2012-10-16  0:15 [PATCH] kvm/powerpc: Handle errors in secondary thread grabbing Michael Ellerman
@ 2012-10-16  3:13 ` Paul Mackerras
  2012-10-16  6:00   ` Michael Ellerman
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Mackerras @ 2012-10-16  3:13 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev, kvm-ppc

Michael,

On Tue, Oct 16, 2012 at 11:15:50AM +1100, Michael Ellerman wrote:
> In the Book3s HV code, kvmppc_run_core() has logic to grab the secondary
> threads of the physical core.
> 
> If for some reason a thread is stuck, kvmppc_grab_hwthread() can fail,
> but currently we ignore the failure and continue into the guest. If the
> stuck thread is in the kernel badness ensues.
> 
> Instead we should check for failure and bail out.
> 
> I've moved the grabbing prior to the startup of runnable threads, to simplify
> the error case. AFAICS this is harmless, but I could be missing something
> subtle.

Thanks for looking at this - but in fact this is fixed by my patch
entitled "KVM: PPC: Book3S HV: Fix some races in starting secondary
threads" submitted back on August 28.

Regards,
Paul.

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

* Re: [PATCH] kvm/powerpc: Handle errors in secondary thread grabbing
  2012-10-16  3:13 ` Paul Mackerras
@ 2012-10-16  6:00   ` Michael Ellerman
  2012-10-16 19:33     ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Ellerman @ 2012-10-16  6:00 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: linuxppc-dev, agraf, kvm-ppc

On Tue, 2012-10-16 at 14:13 +1100, Paul Mackerras wrote:
> Michael,
> 
> On Tue, Oct 16, 2012 at 11:15:50AM +1100, Michael Ellerman wrote:
> > In the Book3s HV code, kvmppc_run_core() has logic to grab the secondary
> > threads of the physical core.
> > 
> > If for some reason a thread is stuck, kvmppc_grab_hwthread() can fail,
> > but currently we ignore the failure and continue into the guest. If the
> > stuck thread is in the kernel badness ensues.
> > 
> > Instead we should check for failure and bail out.
> > 
> > I've moved the grabbing prior to the startup of runnable threads, to simplify
> > the error case. AFAICS this is harmless, but I could be missing something
> > subtle.
> 
> Thanks for looking at this - but in fact this is fixed by my patch
> entitled "KVM: PPC: Book3S HV: Fix some races in starting secondary
> threads" submitted back on August 28.

OK thanks. It seems that patch didn't make 3.7 ?

I don't see it in kvm-ppc-next either.

cheers

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

* Re: [PATCH] kvm/powerpc: Handle errors in secondary thread grabbing
  2012-10-16  6:00   ` Michael Ellerman
@ 2012-10-16 19:33     ` Benjamin Herrenschmidt
  2012-10-17  6:25       ` Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Benjamin Herrenschmidt @ 2012-10-16 19:33 UTC (permalink / raw)
  To: Alexander Graf; +Cc: linuxppc-dev, Paul Mackerras, agraf, kvm-ppc

On Tue, 2012-10-16 at 17:00 +1100, Michael Ellerman wrote:
> > Thanks for looking at this - but in fact this is fixed by my patch
> > entitled "KVM: PPC: Book3S HV: Fix some races in starting secondary
> > threads" submitted back on August 28.
> 
> OK thanks. It seems that patch didn't make 3.7 ?
> 
> I don't see it in kvm-ppc-next either.

Alex, WTF ?

Ben.

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

* Re: [PATCH] kvm/powerpc: Handle errors in secondary thread grabbing
  2012-10-16 19:33     ` Benjamin Herrenschmidt
@ 2012-10-17  6:25       ` Alexander Graf
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Graf @ 2012-10-17  6:25 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev, Paul Mackerras, kvm-ppc


On 16.10.2012, at 21:33, Benjamin Herrenschmidt wrote:

> On Tue, 2012-10-16 at 17:00 +1100, Michael Ellerman wrote:
>>> Thanks for looking at this - but in fact this is fixed by my patch
>>> entitled "KVM: PPC: Book3S HV: Fix some races in starting secondary
>>> threads" submitted back on August 28.
>>=20
>> OK thanks. It seems that patch didn't make 3.7 ?
>>=20
>> I don't see it in kvm-ppc-next either.
>=20
> Alex, WTF ?

Hrm. Not sure what happened there. I think I waited for your ack, but =
never actually applied things when it came. My bad :)


Alex

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

end of thread, other threads:[~2012-10-17  6:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-16  0:15 [PATCH] kvm/powerpc: Handle errors in secondary thread grabbing Michael Ellerman
2012-10-16  3:13 ` Paul Mackerras
2012-10-16  6:00   ` Michael Ellerman
2012-10-16 19:33     ` Benjamin Herrenschmidt
2012-10-17  6:25       ` Alexander Graf

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