From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: LSI SCSI: raise UDC on infinite loop Date: Thu, 28 Aug 2008 10:55:25 -0300 Message-ID: <20080828135525.GA6793@dmt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm-devel To: qemu-devel@nongnu.org, Paul Brook Return-path: Received: from mx1.redhat.com ([66.187.233.31]:33518 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753093AbYH1OA1 (ORCPT ); Thu, 28 Aug 2008 10:00:27 -0400 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: 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 {