Skip to contentSkip to conversation

aspeed: Improve error handling and fix DMA issues

PATCH Superseded Cédric Le Goater 4 participants 9 messages Mar 22 – Mar 23 Arm/Aspeed machine support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover aspeed: Improve error handling and fix DMA issues

Hello,

This series addresses several error handling issues in Aspeed device models that could lead to guest-triggerable denial of service or incorrect behavior.

The first two patches improve DMA error handling by properly propagating memory transaction errors to the guest. The aspeed_smc patch converts memory operations to use read/write_with_attrs to return MEMTX_ERROR on invalid conditions, while the ftgmac100 patch checks DMA operation return values.

The third patch fixes an incorrect assertion in the aspeed_i2c model that could be triggered when firmware uses the RX_BUF_LEN_W1T bit to program DMA length fields separately, which is valid per the Aspeed datasheet.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3335
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3315

Thanks,

C.

Cédric Le Goater (3):
hw/ssi/aspeed_smc: Convert mem ops to read/write_with_attrs for error
handling
ftgmac100: Improve DMA error handling
hw/i2c/aspeed_i2c: Remove assert

 hw/i2c/aspeed_i2c.c |  1 -
 hw/net/ftgmac100.c  | 10 ++++++--
 hw/ssi/aspeed_smc.c | 58 ++++++++++++++++++++++++++-------------------
 3 files changed, 42 insertions(+), 27 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/3 hw/ssi/aspeed_smc: Convert mem ops to read/write_with_attrs for error handling

Error conditions (invalid flash mode, unwritable flash, invalid data FIFO offset) now return MEMTX_ERROR instead of silently succeeding or returning undefined values.

This allows the memory subsystem to properly propagate transaction errors to the guest, improving QEMU reliability.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3335

---
 hw/ssi/aspeed_smc.c | 58 ++++++++++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 24 deletions(-)
hw/ssi/aspeed_smc.c +34 -24
index ed6cedabcb3b..b14b1cbddfc3 100644
@@ -502,17 +502,18 @@ static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr)
     }
 }
 
-static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
+static MemTxResult aspeed_smc_flash_read(void *opaque, hwaddr addr,
+                                 uint64_t *data, unsigned size, MemTxAttrs attrs)
 {
     AspeedSMCFlash *fl = opaque;
     AspeedSMCState *s = fl->controller;
-    uint64_t ret = 0;
     int i;
 
+    *data = 0;
     switch (aspeed_smc_flash_mode(fl)) {
     case CTRL_USERMODE:
         for (i = 0; i < size; i++) {
-            ret |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
+            *data |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
         }
         break;
     case CTRL_READMODE:
@@ -521,18 +522,19 @@ static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
         aspeed_smc_flash_setup(fl, addr);
 
         for (i = 0; i < size; i++) {
-            ret |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
+            *data |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
         }
 
         aspeed_smc_flash_unselect(fl);
         break;
     default:
         aspeed_smc_error("invalid flash mode %d", aspeed_smc_flash_mode(fl));
+        return MEMTX_ERROR;
     }
 
-    trace_aspeed_smc_flash_read(fl->cs, addr, size, ret,
+    trace_aspeed_smc_flash_read(fl->cs, addr, size, *data,
                                 aspeed_smc_flash_mode(fl));
-    return ret;
+    return MEMTX_OK;
 }
 
 /*
@@ -633,8 +635,8 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl,  uint64_t data,
     return false;
 }
 
-static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
-                                   unsigned size)
+static MemTxResult aspeed_smc_flash_write(void *opaque, hwaddr addr,
+                                   uint64_t data, unsigned size, MemTxAttrs attrs)
 {
     AspeedSMCFlash *fl = opaque;
     AspeedSMCState *s = fl->controller;
@@ -645,7 +647,7 @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
 
     if (!aspeed_smc_is_writable(fl)) {
         aspeed_smc_error("flash is not writable at 0x%" HWADDR_PRIx, addr);
-        return;
+        return MEMTX_ERROR;
     }
 
     switch (aspeed_smc_flash_mode(fl)) {
@@ -670,12 +672,15 @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     default:
         aspeed_smc_error("invalid flash mode %d", aspeed_smc_flash_mode(fl));
+        return MEMTX_ERROR;
     }
+
+    return MEMTX_OK;
 }
 
 static const MemoryRegionOps aspeed_smc_flash_ops = {
-    .read = aspeed_smc_flash_read,
-    .write = aspeed_smc_flash_write,
+    .read_with_attrs = aspeed_smc_flash_read,
+    .write_with_attrs = aspeed_smc_flash_write,
     .endianness = DEVICE_LITTLE_ENDIAN,
     .valid = {
         .min_access_size = 1,
@@ -763,7 +768,8 @@ static void aspeed_smc_reset(DeviceState *d)
     s->snoop_dummies = 0;
 }
 
-static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
+static MemTxResult aspeed_smc_read(void *opaque, hwaddr addr, uint64_t *data,
+                                   unsigned int size, MemTxAttrs attrs)
 {
     AspeedSMCState *s = ASPEED_SMC(opaque);
     AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(opaque);
@@ -792,7 +798,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
 
         trace_aspeed_smc_read(addr << 2, size, s->regs[addr]);
 
-        return s->regs[addr];
+        *data = s->regs[addr];
     } else if (aspeed_smc_has_data_fifo(asc) && addr >= R_DATA_FIFO) {
         cs = asc->data_fifo_offset_to_cs(s, addr << 2);
         if (cs >= 0) {
@@ -801,15 +807,17 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
              * The flash address is provided by the SPI command/address cycles,
              * the MMIO addr parameter is ignored.
              */
-            return aspeed_smc_flash_read(&s->flashes[cs], 0, size);
+            return aspeed_smc_flash_read(&s->flashes[cs], 0, data, size, attrs);
         }
         aspeed_smc_error("Invalid data fifo offset %" HWADDR_PRIx, addr << 2);
-        return -1;
+        *data = -1;
+        return MEMTX_ERROR;
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                       __func__, addr);
-        return -1;
+        *data = -1;
     }
+    return MEMTX_OK;
 }
 
 static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask)
@@ -1130,8 +1138,8 @@ static void aspeed_2600_smc_dma_ctrl(AspeedSMCState *s, uint32_t dma_ctrl)
     s->regs[R_DMA_CTRL] &= ~(DMA_CTRL_REQUEST | DMA_CTRL_GRANT);
 }
 
-static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
-                             unsigned int size)
+static MemTxResult aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
+                                    unsigned int size, MemTxAttrs attrs)
 {
     AspeedSMCState *s = ASPEED_SMC(opaque);
     AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(s);
@@ -1186,19 +1194,21 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
              * The flash address is provided by the SPI command/address cycles,
              * the MMIO addr parameter is ignored.
              */
-            return aspeed_smc_flash_write(&s->flashes[cs], 0, data, size);
+            return aspeed_smc_flash_write(&s->flashes[cs], 0, data, size,
+                                          attrs);
         }
         aspeed_smc_error("Invalid data fifo offset %" HWADDR_PRIx, addr << 2);
+        return MEMTX_ERROR;
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                       __func__, addr);
-        return;
     }
+    return MEMTX_OK;
 }
 
 static const MemoryRegionOps aspeed_smc_ops = {
-    .read = aspeed_smc_read,
-    .write = aspeed_smc_write,
+    .read_with_attrs = aspeed_smc_read,
+    .write_with_attrs = aspeed_smc_write,
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
@@ -2073,8 +2083,8 @@ static const uint32_t aspeed_2700_fmc_resets[ASPEED_SMC_R_MAX] = {
 };
 
 static const MemoryRegionOps aspeed_2700_smc_flash_ops = {
-    .read = aspeed_smc_flash_read,
-    .write = aspeed_smc_flash_write,
+    .read_with_attrs = aspeed_smc_flash_read,
+    .write_with_attrs = aspeed_smc_flash_write,
     .endianness = DEVICE_LITTLE_ENDIAN,
     .valid = {
         .min_access_size = 1,
Signature · 1 line
2.53.0
Reviewed-by on v1 1/3
#2 lore raw

RE: [PATCH 1/3] hw/ssi/aspeed_smc: Convert mem ops to read/write_with_attrs for error handling

Quoted 224 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, March 23, 2026 5:58 AM
To: [email protected]
Cc: [email protected]; Peter Maydell <[email protected]>; Jamin Lin <[email protected]>; Kane Chen <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH 1/3] hw/ssi/aspeed_smc: Convert mem ops to read/write_with_attrs for error handling

Error conditions (invalid flash mode, unwritable flash, invalid data FIFO offset) now return MEMTX_ERROR instead of silently succeeding or returning undefined values.

This allows the memory subsystem to properly propagate transaction errors to the guest, improving QEMU reliability.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3335

---
 hw/ssi/aspeed_smc.c | 58 ++++++++++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 24 deletions(-)
hw/ssi/aspeed_smc.c index renamed from hw/ssi/aspeed_smc.c +0 -0

ed6cedabcb3b..b14b1cbddfc3 100644

hw/ssi/aspeed_smc.c +9 -6
@@ -502,17 +502,18 @@ static void
 aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr)
     }
 }
 
-static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned
 size)
+static MemTxResult aspeed_smc_flash_read(void *opaque, hwaddr addr,
+                                 uint64_t *data, unsigned size,
+MemTxAttrs attrs)
 {
     AspeedSMCFlash *fl = opaque;
     AspeedSMCState *s = fl->controller;
-    uint64_t ret = 0;
     int i;
 
+    *data = 0;
     switch (aspeed_smc_flash_mode(fl)) {
     case CTRL_USERMODE:
         for (i = 0; i < size; i++) {
-            ret |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
+            *data |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
         }
         break;
     case CTRL_READMODE:
@@ -521,18 +522,19 @@ static uint64_t aspeed_smc_flash_read(void
 *opaque, hwaddr addr, unsigned size)
         aspeed_smc_flash_setup(fl, addr);
 
         for (i = 0; i < size; i++) {
-            ret |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
+            *data |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
         }
 
         aspeed_smc_flash_unselect(fl);
         break;
     default:
         aspeed_smc_error("invalid flash mode %d",
 aspeed_smc_flash_mode(fl));
+        return MEMTX_ERROR;
     }
 
-    trace_aspeed_smc_flash_read(fl->cs, addr, size, ret,
+    trace_aspeed_smc_flash_read(fl->cs, addr, size, *data,
                                 aspeed_smc_flash_mode(fl));
-    return ret;
+    return MEMTX_OK;
 }

/*

hw/ssi/aspeed_smc.c +3 -2
@@ -633,8 +635,8 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash
 *fl,  uint64_t data,
     return false;
 }
 
-static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t
 data,
-                                   unsigned size)
+static MemTxResult aspeed_smc_flash_write(void *opaque, hwaddr addr,
+                                   uint64_t data, unsigned size,
+MemTxAttrs attrs)
 {
     AspeedSMCFlash *fl = opaque;
     AspeedSMCState *s = fl->controller; @@ -645,7 +647,7 @@ static void

aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,

     if (!aspeed_smc_is_writable(fl)) {
         aspeed_smc_error("flash is not writable at 0x%" HWADDR_PRIx,

addr);

hw/ssi/aspeed_smc.c +1 -1
-        return;
+        return MEMTX_ERROR;
     }
 
     switch (aspeed_smc_flash_mode(fl)) { @@ -670,12 +672,15 @@ static

void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
break;
default:
aspeed_smc_error("invalid flash mode %d",
aspeed_smc_flash_mode(fl));

hw/ssi/aspeed_smc.c +7 -3
+        return MEMTX_ERROR;
     }
+
+    return MEMTX_OK;
 }
 
 static const MemoryRegionOps aspeed_smc_flash_ops = {
-    .read = aspeed_smc_flash_read,
-    .write = aspeed_smc_flash_write,
+    .read_with_attrs = aspeed_smc_flash_read,
+    .write_with_attrs = aspeed_smc_flash_write,
     .endianness = DEVICE_LITTLE_ENDIAN,
     .valid = {
         .min_access_size = 1,
@@ -763,7 +768,8 @@ static void aspeed_smc_reset(DeviceState *d)
     s->snoop_dummies = 0;
 }
 
-static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int
 size)
+static MemTxResult aspeed_smc_read(void *opaque, hwaddr addr, uint64_t
 *data,
+                                   unsigned int size, MemTxAttrs
 attrs)
 {
     AspeedSMCState *s = ASPEED_SMC(opaque);
     AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(opaque); @@ -792,7

+798,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)

         trace_aspeed_smc_read(addr << 2, size, s->regs[addr]);
hw/ssi/aspeed_smc.c +6 -4
-        return s->regs[addr];
+        *data = s->regs[addr];
     } else if (aspeed_smc_has_data_fifo(asc) && addr >= R_DATA_FIFO) {
         cs = asc->data_fifo_offset_to_cs(s, addr << 2);
         if (cs >= 0) {
@@ -801,15 +807,17 @@ static uint64_t aspeed_smc_read(void *opaque,
 hwaddr addr, unsigned int size)
              * The flash address is provided by the SPI command/address
 cycles,
              * the MMIO addr parameter is ignored.
              */
-            return aspeed_smc_flash_read(&s->flashes[cs], 0, size);
+            return aspeed_smc_flash_read(&s->flashes[cs], 0, data,
+ size, attrs);
         }
         aspeed_smc_error("Invalid data fifo offset %" HWADDR_PRIx, addr
 << 2);
-        return -1;
+        *data = -1;
+        return MEMTX_ERROR;
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%"
 HWADDR_PRIx "\n",
                       __func__, addr);
-        return -1;
+        *data = -1;
     }

+ return MEMTX_OK;
}

static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask) @@ -1130,8
+1138,8 @@ static void aspeed_2600_smc_dma_ctrl(AspeedSMCState *s, uint32_t dma_ctrl)

     s->regs[R_DMA_CTRL] &= ~(DMA_CTRL_REQUEST |

DMA_CTRL_GRANT); }

hw/ssi/aspeed_smc.c +1 -2
-static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
-                             unsigned int size)
+static MemTxResult aspeed_smc_write(void *opaque, hwaddr addr, uint64_t

data,

hw/ssi/aspeed_smc.c +3 -0
+                                    unsigned int size, MemTxAttrs
+attrs)
 {
     AspeedSMCState *s = ASPEED_SMC(opaque);
     AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(s); @@ -1186,19
+1194,21 @@ static void aspeed_smc_write(void *opaque, hwaddr addr,

uint64_t data,
* The flash address is provided by the SPI command/address
cycles,
* the MMIO addr parameter is ignored.
*/

hw/ssi/aspeed_smc.c +2 -1
-            return aspeed_smc_flash_write(&s->flashes[cs], 0, data, size);
+            return aspeed_smc_flash_write(&s->flashes[cs], 0, data, size,
+                                          attrs);
         }
         aspeed_smc_error("Invalid data fifo offset %" HWADDR_PRIx, addr

<< 2);

+        return MEMTX_ERROR;
     } else {
         qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%"
HWADDR_PRIx "\n",
                       __func__, addr);
hw/ssi/aspeed_smc.c +5 -6
-        return;
     }
+    return MEMTX_OK;
 }
 
 static const MemoryRegionOps aspeed_smc_ops = {
-    .read = aspeed_smc_read,
-    .write = aspeed_smc_write,
+    .read_with_attrs = aspeed_smc_read,
+    .write_with_attrs = aspeed_smc_write,
     .endianness = DEVICE_LITTLE_ENDIAN,  };
@@ -2073,8 +2083,8 @@ static const uint32_t
 aspeed_2700_fmc_resets[ASPEED_SMC_R_MAX] = {  };
 
 static const MemoryRegionOps aspeed_2700_smc_flash_ops = {
-    .read = aspeed_smc_flash_read,
-    .write = aspeed_smc_flash_write,
+    .read_with_attrs = aspeed_smc_flash_read,
+    .write_with_attrs = aspeed_smc_flash_write,
     .endianness = DEVICE_LITTLE_ENDIAN,
     .valid = {
         .min_access_size = 1,
--
Quoted 1 line

2.53.0

Thanks,
Jamin

#3 lore raw

Re: [PATCH 1/3] hw/ssi/aspeed_smc: Convert mem ops to read/write_with_attrs for error handling

In reply to Cédric Le Goater
Quoted 3 lines · Cédric Le Goater

Error conditions (invalid flash mode, unwritable flash, invalid data FIFO offset) now return MEMTX_ERROR instead of silently succeeding or returning undefined values.

The invalid FIFO offset is not upstream yet, only in my aspeed-11.0 branch including :

https://lore.kernel.org/all/[email protected]/

I will resend a v2 with the updated patch.

Thanks,

C.

Quoted 184 lines

This allows the memory subsystem to properly propagate transaction errors to the guest, improving QEMU reliability.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3335

---
  hw/ssi/aspeed_smc.c | 58 ++++++++++++++++++++++++++-------------------
  1 file changed, 34 insertions(+), 24 deletions(-)
hw/ssi/aspeed_smc.c +34 -24
index ed6cedabcb3b..b14b1cbddfc3 100644
@@ -502,17 +502,18 @@ static void aspeed_smc_flash_setup(AspeedSMCFlash *fl, uint32_t addr)
      }
  }
 
-static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
+static MemTxResult aspeed_smc_flash_read(void *opaque, hwaddr addr,
+                                 uint64_t *data, unsigned size, MemTxAttrs attrs)
  {
      AspeedSMCFlash *fl = opaque;
      AspeedSMCState *s = fl->controller;
-    uint64_t ret = 0;
      int i;
 
+    *data = 0;
      switch (aspeed_smc_flash_mode(fl)) {
      case CTRL_USERMODE:
          for (i = 0; i < size; i++) {
-            ret |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
+            *data |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
          }
          break;
      case CTRL_READMODE:
@@ -521,18 +522,19 @@ static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
          aspeed_smc_flash_setup(fl, addr);
 
          for (i = 0; i < size; i++) {
-            ret |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
+            *data |= (uint64_t) ssi_transfer(s->spi, 0x0) << (8 * i);
          }
 
          aspeed_smc_flash_unselect(fl);
          break;
      default:
          aspeed_smc_error("invalid flash mode %d", aspeed_smc_flash_mode(fl));
+        return MEMTX_ERROR;
      }
 
-    trace_aspeed_smc_flash_read(fl->cs, addr, size, ret,
+    trace_aspeed_smc_flash_read(fl->cs, addr, size, *data,
                                  aspeed_smc_flash_mode(fl));
-    return ret;
+    return MEMTX_OK;
  }
 
  /*
@@ -633,8 +635,8 @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl,  uint64_t data,
      return false;
  }
 
-static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
-                                   unsigned size)
+static MemTxResult aspeed_smc_flash_write(void *opaque, hwaddr addr,
+                                   uint64_t data, unsigned size, MemTxAttrs attrs)
  {
      AspeedSMCFlash *fl = opaque;
      AspeedSMCState *s = fl->controller;
@@ -645,7 +647,7 @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
 
      if (!aspeed_smc_is_writable(fl)) {
          aspeed_smc_error("flash is not writable at 0x%" HWADDR_PRIx, addr);
-        return;
+        return MEMTX_ERROR;
      }
 
      switch (aspeed_smc_flash_mode(fl)) {
@@ -670,12 +672,15 @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
          break;
      default:
          aspeed_smc_error("invalid flash mode %d", aspeed_smc_flash_mode(fl));
+        return MEMTX_ERROR;
      }
+
+    return MEMTX_OK;
  }
 
  static const MemoryRegionOps aspeed_smc_flash_ops = {
-    .read = aspeed_smc_flash_read,
-    .write = aspeed_smc_flash_write,
+    .read_with_attrs = aspeed_smc_flash_read,
+    .write_with_attrs = aspeed_smc_flash_write,
      .endianness = DEVICE_LITTLE_ENDIAN,
      .valid = {
          .min_access_size = 1,
@@ -763,7 +768,8 @@ static void aspeed_smc_reset(DeviceState *d)
      s->snoop_dummies = 0;
  }
 
-static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
+static MemTxResult aspeed_smc_read(void *opaque, hwaddr addr, uint64_t *data,
+                                   unsigned int size, MemTxAttrs attrs)
  {
      AspeedSMCState *s = ASPEED_SMC(opaque);
      AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(opaque);
@@ -792,7 +798,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
 
          trace_aspeed_smc_read(addr << 2, size, s->regs[addr]);
 
-        return s->regs[addr];
+        *data = s->regs[addr];
      } else if (aspeed_smc_has_data_fifo(asc) && addr >= R_DATA_FIFO) {
          cs = asc->data_fifo_offset_to_cs(s, addr << 2);
          if (cs >= 0) {
@@ -801,15 +807,17 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
               * The flash address is provided by the SPI command/address cycles,
               * the MMIO addr parameter is ignored.
               */
-            return aspeed_smc_flash_read(&s->flashes[cs], 0, size);
+            return aspeed_smc_flash_read(&s->flashes[cs], 0, data, size, attrs);
          }
          aspeed_smc_error("Invalid data fifo offset %" HWADDR_PRIx, addr << 2);
-        return -1;
+        *data = -1;
+        return MEMTX_ERROR;
      } else {
          qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                        __func__, addr);
-        return -1;
+        *data = -1;
      }
+    return MEMTX_OK;
  }
 
  static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask)
@@ -1130,8 +1138,8 @@ static void aspeed_2600_smc_dma_ctrl(AspeedSMCState *s, uint32_t dma_ctrl)
      s->regs[R_DMA_CTRL] &= ~(DMA_CTRL_REQUEST | DMA_CTRL_GRANT);
  }
 
-static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
-                             unsigned int size)
+static MemTxResult aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
+                                    unsigned int size, MemTxAttrs attrs)
  {
      AspeedSMCState *s = ASPEED_SMC(opaque);
      AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(s);
@@ -1186,19 +1194,21 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
               * The flash address is provided by the SPI command/address cycles,
               * the MMIO addr parameter is ignored.
               */
-            return aspeed_smc_flash_write(&s->flashes[cs], 0, data, size);
+            return aspeed_smc_flash_write(&s->flashes[cs], 0, data, size,
+                                          attrs);
          }
          aspeed_smc_error("Invalid data fifo offset %" HWADDR_PRIx, addr << 2);
+        return MEMTX_ERROR;
      } else {
          qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
                        __func__, addr);
-        return;
      }
+    return MEMTX_OK;
  }
 
  static const MemoryRegionOps aspeed_smc_ops = {
-    .read = aspeed_smc_read,
-    .write = aspeed_smc_write,
+    .read_with_attrs = aspeed_smc_read,
+    .write_with_attrs = aspeed_smc_write,
      .endianness = DEVICE_LITTLE_ENDIAN,
  };
 
@@ -2073,8 +2083,8 @@ static const uint32_t aspeed_2700_fmc_resets[ASPEED_SMC_R_MAX] = {
  };
 
  static const MemoryRegionOps aspeed_2700_smc_flash_ops = {
-    .read = aspeed_smc_flash_read,
-    .write = aspeed_smc_flash_write,
+    .read_with_attrs = aspeed_smc_flash_read,
+    .write_with_attrs = aspeed_smc_flash_write,
      .endianness = DEVICE_LITTLE_ENDIAN,
      .valid = {
          .min_access_size = 1,
#4 lore raw

PATCH 2/3 ftgmac100: Improve DMA error handling

In reply to Cédric Le Goater

Currently, DMA memory operation errors in the ftgmac100 model are not all tested and this can lead to a guest-triggerable denial of service as described in https://gitlab.com/qemu-project/qemu/-/work_items/3335.

To fix this, check the return value of ftgmac100_write_bd() in the TX path and exit the TX loop on error to prevent further processing. In the event of a DMA error, also set FTGMAC100_INT_AHB_ERR interrupt flag as appropriate.

The FTGMAC100_INT_AHB_ERR interrupt status bit only applies to the AST2400 SoC; on newer Aspeed SoCs, it is a reserved bit. Nevertheless, since it is supported by the Linux driver and it should be safe to use in the QEMU implementation across all SoCs.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3335

---
 hw/net/ftgmac100.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
hw/net/ftgmac100.c +8 -2
index 69a38adb627f..25c3ede72cbb 100644
@@ -624,7 +624,10 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint64_t tx_ring,
         bd.des0 &= ~FTGMAC100_TXDES0_TXDMA_OWN;
 
         /* Write back the modified descriptor.  */
-        ftgmac100_write_bd(&bd, addr);
+        if (ftgmac100_write_bd(&bd, addr)) {
+            s->isr |= FTGMAC100_INT_AHB_ERR;
+            break;
+        }
         /* Advance to the next descriptor.  */
         if (bd.des0 & s->txdes0_edotr) {
             addr = tx_ring;
@@ -1134,7 +1137,10 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
             bd.des0 |= flags | FTGMAC100_RXDES0_LRS;
             s->isr |= FTGMAC100_INT_RPKT_BUF;
         }
-        ftgmac100_write_bd(&bd, addr);
+        if (ftgmac100_write_bd(&bd, addr)) {
+            s->isr |= FTGMAC100_INT_AHB_ERR;
+            break;
+        }
         if (bd.des0 & s->rxdes0_edorr) {
             addr = s->rx_ring;
         } else {
Signature · 1 line
2.53.0
Reviewed-by on v1 2/3
#5 lore raw

RE: [PATCH 2/3] ftgmac100: Improve DMA error handling

Quoted 58 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, March 23, 2026 5:58 AM
To: [email protected]
Cc: [email protected]; Peter Maydell <[email protected]>; Jamin Lin <[email protected]>; Kane Chen <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH 2/3] ftgmac100: Improve DMA error handling

Currently, DMA memory operation errors in the ftgmac100 model are not all tested and this can lead to a guest-triggerable denial of service as described in
https://gitlab.com/qemu-project/qemu/-/work_items/3335.

To fix this, check the return value of ftgmac100_write_bd() in the TX path and exit the TX loop on error to prevent further processing. In the event of a DMA error, also set FTGMAC100_INT_AHB_ERR interrupt flag as appropriate.

The FTGMAC100_INT_AHB_ERR interrupt status bit only applies to the AST2400 SoC; on newer Aspeed SoCs, it is a reserved bit. Nevertheless, since it is supported by the Linux driver and it should be safe to use in the QEMU implementation across all SoCs.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3335

---
 hw/net/ftgmac100.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
hw/net/ftgmac100.c index renamed from hw/net/ftgmac100.c +0 -0

69a38adb627f..25c3ede72cbb 100644

hw/net/ftgmac100.c +4 -1
@@ -624,7 +624,10 @@ static void ftgmac100_do_tx(FTGMAC100State *s,
 uint64_t tx_ring,
         bd.des0 &= ~FTGMAC100_TXDES0_TXDMA_OWN;
 
         /* Write back the modified descriptor.  */
-        ftgmac100_write_bd(&bd, addr);
+        if (ftgmac100_write_bd(&bd, addr)) {
+            s->isr |= FTGMAC100_INT_AHB_ERR;
+            break;
+        }
         /* Advance to the next descriptor.  */
         if (bd.des0 & s->txdes0_edotr) {
             addr = tx_ring;
hw/net/ftgmac100.c +4 -1
@@ -1134,7 +1137,10 @@ static ssize_t ftgmac100_receive(NetClientState
 *nc, const uint8_t *buf,
             bd.des0 |= flags | FTGMAC100_RXDES0_LRS;
             s->isr |= FTGMAC100_INT_RPKT_BUF;
         }
-        ftgmac100_write_bd(&bd, addr);
+        if (ftgmac100_write_bd(&bd, addr)) {
+            s->isr |= FTGMAC100_INT_AHB_ERR;
+            break;
+        }
         if (bd.des0 & s->rxdes0_edorr) {
             addr = s->rx_ring;
         } else {
Quoted 2 lines

--
2.53.0

Thanks,
Jamin

Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] ftgmac100: Improve DMA error handling

In reply to Cédric Le Goater
Quoted 14 lines · Cédric Le Goater

Currently, DMA memory operation errors in the ftgmac100 model are not all tested and this can lead to a guest-triggerable denial of service as described in https://gitlab.com/qemu-project/qemu/-/work_items/3335.

To fix this, check the return value of ftgmac100_write_bd() in the TX path and exit the TX loop on error to prevent further processing. In the event of a DMA error, also set FTGMAC100_INT_AHB_ERR interrupt flag as appropriate.

The FTGMAC100_INT_AHB_ERR interrupt status bit only applies to the AST2400 SoC; on newer Aspeed SoCs, it is a reserved bit. Nevertheless, since it is supported by the Linux driver and it should be safe to use in the QEMU implementation across all SoCs.

Quoted 5 lines

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3335

---
  hw/net/ftgmac100.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
#7 lore raw

PATCH 3/3 hw/i2c/aspeed_i2c: Remove assert

In reply to Cédric Le Goater

According to the Aspeed datasheet, the RX_BUF_LEN_W1T and TX_BUF_LEN_W1T bits of the A_I2CS_DMA_LEN (0x2c) register allow firmware to program the TX and RX DMA length (TX_BUF_LEN and RX_BUF_LEN fields of the same register) separately without the need to read/modify/write the value. If RX_BUF_LEN_W1T and TX_BUF_LEN_W1T bits are 0, then both TX and RX DMA length will be written.

When setting the RX_BUF_LEN field, the TX_BUF_LEN field being set is not an invalid condition. Remove the assert.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3315

---
 hw/i2c/aspeed_i2c.c | 1 -
 1 file changed, 1 deletion(-)
hw/i2c/aspeed_i2c.c +0 -1
index ad6342bec0d4..5d18f8d49ea4 100644
@@ -780,7 +780,6 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus, hwaddr offset,
         bus->regs[R_I2CS_DMA_RX_ADDR] = value;
         break;
     case A_I2CS_DMA_LEN:
-        assert(FIELD_EX32(value, I2CS_DMA_LEN, TX_BUF_LEN) == 0);
         if (FIELD_EX32(value, I2CS_DMA_LEN, RX_BUF_LEN_W1T)) {
             ARRAY_FIELD_DP32(bus->regs, I2CS_DMA_LEN, RX_BUF_LEN,
                              FIELD_EX32(value, I2CS_DMA_LEN, RX_BUF_LEN));
Signature · 1 line
2.53.0
Reviewed-by on v1 3/3
#8 lore raw

RE: [PATCH 3/3] hw/i2c/aspeed_i2c: Remove assert

Quoted 38 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, March 23, 2026 5:58 AM
To: [email protected]
Cc: [email protected]; Peter Maydell <[email protected]>; Jamin Lin <[email protected]>; Kane Chen <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH 3/3] hw/i2c/aspeed_i2c: Remove assert

According to the Aspeed datasheet, the RX_BUF_LEN_W1T and TX_BUF_LEN_W1T bits of the A_I2CS_DMA_LEN (0x2c) register allow firmware to program the TX and RX DMA length (TX_BUF_LEN and RX_BUF_LEN fields of the same register) separately without the need to read/modify/write the value. If RX_BUF_LEN_W1T and TX_BUF_LEN_W1T bits are 0, then both TX and RX DMA length will be written.

When setting the RX_BUF_LEN field, the TX_BUF_LEN field being set is not an invalid condition. Remove the assert.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3315

---
 hw/i2c/aspeed_i2c.c | 1 -
 1 file changed, 1 deletion(-)
hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0 -0

ad6342bec0d4..5d18f8d49ea4 100644

hw/i2c/aspeed_i2c.c +0 -1
@@ -780,7 +780,6 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus
 *bus, hwaddr offset,
         bus->regs[R_I2CS_DMA_RX_ADDR] = value;
         break;
     case A_I2CS_DMA_LEN:
-        assert(FIELD_EX32(value, I2CS_DMA_LEN, TX_BUF_LEN) == 0);
         if (FIELD_EX32(value, I2CS_DMA_LEN, RX_BUF_LEN_W1T)) {
             ARRAY_FIELD_DP32(bus->regs, I2CS_DMA_LEN, RX_BUF_LEN,
                              FIELD_EX32(value, I2CS_DMA_LEN,
Quoted 3 lines

RX_BUF_LEN));
--
2.53.0

Thanks,
Jamin