qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] LSI: avoid infinite loops
@ 2008-05-07 23:02 Marcelo Tosatti
  2008-05-07 23:21 ` [Qemu-devel] " Paul Brook
  0 siblings, 1 reply; 8+ messages in thread
From: Marcelo Tosatti @ 2008-05-07 23:02 UTC (permalink / raw)
  To: Paul Brook; +Cc: Alberto Treviño, qemu-devel


The Windows driver has SCRIPTS code which busy loops on main memory. So
give the CPU's a chance to run if that happens.

Fixes
http://sourceforge.net/tracker/index.php?func=detail&aid=1895893&group_id=180599&atid=893831

Paul, I'm not conviced that a smarter algorithm to determine this
conditions is necessary... perhaps it would be wise to increase the
"200" magic number.

The scsi-disk.c patch in the bugzilla entry has been submitted but ignored.

diff --git a/qemu/hw/lsi53c895a.c b/qemu/hw/lsi53c895a.c
index 72ed5c3..2691418 100644
--- a/qemu/hw/lsi53c895a.c
+++ b/qemu/hw/lsi53c895a.c
@@ -840,9 +840,11 @@ static void lsi_execute_script(LSIState *s)
     uint32_t insn;
     uint32_t addr;
     int opcode;
+    int insns_processed = 0;
 
     s->istat1 |= LSI_ISTAT1_SRUN;
 again:
+    insns_processed++;
     insn = read_dword(s, s->dsp);
     addr = read_dword(s, s->dsp + 4);
     DPRINTF("SCRIPTS dsp=%08x opcode %08x arg %08x\n", s->dsp, insn, addr);
@@ -1197,8 +1199,13 @@ again:
             }
         }
     }
-    /* ??? Need to avoid infinite loops.  */
-    if (s->istat1 & LSI_ISTAT1_SRUN && !s->waiting) {
+    /*
+     * The Windows driver downloads SCRIPT code which busy loops 
+     * on main memory, so give the CPU's a chance to run if that
+     * happens.
+     */
+    if (insns_processed < 200 && s->istat1 & LSI_ISTAT1_SRUN &&
+       !s->waiting) {
         if (s->dcntl & LSI_DCNTL_SSM) {
             lsi_script_dma_interrupt(s, LSI_DSTAT_SSI);
         } else {

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

* [Qemu-devel] Re: LSI: avoid infinite loops
  2008-05-07 23:02 [Qemu-devel] LSI: avoid infinite loops Marcelo Tosatti
@ 2008-05-07 23:21 ` Paul Brook
  2008-05-07 23:42   ` Marcelo Tosatti
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Brook @ 2008-05-07 23:21 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: Alberto Treviño, qemu-devel

On Thursday 08 May 2008, Marcelo Tosatti wrote:
> The Windows driver has SCRIPTS code which busy loops on main memory. So
> give the CPU's a chance to run if that happens.

I'm kinda surprised this works.  What causes the scripts engine to be 
restarted?

Paul

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

* [Qemu-devel] Re: LSI: avoid infinite loops
  2008-05-07 23:21 ` [Qemu-devel] " Paul Brook
@ 2008-05-07 23:42   ` Marcelo Tosatti
  2008-05-08  0:39     ` Paul Brook
  0 siblings, 1 reply; 8+ messages in thread
From: Marcelo Tosatti @ 2008-05-07 23:42 UTC (permalink / raw)
  To: Paul Brook; +Cc: Alberto Treviño, qemu-devel

On Thu, May 08, 2008 at 12:21:54AM +0100, Paul Brook wrote:
> On Thursday 08 May 2008, Marcelo Tosatti wrote:
> > The Windows driver has SCRIPTS code which busy loops on main memory. So
> > give the CPU's a chance to run if that happens.
> 
> I'm kinda surprised this works.  What causes the scripts engine to be 
> restarted?

LSI_ISTAT0_SIGP.

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

* Re: [Qemu-devel] Re: LSI: avoid infinite loops
  2008-05-07 23:42   ` Marcelo Tosatti
@ 2008-05-08  0:39     ` Paul Brook
  2008-05-08  0:52       ` Paul Brook
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Brook @ 2008-05-08  0:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alberto Treviño, Marcelo Tosatti

On Thursday 08 May 2008, Marcelo Tosatti wrote:
> On Thu, May 08, 2008 at 12:21:54AM +0100, Paul Brook wrote:
> > On Thursday 08 May 2008, Marcelo Tosatti wrote:
> > > The Windows driver has SCRIPTS code which busy loops on main memory. So
> > > give the CPU's a chance to run if that happens.
> >
> > I'm kinda surprised this works.  What causes the scripts engine to be
> > restarted?
>
> LSI_ISTAT0_SIGP.

In that case my surprise continues, and this is looking like an unbelievably 
horrid hack.

By my reading you're making LSI_ISTAT0_SIGP effect whatever instruction 
happens to be executing when we stall. You get doubly lucky because (a) the 
guest OS decides to bang on SIGP, even though it doesn't need to. And (b) the 
last instruction executed happens to have set dnad to a value that "works". 
I'm guessing you always happen to stop execution on the conditional jump 
instruction and taking that jump doesn't cause any bad effects, right?

Paul

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

* Re: [Qemu-devel] Re: LSI: avoid infinite loops
  2008-05-08  0:39     ` Paul Brook
@ 2008-05-08  0:52       ` Paul Brook
  2008-05-08  3:13         ` Marcelo Tosatti
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Brook @ 2008-05-08  0:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alberto Treviño, Marcelo Tosatti

On Thursday 08 May 2008, Paul Brook wrote:
> On Thursday 08 May 2008, Marcelo Tosatti wrote:
> > On Thu, May 08, 2008 at 12:21:54AM +0100, Paul Brook wrote:
> > > On Thursday 08 May 2008, Marcelo Tosatti wrote:
> > > > The Windows driver has SCRIPTS code which busy loops on main memory.
> > > > So give the CPU's a chance to run if that happens.
> > >
> > > I'm kinda surprised this works.  What causes the scripts engine to be
> > > restarted?
> >
> > LSI_ISTAT0_SIGP.
>
> In that case my surprise continues, and this is looking like an
> unbelievably horrid hack.
>
> By my reading you're making LSI_ISTAT0_SIGP effect whatever instruction
> happens to be executing when we stall. You get doubly lucky because (a) the
> guest OS decides to bang on SIGP, even though it doesn't need to. And (b)
> the last instruction executed happens to have set dnad to a value that
> "works". I'm guessing you always happen to stop execution on the
> conditional jump instruction and taking that jump doesn't cause any bad
> effects, right?

Oh, I'd also be worried what happens if an async IO operation completes at 
this point. lsi_command_complete is liable to trample all over your state.

Paul

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

* Re: [Qemu-devel] Re: LSI: avoid infinite loops
  2008-05-08  0:52       ` Paul Brook
@ 2008-05-08  3:13         ` Marcelo Tosatti
  2008-06-19 21:53           ` Marcelo Tosatti
  0 siblings, 1 reply; 8+ messages in thread
From: Marcelo Tosatti @ 2008-05-08  3:13 UTC (permalink / raw)
  To: Paul Brook; +Cc: Alberto Treviño, qemu-devel

On Thu, May 08, 2008 at 01:52:11AM +0100, Paul Brook wrote:
> On Thursday 08 May 2008, Paul Brook wrote:
> > On Thursday 08 May 2008, Marcelo Tosatti wrote:
> > > On Thu, May 08, 2008 at 12:21:54AM +0100, Paul Brook wrote:
> > > > On Thursday 08 May 2008, Marcelo Tosatti wrote:
> > > > > The Windows driver has SCRIPTS code which busy loops on main memory.
> > > > > So give the CPU's a chance to run if that happens.
> > > >
> > > > I'm kinda surprised this works.  What causes the scripts engine to be
> > > > restarted?
> > >
> > > LSI_ISTAT0_SIGP.
> >
> > In that case my surprise continues, and this is looking like an
> > unbelievably horrid hack.
> >
> > By my reading you're making LSI_ISTAT0_SIGP effect whatever instruction
> > happens to be executing when we stall. You get doubly lucky because (a) the
> > guest OS decides to bang on SIGP, even though it doesn't need to. And (b)
> > the last instruction executed happens to have set dnad to a value that
> > "works". I'm guessing you always happen to stop execution on the
> > conditional jump instruction and taking that jump doesn't cause any bad
> > effects, right?
> 
> Oh, I'd also be worried what happens if an async IO operation completes at 
> this point. lsi_command_complete is liable to trample all over your state.

So what do you suggest as a proper fix?

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

* Re: [Qemu-devel] Re: LSI: avoid infinite loops
  2008-05-08  3:13         ` Marcelo Tosatti
@ 2008-06-19 21:53           ` Marcelo Tosatti
  2008-06-19 22:33             ` Paul Brook
  0 siblings, 1 reply; 8+ messages in thread
From: Marcelo Tosatti @ 2008-06-19 21:53 UTC (permalink / raw)
  To: Paul Brook, Avi Kivity; +Cc: Alberto Treviño, qemu-devel

On Thu, May 08, 2008 at 12:13:15AM -0300, Marcelo Tosatti wrote:
> On Thu, May 08, 2008 at 01:52:11AM +0100, Paul Brook wrote:
> > On Thursday 08 May 2008, Paul Brook wrote:
> > > On Thursday 08 May 2008, Marcelo Tosatti wrote:
> > > > On Thu, May 08, 2008 at 12:21:54AM +0100, Paul Brook wrote:
> > > > > On Thursday 08 May 2008, Marcelo Tosatti wrote:
> > > > > > The Windows driver has SCRIPTS code which busy loops on main memory.
> > > > > > So give the CPU's a chance to run if that happens.
> > > > >
> > > > > I'm kinda surprised this works.  What causes the scripts engine to be
> > > > > restarted?
> > > >
> > > > LSI_ISTAT0_SIGP.
> > >
> > > In that case my surprise continues, and this is looking like an
> > > unbelievably horrid hack.
> > >
> > > By my reading you're making LSI_ISTAT0_SIGP effect whatever instruction
> > > happens to be executing when we stall. You get doubly lucky because (a) the
> > > guest OS decides to bang on SIGP, even though it doesn't need to. And (b)
> > > the last instruction executed happens to have set dnad to a value that
> > > "works". I'm guessing you always happen to stop execution on the
> > > conditional jump instruction and taking that jump doesn't cause any bad
> > > effects, right?
> > 
> > Oh, I'd also be worried what happens if an async IO operation completes at 
> > this point. lsi_command_complete is liable to trample all over your state.
> 
> So what do you suggest as a proper fix?

Paul, 

What do you suggest as a proper fix to this problem?

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

* Re: [Qemu-devel] Re: LSI: avoid infinite loops
  2008-06-19 21:53           ` Marcelo Tosatti
@ 2008-06-19 22:33             ` Paul Brook
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Brook @ 2008-06-19 22:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alberto Treviño, Marcelo Tosatti

> > > > > > > The Windows driver has SCRIPTS code which busy loops on main
> > > > > > > memory. So give the CPU's a chance to run if that happens.
> > > > > >
> > > > > > I'm kinda surprised this works.  What causes the scripts engine
> > > > > > to be restarted?
> > > > >
> > > > > LSI_ISTAT0_SIGP.
> > > >
> > > > In that case my surprise continues, and this is looking like an
> > > > unbelievably horrid hack.
> > > >
> > > > By my reading you're making LSI_ISTAT0_SIGP effect whatever
> > > > instruction happens to be executing when we stall. You get doubly
> > > > lucky because (a) the guest OS decides to bang on SIGP, even though
> > > > it doesn't need to. And (b) the last instruction executed happens to
> > > > have set dnad to a value that "works". I'm guessing you always happen
> > > > to stop execution on the conditional jump instruction and taking that
> > > > jump doesn't cause any bad effects, right?
> > >
> > > Oh, I'd also be worried what happens if an async IO operation completes
> > > at this point. lsi_command_complete is liable to trample all over your
> > > state.
> >
> > So what do you suggest as a proper fix?
>
> What do you suggest as a proper fix to this problem?

At minimum you need to address the issues I've raised with your current patch.  
Stalling execution temporarily every few hundred instructions and waiting for 
SIGP (or some other trigger) before resuming may be acceptable.  Aborting 
execution and relying on very specific guest OS behavior to give correct 
results is not.  The current code is written with the assumption that 
execution will only stop at very specific points. Your patch breaks this 
assumption.

Ideally you'd also do proper loop detection rather than setting an arbitrary 
limit. I wouldn't be surprised if a good OS can create very long queues.

Paul

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

end of thread, other threads:[~2008-06-19 22:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-07 23:02 [Qemu-devel] LSI: avoid infinite loops Marcelo Tosatti
2008-05-07 23:21 ` [Qemu-devel] " Paul Brook
2008-05-07 23:42   ` Marcelo Tosatti
2008-05-08  0:39     ` Paul Brook
2008-05-08  0:52       ` Paul Brook
2008-05-08  3:13         ` Marcelo Tosatti
2008-06-19 21:53           ` Marcelo Tosatti
2008-06-19 22:33             ` Paul Brook

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