Skip to contentSkip to conversation

Misc HW patches for 2026-07-21

GIT PULL Applied Philippe Mathieu-Daudé 2 participants 11 messages Jul 21 Networking

lore
Share & tools
lore
#0 lore raw

The following changes since commit bd6079a7a1d14de0918a7715ef6db85dc32de3bb:

Merge tag 'next-pull-request' of https://gitlab.com/peterx/qemu into staging (2026-07-20 11:12:38 -0400)

are available in the Git repository at:

https://github.com/philmd/qemu.git tags/hw-misc-20260714

for you to fetch changes up to d06edc83b522c68627b83d3178197353c4d548ab:

vfio/listener: Remove unnecessary 'linux/kvm.h' include (2026-07-21 12:38:48 +0200)

----------------------------------------------------------------
Misc HW patches

Various fixes mostly related to misc hardware devices.

The only CI failure is related to a sphinx error, and there is already developers looking at that so I ignored it:
https://lore.kernel.org/qemu-devel/[email protected]/
----------------------------------------------------------------

Bernhard Beschow (1):
hw/sd/sdcard: Fix error case for CMD18

Bin Meng (1):
hw/net/cadence: Return current Cadence GEM queue pointers

Cédric Le Goater (1):
vfio/listener: Remove unnecessary 'linux/kvm.h' include

Haotian Jiang (1):
hw/audio/intel-hda: restrict all DMA engine paths to memories

Marc-André Lureau (2):
hw/display/qxl: validate monitors_config heads[] in phys2virt
replay: fix use of uninitialized pointer on error

Peter Maydell (1):
net: Correct padding check in qemu_receive_packet()

Philippe Mathieu-Daudé (1):
hw/misc/applesmc: Fix a typo setting MSSD key

Richard Henderson (1):
user/guest-host: Include exec/abi_ptr.h

 include/net/net.h         | 23 +++++++++++++++++++++++
 include/user/guest-host.h |  1 +
 hw/audio/intel-hda.c      |  9 ++++++---
 hw/display/qxl.c          |  2 +-
 hw/misc/applesmc.c        |  6 +++---
 hw/net/cadence_gem.c      | 17 ++++++++++++++++-
 hw/sd/sd.c                |  3 ++-
 hw/vfio/listener.c        |  1 -
 net/net.c                 |  2 +-
 replay/replay-debugging.c | 23 ++++++++++++-----------
 10 files changed, 65 insertions(+), 22 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

[PULL 1/9] net: Correct padding check in qemu_receive_packet()

From: Peter Maydell <[email protected]>

In qemu_receive_packet() we check to see if we should pad a short packet. This is doing the wrong test: because this function is used when the device adds a packet to its own incoming queue (i.e. for loopback), we should be checking the NetClientState's own do_not_pad flag, not that for its peer.

We didn't notice this earlier, because at the moment all the real peers of a network device (i.e. the network backends) do not set do_not_pad, so net_peer_needs_padding() always returns true except in the corner case where the network device has no peer at all.

The effect of this is that if a network device has no peer (e.g. because QEMU was started with -net none or with -nodefaults) then we can still let through the kind of "guest misprograms the network device to loopback-transmit a short packet and then we mishandle it in the receive path" bug like #3043 which commit a01344d9d78 was trying to fix.

Since the distinction between "we should check nc->do_not_pad" and "we should check nc->peer->do_not_pad" is a bit subtle, add enough documentation commentary to make it more obvious.

Fixes a01344d9d78 ("net: pad packets to minimum length in qemu_receive_packet()")

Message-ID: <[email protected]>

---
 include/net/net.h | 23 +++++++++++++++++++++++
 net/net.c         |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)
include/net/net.h +23 -0
index 45bc86fc86b..9edfacf827c 100644
@@ -349,9 +349,32 @@ uint32_t net_crc32_le(const uint8_t *p, int len);
     .offset     = vmstate_offset_macaddr(_state, _field),            \
 }
 
+/**
+ * net_peer_needs_padding: Should we pad as we send out packets?
+ * @nc: NetClientState
+ *
+ * Return true if the peer of this NetClientState (i.e. the
+ * destination that qemu_send_packet() etc send to) requires us to pad
+ * out packets that are shorter than the minimum ethernet frame
+ * length.
+ */
 static inline bool net_peer_needs_padding(NetClientState *nc)
 {
   return nc->peer && !nc->peer->do_not_pad;
 }
 
+/**
+ * net_client_needs_padding: Should we pad as we queue packets to ourselves?
+ * @nc: NetClientState
+ *
+ * Return true if this NetClientState requires us to pad out packets
+ * that are shorter than the minimum ethernet frame length.  This is
+ * the check to make in qemu_receive_packet() when we are queuing a
+ * packet back into ourselves (i.e. loopback).
+ */
+static inline bool net_client_needs_padding(NetClientState *nc)
+{
+    return !nc->do_not_pad;
+}
+
 #endif
net/net.c +1 -1
index 5c39f8e7b44..0a30579ca4a 100644
@@ -783,7 +783,7 @@ ssize_t qemu_receive_packet(NetClientState *nc, const uint8_t *buf, int size)
         return 0;
     }
 
-    if (net_peer_needs_padding(nc)) {
+    if (net_client_needs_padding(nc)) {
         if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
             buf = min_pkt;
             size = min_pktsz;
Signature · 1 line
2.53.0
#2 lore raw

[PULL 7/9] hw/sd/sdcard: Fix error case for CMD18

In reply to Philippe Mathieu-Daudé

From: Bernhard Beschow <[email protected]>

In commit 468fa450a7e0 ("hw/sd: Switch read/write primitive to buf+len"), sd_read_byte() changed its contract to return the read size rather than the read value (and was renamed to sd_read_data() accordingly). In an error case, however, sd_read_data() returns 0 by means of dummy_byte which is the code for the old contract. Moreover, sdbus_read_data() asserts the virtual method read_data() (and thus sd_read_data()) to return a non-zero size, i.e. to make progress and not loop forever. Fix the code to behave like the "DAT read illegal for command" case.

Fixes 468fa450a7e0 ("hw/sd: Switch read/write primitive to buf+len")

Message-ID: <[email protected]>

---
 hw/sd/sd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/sd/sd.c +2 -1
index 33607570043..a30c541df07 100644
@@ -2860,7 +2860,8 @@ static size_t sd_read_data(SDState *sd, void *buf, size_t length)
         if (sd->data_offset == 0) {
             if (!address_in_range(sd, "READ_MULTIPLE_BLOCK",
                                   sd->data_start, io_len)) {
-                return dummy_byte;
+                *value = dummy_byte;
+                return length;
             }
             partition_access = sd->ext_csd[EXT_CSD_PART_CONFIG]
                     & EXT_CSD_PART_CONFIG_ACC_MASK;
Signature · 1 line
2.53.0
#3 lore raw

[PULL 5/9] hw/misc/applesmc: Fix a typo setting MSSD key

In reply to Philippe Mathieu-Daudé

In commit 1ddda5cd364 we meant to set MSSD=3, but due to a typo we ended setting MSSD=0. Convert the two other NATJ and MSSP keys to use hexadecimal notation to avoid similar copy/paste typos.

Message-Id: <[email protected]>

---
 hw/misc/applesmc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/misc/applesmc.c +3 -3
index fd96f5f245f..d004e8b4431 100644
@@ -333,9 +333,9 @@ static void applesmc_isa_realize(DeviceState *dev, Error **errp)
     applesmc_add_key(s, "REV ", 6, "\x01\x13\x0f\x00\x00\x03");
     applesmc_add_key(s, "OSK0", 32, s->osk);
     applesmc_add_key(s, "OSK1", 32, s->osk + 32);
-    applesmc_add_key(s, "NATJ", 1, "\0");
-    applesmc_add_key(s, "MSSP", 1, "\0");
-    applesmc_add_key(s, "MSSD", 1, "\0x3");
+    applesmc_add_key(s, "NATJ", 1, "\x00");
+    applesmc_add_key(s, "MSSP", 1, "\x00");
+    applesmc_add_key(s, "MSSD", 1, "\x03");
 }
 
 static void applesmc_unrealize(DeviceState *dev)
Signature · 1 line
2.53.0
#4 lore raw

[PULL 2/9] hw/display/qxl: validate monitors_config heads[] in phys2virt

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

The qxl_phys2virt() call for guest_monitors_config only validates sizeof(QXLMonitorsConfig), which covers the fixed header (count and max_allowed) since commit 8efec0ef8bbc ("hw/display/qxl: Pass requested buffer size to qxl_phys2virt()"), but not the flexible array member heads[]. When count == 1, heads[0] is accessed without its memory being validated, allowing a guest to cause an out-of-bounds read.

Include sizeof(QXLHead) in the size passed to qxl_phys2virt() so that the first head entry is validated within the guest memory slot, preventing guest-visible memory reading.

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

Message-ID: <[email protected]>

---
 hw/display/qxl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/qxl.c +1 -1
index 74258afa582..3df796175c2 100644
@@ -270,7 +270,7 @@ static void qxl_spice_monitors_config_async(PCIQXLDevice *qxl, int replay)
     }
 
     cfg = qxl_phys2virt(qxl, qxl->guest_monitors_config, MEMSLOT_GROUP_GUEST,
-                        sizeof(QXLMonitorsConfig));
+                        sizeof(QXLMonitorsConfig) + sizeof(QXLHead));
     if (cfg != NULL && cfg->count == 1) {
         qxl->guest_primary.resized = 1;
         qxl->guest_head0_width  = cfg->heads[0].width;
Signature · 1 line
2.53.0
#5 lore raw

[PULL 4/9] replay: fix use of uninitialized pointer on error

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

When bdrv_snapshot_list() returns a negative error code, sn_tab is uninitialized. The loop does not execute (since i=0 < negative is false), but the code falls through to g_free(sn_tab) which frees an uninitialized pointer.

Fixes f6baed3d1485 ("replay: implement replay-seek command")

Message-ID: <[email protected]>

---
 replay/replay-debugging.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
replay/replay-debugging.c +12 -11
index 11053640021..7b904a14165 100644
@@ -139,9 +139,8 @@ static char *replay_find_nearest_snapshot(int64_t icount,
                                           int64_t *snapshot_icount)
 {
     BlockDriverState *bs;
-    QEMUSnapshotInfo *sn_tab;
+    g_autofree QEMUSnapshotInfo *sn_tab = NULL;
     QEMUSnapshotInfo *nearest = NULL;
-    char *ret = NULL;
     int rv;
     int nb_sns, i;
 
@@ -149,15 +148,19 @@ static char *replay_find_nearest_snapshot(int64_t icount,
 
     bs = bdrv_all_find_vmstate_bs(NULL, false, NULL, NULL);
     if (!bs) {
-        goto fail;
+        return NULL;
     }
 
     nb_sns = bdrv_snapshot_list(bs, &sn_tab);
+    if (nb_sns < 0) {
+        return NULL;
+    }
 
     for (i = 0; i < nb_sns; i++) {
         rv = bdrv_all_has_snapshot(sn_tab[i].name, false, NULL, NULL);
-        if (rv < 0)
-            goto fail;
+        if (rv < 0) {
+            return NULL;
+        }
         if (rv == 1) {
             if (sn_tab[i].icount != -1ULL
                 && sn_tab[i].icount <= icount
@@ -166,14 +169,12 @@ static char *replay_find_nearest_snapshot(int64_t icount,
             }
         }
     }
-    if (nearest) {
-        ret = g_strdup(nearest->name);
-        *snapshot_icount = nearest->icount;
+    if (!nearest) {
+        return NULL;
     }
-    g_free(sn_tab);
 
-fail:
-    return ret;
+    *snapshot_icount = nearest->icount;
+    return g_strdup(nearest->name);
 }
 
 static void replay_seek(int64_t icount, QEMUTimerCB callback, Error **errp)
Signature · 1 line
2.53.0
#6 lore raw

[PULL 6/9] hw/net/cadence: Return current Cadence GEM queue pointers

In reply to Philippe Mathieu-Daudé

From: Bin Meng <[email protected]>

Cadence GEM queue pointer registers are programmed with the descriptor ring base, but reads return the descriptor currently being accessed. The model tracked the current positions separately while continuing to return the configured base.

The Linux macb driver uses the transmit queue pointer when recovering from a used-buffer interrupt. A stale priority-queue pointer can make the driver restart DMA before that queue handles its completion interrupt, causing queue 0 to repeatedly raise TX_USED.

The primary queue has had this mismatch since the initial model. Priority queue support later copied the same register-read behavior.

A single-queue machine usually handles TX_COMPLETE before TX_USED and empties the software queue before the restart check, which kept the issue hidden there.

Return the current RX and TX descriptor positions on queue-pointer reads and clear those positions on reset.

Fixes e9f186e514a7 ("cadence_gem: initial version of device model")
Fixes 6710172501be ("cadence_gem: Add queue support")

Message-ID: <[email protected]>

---
 hw/net/cadence_gem.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
hw/net/cadence_gem.c +16 -1
index b568fa3392d..39e3620ef5b 100644
@@ -1469,6 +1469,8 @@ static void gem_reset(DeviceState *d)
 
     /* Set post reset register values */
     memset(&s->regs[0], 0, sizeof(s->regs));
+    memset(&s->rx_desc_addr[0], 0, sizeof(s->rx_desc_addr));
+    memset(&s->tx_desc_addr[0], 0, sizeof(s->tx_desc_addr));
     s->regs[R_NWCFG] = 0x00080000;
     s->regs[R_NWSTATUS] = 0x00000006;
     s->regs[R_DMACFG] = 0x00020784;
@@ -1593,9 +1595,22 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
     offset >>= 2;
     retval = s->regs[offset];
 
-    DB_PRINT("offset: 0x%04x read: 0x%08x\n", (unsigned)offset*4, retval);
+    DB_PRINT("offset: 0x%04x read: 0x%08x\n", (unsigned)offset * 4,
+             retval);
 
     switch (offset) {
+    case R_RXQBASE:
+        retval = s->rx_desc_addr[0];
+        break;
+    case R_TXQBASE:
+        retval = s->tx_desc_addr[0];
+        break;
+    case R_TRANSMIT_Q1_PTR ... R_TRANSMIT_Q7_PTR:
+        retval = s->tx_desc_addr[offset - R_TRANSMIT_Q1_PTR + 1];
+        break;
+    case R_RECEIVE_Q1_PTR ... R_RECEIVE_Q7_PTR:
+        retval = s->rx_desc_addr[offset - R_RECEIVE_Q1_PTR + 1];
+        break;
     case R_ISR:
         DB_PRINT("lowering irqs on ISR read\n");
         /* The interrupts get updated at the end of the function. */
Signature · 1 line
2.53.0
#7 lore raw

[PULL 9/9] vfio/listener: Remove unnecessary 'linux/kvm.h' include

In reply to Philippe Mathieu-Daudé

From: Cédric Le Goater <[email protected]>

Since commit d0e8bccafc23 ("hw/vfio/listener.c: remove CONFIG_KVM"), the linux/kvm.h include is unconditional. This breaks the build on targets that lack asm/kvm.h such as sparc and sparc64:

In file included from ../hw/vfio/listener.c:23:
linux-headers/linux/kvm.h:16:10: fatal error: asm/kvm.h: No such file or directory

This include is not needed in listener.c which only uses kvm_enabled() and kvm_get_max_memslots(), both are declared in "system/kvm.h". Remove it.

Fixes d0e8bccafc23 ("hw/vfio/listener.c: remove CONFIG_KVM")
Cc Pierrick Bouvier <[email protected]>"

Message-ID: <[email protected]>

---
 hw/vfio/listener.c | 1 -
 1 file changed, 1 deletion(-)
hw/vfio/listener.c +0 -1
index c19600e980a..008f488a3e7 100644
@@ -20,7 +20,6 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#include <linux/kvm.h>
 #include <linux/vfio.h>
 
 #include "exec/target_page.h"
Signature · 1 line
2.53.0
#8 lore raw

[PULL 3/9] user/guest-host: Include exec/abi_ptr.h

In reply to Philippe Mathieu-Daudé

From: Richard Henderson <[email protected]>

The COMPILING_PER_TARGET block uses the abi_ptr type without including the proper header.

Message-ID: <[email protected]>

---
 include/user/guest-host.h | 1 +
 1 file changed, 1 insertion(+)
include/user/guest-host.h +1 -0
index 506efc097e0..f136f81f5d9 100644
@@ -80,6 +80,7 @@ static inline bool guest_range_valid_untagged_vaddr(vaddr start, vaddr len)
 })
 
 #ifdef COMPILING_PER_TARGET
+#include "exec/abi_ptr.h"
 
 /*
  * These functions take the guest virtual address as an abi_ptr.  This
Signature · 1 line
2.53.0
#9 lore raw

[PULL 8/9] hw/audio/intel-hda: restrict all DMA engine paths to memories

In reply to Philippe Mathieu-Daudé

From: Haotian Jiang <[email protected]>

CVE-2021-3611 (commit 79fa99831d) restricted the DMA engine to memories by setting attrs.memory=true, but only applied this to intel_hda_response. Three other DMA engine access points still use MEMTXATTRS_UNSPECIFIED, allowing a malicious guest to trigger DMA-to-self-MMIO reentry:

- intel_hda_xfer (line 398): called from the audio timer callback (hda_codec_xfer -> bus->xfer), so the MemReentrancyGuard does not fire (engaged_in_io is false outside MMIO dispatch). A guest that points a BDL entry at the HDA controller's own MMIO BAR can write audio samples to device registers, triggering whandler side effects such as starting/stopping streams or injecting codec commands via CORBWP.
- intel_hda_parse_bdl (line 478): uses pci_dma_read which hardcodes MEMTXATTRS_UNSPECIFIED. A guest-controlled BDL base address can point at controller MMIO, allowing the DMA engine to read device registers as BDL descriptors.
- intel_hda_corb_run (line 333): ldl_le_pci_dma reads the CORB ring with MEMTXATTRS_UNSPECIFIED, allowing the DMA engine to read controller MMIO as CORB entries.

Fix all three by passing {.memory = true} explicitly, matching the fix already applied to intel_hda_response. For intel_hda_parse_bdl, replace pci_dma_read with pci_dma_rw to pass the controlled attrs.

Fixes 79fa99831d ("hw/audio/intel-hda: Restrict DMA engine to memories (not MMIO devices)")

Message-ID: <[email protected]>

---
 hw/audio/intel-hda.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/audio/intel-hda.c +6 -3
index d7c2c3c2fd4..3d361a4976c 100644
@@ -305,6 +305,7 @@ static int intel_hda_send_command(IntelHDAState *d, uint32_t verb)
 
 static void intel_hda_corb_run(IntelHDAState *d)
 {
+    const MemTxAttrs attrs = { .memory = true };
     hwaddr addr;
     uint32_t rp, verb;
 
@@ -330,7 +331,7 @@ static void intel_hda_corb_run(IntelHDAState *d)
 
         rp = (d->corb_rp + 1) & 0xff;
         addr = intel_hda_addr(d->corb_lbase, d->corb_ubase);
-        ldl_le_pci_dma(&d->pci, addr + 4 * rp, &verb, MEMTXATTRS_UNSPECIFIED);
+        ldl_le_pci_dma(&d->pci, addr + 4 * rp, &verb, attrs);
         d->corb_rp = rp;
 
         dprint(d, 2, "%s: [rp 0x%x] verb 0x%08x\n", __func__, rp, verb);
@@ -395,7 +396,7 @@ static void intel_hda_response(HDACodecDevice *dev, bool solicited, uint32_t res
 static bool intel_hda_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
                            uint8_t *buf, uint32_t len)
 {
-    const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;
+    const MemTxAttrs attrs = { .memory = true };
     HDACodecBus *bus = HDA_BUS(dev->qdev.parent_bus);
     IntelHDAState *d = container_of(bus, IntelHDAState, codecs);
     hwaddr addr;
@@ -466,6 +467,7 @@ static bool intel_hda_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
 
 static void intel_hda_parse_bdl(IntelHDAState *d, IntelHDAStream *st)
 {
+    const MemTxAttrs attrs = { .memory = true };
     hwaddr addr;
     uint8_t buf[16];
     uint32_t i;
@@ -475,7 +477,8 @@ static void intel_hda_parse_bdl(IntelHDAState *d, IntelHDAStream *st)
     g_free(st->bpl);
     st->bpl = g_new(bpl, st->bentries);
     for (i = 0; i < st->bentries; i++, addr += 16) {
-        pci_dma_read(&d->pci, addr, buf, 16);
+        pci_dma_rw(&d->pci, addr, buf, 16,
+                   DMA_DIRECTION_TO_DEVICE, attrs);
         st->bpl[i].addr  = le64_to_cpu(*(uint64_t *)buf);
         st->bpl[i].len   = le32_to_cpu(*(uint32_t *)(buf + 8));
         st->bpl[i].flags = le32_to_cpu(*(uint32_t *)(buf + 12));
Signature · 1 line
2.53.0