qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] LSI SCSI: raise UDC on infinite loop (resend #1)
@ 2008-09-12 12:38 Marcelo Tosatti
  2008-09-12 17:58 ` Anthony Liguori
  2008-09-22 14:53 ` Anthony Liguori
  0 siblings, 2 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2008-09-12 12:38 UTC (permalink / raw)
  To: qemu-devel, Paul Brook


Raise UDC (Unexpected Disconnect) when a large enough number of
instructions has been executed by the SCRIPTS processor. This "solution"
is much simpler than temporarily interrupting execution.

This remedies the situation with Windows which downloads SCRIPTS code
that busy loops on guest main memory. Their drivers _do_ handle UDC 
appropriately (at least XP and 2003).

It would be nicer to actually detect infinite loops, but until then,
this bandaid seems acceptable.

Since the situation seems to be rare enough, raise the number 
of instructions to 10000 (previously 1000).

Three people other than myself had success with this patch.


diff --git a/qemu/hw/lsi53c895a.c b/qemu/hw/lsi53c895a.c
index 72ed5c3..50f66aa 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 insn_processed = 0;
 
     s->istat1 |= LSI_ISTAT1_SRUN;
 again:
+    insn_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,12 @@ again:
             }
         }
     }
-    /* ??? Need to avoid infinite loops.  */
-    if (s->istat1 & LSI_ISTAT1_SRUN && !s->waiting) {
+    if (insn_processed > 10000 && !s->waiting) {
+        if (!(s->sien0 & LSI_SIST0_UDC))
+            fprintf(stderr, "inf. loop with UDC masked\n");
+        lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
+        lsi_disconnect(s);
+    } else if (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] 3+ messages in thread

* Re: [Qemu-devel] LSI SCSI: raise UDC on infinite loop (resend #1)
  2008-09-12 12:38 [Qemu-devel] LSI SCSI: raise UDC on infinite loop (resend #1) Marcelo Tosatti
@ 2008-09-12 17:58 ` Anthony Liguori
  2008-09-22 14:53 ` Anthony Liguori
  1 sibling, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2008-09-12 17:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paul Brook

Paul: do you have an objection to me applying this?

Regards,

Anthony Liguori

Marcelo Tosatti wrote:
> Raise UDC (Unexpected Disconnect) when a large enough number of
> instructions has been executed by the SCRIPTS processor. This "solution"
> is much simpler than temporarily interrupting execution.
>
> This remedies the situation with Windows which downloads SCRIPTS code
> that busy loops on guest main memory. Their drivers _do_ handle UDC 
> appropriately (at least XP and 2003).
>
> It would be nicer to actually detect infinite loops, but until then,
> this bandaid seems acceptable.
>
> Since the situation seems to be rare enough, raise the number 
> of instructions to 10000 (previously 1000).
>
> Three people other than myself had success with this patch.
>
>
> diff --git a/qemu/hw/lsi53c895a.c b/qemu/hw/lsi53c895a.c
> index 72ed5c3..50f66aa 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 insn_processed = 0;
>  
>      s->istat1 |= LSI_ISTAT1_SRUN;
>  again:
> +    insn_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,12 @@ again:
>              }
>          }
>      }
> -    /* ??? Need to avoid infinite loops.  */
> -    if (s->istat1 & LSI_ISTAT1_SRUN && !s->waiting) {
> +    if (insn_processed > 10000 && !s->waiting) {
> +        if (!(s->sien0 & LSI_SIST0_UDC))
> +            fprintf(stderr, "inf. loop with UDC masked\n");
> +        lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
> +        lsi_disconnect(s);
> +    } else if (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	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] LSI SCSI: raise UDC on infinite loop (resend #1)
  2008-09-12 12:38 [Qemu-devel] LSI SCSI: raise UDC on infinite loop (resend #1) Marcelo Tosatti
  2008-09-12 17:58 ` Anthony Liguori
@ 2008-09-22 14:53 ` Anthony Liguori
  1 sibling, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2008-09-22 14:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marcelo Tosatti, Paul Brook

Hi Marcelo,

Marcelo Tosatti wrote:
> Raise UDC (Unexpected Disconnect) when a large enough number of
> instructions has been executed by the SCRIPTS processor. This "solution"
> is much simpler than temporarily interrupting execution.
>
> This remedies the situation with Windows which downloads SCRIPTS code
> that busy loops on guest main memory. Their drivers _do_ handle UDC 
> appropriately (at least XP and 2003).
>
> It would be nicer to actually detect infinite loops, but until then,
> this bandaid seems acceptable.
>
> Since the situation seems to be rare enough, raise the number 
> of instructions to 10000 (previously 1000).
>
> Three people other than myself had success with this patch.
>   

Please add a Signed-off-by and I'll apply this patch.  I don't know that 
Paul has gotten a chance to look yet but we talked in IRC a while ago 
and he mentioned that it's probably the best solution we'll be able to 
come up with so that seems to suggest to me that it's safe to apply.

Regards,

Anthony Liguori

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

end of thread, other threads:[~2008-09-22 14:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-12 12:38 [Qemu-devel] LSI SCSI: raise UDC on infinite loop (resend #1) Marcelo Tosatti
2008-09-12 17:58 ` Anthony Liguori
2008-09-22 14:53 ` Anthony Liguori

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