|
@@ -188,7 +188,7 @@ static const char *names[] = {
|
|
#define LSI_TAG_VALID (1 << 16)
|
|
#define LSI_TAG_VALID (1 << 16)
|
|
|
|
|
|
/* Maximum instructions to process. */
|
|
/* Maximum instructions to process. */
|
|
-#define LSI_MAX_INSN 10000
|
|
|
|
|
|
+#define LSI_MAX_INSN 100
|
|
|
|
|
|
typedef struct lsi_request {
|
|
typedef struct lsi_request {
|
|
SCSIRequest *req;
|
|
SCSIRequest *req;
|
|
@@ -205,6 +205,7 @@ enum {
|
|
LSI_WAIT_RESELECT, /* Wait Reselect instruction has been issued */
|
|
LSI_WAIT_RESELECT, /* Wait Reselect instruction has been issued */
|
|
LSI_DMA_SCRIPTS, /* processing DMA from lsi_execute_script */
|
|
LSI_DMA_SCRIPTS, /* processing DMA from lsi_execute_script */
|
|
LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
|
|
LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
|
|
|
|
+ LSI_WAIT_SCRIPTS, /* SCRIPTS stopped because of instruction count limit */
|
|
};
|
|
};
|
|
|
|
|
|
enum {
|
|
enum {
|
|
@@ -224,6 +225,7 @@ struct LSIState {
|
|
MemoryRegion ram_io;
|
|
MemoryRegion ram_io;
|
|
MemoryRegion io_io;
|
|
MemoryRegion io_io;
|
|
AddressSpace pci_io_as;
|
|
AddressSpace pci_io_as;
|
|
|
|
+ QEMUTimer *scripts_timer;
|
|
|
|
|
|
int carry; /* ??? Should this be an a visible register somewhere? */
|
|
int carry; /* ??? Should this be an a visible register somewhere? */
|
|
int status;
|
|
int status;
|
|
@@ -415,6 +417,7 @@ static void lsi_soft_reset(LSIState *s)
|
|
s->sbr = 0;
|
|
s->sbr = 0;
|
|
assert(QTAILQ_EMPTY(&s->queue));
|
|
assert(QTAILQ_EMPTY(&s->queue));
|
|
assert(!s->current);
|
|
assert(!s->current);
|
|
|
|
+ timer_del(s->scripts_timer);
|
|
}
|
|
}
|
|
|
|
|
|
static int lsi_dma_40bit(LSIState *s)
|
|
static int lsi_dma_40bit(LSIState *s)
|
|
@@ -1127,6 +1130,12 @@ static void lsi_wait_reselect(LSIState *s)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void lsi_scripts_timer_start(LSIState *s)
|
|
|
|
+{
|
|
|
|
+ trace_lsi_scripts_timer_start();
|
|
|
|
+ timer_mod(s->scripts_timer, qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + 500);
|
|
|
|
+}
|
|
|
|
+
|
|
static void lsi_execute_script(LSIState *s)
|
|
static void lsi_execute_script(LSIState *s)
|
|
{
|
|
{
|
|
PCIDevice *pci_dev = PCI_DEVICE(s);
|
|
PCIDevice *pci_dev = PCI_DEVICE(s);
|
|
@@ -1136,6 +1145,11 @@ static void lsi_execute_script(LSIState *s)
|
|
int insn_processed = 0;
|
|
int insn_processed = 0;
|
|
static int reentrancy_level;
|
|
static int reentrancy_level;
|
|
|
|
|
|
|
|
+ if (s->waiting == LSI_WAIT_SCRIPTS) {
|
|
|
|
+ timer_del(s->scripts_timer);
|
|
|
|
+ s->waiting = LSI_NOWAIT;
|
|
|
|
+ }
|
|
|
|
+
|
|
reentrancy_level++;
|
|
reentrancy_level++;
|
|
|
|
|
|
s->istat1 |= LSI_ISTAT1_SRUN;
|
|
s->istat1 |= LSI_ISTAT1_SRUN;
|
|
@@ -1143,8 +1157,8 @@ again:
|
|
/*
|
|
/*
|
|
* Some windows drivers make the device spin waiting for a memory location
|
|
* Some windows drivers make the device spin waiting for a memory location
|
|
* to change. If we have executed more than LSI_MAX_INSN instructions then
|
|
* to change. If we have executed more than LSI_MAX_INSN instructions then
|
|
- * assume this is the case and force an unexpected device disconnect. This
|
|
|
|
- * is apparently sufficient to beat the drivers into submission.
|
|
|
|
|
|
+ * assume this is the case and start a timer. Until the timer fires, the
|
|
|
|
+ * host CPU has a chance to run and change the memory location.
|
|
*
|
|
*
|
|
* Another issue (CVE-2023-0330) can occur if the script is programmed to
|
|
* Another issue (CVE-2023-0330) can occur if the script is programmed to
|
|
* trigger itself again and again. Avoid this problem by stopping after
|
|
* trigger itself again and again. Avoid this problem by stopping after
|
|
@@ -1152,13 +1166,8 @@ again:
|
|
* which should be enough for all valid use cases).
|
|
* which should be enough for all valid use cases).
|
|
*/
|
|
*/
|
|
if (++insn_processed > LSI_MAX_INSN || reentrancy_level > 8) {
|
|
if (++insn_processed > LSI_MAX_INSN || reentrancy_level > 8) {
|
|
- if (!(s->sien0 & LSI_SIST0_UDC)) {
|
|
|
|
- qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
- "lsi_scsi: inf. loop with UDC masked");
|
|
|
|
- }
|
|
|
|
- lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
|
|
|
|
- lsi_disconnect(s);
|
|
|
|
- trace_lsi_execute_script_stop();
|
|
|
|
|
|
+ s->waiting = LSI_WAIT_SCRIPTS;
|
|
|
|
+ lsi_scripts_timer_start(s);
|
|
reentrancy_level--;
|
|
reentrancy_level--;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -2197,6 +2206,9 @@ static int lsi_post_load(void *opaque, int version_id)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (s->waiting == LSI_WAIT_SCRIPTS) {
|
|
|
|
+ lsi_scripts_timer_start(s);
|
|
|
|
+ }
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2294,6 +2306,15 @@ static const struct SCSIBusInfo lsi_scsi_info = {
|
|
.cancel = lsi_request_cancelled
|
|
.cancel = lsi_request_cancelled
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+static void scripts_timer_cb(void *opaque)
|
|
|
|
+{
|
|
|
|
+ LSIState *s = opaque;
|
|
|
|
+
|
|
|
|
+ trace_lsi_scripts_timer_triggered();
|
|
|
|
+ s->waiting = LSI_NOWAIT;
|
|
|
|
+ lsi_execute_script(s);
|
|
|
|
+}
|
|
|
|
+
|
|
static void lsi_scsi_realize(PCIDevice *dev, Error **errp)
|
|
static void lsi_scsi_realize(PCIDevice *dev, Error **errp)
|
|
{
|
|
{
|
|
LSIState *s = LSI53C895A(dev);
|
|
LSIState *s = LSI53C895A(dev);
|
|
@@ -2313,6 +2334,7 @@ static void lsi_scsi_realize(PCIDevice *dev, Error **errp)
|
|
"lsi-ram", 0x2000);
|
|
"lsi-ram", 0x2000);
|
|
memory_region_init_io(&s->io_io, OBJECT(s), &lsi_io_ops, s,
|
|
memory_region_init_io(&s->io_io, OBJECT(s), &lsi_io_ops, s,
|
|
"lsi-io", 256);
|
|
"lsi-io", 256);
|
|
|
|
+ s->scripts_timer = timer_new_us(QEMU_CLOCK_VIRTUAL, scripts_timer_cb, s);
|
|
|
|
|
|
/*
|
|
/*
|
|
* Since we use the address-space API to interact with ram_io, disable the
|
|
* Since we use the address-space API to interact with ram_io, disable the
|
|
@@ -2337,6 +2359,7 @@ static void lsi_scsi_exit(PCIDevice *dev)
|
|
LSIState *s = LSI53C895A(dev);
|
|
LSIState *s = LSI53C895A(dev);
|
|
|
|
|
|
address_space_destroy(&s->pci_io_as);
|
|
address_space_destroy(&s->pci_io_as);
|
|
|
|
+ timer_del(s->scripts_timer);
|
|
}
|
|
}
|
|
|
|
|
|
static void lsi_class_init(ObjectClass *klass, void *data)
|
|
static void lsi_class_init(ObjectClass *klass, void *data)
|