Skip to contentSkip to conversation

bcm2835_dma: add emulation of Raspberry Pi DMA controller

RFC PATCH In review Andrew Baumann 4 participants 7 messages Feb 29, 2016 – Mar 4, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 bcm2835_dma: add emulation of Raspberry Pi DMA controller

---
This patch applies on top of the previous series for Windows and framebuffer support:
https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg06387.html

After preparing that, I was disappointed to discover that Raspbian won't boot cleanly without the DMA controller. In the hope of beating the freeze deadline (it's still February 29 here :-) I'm sending this for review.

After applying this patch, it is possible to boot Raspbian to the GUI using a command such as:

qemu-system-arm -M raspi2 -kernel raspbian-boot/kernel7.img -sd 2015-09-24-raspbian-jessie.img -append "rw earlyprintk loglevel=8 console=ttyAMA0 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootwait" -dtb raspbian-boot/bcm2709-rpi-2-b.dtb -serial stdio

As before, this derives from the original (out of tree) work of Gregory Estrade, Stefan Weil and others to support Raspberry Pi
1. This patch in particulary is Gregory's code, which I have cleaned up for submission.

Thanks,
Andrew

 hw/arm/bcm2835_peripherals.c         |  26 +++
 hw/dma/Makefile.objs                 |   1 +
 hw/dma/bcm2835_dma.c                 | 397 +++++++++++++++++++++++++++++++++++
 include/hw/arm/bcm2835_peripherals.h |   2 +
 include/hw/dma/bcm2835_dma.h         |  47 +++++
 5 files changed, 473 insertions(+)
 create mode 100644 hw/dma/bcm2835_dma.c
 create mode 100644 include/hw/dma/bcm2835_dma.h
hw/arm/bcm2835_peripherals.c +26 -0
index c2b812a..fdd346e 100644
@@ -87,6 +87,14 @@ static void bcm2835_peripherals_init(Object *obj)
     object_initialize(&s->sdhci, sizeof(s->sdhci), TYPE_SYSBUS_SDHCI);
     object_property_add_child(obj, "sdhci", OBJECT(&s->sdhci), NULL);
     qdev_set_parent_bus(DEVICE(&s->sdhci), sysbus_get_default());
+
+    /* DMA Channels */
+    object_initialize(&s->dma, sizeof(s->dma), TYPE_BCM2835_DMA);
+    object_property_add_child(obj, "dma", OBJECT(&s->dma), NULL);
+    qdev_set_parent_bus(DEVICE(&s->dma), sysbus_get_default());
+
+    object_property_add_const_link(OBJECT(&s->dma), "dma-mr",
+                                   OBJECT(&s->gpu_bus_mr), &error_abort);
 }
 
 static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
@@ -246,6 +254,24 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    /* DMA Channels */
+    object_property_set_bool(OBJECT(&s->dma), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    memory_region_add_subregion(&s->peri_mr, DMA_OFFSET,
+                sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dma), 0));
+    memory_region_add_subregion(&s->peri_mr, DMA15_OFFSET,
+                sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dma), 1));
+
+    for (n = 0; n <= 12; n++) {
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->dma), n,
+                           qdev_get_gpio_in_named(DEVICE(&s->ic),
+                                                  BCM2835_IC_GPU_IRQ,
+                                                  INTERRUPT_DMA0 + n));
+    }
 }
 
 static void bcm2835_peripherals_class_init(ObjectClass *oc, void *data)
hw/dma/Makefile.objs +1 -0
index 0e65ed0..a1abbcf 100644
@@ -11,3 +11,4 @@ common-obj-$(CONFIG_SUN4M) += sun4m_iommu.o
 
 obj-$(CONFIG_OMAP) += omap_dma.o soc_dma.o
 obj-$(CONFIG_PXA2XX) += pxa2xx_dma.o
+obj-$(CONFIG_RASPI) += bcm2835_dma.o
hw/dma/bcm2835_dma.c new file +397 -0

397 lines not on this page · raw message

include/hw/arm/bcm2835_peripherals.h +2 -0
index e19d360..e12ae37 100644
@@ -16,6 +16,7 @@
 #include "hw/sysbus.h"
 #include "hw/char/bcm2835_aux.h"
 #include "hw/display/bcm2835_fb.h"
+#include "hw/dma/bcm2835_dma.h"
 #include "hw/intc/bcm2835_ic.h"
 #include "hw/misc/bcm2835_property.h"
 #include "hw/misc/bcm2835_mbox.h"
@@ -37,6 +38,7 @@ typedef struct BCM2835PeripheralState {
     SysBusDevice *uart0;
     BCM2835AuxState aux;
     BCM2835FBState fb;
+    BCM2835DMAState dma;
     BCM2835ICState ic;
     BCM2835PropertyState property;
     BCM2835MboxState mboxes;
include/hw/dma/bcm2835_dma.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.5.3
#1 lore raw
Quoted 19 lines · Andrew Baumann

---
This patch applies on top of the previous series for Windows and framebuffer support:
https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg06387.html

After preparing that, I was disappointed to discover that Raspbian won't boot cleanly without the DMA controller. In the hope of beating the freeze deadline (it's still February 29 here :-) I'm sending this for review.

After applying this patch, it is possible to boot Raspbian to the GUI using a command such as:

qemu-system-arm -M raspi2 -kernel raspbian-boot/kernel7.img -sd 2015-09-24-raspbian-jessie.img -append "rw earlyprintk loglevel=8 console=ttyAMA0 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootwait" -dtb raspbian-boot/bcm2709-rpi-2-b.dtb -serial stdio

Quoted 4 lines

As before, this derives from the original (out of tree) work of Gregory Estrade, Stefan Weil and others to support Raspberry Pi
1. This patch in particulary is Gregory's code, which I have cleaned up for submission.

Should it have a Signed-off-by: line and/or authorship line from Gregory, then?

(This is largely about giving credit where due, so it's Gregory's choice really. I forget whether we've had this discussion before but I couldn't find anything in a quick sweep through earlier mail threads.)

Quoted 8 lines
hw/dma/bcm2835_dma.c new file +8 -0
+static void bcm2835_dma_update(BCM2835DMAState *s, unsigned c)
+{
+    BCM2835DMAChan *ch = &s->chan[c];
+    uint32_t data, xlen, ylen;
+    int16_t dst_stride, src_stride;
+
+    if (!(s->enable & (1 << c))) {
+        return;

hw/dma/bcm2835_dma.c line 66

Quoted 10 lines
hw/dma/bcm2835_dma.c new file +10 -0
+    }
+
+    while ((s->enable & (1 << c)) && (ch->conblk_ad != 0)) {
+        /* CB fetch */
+        ch->ti = ldl_phys(&s->dma_as, ch->conblk_ad);
+        ch->source_ad = ldl_phys(&s->dma_as, ch->conblk_ad + 4);
+        ch->dest_ad = ldl_phys(&s->dma_as, ch->conblk_ad + 8);
+        ch->txfr_len = ldl_phys(&s->dma_as, ch->conblk_ad + 12);
+        ch->stride = ldl_phys(&s->dma_as, ch->conblk_ad + 16);
+        ch->nextconbk = ldl_phys(&s->dma_as, ch->conblk_ad + 20);

These should use the ldl_{le,be}_phys functions. (If you care about modelling the response to "unreadable address" you can use address_space_ldl_{le,be}.)

Quoted 50 lines
hw/dma/bcm2835_dma.c new file +50 -0
+
+        if (ch->ti & BCM2708_DMA_TDMODE) {
+            /* 2D transfer mode */
+            ylen = (ch->txfr_len >> 16) & 0x3fff;
+            xlen = ch->txfr_len & 0xffff;
+            dst_stride = ch->stride >> 16;
+            src_stride = ch->stride & 0xffff;
+        } else {
+            ylen = 1;
+            xlen = ch->txfr_len;
+            dst_stride = 0;
+            src_stride = 0;
+        }
+
+        while (ylen != 0) {
+            /* Normal transfer mode */
+            while (xlen != 0) {
+                if (ch->ti & BCM2708_DMA_S_IGNORE) {
+                    /* Ignore reads */
+                    data = 0;
+                } else {
+                    data = ldl_phys(&s->dma_as, ch->source_ad);
+                }
+                if (ch->ti & BCM2708_DMA_S_INC) {
+                    ch->source_ad += 4;
+                }
+
+                if (ch->ti & BCM2708_DMA_D_IGNORE) {
+                    /* Ignore writes */
+                } else {
+                    stl_phys(&s->dma_as, ch->dest_ad, data);
+                }
+                if (ch->ti & BCM2708_DMA_D_INC) {
+                    ch->dest_ad += 4;
+                }
+
+                /* update remaining transfer length */
+                xlen -= 4;
+                if (ch->ti & BCM2708_DMA_TDMODE) {
+                    ch->txfr_len = (ylen << 16) | xlen;
+                } else {
+                    ch->txfr_len = xlen;
+                }
+            }
+
+            if (--ylen != 0) {
+                ch->source_ad += src_stride;
+                ch->dest_ad += dst_stride;
+            }
+        }

hw/dma/bcm2835_dma.c line 126

Quoted 10 lines
hw/dma/bcm2835_dma.c new file +10 -0
+        ch->cs |= BCM2708_DMA_END;
+        if (ch->ti & BCM2708_DMA_INT_EN) {
+            ch->cs |= BCM2708_DMA_INT;
+            s->int_status |= (1 << c);
+            qemu_set_irq(ch->irq, 1);
+        }
+
+        /* Process next CB */
+        ch->conblk_ad = ch->nextconbk;
+    }

This loop allows a guest to make QEMU lock up (stop responding to monitor commands, etc) if it feeds the device a circular loop of CBs. On the other hand I don't think we have a good approach to avoiding this problem, so never mind.

hw/dma/bcm2835_dma.c line 137

Quoted 11 lines
hw/dma/bcm2835_dma.c new file +11 -0
+    ch->cs &= ~BCM2708_DMA_ACTIVE;
+}
+
+static uint64_t bcm2835_dma_read(BCM2835DMAState *s, hwaddr offset,
+                                 unsigned size, unsigned c)
+{
+    BCM2835DMAChan *ch = &s->chan[c];
+    uint32_t res = 0;
+
+    assert(size == 4);
+    assert(c < BCM2835_DMA_NCHANS);

It's a bit late to assert after you've already used c as an array index... (the compiler is free to conclude that the condition must always be true, for instance.)

Quoted 41 lines
hw/dma/bcm2835_dma.c new file +41 -0
+
+    switch (offset) {
+    case BCM2708_DMA_CS:
+        res = ch->cs;
+        break;
+    case BCM2708_DMA_ADDR:
+        res = ch->conblk_ad;
+        break;
+    case BCM2708_DMA_INFO:
+        res = ch->ti;
+        break;
+    case BCM2708_DMA_SOURCE_AD:
+        res = ch->source_ad;
+        break;
+    case BCM2708_DMA_DEST_AD:
+        res = ch->dest_ad;
+        break;
+    case BCM2708_DMA_TXFR_LEN:
+        res = ch->txfr_len;
+        break;
+    case BCM2708_DMA_STRIDE:
+        res = ch->stride;
+        break;
+    case BCM2708_DMA_NEXTCB:
+        res = ch->nextconbk;
+        break;
+    case BCM2708_DMA_DEBUG:
+        res = ch->debug;
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
+                      __func__, offset);
+        break;
+    }
+    return res;
+}
+
+static void bcm2835_dma_write(BCM2835DMAState *s, hwaddr offset,
+                              uint64_t value, unsigned size, unsigned c)
+{
+    BCM2835DMAChan *ch = &s->chan[c];

hw/dma/bcm2835_dma.c line 188

Quoted 10 lines
hw/dma/bcm2835_dma.c new file +10 -0
+    uint32_t oldcs;
+
+    assert(size == 4);
+    assert(c < BCM2835_DMA_NCHANS);
+
+    switch (offset) {
+    case BCM2708_DMA_CS:
+        oldcs = ch->cs;
+        if (value & BCM2708_DMA_RESET) {
+            ch->cs |= BCM2708_DMA_RESET;

The comment about this bit earlier says it's self-clearing, but I don't see where it gets cleared.

Otherwise looks OK.

thanks
-- PMM

#2 lore raw

I'd be glad if you add a sign-off by me, but it doesn't matter much. Having this work finally getting into mainstream thanks to Andrew is what matters there.
Best regards,
Gregory

Quoted 200 lines · Peter Maydell
Quoted 19 lines · Andrew Baumann

---
This patch applies on top of the previous series for Windows and framebuffer support:
https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg06387.html

After preparing that, I was disappointed to discover that Raspbian won't boot cleanly without the DMA controller. In the hope of beating the freeze deadline (it's still February 29 here :-) I'm sending this for review.

After applying this patch, it is possible to boot Raspbian to the GUI using a command such as:

qemu-system-arm -M raspi2 -kernel raspbian-boot/kernel7.img -sd 2015-09-24-raspbian-jessie.img -append "rw earlyprintk loglevel=8 console=ttyAMA0 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootwait" -dtb raspbian-boot/bcm2709-rpi-2-b.dtb -serial stdio

Quoted 4 lines

As before, this derives from the original (out of tree) work of Gregory Estrade, Stefan Weil and others to support Raspberry Pi
1. This patch in particulary is Gregory's code, which I have cleaned up for submission.

Should it have a Signed-off-by: line and/or authorship line from Gregory, then?

(This is largely about giving credit where due, so it's Gregory's choice really. I forget whether we've had this discussion before but I couldn't find anything in a quick sweep through earlier mail threads.)

Quoted 8 lines
hw/dma/bcm2835_dma.c new file +8 -0
+static void bcm2835_dma_update(BCM2835DMAState *s, unsigned c)
+{
+    BCM2835DMAChan *ch = &s->chan[c];
+    uint32_t data, xlen, ylen;
+    int16_t dst_stride, src_stride;
+
+    if (!(s->enable & (1 << c))) {
+        return;

hw/dma/bcm2835_dma.c line 66

Quoted 10 lines
hw/dma/bcm2835_dma.c new file +10 -0
+    }
+
+    while ((s->enable & (1 << c)) && (ch->conblk_ad != 0)) {
+        /* CB fetch */
+        ch->ti = ldl_phys(&s->dma_as, ch->conblk_ad);
+        ch->source_ad = ldl_phys(&s->dma_as, ch->conblk_ad + 4);
+        ch->dest_ad = ldl_phys(&s->dma_as, ch->conblk_ad + 8);
+        ch->txfr_len = ldl_phys(&s->dma_as, ch->conblk_ad + 12);
+        ch->stride = ldl_phys(&s->dma_as, ch->conblk_ad + 16);
+        ch->nextconbk = ldl_phys(&s->dma_as, ch->conblk_ad + 20);

These should use the ldl_{le,be}_phys functions. (If you care about modelling the response to "unreadable address" you can use address_space_ldl_{le,be}.)

Quoted 50 lines
hw/dma/bcm2835_dma.c new file +50 -0
+
+        if (ch->ti & BCM2708_DMA_TDMODE) {
+            /* 2D transfer mode */
+            ylen = (ch->txfr_len >> 16) & 0x3fff;
+            xlen = ch->txfr_len & 0xffff;
+            dst_stride = ch->stride >> 16;
+            src_stride = ch->stride & 0xffff;
+        } else {
+            ylen = 1;
+            xlen = ch->txfr_len;
+            dst_stride = 0;
+            src_stride = 0;
+        }
+
+        while (ylen != 0) {
+            /* Normal transfer mode */
+            while (xlen != 0) {
+                if (ch->ti & BCM2708_DMA_S_IGNORE) {
+                    /* Ignore reads */
+                    data = 0;
+                } else {
+                    data = ldl_phys(&s->dma_as, ch->source_ad);
+                }
+                if (ch->ti & BCM2708_DMA_S_INC) {
+                    ch->source_ad += 4;
+                }
+
+                if (ch->ti & BCM2708_DMA_D_IGNORE) {
+                    /* Ignore writes */
+                } else {
+                    stl_phys(&s->dma_as, ch->dest_ad, data);
+                }
+                if (ch->ti & BCM2708_DMA_D_INC) {
+                    ch->dest_ad += 4;
+                }
+
+                /* update remaining transfer length */
+                xlen -= 4;
+                if (ch->ti & BCM2708_DMA_TDMODE) {
+                    ch->txfr_len = (ylen << 16) | xlen;
+                } else {
+                    ch->txfr_len = xlen;
+                }
+            }
+
+            if (--ylen != 0) {
+                ch->source_ad += src_stride;
+                ch->dest_ad += dst_stride;
+            }
+        }

hw/dma/bcm2835_dma.c line 126

Quoted 10 lines
hw/dma/bcm2835_dma.c new file +10 -0
+        ch->cs |= BCM2708_DMA_END;
+        if (ch->ti & BCM2708_DMA_INT_EN) {
+            ch->cs |= BCM2708_DMA_INT;
+            s->int_status |= (1 << c);
+            qemu_set_irq(ch->irq, 1);
+        }
+
+        /* Process next CB */
+        ch->conblk_ad = ch->nextconbk;
+    }

This loop allows a guest to make QEMU lock up (stop responding to monitor commands, etc) if it feeds the device a circular loop of CBs. On the other hand I don't think we have a good approach to avoiding this problem, so never mind.

hw/dma/bcm2835_dma.c line 137

Quoted 11 lines
hw/dma/bcm2835_dma.c new file +11 -0
+    ch->cs &= ~BCM2708_DMA_ACTIVE;
+}
+
+static uint64_t bcm2835_dma_read(BCM2835DMAState *s, hwaddr offset,
+                                 unsigned size, unsigned c)
+{
+    BCM2835DMAChan *ch = &s->chan[c];
+    uint32_t res = 0;
+
+    assert(size == 4);
+    assert(c < BCM2835_DMA_NCHANS);

It's a bit late to assert after you've already used c as an array index... (the compiler is free to conclude that the condition must always be true, for instance.)

Quoted 21 lines
hw/dma/bcm2835_dma.c new file +21 -0
+
+    switch (offset) {
+    case BCM2708_DMA_CS:
+        res = ch->cs;
+        break;
+    case BCM2708_DMA_ADDR:
+        res = ch->conblk_ad;
+        break;
+    case BCM2708_DMA_INFO:
+        res = ch->ti;
+        break;
+    case BCM2708_DMA_SOURCE_AD:
+        res = ch->source_ad;
+        break;
+    case BCM2708_DMA_DEST_AD:
+        res = ch->dest_ad;
+        break;
+    case BCM2708_DMA_TXFR_LEN:
+        res = ch->txfr_len;
+        break;
+    case BCM2708_DMA_STRIDE:

hw/dma/bcm2835_dma.c

Quoted 10 lines
hw/dma/bcm2835_dma.c new file +10 -0
+        res = ch->stride;
+        break;
+    case BCM2708_DMA_NEXTCB:
+        res = ch->nextconbk;
+        break;
+    case BCM2708_DMA_DEBUG:
+        res = ch->debug;
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset

%"HWADDR_PRIx"\n",

Quoted 10 lines
hw/dma/bcm2835_dma.c new file +10 -0
+                      __func__, offset);
+        break;
+    }
+    return res;
+}
+
+static void bcm2835_dma_write(BCM2835DMAState *s, hwaddr offset,
+                              uint64_t value, unsigned size, unsigned c)
+{
+    BCM2835DMAChan *ch = &s->chan[c];

hw/dma/bcm2835_dma.c line 188

Quoted 10 lines
hw/dma/bcm2835_dma.c new file +10 -0
+    uint32_t oldcs;
+
+    assert(size == 4);
+    assert(c < BCM2835_DMA_NCHANS);
+
+    switch (offset) {
+    case BCM2708_DMA_CS:
+        oldcs = ch->cs;
+        if (value & BCM2708_DMA_RESET) {
+            ch->cs |= BCM2708_DMA_RESET;

The comment about this bit earlier says it's self-clearing, but I don't see where it gets cleared.

Otherwise looks OK.

thanks
-- PMM

#3 lore raw
In reply to Peter Maydell

Hi,

Quoted 11 lines

hw/dma/bcm2835_dma.c line 126

Quoted 10 lines
hw/dma/bcm2835_dma.c new file +10 -0
+        ch->cs |= BCM2708_DMA_END;
+        if (ch->ti & BCM2708_DMA_INT_EN) {
+            ch->cs |= BCM2708_DMA_INT;
+            s->int_status |= (1 << c);
+            qemu_set_irq(ch->irq, 1);
+        }
+
+        /* Process next CB */
+        ch->conblk_ad = ch->nextconbk;
+    }
Quoted 4 lines

This loop allows a guest to make QEMU lock up (stop responding to monitor commands, etc) if it feeds the device a circular loop of CBs. On the other hand I don't think we have a good approach to avoiding this problem, so never mind.

usb emulation has this problem too.

uhci queue heads can go in circles. The emulation code keeps a linked list of active queue heads, which is (among other bookkeeping things) used to detect when we run in circles. It's a legal thing to do for a guest btw, so you can see that happening in practice.

until recently ehci could be tricked into running in loops too, by creating a circular chain of IDTs. Which is not legal according to specs, so this went unnoticed for a while. But a malicious guest can do it nevertheless. That one was fixed by stopping IDT processing in case no data was transfered. This is possible because the ehci controller writes back the status to the IDT, so we can figure there is nothing to do (because we already processed that IDT) without additional bookkeeping, by simply checking the status.

From a brief look at the patch it seems you can not use the later for the bcm2835 dma controller, I can't spot a place where the some status is written back to the dma contol block ...

cheers,
Gerd

#4 lore raw
Quoted 16 lines · Gerd Hoffmann

usb emulation has this problem too.

uhci queue heads can go in circles. The emulation code keeps a linked list of active queue heads, which is (among other bookkeeping things) used to detect when we run in circles. It's a legal thing to do for a guest btw, so you can see that happening in practice.

until recently ehci could be tricked into running in loops too, by creating a circular chain of IDTs. Which is not legal according to specs, so this went unnoticed for a while. But a malicious guest can do it nevertheless. That one was fixed by stopping IDT processing in case no data was transfered. This is possible because the ehci controller writes back the status to the IDT, so we can figure there is nothing to do (because we already processed that IDT) without additional bookkeeping, by simply checking the status.

Quoted 3 lines

From a brief look at the patch it seems you can not use the later for the bcm2835 dma controller, I can't spot a place where the some status is written back to the dma contol block ...

I guess a more general approach to the problem would be to have a (hopefully easy) way to say "if this has been going on for too long then arrange to defer continued processing of it til later, and for now resume the guest". That's too big a can of worms for this patch, though. (And for something that's only used in TCG emulation we care much less about malicious guests than for devices that can be used with KVM.)

thanks
-- PMM

#5 lore raw
Quoted 24 lines

From: Peter Maydell [mailto:[email protected]]
Sent: Thursday, 3 March 2016 8:22 AM

Quoted 16 lines · Gerd Hoffmann

usb emulation has this problem too.

uhci queue heads can go in circles. The emulation code keeps a linked list of active queue heads, which is (among other bookkeeping things) used to detect when we run in circles. It's a legal thing to do for a guest btw, so you can see that happening in practice.

until recently ehci could be tricked into running in loops too, by creating a circular chain of IDTs. Which is not legal according to specs, so this went unnoticed for a while. But a malicious guest can do it nevertheless. That one was fixed by stopping IDT processing in case no data was transfered. This is possible because the ehci controller writes back the status to the IDT, so we can figure there is nothing to do (because we already processed that IDT) without additional bookkeeping, by simply checking the status.

Quoted 3 lines

From a brief look at the patch it seems you can not use the later for the bcm2835 dma controller, I can't spot a place where the some status is written back to the dma contol block ...

Quoted 7 lines

I guess a more general approach to the problem would be to have a (hopefully easy) way to say "if this has been going on for too long then arrange to defer continued processing of it til later, and for now resume the guest". That's too big a can of worms for this patch, though. (And for something that's only used in TCG emulation we care much less about malicious guests than for devices that can be used with KVM.)

It seems like the ultimate solution here is to model the concurrency of DMA. Run each DMA engine as its own thread, including modelling the ability to pause/abort transfers, and provide some suitable scheduling/resource arbitration mechanism, and then you don’t need to worry about whether a guest can tie up one of those threads in a loop, because it can't hurt anyone else. Of course, this is much more complex to implement.

But in this particular case, I _really_ hope that we don't have to worry about virtual raspberry pi's in multi-tenant hosting! :)

Thanks for the feedback,
Andrew

#6 lore raw
In reply to Peter Maydell

Hi,

Quoted 4 lines

I guess a more general approach to the problem would be to have a (hopefully easy) way to say "if this has been going on for too long then arrange to defer continued processing of it til later, and for now resume the guest".

Doable today, by simply applying some limit and if we hit it schedule a timer to continue later.

uhci emulation does this, but it's basically no extra work there as usb emulation is timer based _anyway_.

Quoted 4 lines

That's too big a can of worms for
this patch, though. (And for something that's only used in TCG emulation we care much less about malicious guests than for devices that can be used with KVM.)

Agree, given the use case this isn't critical by any means.

cheers,
Gerd